2024-06-03 13:34:40

by Mike Looijmans

[permalink] [raw]
Subject: [PATCH] usb: dwc3: gadget: Inform system of suspended state

When disconnecting the USB cable on an LS1028 device, nothing happens
in userspace, which keeps thinking everything is still up and running.
Turns out that the DWC3 controller only sends DWC3_DEVICE_EVENT_SUSPEND
in that case, and not a DWC3_DEVICE_EVENT_DISCONNECT as one would
expect. As a result, sysfs attribute "state" remains "configured"
until something resets it.

Forward the "suspended" state to sysfs, so that the "state" at least
changes into "suspended" when one removes the cable, and hence also
matches the gadget's state when really suspended.

Signed-off-by: Mike Looijmans <[email protected]>
---

drivers/usb/dwc3/gadget.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 4df2661f6675..99e8ea9db600 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -4343,6 +4343,7 @@ static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc,
if (!dwc->suspended && next == DWC3_LINK_STATE_U3) {
dwc->suspended = true;
dwc3_suspend_gadget(dwc);
+ usb_gadget_set_state(dwc->gadget, USB_STATE_SUSPENDED);
}

dwc->link_state = next;
--
2.34.1


Met vriendelijke groet / kind regards,

Mike Looijmans
System Expert


TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W: http://www.topic.nl

Please consider the environment before printing this e-mail


2024-06-04 01:03:37

by Thinh Nguyen

[permalink] [raw]
Subject: Re: [PATCH] usb: dwc3: gadget: Inform system of suspended state

Hi,

On Mon, Jun 03, 2024, Mike Looijmans wrote:
> When disconnecting the USB cable on an LS1028 device, nothing happens
> in userspace, which keeps thinking everything is still up and running.
> Turns out that the DWC3 controller only sends DWC3_DEVICE_EVENT_SUSPEND
> in that case, and not a DWC3_DEVICE_EVENT_DISCONNECT as one would
> expect. As a result, sysfs attribute "state" remains "configured"
> until something resets it.
>
> Forward the "suspended" state to sysfs, so that the "state" at least
> changes into "suspended" when one removes the cable, and hence also
> matches the gadget's state when really suspended.

On disconnection, did you see disconnect interrupt? If so, it should
transition to USB_STATE_NOATTACHED. This change doesn't seem to directly
address your issue. Can you provide the driver tracepoints?

Thanks,
Thinh

>
> Signed-off-by: Mike Looijmans <[email protected]>
> ---
>
> drivers/usb/dwc3/gadget.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 4df2661f6675..99e8ea9db600 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -4343,6 +4343,7 @@ static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc,
> if (!dwc->suspended && next == DWC3_LINK_STATE_U3) {
> dwc->suspended = true;
> dwc3_suspend_gadget(dwc);
> + usb_gadget_set_state(dwc->gadget, USB_STATE_SUSPENDED);
> }
>
> dwc->link_state = next;
> --
> 2.34.1
>
>
> Met vriendelijke groet / kind regards,
>
> Mike Looijmans
> System Expert
>
>
> TOPIC Embedded Products B.V.
> Materiaalweg 4, 5681 RJ Best
> The Netherlands
>
> T: +31 (0) 499 33 69 69
> E: [email protected]
> W: https://urldefense.com/v3/__http://www.topic.nl__;!!A4F2R9G_pg!dXv5bN6_FJRVB7pQogk6ZxPOb97r2m4CJ9R2rvxelfjbfNhJjQ9ilRpqRBgO983Jxof9Hs8f8rY6nX1hyIvD6ZNIwnKmb9c$
>
> Please consider the environment before printing this e-mail

2024-06-04 05:31:02

by Mike Looijmans

[permalink] [raw]
Subject: Re: [PATCH] usb: dwc3: gadget: Inform system of suspended state

On 04-06-2024 03:03, Thinh Nguyen wrote:
> Hi,
>
> On Mon, Jun 03, 2024, Mike Looijmans wrote:
>> When disconnecting the USB cable on an LS1028 device, nothing happens
>> in userspace, which keeps thinking everything is still up and running.
>> Turns out that the DWC3 controller only sends DWC3_DEVICE_EVENT_SUSPEND
>> in that case, and not a DWC3_DEVICE_EVENT_DISCONNECT as one would
>> expect. As a result, sysfs attribute "state" remains "configured"
>> until something resets it.
>>
>> Forward the "suspended" state to sysfs, so that the "state" at least
>> changes into "suspended" when one removes the cable, and hence also
>> matches the gadget's state when really suspended.
> On disconnection, did you see disconnect interrupt? If so, it should
> transition to USB_STATE_NOATTACHED. This change doesn't seem to directly
> address your issue. Can you provide the driver tracepoints?

The device doesn't issue a disconnect event, I didn't have tracing
enabled in the kernel but added some dev_info() calls to determine what
was going on. Added this to dwc3_process_event_entry():

dev_info(dwc->dev, "event: 0x%x type=0x%x", event->raw, event->type.type);

When disconnecting the cable from the host, I see this:

[   50.841411] dwc3 3110000.usb: event: 0x6084 type=0x42
[   50.841457] dwc3 3110000.usb: event: 0x4086 type=0x43
[   50.841494] dwc3 3110000.usb: event: 0x6084 type=0x42
[   50.841534] dwc3 3110000.usb: event: 0x4086 type=0x43
[   50.841571] dwc3 3110000.usb: event: 0x4086 type=0x43
[   52.650990] dwc3 3110000.usb: event: 0x30601 type=0x0

The "0x4086" and "0x6084" messages are endpoint events that occur all
the time while connected. The last event is the "suspend" one. After
that, total silence.

If you need traces, please point me to a description on how to obtain them.


>
> Thanks,
> Thinh
>
>> Signed-off-by: Mike Looijmans <[email protected]>
>> ---
>>
>> drivers/usb/dwc3/gadget.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
>> index 4df2661f6675..99e8ea9db600 100644
>> --- a/drivers/usb/dwc3/gadget.c
>> +++ b/drivers/usb/dwc3/gadget.c
>> @@ -4343,6 +4343,7 @@ static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc,
>> if (!dwc->suspended && next == DWC3_LINK_STATE_U3) {
>> dwc->suspended = true;
>> dwc3_suspend_gadget(dwc);
>> + usb_gadget_set_state(dwc->gadget, USB_STATE_SUSPENDED);
>> }
>>
>> dwc->link_state = next;
>> --
>> 2.34.1
>>
>>
>> Met vriendelijke groet / kind regards,
>>
>> Mike Looijmans


--
Mike Looijmans
System Expert

TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W: http://www.topic.nl




2024-06-04 06:46:20

by Krishna Kurapati PSSNV

[permalink] [raw]
Subject: Re: [PATCH] usb: dwc3: gadget: Inform system of suspended state



On 6/4/2024 10:56 AM, Mike Looijmans wrote:
> On 04-06-2024 03:03, Thinh Nguyen wrote:
>> Hi,
>>
>> On Mon, Jun 03, 2024, Mike Looijmans wrote:
>>> When disconnecting the USB cable on an LS1028 device, nothing happens
>>> in userspace, which keeps thinking everything is still up and running.
>>> Turns out that the DWC3 controller only sends DWC3_DEVICE_EVENT_SUSPEND
>>> in that case, and not a DWC3_DEVICE_EVENT_DISCONNECT as one would
>>> expect. As a result, sysfs attribute "state" remains "configured"
>>> until something resets it.
>>>
>>> Forward the "suspended" state to sysfs, so that the "state" at least
>>> changes into "suspended" when one removes the cable, and hence also
>>> matches the gadget's state when really suspended.
>> On disconnection, did you see disconnect interrupt? If so, it should
>> transition to USB_STATE_NOATTACHED. This change doesn't seem to directly
>> address your issue. Can you provide the driver tracepoints?
>
> The device doesn't issue a disconnect event, I didn't have tracing
> enabled in the kernel but added some dev_info() calls to determine what
> was going on. Added this to dwc3_process_event_entry():
>
> dev_info(dwc->dev, "event: 0x%x type=0x%x", event->raw, event->type.type);
>
> When disconnecting the cable from the host, I see this:
>
> [   50.841411] dwc3 3110000.usb: event: 0x6084 type=0x42
> [   50.841457] dwc3 3110000.usb: event: 0x4086 type=0x43
> [   50.841494] dwc3 3110000.usb: event: 0x6084 type=0x42
> [   50.841534] dwc3 3110000.usb: event: 0x4086 type=0x43
> [   50.841571] dwc3 3110000.usb: event: 0x4086 type=0x43
> [   52.650990] dwc3 3110000.usb: event: 0x30601 type=0x0
>
> The "0x4086" and "0x6084" messages are endpoint events that occur all
> the time while connected. The last event is the "suspend" one. After
> that, total silence.
>
> If you need traces, please point me to a description on how to obtain them.
>
>

Hi Mike,

I may be wrong, but can you help understand the mechanism as to how
disconnect interrupt is generated in your targets. For example, on QC
SoC's, this happens when HS_PHY_CTRL reg VBUS_VALID bit is cleared and
cable is disconnected. This is because the vbus line is not routed to
controller. But from my calls with Synopsys previously, I remember that
the vbus line is routed to the controller as well for other OEMs. In
your SoC, what is the indication to controller that vbus is absent ?

Also, after this happens, do you see the next plug in working ?

Regards,
Krishna,

2024-06-04 08:26:35

by Mike Looijmans

[permalink] [raw]
Subject: Re: [PATCH] usb: dwc3: gadget: Inform system of suspended state

On 04-06-2024 08:45, Krishna Kurapati PSSNV wrote:
>
>
> On 6/4/2024 10:56 AM, Mike Looijmans wrote:
>> On 04-06-2024 03:03, Thinh Nguyen wrote:
>>> Hi,
>>>
>>> On Mon, Jun 03, 2024, Mike Looijmans wrote:
>>>> When disconnecting the USB cable on an LS1028 device, nothing happens
>>>> in userspace, which keeps thinking everything is still up and running.
>>>> Turns out that the DWC3 controller only sends
>>>> DWC3_DEVICE_EVENT_SUSPEND
>>>> in that case, and not a DWC3_DEVICE_EVENT_DISCONNECT as one would
>>>> expect. As a result, sysfs attribute "state" remains "configured"
>>>> until something resets it.
>>>>
>>>> Forward the "suspended" state to sysfs, so that the "state" at least
>>>> changes into "suspended" when one removes the cable, and hence also
>>>> matches the gadget's state when really suspended.
>>> On disconnection, did you see disconnect interrupt? If so, it should
>>> transition to USB_STATE_NOATTACHED. This change doesn't seem to
>>> directly
>>> address your issue. Can you provide the driver tracepoints?
>>
>> The device doesn't issue a disconnect event, I didn't have tracing
>> enabled in the kernel but added some dev_info() calls to determine
>> what was going on. Added this to dwc3_process_event_entry():
>>
>> dev_info(dwc->dev, "event: 0x%x type=0x%x", event->raw,
>> event->type.type);
>>
>> When disconnecting the cable from the host, I see this:
>>
>> [   50.841411] dwc3 3110000.usb: event: 0x6084 type=0x42
>> [   50.841457] dwc3 3110000.usb: event: 0x4086 type=0x43
>> [   50.841494] dwc3 3110000.usb: event: 0x6084 type=0x42
>> [   50.841534] dwc3 3110000.usb: event: 0x4086 type=0x43
>> [   50.841571] dwc3 3110000.usb: event: 0x4086 type=0x43
>> [   52.650990] dwc3 3110000.usb: event: 0x30601 type=0x0
>>
>> The "0x4086" and "0x6084" messages are endpoint events that occur all
>> the time while connected. The last event is the "suspend" one. After
>> that, total silence.
>>
>> If you need traces, please point me to a description on how to obtain
>> them.
>>
>>
>
> Hi Mike,
>
>  I may be wrong, but can you help understand the mechanism as to how
> disconnect interrupt is generated in your targets. For example, on QC
> SoC's, this happens when HS_PHY_CTRL reg VBUS_VALID bit is cleared and
> cable is disconnected. This is because the vbus line is not routed to
> controller. But from my calls with Synopsys previously, I remember
> that the vbus line is routed to the controller as well for other OEMs.
> In your SoC, what is the indication to controller that vbus is absent ?
>
The board I'm testing this on is an LS1028ARDB. Looking at the
schematic, VBUS is routed to the chip. There's also an LED attached to
it, which turns off when I unplug the cable.

In the devicetree, I can't see any hint of NXP-specific "glue" in the
DWC3 entries, so it uses the controller "as is":

                        compatible = "fsl,ls1028a-dwc3", "snps,dwc3";
                        reg = <0x0 0x3100000 0x0 0x10000>;
                        snps,dis_rxdet_inp3_quirk;
                        snps,quirk-frame-length-adjustment = <0x20>;
                        snps,incr-burst-type-adjustment = <1>, <4>,
<8>, <16>;

The "fsl,ls1028a-dwc3" keyword doesn't actually occur anywhere in the
kernel, so it uses plain "snps,dwc3".


> Also, after this happens, do you see the next plug in working ?

Next plugin works, because of a "reset" event at that point that makes
everything happy again.

The state remains in "configured" while the cable is out. Plugging the
cable back in makes it revert to "default" first, then it goes back into
"configured".

--
Mike Looijmans
System Expert

TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W: http://www.topic.nl




2024-06-04 08:52:50

by Krishna Kurapati PSSNV

[permalink] [raw]
Subject: Re: [PATCH] usb: dwc3: gadget: Inform system of suspended state



On 6/4/2024 1:55 PM, Mike Looijmans wrote:
> On 04-06-2024 08:45, Krishna Kurapati PSSNV wrote:
>>
>>
>> On 6/4/2024 10:56 AM, Mike Looijmans wrote:
>>> On 04-06-2024 03:03, Thinh Nguyen wrote:
>>>> Hi,
>>>>
>>>> On Mon, Jun 03, 2024, Mike Looijmans wrote:
>>>>> When disconnecting the USB cable on an LS1028 device, nothing happens
>>>>> in userspace, which keeps thinking everything is still up and running.
>>>>> Turns out that the DWC3 controller only sends
>>>>> DWC3_DEVICE_EVENT_SUSPEND
>>>>> in that case, and not a DWC3_DEVICE_EVENT_DISCONNECT as one would
>>>>> expect. As a result, sysfs attribute "state" remains "configured"
>>>>> until something resets it.
>>>>>
>>>>> Forward the "suspended" state to sysfs, so that the "state" at least
>>>>> changes into "suspended" when one removes the cable, and hence also
>>>>> matches the gadget's state when really suspended.
>>>> On disconnection, did you see disconnect interrupt? If so, it should
>>>> transition to USB_STATE_NOATTACHED. This change doesn't seem to
>>>> directly
>>>> address your issue. Can you provide the driver tracepoints?
>>>
>>> The device doesn't issue a disconnect event, I didn't have tracing
>>> enabled in the kernel but added some dev_info() calls to determine
>>> what was going on. Added this to dwc3_process_event_entry():
>>>
>>> dev_info(dwc->dev, "event: 0x%x type=0x%x", event->raw,
>>> event->type.type);
>>>
>>> When disconnecting the cable from the host, I see this:
>>>
>>> [   50.841411] dwc3 3110000.usb: event: 0x6084 type=0x42
>>> [   50.841457] dwc3 3110000.usb: event: 0x4086 type=0x43
>>> [   50.841494] dwc3 3110000.usb: event: 0x6084 type=0x42
>>> [   50.841534] dwc3 3110000.usb: event: 0x4086 type=0x43
>>> [   50.841571] dwc3 3110000.usb: event: 0x4086 type=0x43
>>> [   52.650990] dwc3 3110000.usb: event: 0x30601 type=0x0
>>>
>>> The "0x4086" and "0x6084" messages are endpoint events that occur all
>>> the time while connected. The last event is the "suspend" one. After
>>> that, total silence.
>>>
>>> If you need traces, please point me to a description on how to obtain
>>> them.
>>>
>>>
>>
>> Hi Mike,
>>
>>  I may be wrong, but can you help understand the mechanism as to how
>> disconnect interrupt is generated in your targets. For example, on QC
>> SoC's, this happens when HS_PHY_CTRL reg VBUS_VALID bit is cleared and
>> cable is disconnected. This is because the vbus line is not routed to
>> controller. But from my calls with Synopsys previously, I remember
>> that the vbus line is routed to the controller as well for other OEMs.
>> In your SoC, what is the indication to controller that vbus is absent ?
>>
> The board I'm testing this on is an LS1028ARDB. Looking at the
> schematic, VBUS is routed to the chip. There's also an LED attached to
> it, which turns off when I unplug the cable.
>
> In the devicetree, I can't see any hint of NXP-specific "glue" in the
> DWC3 entries, so it uses the controller "as is":
>
>                         compatible = "fsl,ls1028a-dwc3", "snps,dwc3";
>                         reg = <0x0 0x3100000 0x0 0x10000>;
>                         snps,dis_rxdet_inp3_quirk;
>                         snps,quirk-frame-length-adjustment = <0x20>;
>                         snps,incr-burst-type-adjustment = <1>, <4>,
> <8>, <16>;
>
> The "fsl,ls1028a-dwc3" keyword doesn't actually occur anywhere in the
> kernel, so it uses plain "snps,dwc3".
>
>
>> Also, after this happens, do you see the next plug in working ?
>
> Next plugin works, because of a "reset" event at that point that makes
> everything happy again.

Ahh, got it. Thanks for the info.
I ran into a similar issue before where disconnect isn't generated [1]
and was suspecting it could be the case here but it isn't.

[1]:
https://patchwork.kernel.org/project/linux-usb/patch/[email protected]/

Regards,
Krishna,

>
> The state remains in "configured" while the cable is out. Plugging the
> cable back in makes it revert to "default" first, then it goes back into
> "configured".
>

2024-06-04 23:20:45

by Thinh Nguyen

[permalink] [raw]
Subject: Re: [PATCH] usb: dwc3: gadget: Inform system of suspended state

Hi,

On Tue, Jun 04, 2024, Mike Looijmans wrote:
> On 04-06-2024 03:03, Thinh Nguyen wrote:
> > Hi,
> >
> > On Mon, Jun 03, 2024, Mike Looijmans wrote:
> > > When disconnecting the USB cable on an LS1028 device, nothing happens
> > > in userspace, which keeps thinking everything is still up and running.
> > > Turns out that the DWC3 controller only sends DWC3_DEVICE_EVENT_SUSPEND
> > > in that case, and not a DWC3_DEVICE_EVENT_DISCONNECT as one would
> > > expect. As a result, sysfs attribute "state" remains "configured"
> > > until something resets it.
> > >
> > > Forward the "suspended" state to sysfs, so that the "state" at least
> > > changes into "suspended" when one removes the cable, and hence also
> > > matches the gadget's state when really suspended.
> > On disconnection, did you see disconnect interrupt? If so, it should
> > transition to USB_STATE_NOATTACHED. This change doesn't seem to directly
> > address your issue. Can you provide the driver tracepoints?
>
> The device doesn't issue a disconnect event, I didn't have tracing enabled
> in the kernel but added some dev_info() calls to determine what was going
> on. Added this to dwc3_process_event_entry():
>
> dev_info(dwc->dev, "event: 0x%x type=0x%x", event->raw, event->type.type);
>
> When disconnecting the cable from the host, I see this:
>
> [   50.841411] dwc3 3110000.usb: event: 0x6084 type=0x42
> [   50.841457] dwc3 3110000.usb: event: 0x4086 type=0x43
> [   50.841494] dwc3 3110000.usb: event: 0x6084 type=0x42
> [   50.841534] dwc3 3110000.usb: event: 0x4086 type=0x43
> [   50.841571] dwc3 3110000.usb: event: 0x4086 type=0x43
> [   52.650990] dwc3 3110000.usb: event: 0x30601 type=0x0
>
> The "0x4086" and "0x6084" messages are endpoint events that occur all the
> time while connected. The last event is the "suspend" one. After that, total
> silence.
>
> If you need traces, please point me to a description on how to obtain them.
>
>

Let me know if you run into issues following this instructions to
capture the tracepoints:
https://docs.kernel.org/driver-api/usb/dwc3.html#required-information

From the patch you provided, you only apply the change for the usb
suspend. But did your device go through system suspend? If that's the
case, then the dwc3 driver will cause a soft-disconnect. Currently that
will not prompt a state change. We need the tracepoint to know more
detail.

Until we have the tracepoints, you can experiment with this test patch.
If my suspiction is correct, then this may resolve your issue:

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 89fc690fdf34..29dbb889a0e2 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2682,6 +2682,8 @@ static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc)
*/
ret = dwc3_gadget_run_stop(dwc, false);

+ usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED);
+
/*
* Stop the gadget after controller is halted, so that if needed, the
* events to update EP0 state can still occur while the run/stop


--

Thanks,
Thinh

2024-06-05 14:41:45

by Mike Looijmans

[permalink] [raw]
Subject: Re: [PATCH] usb: dwc3: gadget: Inform system of suspended state

On 05-06-2024 01:06, Thinh Nguyen wrote:
> Hi,
>
> On Tue, Jun 04, 2024, Mike Looijmans wrote:
>> On 04-06-2024 03:03, Thinh Nguyen wrote:
>>> Hi,
>>>
>>> On Mon, Jun 03, 2024, Mike Looijmans wrote:
>>>> When disconnecting the USB cable on an LS1028 device, nothing happens
>>>> in userspace, which keeps thinking everything is still up and running.
>>>> Turns out that the DWC3 controller only sends DWC3_DEVICE_EVENT_SUSPEND
>>>> in that case, and not a DWC3_DEVICE_EVENT_DISCONNECT as one would
>>>> expect. As a result, sysfs attribute "state" remains "configured"
>>>> until something resets it.
>>>>
>>>> Forward the "suspended" state to sysfs, so that the "state" at least
>>>> changes into "suspended" when one removes the cable, and hence also
>>>> matches the gadget's state when really suspended.
>>> On disconnection, did you see disconnect interrupt? If so, it should
>>> transition to USB_STATE_NOATTACHED. This change doesn't seem to directly
>>> address your issue. Can you provide the driver tracepoints?
>> The device doesn't issue a disconnect event, I didn't have tracing enabled
>> in the kernel but added some dev_info() calls to determine what was going
>> on. Added this to dwc3_process_event_entry():
>>
>> dev_info(dwc->dev, "event: 0x%x type=0x%x", event->raw, event->type.type);
>>
>> When disconnecting the cable from the host, I see this:
>>
>> [   50.841411] dwc3 3110000.usb: event: 0x6084 type=0x42
>> [   50.841457] dwc3 3110000.usb: event: 0x4086 type=0x43
>> [   50.841494] dwc3 3110000.usb: event: 0x6084 type=0x42
>> [   50.841534] dwc3 3110000.usb: event: 0x4086 type=0x43
>> [   50.841571] dwc3 3110000.usb: event: 0x4086 type=0x43
>> [   52.650990] dwc3 3110000.usb: event: 0x30601 type=0x0
>>
>> The "0x4086" and "0x6084" messages are endpoint events that occur all the
>> time while connected. The last event is the "suspend" one. After that, total
>> silence.
>>
>> If you need traces, please point me to a description on how to obtain them.
>>
>>
> Let me know if you run into issues following this instructions to
> capture the tracepoints:
> https://docs.kernel.org/driver-api/usb/dwc3.html#required-information
>
> From the patch you provided, you only apply the change for the usb
> suspend. But did your device go through system suspend? If that's the
> case, then the dwc3 driver will cause a soft-disconnect. Currently that
> will not prompt a state change. We need the tracepoint to know more
> detail.
>
> Until we have the tracepoints, you can experiment with this test patch.
> If my suspiction is correct, then this may resolve your issue:
>
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 89fc690fdf34..29dbb889a0e2 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -2682,6 +2682,8 @@ static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc)
> */
> ret = dwc3_gadget_run_stop(dwc, false);
>
> + usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED);
> +
> /*
> * Stop the gadget after controller is halted, so that if needed, the
> * events to update EP0 state can still occur while the run/stop

I tried the patch above, but it doesn't work. Apparently
dwc3_gadget_soft_disconnect() doesn't get called when I unplug the cable.

--

Mike Looijmans
System Expert

TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W: http://www.topic.nl




2024-06-06 00:29:48

by Thinh Nguyen

[permalink] [raw]
Subject: Re: [PATCH] usb: dwc3: gadget: Inform system of suspended state

On Wed, Jun 05, 2024, Mike Looijmans wrote:
> On 05-06-2024 01:06, Thinh Nguyen wrote:
> > Hi,
> >
> > On Tue, Jun 04, 2024, Mike Looijmans wrote:
> > > On 04-06-2024 03:03, Thinh Nguyen wrote:
> > > > Hi,
> > > >
> > > > On Mon, Jun 03, 2024, Mike Looijmans wrote:
> > > > > When disconnecting the USB cable on an LS1028 device, nothing happens
> > > > > in userspace, which keeps thinking everything is still up and running.
> > > > > Turns out that the DWC3 controller only sends DWC3_DEVICE_EVENT_SUSPEND
> > > > > in that case, and not a DWC3_DEVICE_EVENT_DISCONNECT as one would
> > > > > expect. As a result, sysfs attribute "state" remains "configured"
> > > > > until something resets it.
> > > > >
> > > > > Forward the "suspended" state to sysfs, so that the "state" at least
> > > > > changes into "suspended" when one removes the cable, and hence also
> > > > > matches the gadget's state when really suspended.
> > > > On disconnection, did you see disconnect interrupt? If so, it should
> > > > transition to USB_STATE_NOATTACHED. This change doesn't seem to directly
> > > > address your issue. Can you provide the driver tracepoints?
> > > The device doesn't issue a disconnect event, I didn't have tracing enabled
> > > in the kernel but added some dev_info() calls to determine what was going
> > > on. Added this to dwc3_process_event_entry():
> > >
> > > dev_info(dwc->dev, "event: 0x%x type=0x%x", event->raw, event->type.type);
> > >
> > > When disconnecting the cable from the host, I see this:
> > >
> > > [   50.841411] dwc3 3110000.usb: event: 0x6084 type=0x42
> > > [   50.841457] dwc3 3110000.usb: event: 0x4086 type=0x43
> > > [   50.841494] dwc3 3110000.usb: event: 0x6084 type=0x42
> > > [   50.841534] dwc3 3110000.usb: event: 0x4086 type=0x43
> > > [   50.841571] dwc3 3110000.usb: event: 0x4086 type=0x43
> > > [   52.650990] dwc3 3110000.usb: event: 0x30601 type=0x0
> > >
> > > The "0x4086" and "0x6084" messages are endpoint events that occur all the
> > > time while connected. The last event is the "suspend" one. After that, total
> > > silence.
> > >
> > > If you need traces, please point me to a description on how to obtain them.
> > >
> > >
> > Let me know if you run into issues following this instructions to
> > capture the tracepoints:
> > https://urldefense.com/v3/__https://docs.kernel.org/driver-api/usb/dwc3.html*required-information__;Iw!!A4F2R9G_pg!epxtPmXHiizMg5_5igEYiKU483OZb1zcYK1M3afqXxIfgsw_cU_kdz9Rlpf1w-30JF0v4UUkxBViJtx4Prv3ZWchjKNHkKE$
> >
> > From the patch you provided, you only apply the change for the usb
> > suspend. But did your device go through system suspend? If that's the
> > case, then the dwc3 driver will cause a soft-disconnect. Currently that
> > will not prompt a state change. We need the tracepoint to know more
> > detail.
> >
> > Until we have the tracepoints, you can experiment with this test patch.
> > If my suspiction is correct, then this may resolve your issue:
> >
> > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> > index 89fc690fdf34..29dbb889a0e2 100644
> > --- a/drivers/usb/dwc3/gadget.c
> > +++ b/drivers/usb/dwc3/gadget.c
> > @@ -2682,6 +2682,8 @@ static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc)
> > */
> > ret = dwc3_gadget_run_stop(dwc, false);
> > + usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED);
> > +
> > /*
> > * Stop the gadget after controller is halted, so that if needed, the
> > * events to update EP0 state can still occur while the run/stop
>
> I tried the patch above, but it doesn't work. Apparently
> dwc3_gadget_soft_disconnect() doesn't get called when I unplug the cable.
>

Thanks for testing. There's no system suspend, so that's expected.

BR,
Thinh