ide: drop 'timeout' and 'expiry' arguments from ide_pc_intr()
[safe/jmp/linux-2.6] / drivers / scsi / ide-scsi.c
index ed92cf7..f71d1b3 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>
 
 #define IDESCSI_DEBUG_LOG              0
 
+#if IDESCSI_DEBUG_LOG
+#define debug_log(fmt, args...) \
+       printk(KERN_INFO "ide-scsi: " fmt, ## args)
+#else
+#define debug_log(fmt, args...) do {} while (0)
+#endif
+
 /*
  *     SCSI command transformation layer
  */
@@ -76,8 +82,6 @@ typedef struct ide_scsi_obj {
        struct gendisk          *disk;
        struct Scsi_Host        *host;
 
-       struct ide_atapi_pc *pc;                /* Current packet command */
-       unsigned long flags;                    /* Status/Action flags */
        unsigned long transform;                /* SCSI cmd translation layer */
        unsigned long log;                      /* log flags */
 } idescsi_scsi_t;
@@ -95,16 +99,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);
 }
 
@@ -118,96 +129,27 @@ static inline idescsi_scsi_t *drive_to_idescsi(ide_drive_t *ide_drive)
        return scsihost_to_idescsi(ide_drive->driver_data);
 }
 
-/*
- *     Per ATAPI device status bits.
- */
-#define IDESCSI_DRQ_INTERRUPT          0       /* DRQ interrupt device */
-
-/*
- *     ide-scsi requests.
- */
-#define IDESCSI_PC_RQ                  90
-
-/*
- *     PIO data transfer routines using the scatter gather table.
- */
-static void idescsi_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
-               unsigned int bcount)
+static void ide_scsi_hex_dump(u8 *data, int len)
 {
-       ide_hwif_t *hwif = drive->hwif;
-       int count;
-       char *buf;
-
-       while (bcount) {
-               count = min(pc->sg->length - pc->b_count, bcount);
-               if (PageHighMem(sg_page(pc->sg))) {
-                       unsigned long flags;
-
-                       local_irq_save(flags);
-                       buf = kmap_atomic(sg_page(pc->sg), KM_IRQ0) +
-                                       pc->sg->offset;
-                       hwif->input_data(drive, NULL, buf + pc->b_count, count);
-                       kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
-                       local_irq_restore(flags);
-               } else {
-                       buf = sg_virt(pc->sg);
-                       hwif->input_data(drive, NULL, buf + pc->b_count, count);
-               }
-               bcount -= count; pc->b_count += count;
-               if (pc->b_count == pc->sg->length) {
-                       if (!--pc->sg_cnt)
-                               break;
-                       pc->sg = sg_next(pc->sg);
-                       pc->b_count = 0;
-               }
-       }
-
-       if (bcount) {
-               printk (KERN_ERR "ide-scsi: scatter gather table too small, discarding data\n");
-               ide_pad_transfer(drive, 0, bcount);
-       }
+       print_hex_dump(KERN_CONT, "", DUMP_PREFIX_NONE, 16, 1, data, len, 0);
 }
 
