blob: ab0bb98239b0d921bf01aae5e62b34589d5e4556 [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
K. Y. Srinivasan09f03552012-01-12 12:37:54 -080059 */
60
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -070061
62#define VMSTOR_WIN7_MAJOR 4
63#define VMSTOR_WIN7_MINOR 2
64
65#define VMSTOR_WIN8_MAJOR 5
66#define VMSTOR_WIN8_MINOR 1
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -070067
68
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -070069/* Packet structure describing virtual storage requests. */
70enum vstor_packet_operation {
71 VSTOR_OPERATION_COMPLETE_IO = 1,
72 VSTOR_OPERATION_REMOVE_DEVICE = 2,
73 VSTOR_OPERATION_EXECUTE_SRB = 3,
74 VSTOR_OPERATION_RESET_LUN = 4,
75 VSTOR_OPERATION_RESET_ADAPTER = 5,
76 VSTOR_OPERATION_RESET_BUS = 6,
77 VSTOR_OPERATION_BEGIN_INITIALIZATION = 7,
78 VSTOR_OPERATION_END_INITIALIZATION = 8,
79 VSTOR_OPERATION_QUERY_PROTOCOL_VERSION = 9,
80 VSTOR_OPERATION_QUERY_PROPERTIES = 10,
K. Y. Srinivasan2b9525f2011-11-08 09:01:48 -080081 VSTOR_OPERATION_ENUMERATE_BUS = 11,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -070082 VSTOR_OPERATION_FCHBA_DATA = 12,
83 VSTOR_OPERATION_CREATE_SUB_CHANNELS = 13,
84 VSTOR_OPERATION_MAXIMUM = 13
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -070085};
86
87/*
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -070088 * WWN packet for Fibre Channel HBA
89 */
90
91struct hv_fc_wwn_packet {
92 bool primary_active;
93 u8 reserved1;
94 u8 reserved2;
95 u8 primary_port_wwn[8];
96 u8 primary_node_wwn[8];
97 u8 secondary_port_wwn[8];
98 u8 secondary_node_wwn[8];
99};
100
101
102
103/*
104 * SRB Flag Bits
105 */
106
107#define SRB_FLAGS_QUEUE_ACTION_ENABLE 0x00000002
108#define SRB_FLAGS_DISABLE_DISCONNECT 0x00000004
109#define SRB_FLAGS_DISABLE_SYNCH_TRANSFER 0x00000008
110#define SRB_FLAGS_BYPASS_FROZEN_QUEUE 0x00000010
111#define SRB_FLAGS_DISABLE_AUTOSENSE 0x00000020
112#define SRB_FLAGS_DATA_IN 0x00000040
113#define SRB_FLAGS_DATA_OUT 0x00000080
114#define SRB_FLAGS_NO_DATA_TRANSFER 0x00000000
115#define SRB_FLAGS_UNSPECIFIED_DIRECTION (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)
116#define SRB_FLAGS_NO_QUEUE_FREEZE 0x00000100
117#define SRB_FLAGS_ADAPTER_CACHE_ENABLE 0x00000200
118#define SRB_FLAGS_FREE_SENSE_BUFFER 0x00000400
119
120/*
121 * This flag indicates the request is part of the workflow for processing a D3.
122 */
123#define SRB_FLAGS_D3_PROCESSING 0x00000800
124#define SRB_FLAGS_IS_ACTIVE 0x00010000
125#define SRB_FLAGS_ALLOCATED_FROM_ZONE 0x00020000
126#define SRB_FLAGS_SGLIST_FROM_POOL 0x00040000
127#define SRB_FLAGS_BYPASS_LOCKED_QUEUE 0x00080000
128#define SRB_FLAGS_NO_KEEP_AWAKE 0x00100000
129#define SRB_FLAGS_PORT_DRIVER_ALLOCSENSE 0x00200000
130#define SRB_FLAGS_PORT_DRIVER_SENSEHASPORT 0x00400000
131#define SRB_FLAGS_DONT_START_NEXT_PACKET 0x00800000
132#define SRB_FLAGS_PORT_DRIVER_RESERVED 0x0F000000
133#define SRB_FLAGS_CLASS_DRIVER_RESERVED 0xF0000000
134
135
136/*
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700137 * Platform neutral description of a scsi request -
138 * this remains the same across the write regardless of 32/64 bit
139 * note: it's patterned off the SCSI_PASS_THROUGH structure
140 */
K. Y. Srinivasan6b2f9492012-01-12 12:38:05 -0800141#define STORVSC_MAX_CMD_LEN 0x10
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700142
143#define POST_WIN7_STORVSC_SENSE_BUFFER_SIZE 0x14
144#define PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE 0x12
145
146#define STORVSC_SENSE_BUFFER_SIZE 0x14
K. Y. Srinivasan6b2f9492012-01-12 12:38:05 -0800147#define STORVSC_MAX_BUF_LEN_WITH_PADDING 0x14
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700148
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700149/*
150 * Sense buffer size changed in win8; have a run-time
151 * variable to track the size we should use.
152 */
153static int sense_buffer_size;
154
155/*
156 * The size of the vmscsi_request has changed in win8. The
157 * additional size is because of new elements added to the
158 * structure. These elements are valid only when we are talking
159 * to a win8 host.
160 * Track the correction to size we need to apply.
161 */
162
163static int vmscsi_size_delta;
164static int vmstor_current_major;
165static int vmstor_current_minor;
166
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/*
210 * This structure is sent during the intialization phase to get the different
211 * properties of the channel.
212 */
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700213
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700214#define STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL 0x1
215
216struct vmstorage_channel_properties {
217 u32 reserved;
218 u16 max_channel_cnt;
219 u16 reserved1;
220
221 u32 flags;
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800222 u32 max_transfer_bytes;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700223
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700224 u64 reserved2;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700225} __packed;
226
227/* This structure is sent during the storage protocol negotiations. */
228struct vmstorage_protocol_version {
229 /* Major (MSW) and minor (LSW) version numbers. */
K. Y. Srinivasan85904a52012-01-12 12:38:04 -0800230 u16 major_minor;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700231
232 /*
233 * Revision number is auto-incremented whenever this file is changed
234 * (See FILL_VMSTOR_REVISION macro above). Mismatch does not
235 * definitely indicate incompatibility--but it does indicate mismatched
236 * builds.
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800237 * This is only used on the windows side. Just set it to 0.
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700238 */
K. Y. Srinivasan85904a52012-01-12 12:38:04 -0800239 u16 revision;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700240} __packed;
241
242/* Channel Property Flags */
243#define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1
244#define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2
245
246struct vstor_packet {
247 /* Requested operation type */
248 enum vstor_packet_operation operation;
249
250 /* Flags - see below for values */
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800251 u32 flags;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700252
253 /* Status of the request returned from the server side. */
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800254 u32 status;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700255
256 /* Data payload area */
257 union {
258 /*
259 * Structure used to forward SCSI commands from the
260 * client to the server.
261 */
262 struct vmscsi_request vm_srb;
263
264 /* Structure used to query channel properties. */
265 struct vmstorage_channel_properties storage_channel_properties;
266
267 /* Used during version negotiations. */
268 struct vmstorage_protocol_version version;
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700269
270 /* Fibre channel address packet */
271 struct hv_fc_wwn_packet wwn_packet;
272
273 /* Number of sub-channels to create */
274 u16 sub_channel_count;
275
276 /* This will be the maximum of the union members */
277 u8 buffer[0x34];
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700278 };
279} __packed;
280
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700281/*
K. Y. Srinivasan09f03552012-01-12 12:37:54 -0800282 * Packet Flags:
283 *
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700284 * This flag indicates that the server should send back a completion for this
285 * packet.
286 */
K. Y. Srinivasan09f03552012-01-12 12:37:54 -0800287
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700288#define REQUEST_COMPLETION_FLAG 0x1
289
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700290/* Matches Windows-end */
291enum storvsc_request_type {
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800292 WRITE_TYPE = 0,
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700293 READ_TYPE,
294 UNKNOWN_TYPE,
295};
296
K. Y. Srinivasan16046322012-01-12 12:37:57 -0800297/*
298 * SRB status codes and masks; a subset of the codes used here.
299 */
300
301#define SRB_STATUS_AUTOSENSE_VALID 0x80
302#define SRB_STATUS_INVALID_LUN 0x20
303#define SRB_STATUS_SUCCESS 0x01
K. Y. Srinivasan67812092013-02-21 12:04:53 -0800304#define SRB_STATUS_ABORTED 0x02
K. Y. Srinivasan16046322012-01-12 12:37:57 -0800305#define SRB_STATUS_ERROR 0x04
306
K. Y. Srinivasanaf9584b2012-01-12 12:38:08 -0800307/*
308 * This is the end of Protocol specific defines.
309 */
310
K. Y. Srinivasanaf9584b2012-01-12 12:38:08 -0800311static int storvsc_ringbuffer_size = (20 * PAGE_SIZE);
312
313module_param(storvsc_ringbuffer_size, int, S_IRUGO);
314MODULE_PARM_DESC(storvsc_ringbuffer_size, "Ring buffer size (bytes)");
315
K. Y. Srinivasan893def32013-06-04 12:05:05 -0700316/*
317 * Timeout in seconds for all devices managed by this driver.
318 */
319static int storvsc_timeout = 180;
320
K. Y. Srinivasanf3cfabc2014-07-21 16:06:01 -0700321static int msft_blist_flags = BLIST_TRY_VPD_PAGES;
322
K. Y. Srinivasanbb6a4df2013-06-04 12:05:09 -0700323#define STORVSC_MAX_IO_REQUESTS 200
K. Y. Srinivasanaf9584b2012-01-12 12:38:08 -0800324
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700325static void storvsc_on_channel_callback(void *context);
326
K. Y. Srinivasan4cd83ec2014-07-12 09:48:26 -0700327#define STORVSC_MAX_LUNS_PER_TARGET 255
328#define STORVSC_MAX_TARGETS 2
329#define STORVSC_MAX_CHANNELS 8
K. Y. Srinivasanaf9584b2012-01-12 12:38:08 -0800330
K. Y. Srinivasan4cd83ec2014-07-12 09:48:26 -0700331#define STORVSC_FC_MAX_LUNS_PER_TARGET 255
332#define STORVSC_FC_MAX_TARGETS 128
333#define STORVSC_FC_MAX_CHANNELS 8
K. Y. Srinivasanaf9584b2012-01-12 12:38:08 -0800334
K. Y. Srinivasan4cd83ec2014-07-12 09:48:26 -0700335#define STORVSC_IDE_MAX_LUNS_PER_TARGET 64
336#define STORVSC_IDE_MAX_TARGETS 1
337#define STORVSC_IDE_MAX_CHANNELS 1
K. Y. Srinivasan16046322012-01-12 12:37:57 -0800338
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800339struct storvsc_cmd_request {
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800340 struct scsi_cmnd *cmd;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700341
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800342 unsigned int bounce_sgl_count;
343 struct scatterlist *bounce_sgl;
344
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700345 struct hv_device *device;
346
347 /* Synchronize the request/response if needed */
348 struct completion wait_event;
349
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700350 struct hv_multipage_buffer data_buffer;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700351 struct vstor_packet vstor_packet;
352};
353
354
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700355/* A storvsc device is a device object that contains a vmbus channel */
356struct storvsc_device {
357 struct hv_device *device;
358
359 bool destroy;
360 bool drain_notify;
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700361 bool open_sub_channel;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700362 atomic_t num_outstanding_req;
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -0700363 struct Scsi_Host *host;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700364
365 wait_queue_head_t waiting_to_drain;
366
367 /*
368 * Each unique Port/Path/Target represents 1 channel ie scsi
369 * controller. In reality, the pathid, targetid is always 0
370 * and the port is set by us
371 */
372 unsigned int port_number;
373 unsigned char path_id;
374 unsigned char target_id;
375
376 /* Used for vsc/vsp channel reset process */
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800377 struct storvsc_cmd_request init_request;
378 struct storvsc_cmd_request reset_request;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700379};
380
K. Y. Srinivasance3e3012011-12-01 04:59:20 -0800381struct hv_host_device {
382 struct hv_device *dev;
K. Y. Srinivasanc1b3d062011-08-27 11:31:25 -0700383 unsigned int port;
384 unsigned char path;
385 unsigned char target;
386};
387
K. Y. Srinivasan12675792011-11-08 09:01:49 -0800388struct storvsc_scan_work {
389 struct work_struct work;
390 struct Scsi_Host *host;
391 uint lun;
392};
393
K. Y. Srinivasan67812092013-02-21 12:04:53 -0800394static void storvsc_device_scan(struct work_struct *work)
395{
396 struct storvsc_scan_work *wrk;
397 uint lun;
398 struct scsi_device *sdev;
399
400 wrk = container_of(work, struct storvsc_scan_work, work);
401 lun = wrk->lun;
402
403 sdev = scsi_device_lookup(wrk->host, 0, 0, lun);
404 if (!sdev)
405 goto done;
406 scsi_rescan_device(&sdev->sdev_gendev);
407 scsi_device_put(sdev);
408
409done:
410 kfree(wrk);
411}
412
K. Y. Srinivasan2a09ed32014-12-16 13:21:42 -0800413static void storvsc_host_scan(struct work_struct *work)
K. Y. Srinivasan12675792011-11-08 09:01:49 -0800414{
415 struct storvsc_scan_work *wrk;
K. Y. Srinivasan2a09ed32014-12-16 13:21:42 -0800416 struct Scsi_Host *host;
K. Y. Srinivasan12675792011-11-08 09:01:49 -0800417
418 wrk = container_of(work, struct storvsc_scan_work, work);
K. Y. Srinivasan2a09ed32014-12-16 13:21:42 -0800419 host = wrk->host;
K. Y. Srinivasan12675792011-11-08 09:01:49 -0800420
K. Y. Srinivasan2a09ed32014-12-16 13:21:42 -0800421 scsi_scan_host(host);
422
K. Y. Srinivasan12675792011-11-08 09:01:49 -0800423 kfree(wrk);
424}
425
K. Y. Srinivasanb4017312011-11-08 09:01:50 -0800426static void storvsc_remove_lun(struct work_struct *work)
427{
428 struct storvsc_scan_work *wrk;
429 struct scsi_device *sdev;
430
431 wrk = container_of(work, struct storvsc_scan_work, work);
432 if (!scsi_host_get(wrk->host))
433 goto done;
434
435 sdev = scsi_device_lookup(wrk->host, 0, 0, wrk->lun);
436
437 if (sdev) {
438 scsi_remove_device(sdev);
439 scsi_device_put(sdev);
440 }
441 scsi_host_put(wrk->host);
442
443done:
444 kfree(wrk);
445}
446
K. Y. Srinivasana8c18c52012-01-12 12:38:00 -0800447/*
K. Y. Srinivasanaf9584b2012-01-12 12:38:08 -0800448 * Major/minor macros. Minor version is in LSB, meaning that earlier flat
449 * version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1).
450 */
451
452static inline u16 storvsc_get_version(u8 major, u8 minor)
453{
454 u16 version;
455
456 version = ((major << 8) | minor);
457 return version;
458}
459
460/*
K. Y. Srinivasana8c18c52012-01-12 12:38:00 -0800461 * We can get incoming messages from the host that are not in response to
462 * messages that we have sent out. An example of this would be messages
463 * received by the guest to notify dynamic addition/removal of LUNs. To
464 * deal with potential race conditions where the driver may be in the
465 * midst of being unloaded when we might receive an unsolicited message
466 * from the host, we have implemented a mechanism to gurantee sequential
467 * consistency:
468 *
469 * 1) Once the device is marked as being destroyed, we will fail all
470 * outgoing messages.
471 * 2) We permit incoming messages when the device is being destroyed,
472 * only to properly account for messages already sent out.
473 */
474
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700475static inline struct storvsc_device *get_out_stor_device(
476 struct hv_device *device)
477{
478 struct storvsc_device *stor_device;
479
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -0700480 stor_device = hv_get_drvdata(device);
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700481
482 if (stor_device && stor_device->destroy)
483 stor_device = NULL;
484
485 return stor_device;
486}
487
488
489static inline void storvsc_wait_to_drain(struct storvsc_device *dev)
490{
491 dev->drain_notify = true;
492 wait_event(dev->waiting_to_drain,
493 atomic_read(&dev->num_outstanding_req) == 0);
494 dev->drain_notify = false;
495}
Hank Janssenbef4a342009-07-13 16:01:31 -0700496
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700497static inline struct storvsc_device *get_in_stor_device(
498 struct hv_device *device)
499{
500 struct storvsc_device *stor_device;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700501
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -0700502 stor_device = hv_get_drvdata(device);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700503
504 if (!stor_device)
505 goto get_in_err;
506
507 /*
508 * If the device is being destroyed; allow incoming
509 * traffic only to cleanup outstanding requests.
510 */
511
512 if (stor_device->destroy &&
513 (atomic_read(&stor_device->num_outstanding_req) == 0))
514 stor_device = NULL;
515
516get_in_err:
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700517 return stor_device;
518
519}
520
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800521static void destroy_bounce_buffer(struct scatterlist *sgl,
522 unsigned int sg_count)
523{
524 int i;
525 struct page *page_buf;
526
527 for (i = 0; i < sg_count; i++) {
528 page_buf = sg_page((&sgl[i]));
529 if (page_buf != NULL)
530 __free_page(page_buf);
531 }
532
533 kfree(sgl);
534}
535
536static int do_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count)
537{
538 int i;
539
540 /* No need to check */
541 if (sg_count < 2)
542 return -1;
543
544 /* We have at least 2 sg entries */
545 for (i = 0; i < sg_count; i++) {
546 if (i == 0) {
547 /* make sure 1st one does not have hole */
548 if (sgl[i].offset + sgl[i].length != PAGE_SIZE)
549 return i;
550 } else if (i == sg_count - 1) {
551 /* make sure last one does not have hole */
552 if (sgl[i].offset != 0)
553 return i;
554 } else {
555 /* make sure no hole in the middle */
556 if (sgl[i].length != PAGE_SIZE || sgl[i].offset != 0)
557 return i;
558 }
559 }
560 return -1;
561}
562
563static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl,
564 unsigned int sg_count,
565 unsigned int len,
566 int write)
567{
568 int i;
569 int num_pages;
570 struct scatterlist *bounce_sgl;
571 struct page *page_buf;
572 unsigned int buf_len = ((write == WRITE_TYPE) ? 0 : PAGE_SIZE);
573
574 num_pages = ALIGN(len, PAGE_SIZE) >> PAGE_SHIFT;
575
576 bounce_sgl = kcalloc(num_pages, sizeof(struct scatterlist), GFP_ATOMIC);
577 if (!bounce_sgl)
578 return NULL;
579
K. Y. Srinivasan9d2696e2013-02-06 05:15:28 -0800580 sg_init_table(bounce_sgl, num_pages);
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800581 for (i = 0; i < num_pages; i++) {
582 page_buf = alloc_page(GFP_ATOMIC);
583 if (!page_buf)
584 goto cleanup;
585 sg_set_page(&bounce_sgl[i], page_buf, buf_len, 0);
586 }
587
588 return bounce_sgl;
589
590cleanup:
591 destroy_bounce_buffer(bounce_sgl, num_pages);
592 return NULL;
593}
594
Linus Torvalds9f393832012-03-21 09:40:26 -0700595/* Disgusting wrapper functions */
596static inline unsigned long sg_kmap_atomic(struct scatterlist *sgl, int idx)
597{
598 void *addr = kmap_atomic(sg_page(sgl + idx));
599 return (unsigned long)addr;
600}
601
602static inline void sg_kunmap_atomic(unsigned long addr)
603{
604 kunmap_atomic((void *)addr);
605}
606
607
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800608/* Assume the original sgl has enough room */
609static unsigned int copy_from_bounce_buffer(struct scatterlist *orig_sgl,
610 struct scatterlist *bounce_sgl,
611 unsigned int orig_sgl_count,
612 unsigned int bounce_sgl_count)
613{
614 int i;
615 int j = 0;
616 unsigned long src, dest;
617 unsigned int srclen, destlen, copylen;
618 unsigned int total_copied = 0;
619 unsigned long bounce_addr = 0;
620 unsigned long dest_addr = 0;
621 unsigned long flags;
622
623 local_irq_save(flags);
624
625 for (i = 0; i < orig_sgl_count; i++) {
Linus Torvalds9f393832012-03-21 09:40:26 -0700626 dest_addr = sg_kmap_atomic(orig_sgl,i) + orig_sgl[i].offset;
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800627 dest = dest_addr;
628 destlen = orig_sgl[i].length;
629
630 if (bounce_addr == 0)
Linus Torvalds9f393832012-03-21 09:40:26 -0700631 bounce_addr = sg_kmap_atomic(bounce_sgl,j);
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800632
633 while (destlen) {
634 src = bounce_addr + bounce_sgl[j].offset;
635 srclen = bounce_sgl[j].length - bounce_sgl[j].offset;
636
637 copylen = min(srclen, destlen);
638 memcpy((void *)dest, (void *)src, copylen);
639
640 total_copied += copylen;
641 bounce_sgl[j].offset += copylen;
642 destlen -= copylen;
643 dest += copylen;
644
645 if (bounce_sgl[j].offset == bounce_sgl[j].length) {
646 /* full */
Linus Torvalds9f393832012-03-21 09:40:26 -0700647 sg_kunmap_atomic(bounce_addr);
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800648 j++;
649
650 /*
651 * It is possible that the number of elements
652 * in the bounce buffer may not be equal to
653 * the number of elements in the original
654 * scatter list. Handle this correctly.
655 */
656
657 if (j == bounce_sgl_count) {
658 /*
659 * We are done; cleanup and return.
660 */
Linus Torvalds9f393832012-03-21 09:40:26 -0700661 sg_kunmap_atomic(dest_addr - orig_sgl[i].offset);
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800662 local_irq_restore(flags);
663 return total_copied;
664 }
665
666 /* if we need to use another bounce buffer */
667 if (destlen || i != orig_sgl_count - 1)
Linus Torvalds9f393832012-03-21 09:40:26 -0700668 bounce_addr = sg_kmap_atomic(bounce_sgl,j);
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800669 } else if (destlen == 0 && i == orig_sgl_count - 1) {
670 /* unmap the last bounce that is < PAGE_SIZE */
Linus Torvalds9f393832012-03-21 09:40:26 -0700671 sg_kunmap_atomic(bounce_addr);
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800672 }
673 }
674
Linus Torvalds9f393832012-03-21 09:40:26 -0700675 sg_kunmap_atomic(dest_addr - orig_sgl[i].offset);
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800676 }
677
678 local_irq_restore(flags);
679
680 return total_copied;
681}
682
683/* Assume the bounce_sgl has enough room ie using the create_bounce_buffer() */
684static unsigned int copy_to_bounce_buffer(struct scatterlist *orig_sgl,
685 struct scatterlist *bounce_sgl,
686 unsigned int orig_sgl_count)
687{
688 int i;
689 int j = 0;
690 unsigned long src, dest;
691 unsigned int srclen, destlen, copylen;
692 unsigned int total_copied = 0;
693 unsigned long bounce_addr = 0;
694 unsigned long src_addr = 0;
695 unsigned long flags;
696
697 local_irq_save(flags);
698
699 for (i = 0; i < orig_sgl_count; i++) {
Linus Torvalds9f393832012-03-21 09:40:26 -0700700 src_addr = sg_kmap_atomic(orig_sgl,i) + orig_sgl[i].offset;
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800701 src = src_addr;
702 srclen = orig_sgl[i].length;
703
704 if (bounce_addr == 0)
Linus Torvalds9f393832012-03-21 09:40:26 -0700705 bounce_addr = sg_kmap_atomic(bounce_sgl,j);
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800706
707 while (srclen) {
708 /* assume bounce offset always == 0 */
709 dest = bounce_addr + bounce_sgl[j].length;
710 destlen = PAGE_SIZE - bounce_sgl[j].length;
711
712 copylen = min(srclen, destlen);
713 memcpy((void *)dest, (void *)src, copylen);
714
715 total_copied += copylen;
716 bounce_sgl[j].length += copylen;
717 srclen -= copylen;
718 src += copylen;
719
720 if (bounce_sgl[j].length == PAGE_SIZE) {
721 /* full..move to next entry */
Linus Torvalds9f393832012-03-21 09:40:26 -0700722 sg_kunmap_atomic(bounce_addr);
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800723 j++;
724
725 /* if we need to use another bounce buffer */
726 if (srclen || i != orig_sgl_count - 1)
Linus Torvalds9f393832012-03-21 09:40:26 -0700727 bounce_addr = sg_kmap_atomic(bounce_sgl,j);
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800728
729 } else if (srclen == 0 && i == orig_sgl_count - 1) {
730 /* unmap the last bounce that is < PAGE_SIZE */
Linus Torvalds9f393832012-03-21 09:40:26 -0700731 sg_kunmap_atomic(bounce_addr);
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800732 }
733 }
734
Linus Torvalds9f393832012-03-21 09:40:26 -0700735 sg_kunmap_atomic(src_addr - orig_sgl[i].offset);
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800736 }
737
738 local_irq_restore(flags);
739
740 return total_copied;
741}
742
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700743static void handle_sc_creation(struct vmbus_channel *new_sc)
744{
745 struct hv_device *device = new_sc->primary_channel->device_obj;
746 struct storvsc_device *stor_device;
747 struct vmstorage_channel_properties props;
748
749 stor_device = get_out_stor_device(device);
750 if (!stor_device)
751 return;
752
753 if (stor_device->open_sub_channel == false)
754 return;
755
756 memset(&props, 0, sizeof(struct vmstorage_channel_properties));
757
758 vmbus_open(new_sc,
759 storvsc_ringbuffer_size,
760 storvsc_ringbuffer_size,
761 (void *)&props,
762 sizeof(struct vmstorage_channel_properties),
763 storvsc_on_channel_callback, new_sc);
764}
765
766static void handle_multichannel_storage(struct hv_device *device, int max_chns)
767{
768 struct storvsc_device *stor_device;
769 int num_cpus = num_online_cpus();
770 int num_sc;
771 struct storvsc_cmd_request *request;
772 struct vstor_packet *vstor_packet;
773 int ret, t;
774
775 num_sc = ((max_chns > num_cpus) ? num_cpus : max_chns);
776 stor_device = get_out_stor_device(device);
777 if (!stor_device)
778 return;
779
780 request = &stor_device->init_request;
781 vstor_packet = &request->vstor_packet;
782
783 stor_device->open_sub_channel = true;
784 /*
785 * Establish a handler for dealing with subchannels.
786 */
787 vmbus_set_sc_create_callback(device->channel, handle_sc_creation);
788
789 /*
790 * Check to see if sub-channels have already been created. This
791 * can happen when this driver is re-loaded after unloading.
792 */
793
794 if (vmbus_are_subchannels_present(device->channel))
795 return;
796
797 stor_device->open_sub_channel = false;
798 /*
799 * Request the host to create sub-channels.
800 */
801 memset(request, 0, sizeof(struct storvsc_cmd_request));
802 init_completion(&request->wait_event);
803 vstor_packet->operation = VSTOR_OPERATION_CREATE_SUB_CHANNELS;
804 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
805 vstor_packet->sub_channel_count = num_sc;
806
807 ret = vmbus_sendpacket(device->channel, vstor_packet,
808 (sizeof(struct vstor_packet) -
809 vmscsi_size_delta),
810 (unsigned long)request,
811 VM_PKT_DATA_INBAND,
812 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
813
814 if (ret != 0)
815 return;
816
817 t = wait_for_completion_timeout(&request->wait_event, 10*HZ);
818 if (t == 0)
819 return;
820
821 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
822 vstor_packet->status != 0)
823 return;
824
825 /*
826 * Now that we created the sub-channels, invoke the check; this
827 * may trigger the callback.
828 */
829 stor_device->open_sub_channel = true;
830 vmbus_are_subchannels_present(device->channel);
831}
832
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700833static int storvsc_channel_init(struct hv_device *device)
834{
835 struct storvsc_device *stor_device;
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800836 struct storvsc_cmd_request *request;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700837 struct vstor_packet *vstor_packet;
838 int ret, t;
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700839 int max_chns;
840 bool process_sub_channels = false;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700841
842 stor_device = get_out_stor_device(device);
843 if (!stor_device)
844 return -ENODEV;
845
846 request = &stor_device->init_request;
847 vstor_packet = &request->vstor_packet;
848
849 /*
850 * Now, initiate the vsc/vsp initialization protocol on the open
851 * channel
852 */
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -0800853 memset(request, 0, sizeof(struct storvsc_cmd_request));
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700854 init_completion(&request->wait_event);
855 vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION;
856 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
857
858 ret = vmbus_sendpacket(device->channel, vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700859 (sizeof(struct vstor_packet) -
860 vmscsi_size_delta),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700861 (unsigned long)request,
862 VM_PKT_DATA_INBAND,
863 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
864 if (ret != 0)
865 goto cleanup;
866
867 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
868 if (t == 0) {
869 ret = -ETIMEDOUT;
870 goto cleanup;
871 }
872
873 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
874 vstor_packet->status != 0)
875 goto cleanup;
876
877
878 /* reuse the packet for version range supported */
879 memset(vstor_packet, 0, sizeof(struct vstor_packet));
880 vstor_packet->operation = VSTOR_OPERATION_QUERY_PROTOCOL_VERSION;
881 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
882
K. Y. Srinivasan85904a52012-01-12 12:38:04 -0800883 vstor_packet->version.major_minor =
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700884 storvsc_get_version(vmstor_current_major, vmstor_current_minor);
K. Y. Srinivasan85904a52012-01-12 12:38:04 -0800885
886 /*
887 * The revision number is only used in Windows; set it to 0.
888 */
K. Y. Srinivasanc6491142012-01-12 12:38:03 -0800889 vstor_packet->version.revision = 0;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700890
891 ret = vmbus_sendpacket(device->channel, vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700892 (sizeof(struct vstor_packet) -
893 vmscsi_size_delta),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700894 (unsigned long)request,
895 VM_PKT_DATA_INBAND,
896 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
897 if (ret != 0)
898 goto cleanup;
899
900 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
901 if (t == 0) {
902 ret = -ETIMEDOUT;
903 goto cleanup;
904 }
905
906 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
907 vstor_packet->status != 0)
908 goto cleanup;
909
910
911 memset(vstor_packet, 0, sizeof(struct vstor_packet));
912 vstor_packet->operation = VSTOR_OPERATION_QUERY_PROPERTIES;
913 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700914
915 ret = vmbus_sendpacket(device->channel, vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700916 (sizeof(struct vstor_packet) -
917 vmscsi_size_delta),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700918 (unsigned long)request,
919 VM_PKT_DATA_INBAND,
920 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
921
922 if (ret != 0)
923 goto cleanup;
924
925 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
926 if (t == 0) {
927 ret = -ETIMEDOUT;
928 goto cleanup;
929 }
930
931 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
932 vstor_packet->status != 0)
933 goto cleanup;
934
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700935 /*
936 * Check to see if multi-channel support is there.
937 * Hosts that implement protocol version of 5.1 and above
938 * support multi-channel.
939 */
940 max_chns = vstor_packet->storage_channel_properties.max_channel_cnt;
941 if ((vmbus_proto_version != VERSION_WIN7) &&
942 (vmbus_proto_version != VERSION_WS2008)) {
943 if (vstor_packet->storage_channel_properties.flags &
944 STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL)
945 process_sub_channels = true;
946 }
947
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700948 memset(vstor_packet, 0, sizeof(struct vstor_packet));
949 vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION;
950 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
951
952 ret = vmbus_sendpacket(device->channel, vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -0700953 (sizeof(struct vstor_packet) -
954 vmscsi_size_delta),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700955 (unsigned long)request,
956 VM_PKT_DATA_INBAND,
957 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
958
959 if (ret != 0)
960 goto cleanup;
961
962 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
963 if (t == 0) {
964 ret = -ETIMEDOUT;
965 goto cleanup;
966 }
967
968 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
969 vstor_packet->status != 0)
970 goto cleanup;
971
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -0700972 if (process_sub_channels)
973 handle_multichannel_storage(device, max_chns);
974
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700975
976cleanup:
977 return ret;
978}
979
K. Y. Srinivasanc50bd442013-02-21 12:04:52 -0800980static void storvsc_handle_error(struct vmscsi_request *vm_srb,
981 struct scsi_cmnd *scmnd,
982 struct Scsi_Host *host,
983 u8 asc, u8 ascq)
984{
985 struct storvsc_scan_work *wrk;
986 void (*process_err_fn)(struct work_struct *work);
987 bool do_work = false;
988
989 switch (vm_srb->srb_status) {
990 case SRB_STATUS_ERROR:
991 /*
992 * If there is an error; offline the device since all
993 * error recovery strategies would have already been
994 * deployed on the host side. However, if the command
995 * were a pass-through command deal with it appropriately.
996 */
997 switch (scmnd->cmnd[0]) {
998 case ATA_16:
999 case ATA_12:
1000 set_host_byte(scmnd, DID_PASSTHROUGH);
1001 break;
K. Y. Srinivasan3533f8602014-07-12 09:48:32 -07001002 /*
1003 * On Some Windows hosts TEST_UNIT_READY command can return
1004 * SRB_STATUS_ERROR, let the upper level code deal with it
1005 * based on the sense information.
1006 */
1007 case TEST_UNIT_READY:
1008 break;
K. Y. Srinivasanc50bd442013-02-21 12:04:52 -08001009 default:
1010 set_host_byte(scmnd, DID_TARGET_FAILURE);
1011 }
1012 break;
1013 case SRB_STATUS_INVALID_LUN:
1014 do_work = true;
1015 process_err_fn = storvsc_remove_lun;
1016 break;
K. Y. Srinivasan67812092013-02-21 12:04:53 -08001017 case (SRB_STATUS_ABORTED | SRB_STATUS_AUTOSENSE_VALID):
1018 if ((asc == 0x2a) && (ascq == 0x9)) {
1019 do_work = true;
1020 process_err_fn = storvsc_device_scan;
1021 /*
1022 * Retry the I/O that trigerred this.
1023 */
1024 set_host_byte(scmnd, DID_REQUEUE);
1025 }
1026 break;
K. Y. Srinivasanc50bd442013-02-21 12:04:52 -08001027 }
K. Y. Srinivasan67812092013-02-21 12:04:53 -08001028
K. Y. Srinivasanc50bd442013-02-21 12:04:52 -08001029 if (!do_work)
1030 return;
1031
1032 /*
1033 * We need to schedule work to process this error; schedule it.
1034 */
1035 wrk = kmalloc(sizeof(struct storvsc_scan_work), GFP_ATOMIC);
1036 if (!wrk) {
1037 set_host_byte(scmnd, DID_TARGET_FAILURE);
1038 return;
1039 }
1040
1041 wrk->host = host;
1042 wrk->lun = vm_srb->lun;
1043 INIT_WORK(&wrk->work, process_err_fn);
1044 schedule_work(&wrk->work);
1045}
1046
K. Y. Srinivasan27073882012-01-12 12:38:01 -08001047
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001048static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request)
K. Y. Srinivasan27073882012-01-12 12:38:01 -08001049{
K. Y. Srinivasan27073882012-01-12 12:38:01 -08001050 struct scsi_cmnd *scmnd = cmd_request->cmd;
1051 struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
K. Y. Srinivasan27073882012-01-12 12:38:01 -08001052 struct scsi_sense_hdr sense_hdr;
1053 struct vmscsi_request *vm_srb;
K. Y. Srinivasanc50bd442013-02-21 12:04:52 -08001054 struct Scsi_Host *host;
1055 struct storvsc_device *stor_dev;
1056 struct hv_device *dev = host_dev->dev;
1057
1058 stor_dev = get_in_stor_device(dev);
1059 host = stor_dev->host;
K. Y. Srinivasan27073882012-01-12 12:38:01 -08001060
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001061 vm_srb = &cmd_request->vstor_packet.vm_srb;
K. Y. Srinivasan27073882012-01-12 12:38:01 -08001062 if (cmd_request->bounce_sgl_count) {
1063 if (vm_srb->data_in == READ_TYPE)
1064 copy_from_bounce_buffer(scsi_sglist(scmnd),
1065 cmd_request->bounce_sgl,
1066 scsi_sg_count(scmnd),
1067 cmd_request->bounce_sgl_count);
1068 destroy_bounce_buffer(cmd_request->bounce_sgl,
1069 cmd_request->bounce_sgl_count);
1070 }
1071
K. Y. Srinivasan42e22ca2012-04-05 12:26:52 -07001072 scmnd->result = vm_srb->scsi_status;
1073
K. Y. Srinivasan27073882012-01-12 12:38:01 -08001074 if (scmnd->result) {
1075 if (scsi_normalize_sense(scmnd->sense_buffer,
1076 SCSI_SENSE_BUFFERSIZE, &sense_hdr))
Hannes Reinecked811b842014-10-24 14:26:45 +02001077 scsi_print_sense_hdr(scmnd->device, "storvsc",
1078 &sense_hdr);
K. Y. Srinivasan27073882012-01-12 12:38:01 -08001079 }
1080
K. Y. Srinivasanc50bd442013-02-21 12:04:52 -08001081 if (vm_srb->srb_status != SRB_STATUS_SUCCESS)
1082 storvsc_handle_error(vm_srb, scmnd, host, sense_hdr.asc,
1083 sense_hdr.ascq);
1084
K. Y. Srinivasan27073882012-01-12 12:38:01 -08001085 scsi_set_resid(scmnd,
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001086 cmd_request->data_buffer.len -
K. Y. Srinivasan27073882012-01-12 12:38:01 -08001087 vm_srb->data_transfer_length);
1088
Christoph Hellwigead37002014-12-29 20:05:09 -08001089 scmnd->scsi_done(scmnd);
K. Y. Srinivasan27073882012-01-12 12:38:01 -08001090}
1091
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001092static void storvsc_on_io_completion(struct hv_device *device,
1093 struct vstor_packet *vstor_packet,
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001094 struct storvsc_cmd_request *request)
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001095{
1096 struct storvsc_device *stor_device;
1097 struct vstor_packet *stor_pkt;
1098
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -07001099 stor_device = hv_get_drvdata(device);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001100 stor_pkt = &request->vstor_packet;
1101
K. Y. Srinivasan4ed51a22011-08-27 11:31:26 -07001102 /*
1103 * The current SCSI handling on the host side does
1104 * not correctly handle:
1105 * INQUIRY command with page code parameter set to 0x80
1106 * MODE_SENSE command with cmd[2] == 0x1c
1107 *
1108 * Setup srb and scsi status so this won't be fatal.
1109 * We do this so we can distinguish truly fatal failues
1110 * (srb status == 0x4) and off-line the device in that case.
1111 */
1112
1113 if ((stor_pkt->vm_srb.cdb[0] == INQUIRY) ||
K. Y. Srinivasana8c18c52012-01-12 12:38:00 -08001114 (stor_pkt->vm_srb.cdb[0] == MODE_SENSE)) {
K. Y. Srinivasan4ed51a22011-08-27 11:31:26 -07001115 vstor_packet->vm_srb.scsi_status = 0;
K. Y. Srinivasan16046322012-01-12 12:37:57 -08001116 vstor_packet->vm_srb.srb_status = SRB_STATUS_SUCCESS;
K. Y. Srinivasan4ed51a22011-08-27 11:31:26 -07001117 }
1118
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001119
1120 /* Copy over the status...etc */
1121 stor_pkt->vm_srb.scsi_status = vstor_packet->vm_srb.scsi_status;
1122 stor_pkt->vm_srb.srb_status = vstor_packet->vm_srb.srb_status;
1123 stor_pkt->vm_srb.sense_info_length =
1124 vstor_packet->vm_srb.sense_info_length;
1125
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001126
1127 if ((vstor_packet->vm_srb.scsi_status & 0xFF) == 0x02) {
1128 /* CHECK_CONDITION */
K. Y. Srinivasan16046322012-01-12 12:37:57 -08001129 if (vstor_packet->vm_srb.srb_status &
1130 SRB_STATUS_AUTOSENSE_VALID) {
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001131 /* autosense data available */
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001132
Christoph Hellwigead37002014-12-29 20:05:09 -08001133 memcpy(request->cmd->sense_buffer,
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001134 vstor_packet->vm_srb.sense_data,
1135 vstor_packet->vm_srb.sense_info_length);
1136
1137 }
1138 }
1139
1140 stor_pkt->vm_srb.data_transfer_length =
1141 vstor_packet->vm_srb.data_transfer_length;
1142
K. Y. Srinivasan27073882012-01-12 12:38:01 -08001143 storvsc_command_completion(request);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001144
1145 if (atomic_dec_and_test(&stor_device->num_outstanding_req) &&
1146 stor_device->drain_notify)
1147 wake_up(&stor_device->waiting_to_drain);
1148
1149
1150}
1151
1152static void storvsc_on_receive(struct hv_device *device,
1153 struct vstor_packet *vstor_packet,
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001154 struct storvsc_cmd_request *request)
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001155{
K. Y. Srinivasan12675792011-11-08 09:01:49 -08001156 struct storvsc_scan_work *work;
1157 struct storvsc_device *stor_device;
1158
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001159 switch (vstor_packet->operation) {
1160 case VSTOR_OPERATION_COMPLETE_IO:
1161 storvsc_on_io_completion(device, vstor_packet, request);
1162 break;
K. Y. Srinivasan12675792011-11-08 09:01:49 -08001163
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001164 case VSTOR_OPERATION_REMOVE_DEVICE:
K. Y. Srinivasan12675792011-11-08 09:01:49 -08001165 case VSTOR_OPERATION_ENUMERATE_BUS:
1166 stor_device = get_in_stor_device(device);
1167 work = kmalloc(sizeof(struct storvsc_scan_work), GFP_ATOMIC);
1168 if (!work)
1169 return;
1170
K. Y. Srinivasan2a09ed32014-12-16 13:21:42 -08001171 INIT_WORK(&work->work, storvsc_host_scan);
K. Y. Srinivasan12675792011-11-08 09:01:49 -08001172 work->host = stor_device->host;
1173 schedule_work(&work->work);
1174 break;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001175
1176 default:
1177 break;
1178 }
1179}
1180
1181static void storvsc_on_channel_callback(void *context)
1182{
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001183 struct vmbus_channel *channel = (struct vmbus_channel *)context;
1184 struct hv_device *device;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001185 struct storvsc_device *stor_device;
1186 u32 bytes_recvd;
1187 u64 request_id;
1188 unsigned char packet[ALIGN(sizeof(struct vstor_packet), 8)];
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001189 struct storvsc_cmd_request *request;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001190 int ret;
1191
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001192 if (channel->primary_channel != NULL)
1193 device = channel->primary_channel->device_obj;
1194 else
1195 device = channel->device_obj;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001196
1197 stor_device = get_in_stor_device(device);
1198 if (!stor_device)
1199 return;
1200
1201 do {
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001202 ret = vmbus_recvpacket(channel, packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001203 ALIGN((sizeof(struct vstor_packet) -
1204 vmscsi_size_delta), 8),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001205 &bytes_recvd, &request_id);
1206 if (ret == 0 && bytes_recvd > 0) {
1207
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001208 request = (struct storvsc_cmd_request *)
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001209 (unsigned long)request_id;
1210
1211 if ((request == &stor_device->init_request) ||
1212 (request == &stor_device->reset_request)) {
1213
1214 memcpy(&request->vstor_packet, packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001215 (sizeof(struct vstor_packet) -
1216 vmscsi_size_delta));
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001217 complete(&request->wait_event);
1218 } else {
1219 storvsc_on_receive(device,
1220 (struct vstor_packet *)packet,
1221 request);
1222 }
1223 } else {
1224 break;
1225 }
1226 } while (1);
1227
1228 return;
1229}
1230
1231static int storvsc_connect_to_vsp(struct hv_device *device, u32 ring_size)
1232{
1233 struct vmstorage_channel_properties props;
1234 int ret;
1235
1236 memset(&props, 0, sizeof(struct vmstorage_channel_properties));
1237
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001238 ret = vmbus_open(device->channel,
1239 ring_size,
1240 ring_size,
1241 (void *)&props,
1242 sizeof(struct vmstorage_channel_properties),
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001243 storvsc_on_channel_callback, device->channel);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001244
1245 if (ret != 0)
1246 return ret;
1247
1248 ret = storvsc_channel_init(device);
1249
1250 return ret;
1251}
1252
K. Y. Srinivasanc1b3d062011-08-27 11:31:25 -07001253static int storvsc_dev_remove(struct hv_device *device)
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001254{
1255 struct storvsc_device *stor_device;
1256 unsigned long flags;
1257
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -07001258 stor_device = hv_get_drvdata(device);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001259
1260 spin_lock_irqsave(&device->channel->inbound_lock, flags);
1261 stor_device->destroy = true;
1262 spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
1263
1264 /*
1265 * At this point, all outbound traffic should be disable. We
1266 * only allow inbound traffic (responses) to proceed so that
1267 * outstanding requests can be completed.
1268 */
1269
1270 storvsc_wait_to_drain(stor_device);
1271
1272 /*
1273 * Since we have already drained, we don't need to busy wait
1274 * as was done in final_release_stor_device()
1275 * Note that we cannot set the ext pointer to NULL until
1276 * we have drained - to drain the outgoing packets, we need to
1277 * allow incoming packets.
1278 */
1279 spin_lock_irqsave(&device->channel->inbound_lock, flags);
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -07001280 hv_set_drvdata(device, NULL);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001281 spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
1282
1283 /* Close the channel */
1284 vmbus_close(device->channel);
1285
1286 kfree(stor_device);
1287 return 0;
1288}
1289
K. Y. Srinivasanc1b3d062011-08-27 11:31:25 -07001290static int storvsc_do_io(struct hv_device *device,
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001291 struct storvsc_cmd_request *request)
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001292{
1293 struct storvsc_device *stor_device;
1294 struct vstor_packet *vstor_packet;
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001295 struct vmbus_channel *outgoing_channel;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001296 int ret = 0;
1297
1298 vstor_packet = &request->vstor_packet;
1299 stor_device = get_out_stor_device(device);
1300
1301 if (!stor_device)
1302 return -ENODEV;
1303
1304
1305 request->device = device;
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001306 /*
1307 * Select an an appropriate channel to send the request out.
1308 */
1309
1310 outgoing_channel = vmbus_get_outgoing_channel(device->channel);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001311
1312
1313 vstor_packet->flags |= REQUEST_COMPLETION_FLAG;
1314
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001315 vstor_packet->vm_srb.length = (sizeof(struct vmscsi_request) -
1316 vmscsi_size_delta);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001317
1318
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001319 vstor_packet->vm_srb.sense_info_length = sense_buffer_size;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001320
1321
1322 vstor_packet->vm_srb.data_transfer_length =
1323 request->data_buffer.len;
1324
1325 vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB;
1326
1327 if (request->data_buffer.len) {
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001328 ret = vmbus_sendpacket_multipagebuffer(outgoing_channel,
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001329 &request->data_buffer,
1330 vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001331 (sizeof(struct vstor_packet) -
1332 vmscsi_size_delta),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001333 (unsigned long)request);
1334 } else {
1335 ret = vmbus_sendpacket(device->channel, vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001336 (sizeof(struct vstor_packet) -
1337 vmscsi_size_delta),
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001338 (unsigned long)request,
1339 VM_PKT_DATA_INBAND,
1340 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
1341 }
1342
1343 if (ret != 0)
1344 return ret;
1345
1346 atomic_inc(&stor_device->num_outstanding_req);
1347
1348 return ret;
1349}
1350
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001351static int storvsc_device_configure(struct scsi_device *sdevice)
1352{
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001353 scsi_change_queue_depth(sdevice, STORVSC_MAX_IO_REQUESTS);
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001354
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001355 blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE);
1356
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001357 blk_queue_bounce_limit(sdevice->request_queue, BLK_BOUNCE_ANY);
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001358
K. Y. Srinivasan893def32013-06-04 12:05:05 -07001359 blk_queue_rq_timeout(sdevice->request_queue, (storvsc_timeout * HZ));
1360
Olaf Hering3e8f4f42013-02-21 12:04:51 -08001361 sdevice->no_write_same = 1;
1362
K. Y. Srinivasanf3cfabc2014-07-21 16:06:01 -07001363 /*
1364 * Add blist flags to permit the reading of the VPD pages even when
1365 * the target may claim SPC-2 compliance. MSFT targets currently
1366 * claim SPC-2 compliance while they implement post SPC-2 features.
1367 * With this patch we can correctly handle WRITE_SAME_16 issues.
1368 */
1369 sdevice->sdev_bflags |= msft_blist_flags;
1370
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001371 return 0;
1372}
1373
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001374static int storvsc_get_chs(struct scsi_device *sdev, struct block_device * bdev,
1375 sector_t capacity, int *info)
1376{
K. Y. Srinivasan5326fd52011-05-10 07:54:52 -07001377 sector_t nsect = capacity;
1378 sector_t cylinders = nsect;
1379 int heads, sectors_pt;
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001380
K. Y. Srinivasan5326fd52011-05-10 07:54:52 -07001381 /*
1382 * We are making up these values; let us keep it simple.
1383 */
1384 heads = 0xff;
1385 sectors_pt = 0x3f; /* Sectors per track */
1386 sector_div(cylinders, heads * sectors_pt);
1387 if ((sector_t)(cylinders + 1) * heads * sectors_pt < nsect)
1388 cylinders = 0xffff;
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001389
1390 info[0] = heads;
K. Y. Srinivasan5326fd52011-05-10 07:54:52 -07001391 info[1] = sectors_pt;
1392 info[2] = (int)cylinders;
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001393
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001394 return 0;
1395}
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001396
K. Y. Srinivasan4b270c82012-01-12 12:37:58 -08001397static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd)
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001398{
K. Y. Srinivasan4b270c82012-01-12 12:37:58 -08001399 struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
1400 struct hv_device *device = host_dev->dev;
1401
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001402 struct storvsc_device *stor_device;
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001403 struct storvsc_cmd_request *request;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001404 struct vstor_packet *vstor_packet;
1405 int ret, t;
1406
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001407
K. Y. Srinivasan1eaaddf2011-08-27 11:31:03 -07001408 stor_device = get_out_stor_device(device);
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001409 if (!stor_device)
K. Y. Srinivasana00e8222011-11-08 09:01:43 -08001410 return FAILED;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001411
1412 request = &stor_device->reset_request;
1413 vstor_packet = &request->vstor_packet;
1414
1415 init_completion(&request->wait_event);
1416
1417 vstor_packet->operation = VSTOR_OPERATION_RESET_BUS;
1418 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
1419 vstor_packet->vm_srb.path_id = stor_device->path_id;
1420
1421 ret = vmbus_sendpacket(device->channel, vstor_packet,
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001422 (sizeof(struct vstor_packet) -
1423 vmscsi_size_delta),
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001424 (unsigned long)&stor_device->reset_request,
1425 VM_PKT_DATA_INBAND,
1426 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
1427 if (ret != 0)
K. Y. Srinivasana00e8222011-11-08 09:01:43 -08001428 return FAILED;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001429
K. Y. Srinivasan46d2eb62011-06-16 13:16:36 -07001430 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
K. Y. Srinivasana00e8222011-11-08 09:01:43 -08001431 if (t == 0)
1432 return TIMEOUT_ERROR;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001433
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001434
1435 /*
1436 * At this point, all outstanding requests in the adapter
1437 * should have been flushed out and return to us
K. Y. Srinivasan5c1b10a2012-10-02 11:03:31 -07001438 * There is a potential race here where the host may be in
1439 * the process of responding when we return from here.
1440 * Just wait for all in-transit packets to be accounted for
1441 * before we return from here.
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001442 */
K. Y. Srinivasan5c1b10a2012-10-02 11:03:31 -07001443 storvsc_wait_to_drain(stor_device);
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001444
K. Y. Srinivasana00e8222011-11-08 09:01:43 -08001445 return SUCCESS;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001446}
1447
K. Y. Srinivasan56b26e62014-07-12 09:48:30 -07001448/*
1449 * The host guarantees to respond to each command, although I/O latencies might
1450 * be unbounded on Azure. Reset the timer unconditionally to give the host a
1451 * chance to perform EH.
1452 */
1453static enum blk_eh_timer_return storvsc_eh_timed_out(struct scsi_cmnd *scmnd)
1454{
1455 return BLK_EH_RESET_TIMER;
1456}
1457
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001458static bool storvsc_scsi_cmd_ok(struct scsi_cmnd *scmnd)
Olaf Hering92ae4eb2011-10-10 09:37:39 +02001459{
1460 bool allowed = true;
1461 u8 scsi_op = scmnd->cmnd[0];
1462
1463 switch (scsi_op) {
Olaf Hering3e8f4f42013-02-21 12:04:51 -08001464 /* the host does not handle WRITE_SAME, log accident usage */
1465 case WRITE_SAME:
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001466 /*
1467 * smartd sends this command and the host does not handle
1468 * this. So, don't send it.
1469 */
K. Y. Srinivasan41098f82011-10-14 21:31:57 -07001470 case SET_WINDOW:
K. Y. Srinivasan59e00e72011-11-08 09:01:42 -08001471 scmnd->result = ILLEGAL_REQUEST << 16;
K. Y. Srinivasan41098f82011-10-14 21:31:57 -07001472 allowed = false;
1473 break;
1474 default:
1475 break;
Olaf Hering92ae4eb2011-10-10 09:37:39 +02001476 }
1477 return allowed;
1478}
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001479
K. Y. Srinivasanbab445e2011-11-08 09:01:45 -08001480static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001481{
1482 int ret;
K. Y. Srinivasanbab445e2011-11-08 09:01:45 -08001483 struct hv_host_device *host_dev = shost_priv(host);
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001484 struct hv_device *dev = host_dev->dev;
Christoph Hellwigead37002014-12-29 20:05:09 -08001485 struct storvsc_cmd_request *cmd_request = scsi_cmd_priv(scmnd);
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001486 int i;
1487 struct scatterlist *sgl;
1488 unsigned int sg_count = 0;
1489 struct vmscsi_request *vm_srb;
1490
K. Y. Srinivasan8caf92d2014-07-12 09:48:28 -07001491 if (vmstor_current_major <= VMSTOR_WIN8_MAJOR) {
1492 /*
1493 * On legacy hosts filter unimplemented commands.
1494 * Future hosts are expected to correctly handle
1495 * unsupported commands. Furthermore, it is
1496 * possible that some of the currently
1497 * unsupported commands maybe supported in
1498 * future versions of the host.
1499 */
1500 if (!storvsc_scsi_cmd_ok(scmnd)) {
1501 scmnd->scsi_done(scmnd);
1502 return 0;
1503 }
Olaf Hering92ae4eb2011-10-10 09:37:39 +02001504 }
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001505
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001506 /* Setup the cmd request */
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001507 cmd_request->cmd = scmnd;
1508
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001509 vm_srb = &cmd_request->vstor_packet.vm_srb;
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001510 vm_srb->win8_extension.time_out_value = 60;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001511
K. Y. Srinivasanf885fb72014-07-12 09:48:31 -07001512 vm_srb->win8_extension.srb_flags |=
1513 (SRB_FLAGS_QUEUE_ACTION_ENABLE |
1514 SRB_FLAGS_DISABLE_SYNCH_TRANSFER);
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001515
1516 /* Build the SRB */
1517 switch (scmnd->sc_data_direction) {
1518 case DMA_TO_DEVICE:
1519 vm_srb->data_in = WRITE_TYPE;
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001520 vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_OUT;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001521 break;
1522 case DMA_FROM_DEVICE:
1523 vm_srb->data_in = READ_TYPE;
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001524 vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_IN;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001525 break;
1526 default:
1527 vm_srb->data_in = UNKNOWN_TYPE;
K. Y. Srinivasanf885fb72014-07-12 09:48:31 -07001528 vm_srb->win8_extension.srb_flags |= (SRB_FLAGS_DATA_IN |
1529 SRB_FLAGS_DATA_OUT);
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001530 break;
1531 }
1532
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001533
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001534 vm_srb->port_number = host_dev->port;
1535 vm_srb->path_id = scmnd->device->channel;
1536 vm_srb->target_id = scmnd->device->id;
1537 vm_srb->lun = scmnd->device->lun;
1538
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001539 vm_srb->cdb_length = scmnd->cmd_len;
1540
1541 memcpy(vm_srb->cdb, scmnd->cmnd, vm_srb->cdb_length);
1542
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001543 cmd_request->data_buffer.len = scsi_bufflen(scmnd);
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001544 if (scsi_sg_count(scmnd)) {
1545 sgl = (struct scatterlist *)scsi_sglist(scmnd);
1546 sg_count = scsi_sg_count(scmnd);
1547
1548 /* check if we need to bounce the sgl */
1549 if (do_bounce_buffer(sgl, scsi_sg_count(scmnd)) != -1) {
1550 cmd_request->bounce_sgl =
1551 create_bounce_buffer(sgl, scsi_sg_count(scmnd),
K. Y. Srinivasan6e8087a2011-12-07 07:15:52 -08001552 scsi_bufflen(scmnd),
1553 vm_srb->data_in);
Christoph Hellwigead37002014-12-29 20:05:09 -08001554 if (!cmd_request->bounce_sgl)
1555 return SCSI_MLQUEUE_HOST_BUSY;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001556
1557 cmd_request->bounce_sgl_count =
1558 ALIGN(scsi_bufflen(scmnd), PAGE_SIZE) >>
1559 PAGE_SHIFT;
1560
K. Y. Srinivasanfa23b8c2011-08-27 11:31:21 -07001561 if (vm_srb->data_in == WRITE_TYPE)
1562 copy_to_bounce_buffer(sgl,
1563 cmd_request->bounce_sgl,
1564 scsi_sg_count(scmnd));
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001565
1566 sgl = cmd_request->bounce_sgl;
1567 sg_count = cmd_request->bounce_sgl_count;
1568 }
1569
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001570 cmd_request->data_buffer.offset = sgl[0].offset;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001571
1572 for (i = 0; i < sg_count; i++)
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001573 cmd_request->data_buffer.pfn_array[i] =
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001574 page_to_pfn(sg_page((&sgl[i])));
1575
1576 } else if (scsi_sglist(scmnd)) {
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001577 cmd_request->data_buffer.offset =
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001578 virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE-1);
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001579 cmd_request->data_buffer.pfn_array[0] =
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001580 virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT;
1581 }
1582
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001583 /* Invokes the vsc to start an IO */
K. Y. Srinivasan61eaffc2012-01-12 12:38:07 -08001584 ret = storvsc_do_io(dev, cmd_request);
K. Y. Srinivasan636f0fd2011-05-10 07:54:50 -07001585
K. Y. Srinivasand2598f02011-08-25 09:48:58 -07001586 if (ret == -EAGAIN) {
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001587 /* no more space */
1588
Long Lie86fb5e82014-12-05 19:38:18 -08001589 if (cmd_request->bounce_sgl_count)
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001590 destroy_bounce_buffer(cmd_request->bounce_sgl,
K. Y. Srinivasan70691ec2011-08-27 11:31:29 -07001591 cmd_request->bounce_sgl_count);
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001592
Christoph Hellwigead37002014-12-29 20:05:09 -08001593 return SCSI_MLQUEUE_DEVICE_BUSY;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001594 }
1595
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001596 return 0;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001597}
1598
Hank Janssenbef4a342009-07-13 16:01:31 -07001599static struct scsi_host_template scsi_driver = {
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001600 .module = THIS_MODULE,
1601 .name = "storvsc_host_t",
Christoph Hellwigead37002014-12-29 20:05:09 -08001602 .cmd_size = sizeof(struct storvsc_cmd_request),
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001603 .bios_param = storvsc_get_chs,
1604 .queuecommand = storvsc_queuecommand,
1605 .eh_host_reset_handler = storvsc_host_reset_handler,
Christoph Hellwigead37002014-12-29 20:05:09 -08001606 .proc_name = "storvsc_host",
K. Y. Srinivasan56b26e62014-07-12 09:48:30 -07001607 .eh_timed_out = storvsc_eh_timed_out,
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001608 .slave_configure = storvsc_device_configure,
K. Y. Srinivasan52f96142014-07-12 09:48:27 -07001609 .cmd_per_lun = 255,
Lars Lindley0686e4f2010-03-11 23:51:23 +01001610 .can_queue = STORVSC_MAX_IO_REQUESTS*STORVSC_MAX_TARGETS,
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001611 .this_id = -1,
Bill Pemberton454f18a2009-07-27 16:47:24 -04001612 /* no use setting to 0 since ll_blk_rw reset it to 1 */
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001613 /* currently 32 */
1614 .sg_tablesize = MAX_MULTIPAGE_BUFFER_COUNT,
K. Y. Srinivasan039db522011-12-01 04:59:16 -08001615 .use_clustering = DISABLE_CLUSTERING,
Bill Pemberton454f18a2009-07-27 16:47:24 -04001616 /* Make sure we dont get a sg segment crosses a page boundary */
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001617 .dma_boundary = PAGE_SIZE-1,
Martin K. Petersen54b2b502013-10-23 06:25:40 -04001618 .no_write_same = 1,
Hank Janssenbef4a342009-07-13 16:01:31 -07001619};
1620
K. Y. Srinivasanef52a812011-09-13 10:59:39 -07001621enum {
1622 SCSI_GUID,
1623 IDE_GUID,
K. Y. Srinivasanbde6d0f2013-06-04 12:05:08 -07001624 SFC_GUID,
K. Y. Srinivasanef52a812011-09-13 10:59:39 -07001625};
1626
K. Y. Srinivasand847b5f2011-08-25 09:48:33 -07001627static const struct hv_vmbus_device_id id_table[] = {
Greg Kroah-Hartmanc45cf2d2011-08-25 11:41:33 -07001628 /* SCSI guid */
K. Y. Srinivasan35c3bc22013-01-23 17:42:43 -08001629 { HV_SCSI_GUID,
1630 .driver_data = SCSI_GUID
1631 },
K. Y. Srinivasan21e37742011-08-27 11:31:18 -07001632 /* IDE guid */
K. Y. Srinivasan35c3bc22013-01-23 17:42:43 -08001633 { HV_IDE_GUID,
1634 .driver_data = IDE_GUID
1635 },
K. Y. Srinivasanbde6d0f2013-06-04 12:05:08 -07001636 /* Fibre Channel GUID */
1637 {
1638 HV_SYNTHFC_GUID,
1639 .driver_data = SFC_GUID
1640 },
Greg Kroah-Hartmanc45cf2d2011-08-25 11:41:33 -07001641 { },
K. Y. Srinivasand847b5f2011-08-25 09:48:33 -07001642};
Hank Janssenbef4a342009-07-13 16:01:31 -07001643
K. Y. Srinivasand847b5f2011-08-25 09:48:33 -07001644MODULE_DEVICE_TABLE(vmbus, id_table);
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001645
K. Y. Srinivasan84946892011-09-13 10:59:38 -07001646static int storvsc_probe(struct hv_device *device,
1647 const struct hv_vmbus_device_id *dev_id)
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001648{
1649 int ret;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001650 struct Scsi_Host *host;
1651 struct hv_host_device *host_dev;
K. Y. Srinivasanef52a812011-09-13 10:59:39 -07001652 bool dev_is_ide = ((dev_id->driver_data == IDE_GUID) ? true : false);
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001653 int target = 0;
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001654 struct storvsc_device *stor_device;
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001655
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001656 /*
1657 * Based on the windows host we are running on,
1658 * set state to properly communicate with the host.
1659 */
1660
K. Y. Srinivasanadb6f9e2014-07-12 09:48:29 -07001661 switch (vmbus_proto_version) {
1662 case VERSION_WS2008:
1663 case VERSION_WIN7:
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001664 sense_buffer_size = PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE;
1665 vmscsi_size_delta = sizeof(struct vmscsi_win8_extension);
1666 vmstor_current_major = VMSTOR_WIN7_MAJOR;
1667 vmstor_current_minor = VMSTOR_WIN7_MINOR;
K. Y. Srinivasanadb6f9e2014-07-12 09:48:29 -07001668 break;
1669 default:
1670 sense_buffer_size = POST_WIN7_STORVSC_SENSE_BUFFER_SIZE;
1671 vmscsi_size_delta = 0;
1672 vmstor_current_major = VMSTOR_WIN8_MAJOR;
1673 vmstor_current_minor = VMSTOR_WIN8_MINOR;
1674 break;
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001675 }
1676
K. Y. Srinivasan4cd83ec2014-07-12 09:48:26 -07001677 if (dev_id->driver_data == SFC_GUID)
1678 scsi_driver.can_queue = (STORVSC_MAX_IO_REQUESTS *
1679 STORVSC_FC_MAX_TARGETS);
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001680 host = scsi_host_alloc(&scsi_driver,
1681 sizeof(struct hv_host_device));
1682 if (!host)
1683 return -ENOMEM;
1684
K. Y. Srinivasan7f33f302011-11-08 09:01:44 -08001685 host_dev = shost_priv(host);
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001686 memset(host_dev, 0, sizeof(struct hv_host_device));
1687
1688 host_dev->port = host->host_no;
1689 host_dev->dev = device;
1690
K. Y. Srinivasan4e03e692011-11-08 09:01:40 -08001691
K. Y. Srinivasana13d35a2011-09-13 10:59:46 -07001692 stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001693 if (!stor_device) {
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001694 ret = -ENOMEM;
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001695 goto err_out0;
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001696 }
1697
K. Y. Srinivasana13d35a2011-09-13 10:59:46 -07001698 stor_device->destroy = false;
K. Y. Srinivasan6f94d5d2013-06-04 12:05:07 -07001699 stor_device->open_sub_channel = false;
K. Y. Srinivasana13d35a2011-09-13 10:59:46 -07001700 init_waitqueue_head(&stor_device->waiting_to_drain);
1701 stor_device->device = device;
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -07001702 stor_device->host = host;
1703 hv_set_drvdata(device, stor_device);
K. Y. Srinivasana13d35a2011-09-13 10:59:46 -07001704
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001705 stor_device->port_number = host->host_no;
1706 ret = storvsc_connect_to_vsp(device, storvsc_ringbuffer_size);
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001707 if (ret)
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001708 goto err_out1;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001709
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001710 host_dev->path = stor_device->path_id;
1711 host_dev->target = stor_device->target_id;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001712
K. Y. Srinivasan4cd83ec2014-07-12 09:48:26 -07001713 switch (dev_id->driver_data) {
1714 case SFC_GUID:
1715 host->max_lun = STORVSC_FC_MAX_LUNS_PER_TARGET;
1716 host->max_id = STORVSC_FC_MAX_TARGETS;
1717 host->max_channel = STORVSC_FC_MAX_CHANNELS - 1;
1718 break;
1719
1720 case SCSI_GUID:
1721 host->max_lun = STORVSC_MAX_LUNS_PER_TARGET;
1722 host->max_id = STORVSC_MAX_TARGETS;
1723 host->max_channel = STORVSC_MAX_CHANNELS - 1;
1724 break;
1725
1726 default:
1727 host->max_lun = STORVSC_IDE_MAX_LUNS_PER_TARGET;
1728 host->max_id = STORVSC_IDE_MAX_TARGETS;
1729 host->max_channel = STORVSC_IDE_MAX_CHANNELS - 1;
1730 break;
1731 }
Mike Sterlingcf55f4a2011-09-06 16:10:55 -07001732 /* max cmd length */
1733 host->max_cmd_len = STORVSC_MAX_CMD_LEN;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001734
1735 /* Register the HBA and start the scsi bus scan */
1736 ret = scsi_add_host(host, &device->device);
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001737 if (ret != 0)
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001738 goto err_out2;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001739
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001740 if (!dev_is_ide) {
1741 scsi_scan_host(host);
K. Y. Srinivasan59d22952012-01-12 12:37:55 -08001742 } else {
1743 target = (device->dev_instance.b[5] << 8 |
1744 device->dev_instance.b[4]);
1745 ret = scsi_add_device(host, 0, target, 0);
1746 if (ret) {
1747 scsi_remove_host(host);
1748 goto err_out2;
1749 }
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001750 }
1751 return 0;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001752
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001753err_out2:
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001754 /*
1755 * Once we have connected with the host, we would need to
1756 * to invoke storvsc_dev_remove() to rollback this state and
1757 * this call also frees up the stor_device; hence the jump around
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001758 * err_out1 label.
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001759 */
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001760 storvsc_dev_remove(device);
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001761 goto err_out0;
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001762
1763err_out1:
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001764 kfree(stor_device);
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001765
1766err_out0:
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001767 scsi_host_put(host);
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001768 return ret;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001769}
1770
K. Y. Srinivasanddcbf652012-01-12 12:37:59 -08001771static int storvsc_remove(struct hv_device *dev)
1772{
1773 struct storvsc_device *stor_device = hv_get_drvdata(dev);
1774 struct Scsi_Host *host = stor_device->host;
1775
1776 scsi_remove_host(host);
1777 storvsc_dev_remove(dev);
1778 scsi_host_put(host);
1779
1780 return 0;
1781}
1782
K. Y. Srinivasan40bf63e2011-05-10 07:56:09 -07001783static struct hv_driver storvsc_drv = {
K. Y. Srinivasanfafb0ef2011-11-08 09:01:46 -08001784 .name = KBUILD_MODNAME,
K. Y. Srinivasand847b5f2011-08-25 09:48:33 -07001785 .id_table = id_table,
K. Y. Srinivasan40bf63e2011-05-10 07:56:09 -07001786 .probe = storvsc_probe,
1787 .remove = storvsc_remove,
K. Y. Srinivasan39ae6fa2011-05-10 07:54:46 -07001788};
K. Y. Srinivasan7bd05b92011-05-10 07:54:45 -07001789
K. Y. Srinivasand9bbae82011-06-06 15:49:27 -07001790static int __init storvsc_drv_init(void)
Hank Janssenbef4a342009-07-13 16:01:31 -07001791{
K. Y. Srinivasan01415ab32011-05-10 07:55:58 -07001792 u32 max_outstanding_req_per_channel;
1793
1794 /*
1795 * Divide the ring buffer data size (which is 1 page less
1796 * than the ring buffer size since that page is reserved for
1797 * the ring buffer indices) by the max request size (which is
1798 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
1799 */
K. Y. Srinivasan01415ab32011-05-10 07:55:58 -07001800 max_outstanding_req_per_channel =
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001801 ((storvsc_ringbuffer_size - PAGE_SIZE) /
1802 ALIGN(MAX_MULTIPAGE_BUFFER_PACKET +
K. Y. Srinivasan8b612fa2013-06-04 12:05:06 -07001803 sizeof(struct vstor_packet) + sizeof(u64) -
1804 vmscsi_size_delta,
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001805 sizeof(u64)));
Hank Janssenbef4a342009-07-13 16:01:31 -07001806
K. Y. Srinivasan01415ab32011-05-10 07:55:58 -07001807 if (max_outstanding_req_per_channel <
K. Y. Srinivasanf8feed02011-05-10 07:54:24 -07001808 STORVSC_MAX_IO_REQUESTS)
K. Y. Srinivasanb06efc12011-08-25 09:49:10 -07001809 return -EINVAL;
Hank Janssenbef4a342009-07-13 16:01:31 -07001810
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001811 return vmbus_driver_register(&storvsc_drv);
Hank Janssenbef4a342009-07-13 16:01:31 -07001812}
1813
K. Y. Srinivasanc63ba9e2011-06-06 15:49:26 -07001814static void __exit storvsc_drv_exit(void)
Hank Janssenbef4a342009-07-13 16:01:31 -07001815{
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001816 vmbus_driver_unregister(&storvsc_drv);
Hank Janssenbef4a342009-07-13 16:01:31 -07001817}
1818
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001819MODULE_LICENSE("GPL");
Stephen Hemminger3afc7cc32010-05-06 21:44:45 -07001820MODULE_DESCRIPTION("Microsoft Hyper-V virtual storage driver");
K. Y. Srinivasand9bbae82011-06-06 15:49:27 -07001821module_init(storvsc_drv_init);
K. Y. Srinivasanc63ba9e2011-06-06 15:49:26 -07001822module_exit(storvsc_drv_exit);