[SCSI] nsp_cs: remove old scsi code
[safe/jmp/linux-2.6] / drivers / scsi / ide-scsi.c
index 2e2486b..8f6b5bf 100644 (file)
@@ -34,7 +34,6 @@
 #define IDESCSI_VERSION "0.92"
 
 #include <linux/module.h>
-#include <linux/config.h>
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/kernel.h>
@@ -46,6 +45,8 @@
 #include <linux/slab.h>
 #include <linux/ide.h>
 #include <linux/scatterlist.h>
+#include <linux/delay.h>
+#include <linux/mutex.h>
 
 #include <asm/io.h>
 #include <asm/bitops.h>
@@ -108,7 +109,8 @@ typedef struct ide_scsi_obj {
        unsigned long log;                      /* log flags */
 } idescsi_scsi_t;
 
-static DECLARE_MUTEX(idescsi_ref_sem);
+static DEFINE_MUTEX(idescsi_ref_mutex);
+static int idescsi_nocd;                       /* Set by module param to skip cd */
 
 #define ide_scsi_g(disk) \
        container_of((disk)->private_data, struct ide_scsi_obj, driver)
@@ -117,19 +119,19 @@ static struct ide_scsi_obj *ide_scsi_get(struct gendisk *disk)
 {
        struct ide_scsi_obj *scsi = NULL;
 
-       down(&idescsi_ref_sem);
+       mutex_lock(&idescsi_ref_mutex);
        scsi = ide_scsi_g(disk);
        if (scsi)
                scsi_host_get(scsi->host);
-       up(&idescsi_ref_sem);
+       mutex_unlock(&idescsi_ref_mutex);
        return scsi;
 }
 
 static void ide_scsi_put(struct ide_scsi_obj *scsi)
 {
-       down(&idescsi_ref_sem);
+       mutex_lock(&idescsi_ref_mutex);
        scsi_host_put(scsi->host);
-       up(&idescsi_ref_sem);
+       mutex_unlock(&idescsi_ref_mutex);
 }
 
 static inline idescsi_scsi_t *scsihost_to_idescsi(struct Scsi_Host *host)
@@ -179,8 +181,21 @@ static void idescsi_input_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigne
                        return;
                }
                count = min(pc->sg->length - pc->b_count, bcount);
-               buf = page_address(pc->sg->page) + pc->sg->offset;
-               drive->hwif->atapi_input_bytes(drive, buf + pc->b_count, count);
+               if (PageHighMem(pc->sg->page)) {
+                       unsigned long flags;
+
+                       local_irq_save(flags);
+                       buf = kmap_atomic(pc->sg->page, KM_IRQ0) +
+                                       pc->sg->offset;
+                       drive->hwif->atapi_input_bytes(drive,
+                                               buf + pc->b_count, count);
+                       kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
+                       local_irq_restore(flags);
+               } else {
+                       buf = page_address(pc->sg->page) + pc->sg->offset;
+                       drive->hwif->atapi_input_bytes(drive,
+                                               buf + pc->b_count, count);
+               }
                bcount -= count; pc->b_count += count;
                if (pc->b_count == pc->sg->length) {
                        pc->sg++;
@@ -201,8 +216,21 @@ static void idescsi_output_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsign
                        return;
                }
                count = min(pc->sg->length - pc->b_count, bcount);
-               buf = page_address(pc->sg->page) + pc->sg->offset;
-               drive->hwif->atapi_output_bytes(drive, buf + pc->b_count, count);
+               if (PageHighMem(pc->sg->page)) {
+                       unsigned long flags;
+
+                       local_irq_save(flags);
+                       buf = kmap_atomic(pc->sg->page, KM_IRQ0) +
+                                               pc->sg->offset;
+                       drive->hwif->atapi_output_bytes(drive,
+                                               buf + pc->b_count, count);
+                       kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
+                       local_irq_restore(flags);
+               } else {
+                       buf = page_address(pc->sg->page) + pc->sg->offset;
+                       drive->hwif->atapi_output_bytes(drive,
+                                               buf + pc->b_count, count);
+               }
                bcount -= count; pc->b_count += count;
                if (pc->b_count == pc->sg->length) {
                        pc->sg++;
@@ -304,9 +332,9 @@ static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_co
        rq = kmalloc (sizeof (struct request), GFP_ATOMIC);
        buf = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC);
        if (pc == NULL || rq == NULL || buf == NULL) {
-               if (pc) kfree(pc);
-               if (rq) kfree(rq);
-               if (buf) kfree(buf);
+               kfree(buf);
+               kfree(rq);
+               kfree(pc);
                return -ENOMEM;
        }
        memset (pc, 0, sizeof (idescsi_pc_t));
@@ -317,7 +345,7 @@ static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_co
        pc->buffer = buf;
        pc->c[0] = REQUEST_SENSE;
        pc->c[4] = pc->request_transfer = pc->buffer_size = SCSI_SENSE_BUFFERSIZE;
-       rq->flags = REQ_SENSE;
+       rq->cmd_type = REQ_TYPE_SENSE;
        pc->timeout = jiffies + WAIT_READY;
        /* NOTE! Save the failed packet command in "rq->buffer" */
        rq->buffer = (void *) failed_command->special;
@@ -368,14 +396,15 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
        int log = test_bit(IDESCSI_LOG_CMD, &scsi->log);
        struct Scsi_Host *host;
        u8 *scsi_buf;
+       int errors = rq->errors;
        unsigned long flags;
 
