linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 4/6] ide: add ide_busy_sleep() helper
@ 2007-12-03 21:52 Bartlomiej Zolnierkiewicz
  2007-12-04 12:32 ` Sergei Shtylyov
  0 siblings, 1 reply; 3+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2007-12-03 21:52 UTC (permalink / raw)
  To: linux-ide


Add ide_busy_sleep() helper and use it in do_probe(),
enable_nest() and probe_hwif().

As a nice side-effect this fixes a minor bug in enable_nest()
(the code was reading status register without any delay).

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-probe.c |   43 +++++++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 22 deletions(-)

Index: b/drivers/ide/ide-probe.c
===================================================================
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -382,6 +382,20 @@ static int try_to_identify (ide_drive_t 
 	return retval;
 }
 
+static int ide_busy_sleep(ide_hwif_t *hwif)
+{
+	unsigned long timeout = jiffies + WAIT_WORSTCASE;
+	u8 stat;
+
+	do {
+		msleep(50);
+		stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);
+		if ((stat & BUSY_STAT) == 0)
+			return 0;
+	} while (time_before(jiffies, timeout));
+
+	return 1;
+}
 
 /**
  *	do_probe		-	probe an IDE device
@@ -450,7 +464,6 @@ static int do_probe (ide_drive_t *drive,
 		if ((rc == 1 && cmd == WIN_PIDENTIFY) &&
 			((drive->autotune == IDE_TUNE_DEFAULT) ||
 			(drive->autotune == IDE_TUNE_AUTO))) {
-			unsigned long timeout;
 			printk("%s: no response (status = 0x%02x), "
 				"resetting drive\n", drive->name,
 				hwif->INB(IDE_STATUS_REG));
@@ -458,10 +471,7 @@ static int do_probe (ide_drive_t *drive,
 			hwif->OUTB(drive->select.all, IDE_SELECT_REG);
 			msleep(50);
 			hwif->OUTB(WIN_SRST, IDE_COMMAND_REG);
-			timeout = jiffies;
-			while (((hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) &&
-			       time_before(jiffies, timeout + WAIT_WORSTCASE))
-				msleep(50);
+			(void)ide_busy_sleep(hwif);
 			rc = try_to_identify(drive, cmd);
 		}
 		if (rc == 1)
@@ -489,20 +499,16 @@ static int do_probe (ide_drive_t *drive,
 static void enable_nest (ide_drive_t *drive)
 {
 	ide_hwif_t *hwif = HWIF(drive);
-	unsigned long timeout;
 
 	printk("%s: enabling %s -- ", hwif->name, drive->id->model);
 	SELECT_DRIVE(drive);
 	msleep(50);
 	hwif->OUTB(EXABYTE_ENABLE_NEST, IDE_COMMAND_REG);
-	timeout = jiffies + WAIT_WORSTCASE;
-	do {
-		if (time_after(jiffies, timeout)) {
-			printk("failed (timeout)\n");
-			return;
-		}
-		msleep(50);
-	} while ((hwif->INB(IDE_STATUS_REG)) & BUSY_STAT);
+
+	if (ide_busy_sleep(hwif)) {
+		printk(KERN_CONT "failed (timeout)\n");
+		return;
+	}
 
 	msleep(50);
 
@@ -783,18 +789,11 @@ static void probe_hwif(ide_hwif_t *hwif)
 		}
 	}
 	if (hwif->io_ports[IDE_CONTROL_OFFSET] && hwif->reset) {
-		unsigned long timeout = jiffies + WAIT_WORSTCASE;
-		u8 stat;
-
 		printk(KERN_WARNING "%s: reset\n", hwif->name);
 		hwif->OUTB(12, hwif->io_ports[IDE_CONTROL_OFFSET]);
 		udelay(10);
 		hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]);
-		do {
-			msleep(50);
-			stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);
-		} while ((stat & BUSY_STAT) && time_after(timeout, jiffies));
-
+		(void)ide_busy_sleep(hwif);
 	}
 	local_irq_restore(flags);
 	/*

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 4/6] ide: add ide_busy_sleep() helper
  2007-12-03 21:52 [PATCH 4/6] ide: add ide_busy_sleep() helper Bartlomiej Zolnierkiewicz
@ 2007-12-04 12:32 ` Sergei Shtylyov
  2007-12-04 14:01   ` Bartlomiej Zolnierkiewicz
  0 siblings, 1 reply; 3+ messages in thread
From: Sergei Shtylyov @ 2007-12-04 12:32 UTC (permalink / raw)
  To: Bartlomiej Zolnierkiewicz; +Cc: linux-ide

Bartlomiej Zolnierkiewicz wrote:

> Add ide_busy_sleep() helper and use it in do_probe(),
> enable_nest() and probe_hwif().

> As a nice side-effect this fixes a minor bug in enable_nest()
> (the code was reading status register without any delay).

    Huh?

> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>

Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>

> Index: b/drivers/ide/ide-probe.c
> ===================================================================
> --- a/drivers/ide/ide-probe.c
> +++ b/drivers/ide/ide-probe.c
[...]
> @@ -489,20 +499,16 @@ static int do_probe (ide_drive_t *drive,
>  static void enable_nest (ide_drive_t *drive)
>  {
>  	ide_hwif_t *hwif = HWIF(drive);
> -	unsigned long timeout;
>  
>  	printk("%s: enabling %s -- ", hwif->name, drive->id->model);
>  	SELECT_DRIVE(drive);
>  	msleep(50);
>  	hwif->OUTB(EXABYTE_ENABLE_NEST, IDE_COMMAND_REG);
> -	timeout = jiffies + WAIT_WORSTCASE;
> -	do {
> -		if (time_after(jiffies, timeout)) {
> -			printk("failed (timeout)\n");
> -			return;
> -		}
> -		msleep(50);

    Here's a delay, isn't it?

> -	} while ((hwif->INB(IDE_STATUS_REG)) & BUSY_STAT);
> +
> +	if (ide_busy_sleep(hwif)) {
> +		printk(KERN_CONT "failed (timeout)\n");
> +		return;
> +	}
>  
>  	msleep(50);

MBR, Sergei

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 4/6] ide: add ide_busy_sleep() helper
  2007-12-04 12:32 ` Sergei Shtylyov
