patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / block / viodasd.c
index ada4336..fdac6e3 100644 (file)
 #include <linux/string.h>
 #include <linux/dma-mapping.h>
 #include <linux/completion.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
 
 #include <asm/uaccess.h>
+#include <asm/vio.h>
 #include <asm/iSeries/HvTypes.h>
 #include <asm/iSeries/HvLpEvent.h>
 #include <asm/iSeries/HvLpConfig.h>
@@ -175,6 +178,13 @@ static int viodasd_open(struct inode *ino, struct file *fil)
        struct viodasd_device *d = ino->i_bdev->bd_disk->private_data;
        HvLpEvent_Rc hvrc;
        struct viodasd_waitevent we;
+       u16 flags = 0;
+
+       if (d->read_only) {
+               if ((fil != NULL) && (fil->f_mode & FMODE_WRITE))
+                       return -EROFS;
+               flags = vioblockflags_ro;
+       }
 
        init_completion(&we.com);
 
@@ -186,7 +196,7 @@ static int viodasd_open(struct inode *ino, struct file *fil)
                        viopath_sourceinst(viopath_hostLp),
                        viopath_targetinst(viopath_hostLp),
                        (u64)(unsigned long)&we, VIOVERSION << 16,
-                       ((u64)DEVICE_NO(d) << 48) /* | ((u64)flags << 32) */,
+                       ((u64)DEVICE_NO(d) << 48) | ((u64)flags << 32),
                        0, 0, 0);
        if (hvrc != 0) {
                printk(VIOD_KERN_WARNING "HV open failed %d\n", (int)hvrc);
@@ -456,7 +466,9 @@ static void probe_disk(struct viodasd_device *d)
        int dev_no = DEVICE_NO(d);
        struct gendisk *g;
        struct request_queue *q;
+       u16 flags = 0;
 
+retry:
        init_completion(&we.com);
 
        /* Send the open event to OS/400 */
@@ -467,7 +479,7 @@ static void probe_disk(struct viodasd_device *d)
                        viopath_sourceinst(viopath_hostLp),
                        viopath_targetinst(viopath_hostLp),
                        (u64)(unsigned long)&we, VIOVERSION << 16,
-                       ((u64)dev_no << 48) | ((u64)vioblockflags_ro << 32),
+                       ((u64)dev_no << 48) | ((u64)flags<< 32),
                        0, 0, 0);
        if (hvrc != 0) {
                printk(VIOD_KERN_WARNING "bad rc on HV open %d\n", (int)hvrc);
@@ -476,8 +488,13 @@ static void probe_disk(struct viodasd_device *d)
 
        wait_for_completion(&we.com);
 
-       if (we.rc != 0)
-               return;
+       if (we.rc != 0) {
+               if (flags != 0)
+                       return;
+               /* try again with read only flag set */
+               flags = vioblockflags_ro;
+               goto retry;
+       }
        if (we.max_disk > (MAX_DISKNO - 1)) {
                static int warned;
 
@@ -498,19 +515,13 @@ static void probe_disk(struct viodasd_device *d)
                        viopath_sourceinst(viopath_hostLp),
                        viopath_targetinst(viopath_hostLp),
                        0, VIOVERSION << 16,
-                       ((u64)dev_no << 48) | ((u64)vioblockflags_ro << 32),
+                       ((u64)dev_no << 48) | ((u64)flags << 32),
                        0, 0, 0);
        if (hvrc != 0) {
                printk(VIOD_KERN_WARNING
                       "bad rc sending event to OS/400 %d\n", (int)hvrc);
                return;
        }
-       printk(VIOD_KERN_INFO "disk %d: %lu sectors (%lu MB) "
-                       "CHS=%d/%d/%d sector size %d\n",
-                       dev_no, (unsigned long)(d->size >> 9),
-                       (unsigned long)(d->size >> 20),
-                       (int)d->cylinders, (int)d->tracks,
-                       (int)d->sectors, (int)d->bytes_per_sector);
        /* create the request queue for the disk */
        spin_lock_init(&d->q_lock);
        q = blk_init_queue(do_viodasd_request, &d->q_lock);
@@ -548,6 +559,14 @@ static void probe_disk(struct viodasd_device *d)
        g->private_data = d;
        set_capacity(g, d->size >> 9);
 
+       printk(VIOD_KERN_INFO "disk %d: %lu sectors (%lu MB) "
+                       "CHS=%d/%d/%d sector size %d%s\n",
+                       dev_no, (unsigned long)(d->size >> 9),
+                       (unsigned long)(d->size >> 20),
+                       (int)d->cylinders, (int)d->tracks,
+                       (int)d->sectors, (int)d->bytes_per_sector,
+                       d->read_only ? " (RO)" : "");
+
        /* register us in the global list */
        add_disk(g);
 }
@@ -709,6 +728,26 @@ static void handle_block_event(struct HvLpEvent *event)
        }
 }
 
+/*
+ * Get the driver to reprobe for more disks.
+ */
+static ssize_t probe_disks(struct device_driver *drv, const char *buf,
+               size_t count)
+{
+       struct viodasd_device *d;
+
+       for (d = viodasd_devices; d < &viodasd_devices[MAX_DISKNO]; d++) {
+               if (d->disk == NULL)
+                       probe_disk(d);
+       }
+       return count;
+}
+static DRIVER_ATTR(probe, S_IWUSR, NULL, probe_disks)
+
+static struct vio_driver viodasd_driver = {
+       .name = "viodasd"
+};
+
 /*
  * Initialize the whole device driver.  Handle module and non-module
  * versions
@@ -752,6 +791,9 @@ static int __init viodasd_init(void)
        for (i = 0; i < MAX_DISKNO; i++)
                probe_disk(&viodasd_devices[i]);
 
+       vio_register_driver(&viodasd_driver);   /* FIX ME - error checking */
+       driver_create_file(&viodasd_driver.driver, &driver_attr_probe);
+
        return 0;
 }
 module_init(viodasd_init);
@@ -761,6 +803,9 @@ void viodasd_exit(void)
        int i;
        struct viodasd_device *d;
 
+       driver_remove_file(&viodasd_driver.driver, &driver_attr_probe);
+       vio_unregister_driver(&viodasd_driver);
+
         for (i = 0; i < MAX_DISKNO; i++) {
                d = &viodasd_devices[i];
                if (d->disk) {