-       if (!(rq->flags & (REQ_SPECIAL|REQ_SENSE))) {
+       if (!blk_special_request(rq) && !blk_sense_request(rq)) {
                ide_end_request(drive, uptodate, nrsecs);
                return 0;
        }
        ide_end_drive_cmd (drive, 0, 0);
-       if (rq->flags & REQ_SENSE) {
+       if (blk_sense_request(rq)) {
                idescsi_pc_t *opc = (idescsi_pc_t *) rq->buffer;
                if (log) {
                        printk ("ide-scsi: %s: wrap up check %lu, rst = ", drive->name, opc->scsi_cmd->serial_number);
@@ -394,11 +423,11 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
                        printk (KERN_WARNING "ide-scsi: %s: timed out for %lu\n",
                                        drive->name, pc->scsi_cmd->serial_number);
                pc->scsi_cmd->result = DID_TIME_OUT << 16;
-       } else if (rq->errors >= ERROR_MAX) {
+       } else if (errors >= ERROR_MAX) {
                pc->scsi_cmd->result = DID_ERROR << 16;
                if (log)
                        printk ("ide-scsi: %s: I/O error for %lu\n", drive->name, pc->scsi_cmd->serial_number);
-       } else if (rq->errors) {
+       } else if (errors) {
                if (log)
                        printk ("ide-scsi: %s: check condition for %lu\n", drive->name, pc->scsi_cmd->serial_number);
                if (!idescsi_check_condition(drive, rq))
@@ -489,7 +518,7 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
                /* No more interrupts */
                if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
                        printk (KERN_INFO "Packet command completed, %d bytes transferred\n", pc->actually_transferred);
-               local_irq_enable();
+               local_irq_enable_in_hardirq();
                if (status.b.check)
                        rq->errors++;
                idescsi_end_request (drive, 1, 0);
@@ -571,8 +600,7 @@ static ide_startstop_t idescsi_transfer_pc(ide_drive_t *drive)
                                "issuing a packet command\n");
                return ide_do_reset (drive);
        }
-       if (HWGROUP(drive)->handler != NULL)
-               BUG();
+       BUG_ON(HWGROUP(drive)->handler != NULL);
        /* Set the interrupt routine */
        ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry);
        /* Send the actual packet */
@@ -662,8 +690,7 @@ static ide_startstop_t idescsi_issue_pc (ide_drive_t *drive, idescsi_pc_t *pc)
                set_bit(PC_DMA_OK, &pc->flags);
 
        if (test_bit(IDESCSI_DRQ_INTERRUPT, &scsi->flags)) {
-               if (HWGROUP(drive)->handler != NULL)
-                       BUG();
+               BUG_ON(HWGROUP(drive)->handler != NULL);
                ide_set_handler(drive, &idescsi_transfer_pc,
                                get_timeout(pc), idescsi_expiry);
                /* Issue the packet command */
@@ -682,11 +709,11 @@ static ide_startstop_t idescsi_issue_pc (ide_drive_t *drive, idescsi_pc_t *pc)
 static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *rq, sector_t block)
 {
 #if IDESCSI_DEBUG_LOG
-       printk (KERN_INFO "rq_status: %d, dev: %s, cmd: %x, errors: %d\n",rq->rq_status, rq->rq_disk->disk_name,rq->cmd[0],rq->errors);
+       printk (KERN_INFO "dev: %s, cmd: %x, errors: %d\n", rq->rq_disk->disk_name,rq->cmd[0],rq->errors);
        printk (KERN_INFO "sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n",rq->sector,rq->nr_sectors,rq->current_nr_sectors);
 #endif /* IDESCSI_DEBUG_LOG */
 
-       if (rq->flags & (REQ_SPECIAL|REQ_SENSE)) {
+       if (blk_sense_request(rq) || blk_special_request(rq)) {
                return idescsi_issue_pc (drive, (idescsi_pc_t *) rq->special);
        }
        blk_dump_rq_flags(rq, "ide-scsi: unsup command");
@@ -713,7 +740,6 @@ static void idescsi_add_settings(ide_drive_t *drive)
  */
 static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi)
 {
-       DRIVER(drive)->busy++;
        if (drive->id && (drive->id->config & 0x0060) == 0x20)
                set_bit (IDESCSI_DRQ_INTERRUPT, &scsi->flags);
        set_bit(IDESCSI_TRANSFORM, &scsi->transform);
@@ -722,17 +748,15 @@ static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi)
        set_bit(IDESCSI_LOG_CMD, &scsi->log);
 #endif /* IDESCSI_DEBUG_LOG */
        idescsi_add_settings(drive);
-       DRIVER(drive)->busy--;
 }
 
-static int idescsi_cleanup (ide_drive_t *drive)
+static void ide_scsi_remove(ide_drive_t *drive)
 {
        struct Scsi_Host *scsihost = drive->driver_data;
        struct ide_scsi_obj *scsi = scsihost_to_idescsi(scsihost);
        struct gendisk *g = scsi->disk;
 
-       if (ide_unregister_subdriver(drive))
-               return 1;
+       ide_unregister_subdriver(drive, scsi->driver);
 
        ide_unregister_region(g);
 
@@ -742,11 +766,9 @@ static int idescsi_cleanup (ide_drive_t *drive)
 
        scsi_remove_host(scsihost);
        ide_scsi_put(scsi);
-
-       return 0;
 }
 
-static int idescsi_attach(ide_drive_t *drive);
+static int ide_scsi_probe(ide_drive_t *);
 
 #ifdef CONFIG_PROC_FS
 static ide_proc_entry_t idescsi_proc[] = {
@@ -757,24 +779,22 @@ static ide_proc_entry_t idescsi_proc[] = {
 # define idescsi_proc  NULL
 #endif
 
-/*
- *     IDE subdriver functions, registered with ide.c
- */
 static ide_driver_t idescsi_driver = {
-       .owner                  = THIS_MODULE,
-       .name                   = "ide-scsi",
+       .gen_driver = {
+               .owner          = THIS_MODULE,
+               .name           = "ide-scsi",
+               .bus            = &ide_bus_type,
+       },
+       .probe                  = ide_scsi_probe,
+       .remove                 = ide_scsi_remove,
        .version                = IDESCSI_VERSION,
        .media                  = ide_scsi,
-       .busy                   = 0,
        .supports_dsc_overlap   = 0,
        .proc                   = idescsi_proc,
-       .attach                 = idescsi_attach,
-       .cleanup                = idescsi_cleanup,
        .do_request             = idescsi_do_request,
        .end_request            = idescsi_end_request,
        .error                  = idescsi_atapi_error,
        .abort                  = idescsi_atapi_abort,
-       .drives                 = LIST_HEAD_INIT(idescsi_driver.drives),
 };
 
 static int idescsi_ide_open(struct inode *inode, struct file *filp)
@@ -821,8 +841,6 @@ static struct block_device_operations idescsi_ops = {
        .ioctl          = idescsi_ide_ioctl,
 };
 
-static int idescsi_attach(ide_drive_t *drive);
-
 static int idescsi_slave_configure(struct scsi_device * sdp)
 {
        /* Configure detected device */
@@ -860,7 +878,7 @@ static inline int should_transform(ide_drive_t *drive, struct scsi_cmnd *cmd)
        struct gendisk *disk = cmd->request->rq_disk;
 
        if (disk) {
-               struct Scsi_Device_Template **p = disk->private_data;
+               struct struct scsi_device_Template **p = disk->private_data;
                if (strcmp((*p)->scsi_driverfs_driver.name, "sg") == 0)
                        return test_bit(IDESCSI_SG_TRANSFORM, &scsi->transform);
        }
@@ -878,7 +896,7 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
        idescsi_pc_t *pc = NULL;
 
        if (!drive) {
-               printk (KERN_ERR "ide-scsi: drive id %d not present\n", cmd->device->id);
+               scmd_printk (KERN_ERR, cmd, "drive not present\n");
                goto abort;
        }
        scsi = drive_to_idescsi(drive);
@@ -921,15 +939,15 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
 
        ide_init_drive_cmd (rq);
        rq->special = (char *) pc;
-       rq->flags = REQ_SPECIAL;
+       rq->cmd_type = REQ_TYPE_SPECIAL;
        spin_unlock_irq(host->host_lock);
        rq->rq_disk = scsi->disk;
        (void) ide_do_drive_cmd (drive, rq, ide_end);
        spin_lock_irq(host->host_lock);
        return 0;
 abort:
-       if (pc) kfree (pc);
-       if (rq) kfree (rq);
+       kfree (pc);
+       kfree (rq);
        cmd->result = DID_ERROR << 16;
        done(cmd);
        return 0;
@@ -975,7 +993,7 @@ static int idescsi_eh_abort (struct scsi_cmnd *cmd)
                 */
                printk (KERN_ERR "ide-scsi: cmd aborted!\n");
 
-               if (scsi->pc->rq->flags & REQ_SENSE)
+               if (blk_sense_request(scsi->pc->rq))
                        kfree(scsi->pc->buffer);
                kfree(scsi->pc->rq);
                kfree(scsi->pc);
@@ -1012,18 +1030,20 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
                return FAILED;
        }
 
-       spin_lock_irq(&ide_lock);
+       spin_lock_irq(cmd->device->host->host_lock);
+       spin_lock(&ide_lock);
 
        if (!scsi->pc || (req = scsi->pc->rq) != HWGROUP(drive)->rq || !HWGROUP(drive)->handler) {
                printk (KERN_WARNING "ide-scsi: No active request in idescsi_eh_reset\n");
                spin_unlock(&ide_lock);
+               spin_unlock_irq(cmd->device->host->host_lock);
                return FAILED;
        }
 
        /* kill current request */
        blkdev_dequeue_request(req);
-       end_that_request_last(req);
-       if (req->flags & REQ_SENSE)
+       end_that_request_last(req, 0);
+       if (blk_sense_request(req))
                kfree(scsi->pc->buffer);
        kfree(scsi->pc);
        scsi->pc = NULL;
@@ -1032,22 +1052,21 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
        /* now nuke the drive queue */
        while ((req = elv_next_request(drive->queue))) {
                blkdev_dequeue_request(req);
-               end_that_request_last(req);
+               end_that_request_last(req, 0);
        }
 
        HWGROUP(drive)->rq = NULL;
        HWGROUP(drive)->handler = NULL;
        HWGROUP(drive)->busy = 1;               /* will set this to zero when ide reset finished */
-       spin_unlock_irq(&ide_lock);
+       spin_unlock(&ide_lock);
 
        ide_do_reset(drive);
 
        /* ide_do_reset starts a polling handler which restarts itself every 50ms until the reset finishes */
 
        do {
-               set_current_state(TASK_UNINTERRUPTIBLE);
                spin_unlock_irq(cmd->device->host->host_lock);
-               schedule_timeout(HZ/20);
+               msleep(50);
                spin_lock_irq(cmd->device->host->host_lock);
        } while ( HWGROUP(drive)->handler );
 
@@ -1058,6 +1077,7 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
                ret = FAILED;
        }
 
+       spin_unlock_irq(cmd->device->host->host_lock);
        return ret;
 }
 
@@ -1095,7 +1115,7 @@ static struct scsi_host_template idescsi_template = {
        .proc_name              = "ide-scsi",
 };
 
-static int idescsi_attach(ide_drive_t *drive)
+static int ide_scsi_probe(ide_drive_t *drive)
 {
        idescsi_scsi_t *idescsi;
        struct Scsi_Host *host;
@@ -1108,11 +1128,14 @@ static int idescsi_attach(ide_drive_t *drive)
                warned = 1;
        }
 
+       if (idescsi_nocd && drive->media == ide_cdrom)
+               return -ENODEV;
+
        if (!strstr("ide-scsi", drive->driver_req) ||
            !drive->present ||
            drive->media == ide_disk ||
            !(host = scsi_host_alloc(&idescsi_template,sizeof(idescsi_scsi_t))))
-               return 1;
+               return -ENODEV;
 
        g = alloc_disk(1 << PARTN_BITS);
        if (!g)
@@ -1138,20 +1161,19 @@ static int idescsi_attach(ide_drive_t *drive)
        idescsi->host = host;
        idescsi->disk = g;
        g->private_data = &idescsi->driver;
-       err = ide_register_subdriver(drive, &idescsi_driver);
+       ide_register_subdriver(drive, &idescsi_driver);
+       err = 0;
+       idescsi_setup(drive, idescsi);
+       g->fops = &idescsi_ops;
+       ide_register_region(g);
+       err = scsi_add_host(host, &drive->gendev);
        if (!err) {
-               idescsi_setup (drive, idescsi);
-               g->fops = &idescsi_ops;
-               ide_register_region(g);
-               err = scsi_add_host(host, &drive->gendev);
-               if (!err) {
-                       scsi_scan_host(host);
-                       return 0;
-               }
-               /* fall through on error */
-               ide_unregister_region(g);
-               ide_unregister_subdriver(drive);
+               scsi_scan_host(host);
+               return 0;
        }
+       /* fall through on error */
+       ide_unregister_region(g);
+       ide_unregister_subdriver(drive, &idescsi_driver);
 
        put_disk(g);
 out_host_put:
@@ -1161,14 +1183,16 @@ out_host_put:
 
 static int __init init_idescsi_module(void)
 {
-       return ide_register_driver(&idescsi_driver);
+       return driver_register(&idescsi_driver.gen_driver);
 }
 
 static void __exit exit_idescsi_module(void)
 {
-       ide_unregister_driver(&idescsi_driver);
+       driver_unregister(&idescsi_driver.gen_driver);
 }
 
+module_param(idescsi_nocd, int, 0600);
+MODULE_PARM_DESC(idescsi_nocd, "Disable handling of CD-ROMs so they may be driven by ide-cd");
 module_init(init_idescsi_module);
 module_exit(exit_idescsi_module);
 MODULE_LICENSE("GPL");