]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/scsi/ide-scsi.c
ide: remove ->supports_dsc_overlap field from ide_driver_t
[linux-2.6-omap-h63xx.git] / drivers / scsi / ide-scsi.c
index 538552495d486da9f896e5cdc3067e360ea27109..a2d003c5e85f373f20226b6768343d1eb446ee2a 100644 (file)
@@ -40,7 +40,6 @@
 #include <linux/ioport.h>
 #include <linux/blkdev.h>
 #include <linux/errno.h>
-#include <linux/hdreg.h>
 #include <linux/slab.h>
 #include <linux/ide.h>
 #include <linux/scatterlist.h>
@@ -101,16 +100,23 @@ static struct ide_scsi_obj *ide_scsi_get(struct gendisk *disk)
 
        mutex_lock(&idescsi_ref_mutex);
        scsi = ide_scsi_g(disk);
-       if (scsi)
-               scsi_host_get(scsi->host);
+       if (scsi) {
+               if (ide_device_get(scsi->drive))
+                       scsi = NULL;
+               else
+                       scsi_host_get(scsi->host);
+       }
        mutex_unlock(&idescsi_ref_mutex);
        return scsi;
 }
 
 static void ide_scsi_put(struct ide_scsi_obj *scsi)
 {
+       ide_drive_t *drive = scsi->drive;
+
        mutex_lock(&idescsi_ref_mutex);
        scsi_host_put(scsi->host);
+       ide_device_put(drive);
        mutex_unlock(&idescsi_ref_mutex);
 }
 
@@ -201,15 +207,15 @@ static int idescsi_check_condition(ide_drive_t *drive,
 
        /* stuff a sense request in front of our current request */
        pc = kzalloc(sizeof(struct ide_atapi_pc), GFP_ATOMIC);
-       rq = kmalloc(sizeof(struct request), GFP_ATOMIC);
+       rq = blk_get_request(drive->queue, READ, GFP_ATOMIC);
        buf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC);
        if (!pc || !rq || !buf) {
                kfree(buf);
-               kfree(rq);
+               if (rq)
+                       blk_put_request(rq);
                kfree(pc);
                return -ENOMEM;
        }
-       blk_rq_init(NULL, rq);
        rq->special = (char *) pc;
        pc->rq = rq;
        pc->buf = buf;
@@ -226,6 +232,7 @@ static int idescsi_check_condition(ide_drive_t *drive,
                ide_scsi_hex_dump(pc->c, 6);
        }
        rq->rq_disk = scsi->disk;
+       rq->ref_count++;
        memcpy(rq->cmd, pc->c, 12);
        ide_do_drive_cmd(drive, rq);
        return 0;
@@ -236,9 +243,9 @@ idescsi_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
 {
        ide_hwif_t *hwif = drive->hwif;
 
-       if (hwif->tp_ops->read_status(hwif) & (BUSY_STAT | DRQ_STAT))
+       if (hwif->tp_ops->read_status(hwif) & (ATA_BUSY | ATA_DRQ))
                /* force an abort */
-               hwif->tp_ops->exec_command(hwif, WIN_IDLEIMMEDIATE);
+               hwif->tp_ops->exec_command(hwif, ATA_CMD_IDLEIMMEDIATE);
 
        rq->errors++;
 
@@ -272,7 +279,7 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
                        SCSI_SENSE_BUFFERSIZE);
                kfree(pc->buf);
                kfree(pc);
-               kfree(rq);
+               blk_put_request(rq);
                pc = opc;
                rq = pc->rq;
                pc->scsi_cmd->result = (CHECK_CONDITION << 1) |
@@ -303,7 +310,7 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
        pc->done(pc->scsi_cmd);
        spin_unlock_irqrestore(host->host_lock, flags);
        kfree(pc);
-       kfree(rq);
+       blk_put_request(rq);
        scsi->pc = NULL;
        return 0;
 }
@@ -422,21 +429,41 @@ static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *r
 }
 
 #ifdef CONFIG_IDE_PROC_FS
