Re: [PATCH v3 2/2] usb: xhci: set page size to the xHCI-supported size

Mathias Nyman
2025-02-04T16:06:07Z

On 4.2.2025 14.41, Niklas Neronin wrote:
> 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>
> ---
> V3:
> * Rename local variable 'page_shift' to 'page_size'.
>
> drivers/usb/host/xhci-mem.c | 34 ++++++++++++++++++----------------
> drivers/usb/host/xhci.h | 8 ++++----
> 2 files changed, 22 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> index dc5bcd8db4c0..c2ee0d32f5cd 100644
> --- a/drivers/usb/host/xhci-mem.c
> +++ b/drivers/usb/host/xhci-mem.c
> @@ -1953,7 +1953,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
> xhci->interrupters = NULL;
>
> xhci->page_size = 0;
> - xhci->page_shift = 0;
> xhci->usb2_rhub.bus_state.bus_suspended = 0;
> xhci->usb3_rhub.bus_state.bus_suspended = 0;
> }
> @@ -2372,6 +2371,22 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs,
> }
> EXPORT_SYMBOL_GPL(xhci_create_secondary_interrupter);
>
> +static void xhci_hcd_page_size(struct xhci_hcd *xhci)
> +{
> + u32 page_size;
> +
> + page_size = readl(&xhci->op_regs->page_size) & XHCI_PAGE_SIZE_MASK;
> + if (!page_size || page_size & (page_size - 1)) {

is_power_of_2(page_size) does the same, and is easier to understand

-Mathias