Skip to contentSkip to conversation

Use correct IDE error recovery

PATCH In review Suleiman Souhlal 4 participants 8 messages Feb 21, 2007 – Mar 24, 2007 libata

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 Use correct IDE error recovery

IDE error recovery is using WIN_IDLEIMMEDIATE which was only valid for IDE V1 and IDE V2. Modern drives will not be able to recover using this error handling. The correct thing to do is issue a SRST followed by a SET_FEATURES.

---
 drivers/ide/ide-io.c   |   35 +++++++++++-----
 drivers/ide/ide-iops.c |  105 ++++++++++++++++++++++++++++--------------------
 include/linux/ide.h    |    2 +
 3 files changed, 88 insertions(+), 54 deletions(-)
drivers/ide/ide-io.c +24 -11
index c193553..2f05b4d 100644
@@ -519,21 +519,21 @@ static ide_startstop_t ide_ata_error(ide
 	if ((stat & DRQ_STAT) && rq_data_dir(rq) == READ && hwif->err_stops_fifo == 0)
 		try_to_flush_leftover_data(drive);
 
+	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq)) {
+		ide_kill_rq(drive, rq);
+		return ide_stopped;
+	}
+
 	if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
-		/* force an abort */
-		hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG);
+		rq->errors |= ERROR_RESET;
 
-	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq))
-		ide_kill_rq(drive, rq);
-	else {
-		if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
-			++rq->errors;
-			return ide_do_reset(drive);
-		}
-		if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
-			drive->special.b.recalibrate = 1;
+	if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
 		++rq->errors;
+		return ide_do_reset(drive);
 	}
+
+	++rq->errors;
+
 	return ide_stopped;
 }
 
@@ -586,6 +586,13 @@ EXPORT_SYMBOL_GPL(__ide_error);
  *	both new-style (taskfile) and old style command handling here.
  *	In the case of taskfile command handling there is work left to
  *	do
+ *	This used to send a idle immediate to the drive if the drive was
+ *	busy or had drq set.  This violates the ATA spec (can only send IDLE
+ *	immediate when drive is not busy) and really hoses up some drives.
+ *	We've changed it to just do a SRST followed by a set features (set
+ *	udma mode) it those cases.  This is what Western Digital recommends
+ *	for error recovery and what Western Digital says Windows does.  It
+ *	also does not violate the ATA spec as far as I can tell.
  */
  
 ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, u8 stat)
@@ -1004,6 +1011,12 @@ #endif
 		goto kill_rq;
 	}
 
+	/* We reset the drive so we need to issue a SETFEATURES. */
+	if ((drive->current_speed == 0xff) &&
+	    ((rq->cmd_type == REQ_TYPE_ATA_CMD) ||
+	    (rq->cmd_type == REQ_TYPE_ATA_TASK)))
+		ide_config_drive_speed_irq(drive, drive->desired_speed);
+
 	block    = rq->sector;
 	if (blk_fs_request(rq) &&
 	    (drive->media == ide_disk || drive->media == ide_floppy)) {
drivers/ide/ide-iops.c +62 -43

134 lines not on this page · raw message

include/linux/ide.h +2 -0
index 3861753..c7f6027 100644
@@ -616,6 +616,7 @@ typedef struct ide_drive_s {
         u8	init_speed;	/* transfer rate set at boot */
         u8	pio_speed;      /* unused by core, used by some drivers for fallback from DMA */
         u8	current_speed;	/* current transfer rate set */
+        u8	desired_speed;	/* desired transfer rate set */
         u8	dn;		/* now wide spread use */
         u8	wcache;		/* status of write cache */
 	u8	acoustic;	/* acoustic management */
@@ -1184,6 +1185,7 @@ extern int system_bus_clock(void);
 extern int ide_driveid_update(ide_drive_t *);
 extern int ide_ata66_check(ide_drive_t *, ide_task_t *);
 extern int ide_config_drive_speed(ide_drive_t *, u8);
+extern int ide_config_drive_speed_irq(ide_drive_t *, u8);
 extern u8 eighty_ninty_three (ide_drive_t *);
 extern int set_transfer(ide_drive_t *, ide_task_t *);
 extern int taskfile_lib_get_identify(ide_drive_t *drive, u8 *);
#1 lore raw

Hi,

(sorry for the long delay)

Quoted 4 lines · Suleiman Souhlal

IDE error recovery is using WIN_IDLEIMMEDIATE which was only valid for IDE V1 and IDE V2. Modern drives will not be able to recover using this error handling. The correct thing to do is issue a SRST followed by a SET_FEATURES.

This change looks fine, indeed we are better of using SRST + SET_FEATURES than IDLE_IMMEDIATE.

Quoted 25 lines
---
 drivers/ide/ide-io.c   |   35 +++++++++++-----
 drivers/ide/ide-iops.c |  105 ++++++++++++++++++++++++++++--------------------
 include/linux/ide.h    |    2 +
 3 files changed, 88 insertions(+), 54 deletions(-)
drivers/ide/ide-io.c +6 -2
index c193553..2f05b4d 100644
@@ -519,21 +519,21 @@ static ide_startstop_t ide_ata_error(ide
 	if ((stat & DRQ_STAT) && rq_data_dir(rq) == READ && hwif->err_stops_fifo == 0)
 		try_to_flush_leftover_data(drive);
 
+	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq)) {
+		ide_kill_rq(drive, rq);
+		return ide_stopped;
+	}
+
 	if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
-		/* force an abort */
-		hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG);
+		rq->errors |= ERROR_RESET;