-static void idescsi_add_settings(ide_drive_t *drive)
-{
-       idescsi_scsi_t *scsi = drive_to_idescsi(drive);
-
-/*
- *                     drive   setting name    read/write      data type       min     max     mul_factor      div_factor      data pointer            set function
- */
-       ide_add_setting(drive,  "bios_cyl",     SETTING_RW,     TYPE_INT,       0,      1023,   1,              1,              &drive->bios_cyl,       NULL);
-       ide_add_setting(drive,  "bios_head",    SETTING_RW,     TYPE_BYTE,      0,      255,    1,              1,              &drive->bios_head,      NULL);
-       ide_add_setting(drive,  "bios_sect",    SETTING_RW,     TYPE_BYTE,      0,      63,     1,              1,              &drive->bios_sect,      NULL);
-       ide_add_setting(drive,  "transform",    SETTING_RW,     TYPE_INT,       0,      3,      1,              1,              &scsi->transform,       NULL);
-       ide_add_setting(drive,  "log",          SETTING_RW,     TYPE_INT,       0,      1,      1,              1,              &scsi->log,             NULL);
-}
-#else
-static inline void idescsi_add_settings(ide_drive_t *drive) { ; }
+#define ide_scsi_devset_get(name, field) \
+static int get_##name(ide_drive_t *drive) \
+{ \
+       idescsi_scsi_t *scsi = drive_to_idescsi(drive); \
+       return scsi->field; \
+}
+
+#define ide_scsi_devset_set(name, field) \
+static int set_##name(ide_drive_t *drive, int arg) \
+{ \
+       idescsi_scsi_t *scsi = drive_to_idescsi(drive); \
+       scsi->field = arg; \
+       return 0; \
+}
+
+#define ide_scsi_devset_rw(_name, _min, _max, _field) \
+ide_scsi_devset_get(_name, _field); \
+ide_scsi_devset_set(_name, _field); \
+IDE_DEVSET(_name, S_RW, _min, _max, get_##_name, set_##_name)
+
+ide_devset_rw(bios_cyl,                0, 1023, bios_cyl);
+ide_devset_rw(bios_head,       0,  255, bios_head);
+ide_devset_rw(bios_sect,       0,   63, bios_sect);
+
+ide_scsi_devset_rw(transform,  0,    3, transform);
+ide_scsi_devset_rw(log,                0,    1, log);
+
+static const struct ide_devset *idescsi_settings[] = {
+       &ide_devset_bios_cyl,
+       &ide_devset_bios_head,
+       &ide_devset_bios_sect,
+       &ide_devset_log,
+       &ide_devset_transform,
+       NULL
+};
 #endif
 
 /*
@@ -444,7 +471,7 @@ static inline void idescsi_add_settings(ide_drive_t *drive) { ; }
  */
 static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi)
 {
-       if (drive->id && (drive->id->config & 0x0060) == 0x20)
+       if ((drive->id[ATA_ID_CONFIG] & 0x0060) == 0x20)
                set_bit(IDE_AFLAG_DRQ_INTERRUPT, &drive->atapi_flags);
        clear_bit(IDESCSI_SG_TRANSFORM, &scsi->transform);
 #if IDESCSI_DEBUG_LOG
@@ -453,7 +480,7 @@ static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi)
 
        drive->pc_callback = ide_scsi_callback;
 
-       idescsi_add_settings(drive);
+       ide_proc_register_driver(drive, scsi->driver);
 }
 
 static void ide_scsi_remove(ide_drive_t *drive)
@@ -495,12 +522,12 @@ static ide_driver_t idescsi_driver = {
        .remove                 = ide_scsi_remove,
        .version                = IDESCSI_VERSION,
        .media                  = ide_scsi,
-       .supports_dsc_overlap   = 0,
        .do_request             = idescsi_do_request,
        .end_request            = idescsi_end_request,
        .error                  = idescsi_atapi_error,
 #ifdef CONFIG_IDE_PROC_FS
        .proc                   = idescsi_proc,
+       .settings               = idescsi_settings,
 #endif
 };
 
@@ -577,6 +604,7 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
        ide_drive_t *drive = scsi->drive;
        struct request *rq = NULL;
        struct ide_atapi_pc *pc = NULL;
