linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc2: drd: fix soft connect when gadget is unconfigured
@ 2022-02-09 16:15 Fabrice Gasnier
  2022-02-10 17:21 ` Amelie DELAUNAY
  2022-02-11  8:03 ` Minas Harutyunyan
  0 siblings, 2 replies; 3+ messages in thread
From: Fabrice Gasnier @ 2022-02-09 16:15 UTC (permalink / raw)
  To: hminas, gregkh
  Cc: linux-usb, linux-kernel, linux-stm32, amelie.delaunay,
	alexandre.torgue, fabrice.gasnier

When the gadget driver hasn't been (yet) configured, and the cable is
connected to a HOST, the SFTDISCON gets cleared unconditionally, so the
HOST tries to enumerate it.
At the host side, this can result in a stuck USB port or worse. When
getting lucky, some dmesg can be observed at the host side:
 new high-speed USB device number ...
 device descriptor read/64, error -110

Fix it in drd, by checking the enabled flag before calling
dwc2_hsotg_core_connect(). It will be called later, once configured,
by the normal flow:
- udc_bind_to_driver
 - usb_gadget_connect
   - dwc2_hsotg_pullup
     - dwc2_hsotg_core_connect

Fixes: 17f934024e84 ("usb: dwc2: override PHY input signals with usb role switch support")
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
---
 drivers/usb/dwc2/drd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc2/drd.c b/drivers/usb/dwc2/drd.c
