From patchwork Mon Jan 13 14:30:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 857190 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47EDF23ED68 for ; Mon, 13 Jan 2025 14:30:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736778653; cv=none; b=seFRxcnW8Q2r+Ymgk9fvuuUw0qdqnROX6d7v/b6YMJQ1sP/0aGW8/qKvEvfg16nCxKmI7l9OgCLpVQUF/vSP/CTJNf/VCp0pPzgyml6rdcaoB2NxqjAtU4qilBQC18XPaT/ZmzeFp9CtNBwe4SrZOeVQ8cZZlbfLj8P5cl0ptqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736778653; c=relaxed/simple; bh=PhsenPDYqizoyduC5U7ST2uPcvRxvh11YJ/cHk0sTyI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pUjVtEeaB6kVp1czT+0XeHRa/G0gdhIShk1o1YhZPEpS2bPOnxfLJxc+tPnF6USliKPz+2JBKKv5i60kVNSMLFeMpopSCyf+/3qa1ShJvVPjfzmYpGev5KtnYq5B+g1KylQ7OTRdb1QLy/yhZ2Ku4VjweIq5HMeil9nzYgrYBgc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=POjFnyTx; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="POjFnyTx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1736778652; x=1768314652; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PhsenPDYqizoyduC5U7ST2uPcvRxvh11YJ/cHk0sTyI=; b=POjFnyTxT1fNO2MdzXplP/1rpwJbpP8vyGiwLXheUiXJLnj/e6lXBFjr YA7btjq6Gf8U+9IoF0mEtdJ08MSkdTv9588kMwXrQfIFhTzSvnN7TXQDT +nBKBs8iKymR5fq9ZMjgHHoZwLS59U3/6QIxV+XZ4ngj6muJcZNKgmxWQ PTpZUH7FQJg3kvrnvtBI6WMTc1KOMP3BehsZ3G5EdQQZKWb7zSUi94hTl DYEpcIqBAoejH4O9IqiTsJloeVH87B7cOiGriLtSk+mCuJa6Yvj9s0uoc WSjomRrXLssJw9eItRQrF+rumf+TdjBbmsdVnFY7rKAIqVSck6a4HoATo g==; X-CSE-ConnectionGUID: ktIgxDa7SA+BzS44RRJVBw== X-CSE-MsgGUID: u2VEZx3KRk+N1TE50JRL6g== X-IronPort-AV: E=McAfee;i="6700,10204,11314"; a="48458173" X-IronPort-AV: E=Sophos;i="6.12,310,1728975600"; d="scan'208";a="48458173" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2025 06:30:50 -0800 X-CSE-ConnectionGUID: /Sk4EZoATo+k877/1mzxSQ== X-CSE-MsgGUID: t9tUBvRgQRu6eN1rLdFYVQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="141774300" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 13 Jan 2025 06:30:49 -0800 Received: by black.fi.intel.com (Postfix, from userid 1058) id 24F2F478; Mon, 13 Jan 2025 16:30:48 +0200 (EET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: michal.pecio@gmail.com, linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH v2 2/2] usb: xhci: set page size to the xHCI-supported size Date: Mon, 13 Jan 2025 16:30:37 +0200 Message-ID: <20250113143037.2131346-3-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250113143037.2131346-1-niklas.neronin@linux.intel.com> References: <20250113143037.2131346-1-niklas.neronin@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 used page size once, and a warning in case of unexpected value. 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 --- v2: Added handling for invlalid page size register value. 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 66584aafc513..f1243017effa 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_shift; + + page_shift = readl(&xhci->op_regs->page_size) & XHCI_PAGE_SIZE_MASK; + if (!page_shift || page_shift & (page_shift - 1)) { + xhci_warn(xhci, "Invalid page size register = 0x%x\n", page_shift); + /* Fallback to 4K page size, since that's common */ + page_shift = 1; + } + + xhci->page_size = page_shift << 12; + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "HCD page size set to %iK", + xhci->page_size >> 10); +} + int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) { struct xhci_interrupter *ir; @@ -2379,7 +2394,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) dma_addr_t dma; unsigned int val, val2; u64 val_64; - u32 page_size, temp; + u32 temp; int i; INIT_LIST_HEAD(&xhci->cmd_list); @@ -2388,20 +2403,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout); init_completion(&xhci->cmd_ring_stop_completion); - page_size = readl(&xhci->op_regs->page_size); - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "Supported page size register = 0x%x", page_size); - i = ffs(page_size) - 1; - if (i < 16) - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "Supported page size of %iK", (1 << (i+12)) / 1024); - else - xhci_warn(xhci, "WARN: no supported page size\n"); - /* Use 4K pages, since that's common and the minimum the HC supports */ - xhci->page_shift = 12; - xhci->page_size = 1 << xhci->page_shift; - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "HCD page size set to %iK", xhci->page_size / 1024); + xhci_hcd_page_size(xhci); /* * Program the Number of Device Slots Enabled field in the CONFIG diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 4914f0a10cff..238cf54ac59f 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -211,6 +211,9 @@ struct xhci_op_regs { #define CONFIG_CIE (1 << 9) /* bits 10:31 - reserved and should be preserved */ +/* bits 15:0 - HCD page shift bit */ +#define XHCI_PAGE_SIZE_MASK 0xffff + /** * struct xhci_intr_reg - Interrupt Register Set * @irq_pending: IMAN - Interrupt Management Register. Used to enable @@ -1510,10 +1513,7 @@ struct xhci_hcd { u16 max_interrupters; /* imod_interval in ns (I * 250ns) */ u32 imod_interval; - /* 4KB min, 128MB max */ - int page_size; - /* Valid values are 12 to 20, inclusive */ - int page_shift; + u32 page_size; /* MSI-X/MSI vectors */ int nvecs; /* optional clocks */