BKL: introduce CONFIG_BKL.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / block / viodasd.c
blobf651e51a3319e0311f6a7bcc5e3d7e12d0e7d0e4
1 /* -*- linux-c -*-
2 * viodasd.c
3 * Authors: Dave Boutcher <boutcher@us.ibm.com>
4 * Ryan Arnold <ryanarn@us.ibm.com>
5 * Colin Devilbiss <devilbis@us.ibm.com>
6 * Stephen Rothwell
8 * (C) Copyright 2000-2004 IBM Corporation
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of the
13 * License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * This routine provides access to disk space (termed "DASD" in historical
25 * IBM terms) owned and managed by an OS/400 partition running on the
26 * same box as this Linux partition.
28 * All disk operations are performed by sending messages back and forth to
29 * the OS/400 partition.
32 #define pr_fmt(fmt) "viod: " fmt
34 #include <linux/major.h>
35 #include <linux/fs.h>
36 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/blkdev.h>
39 #include <linux/genhd.h>
40 #include <linux/hdreg.h>
41 #include <linux/errno.h>
42 #include <linux/init.h>
43 #include <linux/string.h>
44 #include <linux/smp_lock.h>
45 #include <linux/dma-mapping.h>
46 #include <linux/completion.h>
47 #include <linux/device.h>
48 #include <linux/scatterlist.h>
50 #include <asm/uaccess.h>
51 #include <asm/vio.h>
52 #include <asm/iseries/hv_types.h>
53 #include <asm/iseries/hv_lp_event.h>
54 #include <asm/iseries/hv_lp_config.h>
55 #include <asm/iseries/vio.h>
56 #include <asm/firmware.h>
58 MODULE_DESCRIPTION("iSeries Virtual DASD");
59 MODULE_AUTHOR("Dave Boutcher");
60 MODULE_LICENSE("GPL");
63 * We only support 7 partitions per physical disk....so with minor
64 * numbers 0-255 we get a maximum of 32 disks.
66 #define VIOD_GENHD_NAME "iseries/vd"
68 #define VIOD_VERS "1.64"
70 enum {
71 PARTITION_SHIFT = 3,
72 MAX_DISKNO = HVMAXARCHITECTEDVIRTUALDISKS,
73 MAX_DISK_NAME = FIELD_SIZEOF(struct gendisk, disk_name)
76 static DEFINE_SPINLOCK(viodasd_spinlock);
78 #define VIOMAXREQ 16
80 #define DEVICE_NO(cell) ((struct viodasd_device *)(cell) - &viodasd_devices[0])
82 struct viodasd_waitevent {
83 struct completion com;
84 int rc;
85 u16 sub_result;
86 int max_disk; /* open */
89 static const struct vio_error_entry viodasd_err_table[] = {
90 { 0x0201, EINVAL, "Invalid Range" },
91 { 0x0202, EINVAL, "Invalid Token" },
92 { 0x0203, EIO, "DMA Error" },
93 { 0x0204, EIO, "Use Error" },
94 { 0x0205, EIO, "Release Error" },
95 { 0x0206, EINVAL, "Invalid Disk" },
96 { 0x0207, EBUSY, "Cant Lock" },
97 { 0x0208, EIO, "Already Locked" },
98 { 0x0209, EIO, "Already Unlocked" },
99 { 0x020A, EIO, "Invalid Arg" },
100 { 0x020B, EIO, "Bad IFS File" },
101 { 0x020C, EROFS, "Read Only Device" },
102 { 0x02FF, EIO, "Internal Error" },
103 { 0x0000, 0, NULL },
107 * Figure out the biggest I/O request (in sectors) we can accept
109 #define VIODASD_MAXSECTORS (4096 / 512 * VIOMAXBLOCKDMA)
112 * Number of disk I/O requests we've sent to OS/400
114 static int num_req_outstanding;
117 * This is our internal structure for keeping track of disk devices
119 struct viodasd_device {
120 u16 cylinders;
121 u16 tracks;
122 u16 sectors;
123 u16 bytes_per_sector;
124 u64 size;
125 int read_only;
126 spinlock_t q_lock;
127 struct gendisk *disk;
128 struct device *dev;
129 } viodasd_devices[MAX_DISKNO];
132 * External open entry point.
134 static int viodasd_open(struct block_device *bdev, fmode_t mode)
136 struct viodasd_device *d = bdev->bd_disk->private_data;
137 HvLpEvent_Rc hvrc;
138 struct viodasd_waitevent we;
139 u16 flags = 0;
141 if (d->read_only) {
142 if (mode & FMODE_WRITE)
143 return -EROFS;
144 flags = vioblockflags_ro;
147 init_completion(&we.com);
149 /* Send the open event to OS/400 */
150 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
151 HvLpEvent_Type_VirtualIo,
152 viomajorsubtype_blockio | vioblockopen,
153 HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck,
154 viopath_sourceinst(viopath_hostLp),
155 viopath_targetinst(viopath_hostLp),
156 (u64)(unsigned long)&we, VIOVERSION << 16,
157 ((u64)DEVICE_NO(d) << 48) | ((u64)flags << 32),
158 0, 0, 0);
159 if (hvrc != 0) {
160 pr_warning("HV open failed %d\n", (int)hvrc);
161 return -EIO;
164 wait_for_completion(&we.com);
166 /* Check the return code */
167 if (we.rc != 0) {
168 const struct vio_error_entry *err =
169 vio_lookup_rc(viodasd_err_table, we.sub_result);
171 pr_warning("bad rc opening disk: %d:0x%04x (%s)\n",
172 (int)we.rc, we.sub_result, err->msg);
173 return -EIO;
176 return 0;
179 static int viodasd_unlocked_open(struct block_device *bdev, fmode_t mode)
181 int ret;
183 lock_kernel();
184 ret = viodasd_open(bdev, mode);
185 unlock_kernel();
187 return ret;
192 * External release entry point.
194 static int viodasd_release(struct gendisk *disk, fmode_t mode)
196 struct viodasd_device *d = disk->private_data;
197 HvLpEvent_Rc hvrc;
199 lock_kernel();
200 /* Send the event to OS/400. We DON'T expect a response */
201 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
202 HvLpEvent_Type_VirtualIo,
203 viomajorsubtype_blockio | vioblockclose,
204 HvLpEvent_AckInd_NoAck, HvLpEvent_AckType_ImmediateAck,
205 viopath_sourceinst(viopath_hostLp),
206 viopath_targetinst(viopath_hostLp),
207 0, VIOVERSION << 16,
208 ((u64)DEVICE_NO(d) << 48) /* | ((u64)flags << 32) */,
209 0, 0, 0);
210 if (hvrc != 0)
211 pr_warning("HV close call failed %d\n", (int)hvrc);
213 unlock_kernel();
215 return 0;
219 /* External ioctl entry point.
221 static int viodasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
223 struct gendisk *disk = bdev->bd_disk;
224 struct viodasd_device *d = disk->private_data;
226 geo->sectors = d->sectors ? d->sectors : 32;
227 geo->heads = d->tracks ? d->tracks : 64;
228 geo->cylinders = d->cylinders ? d->cylinders :
229 get_capacity(disk) / (geo->sectors * geo->heads);
231 return 0;
235 * Our file operations table
237 static const struct block_device_operations viodasd_fops = {
238 .owner = THIS_MODULE,
239 .open = viodasd_unlocked_open,
240 .release = viodasd_release,
241 .getgeo = viodasd_getgeo,
245 * End a request
247 static void viodasd_end_request(struct request *req, int error,
248 int num_sectors)
250 __blk_end_request(req, error, num_sectors << 9);
254 * Send an actual I/O request to OS/400
256 static int send_request(struct request *req)
258 u64 start;
259 int direction;
260 int nsg;
261 u16 viocmd;
262 HvLpEvent_Rc hvrc;
263 struct vioblocklpevent *bevent;
264 struct HvLpEvent *hev;
265 struct scatterlist sg[VIOMAXBLOCKDMA];
266 int sgindex;
267 struct viodasd_device *d;
268 unsigned long flags;
270 start = (u64)blk_rq_pos(req) << 9;
272 if (rq_data_dir(req) == READ) {
273 direction = DMA_FROM_DEVICE;
274 viocmd = viomajorsubtype_blockio | vioblockread;
275 } else {
276 direction = DMA_TO_DEVICE;
277 viocmd = viomajorsubtype_blockio | vioblockwrite;
280 d = req->rq_disk->private_data;
282 /* Now build the scatter-gather list */
283 sg_init_table(sg, VIOMAXBLOCKDMA);
284 nsg = blk_rq_map_sg(req->q, req, sg);
285 nsg = dma_map_sg(d->dev, sg, nsg, direction);
287 spin_lock_irqsave(&viodasd_spinlock, flags);
288 num_req_outstanding++;
290 /* This optimization handles a single DMA block */
291 if (nsg == 1)
292 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
293 HvLpEvent_Type_VirtualIo, viocmd,
294 HvLpEvent_AckInd_DoAck,
295 HvLpEvent_AckType_ImmediateAck,
296 viopath_sourceinst(viopath_hostLp),
297 viopath_targetinst(viopath_hostLp),
298 (u64)(unsigned long)req, VIOVERSION << 16,
299 ((u64)DEVICE_NO(d) << 48), start,
300 ((u64)sg_dma_address(&sg[0])) << 32,
301 sg_dma_len(&sg[0]));
302 else {
303 bevent = (struct vioblocklpevent *)
304 vio_get_event_buffer(viomajorsubtype_blockio);
305 if (bevent == NULL) {
306 pr_warning("error allocating disk event buffer\n");
307 goto error_ret;
311 * Now build up the actual request. Note that we store
312 * the pointer to the request in the correlation
313 * token so we can match the response up later
315 memset(bevent, 0, sizeof(struct vioblocklpevent));
316 hev = &bevent->event;
317 hev->flags = HV_LP_EVENT_VALID | HV_LP_EVENT_DO_ACK |
318 HV_LP_EVENT_INT;
319 hev->xType = HvLpEvent_Type_VirtualIo;
320 hev->xSubtype = viocmd;
321 hev->xSourceLp = HvLpConfig_getLpIndex();
322 hev->xTargetLp = viopath_hostLp;
323 hev->xSizeMinus1 =
324 offsetof(struct vioblocklpevent, u.rw_data.dma_info) +
325 (sizeof(bevent->u.rw_data.dma_info[0]) * nsg) - 1;
326 hev->xSourceInstanceId = viopath_sourceinst(viopath_hostLp);
327 hev->xTargetInstanceId = viopath_targetinst(viopath_hostLp);
328 hev->xCorrelationToken = (u64)req;
329 bevent->version = VIOVERSION;
330 bevent->disk = DEVICE_NO(d);
331 bevent->u.rw_data.offset = start;
334 * Copy just the dma information from the sg list
335 * into the request
337 for (sgindex = 0; sgindex < nsg; sgindex++) {
338 bevent->u.rw_data.dma_info[sgindex].token =
339 sg_dma_address(&sg[sgindex]);
340 bevent->u.rw_data.dma_info[sgindex].len =
341 sg_dma_len(&sg[sgindex]);
344 /* Send the request */
345 hvrc = HvCallEvent_signalLpEvent(&bevent->event);
346 vio_free_event_buffer(viomajorsubtype_blockio, bevent);
349 if (hvrc != HvLpEvent_Rc_Good) {
350 pr_warning("error sending disk event to OS/400 (rc %d)\n",
351 (int)hvrc);
352 goto error_ret;
354 spin_unlock_irqrestore(&viodasd_spinlock, flags);
355 return 0;
357 error_ret:
358 num_req_outstanding--;
359 spin_unlock_irqrestore(&viodasd_spinlock, flags);
360 dma_unmap_sg(d->dev, sg, nsg, direction);
361 return -1;
365 * This is the external request processing routine
367 static void do_viodasd_request(struct request_queue *q)
369 struct request *req;
372 * If we already have the maximum number of requests
373 * outstanding to OS/400 just bail out. We'll come
374 * back later.
376 while (num_req_outstanding < VIOMAXREQ) {
377 req = blk_fetch_request(q);
378 if (req == NULL)
379 return;
380 /* check that request contains a valid command */
381 if (req->cmd_type != REQ_TYPE_FS) {
382 viodasd_end_request(req, -EIO, blk_rq_sectors(req));
383 continue;
385 /* Try sending the request */
386 if (send_request(req) != 0)
387 viodasd_end_request(req, -EIO, blk_rq_sectors(req));
392 * Probe a single disk and fill in the viodasd_device structure
393 * for it.
395 static int probe_disk(struct viodasd_device *d)
397 HvLpEvent_Rc hvrc;
398 struct viodasd_waitevent we;
399 int dev_no = DEVICE_NO(d);
400 struct gendisk *g;
401 struct request_queue *q;
402 u16 flags = 0;
404 retry:
405 init_completion(&we.com);
407 /* Send the open event to OS/400 */
408 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
409 HvLpEvent_Type_VirtualIo,
410 viomajorsubtype_blockio | vioblockopen,
411 HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck,
412 viopath_sourceinst(viopath_hostLp),
413 viopath_targetinst(viopath_hostLp),
414 (u64)(unsigned long)&we, VIOVERSION << 16,
415 ((u64)dev_no << 48) | ((u64)flags<< 32),
416 0, 0, 0);
417 if (hvrc != 0) {
418 pr_warning("bad rc on HV open %d\n", (int)hvrc);
419 return 0;
422 wait_for_completion(&we.com);
424 if (we.rc != 0) {
425 if (flags != 0)
426 return 0;
427 /* try again with read only flag set */
428 flags = vioblockflags_ro;
429 goto retry;
431 if (we.max_disk > (MAX_DISKNO - 1)) {
432 printk_once(KERN_INFO pr_fmt("Only examining the first %d of %d disks connected\n"),
433 MAX_DISKNO, we.max_disk + 1);
436 /* Send the close event to OS/400. We DON'T expect a response */
437 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
438 HvLpEvent_Type_VirtualIo,
439 viomajorsubtype_blockio | vioblockclose,
440 HvLpEvent_AckInd_NoAck, HvLpEvent_AckType_ImmediateAck,
441 viopath_sourceinst(viopath_hostLp),
442 viopath_targetinst(viopath_hostLp),
443 0, VIOVERSION << 16,
444 ((u64)dev_no << 48) | ((u64)flags << 32),
445 0, 0, 0);
446 if (hvrc != 0) {
447 pr_warning("bad rc sending event to OS/400 %d\n", (int)hvrc);
448 return 0;
451 if (d->dev == NULL) {
452 /* this is when we reprobe for new disks */
453 if (vio_create_viodasd(dev_no) == NULL) {
454 pr_warning("cannot allocate virtual device for disk %d\n",
455 dev_no);
456 return 0;
459 * The vio_create_viodasd will have recursed into this
460 * routine with d->dev set to the new vio device and
461 * will finish the setup of the disk below.
463 return 1;
466 /* create the request queue for the disk */
467 spin_lock_init(&d->q_lock);
468 q = blk_init_queue(do_viodasd_request, &d->q_lock);
469 if (q == NULL) {
470 pr_warning("cannot allocate queue for disk %d\n", dev_no);
471 return 0;
473 g = alloc_disk(1 << PARTITION_SHIFT);
474 if (g == NULL) {
475 pr_warning("cannot allocate disk structure for disk %d\n",
476 dev_no);
477 blk_cleanup_queue(q);
478 return 0;
481 d->disk = g;
482 blk_queue_max_segments(q, VIOMAXBLOCKDMA);
483 blk_queue_max_hw_sectors(q, VIODASD_MAXSECTORS);
484 g->major = VIODASD_MAJOR;
485 g->first_minor = dev_no << PARTITION_SHIFT;
486 if (dev_no >= 26)
487 snprintf(g->disk_name, sizeof(g->disk_name),
488 VIOD_GENHD_NAME "%c%c",
489 'a' + (dev_no / 26) - 1, 'a' + (dev_no % 26));
490 else
491 snprintf(g->disk_name, sizeof(g->disk_name),
492 VIOD_GENHD_NAME "%c", 'a' + (dev_no % 26));
493 g->fops = &viodasd_fops;
494 g->queue = q;
495 g->private_data = d;
496 g->driverfs_dev = d->dev;
497 set_capacity(g, d->size >> 9);
499 pr_info("disk %d: %lu sectors (%lu MB) CHS=%d/%d/%d sector size %d%s\n",
500 dev_no, (unsigned long)(d->size >> 9),
501 (unsigned long)(d->size >> 20),
502 (int)d->cylinders, (int)d->tracks,
503 (int)d->sectors, (int)d->bytes_per_sector,
504 d->read_only ? " (RO)" : "");
506 /* register us in the global list */
507 add_disk(g);
508 return 1;
511 /* returns the total number of scatterlist elements converted */
512 static int block_event_to_scatterlist(const struct vioblocklpevent *bevent,
513 struct scatterlist *sg, int *total_len)
515 int i, numsg;
516 const struct rw_data *rw_data = &bevent->u.rw_data;
517 static const int offset =
518 offsetof(struct vioblocklpevent, u.rw_data.dma_info);
519 static const int element_size = sizeof(rw_data->dma_info[0]);
521 numsg = ((bevent->event.xSizeMinus1 + 1) - offset) / element_size;
522 if (numsg > VIOMAXBLOCKDMA)
523 numsg = VIOMAXBLOCKDMA;
525 *total_len = 0;
526 sg_init_table(sg, VIOMAXBLOCKDMA);
527 for (i = 0; (i < numsg) && (rw_data->dma_info[i].len > 0); ++i) {
528 sg_dma_address(&sg[i]) = rw_data->dma_info[i].token;
529 sg_dma_len(&sg[i]) = rw_data->dma_info[i].len;
530 *total_len += rw_data->dma_info[i].len;
532 return i;
536 * Restart all queues, starting with the one _after_ the disk given,
537 * thus reducing the chance of starvation of higher numbered disks.
539 static void viodasd_restart_all_queues_starting_from(int first_index)
541 int i;
543 for (i = first_index + 1; i < MAX_DISKNO; ++i)
544 if (viodasd_devices[i].disk)
545 blk_run_queue(viodasd_devices[i].disk->queue);
546 for (i = 0; i <= first_index; ++i)
547 if (viodasd_devices[i].disk)
548 blk_run_queue(viodasd_devices[i].disk->queue);
552 * For read and write requests, decrement the number of outstanding requests,
553 * Free the DMA buffers we allocated.
555 static int viodasd_handle_read_write(struct vioblocklpevent *bevent)
557 int num_sg, num_sect, pci_direction, total_len;
558 struct request *req;
559 struct scatterlist sg[VIOMAXBLOCKDMA];
560 struct HvLpEvent *event = &bevent->event;
561 unsigned long irq_flags;
562 struct viodasd_device *d;
563 int error;
564 spinlock_t *qlock;
566 num_sg = block_event_to_scatterlist(bevent, sg, &total_len);
567 num_sect = total_len >> 9;
568 if (event->xSubtype == (viomajorsubtype_blockio | vioblockread))
569 pci_direction = DMA_FROM_DEVICE;
570 else
571 pci_direction = DMA_TO_DEVICE;
572 req = (struct request *)bevent->event.xCorrelationToken;
573 d = req->rq_disk->private_data;
575 dma_unmap_sg(d->dev, sg, num_sg, pci_direction);
578 * Since this is running in interrupt mode, we need to make sure
579 * we're not stepping on any global I/O operations
581 spin_lock_irqsave(&viodasd_spinlock, irq_flags);
582 num_req_outstanding--;
583 spin_unlock_irqrestore(&viodasd_spinlock, irq_flags);
585 error = (event->xRc == HvLpEvent_Rc_Good) ? 0 : -EIO;
586 if (error) {
587 const struct vio_error_entry *err;
588 err = vio_lookup_rc(viodasd_err_table, bevent->sub_result);
589 pr_warning("read/write error %d:0x%04x (%s)\n",
590 event->xRc, bevent->sub_result, err->msg);
591 num_sect = blk_rq_sectors(req);
593 qlock = req->q->queue_lock;
594 spin_lock_irqsave(qlock, irq_flags);
595 viodasd_end_request(req, error, num_sect);
596 spin_unlock_irqrestore(qlock, irq_flags);
598 /* Finally, try to get more requests off of this device's queue */
599 viodasd_restart_all_queues_starting_from(DEVICE_NO(d));
601 return 0;
604 /* This routine handles incoming block LP events */
605 static void handle_block_event(struct HvLpEvent *event)
607 struct vioblocklpevent *bevent = (struct vioblocklpevent *)event;
608 struct viodasd_waitevent *pwe;
610 if (event == NULL)
611 /* Notification that a partition went away! */
612 return;
613 /* First, we should NEVER get an int here...only acks */
614 if (hvlpevent_is_int(event)) {
615 pr_warning("Yikes! got an int in viodasd event handler!\n");
616 if (hvlpevent_need_ack(event)) {
617 event->xRc = HvLpEvent_Rc_InvalidSubtype;
618 HvCallEvent_ackLpEvent(event);
622 switch (event->xSubtype & VIOMINOR_SUBTYPE_MASK) {
623 case vioblockopen:
625 * Handle a response to an open request. We get all the
626 * disk information in the response, so update it. The
627 * correlation token contains a pointer to a waitevent
628 * structure that has a completion in it. update the
629 * return code in the waitevent structure and post the
630 * completion to wake up the guy who sent the request
632 pwe = (struct viodasd_waitevent *)event->xCorrelationToken;
633 pwe->rc = event->xRc;
634 pwe->sub_result = bevent->sub_result;
635 if (event->xRc == HvLpEvent_Rc_Good) {
636 const struct open_data *data = &bevent->u.open_data;
637 struct viodasd_device *device =
638 &viodasd_devices[bevent->disk];
639 device->read_only =
640 bevent->flags & vioblockflags_ro;
641 device->size = data->disk_size;
642 device->cylinders = data->cylinders;
643 device->tracks = data->tracks;
644 device->sectors = data->sectors;
645 device->bytes_per_sector = data->bytes_per_sector;
646 pwe->max_disk = data->max_disk;
648 complete(&pwe->com);
649 break;
650 case vioblockclose:
651 break;
652 case vioblockread:
653 case vioblockwrite:
654 viodasd_handle_read_write(bevent);
655 break;
657 default:
658 pr_warning("invalid subtype!");
659 if (hvlpevent_need_ack(event)) {
660 event->xRc = HvLpEvent_Rc_InvalidSubtype;
661 HvCallEvent_ackLpEvent(event);
667 * Get the driver to reprobe for more disks.
669 static ssize_t probe_disks(struct device_driver *drv, const char *buf,
670 size_t count)
672 struct viodasd_device *d;
674 for (d = viodasd_devices; d < &viodasd_devices[MAX_DISKNO]; d++) {
675 if (d->disk == NULL)
676 probe_disk(d);
678 return count;
680 static DRIVER_ATTR(probe, S_IWUSR, NULL, probe_disks);
682 static int viodasd_probe(struct vio_dev *vdev, const struct vio_device_id *id)
684 struct viodasd_device *d = &viodasd_devices[vdev->unit_address];
686 d->dev = &vdev->dev;
687 if (!probe_disk(d))
688 return -ENODEV;
689 return 0;
692 static int viodasd_remove(struct vio_dev *vdev)
694 struct viodasd_device *d;
696 d = &viodasd_devices[vdev->unit_address];
697 if (d->disk) {
698 del_gendisk(d->disk);
699 blk_cleanup_queue(d->disk->queue);
700 put_disk(d->disk);
701 d->disk = NULL;
703 d->dev = NULL;
704 return 0;
708 * viodasd_device_table: Used by vio.c to match devices that we
709 * support.
711 static struct vio_device_id viodasd_device_table[] __devinitdata = {
712 { "block", "IBM,iSeries-viodasd" },
713 { "", "" }
715 MODULE_DEVICE_TABLE(vio, viodasd_device_table);
717 static struct vio_driver viodasd_driver = {
718 .id_table = viodasd_device_table,
719 .probe = viodasd_probe,
720 .remove = viodasd_remove,
721 .driver = {
722 .name = "viodasd",
723 .owner = THIS_MODULE,
727 static int need_delete_probe;
730 * Initialize the whole device driver. Handle module and non-module
731 * versions
733 static int __init viodasd_init(void)
735 int rc;
737 if (!firmware_has_feature(FW_FEATURE_ISERIES)) {
738 rc = -ENODEV;
739 goto early_fail;
742 /* Try to open to our host lp */
743 if (viopath_hostLp == HvLpIndexInvalid)
744 vio_set_hostlp();
746 if (viopath_hostLp == HvLpIndexInvalid) {
747 pr_warning("invalid hosting partition\n");
748 rc = -EIO;
749 goto early_fail;
752 pr_info("vers " VIOD_VERS ", hosting partition %d\n", viopath_hostLp);
754 /* register the block device */
755 rc = register_blkdev(VIODASD_MAJOR, VIOD_GENHD_NAME);
756 if (rc) {
757 pr_warning("Unable to get major number %d for %s\n",
758 VIODASD_MAJOR, VIOD_GENHD_NAME);
759 goto early_fail;
761 /* Actually open the path to the hosting partition */
762 rc = viopath_open(viopath_hostLp, viomajorsubtype_blockio,
763 VIOMAXREQ + 2);
764 if (rc) {
765 pr_warning("error opening path to host partition %d\n",
766 viopath_hostLp);
767 goto unregister_blk;
770 /* Initialize our request handler */
771 vio_setHandler(viomajorsubtype_blockio, handle_block_event);
773 rc = vio_register_driver(&viodasd_driver);
774 if (rc) {
775 pr_warning("vio_register_driver failed\n");
776 goto unset_handler;
780 * If this call fails, it just means that we cannot dynamically
781 * add virtual disks, but the driver will still work fine for
782 * all existing disk, so ignore the failure.
784 if (!driver_create_file(&viodasd_driver.driver, &driver_attr_probe))
785 need_delete_probe = 1;
787 return 0;
789 unset_handler:
790 vio_clearHandler(viomajorsubtype_blockio);
791 viopath_close(viopath_hostLp, viomajorsubtype_blockio, VIOMAXREQ + 2);
792 unregister_blk:
793 unregister_blkdev(VIODASD_MAJOR, VIOD_GENHD_NAME);
794 early_fail:
795 return rc;
797 module_init(viodasd_init);
799 void __exit viodasd_exit(void)
801 if (need_delete_probe)
802 driver_remove_file(&viodasd_driver.driver, &driver_attr_probe);
803 vio_unregister_driver(&viodasd_driver);
804 vio_clearHandler(viomajorsubtype_blockio);
805 viopath_close(viopath_hostLp, viomajorsubtype_blockio, VIOMAXREQ + 2);
806 unregister_blkdev(VIODASD_MAJOR, VIOD_GENHD_NAME);
808 module_exit(viodasd_exit);