index 1b39c47..9b6d44d 100644
--- a/drivers/usb/dwc2/drd.c
+++ b/drivers/usb/dwc2/drd.c
@@ -130,8 +130,10 @@ static int dwc2_drd_role_sw_set(struct usb_role_switch *sw, enum usb_role role)
 		already = dwc2_ovr_avalid(hsotg, true);
 	} else if (role == USB_ROLE_DEVICE) {
 		already = dwc2_ovr_bvalid(hsotg, true);
-		/* This clear DCTL.SFTDISCON bit */
-		dwc2_hsotg_core_connect(hsotg);
+		if (hsotg->enabled) {
+			/* This clear DCTL.SFTDISCON bit */
+			dwc2_hsotg_core_connect(hsotg);
+		}
 	} else {
 		if (dwc2_is_device_mode(hsotg)) {
 			if (!dwc2_ovr_bvalid(hsotg, false))
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: dwc2: drd: fix soft connect when gadget is unconfigured
  2022-02-09 16:15 [PATCH] usb: dwc2: drd: fix soft connect when gadget is unconfigured Fabrice Gasnier
@ 2022-02-10 17:21 ` Amelie DELAUNAY
  2022-02-11  8:03 ` Minas Harutyunyan
  1 sibling, 0 replies; 3+ messages in thread
From: Amelie DELAUNAY @ 2022-02-10 17:21 UTC (permalink / raw)
  To: Fabrice Gasnier, hminas, gregkh
  Cc: linux-usb, linux-kernel, linux-stm32, alexandre.torgue


On 2/9/22 17:15, Fabrice Gasnier wrote:
> When the gadget driver hasn't been (yet) configured, and the cable is
> connected to a HOST, the SFTDISCON gets cleared unconditionally, so the
> HOST tries to enumerate it.
> At the host side, this can result in a stuck USB port or worse. When
> getting lucky, some dmesg can be observed at the host side:
>   new high-speed USB device number ...
>   device descriptor read/64, error -110
> 
> Fix it in drd, by checking the enabled flag before calling
> dwc2_hsotg_core_connect(). It will be called later, once configured,
> by the normal flow:
> - udc_bind_to_driver
>   - usb_gadget_connect
>     - dwc2_hsotg_pullup
>       - dwc2_hsotg_core_connect
> 
> Fixes: 17f934024e84 ("usb: dwc2: override PHY input signals with usb role switch support")
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>

Thanks for your patch,

Reviewed-by: Amelie Delaunay <amelie.delaunay@foss.st.com>

Regards,
Amelie

> ---
>   drivers/usb/dwc2/drd.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/drd.c b/drivers/usb/dwc2/drd.c
> index 1b39c47..9b6d44d 100644
> --- a/drivers/usb/dwc2/drd.c
> +++ b/drivers/usb/dwc2/drd.c
> @@ -130,8 +130,10 @@ static int dwc2_drd_role_sw_set(struct usb_role_switch *sw, enum usb_role role)
>   		already = dwc2_ovr_avalid(hsotg, true);
>   	} else if (role == USB_ROLE_DEVICE) {
>   		already = dwc2_ovr_bvalid(hsotg, true);
> -		/* This clear DCTL.SFTDISCON bit */
> -		dwc2_hsotg_core_connect(hsotg);
> +		if (hsotg->enabled) {
> +			/* This clear DCTL.SFTDISCON bit */
> +			dwc2_hsotg_core_connect(hsotg);
> +		}
>   	} else {
>   		if (dwc2_is_device_mode(hsotg)) {
>   			if (!dwc2_ovr_bvalid(hsotg, false))

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: dwc2: drd: fix soft connect when gadget is unconfigured
  2022-02-09 16:15 [PATCH] usb: dwc2: drd: fix soft connect when gadget is unconfigured Fabrice Gasnier
  2022-02-10 17:21 ` Amelie DELAUNAY
@ 2022-02-11  8:03 ` Minas Harutyunyan
  1 sibling, 0 replies; 3+ messages in thread
From: Minas Harutyunyan @ 2022-02-11  8:03 UTC (permalink / raw)
  To: Fabrice Gasnier, gregkh@linuxfoundation.org
  Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	amelie.delaunay@foss.st.com, alexandre.torgue@foss.st.com

On 2/9/2022 8:15 PM, Fabrice Gasnier wrote:
> When the gadget driver hasn't been (yet) configured, and the cable is
> connected to a HOST, the SFTDISCON gets cleared unconditionally, so the
> HOST tries to enumerate it.
> At the host side, this can result in a stuck USB port or worse. When
> getting lucky, some dmesg can be observed at the host side:
>   new high-speed USB device number ...
>   device descriptor read/64, error -110
> 
> Fix it in drd, by checking the enabled flag before calling
> dwc2_hsotg_core_connect(). It will be called later, once configured,
> by the normal flow:
> - udc_bind_to_driver
>   - usb_gadget_connect
>     - dwc2_hsotg_pullup
>       - dwc2_hsotg_core_connect
> 
> Fixes: 17f934024e84 ("usb: dwc2: override PHY input signals with usb role switch support")
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>

Acked-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>

> ---
>   drivers/usb/dwc2/drd.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/drd.c b/drivers/usb/dwc2/drd.c
> index 1b39c47..9b6d44d 100644
> --- a/drivers/usb/dwc2/drd.c
> +++ b/drivers/usb/dwc2/drd.c
> @@ -130,8 +130,10 @@ static int dwc2_drd_role_sw_set(struct usb_role_switch *sw, enum usb_role role)
>   		already = dwc2_ovr_avalid(hsotg, true);
>   	} else if (role == USB_ROLE_DEVICE) {
>   		already = dwc2_ovr_bvalid(hsotg, true);
> -		/* This clear DCTL.SFTDISCON bit */
> -		dwc2_hsotg_core_connect(hsotg);
> +		if (hsotg->enabled) {
> +			/* This clear DCTL.SFTDISCON bit */
> +			dwc2_hsotg_core_connect(hsotg);
> +		}
>   	} else {
>   		if (dwc2_is_device_mode(hsotg)) {
>   			if (!dwc2_ovr_bvalid(hsotg, false))


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-11  8:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-09 16:15 [PATCH] usb: dwc2: drd: fix soft connect when gadget is unconfigured Fabrice Gasnier
2022-02-10 17:21 ` Amelie DELAUNAY
2022-02-11  8:03 ` Minas Harutyunyan

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).