Skip to contentSkip to conversation

ide: ide_find_best_pio_mode() fixes

PATCH In review Bartlomiej Zolnierkiewicz 2 participants 5 messages Jun 30, 2007 – Jul 4, 2007 libata

lore
Share & tools
lore
#0 lore raw

PATCH 6/15 ide: ide_find_best_pio_mode() fixes

* Check IORDY bit for PIO modes > 2.

* Some devices claim maximum PIO mode > 2 in id->tPIO, they were punished too severly for this by being limited to PIO_SLOW. Limit them to PIO2 instead.

---
 drivers/ide/ide-timing.h |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/ide/ide-timing.h +4 -6
Index: b/drivers/ide/ide-timing.h
===================================================================
@@ -111,16 +111,14 @@ static short ide_find_best_pio_mode(ide_
 	struct hd_driveid *id = drive->id;
 	short best = 0;
 
-	if (id->field_valid & 2) {	/* EIDE PIO modes */
-
+	/* EIDE PIO modes */
+	if ((id->field_valid & 2) && (id->capability & 8)) {
 		if ((best = (drive->id->eide_pio_modes & 4) ? XFER_PIO_5 :
 			    (drive->id->eide_pio_modes & 2) ? XFER_PIO_4 :
 			    (drive->id->eide_pio_modes & 1) ? XFER_PIO_3 : 0)) return best;
 	}
-	
-	return  (drive->id->tPIO == 2) ? XFER_PIO_2 :
-		(drive->id->tPIO == 1) ? XFER_PIO_1 :
-		(drive->id->tPIO == 0) ? XFER_PIO_0 : XFER_PIO_SLOW;
+
+	return min_t(u8, id->tPIO, 2);
 }
 
 static void ide_timing_quantize(struct ide_timing *t, struct ide_timing *q, int T, int UT)
#1 lore raw

Hello.

Quoted 6 lines · Bartlomiej Zolnierkiewicz

* Check IORDY bit for PIO modes > 2.

* Some devices claim maximum PIO mode > 2 in id->tPIO, they were punished too severly for this by being limited to PIO_SLOW. Limit them to PIO2 instead.

NAK. :-)

Quoted 12 lines

Index: b/drivers/ide/ide-timing.h
===================================================================

