blob: f56b89a6ef95f427ed27d816ad1c234d35ef6073 [file] [log] [blame]
Hank Janssenbef4a342009-07-13 16:01:31 -07001/*
Hank Janssenbef4a342009-07-13 16:01:31 -07002 * Copyright (c) 2009, Microsoft Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 *
17 * Authors:
18 * Haiyang Zhang <haiyangz@microsoft.com>
19 * Hank Janssen <hjanssen@microsoft.com>
K. Y. Srinivasan972621c2011-05-10 07:54:19 -070020 * K. Y. Srinivasan <kys@microsoft.com>
Hank Janssenbef4a342009-07-13 16:01:31 -070021 */
K. Y. Srinivasana1be1702011-08-27 11:31:23 -070022
23#include <linux/kernel.h>
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -070024#include <linux/wait.h>
K. Y. Srinivasana1be1702011-08-27 11:31:23 -070025#include <linux/sched.h>
26#include <linux/completion.h>
27#include <linux/string.h>
28#include <linux/mm.h>
29#include <linux/delay.h>
Hank Janssenbef4a342009-07-13 16:01:31 -070030#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Hank Janssenbef4a342009-07-13 16:01:31 -070032#include <linux/module.h>
33#include <linux/device.h>
Greg Kroah-Hartman46a97192011-10-04 12:29:52 -070034#include <linux/hyperv.h>
K. Y. Srinivasan56b26e62014-07-12 09:48:30 -070035#include <linux/blkdev.h>
Hank Janssenbef4a342009-07-13 16:01:31 -070036#include <scsi/scsi.h>
37#include <scsi/scsi_cmnd.h>
38#include <scsi/scsi_host.h>
39#include <scsi/scsi_device.h>
40#include <scsi/scsi_tcq.h>
41#include <scsi/scsi_eh.h>
42#include <scsi/scsi_devinfo.h>
Hank Janssenbef4a342009-07-13 16:01:31 -070043#include <scsi/scsi_dbg.h>
K. Y. Srinivasan3f335ea2011-05-12 19:34:15 -070044
K. Y. Srinivasanc6491142012-01-12 12:38:03 -080045/*
K. Y. Srinivasanaf9584b2012-01-12 12:38:08 -080046 * All wire protocol details (storage protocol between the guest and the host)
47 * are consolidated here.
48 *
49 * Begin protocol definitions.
K. Y. Srinivasanc6491142012-01-12 12:38:03 -080050 */
51
K. Y. Srinivasan09f03552012-01-12 12:37:54 -080052/*
53 * Version history:
54 * V1 Beta: 0.1
55 * V1 RC < 2008/1/31: 1.0
56 * V1 RC > 2008/1/31: 2.0
57 * Win7: 4.2
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -070058 * Win8: 5.1
Keith Mange1a363102015-08-13 08:43:48 -070059 * Win8.1: 6.0
60 * Win10: 6.2
K. Y. Srinivasan09f03552012-01-12 12:37:54 -080061 */
62
Keith Mange2492fd72015-08-13 08:43:47 -070063#define VMSTOR_PROTO_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \
64 (((MINOR_) & 0xff)))
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -070065
Keith Mange1a363102015-08-13 08:43:48 -070066#define VMSTOR_PROTO_VERSION_WIN6 VMSTOR_PROTO_VERSION(2, 0)
Keith Mange2492fd72015-08-13 08:43:47 -070067#define VMSTOR_PROTO_VERSION_WIN7 VMSTOR_PROTO_VERSION(4, 2)
68#define VMSTOR_PROTO_VERSION_WIN8 VMSTOR_PROTO_VERSION(5, 1)
Keith Mange1a363102015-08-13 08:43:48 -070069#define VMSTOR_PROTO_VERSION_WIN8_1 VMSTOR_PROTO_VERSION(6, 0)
70#define VMSTOR_PROTO_VERSION_WIN10 VMSTOR_PROTO_VERSION(6, 2)
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -070071
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -070072/* Packet structure describing virtual storage requests. */
73enum vstor_packet_operation {
74 VSTOR_OPERATION_COMPLETE_IO = 1,
75 VSTOR_OPERATION_REMOVE_DEVICE = 2,
76 VSTOR_OPERATION_EXECUTE_SRB = 3,
77 VSTOR_OPERATION_RESET_LUN = 4,
78 VSTOR_OPERATION_RESET_ADAPTER = 5,
79 VSTOR_OPERATION_RESET_BUS = 6,
80 VSTOR_OPERATION_BEGIN_INITIALIZATION = 7,
81 VSTOR_OPERATION_END_INITIALIZATION = 8,
82 VSTOR_OPERATION_QUERY_PROTOCOL_VERSION = 9,
83 VSTOR_OPERATION_QUERY_PROPERTIES = 10,
K. Y. Srinivasan2b9525f2011-11-08 09:01:48 -080084 VSTOR_OPERATION_ENUMERATE_BUS = 11,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -070085 VSTOR_OPERATION_FCHBA_DATA = 12,
86 VSTOR_OPERATION_CREATE_SUB_CHANNELS = 13,
87 VSTOR_OPERATION_MAXIMUM = 13
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -070088};
89
90/*
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -070091 * WWN packet for Fibre Channel HBA
92 */
93
94struct hv_fc_wwn_packet {
95 bool primary_active;
96 u8 reserved1;
97 u8 reserved2;
98 u8 primary_port_wwn[8];
99 u8 primary_node_wwn[8];
100 u8 secondary_port_wwn[8];
101 u8 secondary_node_wwn[8];
102};
103
104
105
106/*
107 * SRB Flag Bits
108 */
109
110#define SRB_FLAGS_QUEUE_ACTION_ENABLE 0x00000002
111#define SRB_FLAGS_DISABLE_DISCONNECT 0x00000004
112#define SRB_FLAGS_DISABLE_SYNCH_TRANSFER 0x00000008
113#define SRB_FLAGS_BYPASS_FROZEN_QUEUE 0x00000010
114#define SRB_FLAGS_DISABLE_AUTOSENSE 0x00000020
115#define SRB_FLAGS_DATA_IN 0x00000040
116#define SRB_FLAGS_DATA_OUT 0x00000080
117#define SRB_FLAGS_NO_DATA_TRANSFER 0x00000000
118#define SRB_FLAGS_UNSPECIFIED_DIRECTION (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)
119#define SRB_FLAGS_NO_QUEUE_FREEZE 0x00000100
120#define SRB_FLAGS_ADAPTER_CACHE_ENABLE 0x00000200
121#define SRB_FLAGS_FREE_SENSE_BUFFER 0x00000400
122
123/*
124 * This flag indicates the request is part of the workflow for processing a D3.
125 */
126#define SRB_FLAGS_D3_PROCESSING 0x00000800
127#define SRB_FLAGS_IS_ACTIVE 0x00010000
128#define SRB_FLAGS_ALLOCATED_FROM_ZONE 0x00020000
129#define SRB_FLAGS_SGLIST_FROM_POOL 0x00040000
130#define SRB_FLAGS_BYPASS_LOCKED_QUEUE 0x00080000
131#define SRB_FLAGS_NO_KEEP_AWAKE 0x00100000
132#define SRB_FLAGS_PORT_DRIVER_ALLOCSENSE 0x00200000
133#define SRB_FLAGS_PORT_DRIVER_SENSEHASPORT 0x00400000
134#define SRB_FLAGS_DONT_START_NEXT_PACKET 0x00800000
135#define SRB_FLAGS_PORT_DRIVER_RESERVED 0x0F000000
136#define SRB_FLAGS_CLASS_DRIVER_RESERVED 0xF0000000
137
138
139/*
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700140 * Platform neutral description of a scsi request -
141 * this remains the same across the write regardless of 32/64 bit
142 * note: it's patterned off the SCSI_PASS_THROUGH structure
143 */
K. Y. Srinivasan6b2f9492012-01-12 12:38:05 -0800144#define STORVSC_MAX_CMD_LEN 0x10
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700145
146#define POST_WIN7_STORVSC_SENSE_BUFFER_SIZE 0x14
147#define PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE 0x12
148
149#define STORVSC_SENSE_BUFFER_SIZE 0x14
K. Y. Srinivasan6b2f9492012-01-12 12:38:05 -0800150#define STORVSC_MAX_BUF_LEN_WITH_PADDING 0x14
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700151
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700152/*
153 * Sense buffer size changed in win8; have a run-time
Keith Mangecb11fead2015-08-13 08:43:49 -0700154 * variable to track the size we should use. This value will
155 * likely change during protocol negotiation but it is valid
156 * to start by assuming pre-Win8.
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700157 */
Keith Mangecb11fead2015-08-13 08:43:49 -0700158static int sense_buffer_size = PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE;
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700159
160/*
Keith Mangecb11fead2015-08-13 08:43:49 -0700161 * The storage protocol version is determined during the
162 * initial exchange with the host. It will indicate which
163 * storage functionality is available in the host.
164*/
Keith Mange2492fd72015-08-13 08:43:47 -0700165static int vmstor_proto_version;
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700166
167struct vmscsi_win8_extension {
168 /*
169 * The following were added in Windows 8
170 */
171 u16 reserve;
172 u8 queue_tag;
173 u8 queue_action;
174 u32 srb_flags;
175 u32 time_out_value;
176 u32 queue_sort_ey;
177} __packed;
178
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700179struct vmscsi_request {
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800180 u16 length;
181 u8 srb_status;
182 u8 scsi_status;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700183
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800184 u8 port_number;
185 u8 path_id;
186 u8 target_id;
187 u8 lun;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700188
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800189 u8 cdb_length;
190 u8 sense_info_length;
191 u8 data_in;
192 u8 reserved;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700193
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800194 u32 data_transfer_length;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700195
196 union {
K. Y. Srinivasan6b2f9492012-01-12 12:38:05 -0800197 u8 cdb[STORVSC_MAX_CMD_LEN];
198 u8 sense_data[STORVSC_SENSE_BUFFER_SIZE];
199 u8 reserved_array[STORVSC_MAX_BUF_LEN_WITH_PADDING];
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700200 };
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700201 /*
202 * The following was added in win8.
203 */
204 struct vmscsi_win8_extension win8_extension;
205
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700206} __attribute((packed));
207
208
209/*
Keith Mangecb11fead2015-08-13 08:43:49 -0700210 * The size of the vmscsi_request has changed in win8. The
211 * additional size is because of new elements added to the
212 * structure. These elements are valid only when we are talking
213 * to a win8 host.
214 * Track the correction to size we need to apply. This value
215 * will likely change during protocol negotiation but it is
216 * valid to start by assuming pre-Win8.
217 */
218static int vmscsi_size_delta = sizeof(struct vmscsi_win8_extension);
219
220/*
Keith Mange1a363102015-08-13 08:43:48 -0700221 * The list of storage protocols in order of preference.
222 */
223struct vmstor_protocol {
224 int protocol_version;
225 int sense_buffer_size;
226 int vmscsi_size_delta;
227};
228
229
230static const struct vmstor_protocol vmstor_protocols[] = {
231 {
232 VMSTOR_PROTO_VERSION_WIN10,
233 POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
234 0
235 },
236 {
237 VMSTOR_PROTO_VERSION_WIN8_1,
238 POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
239 0
240 },
241 {
242 VMSTOR_PROTO_VERSION_WIN8,
243 POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
244 0
245 },
246 {
247 VMSTOR_PROTO_VERSION_WIN7,
248 PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE,
249 sizeof(struct vmscsi_win8_extension),
250 },
251 {
252 VMSTOR_PROTO_VERSION_WIN6,
253 PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE,
254 sizeof(struct vmscsi_win8_extension),
255 }
256};
257
258
259/*
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700260 * This structure is sent during the intialization phase to get the different
261 * properties of the channel.
262 */
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700263
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700264#define STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL 0x1
265
266struct vmstorage_channel_properties {
267 u32 reserved;
268 u16 max_channel_cnt;
269 u16 reserved1;
270
271 u32 flags;
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800272 u32 max_transfer_bytes;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700273
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700274 u64 reserved2;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700275} __packed;
276
277/* This structure is sent during the storage protocol negotiations. */
278struct vmstorage_protocol_version {
279 /* Major (MSW) and minor (LSW) version numbers. */
K. Y. Srinivasan85904a52012-01-12 12:38:04 -0800280 u16 major_minor;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700281
282 /*
283 * Revision number is auto-incremented whenever this file is changed
284 * (See FILL_VMSTOR_REVISION macro above). Mismatch does not
285 * definitely indicate incompatibility--but it does indicate mismatched
286 * builds.
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800287 * This is only used on the windows side. Just set it to 0.
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700288 */
K. Y. Srinivasan85904a52012-01-12 12:38:04 -0800289 u16 revision;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700290} __packed;
291
292/* Channel Property Flags */
293#define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1
294#define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2
295
296struct vstor_packet {
297 /* Requested operation type */
298 enum vstor_packet_operation operation;
299
300 /* Flags - see below for values */
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800301 u32 flags;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700302
303 /* Status of the request returned from the server side. */
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800304 u32 status;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700305
306 /* Data payload area */
307 union {
308 /*
309 * Structure used to forward SCSI commands from the
310 * client to the server.
311 */
312 struct vmscsi_request vm_srb;
313
314 /* Structure used to query channel properties. */
315 struct vmstorage_channel_properties storage_channel_properties;
316
317 /* Used during version negotiations. */
318 struct vmstorage_protocol_version version;
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700319
320 /* Fibre channel address packet */
321 struct hv_fc_wwn_packet wwn_packet;
322
323 /* Number of sub-channels to create */
324 u16 sub_channel_count;
325
326 /* This will be the maximum of the union members */
327 u8 buffer[0x34];
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700328 };
329} __packed;
330
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700331/*
K. Y. Srinivasan09f03552012-01-12 12:37:54 -0800332 * Packet Flags:
333 *
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700334 * This flag indicates that the server should send back a completion for this
335 * packet.
336 */
K. Y. Srinivasan09f03552012-01-12 12:37:54 -0800337
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700338#define REQUEST_COMPLETION_FLAG 0x1
339
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700340/* Matches Windows-end */
341enum storvsc_request_type {
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800342 WRITE_TYPE = 0,
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700343 READ_TYPE,
344 UNKNOWN_TYPE,
345};
346
K. Y. Srinivasan16046322012-01-12 12:37:57 -0800347/*
348 * SRB status codes and masks; a subset of the codes used here.
349 */
350
351#define SRB_STATUS_AUTOSENSE_VALID 0x80
352#define SRB_STATUS_INVALID_LUN 0x20
353#define SRB_STATUS_SUCCESS 0x01
K. Y. Srinivasan67812092013-02-21 12:04:53 -0800354#define SRB_STATUS_ABORTED 0x02
K. Y. Srinivasan16046322012-01-12 12:37:57 -0800355#define SRB_STATUS_ERROR 0x04
356
K. Y. Srinivasanaf9584b2012-01-12 12:38:08 -0800357/*
358 * This is the end of Protocol specific defines.
359 */
360
K. Y. Srinivasanb9ec3a52015-03-27 00:27:14 -0700361static int storvsc_ringbuffer_size = (256 * PAGE_SIZE);
K. Y. Srinivasanf458aad2015-03-27 00:27:15 -0700362static u32 max_outstanding_req_per_channel;
363
364static int storvsc_vcpus_per_sub_channel = 4;
K. Y. Srinivasanaf9584b2012-01-12 12:38:08 -0800365
366module_param(storvsc_ringbuffer_size, int, S_IRUGO);
367MODULE_PARM_DESC(storvsc_ringbuffer_size, "Ring buffer size (bytes)");
368
K. Y. Srinivasanf458aad2015-03-27 00:27:15 -0700369module_param(storvsc_vcpus_per_sub_channel, int, S_IRUGO);
370MODULE_PARM_DESC(vcpus_per_sub_channel, "Ratio of VCPUs to subchannels");
K. Y. Srinivasan893def32013-06-04 12:05:05 -0700371/*
372 * Timeout in seconds for all devices managed by this driver.
373 */
374static int storvsc_timeout = 180;
375
K. Y. Srinivasanf3cfabc2014-07-21 16:06:01 -0700376static int msft_blist_flags = BLIST_TRY_VPD_PAGES;
377
K. Y. Srinivasanaf9584b2012-01-12 12:38:08 -0800378
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700379static void storvsc_on_channel_callback(void *context);
380
K. Y. Srinivasan4cd83ec2014-07-12 09:48:26 -0700381#define STORVSC_MAX_LUNS_PER_TARGET 255
382#define STORVSC_MAX_TARGETS 2
383#define STORVSC_MAX_CHANNELS 8
K. Y. Srinivasanaf9584b2012-01-12 12:38:08 -0800384
K. Y. Srinivasan4cd83ec2014-07-12 09:48:26 -0700385#define STORVSC_FC_MAX_LUNS_PER_TARGET 255
386#define STORVSC_FC_MAX_TARGETS 128
387#define STORVSC_FC_MAX_CHANNELS 8
K. Y. Srinivasanaf9584b2012-01-12 12:38:08 -0800388
K. Y. Srinivasan4cd83ec2014-07-12 09:48:26 -0700389#define STORVSC_IDE_MAX_LUNS_PER_TARGET 64
390#define STORVSC_IDE_MAX_TARGETS 1
391#define STORVSC_IDE_MAX_CHANNELS 1
K. Y. Srinivasan16046322012-01-12 12:37:57 -0800392
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800393struct storvsc_cmd_request {
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800394 struct scsi_cmnd *cmd;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700395
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700396 struct hv_device *device;
397
398 /* Synchronize the request/response if needed */
399 struct completion wait_event;
400
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -0700401 struct vmbus_channel_packet_multipage_buffer mpb;
402 struct vmbus_packet_mpb_array *payload;
403 u32 payload_sz;
404
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700405 struct vstor_packet vstor_packet;
406};
407
408
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700409/* A storvsc device is a device object that contains a vmbus channel */
410struct storvsc_device {
411 struct hv_device *device;
412
413 bool destroy;
414 bool drain_notify;
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700415 bool open_sub_channel;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700416 atomic_t num_outstanding_req;
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -0700417 struct Scsi_Host *host;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700418
419 wait_queue_head_t waiting_to_drain;
420
421 /*
422 * Each unique Port/Path/Target represents 1 channel ie scsi
423 * controller. In reality, the pathid, targetid is always 0
424 * and the port is set by us
425 */
426 unsigned int port_number;
427 unsigned char path_id;
428 unsigned char target_id;
429
K. Y. Srinivasan5117b932015-03-27 00:27:17 -0700430 /*
431 * Max I/O, the device can support.
432 */
433 u32 max_transfer_bytes;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700434 /* Used for vsc/vsp channel reset process */
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800435 struct storvsc_cmd_request init_request;
436 struct storvsc_cmd_request reset_request;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700437};
438
K. Y. Srinivasance3e3012011-12-01 04:59:20 -0800439struct hv_host_device {
440 struct hv_device *dev;
K. Y. Srinivasanc1b3d062011-08-27 11:31:25 -0700441 unsigned int port;
442 unsigned char path;
443 unsigned char target;
444};
445
K. Y. Srinivasan126757992011-11-08 09:01:49 -0800446struct storvsc_scan_work {
447 struct work_struct work;
448 struct Scsi_Host *host;
449 uint lun;
450};
451
K. Y. Srinivasan67812092013-02-21 12:04:53 -0800452static void storvsc_device_scan(struct work_struct *work)
453{
454 struct storvsc_scan_work *wrk;
455 uint lun;
456 struct scsi_device *sdev;
457
458 wrk = container_of(work, struct storvsc_scan_work, work);
459 lun = wrk->lun;
460
461 sdev = scsi_device_lookup(wrk->host, 0, 0, lun);
462 if (!sdev)
463 goto done;
464 scsi_rescan_device(&sdev->sdev_gendev);
465 scsi_device_put(sdev);
466
467done:
468 kfree(wrk);
469}
470
K. Y. Srinivasan2a09ed32014-12-16 13:21:42 -0800471static void storvsc_host_scan(struct work_struct *work)
K. Y. Srinivasan126757992011-11-08 09:01:49 -0800472{
473 struct storvsc_scan_work *wrk;
K. Y. Srinivasan2a09ed32014-12-16 13:21:42 -0800474 struct Scsi_Host *host;
K. Y. Srinivasan34a716b2014-12-16 13:21:43 -0800475 struct scsi_device *sdev;
K. Y. Srinivasan126757992011-11-08 09:01:49 -0800476
477 wrk = container_of(work, struct storvsc_scan_work, work);
K. Y. Srinivasan2a09ed32014-12-16 13:21:42 -0800478 host = wrk->host;
K. Y. Srinivasan126757992011-11-08 09:01:49 -0800479
K. Y. Srinivasan34a716b2014-12-16 13:21:43 -0800480 /*
481 * Before scanning the host, first check to see if any of the
482 * currrently known devices have been hot removed. We issue a
483 * "unit ready" command against all currently known devices.
484 * This I/O will result in an error for devices that have been
485 * removed. As part of handling the I/O error, we remove the device.
486 *
487 * When a LUN is added or removed, the host sends us a signal to
488 * scan the host. Thus we are forced to discover the LUNs that
489 * may have been removed this way.
490 */
491 mutex_lock(&host->scan_mutex);
Vitaly Kuznetsov8d6a9f52015-07-01 11:31:27 +0200492 shost_for_each_device(sdev, host)
K. Y. Srinivasan34a716b2014-12-16 13:21:43 -0800493 scsi_test_unit_ready(sdev, 1, 1, NULL);
K. Y. Srinivasan34a716b2014-12-16 13:21:43 -0800494 mutex_unlock(&host->scan_mutex);
495 /*
496 * Now scan the host to discover LUNs that may have been added.
497 */
K. Y. Srinivasan2a09ed32014-12-16 13:21:42 -0800498 scsi_scan_host(host);
499
K. Y. Srinivasan126757992011-11-08 09:01:49 -0800500 kfree(wrk);
501}
502
K. Y. Srinivasanb4017312011-11-08 09:01:50 -0800503static void storvsc_remove_lun(struct work_struct *work)
504{
505 struct storvsc_scan_work *wrk;
506 struct scsi_device *sdev;
507
508 wrk = container_of(work, struct storvsc_scan_work, work);
509 if (!scsi_host_get(wrk->host))
510 goto done;
511
512 sdev = scsi_device_lookup(wrk->host, 0, 0, wrk->lun);
513
514 if (sdev) {
515 scsi_remove_device(sdev);
516 scsi_device_put(sdev);
517 }
518 scsi_host_put(wrk->host);
519
520done:
521 kfree(wrk);
522}
523
K. Y. Srinivasanaf9584b2012-01-12 12:38:08 -0800524
525/*
K. Y. Srinivasana8c18c52012-01-12 12:38:00 -0800526 * We can get incoming messages from the host that are not in response to
527 * messages that we have sent out. An example of this would be messages
528 * received by the guest to notify dynamic addition/removal of LUNs. To
529 * deal with potential race conditions where the driver may be in the
530 * midst of being unloaded when we might receive an unsolicited message
531 * from the host, we have implemented a mechanism to gurantee sequential
532 * consistency:
533 *
534 * 1) Once the device is marked as being destroyed, we will fail all
535 * outgoing messages.
536 * 2) We permit incoming messages when the device is being destroyed,
537 * only to properly account for messages already sent out.
538 */
539
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700540static inline struct storvsc_device *get_out_stor_device(
541 struct hv_device *device)
542{
543 struct storvsc_device *stor_device;
544
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -0700545 stor_device = hv_get_drvdata(device);
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700546
547 if (stor_device && stor_device->destroy)
548 stor_device = NULL;
549
550 return stor_device;
551}
552
553
554static inline void storvsc_wait_to_drain(struct storvsc_device *dev)
555{
556 dev->drain_notify = true;
557 wait_event(dev->waiting_to_drain,
558 atomic_read(&dev->num_outstanding_req) == 0);
559 dev->drain_notify = false;
560}
Hank Janssenbef4a342009-07-13 16:01:31 -0700561
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700562static inline struct storvsc_device *get_in_stor_device(
563 struct hv_device *device)
564{
565 struct storvsc_device *stor_device;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700566
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -0700567 stor_device = hv_get_drvdata(device);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700568
569 if (!stor_device)
570 goto get_in_err;
571
572 /*
573 * If the device is being destroyed; allow incoming
574 * traffic only to cleanup outstanding requests.
575 */
576
577 if (stor_device->destroy &&
578 (atomic_read(&stor_device->num_outstanding_req) == 0))
579 stor_device = NULL;
580
581get_in_err:
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700582 return stor_device;
583
584}
585
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700586static void handle_sc_creation(struct vmbus_channel *new_sc)
587{
588 struct hv_device *device = new_sc->primary_channel->device_obj;
589 struct storvsc_device *stor_device;
590 struct vmstorage_channel_properties props;
591
592 stor_device = get_out_stor_device(device);
593 if (!stor_device)
594 return;
595
596 if (stor_device->open_sub_channel == false)
597 return;
598
599 memset(&props, 0, sizeof(struct vmstorage_channel_properties));
600
601 vmbus_open(new_sc,
602 storvsc_ringbuffer_size,
603 storvsc_ringbuffer_size,
604 (void *)&props,
605 sizeof(struct vmstorage_channel_properties),
606 storvsc_on_channel_callback, new_sc);
607}
608
609static void handle_multichannel_storage(struct hv_device *device, int max_chns)
610{
611 struct storvsc_device *stor_device;
612 int num_cpus = num_online_cpus();
613 int num_sc;
614 struct storvsc_cmd_request *request;
615 struct vstor_packet *vstor_packet;
616 int ret, t;
617
618 num_sc = ((max_chns > num_cpus) ? num_cpus : max_chns);
619 stor_device = get_out_stor_device(device);
620 if (!stor_device)
621 return;
622
623 request = &stor_device->init_request;
624 vstor_packet = &request->vstor_packet;
625
626 stor_device->open_sub_channel = true;
627 /*
628 * Establish a handler for dealing with subchannels.
629 */
630 vmbus_set_sc_create_callback(device->channel, handle_sc_creation);
631
632 /*
633 * Check to see if sub-channels have already been created. This
634 * can happen when this driver is re-loaded after unloading.
635 */
636
637 if (vmbus_are_subchannels_present(device->channel))
638 return;
639
640 stor_device->open_sub_channel = false;
641 /*
642 * Request the host to create sub-channels.
643 */
644 memset(request, 0, sizeof(struct storvsc_cmd_request));
645 init_completion(&request->wait_event);
646 vstor_packet->operation = VSTOR_OPERATION_CREATE_SUB_CHANNELS;
647 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
648 vstor_packet->sub_channel_count = num_sc;
649
650 ret = vmbus_sendpacket(device->channel, vstor_packet,
651 (sizeof(struct vstor_packet) -
652 vmscsi_size_delta),
653 (unsigned long)request,
654 VM_PKT_DATA_INBAND,
655 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
656
657 if (ret != 0)
658 return;
659
660 t = wait_for_completion_timeout(&request->wait_event, 10*HZ);
661 if (t == 0)
662 return;
663
664 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
665 vstor_packet->status != 0)
666 return;
667
668 /*
669 * Now that we created the sub-channels, invoke the check; this
670 * may trigger the callback.
671 */
672 stor_device->open_sub_channel = true;
673 vmbus_are_subchannels_present(device->channel);
674}
675
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700676static int storvsc_channel_init(struct hv_device *device)
677{
678 struct storvsc_device *stor_device;
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800679 struct storvsc_cmd_request *request;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700680 struct vstor_packet *vstor_packet;
Keith Mange1a363102015-08-13 08:43:48 -0700681 int ret, t, i;
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700682 int max_chns;
683 bool process_sub_channels = false;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700684
685 stor_device = get_out_stor_device(device);
686 if (!stor_device)
687 return -ENODEV;
688
689 request = &stor_device->init_request;
690 vstor_packet = &request->vstor_packet;
691
692 /*
693 * Now, initiate the vsc/vsp initialization protocol on the open
694 * channel
695 */
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800696 memset(request, 0, sizeof(struct storvsc_cmd_request));
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700697 init_completion(&request->wait_event);
698 vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION;
699 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
700
701 ret = vmbus_sendpacket(device->channel, vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700702 (sizeof(struct vstor_packet) -
703 vmscsi_size_delta),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700704 (unsigned long)request,
705 VM_PKT_DATA_INBAND,
706 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
707 if (ret != 0)
708 goto cleanup;
709
710 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
711 if (t == 0) {
712 ret = -ETIMEDOUT;
713 goto cleanup;
714 }
715
716 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
K. Y. Srinivasan111f2d12015-08-13 08:43:52 -0700717 vstor_packet->status != 0) {
718 ret = -EINVAL;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700719 goto cleanup;
K. Y. Srinivasan111f2d12015-08-13 08:43:52 -0700720 }
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700721
722
Keith Mange1a363102015-08-13 08:43:48 -0700723 for (i = 0; i < ARRAY_SIZE(vmstor_protocols); i++) {
724 /* reuse the packet for version range supported */
725 memset(vstor_packet, 0, sizeof(struct vstor_packet));
726 vstor_packet->operation =
727 VSTOR_OPERATION_QUERY_PROTOCOL_VERSION;
728 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700729
Keith Mange1a363102015-08-13 08:43:48 -0700730 vstor_packet->version.major_minor =
731 vmstor_protocols[i].protocol_version;
K. Y. Srinivasan85904a52012-01-12 12:38:04 -0800732
Keith Mange1a363102015-08-13 08:43:48 -0700733 /*
734 * The revision number is only used in Windows; set it to 0.
735 */
736 vstor_packet->version.revision = 0;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700737
Keith Mange1a363102015-08-13 08:43:48 -0700738 ret = vmbus_sendpacket(device->channel, vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700739 (sizeof(struct vstor_packet) -
740 vmscsi_size_delta),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700741 (unsigned long)request,
742 VM_PKT_DATA_INBAND,
743 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
Keith Mange1a363102015-08-13 08:43:48 -0700744 if (ret != 0)
745 goto cleanup;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700746
Keith Mange1a363102015-08-13 08:43:48 -0700747 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
748 if (t == 0) {
749 ret = -ETIMEDOUT;
750 goto cleanup;
751 }
752
753 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO) {
754 ret = -EINVAL;
755 goto cleanup;
756 }
757
758 if (vstor_packet->status == 0) {
759 vmstor_proto_version =
760 vmstor_protocols[i].protocol_version;
761
762 sense_buffer_size =
763 vmstor_protocols[i].sense_buffer_size;
764
765 vmscsi_size_delta =
766 vmstor_protocols[i].vmscsi_size_delta;
767
768 break;
769 }
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700770 }
771
Keith Mange1a363102015-08-13 08:43:48 -0700772 if (vstor_packet->status != 0) {
773 ret = -EINVAL;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700774 goto cleanup;
Keith Mange1a363102015-08-13 08:43:48 -0700775 }
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700776
777
778 memset(vstor_packet, 0, sizeof(struct vstor_packet));
779 vstor_packet->operation = VSTOR_OPERATION_QUERY_PROPERTIES;
780 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700781
782 ret = vmbus_sendpacket(device->channel, vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700783 (sizeof(struct vstor_packet) -
784 vmscsi_size_delta),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700785 (unsigned long)request,
786 VM_PKT_DATA_INBAND,
787 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
788
789 if (ret != 0)
790 goto cleanup;
791
792 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
793 if (t == 0) {
794 ret = -ETIMEDOUT;
795 goto cleanup;
796 }
797
798 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
K. Y. Srinivasan111f2d12015-08-13 08:43:52 -0700799 vstor_packet->status != 0) {
800 ret = -EINVAL;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700801 goto cleanup;
K. Y. Srinivasan111f2d12015-08-13 08:43:52 -0700802 }
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700803
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700804 /*
805 * Check to see if multi-channel support is there.
806 * Hosts that implement protocol version of 5.1 and above
807 * support multi-channel.
808 */
809 max_chns = vstor_packet->storage_channel_properties.max_channel_cnt;
Keith Mangee6c4bc62015-08-13 08:43:50 -0700810 if (vmstor_proto_version >= VMSTOR_PROTO_VERSION_WIN8) {
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700811 if (vstor_packet->storage_channel_properties.flags &
812 STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL)
813 process_sub_channels = true;
814 }
K. Y. Srinivasan5117b932015-03-27 00:27:17 -0700815 stor_device->max_transfer_bytes =
816 vstor_packet->storage_channel_properties.max_transfer_bytes;
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700817
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700818 memset(vstor_packet, 0, sizeof(struct vstor_packet));
819 vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION;
820 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
821
822 ret = vmbus_sendpacket(device->channel, vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700823 (sizeof(struct vstor_packet) -
824 vmscsi_size_delta),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700825 (unsigned long)request,
826 VM_PKT_DATA_INBAND,
827 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
828
829 if (ret != 0)
830 goto cleanup;
831
832 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
833 if (t == 0) {
834 ret = -ETIMEDOUT;
835 goto cleanup;
836 }
837
838 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
K. Y. Srinivasan111f2d12015-08-13 08:43:52 -0700839 vstor_packet->status != 0) {
840 ret = -EINVAL;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700841 goto cleanup;
K. Y. Srinivasan111f2d12015-08-13 08:43:52 -0700842 }
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700843
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700844 if (process_sub_channels)
845 handle_multichannel_storage(device, max_chns);
846
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700847
848cleanup:
849 return ret;
850}
851
K. Y. Srinivasanc50bd442013-02-21 12:04:52 -0800852static void storvsc_handle_error(struct vmscsi_request *vm_srb,
853 struct scsi_cmnd *scmnd,
854 struct Scsi_Host *host,
855 u8 asc, u8 ascq)
856{
857 struct storvsc_scan_work *wrk;
858 void (*process_err_fn)(struct work_struct *work);
859 bool do_work = false;
860
861 switch (vm_srb->srb_status) {
862 case SRB_STATUS_ERROR:
863 /*
864 * If there is an error; offline the device since all
865 * error recovery strategies would have already been
866 * deployed on the host side. However, if the command
867 * were a pass-through command deal with it appropriately.
868 */
869 switch (scmnd->cmnd[0]) {
870 case ATA_16:
871 case ATA_12:
872 set_host_byte(scmnd, DID_PASSTHROUGH);
873 break;
K. Y. Srinivasan3533f8602014-07-12 09:48:32 -0700874 /*
875 * On Some Windows hosts TEST_UNIT_READY command can return
876 * SRB_STATUS_ERROR, let the upper level code deal with it
877 * based on the sense information.
878 */
879 case TEST_UNIT_READY:
880 break;
K. Y. Srinivasanc50bd442013-02-21 12:04:52 -0800881 default:
882 set_host_byte(scmnd, DID_TARGET_FAILURE);
883 }
884 break;
885 case SRB_STATUS_INVALID_LUN:
886 do_work = true;
887 process_err_fn = storvsc_remove_lun;
888 break;
K. Y. Srinivasan67812092013-02-21 12:04:53 -0800889 case (SRB_STATUS_ABORTED | SRB_STATUS_AUTOSENSE_VALID):
890 if ((asc == 0x2a) && (ascq == 0x9)) {
891 do_work = true;
892 process_err_fn = storvsc_device_scan;
893 /*
894 * Retry the I/O that trigerred this.
895 */
896 set_host_byte(scmnd, DID_REQUEUE);
897 }
898 break;
K. Y. Srinivasanc50bd442013-02-21 12:04:52 -0800899 }
K. Y. Srinivasan67812092013-02-21 12:04:53 -0800900
K. Y. Srinivasanc50bd442013-02-21 12:04:52 -0800901 if (!do_work)
902 return;
903
904 /*
905 * We need to schedule work to process this error; schedule it.
906 */
907 wrk = kmalloc(sizeof(struct storvsc_scan_work), GFP_ATOMIC);
908 if (!wrk) {
909 set_host_byte(scmnd, DID_TARGET_FAILURE);
910 return;
911 }
912
913 wrk->host = host;
914 wrk->lun = vm_srb->lun;
915 INIT_WORK(&wrk->work, process_err_fn);
916 schedule_work(&wrk->work);
917}
918
K. Y. Srinivasan2707388c2012-01-12 12:38:01 -0800919
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800920static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request)
K. Y. Srinivasan2707388c2012-01-12 12:38:01 -0800921{
K. Y. Srinivasan2707388c2012-01-12 12:38:01 -0800922 struct scsi_cmnd *scmnd = cmd_request->cmd;
923 struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
K. Y. Srinivasan2707388c2012-01-12 12:38:01 -0800924 struct scsi_sense_hdr sense_hdr;
925 struct vmscsi_request *vm_srb;
K. Y. Srinivasanc50bd442013-02-21 12:04:52 -0800926 struct Scsi_Host *host;
927 struct storvsc_device *stor_dev;
928 struct hv_device *dev = host_dev->dev;
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -0700929 u32 payload_sz = cmd_request->payload_sz;
930 void *payload = cmd_request->payload;
K. Y. Srinivasanc50bd442013-02-21 12:04:52 -0800931
932 stor_dev = get_in_stor_device(dev);
933 host = stor_dev->host;
K. Y. Srinivasan2707388c2012-01-12 12:38:01 -0800934
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800935 vm_srb = &cmd_request->vstor_packet.vm_srb;
K. Y. Srinivasan2707388c2012-01-12 12:38:01 -0800936
K. Y. Srinivasan42e22ca2012-04-05 12:26:52 -0700937 scmnd->result = vm_srb->scsi_status;
938
K. Y. Srinivasan2707388c2012-01-12 12:38:01 -0800939 if (scmnd->result) {
940 if (scsi_normalize_sense(scmnd->sense_buffer,
941 SCSI_SENSE_BUFFERSIZE, &sense_hdr))
Hannes Reinecked811b842014-10-24 14:26:45 +0200942 scsi_print_sense_hdr(scmnd->device, "storvsc",
943 &sense_hdr);
K. Y. Srinivasan2707388c2012-01-12 12:38:01 -0800944 }
945
K. Y. Srinivasanc50bd442013-02-21 12:04:52 -0800946 if (vm_srb->srb_status != SRB_STATUS_SUCCESS)
947 storvsc_handle_error(vm_srb, scmnd, host, sense_hdr.asc,
948 sense_hdr.ascq);
949
K. Y. Srinivasan2707388c2012-01-12 12:38:01 -0800950 scsi_set_resid(scmnd,
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -0700951 cmd_request->payload->range.len -
K. Y. Srinivasan2707388c2012-01-12 12:38:01 -0800952 vm_srb->data_transfer_length);
953
Christoph Hellwigead37002014-12-29 20:05:09 -0800954 scmnd->scsi_done(scmnd);
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -0700955
956 if (payload_sz >
957 sizeof(struct vmbus_channel_packet_multipage_buffer))
958 kfree(payload);
K. Y. Srinivasan2707388c2012-01-12 12:38:01 -0800959}
960
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700961static void storvsc_on_io_completion(struct hv_device *device,
962 struct vstor_packet *vstor_packet,
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800963 struct storvsc_cmd_request *request)
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700964{
965 struct storvsc_device *stor_device;
966 struct vstor_packet *stor_pkt;
967
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -0700968 stor_device = hv_get_drvdata(device);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700969 stor_pkt = &request->vstor_packet;
970
K. Y. Srinivasan4ed51a22011-08-27 11:31:26 -0700971 /*
972 * The current SCSI handling on the host side does
973 * not correctly handle:
974 * INQUIRY command with page code parameter set to 0x80
975 * MODE_SENSE command with cmd[2] == 0x1c
976 *
977 * Setup srb and scsi status so this won't be fatal.
978 * We do this so we can distinguish truly fatal failues
979 * (srb status == 0x4) and off-line the device in that case.
980 */
981
982 if ((stor_pkt->vm_srb.cdb[0] == INQUIRY) ||
K. Y. Srinivasana8c18c52012-01-12 12:38:00 -0800983 (stor_pkt->vm_srb.cdb[0] == MODE_SENSE)) {
K. Y. Srinivasan4ed51a22011-08-27 11:31:26 -0700984 vstor_packet->vm_srb.scsi_status = 0;
K. Y. Srinivasan16046322012-01-12 12:37:57 -0800985 vstor_packet->vm_srb.srb_status = SRB_STATUS_SUCCESS;
K. Y. Srinivasan4ed51a22011-08-27 11:31:26 -0700986 }
987
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700988
989 /* Copy over the status...etc */
990 stor_pkt->vm_srb.scsi_status = vstor_packet->vm_srb.scsi_status;
991 stor_pkt->vm_srb.srb_status = vstor_packet->vm_srb.srb_status;
992 stor_pkt->vm_srb.sense_info_length =
993 vstor_packet->vm_srb.sense_info_length;
994
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700995
996 if ((vstor_packet->vm_srb.scsi_status & 0xFF) == 0x02) {
997 /* CHECK_CONDITION */
K. Y. Srinivasan16046322012-01-12 12:37:57 -0800998 if (vstor_packet->vm_srb.srb_status &
999 SRB_STATUS_AUTOSENSE_VALID) {
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001000 /* autosense data available */
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001001
Christoph Hellwigead37002014-12-29 20:05:09 -08001002 memcpy(request->cmd->sense_buffer,
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001003 vstor_packet->vm_srb.sense_data,
1004 vstor_packet->vm_srb.sense_info_length);
1005
1006 }
1007 }
1008
1009 stor_pkt->vm_srb.data_transfer_length =
1010 vstor_packet->vm_srb.data_transfer_length;
1011
K. Y. Srinivasan2707388c2012-01-12 12:38:01 -08001012 storvsc_command_completion(request);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001013
1014 if (atomic_dec_and_test(&stor_device->num_outstanding_req) &&
1015 stor_device->drain_notify)
1016 wake_up(&stor_device->waiting_to_drain);
1017
1018
1019}
1020
1021static void storvsc_on_receive(struct hv_device *device,
1022 struct vstor_packet *vstor_packet,
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001023 struct storvsc_cmd_request *request)
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001024{
K. Y. Srinivasan126757992011-11-08 09:01:49 -08001025 struct storvsc_scan_work *work;
1026 struct storvsc_device *stor_device;
1027
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001028 switch (vstor_packet->operation) {
1029 case VSTOR_OPERATION_COMPLETE_IO:
1030 storvsc_on_io_completion(device, vstor_packet, request);
1031 break;
K. Y. Srinivasan126757992011-11-08 09:01:49 -08001032
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001033 case VSTOR_OPERATION_REMOVE_DEVICE:
K. Y. Srinivasan126757992011-11-08 09:01:49 -08001034 case VSTOR_OPERATION_ENUMERATE_BUS:
1035 stor_device = get_in_stor_device(device);
1036 work = kmalloc(sizeof(struct storvsc_scan_work), GFP_ATOMIC);
1037 if (!work)
1038 return;
1039
K. Y. Srinivasan2a09ed32014-12-16 13:21:42 -08001040 INIT_WORK(&work->work, storvsc_host_scan);
K. Y. Srinivasan126757992011-11-08 09:01:49 -08001041 work->host = stor_device->host;
1042 schedule_work(&work->work);
1043 break;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001044
1045 default:
1046 break;
1047 }
1048}
1049
1050static void storvsc_on_channel_callback(void *context)
1051{
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001052 struct vmbus_channel *channel = (struct vmbus_channel *)context;
1053 struct hv_device *device;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001054 struct storvsc_device *stor_device;
1055 u32 bytes_recvd;
1056 u64 request_id;
1057 unsigned char packet[ALIGN(sizeof(struct vstor_packet), 8)];
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001058 struct storvsc_cmd_request *request;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001059 int ret;
1060
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001061 if (channel->primary_channel != NULL)
1062 device = channel->primary_channel->device_obj;
1063 else
1064 device = channel->device_obj;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001065
1066 stor_device = get_in_stor_device(device);
1067 if (!stor_device)
1068 return;
1069
1070 do {
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001071 ret = vmbus_recvpacket(channel, packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001072 ALIGN((sizeof(struct vstor_packet) -
1073 vmscsi_size_delta), 8),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001074 &bytes_recvd, &request_id);
1075 if (ret == 0 && bytes_recvd > 0) {
1076
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001077 request = (struct storvsc_cmd_request *)
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001078 (unsigned long)request_id;
1079
1080 if ((request == &stor_device->init_request) ||
1081 (request == &stor_device->reset_request)) {
1082
1083 memcpy(&request->vstor_packet, packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001084 (sizeof(struct vstor_packet) -
1085 vmscsi_size_delta));
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001086 complete(&request->wait_event);
1087 } else {
1088 storvsc_on_receive(device,
1089 (struct vstor_packet *)packet,
1090 request);
1091 }
1092 } else {
1093 break;
1094 }
1095 } while (1);
1096
1097 return;
1098}
1099
1100static int storvsc_connect_to_vsp(struct hv_device *device, u32 ring_size)
1101{
1102 struct vmstorage_channel_properties props;
1103 int ret;
1104
1105 memset(&props, 0, sizeof(struct vmstorage_channel_properties));
1106
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001107 ret = vmbus_open(device->channel,
1108 ring_size,
1109 ring_size,
1110 (void *)&props,
1111 sizeof(struct vmstorage_channel_properties),
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001112 storvsc_on_channel_callback, device->channel);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001113
1114 if (ret != 0)
1115 return ret;
1116
1117 ret = storvsc_channel_init(device);
1118
1119 return ret;
1120}
1121
K. Y. Srinivasanc1b3d062011-08-27 11:31:25 -07001122static int storvsc_dev_remove(struct hv_device *device)
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001123{
1124 struct storvsc_device *stor_device;
1125 unsigned long flags;
1126
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -07001127 stor_device = hv_get_drvdata(device);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001128
1129 spin_lock_irqsave(&device->channel->inbound_lock, flags);
1130 stor_device->destroy = true;
1131 spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
1132
1133 /*
1134 * At this point, all outbound traffic should be disable. We
1135 * only allow inbound traffic (responses) to proceed so that
1136 * outstanding requests can be completed.
1137 */
1138
1139 storvsc_wait_to_drain(stor_device);
1140
1141 /*
1142 * Since we have already drained, we don't need to busy wait
1143 * as was done in final_release_stor_device()
1144 * Note that we cannot set the ext pointer to NULL until
1145 * we have drained - to drain the outgoing packets, we need to
1146 * allow incoming packets.
1147 */
1148 spin_lock_irqsave(&device->channel->inbound_lock, flags);
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -07001149 hv_set_drvdata(device, NULL);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001150 spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
1151
1152 /* Close the channel */
1153 vmbus_close(device->channel);
1154
1155 kfree(stor_device);
1156 return 0;
1157}
1158
K. Y. Srinivasanc1b3d062011-08-27 11:31:25 -07001159static int storvsc_do_io(struct hv_device *device,
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001160 struct storvsc_cmd_request *request)
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001161{
1162 struct storvsc_device *stor_device;
1163 struct vstor_packet *vstor_packet;
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001164 struct vmbus_channel *outgoing_channel;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001165 int ret = 0;
1166
1167 vstor_packet = &request->vstor_packet;
1168 stor_device = get_out_stor_device(device);
1169
1170 if (!stor_device)
1171 return -ENODEV;
1172
1173
1174 request->device = device;
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001175 /*
1176 * Select an an appropriate channel to send the request out.
1177 */
1178
1179 outgoing_channel = vmbus_get_outgoing_channel(device->channel);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001180
1181
1182 vstor_packet->flags |= REQUEST_COMPLETION_FLAG;
1183
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001184 vstor_packet->vm_srb.length = (sizeof(struct vmscsi_request) -
1185 vmscsi_size_delta);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001186
1187
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001188 vstor_packet->vm_srb.sense_info_length = sense_buffer_size;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001189
1190
1191 vstor_packet->vm_srb.data_transfer_length =
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001192 request->payload->range.len;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001193
1194 vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB;
1195
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001196 if (request->payload->range.len) {
1197
1198 ret = vmbus_sendpacket_mpb_desc(outgoing_channel,
1199 request->payload, request->payload_sz,
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001200 vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001201 (sizeof(struct vstor_packet) -
1202 vmscsi_size_delta),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001203 (unsigned long)request);
1204 } else {
K. Y. Srinivasan0147dab2015-03-27 00:27:16 -07001205 ret = vmbus_sendpacket(outgoing_channel, vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001206 (sizeof(struct vstor_packet) -
1207 vmscsi_size_delta),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001208 (unsigned long)request,
1209 VM_PKT_DATA_INBAND,
1210 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
1211 }
1212
1213 if (ret != 0)
1214 return ret;
1215
1216 atomic_inc(&stor_device->num_outstanding_req);
1217
1218 return ret;
1219}
1220
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001221static int storvsc_device_configure(struct scsi_device *sdevice)
1222{
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001223
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001224 blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE);
1225
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001226 blk_queue_bounce_limit(sdevice->request_queue, BLK_BOUNCE_ANY);
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001227
K. Y. Srinivasan893def32013-06-04 12:05:05 -07001228 blk_queue_rq_timeout(sdevice->request_queue, (storvsc_timeout * HZ));
1229
Vitaly Kuznetsov81988a02015-10-01 14:53:17 -07001230 /* Ensure there are no gaps in presented sgls */
1231 blk_queue_virt_boundary(sdevice->request_queue, PAGE_SIZE - 1);
1232
Olaf Hering3e8f4f42013-02-21 12:04:51 -08001233 sdevice->no_write_same = 1;
1234
K. Y. Srinivasanf3cfabc2014-07-21 16:06:01 -07001235 /*
1236 * Add blist flags to permit the reading of the VPD pages even when
1237 * the target may claim SPC-2 compliance. MSFT targets currently
1238 * claim SPC-2 compliance while they implement post SPC-2 features.
1239 * With this patch we can correctly handle WRITE_SAME_16 issues.
1240 */
1241 sdevice->sdev_bflags |= msft_blist_flags;
1242
K. Y. Srinivasanb0a93d92014-12-16 13:21:45 -08001243 /*
1244 * If the host is WIN8 or WIN8 R2, claim conformance to SPC-3
Keith Mangeb95f5be2015-08-13 08:43:51 -07001245 * if the device is a MSFT virtual device. If the host is
1246 * WIN10 or newer, allow write_same.
K. Y. Srinivasanb0a93d92014-12-16 13:21:45 -08001247 */
1248 if (!strncmp(sdevice->vendor, "Msft", 4)) {
Keith Mangee6c4bc62015-08-13 08:43:50 -07001249 switch (vmstor_proto_version) {
1250 case VMSTOR_PROTO_VERSION_WIN8:
1251 case VMSTOR_PROTO_VERSION_WIN8_1:
K. Y. Srinivasanb0a93d92014-12-16 13:21:45 -08001252 sdevice->scsi_level = SCSI_SPC_3;
1253 break;
1254 }
Keith Mangeb95f5be2015-08-13 08:43:51 -07001255
1256 if (vmstor_proto_version >= VMSTOR_PROTO_VERSION_WIN10)
1257 sdevice->no_write_same = 0;
K. Y. Srinivasanb0a93d92014-12-16 13:21:45 -08001258 }
1259
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001260 return 0;
1261}
1262
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001263static int storvsc_get_chs(struct scsi_device *sdev, struct block_device * bdev,
1264 sector_t capacity, int *info)
1265{
K. Y. Srinivasan5326fd52011-05-10 07:54:52 -07001266 sector_t nsect = capacity;
1267 sector_t cylinders = nsect;
1268 int heads, sectors_pt;
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001269
K. Y. Srinivasan5326fd52011-05-10 07:54:52 -07001270 /*
1271 * We are making up these values; let us keep it simple.
1272 */
1273 heads = 0xff;
1274 sectors_pt = 0x3f; /* Sectors per track */
1275 sector_div(cylinders, heads * sectors_pt);
1276 if ((sector_t)(cylinders + 1) * heads * sectors_pt < nsect)
1277 cylinders = 0xffff;
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001278
1279 info[0] = heads;
K. Y. Srinivasan5326fd52011-05-10 07:54:52 -07001280 info[1] = sectors_pt;
1281 info[2] = (int)cylinders;
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001282
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001283 return 0;
1284}
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001285
K. Y. Srinivasan4b270c82012-01-12 12:37:58 -08001286static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd)
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001287{
K. Y. Srinivasan4b270c82012-01-12 12:37:58 -08001288 struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
1289 struct hv_device *device = host_dev->dev;
1290
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001291 struct storvsc_device *stor_device;
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001292 struct storvsc_cmd_request *request;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001293 struct vstor_packet *vstor_packet;
1294 int ret, t;
1295
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001296
K. Y. Srinivasan1eaaddf2011-08-27 11:31:03 -07001297 stor_device = get_out_stor_device(device);
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001298 if (!stor_device)
K. Y. Srinivasana00e8222011-11-08 09:01:43 -08001299 return FAILED;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001300
1301 request = &stor_device->reset_request;
1302 vstor_packet = &request->vstor_packet;
1303
1304 init_completion(&request->wait_event);
1305
1306 vstor_packet->operation = VSTOR_OPERATION_RESET_BUS;
1307 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
1308 vstor_packet->vm_srb.path_id = stor_device->path_id;
1309
1310 ret = vmbus_sendpacket(device->channel, vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001311 (sizeof(struct vstor_packet) -
1312 vmscsi_size_delta),
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001313 (unsigned long)&stor_device->reset_request,
1314 VM_PKT_DATA_INBAND,
1315 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
1316 if (ret != 0)
K. Y. Srinivasana00e8222011-11-08 09:01:43 -08001317 return FAILED;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001318
K. Y. Srinivasan46d2eb62011-06-16 13:16:36 -07001319 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
K. Y. Srinivasana00e8222011-11-08 09:01:43 -08001320 if (t == 0)
1321 return TIMEOUT_ERROR;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001322
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001323
1324 /*
1325 * At this point, all outstanding requests in the adapter
1326 * should have been flushed out and return to us
K. Y. Srinivasan5c1b10a2012-10-02 11:03:31 -07001327 * There is a potential race here where the host may be in
1328 * the process of responding when we return from here.
1329 * Just wait for all in-transit packets to be accounted for
1330 * before we return from here.
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001331 */
K. Y. Srinivasan5c1b10a2012-10-02 11:03:31 -07001332 storvsc_wait_to_drain(stor_device);
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001333
K. Y. Srinivasana00e8222011-11-08 09:01:43 -08001334 return SUCCESS;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001335}
1336
K. Y. Srinivasan56b26e62014-07-12 09:48:30 -07001337/*
1338 * The host guarantees to respond to each command, although I/O latencies might
1339 * be unbounded on Azure. Reset the timer unconditionally to give the host a
1340 * chance to perform EH.
1341 */
1342static enum blk_eh_timer_return storvsc_eh_timed_out(struct scsi_cmnd *scmnd)
1343{
1344 return BLK_EH_RESET_TIMER;
1345}
1346
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001347static bool storvsc_scsi_cmd_ok(struct scsi_cmnd *scmnd)
Olaf Hering92ae4eb2011-10-10 09:37:39 +02001348{
1349 bool allowed = true;
1350 u8 scsi_op = scmnd->cmnd[0];
1351
1352 switch (scsi_op) {
Olaf Hering3e8f4f42013-02-21 12:04:51 -08001353 /* the host does not handle WRITE_SAME, log accident usage */
1354 case WRITE_SAME:
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001355 /*
1356 * smartd sends this command and the host does not handle
1357 * this. So, don't send it.
1358 */
K. Y. Srinivasan41098f82011-10-14 21:31:57 -07001359 case SET_WINDOW:
K. Y. Srinivasan59e00e72011-11-08 09:01:42 -08001360 scmnd->result = ILLEGAL_REQUEST << 16;
K. Y. Srinivasan41098f82011-10-14 21:31:57 -07001361 allowed = false;
1362 break;
1363 default:
1364 break;
Olaf Hering92ae4eb2011-10-10 09:37:39 +02001365 }
1366 return allowed;
1367}
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001368
K. Y. Srinivasanbab445e2011-11-08 09:01:45 -08001369static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001370{
1371 int ret;
K. Y. Srinivasanbab445e2011-11-08 09:01:45 -08001372 struct hv_host_device *host_dev = shost_priv(host);
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001373 struct hv_device *dev = host_dev->dev;
Christoph Hellwigead37002014-12-29 20:05:09 -08001374 struct storvsc_cmd_request *cmd_request = scsi_cmd_priv(scmnd);
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001375 int i;
1376 struct scatterlist *sgl;
1377 unsigned int sg_count = 0;
1378 struct vmscsi_request *vm_srb;
K. Y. Srinivasanaaced992015-03-27 00:27:19 -07001379 struct scatterlist *cur_sgl;
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001380 struct vmbus_packet_mpb_array *payload;
1381 u32 payload_sz;
1382 u32 length;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001383
Keith Mange2492fd72015-08-13 08:43:47 -07001384 if (vmstor_proto_version <= VMSTOR_PROTO_VERSION_WIN8) {
K. Y. Srinivasan8caf92d2014-07-12 09:48:28 -07001385 /*
1386 * On legacy hosts filter unimplemented commands.
1387 * Future hosts are expected to correctly handle
1388 * unsupported commands. Furthermore, it is
1389 * possible that some of the currently
1390 * unsupported commands maybe supported in
1391 * future versions of the host.
1392 */
1393 if (!storvsc_scsi_cmd_ok(scmnd)) {
1394 scmnd->scsi_done(scmnd);
1395 return 0;
1396 }
Olaf Hering92ae4eb2011-10-10 09:37:39 +02001397 }
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001398
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001399 /* Setup the cmd request */
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001400 cmd_request->cmd = scmnd;
1401
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001402 vm_srb = &cmd_request->vstor_packet.vm_srb;
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001403 vm_srb->win8_extension.time_out_value = 60;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001404
K. Y. Srinivasanf885fb72014-07-12 09:48:31 -07001405 vm_srb->win8_extension.srb_flags |=
K. Y. Srinivasan8cf308e2015-08-31 08:21:54 -07001406 SRB_FLAGS_DISABLE_SYNCH_TRANSFER;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001407
1408 /* Build the SRB */
1409 switch (scmnd->sc_data_direction) {
1410 case DMA_TO_DEVICE:
1411 vm_srb->data_in = WRITE_TYPE;
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001412 vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_OUT;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001413 break;
1414 case DMA_FROM_DEVICE:
1415 vm_srb->data_in = READ_TYPE;
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001416 vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_IN;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001417 break;
Vitaly Kuznetsovcb1cf082015-06-25 18:12:11 +02001418 case DMA_NONE:
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001419 vm_srb->data_in = UNKNOWN_TYPE;
K. Y. Srinivasandc457082015-05-01 11:03:02 -07001420 vm_srb->win8_extension.srb_flags |= SRB_FLAGS_NO_DATA_TRANSFER;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001421 break;
Vitaly Kuznetsovcb1cf082015-06-25 18:12:11 +02001422 default:
1423 /*
1424 * This is DMA_BIDIRECTIONAL or something else we are never
1425 * supposed to see here.
1426 */
1427 WARN(1, "Unexpected data direction: %d\n",
1428 scmnd->sc_data_direction);
1429 return -EINVAL;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001430 }
1431
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001432
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001433 vm_srb->port_number = host_dev->port;
1434 vm_srb->path_id = scmnd->device->channel;
1435 vm_srb->target_id = scmnd->device->id;
1436 vm_srb->lun = scmnd->device->lun;
1437
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001438 vm_srb->cdb_length = scmnd->cmd_len;
1439
1440 memcpy(vm_srb->cdb, scmnd->cmnd, vm_srb->cdb_length);
1441
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001442 sgl = (struct scatterlist *)scsi_sglist(scmnd);
1443 sg_count = scsi_sg_count(scmnd);
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001444
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001445 length = scsi_bufflen(scmnd);
1446 payload = (struct vmbus_packet_mpb_array *)&cmd_request->mpb;
1447 payload_sz = sizeof(cmd_request->mpb);
1448
1449 if (sg_count) {
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001450 if (sg_count > MAX_PAGE_BUFFER_COUNT) {
1451
1452 payload_sz = (sg_count * sizeof(void *) +
1453 sizeof(struct vmbus_packet_mpb_array));
1454 payload = kmalloc(payload_sz, GFP_ATOMIC);
Vitaly Kuznetsov81988a02015-10-01 14:53:17 -07001455 if (!payload)
1456 return SCSI_MLQUEUE_DEVICE_BUSY;
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001457 }
1458
1459 payload->range.len = length;
1460 payload->range.offset = sgl[0].offset;
1461
K. Y. Srinivasanaaced992015-03-27 00:27:19 -07001462 cur_sgl = sgl;
1463 for (i = 0; i < sg_count; i++) {
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001464 payload->range.pfn_array[i] =
K. Y. Srinivasanaaced992015-03-27 00:27:19 -07001465 page_to_pfn(sg_page((cur_sgl)));
1466 cur_sgl = sg_next(cur_sgl);
1467 }
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001468
1469 } else if (scsi_sglist(scmnd)) {
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001470 payload->range.len = length;
1471 payload->range.offset =
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001472 virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE-1);
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001473 payload->range.pfn_array[0] =
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001474 virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT;
1475 }
1476
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001477 cmd_request->payload = payload;
1478 cmd_request->payload_sz = payload_sz;
1479
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001480 /* Invokes the vsc to start an IO */
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001481 ret = storvsc_do_io(dev, cmd_request);
K. Y. Srinivasan636f0fd2011-05-10 07:54:50 -07001482
K. Y. Srinivasand2598f02011-08-25 09:48:58 -07001483 if (ret == -EAGAIN) {
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001484 /* no more space */
Christoph Hellwigead37002014-12-29 20:05:09 -08001485 return SCSI_MLQUEUE_DEVICE_BUSY;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001486 }
1487
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001488 return 0;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001489}
1490
Hank Janssenbef4a342009-07-13 16:01:31 -07001491static struct scsi_host_template scsi_driver = {
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001492 .module = THIS_MODULE,
1493 .name = "storvsc_host_t",
Christoph Hellwigead37002014-12-29 20:05:09 -08001494 .cmd_size = sizeof(struct storvsc_cmd_request),
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001495 .bios_param = storvsc_get_chs,
1496 .queuecommand = storvsc_queuecommand,
1497 .eh_host_reset_handler = storvsc_host_reset_handler,
Christoph Hellwigead37002014-12-29 20:05:09 -08001498 .proc_name = "storvsc_host",
K. Y. Srinivasan56b26e62014-07-12 09:48:30 -07001499 .eh_timed_out = storvsc_eh_timed_out,
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001500 .slave_configure = storvsc_device_configure,
K. Y. Srinivasan52f96142014-07-12 09:48:27 -07001501 .cmd_per_lun = 255,
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001502 .this_id = -1,
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001503 .use_clustering = ENABLE_CLUSTERING,
Bill Pemberton454f18a2009-07-27 16:47:24 -04001504 /* Make sure we dont get a sg segment crosses a page boundary */
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001505 .dma_boundary = PAGE_SIZE-1,
Martin K. Petersen54b2b502013-10-23 06:25:40 -04001506 .no_write_same = 1,
Hank Janssenbef4a342009-07-13 16:01:31 -07001507};
1508
K. Y. Srinivasanef52a812011-09-13 10:59:39 -07001509enum {
1510 SCSI_GUID,
1511 IDE_GUID,
K. Y. Srinivasanbde6d0f2013-06-04 12:05:08 -07001512 SFC_GUID,
K. Y. Srinivasanef52a812011-09-13 10:59:39 -07001513};
1514
K. Y. Srinivasand847b5f2011-08-25 09:48:33 -07001515static const struct hv_vmbus_device_id id_table[] = {
Greg Kroah-Hartmanc45cf2d2011-08-25 11:41:33 -07001516 /* SCSI guid */
K. Y. Srinivasan35c3bc22013-01-23 17:42:43 -08001517 { HV_SCSI_GUID,
1518 .driver_data = SCSI_GUID
1519 },
K. Y. Srinivasan21e37742011-08-27 11:31:18 -07001520 /* IDE guid */
K. Y. Srinivasan35c3bc22013-01-23 17:42:43 -08001521 { HV_IDE_GUID,
1522 .driver_data = IDE_GUID
1523 },
K. Y. Srinivasanbde6d0f2013-06-04 12:05:08 -07001524 /* Fibre Channel GUID */
1525 {
1526 HV_SYNTHFC_GUID,
1527 .driver_data = SFC_GUID
1528 },
Greg Kroah-Hartmanc45cf2d2011-08-25 11:41:33 -07001529 { },
K. Y. Srinivasand847b5f2011-08-25 09:48:33 -07001530};
Hank Janssenbef4a342009-07-13 16:01:31 -07001531
K. Y. Srinivasand847b5f2011-08-25 09:48:33 -07001532MODULE_DEVICE_TABLE(vmbus, id_table);
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001533
K. Y. Srinivasan84946892011-09-13 10:59:38 -07001534static int storvsc_probe(struct hv_device *device,
1535 const struct hv_vmbus_device_id *dev_id)
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001536{
1537 int ret;
K. Y. Srinivasanf458aad2015-03-27 00:27:15 -07001538 int num_cpus = num_online_cpus();
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001539 struct Scsi_Host *host;
1540 struct hv_host_device *host_dev;
K. Y. Srinivasanef52a812011-09-13 10:59:39 -07001541 bool dev_is_ide = ((dev_id->driver_data == IDE_GUID) ? true : false);
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001542 int target = 0;
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001543 struct storvsc_device *stor_device;
K. Y. Srinivasan0fb8db22014-12-16 13:21:44 -08001544 int max_luns_per_target;
1545 int max_targets;
1546 int max_channels;
K. Y. Srinivasanf458aad2015-03-27 00:27:15 -07001547 int max_sub_channels = 0;
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001548
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001549 /*
1550 * Based on the windows host we are running on,
1551 * set state to properly communicate with the host.
1552 */
1553
Keith Mange6ee5c612015-08-13 08:43:46 -07001554 if (vmbus_proto_version < VERSION_WIN8) {
K. Y. Srinivasan0fb8db22014-12-16 13:21:44 -08001555 max_luns_per_target = STORVSC_IDE_MAX_LUNS_PER_TARGET;
1556 max_targets = STORVSC_IDE_MAX_TARGETS;
1557 max_channels = STORVSC_IDE_MAX_CHANNELS;
Keith Mange6ee5c612015-08-13 08:43:46 -07001558 } else {
K. Y. Srinivasan0fb8db22014-12-16 13:21:44 -08001559 max_luns_per_target = STORVSC_MAX_LUNS_PER_TARGET;
1560 max_targets = STORVSC_MAX_TARGETS;
1561 max_channels = STORVSC_MAX_CHANNELS;
K. Y. Srinivasanf458aad2015-03-27 00:27:15 -07001562 /*
1563 * On Windows8 and above, we support sub-channels for storage.
1564 * The number of sub-channels offerred is based on the number of
1565 * VCPUs in the guest.
1566 */
1567 max_sub_channels = (num_cpus / storvsc_vcpus_per_sub_channel);
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001568 }
1569
K. Y. Srinivasanf458aad2015-03-27 00:27:15 -07001570 scsi_driver.can_queue = (max_outstanding_req_per_channel *
1571 (max_sub_channels + 1));
1572
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001573 host = scsi_host_alloc(&scsi_driver,
1574 sizeof(struct hv_host_device));
1575 if (!host)
1576 return -ENOMEM;
1577
K. Y. Srinivasan7f33f302011-11-08 09:01:44 -08001578 host_dev = shost_priv(host);
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001579 memset(host_dev, 0, sizeof(struct hv_host_device));
1580
1581 host_dev->port = host->host_no;
1582 host_dev->dev = device;
1583
K. Y. Srinivasan4e03e692011-11-08 09:01:40 -08001584
K. Y. Srinivasana13d35a2011-09-13 10:59:46 -07001585 stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001586 if (!stor_device) {
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001587 ret = -ENOMEM;
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001588 goto err_out0;
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001589 }
1590
K. Y. Srinivasana13d35a2011-09-13 10:59:46 -07001591 stor_device->destroy = false;
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001592 stor_device->open_sub_channel = false;
K. Y. Srinivasana13d35a2011-09-13 10:59:46 -07001593 init_waitqueue_head(&stor_device->waiting_to_drain);
1594 stor_device->device = device;
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -07001595 stor_device->host = host;
1596 hv_set_drvdata(device, stor_device);
K. Y. Srinivasana13d35a2011-09-13 10:59:46 -07001597
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001598 stor_device->port_number = host->host_no;
1599 ret = storvsc_connect_to_vsp(device, storvsc_ringbuffer_size);
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001600 if (ret)
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001601 goto err_out1;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001602
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001603 host_dev->path = stor_device->path_id;
1604 host_dev->target = stor_device->target_id;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001605
K. Y. Srinivasan4cd83ec2014-07-12 09:48:26 -07001606 switch (dev_id->driver_data) {
1607 case SFC_GUID:
1608 host->max_lun = STORVSC_FC_MAX_LUNS_PER_TARGET;
1609 host->max_id = STORVSC_FC_MAX_TARGETS;
1610 host->max_channel = STORVSC_FC_MAX_CHANNELS - 1;
1611 break;
1612
1613 case SCSI_GUID:
K. Y. Srinivasan0fb8db22014-12-16 13:21:44 -08001614 host->max_lun = max_luns_per_target;
1615 host->max_id = max_targets;
1616 host->max_channel = max_channels - 1;
K. Y. Srinivasan4cd83ec2014-07-12 09:48:26 -07001617 break;
1618
1619 default:
1620 host->max_lun = STORVSC_IDE_MAX_LUNS_PER_TARGET;
1621 host->max_id = STORVSC_IDE_MAX_TARGETS;
1622 host->max_channel = STORVSC_IDE_MAX_CHANNELS - 1;
1623 break;
1624 }
Mike Sterlingcf55f4a2011-09-06 16:10:55 -07001625 /* max cmd length */
1626 host->max_cmd_len = STORVSC_MAX_CMD_LEN;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001627
K. Y. Srinivasanbe0cf6c2015-03-27 00:27:20 -07001628 /*
1629 * set the table size based on the info we got
1630 * from the host.
1631 */
1632 host->sg_tablesize = (stor_device->max_transfer_bytes >> PAGE_SHIFT);
1633
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001634 /* Register the HBA and start the scsi bus scan */
1635 ret = scsi_add_host(host, &device->device);
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001636 if (ret != 0)
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001637 goto err_out2;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001638
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001639 if (!dev_is_ide) {
1640 scsi_scan_host(host);
K. Y. Srinivasan59d22952012-01-12 12:37:55 -08001641 } else {
1642 target = (device->dev_instance.b[5] << 8 |
1643 device->dev_instance.b[4]);
1644 ret = scsi_add_device(host, 0, target, 0);
1645 if (ret) {
1646 scsi_remove_host(host);
1647 goto err_out2;
1648 }
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001649 }
1650 return 0;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001651
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001652err_out2:
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001653 /*
1654 * Once we have connected with the host, we would need to
1655 * to invoke storvsc_dev_remove() to rollback this state and
1656 * this call also frees up the stor_device; hence the jump around
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001657 * err_out1 label.
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001658 */
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001659 storvsc_dev_remove(device);
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001660 goto err_out0;
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001661
1662err_out1:
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001663 kfree(stor_device);
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001664
1665err_out0:
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001666 scsi_host_put(host);
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001667 return ret;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001668}
1669
K. Y. Srinivasanddcbf652012-01-12 12:37:59 -08001670static int storvsc_remove(struct hv_device *dev)
1671{
1672 struct storvsc_device *stor_device = hv_get_drvdata(dev);
1673 struct Scsi_Host *host = stor_device->host;
1674
1675 scsi_remove_host(host);
1676 storvsc_dev_remove(dev);
1677 scsi_host_put(host);
1678
1679 return 0;
1680}
1681
K. Y. Srinivasan40bf63e2011-05-10 07:56:09 -07001682static struct hv_driver storvsc_drv = {
K. Y. Srinivasanfafb0ef2011-11-08 09:01:46 -08001683 .name = KBUILD_MODNAME,
K. Y. Srinivasand847b5f2011-08-25 09:48:33 -07001684 .id_table = id_table,
K. Y. Srinivasan40bf63e2011-05-10 07:56:09 -07001685 .probe = storvsc_probe,
1686 .remove = storvsc_remove,
K. Y. Srinivasan39ae6fa2011-05-10 07:54:46 -07001687};
K. Y. Srinivasan7bd05b92011-05-10 07:54:45 -07001688
K. Y. Srinivasand9bbae82011-06-06 15:49:27 -07001689static int __init storvsc_drv_init(void)
Hank Janssenbef4a342009-07-13 16:01:31 -07001690{
K. Y. Srinivasan01415ab32011-05-10 07:55:58 -07001691
1692 /*
1693 * Divide the ring buffer data size (which is 1 page less
1694 * than the ring buffer size since that page is reserved for
1695 * the ring buffer indices) by the max request size (which is
1696 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
1697 */
K. Y. Srinivasan01415ab32011-05-10 07:55:58 -07001698 max_outstanding_req_per_channel =
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001699 ((storvsc_ringbuffer_size - PAGE_SIZE) /
1700 ALIGN(MAX_MULTIPAGE_BUFFER_PACKET +
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001701 sizeof(struct vstor_packet) + sizeof(u64) -
1702 vmscsi_size_delta,
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001703 sizeof(u64)));
Hank Janssenbef4a342009-07-13 16:01:31 -07001704
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001705 return vmbus_driver_register(&storvsc_drv);
Hank Janssenbef4a342009-07-13 16:01:31 -07001706}
1707
K. Y. Srinivasanc63ba9e2011-06-06 15:49:26 -07001708static void __exit storvsc_drv_exit(void)
Hank Janssenbef4a342009-07-13 16:01:31 -07001709{
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001710 vmbus_driver_unregister(&storvsc_drv);
Hank Janssenbef4a342009-07-13 16:01:31 -07001711}
1712
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001713MODULE_LICENSE("GPL");
Stephen Hemminger3afc7cc32010-05-06 21:44:45 -07001714MODULE_DESCRIPTION("Microsoft Hyper-V virtual storage driver");
K. Y. Srinivasand9bbae82011-06-06 15:49:27 -07001715module_init(storvsc_drv_init);
K. Y. Srinivasanc63ba9e2011-06-06 15:49:26 -07001716module_exit(storvsc_drv_exit);