drivers/ide/ide-io.c static ide_startstop_t ide_ata_error(ide · line 534

Quoted 10 lines
drivers/ide/ide-io.c +0 -9
 
-	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq))
-		ide_kill_rq(drive, rq);
-	else {
-		if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
-			++rq->errors;
-			return ide_do_reset(drive);
-		}
-		if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
-			drive->special.b.recalibrate = 1;

Is the removal of ERROR_RECAL handling intentional? There is nothing about it in the patch description...

Quoted 11 lines
drivers/ide/ide-io.c +5 -0
+	if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
 		++rq->errors;
+		return ide_do_reset(drive);
 	}
+
+	++rq->errors;
+
 	return ide_stopped;
 }
 

drivers/ide/ide-io.c EXPORT_SYMBOL_GPL(__ide_error); · line 591

Quoted 6 lines
drivers/ide/ide-io.c +3 -0
@@ -586,6 +586,13 @@ EXPORT_SYMBOL_GPL(__ide_error);
  *	both new-style (taskfile) and old style command handling here.
  *	In the case of taskfile command handling there is work left to
  *	do
+ *	This used to send a idle immediate to the drive if the drive was
+ *	busy or had drq set.  This violates the ATA spec (can only send IDLE
+ *	immediate when drive is not busy) and really hoses up some drives.

Could this part of the comment be merged into the patch description? We don't want to clutter the code with the history of the changes.

drivers/ide/ide-io.c EXPORT_SYMBOL_GPL(__ide_error); · line 593

Quoted 2 lines
drivers/ide/ide-io.c +2 -0
+ *	We've changed it to just do a SRST followed by a set features (set
+ *	udma mode) it those cases.  This is what Western Digital recommends

hmm, it doesn't have to be UDMA mode,
->current_speed can also be PIO/SWDMA/MWDMA

drivers/ide/ide-io.c EXPORT_SYMBOL_GPL(__ide_error); · line 596

Quoted 3 lines
drivers/ide/ide-io.c +2 -0
+ *	for error recovery and what Western Digital says Windows does.  It
+ *	also does not violate the ATA spec as far as I can tell.
  */

The patch fixes code in ide_ata_error() and updates the comment for ide_error() but ide_atapi_error() is not left untouched (it still uses IDLE IMMEDIATE).

I suppose that ide_atapi_error() (for ATAPI devices) needs similar fix?

drivers/ide/ide-io.c #endif · line 1018

Quoted 10 lines
drivers/ide/ide-io.c +5 -0
 ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, u8 stat)
@@ -1004,6 +1011,12 @@ #endif
 		goto kill_rq;
 	}
 
