Skip to contentSkip to conversation

tms380tr: fix long delays in initialization

PATCH In review Meelis Roos 2 participants 6 messages Oct 3, 2010 – Oct 4, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tms380tr: fix long delays in initialization

tms380tr driver tries to use udelay (meaning busy loop) for several half second delays during hardware initialization. Crazy overly long busy wait delays mean no delay at all so driver initialization fails without waiting. Fix it by using msleep() for long delays and leave it to udelay() for short delays.

---
 drivers/net/tokenring/tms380tr.c |   32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)
drivers/net/tokenring/tms380tr.c +16 -16
index aaec637..e6dc2df 100644
@@ -177,6 +177,7 @@ static void 	tms380tr_update_rcv_stats(struct net_local *tp,
 			unsigned char DataPtr[], unsigned int Length);
 /* "W" */
 void	 	tms380tr_wait(unsigned long time);
+static void	tms380tr_wait_long(unsigned long time);
 static void 	tms380tr_write_rpl_status(RPL *rpl, unsigned int Status);
 static void 	tms380tr_write_tpl_status(TPL *tpl, unsigned int Status);
 
@@ -1216,20 +1217,19 @@ static void tms380tr_set_multicast_list(struct net_device *dev)
 }
 
 /*
- * Wait for some time (microseconds)
+ * Wait for some time (microseconds) - busy wait
  */
 void tms380tr_wait(unsigned long time)
 {
-#if 0
-	long tmp;
-	
-	tmp = jiffies + time/(1000000/HZ);
-	do {
-		tmp = schedule_timeout_interruptible(tmp);
-	} while(time_after(tmp, jiffies));
-#else
 	udelay(time);
-#endif
+}
+
+/*
+ * Wait for long time (microseconds) - schedule
+ */
+static void tms380tr_wait_long(unsigned long time)
+{
+	msleep(time / 1000);
 }
 
 /*
@@ -1352,9 +1352,9 @@ static int tms380tr_bringup_diags(struct net_device *dev)
 	int loop_cnt, retry_cnt;
 	unsigned short Status;
 
-	tms380tr_wait(HALF_SECOND);
+	tms380tr_wait_long(HALF_SECOND);
 	tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET);
-	tms380tr_wait(HALF_SECOND);
+	tms380tr_wait_long(HALF_SECOND);
 
 	retry_cnt = BUD_MAX_RETRIES;	/* maximal number of retrys */
 
@@ -1365,7 +1365,7 @@ static int tms380tr_bringup_diags(struct net_device *dev)
 		loop_cnt = BUD_MAX_LOOPCNT;	/* maximum: three seconds*/
 		do {			/* Inspect BUD results */
 			loop_cnt--;
-			tms380tr_wait(HALF_SECOND);
+			tms380tr_wait_long(HALF_SECOND);
 			Status = SIFREADW(SIFSTS);
 			Status &= STS_MASK;
 
@@ -1384,7 +1384,7 @@ static int tms380tr_bringup_diags(struct net_device *dev)
 			printk(KERN_INFO "%s: Adapter Software Reset.\n", 
 				dev->name);
 			tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET);
-			tms380tr_wait(HALF_SECOND);
+			tms380tr_wait_long(HALF_SECOND);
 		}
 	} while(retry_cnt > 0);
 
@@ -1457,7 +1457,7 @@ static int tms380tr_init_adapter(struct net_device *dev)
 		do {
 			Status = 0;
 			loop_cnt--;
-			tms380tr_wait(HALF_SECOND);
+			tms380tr_wait_long(HALF_SECOND);
 
 			/* Mask interesting status bits */
 			Status = SIFREADW(SIFSTS);
@@ -1506,7 +1506,7 @@ static int tms380tr_init_adapter(struct net_device *dev)
 				{
 					/* Reset adapter and try init again */
 					tms380tr_exec_sifcmd(dev, EXEC_SOFT_RESET);
-					tms380tr_wait(HALF_SECOND);
+					tms380tr_wait_long(HALF_SECOND);
 				}
 			}
 		}
Signature · 5 lines
1.7.1


-- 
Meelis Roos ([email protected])
maintainer
#1 lore raw

From: Meelis Roos <[email protected]>
Date: Sun, 3 Oct 2010 22:34:30 +0300 (EEST)

Quoted 7 lines

tms380tr driver tries to use udelay (meaning busy loop) for several half second delays during hardware initialization. Crazy overly long busy wait delays mean no delay at all so driver initialization fails without waiting. Fix it by using msleep() for long delays and leave it to udelay() for short delays.

You can't use msleep() here because this code can be invoked from interrupts and thus cannot sleep.

#2 lore raw
Quoted 10 lines
Quoted 7 lines

tms380tr driver tries to use udelay (meaning busy loop) for several half second delays during hardware initialization. Crazy overly long busy wait delays mean no delay at all so driver initialization fails without waiting. Fix it by using msleep() for long delays and leave it to udelay() for short delays.

You can't use msleep() here because this code can be invoked from interrupts and thus cannot sleep.

I checked these two functions that contain long delays that I changed - tms380tr_bringup_diags() and tms380tr_init_adapter() - to be called only from tms380tr_chipset_init() that is only called from tms380tr_open() so no call paths from interrupts AFAICS. Short delyas from interrupt context are not changed in any way, they still use udelay().

Signature · 1 line
Meelis Roos ([email protected])
maintainer
#3 lore raw

From: Meelis Roos <[email protected]>
Date: Mon, 4 Oct 2010 11:39:02 +0300 (EEST)

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

tms380tr driver tries to use udelay (meaning busy loop) for several half second delays during hardware initialization. Crazy overly long busy wait delays mean no delay at all so driver initialization fails without waiting. Fix it by using msleep() for long delays and leave it to udelay() for short delays.

Quoted 8 lines
Quoted 2 lines

You can't use msleep() here because this code can be invoked from interrupts and thus cannot sleep.

I checked these two functions that contain long delays that I changed - tms380tr_bringup_diags() and tms380tr_init_adapter() - to be called only from tms380tr_chipset_init() that is only called from tms380tr_open() so no call paths from interrupts AFAICS. Short delyas from interrupt context are not changed in any way, they still use udelay().

tms380tr_init_adapter() gets called from tms380tr_chk_irq() which is invoked from the interrupt handler.

#4 lore raw
Quoted 2 lines

tms380tr_init_adapter() gets called from tms380tr_chk_irq() which is invoked from the interrupt handler.

Oops, yes, sorry for repeatedly not noticing it even when I was explicitly searching for it :(

What is the general course from here? Defer the long reset to a work queue, or some other kind of background task?

Signature · 1 line
Meelis Roos ([email protected])
maintainer
#5 lore raw

From: Meelis Roos <[email protected]>
Date: Tue, 5 Oct 2010 00:15:17 +0300 (EEST)

Quoted 8 lines
Quoted 2 lines

tms380tr_init_adapter() gets called from tms380tr_chk_irq() which is invoked from the interrupt handler.

Oops, yes, sorry for repeatedly not noticing it even when I was explicitly searching for it :(

What is the general course from here? Defer the long reset to a work queue, or some other kind of background task?

Yes, very likely a workqueue is the best course of action.