2009-07-13 23:01:31 +00: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 22:08:20 +00:00
|
|
|
#include <linux/kernel.h>
|
2011-02-11 17:59:43 +00:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/wait.h>
|
2009-07-15 18:06:01 +00: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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2009-07-15 18:06:01 +00:00
|
|
|
#include <linux/mm.h>
|
2009-07-16 18:50:41 +00:00
|
|
|
#include <linux/delay.h>
|
2011-02-11 18:00:12 +00:00
|
|
|
#include "hv_api.h"
|
2009-08-28 23:22:59 +00:00
|
|
|
#include "logging.h"
|
2010-05-06 05:40:43 +00:00
|
|
|
#include "storvsc_api.h"
|
2010-05-06 05:50:11 +00:00
|
|
|
#include "vmbus_packet_format.h"
|
2009-08-27 22:58:52 +00:00
|
|
|
#include "vstorage.h"
|
2010-10-21 16:15:14 +00:00
|
|
|
#include "channel.h"
|
2009-07-13 23:01:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-06 20:26:47 +00:00
|
|
|
static const char *g_driver_name = "storvsc";
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */
|
2009-08-19 23:17:03 +00: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 23:01:31 +00:00
|
|
|
};
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
static inline struct storvsc_device *alloc_stor_device(struct hv_device *device)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device *stor_device;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
|
|
|
|
if (!stor_device)
|
2009-07-13 23:01:31 +00:00
|
|
|
return NULL;
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Set to 2 to allow both inbound and outbound traffics */
|
2010-12-06 20:26:47 +00:00
|
|
|
/* (ie get_stor_device() and must_get_stor_device()) to proceed. */
|
2010-12-06 20:26:49 +00:00
|
|
|
atomic_cmpxchg(&stor_device->ref_count, 0, 2);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_device->device = device;
|
2011-01-26 20:12:11 +00:00
|
|
|
device->ext = stor_device;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
return stor_device;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
static inline void free_stor_device(struct storvsc_device *device)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
/* ASSERT(atomic_read(&device->ref_count) == 0); */
|
|
|
|
kfree(device);
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Get the stordevice object iff exists and its refcount > 1 */
|
2010-12-06 20:26:49 +00:00
|
|
|
static inline struct storvsc_device *get_stor_device(struct hv_device *device)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device *stor_device;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
stor_device = (struct storvsc_device *)device->ext;
|
2010-12-06 20:26:49 +00:00
|
|
|
if (stor_device && atomic_read(&stor_device->ref_count) > 1)
|
|
|
|
atomic_inc(&stor_device->ref_count);
|
2009-07-13 23:01:31 +00:00
|
|
|
else
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_device = NULL;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
return stor_device;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Get the stordevice object iff exists and its refcount > 0 */
|
2010-12-06 20:26:48 +00:00
|
|
|
static inline struct storvsc_device *must_get_stor_device(
|
2010-12-06 20:26:49 +00:00
|
|
|
struct hv_device *device)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device *stor_device;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
stor_device = (struct storvsc_device *)device->ext;
|
2010-12-06 20:26:49 +00:00
|
|
|
if (stor_device && atomic_read(&stor_device->ref_count))
|
|
|
|
atomic_inc(&stor_device->ref_count);
|
2009-07-13 23:01:31 +00:00
|
|
|
else
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_device = NULL;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
return stor_device;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
static inline void put_stor_device(struct hv_device *device)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device *stor_device;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
stor_device = (struct storvsc_device *)device->ext;
|
2010-12-06 20:26:49 +00:00
|
|
|
/* ASSERT(stor_device); */
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
atomic_dec(&stor_device->ref_count);
|
|
|
|
/* ASSERT(atomic_read(&stor_device->ref_count)); */
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:48 +00:00
|
|
|
/* Drop ref count to 1 to effectively disable get_stor_device() */
|
|
|
|
static inline struct storvsc_device *release_stor_device(
|
2010-12-06 20:26:49 +00:00
|
|
|
struct hv_device *device)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device *stor_device;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
stor_device = (struct storvsc_device *)device->ext;
|
2010-12-06 20:26:49 +00:00
|
|
|
/* ASSERT(stor_device); */
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Busy wait until the ref drop to 2, then set it to 1 */
|
2010-12-06 20:26:49 +00:00
|
|
|
while (atomic_cmpxchg(&stor_device->ref_count, 2, 1) != 2)
|
2009-07-16 18:50:41 +00:00
|
|
|
udelay(100);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
return stor_device;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
/* Drop ref count to 0. No one can use stor_device object. */
|
2010-12-06 20:26:48 +00:00
|
|
|
static inline struct storvsc_device *final_release_stor_device(
|
2010-12-06 20:26:49 +00:00
|
|
|
struct hv_device *device)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device *stor_device;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
stor_device = (struct storvsc_device *)device->ext;
|
2010-12-06 20:26:49 +00:00
|
|
|
/* ASSERT(stor_device); */
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Busy wait until the ref drop to 1, then set it to 0 */
|
2010-12-06 20:26:49 +00:00
|
|
|
while (atomic_cmpxchg(&stor_device->ref_count, 1, 0) != 1)
|
2009-07-16 18:50:41 +00:00
|
|
|
udelay(100);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
device->ext = NULL;
|
2010-12-06 20:26:49 +00:00
|
|
|
return stor_device;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
static int stor_vsc_channel_init(struct hv_device *device)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device *stor_device;
|
2009-08-28 23:26:48 +00:00
|
|
|
struct storvsc_request_extension *request;
|
2010-12-06 20:26:49 +00:00
|
|
|
struct vstor_packet *vstor_packet;
|
2009-09-01 05:25:48 +00:00
|
|
|
int ret;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_device = get_stor_device(device);
|
|
|
|
if (!stor_device) {
|
2009-09-01 05:25:48 +00:00
|
|
|
DPRINT_ERR(STORVSC, "unable to get stor device..."
|
|
|
|
"device being destroyed?");
|
2009-07-13 23:01:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
request = &stor_device->init_request;
|
|
|
|
vstor_packet = &request->vstor_packet;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-09-01 05:25:48 +00:00
|
|
|
/*
|
|
|
|
* Now, initiate the vsc/vsp initialization protocol on the open
|
|
|
|
* channel
|
|
|
|
*/
|
2009-11-11 21:57:03 +00:00
|
|
|
memset(request, 0, sizeof(struct storvsc_request_extension));
|
2011-02-11 17:59:43 +00:00
|
|
|
init_waitqueue_head(&request->wait_event);
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION;
|
|
|
|
vstor_packet->flags = REQUEST_COMPLETION_FLAG;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
|
|
|
DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION...");
|
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
request->wait_condition = 0;
|
2010-12-06 20:26:49 +00:00
|
|
|
ret = vmbus_sendpacket(device->channel, vstor_packet,
|
2010-10-21 16:43:56 +00:00
|
|
|
sizeof(struct vstor_packet),
|
|
|
|
(unsigned long)request,
|
2011-01-26 20:12:13 +00:00
|
|
|
VM_PKT_DATA_INBAND,
|
2010-10-21 16:43:56 +00:00
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
2009-09-01 05:25:48 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(STORVSC,
|
|
|
|
"unable to send BEGIN_INITIALIZATION_OPERATION");
|
2011-02-11 17:59:43 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
wait_event_timeout(request->wait_event, request->wait_condition,
|
|
|
|
msecs_to_jiffies(1000));
|
|
|
|
if (request->wait_condition == 0) {
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
goto cleanup;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
|
|
|
|
vstor_packet->status != 0) {
|
2009-09-01 05:25:48 +00:00
|
|
|
DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed "
|
|
|
|
"(op %d status 0x%x)",
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->operation, vstor_packet->status);
|
2011-02-11 17:59:43 +00:00
|
|
|
goto cleanup;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION...");
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* reuse the packet for version range supported */
|
2010-12-06 20:26:49 +00:00
|
|
|
memset(vstor_packet, 0, sizeof(struct vstor_packet));
|
|
|
|
vstor_packet->operation = VSTOR_OPERATION_QUERY_PROTOCOL_VERSION;
|
|
|
|
vstor_packet->flags = REQUEST_COMPLETION_FLAG;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->version.major_minor = VMSTOR_PROTOCOL_VERSION_CURRENT;
|
|
|
|
FILL_VMSTOR_REVISION(vstor_packet->version.revision);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
request->wait_condition = 0;
|
2010-12-06 20:26:49 +00:00
|
|
|
ret = vmbus_sendpacket(device->channel, vstor_packet,
|
2010-10-21 16:43:56 +00:00
|
|
|
sizeof(struct vstor_packet),
|
|
|
|
(unsigned long)request,
|
2011-01-26 20:12:13 +00:00
|
|
|
VM_PKT_DATA_INBAND,
|
2010-10-21 16:43:56 +00:00
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
2009-09-01 05:25:48 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(STORVSC,
|
|
|
|
"unable to send BEGIN_INITIALIZATION_OPERATION");
|
2011-02-11 17:59:43 +00:00
|
|
|
goto cleanup;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
wait_event_timeout(request->wait_event, request->wait_condition,
|
|
|
|
msecs_to_jiffies(1000));
|
|
|
|
if (request->wait_condition == 0) {
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* TODO: Check returned version */
|
2010-12-06 20:26:49 +00:00
|
|
|
if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
|
|
|
|
vstor_packet->status != 0) {
|
2009-09-01 05:25:48 +00:00
|
|
|
DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed "
|
|
|
|
"(op %d status 0x%x)",
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->operation, vstor_packet->status);
|
2011-02-11 17:59:43 +00:00
|
|
|
goto cleanup;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Query channel properties */
|
2009-07-13 23:01:31 +00:00
|
|
|
DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION...");
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
memset(vstor_packet, 0, sizeof(struct vstor_packet));
|
|
|
|
vstor_packet->operation = VSTOR_OPERATION_QUERY_PROPERTIES;
|
|
|
|
vstor_packet->flags = REQUEST_COMPLETION_FLAG;
|
|
|
|
vstor_packet->storage_channel_properties.port_number =
|
|
|
|
stor_device->port_number;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
request->wait_condition = 0;
|
2010-12-06 20:26:49 +00:00
|
|
|
ret = vmbus_sendpacket(device->channel, vstor_packet,
|
2010-10-21 16:43:56 +00:00
|
|
|
sizeof(struct vstor_packet),
|
|
|
|
(unsigned long)request,
|
2011-01-26 20:12:13 +00:00
|
|
|
VM_PKT_DATA_INBAND,
|
2010-10-21 16:43:56 +00:00
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
2009-09-01 05:25:48 +00:00
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(STORVSC,
|
|
|
|
"unable to send QUERY_PROPERTIES_OPERATION");
|
2011-02-11 17:59:43 +00:00
|
|
|
goto cleanup;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
wait_event_timeout(request->wait_event, request->wait_condition,
|
|
|
|
msecs_to_jiffies(1000));
|
|
|
|
if (request->wait_condition == 0) {
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* TODO: Check returned version */
|
2010-12-06 20:26:49 +00:00
|
|
|
if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
|
|
|
|
vstor_packet->status != 0) {
|
2009-09-01 05:25:48 +00:00
|
|
|
DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed "
|
|
|
|
"(op %d status 0x%x)",
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->operation, vstor_packet->status);
|
2011-02-11 17:59:43 +00:00
|
|
|
goto cleanup;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_device->path_id = vstor_packet->storage_channel_properties.path_id;
|
|
|
|
stor_device->target_id
|
|
|
|
= vstor_packet->storage_channel_properties.target_id;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-09-01 05:25:48 +00:00
|
|
|
DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x",
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->storage_channel_properties.flags,
|
|
|
|
vstor_packet->storage_channel_properties.max_transfer_bytes);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
|
|
|
DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION...");
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
memset(vstor_packet, 0, sizeof(struct vstor_packet));
|
|
|
|
vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION;
|
|
|
|
vstor_packet->flags = REQUEST_COMPLETION_FLAG;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
request->wait_condition = 0;
|
2010-12-06 20:26:49 +00:00
|
|
|
ret = vmbus_sendpacket(device->channel, vstor_packet,
|
2010-10-21 16:43:56 +00:00
|
|
|
sizeof(struct vstor_packet),
|
|
|
|
(unsigned long)request,
|
2011-01-26 20:12:13 +00:00
|
|
|
VM_PKT_DATA_INBAND,
|
2010-10-21 16:43:56 +00:00
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
2009-09-01 05:25:48 +00:00
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(STORVSC,
|
|
|
|
"unable to send END_INITIALIZATION_OPERATION");
|
2011-02-11 17:59:43 +00:00
|
|
|
goto cleanup;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
wait_event_timeout(request->wait_event, request->wait_condition,
|
|
|
|
msecs_to_jiffies(1000));
|
|
|
|
if (request->wait_condition == 0) {
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
|
|
|
|
vstor_packet->status != 0) {
|
2009-09-01 05:25:48 +00:00
|
|
|
DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed "
|
|
|
|
"(op %d status 0x%x)",
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->operation, vstor_packet->status);
|
2011-02-11 17:59:43 +00:00
|
|
|
goto cleanup;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****");
|
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
cleanup:
|
2010-12-06 20:26:49 +00:00
|
|
|
put_stor_device(device);
|
2009-07-13 23:01:31 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
static void stor_vsc_on_io_completion(struct hv_device *device,
|
|
|
|
struct vstor_packet *vstor_packet,
|
|
|
|
struct storvsc_request_extension *request_ext)
|
2009-09-01 05:31:22 +00:00
|
|
|
{
|
|
|
|
struct hv_storvsc_request *request;
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device *stor_device;
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_device = must_get_stor_device(device);
|
|
|
|
if (!stor_device) {
|
2009-09-01 05:31:22 +00:00
|
|
|
DPRINT_ERR(STORVSC, "unable to get stor device..."
|
|
|
|
"device being destroyed?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p "
|
2010-12-06 20:26:49 +00:00
|
|
|
"completed bytes xfer %u", request_ext,
|
|
|
|
vstor_packet->vm_srb.data_transfer_length);
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
/* ASSERT(request_ext != NULL); */
|
|
|
|
/* ASSERT(request_ext->request != NULL); */
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
request = request_ext->request;
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-05-05 19:27:45 +00:00
|
|
|
/* ASSERT(request->OnIOCompletion != NULL); */
|
2009-09-01 05:31:22 +00:00
|
|
|
|
|
|
|
/* Copy over the status...etc */
|
2010-12-06 20:26:49 +00:00
|
|
|
request->status = vstor_packet->vm_srb.scsi_status;
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
if (request->status != 0 || vstor_packet->vm_srb.srb_status != 1) {
|
2009-09-01 05:31:22 +00:00
|
|
|
DPRINT_WARN(STORVSC,
|
|
|
|
"cmd 0x%x scsi status 0x%x srb status 0x%x\n",
|
2010-12-06 20:26:49 +00:00
|
|
|
request->cdb[0], vstor_packet->vm_srb.scsi_status,
|
|
|
|
vstor_packet->vm_srb.srb_status);
|
2009-09-01 05:31:22 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:45 +00:00
|
|
|
if ((request->status & 0xFF) == 0x02) {
|
2009-09-01 05:31:22 +00:00
|
|
|
/* CHECK_CONDITION */
|
2010-12-06 20:26:49 +00:00
|
|
|
if (vstor_packet->vm_srb.srb_status & 0x80) {
|
2009-09-01 05:31:22 +00:00
|
|
|
/* autosense data available */
|
|
|
|
DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data "
|
2010-12-06 20:26:49 +00:00
|
|
|
"valid - len %d\n", request_ext,
|
|
|
|
vstor_packet->vm_srb.sense_info_length);
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
/* ASSERT(vstor_packet->vm_srb.sense_info_length <= */
|
2010-05-05 19:27:45 +00:00
|
|
|
/* request->SenseBufferSize); */
|
2010-12-06 20:26:45 +00:00
|
|
|
memcpy(request->sense_buffer,
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->vm_srb.sense_data,
|
|
|
|
vstor_packet->vm_srb.sense_info_length);
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:45 +00:00
|
|
|
request->sense_buffer_size =
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->vm_srb.sense_info_length;
|
2009-09-01 05:31:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: */
|
2010-12-06 20:26:49 +00:00
|
|
|
request->bytes_xfer = vstor_packet->vm_srb.data_transfer_length;
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:45 +00:00
|
|
|
request->on_io_completion(request);
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
atomic_dec(&stor_device->num_outstanding_req);
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
put_stor_device(device);
|
2009-09-01 05:31:22 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
static void stor_vsc_on_receive(struct hv_device *device,
|
|
|
|
struct vstor_packet *vstor_packet,
|
|
|
|
struct storvsc_request_extension *request_ext)
|
2009-09-01 05:31:22 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
switch (vstor_packet->operation) {
|
2010-12-06 20:26:44 +00:00
|
|
|
case VSTOR_OPERATION_COMPLETE_IO:
|
2009-09-01 05:31:22 +00:00
|
|
|
DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION");
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_vsc_on_io_completion(device, vstor_packet, request_ext);
|
2009-09-01 05:31:22 +00:00
|
|
|
break;
|
2010-12-06 20:26:44 +00:00
|
|
|
case VSTOR_OPERATION_REMOVE_DEVICE:
|
2009-09-01 05:31:22 +00:00
|
|
|
DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION");
|
|
|
|
/* TODO: */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DPRINT_INFO(STORVSC, "Unknown operation received - %d",
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->operation);
|
2009-09-01 05:31:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:48 +00:00
|
|
|
static void stor_vsc_on_channel_callback(void *context)
|
2009-09-01 05:31:22 +00:00
|
|
|
{
|
|
|
|
struct hv_device *device = (struct hv_device *)context;
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device *stor_device;
|
|
|
|
u32 bytes_recvd;
|
|
|
|
u64 request_id;
|
2011-01-20 08:32:01 +00:00
|
|
|
unsigned char packet[ALIGN(sizeof(struct vstor_packet), 8)];
|
2009-09-01 05:31:22 +00:00
|
|
|
struct storvsc_request_extension *request;
|
|
|
|
int ret;
|
|
|
|
|
2010-05-05 19:27:45 +00:00
|
|
|
/* ASSERT(device); */
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_device = must_get_stor_device(device);
|
|
|
|
if (!stor_device) {
|
2009-09-01 05:31:22 +00:00
|
|
|
DPRINT_ERR(STORVSC, "unable to get stor device..."
|
|
|
|
"device being destroyed?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2010-10-21 16:15:14 +00:00
|
|
|
ret = vmbus_recvpacket(device->channel, packet,
|
2011-01-20 08:32:01 +00:00
|
|
|
ALIGN(sizeof(struct vstor_packet), 8),
|
2010-12-06 20:26:49 +00:00
|
|
|
&bytes_recvd, &request_id);
|
|
|
|
if (ret == 0 && bytes_recvd > 0) {
|
2009-09-01 05:31:22 +00:00
|
|
|
DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx",
|
2010-12-06 20:26:49 +00:00
|
|
|
bytes_recvd, request_id);
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
/* ASSERT(bytes_recvd ==
|
|
|
|
sizeof(struct vstor_packet)); */
|
2009-09-01 05:31:22 +00:00
|
|
|
|
|
|
|
request = (struct storvsc_request_extension *)
|
2010-12-06 20:26:49 +00:00
|
|
|
(unsigned long)request_id;
|
2010-05-05 19:27:45 +00:00
|
|
|
/* ASSERT(request);c */
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
/* if (vstor_packet.Flags & SYNTHETIC_FLAG) */
|
|
|
|
if ((request == &stor_device->init_request) ||
|
|
|
|
(request == &stor_device->reset_request)) {
|
2009-09-01 05:31:22 +00:00
|
|
|
/* DPRINT_INFO(STORVSC,
|
|
|
|
* "reset completion - operation "
|
|
|
|
* "%u status %u",
|
2010-12-06 20:26:49 +00:00
|
|
|
* vstor_packet.Operation,
|
|
|
|
* vstor_packet.Status); */
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:47 +00:00
|
|
|
memcpy(&request->vstor_packet, packet,
|
2009-09-01 05:31:22 +00:00
|
|
|
sizeof(struct vstor_packet));
|
2011-02-11 17:59:43 +00:00
|
|
|
request->wait_condition = 1;
|
|
|
|
wake_up(&request->wait_event);
|
2009-09-01 05:31:22 +00:00
|
|
|
} else {
|
2010-12-06 20:26:48 +00:00
|
|
|
stor_vsc_on_receive(device,
|
2009-09-01 05:31:22 +00:00
|
|
|
(struct vstor_packet *)packet,
|
|
|
|
request);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* DPRINT_DBG(STORVSC, "nothing else to read..."); */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
|
2010-12-06 20:26:48 +00:00
|
|
|
put_stor_device(device);
|
2009-09-01 05:31:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
static int stor_vsc_connect_to_vsp(struct hv_device *device)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
2009-08-27 23:00:24 +00:00
|
|
|
struct vmstorage_channel_properties props;
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_driver_object *stor_driver;
|
2009-09-01 05:25:48 +00:00
|
|
|
int ret;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
stor_driver = (struct storvsc_driver_object *)device->drv;
|
2009-11-11 21:57:03 +00:00
|
|
|
memset(&props, 0, sizeof(struct vmstorage_channel_properties));
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Open the channel */
|
2010-12-06 20:26:49 +00:00
|
|
|
ret = vmbus_open(device->channel,
|
|
|
|
stor_driver->ring_buffer_size,
|
|
|
|
stor_driver->ring_buffer_size,
|
2010-10-21 16:59:06 +00:00
|
|
|
(void *)&props,
|
|
|
|
sizeof(struct vmstorage_channel_properties),
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_vsc_on_channel_callback, device);
|
2009-09-01 05:25:48 +00:00
|
|
|
|
|
|
|
DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d",
|
2010-12-06 20:26:44 +00:00
|
|
|
props.path_id, props.target_id, props.max_transfer_bytes);
|
2009-09-01 05:25:48 +00:00
|
|
|
|
|
|
|
if (ret != 0) {
|
2009-07-13 23:01:31 +00:00
|
|
|
DPRINT_ERR(STORVSC, "unable to open channel: %d", ret);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
ret = stor_vsc_channel_init(device);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-04 22:11:00 +00:00
|
|
|
/*
|
2010-12-06 20:26:48 +00:00
|
|
|
* stor_vsc_on_device_add - Callback when the device belonging to this driver
|
2010-12-06 20:26:47 +00:00
|
|
|
* is added
|
2009-09-01 05:31:22 +00:00
|
|
|
*/
|
2010-12-06 20:26:49 +00:00
|
|
|
static int stor_vsc_on_device_add(struct hv_device *device,
|
|
|
|
void *additional_info)
|
2009-09-01 05:31:22 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device *stor_device;
|
2009-09-01 05:31:22 +00:00
|
|
|
/* struct vmstorage_channel_properties *props; */
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device_info *device_info;
|
2009-09-01 05:31:22 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
device_info = (struct storvsc_device_info *)additional_info;
|
|
|
|
stor_device = alloc_stor_device(device);
|
|
|
|
if (!stor_device) {
|
2009-09-01 05:31:22 +00:00
|
|
|
ret = -1;
|
2011-02-11 17:59:43 +00:00
|
|
|
goto cleanup;
|
2009-09-01 05:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the channel properties to our storvsc channel */
|
|
|
|
/* props = (struct vmstorage_channel_properties *)
|
2010-03-11 22:51:23 +00:00
|
|
|
* channel->offerMsg.Offer.u.Standard.UserDefined; */
|
2009-09-01 05:31:22 +00:00
|
|
|
|
|
|
|
/* 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; */
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_device->port_number = device_info->port_number;
|
2009-09-01 05:31:22 +00:00
|
|
|
/* Send it back up */
|
2010-12-06 20:26:49 +00:00
|
|
|
ret = stor_vsc_connect_to_vsp(device);
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
/* device_info->PortNumber = stor_device->PortNumber; */
|
|
|
|
device_info->path_id = stor_device->path_id;
|
|
|
|
device_info->target_id = stor_device->target_id;
|
2009-09-01 05:31:22 +00:00
|
|
|
|
|
|
|
DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n",
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_device->port_number, stor_device->path_id,
|
|
|
|
stor_device->target_id);
|
2009-09-01 05:31:22 +00:00
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
cleanup:
|
2009-09-01 05:31:22 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-03-04 22:11:00 +00:00
|
|
|
/*
|
2010-12-06 20:26:48 +00:00
|
|
|
* stor_vsc_on_device_remove - Callback when the our device is being removed
|
2009-09-01 05:25:48 +00:00
|
|
|
*/
|
2010-12-06 20:26:49 +00:00
|
|
|
static int stor_vsc_on_device_remove(struct hv_device *device)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device *stor_device;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-09-01 05:25:48 +00:00
|
|
|
DPRINT_INFO(STORVSC, "disabling storage device (%p)...",
|
2011-01-26 20:12:11 +00:00
|
|
|
device->ext);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_device = release_stor_device(device);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-07-27 20:47:24 +00: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.
|
|
|
|
*/
|
2010-12-06 20:26:49 +00:00
|
|
|
while (atomic_read(&stor_device->num_outstanding_req)) {
|
2009-09-01 05:25:48 +00:00
|
|
|
DPRINT_INFO(STORVSC, "waiting for %d requests to complete...",
|
2010-12-06 20:26:49 +00:00
|
|
|
atomic_read(&stor_device->num_outstanding_req));
|
2009-07-16 18:50:41 +00:00
|
|
|
udelay(100);
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2009-09-01 05:25:48 +00:00
|
|
|
DPRINT_INFO(STORVSC, "removing storage device (%p)...",
|
2011-01-26 20:12:11 +00:00
|
|
|
device->ext);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_device = final_release_stor_device(device);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", stor_device);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Close the channel */
|
2010-12-06 20:26:49 +00:00
|
|
|
vmbus_close(device->channel);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
free_stor_device(stor_device);
|
2009-09-01 05:25:48 +00:00
|
|
|
return 0;
|
2009-07-27 20:47:24 +00:00
|
|
|
}
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
int stor_vsc_on_host_reset(struct hv_device *device)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device *stor_device;
|
2009-08-28 23:26:48 +00:00
|
|
|
struct storvsc_request_extension *request;
|
2010-12-06 20:26:49 +00:00
|
|
|
struct vstor_packet *vstor_packet;
|
2009-09-01 05:25:48 +00:00
|
|
|
int ret;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
|
|
|
DPRINT_INFO(STORVSC, "resetting host adapter...");
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_device = get_stor_device(device);
|
|
|
|
if (!stor_device) {
|
2009-09-01 05:25:48 +00:00
|
|
|
DPRINT_ERR(STORVSC, "unable to get stor device..."
|
|
|
|
"device being destroyed?");
|
2009-07-13 23:01:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
request = &stor_device->reset_request;
|
|
|
|
vstor_packet = &request->vstor_packet;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
init_waitqueue_head(&request->wait_event);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->operation = VSTOR_OPERATION_RESET_BUS;
|
|
|
|
vstor_packet->flags = REQUEST_COMPLETION_FLAG;
|
|
|
|
vstor_packet->vm_srb.path_id = stor_device->path_id;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
request->wait_condition = 0;
|
2010-12-06 20:26:49 +00:00
|
|
|
ret = vmbus_sendpacket(device->channel, vstor_packet,
|
2010-10-21 16:43:56 +00:00
|
|
|
sizeof(struct vstor_packet),
|
2010-12-06 20:26:49 +00:00
|
|
|
(unsigned long)&stor_device->reset_request,
|
2011-01-26 20:12:13 +00:00
|
|
|
VM_PKT_DATA_INBAND,
|
2010-10-21 16:43:56 +00:00
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
2009-09-01 05:25:48 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d",
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet, ret);
|
2011-02-11 17:59:43 +00:00
|
|
|
goto cleanup;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
wait_event_timeout(request->wait_event, request->wait_condition,
|
|
|
|
msecs_to_jiffies(1000));
|
|
|
|
if (request->wait_condition == 0) {
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-13 23:01:31 +00:00
|
|
|
|
|
|
|
DPRINT_INFO(STORVSC, "host adapter reset completed");
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/*
|
|
|
|
* At this point, all outstanding requests in the adapter
|
|
|
|
* should have been flushed out and return to us
|
|
|
|
*/
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2011-02-11 17:59:43 +00:00
|
|
|
cleanup:
|
2010-12-06 20:26:49 +00:00
|
|
|
put_stor_device(device);
|
2009-07-13 23:01:31 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-04 22:11:00 +00:00
|
|
|
/*
|
2010-12-06 20:26:48 +00:00
|
|
|
* stor_vsc_on_io_request - Callback to initiate an I/O request
|
2009-09-01 05:25:48 +00:00
|
|
|
*/
|
2010-12-06 20:26:49 +00:00
|
|
|
static int stor_vsc_on_io_request(struct hv_device *device,
|
|
|
|
struct hv_storvsc_request *request)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_device *stor_device;
|
|
|
|
struct storvsc_request_extension *request_extension;
|
|
|
|
struct vstor_packet *vstor_packet;
|
2009-09-01 05:25:48 +00:00
|
|
|
int ret = 0;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
request_extension =
|
|
|
|
(struct storvsc_request_extension *)request->extension;
|
|
|
|
vstor_packet = &request_extension->vstor_packet;
|
|
|
|
stor_device = get_stor_device(device);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-09-01 05:25:48 +00:00
|
|
|
DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, "
|
2010-12-06 20:26:49 +00:00
|
|
|
"Extension %p", device, stor_device, request,
|
|
|
|
request_extension);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
|
|
|
DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d",
|
2011-01-26 20:12:11 +00:00
|
|
|
request, request->data_buffer.len, request->bus,
|
2010-12-06 20:26:49 +00:00
|
|
|
request->target_id, request->lun_id, request->cdb_len);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
if (!stor_device) {
|
2009-09-01 05:25:48 +00:00
|
|
|
DPRINT_ERR(STORVSC, "unable to get stor device..."
|
|
|
|
"device being destroyed?");
|
2009-07-13 23:01:31 +00:00
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
/* print_hex_dump_bytes("", DUMP_PREFIX_NONE, request->Cdb,
|
|
|
|
* request->CdbLen); */
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
request_extension->request = request;
|
|
|
|
request_extension->device = device;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
memset(vstor_packet, 0 , sizeof(struct vstor_packet));
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->flags |= REQUEST_COMPLETION_FLAG;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->vm_srb.length = sizeof(struct vmscsi_request);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->vm_srb.port_number = request->host;
|
|
|
|
vstor_packet->vm_srb.path_id = request->bus;
|
|
|
|
vstor_packet->vm_srb.target_id = request->target_id;
|
|
|
|
vstor_packet->vm_srb.lun = request->lun_id;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->vm_srb.sense_info_length = SENSE_BUFFER_SIZE;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* Copy over the scsi command descriptor block */
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->vm_srb.cdb_length = request->cdb_len;
|
|
|
|
memcpy(&vstor_packet->vm_srb.cdb, request->cdb, request->cdb_len);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->vm_srb.data_in = request->type;
|
2011-01-26 20:12:11 +00:00
|
|
|
vstor_packet->vm_srb.data_transfer_length = request->data_buffer.len;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-09-01 05:25:48 +00:00
|
|
|
DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, "
|
|
|
|
"lun %d senselen %d cdblen %d",
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet->vm_srb.length,
|
|
|
|
vstor_packet->vm_srb.port_number,
|
|
|
|
vstor_packet->vm_srb.path_id,
|
|
|
|
vstor_packet->vm_srb.target_id,
|
|
|
|
vstor_packet->vm_srb.lun,
|
|
|
|
vstor_packet->vm_srb.sense_info_length,
|
|
|
|
vstor_packet->vm_srb.cdb_length);
|
|
|
|
|
2011-01-26 20:12:11 +00:00
|
|
|
if (request_extension->request->data_buffer.len) {
|
2010-12-06 20:26:49 +00:00
|
|
|
ret = vmbus_sendpacket_multipagebuffer(device->channel,
|
|
|
|
&request_extension->request->data_buffer,
|
|
|
|
vstor_packet,
|
2009-08-27 23:00:24 +00:00
|
|
|
sizeof(struct vstor_packet),
|
2010-12-06 20:26:49 +00:00
|
|
|
(unsigned long)request_extension);
|
2009-09-01 05:25:48 +00:00
|
|
|
} else {
|
2010-12-06 20:26:49 +00:00
|
|
|
ret = vmbus_sendpacket(device->channel, vstor_packet,
|
2010-10-21 16:43:56 +00:00
|
|
|
sizeof(struct vstor_packet),
|
2010-12-06 20:26:49 +00:00
|
|
|
(unsigned long)request_extension,
|
2011-01-26 20:12:13 +00:00
|
|
|
VM_PKT_DATA_INBAND,
|
2010-10-21 16:43:56 +00:00
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2009-09-01 05:25:48 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d",
|
2010-12-06 20:26:49 +00:00
|
|
|
vstor_packet, ret);
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
atomic_inc(&stor_device->num_outstanding_req);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
put_stor_device(device);
|
2009-07-13 23:01:31 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-04 22:11:00 +00:00
|
|
|
/*
|
2010-12-06 20:26:48 +00:00
|
|
|
* stor_vsc_on_cleanup - Perform any cleanup when the driver is removed
|
2009-09-01 05:25:48 +00:00
|
|
|
*/
|
2010-12-06 20:26:49 +00:00
|
|
|
static void stor_vsc_on_cleanup(struct hv_driver *driver)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-03-04 22:11:00 +00:00
|
|
|
/*
|
2010-12-06 20:26:46 +00:00
|
|
|
* stor_vsc_initialize - Main entry point
|
2009-09-01 05:31:22 +00:00
|
|
|
*/
|
2010-12-06 20:26:49 +00:00
|
|
|
int stor_vsc_initialize(struct hv_driver *driver)
|
2009-07-13 23:01:31 +00:00
|
|
|
{
|
2010-12-06 20:26:49 +00:00
|
|
|
struct storvsc_driver_object *stor_driver;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_driver = (struct storvsc_driver_object *)driver;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-09-01 05:31:22 +00: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 23:01:31 +00:00
|
|
|
|
2009-09-01 05:31:22 +00:00
|
|
|
/* Make sure we are at least 2 pages since 1 page is used for control */
|
2010-12-06 20:26:49 +00:00
|
|
|
/* ASSERT(stor_driver->RingBufferSize >= (PAGE_SIZE << 1)); */
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
driver->name = g_driver_name;
|
2011-01-26 20:12:11 +00:00
|
|
|
memcpy(&driver->dev_type, &gStorVscDeviceType,
|
2009-09-01 05:31:22 +00:00
|
|
|
sizeof(struct hv_guid));
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_driver->request_ext_size =
|
|
|
|
sizeof(struct storvsc_request_extension);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-09-01 05:31:22 +00: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
|
2010-09-20 21:07:51 +00:00
|
|
|
* vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
|
2009-09-01 05:31:22 +00:00
|
|
|
*/
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_driver->max_outstanding_req_per_channel =
|
|
|
|
((stor_driver->ring_buffer_size - PAGE_SIZE) /
|
2011-01-20 08:32:01 +00:00
|
|
|
ALIGN(MAX_MULTIPAGE_BUFFER_PACKET +
|
2009-09-01 05:31:22 +00:00
|
|
|
sizeof(struct vstor_packet) + sizeof(u64),
|
|
|
|
sizeof(u64)));
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-09-01 05:31:22 +00:00
|
|
|
DPRINT_INFO(STORVSC, "max io %u, currently %u\n",
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_driver->max_outstanding_req_per_channel,
|
2009-09-01 05:31:22 +00:00
|
|
|
STORVSC_MAX_IO_REQUESTS);
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-09-01 05:31:22 +00:00
|
|
|
/* Setup the dispatch table */
|
2011-01-26 20:12:11 +00:00
|
|
|
stor_driver->base.dev_add = stor_vsc_on_device_add;
|
|
|
|
stor_driver->base.dev_rm = stor_vsc_on_device_remove;
|
|
|
|
stor_driver->base.cleanup = stor_vsc_on_cleanup;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2010-12-06 20:26:49 +00:00
|
|
|
stor_driver->on_io_request = stor_vsc_on_io_request;
|
2009-07-13 23:01:31 +00:00
|
|
|
|
2009-09-01 05:31:22 +00:00
|
|
|
return 0;
|
2009-07-13 23:01:31 +00:00
|
|
|
}
|