ide: remove ide_task_t typedef
[safe/jmp/linux-2.6] / drivers / ide / ide-atapi.c
index e96c012..92c6ef6 100644 (file)
@@ -140,10 +140,19 @@ static void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
        rq->cmd_flags |= REQ_PREEMPT;
        rq->buffer = (char *)pc;
        rq->rq_disk = disk;
+
+       if (pc->req_xfer) {
+               rq->data = pc->buf;
+               rq->data_len = pc->req_xfer;
+       }
+
        memcpy(rq->cmd, pc->c, 12);
        if (drive->media == ide_tape)
                rq->cmd[13] = REQ_IDETAPE_PC1;
-       ide_do_drive_cmd(drive, rq);
+
+       drive->hwif->rq = NULL;
+
+       elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0);
 }
 
 /*
@@ -159,6 +168,12 @@ int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
        rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
        rq->cmd_type = REQ_TYPE_SPECIAL;
        rq->buffer = (char *)pc;
+
+       if (pc->req_xfer) {
+               rq->data = pc->buf;
+               rq->data_len = pc->req_xfer;
+       }
+
        memcpy(rq->cmd, pc->c, 12);
        if (drive->media == ide_tape)
                rq->cmd[13] = REQ_IDETAPE_PC1;
@@ -285,6 +300,21 @@ int ide_cd_get_xferlen(struct request *rq)
 }
 EXPORT_SYMBOL_GPL(ide_cd_get_xferlen);
 
+void ide_read_bcount_and_ireason(ide_drive_t *drive, u16 *bcount, u8 *ireason)
+{
+       struct ide_cmd cmd;
+
+       memset(&cmd, 0, sizeof(cmd));
+       cmd.tf_flags = IDE_TFLAG_IN_LBAH | IDE_TFLAG_IN_LBAM |
+                      IDE_TFLAG_IN_NSECT;
+
+       drive->hwif->tp_ops->tf_read(drive, &cmd);
+
+       *bcount = (cmd.tf.lbah << 8) | cmd.tf.lbam;
+       *ireason = cmd.tf.nsect & 3;
+}
+EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason);
+
 /*
  * This is the usual interrupt handler which will be called during a packet
  * command.  We will transfer some of the data (as requested by the drive)
@@ -306,11 +336,6 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
        timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
                                               : WAIT_TAPE_CMD;
 
-       if (pc->flags & PC_FLAG_TIMEDOUT) {
-               drive->pc_callback(drive, 0);
-               return ide_stopped;
-       }
-
        /* Clear the interrupt */
        stat = tp_ops->read_status(hwif);
 
@@ -332,6 +357,8 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
 
        /* No more interrupts */
        if ((stat & ATA_DRQ) == 0) {
+               int uptodate;
+
                debug_log("Packet command completed, %d bytes transferred\n",
                          pc->xferred);
 
@@ -370,7 +397,15 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
                        dsc = 1;
 
                /* Command finished - Call the callback function */
-               drive->pc_callback(drive, dsc);
+               uptodate = drive->pc_callback(drive, dsc);
+
+               if (uptodate == 0)
+                       drive->failed_pc = NULL;
+
+               if (blk_special_request(rq))
+                       ide_complete_rq(drive, 0);
+               else
+                       ide_end_request(drive, uptodate, 0);
 
                return ide_stopped;
        }
@@ -444,16 +479,35 @@ next_irq:
        return ide_started;
 }
 
+static void ide_pktcmd_tf_load(ide_drive_t *drive, u32 tf_flags, u16 bcount)
+{
+       ide_hwif_t *hwif = drive->hwif;
+       struct ide_cmd cmd;
+       u8 dma = drive->dma;
+
+       memset(&cmd, 0, sizeof(cmd));
+       cmd.tf_flags = IDE_TFLAG_OUT_LBAH | IDE_TFLAG_OUT_LBAM |
+                      IDE_TFLAG_OUT_FEATURE | tf_flags;
+       cmd.tf.feature = dma;           /* Use PIO/DMA */
+       cmd.tf.lbam    = bcount & 0xff;
+       cmd.tf.lbah    = (bcount >> 8) & 0xff;
+
+       ide_tf_dump(drive->name, &cmd.tf);
+       hwif->tp_ops->set_irq(hwif, 1);
+       SELECT_MASK(drive, 0);
+       hwif->tp_ops->tf_load(drive, &cmd);
+}
+
 static u8 ide_read_ireason(ide_drive_t *drive)
 {
-       ide_task_t task;
+       struct ide_cmd cmd;
 
-       memset(&task, 0, sizeof(task));
-       task.tf_flags = IDE_TFLAG_IN_NSECT;
+       memset(&cmd, 0, sizeof(cmd));
+       cmd.tf_flags = IDE_TFLAG_IN_NSECT;
 
-       drive->hwif->tp_ops->tf_read(drive, &task);
+       drive->hwif->tp_ops->tf_read(drive, &cmd);
 
-       return task.tf.nsect & 3;
+       return cmd.tf.nsect & 3;
 }
 
 static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
@@ -577,18 +631,23 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive)
        struct ide_atapi_pc *pc;
        ide_hwif_t *hwif = drive->hwif;
        ide_expiry_t *expiry = NULL;
+       struct request *rq = hwif->rq;
        unsigned int timeout;
        u32 tf_flags;
        u16 bcount;
 
        if (dev_is_idecd(drive)) {
                tf_flags = IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL;
-               bcount = ide_cd_get_xferlen(hwif->rq);
+               bcount = ide_cd_get_xferlen(rq);
                expiry = ide_cd_expiry;
                timeout = ATAPI_WAIT_PC;
 
-               if (drive->dma)
-                       drive->dma = !hwif->dma_ops->dma_setup(drive);
+               if (drive->dma) {
+                       if (ide_build_sglist(drive, rq))
+                               drive->dma = !hwif->dma_ops->dma_setup(drive);
+                       else
+                               drive->dma = 0;
+               }
        } else {
                pc = drive->pc;
 
@@ -607,8 +666,12 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive)
                }
 
                if ((pc->flags & PC_FLAG_DMA_OK) &&
-                    (drive->dev_flags & IDE_DFLAG_USING_DMA))
-                       drive->dma = !hwif->dma_ops->dma_setup(drive);
+                    (drive->dev_flags & IDE_DFLAG_USING_DMA)) {
+                       if (ide_build_sglist(drive, rq))
+                               drive->dma = !hwif->dma_ops->dma_setup(drive);
+                       else
+                               drive->dma = 0;
+               }
 
                if (!drive->dma)
                        pc->flags &= ~PC_FLAG_DMA_OK;
@@ -617,7 +680,7 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive)
                                                       : WAIT_TAPE_CMD;
        }
 
-       ide_pktcmd_tf_load(drive, tf_flags, bcount, drive->dma);
+       ide_pktcmd_tf_load(drive, tf_flags, bcount);
 
        /* Issue the packet command */
        if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {