2 * Copyright (c) 2009, Microsoft Corporation.
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.
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
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.
18 * Hank Janssen <hjanssen@microsoft.com>
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/device.h>
23 #include <linux/blkdev.h>
24 #include <linux/major.h>
25 #include <linux/delay.h>
26 #include <linux/hdreg.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_cmnd.h>
29 #include <scsi/scsi_eh.h>
30 #include <scsi/scsi_dbg.h>
34 #include "StorVscApi.h"
37 #define BLKVSC_MINORS 64
39 enum blkvsc_device_type
{
46 * This request ties the struct request and struct
47 * blkvsc_request/hv_storvsc_request together A struct request may be
48 * represented by 1 or more struct blkvsc_request
50 struct blkvsc_request_group
{
53 struct list_head blkvsc_req_list
; /* list of blkvsc_requests */
56 struct blkvsc_request
{
57 /* blkvsc_request_group.blkvsc_req_list */
58 struct list_head req_entry
;
60 /* block_device_context.pending_list */
61 struct list_head pend_entry
;
63 /* This may be null if we generate a request internally */
66 struct block_device_context
*dev
;
68 /* The group this request is part of. Maybe null */
69 struct blkvsc_request_group
*group
;
71 wait_queue_head_t wevent
;
75 sector_t sector_start
;
76 unsigned long sector_count
;
78 unsigned char sense_buffer
[SCSI_SENSE_BUFFERSIZE
];
79 unsigned char cmd_len
;
80 unsigned char cmnd
[MAX_COMMAND_SIZE
];
82 struct hv_storvsc_request request
;
84 * !!!DO NOT ADD ANYTHING BELOW HERE!!! Otherwise, memory can overlap,
85 * because - The extension buffer falls right here and is pointed to by
87 * Which sounds like a horrible idea, who designed this?
91 /* Per device structure */
92 struct block_device_context
{
93 /* point back to our device context */
94 struct device_context
*device_ctx
;
95 struct kmem_cache
*request_pool
;
98 enum blkvsc_device_type device_type
;
99 struct list_head pending_list
;
101 unsigned char device_id
[64];
102 unsigned int device_id_len
;
103 int num_outstanding_reqs
;
105 int media_not_present
;
106 unsigned int sector_size
;
110 unsigned char target
;
115 struct blkvsc_driver_context
{
116 /* !! These must be the first 2 fields !! */
117 /* FIXME this is a bug! */
118 struct driver_context drv_ctx
;
119 struct storvsc_driver_object drv_obj
;
123 static int blkvsc_probe(struct device
*dev
);
124 static int blkvsc_remove(struct device
*device
);
125 static void blkvsc_shutdown(struct device
*device
);
127 static int blkvsc_open(struct block_device
*bdev
, fmode_t mode
);
128 static int blkvsc_release(struct gendisk
*disk
, fmode_t mode
);
129 static int blkvsc_media_changed(struct gendisk
*gd
);
130 static int blkvsc_revalidate_disk(struct gendisk
*gd
);
131 static int blkvsc_getgeo(struct block_device
*bd
, struct hd_geometry
*hg
);
132 static int blkvsc_ioctl(struct block_device
*bd
, fmode_t mode
,
133 unsigned cmd
, unsigned long argument
);
134 static void blkvsc_request(struct request_queue
*queue
);
135 static void blkvsc_request_completion(struct hv_storvsc_request
*request
);
136 static int blkvsc_do_request(struct block_device_context
*blkdev
,
137 struct request
*req
);
138 static int blkvsc_submit_request(struct blkvsc_request
*blkvsc_req
,
139 void (*request_completion
)(struct hv_storvsc_request
*));
140 static void blkvsc_init_rw(struct blkvsc_request
*blkvsc_req
);
141 static void blkvsc_cmd_completion(struct hv_storvsc_request
*request
);
142 static int blkvsc_do_inquiry(struct block_device_context
*blkdev
);
143 static int blkvsc_do_read_capacity(struct block_device_context
*blkdev
);
144 static int blkvsc_do_read_capacity16(struct block_device_context
*blkdev
);
145 static int blkvsc_do_flush(struct block_device_context
*blkdev
);
146 static int blkvsc_cancel_pending_reqs(struct block_device_context
*blkdev
);
147 static int blkvsc_do_pending_reqs(struct block_device_context
*blkdev
);
150 static int blkvsc_ringbuffer_size
= BLKVSC_RING_BUFFER_SIZE
;
152 /* The one and only one */
153 static struct blkvsc_driver_context g_blkvsc_drv
;
155 static struct block_device_operations block_ops
= {
156 .owner
= THIS_MODULE
,
158 .release
= blkvsc_release
,
159 .media_changed
= blkvsc_media_changed
,
160 .revalidate_disk
= blkvsc_revalidate_disk
,
161 .getgeo
= blkvsc_getgeo
,
162 .ioctl
= blkvsc_ioctl
,
166 * blkvsc_drv_init - BlkVsc driver initialization.
168 static int blkvsc_drv_init(int (*drv_init
)(struct hv_driver
*drv
))
170 struct storvsc_driver_object
*storvsc_drv_obj
= &g_blkvsc_drv
.drv_obj
;
171 struct driver_context
*drv_ctx
= &g_blkvsc_drv
.drv_ctx
;
174 DPRINT_ENTER(BLKVSC_DRV
);
176 vmbus_get_interface(&storvsc_drv_obj
->Base
.VmbusChannelInterface
);
178 storvsc_drv_obj
->RingBufferSize
= blkvsc_ringbuffer_size
;
180 /* Callback to client driver to complete the initialization */
181 drv_init(&storvsc_drv_obj
->Base
);
183 drv_ctx
->driver
.name
= storvsc_drv_obj
->Base
.name
;
184 memcpy(&drv_ctx
->class_id
, &storvsc_drv_obj
->Base
.deviceType
,
185 sizeof(struct hv_guid
));
187 drv_ctx
->probe
= blkvsc_probe
;
188 drv_ctx
->remove
= blkvsc_remove
;
189 drv_ctx
->shutdown
= blkvsc_shutdown
;
191 /* The driver belongs to vmbus */
192 ret
= vmbus_child_driver_register(drv_ctx
);
194 DPRINT_EXIT(BLKVSC_DRV
);
199 static int blkvsc_drv_exit_cb(struct device
*dev
, void *data
)
201 struct device
**curr
= (struct device
**)data
;
203 return 1; /* stop iterating */
206 static void blkvsc_drv_exit(void)
208 struct storvsc_driver_object
*storvsc_drv_obj
= &g_blkvsc_drv
.drv_obj
;
209 struct driver_context
*drv_ctx
= &g_blkvsc_drv
.drv_ctx
;
210 struct device
*current_dev
;
213 DPRINT_ENTER(BLKVSC_DRV
);
219 ret
= driver_for_each_device(&drv_ctx
->driver
, NULL
,
220 (void *) ¤t_dev
,
224 DPRINT_WARN(BLKVSC_DRV
,
225 "driver_for_each_device returned %d", ret
);
228 if (current_dev
== NULL
)
231 /* Initiate removal from the top-down */
232 device_unregister(current_dev
);
235 if (storvsc_drv_obj
->Base
.OnCleanup
)
236 storvsc_drv_obj
->Base
.OnCleanup(&storvsc_drv_obj
->Base
);
238 vmbus_child_driver_unregister(drv_ctx
);
240 DPRINT_EXIT(BLKVSC_DRV
);
246 * blkvsc_probe - Add a new device for this driver
248 static int blkvsc_probe(struct device
*device
)
250 struct driver_context
*driver_ctx
=
251 driver_to_driver_context(device
->driver
);
252 struct blkvsc_driver_context
*blkvsc_drv_ctx
=
253 (struct blkvsc_driver_context
*)driver_ctx
;
254 struct storvsc_driver_object
*storvsc_drv_obj
=
255 &blkvsc_drv_ctx
->drv_obj
;
256 struct device_context
*device_ctx
= device_to_device_context(device
);
257 struct hv_device
*device_obj
= &device_ctx
->device_obj
;
259 struct block_device_context
*blkdev
= NULL
;
260 struct storvsc_device_info device_info
;
264 static int ide0_registered
;
265 static int ide1_registered
;
267 DPRINT_ENTER(BLKVSC_DRV
);
269 DPRINT_DBG(BLKVSC_DRV
, "blkvsc_probe - enter");
271 if (!storvsc_drv_obj
->Base
.OnDeviceAdd
) {
272 DPRINT_ERR(BLKVSC_DRV
, "OnDeviceAdd() not set");
277 blkdev
= kzalloc(sizeof(struct block_device_context
), GFP_KERNEL
);
283 INIT_LIST_HEAD(&blkdev
->pending_list
);
285 /* Initialize what we can here */
286 spin_lock_init(&blkdev
->lock
);
288 ASSERT(sizeof(struct blkvsc_request_group
) <=
289 sizeof(struct blkvsc_request
));
291 blkdev
->request_pool
= kmem_cache_create(dev_name(&device_ctx
->device
),
292 sizeof(struct blkvsc_request
) +
293 storvsc_drv_obj
->RequestExtSize
, 0,
294 SLAB_HWCACHE_ALIGN
, NULL
);
295 if (!blkdev
->request_pool
) {
301 /* Call to the vsc driver to add the device */
302 ret
= storvsc_drv_obj
->Base
.OnDeviceAdd(device_obj
, &device_info
);
304 DPRINT_ERR(BLKVSC_DRV
, "unable to add blkvsc device");
308 blkdev
->device_ctx
= device_ctx
;
309 /* this identified the device 0 or 1 */
310 blkdev
->target
= device_info
.TargetId
;
311 /* this identified the ide ctrl 0 or 1 */
312 blkdev
->path
= device_info
.PathId
;
314 dev_set_drvdata(device
, blkdev
);
316 /* Calculate the major and device num */
317 if (blkdev
->path
== 0) {
319 devnum
= blkdev
->path
+ blkdev
->target
; /* 0 or 1 */
321 if (!ide0_registered
) {
322 ret
= register_blkdev(major
, "ide");
324 DPRINT_ERR(BLKVSC_DRV
,
325 "register_blkdev() failed! ret %d",
332 } else if (blkdev
->path
== 1) {
334 devnum
= blkdev
->path
+ blkdev
->target
+ 1; /* 2 or 3 */
336 if (!ide1_registered
) {
337 ret
= register_blkdev(major
, "ide");
339 DPRINT_ERR(BLKVSC_DRV
,
340 "register_blkdev() failed! ret %d",
348 DPRINT_ERR(BLKVSC_DRV
, "invalid pathid");
353 DPRINT_INFO(BLKVSC_DRV
, "blkvsc registered for major %d!!", major
);
355 blkdev
->gd
= alloc_disk(BLKVSC_MINORS
);
357 DPRINT_ERR(BLKVSC_DRV
, "register_blkdev() failed! ret %d", ret
);
362 blkdev
->gd
->queue
= blk_init_queue(blkvsc_request
, &blkdev
->lock
);
364 blk_queue_max_segment_size(blkdev
->gd
->queue
, PAGE_SIZE
);
365 blk_queue_max_phys_segments(blkdev
->gd
->queue
,
366 MAX_MULTIPAGE_BUFFER_COUNT
);
367 blk_queue_max_hw_segments(blkdev
->gd
->queue
,
368 MAX_MULTIPAGE_BUFFER_COUNT
);
369 blk_queue_segment_boundary(blkdev
->gd
->queue
, PAGE_SIZE
-1);
370 blk_queue_bounce_limit(blkdev
->gd
->queue
, BLK_BOUNCE_ANY
);
371 blk_queue_dma_alignment(blkdev
->gd
->queue
, 511);
373 blkdev
->gd
->major
= major
;
374 if (devnum
== 1 || devnum
== 3)
375 blkdev
->gd
->first_minor
= BLKVSC_MINORS
;
377 blkdev
->gd
->first_minor
= 0;
378 blkdev
->gd
->fops
= &block_ops
;
379 blkdev
->gd
->private_data
= blkdev
;
380 sprintf(blkdev
->gd
->disk_name
, "hd%c", 'a' + devnum
);
382 blkvsc_do_inquiry(blkdev
);
383 if (blkdev
->device_type
== DVD_TYPE
) {
384 set_disk_ro(blkdev
->gd
, 1);
385 blkdev
->gd
->flags
|= GENHD_FL_REMOVABLE
;
386 blkvsc_do_read_capacity(blkdev
);
388 blkvsc_do_read_capacity16(blkdev
);
391 set_capacity(blkdev
->gd
, blkdev
->capacity
* (blkdev
->sector_size
/512));
392 blk_queue_logical_block_size(blkdev
->gd
->queue
, blkdev
->sector_size
);
394 add_disk(blkdev
->gd
);
396 DPRINT_INFO(BLKVSC_DRV
, "%s added!! capacity %lu sector_size %d",
397 blkdev
->gd
->disk_name
, (unsigned long)blkdev
->capacity
,
398 blkdev
->sector_size
);
403 storvsc_drv_obj
->Base
.OnDeviceRemove(device_obj
);
407 if (blkdev
->request_pool
) {
408 kmem_cache_destroy(blkdev
->request_pool
);
409 blkdev
->request_pool
= NULL
;
415 DPRINT_EXIT(BLKVSC_DRV
);
420 static void blkvsc_shutdown(struct device
*device
)
422 struct block_device_context
*blkdev
= dev_get_drvdata(device
);
428 DPRINT_DBG(BLKVSC_DRV
, "blkvsc_shutdown - users %d disk %s\n",
429 blkdev
->users
, blkdev
->gd
->disk_name
);
431 spin_lock_irqsave(&blkdev
->lock
, flags
);
433 blkdev
->shutting_down
= 1;
435 blk_stop_queue(blkdev
->gd
->queue
);
437 spin_unlock_irqrestore(&blkdev
->lock
, flags
);
439 while (blkdev
->num_outstanding_reqs
) {
440 DPRINT_INFO(STORVSC
, "waiting for %d requests to complete...",
441 blkdev
->num_outstanding_reqs
);
445 blkvsc_do_flush(blkdev
);
447 spin_lock_irqsave(&blkdev
->lock
, flags
);
449 blkvsc_cancel_pending_reqs(blkdev
);
451 spin_unlock_irqrestore(&blkdev
->lock
, flags
);
454 static int blkvsc_do_flush(struct block_device_context
*blkdev
)
456 struct blkvsc_request
*blkvsc_req
;
458 DPRINT_DBG(BLKVSC_DRV
, "blkvsc_do_flush()\n");
460 if (blkdev
->device_type
!= HARDDISK_TYPE
)
463 blkvsc_req
= kmem_cache_alloc(blkdev
->request_pool
, GFP_KERNEL
);
467 memset(blkvsc_req
, 0, sizeof(struct blkvsc_request
));
468 init_waitqueue_head(&blkvsc_req
->wevent
);
469 blkvsc_req
->dev
= blkdev
;
470 blkvsc_req
->req
= NULL
;
471 blkvsc_req
->write
= 0;
473 blkvsc_req
->request
.DataBuffer
.PfnArray
[0] = 0;
474 blkvsc_req
->request
.DataBuffer
.Offset
= 0;
475 blkvsc_req
->request
.DataBuffer
.Length
= 0;
477 blkvsc_req
->cmnd
[0] = SYNCHRONIZE_CACHE
;
478 blkvsc_req
->cmd_len
= 10;
481 * Set this here since the completion routine may be invoked and
482 * completed before we return
484 blkvsc_req
->cond
= 0;
485 blkvsc_submit_request(blkvsc_req
, blkvsc_cmd_completion
);
487 wait_event_interruptible(blkvsc_req
->wevent
, blkvsc_req
->cond
);
489 kmem_cache_free(blkvsc_req
->dev
->request_pool
, blkvsc_req
);
494 /* Do a scsi INQUIRY cmd here to get the device type (ie disk or dvd) */
495 static int blkvsc_do_inquiry(struct block_device_context
*blkdev
)
497 struct blkvsc_request
*blkvsc_req
;
498 struct page
*page_buf
;
500 unsigned char device_type
;
502 DPRINT_DBG(BLKVSC_DRV
, "blkvsc_do_inquiry()\n");
504 blkvsc_req
= kmem_cache_alloc(blkdev
->request_pool
, GFP_KERNEL
);
508 memset(blkvsc_req
, 0, sizeof(struct blkvsc_request
));
509 page_buf
= alloc_page(GFP_KERNEL
);
511 kmem_cache_free(blkvsc_req
->dev
->request_pool
, blkvsc_req
);
515 init_waitqueue_head(&blkvsc_req
->wevent
);
516 blkvsc_req
->dev
= blkdev
;
517 blkvsc_req
->req
= NULL
;
518 blkvsc_req
->write
= 0;
520 blkvsc_req
->request
.DataBuffer
.PfnArray
[0] = page_to_pfn(page_buf
);
521 blkvsc_req
->request
.DataBuffer
.Offset
= 0;
522 blkvsc_req
->request
.DataBuffer
.Length
= 64;
524 blkvsc_req
->cmnd
[0] = INQUIRY
;
525 blkvsc_req
->cmnd
[1] = 0x1; /* Get product data */
526 blkvsc_req
->cmnd
[2] = 0x83; /* mode page 83 */
527 blkvsc_req
->cmnd
[4] = 64;
528 blkvsc_req
->cmd_len
= 6;
531 * Set this here since the completion routine may be invoked and
532 * completed before we return
534 blkvsc_req
->cond
= 0;
536 blkvsc_submit_request(blkvsc_req
, blkvsc_cmd_completion
);
538 DPRINT_DBG(BLKVSC_DRV
, "waiting %p to complete - cond %d\n",
539 blkvsc_req
, blkvsc_req
->cond
);
541 wait_event_interruptible(blkvsc_req
->wevent
, blkvsc_req
->cond
);
543 buf
= kmap(page_buf
);
545 /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, buf, 64); */
547 device_type
= buf
[0] & 0x1F;
549 if (device_type
== 0x0) {
550 blkdev
->device_type
= HARDDISK_TYPE
;
551 } else if (device_type
== 0x5) {
552 blkdev
->device_type
= DVD_TYPE
;
554 /* TODO: this is currently unsupported device type */
555 blkdev
->device_type
= UNKNOWN_DEV_TYPE
;
558 DPRINT_DBG(BLKVSC_DRV
, "device type %d \n", device_type
);
560 blkdev
->device_id_len
= buf
[7];
561 if (blkdev
->device_id_len
> 64)
562 blkdev
->device_id_len
= 64;
564 memcpy(blkdev
->device_id
, &buf
[8], blkdev
->device_id_len
);
565 /* printk_hex_dump_bytes("", DUMP_PREFIX_NONE, blkdev->device_id,
566 * blkdev->device_id_len); */
570 __free_page(page_buf
);
572 kmem_cache_free(blkvsc_req
->dev
->request_pool
, blkvsc_req
);
577 /* Do a scsi READ_CAPACITY cmd here to get the size of the disk */
578 static int blkvsc_do_read_capacity(struct block_device_context
*blkdev
)
580 struct blkvsc_request
*blkvsc_req
;
581 struct page
*page_buf
;
583 struct scsi_sense_hdr sense_hdr
;
585 DPRINT_DBG(BLKVSC_DRV
, "blkvsc_do_read_capacity()\n");
587 blkdev
->sector_size
= 0;
588 blkdev
->capacity
= 0;
589 blkdev
->media_not_present
= 0; /* assume a disk is present */
591 blkvsc_req
= kmem_cache_alloc(blkdev
->request_pool
, GFP_KERNEL
);
595 memset(blkvsc_req
, 0, sizeof(struct blkvsc_request
));
596 page_buf
= alloc_page(GFP_KERNEL
);
598 kmem_cache_free(blkvsc_req
->dev
->request_pool
, blkvsc_req
);
602 init_waitqueue_head(&blkvsc_req
->wevent
);
603 blkvsc_req
->dev
= blkdev
;
604 blkvsc_req
->req
= NULL
;
605 blkvsc_req
->write
= 0;
607 blkvsc_req
->request
.DataBuffer
.PfnArray
[0] = page_to_pfn(page_buf
);
608 blkvsc_req
->request
.DataBuffer
.Offset
= 0;
609 blkvsc_req
->request
.DataBuffer
.Length
= 8;
611 blkvsc_req
->cmnd
[0] = READ_CAPACITY
;
612 blkvsc_req
->cmd_len
= 16;
615 * Set this here since the completion routine may be invoked
616 * and completed before we return
618 blkvsc_req
->cond
= 0;
620 blkvsc_submit_request(blkvsc_req
, blkvsc_cmd_completion
);
622 DPRINT_DBG(BLKVSC_DRV
, "waiting %p to complete - cond %d\n",
623 blkvsc_req
, blkvsc_req
->cond
);
625 wait_event_interruptible(blkvsc_req
->wevent
, blkvsc_req
->cond
);
628 if (blkvsc_req
->request
.Status
) {
629 scsi_normalize_sense(blkvsc_req
->sense_buffer
,
630 SCSI_SENSE_BUFFERSIZE
, &sense_hdr
);
632 if (sense_hdr
.asc
== 0x3A) {
633 /* Medium not present */
634 blkdev
->media_not_present
= 1;
638 buf
= kmap(page_buf
);
641 blkdev
->capacity
= ((buf
[0] << 24) | (buf
[1] << 16) |
642 (buf
[2] << 8) | buf
[3]) + 1;
643 blkdev
->sector_size
= (buf
[4] << 24) | (buf
[5] << 16) |
644 (buf
[6] << 8) | buf
[7];
648 __free_page(page_buf
);
650 kmem_cache_free(blkvsc_req
->dev
->request_pool
, blkvsc_req
);
655 static int blkvsc_do_read_capacity16(struct block_device_context
*blkdev
)
657 struct blkvsc_request
*blkvsc_req
;
658 struct page
*page_buf
;
660 struct scsi_sense_hdr sense_hdr
;
662 DPRINT_DBG(BLKVSC_DRV
, "blkvsc_do_read_capacity16()\n");
664 blkdev
->sector_size
= 0;
665 blkdev
->capacity
= 0;
666 blkdev
->media_not_present
= 0; /* assume a disk is present */
668 blkvsc_req
= kmem_cache_alloc(blkdev
->request_pool
, GFP_KERNEL
);
672 memset(blkvsc_req
, 0, sizeof(struct blkvsc_request
));
673 page_buf
= alloc_page(GFP_KERNEL
);
675 kmem_cache_free(blkvsc_req
->dev
->request_pool
, blkvsc_req
);
679 init_waitqueue_head(&blkvsc_req
->wevent
);
680 blkvsc_req
->dev
= blkdev
;
681 blkvsc_req
->req
= NULL
;
682 blkvsc_req
->write
= 0;
684 blkvsc_req
->request
.DataBuffer
.PfnArray
[0] = page_to_pfn(page_buf
);
685 blkvsc_req
->request
.DataBuffer
.Offset
= 0;
686 blkvsc_req
->request
.DataBuffer
.Length
= 12;
688 blkvsc_req
->cmnd
[0] = 0x9E; /* READ_CAPACITY16; */
689 blkvsc_req
->cmd_len
= 16;
692 * Set this here since the completion routine may be invoked
693 * and completed before we return
695 blkvsc_req
->cond
= 0;
697 blkvsc_submit_request(blkvsc_req
, blkvsc_cmd_completion
);
699 DPRINT_DBG(BLKVSC_DRV
, "waiting %p to complete - cond %d\n",
700 blkvsc_req
, blkvsc_req
->cond
);
702 wait_event_interruptible(blkvsc_req
->wevent
, blkvsc_req
->cond
);
705 if (blkvsc_req
->request
.Status
) {
706 scsi_normalize_sense(blkvsc_req
->sense_buffer
,
707 SCSI_SENSE_BUFFERSIZE
, &sense_hdr
);
708 if (sense_hdr
.asc
== 0x3A) {
709 /* Medium not present */
710 blkdev
->media_not_present
= 1;
714 buf
= kmap(page_buf
);
717 blkdev
->capacity
= be64_to_cpu(*(unsigned long long *) &buf
[0]) + 1;
718 blkdev
->sector_size
= be32_to_cpu(*(unsigned int *)&buf
[8]);
721 blkdev
->capacity
= ((buf
[0] << 24) | (buf
[1] << 16) |
722 (buf
[2] << 8) | buf
[3]) + 1;
723 blkdev
->sector_size
= (buf
[4] << 24) | (buf
[5] << 16) |
724 (buf
[6] << 8) | buf
[7];
729 __free_page(page_buf
);
731 kmem_cache_free(blkvsc_req
->dev
->request_pool
, blkvsc_req
);
737 * blkvsc_remove() - Callback when our device is removed
739 static int blkvsc_remove(struct device
*device
)
741 struct driver_context
*driver_ctx
=
742 driver_to_driver_context(device
->driver
);
743 struct blkvsc_driver_context
*blkvsc_drv_ctx
=
744 (struct blkvsc_driver_context
*)driver_ctx
;
745 struct storvsc_driver_object
*storvsc_drv_obj
=
746 &blkvsc_drv_ctx
->drv_obj
;
747 struct device_context
*device_ctx
= device_to_device_context(device
);
748 struct hv_device
*device_obj
= &device_ctx
->device_obj
;
749 struct block_device_context
*blkdev
= dev_get_drvdata(device
);
753 DPRINT_ENTER(BLKVSC_DRV
);
755 DPRINT_DBG(BLKVSC_DRV
, "blkvsc_remove()\n");
757 if (!storvsc_drv_obj
->Base
.OnDeviceRemove
) {
758 DPRINT_EXIT(BLKVSC_DRV
);
763 * Call to the vsc driver to let it know that the device is being
766 ret
= storvsc_drv_obj
->Base
.OnDeviceRemove(device_obj
);
769 DPRINT_ERR(BLKVSC_DRV
,
770 "unable to remove blkvsc device (ret %d)", ret
);
773 /* Get to a known state */
774 spin_lock_irqsave(&blkdev
->lock
, flags
);
776 blkdev
->shutting_down
= 1;
778 blk_stop_queue(blkdev
->gd
->queue
);
780 spin_unlock_irqrestore(&blkdev
->lock
, flags
);
782 while (blkdev
->num_outstanding_reqs
) {
783 DPRINT_INFO(STORVSC
, "waiting for %d requests to complete...",
784 blkdev
->num_outstanding_reqs
);
788 blkvsc_do_flush(blkdev
);
790 spin_lock_irqsave(&blkdev
->lock
, flags
);
792 blkvsc_cancel_pending_reqs(blkdev
);
794 spin_unlock_irqrestore(&blkdev
->lock
, flags
);
796 blk_cleanup_queue(blkdev
->gd
->queue
);
798 del_gendisk(blkdev
->gd
);
800 kmem_cache_destroy(blkdev
->request_pool
);
804 DPRINT_EXIT(BLKVSC_DRV
);
809 static void blkvsc_init_rw(struct blkvsc_request
*blkvsc_req
)
811 ASSERT(blkvsc_req
->req
);
812 ASSERT(blkvsc_req
->sector_count
<= (MAX_MULTIPAGE_BUFFER_COUNT
*8));
814 blkvsc_req
->cmd_len
= 16;
816 if (blkvsc_req
->sector_start
> 0xffffffff) {
817 if (rq_data_dir(blkvsc_req
->req
)) {
818 blkvsc_req
->write
= 1;
819 blkvsc_req
->cmnd
[0] = WRITE_16
;
821 blkvsc_req
->write
= 0;
822 blkvsc_req
->cmnd
[0] = READ_16
;
825 blkvsc_req
->cmnd
[1] |= blk_fua_rq(blkvsc_req
->req
) ? 0x8 : 0;
827 *(unsigned long long *)&blkvsc_req
->cmnd
[2] =
828 cpu_to_be64(blkvsc_req
->sector_start
);
829 *(unsigned int *)&blkvsc_req
->cmnd
[10] =
830 cpu_to_be32(blkvsc_req
->sector_count
);
831 } else if ((blkvsc_req
->sector_count
> 0xff) ||
832 (blkvsc_req
->sector_start
> 0x1fffff)) {
833 if (rq_data_dir(blkvsc_req
->req
)) {
834 blkvsc_req
->write
= 1;
835 blkvsc_req
->cmnd
[0] = WRITE_10
;
837 blkvsc_req
->write
= 0;
838 blkvsc_req
->cmnd
[0] = READ_10
;
841 blkvsc_req
->cmnd
[1] |= blk_fua_rq(blkvsc_req
->req
) ? 0x8 : 0;
843 *(unsigned int *)&blkvsc_req
->cmnd
[2] =
844 cpu_to_be32(blkvsc_req
->sector_start
);
845 *(unsigned short *)&blkvsc_req
->cmnd
[7] =
846 cpu_to_be16(blkvsc_req
->sector_count
);
848 if (rq_data_dir(blkvsc_req
->req
)) {
849 blkvsc_req
->write
= 1;
850 blkvsc_req
->cmnd
[0] = WRITE_6
;
852 blkvsc_req
->write
= 0;
853 blkvsc_req
->cmnd
[0] = READ_6
;
856 *(unsigned int *)&blkvsc_req
->cmnd
[1] =
857 cpu_to_be32(blkvsc_req
->sector_start
) >> 8;
858 blkvsc_req
->cmnd
[1] &= 0x1f;
859 blkvsc_req
->cmnd
[4] = (unsigned char)blkvsc_req
->sector_count
;
863 static int blkvsc_submit_request(struct blkvsc_request
*blkvsc_req
,
864 void (*request_completion
)(struct hv_storvsc_request
*))
866 struct block_device_context
*blkdev
= blkvsc_req
->dev
;
867 struct device_context
*device_ctx
= blkdev
->device_ctx
;
868 struct driver_context
*driver_ctx
=
869 driver_to_driver_context(device_ctx
->device
.driver
);
870 struct blkvsc_driver_context
*blkvsc_drv_ctx
=
871 (struct blkvsc_driver_context
*)driver_ctx
;
872 struct storvsc_driver_object
*storvsc_drv_obj
=
873 &blkvsc_drv_ctx
->drv_obj
;
874 struct hv_storvsc_request
*storvsc_req
;
877 DPRINT_DBG(BLKVSC_DRV
, "blkvsc_submit_request() - "
878 "req %p type %s start_sector %lu count %ld offset %d "
879 "len %d\n", blkvsc_req
,
880 (blkvsc_req
->write
) ? "WRITE" : "READ",
881 (unsigned long) blkvsc_req
->sector_start
,
882 blkvsc_req
->sector_count
,
883 blkvsc_req
->request
.DataBuffer
.Offset
,
884 blkvsc_req
->request
.DataBuffer
.Length
);
886 for (i
= 0; i
< (blkvsc_req
->request
.DataBuffer
.Length
>> 12); i
++) {
887 DPRINT_DBG(BLKVSC_DRV
, "blkvsc_submit_request() - "
888 "req %p pfn[%d] %llx\n",
890 blkvsc_req
->request
.DataBuffer
.PfnArray
[i
]);
894 storvsc_req
= &blkvsc_req
->request
;
895 storvsc_req
->Extension
= (void *)((unsigned long)blkvsc_req
+
896 sizeof(struct blkvsc_request
));
898 storvsc_req
->Type
= blkvsc_req
->write
? WRITE_TYPE
: READ_TYPE
;
900 storvsc_req
->OnIOCompletion
= request_completion
;
901 storvsc_req
->Context
= blkvsc_req
;
903 storvsc_req
->Host
= blkdev
->port
;
904 storvsc_req
->Bus
= blkdev
->path
;
905 storvsc_req
->TargetId
= blkdev
->target
;
906 storvsc_req
->LunId
= 0; /* this is not really used at all */
908 storvsc_req
->CdbLen
= blkvsc_req
->cmd_len
;
909 storvsc_req
->Cdb
= blkvsc_req
->cmnd
;
911 storvsc_req
->SenseBuffer
= blkvsc_req
->sense_buffer
;
912 storvsc_req
->SenseBufferSize
= SCSI_SENSE_BUFFERSIZE
;
914 ret
= storvsc_drv_obj
->OnIORequest(&blkdev
->device_ctx
->device_obj
,
915 &blkvsc_req
->request
);
917 blkdev
->num_outstanding_reqs
++;
923 * We break the request into 1 or more blkvsc_requests and submit
924 * them. If we cant submit them all, we put them on the
925 * pending_list. The blkvsc_request() will work on the pending_list.
927 static int blkvsc_do_request(struct block_device_context
*blkdev
,
930 struct bio
*bio
= NULL
;
931 struct bio_vec
*bvec
= NULL
;
932 struct bio_vec
*prev_bvec
= NULL
;
933 struct blkvsc_request
*blkvsc_req
= NULL
;
934 struct blkvsc_request
*tmp
;
937 sector_t start_sector
;
938 unsigned long num_sectors
= 0;
941 struct blkvsc_request_group
*group
= NULL
;
943 DPRINT_DBG(BLKVSC_DRV
, "blkdev %p req %p sect %lu \n", blkdev
, req
,
944 (unsigned long)blk_rq_pos(req
));
946 /* Create a group to tie req to list of blkvsc_reqs */
947 group
= kmem_cache_alloc(blkdev
->request_pool
, GFP_ATOMIC
);
951 INIT_LIST_HEAD(&group
->blkvsc_req_list
);
952 group
->outstanding
= group
->status
= 0;
954 start_sector
= blk_rq_pos(req
);
956 /* foreach bio in the request */
958 for (bio
= req
->bio
; bio
; bio
= bio
->bi_next
) {
960 * Map this bio into an existing or new storvsc request
962 bio_for_each_segment(bvec
, bio
, seg_idx
) {
963 DPRINT_DBG(BLKVSC_DRV
, "bio_for_each_segment() "
964 "- req %p bio %p bvec %p seg_idx %d "
965 "databuf_idx %d\n", req
, bio
, bvec
,
966 seg_idx
, databuf_idx
);
968 /* Get a new storvsc request */
971 (databuf_idx
>= MAX_MULTIPAGE_BUFFER_COUNT
)
972 /* hole at the begin of page */
973 || (bvec
->bv_offset
!= 0) ||
974 /* hold at the end of page */
976 (prev_bvec
->bv_len
!= PAGE_SIZE
))) {
977 /* submit the prev one */
979 blkvsc_req
->sector_start
= start_sector
;
980 sector_div(blkvsc_req
->sector_start
, (blkdev
->sector_size
>> 9));
982 blkvsc_req
->sector_count
= num_sectors
/ (blkdev
->sector_size
>> 9);
983 blkvsc_init_rw(blkvsc_req
);
987 * Create new blkvsc_req to represent
990 blkvsc_req
= kmem_cache_alloc(blkdev
->request_pool
, GFP_ATOMIC
);
992 /* free up everything */
993 list_for_each_entry_safe(
995 &group
->blkvsc_req_list
,
997 list_del(&blkvsc_req
->req_entry
);
998 kmem_cache_free(blkdev
->request_pool
, blkvsc_req
);
1001 kmem_cache_free(blkdev
->request_pool
, group
);
1005 memset(blkvsc_req
, 0,
1006 sizeof(struct blkvsc_request
));
1008 blkvsc_req
->dev
= blkdev
;
1009 blkvsc_req
->req
= req
;
1010 blkvsc_req
->request
.DataBuffer
.Offset
= bvec
->bv_offset
;
1011 blkvsc_req
->request
.DataBuffer
.Length
= 0;
1013 /* Add to the group */
1014 blkvsc_req
->group
= group
;
1015 blkvsc_req
->group
->outstanding
++;
1016 list_add_tail(&blkvsc_req
->req_entry
,
1017 &blkvsc_req
->group
->blkvsc_req_list
);
1019 start_sector
+= num_sectors
;
1024 /* Add the curr bvec/segment to the curr blkvsc_req */
1025 blkvsc_req
->request
.DataBuffer
.PfnArray
[databuf_idx
] = page_to_pfn(bvec
->bv_page
);
1026 blkvsc_req
->request
.DataBuffer
.Length
+= bvec
->bv_len
;
1031 num_sectors
+= bvec
->bv_len
>> 9;
1033 } /* bio_for_each_segment */
1035 } /* rq_for_each_bio */
1038 /* Handle the last one */
1040 DPRINT_DBG(BLKVSC_DRV
, "blkdev %p req %p group %p count %d\n",
1041 blkdev
, req
, blkvsc_req
->group
,
1042 blkvsc_req
->group
->outstanding
);
1044 blkvsc_req
->sector_start
= start_sector
;
1045 sector_div(blkvsc_req
->sector_start
,
1046 (blkdev
->sector_size
>> 9));
1048 blkvsc_req
->sector_count
= num_sectors
/
1049 (blkdev
->sector_size
>> 9);
1051 blkvsc_init_rw(blkvsc_req
);
1054 list_for_each_entry(blkvsc_req
, &group
->blkvsc_req_list
, req_entry
) {
1056 DPRINT_DBG(BLKVSC_DRV
, "adding blkvsc_req to "
1057 "pending_list - blkvsc_req %p start_sect %lu"
1058 " sect_count %ld (%lu %ld)\n", blkvsc_req
,
1059 (unsigned long)blkvsc_req
->sector_start
,
1060 blkvsc_req
->sector_count
,
1061 (unsigned long)start_sector
,
1062 (unsigned long)num_sectors
);
1064 list_add_tail(&blkvsc_req
->pend_entry
,
1065 &blkdev
->pending_list
);
1067 ret
= blkvsc_submit_request(blkvsc_req
,
1068 blkvsc_request_completion
);
1071 list_add_tail(&blkvsc_req
->pend_entry
,
1072 &blkdev
->pending_list
);
1075 DPRINT_DBG(BLKVSC_DRV
, "submitted blkvsc_req %p "
1076 "start_sect %lu sect_count %ld (%lu %ld) "
1077 "ret %d\n", blkvsc_req
,
1078 (unsigned long)blkvsc_req
->sector_start
,
1079 blkvsc_req
->sector_count
,
1080 (unsigned long)start_sector
,
1088 static void blkvsc_cmd_completion(struct hv_storvsc_request
*request
)
1090 struct blkvsc_request
*blkvsc_req
=
1091 (struct blkvsc_request
*)request
->Context
;
1092 struct block_device_context
*blkdev
=
1093 (struct block_device_context
*)blkvsc_req
->dev
;
1094 struct scsi_sense_hdr sense_hdr
;
1096 DPRINT_DBG(BLKVSC_DRV
, "blkvsc_cmd_completion() - req %p\n",
1099 blkdev
->num_outstanding_reqs
--;
1101 if (blkvsc_req
->request
.Status
)
1102 if (scsi_normalize_sense(blkvsc_req
->sense_buffer
,
1103 SCSI_SENSE_BUFFERSIZE
, &sense_hdr
))
1104 scsi_print_sense_hdr("blkvsc", &sense_hdr
);
1106 blkvsc_req
->cond
= 1;
1107 wake_up_interruptible(&blkvsc_req
->wevent
);
1110 static void blkvsc_request_completion(struct hv_storvsc_request
*request
)
1112 struct blkvsc_request
*blkvsc_req
=
1113 (struct blkvsc_request
*)request
->Context
;
1114 struct block_device_context
*blkdev
=
1115 (struct block_device_context
*)blkvsc_req
->dev
;
1116 unsigned long flags
;
1117 struct blkvsc_request
*comp_req
, *tmp
;
1119 ASSERT(blkvsc_req
->group
);
1121 DPRINT_DBG(BLKVSC_DRV
, "blkdev %p blkvsc_req %p group %p type %s "
1122 "sect_start %lu sect_count %ld len %d group outstd %d "
1123 "total outstd %d\n",
1124 blkdev
, blkvsc_req
, blkvsc_req
->group
,
1125 (blkvsc_req
->write
) ? "WRITE" : "READ",
1126 (unsigned long)blkvsc_req
->sector_start
,
1127 blkvsc_req
->sector_count
,
1128 blkvsc_req
->request
.DataBuffer
.Length
,
1129 blkvsc_req
->group
->outstanding
,
1130 blkdev
->num_outstanding_reqs
);
1132 spin_lock_irqsave(&blkdev
->lock
, flags
);
1134 blkdev
->num_outstanding_reqs
--;
1135 blkvsc_req
->group
->outstanding
--;
1138 * Only start processing when all the blkvsc_reqs are
1139 * completed. This guarantees no out-of-order blkvsc_req
1140 * completion when calling end_that_request_first()
1142 if (blkvsc_req
->group
->outstanding
== 0) {
1143 list_for_each_entry_safe(comp_req
, tmp
,
1144 &blkvsc_req
->group
->blkvsc_req_list
,
1146 DPRINT_DBG(BLKVSC_DRV
, "completing blkvsc_req %p "
1147 "sect_start %lu sect_count %ld \n",
1149 (unsigned long)comp_req
->sector_start
,
1150 comp_req
->sector_count
);
1152 list_del(&comp_req
->req_entry
);
1154 if (!__blk_end_request(comp_req
->req
,
1155 (!comp_req
->request
.Status
? 0 : -EIO
),
1156 comp_req
->sector_count
* blkdev
->sector_size
)) {
1158 * All the sectors have been xferred ie the
1161 DPRINT_DBG(BLKVSC_DRV
, "req %p COMPLETED\n",
1163 kmem_cache_free(blkdev
->request_pool
,
1167 kmem_cache_free(blkdev
->request_pool
, comp_req
);
1170 if (!blkdev
->shutting_down
) {
1171 blkvsc_do_pending_reqs(blkdev
);
1172 blk_start_queue(blkdev
->gd
->queue
);
1173 blkvsc_request(blkdev
->gd
->queue
);
1177 spin_unlock_irqrestore(&blkdev
->lock
, flags
);
1180 static int blkvsc_cancel_pending_reqs(struct block_device_context
*blkdev
)
1182 struct blkvsc_request
*pend_req
, *tmp
;
1183 struct blkvsc_request
*comp_req
, *tmp2
;
1187 DPRINT_DBG(BLKVSC_DRV
, "blkvsc_cancel_pending_reqs()");
1189 /* Flush the pending list first */
1190 list_for_each_entry_safe(pend_req
, tmp
, &blkdev
->pending_list
,
1193 * The pend_req could be part of a partially completed
1194 * request. If so, complete those req first until we
1197 list_for_each_entry_safe(comp_req
, tmp2
,
1198 &pend_req
->group
->blkvsc_req_list
,
1200 DPRINT_DBG(BLKVSC_DRV
, "completing blkvsc_req %p "
1201 "sect_start %lu sect_count %ld \n",
1203 (unsigned long) comp_req
->sector_start
,
1204 comp_req
->sector_count
);
1206 if (comp_req
== pend_req
)
1209 list_del(&comp_req
->req_entry
);
1211 if (comp_req
->req
) {
1212 ret
= __blk_end_request(comp_req
->req
,
1213 (!comp_req
->request
.Status
? 0 : -EIO
),
1214 comp_req
->sector_count
*
1215 blkdev
->sector_size
);
1219 kmem_cache_free(blkdev
->request_pool
, comp_req
);
1222 DPRINT_DBG(BLKVSC_DRV
, "cancelling pending request - %p\n",
1225 list_del(&pend_req
->pend_entry
);
1227 list_del(&pend_req
->req_entry
);
1229 if (comp_req
->req
) {
1230 if (!__blk_end_request(pend_req
->req
, -EIO
,
1231 pend_req
->sector_count
*
1232 blkdev
->sector_size
)) {
1234 * All the sectors have been xferred ie the
1237 DPRINT_DBG(BLKVSC_DRV
,
1238 "blkvsc_cancel_pending_reqs() - "
1239 "req %p COMPLETED\n", pend_req
->req
);
1240 kmem_cache_free(blkdev
->request_pool
,
1245 kmem_cache_free(blkdev
->request_pool
, pend_req
);
1251 static int blkvsc_do_pending_reqs(struct block_device_context
*blkdev
)
1253 struct blkvsc_request
*pend_req
, *tmp
;
1256 /* Flush the pending list first */
1257 list_for_each_entry_safe(pend_req
, tmp
, &blkdev
->pending_list
,
1259 DPRINT_DBG(BLKVSC_DRV
, "working off pending_list - %p\n",
1262 ret
= blkvsc_submit_request(pend_req
,
1263 blkvsc_request_completion
);
1267 list_del(&pend_req
->pend_entry
);
1273 static void blkvsc_request(struct request_queue
*queue
)
1275 struct block_device_context
*blkdev
= NULL
;
1276 struct request
*req
;
1279 DPRINT_DBG(BLKVSC_DRV
, "- enter \n");
1280 while ((req
= blk_peek_request(queue
)) != NULL
) {
1281 DPRINT_DBG(BLKVSC_DRV
, "- req %p\n", req
);
1283 blkdev
= req
->rq_disk
->private_data
;
1284 if (blkdev
->shutting_down
|| !blk_fs_request(req
) ||
1285 blkdev
->media_not_present
) {
1286 __blk_end_request_cur(req
, 0);
1290 ret
= blkvsc_do_pending_reqs(blkdev
);
1293 DPRINT_DBG(BLKVSC_DRV
,
1294 "- stop queue - pending_list not empty\n");
1295 blk_stop_queue(queue
);
1299 blk_start_request(req
);
1301 ret
= blkvsc_do_request(blkdev
, req
);
1303 DPRINT_DBG(BLKVSC_DRV
, "- stop queue - no room\n");
1304 blk_stop_queue(queue
);
1306 } else if (ret
< 0) {
1307 DPRINT_DBG(BLKVSC_DRV
, "- stop queue - no mem\n");
1308 blk_requeue_request(queue
, req
);
1309 blk_stop_queue(queue
);
1315 static int blkvsc_open(struct block_device
*bdev
, fmode_t mode
)
1317 struct block_device_context
*blkdev
= bdev
->bd_disk
->private_data
;
1319 DPRINT_DBG(BLKVSC_DRV
, "- users %d disk %s\n", blkdev
->users
,
1320 blkdev
->gd
->disk_name
);
1322 spin_lock(&blkdev
->lock
);
1324 if (!blkdev
->users
&& blkdev
->device_type
== DVD_TYPE
) {
1325 spin_unlock(&blkdev
->lock
);
1326 check_disk_change(bdev
);
1327 spin_lock(&blkdev
->lock
);
1332 spin_unlock(&blkdev
->lock
);
1336 static int blkvsc_release(struct gendisk
*disk
, fmode_t mode
)
1338 struct block_device_context
*blkdev
= disk
->private_data
;
1340 DPRINT_DBG(BLKVSC_DRV
, "- users %d disk %s\n", blkdev
->users
,
1341 blkdev
->gd
->disk_name
);
1343 spin_lock(&blkdev
->lock
);
1344 if (blkdev
->users
== 1) {
1345 spin_unlock(&blkdev
->lock
);
1346 blkvsc_do_flush(blkdev
);
1347 spin_lock(&blkdev
->lock
);
1352 spin_unlock(&blkdev
->lock
);
1356 static int blkvsc_media_changed(struct gendisk
*gd
)
1358 DPRINT_DBG(BLKVSC_DRV
, "- enter\n");
1362 static int blkvsc_revalidate_disk(struct gendisk
*gd
)
1364 struct block_device_context
*blkdev
= gd
->private_data
;
1366 DPRINT_DBG(BLKVSC_DRV
, "- enter\n");
1368 if (blkdev
->device_type
== DVD_TYPE
) {
1369 blkvsc_do_read_capacity(blkdev
);
1370 set_capacity(blkdev
->gd
, blkdev
->capacity
*
1371 (blkdev
->sector_size
/512));
1372 blk_queue_logical_block_size(gd
->queue
, blkdev
->sector_size
);
1377 static int blkvsc_getgeo(struct block_device
*bd
, struct hd_geometry
*hg
)
1379 sector_t total_sectors
= get_capacity(bd
->bd_disk
);
1380 sector_t cylinder_times_heads
= 0;
1383 int sectors_per_track
= 0;
1388 if (total_sectors
> (65535 * 16 * 255))
1389 total_sectors
= (65535 * 16 * 255);
1391 if (total_sectors
>= (65535 * 16 * 63)) {
1392 sectors_per_track
= 255;
1395 cylinder_times_heads
= total_sectors
;
1396 /* sector_div stores the quotient in cylinder_times_heads */
1397 rem
= sector_div(cylinder_times_heads
, sectors_per_track
);
1399 sectors_per_track
= 17;
1401 cylinder_times_heads
= total_sectors
;
1402 /* sector_div stores the quotient in cylinder_times_heads */
1403 rem
= sector_div(cylinder_times_heads
, sectors_per_track
);
1405 temp
= cylinder_times_heads
+ 1023;
1406 /* sector_div stores the quotient in temp */
1407 rem
= sector_div(temp
, 1024);
1415 if (cylinder_times_heads
>= (heads
* 1024) || (heads
> 16)) {
1416 sectors_per_track
= 31;
1419 cylinder_times_heads
= total_sectors
;
1421 * sector_div stores the quotient in
1422 * cylinder_times_heads
1424 rem
= sector_div(cylinder_times_heads
,
1428 if (cylinder_times_heads
>= (heads
* 1024)) {
1429 sectors_per_track
= 63;
1432 cylinder_times_heads
= total_sectors
;
1434 * sector_div stores the quotient in
1435 * cylinder_times_heads
1437 rem
= sector_div(cylinder_times_heads
,
1442 temp
= cylinder_times_heads
;
1443 /* sector_div stores the quotient in temp */
1444 rem
= sector_div(temp
, heads
);
1448 hg
->sectors
= sectors_per_track
;
1449 hg
->cylinders
= cylinders
;
1451 DPRINT_INFO(BLKVSC_DRV
, "CHS (%d, %d, %d)", cylinders
, heads
,
1457 static int blkvsc_ioctl(struct block_device
*bd
, fmode_t mode
,
1458 unsigned cmd
, unsigned long argument
)
1460 /* struct block_device_context *blkdev = bd->bd_disk->private_data; */
1465 * TODO: I think there is certain format for HDIO_GET_IDENTITY rather
1466 * than just a GUID. Commented it out for now.
1469 case HDIO_GET_IDENTITY
:
1470 DPRINT_INFO(BLKVSC_DRV
, "HDIO_GET_IDENTITY\n");
1471 if (copy_to_user((void __user
*)arg
, blkdev
->device_id
,
1472 blkdev
->device_id_len
))
1484 static int __init
blkvsc_init(void)
1488 ASSERT(sizeof(sector_t
) == 8); /* Make sure CONFIG_LBD is set */
1490 DPRINT_ENTER(BLKVSC_DRV
);
1492 DPRINT_INFO(BLKVSC_DRV
, "Blkvsc initializing....");
1494 ret
= blkvsc_drv_init(BlkVscInitialize
);
1496 DPRINT_EXIT(BLKVSC_DRV
);
1501 static void __exit
blkvsc_exit(void)
1503 DPRINT_ENTER(BLKVSC_DRV
);
1505 DPRINT_ENTER(BLKVSC_DRV
);
1508 MODULE_LICENSE("GPL");
1509 module_param(blkvsc_ringbuffer_size
, int, S_IRUGO
);
1510 module_init(blkvsc_init
);
1511 module_exit(blkvsc_exit
);