LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2] usb: chipidea: local_irq_save/restore added for hw_ep_prime
@ 2021-08-17  9:53 Jeaho Hwang
  2021-08-18 16:17 ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 9+ messages in thread
From: Jeaho Hwang @ 2021-08-17  9:53 UTC (permalink / raw)
  To: Peter Chen, Greg Kroah-Hartman, linux-usb, linux-kernel
  Cc: tglx, linux-rt-users, team-linux, mkbyeon, khchoib

hw_ep_prime sometimes fails if irq occurs while it rus on RT kernel.
local_irq_save/restore is added inside the function to gurantee atomicity.
only effective for preempt_rt since hw_ep_prime is called inside top half
or spin_lock_irqsave. No effect is expected for standard linux.

Signed-off-by: Jeaho Hwang <jhhwang@rtst.co.kr>

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 8834ca613721..a624eddb3e22 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -191,22 +191,31 @@ static int hw_ep_get_halt(struct ci_hdrc *ci, int num, int dir)
 static int hw_ep_prime(struct ci_hdrc *ci, int num, int dir, int is_ctrl)
 {
 	int n = hw_ep_bit(num, dir);
+	unsigned long flags;
+	int ret = 0;
 
 	/* Synchronize before ep prime */
 	wmb();
 
-	if (is_ctrl && dir == RX && hw_read(ci, OP_ENDPTSETUPSTAT, BIT(num)))
+	/* irq affects this routine so irq should be disabled on RT.
+	 * on standard kernel, irq is already disabled by callers.
+	 */
+	local_irq_save(flags);
+	if (is_ctrl && dir == RX && hw_read(ci, OP_ENDPTSETUPSTAT, BIT(num))) {
+		local_irq_restore(flags);
 		return -EAGAIN;
+	}
 
 	hw_write(ci, OP_ENDPTPRIME, ~0, BIT(n));
 
 	while (hw_read(ci, OP_ENDPTPRIME, BIT(n)))
 		cpu_relax();
 	if (is_ctrl && dir == RX && hw_read(ci, OP_ENDPTSETUPSTAT, BIT(num)))
-		return -EAGAIN;
+		ret = -EAGAIN;
 
+	local_irq_restore(flags);
 	/* status shoult be tested according with manual but it doesn't work */
-	return 0;
+	return ret;
 }
 
 /**
-- 
2.25.1


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

end of thread, other threads:[~2021-08-23 16:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-17  9:53 [PATCH v2] usb: chipidea: local_irq_save/restore added for hw_ep_prime Jeaho Hwang
2021-08-18 16:17 ` Sebastian Andrzej Siewior
2021-08-18 23:50   ` Jeaho Hwang
2021-08-19  8:47     ` Sebastian Andrzej Siewior
2021-08-20  5:15       ` Jeaho Hwang
2021-08-21  5:05         ` Peter Chen
2021-08-21  7:04           ` Jeaho Hwang
2021-08-23 16:14             ` Sebastian Andrzej Siewior
2021-08-23 16:51         ` Sebastian Andrzej Siewior

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).