From: Luca Ceresoli <luca.ceresoli@bootlin.com>
To: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
Cc: "Alan Stern" <stern@rowland.harvard.edu>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"Kever Yang" <kever.yang@rock-chips.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Hervé Codina" <herve.codina@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Stefan Wahren" <wahrenst@gmx.net>,
"Fabrice Gasnier" <fabrice.gasnier@foss.st.com>
Subject: Re: DWC2 gadget: unexpected device reenumeration on Rockchip RK3308
Date: Tue, 20 May 2025 14:09:36 +0200 [thread overview]
Message-ID: <20250520140936.08d72db6@booty> (raw)
In-Reply-To: <329f68fb-a097-ff3d-da9d-f535a8429ea7@synopsys.com>
Hello Minas,
On Tue, 13 May 2025 07:35:40 +0000
Minas Harutyunyan <Minas.Harutyunyan@synopsys.com> wrote:
> >> I don't know anything about that driver, though. Minas is the expert.
> >> You really need his advice.
> >
> > In the meanwhile I did two event captures, one with the mainline kernel
> > and one with the vendor kernel, using the same laptop setup and no hub
> > in between, and for each test I captured both the usbmon log and a
> > wireshark file. Both are available if needed.
> >
> > By analyzing those captures I found that the communication between host
> > and gadget is almost identical. The only differenceis the get
> > configuration descriptor response has one more descriptor in the vendor
> > case (the working one). Here it is:
> >
> > OTG Descriptor:
> > bLength 3
> > bDescriptorType 9
> > bmAttributes 0x03
> > SRP (Session Request Protocol)
> > HNP (Host Negotiation Protocol)
> >
> > I don't know exacty what that implies, but for a quick test I went in
> > the mainline kernel and found that it can add the same descriptor if
> > both of these is true:
> >
> > * dr_mode = "otg" in device tree
> > * "DWC2 Mode Selection" is "Dual role mode" in kconfig
> > (i.e. CONFIG_USB_DWC2_DUAL_ROLE=y)
> >
> > While I had:
> >
> > * dr_mode = "peripheral"
> > * "DWC2 Mode Selection" = "Gadget only mode"
> > (i.e. CONFIG_USB_DWC2_PERIPHERAL=y)
> >
> > With those two changes the mainline kernel now behaves correctly, just
> > like the vendor kernel. No more disconnection after 5-6 seconds.
> >
> > For the records, the vendor kernel already had dr_mode = "otg" and
> > CONFIG_USB_DWC2_DUAL_ROLE=y.
> >
> > Based on my very limited knowledge of USB, intuitively it looks that:
> >
> > * in peripheral-only mode the OTG Descriptor should not be sent
> > * in peripheral-only mode SRP does not make sense
> > * in peripheral-only mode HNP does not make sense
> >
> > Are the above correct?
> >
> > Whether the answer, I think these new findings do not yet explain the
> > problem nor point to a correct solution. Apart from the added
> > descriptor, all of the initial enumeration events seen by usbmon is
> > identical in the two cases.
> >
> > Minas, were you able to have a look at the info I collected?
> > Do they suggesting you anything about the dwc2 driver?
> >
> Configuration parameters: CONFIG_USB_DWC2_HOST,
> CONFIG_USB_DWC2_PERIPHERAL and CONFIG_USB_DWC2_DUAL_ROLE have impact
> only on build process. Based on these parameters driver can build as
> host only, device only or host + device.
>
> OTG functionality of depend on:
> 1. On core configuration - GHWCFG2 bits 0:2:
> Mode of Operation (OtgMode)
> 3'b000: HNP- and SRP-Capable OTG (Host & Device)
> 3'b001: SRP-Capable OTG (Host & Device)
> 3'b010: Non-HNP and Non-SRP Capable OTG (Host and Device)
> 3'b011: SRP-Capable Device
> 3'b100: Non-OTG Device
> 3'b101: SRP-Capable Host
> 3'b110: Non-OTG Host
> Others: Reserved
> As you can see above, device only mode can support OTG, i.e.
> "SRP-capable device".
> Based on provided OTG descriptor your core's OTG mode is equal to 0,
> which means "HNP- and SRP-Capable OTG (Host & Device)".
> 2. Depend on platform (see dwc2/param.c) OTG functionality can be
> updated, if it allowed by above core configuration OTG parameter.
> 3. OTG functionality can updated also through devicetree parameters
> settings.
Thanks for the clarification. FYI the GHWCFG2 value is 0x228e2450 on
the RK3308, so OtgMode = "3'b000: HNP- and SRP-Capable OTG (Host &
Device)".
And I confirm the outcome of my tests:
A) if dr_mode = "otg" in DT AND CONFIG_USB_DWC2_DUAL_ROLE=y:
- OTG descriptor is sent
- no disconnection, no re-enumeration
B) if dr_mode = "peripheral" in DT OR CONFIG_USB_DWC2_PERIPHERAL=y:
- OTG descriptor is not sent
- disconnection+enumeration after ~6 seconds
The disconnection in case B should _not_ happen.
The presence/absence of the OTG descriptor is not wrong AFAICU. I'm
mentioning it just because it might give some clues.
I did a comparison of /sys/kernel/debug/usb/ff400000.usb/regdump in
cases A and B. The only relevant difference is that bit
USBOTG_GUSBCFG.ForceDevMode is 1 in case B. Based on the TRM, this
seems correct.
Doing other checks on registers and adding some logging to the code
showed everything appears to be configured correctly.
So, nothing explains why after about 6 seconds there is a disconnect.
My tests are done on mainline Linux v6.15-rc2.
Minas, do you have any hints or advice to understand why there is a
disconnect about ~6 seconds after a successful enumeration in gadget
mode?
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2025-05-20 12:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-14 16:54 DWC2 gadget: unexpected device reenumeration on Rockchip RK3308 Luca Ceresoli
2025-04-14 17:26 ` Alan Stern
2025-04-15 11:26 ` Minas Harutyunyan
2025-04-15 14:28 ` Luca Ceresoli
2025-04-15 15:58 ` Luca Ceresoli
2025-04-15 16:14 ` Alan Stern
2025-05-02 13:53 ` Luca Ceresoli
2025-05-02 17:56 ` Alan Stern
2025-05-09 7:17 ` Luca Ceresoli
2025-05-13 7:35 ` Minas Harutyunyan
2025-05-20 12:09 ` Luca Ceresoli [this message]
2025-06-12 13:23 ` Louis Chauvet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250520140936.08d72db6@booty \
--to=luca.ceresoli@bootlin.com \
--cc=Minas.Harutyunyan@synopsys.com \
--cc=fabrice.gasnier@foss.st.com \
--cc=gregkh@linuxfoundation.org \
--cc=herve.codina@bootlin.com \
--cc=kever.yang@rock-chips.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=thomas.petazzoni@bootlin.com \
--cc=wahrenst@gmx.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).