+	/* We reset the drive so we need to issue a SETFEATURES. */
+	if ((drive->current_speed == 0xff) &&
+	    ((rq->cmd_type == REQ_TYPE_ATA_CMD) ||
+	    (rq->cmd_type == REQ_TYPE_ATA_TASK)))
+		ide_config_drive_speed_irq(drive, drive->desired_speed);

Please update the patch to not depend on ide_config_drive_speed() fixes [PATCH 2/3] which need more work (shouldn't be a problem as the code here uses _irq variant anyway).

Please respin the patch so I could merge it.

Thanks,
Bart

Acked-by
#2 lore raw
Quoted 10 lines · Suleiman Souhlal
Quoted 4 lines

IDE error recovery is using WIN_IDLEIMMEDIATE which was only valid for IDE V1 and IDE V2. Modern drives will not be able to recover using this error handling. The correct thing to do is issue a SRST followed by a SET_FEATURES.

This change looks fine, indeed we are better of using SRST + SET_FEATURES than IDLE_IMMEDIATE.

Quoted 1 line

And this is well worth doing - IDLEIMMEDIATE blows the mind of some later drive firmware that doesn't expect to be treated in an IDE v1 manner.

Alan

#3 lore raw
In reply to Bartlomiej Zolnierkiewicz
Quoted 42 lines · Bartlomiej Zolnierkiewicz

Hi,

(sorry for the long delay)

Quoted 4 lines · Suleiman Souhlal

IDE error recovery is using WIN_IDLEIMMEDIATE which was only valid for IDE V1 and IDE V2. Modern drives will not be able to recover using this error handling. The correct thing to do is issue a SRST followed by a SET_FEATURES.

This change looks fine, indeed we are better of using SRST + SET_FEATURES than IDLE_IMMEDIATE.

Quoted 28 lines
---
 drivers/ide/ide-io.c   |   35 +++++++++++-----
 drivers/ide/ide-iops.c |  105 +++++++++++++++++++++++++++ 
+--------------------
 include/linux/ide.h    |    2 +
 3 files changed, 88 insertions(+), 54 deletions(-)
drivers/ide/ide-io.c +6 -2
index c193553..2f05b4d 100644
@@ -519,21 +519,21 @@ static ide_startstop_t ide_ata_error(ide
 	if ((stat & DRQ_STAT) && rq_data_dir(rq) == READ && hwif- 
 >err_stops_fifo == 0)
 		try_to_flush_leftover_data(drive);
 
+	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq)) {
+		ide_kill_rq(drive, rq);
+		return ide_stopped;
+	}
+
 	if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
-		/* force an abort */
-		hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG);
+		rq->errors |= ERROR_RESET;
 
Quoted 12 lines

drivers/ide/ide-io.c static ide_startstop_t ide_ata_error(ide · line 534

Quoted 9 lines
drivers/ide/ide-io.c +0 -9
-	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq))
-		ide_kill_rq(drive, rq);
-	else {
-		if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
-			++rq->errors;
-			return ide_do_reset(drive);
-		}
-		if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
-			drive->special.b.recalibrate = 1;

Is the removal of ERROR_RECAL handling intentional? There is nothing about it in the patch description...

Yes, it was intentional, but I forgot to add "while there remove some useless code" to the description. Maybe it's better if I send this as a separate patch.

Quoted 37 lines
Quoted 17 lines
drivers/ide/ide-io.c +7 -0
+	if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
 		++rq->errors;
+		return ide_do_reset(drive);
 	}
+
+	++rq->errors;
+
 	return ide_stopped;
 }
@@ -586,6 +586,13 @@ EXPORT_SYMBOL_GPL(__ide_error);
  *	both new-style (taskfile) and old style command handling here.
  *	In the case of taskfile command handling there is work left to
  *	do
+ *	This used to send a idle immediate to the drive if the drive was
+ *	busy or had drq set.  This violates the ATA spec (can only  
Quoted 3 lines

send IDLE
+ * immediate when drive is not busy) and really hoses up some
drives.

Could this part of the comment be merged into the patch description? We don't want to clutter the code with the history of the changes.

Quoted 4 lines

+ * We've changed it to just do a SRST followed by a set features
(set
+ * udma mode) it those cases. This is what Western Digital
recommends

