Skip to content

Commit 9a7f4bc

Browse files
Epicuriusgregkh
authored andcommitted
usb: xhci: move debug capabilities from trb_in_td() to handle_tx_event()
Function trb_in_td() currently includes debug capabilities that are triggered when its debug argument is set to true. The only consumer of these debug capabilities is handle_tx_event(), which calls trb_in_td() twice, once for its primary functionality and a second time solely for debugging purposes if the first call returns 'NULL'. This approach is inefficient and can lead to confusion, as trb_in_td() executes the same code with identical arguments twice, differing only in the debug output during the second execution. To enhance clarity and efficiency, move the debug capabilities out of trb_in_td() and integrates them directly into handle_tx_event(). This change reduces the argument count of trb_in_td() and ensures that debug steps are executed only when necessary, streamlining the function's operation. Signed-off-by: Niklas Neronin <[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 d71cb7d commit 9a7f4bc

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

drivers/usb/host/xhci-ring.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring,
281281
* If the suspect DMA address is a TRB in this TD, this function returns that
282282
* TRB's segment. Otherwise it returns 0.
283283
*/
284-
static struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, struct xhci_td *td,
285-
dma_addr_t suspect_dma, bool debug)
284+
static struct xhci_segment *trb_in_td(struct xhci_td *td, dma_addr_t suspect_dma)
286285
{
287286
dma_addr_t start_dma;
288287
dma_addr_t end_seg_dma;
@@ -301,15 +300,6 @@ static struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, struct xhci_td *td,
301300
/* If the end TRB isn't in this segment, this is set to 0 */
302301
end_trb_dma = xhci_trb_virt_to_dma(cur_seg, td->end_trb);
303302

304-
if (debug)
305-
xhci_warn(xhci,
306-
"Looking for event-dma %016llx trb-start %016llx trb-end %016llx seg-start %016llx seg-end %016llx\n",
307-
(unsigned long long)suspect_dma,
308-
(unsigned long long)start_dma,
309-
(unsigned long long)end_trb_dma,
310-
(unsigned long long)cur_seg->dma,
311-
(unsigned long long)end_seg_dma);
312-
313303
if (end_trb_dma > 0) {
314304
/* The end TRB is in this segment, so suspect should be here */
315305
if (start_dma <= end_trb_dma) {
@@ -1075,7 +1065,7 @@ static int xhci_invalidate_cancelled_tds(struct xhci_virt_ep *ep)
10751065
td->urb->stream_id);
10761066
hw_deq &= ~0xf;
10771067

1078-
if (td->cancel_status == TD_HALTED || trb_in_td(xhci, td, hw_deq, false)) {
1068+
if (td->cancel_status == TD_HALTED || trb_in_td(td, hw_deq)) {
10791069
switch (td->cancel_status) {
10801070
case TD_CLEARED: /* TD is already no-op */
10811071
case TD_CLEARING_CACHE: /* set TR deq command already queued */
@@ -1165,7 +1155,7 @@ static struct xhci_td *find_halted_td(struct xhci_virt_ep *ep)
11651155
hw_deq = xhci_get_hw_deq(ep->xhci, ep->vdev, ep->ep_index, 0);
11661156
hw_deq &= ~0xf;
11671157
td = list_first_entry(&ep->ring->td_list, struct xhci_td, td_list);
1168-
if (trb_in_td(ep->xhci, td, hw_deq, false))
1158+
if (trb_in_td(td, hw_deq))
11691159
return td;
11701160
}
11711161
return NULL;
@@ -2800,7 +2790,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
28002790
*/
28012791
td = list_first_entry_or_null(&ep_ring->td_list, struct xhci_td, td_list);
28022792

2803-
if (td && td->error_mid_td && !trb_in_td(xhci, td, ep_trb_dma, false)) {
2793+
if (td && td->error_mid_td && !trb_in_td(td, ep_trb_dma)) {
28042794
xhci_dbg(xhci, "Missing TD completion event after mid TD error\n");
28052795
xhci_dequeue_td(xhci, td, ep_ring, td->status);
28062796
}
@@ -2833,7 +2823,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
28332823
td_list);
28342824

28352825
/* Is this a TRB in the currently executing TD? */
2836-
ep_seg = trb_in_td(xhci, td, ep_trb_dma, false);
2826+
ep_seg = trb_in_td(td, ep_trb_dma);
28372827

28382828
if (!ep_seg) {
28392829

@@ -2893,12 +2883,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
28932883
}
28942884

28952885
/* HC is busted, give up! */
2896-
xhci_err(xhci,
2897-
"ERROR Transfer event TRB DMA ptr not part of current TD ep_index %d comp_code %u\n",
2898-
ep_index, trb_comp_code);
2899-
trb_in_td(xhci, td, ep_trb_dma, true);
2900-
2901-
return -ESHUTDOWN;
2886+
goto debug_finding_td;
29022887
}
29032888

29042889
if (ep->skip) {
@@ -2955,6 +2940,17 @@ static int handle_tx_event(struct xhci_hcd *xhci,
29552940

29562941
return 0;
29572942

2943+
debug_finding_td:
2944+
xhci_err(xhci, "Event dma %pad for ep %d status %d not part of TD at %016llx - %016llx\n",
2945+
&ep_trb_dma, ep_index, trb_comp_code,
2946+
(unsigned long long)xhci_trb_virt_to_dma(td->start_seg, td->start_trb),
2947+
(unsigned long long)xhci_trb_virt_to_dma(td->end_seg, td->end_trb));
2948+
2949+
xhci_for_each_ring_seg(ep_ring->first_seg, ep_seg)
2950+
xhci_warn(xhci, "Ring seg %u dma %pad\n", ep_seg->num, &ep_seg->dma);
2951+
2952+
return -ESHUTDOWN;
2953+
29582954
err_out:
29592955
xhci_err(xhci, "@%016llx %08x %08x %08x %08x\n",
29602956
(unsigned long long) xhci_trb_virt_to_dma(

0 commit comments

Comments
 (0)