Skip to content

Commit 4e8ef34

Browse files
Linyu Yuangregkh
authored andcommitted
usb: dwc3: fix gadget mode suspend interrupt handler issue
When work in gadget mode, currently driver doesn't update software level link_state correctly as link state change event is not enabled for most devices, in function dwc3_gadget_suspend_interrupt(), it will only pass suspend event to UDC core when software level link state changes, so when interrupt generated in sequences of suspend -> reset -> conndone -> suspend, link state is not updated during reset and conndone, so second suspend interrupt event will not pass to UDC core. Remove link_state compare in dwc3_gadget_suspend_interrupt() and add a suspended flag to replace the compare function. Fixes: 799e9dc ("usb: dwc3: gadget: conditionally disable Link State change events") Cc: stable <[email protected]> Acked-by: Thinh Nguyen <[email protected]> Signed-off-by: Linyu Yuan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c854087 commit 4e8ef34

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

drivers/usb/dwc3/core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,7 @@ struct dwc3_scratchpad_array {
11161116
* @dis_metastability_quirk: set to disable metastability quirk.
11171117
* @dis_split_quirk: set to disable split boundary.
11181118
* @wakeup_configured: set if the device is configured for remote wakeup.
1119+
* @suspended: set to track suspend event due to U3/L2.
11191120
* @imod_interval: set the interrupt moderation interval in 250ns
11201121
* increments or 0 to disable.
11211122
* @max_cfg_eps: current max number of IN eps used across all USB configs.
@@ -1332,6 +1333,7 @@ struct dwc3 {
13321333
unsigned dis_split_quirk:1;
13331334
unsigned async_callbacks:1;
13341335
unsigned wakeup_configured:1;
1336+
unsigned suspended:1;
13351337

13361338
u16 imod_interval;
13371339

drivers/usb/dwc3/gadget.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2440,6 +2440,7 @@ static int dwc3_gadget_func_wakeup(struct usb_gadget *g, int intf_id)
24402440
return -EINVAL;
24412441
}
24422442
dwc3_resume_gadget(dwc);
2443+
dwc->suspended = false;
24432444
dwc->link_state = DWC3_LINK_STATE_U0;
24442445
}
24452446

@@ -3942,6 +3943,8 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc)
39423943
{
39433944
int reg;
39443945

3946+
dwc->suspended = false;
3947+
39453948
dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RX_DET);
39463949

39473950
reg = dwc3_readl(dwc->regs, DWC3_DCTL);
@@ -3966,6 +3969,8 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
39663969
{
39673970
u32 reg;
39683971

3972+
dwc->suspended = false;
3973+
39693974
/*
39703975
* Ideally, dwc3_reset_gadget() would trigger the function
39713976
* drivers to stop any active transfers through ep disable.
@@ -4184,6 +4189,8 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
41844189

41854190
static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc, unsigned int evtinfo)
41864191
{
4192+
dwc->suspended = false;
4193+
41874194
/*
41884195
* TODO take core out of low power mode when that's
41894196
* implemented.
@@ -4281,6 +4288,7 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc,
42814288
if (dwc->gadget->wakeup_armed) {
42824289
dwc3_gadget_enable_linksts_evts(dwc, false);
42834290
dwc3_resume_gadget(dwc);
4291+
dwc->suspended = false;
42844292
}
42854293
break;
42864294
case DWC3_LINK_STATE_U1:
@@ -4307,8 +4315,10 @@ static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc,
43074315
{
43084316
enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK;
43094317

4310-
if (dwc->link_state != next && next == DWC3_LINK_STATE_U3)
4318+
if (!dwc->suspended && next == DWC3_LINK_STATE_U3) {
4319+
dwc->suspended = true;
43114320
dwc3_suspend_gadget(dwc);
4321+
}
43124322

43134323
dwc->link_state = next;
43144324
}

0 commit comments

Comments
 (0)