hmm, it doesn't have to be UDMA mode,
->current_speed can also be PIO/SWDMA/MWDMA

Quoted 4 lines

+ * for error recovery and what Western Digital says Windows
does. It
+ * also does not violate the ATA spec as far as I can tell.
*/

Quoted 5 lines

The patch fixes code in ide_ata_error() and updates the comment for ide_error() but ide_atapi_error() is not left untouched (it still uses IDLE IMMEDIATE).

I suppose that ide_atapi_error() (for ATAPI devices) needs similar fix?

I'm not sure.. I don't have any ATAPI hardware to test this on either, so I preferred not to touch it.

Quoted 16 lines

drivers/ide/ide-io.c #endif · line 1018

Quoted 11 lines

ide_startstop_t ide_error (ide_drive_t *drive, const char *msg,
u8 stat)

drivers/ide/ide-io.c +5 -0
@@ -1004,6 +1011,12 @@ #endif
 		goto kill_rq;
 	}
 
+	/* We reset the drive so we need to issue a SETFEATURES. */
+	if ((drive->current_speed == 0xff) &&
+	    ((rq->cmd_type == REQ_TYPE_ATA_CMD) ||
+	    (rq->cmd_type == REQ_TYPE_ATA_TASK)))
+		ide_config_drive_speed_irq(drive, drive->desired_speed);

Please update the patch to not depend on ide_config_drive_speed() fixes [PATCH 2/3] which need more work (shouldn't be a problem as the code here uses _irq variant anyway).

Quoted 1 line

Please respin the patch so I could merge it.

Ok.

-- Suleiman

#4 lore raw

Hi,

Quoted 57 lines · Suleiman Souhlal
Quoted 41 lines · Bartlomiej Zolnierkiewicz

Hi,

(sorry for the long delay)

Quoted 4 lines · Suleiman Souhlal

IDE error recovery is using WIN_IDLEIMMEDIATE which was only valid for IDE V1 and IDE V2. Modern drives will not be able to recover using this error handling. The correct thing to do is issue a SRST followed by a SET_FEATURES.

This change looks fine, indeed we are better of using SRST + SET_FEATURES than IDLE_IMMEDIATE.

Quoted 27 lines
---
 drivers/ide/ide-io.c   |   35 +++++++++++-----
 drivers/ide/ide-iops.c |  105 ++++++++++++++++++++++++++++--------------------
 include/linux/ide.h    |    2 +
 3 files changed, 88 insertions(+), 54 deletions(-)
drivers/ide/ide-io.c +6 -2
index c193553..2f05b4d 100644
@@ -519,21 +519,21 @@ static ide_startstop_t ide_ata_error(ide
 	if ((stat & DRQ_STAT) && rq_data_dir(rq) == READ && hwif- 
 >err_stops_fifo == 0)
 		try_to_flush_leftover_data(drive);
 
+	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq)) {
+		ide_kill_rq(drive, rq);
+		return ide_stopped;
+	}
+
 	if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
-		/* force an abort */
-		hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG);
+		rq->errors |= ERROR_RESET;
 
Quoted 12 lines

drivers/ide/ide-io.c static ide_startstop_t ide_ata_error(ide · line 534

Quoted 9 lines
drivers/ide/ide-io.c +0 -9
-	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq))
-		ide_kill_rq(drive, rq);
-	else {
-		if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
-			++rq->errors;
-			return ide_do_reset(drive);
-		}
-		if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
-			drive->special.b.recalibrate = 1;

Is the removal of ERROR_RECAL handling intentional? There is nothing about it in the patch description...

Quoted 1 line

Yes, it was intentional, but I forgot to add "while there remove some

Why is it useless? What am I missing?

Quoted 2 lines

useless code" to the description. Maybe it's better if I send this as a separate patch.

Yes, please do so.

[ ... ]

Quoted 9 lines
Quoted 6 lines

The patch fixes code in ide_ata_error() and updates the comment for ide_error() but ide_atapi_error() is not left untouched (it still uses IDLE IMMEDIATE).

I suppose that ide_atapi_error() (for ATAPI devices) needs similar fix?

I'm not sure.. I don't have any ATAPI hardware to test this on either, so I preferred not to touch it.

