2009-07-14 06:01:31 +07: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>
|
2011-05-10 21:54:19 +07:00
|
|
|
* K. Y. Srinivasan <kys@microsoft.com>
|
2009-07-14 06:01:31 +07:00
|
|
|
*/
|
2011-08-28 01:31:23 +07:00
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2011-08-28 01:31:24 +07:00
|
|
|
#include <linux/wait.h>
|
2011-08-28 01:31:23 +07:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/delay.h>
|
2009-07-14 06:01:31 +07:00
|
|
|
#include <linux/init.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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2009-07-14 06:01:31 +07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/device.h>
|
2011-10-05 02:29:52 +07:00
|
|
|
#include <linux/hyperv.h>
|
2014-07-12 23:48:30 +07:00
|
|
|
#include <linux/blkdev.h>
|
2009-07-14 06:01:31 +07:00
|
|
|
#include <scsi/scsi.h>
|
|
|
|
#include <scsi/scsi_cmnd.h>
|
|
|
|
#include <scsi/scsi_host.h>
|
|
|
|
#include <scsi/scsi_device.h>
|
|
|
|
#include <scsi/scsi_tcq.h>
|
|
|
|
#include <scsi/scsi_eh.h>
|
|
|
|
#include <scsi/scsi_devinfo.h>
|
|
|
|
#include <scsi/scsi_dbg.h>
|
2015-12-24 04:15:49 +07:00
|
|
|
#include <scsi/scsi_transport_fc.h>
|
2016-01-28 09:22:44 +07:00
|
|
|
#include <scsi/scsi_transport.h>
|
2011-05-13 09:34:15 +07:00
|
|
|
|
2012-01-13 03:37:54 +07:00
|
|
|
/*
|
2012-01-13 03:38:08 +07:00
|
|
|
* All wire protocol details (storage protocol between the guest and the host)
|
|
|
|
* are consolidated here.
|
|
|
|
*
|
|
|
|
* Begin protocol definitions.
|
2012-01-13 03:37:54 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Version history:
|
|
|
|
* V1 Beta: 0.1
|
|
|
|
* V1 RC < 2008/1/31: 1.0
|
|
|
|
* V1 RC > 2008/1/31: 2.0
|
|
|
|
* Win7: 4.2
|
2013-06-05 02:05:06 +07:00
|
|
|
* Win8: 5.1
|
2015-08-13 22:43:48 +07:00
|
|
|
* Win8.1: 6.0
|
|
|
|
* Win10: 6.2
|
2012-01-13 03:37:54 +07:00
|
|
|
*/
|
|
|
|
|
2015-08-13 22:43:47 +07:00
|
|
|
#define VMSTOR_PROTO_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \
|
|
|
|
(((MINOR_) & 0xff)))
|
2013-06-05 02:05:06 +07:00
|
|
|
|
2015-08-13 22:43:48 +07:00
|
|
|
#define VMSTOR_PROTO_VERSION_WIN6 VMSTOR_PROTO_VERSION(2, 0)
|
2015-08-13 22:43:47 +07:00
|
|
|
#define VMSTOR_PROTO_VERSION_WIN7 VMSTOR_PROTO_VERSION(4, 2)
|
|
|
|
#define VMSTOR_PROTO_VERSION_WIN8 VMSTOR_PROTO_VERSION(5, 1)
|
2015-08-13 22:43:48 +07:00
|
|
|
#define VMSTOR_PROTO_VERSION_WIN8_1 VMSTOR_PROTO_VERSION(6, 0)
|
|
|
|
#define VMSTOR_PROTO_VERSION_WIN10 VMSTOR_PROTO_VERSION(6, 2)
|
2011-08-28 01:31:24 +07:00
|
|
|
|
|
|
|
/* Packet structure describing virtual storage requests. */
|
|
|
|
enum vstor_packet_operation {
|
|
|
|
VSTOR_OPERATION_COMPLETE_IO = 1,
|
|
|
|
VSTOR_OPERATION_REMOVE_DEVICE = 2,
|
|
|
|
VSTOR_OPERATION_EXECUTE_SRB = 3,
|
|
|
|
VSTOR_OPERATION_RESET_LUN = 4,
|
|
|
|
VSTOR_OPERATION_RESET_ADAPTER = 5,
|
|
|
|
VSTOR_OPERATION_RESET_BUS = 6,
|
|
|
|
VSTOR_OPERATION_BEGIN_INITIALIZATION = 7,
|
|
|
|
VSTOR_OPERATION_END_INITIALIZATION = 8,
|
|
|
|
VSTOR_OPERATION_QUERY_PROTOCOL_VERSION = 9,
|
|
|
|
VSTOR_OPERATION_QUERY_PROPERTIES = 10,
|
2011-11-09 00:01:48 +07:00
|
|
|
VSTOR_OPERATION_ENUMERATE_BUS = 11,
|
2013-06-05 02:05:06 +07:00
|
|
|
VSTOR_OPERATION_FCHBA_DATA = 12,
|
|
|
|
VSTOR_OPERATION_CREATE_SUB_CHANNELS = 13,
|
|
|
|
VSTOR_OPERATION_MAXIMUM = 13
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WWN packet for Fibre Channel HBA
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct hv_fc_wwn_packet {
|
2015-12-24 04:15:48 +07:00
|
|
|
u8 primary_active;
|
|
|
|
u8 reserved1[3];
|
2013-06-05 02:05:06 +07:00
|
|
|
u8 primary_port_wwn[8];
|
|
|
|
u8 primary_node_wwn[8];
|
|
|
|
u8 secondary_port_wwn[8];
|
|
|
|
u8 secondary_node_wwn[8];
|
2011-08-28 01:31:24 +07:00
|
|
|
};
|
|
|
|
|
2013-06-05 02:05:06 +07:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SRB Flag Bits
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SRB_FLAGS_QUEUE_ACTION_ENABLE 0x00000002
|
|
|
|
#define SRB_FLAGS_DISABLE_DISCONNECT 0x00000004
|
|
|
|
#define SRB_FLAGS_DISABLE_SYNCH_TRANSFER 0x00000008
|
|
|
|
#define SRB_FLAGS_BYPASS_FROZEN_QUEUE 0x00000010
|
|
|
|
#define SRB_FLAGS_DISABLE_AUTOSENSE 0x00000020
|
|
|
|
#define SRB_FLAGS_DATA_IN 0x00000040
|
|
|
|
#define SRB_FLAGS_DATA_OUT 0x00000080
|
|
|
|
#define SRB_FLAGS_NO_DATA_TRANSFER 0x00000000
|
|
|
|
#define SRB_FLAGS_UNSPECIFIED_DIRECTION (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)
|
|
|
|
#define SRB_FLAGS_NO_QUEUE_FREEZE 0x00000100
|
|
|
|
#define SRB_FLAGS_ADAPTER_CACHE_ENABLE 0x00000200
|
|
|
|
#define SRB_FLAGS_FREE_SENSE_BUFFER 0x00000400
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This flag indicates the request is part of the workflow for processing a D3.
|
|
|
|
*/
|
|
|
|
#define SRB_FLAGS_D3_PROCESSING 0x00000800
|
|
|
|
#define SRB_FLAGS_IS_ACTIVE 0x00010000
|
|
|
|
#define SRB_FLAGS_ALLOCATED_FROM_ZONE 0x00020000
|
|
|
|
#define SRB_FLAGS_SGLIST_FROM_POOL 0x00040000
|
|
|
|
#define SRB_FLAGS_BYPASS_LOCKED_QUEUE 0x00080000
|
|
|
|
#define SRB_FLAGS_NO_KEEP_AWAKE 0x00100000
|
|
|
|
#define SRB_FLAGS_PORT_DRIVER_ALLOCSENSE 0x00200000
|
|
|
|
#define SRB_FLAGS_PORT_DRIVER_SENSEHASPORT 0x00400000
|
|
|
|
#define SRB_FLAGS_DONT_START_NEXT_PACKET 0x00800000
|
|
|
|
#define SRB_FLAGS_PORT_DRIVER_RESERVED 0x0F000000
|
|
|
|
#define SRB_FLAGS_CLASS_DRIVER_RESERVED 0xF0000000
|
|
|
|
|
2016-12-15 09:46:01 +07:00
|
|
|
#define SP_UNTAGGED ((unsigned char) ~0)
|
|
|
|
#define SRB_SIMPLE_TAG_REQUEST 0x20
|
2013-06-05 02:05:06 +07:00
|
|
|
|
2011-08-28 01:31:24 +07:00
|
|
|
/*
|
|
|
|
* Platform neutral description of a scsi request -
|
|
|
|
* this remains the same across the write regardless of 32/64 bit
|
|
|
|
* note: it's patterned off the SCSI_PASS_THROUGH structure
|
|
|
|
*/
|
2012-01-13 03:38:05 +07:00
|
|
|
#define STORVSC_MAX_CMD_LEN 0x10
|
2013-06-05 02:05:06 +07:00
|
|
|
|
|
|
|
#define POST_WIN7_STORVSC_SENSE_BUFFER_SIZE 0x14
|
|
|
|
#define PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE 0x12
|
|
|
|
|
|
|
|
#define STORVSC_SENSE_BUFFER_SIZE 0x14
|
2012-01-13 03:38:05 +07:00
|
|
|
#define STORVSC_MAX_BUF_LEN_WITH_PADDING 0x14
|
2011-08-28 01:31:24 +07:00
|
|
|
|
2013-06-05 02:05:06 +07:00
|
|
|
/*
|
|
|
|
* Sense buffer size changed in win8; have a run-time
|
2015-08-13 22:43:49 +07:00
|
|
|
* variable to track the size we should use. This value will
|
|
|
|
* likely change during protocol negotiation but it is valid
|
|
|
|
* to start by assuming pre-Win8.
|
2013-06-05 02:05:06 +07:00
|
|
|
*/
|
2015-08-13 22:43:49 +07:00
|
|
|
static int sense_buffer_size = PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE;
|
2013-06-05 02:05:06 +07:00
|
|
|
|
|
|
|
/*
|
2015-08-13 22:43:49 +07:00
|
|
|
* The storage protocol version is determined during the
|
|
|
|
* initial exchange with the host. It will indicate which
|
|
|
|
* storage functionality is available in the host.
|
|
|
|
*/
|
2015-08-13 22:43:47 +07:00
|
|
|
static int vmstor_proto_version;
|
2013-06-05 02:05:06 +07:00
|
|
|
|
2015-12-04 15:07:24 +07:00
|
|
|
#define STORVSC_LOGGING_NONE 0
|
|
|
|
#define STORVSC_LOGGING_ERROR 1
|
|
|
|
#define STORVSC_LOGGING_WARN 2
|
|
|
|
|
|
|
|
static int logging_level = STORVSC_LOGGING_ERROR;
|
|
|
|
module_param(logging_level, int, S_IRUGO|S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(logging_level,
|
|
|
|
"Logging level, 0 - None, 1 - Error (default), 2 - Warning.");
|
|
|
|
|
|
|
|
static inline bool do_logging(int level)
|
|
|
|
{
|
|
|
|
return logging_level >= level;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define storvsc_log(dev, level, fmt, ...) \
|
|
|
|
do { \
|
|
|
|
if (do_logging(level)) \
|
|
|
|
dev_warn(&(dev)->device, fmt, ##__VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
2013-06-05 02:05:06 +07:00
|
|
|
struct vmscsi_win8_extension {
|
|
|
|
/*
|
|
|
|
* The following were added in Windows 8
|
|
|
|
*/
|
|
|
|
u16 reserve;
|
|
|
|
u8 queue_tag;
|
|
|
|
u8 queue_action;
|
|
|
|
u32 srb_flags;
|
|
|
|
u32 time_out_value;
|
|
|
|
u32 queue_sort_ey;
|
|
|
|
} __packed;
|
|
|
|
|
2011-08-28 01:31:24 +07:00
|
|
|
struct vmscsi_request {
|
2012-01-13 03:38:03 +07:00
|
|
|
u16 length;
|
|
|
|
u8 srb_status;
|
|
|
|
u8 scsi_status;
|
2011-08-28 01:31:24 +07:00
|
|
|
|
2012-01-13 03:38:03 +07:00
|
|
|
u8 port_number;
|
|
|
|
u8 path_id;
|
|
|
|
u8 target_id;
|
|
|
|
u8 lun;
|
2011-08-28 01:31:24 +07:00
|
|
|
|
2012-01-13 03:38:03 +07:00
|
|
|
u8 cdb_length;
|
|
|
|
u8 sense_info_length;
|
|
|
|
u8 data_in;
|
|
|
|
u8 reserved;
|
2011-08-28 01:31:24 +07:00
|
|
|
|
2012-01-13 03:38:03 +07:00
|
|
|
u32 data_transfer_length;
|
2011-08-28 01:31:24 +07:00
|
|
|
|
|
|
|
union {
|
2012-01-13 03:38:05 +07:00
|
|
|
u8 cdb[STORVSC_MAX_CMD_LEN];
|
|
|
|
u8 sense_data[STORVSC_SENSE_BUFFER_SIZE];
|
|
|
|
u8 reserved_array[STORVSC_MAX_BUF_LEN_WITH_PADDING];
|
2011-08-28 01:31:24 +07:00
|
|
|
};
|
2013-06-05 02:05:06 +07:00
|
|
|
/*
|
|
|
|
* The following was added in win8.
|
|
|
|
*/
|
|
|
|
struct vmscsi_win8_extension win8_extension;
|
|
|
|
|
2011-08-28 01:31:24 +07:00
|
|
|
} __attribute((packed));
|
|
|
|
|
|
|
|
|
2015-08-13 22:43:49 +07:00
|
|
|
/*
|
|
|
|
* The size of the vmscsi_request has changed in win8. The
|
|
|
|
* additional size is because of new elements added to the
|
|
|
|
* structure. These elements are valid only when we are talking
|
|
|
|
* to a win8 host.
|
|
|
|
* Track the correction to size we need to apply. This value
|
|
|
|
* will likely change during protocol negotiation but it is
|
|
|
|
* valid to start by assuming pre-Win8.
|
|
|
|
*/
|
|
|
|
static int vmscsi_size_delta = sizeof(struct vmscsi_win8_extension);
|
|
|
|
|
2015-08-13 22:43:48 +07:00
|
|
|
/*
|
|
|
|
* The list of storage protocols in order of preference.
|
|
|
|
*/
|
|
|
|
struct vmstor_protocol {
|
|
|
|
int protocol_version;
|
|
|
|
int sense_buffer_size;
|
|
|
|
int vmscsi_size_delta;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const struct vmstor_protocol vmstor_protocols[] = {
|
|
|
|
{
|
|
|
|
VMSTOR_PROTO_VERSION_WIN10,
|
|
|
|
POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
|
|
|
|
0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
VMSTOR_PROTO_VERSION_WIN8_1,
|
|
|
|
POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
|
|
|
|
0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
VMSTOR_PROTO_VERSION_WIN8,
|
|
|
|
POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
|
|
|
|
0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
VMSTOR_PROTO_VERSION_WIN7,
|
|
|
|
PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE,
|
|
|
|
sizeof(struct vmscsi_win8_extension),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
VMSTOR_PROTO_VERSION_WIN6,
|
|
|
|
PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE,
|
|
|
|
sizeof(struct vmscsi_win8_extension),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-28 01:31:24 +07:00
|
|
|
/*
|
2017-02-28 05:29:20 +07:00
|
|
|
* This structure is sent during the initialization phase to get the different
|
2011-08-28 01:31:24 +07:00
|
|
|
* properties of the channel.
|
|
|
|
*/
|
2013-06-05 02:05:06 +07:00
|
|
|
|
|
|
|
#define STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL 0x1
|
|
|
|
|
2011-08-28 01:31:24 +07:00
|
|
|
struct vmstorage_channel_properties {
|
2013-06-05 02:05:06 +07:00
|
|
|
u32 reserved;
|
|
|
|
u16 max_channel_cnt;
|
|
|
|
u16 reserved1;
|
2011-08-28 01:31:24 +07:00
|
|
|
|
2013-06-05 02:05:06 +07:00
|
|
|
u32 flags;
|
2012-01-13 03:38:03 +07:00
|
|
|
u32 max_transfer_bytes;
|
2011-08-28 01:31:24 +07:00
|
|
|
|
2013-06-05 02:05:06 +07:00
|
|
|
u64 reserved2;
|
2011-08-28 01:31:24 +07:00
|
|
|
} __packed;
|
|
|
|
|
|
|
|
/* This structure is sent during the storage protocol negotiations. */
|
|
|
|
struct vmstorage_protocol_version {
|
|
|
|
/* Major (MSW) and minor (LSW) version numbers. */
|
2012-01-13 03:38:04 +07:00
|
|
|
u16 major_minor;
|
2011-08-28 01:31:24 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Revision number is auto-incremented whenever this file is changed
|
|
|
|
* (See FILL_VMSTOR_REVISION macro above). Mismatch does not
|
|
|
|
* definitely indicate incompatibility--but it does indicate mismatched
|
|
|
|
* builds.
|
2012-01-13 03:38:03 +07:00
|
|
|
* This is only used on the windows side. Just set it to 0.
|
2011-08-28 01:31:24 +07:00
|
|
|
*/
|
2012-01-13 03:38:04 +07:00
|
|
|
u16 revision;
|
2011-08-28 01:31:24 +07:00
|
|
|
} __packed;
|
|
|
|
|
|
|
|
/* Channel Property Flags */
|
|
|
|
#define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1
|
|
|
|
#define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2
|
|
|
|
|
|
|
|
struct vstor_packet {
|
|
|
|
/* Requested operation type */
|
|
|
|
enum vstor_packet_operation operation;
|
|
|
|
|
|
|
|
/* Flags - see below for values */
|
2012-01-13 03:38:03 +07:00
|
|
|
u32 flags;
|
2011-08-28 01:31:24 +07:00
|
|
|
|
|
|
|
/* Status of the request returned from the server side. */
|
2012-01-13 03:38:03 +07:00
|
|
|
u32 status;
|
2011-08-28 01:31:24 +07:00
|
|
|
|
|
|
|
/* Data payload area */
|
|
|
|
union {
|
|
|
|
/*
|
|
|
|
* Structure used to forward SCSI commands from the
|
|
|
|
* client to the server.
|
|
|
|
*/
|
|
|
|
struct vmscsi_request vm_srb;
|
|
|
|
|
|
|
|
/* Structure used to query channel properties. */
|
|
|
|
struct vmstorage_channel_properties storage_channel_properties;
|
|
|
|
|
|
|
|
/* Used during version negotiations. */
|
|
|
|
struct vmstorage_protocol_version version;
|
2013-06-05 02:05:06 +07:00
|
|
|
|
|
|
|
/* Fibre channel address packet */
|
|
|
|
struct hv_fc_wwn_packet wwn_packet;
|
|
|
|
|
|
|
|
/* Number of sub-channels to create */
|
|
|
|
u16 sub_channel_count;
|
|
|
|
|
|
|
|
/* This will be the maximum of the union members */
|
|
|
|
u8 buffer[0x34];
|
2011-08-28 01:31:24 +07:00
|
|
|
};
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
/*
|
2012-01-13 03:37:54 +07:00
|
|
|
* Packet Flags:
|
|
|
|
*
|
2011-08-28 01:31:24 +07:00
|
|
|
* This flag indicates that the server should send back a completion for this
|
|
|
|
* packet.
|
|
|
|
*/
|
2012-01-13 03:37:54 +07:00
|
|
|
|
2011-08-28 01:31:24 +07:00
|
|
|
#define REQUEST_COMPLETION_FLAG 0x1
|
|
|
|
|
|
|
|
/* Matches Windows-end */
|
|
|
|
enum storvsc_request_type {
|
2012-01-13 03:38:03 +07:00
|
|
|
WRITE_TYPE = 0,
|
2011-08-28 01:31:24 +07:00
|
|
|
READ_TYPE,
|
|
|
|
UNKNOWN_TYPE,
|
|
|
|
};
|
|
|
|
|
2012-01-13 03:37:57 +07:00
|
|
|
/*
|
|
|
|
* SRB status codes and masks; a subset of the codes used here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SRB_STATUS_AUTOSENSE_VALID 0x80
|
2015-10-07 08:04:01 +07:00
|
|
|
#define SRB_STATUS_QUEUE_FROZEN 0x40
|
2012-01-13 03:37:57 +07:00
|
|
|
#define SRB_STATUS_INVALID_LUN 0x20
|
|
|
|
#define SRB_STATUS_SUCCESS 0x01
|
2013-02-22 03:04:53 +07:00
|
|
|
#define SRB_STATUS_ABORTED 0x02
|
2012-01-13 03:37:57 +07:00
|
|
|
#define SRB_STATUS_ERROR 0x04
|
2016-12-15 09:46:03 +07:00
|
|
|
#define SRB_STATUS_DATA_OVERRUN 0x12
|
2012-01-13 03:37:57 +07:00
|
|
|
|
2015-10-07 08:04:01 +07:00
|
|
|
#define SRB_STATUS(status) \
|
|
|
|
(status & ~(SRB_STATUS_AUTOSENSE_VALID | SRB_STATUS_QUEUE_FROZEN))
|
2012-01-13 03:38:08 +07:00
|
|
|
/*
|
|
|
|
* This is the end of Protocol specific defines.
|
|
|
|
*/
|
|
|
|
|
2015-03-27 14:27:14 +07:00
|
|
|
static int storvsc_ringbuffer_size = (256 * PAGE_SIZE);
|
2015-03-27 14:27:15 +07:00
|
|
|
static u32 max_outstanding_req_per_channel;
|
|
|
|
|
|
|
|
static int storvsc_vcpus_per_sub_channel = 4;
|
2012-01-13 03:38:08 +07:00
|
|
|
|
|
|
|
module_param(storvsc_ringbuffer_size, int, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(storvsc_ringbuffer_size, "Ring buffer size (bytes)");
|
|
|
|
|
2015-03-27 14:27:15 +07:00
|
|
|
module_param(storvsc_vcpus_per_sub_channel, int, S_IRUGO);
|
2016-01-08 18:02:04 +07:00
|
|
|
MODULE_PARM_DESC(storvsc_vcpus_per_sub_channel, "Ratio of VCPUs to subchannels");
|
2013-06-05 02:05:05 +07:00
|
|
|
/*
|
|
|
|
* Timeout in seconds for all devices managed by this driver.
|
|
|
|
*/
|
|
|
|
static int storvsc_timeout = 180;
|
|
|
|
|
2015-12-24 04:15:49 +07:00
|
|
|
#if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
|
|
|
|
static struct scsi_transport_template *fc_transport_template;
|
|
|
|
#endif
|
2012-01-13 03:38:08 +07:00
|
|
|
|
2013-06-05 02:05:07 +07:00
|
|
|
static void storvsc_on_channel_callback(void *context);
|
|
|
|
|
2014-07-12 23:48:26 +07:00
|
|
|
#define STORVSC_MAX_LUNS_PER_TARGET 255
|
|
|
|
#define STORVSC_MAX_TARGETS 2
|
|
|
|
#define STORVSC_MAX_CHANNELS 8
|
2012-01-13 03:38:08 +07:00
|
|
|
|
2014-07-12 23:48:26 +07:00
|
|
|
#define STORVSC_FC_MAX_LUNS_PER_TARGET 255
|
|
|
|
#define STORVSC_FC_MAX_TARGETS 128
|
|
|
|
#define STORVSC_FC_MAX_CHANNELS 8
|
2012-01-13 03:38:08 +07:00
|
|
|
|
2014-07-12 23:48:26 +07:00
|
|
|
#define STORVSC_IDE_MAX_LUNS_PER_TARGET 64
|
|
|
|
#define STORVSC_IDE_MAX_TARGETS 1
|
|
|
|
#define STORVSC_IDE_MAX_CHANNELS 1
|
2012-01-13 03:37:57 +07:00
|
|
|
|
2012-01-13 03:38:07 +07:00
|
|
|
struct storvsc_cmd_request {
|
|
|
|
struct scsi_cmnd *cmd;
|
|
|
|
|
2011-08-28 01:31:24 +07:00
|
|
|
struct hv_device *device;
|
|
|
|
|
|
|
|
/* Synchronize the request/response if needed */
|
|
|
|
struct completion wait_event;
|
|
|
|
|
2015-03-27 14:27:20 +07:00
|
|
|
struct vmbus_channel_packet_multipage_buffer mpb;
|
|
|
|
struct vmbus_packet_mpb_array *payload;
|
|
|
|
u32 payload_sz;
|
|
|
|
|
2011-08-28 01:31:24 +07:00
|
|
|
struct vstor_packet vstor_packet;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* A storvsc device is a device object that contains a vmbus channel */
|
|
|
|
struct storvsc_device {
|
|
|
|
struct hv_device *device;
|
|
|
|
|
|
|
|
bool destroy;
|
|
|
|
bool drain_notify;
|
2013-06-05 02:05:07 +07:00
|
|
|
bool open_sub_channel;
|
2011-08-28 01:31:24 +07:00
|
|
|
atomic_t num_outstanding_req;
|
2011-09-14 00:59:48 +07:00
|
|
|
struct Scsi_Host *host;
|
2011-08-28 01:31:24 +07:00
|
|
|
|
|
|
|
wait_queue_head_t waiting_to_drain;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
unsigned int port_number;
|
|
|
|
unsigned char path_id;
|
|
|
|
unsigned char target_id;
|
|
|
|
|
2015-03-27 14:27:17 +07:00
|
|
|
/*
|
|
|
|
* Max I/O, the device can support.
|
|
|
|
*/
|
|
|
|
u32 max_transfer_bytes;
|
2016-12-15 09:46:00 +07:00
|
|
|
/*
|
|
|
|
* Number of sub-channels we will open.
|
|
|
|
*/
|
|
|
|
u16 num_sc;
|
|
|
|
struct vmbus_channel **stor_chns;
|
|
|
|
/*
|
|
|
|
* Mask of CPUs bound to subchannels.
|
|
|
|
*/
|
|
|
|
struct cpumask alloced_cpus;
|
2011-08-28 01:31:24 +07:00
|
|
|
/* Used for vsc/vsp channel reset process */
|
2012-01-13 03:38:07 +07:00
|
|
|
struct storvsc_cmd_request init_request;
|
|
|
|
struct storvsc_cmd_request reset_request;
|
2015-12-24 04:15:49 +07:00
|
|
|
/*
|
|
|
|
* Currently active port and node names for FC devices.
|
|
|
|
*/
|
|
|
|
u64 node_name;
|
|
|
|
u64 port_name;
|
2011-08-28 01:31:24 +07:00
|
|
|
};
|
|
|
|
|
2011-12-01 19:59:20 +07:00
|
|
|
struct hv_host_device {
|
|
|
|
struct hv_device *dev;
|
2011-08-28 01:31:25 +07:00
|
|
|
unsigned int port;
|
|
|
|
unsigned char path;
|
|
|
|
unsigned char target;
|
|
|
|
};
|
|
|
|
|
2011-11-09 00:01:49 +07:00
|
|
|
struct storvsc_scan_work {
|
|
|
|
struct work_struct work;
|
|
|
|
struct Scsi_Host *host;
|
2016-01-28 09:22:45 +07:00
|
|
|
u8 lun;
|
|
|
|
u8 tgt_id;
|
2011-11-09 00:01:49 +07:00
|
|
|
};
|
|
|
|
|
2013-02-22 03:04:53 +07:00
|
|
|
static void storvsc_device_scan(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct storvsc_scan_work *wrk;
|
|
|
|
struct scsi_device *sdev;
|
|
|
|
|
|
|
|
wrk = container_of(work, struct storvsc_scan_work, work);
|
|
|
|
|
2016-01-28 09:22:45 +07:00
|
|
|
sdev = scsi_device_lookup(wrk->host, 0, wrk->tgt_id, wrk->lun);
|
2013-02-22 03:04:53 +07:00
|
|
|
if (!sdev)
|
|
|
|
goto done;
|
|
|
|
scsi_rescan_device(&sdev->sdev_gendev);
|
|
|
|
scsi_device_put(sdev);
|
|
|
|
|
|
|
|
done:
|
|
|
|
kfree(wrk);
|
|
|
|
}
|
|
|
|
|
2014-12-17 04:21:42 +07:00
|
|
|
static void storvsc_host_scan(struct work_struct *work)
|
2011-11-09 00:01:49 +07:00
|
|
|
{
|
|
|
|
struct storvsc_scan_work *wrk;
|
2014-12-17 04:21:42 +07:00
|
|
|
struct Scsi_Host *host;
|
2014-12-17 04:21:43 +07:00
|
|
|
struct scsi_device *sdev;
|
2011-11-09 00:01:49 +07:00
|
|
|
|
|
|
|
wrk = container_of(work, struct storvsc_scan_work, work);
|
2014-12-17 04:21:42 +07:00
|
|
|
host = wrk->host;
|
|
|
|
|
2014-12-17 04:21:43 +07:00
|
|
|
/*
|
|
|
|
* Before scanning the host, first check to see if any of the
|
|
|
|
* currrently known devices have been hot removed. We issue a
|
|
|
|
* "unit ready" command against all currently known devices.
|
|
|
|
* This I/O will result in an error for devices that have been
|
|
|
|
* removed. As part of handling the I/O error, we remove the device.
|
|
|
|
*
|
|
|
|
* When a LUN is added or removed, the host sends us a signal to
|
|
|
|
* scan the host. Thus we are forced to discover the LUNs that
|
|
|
|
* may have been removed this way.
|
|
|
|
*/
|
|
|
|
mutex_lock(&host->scan_mutex);
|
2015-07-01 16:31:27 +07:00
|
|
|
shost_for_each_device(sdev, host)
|
2014-12-17 04:21:43 +07:00
|
|
|
scsi_test_unit_ready(sdev, 1, 1, NULL);
|
|
|
|
mutex_unlock(&host->scan_mutex);
|
|
|
|
/*
|
|
|
|
* Now scan the host to discover LUNs that may have been added.
|
|
|
|
*/
|
2014-12-17 04:21:42 +07:00
|
|
|
scsi_scan_host(host);
|
|
|
|
|
2011-11-09 00:01:49 +07:00
|
|
|
kfree(wrk);
|
|
|
|
}
|
|
|
|
|
2011-11-09 00:01:50 +07:00
|
|
|
static void storvsc_remove_lun(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct storvsc_scan_work *wrk;
|
|
|
|
struct scsi_device *sdev;
|
|
|
|
|
|
|
|
wrk = container_of(work, struct storvsc_scan_work, work);
|
|
|
|
if (!scsi_host_get(wrk->host))
|
|
|
|
goto done;
|
|
|
|
|
2016-01-28 09:22:45 +07:00
|
|
|
sdev = scsi_device_lookup(wrk->host, 0, wrk->tgt_id, wrk->lun);
|
2011-11-09 00:01:50 +07:00
|
|
|
|
|
|
|
if (sdev) {
|
|
|
|
scsi_remove_device(sdev);
|
|
|
|
scsi_device_put(sdev);
|
|
|
|
}
|
|
|
|
scsi_host_put(wrk->host);
|
|
|
|
|
|
|
|
done:
|
|
|
|
kfree(wrk);
|
|
|
|
}
|
|
|
|
|
2012-01-13 03:38:08 +07:00
|
|
|
|
2012-01-13 03:38:00 +07:00
|
|
|
/*
|
|
|
|
* We can get incoming messages from the host that are not in response to
|
|
|
|
* messages that we have sent out. An example of this would be messages
|
|
|
|
* received by the guest to notify dynamic addition/removal of LUNs. To
|
|
|
|
* deal with potential race conditions where the driver may be in the
|
|
|
|
* midst of being unloaded when we might receive an unsolicited message
|
|
|
|
* from the host, we have implemented a mechanism to gurantee sequential
|
|
|
|
* consistency:
|
|
|
|
*
|
|
|
|
* 1) Once the device is marked as being destroyed, we will fail all
|
|
|
|
* outgoing messages.
|
|
|
|
* 2) We permit incoming messages when the device is being destroyed,
|
|
|
|
* only to properly account for messages already sent out.
|
|
|
|
*/
|
|
|
|
|
2011-08-28 01:31:24 +07:00
|
|
|
static inline struct storvsc_device *get_out_stor_device(
|
|
|
|
struct hv_device *device)
|
|
|
|
{
|
|
|
|
struct storvsc_device *stor_device;
|
|
|
|
|
2011-09-14 00:59:48 +07:00
|
|
|
stor_device = hv_get_drvdata(device);
|
2011-08-28 01:31:24 +07:00
|
|
|
|
|
|
|
if (stor_device && stor_device->destroy)
|
|
|
|
stor_device = NULL;
|
|
|
|
|
|
|
|
return stor_device;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void storvsc_wait_to_drain(struct storvsc_device *dev)
|
|
|
|
{
|
|
|
|
dev->drain_notify = true;
|
|
|
|
wait_event(dev->waiting_to_drain,
|
|
|
|
atomic_read(&dev->num_outstanding_req) == 0);
|
|
|
|
dev->drain_notify = false;
|
|
|
|
}
|
2009-07-14 06:01:31 +07:00
|
|
|
|
2011-08-28 01:31:22 +07:00
|
|
|
static inline struct storvsc_device *get_in_stor_device(
|
|
|
|
struct hv_device *device)
|
|
|
|
{
|
|
|
|
struct storvsc_device *stor_device;
|
|
|
|
|
2011-09-14 00:59:48 +07:00
|
|
|
stor_device = hv_get_drvdata(device);
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
if (!stor_device)
|
|
|
|
goto get_in_err;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the device is being destroyed; allow incoming
|
|
|
|
* traffic only to cleanup outstanding requests.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (stor_device->destroy &&
|
|
|
|
(atomic_read(&stor_device->num_outstanding_req) == 0))
|
|
|
|
stor_device = NULL;
|
|
|
|
|
|
|
|
get_in_err:
|
|
|
|
return stor_device;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-05 02:05:07 +07:00
|
|
|
static void handle_sc_creation(struct vmbus_channel *new_sc)
|
|
|
|
{
|
|
|
|
struct hv_device *device = new_sc->primary_channel->device_obj;
|
|
|
|
struct storvsc_device *stor_device;
|
|
|
|
struct vmstorage_channel_properties props;
|
|
|
|
|
|
|
|
stor_device = get_out_stor_device(device);
|
|
|
|
if (!stor_device)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (stor_device->open_sub_channel == false)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(&props, 0, sizeof(struct vmstorage_channel_properties));
|
|
|
|
|
|
|
|
vmbus_open(new_sc,
|
|
|
|
storvsc_ringbuffer_size,
|
|
|
|
storvsc_ringbuffer_size,
|
|
|
|
(void *)&props,
|
|
|
|
sizeof(struct vmstorage_channel_properties),
|
|
|
|
storvsc_on_channel_callback, new_sc);
|
2016-12-15 09:46:00 +07:00
|
|
|
|
|
|
|
if (new_sc->state == CHANNEL_OPENED_STATE) {
|
|
|
|
stor_device->stor_chns[new_sc->target_cpu] = new_sc;
|
|
|
|
cpumask_set_cpu(new_sc->target_cpu, &stor_device->alloced_cpus);
|
|
|
|
}
|
2013-06-05 02:05:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_multichannel_storage(struct hv_device *device, int max_chns)
|
|
|
|
{
|
|
|
|
struct storvsc_device *stor_device;
|
|
|
|
int num_cpus = num_online_cpus();
|
|
|
|
int num_sc;
|
|
|
|
struct storvsc_cmd_request *request;
|
|
|
|
struct vstor_packet *vstor_packet;
|
|
|
|
int ret, t;
|
|
|
|
|
|
|
|
num_sc = ((max_chns > num_cpus) ? num_cpus : max_chns);
|
|
|
|
stor_device = get_out_stor_device(device);
|
|
|
|
if (!stor_device)
|
|
|
|
return;
|
|
|
|
|
2016-12-15 09:46:00 +07:00
|
|
|
stor_device->num_sc = num_sc;
|
2013-06-05 02:05:07 +07:00
|
|
|
request = &stor_device->init_request;
|
|
|
|
vstor_packet = &request->vstor_packet;
|
|
|
|
|
|
|
|
stor_device->open_sub_channel = true;
|
|
|
|
/*
|
|
|
|
* Establish a handler for dealing with subchannels.
|
|
|
|
*/
|
|
|
|
vmbus_set_sc_create_callback(device->channel, handle_sc_creation);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if sub-channels have already been created. This
|
|
|
|
* can happen when this driver is re-loaded after unloading.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (vmbus_are_subchannels_present(device->channel))
|
|
|
|
return;
|
|
|
|
|
|
|
|
stor_device->open_sub_channel = false;
|
|
|
|
/*
|
|
|
|
* Request the host to create sub-channels.
|
|
|
|
*/
|
|
|
|
memset(request, 0, sizeof(struct storvsc_cmd_request));
|
|
|
|
init_completion(&request->wait_event);
|
|
|
|
vstor_packet->operation = VSTOR_OPERATION_CREATE_SUB_CHANNELS;
|
|
|
|
vstor_packet->flags = REQUEST_COMPLETION_FLAG;
|
|
|
|
vstor_packet->sub_channel_count = num_sc;
|
|
|
|
|
|
|
|
ret = vmbus_sendpacket(device->channel, vstor_packet,
|
|
|
|
(sizeof(struct vstor_packet) -
|
|
|
|
vmscsi_size_delta),
|
|
|
|
(unsigned long)request,
|
|
|
|
VM_PKT_DATA_INBAND,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
t = wait_for_completion_timeout(&request->wait_event, 10*HZ);
|
|
|
|
if (t == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
|
|
|
|
vstor_packet->status != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that we created the sub-channels, invoke the check; this
|
|
|
|
* may trigger the callback.
|
|
|
|
*/
|
|
|
|
stor_device->open_sub_channel = true;
|
|
|
|
vmbus_are_subchannels_present(device->channel);
|
|
|
|
}
|
|
|
|
|
2015-12-24 04:15:49 +07:00
|
|
|
static void cache_wwn(struct storvsc_device *stor_device,
|
|
|
|
struct vstor_packet *vstor_packet)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Cache the currently active port and node ww names.
|
|
|
|
*/
|
|
|
|
if (vstor_packet->wwn_packet.primary_active) {
|
|
|
|
stor_device->node_name =
|
|
|
|
wwn_to_u64(vstor_packet->wwn_packet.primary_node_wwn);
|
|
|
|
stor_device->port_name =
|
|
|
|
wwn_to_u64(vstor_packet->wwn_packet.primary_port_wwn);
|
|
|
|
} else {
|
|
|
|
stor_device->node_name =
|
|
|
|
wwn_to_u64(vstor_packet->wwn_packet.secondary_node_wwn);
|
|
|
|
stor_device->port_name =
|
|
|
|
wwn_to_u64(vstor_packet->wwn_packet.secondary_port_wwn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-24 04:15:50 +07:00
|
|
|
|
|
|
|
static int storvsc_execute_vstor_op(struct hv_device *device,
|
|
|
|
struct storvsc_cmd_request *request,
|
|
|
|
bool status_check)
|
2011-08-28 01:31:22 +07:00
|
|
|
{
|
|
|
|
struct vstor_packet *vstor_packet;
|
2015-12-24 04:15:50 +07:00
|
|
|
int ret, t;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
vstor_packet = &request->vstor_packet;
|
|
|
|
|
|
|
|
init_completion(&request->wait_event);
|
|
|
|
vstor_packet->flags = REQUEST_COMPLETION_FLAG;
|
|
|
|
|
|
|
|
ret = vmbus_sendpacket(device->channel, vstor_packet,
|
2013-06-05 02:05:06 +07:00
|
|
|
(sizeof(struct vstor_packet) -
|
|
|
|
vmscsi_size_delta),
|
2011-08-28 01:31:22 +07:00
|
|
|
(unsigned long)request,
|
|
|
|
VM_PKT_DATA_INBAND,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
if (ret != 0)
|
2015-12-24 04:15:49 +07:00
|
|
|
return ret;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
|
2015-12-24 04:15:49 +07:00
|
|
|
if (t == 0)
|
|
|
|
return -ETIMEDOUT;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
2015-12-24 04:15:50 +07:00
|
|
|
if (!status_check)
|
|
|
|
return ret;
|
|
|
|
|
2011-08-28 01:31:22 +07:00
|
|
|
if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
|
2015-12-24 04:15:49 +07:00
|
|
|
vstor_packet->status != 0)
|
|
|
|
return -EINVAL;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
2015-12-24 04:15:50 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int storvsc_channel_init(struct hv_device *device, bool is_fc)
|
|
|
|
{
|
|
|
|
struct storvsc_device *stor_device;
|
|
|
|
struct storvsc_cmd_request *request;
|
|
|
|
struct vstor_packet *vstor_packet;
|
|
|
|
int ret, i;
|
|
|
|
int max_chns;
|
|
|
|
bool process_sub_channels = false;
|
|
|
|
|
|
|
|
stor_device = get_out_stor_device(device);
|
|
|
|
if (!stor_device)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
request = &stor_device->init_request;
|
|
|
|
vstor_packet = &request->vstor_packet;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now, initiate the vsc/vsp initialization protocol on the open
|
|
|
|
* channel
|
|
|
|
*/
|
|
|
|
memset(request, 0, sizeof(struct storvsc_cmd_request));
|
|
|
|
vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION;
|
|
|
|
ret = storvsc_execute_vstor_op(device, request, true);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
/*
|
|
|
|
* Query host supported protocol version.
|
|
|
|
*/
|
2011-08-28 01:31:22 +07:00
|
|
|
|
2015-08-13 22:43:48 +07:00
|
|
|
for (i = 0; i < ARRAY_SIZE(vmstor_protocols); i++) {
|
|
|
|
/* reuse the packet for version range supported */
|
|
|
|
memset(vstor_packet, 0, sizeof(struct vstor_packet));
|
|
|
|
vstor_packet->operation =
|
|
|
|
VSTOR_OPERATION_QUERY_PROTOCOL_VERSION;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
2015-08-13 22:43:48 +07:00
|
|
|
vstor_packet->version.major_minor =
|
|
|
|
vmstor_protocols[i].protocol_version;
|
2012-01-13 03:38:04 +07:00
|
|
|
|
2015-08-13 22:43:48 +07:00
|
|
|
/*
|
|
|
|
* The revision number is only used in Windows; set it to 0.
|
|
|
|
*/
|
|
|
|
vstor_packet->version.revision = 0;
|
2015-12-24 04:15:50 +07:00
|
|
|
ret = storvsc_execute_vstor_op(device, request, false);
|
2015-08-13 22:43:48 +07:00
|
|
|
if (ret != 0)
|
2015-12-24 04:15:49 +07:00
|
|
|
return ret;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
2015-12-24 04:15:49 +07:00
|
|
|
if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO)
|
|
|
|
return -EINVAL;
|
2015-08-13 22:43:48 +07:00
|
|
|
|
|
|
|
if (vstor_packet->status == 0) {
|
|
|
|
vmstor_proto_version =
|
|
|
|
vmstor_protocols[i].protocol_version;
|
|
|
|
|
|
|
|
sense_buffer_size =
|
|
|
|
vmstor_protocols[i].sense_buffer_size;
|
|
|
|
|
|
|
|
vmscsi_size_delta =
|
|
|
|
vmstor_protocols[i].vmscsi_size_delta;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2011-08-28 01:31:22 +07:00
|
|
|
}
|
|
|
|
|
2015-12-24 04:15:49 +07:00
|
|
|
if (vstor_packet->status != 0)
|
|
|
|
return -EINVAL;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
|
|
|
|
memset(vstor_packet, 0, sizeof(struct vstor_packet));
|
|
|
|
vstor_packet->operation = VSTOR_OPERATION_QUERY_PROPERTIES;
|
2015-12-24 04:15:50 +07:00
|
|
|
ret = storvsc_execute_vstor_op(device, request, true);
|
2011-08-28 01:31:22 +07:00
|
|
|
if (ret != 0)
|
2015-12-24 04:15:49 +07:00
|
|
|
return ret;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
2013-06-05 02:05:07 +07:00
|
|
|
/*
|
|
|
|
* Check to see if multi-channel support is there.
|
|
|
|
* Hosts that implement protocol version of 5.1 and above
|
|
|
|
* support multi-channel.
|
|
|
|
*/
|
|
|
|
max_chns = vstor_packet->storage_channel_properties.max_channel_cnt;
|
2016-12-15 09:46:00 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate state to manage the sub-channels.
|
|
|
|
* We allocate an array based on the numbers of possible CPUs
|
|
|
|
* (Hyper-V does not support cpu online/offline).
|
|
|
|
* This Array will be sparseley populated with unique
|
|
|
|
* channels - primary + sub-channels.
|
|
|
|
* We will however populate all the slots to evenly distribute
|
|
|
|
* the load.
|
|
|
|
*/
|
|
|
|
stor_device->stor_chns = kzalloc(sizeof(void *) * num_possible_cpus(),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (stor_device->stor_chns == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
stor_device->stor_chns[device->channel->target_cpu] = device->channel;
|
|
|
|
cpumask_set_cpu(device->channel->target_cpu,
|
|
|
|
&stor_device->alloced_cpus);
|
|
|
|
|
2015-08-13 22:43:50 +07:00
|
|
|
if (vmstor_proto_version >= VMSTOR_PROTO_VERSION_WIN8) {
|
2013-06-05 02:05:07 +07:00
|
|
|
if (vstor_packet->storage_channel_properties.flags &
|
|
|
|
STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL)
|
|
|
|
process_sub_channels = true;
|
|
|
|
}
|
2015-03-27 14:27:17 +07:00
|
|
|
stor_device->max_transfer_bytes =
|
|
|
|
vstor_packet->storage_channel_properties.max_transfer_bytes;
|
2013-06-05 02:05:07 +07:00
|
|
|
|
2015-12-24 04:15:49 +07:00
|
|
|
if (!is_fc)
|
|
|
|
goto done;
|
|
|
|
|
2015-12-24 04:15:50 +07:00
|
|
|
/*
|
|
|
|
* For FC devices retrieve FC HBA data.
|
|
|
|
*/
|
2015-12-24 04:15:49 +07:00
|
|
|
memset(vstor_packet, 0, sizeof(struct vstor_packet));
|
|
|
|
vstor_packet->operation = VSTOR_OPERATION_FCHBA_DATA;
|
2015-12-24 04:15:50 +07:00
|
|
|
ret = storvsc_execute_vstor_op(device, request, true);
|
2015-12-24 04:15:49 +07:00
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cache the currently active port and node ww names.
|
|
|
|
*/
|
|
|
|
cache_wwn(stor_device, vstor_packet);
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
2011-08-28 01:31:22 +07:00
|
|
|
memset(vstor_packet, 0, sizeof(struct vstor_packet));
|
|
|
|
vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION;
|
2015-12-24 04:15:50 +07:00
|
|
|
ret = storvsc_execute_vstor_op(device, request, true);
|
2011-08-28 01:31:22 +07:00
|
|
|
if (ret != 0)
|
2015-12-24 04:15:49 +07:00
|
|
|
return ret;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
2013-06-05 02:05:07 +07:00
|
|
|
if (process_sub_channels)
|
|
|
|
handle_multichannel_storage(device, max_chns);
|
|
|
|
|
2011-08-28 01:31:22 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-02-22 03:04:52 +07:00
|
|
|
static void storvsc_handle_error(struct vmscsi_request *vm_srb,
|
|
|
|
struct scsi_cmnd *scmnd,
|
|
|
|
struct Scsi_Host *host,
|
|
|
|
u8 asc, u8 ascq)
|
|
|
|
{
|
|
|
|
struct storvsc_scan_work *wrk;
|
|
|
|
void (*process_err_fn)(struct work_struct *work);
|
|
|
|
bool do_work = false;
|
|
|
|
|
2015-10-07 08:04:01 +07:00
|
|
|
switch (SRB_STATUS(vm_srb->srb_status)) {
|
2013-02-22 03:04:52 +07:00
|
|
|
case SRB_STATUS_ERROR:
|
2016-12-15 09:46:02 +07:00
|
|
|
/*
|
|
|
|
* Let upper layer deal with error when
|
|
|
|
* sense message is present.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID)
|
|
|
|
break;
|
2013-02-22 03:04:52 +07:00
|
|
|
/*
|
|
|
|
* If there is an error; offline the device since all
|
|
|
|
* error recovery strategies would have already been
|
|
|
|
* deployed on the host side. However, if the command
|
|
|
|
* were a pass-through command deal with it appropriately.
|
|
|
|
*/
|
|
|
|
switch (scmnd->cmnd[0]) {
|
|
|
|
case ATA_16:
|
|
|
|
case ATA_12:
|
|
|
|
set_host_byte(scmnd, DID_PASSTHROUGH);
|
|
|
|
break;
|
2014-07-12 23:48:32 +07:00
|
|
|
/*
|
|
|
|
* On Some Windows hosts TEST_UNIT_READY command can return
|
|
|
|
* SRB_STATUS_ERROR, let the upper level code deal with it
|
|
|
|
* based on the sense information.
|
|
|
|
*/
|
|
|
|
case TEST_UNIT_READY:
|
|
|
|
break;
|
2013-02-22 03:04:52 +07:00
|
|
|
default:
|
|
|
|
set_host_byte(scmnd, DID_TARGET_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SRB_STATUS_INVALID_LUN:
|
|
|
|
do_work = true;
|
|
|
|
process_err_fn = storvsc_remove_lun;
|
|
|
|
break;
|
2016-03-07 17:59:44 +07:00
|
|
|
case SRB_STATUS_ABORTED:
|
|
|
|
if (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID &&
|
|
|
|
(asc == 0x2a) && (ascq == 0x9)) {
|
2013-02-22 03:04:53 +07:00
|
|
|
do_work = true;
|
|
|
|
process_err_fn = storvsc_device_scan;
|
|
|
|
/*
|
|
|
|
* Retry the I/O that trigerred this.
|
|
|
|
*/
|
|
|
|
set_host_byte(scmnd, DID_REQUEUE);
|
|
|
|
}
|
|
|
|
break;
|
2013-02-22 03:04:52 +07:00
|
|
|
}
|
2013-02-22 03:04:53 +07:00
|
|
|
|
2013-02-22 03:04:52 +07:00
|
|
|
if (!do_work)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to schedule work to process this error; schedule it.
|
|
|
|
*/
|
|
|
|
wrk = kmalloc(sizeof(struct storvsc_scan_work), GFP_ATOMIC);
|
|
|
|
if (!wrk) {
|
|
|
|
set_host_byte(scmnd, DID_TARGET_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wrk->host = host;
|
|
|
|
wrk->lun = vm_srb->lun;
|
2016-01-28 09:22:45 +07:00
|
|
|
wrk->tgt_id = vm_srb->target_id;
|
2013-02-22 03:04:52 +07:00
|
|
|
INIT_WORK(&wrk->work, process_err_fn);
|
|
|
|
schedule_work(&wrk->work);
|
|
|
|
}
|
|
|
|
|
2012-01-13 03:38:01 +07:00
|
|
|
|
2015-12-24 04:15:51 +07:00
|
|
|
static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request,
|
|
|
|
struct storvsc_device *stor_dev)
|
2011-08-28 01:31:22 +07:00
|
|
|
{
|
2012-01-13 03:38:01 +07:00
|
|
|
struct scsi_cmnd *scmnd = cmd_request->cmd;
|
|
|
|
struct scsi_sense_hdr sense_hdr;
|
|
|
|
struct vmscsi_request *vm_srb;
|
2016-12-15 09:46:03 +07:00
|
|
|
u32 data_transfer_length;
|
2013-02-22 03:04:52 +07:00
|
|
|
struct Scsi_Host *host;
|
2015-03-27 14:27:20 +07:00
|
|
|
u32 payload_sz = cmd_request->payload_sz;
|
|
|
|
void *payload = cmd_request->payload;
|
2013-02-22 03:04:52 +07:00
|
|
|
|
|
|
|
host = stor_dev->host;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
2012-01-13 03:38:07 +07:00
|
|
|
vm_srb = &cmd_request->vstor_packet.vm_srb;
|
2016-12-15 09:46:03 +07:00
|
|
|
data_transfer_length = vm_srb->data_transfer_length;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
2012-04-06 02:26:52 +07:00
|
|
|
scmnd->result = vm_srb->scsi_status;
|
|
|
|
|
2012-01-13 03:38:01 +07:00
|
|
|
if (scmnd->result) {
|
|
|
|
if (scsi_normalize_sense(scmnd->sense_buffer,
|
2015-12-04 15:07:24 +07:00
|
|
|
SCSI_SENSE_BUFFERSIZE, &sense_hdr) &&
|
2016-05-23 21:29:17 +07:00
|
|
|
!(sense_hdr.sense_key == NOT_READY &&
|
|
|
|
sense_hdr.asc == 0x03A) &&
|
2015-12-04 15:07:24 +07:00
|
|
|
do_logging(STORVSC_LOGGING_ERROR))
|
2014-10-24 19:26:45 +07:00
|
|
|
scsi_print_sense_hdr(scmnd->device, "storvsc",
|
|
|
|
&sense_hdr);
|
2012-01-13 03:38:01 +07:00
|
|
|
}
|
|
|
|
|
2016-12-15 09:46:03 +07:00
|
|
|
if (vm_srb->srb_status != SRB_STATUS_SUCCESS) {
|
2013-02-22 03:04:52 +07:00
|
|
|
storvsc_handle_error(vm_srb, scmnd, host, sense_hdr.asc,
|
|
|
|
sense_hdr.ascq);
|
2016-12-15 09:46:03 +07:00
|
|
|
/*
|
|
|
|
* The Windows driver set data_transfer_length on
|
|
|
|
* SRB_STATUS_DATA_OVERRUN. On other errors, this value
|
|
|
|
* is untouched. In these cases we set it to 0.
|
|
|
|
*/
|
|
|
|
if (vm_srb->srb_status != SRB_STATUS_DATA_OVERRUN)
|
|
|
|
data_transfer_length = 0;
|
|
|
|
}
|
2013-02-22 03:04:52 +07:00
|
|
|
|
2012-01-13 03:38:01 +07:00
|
|
|
scsi_set_resid(scmnd,
|
2016-12-15 09:46:03 +07:00
|
|
|
cmd_request->payload->range.len - data_transfer_length);
|
2012-01-13 03:38:01 +07:00
|
|
|
|
2014-12-30 11:05:09 +07:00
|
|
|
scmnd->scsi_done(scmnd);
|
2015-03-27 14:27:20 +07:00
|
|
|
|
|
|
|
if (payload_sz >
|
|
|
|
sizeof(struct vmbus_channel_packet_multipage_buffer))
|
|
|
|
kfree(payload);
|
2012-01-13 03:38:01 +07:00
|
|
|
}
|
|
|
|
|
2015-12-24 04:15:51 +07:00
|
|
|
static void storvsc_on_io_completion(struct storvsc_device *stor_device,
|
2012-01-13 03:38:01 +07:00
|
|
|
struct vstor_packet *vstor_packet,
|
2012-01-13 03:38:07 +07:00
|
|
|
struct storvsc_cmd_request *request)
|
2012-01-13 03:38:01 +07:00
|
|
|
{
|
|
|
|
struct vstor_packet *stor_pkt;
|
2015-12-24 04:15:51 +07:00
|
|
|
struct hv_device *device = stor_device->device;
|
2012-01-13 03:38:01 +07:00
|
|
|
|
|
|
|
stor_pkt = &request->vstor_packet;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The current SCSI handling on the host side does
|
|
|
|
* not correctly handle:
|
|
|
|
* INQUIRY command with page code parameter set to 0x80
|
|
|
|
* MODE_SENSE command with cmd[2] == 0x1c
|
|
|
|
*
|
|
|
|
* Setup srb and scsi status so this won't be fatal.
|
|
|
|
* We do this so we can distinguish truly fatal failues
|
2011-08-28 01:31:26 +07:00
|
|
|
* (srb status == 0x4) and off-line the device in that case.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((stor_pkt->vm_srb.cdb[0] == INQUIRY) ||
|
2012-01-13 03:38:00 +07:00
|
|
|
(stor_pkt->vm_srb.cdb[0] == MODE_SENSE)) {
|
2011-08-28 01:31:26 +07:00
|
|
|
vstor_packet->vm_srb.scsi_status = 0;
|
2012-01-13 03:37:57 +07:00
|
|
|
vstor_packet->vm_srb.srb_status = SRB_STATUS_SUCCESS;
|
2011-08-28 01:31:26 +07:00
|
|
|
}
|
|
|
|
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
/* Copy over the status...etc */
|
|
|
|
stor_pkt->vm_srb.scsi_status = vstor_packet->vm_srb.scsi_status;
|
|
|
|
stor_pkt->vm_srb.srb_status = vstor_packet->vm_srb.srb_status;
|
|
|
|
stor_pkt->vm_srb.sense_info_length =
|
|
|
|
vstor_packet->vm_srb.sense_info_length;
|
|
|
|
|
2015-12-04 15:07:24 +07:00
|
|
|
if (vstor_packet->vm_srb.scsi_status != 0 ||
|
|
|
|
vstor_packet->vm_srb.srb_status != SRB_STATUS_SUCCESS)
|
|
|
|
storvsc_log(device, STORVSC_LOGGING_WARN,
|
|
|
|
"cmd 0x%x scsi status 0x%x srb status 0x%x\n",
|
|
|
|
stor_pkt->vm_srb.cdb[0],
|
|
|
|
vstor_packet->vm_srb.scsi_status,
|
|
|
|
vstor_packet->vm_srb.srb_status);
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
if ((vstor_packet->vm_srb.scsi_status & 0xFF) == 0x02) {
|
|
|
|
/* CHECK_CONDITION */
|
2012-01-13 03:37:57 +07:00
|
|
|
if (vstor_packet->vm_srb.srb_status &
|
|
|
|
SRB_STATUS_AUTOSENSE_VALID) {
|
2011-08-28 01:31:22 +07:00
|
|
|
/* autosense data available */
|
|
|
|
|
2015-12-04 15:07:24 +07:00
|
|
|
storvsc_log(device, STORVSC_LOGGING_WARN,
|
|
|
|
"stor pkt %p autosense data valid - len %d\n",
|
|
|
|
request, vstor_packet->vm_srb.sense_info_length);
|
|
|
|
|
2014-12-30 11:05:09 +07:00
|
|
|
memcpy(request->cmd->sense_buffer,
|
2011-08-28 01:31:22 +07:00
|
|
|
vstor_packet->vm_srb.sense_data,
|
|
|
|
vstor_packet->vm_srb.sense_info_length);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stor_pkt->vm_srb.data_transfer_length =
|
|
|
|
vstor_packet->vm_srb.data_transfer_length;
|
|
|
|
|
2015-12-24 04:15:51 +07:00
|
|
|
storvsc_command_completion(request, stor_device);
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
if (atomic_dec_and_test(&stor_device->num_outstanding_req) &&
|
|
|
|
stor_device->drain_notify)
|
|
|
|
wake_up(&stor_device->waiting_to_drain);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-24 04:15:51 +07:00
|
|
|
static void storvsc_on_receive(struct storvsc_device *stor_device,
|
2011-08-28 01:31:22 +07:00
|
|
|
struct vstor_packet *vstor_packet,
|
2012-01-13 03:38:07 +07:00
|
|
|
struct storvsc_cmd_request *request)
|
2011-08-28 01:31:22 +07:00
|
|
|
{
|
2011-11-09 00:01:49 +07:00
|
|
|
struct storvsc_scan_work *work;
|
|
|
|
|
2011-08-28 01:31:22 +07:00
|
|
|
switch (vstor_packet->operation) {
|
|
|
|
case VSTOR_OPERATION_COMPLETE_IO:
|
2015-12-24 04:15:51 +07:00
|
|
|
storvsc_on_io_completion(stor_device, vstor_packet, request);
|
2011-08-28 01:31:22 +07:00
|
|
|
break;
|
2011-11-09 00:01:49 +07:00
|
|
|
|
2011-08-28 01:31:22 +07:00
|
|
|
case VSTOR_OPERATION_REMOVE_DEVICE:
|
2011-11-09 00:01:49 +07:00
|
|
|
case VSTOR_OPERATION_ENUMERATE_BUS:
|
|
|
|
work = kmalloc(sizeof(struct storvsc_scan_work), GFP_ATOMIC);
|
|
|
|
if (!work)
|
|
|
|
return;
|
|
|
|
|
2014-12-17 04:21:42 +07:00
|
|
|
INIT_WORK(&work->work, storvsc_host_scan);
|
2011-11-09 00:01:49 +07:00
|
|
|
work->host = stor_device->host;
|
|
|
|
schedule_work(&work->work);
|
|
|
|
break;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
2015-12-24 04:15:49 +07:00
|
|
|
case VSTOR_OPERATION_FCHBA_DATA:
|
|
|
|
cache_wwn(stor_device, vstor_packet);
|
|
|
|
#if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
|
|
|
|
fc_host_node_name(stor_device->host) = stor_device->node_name;
|
|
|
|
fc_host_port_name(stor_device->host) = stor_device->port_name;
|
|
|
|
#endif
|
|
|
|
break;
|
2011-08-28 01:31:22 +07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void storvsc_on_channel_callback(void *context)
|
|
|
|
{
|
2013-06-05 02:05:07 +07:00
|
|
|
struct vmbus_channel *channel = (struct vmbus_channel *)context;
|
|
|
|
struct hv_device *device;
|
2011-08-28 01:31:22 +07:00
|
|
|
struct storvsc_device *stor_device;
|
|
|
|
u32 bytes_recvd;
|
|
|
|
u64 request_id;
|
|
|
|
unsigned char packet[ALIGN(sizeof(struct vstor_packet), 8)];
|
2012-01-13 03:38:07 +07:00
|
|
|
struct storvsc_cmd_request *request;
|
2011-08-28 01:31:22 +07:00
|
|
|
int ret;
|
|
|
|
|
2013-06-05 02:05:07 +07:00
|
|
|
if (channel->primary_channel != NULL)
|
|
|
|
device = channel->primary_channel->device_obj;
|
|
|
|
else
|
|
|
|
device = channel->device_obj;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
stor_device = get_in_stor_device(device);
|
|
|
|
if (!stor_device)
|
|
|
|
return;
|
|
|
|
|
|
|
|
do {
|
2013-06-05 02:05:07 +07:00
|
|
|
ret = vmbus_recvpacket(channel, packet,
|
2013-06-05 02:05:06 +07:00
|
|
|
ALIGN((sizeof(struct vstor_packet) -
|
|
|
|
vmscsi_size_delta), 8),
|
2011-08-28 01:31:22 +07:00
|
|
|
&bytes_recvd, &request_id);
|
|
|
|
if (ret == 0 && bytes_recvd > 0) {
|
|
|
|
|
2012-01-13 03:38:07 +07:00
|
|
|
request = (struct storvsc_cmd_request *)
|
2011-08-28 01:31:22 +07:00
|
|
|
(unsigned long)request_id;
|
|
|
|
|
|
|
|
if ((request == &stor_device->init_request) ||
|
|
|
|
(request == &stor_device->reset_request)) {
|
|
|
|
|
|
|
|
memcpy(&request->vstor_packet, packet,
|
2013-06-05 02:05:06 +07:00
|
|
|
(sizeof(struct vstor_packet) -
|
|
|
|
vmscsi_size_delta));
|
2011-08-28 01:31:22 +07:00
|
|
|
complete(&request->wait_event);
|
|
|
|
} else {
|
2015-12-24 04:15:51 +07:00
|
|
|
storvsc_on_receive(stor_device,
|
2011-08-28 01:31:22 +07:00
|
|
|
(struct vstor_packet *)packet,
|
|
|
|
request);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-24 04:15:49 +07:00
|
|
|
static int storvsc_connect_to_vsp(struct hv_device *device, u32 ring_size,
|
|
|
|
bool is_fc)
|
2011-08-28 01:31:22 +07:00
|
|
|
{
|
|
|
|
struct vmstorage_channel_properties props;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
memset(&props, 0, sizeof(struct vmstorage_channel_properties));
|
|
|
|
|
|
|
|
ret = vmbus_open(device->channel,
|
|
|
|
ring_size,
|
|
|
|
ring_size,
|
|
|
|
(void *)&props,
|
|
|
|
sizeof(struct vmstorage_channel_properties),
|
2013-06-05 02:05:07 +07:00
|
|
|
storvsc_on_channel_callback, device->channel);
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
2015-12-24 04:15:49 +07:00
|
|
|
ret = storvsc_channel_init(device, is_fc);
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-08-28 01:31:25 +07:00
|
|
|
static int storvsc_dev_remove(struct hv_device *device)
|
2011-08-28 01:31:22 +07:00
|
|
|
{
|
|
|
|
struct storvsc_device *stor_device;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2011-09-14 00:59:48 +07:00
|
|
|
stor_device = hv_get_drvdata(device);
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
spin_lock_irqsave(&device->channel->inbound_lock, flags);
|
|
|
|
stor_device->destroy = true;
|
|
|
|
spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, all outbound traffic should be disable. We
|
|
|
|
* only allow inbound traffic (responses) to proceed so that
|
|
|
|
* outstanding requests can be completed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
storvsc_wait_to_drain(stor_device);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since we have already drained, we don't need to busy wait
|
|
|
|
* as was done in final_release_stor_device()
|
|
|
|
* Note that we cannot set the ext pointer to NULL until
|
|
|
|
* we have drained - to drain the outgoing packets, we need to
|
|
|
|
* allow incoming packets.
|
|
|
|
*/
|
|
|
|
spin_lock_irqsave(&device->channel->inbound_lock, flags);
|
2011-09-14 00:59:48 +07:00
|
|
|
hv_set_drvdata(device, NULL);
|
2011-08-28 01:31:22 +07:00
|
|
|
spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
|
|
|
|
|
|
|
|
/* Close the channel */
|
|
|
|
vmbus_close(device->channel);
|
|
|
|
|
2016-12-15 09:46:00 +07:00
|
|
|
kfree(stor_device->stor_chns);
|
2011-08-28 01:31:22 +07:00
|
|
|
kfree(stor_device);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-15 09:46:00 +07:00
|
|
|
static struct vmbus_channel *get_og_chn(struct storvsc_device *stor_device,
|
|
|
|
u16 q_num)
|
|
|
|
{
|
|
|
|
u16 slot = 0;
|
|
|
|
u16 hash_qnum;
|
|
|
|
struct cpumask alloced_mask;
|
|
|
|
int num_channels, tgt_cpu;
|
|
|
|
|
|
|
|
if (stor_device->num_sc == 0)
|
|
|
|
return stor_device->device->channel;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our channel array is sparsley populated and we
|
|
|
|
* initiated I/O on a processor/hw-q that does not
|
|
|
|
* currently have a designated channel. Fix this.
|
|
|
|
* The strategy is simple:
|
|
|
|
* I. Ensure NUMA locality
|
|
|
|
* II. Distribute evenly (best effort)
|
|
|
|
* III. Mapping is persistent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
cpumask_and(&alloced_mask, &stor_device->alloced_cpus,
|
|
|
|
cpumask_of_node(cpu_to_node(q_num)));
|
|
|
|
|
|
|
|
num_channels = cpumask_weight(&alloced_mask);
|
|
|
|
if (num_channels == 0)
|
|
|
|
return stor_device->device->channel;
|
|
|
|
|
|
|
|
hash_qnum = q_num;
|
|
|
|
while (hash_qnum >= num_channels)
|
|
|
|
hash_qnum -= num_channels;
|
|
|
|
|
|
|
|
for_each_cpu(tgt_cpu, &alloced_mask) {
|
|
|
|
if (slot == hash_qnum)
|
|
|
|
break;
|
|
|
|
slot++;
|
|
|
|
}
|
|
|
|
|
|
|
|
stor_device->stor_chns[q_num] = stor_device->stor_chns[tgt_cpu];
|
|
|
|
|
|
|
|
return stor_device->stor_chns[q_num];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-28 01:31:25 +07:00
|
|
|
static int storvsc_do_io(struct hv_device *device,
|
2016-12-15 09:46:00 +07:00
|
|
|
struct storvsc_cmd_request *request, u16 q_num)
|
2011-08-28 01:31:22 +07:00
|
|
|
{
|
|
|
|
struct storvsc_device *stor_device;
|
|
|
|
struct vstor_packet *vstor_packet;
|
2013-06-05 02:05:07 +07:00
|
|
|
struct vmbus_channel *outgoing_channel;
|
2011-08-28 01:31:22 +07:00
|
|
|
int ret = 0;
|
2016-12-15 09:46:00 +07:00
|
|
|
struct cpumask alloced_mask;
|
|
|
|
int tgt_cpu;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
vstor_packet = &request->vstor_packet;
|
|
|
|
stor_device = get_out_stor_device(device);
|
|
|
|
|
|
|
|
if (!stor_device)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
|
|
|
|
request->device = device;
|
2013-06-05 02:05:07 +07:00
|
|
|
/*
|
|
|
|
* Select an an appropriate channel to send the request out.
|
|
|
|
*/
|
|
|
|
|
2016-12-15 09:46:00 +07:00
|
|
|
if (stor_device->stor_chns[q_num] != NULL) {
|
|
|
|
outgoing_channel = stor_device->stor_chns[q_num];
|
|
|
|
if (outgoing_channel->target_cpu == smp_processor_id()) {
|
|
|
|
/*
|
|
|
|
* Ideally, we want to pick a different channel if
|
|
|
|
* available on the same NUMA node.
|
|
|
|
*/
|
|
|
|
cpumask_and(&alloced_mask, &stor_device->alloced_cpus,
|
|
|
|
cpumask_of_node(cpu_to_node(q_num)));
|
|
|
|
for_each_cpu(tgt_cpu, &alloced_mask) {
|
|
|
|
if (tgt_cpu != outgoing_channel->target_cpu) {
|
|
|
|
outgoing_channel =
|
|
|
|
stor_device->stor_chns[tgt_cpu];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
outgoing_channel = get_og_chn(stor_device, q_num);
|
|
|
|
}
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
|
|
|
|
vstor_packet->flags |= REQUEST_COMPLETION_FLAG;
|
|
|
|
|
2013-06-05 02:05:06 +07:00
|
|
|
vstor_packet->vm_srb.length = (sizeof(struct vmscsi_request) -
|
|
|
|
vmscsi_size_delta);
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
|
2013-06-05 02:05:06 +07:00
|
|
|
vstor_packet->vm_srb.sense_info_length = sense_buffer_size;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
|
|
|
|
vstor_packet->vm_srb.data_transfer_length =
|
2015-03-27 14:27:20 +07:00
|
|
|
request->payload->range.len;
|
2011-08-28 01:31:22 +07:00
|
|
|
|
|
|
|
vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB;
|
|
|
|
|
2015-03-27 14:27:20 +07:00
|
|
|
if (request->payload->range.len) {
|
|
|
|
|
|
|
|
ret = vmbus_sendpacket_mpb_desc(outgoing_channel,
|
|
|
|
request->payload, request->payload_sz,
|
2011-08-28 01:31:22 +07:00
|
|
|
vstor_packet,
|
2013-06-05 02:05:06 +07:00
|
|
|
(sizeof(struct vstor_packet) -
|
|
|
|
vmscsi_size_delta),
|
2011-08-28 01:31:22 +07:00
|
|
|
(unsigned long)request);
|
|
|
|
} else {
|
2015-03-27 14:27:16 +07:00
|
|
|
ret = vmbus_sendpacket(outgoing_channel, vstor_packet,
|
2013-06-05 02:05:06 +07:00
|
|
|
(sizeof(struct vstor_packet) -
|
|
|
|
vmscsi_size_delta),
|
2011-08-28 01:31:22 +07:00
|
|
|
(unsigned long)request,
|
|
|
|
VM_PKT_DATA_INBAND,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
atomic_inc(&stor_device->num_outstanding_req);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-08 00:15:53 +07:00
|
|
|
static int storvsc_device_alloc(struct scsi_device *sdevice)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set blist flag to permit the reading of the VPD pages even when
|
|
|
|
* the target may claim SPC-2 compliance. MSFT targets currently
|
|
|
|
* claim SPC-2 compliance while they implement post SPC-2 features.
|
|
|
|
* With this flag we can correctly handle WRITE_SAME_16 issues.
|
|
|
|
*
|
|
|
|
* Hypervisor reports SCSI_UNKNOWN type for DVD ROM device but
|
|
|
|
* still supports REPORT LUN.
|
|
|
|
*/
|
|
|
|
sdevice->sdev_bflags = BLIST_REPORTLUN2 | BLIST_TRY_VPD_PAGES;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-10 21:54:27 +07:00
|
|
|
static int storvsc_device_configure(struct scsi_device *sdevice)
|
|
|
|
{
|
|
|
|
|
|
|
|
blk_queue_bounce_limit(sdevice->request_queue, BLK_BOUNCE_ANY);
|
|
|
|
|
2013-06-05 02:05:05 +07:00
|
|
|
blk_queue_rq_timeout(sdevice->request_queue, (storvsc_timeout * HZ));
|
|
|
|
|
2015-10-02 04:53:17 +07:00
|
|
|
/* Ensure there are no gaps in presented sgls */
|
|
|
|
blk_queue_virt_boundary(sdevice->request_queue, PAGE_SIZE - 1);
|
|
|
|
|
2013-02-22 03:04:51 +07:00
|
|
|
sdevice->no_write_same = 1;
|
|
|
|
|
2014-12-17 04:21:45 +07:00
|
|
|
/*
|
|
|
|
* If the host is WIN8 or WIN8 R2, claim conformance to SPC-3
|
2015-08-13 22:43:51 +07:00
|
|
|
* if the device is a MSFT virtual device. If the host is
|
|
|
|
* WIN10 or newer, allow write_same.
|
2014-12-17 04:21:45 +07:00
|
|
|
*/
|
|
|
|
if (!strncmp(sdevice->vendor, "Msft", 4)) {
|
2015-08-13 22:43:50 +07:00
|
|
|
switch (vmstor_proto_version) {
|
|
|
|
case VMSTOR_PROTO_VERSION_WIN8:
|
|
|
|
case VMSTOR_PROTO_VERSION_WIN8_1:
|
2014-12-17 04:21:45 +07:00
|
|
|
sdevice->scsi_level = SCSI_SPC_3;
|
|
|
|
break;
|
|
|
|
}
|
2015-08-13 22:43:51 +07:00
|
|
|
|
|
|
|
if (vmstor_proto_version >= VMSTOR_PROTO_VERSION_WIN10)
|
|
|
|
sdevice->no_write_same = 0;
|
2014-12-17 04:21:45 +07:00
|
|
|
}
|
|
|
|
|
2011-05-10 21:54:27 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-10 21:54:34 +07:00
|
|
|
static int storvsc_get_chs(struct scsi_device *sdev, struct block_device * bdev,
|
|
|
|
sector_t capacity, int *info)
|
|
|
|
{
|
2011-05-10 21:54:52 +07:00
|
|
|
sector_t nsect = capacity;
|
|
|
|
sector_t cylinders = nsect;
|
|
|
|
int heads, sectors_pt;
|
2011-05-10 21:54:34 +07:00
|
|
|
|
2011-05-10 21:54:52 +07:00
|
|
|
/*
|
|
|
|
* We are making up these values; let us keep it simple.
|
|
|
|
*/
|
|
|
|
heads = 0xff;
|
|
|
|
sectors_pt = 0x3f; /* Sectors per track */
|
|
|
|
sector_div(cylinders, heads * sectors_pt);
|
|
|
|
if ((sector_t)(cylinders + 1) * heads * sectors_pt < nsect)
|
|
|
|
cylinders = 0xffff;
|
2011-05-10 21:54:34 +07:00
|
|
|
|
|
|
|
info[0] = heads;
|
2011-05-10 21:54:52 +07:00
|
|
|
info[1] = sectors_pt;
|
|
|
|
info[2] = (int)cylinders;
|
2011-05-10 21:54:34 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-05-10 21:54:37 +07:00
|
|
|
|
2012-01-13 03:37:58 +07:00
|
|
|
static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd)
|
2011-05-10 21:54:37 +07:00
|
|
|
{
|
2012-01-13 03:37:58 +07:00
|
|
|
struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
|
|
|
|
struct hv_device *device = host_dev->dev;
|
|
|
|
|
2011-05-10 21:54:37 +07:00
|
|
|
struct storvsc_device *stor_device;
|
2012-01-13 03:38:07 +07:00
|
|
|
struct storvsc_cmd_request *request;
|
2011-05-10 21:54:37 +07:00
|
|
|
struct vstor_packet *vstor_packet;
|
|
|
|
int ret, t;
|
|
|
|
|
|
|
|
|
2011-08-28 01:31:03 +07:00
|
|
|
stor_device = get_out_stor_device(device);
|
2011-05-10 21:54:37 +07:00
|
|
|
if (!stor_device)
|
2011-11-09 00:01:43 +07:00
|
|
|
return FAILED;
|
2011-05-10 21:54:37 +07:00
|
|
|
|
|
|
|
request = &stor_device->reset_request;
|
|
|
|
vstor_packet = &request->vstor_packet;
|
|
|
|
|
|
|
|
init_completion(&request->wait_event);
|
|
|
|
|
|
|
|
vstor_packet->operation = VSTOR_OPERATION_RESET_BUS;
|
|
|
|
vstor_packet->flags = REQUEST_COMPLETION_FLAG;
|
|
|
|
vstor_packet->vm_srb.path_id = stor_device->path_id;
|
|
|
|
|
|
|
|
ret = vmbus_sendpacket(device->channel, vstor_packet,
|
2013-06-05 02:05:06 +07:00
|
|
|
(sizeof(struct vstor_packet) -
|
|
|
|
vmscsi_size_delta),
|
2011-05-10 21:54:37 +07:00
|
|
|
(unsigned long)&stor_device->reset_request,
|
|
|
|
VM_PKT_DATA_INBAND,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
if (ret != 0)
|
2011-11-09 00:01:43 +07:00
|
|
|
return FAILED;
|
2011-05-10 21:54:37 +07:00
|
|
|
|
2011-06-17 03:16:36 +07:00
|
|
|
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
|
2011-11-09 00:01:43 +07:00
|
|
|
if (t == 0)
|
|
|
|
return TIMEOUT_ERROR;
|
2011-05-10 21:54:37 +07:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, all outstanding requests in the adapter
|
|
|
|
* should have been flushed out and return to us
|
2012-10-03 01:03:31 +07:00
|
|
|
* There is a potential race here where the host may be in
|
|
|
|
* the process of responding when we return from here.
|
|
|
|
* Just wait for all in-transit packets to be accounted for
|
|
|
|
* before we return from here.
|
2011-05-10 21:54:37 +07:00
|
|
|
*/
|
2012-10-03 01:03:31 +07:00
|
|
|
storvsc_wait_to_drain(stor_device);
|
2011-05-10 21:54:37 +07:00
|
|
|
|
2011-11-09 00:01:43 +07:00
|
|
|
return SUCCESS;
|
2011-05-10 21:54:37 +07:00
|
|
|
}
|
|
|
|
|
2014-07-12 23:48:30 +07:00
|
|
|
/*
|
|
|
|
* The host guarantees to respond to each command, although I/O latencies might
|
|
|
|
* be unbounded on Azure. Reset the timer unconditionally to give the host a
|
|
|
|
* chance to perform EH.
|
|
|
|
*/
|
|
|
|
static enum blk_eh_timer_return storvsc_eh_timed_out(struct scsi_cmnd *scmnd)
|
|
|
|
{
|
|
|
|
return BLK_EH_RESET_TIMER;
|
|
|
|
}
|
|
|
|
|
2012-01-13 03:37:56 +07:00
|
|
|
static bool storvsc_scsi_cmd_ok(struct scsi_cmnd *scmnd)
|
2011-10-10 14:37:39 +07:00
|
|
|
{
|
|
|
|
bool allowed = true;
|
|
|
|
u8 scsi_op = scmnd->cmnd[0];
|
|
|
|
|
|
|
|
switch (scsi_op) {
|
2013-02-22 03:04:51 +07:00
|
|
|
/* the host does not handle WRITE_SAME, log accident usage */
|
|
|
|
case WRITE_SAME:
|
2012-01-13 03:37:56 +07:00
|
|
|
/*
|
|
|
|
* smartd sends this command and the host does not handle
|
|
|
|
* this. So, don't send it.
|
|
|
|
*/
|
2011-10-15 11:31:57 +07:00
|
|
|
case SET_WINDOW:
|
2011-11-09 00:01:42 +07:00
|
|
|
scmnd->result = ILLEGAL_REQUEST << 16;
|
2011-10-15 11:31:57 +07:00
|
|
|
allowed = false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2011-10-10 14:37:39 +07:00
|
|
|
}
|
|
|
|
return allowed;
|
|
|
|
}
|
2011-05-10 21:54:42 +07:00
|
|
|
|
2011-11-09 00:01:45 +07:00
|
|
|
static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
|
2011-05-10 21:54:42 +07:00
|
|
|
{
|
|
|
|
int ret;
|
2011-11-09 00:01:45 +07:00
|
|
|
struct hv_host_device *host_dev = shost_priv(host);
|
2011-05-10 21:54:42 +07:00
|
|
|
struct hv_device *dev = host_dev->dev;
|
2014-12-30 11:05:09 +07:00
|
|
|
struct storvsc_cmd_request *cmd_request = scsi_cmd_priv(scmnd);
|
2011-05-10 21:54:42 +07:00
|
|
|
int i;
|
|
|
|
struct scatterlist *sgl;
|
|
|
|
unsigned int sg_count = 0;
|
|
|
|
struct vmscsi_request *vm_srb;
|
2015-03-27 14:27:19 +07:00
|
|
|
struct scatterlist *cur_sgl;
|
2015-03-27 14:27:20 +07:00
|
|
|
struct vmbus_packet_mpb_array *payload;
|
|
|
|
u32 payload_sz;
|
|
|
|
u32 length;
|
2011-05-10 21:54:42 +07:00
|
|
|
|
2015-08-13 22:43:47 +07:00
|
|
|
if (vmstor_proto_version <= VMSTOR_PROTO_VERSION_WIN8) {
|
2014-07-12 23:48:28 +07:00
|
|
|
/*
|
|
|
|
* On legacy hosts filter unimplemented commands.
|
|
|
|
* Future hosts are expected to correctly handle
|
|
|
|
* unsupported commands. Furthermore, it is
|
|
|
|
* possible that some of the currently
|
|
|
|
* unsupported commands maybe supported in
|
|
|
|
* future versions of the host.
|
|
|
|
*/
|
|
|
|
if (!storvsc_scsi_cmd_ok(scmnd)) {
|
|
|
|
scmnd->scsi_done(scmnd);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-10-10 14:37:39 +07:00
|
|
|
}
|
2011-05-10 21:54:42 +07:00
|
|
|
|
|
|
|
/* Setup the cmd request */
|
|
|
|
cmd_request->cmd = scmnd;
|
|
|
|
|
2012-01-13 03:38:07 +07:00
|
|
|
vm_srb = &cmd_request->vstor_packet.vm_srb;
|
2013-06-05 02:05:06 +07:00
|
|
|
vm_srb->win8_extension.time_out_value = 60;
|
2011-05-10 21:54:42 +07:00
|
|
|
|
2014-07-12 23:48:31 +07:00
|
|
|
vm_srb->win8_extension.srb_flags |=
|
2015-08-31 22:21:54 +07:00
|
|
|
SRB_FLAGS_DISABLE_SYNCH_TRANSFER;
|
2011-05-10 21:54:42 +07:00
|
|
|
|
2016-12-15 09:46:01 +07:00
|
|
|
if (scmnd->device->tagged_supported) {
|
|
|
|
vm_srb->win8_extension.srb_flags |=
|
|
|
|
(SRB_FLAGS_QUEUE_ACTION_ENABLE | SRB_FLAGS_NO_QUEUE_FREEZE);
|
|
|
|
vm_srb->win8_extension.queue_tag = SP_UNTAGGED;
|
|
|
|
vm_srb->win8_extension.queue_action = SRB_SIMPLE_TAG_REQUEST;
|
|
|
|
}
|
|
|
|
|
2011-05-10 21:54:42 +07:00
|
|
|
/* Build the SRB */
|
|
|
|
switch (scmnd->sc_data_direction) {
|
|
|
|
case DMA_TO_DEVICE:
|
|
|
|
vm_srb->data_in = WRITE_TYPE;
|
2013-06-05 02:05:06 +07:00
|
|
|
vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_OUT;
|
2011-05-10 21:54:42 +07:00
|
|
|
break;
|
|
|
|
case DMA_FROM_DEVICE:
|
|
|
|
vm_srb->data_in = READ_TYPE;
|
2013-06-05 02:05:06 +07:00
|
|
|
vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_IN;
|
2011-05-10 21:54:42 +07:00
|
|
|
break;
|
2015-06-25 23:12:11 +07:00
|
|
|
case DMA_NONE:
|
2011-05-10 21:54:42 +07:00
|
|
|
vm_srb->data_in = UNKNOWN_TYPE;
|
2015-05-02 01:03:02 +07:00
|
|
|
vm_srb->win8_extension.srb_flags |= SRB_FLAGS_NO_DATA_TRANSFER;
|
2011-05-10 21:54:42 +07:00
|
|
|
break;
|
2015-06-25 23:12:11 +07:00
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* This is DMA_BIDIRECTIONAL or something else we are never
|
|
|
|
* supposed to see here.
|
|
|
|
*/
|
|
|
|
WARN(1, "Unexpected data direction: %d\n",
|
|
|
|
scmnd->sc_data_direction);
|
|
|
|
return -EINVAL;
|
2011-05-10 21:54:42 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vm_srb->port_number = host_dev->port;
|
|
|
|
vm_srb->path_id = scmnd->device->channel;
|
|
|
|
vm_srb->target_id = scmnd->device->id;
|
|
|
|
vm_srb->lun = scmnd->device->lun;
|
|
|
|
|
|
|
|
vm_srb->cdb_length = scmnd->cmd_len;
|
|
|
|
|
|
|
|
memcpy(vm_srb->cdb, scmnd->cmnd, vm_srb->cdb_length);
|
|
|
|
|
2015-03-27 14:27:20 +07:00
|
|
|
sgl = (struct scatterlist *)scsi_sglist(scmnd);
|
|
|
|
sg_count = scsi_sg_count(scmnd);
|
2011-05-10 21:54:42 +07:00
|
|
|
|
2015-03-27 14:27:20 +07:00
|
|
|
length = scsi_bufflen(scmnd);
|
|
|
|
payload = (struct vmbus_packet_mpb_array *)&cmd_request->mpb;
|
|
|
|
payload_sz = sizeof(cmd_request->mpb);
|
|
|
|
|
|
|
|
if (sg_count) {
|
|
|
|
if (sg_count > MAX_PAGE_BUFFER_COUNT) {
|
|
|
|
|
2016-11-23 20:46:33 +07:00
|
|
|
payload_sz = (sg_count * sizeof(u64) +
|
2015-03-27 14:27:20 +07:00
|
|
|
sizeof(struct vmbus_packet_mpb_array));
|
2016-11-23 20:46:33 +07:00
|
|
|
payload = kzalloc(payload_sz, GFP_ATOMIC);
|
2015-10-02 04:53:17 +07:00
|
|
|
if (!payload)
|
|
|
|
return SCSI_MLQUEUE_DEVICE_BUSY;
|
2015-03-27 14:27:20 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
payload->range.len = length;
|
|
|
|
payload->range.offset = sgl[0].offset;
|
|
|
|
|
2015-03-27 14:27:19 +07:00
|
|
|
cur_sgl = sgl;
|
|
|
|
for (i = 0; i < sg_count; i++) {
|
2015-03-27 14:27:20 +07:00
|
|
|
payload->range.pfn_array[i] =
|
2015-03-27 14:27:19 +07:00
|
|
|
page_to_pfn(sg_page((cur_sgl)));
|
|
|
|
cur_sgl = sg_next(cur_sgl);
|
|
|
|
}
|
2011-05-10 21:54:42 +07:00
|
|
|
}
|
|
|
|
|
2015-03-27 14:27:20 +07:00
|
|
|
cmd_request->payload = payload;
|
|
|
|
cmd_request->payload_sz = payload_sz;
|
|
|
|
|
2011-05-10 21:54:42 +07:00
|
|
|
/* Invokes the vsc to start an IO */
|
2016-12-15 09:46:00 +07:00
|
|
|
ret = storvsc_do_io(dev, cmd_request, get_cpu());
|
|
|
|
put_cpu();
|
2011-05-10 21:54:50 +07:00
|
|
|
|
2011-08-25 23:48:58 +07:00
|
|
|
if (ret == -EAGAIN) {
|
2011-05-10 21:54:42 +07:00
|
|
|
/* no more space */
|
2014-12-30 11:05:09 +07:00
|
|
|
return SCSI_MLQUEUE_DEVICE_BUSY;
|
2011-05-10 21:54:42 +07:00
|
|
|
}
|
|
|
|
|
2012-01-13 03:37:56 +07:00
|
|
|
return 0;
|
2011-05-10 21:54:42 +07:00
|
|
|
}
|
|
|
|
|
2009-07-14 06:01:31 +07:00
|
|
|
static struct scsi_host_template scsi_driver = {
|
2009-09-02 22:37:47 +07:00
|
|
|
.module = THIS_MODULE,
|
|
|
|
.name = "storvsc_host_t",
|
2014-12-30 11:05:09 +07:00
|
|
|
.cmd_size = sizeof(struct storvsc_cmd_request),
|
2009-09-02 22:37:47 +07:00
|
|
|
.bios_param = storvsc_get_chs,
|
|
|
|
.queuecommand = storvsc_queuecommand,
|
|
|
|
.eh_host_reset_handler = storvsc_host_reset_handler,
|
2014-12-30 11:05:09 +07:00
|
|
|
.proc_name = "storvsc_host",
|
2014-07-12 23:48:30 +07:00
|
|
|
.eh_timed_out = storvsc_eh_timed_out,
|
2017-03-08 00:15:53 +07:00
|
|
|
.slave_alloc = storvsc_device_alloc,
|
2009-09-02 22:37:47 +07:00
|
|
|
.slave_configure = storvsc_device_configure,
|
2014-07-12 23:48:27 +07:00
|
|
|
.cmd_per_lun = 255,
|
2009-09-02 22:37:47 +07:00
|
|
|
.this_id = -1,
|
2015-03-27 14:27:20 +07:00
|
|
|
.use_clustering = ENABLE_CLUSTERING,
|
2009-07-28 03:47:24 +07:00
|
|
|
/* Make sure we dont get a sg segment crosses a page boundary */
|
2009-09-02 22:37:47 +07:00
|
|
|
.dma_boundary = PAGE_SIZE-1,
|
2013-10-23 17:25:40 +07:00
|
|
|
.no_write_same = 1,
|
2016-12-15 09:45:58 +07:00
|
|
|
.track_queue_depth = 1,
|
2009-07-14 06:01:31 +07:00
|
|
|
};
|
|
|
|
|
2011-09-14 00:59:39 +07:00
|
|
|
enum {
|
|
|
|
SCSI_GUID,
|
|
|
|
IDE_GUID,
|
2013-06-05 02:05:08 +07:00
|
|
|
SFC_GUID,
|
2011-09-14 00:59:39 +07:00
|
|
|
};
|
|
|
|
|
2011-08-25 23:48:33 +07:00
|
|
|
static const struct hv_vmbus_device_id id_table[] = {
|
2011-08-26 01:41:33 +07:00
|
|
|
/* SCSI guid */
|
2013-01-24 08:42:43 +07:00
|
|
|
{ HV_SCSI_GUID,
|
|
|
|
.driver_data = SCSI_GUID
|
|
|
|
},
|
2011-08-28 01:31:18 +07:00
|
|
|
/* IDE guid */
|
2013-01-24 08:42:43 +07:00
|
|
|
{ HV_IDE_GUID,
|
|
|
|
.driver_data = IDE_GUID
|
|
|
|
},
|
2013-06-05 02:05:08 +07:00
|
|
|
/* Fibre Channel GUID */
|
|
|
|
{
|
|
|
|
HV_SYNTHFC_GUID,
|
|
|
|
.driver_data = SFC_GUID
|
|
|
|
},
|
2011-08-26 01:41:33 +07:00
|
|
|
{ },
|
2011-08-25 23:48:33 +07:00
|
|
|
};
|
2009-07-14 06:01:31 +07:00
|
|
|
|
2011-08-25 23:48:33 +07:00
|
|
|
MODULE_DEVICE_TABLE(vmbus, id_table);
|
2011-08-28 01:31:17 +07:00
|
|
|
|
2011-09-14 00:59:38 +07:00
|
|
|
static int storvsc_probe(struct hv_device *device,
|
|
|
|
const struct hv_vmbus_device_id *dev_id)
|
2009-07-14 06:01:31 +07:00
|
|
|
{
|
2009-09-02 22:37:47 +07:00
|
|
|
int ret;
|
2015-03-27 14:27:15 +07:00
|
|
|
int num_cpus = num_online_cpus();
|
2009-07-14 06:01:31 +07:00
|
|
|
struct Scsi_Host *host;
|
2011-05-10 21:54:20 +07:00
|
|
|
struct hv_host_device *host_dev;
|
2011-09-14 00:59:39 +07:00
|
|
|
bool dev_is_ide = ((dev_id->driver_data == IDE_GUID) ? true : false);
|
2015-12-24 04:15:49 +07:00
|
|
|
bool is_fc = ((dev_id->driver_data == SFC_GUID) ? true : false);
|
2011-08-28 01:31:17 +07:00
|
|
|
int target = 0;
|
2011-09-14 00:59:45 +07:00
|
|
|
struct storvsc_device *stor_device;
|
2014-12-17 04:21:44 +07:00
|
|
|
int max_luns_per_target;
|
|
|
|
int max_targets;
|
|
|
|
int max_channels;
|
2015-03-27 14:27:15 +07:00
|
|
|
int max_sub_channels = 0;
|
2011-08-28 01:31:17 +07:00
|
|
|
|
2013-06-05 02:05:06 +07:00
|
|
|
/*
|
|
|
|
* Based on the windows host we are running on,
|
|
|
|
* set state to properly communicate with the host.
|
|
|
|
*/
|
|
|
|
|
2015-08-13 22:43:46 +07:00
|
|
|
if (vmbus_proto_version < VERSION_WIN8) {
|
2014-12-17 04:21:44 +07:00
|
|
|
max_luns_per_target = STORVSC_IDE_MAX_LUNS_PER_TARGET;
|
|
|
|
max_targets = STORVSC_IDE_MAX_TARGETS;
|
|
|
|
max_channels = STORVSC_IDE_MAX_CHANNELS;
|
2015-08-13 22:43:46 +07:00
|
|
|
} else {
|
2014-12-17 04:21:44 +07:00
|
|
|
max_luns_per_target = STORVSC_MAX_LUNS_PER_TARGET;
|
|
|
|
max_targets = STORVSC_MAX_TARGETS;
|
|
|
|
max_channels = STORVSC_MAX_CHANNELS;
|
2015-03-27 14:27:15 +07:00
|
|
|
/*
|
|
|
|
* On Windows8 and above, we support sub-channels for storage.
|
|
|
|
* The number of sub-channels offerred is based on the number of
|
|
|
|
* VCPUs in the guest.
|
|
|
|
*/
|
|
|
|
max_sub_channels = (num_cpus / storvsc_vcpus_per_sub_channel);
|
2013-06-05 02:05:06 +07:00
|
|
|
}
|
|
|
|
|
2015-03-27 14:27:15 +07:00
|
|
|
scsi_driver.can_queue = (max_outstanding_req_per_channel *
|
|
|
|
(max_sub_channels + 1));
|
|
|
|
|
2009-09-02 22:37:47 +07:00
|
|
|
host = scsi_host_alloc(&scsi_driver,
|
2011-05-10 21:54:19 +07:00
|
|
|
sizeof(struct hv_host_device));
|
2011-05-10 21:54:24 +07:00
|
|
|
if (!host)
|
2009-07-14 06:01:31 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-11-09 00:01:44 +07:00
|
|
|
host_dev = shost_priv(host);
|
2011-05-10 21:54:20 +07:00
|
|
|
memset(host_dev, 0, sizeof(struct hv_host_device));
|
2009-07-14 06:01:31 +07:00
|
|
|
|
2011-05-10 21:54:20 +07:00
|
|
|
host_dev->port = host->host_no;
|
2011-05-10 21:54:21 +07:00
|
|
|
host_dev->dev = device;
|
2009-07-14 06:01:31 +07:00
|
|
|
|
2011-11-09 00:01:40 +07:00
|
|
|
|
2011-09-14 00:59:46 +07:00
|
|
|
stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
|
2011-09-14 00:59:45 +07:00
|
|
|
if (!stor_device) {
|
2011-11-09 00:01:41 +07:00
|
|
|
ret = -ENOMEM;
|
2011-12-01 19:59:20 +07:00
|
|
|
goto err_out0;
|
2011-09-14 00:59:45 +07:00
|
|
|
}
|
2011-04-30 03:45:10 +07:00
|
|
|
|
2011-09-14 00:59:46 +07:00
|
|
|
stor_device->destroy = false;
|
2013-06-05 02:05:07 +07:00
|
|
|
stor_device->open_sub_channel = false;
|
2011-09-14 00:59:46 +07:00
|
|
|
init_waitqueue_head(&stor_device->waiting_to_drain);
|
|
|
|
stor_device->device = device;
|
2011-09-14 00:59:48 +07:00
|
|
|
stor_device->host = host;
|
|
|
|
hv_set_drvdata(device, stor_device);
|
2011-09-14 00:59:46 +07:00
|
|
|
|
2011-09-14 00:59:45 +07:00
|
|
|
stor_device->port_number = host->host_no;
|
2015-12-24 04:15:49 +07:00
|
|
|
ret = storvsc_connect_to_vsp(device, storvsc_ringbuffer_size, is_fc);
|
2011-11-09 00:01:41 +07:00
|
|
|
if (ret)
|
2011-12-01 19:59:20 +07:00
|
|
|
goto err_out1;
|
2009-07-14 06:01:31 +07:00
|
|
|
|
2011-09-14 00:59:45 +07:00
|
|
|
host_dev->path = stor_device->path_id;
|
|
|
|
host_dev->target = stor_device->target_id;
|
2009-07-14 06:01:31 +07:00
|
|
|
|
2014-07-12 23:48:26 +07:00
|
|
|
switch (dev_id->driver_data) {
|
|
|
|
case SFC_GUID:
|
|
|
|
host->max_lun = STORVSC_FC_MAX_LUNS_PER_TARGET;
|
|
|
|
host->max_id = STORVSC_FC_MAX_TARGETS;
|
|
|
|
host->max_channel = STORVSC_FC_MAX_CHANNELS - 1;
|
2015-12-24 04:15:49 +07:00
|
|
|
#if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
|
|
|
|
host->transportt = fc_transport_template;
|
|
|
|
#endif
|
2014-07-12 23:48:26 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCSI_GUID:
|
2014-12-17 04:21:44 +07:00
|
|
|
host->max_lun = max_luns_per_target;
|
|
|
|
host->max_id = max_targets;
|
|
|
|
host->max_channel = max_channels - 1;
|
2014-07-12 23:48:26 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
host->max_lun = STORVSC_IDE_MAX_LUNS_PER_TARGET;
|
|
|
|
host->max_id = STORVSC_IDE_MAX_TARGETS;
|
|
|
|
host->max_channel = STORVSC_IDE_MAX_CHANNELS - 1;
|
|
|
|
break;
|
|
|
|
}
|
2011-09-07 06:10:55 +07:00
|
|
|
/* max cmd length */
|
|
|
|
host->max_cmd_len = STORVSC_MAX_CMD_LEN;
|
2009-07-14 06:01:31 +07:00
|
|
|
|
2015-03-27 14:27:20 +07:00
|
|
|
/*
|
|
|
|
* set the table size based on the info we got
|
|
|
|
* from the host.
|
|
|
|
*/
|
|
|
|
host->sg_tablesize = (stor_device->max_transfer_bytes >> PAGE_SHIFT);
|
2016-12-15 09:46:00 +07:00
|
|
|
/*
|
|
|
|
* Set the number of HW queues we are supporting.
|
|
|
|
*/
|
|
|
|
if (stor_device->num_sc != 0)
|
|
|
|
host->nr_hw_queues = stor_device->num_sc + 1;
|
2015-03-27 14:27:20 +07:00
|
|
|
|
2009-07-28 03:47:24 +07:00
|
|
|
/* Register the HBA and start the scsi bus scan */
|
2011-04-30 03:45:10 +07:00
|
|
|
ret = scsi_add_host(host, &device->device);
|
2011-08-28 01:31:17 +07:00
|
|
|
if (ret != 0)
|
2011-12-01 19:59:20 +07:00
|
|
|
goto err_out2;
|
2009-07-14 06:01:31 +07:00
|
|
|
|
2011-08-28 01:31:17 +07:00
|
|
|
if (!dev_is_ide) {
|
|
|
|
scsi_scan_host(host);
|
2012-01-13 03:37:55 +07:00
|
|
|
} else {
|
|
|
|
target = (device->dev_instance.b[5] << 8 |
|
|
|
|
device->dev_instance.b[4]);
|
|
|
|
ret = scsi_add_device(host, 0, target, 0);
|
|
|
|
if (ret) {
|
|
|
|
scsi_remove_host(host);
|
|
|
|
goto err_out2;
|
|
|
|
}
|
2009-07-14 06:01:31 +07:00
|
|
|
}
|
2015-12-24 04:15:49 +07:00
|
|
|
#if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
|
|
|
|
if (host->transportt == fc_transport_template) {
|
|
|
|
fc_host_node_name(host) = stor_device->node_name;
|
|
|
|
fc_host_port_name(host) = stor_device->port_name;
|
|
|
|
}
|
|
|
|
#endif
|
2011-08-28 01:31:17 +07:00
|
|
|
return 0;
|
2009-07-14 06:01:31 +07:00
|
|
|
|
2011-12-01 19:59:20 +07:00
|
|
|
err_out2:
|
2011-11-09 00:01:41 +07:00
|
|
|
/*
|
|
|
|
* Once we have connected with the host, we would need to
|
|
|
|
* to invoke storvsc_dev_remove() to rollback this state and
|
|
|
|
* this call also frees up the stor_device; hence the jump around
|
2011-12-01 19:59:20 +07:00
|
|
|
* err_out1 label.
|
2011-11-09 00:01:41 +07:00
|
|
|
*/
|
2011-08-28 01:31:17 +07:00
|
|
|
storvsc_dev_remove(device);
|
2011-12-01 19:59:20 +07:00
|
|
|
goto err_out0;
|
2011-11-09 00:01:41 +07:00
|
|
|
|
|
|
|
err_out1:
|
2016-12-15 09:46:00 +07:00
|
|
|
kfree(stor_device->stor_chns);
|
2011-12-01 19:59:20 +07:00
|
|
|
kfree(stor_device);
|
2011-11-09 00:01:41 +07:00
|
|
|
|
|
|
|
err_out0:
|
2011-08-28 01:31:17 +07:00
|
|
|
scsi_host_put(host);
|
2011-11-09 00:01:41 +07:00
|
|
|
return ret;
|
2009-07-14 06:01:31 +07:00
|
|
|
}
|
|
|
|
|
2012-01-13 03:37:59 +07:00
|
|
|
static int storvsc_remove(struct hv_device *dev)
|
|
|
|
{
|
|
|
|
struct storvsc_device *stor_device = hv_get_drvdata(dev);
|
|
|
|
struct Scsi_Host *host = stor_device->host;
|
|
|
|
|
2015-12-24 04:15:49 +07:00
|
|
|
#if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
|
|
|
|
if (host->transportt == fc_transport_template)
|
|
|
|
fc_remove_host(host);
|
|
|
|
#endif
|
2012-01-13 03:37:59 +07:00
|
|
|
scsi_remove_host(host);
|
|
|
|
storvsc_dev_remove(dev);
|
|
|
|
scsi_host_put(host);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-10 21:56:09 +07:00
|
|
|
static struct hv_driver storvsc_drv = {
|
2011-11-09 00:01:46 +07:00
|
|
|
.name = KBUILD_MODNAME,
|
2011-08-25 23:48:33 +07:00
|
|
|
.id_table = id_table,
|
2011-05-10 21:56:09 +07:00
|
|
|
.probe = storvsc_probe,
|
|
|
|
.remove = storvsc_remove,
|
2011-05-10 21:54:46 +07:00
|
|
|
};
|
2011-05-10 21:54:45 +07:00
|
|
|
|
2015-12-24 04:15:49 +07:00
|
|
|
#if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
|
|
|
|
static struct fc_function_template fc_transport_functions = {
|
|
|
|
.show_host_node_name = 1,
|
|
|
|
.show_host_port_name = 1,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2011-06-07 05:49:27 +07:00
|
|
|
static int __init storvsc_drv_init(void)
|
2011-05-10 21:54:43 +07:00
|
|
|
{
|
2015-12-24 04:15:49 +07:00
|
|
|
int ret;
|
2011-05-10 21:55:58 +07: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_multipage_buffer + struct vstor_packet + u64)
|
|
|
|
*/
|
|
|
|
max_outstanding_req_per_channel =
|
2011-08-26 05:07:32 +07:00
|
|
|
((storvsc_ringbuffer_size - PAGE_SIZE) /
|
|
|
|
ALIGN(MAX_MULTIPAGE_BUFFER_PACKET +
|
2013-06-05 02:05:06 +07:00
|
|
|
sizeof(struct vstor_packet) + sizeof(u64) -
|
|
|
|
vmscsi_size_delta,
|
2011-08-26 05:07:32 +07:00
|
|
|
sizeof(u64)));
|
2011-05-10 21:54:43 +07:00
|
|
|
|
2015-12-24 04:15:49 +07:00
|
|
|
#if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
|
|
|
|
fc_transport_template = fc_attach_transport(&fc_transport_functions);
|
|
|
|
if (!fc_transport_template)
|
|
|
|
return -ENODEV;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ret = vmbus_driver_register(&storvsc_drv);
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
|
|
|
|
if (ret)
|
|
|
|
fc_release_transport(fc_transport_template);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
2011-05-10 21:54:43 +07:00
|
|
|
}
|
|
|
|
|
2011-06-07 05:49:26 +07:00
|
|
|
static void __exit storvsc_drv_exit(void)
|
2011-05-10 21:54:43 +07:00
|
|
|
{
|
2011-08-26 05:07:32 +07:00
|
|
|
vmbus_driver_unregister(&storvsc_drv);
|
2015-12-24 04:15:49 +07:00
|
|
|
#if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
|
|
|
|
fc_release_transport(fc_transport_template);
|
|
|
|
#endif
|
2011-05-10 21:54:43 +07:00
|
|
|
}
|
|
|
|
|
2009-09-02 22:37:47 +07:00
|
|
|
MODULE_LICENSE("GPL");
|
2010-05-07 11:44:45 +07:00
|
|
|
MODULE_DESCRIPTION("Microsoft Hyper-V virtual storage driver");
|
2011-06-07 05:49:27 +07:00
|
|
|
module_init(storvsc_drv_init);
|
2011-06-07 05:49:26 +07:00
|
|
|
module_exit(storvsc_drv_exit);
|