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: set page size to the xHCI-supported size

The current xHCI driver does not validate whether a page size of 4096
bytes is supported. Address the issue by setting the page size to the
value supported by the xHCI controller, as read from the Page Size
register. In the event of an unexpected value; default to a 4K page size.

Additionally, this commit removes unnecessary debug messages and instead
prints the supported and used page size once.

The xHCI controller supports page sizes of (2^{(n+12)}) bytes, where 'n'
is the Page Size Bit. Only one page size is supported, with a maximum
page size of 128 KB.

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-10-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Niklas Neronin and committed by
Greg Kroah-Hartman
68c1f167 55741c72

+22 -20
+18 -16
drivers/usb/host/xhci-mem.c
··· 1953 1953 xhci->interrupters = NULL; 1954 1954 1955 1955 xhci->page_size = 0; 1956 - xhci->page_shift = 0; 1957 1956 xhci->usb2_rhub.bus_state.bus_suspended = 0; 1958 1957 xhci->usb3_rhub.bus_state.bus_suspended = 0; 1959 1958 } ··· 2371 2372 } 2372 2373 EXPORT_SYMBOL_GPL(xhci_create_secondary_interrupter); 2373 2374 2375 + static void xhci_hcd_page_size(struct xhci_hcd *xhci) 2376 + { 2377 + u32 page_size; 2378 + 2379 + page_size = readl(&xhci->op_regs->page_size) & XHCI_PAGE_SIZE_MASK; 2380 + if (!is_power_of_2(page_size)) { 2381 + xhci_warn(xhci, "Invalid page size register = 0x%x\n", page_size); 2382 + /* Fallback to 4K page size, since that's common */ 2383 + page_size = 1; 2384 + } 2385 + 2386 + xhci->page_size = page_size << 12; 2387 + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "HCD page size set to %iK", 2388 + xhci->page_size >> 10); 2389 + } 2390 + 2374 2391 int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) 2375 2392 { 2376 2393 struct xhci_interrupter *ir; ··· 2394 2379 dma_addr_t dma; 2395 2380 unsigned int val, val2; 2396 2381 u64 val_64; 2397 - u32 page_size, temp; 2382 + u32 temp; 2398 2383 int i; 2399 2384 2400 2385 INIT_LIST_HEAD(&xhci->cmd_list); ··· 2403 2388 INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout); 2404 2389 init_completion(&xhci->cmd_ring_stop_completion); 2405 2390 2406 - page_size = readl(&xhci->op_regs->page_size); 2407 - xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2408 - "Supported page size register = 0x%x", page_size); 2409 - val = ffs(page_size) - 1; 2410 - if (val < 16) 2411 - xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2412 - "Supported page size of %iK", (1 << (val + 12)) / 1024); 2413 - else 2414 - xhci_warn(xhci, "WARN: no supported page size\n"); 2415 - /* Use 4K pages, since that's common and the minimum the HC supports */ 2416 - xhci->page_shift = 12; 2417 - xhci->page_size = 1 << xhci->page_shift; 2418 - xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2419 - "HCD page size set to %iK", xhci->page_size / 1024); 2391 + xhci_hcd_page_size(xhci); 2420 2392 2421 2393 /* 2422 2394 * Program the Number of Device Slots Enabled field in the CONFIG
+4 -4
drivers/usb/host/xhci.h
··· 211 211 #define CONFIG_CIE (1 << 9) 212 212 /* bits 10:31 - reserved and should be preserved */ 213 213 214 + /* bits 15:0 - HCD page shift bit */ 215 + #define XHCI_PAGE_SIZE_MASK 0xffff 216 + 214 217 /** 215 218 * struct xhci_intr_reg - Interrupt Register Set 216 219 * @irq_pending: IMAN - Interrupt Management Register. Used to enable ··· 1517 1514 u16 max_interrupters; 1518 1515 /* imod_interval in ns (I * 250ns) */ 1519 1516 u32 imod_interval; 1520 - /* 4KB min, 128MB max */ 1521 - int page_size; 1522 - /* Valid values are 12 to 20, inclusive */ 1523 - int page_shift; 1517 + u32 page_size; 1524 1518 /* MSI-X/MSI vectors */ 1525 1519 int nvecs; 1526 1520 /* optional clocks */