Skip to content

Commit 68c1f16

Browse files
Epicuriusgregkh
authored andcommitted
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 <[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 55741c7 commit 68c1f16

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

drivers/usb/host/xhci-mem.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
19531953
xhci->interrupters = NULL;
19541954

19551955
xhci->page_size = 0;
1956-
xhci->page_shift = 0;
19571956
xhci->usb2_rhub.bus_state.bus_suspended = 0;
19581957
xhci->usb3_rhub.bus_state.bus_suspended = 0;
19591958
}
@@ -2372,14 +2371,30 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs,
23722371
}
23732372
EXPORT_SYMBOL_GPL(xhci_create_secondary_interrupter);
23742373

2374+
static void xhci_hcd_page_size(struct xhci_hcd *xhci)
2375+
{
2376+
u32 page_size;
2377+
2378+
page_size = readl(&xhci->op_regs->page_size) & XHCI_PAGE_SIZE_MASK;
2379+
if (!is_power_of_2(page_size)) {
2380+
xhci_warn(xhci, "Invalid page size register = 0x%x\n", page_size);
2381+
/* Fallback to 4K page size, since that's common */
2382+
page_size = 1;
2383+
}
2384+
2385+
xhci->page_size = page_size << 12;
2386+
xhci_dbg_trace(xhci, trace_xhci_dbg_init, "HCD page size set to %iK",
2387+
xhci->page_size >> 10);
2388+
}
2389+
23752390
int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
23762391
{
23772392
struct xhci_interrupter *ir;
23782393
struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
23792394
dma_addr_t dma;
23802395
unsigned int val, val2;
23812396
u64 val_64;
2382-
u32 page_size, temp;
2397+
u32 temp;
23832398
int i;
23842399

23852400
INIT_LIST_HEAD(&xhci->cmd_list);
@@ -2388,20 +2403,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
23882403
INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout);
23892404
init_completion(&xhci->cmd_ring_stop_completion);
23902405

2391-
page_size = readl(&xhci->op_regs->page_size);
2392-
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2393-
"Supported page size register = 0x%x", page_size);
2394-
val = ffs(page_size) - 1;
2395-
if (val < 16)
2396-
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2397-
"Supported page size of %iK", (1 << (val + 12)) / 1024);
2398-
else
2399-
xhci_warn(xhci, "WARN: no supported page size\n");
2400-
/* Use 4K pages, since that's common and the minimum the HC supports */
2401-
xhci->page_shift = 12;
2402-
xhci->page_size = 1 << xhci->page_shift;
2403-
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2404-
"HCD page size set to %iK", xhci->page_size / 1024);
2406+
xhci_hcd_page_size(xhci);
24052407

24062408
/*
24072409
* Program the Number of Device Slots Enabled field in the CONFIG

drivers/usb/host/xhci.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ struct xhci_op_regs {
211211
#define CONFIG_CIE (1 << 9)
212212
/* bits 10:31 - reserved and should be preserved */
213213

214+
/* bits 15:0 - HCD page shift bit */
215+
#define XHCI_PAGE_SIZE_MASK 0xffff
216+
214217
/**
215218
* struct xhci_intr_reg - Interrupt Register Set
216219
* @irq_pending: IMAN - Interrupt Management Register. Used to enable
@@ -1514,10 +1517,7 @@ struct xhci_hcd {
15141517
u16 max_interrupters;
15151518
/* imod_interval in ns (I * 250ns) */
15161519
u32 imod_interval;
1517-
/* 4KB min, 128MB max */
1518-
int page_size;
1519-
/* Valid values are 12 to 20, inclusive */
1520-
int page_shift;
1520+
u32 page_size;
15211521
/* MSI-X/MSI vectors */
15221522
int nvecs;
15231523
/* optional clocks */

0 commit comments

Comments
 (0)