mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 4/7] AT91 UDC, fix recursive poll()
@ 2013-03-12 16:03 Renaud C.
  2013-03-13 10:31 ` Cerrato Renaud
  0 siblings, 1 reply; 2+ messages in thread
From: Renaud C. @ 2013-03-12 16:03 UTC (permalink / raw)
  To: barebox


[-- Attachment #1.1: Type: text/plain, Size: 395 bytes --]

I noticed some weird behavior using DFU gadget on AT91SAM9260 which worked
1 of 10 times. The bug was due to the usb_gadget_poll() being called while
the previous call was still in progress : some USB calls may takes a lot of
time (ex : DFU erase-then-write), resulting in the poller to be triggered
again while still in the poll() function.

This patch adds a poll lock to the AT91 UDC driver.

[-- Attachment #1.2: Type: text/html, Size: 445 bytes --]

[-- Attachment #2: at91udc-added-missing-lock-for-poll.patch --]
[-- Type: application/octet-stream, Size: 1535 bytes --]

From c9e73cbb704f8e4e3c13a712587f0b4fbbdfcac7 Mon Sep 17 00:00:00 2001
From: Cerrato Renaud <r.cerrato@til-technologies.fr>
Date: Mon, 11 Mar 2013 11:06:06 +0100
Subject: [PATCH] added missing lock for poll

---
 drivers/usb/gadget/at91_udc.c |   14 ++++++++------
 drivers/usb/gadget/at91_udc.h |    1 +
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 0654038..8ae9119 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1340,22 +1340,24 @@ int usb_gadget_poll(void)
 	struct at91_udc	*udc = &controller;
 	u32 value;
 
-	if (!udc->udp_baseaddr)
+	if (!udc->udp_baseaddr || udc->poll_lock)
 		return 0;
 
+	udc->poll_lock = 1;
+
 	value = gpio_get_value(udc->board.vbus_pin);
 	value ^= udc->board.vbus_active_low;
-
-	if (!value) {
-		at91_update_vbus(udc, value);
-		return 0;
-	}
 	at91_update_vbus(udc, value);
 
+	if (!value)
+		goto exit;
+
 	value = at91_udp_read(udc, AT91_UDP_ISR) & (~(AT91_UDP_SOFINT));
 	if (value)
 		at91_udc_irq(udc);
 
+exit:
+	udc->poll_lock = 0;
 	return value;
 }
 
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h
index e592cc5..51145a9 100644
--- a/drivers/usb/gadget/at91_udc.h
+++ b/drivers/usb/gadget/at91_udc.h
@@ -127,6 +127,7 @@ struct at91_udc {
 	unsigned			wait_for_config_ack:1;
 	unsigned			selfpowered:1;
 	unsigned			active_suspend:1;
+	unsigned			poll_lock:1;
 	u8				addr;
 	u32				gpio_vbus_val;
 	struct at91_udc_data		board;
-- 
1.7.2.5


[-- Attachment #3: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 4/7] AT91 UDC, fix recursive poll()
  2013-03-12 16:03 [PATCH 4/7] AT91 UDC, fix recursive poll() Renaud C.
@ 2013-03-13 10:31 ` Cerrato Renaud
  0 siblings, 0 replies; 2+ messages in thread
From: Cerrato Renaud @ 2013-03-13 10:31 UTC (permalink / raw)
  To: barebox

Inlined patch below.

Signed-off-by: Cerrato Renaud <r.cerrato@til-technologies.fr>
---
 drivers/usb/gadget/at91_udc.c |   14 ++++++++------
 drivers/usb/gadget/at91_udc.h |    1 +
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 0654038..8ae9119 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1340,22 +1340,24 @@ int usb_gadget_poll(void)
     struct at91_udc    *udc = &controller;
     u32 value;
 
-    if (!udc->udp_baseaddr)
+    if (!udc->udp_baseaddr || udc->poll_lock)
         return 0;
 
+    udc->poll_lock = 1;
+
     value = gpio_get_value(udc->board.vbus_pin);
     value ^= udc->board.vbus_active_low;
-
-    if (!value) {
-        at91_update_vbus(udc, value);
-        return 0;
-    }
     at91_update_vbus(udc, value);
 
+    if (!value)
+        goto exit;
+
     value = at91_udp_read(udc, AT91_UDP_ISR) & (~(AT91_UDP_SOFINT));
     if (value)
         at91_udc_irq(udc);
 
+exit:
+    udc->poll_lock = 0;
     return value;
 }
 
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h
index e592cc5..51145a9 100644
--- a/drivers/usb/gadget/at91_udc.h
+++ b/drivers/usb/gadget/at91_udc.h
@@ -127,6 +127,7 @@ struct at91_udc {
     unsigned            wait_for_config_ack:1;
     unsigned            selfpowered:1;
     unsigned            active_suspend:1;
+    unsigned            poll_lock:1;
     u8                addr;
     u32                gpio_vbus_val;
     struct at91_udc_data        board;
-- 
1.7.2.5


On 12/03/2013 17:03, Renaud C. wrote:
> I noticed some weird behavior using DFU gadget on AT91SAM9260 which worked 1 of 10 times. The bug was due to the usb_gadget_poll() being called while the previous call was still in progress : some USB calls may takes a lot of time (ex : DFU erase-then-write), resulting in the poller to be triggered again while still in the poll() function.
>
> This patch adds a poll lock to the AT91 UDC driver.
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox



_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2013-03-13 10:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-12 16:03 [PATCH 4/7] AT91 UDC, fix recursive poll() Renaud C.
2013-03-13 10:31 ` Cerrato Renaud

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox