]> err.no Git - linux-2.6/blobdiff - drivers/scsi/ide-scsi.c
ide-scsi: use pc->callback
[linux-2.6] / drivers / scsi / ide-scsi.c
index c9fdf60c9dcfb0cb72c03e1ca9da9096181c5afc..c0b39b9e5c1488c0bc25965843f28bebe9661491 100644 (file)
@@ -183,6 +183,24 @@ static void ide_scsi_hex_dump(u8 *data, int len)
        print_hex_dump(KERN_CONT, "", DUMP_PREFIX_NONE, 16, 1, data, len, 0);
 }
 
+static int idescsi_end_request(ide_drive_t *, int, int);
+
+static void ide_scsi_callback(ide_drive_t *drive)
+{
+       idescsi_scsi_t *scsi = drive_to_idescsi(drive);
+       struct ide_atapi_pc *pc = scsi->pc;
+
+       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);
+
+       idescsi_end_request(drive, 1, 0);
+}
+
 static int idescsi_check_condition(ide_drive_t *drive,
                struct request *failed_cmd)
 {
@@ -210,6 +228,7 @@ static int idescsi_check_condition(ide_drive_t *drive,
        rq->cmd_type = REQ_TYPE_SENSE;
        rq->cmd_flags |= REQ_PREEMPT;
        pc->timeout = jiffies + WAIT_READY;
+       pc->callback = ide_scsi_callback;
        /* NOTE! Save the failed packet command in "rq->buffer" */
        rq->buffer = (void *) failed_cmd->special;
        pc->scsi_cmd = ((struct ide_atapi_pc *) failed_cmd->special)->scsi_cmd;
@@ -222,8 +241,6 @@ static int idescsi_check_condition(ide_drive_t *drive,
        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)
 {
@@ -350,10 +367,7 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
        debug_log("Reached %s interrupt handler\n", __func__);
 
        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*/
-               idescsi_end_request (drive, 1, 0);
+               pc->callback(drive);
                return ide_stopped;
        }
        if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
@@ -369,14 +383,11 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *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);
+               pc->callback(drive);
                return ide_stopped;
        }
        if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
@@ -453,36 +464,10 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
 
 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 "%s: Strange, packet command initiated yet "
-                               "DRQ isn't asserted\n", drive->name);
-               return startstop;
-       }
-       ireason = hwif->INB(hwif->io_ports.nsect_addr);
-       if ((ireason & CD) == 0 || (ireason & IO)) {
-               printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing "
-                               "a packet command\n", drive->name);
-               return ide_do_reset (drive);
-       }
-
-       /* 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, scsi->pc, idescsi_pc_intr,
+                              get_timeout(scsi->pc), idescsi_expiry);
 }
 
 static inline int idescsi_set_direction(struct ide_atapi_pc *pc)
@@ -528,38 +513,12 @@ 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;
 
-       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, pc, idescsi_transfer_pc,
+                           get_timeout(pc), idescsi_expiry);
 }
 
 /*
@@ -573,8 +532,16 @@ static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *r
                  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;
+               idescsi_scsi_t *scsi = drive_to_idescsi(drive);
+
+               if (test_bit(IDESCSI_DRQ_INTERRUPT, &scsi->flags))
+                       pc->flags |= PC_FLAG_DRQ_INTERRUPT;
+
+               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);
@@ -762,6 +729,7 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
        pc->scsi_cmd = cmd;
        pc->done = done;
        pc->timeout = jiffies + cmd->timeout_per_command;
+       pc->callback = ide_scsi_callback;
 
        if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) {
                printk ("ide-scsi: %s: que %lu, cmd = ", drive->name, cmd->serial_number);