-static void idescsi_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
-               unsigned int bcount)
+static int idescsi_end_request(ide_drive_t *, int, int);
+
+static void ide_scsi_callback(ide_drive_t *drive, int dsc)
 {
-       ide_hwif_t *hwif = drive->hwif;
-       int count;
-       char *buf;
-
-       while (bcount) {
-               count = min(pc->sg->length - pc->b_count, bcount);
-               if (PageHighMem(sg_page(pc->sg))) {
-                       unsigned long flags;
-
-                       local_irq_save(flags);
-                       buf = kmap_atomic(sg_page(pc->sg), KM_IRQ0) +
-                                               pc->sg->offset;
-                       hwif->output_data(drive, NULL, buf + pc->b_count, count);
-                       kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
-                       local_irq_restore(flags);
-               } else {
-                       buf = sg_virt(pc->sg);
-                       hwif->output_data(drive, NULL, buf + pc->b_count, count);
-               }
-               bcount -= count; pc->b_count += count;
-               if (pc->b_count == pc->sg->length) {
-                       if (!--pc->sg_cnt)
-                               break;
-                       pc->sg = sg_next(pc->sg);
-                       pc->b_count = 0;
-               }
-       }
+       idescsi_scsi_t *scsi = drive_to_idescsi(drive);
+       struct ide_atapi_pc *pc = drive->pc;
 
-       if (bcount) {
-               printk (KERN_ERR "ide-scsi: scatter gather table too small, padding with zeros\n");
-               ide_pad_transfer(drive, 1, bcount);
-       }
-}
+       if (pc->flags & PC_FLAG_TIMEDOUT)
+               debug_log("%s: got timed out packet %lu at %lu\n", __func__,
+                         pc->scsi_cmd->serial_number, jiffies);
+               /* end this request now - scsi should retry it*/
+       else if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
+               printk(KERN_INFO "Packet command completed, %d bytes"
+                                " transferred\n", pc->xferred);
 
-static void ide_scsi_hex_dump(u8 *data, int len)
-{
-       print_hex_dump(KERN_CONT, "", DUMP_PREFIX_NONE, 16, 1, data, len, 0);
+       idescsi_end_request(drive, 1, 0);
 }
 
 static int idescsi_check_condition(ide_drive_t *drive,
@@ -220,15 +162,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;
@@ -245,21 +187,20 @@ 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;
 }
 
-static int idescsi_end_request(ide_drive_t *, int, int);
-
 static ide_startstop_t
 idescsi_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
 {
        ide_hwif_t *hwif = drive->hwif;
 
-       if (ide_read_status(drive) & (BUSY_STAT | DRQ_STAT))
+       if (hwif->tp_ops->read_status(hwif) & (ATA_BUSY | ATA_DRQ))
                /* force an abort */
-               hwif->OUTBSYNC(hwif, WIN_IDLEIMMEDIATE,
-                              hwif->io_ports.command_addr);
+               hwif->tp_ops->exec_command(hwif, ATA_CMD_IDLEIMMEDIATE);
 
        rq->errors++;
 
@@ -268,20 +209,6 @@ idescsi_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
        return ide_stopped;
 }
 
-static ide_startstop_t
-idescsi_atapi_abort(ide_drive_t *drive, struct request *rq)
-{
-#if IDESCSI_DEBUG_LOG
-       printk(KERN_WARNING "idescsi_atapi_abort called for %lu\n",
-               ((struct ide_atapi_pc *) rq->special)->scsi_cmd->serial_number);
-#endif
-       rq->errors |= ERROR_MAX;
-
-       idescsi_end_request(drive, 0, 0);
-
-       return ide_stopped;
-}
-
 static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
 {
        idescsi_scsi_t *scsi = drive_to_idescsi(drive);
@@ -307,7 +234,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) |
@@ -338,180 +265,24 @@ 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);
-       scsi->pc = NULL;
+       blk_put_request(rq);
+       drive->pc = NULL;
        return 0;
 }
 