@ 2007-12-04 14:01   ` Bartlomiej Zolnierkiewicz
  0 siblings, 0 replies; 3+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2007-12-04 14:01 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: linux-ide


Hi,

On Tuesday 04 December 2007, Sergei Shtylyov wrote:
> Bartlomiej Zolnierkiewicz wrote:
> 
> > Add ide_busy_sleep() helper and use it in do_probe(),
> > enable_nest() and probe_hwif().
> 
> > As a nice side-effect this fixes a minor bug in enable_nest()
> > (the code was reading status register without any delay).
> 
>     Huh?
> 
> > Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
> 
> Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
> 
> > Index: b/drivers/ide/ide-probe.c
> > ===================================================================
> > --- a/drivers/ide/ide-probe.c
> > +++ b/drivers/ide/ide-probe.c
> [...]
> > @@ -489,20 +499,16 @@ static int do_probe (ide_drive_t *drive,
> >  static void enable_nest (ide_drive_t *drive)
> >  {
> >  	ide_hwif_t *hwif = HWIF(drive);
> > -	unsigned long timeout;
> >  
> >  	printk("%s: enabling %s -- ", hwif->name, drive->id->model);
> >  	SELECT_DRIVE(drive);
> >  	msleep(50);
> >  	hwif->OUTB(EXABYTE_ENABLE_NEST, IDE_COMMAND_REG);
> > -	timeout = jiffies + WAIT_WORSTCASE;
> > -	do {
> > -		if (time_after(jiffies, timeout)) {
> > -			printk("failed (timeout)\n");
> > -			return;
> > -		}
> > -		msleep(50);
> 
>     Here's a delay, isn't it?

s/enable_nest/do_probe/

Thanks for pointing this out, I fixed patch description locally.

> > -	} while ((hwif->INB(IDE_STATUS_REG)) & BUSY_STAT);
> > +
> > +	if (ide_busy_sleep(hwif)) {
> > +		printk(KERN_CONT "failed (timeout)\n");
> > +		return;
> > +	}
> >  
> >  	msleep(50);

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-12-04 13:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-03 21:52 [PATCH 4/6] ide: add ide_busy_sleep() helper Bartlomiej Zolnierkiewicz
2007-12-04 12:32 ` Sergei Shtylyov
2007-12-04 14:01   ` Bartlomiej Zolnierkiewicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).