linux/drivers/usb
Fabrice Gasnier 5021383242 usb: dwc2: fix a race, don't power off/on phy for dual-role mode
When in dual role mode (dr_mode == USB_DR_MODE_OTG), platform probe
successively basically calls:
- dwc2_gadget_init()
- dwc2_hcd_init()
- dwc2_lowlevel_hw_disable() since recent change [1]
- usb_add_gadget_udc()

The PHYs (and so the clocks it may provide) shouldn't be disabled for all
SoCs, in OTG mode, as the HCD part has been initialized.

On STM32 this creates some weird race condition upon boot, when:
- initially attached as a device, to a HOST
- and there is a gadget script invoked to setup the device part.
Below issue becomes systematic, as long as the gadget script isn't
started by userland: the hardware PHYs (and so the clocks provided by the
PHYs) remains disabled.
It ends up in having an endless interrupt storm, before the watchdog
resets the platform.

[   16.924163] dwc2 49000000.usb-otg: EPs: 9, dedicated fifos, 952 entries in SPRAM
[   16.962704] dwc2 49000000.usb-otg: DWC OTG Controller
[   16.966488] dwc2 49000000.usb-otg: new USB bus registered, assigned bus number 2
[   16.974051] dwc2 49000000.usb-otg: irq 77, io mem 0x49000000
[   17.032170] hub 2-0:1.0: USB hub found
[   17.042299] hub 2-0:1.0: 1 port detected
[   17.175408] dwc2 49000000.usb-otg: Mode Mismatch Interrupt: currently in Host mode
[   17.181741] dwc2 49000000.usb-otg: Mode Mismatch Interrupt: currently in Host mode
[   17.189303] dwc2 49000000.usb-otg: Mode Mismatch Interrupt: currently in Host mode
...

The host part is also not functional, until the gadget part is configured.

The HW may only be disabled for peripheral mode (original init), e.g.
dr_mode == USB_DR_MODE_PERIPHERAL, until the gadget driver initializes.

But when in USB_DR_MODE_OTG, the HW should remain enabled, as the HCD part
is able to run, while the gadget part isn't necessarily configured.

I don't fully get the of purpose the original change, that claims disabling
the hardware is missing. It creates conditions on SOCs using the PHY
initialization to be completely non working in OTG mode. Original
change [1] should be reworked to be platform specific.

[1] https://lore.kernel.org/r/20221206-dwc2-gadget-dual-role-v1-2-36515e1092cd@theobroma-systems.com

Fixes: ade23d7b7e ("usb: dwc2: power on/off phy for peripheral mode in dual-role mode")
Cc: stable <stable@kernel.org>
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Reviewed-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
Tested-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
Link: https://lore.kernel.org/r/20230315144433.3095859-1-fabrice.gasnier@foss.st.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-03-23 19:13:16 +01:00
..
atm
c67x00
cdns3 usb: cdnsp: changes PCI Device ID to fix conflict with CNDS3 driver 2023-03-16 12:43:58 +01:00
chipidea usb: chipidea: core: fix possible concurrent when switch role 2023-03-23 18:17:32 +01:00
class tty: Call ->dtr_rts() parameter active consistently 2023-01-19 16:04:35 +01:00
common Driver core changes for 6.3-rc1 2023-02-24 12:58:55 -08:00
core Driver core changes for 6.3-rc1 2023-02-24 12:58:55 -08:00
dwc2 usb: dwc2: fix a race, don't power off/on phy for dual-role mode 2023-03-23 19:13:16 +01:00
dwc3 usb: dwc3: gadget: Add 1ms delay after end transfer command without IOC 2023-03-09 14:54:46 +01:00
early usb: early: xhci-dbc: Use memcpy_and_pad() 2023-01-31 10:40:54 +01:00
fotg210 USB: fotg210: fix memory leak with using debugfs_lookup() 2023-02-06 13:46:42 +01:00
gadget usb: gadget: Use correct endianness of the wLength field for WebUSB 2023-03-16 12:45:35 +01:00
host phy-for-6.3 2023-02-24 17:22:11 -08:00
image
isp1760
misc usb: misc: onboard-hub: add support for Microchip USB2517 USB 2.0 hub 2023-03-09 14:54:46 +01:00
mon mm: replace vma->vm_flags direct modifications with modifier calls 2023-02-09 16:51:39 -08:00
mtu3 usb: mtu3: fix the failure of qmu stop 2023-01-19 14:12:08 +01:00
musb usb: musb: sunxi: Introduce config struct 2023-02-02 11:13:42 +01:00
phy Driver core changes for 6.3-rc1 2023-02-24 12:58:55 -08:00
renesas_usbhs
roles driver core: make struct device_type.uevent() take a const * 2023-01-27 13:45:36 +01:00
serial TTY/Serial driver updates for 6.3-rc1 2023-02-24 12:17:14 -08:00
storage uas: Add US_FL_NO_REPORT_OPCODES for JMicron JMS583Gen 2 2023-03-16 12:44:17 +01:00
typec usb: typec: tcpm: fix warning when handle discover_identity message 2023-03-09 15:15:28 +01:00
usbip Including fixes from bpf, netfilter and can. 2022-12-21 08:41:32 -08:00
Kconfig usb: fotg210: Collect pieces of dual mode controller 2022-11-09 12:38:09 +01:00
Makefile usb: fotg210: Collect pieces of dual mode controller 2022-11-09 12:38:09 +01:00
usb-skeleton.c usb: add usb_set_intfdata() documentation 2022-11-29 08:56:09 +01:00