]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ide/ide-atapi.c
ide: add ide_retry_pc() helper
[linux-2.6-omap-h63xx.git] / drivers / ide / ide-atapi.c
index 608c5bade92939476d15a1c1f053584fde419e95..d758dcd871780329798351714d8cab44f1828739 100644 (file)
@@ -124,8 +124,8 @@ EXPORT_SYMBOL_GPL(ide_init_pc);
  * the current request, so that it will be processed immediately, on the next
  * pass through the driver.
  */
-void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
-                      struct ide_atapi_pc *pc, struct request *rq)
+static void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
+                             struct ide_atapi_pc *pc, struct request *rq)
 {
        blk_rq_init(NULL, rq);
        rq->cmd_type = REQ_TYPE_SPECIAL;
@@ -137,7 +137,6 @@ void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
                rq->cmd[13] = REQ_IDETAPE_PC1;
        ide_do_drive_cmd(drive, rq);
 }
-EXPORT_SYMBOL_GPL(ide_queue_pc_head);
 
 /*
  * Add a special packet command request to the tail of the request queue,
@@ -203,25 +202,78 @@ int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on)
 }
 EXPORT_SYMBOL_GPL(ide_set_media_lock);
 
+void ide_create_request_sense_cmd(ide_drive_t *drive, struct ide_atapi_pc *pc)
+{
+       ide_init_pc(pc);
+       pc->c[0] = REQUEST_SENSE;
+       if (drive->media == ide_floppy) {
+               pc->c[4] = 255;
+               pc->req_xfer = 18;
+       } else {
+               pc->c[4] = 20;
+               pc->req_xfer = 20;
+       }
+}
+EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd);
+
+/*
+ * Called when an error was detected during the last packet command.
+ * We queue a request sense packet command in the head of the request list.
+ */
+void ide_retry_pc(ide_drive_t *drive, struct gendisk *disk)
+{
+       struct request *rq = &drive->request_sense_rq;
+       struct ide_atapi_pc *pc = &drive->request_sense_pc;
+
+       (void)ide_read_error(drive);
+       ide_create_request_sense_cmd(drive, pc);
+       if (drive->media == ide_tape)
+               set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
+       ide_queue_pc_head(drive, disk, pc, rq);
+}
+EXPORT_SYMBOL_GPL(ide_retry_pc);
+
+int ide_scsi_expiry(ide_drive_t *drive)
+{
+       struct ide_atapi_pc *pc = drive->pc;
+
+       debug_log("%s called for %lu at %lu\n", __func__,
+                 pc->scsi_cmd->serial_number, jiffies);
+
+       pc->flags |= PC_FLAG_TIMEDOUT;
+
+       return 0; /* we do not want the IDE subsystem to retry */
+}
+EXPORT_SYMBOL_GPL(ide_scsi_expiry);
+
 /* TODO: unify the code thus making some arguments go away */
-ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
-       ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
+ide_startstop_t ide_pc_intr(ide_drive_t *drive, ide_handler_t *handler,
        void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *),
-       void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *),
        int (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int))
 {
+       struct ide_atapi_pc *pc = drive->pc;
        ide_hwif_t *hwif = drive->hwif;
        struct request *rq = hwif->hwgroup->rq;
        const struct ide_tp_ops *tp_ops = hwif->tp_ops;
        xfer_func_t *xferfunc;
-       unsigned int temp;
+       ide_expiry_t *expiry;
+       unsigned int timeout, temp;
        u16 bcount;
-       u8 stat, ireason, scsi = drive->scsi;
+       u8 stat, ireason, scsi = drive->scsi, dsc = 0;
 
        debug_log("Enter %s - interrupt handler\n", __func__);
 
+       if (scsi) {
+               timeout = ide_scsi_get_timeout(pc);
+               expiry = ide_scsi_expiry;
+       } else {
+               timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
+                                                      : WAIT_TAPE_CMD;
+               expiry = NULL;
+       }
+
        if (pc->flags & PC_FLAG_TIMEDOUT) {
-               drive->pc_callback(drive);
+               drive->pc_callback(drive, 0);
                return ide_stopped;
        }
 
@@ -276,21 +328,19 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
                        debug_log("[cmd %x]: check condition\n", rq->cmd[0]);
 
                        /* Retry operation */
-                       retry_pc(drive);
+                       ide_retry_pc(drive, rq->rq_disk);
 
                        /* queued, but not started */
                        return ide_stopped;
                }
 cmd_finished:
                pc->error = 0;
-               if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) &&
-                   (stat & ATA_DSC) == 0) {
-                       dsc_handle(drive);
-                       return ide_stopped;
-               }
+
+               if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0)
+                       dsc = 1;
 
                /* Command finished - Call the callback function */
-               drive->pc_callback(drive);
+               drive->pc_callback(drive, dsc);
 
                return ide_stopped;
        }
@@ -348,9 +398,7 @@ cmd_finished:
                                pc->xferred += temp;
                                pc->cur_pos += temp;
                                ide_pad_transfer(drive, 0, bcount - temp);
-                               ide_set_handler(drive, handler, timeout,
-                                               expiry);
-                               return ide_started;
+                               goto next_irq;
                        }
                        debug_log("The device wants to send us more data than "
                                  "expected - allowing transfer\n");
@@ -377,7 +425,7 @@ cmd_finished:
 
        debug_log("[cmd %x] transferred %d bytes on that intr.\n",
                  rq->cmd[0], bcount);
-
+next_irq:
        /* And set the interrupt handler again */
        ide_set_handler(drive, handler, timeout, expiry);
        return ide_started;
@@ -418,10 +466,11 @@ static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
        return ireason;
 }
 
-ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
+ide_startstop_t ide_transfer_pc(ide_drive_t *drive,
                                ide_handler_t *handler, unsigned int timeout,
                                ide_expiry_t *expiry)
 {
+       struct ide_atapi_pc *pc = drive->pc;
        ide_hwif_t *hwif = drive->hwif;
        struct request *rq = hwif->hwgroup->rq;
        ide_startstop_t startstop;
@@ -460,10 +509,11 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
 }
 EXPORT_SYMBOL_GPL(ide_transfer_pc);
 
-ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
+ide_startstop_t ide_issue_pc(ide_drive_t *drive,
                             ide_handler_t *handler, unsigned int timeout,
                             ide_expiry_t *expiry)
 {
+       struct ide_atapi_pc *pc = drive->pc;
        ide_hwif_t *hwif = drive->hwif;
        u16 bcount;
        u8 dma = 0;