[PATCH] usb/dwc3: replace mdelay with udelay in the busy loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There are two spots where we wait until the HW finishes processing a
certain command. Initially we had a few problems and we used 500ms as a
limit to be on a the safe side. Now Paul thinks that this is little too
much. After looking here I don't hardly pass 20us and didn't pass 30usec
so far. So using mdelay() seems way overloaded.
Giving the current numbers I observe I think that 500usec as the upper
limit is enough. Should it ever timeout then something is probably
wrong.
Whilete here I also replace the type with u32 since long does not really
fits here.

Cc: Paul Zimmerman <paul.zimmerman@xxxxxxxxxxxx>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
---
Felipe can you please re-test on your side? I see here
|dwc3_send_gadget_ep_cmd() 490
|dwc3_send_gadget_ep_cmd() 494
|dwc3_send_gadget_ep_cmd() 492
|dwc3_send_gadget_ep_cmd() 481
|dwc3_send_gadget_ep_cmd() 492
|dwc3_send_gadget_ep_cmd() 474
|dwc3_send_gadget_ep_cmd() 494
|dwc3_send_gadget_ep_cmd() 497
|dwc3_send_gadget_ep_cmd() 485
|dwc3_send_gadget_ep_cmd() 497
|dwc3_send_gadget_ep_cmd() 476
|dwc3_send_gadget_ep_cmd() 485
|dwc3_send_gadget_ep_cmd() 494
|dwc3_send_gadget_ep_cmd() 492
|dwc3_send_gadget_ep_cmd() 490
|dwc3_send_gadget_ep_cmd() 494
|dwc3_send_gadget_ep_cmd() 497
|dwc3_send_gadget_ep_cmd() 481

 drivers/usb/dwc3/gadget.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 6e0db63..60463d9 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -152,7 +152,7 @@ int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
 		unsigned cmd, struct dwc3_gadget_ep_cmd_params *params)
 {
 	struct dwc3_ep		*dep = dwc->eps[ep];
-	unsigned long		timeout = 500;
+	u32			timeout = 500;
 	u32			reg;
 
 	dev_vdbg(dwc->dev, "%s: cmd '%s' params %08x %08x %08x\n",
@@ -174,7 +174,6 @@ int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
 		}
 
 		/*
-		 * XXX Figure out a sane timeout here. 500ms is way too much.
 		 * We can't sleep here, because it is also called from
 		 * interrupt context.
 		 */
@@ -182,7 +181,7 @@ int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
 		if (!timeout)
 			return -ETIMEDOUT;
 
-		mdelay(1);
+		udelay(1);
 	} while (1);
 }
 
@@ -1066,7 +1065,7 @@ static int dwc3_gadget_set_selfpowered(struct usb_gadget *g,
 static void dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
 {
 	u32			reg;
-	unsigned long		timeout = 500;
+	u32			timeout = 500;
 
 	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
 	if (is_on)
@@ -1085,13 +1084,10 @@ static void dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
 			if (reg & DWC3_DSTS_DEVCTRLHLT)
 				break;
 		}
-		/*
-		 * XXX reduce the 500ms delay
-		 */
 		timeout--;
 		if (!timeout)
 			break;
-		mdelay(1);
+		udelay(1);
 	} while (1);
 
 	dev_vdbg(dwc->dev, "gadget %s data soft-%s\n",
-- 
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux