Skip to contentSkip to conversation

gianfar: Wait for both RX and TX to stop

PATCH In review Andy Fleming 4 participants 14 messages Apr 18, 2010 – Apr 21, 2010

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

PATCH 1/1 gianfar: Wait for both RX and TX to stop

When gracefully stopping the controller, the driver was continuing if *either* RX or TX had stopped. We need to wait for both, or the controller could get into an invalid state.

---
 drivers/net/gianfar.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/gianfar.c +3 -2
index 032073d..6038397 100644
@@ -1571,8 +1571,9 @@ static void gfar_halt_nodisable(struct net_device *dev)
 		tempval |= (DMACTRL_GRS | DMACTRL_GTS);
 		gfar_write(&regs->dmactrl, tempval);
 
-		while (!(gfar_read(&regs->ievent) &
-			 (IEVENT_GRSC | IEVENT_GTSC)))
+		while ((gfar_read(&regs->ievent) &
+			 (IEVENT_GRSC | IEVENT_GTSC)) !=
+			 (IEVENT_GRSC | IEVENT_GTSC))
 			cpu_relax();
 	}
 }
Signature · 1 line
1.6.5.2.g6ff9a
#1 lore raw
Quoted 6 lines · Andy Fleming

-               while (!(gfar_read(&regs->ievent) &
-                        (IEVENT_GRSC | IEVENT_GTSC)))
+               while ((gfar_read(&regs->ievent) &
+                        (IEVENT_GRSC | IEVENT_GTSC)) !=
+                        (IEVENT_GRSC | IEVENT_GTSC)) cpu_relax();

How about using spin_event_timeout()? It streamlines this process and includes a timeout.

The U-Boot version of this code doesn't have a timeout either, but spin_event_timeout() is not available in U-Boot.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#2 lore raw
Quoted 9 lines · Timur Tabi

drivers/net/gianfar.c static void gfar_halt_nodisable(struct net_device *dev) · line 1577

Quoted 6 lines · Andy Fleming
drivers/net/gianfar.c +3 -2
-               while (!(gfar_read(&regs->ievent) &
-                        (IEVENT_GRSC | IEVENT_GTSC)))
+               while ((gfar_read(&regs->ievent) &
+                        (IEVENT_GRSC | IEVENT_GTSC)) !=
+                        (IEVENT_GRSC | IEVENT_GTSC))
                       cpu_relax();
Quoted 5 lines

How about using spin_event_timeout()? It streamlines this process and includes a timeout.

The U-Boot version of this code doesn't have a timeout either, but spin_event_timeout() is not available in U-Boot.

spin_event_timeout doesn't make sense for this. The patch is fine.

- k

#3 lore raw
Quoted 1 line · Kumar Gala

spin_event_timeout doesn't make sense for this.  The patch is fine.

Can you please elaborate on that? I don't understand why you think that. spin_event_timeout() takes an expression and a timeout, and loops over the expression calling cpu_relax(), just like this loop does.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#4 lore raw
Quoted 8 lines · Timur Tabi
Quoted 1 line · Kumar Gala

spin_event_timeout doesn't make sense for this.  The patch is fine.

Can you please elaborate on that?  I don't understand why you think that.  spin_event_timeout() takes an expression and a timeout, and loops over the expression calling cpu_relax(), just like this loop does.

I haven't tested it, but I think this should work:

	spin_event_timeout((gfar_read(&regs->ievent) &
		(IEVENT_GRSC | IEVENT_GTSC)) ==
		(IEVENT_GRSC | IEVENT_GTSC), -1, 0);

Ideally, Andy should use a timeout value other than -1, and then test the result like this:

	u32 ret;

	ret = spin_event_timeout((gfar_read(&regs->ievent) &
		(IEVENT_GRSC | IEVENT_GTSC)) ==
		(IEVENT_GRSC | IEVENT_GTSC), 1000, 0);

	if (!ret)
		/* timeout has occurred */
Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
maintainer
#5 lore raw
In reply to Timur Tabi

From: Timur Tabi <[email protected]>
Date: Tue, 20 Apr 2010 10:01:48 -0500

Quoted 8 lines · Kumar Gala
Quoted 2 lines

spin_event_timeout doesn't make sense for this.  The patch is fine.

Can you please elaborate on that? I don't understand why you think that. spin_event_timeout() takes an expression and a timeout, and loops over the expression calling cpu_relax(), just like this loop does.

Indeed it does, Kumar this request seems reasonable.

#6 lore raw
Quoted 5 lines · David Miller

From: Timur Tabi <[email protected]>
Date: Tue, 20 Apr 2010 10:01:48 -0500

Quoted 2 lines · Kumar Gala
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

spin_event_timeout doesn't make sense for this. The patch is fine.

Can you please elaborate on that? I don't understand why you think that. spin_event_timeout() takes an expression and a timeout, and loops over the expression calling cpu_relax(), just like this loop does.

Indeed it does, Kumar this request seems reasonable.

Are we saying that cpu_relax() is useless and should be removed if we are spinning on a HW register?

Its fatally buggy HW if the bits never clear or get set in the few conditions that cpu_relax() are being used.

- k

maintainer
#7 lore raw

From: Kumar Gala <[email protected]>
Date: Tue, 20 Apr 2010 23:22:19 -0500

Quoted 10 lines · David Miller
Quoted 8 lines

From: Timur Tabi <[email protected]>
Date: Tue, 20 Apr 2010 10:01:48 -0500

