]> git.itanic.dy.fi Git - linux-stable/commitdiff
xhci: make isoc_bei_interval variable interrupter specific.
authorMathias Nyman <mathias.nyman@linux.intel.com>
Sat, 17 Feb 2024 00:09:29 +0000 (16:09 -0800)
committerSasha Levin <sashal@kernel.org>
Tue, 26 Mar 2024 22:17:29 +0000 (18:17 -0400)
[ Upstream commit becbd202af8425e336b1c25e9254616a5c03d819 ]

isoc_bei_interval is used to balance how often completed isochronous
events cause interrupts. If interval is too large then the event ring
may fill up before the completed isoc TRBs are handled.

isoc_bei_interval is tuned based on how full the event ring is.

isoc_bei_interval variable needs to be per interrupter as
with several interrupters each one has its own event ring.

move isoc_bei_interval variable to the interrupter structure.

if a secondary interrupter does not care about this feature then
keep isoc_bei_interval 0.

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-4-quic_wcheng@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Stable-dep-of: e30e9ad9ed66 ("xhci: update event ring dequeue pointer position to controller correctly")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/host/xhci-mem.c
drivers/usb/host/xhci-ring.c
drivers/usb/host/xhci.h

index a7716202a8dd58d74f3d31fd48d0833de89db2be..450adaca68eeb1d73d90c7662615b3cb757f4290 100644 (file)
@@ -2533,7 +2533,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
        if (xhci_add_interrupter(xhci, ir, 0))
                goto fail;
 
-       xhci->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX;
+       ir->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX;
 
        /*
         * XXX: Might need to set the Interrupter Moderation Register to
index b1ca3c9e5a75f7b20bec712e83dc03300b4f8c4c..53852383d6143a4615715436d4061ed639e5426b 100644 (file)
@@ -3159,8 +3159,8 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
                event_ring_deq = ir->event_ring->dequeue;
 
                /* ring is half-full, force isoc trbs to interrupt more often */
-               if (xhci->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN)
-                       xhci->isoc_bei_interval = xhci->isoc_bei_interval / 2;
+               if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN)
+                       ir->isoc_bei_interval = ir->isoc_bei_interval / 2;
 
                event_loop = 0;
        }
@@ -4028,7 +4028,8 @@ static int xhci_get_isoc_frame_id(struct xhci_hcd *xhci,
 }
 
 /* Check if we should generate event interrupt for a TD in an isoc URB */
-static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i)
+static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i,
+                                struct xhci_interrupter *ir)
 {
        if (xhci->hci_version < 0x100)
                return false;
@@ -4039,8 +4040,8 @@ static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i)
         * If AVOID_BEI is set the host handles full event rings poorly,
         * generate an event at least every 8th TD to clear the event ring
         */
-       if (i && xhci->quirks & XHCI_AVOID_BEI)
-               return !!(i % xhci->isoc_bei_interval);
+       if (i && ir->isoc_bei_interval && xhci->quirks & XHCI_AVOID_BEI)
+               return !!(i % ir->isoc_bei_interval);
 
        return true;
 }
@@ -4049,6 +4050,7 @@ static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i)
 static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
                struct urb *urb, int slot_id, unsigned int ep_index)
 {
+       struct xhci_interrupter *ir;
        struct xhci_ring *ep_ring;
        struct urb_priv *urb_priv;
        struct xhci_td *td;
@@ -4066,6 +4068,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
 
        xep = &xhci->devs[slot_id]->eps[ep_index];
        ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
+       ir = xhci->interrupters[0];
 
        num_tds = urb->number_of_packets;
        if (num_tds < 1) {
@@ -4153,7 +4156,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
                                td->last_trb = ep_ring->enqueue;
                                td->last_trb_seg = ep_ring->enq_seg;
                                field |= TRB_IOC;
-                               if (trb_block_event_intr(xhci, num_tds, i))
+                               if (trb_block_event_intr(xhci, num_tds, i, ir))
                                        field |= TRB_BEI;
                        }
                        /* Calculate TRB length */
index 9e05ccdd36b2bbfd2feea06eb5b9a3d9ea874131..bf05103aa68a07c5ed181854884d16a45c437336 100644 (file)
@@ -1689,6 +1689,7 @@ struct xhci_interrupter {
        struct xhci_intr_reg __iomem *ir_set;
        unsigned int            intr_num;
        bool                    ip_autoclear;
+       u32                     isoc_bei_interval;
        /* For interrupter registers save and restore over suspend/resume */
        u32     s3_irq_pending;
        u32     s3_irq_control;
@@ -1761,7 +1762,6 @@ struct xhci_hcd {
        u8              isoc_threshold;
        /* imod_interval in ns (I * 250ns) */
        u32             imod_interval;
-       u32             isoc_bei_interval;
        int             event_ring_max;
        /* 4KB min, 128MB max */
        int             page_size;