2009-07-14 01:02:34 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009, Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
|
|
* Place - Suite 330, Boston, MA 02111-1307 USA.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Haiyang Zhang <haiyangz@microsoft.com>
|
|
|
|
* Hank Janssen <hjanssen@microsoft.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-07-15 00:08:20 +02:00
|
|
|
#include <linux/kernel.h>
|
2009-08-18 02:22:08 +02:00
|
|
|
#include <linux/mm.h>
|
2009-08-20 01:14:47 +02:00
|
|
|
#include "osd.h"
|
2009-08-29 01:22:59 +02:00
|
|
|
#include "logging.h"
|
2009-07-14 01:02:34 +02:00
|
|
|
#include "VmbusPrivate.h"
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Internal routines */
|
2009-08-19 00:21:19 +02:00
|
|
|
static int VmbusChannelCreateGpadlHeader(
|
2009-07-27 22:47:24 +02:00
|
|
|
void * Kbuffer, /* must be phys and virt contiguous */
|
|
|
|
u32 Size, /* page-size multiple */
|
2009-08-19 00:21:19 +02:00
|
|
|
struct vmbus_channel_msginfo **msgInfo,
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 *MessageCount
|
2009-07-14 01:02:34 +02:00
|
|
|
);
|
2009-08-19 00:21:19 +02:00
|
|
|
static void DumpVmbusChannel(struct vmbus_channel *channel);
|
|
|
|
static void VmbusChannelSetEvent(struct vmbus_channel *channel);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static void
|
|
|
|
DumpMonitorPage(
|
2009-08-20 21:11:26 +02:00
|
|
|
struct hv_monitor_page *MonitorPage
|
2009-07-14 01:02:34 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int i=0;
|
|
|
|
int j=0;
|
|
|
|
|
|
|
|
DPRINT_DBG(VMBUS, "monitorPage - %p, trigger state - %d", MonitorPage, MonitorPage->TriggerState);
|
|
|
|
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
|
|
|
DPRINT_DBG(VMBUS, "trigger group (%d) - %llx", i, MonitorPage->TriggerGroup[i].AsUINT64);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
|
|
|
for (j=0; j<32; j++)
|
|
|
|
{
|
|
|
|
DPRINT_DBG(VMBUS, "latency (%d)(%d) - %llx", i, j, MonitorPage->Latency[i][j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
|
|
|
for (j=0; j<32; j++)
|
|
|
|
{
|
2009-07-15 00:09:36 +02:00
|
|
|
DPRINT_DBG(VMBUS, "param-conn id (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].ConnectionId.Asu32);
|
2009-07-14 01:02:34 +02:00
|
|
|
DPRINT_DBG(VMBUS, "param-flag (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].FlagNumber);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelSetEvent()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Trigger an event notification on the specified channel.
|
|
|
|
|
|
|
|
--*/
|
2009-08-19 00:21:19 +02:00
|
|
|
static void VmbusChannelSetEvent(struct vmbus_channel *Channel)
|
2009-07-14 01:02:34 +02:00
|
|
|
{
|
2009-08-20 21:11:26 +02:00
|
|
|
struct hv_monitor_page *monitorPage;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_ENTER(VMBUS);
|
|
|
|
|
|
|
|
if (Channel->OfferMsg.MonitorAllocated)
|
|
|
|
{
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Each u32 represents 32 channels */
|
2009-07-29 23:00:11 +02:00
|
|
|
set_bit(Channel->OfferMsg.ChildRelId & 31,
|
|
|
|
(unsigned long *) gVmbusConnection.SendInterruptPage +
|
|
|
|
(Channel->OfferMsg.ChildRelId >> 5) );
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-08-20 21:11:26 +02:00
|
|
|
monitorPage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages;
|
2009-07-27 22:47:24 +02:00
|
|
|
monitorPage++; /* Get the child to parent monitor page */
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-29 23:00:11 +02:00
|
|
|
set_bit(Channel->MonitorBit,
|
|
|
|
(unsigned long *) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending);
|
|
|
|
|
2009-07-14 01:02:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VmbusSetEvent(Channel->OfferMsg.ChildRelId);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2009-08-19 00:21:19 +02:00
|
|
|
static void VmbusChannelClearEvent(struct vmbus_channel *channel)
|
2009-07-14 01:02:34 +02:00
|
|
|
{
|
2009-08-20 21:11:26 +02:00
|
|
|
struct hv_monitor_page *monitorPage;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_ENTER(VMBUS);
|
|
|
|
|
|
|
|
if (Channel->OfferMsg.MonitorAllocated)
|
|
|
|
{
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Each u32 represents 32 channels */
|
2009-07-29 23:00:11 +02:00
|
|
|
clear_bit(Channel->OfferMsg.ChildRelId & 31,
|
|
|
|
(unsigned long *) gVmbusConnection.SendInterruptPage + (Channel->OfferMsg.ChildRelId >> 5));
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-08-20 21:11:26 +02:00
|
|
|
monitorPage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages;
|
2009-07-27 22:47:24 +02:00
|
|
|
monitorPage++; /* Get the child to parent monitor page */
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-29 23:00:11 +02:00
|
|
|
clear_bit(Channel->MonitorBit,
|
|
|
|
(unsigned long *) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending);
|
2009-07-14 01:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
/*++;
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelGetDebugInfo()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Retrieve various channel debug info
|
|
|
|
|
|
|
|
--*/
|
2009-08-19 00:21:19 +02:00
|
|
|
void VmbusChannelGetDebugInfo(struct vmbus_channel *Channel,
|
|
|
|
struct vmbus_channel_debug_info *DebugInfo)
|
2009-07-14 01:02:34 +02:00
|
|
|
{
|
2009-08-20 21:11:26 +02:00
|
|
|
struct hv_monitor_page *monitorPage;
|
2009-07-15 00:08:20 +02:00
|
|
|
u8 monitorGroup = (u8)Channel->OfferMsg.MonitorId / 32;
|
|
|
|
u8 monitorOffset = (u8)Channel->OfferMsg.MonitorId % 32;
|
2009-07-27 22:47:24 +02:00
|
|
|
/* u32 monitorBit = 1 << monitorOffset; */
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DebugInfo->RelId = Channel->OfferMsg.ChildRelId;
|
|
|
|
DebugInfo->State = Channel->State;
|
2009-08-20 01:17:03 +02:00
|
|
|
memcpy(&DebugInfo->InterfaceType, &Channel->OfferMsg.Offer.InterfaceType, sizeof(struct hv_guid));
|
|
|
|
memcpy(&DebugInfo->InterfaceInstance, &Channel->OfferMsg.Offer.InterfaceInstance, sizeof(struct hv_guid));
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-08-20 21:11:26 +02:00
|
|
|
monitorPage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DebugInfo->MonitorId = Channel->OfferMsg.MonitorId;
|
|
|
|
|
|
|
|
DebugInfo->ServerMonitorPending = monitorPage->TriggerGroup[monitorGroup].Pending;
|
|
|
|
DebugInfo->ServerMonitorLatency = monitorPage->Latency[monitorGroup][ monitorOffset];
|
|
|
|
DebugInfo->ServerMonitorConnectionId = monitorPage->Parameter[monitorGroup][ monitorOffset].ConnectionId.u.Id;
|
|
|
|
|
|
|
|
monitorPage++;
|
|
|
|
|
|
|
|
DebugInfo->ClientMonitorPending = monitorPage->TriggerGroup[monitorGroup].Pending;
|
|
|
|
DebugInfo->ClientMonitorLatency = monitorPage->Latency[monitorGroup][ monitorOffset];
|
|
|
|
DebugInfo->ClientMonitorConnectionId = monitorPage->Parameter[monitorGroup][ monitorOffset].ConnectionId.u.Id;
|
|
|
|
|
|
|
|
RingBufferGetDebugInfo(&Channel->Inbound, &DebugInfo->Inbound);
|
|
|
|
RingBufferGetDebugInfo(&Channel->Outbound, &DebugInfo->Outbound);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*++;
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelOpen()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Open the specified channel.
|
|
|
|
|
|
|
|
--*/
|
2009-08-19 00:21:19 +02:00
|
|
|
int VmbusChannelOpen(struct vmbus_channel *NewChannel,
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 SendRingBufferSize,
|
|
|
|
u32 RecvRingBufferSize,
|
2009-07-15 00:06:28 +02:00
|
|
|
void * UserData,
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 UserDataLen,
|
2009-07-14 01:02:34 +02:00
|
|
|
PFN_CHANNEL_CALLBACK pfnOnChannelCallback,
|
2009-07-15 00:06:28 +02:00
|
|
|
void * Context
|
2009-07-14 01:02:34 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int ret=0;
|
2009-08-27 00:16:04 +02:00
|
|
|
struct vmbus_channel_open_channel *openMsg;
|
2009-08-19 00:21:19 +02:00
|
|
|
struct vmbus_channel_msginfo *openInfo;
|
2009-07-14 01:02:34 +02:00
|
|
|
void *in, *out;
|
2009-07-15 23:56:45 +02:00
|
|
|
unsigned long flags;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_ENTER(VMBUS);
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Aligned to page size */
|
2009-07-14 01:02:34 +02:00
|
|
|
ASSERT(!(SendRingBufferSize & (PAGE_SIZE -1)));
|
|
|
|
ASSERT(!(RecvRingBufferSize & (PAGE_SIZE -1)));
|
|
|
|
|
|
|
|
NewChannel->OnChannelCallback = pfnOnChannelCallback;
|
|
|
|
NewChannel->ChannelCallbackContext = Context;
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Allocate the ring buffer */
|
2009-07-30 00:40:18 +02:00
|
|
|
out = osd_PageAlloc((SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT);
|
2009-07-27 22:47:24 +02:00
|
|
|
/* out = kzalloc(sendRingBufferSize + recvRingBufferSize, GFP_KERNEL); */
|
2009-07-14 01:02:34 +02:00
|
|
|
ASSERT(out);
|
2009-07-15 00:12:46 +02:00
|
|
|
ASSERT(((unsigned long)out & (PAGE_SIZE-1)) == 0);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-15 00:12:46 +02:00
|
|
|
in = (void*)((unsigned long)out + SendRingBufferSize);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
NewChannel->RingBufferPages = out;
|
|
|
|
NewChannel->RingBufferPageCount = (SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT;
|
|
|
|
|
|
|
|
RingBufferInit(&NewChannel->Outbound, out, SendRingBufferSize);
|
|
|
|
|
|
|
|
RingBufferInit(&NewChannel->Inbound, in, RecvRingBufferSize);
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Establish the gpadl for the ring buffer */
|
2009-07-14 01:02:34 +02:00
|
|
|
DPRINT_DBG(VMBUS, "Establishing ring buffer's gpadl for channel %p...", NewChannel);
|
|
|
|
|
|
|
|
NewChannel->RingBufferGpadlHandle = 0;
|
|
|
|
|
|
|
|
ret = VmbusChannelEstablishGpadl(NewChannel,
|
|
|
|
NewChannel->Outbound.RingBuffer,
|
|
|
|
SendRingBufferSize + RecvRingBufferSize,
|
|
|
|
&NewChannel->RingBufferGpadlHandle);
|
|
|
|
|
|
|
|
DPRINT_DBG(VMBUS, "channel %p <relid %d gpadl 0x%x send ring %p size %d recv ring %p size %d, downstreamoffset %d>",
|
|
|
|
NewChannel,
|
|
|
|
NewChannel->OfferMsg.ChildRelId,
|
|
|
|
NewChannel->RingBufferGpadlHandle,
|
|
|
|
NewChannel->Outbound.RingBuffer,
|
|
|
|
NewChannel->Outbound.RingSize,
|
|
|
|
NewChannel->Inbound.RingBuffer,
|
|
|
|
NewChannel->Inbound.RingSize,
|
|
|
|
SendRingBufferSize);
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Create and init the channel open message */
|
2009-08-27 00:16:04 +02:00
|
|
|
openInfo = kmalloc(sizeof(*openInfo) + sizeof(struct vmbus_channel_open_channel), GFP_KERNEL);
|
2009-07-14 01:02:34 +02:00
|
|
|
ASSERT(openInfo != NULL);
|
|
|
|
|
2009-07-30 00:40:18 +02:00
|
|
|
openInfo->WaitEvent = osd_WaitEventCreate();
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-08-27 00:16:04 +02:00
|
|
|
openMsg = (struct vmbus_channel_open_channel *)openInfo->Msg;
|
2009-07-14 01:02:34 +02:00
|
|
|
openMsg->Header.MessageType = ChannelMessageOpenChannel;
|
2009-07-27 22:47:24 +02:00
|
|
|
openMsg->OpenId = NewChannel->OfferMsg.ChildRelId; /* FIXME */
|
2009-07-14 01:02:34 +02:00
|
|
|
openMsg->ChildRelId = NewChannel->OfferMsg.ChildRelId;
|
|
|
|
openMsg->RingBufferGpadlHandle = NewChannel->RingBufferGpadlHandle;
|
|
|
|
ASSERT(openMsg->RingBufferGpadlHandle);
|
|
|
|
openMsg->DownstreamRingBufferPageOffset = SendRingBufferSize >> PAGE_SHIFT;
|
2009-07-27 22:47:24 +02:00
|
|
|
openMsg->ServerContextAreaGpadlHandle = 0; /* TODO */
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
ASSERT(UserDataLen <= MAX_USER_DEFINED_BYTES);
|
|
|
|
if (UserDataLen)
|
|
|
|
{
|
|
|
|
memcpy(openMsg->UserData, UserData, UserDataLen);
|
|
|
|
}
|
|
|
|
|
2009-07-15 23:56:45 +02:00
|
|
|
spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &openInfo->MsgListEntry);
|
2009-07-15 23:56:45 +02:00
|
|
|
spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_DBG(VMBUS, "Sending channel open msg...");
|
|
|
|
|
2009-08-27 00:16:04 +02:00
|
|
|
ret = VmbusPostMessage(openMsg, sizeof(struct vmbus_channel_open_channel));
|
2009-07-14 01:02:34 +02:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
DPRINT_ERR(VMBUS, "unable to open channel - %d", ret);
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* FIXME: Need to time-out here */
|
2009-07-30 00:40:18 +02:00
|
|
|
osd_WaitEventWait(openInfo->WaitEvent);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
if (openInfo->Response.OpenResult.Status == 0)
|
|
|
|
{
|
|
|
|
DPRINT_INFO(VMBUS, "channel <%p> open success!!", NewChannel);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DPRINT_INFO(VMBUS, "channel <%p> open failed - %d!!", NewChannel, openInfo->Response.OpenResult.Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
Cleanup:
|
2009-07-15 23:56:45 +02:00
|
|
|
spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
REMOVE_ENTRY_LIST(&openInfo->MsgListEntry);
|
2009-07-15 23:56:45 +02:00
|
|
|
spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-29 23:00:10 +02:00
|
|
|
kfree(openInfo->WaitEvent);
|
2009-07-15 21:48:29 +02:00
|
|
|
kfree(openInfo);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++;
|
|
|
|
|
|
|
|
Name:
|
|
|
|
DumpGpadlBody()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Dump the gpadl body message to the console for debugging purposes.
|
|
|
|
|
|
|
|
--*/
|
2009-08-27 00:16:04 +02:00
|
|
|
static void DumpGpadlBody(struct vmbus_channel_gpadl_body *Gpadl, u32 Len)
|
2009-07-14 01:02:34 +02:00
|
|
|
{
|
|
|
|
int i=0;
|
|
|
|
int pfnCount=0;
|
|
|
|
|
2009-08-27 00:16:04 +02:00
|
|
|
pfnCount = (Len - sizeof(struct vmbus_channel_gpadl_body))/ sizeof(u64);
|
2009-07-14 01:02:34 +02:00
|
|
|
DPRINT_DBG(VMBUS, "gpadl body - len %d pfn count %d", Len, pfnCount);
|
|
|
|
|
|
|
|
for (i=0; i< pfnCount; i++)
|
|
|
|
{
|
|
|
|
DPRINT_DBG(VMBUS, "gpadl body - %d) pfn %llu", i, Gpadl->Pfn[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*++;
|
|
|
|
|
|
|
|
Name:
|
|
|
|
DumpGpadlHeader()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Dump the gpadl header message to the console for debugging purposes.
|
|
|
|
|
|
|
|
--*/
|
2009-08-27 00:16:04 +02:00
|
|
|
static void DumpGpadlHeader(struct vmbus_channel_gpadl_header *Gpadl)
|
2009-07-14 01:02:34 +02:00
|
|
|
{
|
|
|
|
int i=0,j=0;
|
|
|
|
int pageCount=0;
|
|
|
|
|
|
|
|
|
|
|
|
DPRINT_DBG(VMBUS, "gpadl header - relid %d, range count %d, range buflen %d",
|
|
|
|
Gpadl->ChildRelId,
|
|
|
|
Gpadl->RangeCount,
|
|
|
|
Gpadl->RangeBufLen);
|
|
|
|
for (i=0; i< Gpadl->RangeCount; i++)
|
|
|
|
{
|
|
|
|
pageCount = Gpadl->Range[i].ByteCount >> PAGE_SHIFT;
|
|
|
|
pageCount = (pageCount > 26)? 26 : pageCount;
|
|
|
|
|
|
|
|
DPRINT_DBG(VMBUS, "gpadl range %d - len %d offset %d page count %d",
|
|
|
|
i, Gpadl->Range[i].ByteCount, Gpadl->Range[i].ByteOffset, pageCount);
|
|
|
|
|
|
|
|
for (j=0; j< pageCount; j++)
|
|
|
|
{
|
|
|
|
DPRINT_DBG(VMBUS, "%d) pfn %llu", j, Gpadl->Range[i].PfnArray[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++;
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelCreateGpadlHeader()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Creates a gpadl for the specified buffer
|
|
|
|
|
|
|
|
--*/
|
|
|
|
static int
|
|
|
|
VmbusChannelCreateGpadlHeader(
|
2009-07-27 22:47:24 +02:00
|
|
|
void * Kbuffer, /* from kmalloc() */
|
|
|
|
u32 Size, /* page-size multiple */
|
2009-08-19 00:21:19 +02:00
|
|
|
struct vmbus_channel_msginfo **MsgInfo,
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 *MessageCount)
|
2009-07-14 01:02:34 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int pageCount;
|
|
|
|
unsigned long long pfn;
|
2009-08-27 00:16:04 +02:00
|
|
|
struct vmbus_channel_gpadl_header *gpaHeader;
|
|
|
|
struct vmbus_channel_gpadl_body *gpadlBody;
|
2009-08-19 00:21:19 +02:00
|
|
|
struct vmbus_channel_msginfo *msgHeader;
|
|
|
|
struct vmbus_channel_msginfo *msgBody;
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 msgSize;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
int pfnSum, pfnCount, pfnLeft, pfnCurr, pfnSize;
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* ASSERT( (kbuffer & (PAGE_SIZE-1)) == 0); */
|
2009-07-14 01:02:34 +02:00
|
|
|
ASSERT( (Size & (PAGE_SIZE-1)) == 0);
|
|
|
|
|
|
|
|
pageCount = Size >> PAGE_SHIFT;
|
2009-07-30 00:39:27 +02:00
|
|
|
pfn = virt_to_phys(Kbuffer) >> PAGE_SHIFT;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* do we need a gpadl body msg */
|
2009-08-28 01:02:36 +02:00
|
|
|
pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(struct vmbus_channel_gpadl_header) - sizeof(struct gpa_range);
|
2009-07-15 00:10:26 +02:00
|
|
|
pfnCount = pfnSize / sizeof(u64);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
if (pageCount > pfnCount) /* we need a gpadl body */
|
2009-07-14 01:02:34 +02:00
|
|
|
{
|
2009-07-27 22:47:24 +02:00
|
|
|
/* fill in the header */
|
2009-08-28 01:02:36 +02:00
|
|
|
msgSize = sizeof(struct vmbus_channel_msginfo) + sizeof(struct vmbus_channel_gpadl_header) + sizeof(struct gpa_range) + pfnCount*sizeof(u64);
|
2009-07-15 21:47:43 +02:00
|
|
|
msgHeader = kzalloc(msgSize, GFP_KERNEL);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
INITIALIZE_LIST_HEAD(&msgHeader->SubMsgList);
|
|
|
|
msgHeader->MessageSize=msgSize;
|
|
|
|
|
2009-08-27 00:16:04 +02:00
|
|
|
gpaHeader = (struct vmbus_channel_gpadl_header *)msgHeader->Msg;
|
2009-07-14 01:02:34 +02:00
|
|
|
gpaHeader->RangeCount = 1;
|
2009-08-28 01:02:36 +02:00
|
|
|
gpaHeader->RangeBufLen = sizeof(struct gpa_range) + pageCount*sizeof(u64);
|
2009-07-14 01:02:34 +02:00
|
|
|
gpaHeader->Range[0].ByteOffset = 0;
|
|
|
|
gpaHeader->Range[0].ByteCount = Size;
|
|
|
|
for (i=0; i<pfnCount; i++)
|
|
|
|
{
|
|
|
|
gpaHeader->Range[0].PfnArray[i] = pfn+i;
|
|
|
|
}
|
|
|
|
*MsgInfo = msgHeader;
|
|
|
|
*MessageCount = 1;
|
|
|
|
|
|
|
|
pfnSum = pfnCount;
|
|
|
|
pfnLeft = pageCount - pfnCount;
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* how many pfns can we fit */
|
2009-08-27 00:16:04 +02:00
|
|
|
pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(struct vmbus_channel_gpadl_body);
|
2009-07-15 00:10:26 +02:00
|
|
|
pfnCount = pfnSize / sizeof(u64);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* fill in the body */
|
2009-07-14 01:02:34 +02:00
|
|
|
while (pfnLeft)
|
|
|
|
{
|
|
|
|
if (pfnLeft > pfnCount)
|
|
|
|
{
|
|
|
|
pfnCurr = pfnCount;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pfnCurr = pfnLeft;
|
|
|
|
}
|
|
|
|
|
2009-08-27 00:16:04 +02:00
|
|
|
msgSize = sizeof(struct vmbus_channel_msginfo) + sizeof(struct vmbus_channel_gpadl_body) + pfnCurr*sizeof(u64);
|
2009-07-15 21:47:43 +02:00
|
|
|
msgBody = kzalloc(msgSize, GFP_KERNEL);
|
2009-07-14 01:02:34 +02:00
|
|
|
ASSERT(msgBody);
|
|
|
|
msgBody->MessageSize = msgSize;
|
|
|
|
(*MessageCount)++;
|
2009-08-27 00:16:04 +02:00
|
|
|
gpadlBody = (struct vmbus_channel_gpadl_body *)msgBody->Msg;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* FIXME: Gpadl is u32 and we are using a pointer which could be 64-bit */
|
|
|
|
/* gpadlBody->Gpadl = kbuffer; */
|
2009-07-14 01:02:34 +02:00
|
|
|
for (i=0; i<pfnCurr; i++)
|
|
|
|
{
|
|
|
|
gpadlBody->Pfn[i] = pfn + pfnSum + i;
|
|
|
|
}
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* add to msg header */
|
2009-07-14 01:02:34 +02:00
|
|
|
INSERT_TAIL_LIST(&msgHeader->SubMsgList, &msgBody->MsgListEntry);
|
|
|
|
pfnSum += pfnCurr;
|
|
|
|
pfnLeft -= pfnCurr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-27 22:47:24 +02:00
|
|
|
/* everything fits in a header */
|
2009-08-28 01:02:36 +02:00
|
|
|
msgSize = sizeof(struct vmbus_channel_msginfo) + sizeof(struct vmbus_channel_gpadl_header) + sizeof(struct gpa_range) + pageCount*sizeof(u64);
|
2009-07-15 21:47:43 +02:00
|
|
|
msgHeader = kzalloc(msgSize, GFP_KERNEL);
|
2009-07-14 01:02:34 +02:00
|
|
|
msgHeader->MessageSize=msgSize;
|
|
|
|
|
2009-08-27 00:16:04 +02:00
|
|
|
gpaHeader = (struct vmbus_channel_gpadl_header *)msgHeader->Msg;
|
2009-07-14 01:02:34 +02:00
|
|
|
gpaHeader->RangeCount = 1;
|
2009-08-28 01:02:36 +02:00
|
|
|
gpaHeader->RangeBufLen = sizeof(struct gpa_range) + pageCount*sizeof(u64);
|
2009-07-14 01:02:34 +02:00
|
|
|
gpaHeader->Range[0].ByteOffset = 0;
|
|
|
|
gpaHeader->Range[0].ByteCount = Size;
|
|
|
|
for (i=0; i<pageCount; i++)
|
|
|
|
{
|
|
|
|
gpaHeader->Range[0].PfnArray[i] = pfn+i;
|
|
|
|
}
|
|
|
|
|
|
|
|
*MsgInfo = msgHeader;
|
|
|
|
*MessageCount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*++;
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelEstablishGpadl()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Estabish a GPADL for the specified buffer
|
|
|
|
|
|
|
|
--*/
|
2009-08-19 00:21:19 +02:00
|
|
|
int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel,
|
2009-07-27 22:47:24 +02:00
|
|
|
void * Kbuffer, /* from kmalloc() */
|
|
|
|
u32 Size, /* page-size multiple */
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 *GpadlHandle
|
2009-07-14 01:02:34 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int ret=0;
|
2009-08-27 00:16:04 +02:00
|
|
|
struct vmbus_channel_gpadl_header *gpadlMsg;
|
|
|
|
struct vmbus_channel_gpadl_body *gpadlBody;
|
|
|
|
/* struct vmbus_channel_gpadl_created *gpadlCreated; */
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-08-19 00:21:19 +02:00
|
|
|
struct vmbus_channel_msginfo *msgInfo;
|
|
|
|
struct vmbus_channel_msginfo *subMsgInfo;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 msgCount;
|
2009-07-14 01:02:34 +02:00
|
|
|
LIST_ENTRY* anchor;
|
|
|
|
LIST_ENTRY* curr;
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 nextGpadlHandle;
|
2009-07-15 23:56:45 +02:00
|
|
|
unsigned long flags;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_ENTER(VMBUS);
|
|
|
|
|
2009-07-29 23:00:12 +02:00
|
|
|
nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle);
|
|
|
|
atomic_inc(&gVmbusConnection.NextGpadlHandle);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
|
|
|
|
ASSERT(msgInfo != NULL);
|
|
|
|
ASSERT(msgCount >0);
|
|
|
|
|
2009-07-30 00:40:18 +02:00
|
|
|
msgInfo->WaitEvent = osd_WaitEventCreate();
|
2009-08-27 00:16:04 +02:00
|
|
|
gpadlMsg = (struct vmbus_channel_gpadl_header *)msgInfo->Msg;
|
2009-07-14 01:02:34 +02:00
|
|
|
gpadlMsg->Header.MessageType = ChannelMessageGpadlHeader;
|
|
|
|
gpadlMsg->ChildRelId = Channel->OfferMsg.ChildRelId;
|
|
|
|
gpadlMsg->Gpadl = nextGpadlHandle;
|
|
|
|
|
|
|
|
DumpGpadlHeader(gpadlMsg);
|
|
|
|
|
2009-07-15 23:56:45 +02:00
|
|
|
spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &msgInfo->MsgListEntry);
|
2009-07-15 23:56:45 +02:00
|
|
|
spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_DBG(VMBUS, "buffer %p, size %d msg cnt %d", Kbuffer, Size, msgCount);
|
|
|
|
|
2009-08-19 00:21:19 +02:00
|
|
|
DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd", msgInfo->MessageSize - sizeof(*msgInfo));
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-08-19 00:21:19 +02:00
|
|
|
ret = VmbusPostMessage(gpadlMsg, msgInfo->MessageSize - sizeof(*msgInfo));
|
2009-07-14 01:02:34 +02:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
DPRINT_ERR(VMBUS, "Unable to open channel - %d", ret);
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msgCount>1)
|
|
|
|
{
|
|
|
|
ITERATE_LIST_ENTRIES(anchor, curr, &msgInfo->SubMsgList)
|
|
|
|
{
|
2009-08-27 00:16:04 +02:00
|
|
|
subMsgInfo = (struct vmbus_channel_msginfo *)curr;
|
|
|
|
gpadlBody = (struct vmbus_channel_gpadl_body *)subMsgInfo->Msg;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
gpadlBody->Header.MessageType = ChannelMessageGpadlBody;
|
|
|
|
gpadlBody->Gpadl = nextGpadlHandle;
|
|
|
|
|
2009-08-19 00:21:19 +02:00
|
|
|
DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd", subMsgInfo->MessageSize - sizeof(*subMsgInfo));
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-08-19 00:21:19 +02:00
|
|
|
DumpGpadlBody(gpadlBody, subMsgInfo->MessageSize - sizeof(*subMsgInfo));
|
|
|
|
ret = VmbusPostMessage(gpadlBody, subMsgInfo->MessageSize - sizeof(*subMsgInfo));
|
2009-07-14 01:02:34 +02:00
|
|
|
ASSERT(ret == 0);
|
|
|
|
}
|
|
|
|
}
|
2009-07-30 00:40:18 +02:00
|
|
|
osd_WaitEventWait(msgInfo->WaitEvent);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* At this point, we received the gpadl created msg */
|
2009-07-14 01:02:34 +02:00
|
|
|
DPRINT_DBG(VMBUS, "Received GPADL created (relid %d, status %d handle %x)",
|
|
|
|
Channel->OfferMsg.ChildRelId,
|
|
|
|
msgInfo->Response.GpadlCreated.CreationStatus,
|
|
|
|
gpadlMsg->Gpadl);
|
|
|
|
|
|
|
|
*GpadlHandle = gpadlMsg->Gpadl;
|
|
|
|
|
|
|
|
Cleanup:
|
2009-07-15 23:56:45 +02:00
|
|
|
spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry);
|
2009-07-15 23:56:45 +02:00
|
|
|
spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-29 23:00:10 +02:00
|
|
|
kfree(msgInfo->WaitEvent);
|
2009-07-15 21:48:29 +02:00
|
|
|
kfree(msgInfo);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*++;
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelTeardownGpadl()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Teardown the specified GPADL handle
|
|
|
|
|
|
|
|
--*/
|
2009-08-19 00:21:19 +02:00
|
|
|
int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle)
|
2009-07-14 01:02:34 +02:00
|
|
|
{
|
|
|
|
int ret=0;
|
2009-08-27 00:16:04 +02:00
|
|
|
struct vmbus_channel_gpadl_teardown *msg;
|
2009-08-19 00:21:19 +02:00
|
|
|
struct vmbus_channel_msginfo *info;
|
2009-07-15 23:56:45 +02:00
|
|
|
unsigned long flags;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_ENTER(VMBUS);
|
|
|
|
|
|
|
|
ASSERT(GpadlHandle != 0);
|
|
|
|
|
2009-08-27 00:16:04 +02:00
|
|
|
info = kmalloc(sizeof(*info) + sizeof(struct vmbus_channel_gpadl_teardown), GFP_KERNEL);
|
2009-07-14 01:02:34 +02:00
|
|
|
ASSERT(info != NULL);
|
|
|
|
|
2009-07-30 00:40:18 +02:00
|
|
|
info->WaitEvent = osd_WaitEventCreate();
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-08-27 00:16:04 +02:00
|
|
|
msg = (struct vmbus_channel_gpadl_teardown *)info->Msg;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
msg->Header.MessageType = ChannelMessageGpadlTeardown;
|
|
|
|
msg->ChildRelId = Channel->OfferMsg.ChildRelId;
|
|
|
|
msg->Gpadl = GpadlHandle;
|
|
|
|
|
2009-07-15 23:56:45 +02:00
|
|
|
spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &info->MsgListEntry);
|
2009-07-15 23:56:45 +02:00
|
|
|
spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-08-27 00:16:04 +02:00
|
|
|
ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_gpadl_teardown));
|
2009-07-14 01:02:34 +02:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
2009-07-27 22:47:24 +02:00
|
|
|
/* TODO: */
|
2009-07-14 01:02:34 +02:00
|
|
|
}
|
|
|
|
|
2009-07-30 00:40:18 +02:00
|
|
|
osd_WaitEventWait(info->WaitEvent);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Received a torndown response */
|
2009-07-15 23:56:45 +02:00
|
|
|
spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
REMOVE_ENTRY_LIST(&info->MsgListEntry);
|
2009-07-15 23:56:45 +02:00
|
|
|
spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-29 23:00:10 +02:00
|
|
|
kfree(info->WaitEvent);
|
2009-07-15 21:48:29 +02:00
|
|
|
kfree(info);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelClose()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Close the specified channel
|
|
|
|
|
|
|
|
--*/
|
2009-08-19 00:21:19 +02:00
|
|
|
void VmbusChannelClose(struct vmbus_channel *Channel)
|
2009-07-14 01:02:34 +02:00
|
|
|
{
|
|
|
|
int ret=0;
|
2009-08-27 00:16:04 +02:00
|
|
|
struct vmbus_channel_close_channel *msg;
|
2009-08-19 00:21:19 +02:00
|
|
|
struct vmbus_channel_msginfo *info;
|
2009-07-15 23:57:16 +02:00
|
|
|
unsigned long flags;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_ENTER(VMBUS);
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Stop callback and cancel the timer asap */
|
2009-07-14 01:02:34 +02:00
|
|
|
Channel->OnChannelCallback = NULL;
|
2009-07-30 00:40:57 +02:00
|
|
|
del_timer(&Channel->poll_timer);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Send a closing message */
|
2009-08-27 00:16:04 +02:00
|
|
|
info = kmalloc(sizeof(*info) + sizeof(struct vmbus_channel_close_channel), GFP_KERNEL);
|
2009-07-14 01:02:34 +02:00
|
|
|
ASSERT(info != NULL);
|
|
|
|
|
2009-07-30 00:40:18 +02:00
|
|
|
/* info->waitEvent = osd_WaitEventCreate(); */
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-08-27 00:16:04 +02:00
|
|
|
msg = (struct vmbus_channel_close_channel *)info->Msg;
|
2009-07-14 01:02:34 +02:00
|
|
|
msg->Header.MessageType = ChannelMessageCloseChannel;
|
|
|
|
msg->ChildRelId = Channel->OfferMsg.ChildRelId;
|
|
|
|
|
2009-08-27 00:16:04 +02:00
|
|
|
ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_close_channel));
|
2009-07-14 01:02:34 +02:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
2009-07-27 22:47:24 +02:00
|
|
|
/* TODO: */
|
2009-07-14 01:02:34 +02:00
|
|
|
}
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Tear down the gpadl for the channel's ring buffer */
|
2009-07-14 01:02:34 +02:00
|
|
|
if (Channel->RingBufferGpadlHandle)
|
|
|
|
{
|
|
|
|
VmbusChannelTeardownGpadl(Channel, Channel->RingBufferGpadlHandle);
|
|
|
|
}
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* TODO: Send a msg to release the childRelId */
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Cleanup the ring buffers for this channel */
|
2009-07-14 01:02:34 +02:00
|
|
|
RingBufferCleanup(&Channel->Outbound);
|
|
|
|
RingBufferCleanup(&Channel->Inbound);
|
|
|
|
|
2009-07-30 00:40:18 +02:00
|
|
|
osd_PageFree(Channel->RingBufferPages, Channel->RingBufferPageCount);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-15 21:48:29 +02:00
|
|
|
kfree(info);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are closing the channel during an error path in
|
|
|
|
* opening the channel, don't free the channel since the
|
|
|
|
* caller will free the channel
|
|
|
|
*/
|
|
|
|
|
2009-07-14 01:02:34 +02:00
|
|
|
if (Channel->State == CHANNEL_OPEN_STATE)
|
|
|
|
{
|
2009-07-15 23:57:16 +02:00
|
|
|
spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
REMOVE_ENTRY_LIST(&Channel->ListEntry);
|
2009-07-15 23:57:16 +02:00
|
|
|
spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
FreeVmbusChannel(Channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelSendPacket()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Send the specified buffer on the given channel
|
|
|
|
|
|
|
|
--*/
|
2009-08-19 00:21:19 +02:00
|
|
|
int VmbusChannelSendPacket(struct vmbus_channel *Channel,
|
2009-07-15 00:06:28 +02:00
|
|
|
const void * Buffer,
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 BufferLen,
|
2009-07-15 00:10:26 +02:00
|
|
|
u64 RequestId,
|
2009-08-28 01:02:36 +02:00
|
|
|
enum vmbus_packet_type Type,
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 Flags
|
2009-07-14 01:02:34 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int ret=0;
|
2009-08-28 01:02:36 +02:00
|
|
|
struct vmpacket_descriptor desc;
|
|
|
|
u32 packetLen = sizeof(struct vmpacket_descriptor) + BufferLen;
|
2009-07-15 00:10:26 +02:00
|
|
|
u32 packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
|
2009-07-30 17:37:23 +02:00
|
|
|
struct scatterlist bufferList[3];
|
2009-07-15 00:10:26 +02:00
|
|
|
u64 alignedData=0;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_ENTER(VMBUS);
|
|
|
|
DPRINT_DBG(VMBUS, "channel %p buffer %p len %d", Channel, Buffer, BufferLen);
|
|
|
|
|
|
|
|
DumpVmbusChannel(Channel);
|
|
|
|
|
2009-07-15 00:10:26 +02:00
|
|
|
ASSERT((packetLenAligned - packetLen) < sizeof(u64));
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Setup the descriptor */
|
|
|
|
desc.Type = Type; /* VmbusPacketTypeDataInBand; */
|
|
|
|
desc.Flags = Flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */
|
2009-08-28 01:02:36 +02:00
|
|
|
desc.DataOffset8 = sizeof(struct vmpacket_descriptor) >> 3; /* in 8-bytes granularity */
|
2009-07-27 22:47:24 +02:00
|
|
|
desc.Length8 = (u16)(packetLenAligned >> 3);
|
|
|
|
desc.TransactionId = RequestId;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-30 17:37:23 +02:00
|
|
|
sg_init_table(bufferList,3);
|
2009-08-28 01:02:36 +02:00
|
|
|
sg_set_buf(&bufferList[0], &desc, sizeof(struct vmpacket_descriptor));
|
2009-07-30 17:37:23 +02:00
|
|
|
sg_set_buf(&bufferList[1], Buffer, BufferLen);
|
|
|
|
sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
ret = RingBufferWrite(
|
|
|
|
&Channel->Outbound,
|
|
|
|
bufferList,
|
|
|
|
3);
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* TODO: We should determine if this is optional */
|
2009-07-14 01:02:34 +02:00
|
|
|
if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
|
|
|
|
{
|
|
|
|
VmbusChannelSetEvent(Channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelSendPacketPageBuffer()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Send a range of single-page buffer packets using a GPADL Direct packet type.
|
|
|
|
|
|
|
|
--*/
|
2009-08-19 00:21:19 +02:00
|
|
|
int VmbusChannelSendPacketPageBuffer(struct vmbus_channel *Channel,
|
2009-08-20 21:17:36 +02:00
|
|
|
struct hv_page_buffer PageBuffers[],
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 PageCount,
|
2009-07-15 00:06:28 +02:00
|
|
|
void * Buffer,
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 BufferLen,
|
2009-07-15 00:10:26 +02:00
|
|
|
u64 RequestId
|
2009-07-14 01:02:34 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int ret=0;
|
|
|
|
int i=0;
|
2009-07-27 22:47:39 +02:00
|
|
|
struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER desc;
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 descSize;
|
|
|
|
u32 packetLen;
|
|
|
|
u32 packetLenAligned;
|
2009-07-30 17:37:23 +02:00
|
|
|
struct scatterlist bufferList[3];
|
2009-07-15 00:10:26 +02:00
|
|
|
u64 alignedData=0;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_ENTER(VMBUS);
|
|
|
|
|
|
|
|
ASSERT(PageCount <= MAX_PAGE_BUFFER_COUNT);
|
|
|
|
|
|
|
|
DumpVmbusChannel(Channel);
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Adjust the size down since VMBUS_CHANNEL_PACKET_PAGE_BUFFER is the largest size we support */
|
2009-08-20 21:17:36 +02:00
|
|
|
descSize = sizeof(struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER) - ((MAX_PAGE_BUFFER_COUNT - PageCount)*sizeof(struct hv_page_buffer));
|
2009-07-14 01:02:34 +02:00
|
|
|
packetLen = descSize + BufferLen;
|
2009-07-15 00:10:26 +02:00
|
|
|
packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-15 00:10:26 +02:00
|
|
|
ASSERT((packetLenAligned - packetLen) < sizeof(u64));
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Setup the descriptor */
|
2009-07-14 01:02:34 +02:00
|
|
|
desc.Type = VmbusPacketTypeDataUsingGpaDirect;
|
|
|
|
desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
|
2009-07-27 22:47:24 +02:00
|
|
|
desc.DataOffset8 = descSize >> 3; /* in 8-bytes grandularity */
|
|
|
|
desc.Length8 = (u16)(packetLenAligned >> 3);
|
|
|
|
desc.TransactionId = RequestId;
|
2009-07-14 01:02:34 +02:00
|
|
|
desc.RangeCount = PageCount;
|
|
|
|
|
|
|
|
for (i=0; i<PageCount; i++)
|
|
|
|
{
|
|
|
|
desc.Range[i].Length = PageBuffers[i].Length;
|
|
|
|
desc.Range[i].Offset = PageBuffers[i].Offset;
|
|
|
|
desc.Range[i].Pfn = PageBuffers[i].Pfn;
|
|
|
|
}
|
|
|
|
|
2009-07-30 17:37:23 +02:00
|
|
|
sg_init_table(bufferList,3);
|
|
|
|
sg_set_buf(&bufferList[0], &desc, descSize);
|
|
|
|
sg_set_buf(&bufferList[1], Buffer, BufferLen);
|
|
|
|
sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
ret = RingBufferWrite(
|
|
|
|
&Channel->Outbound,
|
|
|
|
bufferList,
|
|
|
|
3);
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* TODO: We should determine if this is optional */
|
2009-07-14 01:02:34 +02:00
|
|
|
if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
|
|
|
|
{
|
|
|
|
VmbusChannelSetEvent(Channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelSendPacketMultiPageBuffer()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Send a multi-page buffer packet using a GPADL Direct packet type.
|
|
|
|
|
|
|
|
--*/
|
2009-08-19 00:21:19 +02:00
|
|
|
int VmbusChannelSendPacketMultiPageBuffer(struct vmbus_channel *Channel,
|
2009-08-20 21:17:36 +02:00
|
|
|
struct hv_multipage_buffer *MultiPageBuffer,
|
2009-07-15 00:06:28 +02:00
|
|
|
void * Buffer,
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 BufferLen,
|
2009-07-15 00:10:26 +02:00
|
|
|
u64 RequestId
|
2009-07-14 01:02:34 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int ret=0;
|
2009-07-27 22:47:40 +02:00
|
|
|
struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER desc;
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 descSize;
|
|
|
|
u32 packetLen;
|
|
|
|
u32 packetLenAligned;
|
2009-07-30 17:37:23 +02:00
|
|
|
struct scatterlist bufferList[3];
|
2009-07-15 00:10:26 +02:00
|
|
|
u64 alignedData=0;
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset, MultiPageBuffer->Length);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_ENTER(VMBUS);
|
|
|
|
|
|
|
|
DumpVmbusChannel(Channel);
|
|
|
|
|
|
|
|
DPRINT_DBG(VMBUS, "data buffer - offset %u len %u pfn count %u", MultiPageBuffer->Offset, MultiPageBuffer->Length, PfnCount);
|
|
|
|
|
|
|
|
ASSERT(PfnCount > 0);
|
|
|
|
ASSERT(PfnCount <= MAX_MULTIPAGE_BUFFER_COUNT);
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Adjust the size down since VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER is the largest size we support */
|
2009-07-27 22:47:40 +02:00
|
|
|
descSize = sizeof(struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER) - ((MAX_MULTIPAGE_BUFFER_COUNT - PfnCount)*sizeof(u64));
|
2009-07-14 01:02:34 +02:00
|
|
|
packetLen = descSize + BufferLen;
|
2009-07-15 00:10:26 +02:00
|
|
|
packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-15 00:10:26 +02:00
|
|
|
ASSERT((packetLenAligned - packetLen) < sizeof(u64));
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Setup the descriptor */
|
2009-07-14 01:02:34 +02:00
|
|
|
desc.Type = VmbusPacketTypeDataUsingGpaDirect;
|
|
|
|
desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED;
|
2009-07-27 22:47:24 +02:00
|
|
|
desc.DataOffset8 = descSize >> 3; /* in 8-bytes grandularity */
|
|
|
|
desc.Length8 = (u16)(packetLenAligned >> 3);
|
|
|
|
desc.TransactionId = RequestId;
|
2009-07-14 01:02:34 +02:00
|
|
|
desc.RangeCount = 1;
|
|
|
|
|
|
|
|
desc.Range.Length = MultiPageBuffer->Length;
|
|
|
|
desc.Range.Offset = MultiPageBuffer->Offset;
|
|
|
|
|
2009-07-15 00:10:26 +02:00
|
|
|
memcpy(desc.Range.PfnArray, MultiPageBuffer->PfnArray, PfnCount*sizeof(u64));
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-30 17:37:23 +02:00
|
|
|
sg_init_table(bufferList,3);
|
|
|
|
sg_set_buf(&bufferList[0], &desc, descSize);
|
|
|
|
sg_set_buf(&bufferList[1], Buffer, BufferLen);
|
|
|
|
sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
ret = RingBufferWrite(
|
|
|
|
&Channel->Outbound,
|
|
|
|
bufferList,
|
|
|
|
3);
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* TODO: We should determine if this is optional */
|
2009-07-14 01:02:34 +02:00
|
|
|
if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
|
|
|
|
{
|
|
|
|
VmbusChannelSetEvent(Channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelRecvPacket()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Retrieve the user packet on the specified channel
|
|
|
|
|
|
|
|
--*/
|
2009-07-27 22:47:24 +02:00
|
|
|
/* TODO: Do we ever receive a gpa direct packet other than the ones we send ? */
|
2009-08-19 00:21:19 +02:00
|
|
|
int VmbusChannelRecvPacket(struct vmbus_channel *Channel,
|
2009-08-18 02:21:31 +02:00
|
|
|
void *Buffer,
|
|
|
|
u32 BufferLen,
|
|
|
|
u32 *BufferActualLen,
|
|
|
|
u64 *RequestId)
|
2009-07-14 01:02:34 +02:00
|
|
|
{
|
2009-08-28 01:02:36 +02:00
|
|
|
struct vmpacket_descriptor desc;
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 packetLen;
|
|
|
|
u32 userLen;
|
2009-07-14 01:02:34 +02:00
|
|
|
int ret;
|
2009-07-15 23:48:32 +02:00
|
|
|
unsigned long flags;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_ENTER(VMBUS);
|
|
|
|
|
|
|
|
*BufferActualLen = 0;
|
|
|
|
*RequestId = 0;
|
|
|
|
|
2009-07-15 23:48:32 +02:00
|
|
|
spin_lock_irqsave(&Channel->inbound_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-08-28 01:02:36 +02:00
|
|
|
ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(struct vmpacket_descriptor));
|
2009-07-14 01:02:34 +02:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
2009-07-15 23:48:32 +02:00
|
|
|
spin_unlock_irqrestore(&Channel->inbound_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* DPRINT_DBG(VMBUS, "nothing to read!!"); */
|
2009-07-14 01:02:34 +02:00
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* VmbusChannelClearEvent(Channel); */
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
packetLen = desc.Length8 << 3;
|
|
|
|
userLen = packetLen - (desc.DataOffset8 << 3);
|
2009-07-27 22:47:24 +02:00
|
|
|
/* ASSERT(userLen > 0); */
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ",
|
|
|
|
Channel,
|
|
|
|
Channel->OfferMsg.ChildRelId,
|
|
|
|
desc.Type,
|
|
|
|
desc.Flags,
|
|
|
|
desc.TransactionId, packetLen, userLen);
|
|
|
|
|
|
|
|
*BufferActualLen = userLen;
|
|
|
|
|
|
|
|
if (userLen > BufferLen)
|
|
|
|
{
|
2009-07-15 23:48:32 +02:00
|
|
|
spin_unlock_irqrestore(&Channel->inbound_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_ERR(VMBUS, "buffer too small - got %d needs %d", BufferLen, userLen);
|
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*RequestId = desc.TransactionId;
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Copy over the packet to the user buffer */
|
2009-07-14 01:02:34 +02:00
|
|
|
ret = RingBufferRead(&Channel->Inbound, Buffer, userLen, (desc.DataOffset8 << 3));
|
|
|
|
|
2009-07-15 23:48:32 +02:00
|
|
|
spin_unlock_irqrestore(&Channel->inbound_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelRecvPacketRaw()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Retrieve the raw packet on the specified channel
|
|
|
|
|
|
|
|
--*/
|
2009-08-19 00:21:19 +02:00
|
|
|
int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel,
|
2009-07-15 00:06:28 +02:00
|
|
|
void * Buffer,
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 BufferLen,
|
|
|
|
u32* BufferActualLen,
|
2009-07-15 00:10:26 +02:00
|
|
|
u64* RequestId
|
2009-07-14 01:02:34 +02:00
|
|
|
)
|
|
|
|
{
|
2009-08-28 01:02:36 +02:00
|
|
|
struct vmpacket_descriptor desc;
|
2009-07-15 00:09:36 +02:00
|
|
|
u32 packetLen;
|
|
|
|
u32 userLen;
|
2009-07-14 01:02:34 +02:00
|
|
|
int ret;
|
2009-07-15 23:48:32 +02:00
|
|
|
unsigned long flags;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_ENTER(VMBUS);
|
|
|
|
|
|
|
|
*BufferActualLen = 0;
|
|
|
|
*RequestId = 0;
|
|
|
|
|
2009-07-15 23:48:32 +02:00
|
|
|
spin_lock_irqsave(&Channel->inbound_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-08-28 01:02:36 +02:00
|
|
|
ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(struct vmpacket_descriptor));
|
2009-07-14 01:02:34 +02:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
2009-07-15 23:48:32 +02:00
|
|
|
spin_unlock_irqrestore(&Channel->inbound_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* DPRINT_DBG(VMBUS, "nothing to read!!"); */
|
2009-07-14 01:02:34 +02:00
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* VmbusChannelClearEvent(Channel); */
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
packetLen = desc.Length8 << 3;
|
|
|
|
userLen = packetLen - (desc.DataOffset8 << 3);
|
|
|
|
|
|
|
|
DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ",
|
|
|
|
Channel,
|
|
|
|
Channel->OfferMsg.ChildRelId,
|
|
|
|
desc.Type,
|
|
|
|
desc.Flags,
|
|
|
|
desc.TransactionId, packetLen, userLen);
|
|
|
|
|
|
|
|
*BufferActualLen = packetLen;
|
|
|
|
|
|
|
|
if (packetLen > BufferLen)
|
|
|
|
{
|
2009-07-15 23:48:32 +02:00
|
|
|
spin_unlock_irqrestore(&Channel->inbound_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_ERR(VMBUS, "buffer too small - needed %d bytes but got space for only %d bytes", packetLen, BufferLen);
|
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
*RequestId = desc.TransactionId;
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* Copy over the entire packet to the user buffer */
|
2009-07-14 01:02:34 +02:00
|
|
|
ret = RingBufferRead(&Channel->Inbound, Buffer, packetLen, 0);
|
|
|
|
|
2009-07-15 23:48:32 +02:00
|
|
|
spin_unlock_irqrestore(&Channel->inbound_lock, flags);
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
DPRINT_EXIT(VMBUS);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelOnChannelEvent()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Channel event callback
|
|
|
|
|
|
|
|
--*/
|
2009-08-19 00:21:19 +02:00
|
|
|
void VmbusChannelOnChannelEvent(struct vmbus_channel *Channel)
|
2009-07-14 01:02:34 +02:00
|
|
|
{
|
|
|
|
DumpVmbusChannel(Channel);
|
|
|
|
ASSERT(Channel->OnChannelCallback);
|
|
|
|
#ifdef ENABLE_POLLING
|
2009-07-30 00:40:57 +02:00
|
|
|
del_timer(&Channel->poll_timer);
|
2009-07-14 01:02:34 +02:00
|
|
|
Channel->OnChannelCallback(Channel->ChannelCallbackContext);
|
2009-07-30 00:40:57 +02:00
|
|
|
channel->poll_timer.expires(jiffies + usecs_to_jiffies(100);
|
|
|
|
add_timer(&channel->poll_timer);
|
2009-07-14 01:02:34 +02:00
|
|
|
#else
|
|
|
|
Channel->OnChannelCallback(Channel->ChannelCallbackContext);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Name:
|
|
|
|
VmbusChannelOnTimer()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Timer event callback
|
|
|
|
|
|
|
|
--*/
|
2009-08-18 02:21:31 +02:00
|
|
|
void VmbusChannelOnTimer(unsigned long data)
|
2009-07-14 01:02:34 +02:00
|
|
|
{
|
2009-08-19 00:21:19 +02:00
|
|
|
struct vmbus_channel *channel = (struct vmbus_channel *)data;
|
2009-07-14 01:02:34 +02:00
|
|
|
|
|
|
|
if (channel->OnChannelCallback)
|
|
|
|
{
|
|
|
|
channel->OnChannelCallback(channel->ChannelCallbackContext);
|
|
|
|
#ifdef ENABLE_POLLING
|
2009-07-30 00:40:57 +02:00
|
|
|
channel->poll_timer.expires(jiffies + usecs_to_jiffies(100);
|
|
|
|
add_timer(&channel->poll_timer);
|
2009-07-14 01:02:34 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Name:
|
|
|
|
DumpVmbusChannel()
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Dump vmbus channel info to the console
|
|
|
|
|
|
|
|
--*/
|
2009-08-19 00:21:19 +02:00
|
|
|
static void DumpVmbusChannel(struct vmbus_channel *Channel)
|
2009-07-14 01:02:34 +02:00
|
|
|
{
|
|
|
|
DPRINT_DBG(VMBUS, "Channel (%d)", Channel->OfferMsg.ChildRelId);
|
|
|
|
DumpRingInfo(&Channel->Outbound, "Outbound ");
|
|
|
|
DumpRingInfo(&Channel->Inbound, "Inbound ");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-27 22:47:24 +02:00
|
|
|
/* eof */
|