Skip to content

Commit 7aed153

Browse files
roychl666gregkh
authored andcommitted
Revert "usb: xhci: Implement xhci_handshake_check_state() helper"
This reverts commit 6ccb83d. Commit 6ccb83d ("usb: xhci: Implement xhci_handshake_check_state() helper") was introduced to workaround watchdog timeout issues on some platforms, allowing xhci_reset() to bail out early without waiting for the reset to complete. Skipping the xhci handshake during a reset is a dangerous move. The xhci specification explicitly states that certain registers cannot be accessed during reset in section 5.4.1 USB Command Register (USBCMD), Host Controller Reset (HCRST) field: "This bit is cleared to '0' by the Host Controller when the reset process is complete. Software cannot terminate the reset process early by writinga '0' to this bit and shall not write any xHC Operational or Runtime registers until while HCRST is '1'." This behavior causes a regression on SNPS DWC3 USB controller with dual-role capability. When the DWC3 controller exits host mode and removes xhci while a reset is still in progress, and then tries to configure its hardware for device mode, the ongoing reset leads to register access issues; specifically, all register reads returns 0. These issues extend beyond the xhci register space (which is expected during a reset) and affect the entire DWC3 IP block, causing the DWC3 device mode to malfunction. Cc: stable <[email protected]> Fixes: 6ccb83d ("usb: xhci: Implement xhci_handshake_check_state() helper") Signed-off-by: Roy Luo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3eff494 commit 7aed153

File tree

3 files changed

+3
-30
lines changed

3 files changed

+3
-30
lines changed

drivers/usb/host/xhci-ring.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,8 @@ static int xhci_abort_cmd_ring(struct xhci_hcd *xhci, unsigned long flags)
518518
* In the future we should distinguish between -ENODEV and -ETIMEDOUT
519519
* and try to recover a -ETIMEDOUT with a host controller reset.
520520
*/
521-
ret = xhci_handshake_check_state(xhci, &xhci->op_regs->cmd_ring,
522-
CMD_RING_RUNNING, 0, 5 * 1000 * 1000,
523-
XHCI_STATE_REMOVING);
521+
ret = xhci_handshake(&xhci->op_regs->cmd_ring,
522+
CMD_RING_RUNNING, 0, 5 * 1000 * 1000);
524523
if (ret < 0) {
525524
xhci_err(xhci, "Abort failed to stop command ring: %d\n", ret);
526525
xhci_halt(xhci);

drivers/usb/host/xhci.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,6 @@ int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, u64 timeout_us)
8484
return ret;
8585
}
8686

87-
/*
88-
* xhci_handshake_check_state - same as xhci_handshake but takes an additional
89-
* exit_state parameter, and bails out with an error immediately when xhc_state
90-
* has exit_state flag set.
91-
*/
92-
int xhci_handshake_check_state(struct xhci_hcd *xhci, void __iomem *ptr,
93-
u32 mask, u32 done, int usec, unsigned int exit_state)
94-
{
95-
u32 result;
96-
int ret;
97-
98-
ret = readl_poll_timeout_atomic(ptr, result,
99-
(result & mask) == done ||
100-
result == U32_MAX ||
101-
xhci->xhc_state & exit_state,
102-
1, usec);
103-
104-
if (result == U32_MAX || xhci->xhc_state & exit_state)
105-
return -ENODEV;
106-
107-
return ret;
108-
}
109-
11087
/*
11188
* Disable interrupts and begin the xHCI halting process.
11289
*/
@@ -227,8 +204,7 @@ int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us)
227204
if (xhci->quirks & XHCI_INTEL_HOST)
228205
udelay(1000);
229206

230-
ret = xhci_handshake_check_state(xhci, &xhci->op_regs->command,
231-
CMD_RESET, 0, timeout_us, XHCI_STATE_REMOVING);
207+
ret = xhci_handshake(&xhci->op_regs->command, CMD_RESET, 0, timeout_us);
232208
if (ret)
233209
return ret;
234210

drivers/usb/host/xhci.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,8 +1868,6 @@ void xhci_skip_sec_intr_events(struct xhci_hcd *xhci,
18681868
/* xHCI host controller glue */
18691869
typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *);
18701870
int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, u64 timeout_us);
1871-
int xhci_handshake_check_state(struct xhci_hcd *xhci, void __iomem *ptr,
1872-
u32 mask, u32 done, int usec, unsigned int exit_state);
18731871
void xhci_quiesce(struct xhci_hcd *xhci);
18741872
int xhci_halt(struct xhci_hcd *xhci);
18751873
int xhci_start(struct xhci_hcd *xhci);

0 commit comments

Comments
 (0)