blob: 7c9fa19c9e553f0e9ba23d27c11af69558cc80e5 [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. Srinivasan4e03e692011-11-08 09:01:40 -080035#include <linux/mempool.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. Srinivasanf0d79fe2011-08-27 11:31:24 -070045
K. Y. Srinivasan4e03e692011-11-08 09:01:40 -080046#define STORVSC_MIN_BUF_NR 64
K. Y. Srinivasanc1b3d062011-08-27 11:31:25 -070047#define STORVSC_RING_BUFFER_SIZE (20*PAGE_SIZE)
48static int storvsc_ringbuffer_size = STORVSC_RING_BUFFER_SIZE;
49
50module_param(storvsc_ringbuffer_size, int, S_IRUGO);
51MODULE_PARM_DESC(storvsc_ringbuffer_size, "Ring buffer size (bytes)");
52
K. Y. Srinivasan09f03552012-01-12 12:37:54 -080053/*
54 * To alert the user that structure sizes may be mismatched even though the
55 * protocol versions match.
56 */
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -070057
58
59#define REVISION_STRING(REVISION_) #REVISION_
60#define FILL_VMSTOR_REVISION(RESULT_LVALUE_) \
61 do { \
62 char *revision_string \
63 = REVISION_STRING($Rev : 6 $) + 6; \
64 RESULT_LVALUE_ = 0; \
65 while (*revision_string >= '0' \
66 && *revision_string <= '9') { \
67 RESULT_LVALUE_ *= 10; \
68 RESULT_LVALUE_ += *revision_string - '0'; \
69 revision_string++; \
70 } \
71 } while (0)
72
K. Y. Srinivasan09f03552012-01-12 12:37:54 -080073/*
74 * Major/minor macros. Minor version is in LSB, meaning that earlier flat
75 * version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1).
76 */
77
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -070078#define VMSTOR_PROTOCOL_MAJOR(VERSION_) (((VERSION_) >> 8) & 0xff)
79#define VMSTOR_PROTOCOL_MINOR(VERSION_) (((VERSION_)) & 0xff)
80#define VMSTOR_PROTOCOL_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \
81 (((MINOR_) & 0xff)))
82#define VMSTOR_INVALID_PROTOCOL_VERSION (-1)
83
K. Y. Srinivasan09f03552012-01-12 12:37:54 -080084/*
85 * Version history:
86 * V1 Beta: 0.1
87 * V1 RC < 2008/1/31: 1.0
88 * V1 RC > 2008/1/31: 2.0
89 * Win7: 4.2
90 */
91
K. Y. Srinivasan2b9525f2011-11-08 09:01:48 -080092#define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(4, 2)
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -070093
94
95
96
K. Y. Srinivasan09f03552012-01-12 12:37:54 -080097/*
98 * This will get replaced with the max transfer length that is possible on
99 * the host adapter.
100 * The max transfer length will be published when we offer a vmbus channel.
101 */
102
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700103#define MAX_TRANSFER_LENGTH 0x40000
104#define DEFAULT_PACKET_SIZE (sizeof(struct vmdata_gpa_direct) + \
105 sizeof(struct vstor_packet) + \
106 sizesizeof(u64) * (MAX_TRANSFER_LENGTH / PAGE_SIZE)))
107
108
109/* Packet structure describing virtual storage requests. */
110enum vstor_packet_operation {
111 VSTOR_OPERATION_COMPLETE_IO = 1,
112 VSTOR_OPERATION_REMOVE_DEVICE = 2,
113 VSTOR_OPERATION_EXECUTE_SRB = 3,
114 VSTOR_OPERATION_RESET_LUN = 4,
115 VSTOR_OPERATION_RESET_ADAPTER = 5,
116 VSTOR_OPERATION_RESET_BUS = 6,
117 VSTOR_OPERATION_BEGIN_INITIALIZATION = 7,
118 VSTOR_OPERATION_END_INITIALIZATION = 8,
119 VSTOR_OPERATION_QUERY_PROTOCOL_VERSION = 9,
120 VSTOR_OPERATION_QUERY_PROPERTIES = 10,
K. Y. Srinivasan2b9525f2011-11-08 09:01:48 -0800121 VSTOR_OPERATION_ENUMERATE_BUS = 11,
122 VSTOR_OPERATION_MAXIMUM = 11
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700123};
124
125/*
126 * Platform neutral description of a scsi request -
127 * this remains the same across the write regardless of 32/64 bit
128 * note: it's patterned off the SCSI_PASS_THROUGH structure
129 */
130#define CDB16GENERIC_LENGTH 0x10
131
132#ifndef SENSE_BUFFER_SIZE
133#define SENSE_BUFFER_SIZE 0x12
134#endif
135
136#define MAX_DATA_BUF_LEN_WITH_PADDING 0x14
137
138struct vmscsi_request {
139 unsigned short length;
140 unsigned char srb_status;
141 unsigned char scsi_status;
142
143 unsigned char port_number;
144 unsigned char path_id;
145 unsigned char target_id;
146 unsigned char lun;
147
148 unsigned char cdb_length;
149 unsigned char sense_info_length;
150 unsigned char data_in;
151 unsigned char reserved;
152
153 unsigned int data_transfer_length;
154
155 union {
156 unsigned char cdb[CDB16GENERIC_LENGTH];
157 unsigned char sense_data[SENSE_BUFFER_SIZE];
158 unsigned char reserved_array[MAX_DATA_BUF_LEN_WITH_PADDING];
159 };
160} __attribute((packed));
161
162
163/*
164 * This structure is sent during the intialization phase to get the different
165 * properties of the channel.
166 */
167struct vmstorage_channel_properties {
168 unsigned short protocol_version;
169 unsigned char path_id;
170 unsigned char target_id;
171
172 /* Note: port number is only really known on the client side */
173 unsigned int port_number;
174 unsigned int flags;
175 unsigned int max_transfer_bytes;
176
177 /* This id is unique for each channel and will correspond with */
178 /* vendor specific data in the inquirydata */
179 unsigned long long unique_id;
180} __packed;
181
182/* This structure is sent during the storage protocol negotiations. */
183struct vmstorage_protocol_version {
184 /* Major (MSW) and minor (LSW) version numbers. */
185 unsigned short major_minor;
186
187 /*
188 * Revision number is auto-incremented whenever this file is changed
189 * (See FILL_VMSTOR_REVISION macro above). Mismatch does not
190 * definitely indicate incompatibility--but it does indicate mismatched
191 * builds.
192 */
193 unsigned short revision;
194} __packed;
195
196/* Channel Property Flags */
197#define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1
198#define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2
199
200struct vstor_packet {
201 /* Requested operation type */
202 enum vstor_packet_operation operation;
203
204 /* Flags - see below for values */
205 unsigned int flags;
206
207 /* Status of the request returned from the server side. */
208 unsigned int status;
209
210 /* Data payload area */
211 union {
212 /*
213 * Structure used to forward SCSI commands from the
214 * client to the server.
215 */
216 struct vmscsi_request vm_srb;
217
218 /* Structure used to query channel properties. */
219 struct vmstorage_channel_properties storage_channel_properties;
220
221 /* Used during version negotiations. */
222 struct vmstorage_protocol_version version;
223 };
224} __packed;
225
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700226/*
K. Y. Srinivasan09f03552012-01-12 12:37:54 -0800227 * Packet Flags:
228 *
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700229 * This flag indicates that the server should send back a completion for this
230 * packet.
231 */
K. Y. Srinivasan09f03552012-01-12 12:37:54 -0800232
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700233#define REQUEST_COMPLETION_FLAG 0x1
234
235/* This is the set of flags that the vsc can set in any packets it sends */
236#define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG)
237
238
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700239
240#define STORVSC_MAX_IO_REQUESTS 128
241
242/*
243 * In Hyper-V, each port/path/target maps to 1 scsi host adapter. In
244 * reality, the path/target is not used (ie always set to 0) so our
245 * scsi host adapter essentially has 1 bus with 1 target that contains
246 * up to 256 luns.
247 */
248#define STORVSC_MAX_LUNS_PER_TARGET 64
249#define STORVSC_MAX_TARGETS 1
250#define STORVSC_MAX_CHANNELS 1
Mike Sterlingcf55f4a2011-09-06 16:10:55 -0700251#define STORVSC_MAX_CMD_LEN 16
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700252
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700253/* Matches Windows-end */
254enum storvsc_request_type {
255 WRITE_TYPE,
256 READ_TYPE,
257 UNKNOWN_TYPE,
258};
259
K. Y. Srinivasan16046322012-01-12 12:37:57 -0800260/*
261 * SRB status codes and masks; a subset of the codes used here.
262 */
263
264#define SRB_STATUS_AUTOSENSE_VALID 0x80
265#define SRB_STATUS_INVALID_LUN 0x20
266#define SRB_STATUS_SUCCESS 0x01
267#define SRB_STATUS_ERROR 0x04
268
269
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700270
271struct hv_storvsc_request {
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700272 struct hv_device *device;
273
274 /* Synchronize the request/response if needed */
275 struct completion wait_event;
276
277 unsigned char *sense_buffer;
278 void *context;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700279 struct hv_multipage_buffer data_buffer;
280
281 struct vstor_packet vstor_packet;
282};
283
284
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700285/* A storvsc device is a device object that contains a vmbus channel */
286struct storvsc_device {
287 struct hv_device *device;
288
289 bool destroy;
290 bool drain_notify;
291 atomic_t num_outstanding_req;
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -0700292 struct Scsi_Host *host;
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700293
294 wait_queue_head_t waiting_to_drain;
295
296 /*
297 * Each unique Port/Path/Target represents 1 channel ie scsi
298 * controller. In reality, the pathid, targetid is always 0
299 * and the port is set by us
300 */
301 unsigned int port_number;
302 unsigned char path_id;
303 unsigned char target_id;
304
305 /* Used for vsc/vsp channel reset process */
306 struct hv_storvsc_request init_request;
307 struct hv_storvsc_request reset_request;
308};
309
K. Y. Srinivasance3e3012011-12-01 04:59:20 -0800310struct stor_mem_pools {
K. Y. Srinivasanc1b3d062011-08-27 11:31:25 -0700311 struct kmem_cache *request_pool;
K. Y. Srinivasan4e03e692011-11-08 09:01:40 -0800312 mempool_t *request_mempool;
K. Y. Srinivasance3e3012011-12-01 04:59:20 -0800313};
314
315struct hv_host_device {
316 struct hv_device *dev;
K. Y. Srinivasanc1b3d062011-08-27 11:31:25 -0700317 unsigned int port;
318 unsigned char path;
319 unsigned char target;
320};
321
322struct storvsc_cmd_request {
323 struct list_head entry;
324 struct scsi_cmnd *cmd;
325
326 unsigned int bounce_sgl_count;
327 struct scatterlist *bounce_sgl;
328
329 struct hv_storvsc_request request;
330};
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700331
K. Y. Srinivasan12675792011-11-08 09:01:49 -0800332struct storvsc_scan_work {
333 struct work_struct work;
334 struct Scsi_Host *host;
335 uint lun;
336};
337
338static void storvsc_bus_scan(struct work_struct *work)
339{
340 struct storvsc_scan_work *wrk;
341 int id, order_id;
342
343 wrk = container_of(work, struct storvsc_scan_work, work);
344 for (id = 0; id < wrk->host->max_id; ++id) {
345 if (wrk->host->reverse_ordering)
346 order_id = wrk->host->max_id - id - 1;
347 else
348 order_id = id;
349
350 scsi_scan_target(&wrk->host->shost_gendev, 0,
351 order_id, SCAN_WILD_CARD, 1);
352 }
353 kfree(wrk);
354}
355
K. Y. Srinivasanb4017312011-11-08 09:01:50 -0800356static void storvsc_remove_lun(struct work_struct *work)
357{
358 struct storvsc_scan_work *wrk;
359 struct scsi_device *sdev;
360
361 wrk = container_of(work, struct storvsc_scan_work, work);
362 if (!scsi_host_get(wrk->host))
363 goto done;
364
365 sdev = scsi_device_lookup(wrk->host, 0, 0, wrk->lun);
366
367 if (sdev) {
368 scsi_remove_device(sdev);
369 scsi_device_put(sdev);
370 }
371 scsi_host_put(wrk->host);
372
373done:
374 kfree(wrk);
375}
376
K. Y. Srinivasana8c18c52012-01-12 12:38:00 -0800377/*
378 * We can get incoming messages from the host that are not in response to
379 * messages that we have sent out. An example of this would be messages
380 * received by the guest to notify dynamic addition/removal of LUNs. To
381 * deal with potential race conditions where the driver may be in the
382 * midst of being unloaded when we might receive an unsolicited message
383 * from the host, we have implemented a mechanism to gurantee sequential
384 * consistency:
385 *
386 * 1) Once the device is marked as being destroyed, we will fail all
387 * outgoing messages.
388 * 2) We permit incoming messages when the device is being destroyed,
389 * only to properly account for messages already sent out.
390 */
391
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700392static inline struct storvsc_device *get_out_stor_device(
393 struct hv_device *device)
394{
395 struct storvsc_device *stor_device;
396
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -0700397 stor_device = hv_get_drvdata(device);
K. Y. Srinivasanf0d79fe2011-08-27 11:31:24 -0700398
399 if (stor_device && stor_device->destroy)
400 stor_device = NULL;
401
402 return stor_device;
403}
404
405
406static inline void storvsc_wait_to_drain(struct storvsc_device *dev)
407{
408 dev->drain_notify = true;
409 wait_event(dev->waiting_to_drain,
410 atomic_read(&dev->num_outstanding_req) == 0);
411 dev->drain_notify = false;
412}
Hank Janssenbef4a342009-07-13 16:01:31 -0700413
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700414static inline struct storvsc_device *get_in_stor_device(
415 struct hv_device *device)
416{
417 struct storvsc_device *stor_device;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700418
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -0700419 stor_device = hv_get_drvdata(device);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700420
421 if (!stor_device)
422 goto get_in_err;
423
424 /*
425 * If the device is being destroyed; allow incoming
426 * traffic only to cleanup outstanding requests.
427 */
428
429 if (stor_device->destroy &&
430 (atomic_read(&stor_device->num_outstanding_req) == 0))
431 stor_device = NULL;
432
433get_in_err:
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700434 return stor_device;
435
436}
437
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800438static void destroy_bounce_buffer(struct scatterlist *sgl,
439 unsigned int sg_count)
440{
441 int i;
442 struct page *page_buf;
443
444 for (i = 0; i < sg_count; i++) {
445 page_buf = sg_page((&sgl[i]));
446 if (page_buf != NULL)
447 __free_page(page_buf);
448 }
449
450 kfree(sgl);
451}
452
453static int do_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count)
454{
455 int i;
456
457 /* No need to check */
458 if (sg_count < 2)
459 return -1;
460
461 /* We have at least 2 sg entries */
462 for (i = 0; i < sg_count; i++) {
463 if (i == 0) {
464 /* make sure 1st one does not have hole */
465 if (sgl[i].offset + sgl[i].length != PAGE_SIZE)
466 return i;
467 } else if (i == sg_count - 1) {
468 /* make sure last one does not have hole */
469 if (sgl[i].offset != 0)
470 return i;
471 } else {
472 /* make sure no hole in the middle */
473 if (sgl[i].length != PAGE_SIZE || sgl[i].offset != 0)
474 return i;
475 }
476 }
477 return -1;
478}
479
480static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl,
481 unsigned int sg_count,
482 unsigned int len,
483 int write)
484{
485 int i;
486 int num_pages;
487 struct scatterlist *bounce_sgl;
488 struct page *page_buf;
489 unsigned int buf_len = ((write == WRITE_TYPE) ? 0 : PAGE_SIZE);
490
491 num_pages = ALIGN(len, PAGE_SIZE) >> PAGE_SHIFT;
492
493 bounce_sgl = kcalloc(num_pages, sizeof(struct scatterlist), GFP_ATOMIC);
494 if (!bounce_sgl)
495 return NULL;
496
497 for (i = 0; i < num_pages; i++) {
498 page_buf = alloc_page(GFP_ATOMIC);
499 if (!page_buf)
500 goto cleanup;
501 sg_set_page(&bounce_sgl[i], page_buf, buf_len, 0);
502 }
503
504 return bounce_sgl;
505
506cleanup:
507 destroy_bounce_buffer(bounce_sgl, num_pages);
508 return NULL;
509}
510
511/* Assume the original sgl has enough room */
512static unsigned int copy_from_bounce_buffer(struct scatterlist *orig_sgl,
513 struct scatterlist *bounce_sgl,
514 unsigned int orig_sgl_count,
515 unsigned int bounce_sgl_count)
516{
517 int i;
518 int j = 0;
519 unsigned long src, dest;
520 unsigned int srclen, destlen, copylen;
521 unsigned int total_copied = 0;
522 unsigned long bounce_addr = 0;
523 unsigned long dest_addr = 0;
524 unsigned long flags;
525
526 local_irq_save(flags);
527
528 for (i = 0; i < orig_sgl_count; i++) {
529 dest_addr = (unsigned long)kmap_atomic(sg_page((&orig_sgl[i])),
530 KM_IRQ0) + orig_sgl[i].offset;
531 dest = dest_addr;
532 destlen = orig_sgl[i].length;
533
534 if (bounce_addr == 0)
535 bounce_addr =
536 (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])),
537 KM_IRQ0);
538
539 while (destlen) {
540 src = bounce_addr + bounce_sgl[j].offset;
541 srclen = bounce_sgl[j].length - bounce_sgl[j].offset;
542
543 copylen = min(srclen, destlen);
544 memcpy((void *)dest, (void *)src, copylen);
545
546 total_copied += copylen;
547 bounce_sgl[j].offset += copylen;
548 destlen -= copylen;
549 dest += copylen;
550
551 if (bounce_sgl[j].offset == bounce_sgl[j].length) {
552 /* full */
553 kunmap_atomic((void *)bounce_addr, KM_IRQ0);
554 j++;
555
556 /*
557 * It is possible that the number of elements
558 * in the bounce buffer may not be equal to
559 * the number of elements in the original
560 * scatter list. Handle this correctly.
561 */
562
563 if (j == bounce_sgl_count) {
564 /*
565 * We are done; cleanup and return.
566 */
567 kunmap_atomic((void *)(dest_addr -
568 orig_sgl[i].offset),
569 KM_IRQ0);
570 local_irq_restore(flags);
571 return total_copied;
572 }
573
574 /* if we need to use another bounce buffer */
575 if (destlen || i != orig_sgl_count - 1)
576 bounce_addr =
577 (unsigned long)kmap_atomic(
578 sg_page((&bounce_sgl[j])), KM_IRQ0);
579 } else if (destlen == 0 && i == orig_sgl_count - 1) {
580 /* unmap the last bounce that is < PAGE_SIZE */
581 kunmap_atomic((void *)bounce_addr, KM_IRQ0);
582 }
583 }
584
585 kunmap_atomic((void *)(dest_addr - orig_sgl[i].offset),
586 KM_IRQ0);
587 }
588
589 local_irq_restore(flags);
590
591 return total_copied;
592}
593
594/* Assume the bounce_sgl has enough room ie using the create_bounce_buffer() */
595static unsigned int copy_to_bounce_buffer(struct scatterlist *orig_sgl,
596 struct scatterlist *bounce_sgl,
597 unsigned int orig_sgl_count)
598{
599 int i;
600 int j = 0;
601 unsigned long src, dest;
602 unsigned int srclen, destlen, copylen;
603 unsigned int total_copied = 0;
604 unsigned long bounce_addr = 0;
605 unsigned long src_addr = 0;
606 unsigned long flags;
607
608 local_irq_save(flags);
609
610 for (i = 0; i < orig_sgl_count; i++) {
611 src_addr = (unsigned long)kmap_atomic(sg_page((&orig_sgl[i])),
612 KM_IRQ0) + orig_sgl[i].offset;
613 src = src_addr;
614 srclen = orig_sgl[i].length;
615
616 if (bounce_addr == 0)
617 bounce_addr =
618 (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])),
619 KM_IRQ0);
620
621 while (srclen) {
622 /* assume bounce offset always == 0 */
623 dest = bounce_addr + bounce_sgl[j].length;
624 destlen = PAGE_SIZE - bounce_sgl[j].length;
625
626 copylen = min(srclen, destlen);
627 memcpy((void *)dest, (void *)src, copylen);
628
629 total_copied += copylen;
630 bounce_sgl[j].length += copylen;
631 srclen -= copylen;
632 src += copylen;
633
634 if (bounce_sgl[j].length == PAGE_SIZE) {
635 /* full..move to next entry */
636 kunmap_atomic((void *)bounce_addr, KM_IRQ0);
637 j++;
638
639 /* if we need to use another bounce buffer */
640 if (srclen || i != orig_sgl_count - 1)
641 bounce_addr =
642 (unsigned long)kmap_atomic(
643 sg_page((&bounce_sgl[j])), KM_IRQ0);
644
645 } else if (srclen == 0 && i == orig_sgl_count - 1) {
646 /* unmap the last bounce that is < PAGE_SIZE */
647 kunmap_atomic((void *)bounce_addr, KM_IRQ0);
648 }
649 }
650
651 kunmap_atomic((void *)(src_addr - orig_sgl[i].offset), KM_IRQ0);
652 }
653
654 local_irq_restore(flags);
655
656 return total_copied;
657}
658
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700659static int storvsc_channel_init(struct hv_device *device)
660{
661 struct storvsc_device *stor_device;
662 struct hv_storvsc_request *request;
663 struct vstor_packet *vstor_packet;
664 int ret, t;
665
666 stor_device = get_out_stor_device(device);
667 if (!stor_device)
668 return -ENODEV;
669
670 request = &stor_device->init_request;
671 vstor_packet = &request->vstor_packet;
672
673 /*
674 * Now, initiate the vsc/vsp initialization protocol on the open
675 * channel
676 */
677 memset(request, 0, sizeof(struct hv_storvsc_request));
678 init_completion(&request->wait_event);
679 vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION;
680 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
681
682 ret = vmbus_sendpacket(device->channel, vstor_packet,
683 sizeof(struct vstor_packet),
684 (unsigned long)request,
685 VM_PKT_DATA_INBAND,
686 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
687 if (ret != 0)
688 goto cleanup;
689
690 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
691 if (t == 0) {
692 ret = -ETIMEDOUT;
693 goto cleanup;
694 }
695
696 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
697 vstor_packet->status != 0)
698 goto cleanup;
699
700
701 /* reuse the packet for version range supported */
702 memset(vstor_packet, 0, sizeof(struct vstor_packet));
703 vstor_packet->operation = VSTOR_OPERATION_QUERY_PROTOCOL_VERSION;
704 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
705
706 vstor_packet->version.major_minor = VMSTOR_PROTOCOL_VERSION_CURRENT;
707 FILL_VMSTOR_REVISION(vstor_packet->version.revision);
708
709 ret = vmbus_sendpacket(device->channel, vstor_packet,
710 sizeof(struct vstor_packet),
711 (unsigned long)request,
712 VM_PKT_DATA_INBAND,
713 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
714 if (ret != 0)
715 goto cleanup;
716
717 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
718 if (t == 0) {
719 ret = -ETIMEDOUT;
720 goto cleanup;
721 }
722
723 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
724 vstor_packet->status != 0)
725 goto cleanup;
726
727
728 memset(vstor_packet, 0, sizeof(struct vstor_packet));
729 vstor_packet->operation = VSTOR_OPERATION_QUERY_PROPERTIES;
730 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
731 vstor_packet->storage_channel_properties.port_number =
732 stor_device->port_number;
733
734 ret = vmbus_sendpacket(device->channel, vstor_packet,
735 sizeof(struct vstor_packet),
736 (unsigned long)request,
737 VM_PKT_DATA_INBAND,
738 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
739
740 if (ret != 0)
741 goto cleanup;
742
743 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
744 if (t == 0) {
745 ret = -ETIMEDOUT;
746 goto cleanup;
747 }
748
749 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
750 vstor_packet->status != 0)
751 goto cleanup;
752
753 stor_device->path_id = vstor_packet->storage_channel_properties.path_id;
754 stor_device->target_id
755 = vstor_packet->storage_channel_properties.target_id;
756
757 memset(vstor_packet, 0, sizeof(struct vstor_packet));
758 vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION;
759 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
760
761 ret = vmbus_sendpacket(device->channel, vstor_packet,
762 sizeof(struct vstor_packet),
763 (unsigned long)request,
764 VM_PKT_DATA_INBAND,
765 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
766
767 if (ret != 0)
768 goto cleanup;
769
770 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
771 if (t == 0) {
772 ret = -ETIMEDOUT;
773 goto cleanup;
774 }
775
776 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
777 vstor_packet->status != 0)
778 goto cleanup;
779
780
781cleanup:
782 return ret;
783}
784
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800785
786static void storvsc_command_completion(struct hv_storvsc_request *request)
787{
788 struct storvsc_cmd_request *cmd_request =
789 (struct storvsc_cmd_request *)request->context;
790 struct scsi_cmnd *scmnd = cmd_request->cmd;
791 struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
792 void (*scsi_done_fn)(struct scsi_cmnd *);
793 struct scsi_sense_hdr sense_hdr;
794 struct vmscsi_request *vm_srb;
795 struct storvsc_scan_work *wrk;
796 struct stor_mem_pools *memp = scmnd->device->hostdata;
797
798 vm_srb = &request->vstor_packet.vm_srb;
799 if (cmd_request->bounce_sgl_count) {
800 if (vm_srb->data_in == READ_TYPE)
801 copy_from_bounce_buffer(scsi_sglist(scmnd),
802 cmd_request->bounce_sgl,
803 scsi_sg_count(scmnd),
804 cmd_request->bounce_sgl_count);
805 destroy_bounce_buffer(cmd_request->bounce_sgl,
806 cmd_request->bounce_sgl_count);
807 }
808
809 /*
810 * If there is an error; offline the device since all
811 * error recovery strategies would have already been
812 * deployed on the host side.
813 */
814 if (vm_srb->srb_status == SRB_STATUS_ERROR)
815 scmnd->result = DID_TARGET_FAILURE << 16;
816 else
817 scmnd->result = vm_srb->scsi_status;
818
819 /*
820 * If the LUN is invalid; remove the device.
821 */
822 if (vm_srb->srb_status == SRB_STATUS_INVALID_LUN) {
823 struct storvsc_device *stor_dev;
824 struct hv_device *dev = host_dev->dev;
825 struct Scsi_Host *host;
826
827 stor_dev = get_in_stor_device(dev);
828 host = stor_dev->host;
829
830 wrk = kmalloc(sizeof(struct storvsc_scan_work),
831 GFP_ATOMIC);
832 if (!wrk) {
833 scmnd->result = DID_TARGET_FAILURE << 16;
834 } else {
835 wrk->host = host;
836 wrk->lun = vm_srb->lun;
837 INIT_WORK(&wrk->work, storvsc_remove_lun);
838 schedule_work(&wrk->work);
839 }
840 }
841
842 if (scmnd->result) {
843 if (scsi_normalize_sense(scmnd->sense_buffer,
844 SCSI_SENSE_BUFFERSIZE, &sense_hdr))
845 scsi_print_sense_hdr("storvsc", &sense_hdr);
846 }
847
848 scsi_set_resid(scmnd,
849 request->data_buffer.len -
850 vm_srb->data_transfer_length);
851
852 scsi_done_fn = scmnd->scsi_done;
853
854 scmnd->host_scribble = NULL;
855 scmnd->scsi_done = NULL;
856
857 scsi_done_fn(scmnd);
858
859 mempool_free(cmd_request, memp->request_mempool);
860}
861
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700862static void storvsc_on_io_completion(struct hv_device *device,
863 struct vstor_packet *vstor_packet,
864 struct hv_storvsc_request *request)
865{
866 struct storvsc_device *stor_device;
867 struct vstor_packet *stor_pkt;
868
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -0700869 stor_device = hv_get_drvdata(device);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700870 stor_pkt = &request->vstor_packet;
871
K. Y. Srinivasan4ed51a22011-08-27 11:31:26 -0700872 /*
873 * The current SCSI handling on the host side does
874 * not correctly handle:
875 * INQUIRY command with page code parameter set to 0x80
876 * MODE_SENSE command with cmd[2] == 0x1c
877 *
878 * Setup srb and scsi status so this won't be fatal.
879 * We do this so we can distinguish truly fatal failues
880 * (srb status == 0x4) and off-line the device in that case.
881 */
882
883 if ((stor_pkt->vm_srb.cdb[0] == INQUIRY) ||
K. Y. Srinivasana8c18c52012-01-12 12:38:00 -0800884 (stor_pkt->vm_srb.cdb[0] == MODE_SENSE)) {
K. Y. Srinivasan4ed51a22011-08-27 11:31:26 -0700885 vstor_packet->vm_srb.scsi_status = 0;
K. Y. Srinivasan16046322012-01-12 12:37:57 -0800886 vstor_packet->vm_srb.srb_status = SRB_STATUS_SUCCESS;
K. Y. Srinivasan4ed51a22011-08-27 11:31:26 -0700887 }
888
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700889
890 /* Copy over the status...etc */
891 stor_pkt->vm_srb.scsi_status = vstor_packet->vm_srb.scsi_status;
892 stor_pkt->vm_srb.srb_status = vstor_packet->vm_srb.srb_status;
893 stor_pkt->vm_srb.sense_info_length =
894 vstor_packet->vm_srb.sense_info_length;
895
896 if (vstor_packet->vm_srb.scsi_status != 0 ||
K. Y. Srinivasan16046322012-01-12 12:37:57 -0800897 vstor_packet->vm_srb.srb_status != SRB_STATUS_SUCCESS){
Greg Kroah-Hartmand181daa2011-10-11 09:20:31 -0600898 dev_warn(&device->device,
899 "cmd 0x%x scsi status 0x%x srb status 0x%x\n",
900 stor_pkt->vm_srb.cdb[0],
901 vstor_packet->vm_srb.scsi_status,
902 vstor_packet->vm_srb.srb_status);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700903 }
904
905 if ((vstor_packet->vm_srb.scsi_status & 0xFF) == 0x02) {
906 /* CHECK_CONDITION */
K. Y. Srinivasan16046322012-01-12 12:37:57 -0800907 if (vstor_packet->vm_srb.srb_status &
908 SRB_STATUS_AUTOSENSE_VALID) {
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700909 /* autosense data available */
Greg Kroah-Hartmand181daa2011-10-11 09:20:31 -0600910 dev_warn(&device->device,
K. Y. Srinivasan41098f82011-10-14 21:31:57 -0700911 "stor pkt %p autosense data valid - len %d\n",
912 request,
913 vstor_packet->vm_srb.sense_info_length);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700914
915 memcpy(request->sense_buffer,
916 vstor_packet->vm_srb.sense_data,
917 vstor_packet->vm_srb.sense_info_length);
918
919 }
920 }
921
922 stor_pkt->vm_srb.data_transfer_length =
923 vstor_packet->vm_srb.data_transfer_length;
924
K. Y. Srinivasan27073882012-01-12 12:38:01 -0800925 storvsc_command_completion(request);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700926
927 if (atomic_dec_and_test(&stor_device->num_outstanding_req) &&
928 stor_device->drain_notify)
929 wake_up(&stor_device->waiting_to_drain);
930
931
932}
933
934static void storvsc_on_receive(struct hv_device *device,
935 struct vstor_packet *vstor_packet,
936 struct hv_storvsc_request *request)
937{
K. Y. Srinivasan12675792011-11-08 09:01:49 -0800938 struct storvsc_scan_work *work;
939 struct storvsc_device *stor_device;
940
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700941 switch (vstor_packet->operation) {
942 case VSTOR_OPERATION_COMPLETE_IO:
943 storvsc_on_io_completion(device, vstor_packet, request);
944 break;
K. Y. Srinivasan12675792011-11-08 09:01:49 -0800945
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700946 case VSTOR_OPERATION_REMOVE_DEVICE:
K. Y. Srinivasan12675792011-11-08 09:01:49 -0800947 case VSTOR_OPERATION_ENUMERATE_BUS:
948 stor_device = get_in_stor_device(device);
949 work = kmalloc(sizeof(struct storvsc_scan_work), GFP_ATOMIC);
950 if (!work)
951 return;
952
953 INIT_WORK(&work->work, storvsc_bus_scan);
954 work->host = stor_device->host;
955 schedule_work(&work->work);
956 break;
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -0700957
958 default:
959 break;
960 }
961}
962
963static void storvsc_on_channel_callback(void *context)
964{
965 struct hv_device *device = (struct hv_device *)context;
966 struct storvsc_device *stor_device;
967 u32 bytes_recvd;
968 u64 request_id;
969 unsigned char packet[ALIGN(sizeof(struct vstor_packet), 8)];
970 struct hv_storvsc_request *request;
971 int ret;
972
973
974 stor_device = get_in_stor_device(device);
975 if (!stor_device)
976 return;
977
978 do {
979 ret = vmbus_recvpacket(device->channel, packet,
980 ALIGN(sizeof(struct vstor_packet), 8),
981 &bytes_recvd, &request_id);
982 if (ret == 0 && bytes_recvd > 0) {
983
984 request = (struct hv_storvsc_request *)
985 (unsigned long)request_id;
986
987 if ((request == &stor_device->init_request) ||
988 (request == &stor_device->reset_request)) {
989
990 memcpy(&request->vstor_packet, packet,
991 sizeof(struct vstor_packet));
992 complete(&request->wait_event);
993 } else {
994 storvsc_on_receive(device,
995 (struct vstor_packet *)packet,
996 request);
997 }
998 } else {
999 break;
1000 }
1001 } while (1);
1002
1003 return;
1004}
1005
1006static int storvsc_connect_to_vsp(struct hv_device *device, u32 ring_size)
1007{
1008 struct vmstorage_channel_properties props;
1009 int ret;
1010
1011 memset(&props, 0, sizeof(struct vmstorage_channel_properties));
1012
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001013 ret = vmbus_open(device->channel,
1014 ring_size,
1015 ring_size,
1016 (void *)&props,
1017 sizeof(struct vmstorage_channel_properties),
1018 storvsc_on_channel_callback, device);
1019
1020 if (ret != 0)
1021 return ret;
1022
1023 ret = storvsc_channel_init(device);
1024
1025 return ret;
1026}
1027
K. Y. Srinivasanc1b3d062011-08-27 11:31:25 -07001028static int storvsc_dev_remove(struct hv_device *device)
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001029{
1030 struct storvsc_device *stor_device;
1031 unsigned long flags;
1032
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -07001033 stor_device = hv_get_drvdata(device);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001034
1035 spin_lock_irqsave(&device->channel->inbound_lock, flags);
1036 stor_device->destroy = true;
1037 spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
1038
1039 /*
1040 * At this point, all outbound traffic should be disable. We
1041 * only allow inbound traffic (responses) to proceed so that
1042 * outstanding requests can be completed.
1043 */
1044
1045 storvsc_wait_to_drain(stor_device);
1046
1047 /*
1048 * Since we have already drained, we don't need to busy wait
1049 * as was done in final_release_stor_device()
1050 * Note that we cannot set the ext pointer to NULL until
1051 * we have drained - to drain the outgoing packets, we need to
1052 * allow incoming packets.
1053 */
1054 spin_lock_irqsave(&device->channel->inbound_lock, flags);
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -07001055 hv_set_drvdata(device, NULL);
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001056 spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
1057
1058 /* Close the channel */
1059 vmbus_close(device->channel);
1060
1061 kfree(stor_device);
1062 return 0;
1063}
1064
K. Y. Srinivasanc1b3d062011-08-27 11:31:25 -07001065static int storvsc_do_io(struct hv_device *device,
K. Y. Srinivasan8dcf37d2011-08-27 11:31:22 -07001066 struct hv_storvsc_request *request)
1067{
1068 struct storvsc_device *stor_device;
1069 struct vstor_packet *vstor_packet;
1070 int ret = 0;
1071
1072 vstor_packet = &request->vstor_packet;
1073 stor_device = get_out_stor_device(device);
1074
1075 if (!stor_device)
1076 return -ENODEV;
1077
1078
1079 request->device = device;
1080
1081
1082 vstor_packet->flags |= REQUEST_COMPLETION_FLAG;
1083
1084 vstor_packet->vm_srb.length = sizeof(struct vmscsi_request);
1085
1086
1087 vstor_packet->vm_srb.sense_info_length = SENSE_BUFFER_SIZE;
1088
1089
1090 vstor_packet->vm_srb.data_transfer_length =
1091 request->data_buffer.len;
1092
1093 vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB;
1094
1095 if (request->data_buffer.len) {
1096 ret = vmbus_sendpacket_multipagebuffer(device->channel,
1097 &request->data_buffer,
1098 vstor_packet,
1099 sizeof(struct vstor_packet),
1100 (unsigned long)request);
1101 } else {
1102 ret = vmbus_sendpacket(device->channel, vstor_packet,
1103 sizeof(struct vstor_packet),
1104 (unsigned long)request,
1105 VM_PKT_DATA_INBAND,
1106 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
1107 }
1108
1109 if (ret != 0)
1110 return ret;
1111
1112 atomic_inc(&stor_device->num_outstanding_req);
1113
1114 return ret;
1115}
1116
K. Y. Srinivasan5b60ace2011-05-10 07:54:25 -07001117static int storvsc_device_alloc(struct scsi_device *sdevice)
1118{
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001119 struct stor_mem_pools *memp;
1120 int number = STORVSC_MIN_BUF_NR;
1121
1122 memp = kzalloc(sizeof(struct stor_mem_pools), GFP_KERNEL);
1123 if (!memp)
1124 return -ENOMEM;
1125
1126 memp->request_pool =
1127 kmem_cache_create(dev_name(&sdevice->sdev_dev),
1128 sizeof(struct storvsc_cmd_request), 0,
1129 SLAB_HWCACHE_ALIGN, NULL);
1130
1131 if (!memp->request_pool)
1132 goto err0;
1133
1134 memp->request_mempool = mempool_create(number, mempool_alloc_slab,
1135 mempool_free_slab,
1136 memp->request_pool);
1137
1138 if (!memp->request_mempool)
1139 goto err1;
1140
1141 sdevice->hostdata = memp;
1142
K. Y. Srinivasan5b60ace2011-05-10 07:54:25 -07001143 return 0;
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001144
1145err1:
1146 kmem_cache_destroy(memp->request_pool);
1147
1148err0:
1149 kfree(memp);
1150 return -ENOMEM;
1151}
1152
1153static void storvsc_device_destroy(struct scsi_device *sdevice)
1154{
1155 struct stor_mem_pools *memp = sdevice->hostdata;
1156
1157 mempool_destroy(memp->request_mempool);
1158 kmem_cache_destroy(memp->request_pool);
1159 kfree(memp);
1160 sdevice->hostdata = NULL;
K. Y. Srinivasan5b60ace2011-05-10 07:54:25 -07001161}
1162
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001163static int storvsc_device_configure(struct scsi_device *sdevice)
1164{
1165 scsi_adjust_queue_depth(sdevice, MSG_SIMPLE_TAG,
1166 STORVSC_MAX_IO_REQUESTS);
1167
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001168 blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE);
1169
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001170 blk_queue_bounce_limit(sdevice->request_queue, BLK_BOUNCE_ANY);
K. Y. Srinivasan419f2d02011-05-10 07:54:27 -07001171
1172 return 0;
1173}
1174
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001175static int storvsc_get_chs(struct scsi_device *sdev, struct block_device * bdev,
1176 sector_t capacity, int *info)
1177{
K. Y. Srinivasan5326fd52011-05-10 07:54:52 -07001178 sector_t nsect = capacity;
1179 sector_t cylinders = nsect;
1180 int heads, sectors_pt;
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001181
K. Y. Srinivasan5326fd52011-05-10 07:54:52 -07001182 /*
1183 * We are making up these values; let us keep it simple.
1184 */
1185 heads = 0xff;
1186 sectors_pt = 0x3f; /* Sectors per track */
1187 sector_div(cylinders, heads * sectors_pt);
1188 if ((sector_t)(cylinders + 1) * heads * sectors_pt < nsect)
1189 cylinders = 0xffff;
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001190
1191 info[0] = heads;
K. Y. Srinivasan5326fd52011-05-10 07:54:52 -07001192 info[1] = sectors_pt;
1193 info[2] = (int)cylinders;
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001194
K. Y. Srinivasan62838ce2011-05-10 07:54:34 -07001195 return 0;
1196}
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001197
K. Y. Srinivasan4b270c82012-01-12 12:37:58 -08001198static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd)
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001199{
K. Y. Srinivasan4b270c82012-01-12 12:37:58 -08001200 struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
1201 struct hv_device *device = host_dev->dev;
1202
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001203 struct storvsc_device *stor_device;
1204 struct hv_storvsc_request *request;
1205 struct vstor_packet *vstor_packet;
1206 int ret, t;
1207
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001208
K. Y. Srinivasan1eaaddf2011-08-27 11:31:03 -07001209 stor_device = get_out_stor_device(device);
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001210 if (!stor_device)
K. Y. Srinivasana00e8222011-11-08 09:01:43 -08001211 return FAILED;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001212
1213 request = &stor_device->reset_request;
1214 vstor_packet = &request->vstor_packet;
1215
1216 init_completion(&request->wait_event);
1217
1218 vstor_packet->operation = VSTOR_OPERATION_RESET_BUS;
1219 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
1220 vstor_packet->vm_srb.path_id = stor_device->path_id;
1221
1222 ret = vmbus_sendpacket(device->channel, vstor_packet,
1223 sizeof(struct vstor_packet),
1224 (unsigned long)&stor_device->reset_request,
1225 VM_PKT_DATA_INBAND,
1226 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
1227 if (ret != 0)
K. Y. Srinivasana00e8222011-11-08 09:01:43 -08001228 return FAILED;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001229
K. Y. Srinivasan46d2eb62011-06-16 13:16:36 -07001230 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
K. Y. Srinivasana00e8222011-11-08 09:01:43 -08001231 if (t == 0)
1232 return TIMEOUT_ERROR;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001233
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001234
1235 /*
1236 * At this point, all outstanding requests in the adapter
1237 * should have been flushed out and return to us
1238 */
1239
K. Y. Srinivasana00e8222011-11-08 09:01:43 -08001240 return SUCCESS;
K. Y. Srinivasanaa3d7892011-05-10 07:54:37 -07001241}
1242
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001243static bool storvsc_scsi_cmd_ok(struct scsi_cmnd *scmnd)
Olaf Hering92ae4eb2011-10-10 09:37:39 +02001244{
1245 bool allowed = true;
1246 u8 scsi_op = scmnd->cmnd[0];
1247
1248 switch (scsi_op) {
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001249 /*
1250 * smartd sends this command and the host does not handle
1251 * this. So, don't send it.
1252 */
K. Y. Srinivasan41098f82011-10-14 21:31:57 -07001253 case SET_WINDOW:
K. Y. Srinivasan59e00e72011-11-08 09:01:42 -08001254 scmnd->result = ILLEGAL_REQUEST << 16;
K. Y. Srinivasan41098f82011-10-14 21:31:57 -07001255 allowed = false;
1256 break;
1257 default:
1258 break;
Olaf Hering92ae4eb2011-10-10 09:37:39 +02001259 }
1260 return allowed;
1261}
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001262
K. Y. Srinivasanbab445e2011-11-08 09:01:45 -08001263static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001264{
1265 int ret;
K. Y. Srinivasanbab445e2011-11-08 09:01:45 -08001266 struct hv_host_device *host_dev = shost_priv(host);
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001267 struct hv_device *dev = host_dev->dev;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001268 struct hv_storvsc_request *request;
1269 struct storvsc_cmd_request *cmd_request;
1270 unsigned int request_size = 0;
1271 int i;
1272 struct scatterlist *sgl;
1273 unsigned int sg_count = 0;
1274 struct vmscsi_request *vm_srb;
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001275 struct stor_mem_pools *memp = scmnd->device->hostdata;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001276
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001277 if (!storvsc_scsi_cmd_ok(scmnd)) {
K. Y. Srinivasanbab445e2011-11-08 09:01:45 -08001278 scmnd->scsi_done(scmnd);
Olaf Hering92ae4eb2011-10-10 09:37:39 +02001279 return 0;
1280 }
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001281
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001282 request_size = sizeof(struct storvsc_cmd_request);
1283
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001284 cmd_request = mempool_alloc(memp->request_mempool,
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001285 GFP_ATOMIC);
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001286
1287 /*
1288 * We might be invoked in an interrupt context; hence
1289 * mempool_alloc() can fail.
1290 */
K. Y. Srinivasanbab445e2011-11-08 09:01:45 -08001291 if (!cmd_request)
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001292 return SCSI_MLQUEUE_DEVICE_BUSY;
K. Y. Srinivasanbab445e2011-11-08 09:01:45 -08001293
K. Y. Srinivasan4e03e692011-11-08 09:01:40 -08001294 memset(cmd_request, 0, sizeof(struct storvsc_cmd_request));
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001295
1296 /* Setup the cmd request */
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001297 cmd_request->cmd = scmnd;
1298
1299 scmnd->host_scribble = (unsigned char *)cmd_request;
1300
1301 request = &cmd_request->request;
1302 vm_srb = &request->vstor_packet.vm_srb;
1303
1304
1305 /* Build the SRB */
1306 switch (scmnd->sc_data_direction) {
1307 case DMA_TO_DEVICE:
1308 vm_srb->data_in = WRITE_TYPE;
1309 break;
1310 case DMA_FROM_DEVICE:
1311 vm_srb->data_in = READ_TYPE;
1312 break;
1313 default:
1314 vm_srb->data_in = UNKNOWN_TYPE;
1315 break;
1316 }
1317
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001318 request->context = cmd_request;/* scmnd; */
1319
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001320 vm_srb->port_number = host_dev->port;
1321 vm_srb->path_id = scmnd->device->channel;
1322 vm_srb->target_id = scmnd->device->id;
1323 vm_srb->lun = scmnd->device->lun;
1324
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001325 vm_srb->cdb_length = scmnd->cmd_len;
1326
1327 memcpy(vm_srb->cdb, scmnd->cmnd, vm_srb->cdb_length);
1328
1329 request->sense_buffer = scmnd->sense_buffer;
1330
1331
1332 request->data_buffer.len = scsi_bufflen(scmnd);
1333 if (scsi_sg_count(scmnd)) {
1334 sgl = (struct scatterlist *)scsi_sglist(scmnd);
1335 sg_count = scsi_sg_count(scmnd);
1336
1337 /* check if we need to bounce the sgl */
1338 if (do_bounce_buffer(sgl, scsi_sg_count(scmnd)) != -1) {
1339 cmd_request->bounce_sgl =
1340 create_bounce_buffer(sgl, scsi_sg_count(scmnd),
K. Y. Srinivasan6e8087a2011-12-07 07:15:52 -08001341 scsi_bufflen(scmnd),
1342 vm_srb->data_in);
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001343 if (!cmd_request->bounce_sgl) {
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001344 ret = SCSI_MLQUEUE_HOST_BUSY;
1345 goto queue_error;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001346 }
1347
1348 cmd_request->bounce_sgl_count =
1349 ALIGN(scsi_bufflen(scmnd), PAGE_SIZE) >>
1350 PAGE_SHIFT;
1351
K. Y. Srinivasanfa23b8c2011-08-27 11:31:21 -07001352 if (vm_srb->data_in == WRITE_TYPE)
1353 copy_to_bounce_buffer(sgl,
1354 cmd_request->bounce_sgl,
1355 scsi_sg_count(scmnd));
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001356
1357 sgl = cmd_request->bounce_sgl;
1358 sg_count = cmd_request->bounce_sgl_count;
1359 }
1360
1361 request->data_buffer.offset = sgl[0].offset;
1362
1363 for (i = 0; i < sg_count; i++)
1364 request->data_buffer.pfn_array[i] =
1365 page_to_pfn(sg_page((&sgl[i])));
1366
1367 } else if (scsi_sglist(scmnd)) {
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001368 request->data_buffer.offset =
1369 virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE-1);
1370 request->data_buffer.pfn_array[0] =
1371 virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT;
1372 }
1373
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001374 /* Invokes the vsc to start an IO */
K. Y. Srinivasan636f0fd2011-05-10 07:54:50 -07001375 ret = storvsc_do_io(dev, &cmd_request->request);
1376
K. Y. Srinivasand2598f02011-08-25 09:48:58 -07001377 if (ret == -EAGAIN) {
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001378 /* no more space */
1379
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001380 if (cmd_request->bounce_sgl_count) {
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001381 destroy_bounce_buffer(cmd_request->bounce_sgl,
K. Y. Srinivasan70691ec2011-08-27 11:31:29 -07001382 cmd_request->bounce_sgl_count);
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001383
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001384 ret = SCSI_MLQUEUE_DEVICE_BUSY;
1385 goto queue_error;
1386 }
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001387 }
1388
K. Y. Srinivasanc77b63b2012-01-12 12:37:56 -08001389 return 0;
1390
1391queue_error:
1392 mempool_free(cmd_request, memp->request_mempool);
1393 scmnd->host_scribble = NULL;
K. Y. Srinivasanc5b463a2011-05-10 07:54:42 -07001394 return ret;
1395}
1396
Hank Janssenbef4a342009-07-13 16:01:31 -07001397static struct scsi_host_template scsi_driver = {
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001398 .module = THIS_MODULE,
1399 .name = "storvsc_host_t",
1400 .bios_param = storvsc_get_chs,
1401 .queuecommand = storvsc_queuecommand,
1402 .eh_host_reset_handler = storvsc_host_reset_handler,
1403 .slave_alloc = storvsc_device_alloc,
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001404 .slave_destroy = storvsc_device_destroy,
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001405 .slave_configure = storvsc_device_configure,
1406 .cmd_per_lun = 1,
1407 /* 64 max_queue * 1 target */
Lars Lindley0686e4f2010-03-11 23:51:23 +01001408 .can_queue = STORVSC_MAX_IO_REQUESTS*STORVSC_MAX_TARGETS,
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001409 .this_id = -1,
Bill Pemberton454f18a2009-07-27 16:47:24 -04001410 /* no use setting to 0 since ll_blk_rw reset it to 1 */
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001411 /* currently 32 */
1412 .sg_tablesize = MAX_MULTIPAGE_BUFFER_COUNT,
K. Y. Srinivasan039db522011-12-01 04:59:16 -08001413 .use_clustering = DISABLE_CLUSTERING,
Bill Pemberton454f18a2009-07-27 16:47:24 -04001414 /* Make sure we dont get a sg segment crosses a page boundary */
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001415 .dma_boundary = PAGE_SIZE-1,
Hank Janssenbef4a342009-07-13 16:01:31 -07001416};
1417
K. Y. Srinivasanef52a812011-09-13 10:59:39 -07001418enum {
1419 SCSI_GUID,
1420 IDE_GUID,
1421};
1422
K. Y. Srinivasand847b5f2011-08-25 09:48:33 -07001423static const struct hv_vmbus_device_id id_table[] = {
Greg Kroah-Hartmanc45cf2d2011-08-25 11:41:33 -07001424 /* SCSI guid */
1425 { VMBUS_DEVICE(0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d,
K. Y. Srinivasanef52a812011-09-13 10:59:39 -07001426 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f)
1427 .driver_data = SCSI_GUID },
K. Y. Srinivasan21e37742011-08-27 11:31:18 -07001428 /* IDE guid */
1429 { VMBUS_DEVICE(0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44,
K. Y. Srinivasanef52a812011-09-13 10:59:39 -07001430 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5)
1431 .driver_data = IDE_GUID },
Greg Kroah-Hartmanc45cf2d2011-08-25 11:41:33 -07001432 { },
K. Y. Srinivasand847b5f2011-08-25 09:48:33 -07001433};
Hank Janssenbef4a342009-07-13 16:01:31 -07001434
K. Y. Srinivasand847b5f2011-08-25 09:48:33 -07001435MODULE_DEVICE_TABLE(vmbus, id_table);
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001436
K. Y. Srinivasan84946892011-09-13 10:59:38 -07001437static int storvsc_probe(struct hv_device *device,
1438 const struct hv_vmbus_device_id *dev_id)
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001439{
1440 int ret;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001441 struct Scsi_Host *host;
1442 struct hv_host_device *host_dev;
K. Y. Srinivasanef52a812011-09-13 10:59:39 -07001443 bool dev_is_ide = ((dev_id->driver_data == IDE_GUID) ? true : false);
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001444 int target = 0;
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001445 struct storvsc_device *stor_device;
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001446
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001447 host = scsi_host_alloc(&scsi_driver,
1448 sizeof(struct hv_host_device));
1449 if (!host)
1450 return -ENOMEM;
1451
K. Y. Srinivasan7f33f302011-11-08 09:01:44 -08001452 host_dev = shost_priv(host);
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001453 memset(host_dev, 0, sizeof(struct hv_host_device));
1454
1455 host_dev->port = host->host_no;
1456 host_dev->dev = device;
1457
K. Y. Srinivasan4e03e692011-11-08 09:01:40 -08001458
K. Y. Srinivasana13d35a2011-09-13 10:59:46 -07001459 stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001460 if (!stor_device) {
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001461 ret = -ENOMEM;
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001462 goto err_out0;
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001463 }
1464
K. Y. Srinivasana13d35a2011-09-13 10:59:46 -07001465 stor_device->destroy = false;
1466 init_waitqueue_head(&stor_device->waiting_to_drain);
1467 stor_device->device = device;
K. Y. Srinivasancd654ea2011-09-13 10:59:48 -07001468 stor_device->host = host;
1469 hv_set_drvdata(device, stor_device);
K. Y. Srinivasana13d35a2011-09-13 10:59:46 -07001470
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001471 stor_device->port_number = host->host_no;
1472 ret = storvsc_connect_to_vsp(device, storvsc_ringbuffer_size);
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001473 if (ret)
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001474 goto err_out1;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001475
K. Y. Srinivasan6e4198c2011-09-13 10:59:45 -07001476 host_dev->path = stor_device->path_id;
1477 host_dev->target = stor_device->target_id;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001478
1479 /* max # of devices per target */
1480 host->max_lun = STORVSC_MAX_LUNS_PER_TARGET;
1481 /* max # of targets per channel */
1482 host->max_id = STORVSC_MAX_TARGETS;
1483 /* max # of channels */
1484 host->max_channel = STORVSC_MAX_CHANNELS - 1;
Mike Sterlingcf55f4a2011-09-06 16:10:55 -07001485 /* max cmd length */
1486 host->max_cmd_len = STORVSC_MAX_CMD_LEN;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001487
1488 /* Register the HBA and start the scsi bus scan */
1489 ret = scsi_add_host(host, &device->device);
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001490 if (ret != 0)
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001491 goto err_out2;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001492
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001493 if (!dev_is_ide) {
1494 scsi_scan_host(host);
K. Y. Srinivasan59d22952012-01-12 12:37:55 -08001495 } else {
1496 target = (device->dev_instance.b[5] << 8 |
1497 device->dev_instance.b[4]);
1498 ret = scsi_add_device(host, 0, target, 0);
1499 if (ret) {
1500 scsi_remove_host(host);
1501 goto err_out2;
1502 }
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001503 }
1504 return 0;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001505
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001506err_out2:
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001507 /*
1508 * Once we have connected with the host, we would need to
1509 * to invoke storvsc_dev_remove() to rollback this state and
1510 * this call also frees up the stor_device; hence the jump around
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001511 * err_out1 label.
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001512 */
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001513 storvsc_dev_remove(device);
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001514 goto err_out0;
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001515
1516err_out1:
K. Y. Srinivasance3e3012011-12-01 04:59:20 -08001517 kfree(stor_device);
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001518
1519err_out0:
K. Y. Srinivasanbd1f5d62011-08-27 11:31:17 -07001520 scsi_host_put(host);
K. Y. Srinivasan225ce6e2011-11-08 09:01:41 -08001521 return ret;
K. Y. Srinivasanf5c78872011-05-10 07:54:43 -07001522}
1523
K. Y. Srinivasanddcbf652012-01-12 12:37:59 -08001524static int storvsc_remove(struct hv_device *dev)
1525{
1526 struct storvsc_device *stor_device = hv_get_drvdata(dev);
1527 struct Scsi_Host *host = stor_device->host;
1528
1529 scsi_remove_host(host);
1530 storvsc_dev_remove(dev);
1531 scsi_host_put(host);
1532
1533 return 0;
1534}
1535
K. Y. Srinivasan40bf63e2011-05-10 07:56:09 -07001536static struct hv_driver storvsc_drv = {
K. Y. Srinivasanfafb0ef2011-11-08 09:01:46 -08001537 .name = KBUILD_MODNAME,
K. Y. Srinivasand847b5f2011-08-25 09:48:33 -07001538 .id_table = id_table,
K. Y. Srinivasan40bf63e2011-05-10 07:56:09 -07001539 .probe = storvsc_probe,
1540 .remove = storvsc_remove,
K. Y. Srinivasan39ae6fa2011-05-10 07:54:46 -07001541};
K. Y. Srinivasan7bd05b92011-05-10 07:54:45 -07001542
K. Y. Srinivasand9bbae82011-06-06 15:49:27 -07001543static int __init storvsc_drv_init(void)
Hank Janssenbef4a342009-07-13 16:01:31 -07001544{
K. Y. Srinivasan01415ab32011-05-10 07:55:58 -07001545 u32 max_outstanding_req_per_channel;
1546
1547 /*
1548 * Divide the ring buffer data size (which is 1 page less
1549 * than the ring buffer size since that page is reserved for
1550 * the ring buffer indices) by the max request size (which is
1551 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
1552 */
K. Y. Srinivasan01415ab32011-05-10 07:55:58 -07001553 max_outstanding_req_per_channel =
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001554 ((storvsc_ringbuffer_size - PAGE_SIZE) /
1555 ALIGN(MAX_MULTIPAGE_BUFFER_PACKET +
1556 sizeof(struct vstor_packet) + sizeof(u64),
1557 sizeof(u64)));
Hank Janssenbef4a342009-07-13 16:01:31 -07001558
K. Y. Srinivasan01415ab32011-05-10 07:55:58 -07001559 if (max_outstanding_req_per_channel <
K. Y. Srinivasanf8feed02011-05-10 07:54:24 -07001560 STORVSC_MAX_IO_REQUESTS)
K. Y. Srinivasanb06efc12011-08-25 09:49:10 -07001561 return -EINVAL;
Hank Janssenbef4a342009-07-13 16:01:31 -07001562
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001563 return vmbus_driver_register(&storvsc_drv);
Hank Janssenbef4a342009-07-13 16:01:31 -07001564}
1565
K. Y. Srinivasanc63ba9e2011-06-06 15:49:26 -07001566static void __exit storvsc_drv_exit(void)
Hank Janssenbef4a342009-07-13 16:01:31 -07001567{
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001568 vmbus_driver_unregister(&storvsc_drv);
Hank Janssenbef4a342009-07-13 16:01:31 -07001569}
1570
Greg Kroah-Hartmanff568d32009-09-02 08:37:47 -07001571MODULE_LICENSE("GPL");
Hank Janssen26c14cc2010-02-11 23:02:42 +00001572MODULE_VERSION(HV_DRV_VERSION);
Stephen Hemminger3afc7cc32010-05-06 21:44:45 -07001573MODULE_DESCRIPTION("Microsoft Hyper-V virtual storage driver");
K. Y. Srinivasand9bbae82011-06-06 15:49:27 -07001574module_init(storvsc_drv_init);
K. Y. Srinivasanc63ba9e2011-06-06 15:49:26 -07001575module_exit(storvsc_drv_exit);