OK, this could be fixed later in the incremental patch.

Quoted 15 lines
Quoted 15 lines

drivers/ide/ide-io.c #endif · line 1018

Quoted 10 lines
drivers/ide/ide-io.c +5 -0
 ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, u8 stat)
@@ -1004,6 +1011,12 @@ #endif
 		goto kill_rq;
 	}
 
+	/* We reset the drive so we need to issue a SETFEATURES. */
+	if ((drive->current_speed == 0xff) &&
+	    ((rq->cmd_type == REQ_TYPE_ATA_CMD) ||
+	    (rq->cmd_type == REQ_TYPE_ATA_TASK)))
+		ide_config_drive_speed_irq(drive, drive->desired_speed);

Please update the patch to not depend on ide_config_drive_speed() fixes [PATCH 2/3] which need more work (shouldn't be a problem as the code here uses _irq variant anyway).

Quoted 3 lines
Quoted 1 line

Please respin the patch so I could merge it.

Ok.

Thanks,
Bart

#5 lore raw
Quoted 62 lines · Bartlomiej Zolnierkiewicz

Hi,

Quoted 58 lines · Suleiman Souhlal
Quoted 54 lines · Bartlomiej Zolnierkiewicz

Hi,

(sorry for the long delay)

Quoted 4 lines · Suleiman Souhlal

IDE error recovery is using WIN_IDLEIMMEDIATE which was only valid for IDE V1 and IDE V2. Modern drives will not be able to recover using this error handling. The correct thing to do is issue a SRST followed by a SET_FEATURES.

This change looks fine, indeed we are better of using SRST + SET_FEATURES than IDLE_IMMEDIATE.

Quoted 27 lines
---
 drivers/ide/ide-io.c   |   35 +++++++++++-----
 drivers/ide/ide-iops.c |  105 +++++++++++++++++++++++++++ 
+--------------------
 include/linux/ide.h    |    2 +
 3 files changed, 88 insertions(+), 54 deletions(-)
drivers/ide/ide-io.c +6 -2
index c193553..2f05b4d 100644
@@ -519,21 +519,21 @@ static ide_startstop_t ide_ata_error(ide
 	if ((stat & DRQ_STAT) && rq_data_dir(rq) == READ && hwif-
 > err_stops_fifo == 0)
 		try_to_flush_leftover_data(drive);
 
+	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq)) {
+		ide_kill_rq(drive, rq);
+		return ide_stopped;
+	}
+
 	if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
-		/* force an abort */
-		hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG);
+		rq->errors |= ERROR_RESET;

drivers/ide/ide-io.c static ide_startstop_t ide_ata_error(ide · line 535

Quoted 10 lines
drivers/ide/ide-io.c +0 -9
 
-	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq))
-		ide_kill_rq(drive, rq);
-	else {
-		if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
-			++rq->errors;
-			return ide_do_reset(drive);
-		}
-		if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
-			drive->special.b.recalibrate = 1;

Is the removal of ERROR_RECAL handling intentional? There is nothing about it in the patch description...

Quoted 3 lines
Quoted 1 line

Yes, it was intentional, but I forgot to add "while there remove some

Why is it useless? What am I missing?

I thought the recalibration code didn't do anything, but upon rereading the code I'm not so sure anymore..

-- Suleiman

Acked-by Alan Cox
#6 lore raw
In reply to Suleiman Souhlal

Hi,

Quoted 6 lines · Suleiman Souhlal
Quoted 1 line · Bartlomiej Zolnierkiewicz

Please respin the patch so I could merge it.

Ok.

Since I think that it's worth to have it in 2.6.21-final and respin didn't happen I did the required changes myself (it also turned out that I missed few things during initial review), then applied the patch...

Please let my know whether you are fine with my changes, thanks.

[PATCH] ide: use correct IDE error recovery

From: Suleiman Souhlal <[email protected]>

IDE error recovery is using IDLE IMMEDIATE if the drive is busy or has DRQ set. This violates the ATA spec (can only send IDLE IMMEDIATE when drive is not busy) and really hoses up some drives (modern drives will not be able to recover using this error handling). The correct thing to do is issue a SRST followed by a SET FEATURES command. This is what Western Digital recommends for error recovery and what Western Digital says Windows does.  It also does not violate the ATA spec as far as I can tell.

