linux-stable/drivers/usb
Krishna Kurapati 113b12e164 usb: typec: ucsi: Fix race between typec_switch and role_switch
[ Upstream commit f5e9bda03a ]

When orientation switch is enabled in ucsi glink, there is a xhci
probe failure seen when booting up in host mode in reverse
orientation.

During bootup the following things happen in multiple drivers:

a) DWC3 controller driver initializes the core in device mode when the
dr_mode is set to DRD. It relies on role_switch call to change role to
host.

b) QMP driver initializes the lanes to TYPEC_ORIENTATION_NORMAL as a
normal routine. It relies on the typec_switch_set call to get notified
of orientation changes.

c) UCSI core reads the UCSI_GET_CONNECTOR_STATUS via the glink and
provides initial role switch to dwc3 controller.

When booting up in host mode with orientation TYPEC_ORIENTATION_REVERSE,
then we see the following things happening in order:

a) UCSI gives initial role as host to dwc3 controller ucsi_register_port.
Upon receiving this notification, the dwc3 core needs to program GCTL from
PRTCAP_DEVICE to PRTCAP_HOST and as part of this change, it asserts GCTL
Core soft reset and waits for it to be  completed before shifting it to
host. Only after the reset is done will the dwc3_host_init be invoked and
xhci is probed. DWC3 controller expects that the usb phy's are stable
during this process i.e., the phy init is already done.

b) During the 100ms wait for GCTL core soft reset, the actual notification
from PPM is received by ucsi_glink via pmic glink for changing role to
host. The pmic_glink_ucsi_notify routine first sends the orientation
change to QMP and then sends role to dwc3 via ucsi framework. This is
happening exactly at the time GCTL core soft reset is being processed.

c) When QMP driver receives typec switch to TYPEC_ORIENTATION_REVERSE, it
then re-programs the phy at the instant GCTL core soft reset has been
asserted by dwc3 controller due to which the QMP PLL lock fails in
qmp_combo_usb_power_on.

d) After the 100ms of GCTL core soft reset is completed, the dwc3 core
goes for initializing the host mode and invokes xhci probe. But at this
point the QMP is non-responsive and as a result, the xhci plat probe fails
during xhci_reset.

Fix this by passing orientation switch to available ucsi instances if
their gpio configuration is available before ucsi_register is invoked so
that by the time, the pmic_glink_ucsi_notify provides typec_switch to QMP,
the lane is already configured and the call would be a NOP thus not racing
with role switch.

Cc: stable@vger.kernel.org
Fixes: c6165ed2f4 ("usb: ucsi: glink: use the connector orientation GPIO to provide switch events")
Suggested-by: Wesley Cheng <quic_wcheng@quicinc.com>
Signed-off-by: Krishna Kurapati <quic_kriskura@quicinc.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20240301040914.458492-1-quic_kriskura@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-04-10 16:35:54 +02:00
..
atm
c67x00
cdns3 usb: cdns3: fix memory double free when handle zero packet 2024-03-01 13:35:02 +01:00
chipidea usb: chipidea: core: handle power lost in workqueue 2024-02-23 09:24:57 +01:00
class usb: cdc-wdm: close race between read and workqueue 2024-04-03 15:28:58 +02:00
common usb: ulpi: Fix debugfs directory leak 2024-02-23 09:24:56 +01:00
core USB: core: Fix deadlock in port "disable" sysfs attribute 2024-04-03 15:29:00 +02:00
dwc2 usb: dwc2: gadget: LPM flow fix 2024-04-03 15:29:00 +02:00
dwc3 usb: dwc3: pci: Drop duplicate ID 2024-04-03 15:29:03 +02:00
early
fotg210 usb: fotg210-hcd: delete an incorrect bounds test 2024-01-01 12:42:41 +00:00
gadget usb: udc: remove warning when queue disabled ep 2024-04-03 15:29:00 +02:00
host xhci: Fix failure to detect ring expansion need. 2024-04-03 15:28:42 +02:00
image
isp1760 usb: isp1760: Convert to platform remove callback returning void 2023-05-28 12:38:01 +01:00
misc usb: misc: onboard-hub: add support for Microchip USB5744 2023-12-03 07:33:08 +01:00
mon usb: mon: Fix atomicity violation in mon_bin_vma_fault 2024-01-25 15:35:43 -08:00
mtu3 usb: Explicitly include correct DT includes 2023-07-25 18:20:02 +02:00
musb usb: musb: Get the musb_qh poniter after musb_giveback 2023-10-02 13:37:57 +02:00
phy Revert "usb: phy: generic: Get the vbus supply" 2024-04-03 15:28:58 +02:00
renesas_usbhs usb: Explicitly include correct DT includes 2023-07-25 18:20:02 +02:00
roles usb: roles: don't get/set_role() when usb_role_switch is unregistered 2024-03-01 13:35:02 +01:00
serial USB: serial: cp210x: add pid/vid for TDK NC0110013M and MM0110113M 2024-04-03 15:28:24 +02:00
storage USB: UAS: return ENODEV when submit urbs fail with device not attached 2024-04-03 15:28:58 +02:00
typec usb: typec: ucsi: Fix race between typec_switch and role_switch 2024-04-10 16:35:54 +02:00
usbip USB: usbip: fix stub_dev hub disconnect 2023-11-20 11:59:26 +01:00
Kconfig
Makefile
usb-skeleton.c