Skip to content

Commit 00dcf2f

Browse files
Prashanth Kgregkh
authored andcommitted
usb: dwc3: Avoid waking up gadget during startxfer
When operating in High-Speed, it is observed that DSTS[USBLNKST] doesn't update link state immediately after receiving the wakeup interrupt. Since wakeup event handler calls the resume callbacks, there is a chance that function drivers can perform an ep queue, which in turn tries to perform remote wakeup from send_gadget_ep_cmd(STARTXFER). This happens because DSTS[[21:18] wasn't updated to U0 yet, it's observed that the latency of DSTS can be in order of milli-seconds. Hence avoid calling gadget_wakeup during startxfer to prevent unnecessarily issuing remote wakeup to host. Fixes: c36d8e9 ("usb: dwc3: gadget: put link to U0 before Start Transfer") Cc: [email protected] Suggested-by: Thinh Nguyen <[email protected]> Signed-off-by: Prashanth K <[email protected]> Acked-by: Thinh Nguyen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 431c164 commit 00dcf2f

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

drivers/usb/dwc3/gadget.c

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,23 @@ static int __dwc3_gadget_wakeup(struct dwc3 *dwc, bool async);
287287
*
288288
* Caller should handle locking. This function will issue @cmd with given
289289
* @params to @dep and wait for its completion.
290+
*
291+
* According to the programming guide, if the link state is in L1/L2/U3,
292+
* then sending the Start Transfer command may not complete. The
293+
* programming guide suggested to bring the link state back to ON/U0 by
294+
* performing remote wakeup prior to sending the command. However, don't
295+
* initiate remote wakeup when the user/function does not send wakeup
296+
* request via wakeup ops. Send the command when it's allowed.
297+
*
298+
* Notes:
299+
* For L1 link state, issuing a command requires the clearing of
300+
* GUSB2PHYCFG.SUSPENDUSB2, which turns on the signal required to complete
301+
* the given command (usually within 50us). This should happen within the
302+
* command timeout set by driver. No additional step is needed.
303+
*
304+
* For L2 or U3 link state, the gadget is in USB suspend. Care should be
305+
* taken when sending Start Transfer command to ensure that it's done after
306+
* USB resume.
290307
*/
291308
int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned int cmd,
292309
struct dwc3_gadget_ep_cmd_params *params)
@@ -327,30 +344,6 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned int cmd,
327344
dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
328345
}
329346

330-
if (DWC3_DEPCMD_CMD(cmd) == DWC3_DEPCMD_STARTTRANSFER) {
331-
int link_state;
332-
333-
/*
334-
* Initiate remote wakeup if the link state is in U3 when
335-
* operating in SS/SSP or L1/L2 when operating in HS/FS. If the
336-
* link state is in U1/U2, no remote wakeup is needed. The Start
337-
* Transfer command will initiate the link recovery.
338-
*/
339-
link_state = dwc3_gadget_get_link_state(dwc);
340-
switch (link_state) {
341-
case DWC3_LINK_STATE_U2:
342-
if (dwc->gadget->speed >= USB_SPEED_SUPER)
343-
break;
344-
345-
fallthrough;
346-
case DWC3_LINK_STATE_U3:
347-
ret = __dwc3_gadget_wakeup(dwc, false);
348-
dev_WARN_ONCE(dwc->dev, ret, "wakeup failed --> %d\n",
349-
ret);
350-
break;
351-
}
352-
}
353-
354347
/*
355348
* For some commands such as Update Transfer command, DEPCMDPARn
356349
* registers are reserved. Since the driver often sends Update Transfer

0 commit comments

Comments
 (0)