Bart:
* port the patch over the current tree
* undo the recalibration code removal
* send SET FEATURES command after checking for good drive status
* don't check whether the current request is of REQ_TYPE_ATA_{CMD,TASK} type because we need to send SET FEATURES before handling any requests
* some pre-ATA4 drives require INITIALIZE DEVICE PARAMETERS command before other commands (except IDENTIFY) so send SET FEATURES only if there are no pending drive->special requests
* update comments and patch description
* any bugs introduced by this patch are mine and not Suleiman's :-)

---

 drivers/ide/ide-io.c   |   32 +++++++++++++++++++++-----------
 drivers/ide/ide-iops.c |    3 +++
 include/linux/ide.h    |    1 +
 3 files changed, 25 insertions(+), 11 deletions(-)
drivers/ide/ide-io.c +21 -11
Index: b/drivers/ide/ide-io.c
===================================================================
@@ -519,21 +519,24 @@ static ide_startstop_t ide_ata_error(ide
 	if ((stat & DRQ_STAT) && rq_data_dir(rq) == READ && hwif->err_stops_fifo == 0)
 		try_to_flush_leftover_data(drive);
 
+	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq)) {
+		ide_kill_rq(drive, rq);
+		return ide_stopped;
+	}
+
 	if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
-		/* force an abort */
-		hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG);
+		rq->errors |= ERROR_RESET;
 
-	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq))
-		ide_kill_rq(drive, rq);
-	else {
-		if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
-			++rq->errors;
-			return ide_do_reset(drive);
-		}
-		if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
-			drive->special.b.recalibrate = 1;
+	if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
 		++rq->errors;
+		return ide_do_reset(drive);
 	}
+
+	if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
+		drive->special.b.recalibrate = 1;
+
+	++rq->errors;
+
 	return ide_stopped;
 }
 
@@ -1025,6 +1028,13 @@ static ide_startstop_t start_request (id
 	if (!drive->special.all) {
 		ide_driver_t *drv;
 
+		/*
+		 * We reset the drive so we need to issue a SETFEATURES.
+		 * Do it _after_ do_special() restored device parameters.
+		 */
+		if (drive->current_speed == 0xff)
+			ide_config_drive_speed(drive, drive->desired_speed);
+
 		if (rq->cmd_type == REQ_TYPE_ATA_CMD ||
 		    rq->cmd_type == REQ_TYPE_ATA_TASK ||
 		    rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
drivers/ide/ide-iops.c +3 -0
Index: b/drivers/ide/ide-iops.c
===================================================================
@@ -1094,6 +1094,9 @@ static void pre_reset(ide_drive_t *drive
 	if (HWIF(drive)->pre_reset != NULL)
 		HWIF(drive)->pre_reset(drive);
 
+	if (drive->current_speed != 0xff)
+		drive->desired_speed = drive->current_speed;
+	drive->current_speed = 0xff;
 }
 
 /*
include/linux/ide.h +1 -0
Index: b/include/linux/ide.h
===================================================================
@@ -615,6 +615,7 @@ typedef struct ide_drive_s {
         u8	init_speed;	/* transfer rate set at boot */
         u8	pio_speed;      /* unused by core, used by some drivers for fallback from DMA */
         u8	current_speed;	/* current transfer rate set */
+	u8	desired_speed;	/* desired transfer rate set */
         u8	dn;		/* now wide spread use */
         u8	wcache;		/* status of write cache */
 	u8	acoustic;	/* acoustic management */
#7 lore raw

Hello.

Quoted 6 lines · Bartlomiej Zolnierkiewicz

Since I think that it's worth to have it in 2.6.21-final and respin didn't happen I did the required changes myself (it also turned out that I missed few things during initial review), then applied the patch...

Please let my know whether you are fine with my changes, thanks.

Quoted 7 lines

[PATCH] ide: use correct IDE error recovery

From: Suleiman Souhlal <[email protected]>

IDE error recovery is using IDLE IMMEDIATE if the drive is busy or has DRQ set. This violates the ATA spec (can only send IDLE IMMEDIATE when drive is not busy) and really hoses up some drives (modern drives will not be able to

I wonder if that really ever worked...

Quoted 4 lines

recover using this error handling). The correct thing to do is issue a SRST followed by a SET FEATURES command. This is what Western Digital recommends for error recovery and what Western Digital says Windows does. It also does not violate the ATA spec as far as I can tell.

The patch even does things *not* required by the spec. :-)

Quoted 23 lines

Index: b/drivers/ide/ide-io.c
===================================================================

drivers/ide/ide-io.c +6 -7
@@ -519,21 +519,24 @@ static ide_startstop_t ide_ata_error(ide
 	if ((stat & DRQ_STAT) && rq_data_dir(rq) == READ && hwif->err_stops_fifo == 0)
 		try_to_flush_leftover_data(drive);
 
+	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq)) {
+		ide_kill_rq(drive, rq);
+		return ide_stopped;
+	}
+
 	if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
-		/* force an abort */
-		hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG);
+		rq->errors |= ERROR_RESET;
 