+       int write = cmd->sc_data_direction == DMA_TO_DEVICE;
 
        if (!drive) {
                scmd_printk (KERN_ERR, cmd, "drive not present\n");
@@ -584,7 +612,7 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
        }
        scsi = drive_to_idescsi(drive);
        pc = kmalloc(sizeof(struct ide_atapi_pc), GFP_ATOMIC);
-       rq = kmalloc(sizeof(struct request), GFP_ATOMIC);
+       rq = blk_get_request(drive->queue, write, GFP_ATOMIC);
        if (rq == NULL || pc == NULL) {
                printk (KERN_ERR "ide-scsi: %s: out of memory\n", drive->name);
                goto abort;
@@ -603,7 +631,7 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
        pc->req_xfer = pc->buf_size = scsi_bufflen(cmd);
        pc->scsi_cmd = cmd;
        pc->done = done;
-       pc->timeout = jiffies + cmd->timeout_per_command;
+       pc->timeout = jiffies + cmd->request->timeout;
 
        if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) {
                printk ("ide-scsi: %s: que %lu, cmd = ", drive->name, cmd->serial_number);
@@ -614,17 +642,18 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
                }
        }
 
-       blk_rq_init(NULL, rq);
        rq->special = (char *) pc;
        rq->cmd_type = REQ_TYPE_SPECIAL;
        spin_unlock_irq(host->host_lock);
+       rq->ref_count++;
        memcpy(rq->cmd, pc->c, 12);
        blk_execute_rq_nowait(drive->queue, scsi->disk, rq, 0, NULL);
        spin_lock_irq(host->host_lock);
        return 0;
 abort:
        kfree (pc);
-       kfree (rq);
+       if (rq)
+               blk_put_request(rq);
        cmd->result = DID_ERROR << 16;
        done(cmd);
        return 0;
@@ -672,7 +701,9 @@ static int idescsi_eh_abort (struct scsi_cmnd *cmd)
 
                if (blk_sense_request(scsi->pc->rq))
                        kfree(scsi->pc->buf);
-               kfree(scsi->pc->rq);
+               /* we need to call blk_put_request twice. */
+               blk_put_request(scsi->pc->rq);
+               blk_put_request(scsi->pc->rq);
                kfree(scsi->pc);
                scsi->pc = NULL;
 
@@ -724,7 +755,7 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
                kfree(scsi->pc->buf);
        kfree(scsi->pc);
        scsi->pc = NULL;
-       kfree(req);
+       blk_put_request(req);
 
        /* now nuke the drive queue */
        while ((req = elv_next_request(drive->queue))) {
@@ -799,6 +830,7 @@ static int ide_scsi_probe(ide_drive_t *drive)
        struct gendisk *g;
        static int warned;
        int err = -ENOMEM;
+       u16 last_lun;
 
        if (!warned && drive->media == ide_cdrom) {
                printk(KERN_WARNING "ide-scsi is deprecated for cd burning! Use ide-cd and give dev=/dev/hdX as device\n");
@@ -809,7 +841,6 @@ static int ide_scsi_probe(ide_drive_t *drive)
                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 -ENODEV;
@@ -824,12 +855,12 @@ static int ide_scsi_probe(ide_drive_t *drive)
 
        host->max_id = 1;
 
-       if (drive->id->last_lun)
-               debug_log("%s: id->last_lun=%u\n", drive->name,
-                         drive->id->last_lun);
+       last_lun = drive->id[ATA_ID_LAST_LUN];
+       if (last_lun)
+               debug_log("%s: last_lun=%u\n", drive->name, last_lun);
 
-       if ((drive->id->last_lun & 0x7) != 7)
-               host->max_lun = (drive->id->last_lun & 0x7) + 1;
+       if ((last_lun & 7) != 7)
+               host->max_lun = (last_lun & 7) + 1;
        else
                host->max_lun = 1;
 
@@ -840,7 +871,6 @@ static int ide_scsi_probe(ide_drive_t *drive)
        idescsi->host = host;
        idescsi->disk = g;
        g->private_data = &idescsi->driver;
-       ide_proc_register_driver(drive, &idescsi_driver);
        err = 0;
        idescsi_setup(drive, idescsi);
        g->fops = &idescsi_ops;