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: refactor trb_in_td() to be static

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>

authored by

Niklas Neronin and committed by
Greg Kroah-Hartman
d71cb7d6 68c1f167

+61 -63
+61 -61
drivers/usb/host/xhci-ring.c
··· 278 278 } 279 279 280 280 /* 281 + * If the suspect DMA address is a TRB in this TD, this function returns that 282 + * TRB's segment. Otherwise it returns 0. 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) 286 + { 287 + dma_addr_t start_dma; 288 + dma_addr_t end_seg_dma; 289 + dma_addr_t end_trb_dma; 290 + struct xhci_segment *cur_seg; 291 + 292 + start_dma = xhci_trb_virt_to_dma(td->start_seg, td->start_trb); 293 + cur_seg = td->start_seg; 294 + 295 + do { 296 + if (start_dma == 0) 297 + return NULL; 298 + /* We may get an event for a Link TRB in the middle of a TD */ 299 + end_seg_dma = xhci_trb_virt_to_dma(cur_seg, 300 + &cur_seg->trbs[TRBS_PER_SEGMENT - 1]); 301 + /* If the end TRB isn't in this segment, this is set to 0 */ 302 + end_trb_dma = xhci_trb_virt_to_dma(cur_seg, td->end_trb); 303 + 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 + 313 + if (end_trb_dma > 0) { 314 + /* The end TRB is in this segment, so suspect should be here */ 315 + if (start_dma <= end_trb_dma) { 316 + if (suspect_dma >= start_dma && suspect_dma <= end_trb_dma) 317 + return cur_seg; 318 + } else { 319 + /* Case for one segment with 320 + * a TD wrapped around to the top 321 + */ 322 + if ((suspect_dma >= start_dma && 323 + suspect_dma <= end_seg_dma) || 324 + (suspect_dma >= cur_seg->dma && 325 + suspect_dma <= end_trb_dma)) 326 + return cur_seg; 327 + } 328 + return NULL; 329 + } 330 + /* Might still be somewhere in this segment */ 331 + if (suspect_dma >= start_dma && suspect_dma <= end_seg_dma) 332 + return cur_seg; 333 + 334 + cur_seg = cur_seg->next; 335 + start_dma = xhci_trb_virt_to_dma(cur_seg, &cur_seg->trbs[0]); 336 + } while (cur_seg != td->start_seg); 337 + 338 + return NULL; 339 + } 340 + 341 + /* 281 342 * Return number of free normal TRBs from enqueue to dequeue pointer on ring. 282 343 * Not counting an assumed link TRB at end of each TRBS_PER_SEGMENT sized segment. 283 344 * Only for transfer and command rings where driver is the producer, not for ··· 2138 2077 /* Pass this up to the core */ 2139 2078 usb_hcd_poll_rh_status(hcd); 2140 2079 spin_lock(&xhci->lock); 2141 - } 2142 - 2143 - /* 2144 - * If the suspect DMA address is a TRB in this TD, this function returns that 2145 - * TRB's segment. Otherwise it returns 0. 2146 - */ 2147 - struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, struct xhci_td *td, dma_addr_t suspect_dma, 2148 - bool debug) 2149 - { 2150 - dma_addr_t start_dma; 2151 - dma_addr_t end_seg_dma; 2152 - dma_addr_t end_trb_dma; 2153 - struct xhci_segment *cur_seg; 2154 - 2155 - start_dma = xhci_trb_virt_to_dma(td->start_seg, td->start_trb); 2156 - cur_seg = td->start_seg; 2157 - 2158 - do { 2159 - if (start_dma == 0) 2160 - return NULL; 2161 - /* We may get an event for a Link TRB in the middle of a TD */ 2162 - end_seg_dma = xhci_trb_virt_to_dma(cur_seg, 2163 - &cur_seg->trbs[TRBS_PER_SEGMENT - 1]); 2164 - /* If the end TRB isn't in this segment, this is set to 0 */ 2165 - end_trb_dma = xhci_trb_virt_to_dma(cur_seg, td->end_trb); 2166 - 2167 - if (debug) 2168 - xhci_warn(xhci, 2169 - "Looking for event-dma %016llx trb-start %016llx trb-end %016llx seg-start %016llx seg-end %016llx\n", 2170 - (unsigned long long)suspect_dma, 2171 - (unsigned long long)start_dma, 2172 - (unsigned long long)end_trb_dma, 2173 - (unsigned long long)cur_seg->dma, 2174 - (unsigned long long)end_seg_dma); 2175 - 2176 - if (end_trb_dma > 0) { 2177 - /* The end TRB is in this segment, so suspect should be here */ 2178 - if (start_dma <= end_trb_dma) { 2179 - if (suspect_dma >= start_dma && suspect_dma <= end_trb_dma) 2180 - return cur_seg; 2181 - } else { 2182 - /* Case for one segment with 2183 - * a TD wrapped around to the top 2184 - */ 2185 - if ((suspect_dma >= start_dma && 2186 - suspect_dma <= end_seg_dma) || 2187 - (suspect_dma >= cur_seg->dma && 2188 - suspect_dma <= end_trb_dma)) 2189 - return cur_seg; 2190 - } 2191 - return NULL; 2192 - } else { 2193 - /* Might still be somewhere in this segment */ 2194 - if (suspect_dma >= start_dma && suspect_dma <= end_seg_dma) 2195 - return cur_seg; 2196 - } 2197 - cur_seg = cur_seg->next; 2198 - start_dma = xhci_trb_virt_to_dma(cur_seg, &cur_seg->trbs[0]); 2199 - } while (cur_seg != td->start_seg); 2200 - 2201 - return NULL; 2202 2080 } 2203 2081 2204 2082 static void xhci_clear_hub_tt_buffer(struct xhci_hcd *xhci, struct xhci_td *td,
-2
drivers/usb/host/xhci.h
··· 1884 1884 1885 1885 /* xHCI ring, segment, TRB, and TD functions */ 1886 1886 dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb); 1887 - struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, struct xhci_td *td, 1888 - dma_addr_t suspect_dma, bool debug); 1889 1887 int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); 1890 1888 void xhci_ring_cmd_db(struct xhci_hcd *xhci); 1891 1889 int xhci_queue_slot_control(struct xhci_hcd *xhci, struct xhci_command *cmd,