xhci: move event processing for one interrupter to a separate function

[ Upstream commit 84ac5e4fa5 ]

Split the main XHCI interrupt handler into a different API, so that other
potential interrupters can utilize similar event ring handling.  A scenario
would be if a secondary interrupter required to skip pending events in the
event ring, which would warrant a similar set of operations.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
Link: https://lore.kernel.org/r/20240217001017.29969-7-quic_wcheng@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Stable-dep-of: 5bfc311dd6 ("usb: xhci: correct return value in case of STS_HCE")
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Mathias Nyman 2024-02-16 16:09:32 -08:00 committed by Greg Kroah-Hartman
parent 0bbce526cf
commit 68660caf69
1 changed files with 42 additions and 45 deletions

View File

@ -3075,6 +3075,46 @@ static void xhci_clear_interrupt_pending(struct xhci_hcd *xhci,
}
}
static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir)
{
int event_loop = 0;
u64 temp;
xhci_clear_interrupt_pending(xhci, ir);
if (xhci->xhc_state & XHCI_STATE_DYING ||
xhci->xhc_state & XHCI_STATE_HALTED) {
xhci_dbg(xhci, "xHCI dying, ignoring interrupt. Shouldn't IRQs be disabled?\n");
/* Clear the event handler busy flag (RW1C) */
temp = xhci_read_64(xhci, &ir->ir_set->erst_dequeue);
xhci_write_64(xhci, temp | ERST_EHB, &ir->ir_set->erst_dequeue);
return -ENODEV;
}
while (xhci_handle_event(xhci, ir) > 0) {
/*
* If half a segment of events have been handled in one go then
* update ERDP, and force isoc trbs to interrupt more often
*/
if (event_loop++ > TRBS_PER_SEGMENT / 2) {
xhci_update_erst_dequeue(xhci, ir, false);
if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN)
ir->isoc_bei_interval = ir->isoc_bei_interval / 2;
event_loop = 0;
}
/* Update SW event ring dequeue pointer */
inc_deq(xhci, ir->event_ring);
}
xhci_update_erst_dequeue(xhci, ir, true);
return 0;
}
/*
* xHCI spec says we can get an interrupt, and if the HC has an error condition,
* we might get bad data out of the event ring. Section 4.10.2.7 has a list of
@ -3083,11 +3123,8 @@ static void xhci_clear_interrupt_pending(struct xhci_hcd *xhci,
irqreturn_t xhci_irq(struct usb_hcd *hcd)
{
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
struct xhci_interrupter *ir;
irqreturn_t ret = IRQ_NONE;
u64 temp_64;
u32 status;
int event_loop = 0;
spin_lock(&xhci->lock);
/* Check if the xHC generated the interrupt, or the irq is shared */
@ -3120,50 +3157,10 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
*/
status |= STS_EINT;
writel(status, &xhci->op_regs->status);
/* This is the handler of the primary interrupter */
ir = xhci->interrupters[0];
xhci_clear_interrupt_pending(xhci, ir);
if (xhci->xhc_state & XHCI_STATE_DYING ||
xhci->xhc_state & XHCI_STATE_HALTED) {
xhci_dbg(xhci, "xHCI dying, ignoring interrupt. "
"Shouldn't IRQs be disabled?\n");
/* Clear the event handler busy flag (RW1C);
* the event ring should be empty.
*/
temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue);
xhci_write_64(xhci, temp_64 | ERST_EHB,
&ir->ir_set->erst_dequeue);
ret = IRQ_HANDLED;
goto out;
}
/* FIXME this should be a delayed service routine
* that clears the EHB.
*/
while (xhci_handle_event(xhci, ir) > 0) {
/*
* If half a segment of events have been handled in one go then
* update ERDP, and force isoc trbs to interrupt more often
*/
if (event_loop++ > TRBS_PER_SEGMENT / 2) {
xhci_update_erst_dequeue(xhci, ir, false);
if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN)
ir->isoc_bei_interval = ir->isoc_bei_interval / 2;
event_loop = 0;
}
/* Update SW event ring dequeue pointer */
inc_deq(xhci, ir->event_ring);
}
xhci_update_erst_dequeue(xhci, ir, true);
ret = IRQ_HANDLED;
/* This is the handler of the primary interrupter */
xhci_handle_events(xhci, xhci->interrupters[0]);
out:
spin_unlock(&xhci->lock);