Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <niklas.neronin@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20250306144954.3507700-12-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Niklas Neronin and committed by
Greg Kroah-Hartman
9a7f4bc4 d71cb7d6

+17 -21
+17 -21
drivers/usb/host/xhci-ring.c
··· 281 281 * If the suspect DMA address is a TRB in this TD, this function returns that 282 282 * TRB's segment. Otherwise it returns 0. 283 283 */ 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) 286 285 { 287 286 dma_addr_t start_dma; 288 287 dma_addr_t end_seg_dma; ··· 299 300 &cur_seg->trbs[TRBS_PER_SEGMENT - 1]); 300 301 /* If the end TRB isn't in this segment, this is set to 0 */ 301 302 end_trb_dma = xhci_trb_virt_to_dma(cur_seg, td->end_trb); 302 - 303 - if (debug) 304 - xhci_warn(xhci, 305 - "Looking for event-dma %016llx trb-start %016llx trb-end %016llx seg-start %016llx seg-end %016llx\n", 306 - (unsigned long long)suspect_dma, 307 - (unsigned long long)start_dma, 308 - (unsigned long long)end_trb_dma, 309 - (unsigned long long)cur_seg->dma, 310 - (unsigned long long)end_seg_dma); 311 303 312 304 if (end_trb_dma > 0) { 313 305 /* The end TRB is in this segment, so suspect should be here */ ··· 1065 1075 td->urb->stream_id); 1066 1076 hw_deq &= ~0xf; 1067 1077 1068 - if (td->cancel_status == TD_HALTED || trb_in_td(xhci, td, hw_deq, false)) { 1078 + if (td->cancel_status == TD_HALTED || trb_in_td(td, hw_deq)) { 1069 1079 switch (td->cancel_status) { 1070 1080 case TD_CLEARED: /* TD is already no-op */ 1071 1081 case TD_CLEARING_CACHE: /* set TR deq command already queued */ ··· 1155 1165 hw_deq = xhci_get_hw_deq(ep->xhci, ep->vdev, ep->ep_index, 0); 1156 1166 hw_deq &= ~0xf; 1157 1167 td = list_first_entry(&ep->ring->td_list, struct xhci_td, td_list); 1158 - if (trb_in_td(ep->xhci, td, hw_deq, false)) 1168 + if (trb_in_td(td, hw_deq)) 1159 1169 return td; 1160 1170 } 1161 1171 return NULL; ··· 2790 2800 */ 2791 2801 td = list_first_entry_or_null(&ep_ring->td_list, struct xhci_td, td_list); 2792 2802 2793 - if (td && td->error_mid_td && !trb_in_td(xhci, td, ep_trb_dma, false)) { 2803 + if (td && td->error_mid_td && !trb_in_td(td, ep_trb_dma)) { 2794 2804 xhci_dbg(xhci, "Missing TD completion event after mid TD error\n"); 2795 2805 xhci_dequeue_td(xhci, td, ep_ring, td->status); 2796 2806 } ··· 2823 2833 td_list); 2824 2834 2825 2835 /* Is this a TRB in the currently executing TD? */ 2826 - ep_seg = trb_in_td(xhci, td, ep_trb_dma, false); 2836 + ep_seg = trb_in_td(td, ep_trb_dma); 2827 2837 2828 2838 if (!ep_seg) { 2829 2839 ··· 2883 2893 } 2884 2894 2885 2895 /* HC is busted, give up! */ 2886 - xhci_err(xhci, 2887 - "ERROR Transfer event TRB DMA ptr not part of current TD ep_index %d comp_code %u\n", 2888 - ep_index, trb_comp_code); 2889 - trb_in_td(xhci, td, ep_trb_dma, true); 2890 - 2891 - return -ESHUTDOWN; 2896 + goto debug_finding_td; 2892 2897 } 2893 2898 2894 2899 if (ep->skip) { ··· 2939 2954 xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET); 2940 2955 2941 2956 return 0; 2957 + 2958 + debug_finding_td: 2959 + xhci_err(xhci, "Event dma %pad for ep %d status %d not part of TD at %016llx - %016llx\n", 2960 + &ep_trb_dma, ep_index, trb_comp_code, 2961 + (unsigned long long)xhci_trb_virt_to_dma(td->start_seg, td->start_trb), 2962 + (unsigned long long)xhci_trb_virt_to_dma(td->end_seg, td->end_trb)); 2963 + 2964 + xhci_for_each_ring_seg(ep_ring->first_seg, ep_seg) 2965 + xhci_warn(xhci, "Ring seg %u dma %pad\n", ep_seg->num, &ep_seg->dma); 2966 + 2967 + return -ESHUTDOWN; 2942 2968 2943 2969 err_out: 2944 2970 xhci_err(xhci, "@%016llx %08x %08x %08x %08x\n",