usb: xhci: refactor trb_in_td() to be static
authorNiklas Neronin <niklas.neronin@linux.intel.com>
Thu, 6 Mar 2025 14:49:49 +0000 (16:49 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 6 Mar 2025 15:46:16 +0000 (16:46 +0100)
Relocate trb_in_td() and marks it as static, as it's exclusively utilized
in xhci-ring.c. This adjustment lays the groundwork for future rework of
the function.

The function's logic remains unchanged; only its access specifier is
altered to static and a redundant "else" is removed on line 325
(due to checkpatch.pl complaining).

Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20250306144954.3507700-11-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/xhci-ring.c
drivers/usb/host/xhci.h

index 70b8962974948c4f4c185ebbd938c3387c404748..8c7258afb6bfe8bfc37ea83956b6c78fce1119ec 100644 (file)
@@ -277,6 +277,67 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring,
        }
 }
 
+/*
+ * If the suspect DMA address is a TRB in this TD, this function returns that
+ * TRB's segment. Otherwise it returns 0.
+ */
+static struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, struct xhci_td *td,
+                                     dma_addr_t suspect_dma, bool debug)
+{
+       dma_addr_t start_dma;
+       dma_addr_t end_seg_dma;
+       dma_addr_t end_trb_dma;
+       struct xhci_segment *cur_seg;
+
+       start_dma = xhci_trb_virt_to_dma(td->start_seg, td->start_trb);
+       cur_seg = td->start_seg;
+
+       do {
+               if (start_dma == 0)
+                       return NULL;
+               /* We may get an event for a Link TRB in the middle of a TD */
+               end_seg_dma = xhci_trb_virt_to_dma(cur_seg,
+                               &cur_seg->trbs[TRBS_PER_SEGMENT - 1]);
+               /* If the end TRB isn't in this segment, this is set to 0 */
+               end_trb_dma = xhci_trb_virt_to_dma(cur_seg, td->end_trb);
+
+               if (debug)
+                       xhci_warn(xhci,
+                               "Looking for event-dma %016llx trb-start %016llx trb-end %016llx seg-start %016llx seg-end %016llx\n",
+                               (unsigned long long)suspect_dma,
+                               (unsigned long long)start_dma,
+                               (unsigned long long)end_trb_dma,
+                               (unsigned long long)cur_seg->dma,
+                               (unsigned long long)end_seg_dma);
+
+               if (end_trb_dma > 0) {
+                       /* The end TRB is in this segment, so suspect should be here */
+                       if (start_dma <= end_trb_dma) {
+                               if (suspect_dma >= start_dma && suspect_dma <= end_trb_dma)
+                                       return cur_seg;
+                       } else {
+                               /* Case for one segment with
+                                * a TD wrapped around to the top
+                                */
+                               if ((suspect_dma >= start_dma &&
+                                                       suspect_dma <= end_seg_dma) ||
+                                               (suspect_dma >= cur_seg->dma &&
+                                                suspect_dma <= end_trb_dma))
+                                       return cur_seg;
+                       }
+                       return NULL;
+               }
+               /* Might still be somewhere in this segment */
+               if (suspect_dma >= start_dma && suspect_dma <= end_seg_dma)
+                       return cur_seg;
+
+               cur_seg = cur_seg->next;
+               start_dma = xhci_trb_virt_to_dma(cur_seg, &cur_seg->trbs[0]);
+       } while (cur_seg != td->start_seg);
+
+       return NULL;
+}
+
 /*
  * Return number of free normal TRBs from enqueue to dequeue pointer on ring.
  * Not counting an assumed link TRB at end of each TRBS_PER_SEGMENT sized segment.
@@ -2079,67 +2140,6 @@ cleanup:
        spin_lock(&xhci->lock);
 }
 
-/*
- * If the suspect DMA address is a TRB in this TD, this function returns that
- * TRB's segment. Otherwise it returns 0.
- */
-struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, struct xhci_td *td, dma_addr_t suspect_dma,
-                              bool debug)
-{
-       dma_addr_t start_dma;
-       dma_addr_t end_seg_dma;
-       dma_addr_t end_trb_dma;
-       struct xhci_segment *cur_seg;
-
-       start_dma = xhci_trb_virt_to_dma(td->start_seg, td->start_trb);
-       cur_seg = td->start_seg;
-
-       do {
-               if (start_dma == 0)
-                       return NULL;
-               /* We may get an event for a Link TRB in the middle of a TD */
-               end_seg_dma = xhci_trb_virt_to_dma(cur_seg,
-                               &cur_seg->trbs[TRBS_PER_SEGMENT - 1]);
-               /* If the end TRB isn't in this segment, this is set to 0 */
-               end_trb_dma = xhci_trb_virt_to_dma(cur_seg, td->end_trb);
-
-               if (debug)
-                       xhci_warn(xhci,
-                               "Looking for event-dma %016llx trb-start %016llx trb-end %016llx seg-start %016llx seg-end %016llx\n",
-                               (unsigned long long)suspect_dma,
-                               (unsigned long long)start_dma,
-                               (unsigned long long)end_trb_dma,
-                               (unsigned long long)cur_seg->dma,
-                               (unsigned long long)end_seg_dma);
-
-               if (end_trb_dma > 0) {
-                       /* The end TRB is in this segment, so suspect should be here */
-                       if (start_dma <= end_trb_dma) {
-                               if (suspect_dma >= start_dma && suspect_dma <= end_trb_dma)
-                                       return cur_seg;
-                       } else {
-                               /* Case for one segment with
-                                * a TD wrapped around to the top
-                                */
-                               if ((suspect_dma >= start_dma &&
-                                                       suspect_dma <= end_seg_dma) ||
-                                               (suspect_dma >= cur_seg->dma &&
-                                                suspect_dma <= end_trb_dma))
-                                       return cur_seg;
-                       }
-                       return NULL;
-               } else {
-                       /* Might still be somewhere in this segment */
-                       if (suspect_dma >= start_dma && suspect_dma <= end_seg_dma)
-                               return cur_seg;
-               }
-               cur_seg = cur_seg->next;
-               start_dma = xhci_trb_virt_to_dma(cur_seg, &cur_seg->trbs[0]);
-       } while (cur_seg != td->start_seg);
-
-       return NULL;
-}
-
 static void xhci_clear_hub_tt_buffer(struct xhci_hcd *xhci, struct xhci_td *td,
                struct xhci_virt_ep *ep)
 {
index 5b8751b86008b1a54a0afcd0927a8fb8de4ad0a4..cd96e0a8c593a95bd1872e5c325abffb5fe00292 100644 (file)
@@ -1884,8 +1884,6 @@ int xhci_set_interrupter_moderation(struct xhci_interrupter *ir,
 
 /* xHCI ring, segment, TRB, and TD functions */
 dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb);
-struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, struct xhci_td *td,
-                              dma_addr_t suspect_dma, bool debug);
 int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code);
 void xhci_ring_cmd_db(struct xhci_hcd *xhci);
 int xhci_queue_slot_control(struct xhci_hcd *xhci, struct xhci_command *cmd,