2009-07-13 17:01:31 -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:
|
|
|
|
* Haiyang Zhang <haiyangz@microsoft.com>
|
|
|
|
* 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/string.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-07-15 12:06:01 -06:00
|
|
|
#include <linux/mm.h>
|
2009-07-16 12:50:41 -06:00
|
|
|
#include <linux/delay.h>
|
2009-08-19 17:14:47 -06:00
|
|
|
#include "osd.h"
|
2009-08-28 17:22:59 -06:00
|
|
|
#include "logging.h"
|
2009-08-28 17:23:49 -06:00
|
|
|
#include "StorVscApi.h"
|
2009-08-28 17:24:48 -06:00
|
|
|
#include "VmbusPacketFormat.h"
|
2009-08-27 16:58:52 -06:00
|
|
|
#include "vstorage.h"
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
|
2009-08-28 17:26:48 -06:00
|
|
|
struct storvsc_request_extension {
|
2009-08-31 23:25:48 -06:00
|
|
|
/* LIST_ENTRY ListEntry; */
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-07-29 06:10:19 -06:00
|
|
|
struct hv_storvsc_request *Request;
|
2009-07-28 09:32:53 -06:00
|
|
|
struct hv_device *Device;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Synchronize the request/response if needed */
|
2009-07-28 11:46:24 -06:00
|
|
|
struct osd_waitevent *WaitEvent;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-27 17:00:24 -06:00
|
|
|
struct vstor_packet VStorPacket;
|
2009-08-28 17:26:48 -06:00
|
|
|
};
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* A storvsc device is a device object that contains a vmbus channel */
|
2009-08-28 17:26:48 -06:00
|
|
|
struct storvsc_device {
|
2009-07-28 09:32:53 -06:00
|
|
|
struct hv_device *Device;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
/* 0 indicates the device is being destroyed */
|
|
|
|
atomic_t RefCount;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-07-29 15:00:12 -06:00
|
|
|
atomic_t NumOutstandingRequests;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/*
|
|
|
|
* Each unique Port/Path/Target represents 1 channel ie scsi
|
|
|
|
* controller. In reality, the pathid, targetid is always 0
|
|
|
|
* and the port is set by us
|
|
|
|
*/
|
2009-08-31 23:25:48 -06:00
|
|
|
unsigned int PortNumber;
|
|
|
|
unsigned char PathId;
|
|
|
|
unsigned char TargetId;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
/* LIST_ENTRY OutstandingRequestList; */
|
|
|
|
/* HANDLE OutstandingRequestLock; */
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Used for vsc/vsp channel reset process */
|
2009-08-28 17:26:48 -06:00
|
|
|
struct storvsc_request_extension InitRequest;
|
|
|
|
struct storvsc_request_extension ResetRequest;
|
|
|
|
};
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
static const char *gDriverName = "storvsc";
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */
|
2009-08-19 17:17:03 -06:00
|
|
|
static const struct hv_guid gStorVscDeviceType = {
|
|
|
|
.data = {
|
|
|
|
0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d,
|
|
|
|
0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f
|
|
|
|
}
|
2009-07-13 17:01:31 -06:00
|
|
|
};
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
|
2009-08-28 17:26:48 -06:00
|
|
|
static inline struct storvsc_device *AllocStorDevice(struct hv_device *Device)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
2009-08-28 17:26:48 -06:00
|
|
|
struct storvsc_device *storDevice;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-28 17:26:48 -06:00
|
|
|
storDevice = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
|
2009-07-13 17:01:31 -06:00
|
|
|
if (!storDevice)
|
|
|
|
return NULL;
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Set to 2 to allow both inbound and outbound traffics */
|
|
|
|
/* (ie GetStorDevice() and MustGetStorDevice()) to proceed. */
|
2009-07-29 15:00:12 -06:00
|
|
|
atomic_cmpxchg(&storDevice->RefCount, 0, 2);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
storDevice->Device = Device;
|
|
|
|
Device->Extension = storDevice;
|
|
|
|
|
|
|
|
return storDevice;
|
|
|
|
}
|
|
|
|
|
2009-08-28 17:26:48 -06:00
|
|
|
static inline void FreeStorDevice(struct storvsc_device *Device)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
2009-08-31 23:25:48 -06:00
|
|
|
ASSERT(atomic_read(&Device->RefCount) == 0);
|
2009-07-15 13:48:29 -06:00
|
|
|
kfree(Device);
|
2009-07-13 17:01:31 -06:00
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Get the stordevice object iff exists and its refcount > 1 */
|
2009-08-31 23:25:48 -06:00
|
|
|
static inline struct storvsc_device *GetStorDevice(struct hv_device *Device)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
2009-08-28 17:26:48 -06:00
|
|
|
struct storvsc_device *storDevice;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-28 17:26:48 -06:00
|
|
|
storDevice = (struct storvsc_device *)Device->Extension;
|
2009-07-29 15:00:12 -06:00
|
|
|
if (storDevice && atomic_read(&storDevice->RefCount) > 1)
|
|
|
|
atomic_inc(&storDevice->RefCount);
|
2009-07-13 17:01:31 -06:00
|
|
|
else
|
|
|
|
storDevice = NULL;
|
|
|
|
|
|
|
|
return storDevice;
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Get the stordevice object iff exists and its refcount > 0 */
|
2009-08-28 17:26:48 -06:00
|
|
|
static inline struct storvsc_device *MustGetStorDevice(struct hv_device *Device)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
2009-08-28 17:26:48 -06:00
|
|
|
struct storvsc_device *storDevice;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-28 17:26:48 -06:00
|
|
|
storDevice = (struct storvsc_device *)Device->Extension;
|
2009-07-29 15:00:12 -06:00
|
|
|
if (storDevice && atomic_read(&storDevice->RefCount))
|
|
|
|
atomic_inc(&storDevice->RefCount);
|
2009-07-13 17:01:31 -06:00
|
|
|
else
|
|
|
|
storDevice = NULL;
|
|
|
|
|
|
|
|
return storDevice;
|
|
|
|
}
|
|
|
|
|
2009-07-28 09:32:53 -06:00
|
|
|
static inline void PutStorDevice(struct hv_device *Device)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
2009-08-28 17:26:48 -06:00
|
|
|
struct storvsc_device *storDevice;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-28 17:26:48 -06:00
|
|
|
storDevice = (struct storvsc_device *)Device->Extension;
|
2009-07-13 17:01:31 -06:00
|
|
|
ASSERT(storDevice);
|
|
|
|
|
2009-07-29 15:00:12 -06:00
|
|
|
atomic_dec(&storDevice->RefCount);
|
|
|
|
ASSERT(atomic_read(&storDevice->RefCount));
|
2009-07-13 17:01:31 -06:00
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Drop ref count to 1 to effectively disable GetStorDevice() */
|
2009-08-28 17:26:48 -06:00
|
|
|
static inline struct storvsc_device *ReleaseStorDevice(struct hv_device *Device)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
2009-08-28 17:26:48 -06:00
|
|
|
struct storvsc_device *storDevice;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-28 17:26:48 -06:00
|
|
|
storDevice = (struct storvsc_device *)Device->Extension;
|
2009-07-13 17:01:31 -06:00
|
|
|
ASSERT(storDevice);
|
|
|
|
|
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(&storDevice->RefCount, 2, 1) != 2)
|
2009-07-16 12:50:41 -06:00
|
|
|
udelay(100);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
return storDevice;
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Drop ref count to 0. No one can use StorDevice object. */
|
2009-08-31 23:25:48 -06:00
|
|
|
static inline struct storvsc_device *FinalReleaseStorDevice(
|
|
|
|
struct hv_device *Device)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
2009-08-28 17:26:48 -06:00
|
|
|
struct storvsc_device *storDevice;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-28 17:26:48 -06:00
|
|
|
storDevice = (struct storvsc_device *)Device->Extension;
|
2009-07-13 17:01:31 -06:00
|
|
|
ASSERT(storDevice);
|
|
|
|
|
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(&storDevice->RefCount, 1, 0) != 1)
|
2009-07-16 12:50:41 -06:00
|
|
|
udelay(100);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
Device->Extension = NULL;
|
|
|
|
return storDevice;
|
|
|
|
}
|
|
|
|
|
2009-07-28 09:32:53 -06:00
|
|
|
static int StorVscChannelInit(struct hv_device *Device)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
2009-08-28 17:26:48 -06:00
|
|
|
struct storvsc_device *storDevice;
|
|
|
|
struct storvsc_request_extension *request;
|
2009-08-27 17:00:24 -06:00
|
|
|
struct vstor_packet *vstorPacket;
|
2009-08-31 23:25:48 -06:00
|
|
|
int ret;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
storDevice = GetStorDevice(Device);
|
2009-08-31 23:25:48 -06:00
|
|
|
if (!storDevice) {
|
|
|
|
DPRINT_ERR(STORVSC, "unable to get stor device..."
|
|
|
|
"device being destroyed?");
|
2009-07-13 17:01:31 -06:00
|
|
|
DPRINT_EXIT(STORVSC);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
request = &storDevice->InitRequest;
|
|
|
|
vstorPacket = &request->VStorPacket;
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
/*
|
|
|
|
* Now, initiate the vsc/vsp initialization protocol on the open
|
|
|
|
* channel
|
|
|
|
*/
|
2009-11-11 14:57:03 -07:00
|
|
|
memset(request, 0, sizeof(struct storvsc_request_extension));
|
2009-07-29 16:40:18 -06:00
|
|
|
request->WaitEvent = osd_WaitEventCreate();
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
vstorPacket->Operation = VStorOperationBeginInitialization;
|
|
|
|
vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
|
|
|
|
|
|
|
|
/*SpinlockAcquire(gDriverExt.packetListLock);
|
|
|
|
INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry);
|
|
|
|
SpinlockRelease(gDriverExt.packetListLock);*/
|
|
|
|
|
|
|
|
DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION...");
|
|
|
|
|
|
|
|
ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket,
|
|
|
|
sizeof(struct vstor_packet),
|
|
|
|
(unsigned long)request,
|
|
|
|
VmbusPacketTypeDataInBand,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(STORVSC,
|
|
|
|
"unable to send BEGIN_INITIALIZATION_OPERATION");
|
2009-07-13 17:01:31 -06:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-29 16:40:18 -06:00
|
|
|
osd_WaitEventWait(request->WaitEvent);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
if (vstorPacket->Operation != VStorOperationCompleteIo ||
|
|
|
|
vstorPacket->Status != 0) {
|
|
|
|
DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed "
|
|
|
|
"(op %d status 0x%x)",
|
|
|
|
vstorPacket->Operation, vstorPacket->Status);
|
2009-07-13 17:01:31 -06:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION...");
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* reuse the packet for version range supported */
|
2009-11-11 14:57:03 -07:00
|
|
|
memset(vstorPacket, 0, sizeof(struct vstor_packet));
|
2009-07-13 17:01:31 -06:00
|
|
|
vstorPacket->Operation = VStorOperationQueryProtocolVersion;
|
|
|
|
vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket->Version.MajorMinor = VMSTOR_PROTOCOL_VERSION_CURRENT;
|
|
|
|
FILL_VMSTOR_REVISION(vstorPacket->Version.Revision);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket,
|
|
|
|
sizeof(struct vstor_packet),
|
|
|
|
(unsigned long)request,
|
|
|
|
VmbusPacketTypeDataInBand,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(STORVSC,
|
|
|
|
"unable to send BEGIN_INITIALIZATION_OPERATION");
|
2009-07-13 17:01:31 -06:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-29 16:40:18 -06:00
|
|
|
osd_WaitEventWait(request->WaitEvent);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* TODO: Check returned version */
|
2009-08-31 23:25:48 -06:00
|
|
|
if (vstorPacket->Operation != VStorOperationCompleteIo ||
|
|
|
|
vstorPacket->Status != 0) {
|
|
|
|
DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed "
|
|
|
|
"(op %d status 0x%x)",
|
|
|
|
vstorPacket->Operation, vstorPacket->Status);
|
2009-07-13 17:01:31 -06:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Query channel properties */
|
2009-07-13 17:01:31 -06:00
|
|
|
DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION...");
|
|
|
|
|
2009-11-11 14:57:03 -07:00
|
|
|
memset(vstorPacket, 0, sizeof(struct vstor_packet));
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket->Operation = VStorOperationQueryProperties;
|
2009-07-13 17:01:31 -06:00
|
|
|
vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket->StorageChannelProperties.PortNumber =
|
|
|
|
storDevice->PortNumber;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket,
|
|
|
|
sizeof(struct vstor_packet),
|
|
|
|
(unsigned long)request,
|
|
|
|
VmbusPacketTypeDataInBand,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(STORVSC,
|
|
|
|
"unable to send QUERY_PROPERTIES_OPERATION");
|
2009-07-13 17:01:31 -06:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-29 16:40:18 -06:00
|
|
|
osd_WaitEventWait(request->WaitEvent);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* TODO: Check returned version */
|
2009-08-31 23:25:48 -06:00
|
|
|
if (vstorPacket->Operation != VStorOperationCompleteIo ||
|
|
|
|
vstorPacket->Status != 0) {
|
|
|
|
DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed "
|
|
|
|
"(op %d status 0x%x)",
|
|
|
|
vstorPacket->Operation, vstorPacket->Status);
|
2009-07-13 17:01:31 -06:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
storDevice->PathId = vstorPacket->StorageChannelProperties.PathId;
|
|
|
|
storDevice->TargetId = vstorPacket->StorageChannelProperties.TargetId;
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x",
|
|
|
|
vstorPacket->StorageChannelProperties.Flags,
|
|
|
|
vstorPacket->StorageChannelProperties.MaxTransferBytes);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION...");
|
|
|
|
|
2009-11-11 14:57:03 -07:00
|
|
|
memset(vstorPacket, 0, sizeof(struct vstor_packet));
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket->Operation = VStorOperationEndInitialization;
|
2009-07-13 17:01:31 -06:00
|
|
|
vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
|
|
|
|
|
|
|
|
ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket,
|
|
|
|
sizeof(struct vstor_packet),
|
|
|
|
(unsigned long)request,
|
|
|
|
VmbusPacketTypeDataInBand,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(STORVSC,
|
|
|
|
"unable to send END_INITIALIZATION_OPERATION");
|
2009-07-13 17:01:31 -06:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-29 16:40:18 -06:00
|
|
|
osd_WaitEventWait(request->WaitEvent);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
if (vstorPacket->Operation != VStorOperationCompleteIo ||
|
|
|
|
vstorPacket->Status != 0) {
|
|
|
|
DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed "
|
|
|
|
"(op %d status 0x%x)",
|
|
|
|
vstorPacket->Operation, vstorPacket->Status);
|
2009-07-13 17:01:31 -06:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****");
|
|
|
|
|
|
|
|
Cleanup:
|
2009-08-31 23:25:48 -06:00
|
|
|
kfree(request->WaitEvent);
|
|
|
|
request->WaitEvent = NULL;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
PutStorDevice(Device);
|
|
|
|
|
|
|
|
DPRINT_EXIT(STORVSC);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-31 23:31:22 -06:00
|
|
|
static void StorVscOnIOCompletion(struct hv_device *Device,
|
|
|
|
struct vstor_packet *VStorPacket,
|
|
|
|
struct storvsc_request_extension *RequestExt)
|
|
|
|
{
|
|
|
|
struct hv_storvsc_request *request;
|
|
|
|
struct storvsc_device *storDevice;
|
|
|
|
|
|
|
|
DPRINT_ENTER(STORVSC);
|
|
|
|
|
|
|
|
storDevice = MustGetStorDevice(Device);
|
|
|
|
if (!storDevice) {
|
|
|
|
DPRINT_ERR(STORVSC, "unable to get stor device..."
|
|
|
|
"device being destroyed?");
|
|
|
|
DPRINT_EXIT(STORVSC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p "
|
|
|
|
"completed bytes xfer %u", RequestExt,
|
|
|
|
VStorPacket->VmSrb.DataTransferLength);
|
|
|
|
|
|
|
|
ASSERT(RequestExt != NULL);
|
|
|
|
ASSERT(RequestExt->Request != NULL);
|
|
|
|
|
|
|
|
request = RequestExt->Request;
|
|
|
|
|
|
|
|
ASSERT(request->OnIOCompletion != NULL);
|
|
|
|
|
|
|
|
/* Copy over the status...etc */
|
|
|
|
request->Status = VStorPacket->VmSrb.ScsiStatus;
|
|
|
|
|
|
|
|
if (request->Status != 0 || VStorPacket->VmSrb.SrbStatus != 1) {
|
|
|
|
DPRINT_WARN(STORVSC,
|
|
|
|
"cmd 0x%x scsi status 0x%x srb status 0x%x\n",
|
|
|
|
request->Cdb[0], VStorPacket->VmSrb.ScsiStatus,
|
|
|
|
VStorPacket->VmSrb.SrbStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((request->Status & 0xFF) == 0x02) {
|
|
|
|
/* CHECK_CONDITION */
|
|
|
|
if (VStorPacket->VmSrb.SrbStatus & 0x80) {
|
|
|
|
/* autosense data available */
|
|
|
|
DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data "
|
|
|
|
"valid - len %d\n", RequestExt,
|
|
|
|
VStorPacket->VmSrb.SenseInfoLength);
|
|
|
|
|
|
|
|
ASSERT(VStorPacket->VmSrb.SenseInfoLength <=
|
|
|
|
request->SenseBufferSize);
|
|
|
|
memcpy(request->SenseBuffer,
|
|
|
|
VStorPacket->VmSrb.SenseData,
|
|
|
|
VStorPacket->VmSrb.SenseInfoLength);
|
|
|
|
|
|
|
|
request->SenseBufferSize =
|
|
|
|
VStorPacket->VmSrb.SenseInfoLength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: */
|
|
|
|
request->BytesXfer = VStorPacket->VmSrb.DataTransferLength;
|
|
|
|
|
|
|
|
request->OnIOCompletion(request);
|
|
|
|
|
|
|
|
atomic_dec(&storDevice->NumOutstandingRequests);
|
|
|
|
|
|
|
|
PutStorDevice(Device);
|
|
|
|
|
|
|
|
DPRINT_EXIT(STORVSC);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void StorVscOnReceive(struct hv_device *Device,
|
|
|
|
struct vstor_packet *VStorPacket,
|
|
|
|
struct storvsc_request_extension *RequestExt)
|
|
|
|
{
|
|
|
|
switch (VStorPacket->Operation) {
|
|
|
|
case VStorOperationCompleteIo:
|
|
|
|
DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION");
|
|
|
|
StorVscOnIOCompletion(Device, VStorPacket, RequestExt);
|
|
|
|
break;
|
|
|
|
case VStorOperationRemoveDevice:
|
|
|
|
DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION");
|
|
|
|
/* TODO: */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DPRINT_INFO(STORVSC, "Unknown operation received - %d",
|
|
|
|
VStorPacket->Operation);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void StorVscOnChannelCallback(void *context)
|
|
|
|
{
|
|
|
|
struct hv_device *device = (struct hv_device *)context;
|
|
|
|
struct storvsc_device *storDevice;
|
|
|
|
u32 bytesRecvd;
|
|
|
|
u64 requestId;
|
|
|
|
unsigned char packet[ALIGN_UP(sizeof(struct vstor_packet), 8)];
|
|
|
|
struct storvsc_request_extension *request;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DPRINT_ENTER(STORVSC);
|
|
|
|
|
|
|
|
ASSERT(device);
|
|
|
|
|
|
|
|
storDevice = MustGetStorDevice(device);
|
|
|
|
if (!storDevice) {
|
|
|
|
DPRINT_ERR(STORVSC, "unable to get stor device..."
|
|
|
|
"device being destroyed?");
|
|
|
|
DPRINT_EXIT(STORVSC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
ret = device->Driver->VmbusChannelInterface.RecvPacket(device,
|
|
|
|
packet,
|
|
|
|
ALIGN_UP(sizeof(struct vstor_packet), 8),
|
|
|
|
&bytesRecvd, &requestId);
|
|
|
|
if (ret == 0 && bytesRecvd > 0) {
|
|
|
|
DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx",
|
|
|
|
bytesRecvd, requestId);
|
|
|
|
|
|
|
|
/* ASSERT(bytesRecvd == sizeof(struct vstor_packet)); */
|
|
|
|
|
|
|
|
request = (struct storvsc_request_extension *)
|
|
|
|
(unsigned long)requestId;
|
|
|
|
ASSERT(request);
|
|
|
|
|
|
|
|
/* if (vstorPacket.Flags & SYNTHETIC_FLAG) */
|
|
|
|
if ((request == &storDevice->InitRequest) ||
|
|
|
|
(request == &storDevice->ResetRequest)) {
|
|
|
|
/* DPRINT_INFO(STORVSC,
|
|
|
|
* "reset completion - operation "
|
|
|
|
* "%u status %u",
|
|
|
|
* vstorPacket.Operation,
|
|
|
|
* vstorPacket.Status); */
|
|
|
|
|
|
|
|
memcpy(&request->VStorPacket, packet,
|
|
|
|
sizeof(struct vstor_packet));
|
|
|
|
|
|
|
|
osd_WaitEventSet(request->WaitEvent);
|
|
|
|
} else {
|
|
|
|
StorVscOnReceive(device,
|
|
|
|
(struct vstor_packet *)packet,
|
|
|
|
request);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* DPRINT_DBG(STORVSC, "nothing else to read..."); */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
PutStorDevice(device);
|
|
|
|
|
|
|
|
DPRINT_EXIT(STORVSC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
static int StorVscConnectToVsp(struct hv_device *Device)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
2009-08-27 17:00:24 -06:00
|
|
|
struct vmstorage_channel_properties props;
|
2009-08-31 23:25:48 -06:00
|
|
|
struct storvsc_driver_object *storDriver;
|
|
|
|
int ret;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
storDriver = (struct storvsc_driver_object *)Device->Driver;
|
2009-11-11 14:57:03 -07:00
|
|
|
memset(&props, 0, sizeof(struct vmstorage_channel_properties));
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Open the channel */
|
2009-07-13 17:01:31 -06:00
|
|
|
ret = Device->Driver->VmbusChannelInterface.Open(Device,
|
2009-08-31 23:25:48 -06:00
|
|
|
storDriver->RingBufferSize,
|
|
|
|
storDriver->RingBufferSize,
|
|
|
|
(void *)&props,
|
|
|
|
sizeof(struct vmstorage_channel_properties),
|
|
|
|
StorVscOnChannelCallback,
|
|
|
|
Device);
|
|
|
|
|
|
|
|
DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d",
|
|
|
|
props.PathId, props.TargetId, props.MaxTransferBytes);
|
|
|
|
|
|
|
|
if (ret != 0) {
|
2009-07-13 17:01:31 -06:00
|
|
|
DPRINT_ERR(STORVSC, "unable to open channel: %d", ret);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = StorVscChannelInit(Device);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-31 23:31:22 -06:00
|
|
|
/**
|
|
|
|
* StorVscOnDeviceAdd - Callback when the device belonging to this driver is added
|
|
|
|
*/
|
|
|
|
static int StorVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
|
|
|
|
{
|
|
|
|
struct storvsc_device *storDevice;
|
|
|
|
/* struct vmstorage_channel_properties *props; */
|
|
|
|
struct storvsc_device_info *deviceInfo;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
DPRINT_ENTER(STORVSC);
|
|
|
|
|
|
|
|
deviceInfo = (struct storvsc_device_info *)AdditionalInfo;
|
|
|
|
storDevice = AllocStorDevice(Device);
|
|
|
|
if (!storDevice) {
|
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the channel properties to our storvsc channel */
|
|
|
|
/* props = (struct vmstorage_channel_properties *)
|
|
|
|
* channel->offerMsg.Offer.u.Standard.UserDefined; */
|
|
|
|
|
|
|
|
/* FIXME: */
|
|
|
|
/*
|
|
|
|
* If we support more than 1 scsi channel, we need to set the
|
|
|
|
* port number here to the scsi channel but how do we get the
|
|
|
|
* scsi channel prior to the bus scan
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* storChannel->PortNumber = 0;
|
|
|
|
storChannel->PathId = props->PathId;
|
|
|
|
storChannel->TargetId = props->TargetId; */
|
|
|
|
|
|
|
|
storDevice->PortNumber = deviceInfo->PortNumber;
|
|
|
|
/* Send it back up */
|
|
|
|
ret = StorVscConnectToVsp(Device);
|
|
|
|
|
|
|
|
/* deviceInfo->PortNumber = storDevice->PortNumber; */
|
|
|
|
deviceInfo->PathId = storDevice->PathId;
|
|
|
|
deviceInfo->TargetId = storDevice->TargetId;
|
|
|
|
|
|
|
|
DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n",
|
|
|
|
storDevice->PortNumber, storDevice->PathId,
|
|
|
|
storDevice->TargetId);
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
DPRINT_EXIT(STORVSC);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
/**
|
|
|
|
* StorVscOnDeviceRemove - Callback when the our device is being removed
|
|
|
|
*/
|
|
|
|
static int StorVscOnDeviceRemove(struct hv_device *Device)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
2009-08-28 17:26:48 -06:00
|
|
|
struct storvsc_device *storDevice;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(STORVSC);
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
DPRINT_INFO(STORVSC, "disabling storage device (%p)...",
|
|
|
|
Device->Extension);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
storDevice = ReleaseStorDevice(Device);
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/*
|
|
|
|
* At this point, all outbound traffic should be disable. We
|
|
|
|
* only allow inbound traffic (responses) to proceed so that
|
|
|
|
* outstanding requests can be completed.
|
|
|
|
*/
|
2009-08-31 23:25:48 -06:00
|
|
|
while (atomic_read(&storDevice->NumOutstandingRequests)) {
|
|
|
|
DPRINT_INFO(STORVSC, "waiting for %d requests to complete...",
|
|
|
|
atomic_read(&storDevice->NumOutstandingRequests));
|
2009-07-16 12:50:41 -06:00
|
|
|
udelay(100);
|
2009-07-13 17:01:31 -06:00
|
|
|
}
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
DPRINT_INFO(STORVSC, "removing storage device (%p)...",
|
|
|
|
Device->Extension);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
storDevice = FinalReleaseStorDevice(Device);
|
|
|
|
|
|
|
|
DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", storDevice);
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Close the channel */
|
2009-07-13 17:01:31 -06:00
|
|
|
Device->Driver->VmbusChannelInterface.Close(Device);
|
|
|
|
|
|
|
|
FreeStorDevice(storDevice);
|
|
|
|
|
|
|
|
DPRINT_EXIT(STORVSC);
|
2009-08-31 23:25:48 -06:00
|
|
|
return 0;
|
2009-07-27 14:47:24 -06:00
|
|
|
}
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2010-01-08 11:24:26 -07:00
|
|
|
int StorVscOnHostReset(struct hv_device *Device)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
2009-08-28 17:26:48 -06:00
|
|
|
struct storvsc_device *storDevice;
|
|
|
|
struct storvsc_request_extension *request;
|
2009-08-27 17:00:24 -06:00
|
|
|
struct vstor_packet *vstorPacket;
|
2009-08-31 23:25:48 -06:00
|
|
|
int ret;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(STORVSC);
|
|
|
|
|
|
|
|
DPRINT_INFO(STORVSC, "resetting host adapter...");
|
|
|
|
|
|
|
|
storDevice = GetStorDevice(Device);
|
2009-08-31 23:25:48 -06:00
|
|
|
if (!storDevice) {
|
|
|
|
DPRINT_ERR(STORVSC, "unable to get stor device..."
|
|
|
|
"device being destroyed?");
|
2009-07-13 17:01:31 -06:00
|
|
|
DPRINT_EXIT(STORVSC);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
request = &storDevice->ResetRequest;
|
|
|
|
vstorPacket = &request->VStorPacket;
|
|
|
|
|
2009-07-29 16:40:18 -06:00
|
|
|
request->WaitEvent = osd_WaitEventCreate();
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket->Operation = VStorOperationResetBus;
|
|
|
|
vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
|
|
|
|
vstorPacket->VmSrb.PathId = storDevice->PathId;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket,
|
|
|
|
sizeof(struct vstor_packet),
|
|
|
|
(unsigned long)&storDevice->ResetRequest,
|
|
|
|
VmbusPacketTypeDataInBand,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d",
|
|
|
|
vstorPacket, ret);
|
2009-07-13 17:01:31 -06:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* FIXME: Add a timeout */
|
2009-07-29 16:40:18 -06:00
|
|
|
osd_WaitEventWait(request->WaitEvent);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-07-29 15:00:10 -06:00
|
|
|
kfree(request->WaitEvent);
|
2009-07-13 17:01:31 -06:00
|
|
|
DPRINT_INFO(STORVSC, "host adapter reset completed");
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/*
|
|
|
|
* At this point, all outstanding requests in the adapter
|
|
|
|
* should have been flushed out and return to us
|
|
|
|
*/
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
PutStorDevice(Device);
|
|
|
|
DPRINT_EXIT(STORVSC);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
/**
|
|
|
|
* StorVscOnIORequest - Callback to initiate an I/O request
|
|
|
|
*/
|
|
|
|
static int StorVscOnIORequest(struct hv_device *Device,
|
|
|
|
struct hv_storvsc_request *Request)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
2009-08-28 17:26:48 -06:00
|
|
|
struct storvsc_device *storDevice;
|
2009-08-31 23:25:48 -06:00
|
|
|
struct storvsc_request_extension *requestExtension;
|
|
|
|
struct vstor_packet *vstorPacket;
|
|
|
|
int ret = 0;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(STORVSC);
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
requestExtension =
|
|
|
|
(struct storvsc_request_extension *)Request->Extension;
|
|
|
|
vstorPacket = &requestExtension->VStorPacket;
|
2009-07-13 17:01:31 -06:00
|
|
|
storDevice = GetStorDevice(Device);
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, "
|
|
|
|
"Extension %p", Device, storDevice, Request,
|
|
|
|
requestExtension);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d",
|
2009-08-31 23:25:48 -06:00
|
|
|
Request, Request->DataBuffer.Length, Request->Bus,
|
|
|
|
Request->TargetId, Request->LunId, Request->CdbLen);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
if (!storDevice) {
|
|
|
|
DPRINT_ERR(STORVSC, "unable to get stor device..."
|
|
|
|
"device being destroyed?");
|
2009-07-13 17:01:31 -06:00
|
|
|
DPRINT_EXIT(STORVSC);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
/* print_hex_dump_bytes("", DUMP_PREFIX_NONE, Request->Cdb,
|
|
|
|
* Request->CdbLen); */
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
requestExtension->Request = Request;
|
|
|
|
requestExtension->Device = Device;
|
|
|
|
|
2009-08-27 17:00:24 -06:00
|
|
|
memset(vstorPacket, 0 , sizeof(struct vstor_packet));
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
vstorPacket->Flags |= REQUEST_COMPLETION_FLAG;
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket->VmSrb.Length = sizeof(struct vmscsi_request);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
vstorPacket->VmSrb.PortNumber = Request->Host;
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket->VmSrb.PathId = Request->Bus;
|
|
|
|
vstorPacket->VmSrb.TargetId = Request->TargetId;
|
|
|
|
vstorPacket->VmSrb.Lun = Request->LunId;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
vstorPacket->VmSrb.SenseInfoLength = SENSE_BUFFER_SIZE;
|
|
|
|
|
2009-07-27 14:47:24 -06:00
|
|
|
/* Copy over the scsi command descriptor block */
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket->VmSrb.CdbLength = Request->CdbLen;
|
2009-07-13 17:01:31 -06:00
|
|
|
memcpy(&vstorPacket->VmSrb.Cdb, Request->Cdb, Request->CdbLen);
|
|
|
|
|
|
|
|
vstorPacket->VmSrb.DataIn = Request->Type;
|
|
|
|
vstorPacket->VmSrb.DataTransferLength = Request->DataBuffer.Length;
|
|
|
|
|
|
|
|
vstorPacket->Operation = VStorOperationExecuteSRB;
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, "
|
|
|
|
"lun %d senselen %d cdblen %d",
|
|
|
|
vstorPacket->VmSrb.Length,
|
|
|
|
vstorPacket->VmSrb.PortNumber,
|
|
|
|
vstorPacket->VmSrb.PathId,
|
|
|
|
vstorPacket->VmSrb.TargetId,
|
|
|
|
vstorPacket->VmSrb.Lun,
|
|
|
|
vstorPacket->VmSrb.SenseInfoLength,
|
|
|
|
vstorPacket->VmSrb.CdbLength);
|
|
|
|
|
|
|
|
if (requestExtension->Request->DataBuffer.Length) {
|
|
|
|
ret = Device->Driver->VmbusChannelInterface.
|
|
|
|
SendPacketMultiPageBuffer(Device,
|
2009-07-13 17:01:31 -06:00
|
|
|
&requestExtension->Request->DataBuffer,
|
|
|
|
vstorPacket,
|
2009-08-27 17:00:24 -06:00
|
|
|
sizeof(struct vstor_packet),
|
2009-07-14 16:12:46 -06:00
|
|
|
(unsigned long)requestExtension);
|
2009-08-31 23:25:48 -06:00
|
|
|
} else {
|
2009-07-13 17:01:31 -06:00
|
|
|
ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
|
2009-08-31 23:25:48 -06:00
|
|
|
vstorPacket,
|
|
|
|
sizeof(struct vstor_packet),
|
|
|
|
(unsigned long)requestExtension,
|
|
|
|
VmbusPacketTypeDataInBand,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
2009-07-13 17:01:31 -06:00
|
|
|
}
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d",
|
|
|
|
vstorPacket, ret);
|
2009-07-13 17:01:31 -06:00
|
|
|
}
|
|
|
|
|
2009-07-29 15:00:12 -06:00
|
|
|
atomic_inc(&storDevice->NumOutstandingRequests);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
PutStorDevice(Device);
|
|
|
|
|
|
|
|
DPRINT_EXIT(STORVSC);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-31 23:25:48 -06:00
|
|
|
/**
|
|
|
|
* StorVscOnCleanup - Perform any cleanup when the driver is removed
|
|
|
|
*/
|
|
|
|
static void StorVscOnCleanup(struct hv_driver *Driver)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
|
|
|
DPRINT_ENTER(STORVSC);
|
|
|
|
DPRINT_EXIT(STORVSC);
|
|
|
|
}
|
|
|
|
|
2009-08-31 23:31:22 -06:00
|
|
|
/**
|
|
|
|
* StorVscInitialize - Main entry point
|
|
|
|
*/
|
|
|
|
int StorVscInitialize(struct hv_driver *Driver)
|
2009-07-13 17:01:31 -06:00
|
|
|
{
|
2009-08-31 23:31:22 -06:00
|
|
|
struct storvsc_driver_object *storDriver;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
DPRINT_ENTER(STORVSC);
|
|
|
|
|
2009-08-31 23:31:22 -06:00
|
|
|
storDriver = (struct storvsc_driver_object *)Driver;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:31:22 -06:00
|
|
|
DPRINT_DBG(STORVSC, "sizeof(STORVSC_REQUEST)=%zd "
|
|
|
|
"sizeof(struct storvsc_request_extension)=%zd "
|
|
|
|
"sizeof(struct vstor_packet)=%zd, "
|
|
|
|
"sizeof(struct vmscsi_request)=%zd",
|
|
|
|
sizeof(struct hv_storvsc_request),
|
|
|
|
sizeof(struct storvsc_request_extension),
|
|
|
|
sizeof(struct vstor_packet),
|
|
|
|
sizeof(struct vmscsi_request));
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:31:22 -06:00
|
|
|
/* Make sure we are at least 2 pages since 1 page is used for control */
|
|
|
|
ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1));
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:31:22 -06:00
|
|
|
Driver->name = gDriverName;
|
|
|
|
memcpy(&Driver->deviceType, &gStorVscDeviceType,
|
|
|
|
sizeof(struct hv_guid));
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:31:22 -06:00
|
|
|
storDriver->RequestExtSize = sizeof(struct storvsc_request_extension);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:31:22 -06:00
|
|
|
/*
|
|
|
|
* Divide the ring buffer data size (which is 1 page less
|
|
|
|
* than the ring buffer size since that page is reserved for
|
|
|
|
* the ring buffer indices) by the max request size (which is
|
|
|
|
* VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + struct vstor_packet + u64)
|
|
|
|
*/
|
|
|
|
storDriver->MaxOutstandingRequestsPerChannel =
|
|
|
|
((storDriver->RingBufferSize - PAGE_SIZE) /
|
|
|
|
ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET +
|
|
|
|
sizeof(struct vstor_packet) + sizeof(u64),
|
|
|
|
sizeof(u64)));
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:31:22 -06:00
|
|
|
DPRINT_INFO(STORVSC, "max io %u, currently %u\n",
|
|
|
|
storDriver->MaxOutstandingRequestsPerChannel,
|
|
|
|
STORVSC_MAX_IO_REQUESTS);
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:31:22 -06:00
|
|
|
/* Setup the dispatch table */
|
|
|
|
storDriver->Base.OnDeviceAdd = StorVscOnDeviceAdd;
|
|
|
|
storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove;
|
|
|
|
storDriver->Base.OnCleanup = StorVscOnCleanup;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
2009-08-31 23:31:22 -06:00
|
|
|
storDriver->OnIORequest = StorVscOnIORequest;
|
2009-07-13 17:01:31 -06:00
|
|
|
|
|
|
|
DPRINT_EXIT(STORVSC);
|
|
|
|
|
2009-08-31 23:31:22 -06:00
|
|
|
return 0;
|
2009-07-13 17:01:31 -06:00
|
|
|
}
|