Commit 39d70a4a authored by Haiyang Zhang's avatar Haiyang Zhang Committed by Greg Kroah-Hartman

staging: hv: Remove camel case variables in channel.c

Rename camel case variables in channel.c and changed them to
lowercase.
Signed-off-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: default avatarHank Janssen <hjanssen@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 03094f5e
...@@ -28,10 +28,10 @@ ...@@ -28,10 +28,10 @@
/* 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);
...@@ -70,25 +70,25 @@ static void DumpMonitorPage(struct hv_monitor_page *MonitorPage) ...@@ -70,25 +70,25 @@ static void DumpMonitorPage(struct hv_monitor_page *MonitorPage)
* VmbusChannelSetEvent - Trigger an event notification on the specified * VmbusChannelSetEvent - Trigger an event notification on the specified
* channel. * 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;
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 = 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 (unsigned long *)&monitorpage->TriggerGroup
[Channel->MonitorGroup].Pending); [channel->MonitorGroup].Pending);
} else { } else {
VmbusSetEvent(Channel->OfferMsg.ChildRelId); VmbusSetEvent(channel->OfferMsg.ChildRelId);
} }
} }
...@@ -117,54 +117,54 @@ static void VmbusChannelClearEvent(struct vmbus_channel *channel) ...@@ -117,54 +117,54 @@ static void VmbusChannelClearEvent(struct vmbus_channel *channel)
/* /*
* VmbusChannelGetDebugInfo -Retrieve various channel debug info * VmbusChannelGetDebugInfo -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 monitor_group = (u8)channel->OfferMsg.MonitorId / 32;
u8 monitorOffset = (u8)Channel->OfferMsg.MonitorId % 32; u8 monitor_offset = (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, memcpy(&debuginfo->InterfaceType,
&Channel->OfferMsg.Offer.InterfaceType, sizeof(struct hv_guid)); &channel->OfferMsg.Offer.InterfaceType, sizeof(struct hv_guid));
memcpy(&DebugInfo->InterfaceInstance, memcpy(&debuginfo->InterfaceInstance,
&Channel->OfferMsg.Offer.InterfaceInstance, &channel->OfferMsg.Offer.InterfaceInstance,
sizeof(struct hv_guid)); 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 = debuginfo->ServerMonitorPending =
monitorPage->TriggerGroup[monitorGroup].Pending; monitorpage->TriggerGroup[monitor_group].Pending;
DebugInfo->ServerMonitorLatency = debuginfo->ServerMonitorLatency =
monitorPage->Latency[monitorGroup][monitorOffset]; monitorpage->Latency[monitor_group][monitor_offset];
DebugInfo->ServerMonitorConnectionId = debuginfo->ServerMonitorConnectionId =
monitorPage->Parameter[monitorGroup] monitorpage->Parameter[monitor_group]
[monitorOffset].ConnectionId.u.Id; [monitor_offset].ConnectionId.u.Id;
monitorPage++; monitorpage++;
DebugInfo->ClientMonitorPending = debuginfo->ClientMonitorPending =
monitorPage->TriggerGroup[monitorGroup].Pending; monitorpage->TriggerGroup[monitor_group].Pending;
DebugInfo->ClientMonitorLatency = debuginfo->ClientMonitorLatency =
monitorPage->Latency[monitorGroup][monitorOffset]; monitorpage->Latency[monitor_group][monitor_offset];
DebugInfo->ClientMonitorConnectionId = debuginfo->ClientMonitorConnectionId =
monitorPage->Parameter[monitorGroup] monitorpage->Parameter[monitor_group]
[monitorOffset].ConnectionId.u.Id; [monitor_offset].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. * VmbusChannelOpen - Open the specified channel.
*/ */
int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, int VmbusChannelOpen(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
u32 RecvRingBufferSize, void *UserData, u32 UserDataLen, u32 recv_ringbuffer_size, void *userdata, u32 userdatalen,
void (*OnChannelCallback)(void *context), void *Context) void (*onchannelcallback)(void *context), void *context)
{ {
struct vmbus_channel_open_channel *openMsg; struct vmbus_channel_open_channel *openMsg;
struct vmbus_channel_msginfo *openInfo = NULL; struct vmbus_channel_msginfo *openInfo = NULL;
...@@ -176,30 +176,30 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, ...@@ -176,30 +176,30 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize,
/* ASSERT(!(SendRingBufferSize & (PAGE_SIZE - 1))); */ /* ASSERT(!(SendRingBufferSize & (PAGE_SIZE - 1))); */
/* ASSERT(!(RecvRingBufferSize & (PAGE_SIZE - 1))); */ /* ASSERT(!(RecvRingBufferSize & (PAGE_SIZE - 1))); */
NewChannel->OnChannelCallback = OnChannelCallback; newchannel->OnChannelCallback = onchannelcallback;
NewChannel->ChannelCallbackContext = Context; newchannel->ChannelCallbackContext = context;
/* Allocate the ring buffer */ /* Allocate the ring buffer */
out = osd_PageAlloc((SendRingBufferSize + RecvRingBufferSize) out = osd_PageAlloc((send_ringbuffer_size + recv_ringbuffer_size)
>> PAGE_SHIFT); >> PAGE_SHIFT);
if (!out) if (!out)
return -ENOMEM; return -ENOMEM;
/* 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 + send_ringbuffer_size);
NewChannel->RingBufferPages = out; newchannel->RingBufferPages = out;
NewChannel->RingBufferPageCount = (SendRingBufferSize + newchannel->RingBufferPageCount = (send_ringbuffer_size +
RecvRingBufferSize) >> PAGE_SHIFT; recv_ringbuffer_size) >> PAGE_SHIFT;
ret = RingBufferInit(&NewChannel->Outbound, out, SendRingBufferSize); ret = RingBufferInit(&newchannel->Outbound, out, send_ringbuffer_size);
if (ret != 0) { if (ret != 0) {
err = ret; err = ret;
goto errorout; goto errorout;
} }
ret = RingBufferInit(&NewChannel->Inbound, in, RecvRingBufferSize); ret = RingBufferInit(&newchannel->Inbound, in, recv_ringbuffer_size);
if (ret != 0) { if (ret != 0) {
err = ret; err = ret;
goto errorout; goto errorout;
...@@ -208,15 +208,15 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, ...@@ -208,15 +208,15 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize,
/* 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...", DPRINT_DBG(VMBUS, "Establishing ring buffer's gpadl for channel %p...",
NewChannel); newchannel);
NewChannel->RingBufferGpadlHandle = 0; newchannel->RingBufferGpadlHandle = 0;
ret = VmbusChannelEstablishGpadl(NewChannel, ret = VmbusChannelEstablishGpadl(newchannel,
NewChannel->Outbound.RingBuffer, newchannel->Outbound.RingBuffer,
SendRingBufferSize + send_ringbuffer_size +
RecvRingBufferSize, recv_ringbuffer_size,
&NewChannel->RingBufferGpadlHandle); &newchannel->RingBufferGpadlHandle);
if (ret != 0) { if (ret != 0) {
err = ret; err = ret;
...@@ -225,13 +225,13 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, ...@@ -225,13 +225,13 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize,
DPRINT_DBG(VMBUS, "channel %p <relid %d gpadl 0x%x send ring %p " DPRINT_DBG(VMBUS, "channel %p <relid %d gpadl 0x%x send ring %p "
"size %d recv ring %p size %d, downstreamoffset %d>", "size %d recv ring %p size %d, downstreamoffset %d>",
NewChannel, NewChannel->OfferMsg.ChildRelId, newchannel, newchannel->OfferMsg.ChildRelId,
NewChannel->RingBufferGpadlHandle, newchannel->RingBufferGpadlHandle,
NewChannel->Outbound.RingBuffer, newchannel->Outbound.RingBuffer,
NewChannel->Outbound.RingSize, newchannel->Outbound.RingSize,
NewChannel->Inbound.RingBuffer, newchannel->Inbound.RingBuffer,
NewChannel->Inbound.RingSize, newchannel->Inbound.RingSize,
SendRingBufferSize); send_ringbuffer_size);
/* Create and init the channel open message */ /* Create and init the channel open message */
openInfo = kmalloc(sizeof(*openInfo) + openInfo = kmalloc(sizeof(*openInfo) +
...@@ -250,20 +250,20 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, ...@@ -250,20 +250,20 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize,
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;
openMsg->DownstreamRingBufferPageOffset = SendRingBufferSize >> openMsg->DownstreamRingBufferPageOffset = send_ringbuffer_size >>
PAGE_SHIFT; PAGE_SHIFT;
openMsg->ServerContextAreaGpadlHandle = 0; /* TODO */ openMsg->ServerContextAreaGpadlHandle = 0; /* TODO */
if (UserDataLen > MAX_USER_DEFINED_BYTES) { if (userdatalen > MAX_USER_DEFINED_BYTES) {
err = -EINVAL; err = -EINVAL;
goto errorout; goto errorout;
} }
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);
list_add_tail(&openInfo->MsgListEntry, list_add_tail(&openInfo->MsgListEntry,
...@@ -283,10 +283,10 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, ...@@ -283,10 +283,10 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize,
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);
...@@ -298,9 +298,9 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, ...@@ -298,9 +298,9 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize,
return 0; return 0;
errorout: errorout:
RingBufferCleanup(&NewChannel->Outbound); RingBufferCleanup(&newchannel->Outbound);
RingBufferCleanup(&NewChannel->Inbound); RingBufferCleanup(&newchannel->Inbound);
osd_PageFree(out, (SendRingBufferSize + RecvRingBufferSize) osd_PageFree(out, (send_ringbuffer_size + recv_ringbuffer_size)
>> PAGE_SHIFT); >> PAGE_SHIFT);
kfree(openInfo); kfree(openInfo);
return err; return err;
...@@ -310,289 +310,292 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize, ...@@ -310,289 +310,292 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize,
* DumpGpadlBody - Dump the gpadl body message to the console for * DumpGpadlBody - Dump the gpadl body message to the console for
* debugging purposes. * 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; int i;
int pfnCount; int pfncount;
pfnCount = (Len - sizeof(struct vmbus_channel_gpadl_body)) / pfncount = (len - sizeof(struct vmbus_channel_gpadl_body)) /
sizeof(u64); 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 * DumpGpadlHeader - Dump the gpadl header message to the console for
* debugging purposes. * debugging purposes.
*/ */
static void DumpGpadlHeader(struct vmbus_channel_gpadl_header *Gpadl) static void DumpGpadlHeader(struct vmbus_channel_gpadl_header *gpadl)
{ {
int i, j; int i, j;
int pageCount; int pagecount;
DPRINT_DBG(VMBUS, DPRINT_DBG(VMBUS,
"gpadl header - relid %d, range count %d, range buflen %d", "gpadl header - relid %d, range count %d, range buflen %d",
Gpadl->ChildRelId, Gpadl->RangeCount, Gpadl->RangeBufLen); gpadl->ChildRelId, gpadl->RangeCount, 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 " DPRINT_DBG(VMBUS, "gpadl range %d - len %d offset %d "
"page count %d", i, Gpadl->Range[i].ByteCount, "page count %d", i, gpadl->Range[i].ByteCount,
Gpadl->Range[i].ByteOffset, pageCount); 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 * VmbusChannelCreateGpadlHeader - Creates a gpadl for the specified buffer
*/ */
static int VmbusChannelCreateGpadlHeader(void *Kbuffer, u32 Size, static int VmbusChannelCreateGpadlHeader(void *kbuffer, u32 size,
struct vmbus_channel_msginfo **MsgInfo, struct vmbus_channel_msginfo **msginfo,
u32 *MessageCount) 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 *gpadl_header;
struct vmbus_channel_gpadl_body *gpadlBody; struct vmbus_channel_gpadl_body *gpadl_body;
struct vmbus_channel_msginfo *msgHeader; struct vmbus_channel_msginfo *msgheader;
struct vmbus_channel_msginfo *msgBody = NULL; struct vmbus_channel_msginfo *msgbody = NULL;
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 - pfnsize = MAX_SIZE_CHANNEL_MESSAGE -
sizeof(struct vmbus_channel_gpadl_header) - sizeof(struct vmbus_channel_gpadl_header) -
sizeof(struct gpa_range); sizeof(struct gpa_range);
pfnCount = pfnSize / sizeof(u64); pfncount = pfnsize / sizeof(u64);
if (pageCount > pfnCount) { if (pagecount > pfncount) {
/* we need a gpadl body */ /* we need a gpadl body */
/* fill in the header */ /* fill in the header */
msgSize = sizeof(struct vmbus_channel_msginfo) + msgsize = sizeof(struct vmbus_channel_msginfo) +
sizeof(struct vmbus_channel_gpadl_header) + sizeof(struct vmbus_channel_gpadl_header) +
sizeof(struct gpa_range) + pfnCount * sizeof(u64); sizeof(struct gpa_range) + pfncount * sizeof(u64);
msgHeader = kzalloc(msgSize, GFP_KERNEL); msgheader = kzalloc(msgsize, GFP_KERNEL);
if (!msgHeader) if (!msgheader)
goto nomem; goto nomem;
INIT_LIST_HEAD(&msgHeader->SubMsgList); INIT_LIST_HEAD(&msgheader->SubMsgList);
msgHeader->MessageSize = msgSize; msgheader->MessageSize = msgsize;
gpaHeader = (struct vmbus_channel_gpadl_header *)msgHeader->Msg; gpadl_header = (struct vmbus_channel_gpadl_header *)
gpaHeader->RangeCount = 1; msgheader->Msg;
gpaHeader->RangeBufLen = sizeof(struct gpa_range) + gpadl_header->RangeCount = 1;
pageCount * sizeof(u64); gpadl_header->RangeBufLen = sizeof(struct gpa_range) +
gpaHeader->Range[0].ByteOffset = 0; pagecount * sizeof(u64);
gpaHeader->Range[0].ByteCount = Size; gpadl_header->Range[0].ByteOffset = 0;
for (i = 0; i < pfnCount; i++) gpadl_header->Range[0].ByteCount = size;
gpaHeader->Range[0].PfnArray[i] = pfn+i; for (i = 0; i < pfncount; i++)
*MsgInfo = msgHeader; gpadl_header->Range[0].PfnArray[i] = pfn+i;
*MessageCount = 1; *msginfo = msgheader;
*messagecount = 1;
pfnSum = pfnCount; pfnsum = pfncount;
pfnLeft = pageCount - pfnCount; pfnleft = pagecount - pfncount;
/* how many pfns can we fit */ /* how many pfns can we fit */
pfnSize = MAX_SIZE_CHANNEL_MESSAGE - pfnsize = MAX_SIZE_CHANNEL_MESSAGE -
sizeof(struct vmbus_channel_gpadl_body); 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) + msgsize = sizeof(struct vmbus_channel_msginfo) +
sizeof(struct vmbus_channel_gpadl_body) + sizeof(struct vmbus_channel_gpadl_body) +
pfnCurr * sizeof(u64); pfncurr * sizeof(u64);
msgBody = kzalloc(msgSize, GFP_KERNEL); msgbody = kzalloc(msgsize, GFP_KERNEL);
/* FIXME: we probably need to more if this fails */ /* FIXME: we probably need to more if this fails */
if (!msgBody) if (!msgbody)
goto nomem; goto nomem;
msgBody->MessageSize = msgSize; msgbody->MessageSize = msgsize;
(*MessageCount)++; (*messagecount)++;
gpadlBody = gpadl_body =
(struct vmbus_channel_gpadl_body *)msgBody->Msg; (struct vmbus_channel_gpadl_body *)msgbody->Msg;
/* /*
* FIXME: * FIXME:
* Gpadl is u32 and we are using a pointer which could * Gpadl is u32 and we are using a pointer which could
* be 64-bit * be 64-bit
*/ */
/* gpadlBody->Gpadl = kbuffer; */ /* gpadl_body->Gpadl = kbuffer; */
for (i = 0; i < pfnCurr; i++) for (i = 0; i < pfncurr; i++)
gpadlBody->Pfn[i] = pfn + pfnSum + i; gpadl_body->Pfn[i] = pfn + pfnsum + i;
/* add to msg header */ /* add to msg header */
list_add_tail(&msgBody->MsgListEntry, list_add_tail(&msgbody->MsgListEntry,
&msgHeader->SubMsgList); &msgheader->SubMsgList);
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) + msgsize = sizeof(struct vmbus_channel_msginfo) +
sizeof(struct vmbus_channel_gpadl_header) + sizeof(struct vmbus_channel_gpadl_header) +
sizeof(struct gpa_range) + pageCount * sizeof(u64); sizeof(struct gpa_range) + pagecount * sizeof(u64);
msgHeader = kzalloc(msgSize, GFP_KERNEL); msgheader = kzalloc(msgsize, GFP_KERNEL);
if (msgHeader == NULL) if (msgheader == NULL)
goto nomem; goto nomem;
msgHeader->MessageSize = msgSize; msgheader->MessageSize = msgsize;
gpaHeader = (struct vmbus_channel_gpadl_header *)msgHeader->Msg; gpadl_header = (struct vmbus_channel_gpadl_header *)
gpaHeader->RangeCount = 1; msgheader->Msg;
gpaHeader->RangeBufLen = sizeof(struct gpa_range) + gpadl_header->RangeCount = 1;
pageCount * sizeof(u64); gpadl_header->RangeBufLen = sizeof(struct gpa_range) +
gpaHeader->Range[0].ByteOffset = 0; pagecount * sizeof(u64);
gpaHeader->Range[0].ByteCount = Size; gpadl_header->Range[0].ByteOffset = 0;
for (i = 0; i < pageCount; i++) gpadl_header->Range[0].ByteCount = size;
gpaHeader->Range[0].PfnArray[i] = pfn+i; for (i = 0; i < pagecount; i++)
gpadl_header->Range[0].PfnArray[i] = pfn+i;
*MsgInfo = msgHeader;
*MessageCount = 1; *msginfo = msgheader;
*messagecount = 1;
} }
return 0; return 0;
nomem: nomem:
kfree(msgHeader); kfree(msgheader);
kfree(msgBody); kfree(msgbody);
return -ENOMEM; return -ENOMEM;
} }
/* /*
* VmbusChannelEstablishGpadl - Estabish a GPADL for the specified buffer * VmbusChannelEstablishGpadl - Estabish a GPADL for the specified buffer
* *
* @Channel: a channel * @channel: a channel
* @Kbuffer: from kmalloc * @kbuffer: from kmalloc
* @Size: page-size multiple * @size: page-size multiple
* @GpadlHandle: some funky thing * @gpadl_handle: some funky thing
*/ */
int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel, void *Kbuffer, int VmbusChannelEstablishGpadl(struct vmbus_channel *channel, void *kbuffer,
u32 Size, u32 *GpadlHandle) u32 size, u32 *gpadl_handle)
{ {
struct vmbus_channel_gpadl_header *gpadlMsg; struct vmbus_channel_gpadl_header *gpadlmsg;
struct vmbus_channel_gpadl_body *gpadlBody; struct vmbus_channel_gpadl_body *gpadl_body;
/* struct vmbus_channel_gpadl_created *gpadlCreated; */ /* struct vmbus_channel_gpadl_created *gpadlCreated; */
struct vmbus_channel_msginfo *msgInfo = NULL; struct vmbus_channel_msginfo *msginfo = NULL;
struct vmbus_channel_msginfo *subMsgInfo; struct vmbus_channel_msginfo *submsginfo;
u32 msgCount; u32 msgcount;
struct list_head *curr; struct list_head *curr;
u32 nextGpadlHandle; u32 next_gpadl_handle;
unsigned long flags; unsigned long flags;
int ret = 0; int ret = 0;
nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle); next_gpadl_handle = atomic_read(&gVmbusConnection.NextGpadlHandle);
atomic_inc(&gVmbusConnection.NextGpadlHandle); atomic_inc(&gVmbusConnection.NextGpadlHandle);
ret = VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount); ret = VmbusChannelCreateGpadlHeader(kbuffer, size, &msginfo, &msgcount);
if (ret) if (ret)
return ret; return ret;
msgInfo->WaitEvent = osd_WaitEventCreate(); msginfo->WaitEvent = osd_WaitEventCreate();
if (!msgInfo->WaitEvent) { if (!msginfo->WaitEvent) {
ret = -ENOMEM; ret = -ENOMEM;
goto Cleanup; goto Cleanup;
} }
gpadlMsg = (struct vmbus_channel_gpadl_header *)msgInfo->Msg; gpadlmsg = (struct vmbus_channel_gpadl_header *)msginfo->Msg;
gpadlMsg->Header.MessageType = ChannelMessageGpadlHeader; gpadlmsg->Header.MessageType = ChannelMessageGpadlHeader;
gpadlMsg->ChildRelId = Channel->OfferMsg.ChildRelId; gpadlmsg->ChildRelId = channel->OfferMsg.ChildRelId;
gpadlMsg->Gpadl = nextGpadlHandle; gpadlmsg->Gpadl = next_gpadl_handle;
DumpGpadlHeader(gpadlMsg); DumpGpadlHeader(gpadlmsg);
spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
list_add_tail(&msgInfo->MsgListEntry, list_add_tail(&msginfo->MsgListEntry,
&gVmbusConnection.ChannelMsgList); &gVmbusConnection.ChannelMsgList);
spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
DPRINT_DBG(VMBUS, "buffer %p, size %d msg cnt %d", DPRINT_DBG(VMBUS, "buffer %p, size %d msg cnt %d",
Kbuffer, Size, msgCount); kbuffer, size, msgcount);
DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd", DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd",
msgInfo->MessageSize - sizeof(*msgInfo)); msginfo->MessageSize - sizeof(*msginfo));
ret = VmbusPostMessage(gpadlMsg, msgInfo->MessageSize - ret = VmbusPostMessage(gpadlmsg, msginfo->MessageSize -
sizeof(*msgInfo)); sizeof(*msginfo));
if (ret != 0) { 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) {
list_for_each(curr, &msgInfo->SubMsgList) { list_for_each(curr, &msginfo->SubMsgList) {
/* FIXME: should this use list_entry() instead ? */ /* FIXME: should this use list_entry() instead ? */
subMsgInfo = (struct vmbus_channel_msginfo *)curr; submsginfo = (struct vmbus_channel_msginfo *)curr;
gpadlBody = gpadl_body =
(struct vmbus_channel_gpadl_body *)subMsgInfo->Msg; (struct vmbus_channel_gpadl_body *)submsginfo->Msg;
gpadlBody->Header.MessageType = ChannelMessageGpadlBody; gpadl_body->Header.MessageType =
gpadlBody->Gpadl = nextGpadlHandle; ChannelMessageGpadlBody;
gpadl_body->Gpadl = next_gpadl_handle;
DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd", DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd",
subMsgInfo->MessageSize - submsginfo->MessageSize -
sizeof(*subMsgInfo)); sizeof(*submsginfo));
DumpGpadlBody(gpadlBody, subMsgInfo->MessageSize - DumpGpadlBody(gpadl_body, submsginfo->MessageSize -
sizeof(*subMsgInfo)); sizeof(*submsginfo));
ret = VmbusPostMessage(gpadlBody, ret = VmbusPostMessage(gpadl_body,
subMsgInfo->MessageSize - submsginfo->MessageSize -
sizeof(*subMsgInfo)); sizeof(*submsginfo));
if (ret != 0) if (ret != 0)
goto Cleanup; goto Cleanup;
} }
} }
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 " DPRINT_DBG(VMBUS, "Received GPADL created "
"(relid %d, status %d handle %x)", "(relid %d, status %d handle %x)",
Channel->OfferMsg.ChildRelId, channel->OfferMsg.ChildRelId,
msgInfo->Response.GpadlCreated.CreationStatus, msginfo->Response.GpadlCreated.CreationStatus,
gpadlMsg->Gpadl); gpadlmsg->Gpadl);
*GpadlHandle = gpadlMsg->Gpadl; *gpadl_handle = gpadlmsg->Gpadl;
Cleanup: Cleanup:
spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
list_del(&msgInfo->MsgListEntry); list_del(&msginfo->MsgListEntry);
spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
kfree(msgInfo->WaitEvent); kfree(msginfo->WaitEvent);
kfree(msgInfo); kfree(msginfo);
return ret; return ret;
} }
/* /*
* VmbusChannelTeardownGpadl -Teardown the specified GPADL handle * VmbusChannelTeardownGpadl -Teardown the specified GPADL handle
*/ */
int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle) int VmbusChannelTeardownGpadl(struct vmbus_channel *channel, u32 gpadl_handle)
{ {
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; int ret;
/* ASSERT(GpadlHandle != 0); */ /* ASSERT(gpadl_handle != 0); */
info = kmalloc(sizeof(*info) + info = kmalloc(sizeof(*info) +
sizeof(struct vmbus_channel_gpadl_teardown), GFP_KERNEL); sizeof(struct vmbus_channel_gpadl_teardown), GFP_KERNEL);
...@@ -608,8 +611,8 @@ int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle) ...@@ -608,8 +611,8 @@ 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 = gpadl_handle;
spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
list_add_tail(&info->MsgListEntry, list_add_tail(&info->MsgListEntry,
...@@ -638,7 +641,7 @@ int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle) ...@@ -638,7 +641,7 @@ int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle)
/* /*
* VmbusChannelClose - Close the specified channel * VmbusChannelClose - Close the specified channel
*/ */
void VmbusChannelClose(struct vmbus_channel *Channel) void VmbusChannelClose(struct vmbus_channel *channel)
{ {
struct vmbus_channel_close_channel *msg; struct vmbus_channel_close_channel *msg;
struct vmbus_channel_msginfo *info; struct vmbus_channel_msginfo *info;
...@@ -646,8 +649,8 @@ void VmbusChannelClose(struct vmbus_channel *Channel) ...@@ -646,8 +649,8 @@ void VmbusChannelClose(struct vmbus_channel *Channel)
int ret; int ret;
/* Stop callback and cancel the timer asap */ /* Stop callback and cancel the timer asap */
Channel->OnChannelCallback = NULL; channel->OnChannelCallback = NULL;
del_timer_sync(&Channel->poll_timer); del_timer_sync(&channel->poll_timer);
/* Send a closing message */ /* Send a closing message */
info = kmalloc(sizeof(*info) + info = kmalloc(sizeof(*info) +
...@@ -661,7 +664,7 @@ void VmbusChannelClose(struct vmbus_channel *Channel) ...@@ -661,7 +664,7 @@ void VmbusChannelClose(struct vmbus_channel *Channel)
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) {
...@@ -670,17 +673,17 @@ void VmbusChannelClose(struct vmbus_channel *Channel) ...@@ -670,17 +673,17 @@ void VmbusChannelClose(struct vmbus_channel *Channel)
} }
/* 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 */
/* Cleanup the ring buffers for this channel */ /* Cleanup the ring buffers for this channel */
RingBufferCleanup(&Channel->Outbound); RingBufferCleanup(&channel->Outbound);
RingBufferCleanup(&Channel->Inbound); RingBufferCleanup(&channel->Inbound);
osd_PageFree(Channel->RingBufferPages, Channel->RingBufferPageCount); osd_PageFree(channel->RingBufferPages, channel->RingBufferPageCount);
kfree(info); kfree(info);
...@@ -690,65 +693,66 @@ void VmbusChannelClose(struct vmbus_channel *Channel) ...@@ -690,65 +693,66 @@ void VmbusChannelClose(struct vmbus_channel *Channel)
* 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);
list_del(&Channel->ListEntry); list_del(&channel->ListEntry);
spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
FreeVmbusChannel(Channel); FreeVmbusChannel(channel);
} }
} }
/** /**
* VmbusChannelSendPacket() - Send the specified buffer on the given channel * VmbusChannelSendPacket() - Send the specified buffer on the given channel
* @Channel: Pointer to vmbus_channel structure. * @channel: Pointer to vmbus_channel structure.
* @Buffer: Pointer to the buffer you want to receive the data into. * @buffer: Pointer to the buffer you want to receive the data into.
* @BufferLen: Maximum size of what the the buffer will hold * @bufferlen: Maximum size of what the the buffer will hold
* @RequestId: Identifier of the request * @requestid: Identifier of the request
* @vmbus_packet_type: Type of packet that is being send e.g. negotiate, time * @type: Type of packet that is being send e.g. negotiate, time
* packet etc. * packet etc.
* *
* Sends data in @Buffer directly to hyper-v via the vmbus * Sends data in @buffer directly to hyper-v via the vmbus
* This will send the data unparsed to hyper-v. * This will send the data unparsed to hyper-v.
* *
* Mainly used by Hyper-V drivers. * Mainly used by Hyper-V drivers.
*/ */
int VmbusChannelSendPacket(struct vmbus_channel *Channel, const void *Buffer, int VmbusChannelSendPacket(struct vmbus_channel *channel, const void *buffer,
u32 BufferLen, u64 RequestId, u32 bufferlen, u64 requestid,
enum vmbus_packet_type Type, u32 Flags) enum vmbus_packet_type type, u32 flags)
{ {
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 packetlen_aligned = ALIGN_UP(packetlen, sizeof(u64));
struct scatterlist bufferList[3]; struct scatterlist bufferlist[3];
u64 alignedData = 0; u64 aligned_data = 0;
int ret; int ret;
DPRINT_DBG(VMBUS, "channel %p buffer %p len %d", DPRINT_DBG(VMBUS, "channel %p buffer %p len %d",
Channel, Buffer, BufferLen); channel, buffer, bufferlen);
DumpVmbusChannel(Channel); DumpVmbusChannel(channel);
/* ASSERT((packetLenAligned - packetLen) < sizeof(u64)); */ /* ASSERT((packetLenAligned - packetLen) < sizeof(u64)); */
/* 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; */
/* in 8-bytes granularity */ /* in 8-bytes granularity */
desc.DataOffset8 = sizeof(struct vmpacket_descriptor) >> 3; desc.DataOffset8 = sizeof(struct vmpacket_descriptor) >> 3;
desc.Length8 = (u16)(packetLenAligned >> 3); desc.Length8 = (u16)(packetlen_aligned >> 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], &aligned_data,
packetlen_aligned - packetlen);
ret = RingBufferWrite(&Channel->Outbound, bufferList, 3); ret = RingBufferWrite(&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);
return ret; return ret;
} }
...@@ -758,61 +762,62 @@ EXPORT_SYMBOL(VmbusChannelSendPacket); ...@@ -758,61 +762,62 @@ EXPORT_SYMBOL(VmbusChannelSendPacket);
* VmbusChannelSendPacketPageBuffer - Send a range of single-page buffer * VmbusChannelSendPacketPageBuffer - Send a range of single-page buffer
* packets using a GPADL Direct packet type. * 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, void *Buffer, u32 BufferLen, u32 pagecount, void *buffer, u32 bufferlen,
u64 RequestId) u64 requestid)
{ {
int ret; int ret;
int i; 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 packetlen_aligned;
struct scatterlist bufferList[3]; struct scatterlist bufferlist[3];
u64 alignedData = 0; u64 aligned_data = 0;
if (PageCount > MAX_PAGE_BUFFER_COUNT) if (pagecount > MAX_PAGE_BUFFER_COUNT)
return -EINVAL; return -EINVAL;
DumpVmbusChannel(Channel); DumpVmbusChannel(channel);
/* /*
* Adjust the size down since vmbus_channel_packet_page_buffer is the * Adjust the size down since vmbus_channel_packet_page_buffer is the
* largest size we support * largest size we support
*/ */
descSize = sizeof(struct vmbus_channel_packet_page_buffer) - descsize = sizeof(struct vmbus_channel_packet_page_buffer) -
((MAX_PAGE_BUFFER_COUNT - PageCount) * ((MAX_PAGE_BUFFER_COUNT - pagecount) *
sizeof(struct hv_page_buffer)); sizeof(struct hv_page_buffer));
packetLen = descSize + BufferLen; packetlen = descsize + bufferlen;
packetLenAligned = ALIGN_UP(packetLen, sizeof(u64)); packetlen_aligned = ALIGN_UP(packetlen, sizeof(u64));
/* ASSERT((packetLenAligned - packetLen) < sizeof(u64)); */ /* ASSERT((packetLenAligned - packetLen) < sizeof(u64)); */
/* Setup the descriptor */ /* Setup the descriptor */
desc.type = VmbusPacketTypeDataUsingGpaDirect; desc.type = VmbusPacketTypeDataUsingGpaDirect;
desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
desc.dataoffset8 = descSize >> 3; /* in 8-bytes grandularity */ desc.dataoffset8 = descsize >> 3; /* in 8-bytes grandularity */
desc.length8 = (u16)(packetLenAligned >> 3); desc.length8 = (u16)(packetlen_aligned >> 3);
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], &aligned_data,
packetlen_aligned - packetlen);
ret = RingBufferWrite(&Channel->Outbound, bufferList, 3); ret = RingBufferWrite(&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);
return ret; return ret;
} }
...@@ -821,64 +826,66 @@ int VmbusChannelSendPacketPageBuffer(struct vmbus_channel *Channel, ...@@ -821,64 +826,66 @@ int VmbusChannelSendPacketPageBuffer(struct vmbus_channel *Channel,
* VmbusChannelSendPacketMultiPageBuffer - Send a multi-page buffer packet * VmbusChannelSendPacketMultiPageBuffer - Send a multi-page buffer packet
* using a GPADL Direct packet type. * 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 *multi_pagebuffer,
void *Buffer, u32 BufferLen, u64 RequestId) void *buffer, u32 bufferlen, u64 requestid)
{ {
int ret; int ret;
struct vmbus_channel_packet_multipage_buffer desc; struct vmbus_channel_packet_multipage_buffer desc;
u32 descSize; u32 descsize;
u32 packetLen; u32 packetlen;
u32 packetLenAligned; u32 packetlen_aligned;
struct scatterlist bufferList[3]; struct scatterlist bufferlist[3];
u64 alignedData = 0; u64 aligned_data = 0;
u32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset, u32 pfncount = NUM_PAGES_SPANNED(multi_pagebuffer->Offset,
MultiPageBuffer->Length); multi_pagebuffer->Length);
DumpVmbusChannel(Channel); DumpVmbusChannel(channel);
DPRINT_DBG(VMBUS, "data buffer - offset %u len %u pfn count %u", DPRINT_DBG(VMBUS, "data buffer - offset %u len %u pfn count %u",
MultiPageBuffer->Offset, MultiPageBuffer->Length, PfnCount); multi_pagebuffer->Offset,
multi_pagebuffer->Length, pfncount);
if ((PfnCount < 0) || (PfnCount > MAX_MULTIPAGE_BUFFER_COUNT)) if ((pfncount < 0) || (pfncount > MAX_MULTIPAGE_BUFFER_COUNT))
return -EINVAL; return -EINVAL;
/* /*
* Adjust the size down since vmbus_channel_packet_multipage_buffer is * Adjust the size down since vmbus_channel_packet_multipage_buffer is
* the largest size we support * the largest size we support
*/ */
descSize = sizeof(struct vmbus_channel_packet_multipage_buffer) - descsize = sizeof(struct vmbus_channel_packet_multipage_buffer) -
((MAX_MULTIPAGE_BUFFER_COUNT - PfnCount) * ((MAX_MULTIPAGE_BUFFER_COUNT - pfncount) *
sizeof(u64)); sizeof(u64));
packetLen = descSize + BufferLen; packetlen = descsize + bufferlen;
packetLenAligned = ALIGN_UP(packetLen, sizeof(u64)); packetlen_aligned = ALIGN_UP(packetlen, sizeof(u64));
/* ASSERT((packetLenAligned - packetLen) < sizeof(u64)); */ /* ASSERT((packetLenAligned - packetLen) < sizeof(u64)); */
/* Setup the descriptor */ /* Setup the descriptor */
desc.type = VmbusPacketTypeDataUsingGpaDirect; desc.type = VmbusPacketTypeDataUsingGpaDirect;
desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
desc.dataoffset8 = descSize >> 3; /* in 8-bytes grandularity */ desc.dataoffset8 = descsize >> 3; /* in 8-bytes grandularity */
desc.length8 = (u16)(packetLenAligned >> 3); desc.length8 = (u16)(packetlen_aligned >> 3);
desc.transactionid = RequestId; desc.transactionid = requestid;
desc.rangecount = 1; desc.rangecount = 1;
desc.range.Length = MultiPageBuffer->Length; desc.range.Length = multi_pagebuffer->Length;
desc.range.Offset = MultiPageBuffer->Offset; desc.range.Offset = multi_pagebuffer->Offset;
memcpy(desc.range.PfnArray, MultiPageBuffer->PfnArray, memcpy(desc.range.PfnArray, multi_pagebuffer->PfnArray,
PfnCount * sizeof(u64)); 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], &aligned_data,
packetlen_aligned - packetlen);
ret = RingBufferWrite(&Channel->Outbound, bufferList, 3); ret = RingBufferWrite(&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);
return ret; return ret;
} }
...@@ -886,35 +893,35 @@ int VmbusChannelSendPacketMultiPageBuffer(struct vmbus_channel *Channel, ...@@ -886,35 +893,35 @@ int VmbusChannelSendPacketMultiPageBuffer(struct vmbus_channel *Channel,
/** /**
* VmbusChannelRecvPacket() - Retrieve the user packet on the specified channel * VmbusChannelRecvPacket() - Retrieve the user packet on the specified channel
* @Channel: Pointer to vmbus_channel structure. * @channel: Pointer to vmbus_channel structure.
* @Buffer: Pointer to the buffer you want to receive the data into. * @buffer: Pointer to the buffer you want to receive the data into.
* @BufferLen: Maximum size of what the the buffer will hold * @bufferlen: Maximum size of what the the buffer will hold
* @BufferActualLen: The actual size of the data after it was received * @buffer_actual_len: The actual size of the data after it was received
* @RequestId: Identifier of the request * @requestid: Identifier of the request
* *
* Receives directly from the hyper-v vmbus and puts the data it received * Receives directly from the hyper-v vmbus and puts the data it received
* into Buffer. This will receive the data unparsed from hyper-v. * into Buffer. This will receive the data unparsed from hyper-v.
* *
* Mainly used by Hyper-V drivers. * Mainly used by Hyper-V drivers.
*/ */
int VmbusChannelRecvPacket(struct vmbus_channel *Channel, void *Buffer, int VmbusChannelRecvPacket(struct vmbus_channel *channel, void *buffer,
u32 BufferLen, u32 *BufferActualLen, u64 *RequestId) u32 bufferlen, u32 *buffer_actual_len, u64 *requestid)
{ {
struct vmpacket_descriptor desc; struct vmpacket_descriptor desc;
u32 packetLen; u32 packetlen;
u32 userLen; u32 userlen;
int ret; int ret;
unsigned long flags; unsigned long flags;
*BufferActualLen = 0; *buffer_actual_len = 0;
*RequestId = 0; *requestid = 0;
spin_lock_irqsave(&Channel->inbound_lock, flags); spin_lock_irqsave(&channel->inbound_lock, flags);
ret = RingBufferPeek(&Channel->Inbound, &desc, ret = RingBufferPeek(&channel->Inbound, &desc,
sizeof(struct vmpacket_descriptor)); sizeof(struct vmpacket_descriptor));
if (ret != 0) { 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!!"); */
return 0; return 0;
...@@ -922,32 +929,32 @@ int VmbusChannelRecvPacket(struct vmbus_channel *Channel, void *Buffer, ...@@ -922,32 +929,32 @@ int VmbusChannelRecvPacket(struct vmbus_channel *Channel, void *Buffer,
/* VmbusChannelClearEvent(Channel); */ /* VmbusChannelClearEvent(Channel); */
packetLen = desc.Length8 << 3; packetlen = desc.Length8 << 3;
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 " DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d "
"flag %d tid %llx pktlen %d datalen %d> ", "flag %d tid %llx pktlen %d datalen %d> ",
Channel, Channel->OfferMsg.ChildRelId, desc.Type, channel, channel->OfferMsg.ChildRelId, desc.Type,
desc.Flags, desc.TransactionId, packetLen, userLen); desc.Flags, desc.TransactionId, packetlen, userlen);
*BufferActualLen = userLen; *buffer_actual_len = 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", DPRINT_ERR(VMBUS, "buffer too small - got %d needs %d",
BufferLen, userLen); bufferlen, userlen);
return -1; return -1;
} }
*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, ret = RingBufferRead(&channel->Inbound, buffer, userlen,
(desc.DataOffset8 << 3)); (desc.DataOffset8 << 3));
spin_unlock_irqrestore(&Channel->inbound_lock, flags); spin_unlock_irqrestore(&channel->inbound_lock, flags);
return 0; return 0;
} }
...@@ -956,25 +963,25 @@ EXPORT_SYMBOL(VmbusChannelRecvPacket); ...@@ -956,25 +963,25 @@ EXPORT_SYMBOL(VmbusChannelRecvPacket);
/* /*
* VmbusChannelRecvPacketRaw - Retrieve the raw packet on the specified channel * VmbusChannelRecvPacketRaw - Retrieve the raw packet on the specified channel
*/ */
int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel, void *Buffer, int VmbusChannelRecvPacketRaw(struct vmbus_channel *channel, void *buffer,
u32 BufferLen, u32 *BufferActualLen, u32 bufferlen, u32 *buffer_actual_len,
u64 *RequestId) u64 *requestid)
{ {
struct vmpacket_descriptor desc; struct vmpacket_descriptor desc;
u32 packetLen; u32 packetlen;
u32 userLen; u32 userlen;
int ret; int ret;
unsigned long flags; unsigned long flags;
*BufferActualLen = 0; *buffer_actual_len = 0;
*RequestId = 0; *requestid = 0;
spin_lock_irqsave(&Channel->inbound_lock, flags); spin_lock_irqsave(&channel->inbound_lock, flags);
ret = RingBufferPeek(&Channel->Inbound, &desc, ret = RingBufferPeek(&channel->Inbound, &desc,
sizeof(struct vmpacket_descriptor)); sizeof(struct vmpacket_descriptor));
if (ret != 0) { 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!!"); */
return 0; return 0;
...@@ -982,44 +989,44 @@ int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel, void *Buffer, ...@@ -982,44 +989,44 @@ int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel, void *Buffer,
/* VmbusChannelClearEvent(Channel); */ /* VmbusChannelClearEvent(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 " DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d "
"flag %d tid %llx pktlen %d datalen %d> ", "flag %d tid %llx pktlen %d datalen %d> ",
Channel, Channel->OfferMsg.ChildRelId, desc.Type, channel, channel->OfferMsg.ChildRelId, desc.Type,
desc.Flags, desc.TransactionId, packetLen, userLen); desc.Flags, desc.TransactionId, packetlen, userlen);
*BufferActualLen = packetLen; *buffer_actual_len = 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 " DPRINT_ERR(VMBUS, "buffer too small - needed %d bytes but "
"got space for only %d bytes", packetLen, BufferLen); "got space for only %d bytes", packetlen, bufferlen);
return -2; return -2;
} }
*RequestId = desc.TransactionId; *requestid = desc.TransactionId;
/* Copy over the entire packet to the user buffer */ /* Copy over the entire packet to the user buffer */
ret = RingBufferRead(&Channel->Inbound, Buffer, packetLen, 0); ret = RingBufferRead(&channel->Inbound, buffer, packetlen, 0);
spin_unlock_irqrestore(&Channel->inbound_lock, flags); spin_unlock_irqrestore(&channel->inbound_lock, flags);
return 0; return 0;
} }
/* /*
* VmbusChannelOnChannelEvent - Channel event callback * VmbusChannelOnChannelEvent - Channel event callback
*/ */
void VmbusChannelOnChannelEvent(struct vmbus_channel *Channel) void VmbusChannelOnChannelEvent(struct vmbus_channel *channel)
{ {
DumpVmbusChannel(Channel); DumpVmbusChannel(channel);
/* ASSERT(Channel->OnChannelCallback); */ /* ASSERT(Channel->OnChannelCallback); */
Channel->OnChannelCallback(Channel->ChannelCallbackContext); channel->OnChannelCallback(channel->ChannelCallbackContext);
mod_timer(&Channel->poll_timer, jiffies + usecs_to_jiffies(100)); mod_timer(&channel->poll_timer, jiffies + usecs_to_jiffies(100));
} }
/* /*
...@@ -1036,9 +1043,9 @@ void VmbusChannelOnTimer(unsigned long data) ...@@ -1036,9 +1043,9 @@ void VmbusChannelOnTimer(unsigned long data)
/* /*
* DumpVmbusChannel - Dump vmbus channel info to the console * DumpVmbusChannel - 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 ");
} }
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