UPSTREAM: 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: 799e9dc829 ("usb: dwc3: gadget: conditionally disable Link State change events")
Cc: stable <stable@kernel.org>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
Link: https://lore.kernel.org/r/20230512004524.31950-1-quic_linyyuan@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Bug: 283221152
(cherry picked from commit 4e8ef34e36f2839ef8c8da521ab7035956436818
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git/ usb-linus)

Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
Change-Id: Iaaf34456136e873f1ce5a8fa573f40e22873f2c4
This commit is contained in:
Prashanth K
2023-05-18 23:57:48 +05:30
committed by Todd Kjos
parent 8faa860f55
commit 0461430273
3 changed files with 28 additions and 3 deletions

View File

@@ -1582,15 +1582,17 @@ static int dwc3_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct resource *res, dwc_res;
struct dwc3 *dwc;
struct dwc3_vendor *vdwc;
int ret;
void __iomem *regs;
dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
if (!dwc)
vdwc = devm_kzalloc(dev, sizeof(*vdwc), GFP_KERNEL);
if (!vdwc)
return -ENOMEM;
dwc = &vdwc->dwc;
dwc->dev = dev;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

View File

@@ -1323,6 +1323,16 @@ struct dwc3 {
ANDROID_KABI_RESERVE(4);
};
/**
* struct dwc3_vendor - contains parameters without modifying the format of DWC3 core
* @dwc: contains dwc3 core reference
* @suspended: set to track suspend event due to U3/L2.
*/
struct dwc3_vendor {
struct dwc3 dwc;
unsigned suspended:1;
};
#define INCRX_BURST_MODE 0
#define INCRX_UNDEF_LENGTH_BURST_MODE 1

View File

@@ -3822,8 +3822,11 @@ static void dwc3_clear_stall_all_ep(struct dwc3 *dwc)
static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc)
{
struct dwc3_vendor *vdwc = container_of(dwc, struct dwc3_vendor, dwc);
int reg;
vdwc->suspended = false;
dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RX_DET);
reg = dwc3_readl(dwc->regs, DWC3_DCTL);
@@ -3844,8 +3847,11 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc)
static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
{
struct dwc3_vendor *vdwc = container_of(dwc, struct dwc3_vendor, dwc);
u32 reg;
vdwc->suspended = false;
/*
* Ideally, dwc3_reset_gadget() would trigger the function
* drivers to stop any active transfers through ep disable.
@@ -4062,6 +4068,10 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc)
{
struct dwc3_vendor *vdwc = container_of(dwc, struct dwc3_vendor, dwc);
vdwc->suspended = false;
/*
* TODO take core out of low power mode when that's
* implemented.
@@ -4175,10 +4185,13 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc,
static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc,
unsigned int evtinfo)
{
struct dwc3_vendor *vdwc = container_of(dwc, struct dwc3_vendor, dwc);
enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK;
if (dwc->link_state != next && next == DWC3_LINK_STATE_U3)
if (!vdwc->suspended && next == DWC3_LINK_STATE_U3) {
vdwc->suspended = true;
dwc3_suspend_gadget(dwc);
}
dwc->link_state = next;
}