ide: enhance ide_busy_sleep()

* Make ide_busy_sleep() take timeout value as a parameter
  and also allow use of AltStatus Register if requested with
  altstatus parameter.  Update existing users accordingly.

* Convert ide_driveid_update() and actual_try_to_identify()
  to use ide_busy_sleep().

There should be no functional changes caused by this patch.
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
parent c36a7e98
...@@ -666,7 +666,7 @@ int ide_driveid_update(ide_drive_t *drive) ...@@ -666,7 +666,7 @@ int ide_driveid_update(ide_drive_t *drive)
ide_hwif_t *hwif = drive->hwif; ide_hwif_t *hwif = drive->hwif;
const struct ide_tp_ops *tp_ops = hwif->tp_ops; const struct ide_tp_ops *tp_ops = hwif->tp_ops;
u16 *id; u16 *id;
unsigned long timeout, flags; unsigned long flags;
u8 stat; u8 stat;
/* /*
...@@ -678,16 +678,11 @@ int ide_driveid_update(ide_drive_t *drive) ...@@ -678,16 +678,11 @@ int ide_driveid_update(ide_drive_t *drive)
tp_ops->set_irq(hwif, 0); tp_ops->set_irq(hwif, 0);
msleep(50); msleep(50);
tp_ops->exec_command(hwif, ATA_CMD_ID_ATA); tp_ops->exec_command(hwif, ATA_CMD_ID_ATA);
timeout = jiffies + WAIT_WORSTCASE;
do {
if (time_after(jiffies, timeout)) {
SELECT_MASK(drive, 0);
return 0; /* drive timed-out */
}
msleep(50); /* give drive a breather */ if (ide_busy_sleep(hwif, WAIT_WORSTCASE, 1)) {
stat = tp_ops->read_altstatus(hwif); SELECT_MASK(drive, 0);
} while (stat & ATA_BUSY); return 0;
}
msleep(50); /* wait for IRQ and ATA_DRQ */ msleep(50); /* wait for IRQ and ATA_DRQ */
stat = tp_ops->read_status(hwif); stat = tp_ops->read_status(hwif);
......
...@@ -291,17 +291,9 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd) ...@@ -291,17 +291,9 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
tp_ops->exec_command(hwif, cmd); tp_ops->exec_command(hwif, cmd);
timeout = ((cmd == ATA_CMD_ID_ATA) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2; timeout = ((cmd == ATA_CMD_ID_ATA) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
timeout += jiffies;
do { if (ide_busy_sleep(hwif, timeout, use_altstatus))
if (time_after(jiffies, timeout)) { return 1;
/* drive timed-out */
return 1;
}
/* give drive a breather */
msleep(50);
s = use_altstatus ? tp_ops->read_altstatus(hwif)
: tp_ops->read_status(hwif);
} while (s & ATA_BUSY);
/* wait for IRQ and ATA_DRQ */ /* wait for IRQ and ATA_DRQ */
msleep(50); msleep(50);
...@@ -383,19 +375,21 @@ static int try_to_identify (ide_drive_t *drive, u8 cmd) ...@@ -383,19 +375,21 @@ static int try_to_identify (ide_drive_t *drive, u8 cmd)
return retval; return retval;
} }
static int ide_busy_sleep(ide_hwif_t *hwif) int ide_busy_sleep(ide_hwif_t *hwif, unsigned long timeout, int altstatus)
{ {
unsigned long timeout = jiffies + WAIT_WORSTCASE;
u8 stat; u8 stat;
timeout += jiffies;
do { do {
msleep(50); msleep(50); /* give drive a breather */
stat = hwif->tp_ops->read_status(hwif); stat = altstatus ? hwif->tp_ops->read_altstatus(hwif)
: hwif->tp_ops->read_status(hwif);
if ((stat & ATA_BUSY) == 0) if ((stat & ATA_BUSY) == 0)
return 0; return 0;
} while (time_before(jiffies, timeout)); } while (time_before(jiffies, timeout));
return 1; return 1; /* drive timed-out */
} }
static u8 ide_read_device(ide_drive_t *drive) static u8 ide_read_device(ide_drive_t *drive)
...@@ -489,7 +483,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd) ...@@ -489,7 +483,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
SELECT_DRIVE(drive); SELECT_DRIVE(drive);
msleep(50); msleep(50);
tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET); tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
(void)ide_busy_sleep(hwif); (void)ide_busy_sleep(hwif, WAIT_WORSTCASE, 0);
rc = try_to_identify(drive, cmd); rc = try_to_identify(drive, cmd);
} }
...@@ -529,7 +523,7 @@ static void enable_nest (ide_drive_t *drive) ...@@ -529,7 +523,7 @@ static void enable_nest (ide_drive_t *drive)
msleep(50); msleep(50);
tp_ops->exec_command(hwif, ATA_EXABYTE_ENABLE_NEST); tp_ops->exec_command(hwif, ATA_EXABYTE_ENABLE_NEST);
if (ide_busy_sleep(hwif)) { if (ide_busy_sleep(hwif, WAIT_WORSTCASE, 0)) {
printk(KERN_CONT "failed (timeout)\n"); printk(KERN_CONT "failed (timeout)\n");
return; return;
} }
......
...@@ -923,6 +923,8 @@ void ide_fix_driveid(u16 *); ...@@ -923,6 +923,8 @@ void ide_fix_driveid(u16 *);
extern void ide_fixstring(u8 *, const int, const int); extern void ide_fixstring(u8 *, const int, const int);
int ide_busy_sleep(ide_hwif_t *, unsigned long, int);
int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long); int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long);
extern ide_startstop_t ide_do_reset (ide_drive_t *); extern ide_startstop_t ide_do_reset (ide_drive_t *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment