2009-07-13 16:34:54 -06: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:
|
2009-11-23 10:00:22 -07:00
|
|
|
* Haiyang Zhang <haiyangz@microsoft.com>
|
2009-07-13 16:34:54 -06:00
|
|
|
* Hank Janssen <hjanssen@microsoft.com>
|
|
|
|
*/
|
2009-07-14 16:08:20 -06:00
|
|
|
#include <linux/kernel.h>
|
2009-07-15 12:06:01 -06:00
|
|
|
#include <linux/mm.h>
|
2009-07-16 12:50:41 -06:00
|
|
|
#include <linux/delay.h>
|
2009-09-02 11:33:05 -06:00
|
|
|
#include <linux/io.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2009-08-19 17:14:47 -06:00
|
|
|
#include "osd.h"
|
2009-08-28 17:22:59 -06:00
|
|
|
#include "logging.h"
|
2009-07-13 16:34:54 -06:00
|
|
|
#include "NetVsc.h"
|
|
|
|
#include "RndisFilter.h"
|
|
|
|
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Globals */
|
2009-09-02 11:33:05 -06:00
|
|
|
static const char *gDriverName = "netvsc";
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */
|
2009-08-19 17:17:03 -06:00
|
|
|
static const struct hv_guid gNetVscDeviceType = {
|
|
|
|
.data = {
|
|
|
|
0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46,
|
|
|
|
0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E
|
|
|
|
}
|
2009-07-13 16:34:54 -06:00
|
|
|
};
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo);
|
|
|
|
|
|
|
|
static int NetVscOnDeviceRemove(struct hv_device *Device);
|
|
|
|
|
|
|
|
static void NetVscOnCleanup(struct hv_driver *Driver);
|
|
|
|
|
|
|
|
static void NetVscOnChannelCallback(void *context);
|
|
|
|
|
|
|
|
static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device);
|
|
|
|
|
|
|
|
static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device);
|
|
|
|
|
2009-09-02 11:35:56 -06:00
|
|
|
static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice);
|
2009-09-02 11:33:05 -06:00
|
|
|
|
2009-09-02 11:35:56 -06:00
|
|
|
static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice);
|
2009-09-02 11:33:05 -06:00
|
|
|
|
|
|
|
static int NetVscConnectToVsp(struct hv_device *Device);
|
|
|
|
|
|
|
|
static void NetVscOnSendCompletion(struct hv_device *Device,
|
|
|
|
struct vmpacket_descriptor *Packet);
|
|
|
|
|
|
|
|
static int NetVscOnSend(struct hv_device *Device,
|
|
|
|
struct hv_netvsc_packet *Packet);
|
|
|
|
|
|
|
|
static void NetVscOnReceive(struct hv_device *Device,
|
|
|
|
struct vmpacket_descriptor *Packet);
|
|
|
|
|
|
|
|
static void NetVscOnReceiveCompletion(void *Context);
|
|
|
|
|
|
|
|
static void NetVscSendReceiveCompletion(struct hv_device *Device,
|
|
|
|
u64 TransactionId);
|
|
|
|
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:35:56 -06:00
|
|
|
static struct netvsc_device *AllocNetDevice(struct hv_device *Device)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:35:56 -06:00
|
|
|
netDevice = kzalloc(sizeof(struct netvsc_device), GFP_KERNEL);
|
2009-07-13 16:34:54 -06:00
|
|
|
if (!netDevice)
|
|
|
|
return NULL;
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Set to 2 to allow both inbound and outbound traffic */
|
2009-07-29 15:00:12 -06:00
|
|
|
atomic_cmpxchg(&netDevice->RefCount, 0, 2);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
netDevice->Device = Device;
|
|
|
|
Device->Extension = netDevice;
|
|
|
|
|
|
|
|
return netDevice;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:35:56 -06:00
|
|
|
static void FreeNetDevice(struct netvsc_device *Device)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-07-29 15:00:12 -06:00
|
|
|
ASSERT(atomic_read(&Device->RefCount) == 0);
|
2009-07-13 16:34:54 -06:00
|
|
|
Device->Device->Extension = NULL;
|
2009-07-15 13:48:29 -06:00
|
|
|
kfree(Device);
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Get the net device object iff exists and its refcount > 1 */
|
2009-09-02 11:35:56 -06:00
|
|
|
static struct netvsc_device *GetOutboundNetDevice(struct hv_device *Device)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
netDevice = Device->Extension;
|
2009-07-29 15:00:12 -06:00
|
|
|
if (netDevice && atomic_read(&netDevice->RefCount) > 1)
|
|
|
|
atomic_inc(&netDevice->RefCount);
|
2009-07-13 16:34:54 -06:00
|
|
|
else
|
|
|
|
netDevice = NULL;
|
|
|
|
|
|
|
|
return netDevice;
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Get the net device object iff exists and its refcount > 0 */
|
2009-09-02 11:35:56 -06:00
|
|
|
static struct netvsc_device *GetInboundNetDevice(struct hv_device *Device)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
netDevice = Device->Extension;
|
2009-07-29 15:00:12 -06:00
|
|
|
if (netDevice && atomic_read(&netDevice->RefCount))
|
|
|
|
atomic_inc(&netDevice->RefCount);
|
2009-07-13 16:34:54 -06:00
|
|
|
else
|
|
|
|
netDevice = NULL;
|
|
|
|
|
|
|
|
return netDevice;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
static void PutNetDevice(struct hv_device *Device)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
netDevice = Device->Extension;
|
2009-07-13 16:34:54 -06:00
|
|
|
ASSERT(netDevice);
|
|
|
|
|
2009-07-29 15:00:12 -06:00
|
|
|
atomic_dec(&netDevice->RefCount);
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
|
|
|
|
2009-09-02 11:35:56 -06:00
|
|
|
static struct netvsc_device *ReleaseOutboundNetDevice(struct hv_device *Device)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
netDevice = Device->Extension;
|
2009-07-13 16:34:54 -06:00
|
|
|
if (netDevice == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Busy wait until the ref drop to 2, then set it to 1 */
|
2009-07-29 15:00:12 -06:00
|
|
|
while (atomic_cmpxchg(&netDevice->RefCount, 2, 1) != 2)
|
2009-07-16 12:50:41 -06:00
|
|
|
udelay(100);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
return netDevice;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:35:56 -06:00
|
|
|
static struct netvsc_device *ReleaseInboundNetDevice(struct hv_device *Device)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
netDevice = Device->Extension;
|
2009-07-13 16:34:54 -06:00
|
|
|
if (netDevice == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Busy wait until the ref drop to 1, then set it to 0 */
|
2009-07-29 15:00:12 -06:00
|
|
|
while (atomic_cmpxchg(&netDevice->RefCount, 1, 0) != 1)
|
2009-07-16 12:50:41 -06:00
|
|
|
udelay(100);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
Device->Extension = NULL;
|
|
|
|
return netDevice;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
/**
|
|
|
|
* NetVscInitialize - Main entry point
|
|
|
|
*/
|
|
|
|
int NetVscInitialize(struct hv_driver *drv)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-08-27 16:58:15 -06:00
|
|
|
struct netvsc_driver *driver = (struct netvsc_driver *)drv;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
DPRINT_DBG(NETVSC, "sizeof(struct hv_netvsc_packet)=%zd, "
|
|
|
|
"sizeof(struct nvsp_message)=%zd, "
|
|
|
|
"sizeof(struct vmtransfer_page_packet_header)=%zd",
|
|
|
|
sizeof(struct hv_netvsc_packet),
|
|
|
|
sizeof(struct nvsp_message),
|
|
|
|
sizeof(struct vmtransfer_page_packet_header));
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Make sure we are at least 2 pages since 1 page is used for control */
|
2009-07-13 16:34:54 -06:00
|
|
|
ASSERT(driver->RingBufferSize >= (PAGE_SIZE << 1));
|
|
|
|
|
|
|
|
drv->name = gDriverName;
|
2009-08-19 17:17:03 -06:00
|
|
|
memcpy(&drv->deviceType, &gNetVscDeviceType, sizeof(struct hv_guid));
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Make sure it is set by the caller */
|
2009-07-13 16:34:54 -06:00
|
|
|
ASSERT(driver->OnReceiveCallback);
|
|
|
|
ASSERT(driver->OnLinkStatusChanged);
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Setup the dispatch table */
|
2009-09-02 11:33:05 -06:00
|
|
|
driver->Base.OnDeviceAdd = NetVscOnDeviceAdd;
|
|
|
|
driver->Base.OnDeviceRemove = NetVscOnDeviceRemove;
|
|
|
|
driver->Base.OnCleanup = NetVscOnCleanup;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
driver->OnSend = NetVscOnSend;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
RndisFilterInit(driver);
|
|
|
|
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
return 0;
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:33:05 -06:00
|
|
|
int ret = 0;
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-08-28 17:20:53 -06:00
|
|
|
struct nvsp_message *initPacket;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
|
|
|
netDevice = GetOutboundNetDevice(Device);
|
2009-09-02 11:33:05 -06:00
|
|
|
if (!netDevice) {
|
|
|
|
DPRINT_ERR(NETVSC, "unable to get net device..."
|
|
|
|
"device being destroyed?");
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ASSERT(netDevice->ReceiveBufferSize > 0);
|
2009-09-02 11:33:05 -06:00
|
|
|
/* page-size grandularity */
|
|
|
|
ASSERT((netDevice->ReceiveBufferSize & (PAGE_SIZE - 1)) == 0);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
netDevice->ReceiveBuffer =
|
|
|
|
osd_PageAlloc(netDevice->ReceiveBufferSize >> PAGE_SHIFT);
|
|
|
|
if (!netDevice->ReceiveBuffer) {
|
|
|
|
DPRINT_ERR(NETVSC,
|
|
|
|
"unable to allocate receive buffer of size %d",
|
|
|
|
netDevice->ReceiveBufferSize);
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
2009-09-02 11:33:05 -06:00
|
|
|
/* page-aligned buffer */
|
|
|
|
ASSERT(((unsigned long)netDevice->ReceiveBuffer & (PAGE_SIZE - 1)) ==
|
|
|
|
0);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_INFO(NETVSC, "Establishing receive buffer's GPADL...");
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/*
|
|
|
|
* Establish the gpadl handle for this buffer on this
|
|
|
|
* channel. Note: This call uses the vmbus connection rather
|
|
|
|
* than the channel to establish the gpadl handle.
|
|
|
|
*/
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = Device->Driver->VmbusChannelInterface.EstablishGpadl(Device,
|
2009-09-02 11:33:05 -06:00
|
|
|
netDevice->ReceiveBuffer,
|
|
|
|
netDevice->ReceiveBufferSize,
|
|
|
|
&netDevice->ReceiveBufferGpadlHandle);
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(NETVSC,
|
|
|
|
"unable to establish receive buffer's gpadl");
|
2009-07-13 16:34:54 -06:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-29 16:40:18 -06:00
|
|
|
/* osd_WaitEventWait(ext->ChannelInitEvent); */
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Notify the NetVsp of the gpadl handle */
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendReceiveBuffer...");
|
|
|
|
|
|
|
|
initPacket = &netDevice->ChannelInitPacket;
|
|
|
|
|
2009-08-28 17:20:53 -06:00
|
|
|
memset(initPacket, 0, sizeof(struct nvsp_message));
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
initPacket->Header.MessageType = NvspMessage1TypeSendReceiveBuffer;
|
|
|
|
initPacket->Messages.Version1Messages.SendReceiveBuffer.GpadlHandle = netDevice->ReceiveBufferGpadlHandle;
|
|
|
|
initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Send the gpadl notification request */
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
|
2009-09-02 11:33:05 -06:00
|
|
|
initPacket,
|
|
|
|
sizeof(struct nvsp_message),
|
|
|
|
(unsigned long)initPacket,
|
|
|
|
VmbusPacketTypeDataInBand,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(NETVSC,
|
|
|
|
"unable to send receive buffer's gpadl to netvsp");
|
2009-07-13 16:34:54 -06:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-29 16:40:18 -06:00
|
|
|
osd_WaitEventWait(netDevice->ChannelInitEvent);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Check the response */
|
2009-09-02 11:33:05 -06:00
|
|
|
if (initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status != NvspStatusSuccess) {
|
|
|
|
DPRINT_ERR(NETVSC, "Unable to complete receive buffer "
|
|
|
|
"initialzation with NetVsp - status %d",
|
|
|
|
initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status);
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Parse the response */
|
2009-07-13 16:34:54 -06:00
|
|
|
ASSERT(netDevice->ReceiveSectionCount == 0);
|
|
|
|
ASSERT(netDevice->ReceiveSections == NULL);
|
|
|
|
|
|
|
|
netDevice->ReceiveSectionCount = initPacket->Messages.Version1Messages.SendReceiveBufferComplete.NumSections;
|
|
|
|
|
2009-08-28 17:20:53 -06:00
|
|
|
netDevice->ReceiveSections = kmalloc(netDevice->ReceiveSectionCount * sizeof(struct nvsp_1_receive_buffer_section), GFP_KERNEL);
|
2009-09-02 11:33:05 -06:00
|
|
|
if (netDevice->ReceiveSections == NULL) {
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(netDevice->ReceiveSections,
|
|
|
|
initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Sections,
|
2009-08-28 17:20:53 -06:00
|
|
|
netDevice->ReceiveSectionCount * sizeof(struct nvsp_1_receive_buffer_section));
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
DPRINT_INFO(NETVSC, "Receive sections info (count %d, offset %d, "
|
|
|
|
"endoffset %d, suballoc size %d, num suballocs %d)",
|
|
|
|
netDevice->ReceiveSectionCount,
|
|
|
|
netDevice->ReceiveSections[0].Offset,
|
|
|
|
netDevice->ReceiveSections[0].EndOffset,
|
|
|
|
netDevice->ReceiveSections[0].SubAllocationSize,
|
|
|
|
netDevice->ReceiveSections[0].NumSubAllocations);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
/*
|
|
|
|
* For 1st release, there should only be 1 section that represents the
|
|
|
|
* entire receive buffer
|
|
|
|
*/
|
2009-07-13 16:34:54 -06:00
|
|
|
if (netDevice->ReceiveSectionCount != 1 ||
|
2009-09-02 11:33:05 -06:00
|
|
|
netDevice->ReceiveSections->Offset != 0) {
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
NetVscDestroyReceiveBuffer(netDevice);
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
PutNetDevice(Device);
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:33:05 -06:00
|
|
|
int ret = 0;
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-08-28 17:20:53 -06:00
|
|
|
struct nvsp_message *initPacket;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
|
|
|
netDevice = GetOutboundNetDevice(Device);
|
2009-09-02 11:33:05 -06:00
|
|
|
if (!netDevice) {
|
|
|
|
DPRINT_ERR(NETVSC, "unable to get net device..."
|
|
|
|
"device being destroyed?");
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ASSERT(netDevice->SendBufferSize > 0);
|
2009-09-02 11:33:05 -06:00
|
|
|
/* page-size grandularity */
|
|
|
|
ASSERT((netDevice->SendBufferSize & (PAGE_SIZE - 1)) == 0);
|
|
|
|
|
|
|
|
netDevice->SendBuffer =
|
|
|
|
osd_PageAlloc(netDevice->SendBufferSize >> PAGE_SHIFT);
|
|
|
|
if (!netDevice->SendBuffer) {
|
|
|
|
DPRINT_ERR(NETVSC, "unable to allocate send buffer of size %d",
|
|
|
|
netDevice->SendBufferSize);
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
2009-09-02 11:33:05 -06:00
|
|
|
/* page-aligned buffer */
|
|
|
|
ASSERT(((unsigned long)netDevice->SendBuffer & (PAGE_SIZE - 1)) == 0);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_INFO(NETVSC, "Establishing send buffer's GPADL...");
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/*
|
|
|
|
* Establish the gpadl handle for this buffer on this
|
|
|
|
* channel. Note: This call uses the vmbus connection rather
|
|
|
|
* than the channel to establish the gpadl handle.
|
|
|
|
*/
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = Device->Driver->VmbusChannelInterface.EstablishGpadl(Device,
|
2009-09-02 11:33:05 -06:00
|
|
|
netDevice->SendBuffer,
|
|
|
|
netDevice->SendBufferSize,
|
|
|
|
&netDevice->SendBufferGpadlHandle);
|
|
|
|
if (ret != 0) {
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_ERR(NETVSC, "unable to establish send buffer's gpadl");
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-29 16:40:18 -06:00
|
|
|
/* osd_WaitEventWait(ext->ChannelInitEvent); */
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Notify the NetVsp of the gpadl handle */
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendSendBuffer...");
|
|
|
|
|
|
|
|
initPacket = &netDevice->ChannelInitPacket;
|
|
|
|
|
2009-08-28 17:20:53 -06:00
|
|
|
memset(initPacket, 0, sizeof(struct nvsp_message));
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
initPacket->Header.MessageType = NvspMessage1TypeSendSendBuffer;
|
|
|
|
initPacket->Messages.Version1Messages.SendReceiveBuffer.GpadlHandle = netDevice->SendBufferGpadlHandle;
|
|
|
|
initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_SEND_BUFFER_ID;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Send the gpadl notification request */
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
|
2009-09-02 11:33:05 -06:00
|
|
|
initPacket, sizeof(struct nvsp_message),
|
|
|
|
(unsigned long)initPacket,
|
|
|
|
VmbusPacketTypeDataInBand,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(NETVSC,
|
|
|
|
"unable to send receive buffer's gpadl to netvsp");
|
2009-07-13 16:34:54 -06:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-29 16:40:18 -06:00
|
|
|
osd_WaitEventWait(netDevice->ChannelInitEvent);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Check the response */
|
2009-09-02 11:33:05 -06:00
|
|
|
if (initPacket->Messages.Version1Messages.SendSendBufferComplete.Status != NvspStatusSuccess) {
|
|
|
|
DPRINT_ERR(NETVSC, "Unable to complete send buffer "
|
|
|
|
"initialzation with NetVsp - status %d",
|
|
|
|
initPacket->Messages.Version1Messages.SendSendBufferComplete.Status);
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
netDevice->SendSectionSize = initPacket->Messages.Version1Messages.SendSendBufferComplete.SectionSize;
|
|
|
|
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
NetVscDestroySendBuffer(netDevice);
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
PutNetDevice(Device);
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:35:56 -06:00
|
|
|
static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-08-28 17:20:53 -06:00
|
|
|
struct nvsp_message *revokePacket;
|
2009-09-02 11:33:05 -06:00
|
|
|
int ret = 0;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/*
|
|
|
|
* If we got a section count, it means we received a
|
|
|
|
* SendReceiveBufferComplete msg (ie sent
|
|
|
|
* NvspMessage1TypeSendReceiveBuffer msg) therefore, we need
|
|
|
|
* to send a revoke msg here
|
|
|
|
*/
|
2009-09-02 11:33:05 -06:00
|
|
|
if (NetDevice->ReceiveSectionCount) {
|
|
|
|
DPRINT_INFO(NETVSC,
|
|
|
|
"Sending NvspMessage1TypeRevokeReceiveBuffer...");
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Send the revoke receive buffer */
|
2009-07-13 16:34:54 -06:00
|
|
|
revokePacket = &NetDevice->RevokePacket;
|
2009-08-28 17:20:53 -06:00
|
|
|
memset(revokePacket, 0, sizeof(struct nvsp_message));
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
revokePacket->Header.MessageType = NvspMessage1TypeRevokeReceiveBuffer;
|
|
|
|
revokePacket->Messages.Version1Messages.RevokeReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID;
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket(
|
|
|
|
NetDevice->Device,
|
|
|
|
revokePacket,
|
|
|
|
sizeof(struct nvsp_message),
|
|
|
|
(unsigned long)revokePacket,
|
|
|
|
VmbusPacketTypeDataInBand, 0);
|
2009-07-27 14:47:24 -06:00
|
|
|
/*
|
|
|
|
* If we failed here, we might as well return and
|
|
|
|
* have a leak rather than continue and a bugchk
|
|
|
|
*/
|
2009-09-02 11:33:05 -06:00
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(NETVSC, "unable to send revoke receive "
|
|
|
|
"buffer to netvsp");
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Teardown the gpadl on the vsp end */
|
2009-09-02 11:33:05 -06:00
|
|
|
if (NetDevice->ReceiveBufferGpadlHandle) {
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_INFO(NETVSC, "Tearing down receive buffer's GPADL...");
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
ret = NetDevice->Device->Driver->VmbusChannelInterface.TeardownGpadl(
|
|
|
|
NetDevice->Device,
|
|
|
|
NetDevice->ReceiveBufferGpadlHandle);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* If we failed here, we might as well return and have a leak rather than continue and a bugchk */
|
2009-09-02 11:33:05 -06:00
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(NETVSC,
|
|
|
|
"unable to teardown receive buffer's gpadl");
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
NetDevice->ReceiveBufferGpadlHandle = 0;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
if (NetDevice->ReceiveBuffer) {
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_INFO(NETVSC, "Freeing up receive buffer...");
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Free up the receive buffer */
|
2009-09-02 11:33:05 -06:00
|
|
|
osd_PageFree(NetDevice->ReceiveBuffer,
|
|
|
|
NetDevice->ReceiveBufferSize >> PAGE_SHIFT);
|
2009-07-13 16:34:54 -06:00
|
|
|
NetDevice->ReceiveBuffer = NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
if (NetDevice->ReceiveSections) {
|
|
|
|
NetDevice->ReceiveSectionCount = 0;
|
2009-07-15 13:48:29 -06:00
|
|
|
kfree(NetDevice->ReceiveSections);
|
2009-07-13 16:34:54 -06:00
|
|
|
NetDevice->ReceiveSections = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:35:56 -06:00
|
|
|
static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-08-28 17:20:53 -06:00
|
|
|
struct nvsp_message *revokePacket;
|
2009-09-02 11:33:05 -06:00
|
|
|
int ret = 0;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/*
|
|
|
|
* If we got a section count, it means we received a
|
|
|
|
* SendReceiveBufferComplete msg (ie sent
|
|
|
|
* NvspMessage1TypeSendReceiveBuffer msg) therefore, we need
|
|
|
|
* to send a revoke msg here
|
|
|
|
*/
|
2009-09-02 11:33:05 -06:00
|
|
|
if (NetDevice->SendSectionSize) {
|
|
|
|
DPRINT_INFO(NETVSC,
|
|
|
|
"Sending NvspMessage1TypeRevokeSendBuffer...");
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Send the revoke send buffer */
|
2009-07-13 16:34:54 -06:00
|
|
|
revokePacket = &NetDevice->RevokePacket;
|
2009-08-28 17:20:53 -06:00
|
|
|
memset(revokePacket, 0, sizeof(struct nvsp_message));
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
revokePacket->Header.MessageType = NvspMessage1TypeRevokeSendBuffer;
|
|
|
|
revokePacket->Messages.Version1Messages.RevokeSendBuffer.Id = NETVSC_SEND_BUFFER_ID;
|
|
|
|
|
|
|
|
ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket(NetDevice->Device,
|
2009-09-02 11:33:05 -06:00
|
|
|
revokePacket,
|
|
|
|
sizeof(struct nvsp_message),
|
|
|
|
(unsigned long)revokePacket,
|
|
|
|
VmbusPacketTypeDataInBand, 0);
|
|
|
|
/*
|
|
|
|
* If we failed here, we might as well return and have a leak
|
|
|
|
* rather than continue and a bugchk
|
|
|
|
*/
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(NETVSC, "unable to send revoke send buffer "
|
|
|
|
"to netvsp");
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Teardown the gpadl on the vsp end */
|
2009-09-02 11:33:05 -06:00
|
|
|
if (NetDevice->SendBufferGpadlHandle) {
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_INFO(NETVSC, "Tearing down send buffer's GPADL...");
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
ret = NetDevice->Device->Driver->VmbusChannelInterface.TeardownGpadl(NetDevice->Device, NetDevice->SendBufferGpadlHandle);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
/*
|
|
|
|
* If we failed here, we might as well return and have a leak
|
|
|
|
* rather than continue and a bugchk
|
|
|
|
*/
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(NETVSC, "unable to teardown send buffer's "
|
|
|
|
"gpadl");
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
NetDevice->SendBufferGpadlHandle = 0;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
if (NetDevice->SendBuffer) {
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_INFO(NETVSC, "Freeing up send buffer...");
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Free up the receive buffer */
|
2009-09-02 11:33:05 -06:00
|
|
|
osd_PageFree(NetDevice->SendBuffer,
|
|
|
|
NetDevice->SendBufferSize >> PAGE_SHIFT);
|
2009-07-13 16:34:54 -06:00
|
|
|
NetDevice->SendBuffer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
static int NetVscConnectToVsp(struct hv_device *Device)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:33:05 -06:00
|
|
|
int ret;
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-08-28 17:20:53 -06:00
|
|
|
struct nvsp_message *initPacket;
|
2009-07-13 16:34:54 -06:00
|
|
|
int ndisVersion;
|
|
|
|
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
|
|
|
netDevice = GetOutboundNetDevice(Device);
|
2009-09-02 11:33:05 -06:00
|
|
|
if (!netDevice) {
|
|
|
|
DPRINT_ERR(NETVSC, "unable to get net device..."
|
|
|
|
"device being destroyed?");
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
initPacket = &netDevice->ChannelInitPacket;
|
|
|
|
|
2009-08-28 17:20:53 -06:00
|
|
|
memset(initPacket, 0, sizeof(struct nvsp_message));
|
2009-07-13 16:34:54 -06:00
|
|
|
initPacket->Header.MessageType = NvspMessageTypeInit;
|
2009-09-02 11:33:05 -06:00
|
|
|
initPacket->Messages.InitMessages.Init.MinProtocolVersion = NVSP_MIN_PROTOCOL_VERSION;
|
|
|
|
initPacket->Messages.InitMessages.Init.MaxProtocolVersion = NVSP_MAX_PROTOCOL_VERSION;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_INFO(NETVSC, "Sending NvspMessageTypeInit...");
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Send the init request */
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
|
2009-09-02 11:33:05 -06:00
|
|
|
initPacket,
|
|
|
|
sizeof(struct nvsp_message),
|
|
|
|
(unsigned long)initPacket,
|
|
|
|
VmbusPacketTypeDataInBand,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
|
|
|
|
if (ret != 0) {
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_ERR(NETVSC, "unable to send NvspMessageTypeInit");
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-29 16:40:18 -06:00
|
|
|
osd_WaitEventWait(netDevice->ChannelInitEvent);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Now, check the response */
|
|
|
|
/* ASSERT(initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength <= MAX_MULTIPAGE_BUFFER_COUNT); */
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_INFO(NETVSC, "NvspMessageTypeInit status(%d) max mdl chain (%d)",
|
|
|
|
initPacket->Messages.InitMessages.InitComplete.Status,
|
|
|
|
initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength);
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
if (initPacket->Messages.InitMessages.InitComplete.Status !=
|
|
|
|
NvspStatusSuccess) {
|
|
|
|
DPRINT_ERR(NETVSC,
|
|
|
|
"unable to initialize with netvsp (status 0x%x)",
|
|
|
|
initPacket->Messages.InitMessages.InitComplete.Status);
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
if (initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion != NVSP_PROTOCOL_VERSION_1) {
|
|
|
|
DPRINT_ERR(NETVSC, "unable to initialize with netvsp "
|
|
|
|
"(version expected 1 got %d)",
|
|
|
|
initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion);
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendNdisVersion...");
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Send the ndis version */
|
2009-08-28 17:20:53 -06:00
|
|
|
memset(initPacket, 0, sizeof(struct nvsp_message));
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
ndisVersion = 0x00050000;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
initPacket->Header.MessageType = NvspMessage1TypeSendNdisVersion;
|
|
|
|
initPacket->Messages.Version1Messages.SendNdisVersion.NdisMajorVersion =
|
|
|
|
(ndisVersion & 0xFFFF0000) >> 16;
|
|
|
|
initPacket->Messages.Version1Messages.SendNdisVersion.NdisMinorVersion =
|
|
|
|
ndisVersion & 0xFFFF;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Send the init request */
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
|
2009-09-02 11:33:05 -06:00
|
|
|
initPacket,
|
|
|
|
sizeof(struct nvsp_message),
|
|
|
|
(unsigned long)initPacket,
|
|
|
|
VmbusPacketTypeDataInBand, 0);
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(NETVSC,
|
|
|
|
"unable to send NvspMessage1TypeSendNdisVersion");
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
2009-07-27 14:47:24 -06:00
|
|
|
/*
|
|
|
|
* BUGBUG - We have to wait for the above msg since the
|
|
|
|
* netvsp uses KMCL which acknowledges packet (completion
|
|
|
|
* packet) since our Vmbus always set the
|
|
|
|
* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED flag
|
|
|
|
*/
|
2009-07-29 16:40:18 -06:00
|
|
|
/* osd_WaitEventWait(NetVscChannel->ChannelInitEvent); */
|
2009-07-27 14:47:24 -06:00
|
|
|
|
|
|
|
/* Post the big receive buffer to NetVSP */
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = NetVscInitializeReceiveBufferWithNetVsp(Device);
|
|
|
|
if (ret == 0)
|
|
|
|
ret = NetVscInitializeSendBufferWithNetVsp(Device);
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
PutNetDevice(Device);
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:35:56 -06:00
|
|
|
static void NetVscDisconnectFromVsp(struct netvsc_device *NetDevice)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
|
|
|
NetVscDestroyReceiveBuffer(NetDevice);
|
|
|
|
NetVscDestroySendBuffer(NetDevice);
|
|
|
|
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
/**
|
|
|
|
* NetVscOnDeviceAdd - Callback when the device belonging to this driver is added
|
|
|
|
*/
|
|
|
|
static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:33:05 -06:00
|
|
|
int ret = 0;
|
2009-07-13 16:34:54 -06:00
|
|
|
int i;
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-09-11 19:46:43 -06:00
|
|
|
struct hv_netvsc_packet *packet, *pos;
|
2009-09-02 11:33:05 -06:00
|
|
|
struct netvsc_driver *netDriver =
|
|
|
|
(struct netvsc_driver *)Device->Driver;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
|
|
|
netDevice = AllocNetDevice(Device);
|
2009-09-02 11:33:05 -06:00
|
|
|
if (!netDevice) {
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_DBG(NETVSC, "netvsc channel object allocated - %p", netDevice);
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Initialize the NetVSC channel extension */
|
2009-07-13 16:34:54 -06:00
|
|
|
netDevice->ReceiveBufferSize = NETVSC_RECEIVE_BUFFER_SIZE;
|
2009-07-15 15:56:15 -06:00
|
|
|
spin_lock_init(&netDevice->receive_packet_list_lock);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
netDevice->SendBufferSize = NETVSC_SEND_BUFFER_SIZE;
|
|
|
|
|
2009-09-11 19:46:43 -06:00
|
|
|
INIT_LIST_HEAD(&netDevice->ReceivePacketList);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
for (i = 0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++) {
|
|
|
|
packet = kzalloc(sizeof(struct hv_netvsc_packet) +
|
|
|
|
(NETVSC_RECEIVE_SG_COUNT *
|
|
|
|
sizeof(struct hv_page_buffer)), GFP_KERNEL);
|
|
|
|
if (!packet) {
|
|
|
|
DPRINT_DBG(NETVSC, "unable to allocate netvsc pkts "
|
|
|
|
"for receive pool (wanted %d got %d)",
|
|
|
|
NETVSC_RECEIVE_PACKETLIST_COUNT, i);
|
2009-07-13 16:34:54 -06:00
|
|
|
break;
|
|
|
|
}
|
2009-09-11 19:46:43 -06:00
|
|
|
list_add_tail(&packet->ListEntry,
|
|
|
|
&netDevice->ReceivePacketList);
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
2009-07-29 16:40:18 -06:00
|
|
|
netDevice->ChannelInitEvent = osd_WaitEventCreate();
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Open the channel */
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = Device->Driver->VmbusChannelInterface.Open(Device,
|
2009-09-02 11:33:05 -06:00
|
|
|
netDriver->RingBufferSize,
|
|
|
|
netDriver->RingBufferSize,
|
|
|
|
NULL, 0,
|
|
|
|
NetVscOnChannelCallback,
|
|
|
|
Device);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
if (ret != 0) {
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_ERR(NETVSC, "unable to open channel: %d", ret);
|
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Channel is opened */
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_INFO(NETVSC, "*** NetVSC channel opened successfully! ***");
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Connect with the NetVsp */
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = NetVscConnectToVsp(Device);
|
2009-09-02 11:33:05 -06:00
|
|
|
if (ret != 0) {
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_ERR(NETVSC, "unable to connect to NetVSP - %d", ret);
|
|
|
|
ret = -1;
|
|
|
|
goto Close;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
DPRINT_INFO(NETVSC, "*** NetVSC channel handshake result - %d ***",
|
|
|
|
ret);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
Close:
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Now, we can close the channel safely */
|
2009-07-13 16:34:54 -06:00
|
|
|
Device->Driver->VmbusChannelInterface.Close(Device);
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
if (netDevice) {
|
2009-07-29 15:00:10 -06:00
|
|
|
kfree(netDevice->ChannelInitEvent);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-11 19:46:43 -06:00
|
|
|
list_for_each_entry_safe(packet, pos,
|
|
|
|
&netDevice->ReceivePacketList,
|
|
|
|
ListEntry) {
|
|
|
|
list_del(&packet->ListEntry);
|
2009-07-15 13:48:29 -06:00
|
|
|
kfree(packet);
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseOutboundNetDevice(Device);
|
|
|
|
ReleaseInboundNetDevice(Device);
|
|
|
|
|
|
|
|
FreeNetDevice(netDevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
/**
|
|
|
|
* NetVscOnDeviceRemove - Callback when the root bus device is removed
|
|
|
|
*/
|
|
|
|
static int NetVscOnDeviceRemove(struct hv_device *Device)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-09-11 19:46:43 -06:00
|
|
|
struct hv_netvsc_packet *netvscPacket, *pos;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
DPRINT_INFO(NETVSC, "Disabling outbound traffic on net device (%p)...",
|
|
|
|
Device->Extension);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Stop outbound traffic ie sends and receives completions */
|
2009-07-13 16:34:54 -06:00
|
|
|
netDevice = ReleaseOutboundNetDevice(Device);
|
2009-09-02 11:33:05 -06:00
|
|
|
if (!netDevice) {
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_ERR(NETVSC, "No net device present!!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Wait for all send completions */
|
2009-09-02 11:33:05 -06:00
|
|
|
while (atomic_read(&netDevice->NumOutstandingSends)) {
|
|
|
|
DPRINT_INFO(NETVSC, "waiting for %d requests to complete...",
|
|
|
|
atomic_read(&netDevice->NumOutstandingSends));
|
2009-07-16 12:50:41 -06:00
|
|
|
udelay(100);
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_INFO(NETVSC, "Disconnecting from netvsp...");
|
|
|
|
|
|
|
|
NetVscDisconnectFromVsp(netDevice);
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
DPRINT_INFO(NETVSC, "Disabling inbound traffic on net device (%p)...",
|
|
|
|
Device->Extension);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Stop inbound traffic ie receives and sends completions */
|
2009-07-13 16:34:54 -06:00
|
|
|
netDevice = ReleaseInboundNetDevice(Device);
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* At this point, no one should be accessing netDevice except in here */
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_INFO(NETVSC, "net device (%p) safe to remove", netDevice);
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Now, we can close the channel safely */
|
2009-07-13 16:34:54 -06:00
|
|
|
Device->Driver->VmbusChannelInterface.Close(Device);
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Release all resources */
|
2009-09-11 19:46:43 -06:00
|
|
|
list_for_each_entry_safe(netvscPacket, pos,
|
|
|
|
&netDevice->ReceivePacketList, ListEntry) {
|
|
|
|
list_del(&netvscPacket->ListEntry);
|
2009-07-15 13:48:29 -06:00
|
|
|
kfree(netvscPacket);
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
|
|
|
|
2009-07-29 15:00:10 -06:00
|
|
|
kfree(netDevice->ChannelInitEvent);
|
2009-07-13 16:34:54 -06:00
|
|
|
FreeNetDevice(netDevice);
|
|
|
|
|
|
|
|
DPRINT_EXIT(NETVSC);
|
2009-09-02 11:33:05 -06:00
|
|
|
return 0;
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
/**
|
|
|
|
* NetVscOnCleanup - Perform any cleanup when the driver is removed
|
|
|
|
*/
|
|
|
|
static void NetVscOnCleanup(struct hv_driver *drv)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
static void NetVscOnSendCompletion(struct hv_device *Device,
|
|
|
|
struct vmpacket_descriptor *Packet)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-08-28 17:20:53 -06:00
|
|
|
struct nvsp_message *nvspPacket;
|
2009-07-29 06:10:10 -06:00
|
|
|
struct hv_netvsc_packet *nvscPacket;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
|
|
|
netDevice = GetInboundNetDevice(Device);
|
2009-09-02 11:33:05 -06:00
|
|
|
if (!netDevice) {
|
|
|
|
DPRINT_ERR(NETVSC, "unable to get net device..."
|
|
|
|
"device being destroyed?");
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-28 17:20:53 -06:00
|
|
|
nvspPacket = (struct nvsp_message *)((unsigned long)Packet + (Packet->DataOffset8 << 3));
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
DPRINT_DBG(NETVSC, "send completion packet - type %d",
|
|
|
|
nvspPacket->Header.MessageType);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
if ((nvspPacket->Header.MessageType == NvspMessageTypeInitComplete) ||
|
|
|
|
(nvspPacket->Header.MessageType ==
|
|
|
|
NvspMessage1TypeSendReceiveBufferComplete) ||
|
|
|
|
(nvspPacket->Header.MessageType ==
|
|
|
|
NvspMessage1TypeSendSendBufferComplete)) {
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Copy the response back */
|
2009-09-02 11:33:05 -06:00
|
|
|
memcpy(&netDevice->ChannelInitPacket, nvspPacket,
|
|
|
|
sizeof(struct nvsp_message));
|
2009-07-29 16:40:18 -06:00
|
|
|
osd_WaitEventSet(netDevice->ChannelInitEvent);
|
2009-09-02 11:33:05 -06:00
|
|
|
} else if (nvspPacket->Header.MessageType ==
|
|
|
|
NvspMessage1TypeSendRNDISPacketComplete) {
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Get the send context */
|
2009-07-29 06:10:10 -06:00
|
|
|
nvscPacket = (struct hv_netvsc_packet *)(unsigned long)Packet->TransactionId;
|
2009-07-13 16:34:54 -06:00
|
|
|
ASSERT(nvscPacket);
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Notify the layer above us */
|
2009-07-13 16:34:54 -06:00
|
|
|
nvscPacket->Completion.Send.OnSendCompletion(nvscPacket->Completion.Send.SendCompletionContext);
|
|
|
|
|
2009-07-29 15:00:12 -06:00
|
|
|
atomic_dec(&netDevice->NumOutstandingSends);
|
2009-09-02 11:33:05 -06:00
|
|
|
} else {
|
|
|
|
DPRINT_ERR(NETVSC, "Unknown send completion packet type - "
|
|
|
|
"%d received!!", nvspPacket->Header.MessageType);
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
PutNetDevice(Device);
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
static int NetVscOnSend(struct hv_device *Device,
|
|
|
|
struct hv_netvsc_packet *Packet)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-09-02 11:33:05 -06:00
|
|
|
int ret = 0;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-08-28 17:20:53 -06:00
|
|
|
struct nvsp_message sendMessage;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
|
|
|
netDevice = GetOutboundNetDevice(Device);
|
2009-09-02 11:33:05 -06:00
|
|
|
if (!netDevice) {
|
|
|
|
DPRINT_ERR(NETVSC, "net device (%p) shutting down..."
|
|
|
|
"ignoring outbound packets", netDevice);
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendMessage.Header.MessageType = NvspMessage1TypeSendRNDISPacket;
|
2009-09-02 11:33:05 -06:00
|
|
|
if (Packet->IsDataPacket) {
|
|
|
|
/* 0 is RMC_DATA; */
|
|
|
|
sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 0;
|
|
|
|
} else {
|
|
|
|
/* 1 is RMC_CONTROL; */
|
|
|
|
sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 1;
|
|
|
|
}
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Not using send buffer section */
|
2009-09-02 11:33:05 -06:00
|
|
|
sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionIndex = 0xFFFFFFFF;
|
|
|
|
sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionSize = 0;
|
|
|
|
|
|
|
|
if (Packet->PageBufferCount) {
|
|
|
|
ret = Device->Driver->VmbusChannelInterface.SendPacketPageBuffer(
|
|
|
|
Device, Packet->PageBuffers,
|
|
|
|
Packet->PageBufferCount,
|
|
|
|
&sendMessage,
|
|
|
|
sizeof(struct nvsp_message),
|
|
|
|
(unsigned long)Packet);
|
|
|
|
} else {
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
|
2009-09-02 11:33:05 -06:00
|
|
|
&sendMessage,
|
|
|
|
sizeof(struct nvsp_message),
|
|
|
|
(unsigned long)Packet,
|
|
|
|
VmbusPacketTypeDataInBand,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != 0)
|
2009-09-02 11:33:05 -06:00
|
|
|
DPRINT_ERR(NETVSC, "Unable to send packet %p ret %d",
|
|
|
|
Packet, ret);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-29 15:00:12 -06:00
|
|
|
atomic_inc(&netDevice->NumOutstandingSends);
|
2009-07-13 16:34:54 -06:00
|
|
|
PutNetDevice(Device);
|
|
|
|
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
static void NetVscOnReceive(struct hv_device *Device,
|
|
|
|
struct vmpacket_descriptor *Packet)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-08-27 17:02:36 -06:00
|
|
|
struct vmtransfer_page_packet_header *vmxferpagePacket;
|
2009-08-28 17:20:53 -06:00
|
|
|
struct nvsp_message *nvspPacket;
|
2009-09-02 11:33:05 -06:00
|
|
|
struct hv_netvsc_packet *netvscPacket = NULL;
|
2009-07-14 16:12:46 -06:00
|
|
|
unsigned long start;
|
|
|
|
unsigned long end, endVirtual;
|
2009-08-27 16:58:15 -06:00
|
|
|
/* struct netvsc_driver *netvscDriver; */
|
2009-09-02 11:33:05 -06:00
|
|
|
struct xferpage_packet *xferpagePacket = NULL;
|
|
|
|
int i, j;
|
|
|
|
int count = 0, bytesRemain = 0;
|
2009-07-15 15:56:15 -06:00
|
|
|
unsigned long flags;
|
2009-09-11 19:46:43 -06:00
|
|
|
LIST_HEAD(listHead);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
|
|
|
netDevice = GetInboundNetDevice(Device);
|
2009-09-02 11:33:05 -06:00
|
|
|
if (!netDevice) {
|
|
|
|
DPRINT_ERR(NETVSC, "unable to get net device..."
|
|
|
|
"device being destroyed?");
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
/*
|
|
|
|
* All inbound packets other than send completion should be xfer page
|
|
|
|
* packet
|
|
|
|
*/
|
|
|
|
if (Packet->Type != VmbusPacketTypeDataUsingTransferPages) {
|
|
|
|
DPRINT_ERR(NETVSC, "Unknown packet type received - %d",
|
|
|
|
Packet->Type);
|
2009-07-13 16:34:54 -06:00
|
|
|
PutNetDevice(Device);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
nvspPacket = (struct nvsp_message *)((unsigned long)Packet +
|
|
|
|
(Packet->DataOffset8 << 3));
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Make sure this is a valid nvsp packet */
|
2009-09-02 11:33:05 -06:00
|
|
|
if (nvspPacket->Header.MessageType != NvspMessage1TypeSendRNDISPacket) {
|
|
|
|
DPRINT_ERR(NETVSC, "Unknown nvsp packet type received - %d",
|
|
|
|
nvspPacket->Header.MessageType);
|
2009-07-13 16:34:54 -06:00
|
|
|
PutNetDevice(Device);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
DPRINT_DBG(NETVSC, "NVSP packet received - type %d",
|
|
|
|
nvspPacket->Header.MessageType);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-08-27 17:02:36 -06:00
|
|
|
vmxferpagePacket = (struct vmtransfer_page_packet_header *)Packet;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
if (vmxferpagePacket->TransferPageSetId != NETVSC_RECEIVE_BUFFER_ID) {
|
|
|
|
DPRINT_ERR(NETVSC, "Invalid xfer page set id - "
|
|
|
|
"expecting %x got %x", NETVSC_RECEIVE_BUFFER_ID,
|
|
|
|
vmxferpagePacket->TransferPageSetId);
|
2009-07-13 16:34:54 -06:00
|
|
|
PutNetDevice(Device);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
DPRINT_DBG(NETVSC, "xfer page - range count %d",
|
|
|
|
vmxferpagePacket->RangeCount);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/*
|
|
|
|
* Grab free packets (range count + 1) to represent this xfer
|
|
|
|
* page packet. +1 to represent the xfer page packet itself.
|
|
|
|
* We grab it here so that we know exactly how many we can
|
|
|
|
* fulfil
|
|
|
|
*/
|
2009-07-15 15:56:15 -06:00
|
|
|
spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags);
|
2009-09-11 19:46:43 -06:00
|
|
|
while (!list_empty(&netDevice->ReceivePacketList)) {
|
2009-10-28 16:23:37 -06:00
|
|
|
list_move_tail(netDevice->ReceivePacketList.next, &listHead);
|
2009-07-13 16:34:54 -06:00
|
|
|
if (++count == vmxferpagePacket->RangeCount + 1)
|
|
|
|
break;
|
|
|
|
}
|
2009-07-15 15:56:15 -06:00
|
|
|
spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/*
|
|
|
|
* We need at least 2 netvsc pkts (1 to represent the xfer
|
|
|
|
* page and at least 1 for the range) i.e. we can handled
|
|
|
|
* some of the xfer page packet ranges...
|
|
|
|
*/
|
2009-09-02 11:33:05 -06:00
|
|
|
if (count < 2) {
|
|
|
|
DPRINT_ERR(NETVSC, "Got only %d netvsc pkt...needed %d pkts. "
|
|
|
|
"Dropping this xfer page packet completely!",
|
|
|
|
count, vmxferpagePacket->RangeCount + 1);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Return it to the freelist */
|
2009-07-15 15:56:15 -06:00
|
|
|
spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags);
|
2009-09-02 11:33:05 -06:00
|
|
|
for (i = count; i != 0; i--) {
|
2009-10-28 16:23:37 -06:00
|
|
|
list_move_tail(listHead.next,
|
2009-09-11 19:46:43 -06:00
|
|
|
&netDevice->ReceivePacketList);
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
2009-09-02 11:33:05 -06:00
|
|
|
spin_unlock_irqrestore(&netDevice->receive_packet_list_lock,
|
|
|
|
flags);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
NetVscSendReceiveCompletion(Device,
|
|
|
|
vmxferpagePacket->d.TransactionId);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
PutNetDevice(Device);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Remove the 1st packet to represent the xfer page packet itself */
|
2009-10-28 16:23:37 -06:00
|
|
|
xferpagePacket = (struct xferpage_packet*)listHead.next;
|
2009-09-11 19:46:43 -06:00
|
|
|
list_del(&xferpagePacket->ListEntry);
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
/* This is how much we can satisfy */
|
|
|
|
xferpagePacket->Count = count - 1;
|
|
|
|
ASSERT(xferpagePacket->Count > 0 && xferpagePacket->Count <=
|
|
|
|
vmxferpagePacket->RangeCount);
|
|
|
|
|
|
|
|
if (xferpagePacket->Count != vmxferpagePacket->RangeCount) {
|
|
|
|
DPRINT_INFO(NETVSC, "Needed %d netvsc pkts to satisy this xfer "
|
|
|
|
"page...got %d", vmxferpagePacket->RangeCount,
|
|
|
|
xferpagePacket->Count);
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */
|
2009-09-02 11:33:05 -06:00
|
|
|
for (i = 0; i < (count - 1); i++) {
|
2009-10-28 16:23:37 -06:00
|
|
|
netvscPacket = (struct hv_netvsc_packet*)listHead.next;
|
2009-09-11 19:46:43 -06:00
|
|
|
list_del(&netvscPacket->ListEntry);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Initialize the netvsc packet */
|
2009-07-13 16:34:54 -06:00
|
|
|
netvscPacket->XferPagePacket = xferpagePacket;
|
2009-09-02 11:33:05 -06:00
|
|
|
netvscPacket->Completion.Recv.OnReceiveCompletion =
|
|
|
|
NetVscOnReceiveCompletion;
|
|
|
|
netvscPacket->Completion.Recv.ReceiveCompletionContext =
|
|
|
|
netvscPacket;
|
2009-07-13 16:34:54 -06:00
|
|
|
netvscPacket->Device = Device;
|
2009-09-02 11:33:05 -06:00
|
|
|
/* Save this so that we can send it back */
|
|
|
|
netvscPacket->Completion.Recv.ReceiveCompletionTid =
|
|
|
|
vmxferpagePacket->d.TransactionId;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
netvscPacket->TotalDataBufferLength =
|
|
|
|
vmxferpagePacket->Ranges[i].ByteCount;
|
2009-07-13 16:34:54 -06:00
|
|
|
netvscPacket->PageBufferCount = 1;
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
ASSERT(vmxferpagePacket->Ranges[i].ByteOffset +
|
|
|
|
vmxferpagePacket->Ranges[i].ByteCount <
|
|
|
|
netDevice->ReceiveBufferSize);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
netvscPacket->PageBuffers[0].Length =
|
|
|
|
vmxferpagePacket->Ranges[i].ByteCount;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
start = virt_to_phys((void *)((unsigned long)netDevice->ReceiveBuffer + vmxferpagePacket->Ranges[i].ByteOffset));
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
netvscPacket->PageBuffers[0].Pfn = start >> PAGE_SHIFT;
|
2009-07-14 16:12:46 -06:00
|
|
|
endVirtual = (unsigned long)netDevice->ReceiveBuffer
|
2009-07-13 16:34:54 -06:00
|
|
|
+ vmxferpagePacket->Ranges[i].ByteOffset
|
2009-09-02 11:33:05 -06:00
|
|
|
+ vmxferpagePacket->Ranges[i].ByteCount - 1;
|
|
|
|
end = virt_to_phys((void *)endVirtual);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Calculate the page relative offset */
|
2009-09-02 11:33:05 -06:00
|
|
|
netvscPacket->PageBuffers[0].Offset =
|
|
|
|
vmxferpagePacket->Ranges[i].ByteOffset & (PAGE_SIZE - 1);
|
|
|
|
if ((end >> PAGE_SHIFT) != (start >> PAGE_SHIFT)) {
|
|
|
|
/* Handle frame across multiple pages: */
|
|
|
|
netvscPacket->PageBuffers[0].Length =
|
|
|
|
(netvscPacket->PageBuffers[0].Pfn << PAGE_SHIFT)
|
|
|
|
+ PAGE_SIZE - start;
|
|
|
|
bytesRemain = netvscPacket->TotalDataBufferLength -
|
|
|
|
netvscPacket->PageBuffers[0].Length;
|
|
|
|
for (j = 1; j < NETVSC_PACKET_MAXPAGE; j++) {
|
|
|
|
netvscPacket->PageBuffers[j].Offset = 0;
|
|
|
|
if (bytesRemain <= PAGE_SIZE) {
|
|
|
|
netvscPacket->PageBuffers[j].Length = bytesRemain;
|
|
|
|
bytesRemain = 0;
|
|
|
|
} else {
|
|
|
|
netvscPacket->PageBuffers[j].Length = PAGE_SIZE;
|
|
|
|
bytesRemain -= PAGE_SIZE;
|
|
|
|
}
|
|
|
|
netvscPacket->PageBuffers[j].Pfn =
|
|
|
|
virt_to_phys((void *)(endVirtual - bytesRemain)) >> PAGE_SHIFT;
|
|
|
|
netvscPacket->PageBufferCount++;
|
|
|
|
if (bytesRemain == 0)
|
|
|
|
break;
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
2009-09-02 11:33:05 -06:00
|
|
|
ASSERT(bytesRemain == 0);
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
2009-09-02 11:33:05 -06:00
|
|
|
DPRINT_DBG(NETVSC, "[%d] - (abs offset %u len %u) => "
|
|
|
|
"(pfn %llx, offset %u, len %u)", i,
|
|
|
|
vmxferpagePacket->Ranges[i].ByteOffset,
|
|
|
|
vmxferpagePacket->Ranges[i].ByteCount,
|
|
|
|
netvscPacket->PageBuffers[0].Pfn,
|
|
|
|
netvscPacket->PageBuffers[0].Offset,
|
|
|
|
netvscPacket->PageBuffers[0].Length);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Pass it to the upper layer */
|
2009-08-27 16:58:15 -06:00
|
|
|
((struct netvsc_driver *)Device->Driver)->OnReceiveCallback(Device, netvscPacket);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
NetVscOnReceiveCompletion(netvscPacket->Completion.Recv.ReceiveCompletionContext);
|
|
|
|
}
|
|
|
|
|
2009-09-11 19:46:43 -06:00
|
|
|
ASSERT(list_empty(&listHead));
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
PutNetDevice(Device);
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
static void NetVscSendReceiveCompletion(struct hv_device *Device,
|
|
|
|
u64 TransactionId)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-08-28 17:20:53 -06:00
|
|
|
struct nvsp_message recvcompMessage;
|
2009-09-02 11:33:05 -06:00
|
|
|
int retries = 0;
|
|
|
|
int ret;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
DPRINT_DBG(NETVSC, "Sending receive completion pkt - %llx",
|
|
|
|
TransactionId);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
recvcompMessage.Header.MessageType =
|
|
|
|
NvspMessage1TypeSendRNDISPacketComplete;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* FIXME: Pass in the status */
|
2009-07-13 16:34:54 -06:00
|
|
|
recvcompMessage.Messages.Version1Messages.SendRNDISPacketComplete.Status = NvspStatusSuccess;
|
|
|
|
|
|
|
|
retry_send_cmplt:
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Send the completion */
|
2009-07-13 16:34:54 -06:00
|
|
|
ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
|
2009-09-02 11:33:05 -06:00
|
|
|
&recvcompMessage,
|
|
|
|
sizeof(struct nvsp_message),
|
|
|
|
TransactionId,
|
|
|
|
VmbusPacketTypeCompletion, 0);
|
|
|
|
if (ret == 0) {
|
|
|
|
/* success */
|
2009-07-27 14:47:24 -06:00
|
|
|
/* no-op */
|
2009-09-02 11:33:05 -06:00
|
|
|
} else if (ret == -1) {
|
|
|
|
/* no more room...wait a bit and attempt to retry 3 times */
|
2009-07-13 16:34:54 -06:00
|
|
|
retries++;
|
2009-09-02 11:33:05 -06:00
|
|
|
DPRINT_ERR(NETVSC, "unable to send receive completion pkt "
|
|
|
|
"(tid %llx)...retrying %d", TransactionId, retries);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
if (retries < 4) {
|
2009-07-16 12:50:41 -06:00
|
|
|
udelay(100);
|
2009-07-13 16:34:54 -06:00
|
|
|
goto retry_send_cmplt;
|
2009-09-02 11:33:05 -06:00
|
|
|
} else {
|
|
|
|
DPRINT_ERR(NETVSC, "unable to send receive completion "
|
|
|
|
"pkt (tid %llx)...give up retrying",
|
|
|
|
TransactionId);
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
2009-09-02 11:33:05 -06:00
|
|
|
} else {
|
|
|
|
DPRINT_ERR(NETVSC, "unable to send receive completion pkt - "
|
|
|
|
"%llx", TransactionId);
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Send a receive completion packet to RNDIS device (ie NetVsp) */
|
2009-09-02 11:33:05 -06:00
|
|
|
static void NetVscOnReceiveCompletion(void *Context)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:33:05 -06:00
|
|
|
struct hv_netvsc_packet *packet = Context;
|
|
|
|
struct hv_device *device = (struct hv_device *)packet->Device;
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-09-02 11:33:05 -06:00
|
|
|
u64 transactionId = 0;
|
2009-07-15 13:46:44 -06:00
|
|
|
bool fSendReceiveComp = false;
|
2009-07-15 15:56:15 -06:00
|
|
|
unsigned long flags;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
|
|
|
ASSERT(packet->XferPagePacket);
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
/*
|
|
|
|
* Even though it seems logical to do a GetOutboundNetDevice() here to
|
|
|
|
* send out receive completion, we are using GetInboundNetDevice()
|
|
|
|
* since we may have disable outbound traffic already.
|
|
|
|
*/
|
2009-07-13 16:34:54 -06:00
|
|
|
netDevice = GetInboundNetDevice(device);
|
2009-09-02 11:33:05 -06:00
|
|
|
if (!netDevice) {
|
|
|
|
DPRINT_ERR(NETVSC, "unable to get net device..."
|
|
|
|
"device being destroyed?");
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Overloading use of the lock. */
|
2009-07-15 15:56:15 -06:00
|
|
|
spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
ASSERT(packet->XferPagePacket->Count > 0);
|
|
|
|
packet->XferPagePacket->Count--;
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
/*
|
|
|
|
* Last one in the line that represent 1 xfer page packet.
|
|
|
|
* Return the xfer page packet itself to the freelist
|
|
|
|
*/
|
|
|
|
if (packet->XferPagePacket->Count == 0) {
|
2009-07-15 13:46:44 -06:00
|
|
|
fSendReceiveComp = true;
|
2009-07-13 16:34:54 -06:00
|
|
|
transactionId = packet->Completion.Recv.ReceiveCompletionTid;
|
2009-09-11 19:46:43 -06:00
|
|
|
list_add_tail(&packet->XferPagePacket->ListEntry,
|
|
|
|
&netDevice->ReceivePacketList);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Put the packet back */
|
2009-09-11 19:46:43 -06:00
|
|
|
list_add_tail(&packet->ListEntry, &netDevice->ReceivePacketList);
|
2009-07-15 15:56:15 -06:00
|
|
|
spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags);
|
2009-07-13 16:34:54 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Send a receive completion for the xfer page packet */
|
2009-07-13 16:34:54 -06:00
|
|
|
if (fSendReceiveComp)
|
|
|
|
NetVscSendReceiveCompletion(device, transactionId);
|
|
|
|
|
|
|
|
PutNetDevice(device);
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
void NetVscOnChannelCallback(void *Context)
|
2009-07-13 16:34:54 -06:00
|
|
|
{
|
2009-09-02 11:33:05 -06:00
|
|
|
const int netPacketSize = 2048;
|
|
|
|
int ret;
|
|
|
|
struct hv_device *device = Context;
|
2009-09-02 11:35:56 -06:00
|
|
|
struct netvsc_device *netDevice;
|
2009-07-14 16:09:36 -06:00
|
|
|
u32 bytesRecvd;
|
2009-07-14 16:10:26 -06:00
|
|
|
u64 requestId;
|
|
|
|
unsigned char packet[netPacketSize];
|
2009-08-27 17:02:36 -06:00
|
|
|
struct vmpacket_descriptor *desc;
|
2009-09-02 11:33:05 -06:00
|
|
|
unsigned char *buffer = packet;
|
|
|
|
int bufferlen = netPacketSize;
|
2009-07-13 16:34:54 -06:00
|
|
|
|
|
|
|
|
|
|
|
DPRINT_ENTER(NETVSC);
|
|
|
|
|
|
|
|
ASSERT(device);
|
|
|
|
|
|
|
|
netDevice = GetInboundNetDevice(device);
|
2009-09-02 11:33:05 -06:00
|
|
|
if (!netDevice) {
|
|
|
|
DPRINT_ERR(NETVSC, "net device (%p) shutting down..."
|
|
|
|
"ignoring inbound packets", netDevice);
|
2009-07-13 16:34:54 -06:00
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-02 11:33:05 -06:00
|
|
|
do {
|
|
|
|
ret = device->Driver->VmbusChannelInterface.RecvPacketRaw(
|
|
|
|
device, buffer, bufferlen,
|
|
|
|
&bytesRecvd, &requestId);
|
|
|
|
if (ret == 0) {
|
|
|
|
if (bytesRecvd > 0) {
|
|
|
|
DPRINT_DBG(NETVSC, "receive %d bytes, tid %llx",
|
|
|
|
bytesRecvd, requestId);
|
|
|
|
|
|
|
|
desc = (struct vmpacket_descriptor *)buffer;
|
|
|
|
switch (desc->Type) {
|
|
|
|
case VmbusPacketTypeCompletion:
|
|
|
|
NetVscOnSendCompletion(device, desc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VmbusPacketTypeDataUsingTransferPages:
|
|
|
|
NetVscOnReceive(device, desc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DPRINT_ERR(NETVSC,
|
|
|
|
"unhandled packet type %d, "
|
|
|
|
"tid %llx len %d\n",
|
|
|
|
desc->Type, requestId,
|
|
|
|
bytesRecvd);
|
|
|
|
break;
|
2009-07-13 16:34:54 -06:00
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* reset */
|
2009-09-02 11:33:05 -06:00
|
|
|
if (bufferlen > netPacketSize) {
|
2009-07-15 13:48:29 -06:00
|
|
|
kfree(buffer);
|
2009-07-13 16:34:54 -06:00
|
|
|
buffer = packet;
|
|
|
|
bufferlen = netPacketSize;
|
|
|
|
}
|
2009-09-02 11:33:05 -06:00
|
|
|
} else {
|
2009-07-27 14:47:24 -06:00
|
|
|
/* reset */
|
2009-09-02 11:33:05 -06:00
|
|
|
if (bufferlen > netPacketSize) {
|
2009-07-15 13:48:29 -06:00
|
|
|
kfree(buffer);
|
2009-07-13 16:34:54 -06:00
|
|
|
buffer = packet;
|
|
|
|
bufferlen = netPacketSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2009-09-02 11:33:05 -06:00
|
|
|
} else if (ret == -2) {
|
|
|
|
/* Handle large packet */
|
2009-07-15 13:48:01 -06:00
|
|
|
buffer = kmalloc(bytesRecvd, GFP_ATOMIC);
|
2009-09-02 11:33:05 -06:00
|
|
|
if (buffer == NULL) {
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Try again next time around */
|
2009-09-02 11:33:05 -06:00
|
|
|
DPRINT_ERR(NETVSC,
|
|
|
|
"unable to allocate buffer of size "
|
|
|
|
"(%d)!!", bytesRecvd);
|
2009-07-13 16:34:54 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bufferlen = bytesRecvd;
|
2009-09-02 11:33:05 -06:00
|
|
|
} else {
|
2009-07-13 16:34:54 -06:00
|
|
|
ASSERT(0);
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
PutNetDevice(device);
|
|
|
|
DPRINT_EXIT(NETVSC);
|
|
|
|
return;
|
|
|
|
}
|