-	if (rq->errors >= ERROR_MAX || blk_noretry_request(rq))
-		ide_kill_rq(drive, rq);
-	else {
-		if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
-			++rq->errors;

drivers/ide/ide-io.c static ide_startstop_t ide_ata_error(ide · line 535

Quoted 10 lines
drivers/ide/ide-io.c +4 -4
-			return ide_do_reset(drive);
-		}
-		if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
-			drive->special.b.recalibrate = 1;
+	if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
 		++rq->errors;
+		return ide_do_reset(drive);
 	}
+
+	if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)

Hm, is there any need for ==?

Quoted 8 lines
drivers/ide/ide-io.c +4 -0
+		drive->special.b.recalibrate = 1;
+
+	++rq->errors;
+
 	return ide_stopped;
 }
 

drivers/ide/ide-io.c static ide_startstop_t start_request (id · line 1037

Quoted 10 lines
drivers/ide/ide-io.c +7 -0
@@ -1025,6 +1028,13 @@ static ide_startstop_t start_request (id
 	if (!drive->special.all) {
 		ide_driver_t *drv;
 
+		/*
+		 * We reset the drive so we need to issue a SETFEATURES.
+		 * Do it _after_ do_special() restored device parameters.
+		 */
+		if (drive->current_speed == 0xff)
+			ide_config_drive_speed(drive, drive->desired_speed);
+

Hmm, IIRC, drive's UltraDMA mode shall *not* be cleared by reset,
therefore there's no need to restore it.

Quoted 21 lines
drivers/ide/ide-io.c +0 -0
 		if (rq->cmd_type == REQ_TYPE_ATA_CMD ||
 		    rq->cmd_type == REQ_TYPE_ATA_TASK ||
 		    rq->cmd_type == REQ_TYPE_ATA_TASKFILE)

Index: b/drivers/ide/ide-iops.c
===================================================================

drivers/ide/ide-iops.c +3 -0
@@ -1094,6 +1094,9 @@ static void pre_reset(ide_drive_t *drive
 	if (HWIF(drive)->pre_reset != NULL)
 		HWIF(drive)->pre_reset(drive);
 
+	if (drive->current_speed != 0xff)
+		drive->desired_speed = drive->current_speed;
+	drive->current_speed = 0xff;
 }
 /*

Index: b/include/linux/ide.h
===================================================================

include/linux/ide.h typedef struct ide_drive_s { · line 618

Quoted 4 lines
include/linux/ide.h +1 -0
@@ -615,6 +615,7 @@ typedef struct ide_drive_s {
         u8	init_speed;	/* transfer rate set at boot */
         u8	pio_speed;      /* unused by core, used by some drivers for fallback from DMA */
         u8	current_speed;	/* current transfer rate set */
+	u8	desired_speed;	/* desired transfer rate set */

Oh, more of that *_speed crap. :-)

include/linux/ide.h typedef struct ide_drive_s { · line 621

Quoted 3 lines
include/linux/ide.h +0 -0
         u8	dn;		/* now wide spread use */
         u8	wcache;		/* status of write cache */
 	u8	acoustic;	/* acoustic management */

MBR, Sergei