-static inline unsigned long get_timeout(struct ide_atapi_pc *pc)
-{
-       return max_t(unsigned long, WAIT_CMD, pc->timeout - jiffies);
-}
-
-static int idescsi_expiry(ide_drive_t *drive)
-{
-       idescsi_scsi_t *scsi = drive_to_idescsi(drive);
-       struct ide_atapi_pc   *pc   = scsi->pc;
-
-#if IDESCSI_DEBUG_LOG
-       printk(KERN_WARNING "idescsi_expiry called for %lu at %lu\n", pc->scsi_cmd->serial_number, jiffies);
-#endif
-       pc->flags |= PC_FLAG_TIMEDOUT;
-
-       return 0;                                       /* we do not want the ide subsystem to retry */
-}
-
 /*
  *     Our interrupt handler.
  */
 static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
 {
-       idescsi_scsi_t *scsi = drive_to_idescsi(drive);
-       ide_hwif_t *hwif = drive->hwif;
-       struct ide_atapi_pc *pc = scsi->pc;
-       struct request *rq = pc->rq;
-       unsigned int temp;
-       u16 bcount;
-       u8 stat, ireason;
-
-#if IDESCSI_DEBUG_LOG
-       printk (KERN_INFO "ide-scsi: Reached idescsi_pc_intr interrupt handler\n");
-#endif /* IDESCSI_DEBUG_LOG */
-
-       if (pc->flags & PC_FLAG_TIMEDOUT) {
-#if IDESCSI_DEBUG_LOG
-               printk(KERN_WARNING "idescsi_pc_intr: got timed out packet  %lu at %lu\n",
-                               pc->scsi_cmd->serial_number, jiffies);
-#endif
-               /* end this request now - scsi should retry it*/
-               idescsi_end_request (drive, 1, 0);
-               return ide_stopped;
-       }
-       if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
-               if (hwif->dma_ops->dma_end(drive))
-                       pc->flags |= PC_FLAG_DMA_ERROR;
-               else
-                       pc->xferred = pc->req_xfer;
-#if IDESCSI_DEBUG_LOG
-               printk ("ide-scsi: %s: DMA complete\n", drive->name);
-#endif /* IDESCSI_DEBUG_LOG */
-       }
-
-       /* Clear the interrupt */
-       stat = ide_read_status(drive);
-
-       if ((stat & DRQ_STAT) == 0) {
-               /* No more interrupts */
-               if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
-                       printk(KERN_INFO "Packet command completed, %d bytes"
-                                       " transferred\n", pc->xferred);
-               pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
-               local_irq_enable_in_hardirq();
-               if ((stat & ERR_STAT) || (pc->flags & PC_FLAG_DMA_ERROR))
-                       rq->errors++;
-               idescsi_end_request (drive, 1, 0);
-               return ide_stopped;
-       }
-       if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
-               pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
-               printk(KERN_ERR "%s: The device wants to issue more interrupts "
-                               "in DMA mode\n", drive->name);
-               ide_dma_off(drive);
-               return ide_do_reset(drive);
-       }
-       bcount = (hwif->INB(hwif->io_ports.lbah_addr) << 8) |
-                 hwif->INB(hwif->io_ports.lbam_addr);
-       ireason = hwif->INB(hwif->io_ports.nsect_addr);
-
-       if (ireason & CD) {
-               printk(KERN_ERR "ide-scsi: CoD != 0 in idescsi_pc_intr\n");
-               return ide_do_reset (drive);
-       }
-       if (ireason & IO) {
-               temp = pc->xferred + bcount;
-               if (temp > pc->req_xfer) {
-                       if (temp > pc->buf_size) {
-                               printk(KERN_ERR "ide-scsi: The scsi wants to "
-                                       "send us more data than expected "
-                                       "- discarding data\n");
-                               temp = pc->buf_size - pc->xferred;
-                               if (temp) {
-                                       pc->flags &= ~PC_FLAG_WRITING;
-                                       if (pc->sg)
-                                               idescsi_input_buffers(drive, pc,
-                                                                       temp);
-                                       else
-                                               hwif->input_data(drive, NULL,
-                                                       pc->cur_pos, temp);
-                                       printk(KERN_ERR "ide-scsi: transferred"
-                                                       " %d of %d bytes\n",
-                                                       temp, bcount);
-                               }
-                               pc->xferred += temp;
-                               pc->cur_pos += temp;
-                               ide_pad_transfer(drive, 0, bcount - temp);
-                               ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry);
-                               return ide_started;
-                       }
-#if IDESCSI_DEBUG_LOG
-                       printk (KERN_NOTICE "ide-scsi: The scsi wants to send us more data than expected - allowing transfer\n");
-#endif /* IDESCSI_DEBUG_LOG */
-               }
-       }
-       if (ireason & IO) {
-               pc->flags &= ~PC_FLAG_WRITING;
-               if (pc->sg)
-                       idescsi_input_buffers(drive, pc, bcount);
-               else
-                       hwif->input_data(drive, NULL, pc->cur_pos, bcount);
-       } else {
-               pc->flags |= PC_FLAG_WRITING;
-               if (pc->sg)
-                       idescsi_output_buffers(drive, pc, bcount);
-               else
-                       hwif->output_data(drive, NULL, pc->cur_pos, bcount);
-       }
-       /* Update the current position */
-       pc->xferred += bcount;
-       pc->cur_pos += bcount;
-
-       /* And set the interrupt handler again */
-       ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry);
-       return ide_started;
+       return ide_pc_intr(drive, idescsi_pc_intr, NULL, NULL, ide_io_buffers);
 }
 
 static ide_startstop_t idescsi_transfer_pc(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = drive->hwif;
-       idescsi_scsi_t *scsi = drive_to_idescsi(drive);
-       struct ide_atapi_pc *pc = scsi->pc;
-       ide_startstop_t startstop;
-       u8 ireason;
-
-       if (ide_wait_stat(&startstop,drive,DRQ_STAT,BUSY_STAT,WAIT_READY)) {
-               printk(KERN_ERR "ide-scsi: Strange, packet command "
-                       "initiated yet DRQ isn't asserted\n");
-               return startstop;
-       }
-       ireason = hwif->INB(hwif->io_ports.nsect_addr);
-       if ((ireason & CD) == 0 || (ireason & IO)) {
-               printk(KERN_ERR "ide-scsi: (IO,CoD) != (0,1) while "
-                               "issuing a packet command\n");
-               return ide_do_reset (drive);
-       }
-       BUG_ON(HWGROUP(drive)->handler != NULL);
-       /* Set the interrupt routine */
-       ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry);
-
-       if (pc->flags & PC_FLAG_DMA_OK) {
-               pc->flags |= PC_FLAG_DMA_IN_PROGRESS;
-               hwif->dma_ops->dma_start(drive);
-       }
-
-       /* Send the actual packet */
-       hwif->output_data(drive, NULL, scsi->pc->c, 12);
-
-       return ide_started;
+       return ide_transfer_pc(drive, idescsi_pc_intr,
+                              ide_scsi_get_timeout(drive->pc),
+                              ide_scsi_expiry);
 }
 
 static inline int idescsi_set_direction(struct ide_atapi_pc *pc)
@@ -556,39 +327,11 @@ static int idescsi_map_sg(ide_drive_t *drive, struct ide_atapi_pc *pc)
 static ide_startstop_t idescsi_issue_pc(ide_drive_t *drive,
                struct ide_atapi_pc *pc)
 {
-       idescsi_scsi_t *scsi = drive_to_idescsi(drive);
-       ide_hwif_t *hwif = drive->hwif;
-       u16 bcount;
-       u8 dma = 0;
-
        /* Set the current packet command */
-       scsi->pc = pc;
-       /* We haven't transferred any data yet */
-       pc->xferred = 0;
-       pc->cur_pos = pc->buf;
-       /* Request to transfer the entire buffer at once */
-       bcount = min(pc->req_xfer, 63 * 1024);
-
-       if (drive->using_dma && !idescsi_map_sg(drive, pc)) {
-               hwif->sg_mapped = 1;
-               dma = !hwif->dma_ops->dma_setup(drive);
-               hwif->sg_mapped = 0;
-       }
-
-       ide_pktcmd_tf_load(drive, 0, bcount, dma);
-
-       if (dma)
-               pc->flags |= PC_FLAG_DMA_OK;
+       drive->pc = pc;
 
-       if (test_bit(IDESCSI_DRQ_INTERRUPT, &scsi->flags)) {
-               ide_execute_command(drive, WIN_PACKETCMD, &idescsi_transfer_pc,
-                                   get_timeout(pc), idescsi_expiry);
-               return ide_started;
-       } else {
-               /* Issue the packet command */
-               ide_execute_pkt_cmd(drive);
-               return idescsi_transfer_pc(drive);
-       }
+       return ide_issue_pc(drive, idescsi_transfer_pc,
+                           ide_scsi_get_timeout(pc), ide_scsi_expiry);
 }
 
 /*
@@ -596,14 +339,18 @@ static ide_startstop_t idescsi_issue_pc(ide_drive_t *drive,
  */
 static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *rq, sector_t block)
 {
-#if IDESCSI_DEBUG_LOG
-       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 */
+       debug_log("dev: %s, cmd: %x, errors: %d\n", rq->rq_disk->disk_name,
+                 rq->cmd[0], rq->errors);
+       debug_log("sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n",
+                 rq->sector, rq->nr_sectors, rq->current_nr_sectors);
 
        if (blk_sense_request(rq) || blk_special_request(rq)) {
-               return idescsi_issue_pc(drive,
-                               (struct ide_atapi_pc *) rq->special);
+               struct ide_atapi_pc *pc = (struct ide_atapi_pc *)rq->special;
+
+               if (drive->using_dma && !idescsi_map_sg(drive, pc))
+                       pc->flags |= PC_FLAG_DMA_OK;
+
+               return idescsi_issue_pc(drive, pc);
        }
        blk_dump_rq_flags(rq, "ide-scsi: unsup command");
        idescsi_end_request (drive, 0, 0);
@@ -611,21 +358,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_field(_name, _field) \
+ide_scsi_devset_get(_name, _field); \
+ide_scsi_devset_set(_name, _field); \
+IDE_DEVSET(_name, DS_SYNC, get_##_name, set_##_name);
+
+ide_devset_rw_field(bios_cyl, bios_cyl);
+ide_devset_rw_field(bios_head, bios_head);
+ide_devset_rw_field(bios_sect, bios_sect);
+
+ide_scsi_devset_rw_field(transform, transform);
+ide_scsi_devset_rw_field(log, log);
+
+static const struct ide_proc_devset idescsi_settings[] = {
+       IDE_PROC_DEVSET(bios_cyl,  0, 1023),
+       IDE_PROC_DEVSET(bios_head, 0,  255),
+       IDE_PROC_DEVSET(bios_sect, 0,   63),
+       IDE_PROC_DEVSET(log,       0,    1),
+       IDE_PROC_DEVSET(transform, 0,    3),
+       { 0 },
+};
 #endif
 
 /*
@@ -633,13 +400,16 @@ 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)
-               set_bit (IDESCSI_DRQ_INTERRUPT, &scsi->flags);
+       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
        set_bit(IDESCSI_LOG_CMD, &scsi->log);
 #endif /* IDESCSI_DEBUG_LOG */
-       idescsi_add_settings(drive);
+
+       drive->pc_callback = ide_scsi_callback;
+
+       ide_proc_register_driver(drive, scsi->driver);
 }
 
 static void ide_scsi_remove(ide_drive_t *drive)
@@ -658,6 +428,8 @@ static void ide_scsi_remove(ide_drive_t *drive)
        put_disk(g);
 
        ide_scsi_put(scsi);
+
+       drive->scsi = 0;
 }
 
 static int ide_scsi_probe(ide_drive_t *);
