Skip to content

Commit a808925

Browse files
xy521521gregkh
authored andcommitted
xhci: Keep interrupt disabled in initialization until host is running.
irq is disabled in xhci_quiesce(called by xhci_halt, with bit:2 cleared in USBCMD register), but xhci_run(called by usb_add_hcd) re-enable it. It's possible that you will receive thousands of interrupt requests after initialization for 2.0 roothub. And you will get a lot of warning like, "xHCI dying, ignoring interrupt. Shouldn't IRQs be disabled?". This amount of interrupt requests will cause the entire system to freeze. This problem was first found on a device with ASM2142 host controller on it. [tidy up old code while moving it, reword header -Mathias] Cc: [email protected] Signed-off-by: Hongyu Xie <[email protected]> Signed-off-by: Mathias Nyman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2bdc2bc commit a808925

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

drivers/usb/host/xhci.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -611,15 +611,37 @@ static int xhci_init(struct usb_hcd *hcd)
611611

612612
static int xhci_run_finished(struct xhci_hcd *xhci)
613613
{
614+
unsigned long flags;
615+
u32 temp;
616+
617+
/*
618+
* Enable interrupts before starting the host (xhci 4.2 and 5.5.2).
619+
* Protect the short window before host is running with a lock
620+
*/
621+
spin_lock_irqsave(&xhci->lock, flags);
622+
623+
xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable interrupts");
624+
temp = readl(&xhci->op_regs->command);
625+
temp |= (CMD_EIE);
626+
writel(temp, &xhci->op_regs->command);
627+
628+
xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable primary interrupter");
629+
temp = readl(&xhci->ir_set->irq_pending);
630+
writel(ER_IRQ_ENABLE(temp), &xhci->ir_set->irq_pending);
631+
614632
if (xhci_start(xhci)) {
615633
xhci_halt(xhci);
634+
spin_unlock_irqrestore(&xhci->lock, flags);
616635
return -ENODEV;
617636
}
637+
618638
xhci->cmd_ring_state = CMD_RING_STATE_RUNNING;
619639

620640
if (xhci->quirks & XHCI_NEC_HOST)
621641
xhci_ring_cmd_db(xhci);
622642

643+
spin_unlock_irqrestore(&xhci->lock, flags);
644+
623645
return 0;
624646
}
625647

@@ -668,19 +690,6 @@ int xhci_run(struct usb_hcd *hcd)
668690
temp |= (xhci->imod_interval / 250) & ER_IRQ_INTERVAL_MASK;
669691
writel(temp, &xhci->ir_set->irq_control);
670692

671-
/* Set the HCD state before we enable the irqs */
672-
temp = readl(&xhci->op_regs->command);
673-
temp |= (CMD_EIE);
674-
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
675-
"// Enable interrupts, cmd = 0x%x.", temp);
676-
writel(temp, &xhci->op_regs->command);
677-
678-
temp = readl(&xhci->ir_set->irq_pending);
679-
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
680-
"// Enabling event ring interrupter %p by writing 0x%x to irq_pending",
681-
xhci->ir_set, (unsigned int) ER_IRQ_ENABLE(temp));
682-
writel(ER_IRQ_ENABLE(temp), &xhci->ir_set->irq_pending);
683-
684693
if (xhci->quirks & XHCI_NEC_HOST) {
685694
struct xhci_command *command;
686695

0 commit comments

Comments
 (0)