IDE: Make taskfile interface more robust wrt unexpected end-of-command
[sfrench/cifs-2.6.git] / drivers / ide / ide-taskfile.c
index bf72b6d9f68521b33ac20fbc9b7f4e41bc6130a6..4c86a8d84b4ccd02d8567b6b00f51429e5f9c82a 100644 (file)
@@ -189,12 +189,11 @@ EXPORT_SYMBOL_GPL(do_rw_taskfile);
  */
 static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = HWIF(drive);
-       u8 stat;
+       u8 stat = ide_read_status(drive);
 
-       if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
+       if (OK_STAT(stat, READY_STAT, BAD_STAT))
                drive->mult_count = drive->mult_req;
-       else {
+       else {
                drive->mult_req = drive->mult_count = 0;
                drive->special.b.recalibrate = 1;
                (void) ide_dump_status(drive, "set_multmode", stat);
@@ -207,11 +206,10 @@ static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
  */
 static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = HWIF(drive);
        int retries = 5;
        u8 stat;
 
-       while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
+       while (((stat = ide_read_status(drive)) & BUSY_STAT) && retries--)
                udelay(10);
 
        if (OK_STAT(stat, READY_STAT, BAD_STAT))
@@ -230,10 +228,9 @@ static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
  */
 static ide_startstop_t recal_intr(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = HWIF(drive);
-       u8 stat;
+       u8 stat = ide_read_status(drive);
 
-       if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT))
+       if (!OK_STAT(stat, READY_STAT, BAD_STAT))
                return ide_error(drive, "recal_intr", stat);
        return ide_stopped;
 }
@@ -244,23 +241,23 @@ static ide_startstop_t recal_intr(ide_drive_t *drive)
 static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
 {
        ide_task_t *args        = HWGROUP(drive)->rq->special;
-       ide_hwif_t *hwif        = HWIF(drive);
        u8 stat;
 
        local_irq_enable_in_hardirq();
-       if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
+       stat = ide_read_status(drive);
+
+       if (!OK_STAT(stat, READY_STAT, BAD_STAT))
                return ide_error(drive, "task_no_data_intr", stat);
                /* calls ide_end_drive_cmd */
-       }
+
        if (args)
-               ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
+               ide_end_drive_cmd(drive, stat, ide_read_error(drive));
 
        return ide_stopped;
 }
 
 static u8 wait_drive_not_busy(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = HWIF(drive);
        int retries;
        u8 stat;
 
@@ -269,7 +266,9 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
         * This can take up to 10 usec, but we will wait max 1 ms.
         */
        for (retries = 0; retries < 100; retries++) {
-               if ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT)
+               stat = ide_read_status(drive);
+
+               if (stat & BUSY_STAT)
                        udelay(10);
                else
                        break;
@@ -408,7 +407,7 @@ static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq,
 void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
 {
        if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
-               u8 err = drive->hwif->INB(IDE_ERROR_REG);
+               u8 err = ide_read_error(drive);
 
                ide_end_drive_cmd(drive, stat, err);
                return;
@@ -423,6 +422,25 @@ void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
                ide_end_request(drive, 1, rq->nr_sectors);
 }
 
+/*
+ * We got an interrupt on a task_in case, but no errors and no DRQ.
+ *
+ * It might be a spurious irq (shared irq), but it might be a
+ * command that had no output.
+ */
+static ide_startstop_t task_in_unexpected(ide_drive_t *drive, struct request *rq, u8 stat)
+{
+       /* Command all done? */
+       if (OK_STAT(stat, READY_STAT, BUSY_STAT)) {
+               task_end_request(drive, rq, stat);
+               return ide_stopped;
+       }
+
+       /* Assume it was a spurious irq */
+       ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
+       return ide_started;
+}
+
 /*
  * Handler for command with PIO data-in phase (Read/Read Multiple).
  */
@@ -430,20 +448,19 @@ static ide_startstop_t task_in_intr(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
        struct request *rq = HWGROUP(drive)->rq;
-       u8 stat = hwif->INB(IDE_STATUS_REG);
+       u8 stat = ide_read_status(drive);
 
-       /* new way for dealing with premature shared PCI interrupts */
-       if (!OK_STAT(stat, DRQ_STAT, BAD_R_STAT)) {
-               if (stat & (ERR_STAT | DRQ_STAT))
-                       return task_error(drive, rq, __FUNCTION__, stat);
-               /* No data yet, so wait for another IRQ. */
-               ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL);
-               return ide_started;
-       }
+       /* Error? */
+       if (stat & ERR_STAT)
+               return task_error(drive, rq, __FUNCTION__, stat);
+
+       /* Didn't want any data? Odd. */
+       if (!(stat & DRQ_STAT))
+               return task_in_unexpected(drive, rq, stat);
 
        ide_pio_datablock(drive, rq, 0);
 
-       /* If it was the last datablock check status and finish transfer. */
+       /* Are we done? Check status and finish transfer. */
        if (!hwif->nleft) {
                stat = wait_drive_not_busy(drive);
                if (!OK_STAT(stat, 0, BAD_STAT))
@@ -465,7 +482,7 @@ static ide_startstop_t task_out_intr (ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
        struct request *rq = HWGROUP(drive)->rq;
-       u8 stat = hwif->INB(IDE_STATUS_REG);
+       u8 stat = ide_read_status(drive);
 
        if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
                return task_error(drive, rq, __FUNCTION__, stat);
@@ -798,8 +815,11 @@ int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
            tf->nsect >= XFER_SW_DMA_0 &&
            (id->dma_ultra || id->dma_mword || id->dma_1word)) {
                xfer_rate = args[1];
-               if (ide_ata66_check(drive, &tfargs))
+               if (tf->nsect > XFER_UDMA_2 && !eighty_ninty_three(drive)) {
+                       printk(KERN_WARNING "%s: UDMA speeds >UDMA33 cannot "
+                                           "be set\n", drive->name);
                        goto abort;
+               }
        }
 
        err = ide_raw_taskfile(drive, &tfargs, buf, args[3]);