@@ -679,13 +451,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,
-       .abort                  = idescsi_atapi_abort,
 #ifdef CONFIG_IDE_PROC_FS
        .proc                   = idescsi_proc,
+       .settings               = idescsi_settings,
 #endif
 };
 
@@ -762,6 +533,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");
@@ -769,7 +541,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;
@@ -777,6 +549,8 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
 
        memset (pc->c, 0, 12);
        pc->flags = 0;
+       if (cmd->sc_data_direction == DMA_TO_DEVICE)
+               pc->flags |= PC_FLAG_WRITING;
        pc->rq = rq;
        memcpy (pc->c, cmd->cmnd, cmd->cmd_len);
        pc->buf = NULL;
@@ -786,7 +560,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);
@@ -797,16 +571,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;
@@ -819,6 +595,8 @@ static int idescsi_eh_abort (struct scsi_cmnd *cmd)
        int             busy;
        int             ret   = FAILED;
 
+       struct ide_atapi_pc *pc;
+
        /* In idescsi_eh_abort we try to gently pry our command from the ide subsystem */
 
        if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
@@ -839,24 +617,27 @@ static int idescsi_eh_abort (struct scsi_cmnd *cmd)
        spin_lock_irq(&ide_lock);
 
        /* If there is no pc running we're done (our interrupt took care of it) */
-       if (!scsi->pc) {
+       pc = drive->pc;
+       if (pc == NULL) {
                ret = SUCCESS;
                goto ide_unlock;
        }
 
        /* It's somewhere in flight. Does ide subsystem agree? */
-       if (scsi->pc->scsi_cmd->serial_number == cmd->serial_number && !busy &&
-           elv_queue_empty(drive->queue) && HWGROUP(drive)->rq != scsi->pc->rq) {
+       if (pc->scsi_cmd->serial_number == cmd->serial_number && !busy &&
+           elv_queue_empty(drive->queue) && HWGROUP(drive)->rq != pc->rq) {
                /*
                 * FIXME - not sure this condition can ever occur
                 */
                printk (KERN_ERR "ide-scsi: cmd aborted!\n");
 
-               if (blk_sense_request(scsi->pc->rq))
-                       kfree(scsi->pc->buf);
-               kfree(scsi->pc->rq);
-               kfree(scsi->pc);
-               scsi->pc = NULL;
+               if (blk_sense_request(pc->rq))
+                       kfree(pc->buf);
+               /* we need to call blk_put_request twice. */
+               blk_put_request(pc->rq);
+               blk_put_request(pc->rq);
+               kfree(pc);
+               drive->pc = NULL;
 
                ret = SUCCESS;
        }
@@ -878,6 +659,8 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
        int             ready = 0;
        int             ret   = SUCCESS;
 
+       struct ide_atapi_pc *pc;
+
        /* In idescsi_eh_reset we forcefully remove the command from the ide subsystem and reset the device. */
 
        if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
@@ -892,7 +675,9 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
        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) {
+       pc = drive->pc;
+
+       if (pc == NULL || (req = 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);
@@ -903,10 +688,10 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
        if (__blk_end_request(req, -EIO, 0))
                BUG();
        if (blk_sense_request(req))
-               kfree(scsi->pc->buf);
-       kfree(scsi->pc);
-       scsi->pc = NULL;
-       kfree(req);
+               kfree(pc->buf);
+       kfree(pc);
+       drive->pc = NULL;
+       blk_put_request(req);
 
        /* now nuke the drive queue */
        while ((req = elv_next_request(drive->queue))) {
@@ -981,6 +766,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");
@@ -991,11 +777,12 @@ 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;
 
+       drive->scsi = 1;
+
        g = alloc_disk(1 << PARTN_BITS);
        if (!g)
                goto out_host_put;
@@ -1004,12 +791,12 @@ static int ide_scsi_probe(ide_drive_t *drive)
 
        host->max_id = 1;
 
-#if IDESCSI_DEBUG_LOG
-       if (drive->id->last_lun)
-               printk(KERN_NOTICE "%s: id->last_lun=%u\n", drive->name, drive->id->last_lun);
-#endif
-       if ((drive->id->last_lun & 0x7) != 7)
-               host->max_lun = (drive->id->last_lun & 0x7) + 1;
+       last_lun = drive->id[ATA_ID_LAST_LUN];
+       if (last_lun)
+               debug_log("%s: last_lun=%u\n", drive->name, last_lun);
+
+       if ((last_lun & 7) != 7)
+               host->max_lun = (last_lun & 7) + 1;
        else
                host->max_lun = 1;
 
@@ -1020,7 +807,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;
@@ -1036,6 +822,7 @@ static int ide_scsi_probe(ide_drive_t *drive)
 
        put_disk(g);
 out_host_put:
+       drive->scsi = 0;
        scsi_host_put(host);
        return err;
 }