drivers/ide/ide-timing.h +2 -2
@@ -111,16 +111,14 @@ static short ide_find_best_pio_mode(ide_
 	struct hd_driveid *id = drive->id;
 	short best = 0;
 
-	if (id->field_valid & 2) {	/* EIDE PIO modes */
-
+	/* EIDE PIO modes */
+	if ((id->field_valid & 2) && (id->capability & 8)) {

drivers/ide/ide-timing.h static short ide_find_best_pio_mode(ide_ · line 121

Quoted 10 lines
drivers/ide/ide-timing.h +2 -4
 		if ((best = (drive->id->eide_pio_modes & 4) ? XFER_PIO_5 :
 			    (drive->id->eide_pio_modes & 2) ? XFER_PIO_4 :
 			    (drive->id->eide_pio_modes & 1) ? XFER_PIO_3 : 0)) return best;
 	}
-	
-	return  (drive->id->tPIO == 2) ? XFER_PIO_2 :
-		(drive->id->tPIO == 1) ? XFER_PIO_1 :
-		(drive->id->tPIO == 0) ? XFER_PIO_0 : XFER_PIO_SLOW;
+
+	return min_t(u8, id->tPIO, 2);

XFER_PIO_[012] != [012], and otherwise you're returning XFER_PIO_* constants.

MBR, Sergei

author Reviewed-by Sergei Shtylyov
#2 lore raw
Quoted 20 lines · Sergei Shtylyov

Hello.

Quoted 6 lines · Bartlomiej Zolnierkiewicz

* Check IORDY bit for PIO modes > 2.

* Some devices claim maximum PIO mode > 2 in id->tPIO, they were punished too severly for this by being limited to PIO_SLOW. Limit them to PIO2 instead.

    NAK. :-)
Quoted 8 lines

Index: b/drivers/ide/ide-timing.h
===================================================================

drivers/ide/ide-timing.h +0 -0
@@ -111,16 +111,14 @@ static short ide_find_best_pio_mode(ide_
 	struct hd_driveid *id = drive->id;
 	short best = 0;
 
Quoted 16 lines
Quoted 4 lines
drivers/ide/ide-timing.h +2 -2
-	if (id->field_valid & 2) {	/* EIDE PIO modes */
-
+	/* EIDE PIO modes */
+	if ((id->field_valid & 2) && (id->capability & 8)) {

drivers/ide/ide-timing.h static short ide_find_best_pio_mode(ide_ · line 121

Quoted 10 lines
drivers/ide/ide-timing.h +2 -4
 		if ((best = (drive->id->eide_pio_modes & 4) ? XFER_PIO_5 :
 			    (drive->id->eide_pio_modes & 2) ? XFER_PIO_4 :
 			    (drive->id->eide_pio_modes & 1) ? XFER_PIO_3 : 0)) return best;
 	}
-	
-	return  (drive->id->tPIO == 2) ? XFER_PIO_2 :
-		(drive->id->tPIO == 1) ? XFER_PIO_1 :
-		(drive->id->tPIO == 0) ? XFER_PIO_0 : XFER_PIO_SLOW;
+
+	return min_t(u8, id->tPIO, 2);
    XFER_PIO_[012] != [012], and otherwise you're returning XFER_PIO_* constants.

Oh, crap, there should be "+ XFER_PIO_0" in the return line - fixed.

Thanks for spotting this bug, revised patch included.

[PATCH] ide: ide_find_best_pio_mode() fixes (take 2)

* Check IORDY bit for PIO modes > 2.

* Some devices claim maximum PIO mode > 2 in id->tPIO, they were punished too severly for this by being limited to PIO_SLOW. Limit them to PIO2 instead.

v2:
* Fix PIO number being returned incorrectly instead of PIO mode (Noticed by Sergei).

---
 drivers/ide/ide-timing.h |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/ide/ide-timing.h +4 -6
Index: b/drivers/ide/ide-timing.h
===================================================================
@@ -111,16 +111,14 @@ static short ide_find_best_pio_mode(ide_
 	struct hd_driveid *id = drive->id;
 	short best = 0;
 
-	if (id->field_valid & 2) {	/* EIDE PIO modes */
-
+	/* EIDE PIO modes */
+	if ((id->field_valid & 2) && (id->capability & 8)) {
 		if ((best = (drive->id->eide_pio_modes & 4) ? XFER_PIO_5 :
 			    (drive->id->eide_pio_modes & 2) ? XFER_PIO_4 :
 			    (drive->id->eide_pio_modes & 1) ? XFER_PIO_3 : 0)) return best;
 	}
-	
-	return  (drive->id->tPIO == 2) ? XFER_PIO_2 :
-		(drive->id->tPIO == 1) ? XFER_PIO_1 :
-		(drive->id->tPIO == 0) ? XFER_PIO_0 : XFER_PIO_SLOW;
+
+	return XFER_PIO_0 + min_t(u8, id->tPIO, 2);
 }
 
 static void ide_timing_quantize(struct ide_timing *t, struct ide_timing *q, int T, int UT)
#3 lore raw

Hello.

Quoted 4 lines · Bartlomiej Zolnierkiewicz

[PATCH] ide: ide_find_best_pio_mode() fixes (take 2)

* Check IORDY bit for PIO modes > 2.

Quoted 8 lines

* Some devices claim maximum PIO mode > 2 in id->tPIO, they were punished too severly for this by being limited to PIO_SLOW. Limit them to PIO2 instead.

v2:
* Fix PIO number being returned incorrectly instead of PIO mode (Noticed by Sergei).

MBR, Sergei

#4 lore raw
Quoted 11 lines · Sergei Shtylyov

Hello.

Quoted 6 lines · Bartlomiej Zolnierkiewicz

[PATCH] ide: ide_find_best_pio_mode() fixes (take 2)

* Check IORDY bit for PIO modes > 2.

* Some devices claim maximum PIO mode > 2 in id->tPIO, they were punished too severly for this by being limited to PIO_SLOW. Limit them to PIO2 instead.

Quoted 7 lines
Quoted 5 lines

v2:
* Fix PIO number being returned incorrectly instead of PIO mode (Noticed by Sergei).

added