Staging: hv: create VMBUS_DEVICE macro and use it.
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / hv / storvsc_drv.c
1 /*
2 * 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>
20 * K. Y. Srinivasan <kys@microsoft.com>
21 */
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/module.h>
25 #include <linux/device.h>
26 #include <linux/blkdev.h>
27 #include <linux/dmi.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_cmnd.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_tcq.h>
33 #include <scsi/scsi_eh.h>
34 #include <scsi/scsi_devinfo.h>
35 #include <scsi/scsi_dbg.h>
36
37 #include "hyperv.h"
38 #include "hyperv_storage.h"
39
40 static int storvsc_ringbuffer_size = STORVSC_RING_BUFFER_SIZE;
41
42 module_param(storvsc_ringbuffer_size, int, S_IRUGO);
43 MODULE_PARM_DESC(storvsc_ringbuffer_size, "Ring buffer size (bytes)");
44
45 static const char *driver_name = "storvsc";
46
47 struct hv_host_device {
48 struct hv_device *dev;
49 struct kmem_cache *request_pool;
50 unsigned int port;
51 unsigned char path;
52 unsigned char target;
53 };
54
55 struct storvsc_cmd_request {
56 struct list_head entry;
57 struct scsi_cmnd *cmd;
58
59 unsigned int bounce_sgl_count;
60 struct scatterlist *bounce_sgl;
61
62 struct hv_storvsc_request request;
63 };
64
65
66 static int storvsc_device_alloc(struct scsi_device *sdevice)
67 {
68 /*
69 * This enables luns to be located sparsely. Otherwise, we may not
70 * discovered them.
71 */
72 sdevice->sdev_bflags |= BLIST_SPARSELUN | BLIST_LARGELUN;
73 return 0;
74 }
75
76 static int storvsc_merge_bvec(struct request_queue *q,
77 struct bvec_merge_data *bmd, struct bio_vec *bvec)
78 {
79 /* checking done by caller. */
80 return bvec->bv_len;
81 }
82
83 static int storvsc_device_configure(struct scsi_device *sdevice)
84 {
85 scsi_adjust_queue_depth(sdevice, MSG_SIMPLE_TAG,
86 STORVSC_MAX_IO_REQUESTS);
87
88 blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE);
89
90 blk_queue_merge_bvec(sdevice->request_queue, storvsc_merge_bvec);
91
92 blk_queue_bounce_limit(sdevice->request_queue, BLK_BOUNCE_ANY);
93
94 return 0;
95 }
96
97 static void destroy_bounce_buffer(struct scatterlist *sgl,
98 unsigned int sg_count)
99 {
100 int i;
101 struct page *page_buf;
102
103 for (i = 0; i < sg_count; i++) {
104 page_buf = sg_page((&sgl[i]));
105 if (page_buf != NULL)
106 __free_page(page_buf);
107 }
108
109 kfree(sgl);
110 }
111
112 static int do_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count)
113 {
114 int i;
115
116 /* No need to check */
117 if (sg_count < 2)
118 return -1;
119
120 /* We have at least 2 sg entries */
121 for (i = 0; i < sg_count; i++) {
122 if (i == 0) {
123 /* make sure 1st one does not have hole */
124 if (sgl[i].offset + sgl[i].length != PAGE_SIZE)
125 return i;
126 } else if (i == sg_count - 1) {
127 /* make sure last one does not have hole */
128 if (sgl[i].offset != 0)
129 return i;
130 } else {
131 /* make sure no hole in the middle */
132 if (sgl[i].length != PAGE_SIZE || sgl[i].offset != 0)
133 return i;
134 }
135 }
136 return -1;
137 }
138
139 static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl,
140 unsigned int sg_count,
141 unsigned int len)
142 {
143 int i;
144 int num_pages;
145 struct scatterlist *bounce_sgl;
146 struct page *page_buf;
147
148 num_pages = ALIGN(len, PAGE_SIZE) >> PAGE_SHIFT;
149
150 bounce_sgl = kcalloc(num_pages, sizeof(struct scatterlist), GFP_ATOMIC);
151 if (!bounce_sgl)
152 return NULL;
153
154 for (i = 0; i < num_pages; i++) {
155 page_buf = alloc_page(GFP_ATOMIC);
156 if (!page_buf)
157 goto cleanup;
158 sg_set_page(&bounce_sgl[i], page_buf, 0, 0);
159 }
160
161 return bounce_sgl;
162
163 cleanup:
164 destroy_bounce_buffer(bounce_sgl, num_pages);
165 return NULL;
166 }
167
168
169 /* Assume the original sgl has enough room */
170 static unsigned int copy_from_bounce_buffer(struct scatterlist *orig_sgl,
171 struct scatterlist *bounce_sgl,
172 unsigned int orig_sgl_count)
173 {
174 int i;
175 int j = 0;
176 unsigned long src, dest;
177 unsigned int srclen, destlen, copylen;
178 unsigned int total_copied = 0;
179 unsigned long bounce_addr = 0;
180 unsigned long dest_addr = 0;
181 unsigned long flags;
182
183 local_irq_save(flags);
184
185 for (i = 0; i < orig_sgl_count; i++) {
186 dest_addr = (unsigned long)kmap_atomic(sg_page((&orig_sgl[i])),
187 KM_IRQ0) + orig_sgl[i].offset;
188 dest = dest_addr;
189 destlen = orig_sgl[i].length;
190
191 if (bounce_addr == 0)
192 bounce_addr =
193 (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])),
194 KM_IRQ0);
195
196 while (destlen) {
197 src = bounce_addr + bounce_sgl[j].offset;
198 srclen = bounce_sgl[j].length - bounce_sgl[j].offset;
199
200 copylen = min(srclen, destlen);
201 memcpy((void *)dest, (void *)src, copylen);
202
203 total_copied += copylen;
204 bounce_sgl[j].offset += copylen;
205 destlen -= copylen;
206 dest += copylen;
207
208 if (bounce_sgl[j].offset == bounce_sgl[j].length) {
209 /* full */
210 kunmap_atomic((void *)bounce_addr, KM_IRQ0);
211 j++;
212
213 /* if we need to use another bounce buffer */
214 if (destlen || i != orig_sgl_count - 1)
215 bounce_addr =
216 (unsigned long)kmap_atomic(
217 sg_page((&bounce_sgl[j])), KM_IRQ0);
218 } else if (destlen == 0 && i == orig_sgl_count - 1) {
219 /* unmap the last bounce that is < PAGE_SIZE */
220 kunmap_atomic((void *)bounce_addr, KM_IRQ0);
221 }
222 }
223
224 kunmap_atomic((void *)(dest_addr - orig_sgl[i].offset),
225 KM_IRQ0);
226 }
227
228 local_irq_restore(flags);
229
230 return total_copied;
231 }
232
233
234 /* Assume the bounce_sgl has enough room ie using the create_bounce_buffer() */
235 static unsigned int copy_to_bounce_buffer(struct scatterlist *orig_sgl,
236 struct scatterlist *bounce_sgl,
237 unsigned int orig_sgl_count)
238 {
239 int i;
240 int j = 0;
241 unsigned long src, dest;
242 unsigned int srclen, destlen, copylen;
243 unsigned int total_copied = 0;
244 unsigned long bounce_addr = 0;
245 unsigned long src_addr = 0;
246 unsigned long flags;
247
248 local_irq_save(flags);
249
250 for (i = 0; i < orig_sgl_count; i++) {
251 src_addr = (unsigned long)kmap_atomic(sg_page((&orig_sgl[i])),
252 KM_IRQ0) + orig_sgl[i].offset;
253 src = src_addr;
254 srclen = orig_sgl[i].length;
255
256 if (bounce_addr == 0)
257 bounce_addr =
258 (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])),
259 KM_IRQ0);
260
261 while (srclen) {
262 /* assume bounce offset always == 0 */
263 dest = bounce_addr + bounce_sgl[j].length;
264 destlen = PAGE_SIZE - bounce_sgl[j].length;
265
266 copylen = min(srclen, destlen);
267 memcpy((void *)dest, (void *)src, copylen);
268
269 total_copied += copylen;
270 bounce_sgl[j].length += copylen;
271 srclen -= copylen;
272 src += copylen;
273
274 if (bounce_sgl[j].length == PAGE_SIZE) {
275 /* full..move to next entry */
276 kunmap_atomic((void *)bounce_addr, KM_IRQ0);
277 j++;
278
279 /* if we need to use another bounce buffer */
280 if (srclen || i != orig_sgl_count - 1)
281 bounce_addr =
282 (unsigned long)kmap_atomic(
283 sg_page((&bounce_sgl[j])), KM_IRQ0);
284
285 } else if (srclen == 0 && i == orig_sgl_count - 1) {
286 /* unmap the last bounce that is < PAGE_SIZE */
287 kunmap_atomic((void *)bounce_addr, KM_IRQ0);
288 }
289 }
290
291 kunmap_atomic((void *)(src_addr - orig_sgl[i].offset), KM_IRQ0);
292 }
293
294 local_irq_restore(flags);
295
296 return total_copied;
297 }
298
299
300 static int storvsc_remove(struct hv_device *dev)
301 {
302 struct Scsi_Host *host = dev_get_drvdata(&dev->device);
303 struct hv_host_device *host_dev =
304 (struct hv_host_device *)host->hostdata;
305
306 scsi_remove_host(host);
307
308 scsi_host_put(host);
309
310 storvsc_dev_remove(dev);
311 if (host_dev->request_pool) {
312 kmem_cache_destroy(host_dev->request_pool);
313 host_dev->request_pool = NULL;
314 }
315 return 0;
316 }
317
318
319 static int storvsc_get_chs(struct scsi_device *sdev, struct block_device * bdev,
320 sector_t capacity, int *info)
321 {
322 sector_t nsect = capacity;
323 sector_t cylinders = nsect;
324 int heads, sectors_pt;
325
326 /*
327 * We are making up these values; let us keep it simple.
328 */
329 heads = 0xff;
330 sectors_pt = 0x3f; /* Sectors per track */
331 sector_div(cylinders, heads * sectors_pt);
332 if ((sector_t)(cylinders + 1) * heads * sectors_pt < nsect)
333 cylinders = 0xffff;
334
335 info[0] = heads;
336 info[1] = sectors_pt;
337 info[2] = (int)cylinders;
338
339 return 0;
340 }
341
342 static int storvsc_host_reset(struct hv_device *device)
343 {
344 struct storvsc_device *stor_device;
345 struct hv_storvsc_request *request;
346 struct vstor_packet *vstor_packet;
347 int ret, t;
348
349
350 stor_device = get_stor_device(device);
351 if (!stor_device)
352 return -1;
353
354 request = &stor_device->reset_request;
355 vstor_packet = &request->vstor_packet;
356
357 init_completion(&request->wait_event);
358
359 vstor_packet->operation = VSTOR_OPERATION_RESET_BUS;
360 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
361 vstor_packet->vm_srb.path_id = stor_device->path_id;
362
363 ret = vmbus_sendpacket(device->channel, vstor_packet,
364 sizeof(struct vstor_packet),
365 (unsigned long)&stor_device->reset_request,
366 VM_PKT_DATA_INBAND,
367 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
368 if (ret != 0)
369 goto cleanup;
370
371 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
372 if (t == 0) {
373 ret = -ETIMEDOUT;
374 goto cleanup;
375 }
376
377
378 /*
379 * At this point, all outstanding requests in the adapter
380 * should have been flushed out and return to us
381 */
382
383 cleanup:
384 put_stor_device(device);
385 return ret;
386 }
387
388
389 /*
390 * storvsc_host_reset_handler - Reset the scsi HBA
391 */
392 static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd)
393 {
394 int ret;
395 struct hv_host_device *host_dev =
396 (struct hv_host_device *)scmnd->device->host->hostdata;
397 struct hv_device *dev = host_dev->dev;
398
399 ret = storvsc_host_reset(dev);
400 if (ret != 0)
401 return ret;
402
403 return ret;
404 }
405
406
407 /*
408 * storvsc_commmand_completion - Command completion processing
409 */
410 static void storvsc_commmand_completion(struct hv_storvsc_request *request)
411 {
412 struct storvsc_cmd_request *cmd_request =
413 (struct storvsc_cmd_request *)request->context;
414 struct scsi_cmnd *scmnd = cmd_request->cmd;
415 struct hv_host_device *host_dev =
416 (struct hv_host_device *)scmnd->device->host->hostdata;
417 void (*scsi_done_fn)(struct scsi_cmnd *);
418 struct scsi_sense_hdr sense_hdr;
419 struct vmscsi_request *vm_srb;
420
421 if (cmd_request->bounce_sgl_count) {
422
423 /* FIXME: We can optimize on writes by just skipping this */
424 copy_from_bounce_buffer(scsi_sglist(scmnd),
425 cmd_request->bounce_sgl,
426 scsi_sg_count(scmnd));
427 destroy_bounce_buffer(cmd_request->bounce_sgl,
428 cmd_request->bounce_sgl_count);
429 }
430
431 vm_srb = &request->vstor_packet.vm_srb;
432 scmnd->result = vm_srb->scsi_status;
433
434 if (scmnd->result) {
435 if (scsi_normalize_sense(scmnd->sense_buffer,
436 SCSI_SENSE_BUFFERSIZE, &sense_hdr))
437 scsi_print_sense_hdr("storvsc", &sense_hdr);
438 }
439
440 scsi_set_resid(scmnd,
441 request->data_buffer.len -
442 vm_srb->data_transfer_length);
443
444 scsi_done_fn = scmnd->scsi_done;
445
446 scmnd->host_scribble = NULL;
447 scmnd->scsi_done = NULL;
448
449 scsi_done_fn(scmnd);
450
451 kmem_cache_free(host_dev->request_pool, cmd_request);
452 }
453
454
455 /*
456 * storvsc_queuecommand - Initiate command processing
457 */
458 static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd,
459 void (*done)(struct scsi_cmnd *))
460 {
461 int ret;
462 struct hv_host_device *host_dev =
463 (struct hv_host_device *)scmnd->device->host->hostdata;
464 struct hv_device *dev = host_dev->dev;
465 struct hv_storvsc_request *request;
466 struct storvsc_cmd_request *cmd_request;
467 unsigned int request_size = 0;
468 int i;
469 struct scatterlist *sgl;
470 unsigned int sg_count = 0;
471 struct vmscsi_request *vm_srb;
472
473
474 /* If retrying, no need to prep the cmd */
475 if (scmnd->host_scribble) {
476
477 cmd_request =
478 (struct storvsc_cmd_request *)scmnd->host_scribble;
479
480 goto retry_request;
481 }
482
483 scmnd->scsi_done = done;
484
485 request_size = sizeof(struct storvsc_cmd_request);
486
487 cmd_request = kmem_cache_zalloc(host_dev->request_pool,
488 GFP_ATOMIC);
489 if (!cmd_request) {
490 scmnd->scsi_done = NULL;
491 return SCSI_MLQUEUE_DEVICE_BUSY;
492 }
493
494 /* Setup the cmd request */
495 cmd_request->bounce_sgl_count = 0;
496 cmd_request->bounce_sgl = NULL;
497 cmd_request->cmd = scmnd;
498
499 scmnd->host_scribble = (unsigned char *)cmd_request;
500
501 request = &cmd_request->request;
502 vm_srb = &request->vstor_packet.vm_srb;
503
504
505 /* Build the SRB */
506 switch (scmnd->sc_data_direction) {
507 case DMA_TO_DEVICE:
508 vm_srb->data_in = WRITE_TYPE;
509 break;
510 case DMA_FROM_DEVICE:
511 vm_srb->data_in = READ_TYPE;
512 break;
513 default:
514 vm_srb->data_in = UNKNOWN_TYPE;
515 break;
516 }
517
518 request->on_io_completion = storvsc_commmand_completion;
519 request->context = cmd_request;/* scmnd; */
520
521 vm_srb->port_number = host_dev->port;
522 vm_srb->path_id = scmnd->device->channel;
523 vm_srb->target_id = scmnd->device->id;
524 vm_srb->lun = scmnd->device->lun;
525
526 vm_srb->cdb_length = scmnd->cmd_len;
527
528 memcpy(vm_srb->cdb, scmnd->cmnd, vm_srb->cdb_length);
529
530 request->sense_buffer = scmnd->sense_buffer;
531
532
533 request->data_buffer.len = scsi_bufflen(scmnd);
534 if (scsi_sg_count(scmnd)) {
535 sgl = (struct scatterlist *)scsi_sglist(scmnd);
536 sg_count = scsi_sg_count(scmnd);
537
538 /* check if we need to bounce the sgl */
539 if (do_bounce_buffer(sgl, scsi_sg_count(scmnd)) != -1) {
540 cmd_request->bounce_sgl =
541 create_bounce_buffer(sgl, scsi_sg_count(scmnd),
542 scsi_bufflen(scmnd));
543 if (!cmd_request->bounce_sgl) {
544 scmnd->scsi_done = NULL;
545 scmnd->host_scribble = NULL;
546 kmem_cache_free(host_dev->request_pool,
547 cmd_request);
548
549 return SCSI_MLQUEUE_HOST_BUSY;
550 }
551
552 cmd_request->bounce_sgl_count =
553 ALIGN(scsi_bufflen(scmnd), PAGE_SIZE) >>
554 PAGE_SHIFT;
555
556 /*
557 * FIXME: We can optimize on reads by just skipping
558 * this
559 */
560 copy_to_bounce_buffer(sgl, cmd_request->bounce_sgl,
561 scsi_sg_count(scmnd));
562
563 sgl = cmd_request->bounce_sgl;
564 sg_count = cmd_request->bounce_sgl_count;
565 }
566
567 request->data_buffer.offset = sgl[0].offset;
568
569 for (i = 0; i < sg_count; i++)
570 request->data_buffer.pfn_array[i] =
571 page_to_pfn(sg_page((&sgl[i])));
572
573 } else if (scsi_sglist(scmnd)) {
574 request->data_buffer.offset =
575 virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE-1);
576 request->data_buffer.pfn_array[0] =
577 virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT;
578 }
579
580 retry_request:
581 /* Invokes the vsc to start an IO */
582 ret = storvsc_do_io(dev, &cmd_request->request);
583
584 if (ret == -1) {
585 /* no more space */
586
587 if (cmd_request->bounce_sgl_count) {
588 /*
589 * FIXME: We can optimize on writes by just skipping
590 * this
591 */
592 copy_from_bounce_buffer(scsi_sglist(scmnd),
593 cmd_request->bounce_sgl,
594 scsi_sg_count(scmnd));
595 destroy_bounce_buffer(cmd_request->bounce_sgl,
596 cmd_request->bounce_sgl_count);
597 }
598
599 kmem_cache_free(host_dev->request_pool, cmd_request);
600
601 scmnd->scsi_done = NULL;
602 scmnd->host_scribble = NULL;
603
604 ret = SCSI_MLQUEUE_DEVICE_BUSY;
605 }
606
607 return ret;
608 }
609
610 static DEF_SCSI_QCMD(storvsc_queuecommand)
611
612
613 /* Scsi driver */
614 static struct scsi_host_template scsi_driver = {
615 .module = THIS_MODULE,
616 .name = "storvsc_host_t",
617 .bios_param = storvsc_get_chs,
618 .queuecommand = storvsc_queuecommand,
619 .eh_host_reset_handler = storvsc_host_reset_handler,
620 .slave_alloc = storvsc_device_alloc,
621 .slave_configure = storvsc_device_configure,
622 .cmd_per_lun = 1,
623 /* 64 max_queue * 1 target */
624 .can_queue = STORVSC_MAX_IO_REQUESTS*STORVSC_MAX_TARGETS,
625 .this_id = -1,
626 /* no use setting to 0 since ll_blk_rw reset it to 1 */
627 /* currently 32 */
628 .sg_tablesize = MAX_MULTIPAGE_BUFFER_COUNT,
629 /*
630 * ENABLE_CLUSTERING allows mutiple physically contig bio_vecs to merge
631 * into 1 sg element. If set, we must limit the max_segment_size to
632 * PAGE_SIZE, otherwise we may get 1 sg element that represents
633 * multiple
634 */
635 /* physically contig pfns (ie sg[x].length > PAGE_SIZE). */
636 .use_clustering = ENABLE_CLUSTERING,
637 /* Make sure we dont get a sg segment crosses a page boundary */
638 .dma_boundary = PAGE_SIZE-1,
639 };
640
641 static const struct hv_vmbus_device_id id_table[] = {
642 /* SCSI guid */
643 { VMBUS_DEVICE(0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d,
644 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f) },
645 { },
646 };
647
648 MODULE_DEVICE_TABLE(vmbus, id_table);
649 /*
650 * storvsc_probe - Add a new device for this driver
651 */
652
653 static int storvsc_probe(struct hv_device *device)
654 {
655 int ret;
656 struct Scsi_Host *host;
657 struct hv_host_device *host_dev;
658 struct storvsc_device_info device_info;
659
660 host = scsi_host_alloc(&scsi_driver,
661 sizeof(struct hv_host_device));
662 if (!host)
663 return -ENOMEM;
664
665 dev_set_drvdata(&device->device, host);
666
667 host_dev = (struct hv_host_device *)host->hostdata;
668 memset(host_dev, 0, sizeof(struct hv_host_device));
669
670 host_dev->port = host->host_no;
671 host_dev->dev = device;
672
673 host_dev->request_pool =
674 kmem_cache_create(dev_name(&device->device),
675 sizeof(struct storvsc_cmd_request), 0,
676 SLAB_HWCACHE_ALIGN, NULL);
677
678 if (!host_dev->request_pool) {
679 scsi_host_put(host);
680 return -ENOMEM;
681 }
682
683 device_info.port_number = host->host_no;
684 device_info.ring_buffer_size = storvsc_ringbuffer_size;
685 /* Call to the vsc driver to add the device */
686 ret = storvsc_dev_add(device, (void *)&device_info);
687
688 if (ret != 0) {
689 kmem_cache_destroy(host_dev->request_pool);
690 scsi_host_put(host);
691 return -1;
692 }
693
694 host_dev->path = device_info.path_id;
695 host_dev->target = device_info.target_id;
696
697 /* max # of devices per target */
698 host->max_lun = STORVSC_MAX_LUNS_PER_TARGET;
699 /* max # of targets per channel */
700 host->max_id = STORVSC_MAX_TARGETS;
701 /* max # of channels */
702 host->max_channel = STORVSC_MAX_CHANNELS - 1;
703
704 /* Register the HBA and start the scsi bus scan */
705 ret = scsi_add_host(host, &device->device);
706 if (ret != 0) {
707
708 storvsc_dev_remove(device);
709
710 kmem_cache_destroy(host_dev->request_pool);
711 scsi_host_put(host);
712 return -1;
713 }
714
715 scsi_scan_host(host);
716 return ret;
717 }
718
719 /* The one and only one */
720
721 static struct hv_driver storvsc_drv = {
722 .id_table = id_table,
723 .probe = storvsc_probe,
724 .remove = storvsc_remove,
725 };
726
727 /*
728 * We use a DMI table to determine if we should autoload this driver This is
729 * needed by distro tools to determine if the hyperv drivers should be
730 * installed and/or configured. We don't do anything else with the table, but
731 * it needs to be present.
732 */
733
734 static const struct dmi_system_id __initconst
735 hv_stor_dmi_table[] __maybe_unused = {
736 {
737 .ident = "Hyper-V",
738 .matches = {
739 DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
740 DMI_MATCH(DMI_PRODUCT_NAME, "Virtual Machine"),
741 DMI_MATCH(DMI_BOARD_NAME, "Virtual Machine"),
742 },
743 },
744 { },
745 };
746 MODULE_DEVICE_TABLE(dmi, hv_stor_dmi_table);
747
748 static int __init storvsc_drv_init(void)
749 {
750 int ret;
751 struct hv_driver *drv = &storvsc_drv;
752 u32 max_outstanding_req_per_channel;
753
754 /*
755 * Divide the ring buffer data size (which is 1 page less
756 * than the ring buffer size since that page is reserved for
757 * the ring buffer indices) by the max request size (which is
758 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
759 */
760
761 max_outstanding_req_per_channel =
762 ((storvsc_ringbuffer_size - PAGE_SIZE) /
763 ALIGN(MAX_MULTIPAGE_BUFFER_PACKET +
764 sizeof(struct vstor_packet) + sizeof(u64),
765 sizeof(u64)));
766
767 if (max_outstanding_req_per_channel <
768 STORVSC_MAX_IO_REQUESTS)
769 return -1;
770
771 drv->driver.name = driver_name;
772
773
774 /* The driver belongs to vmbus */
775 ret = vmbus_child_driver_register(&drv->driver);
776
777 return ret;
778 }
779
780 static void __exit storvsc_drv_exit(void)
781 {
782 vmbus_child_driver_unregister(&storvsc_drv.driver);
783 }
784
785 MODULE_LICENSE("GPL");
786 MODULE_VERSION(HV_DRV_VERSION);
787 MODULE_DESCRIPTION("Microsoft Hyper-V virtual storage driver");
788 module_init(storvsc_drv_init);
789 module_exit(storvsc_drv_exit);