Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / drivers / cdrom / viocd.c
index 0509ae2..54ca931 100644 (file)
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 
-#include <asm/bug.h>
-
 #include <asm/vio.h>
 #include <asm/scatterlist.h>
-#include <asm/iSeries/HvTypes.h>
-#include <asm/iSeries/HvLpEvent.h>
-#include <asm/iSeries/vio.h>
+#include <asm/iseries/hv_types.h>
+#include <asm/iseries/hv_lp_event.h>
+#include <asm/iseries/vio.h>
 
 #define VIOCD_DEVICE                   "iseries/vcd"
-#define VIOCD_DEVICE_DEVFS             "iseries/vcd"
 
 #define VIOCD_VERS "1.06"
 
@@ -154,7 +151,6 @@ static struct disk_info viocd_diskinfo[VIOCD_MAX_CD];
 
 #define DEVICE_NR(di)  ((di) - &viocd_diskinfo[0])
 
-static request_queue_t *viocd_queue;
 static spinlock_t viocd_reqlock;
 
 #define MAX_CD_REQ     1
@@ -489,6 +485,20 @@ static int viocd_packet(struct cdrom_device_info *cdi,
                                         & (CDC_DVD_RAM | CDC_RAM)) != 0;
                }
                break;
+       case GPCMD_GET_CONFIGURATION:
+               if (cgc->cmd[3] == CDF_RWRT) {
+                       struct rwrt_feature_desc *rfd = (struct rwrt_feature_desc *)(cgc->buffer + sizeof(struct feature_header));
+
+                       if ((buflen >=
+                            (sizeof(struct feature_header) + sizeof(*rfd))) &&
+                           (cdi->ops->capability & ~cdi->mask
+                            & (CDC_DVD_RAM | CDC_RAM))) {
+                               rfd->feature_code = cpu_to_be16(CDF_RWRT);
+                               rfd->curr = 1;
+                               ret = 0;
+                       }
+               }
+               break;
        default:
                if (cgc->sense) {
                        /* indicate Unknown code */
@@ -503,6 +513,18 @@ static int viocd_packet(struct cdrom_device_info *cdi,
        return ret;
 }
 
+static void restart_all_queues(int first_index)
+{
+       int i;
+
+       for (i = first_index + 1; i < viocd_numdev; i++)
+               if (viocd_diskinfo[i].viocd_disk)
+                       blk_run_queue(viocd_diskinfo[i].viocd_disk->queue);
+       for (i = 0; i <= first_index; i++)
+               if (viocd_diskinfo[i].viocd_disk)
+                       blk_run_queue(viocd_diskinfo[i].viocd_disk->queue);
+}
+
 /* This routine handles incoming CD LP events */
 static void vio_handle_cd_event(struct HvLpEvent *event)
 {
@@ -517,10 +539,10 @@ static void vio_handle_cd_event(struct HvLpEvent *event)
                /* Notification that a partition went away! */
                return;
        /* First, we should NEVER get an int here...only acks */
-       if (event->xFlags.xFunction == HvLpEvent_Function_Int) {
+       if (hvlpevent_is_int(event)) {
                printk(VIOCD_KERN_WARNING
                                "Yikes! got an int in viocd event handler!\n");
-               if (event->xFlags.xAckInd == HvLpEvent_AckInd_DoAck) {
+               if (hvlpevent_need_ack(event)) {
                        event->xRc = HvLpEvent_Rc_InvalidSubtype;
                        HvCallEvent_ackLpEvent(event);
                }
@@ -532,7 +554,7 @@ static void vio_handle_cd_event(struct HvLpEvent *event)
        case viocdopen:
                if (event->xRc == 0) {
                        di = &viocd_diskinfo[bevent->disk];
-                       blk_queue_hardsect_size(viocd_queue,
+                       blk_queue_hardsect_size(di->viocd_disk->queue,
                                        bevent->block_size);
                        set_capacity(di->viocd_disk,
                                        bevent->media_size *
@@ -584,14 +606,14 @@ return_complete:
 
                /* restart handling of incoming requests */
                spin_unlock_irqrestore(&viocd_reqlock, flags);
-               blk_run_queue(viocd_queue);
+               restart_all_queues(bevent->disk);
                break;
 
        default:
                printk(VIOCD_KERN_WARNING
                                "message with invalid subtype %0x04X!\n",
                                event->xSubtype & VIOMINOR_SUBTYPE_MASK);
-               if (event->xFlags.xAckInd == HvLpEvent_AckInd_DoAck) {
+               if (hvlpevent_need_ack(event)) {
                        event->xRc = HvLpEvent_Rc_InvalidSubtype;
                        HvCallEvent_ackLpEvent(event);
                }
@@ -604,7 +626,7 @@ static struct cdrom_device_ops viocd_dops = {
        .media_changed = viocd_media_changed,
        .lock_door = viocd_lock_door,
        .generic_packet = viocd_packet,
-       .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | CDC_SELECT_SPEED | CDC_SELECT_DISC | CDC_MULTI_SESSION | CDC_MCN | CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO | CDC_RESET | CDC_IOCTLS | CDC_DRIVE_STATUS | CDC_GENERIC_PACKET | CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | CDC_DVD_RAM | CDC_RAM
+       .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | CDC_SELECT_SPEED | CDC_SELECT_DISC | CDC_MULTI_SESSION | CDC_MCN | CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO | CDC_RESET | CDC_DRIVE_STATUS | CDC_GENERIC_PACKET | CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | CDC_DVD_RAM | CDC_RAM
 };
 
 static int __init find_capability(const char *type)
@@ -624,6 +646,7 @@ static int viocd_probe(struct vio_dev *vdev, const struct vio_device_id *id)
        struct disk_info *d;
        struct cdrom_device_info *c;
        struct cdrom_info *ci;
+       struct request_queue *q;
 
        deviceno = vdev->unit_address;
        if (deviceno >= viocd_numdev)
@@ -643,25 +666,31 @@ static int viocd_probe(struct vio_dev *vdev, const struct vio_device_id *id)
        if (register_cdrom(c) != 0) {
                printk(VIOCD_KERN_WARNING "Cannot register viocd CD-ROM %s!\n",
                                c->name);
-               return 0;
+               goto out;
        }
        printk(VIOCD_KERN_INFO "cd %s is iSeries resource %10.10s "
                        "type %4.4s, model %3.3s\n",
                        c->name, ci->rsrcname, ci->type, ci->model);
+       q = blk_init_queue(do_viocd_request, &viocd_reqlock);
+       if (q == NULL) {
+               printk(VIOCD_KERN_WARNING "Cannot allocate queue for %s!\n",
+                               c->name);
+               goto out_unregister_cdrom;
+       }
        gendisk = alloc_disk(1);
        if (gendisk == NULL) {
                printk(VIOCD_KERN_WARNING "Cannot create gendisk for %s!\n",
                                c->name);
-               unregister_cdrom(c);
-               return 0;
+               goto out_cleanup_queue;
        }
        gendisk->major = VIOCD_MAJOR;
        gendisk->first_minor = deviceno;
        strncpy(gendisk->disk_name, c->name,
                        sizeof(gendisk->disk_name));
-       snprintf(gendisk->devfs_name, sizeof(gendisk->devfs_name),
-                       VIOCD_DEVICE_DEVFS "%d", deviceno);
-       gendisk->queue = viocd_queue;
+       blk_queue_max_hw_segments(q, 1);
+       blk_queue_max_phys_segments(q, 1);
+       blk_queue_max_sectors(q, 4096 / 512);
+       gendisk->queue = q;
        gendisk->fops = &viocd_fops;
        gendisk->flags = GENHD_FL_CD|GENHD_FL_REMOVABLE;
        set_capacity(gendisk, 0);
@@ -670,8 +699,14 @@ static int viocd_probe(struct vio_dev *vdev, const struct vio_device_id *id)
        d->dev = &vdev->dev;
        gendisk->driverfs_dev = d->dev;
        add_disk(gendisk);
-
        return 0;
+
+out_cleanup_queue:
+       blk_cleanup_queue(q);
+out_unregister_cdrom:
+       unregister_cdrom(c);
+out:
+       return -ENODEV;
 }
 
 static int viocd_remove(struct vio_dev *vdev)
@@ -683,6 +718,7 @@ static int viocd_remove(struct vio_dev *vdev)
                                "Cannot unregister viocd CD-ROM %s!\n",
                                d->viocd_info.name);
        del_gendisk(d->viocd_disk);
+       blk_cleanup_queue(d->viocd_disk->queue);
        put_disk(d->viocd_disk);
        return 0;
 }
@@ -692,16 +728,19 @@ static int viocd_remove(struct vio_dev *vdev)
  * support.
  */
 static struct vio_device_id viocd_device_table[] __devinitdata = {
-       { "viocd", "" },
-       { 0, }
+       { "block", "IBM,iSeries-viocd" },
+       { "", "" }
 };
-
 MODULE_DEVICE_TABLE(vio, viocd_device_table);
+
 static struct vio_driver viocd_driver = {
-       .name = "viocd",
        .id_table = viocd_device_table,
        .probe = viocd_probe,
-       .remove = viocd_remove
+       .remove = viocd_remove,
+       .driver = {
+               .name = "viocd",
+               .owner = THIS_MODULE,
+       }
 };
 
 static int __init viocd_init(void)
@@ -738,22 +777,12 @@ static int __init viocd_init(void)
        vio_setHandler(viomajorsubtype_cdio, vio_handle_cd_event);
 
        get_viocd_info();
-       if (viocd_numdev == 0)
-               goto out_undo_vio;
 
        spin_lock_init(&viocd_reqlock);
-       viocd_queue = blk_init_queue(do_viocd_request, &viocd_reqlock);
-       if (viocd_queue == NULL) {
-               ret = -ENOMEM;
-               goto out_free_info;
-       }
-       blk_queue_max_hw_segments(viocd_queue, 1);
-       blk_queue_max_phys_segments(viocd_queue, 1);
-       blk_queue_max_sectors(viocd_queue, 4096 / 512);
 
        ret = vio_register_driver(&viocd_driver);
        if (ret)
-               goto out_cleanup_queue;
+               goto out_free_info;
 
        e = create_proc_entry("iSeries/viocd", S_IFREG|S_IRUGO, NULL);
        if (e) {
@@ -763,13 +792,10 @@ static int __init viocd_init(void)
 
        return 0;
 
-out_cleanup_queue:
-       blk_cleanup_queue(viocd_queue);
 out_free_info:
        dma_free_coherent(iSeries_vio_dev,
                        sizeof(*viocd_unitinfo) * VIOCD_MAX_CD,
                        viocd_unitinfo, unitinfo_dmaaddr);
-out_undo_vio:
        vio_clearHandler(viomajorsubtype_cdio);
        viopath_close(viopath_hostLp, viomajorsubtype_cdio, MAX_CD_REQ + 2);
 out_unregister:
@@ -781,7 +807,6 @@ static void __exit viocd_exit(void)
 {
        remove_proc_entry("iSeries/viocd", NULL);
        vio_unregister_driver(&viocd_driver);
-       blk_cleanup_queue(viocd_queue);
        if (viocd_unitinfo != NULL)
                dma_free_coherent(iSeries_vio_dev,
                                sizeof(*viocd_unitinfo) * VIOCD_MAX_CD,