Quoted 4 lines · Kumar Gala
Quoted 2 lines

spin_event_timeout doesn't make sense for this. The patch is fine.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Can you please elaborate on that? I don't understand why you think that. spin_event_timeout() takes an expression and a timeout, and loops over the expression calling cpu_relax(), just like this loop does.

Indeed it does, Kumar this request seems reasonable.

Are we saying that cpu_relax() is useless and should be removed if we are spinning on a HW register?

Kumar, take a deep breath and a step back.

spin_event_timeout() does the cpu_relax() too, that's what Timur is trying to tell you.

The code will be basically identical as far as I can tell.

#8 lore raw
Quoted 20 lines · David Miller

From: Kumar Gala <[email protected]>
Date: Tue, 20 Apr 2010 23:22:19 -0500

Quoted 17 lines · David Miller
Quoted 14 lines

From: Timur Tabi <[email protected]>
Date: Tue, 20 Apr 2010 10:01:48 -0500

Quoted 8 lines · Kumar Gala
Quoted 2 lines

spin_event_timeout doesn't make sense for this. The patch is fine.

Can you please elaborate on that? I don't understand why you think that. spin_event_timeout() takes an expression and a timeout, and loops over the expression calling cpu_relax(), just like this loop does.

Indeed it does, Kumar this request seems reasonable.

Quoted 8 lines
Quoted 1 line

Are we saying that cpu_relax() is useless and should be removed if we are spinning on a HW register?

Kumar, take a deep breath and a step back.

spin_event_timeout() does the cpu_relax() too, that's what Timur is trying to tell you.

The code will be basically identical as far as I can tell.

I understand, its more a sense that we are saying we want to time out for what I consider a catastrophic HW failure.

- k

#9 lore raw
Quoted 1 line · Kumar Gala

I understand, its more a sense that we are saying we want to time out for what I consider a catastrophic HW failure.

And how else will you detect and recover from such a failure without a timeout? And are you absolutely certain that there will never be a programming failure that will cause this loop to spin forever?

If you're really opposed to a timeout, you can still use spin_event_timeout() by just setting the timeout to -1 and adding a comment explaining why.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#10 lore raw
Quoted 11 lines · Timur Tabi
Quoted 1 line · Kumar Gala

I understand, its more a sense that we are saying we want to time out for what I consider a catastrophic HW failure.

And how else will you detect and recover from such a failure without a timeout? And are you absolutely certain that there will never be a programming failure that will cause this loop to spin forever?

If you're really opposed to a timeout, you can still use spin_event_timeout() by just setting the timeout to -1 and adding a comment explaining why.

I'm not opposed, I'm just asking if we are saying we shouldn't be using cpu_relax() for spinning on HW status registers ever.

If we are suggesting that cpu_relax() shouldn't be used in these scenarios going forward I'm ok w/the change you suggest and starting to convert other cpu_relax() calls to use spin_event_timeout()

- k

maintainer
#11 lore raw

From: Kumar Gala <[email protected]>
Date: Wed, 21 Apr 2010 14:13:00 -0500

Quoted 3 lines

I'm not opposed, I'm just asking if we are saying we shouldn't be using cpu_relax() for spinning on HW status registers ever.

If we are suggesting that cpu_relax() shouldn't be used in these scenarios going forward I'm ok w/the change you suggest and starting to convert other cpu_relax() calls to use spin_event_timeout()

Kumar this isn't an either-or thing.

In both cases we're using cpu_relax().

But by using spin_event_timeout() you're getting both the cpu_relax() and a break-out in case the hardware gets wedged for some reason.

Acked-by on v1 1/1
#12 lore raw
In reply to Andy Fleming
Quoted 8 lines · Andy Fleming

When gracefully stopping the controller, the driver was continuing if *either* RX or TX had stopped. We need to wait for both, or the controller could get into an invalid state.

---
drivers/net/gianfar.c | 5 +++--

1 files changed, 3 insertions(+), 2 deletions(-)

(please pick this up for 2.6.34, fixes an annoying bug).

- k

Quoted 24 lines
drivers/net/gianfar.c +3 -2
index 032073d..6038397 100644
@@ -1571,8 +1571,9 @@ static void gfar_halt_nodisable(struct net_device *dev)
 		tempval |= (DMACTRL_GRS | DMACTRL_GTS);
 		gfar_write(&regs->dmactrl, tempval);
 
-		while (!(gfar_read(&regs->ievent) &
-			 (IEVENT_GRSC | IEVENT_GTSC)))
+		while ((gfar_read(&regs->ievent) &
+			 (IEVENT_GRSC | IEVENT_GTSC)) !=
+			 (IEVENT_GRSC | IEVENT_GTSC))
 			cpu_relax();
 	}
 }
Signature · 6 lines
1.6.5.2.g6ff9a

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#13 lore raw

From: Kumar Gala <[email protected]>
Date: Mon, 19 Apr 2010 23:44:49 -0500

Quoted 7 lines · Andy Fleming
Quoted 5 lines

When gracefully stopping the controller, the driver was continuing if *either* RX or TX had stopped. We need to wait for both, or the controller could get into an invalid state.

Quoted 8 lines
Quoted 4 lines

---
drivers/net/gianfar.c | 5 +++--

1 files changed, 3 insertions(+), 2 deletions(-)

(please pick this up for 2.6.34, fixes an annoying bug).

I will do this tomorrow, thanks!