From patchwork Wed Apr 16 13:45:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 881829 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 2F4871ACECF for ; Wed, 16 Apr 2025 13:46:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811173; cv=none; b=I5CaDZH84MiavHKGgazTSLxE9E6S2H74yrUnGDxsEcOuKhBCPbD+j2SZq7AUiWq9a7xZoorIGKvpeOzcL9ZwffpbQ3692PAMM6RigsplmLF2KPWobAXaRflGwgjEyoy4sKcOMTKibv/nfVul81emxDTWd+aJYGCOBkKWHK55wsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811173; c=relaxed/simple; bh=C20cBz7e2yLMFoIDGNo0fq9xw2QEejAUM1eEgmJWTZ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DHjDh1dpZvt3pLd4YD6OA0yvnsEaYaxvfoUxjxYd/wckIk6eqyd8V/XgsqsVBiD4cXLx3x6wbq0FZSBANrbu5uRCsPbjSM10q/CmJpe7ljLx0cDn2/gdNOV5ZJzimhK6Tie8inUXEzar+4X+HHW+vnDmrtpSkzBKhLVqlftYoHM= 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=URJuTEWM; arc=none smtp.client-ip=198.175.65.20 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="URJuTEWM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744811170; x=1776347170; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C20cBz7e2yLMFoIDGNo0fq9xw2QEejAUM1eEgmJWTZ0=; b=URJuTEWMrexialWz2dZtR4j99vWBNqytJDCwcjKcKH91+Jcdb7WGVB+o LxuznLppc7nieZTfxm5hufDKVf9C0OUMm9YBIspuvgrWetlrA/ilwZJs1 X2ncQS/ql502J2u4a+XBIwoNFay302XVeUZH58aKSXu0Yi8Evrpw2rDsV CKBN06RbSh7Bk0pez1hCGDDrDloZXmzkYkYu7sxOscUJc+rhZr3cqrPyb saoBuLlNG6OrJEn4NOOLcgLYumWxIhRmTUhvIPJhx7IchDGFSBh04a8nk jCZ3RjnkNRGpPju+5aFHoIKGYYL3e4F5OYtw0JvnG/Ti6FIh2pjtD9Hqh w==; X-CSE-ConnectionGUID: eJ63rSVCSliTC3kAG7iACQ== X-CSE-MsgGUID: cvA3GxzVRS26zuXX8SU7oA== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="46074446" X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="46074446" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 06:46:10 -0700 X-CSE-ConnectionGUID: Y9Sb+FhATza+6YGFGObBpw== X-CSE-MsgGUID: a/QbwmHBRIGyEb1ilcBN1A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="135659137" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa005.jf.intel.com with ESMTP; 16 Apr 2025 06:46:10 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 3CC6E260; Wed, 16 Apr 2025 16:46:08 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, sergei.shtylyov@gmail.com, Niklas Neronin Subject: [PATCH v2 01/11] usb: xhci: relocate pre-allocation initialization Date: Wed, 16 Apr 2025 16:45:00 +0300 Message-ID: <20250416134510.2406543-2-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416134510.2406543-1-niklas.neronin@linux.intel.com> References: <20250416134510.2406543-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 Move pre-allocation initialization from xhci_mem_init() to xhci_init(). This change is part of an ongoing effort to separate initialization from allocation within the xhci driver. By doing so, it will enable future patches to re-initialize xhci driver memory without the necessity of fully recreating it. Additionally, compliance mode recovery initialization has been adjusted to only occur after successful memory allocation. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-mem.c | 28 ---------------------------- drivers/usb/host/xhci.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index ed36df46b140..d309e8e9d508 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2380,22 +2380,6 @@ 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 (!is_power_of_2(page_size)) { - xhci_warn(xhci, "Invalid page size register = 0x%x\n", page_size); - /* Fallback to 4K page size, since that's common */ - page_size = 1; - } - - xhci->page_size = page_size << 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; @@ -2404,15 +2388,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) unsigned int val, val2; u64 val_64; u32 temp; - int i; - - INIT_LIST_HEAD(&xhci->cmd_list); - - /* init command timeout work */ - INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout); - init_completion(&xhci->cmd_ring_stop_completion); - - xhci_hcd_page_size(xhci); /* * Program the Number of Device Slots Enabled field in the CONFIG @@ -2524,9 +2499,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) ir->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; - for (i = 0; i < MAX_HC_SLOTS; i++) - xhci->devs[i] = NULL; - if (scratchpad_alloc(xhci, flags)) goto fail; if (xhci_setup_port_arrays(xhci, flags)) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index cfda35004754..ec2e4a2d8af0 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -461,6 +461,21 @@ static int xhci_all_ports_seen_u0(struct xhci_hcd *xhci) return (xhci->port_status_u0 == ((1 << xhci->usb3_rhub.num_ports) - 1)); } +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 (!is_power_of_2(page_size)) { + xhci_warn(xhci, "Invalid page size register = 0x%x\n", page_size); + /* Fallback to 4K page size, since that's common */ + page_size = 1; + } + + xhci->page_size = page_size << 12; + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "HCD page size set to %iK", + xhci->page_size >> 10); +} /* * Initialize memory for HCD and xHC (one-time init). @@ -474,11 +489,18 @@ static int xhci_init(struct usb_hcd *hcd) struct xhci_hcd *xhci = hcd_to_xhci(hcd); int retval; - xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_init"); + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Starting %s", __func__); spin_lock_init(&xhci->lock); + INIT_LIST_HEAD(&xhci->cmd_list); + INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout); + init_completion(&xhci->cmd_ring_stop_completion); + xhci_hcd_page_size(xhci); + memset(xhci->devs, 0, MAX_HC_SLOTS * sizeof(*xhci->devs)); + retval = xhci_mem_init(xhci, GFP_KERNEL); - xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished xhci_init"); + if (retval) + return retval; /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { @@ -486,7 +508,8 @@ static int xhci_init(struct usb_hcd *hcd) compliance_mode_recovery_timer_init(xhci); } - return retval; + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished %s", __func__); + return 0; } /*-------------------------------------------------------------------------*/ From patchwork Wed Apr 16 13:45:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 882254 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 248FF221F16 for ; Wed, 16 Apr 2025 13:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811174; cv=none; b=HwngUFp7HfpO+qpi3rY0vsrfmeDAuXt0aCrTBa4FqFT+dhHe+HcpaADpxJwaVUy5H5hmT95rxqfN+prNpBd6vwloiSya9FUVAWhiNAJGqFMFwLpBJD3cjdgtmYPZ56o1Elf8Qr09qb/8FG9wvBdGYYtQxx6Lo7jz9V3BL0xgUi8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811174; c=relaxed/simple; bh=vKqksaxq1lqFhLE/VEiL3uiUEVcRAT0Iob6kSCJV4G4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n9cSYem9Vc3w5qF3OfnbBnJyjyKau49v7BqNYLRRuZQStuPDfMzeAsHYgBkc2pYma9GZhjlwA+wBBOXtQoclemQLQ3dDlmb+HuT70D2kIHtE7AGXfrvLQQD7rdOdtpcsyyLEjRxYDLYfHy2M6r33b71dxsePebfD+Wa2mTskgos= 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=FF6mBO2A; arc=none smtp.client-ip=198.175.65.20 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="FF6mBO2A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744811172; x=1776347172; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vKqksaxq1lqFhLE/VEiL3uiUEVcRAT0Iob6kSCJV4G4=; b=FF6mBO2AFr3DtUE6+S2HJtQvK89c9Zp7miMwrdPrt5h/OX4nrhdaVDOd VwhZb9szA6F8nIwRvzdRUZYiGhbkeKWliTYmNiZK0H1oGeQfCjfk+HZzi WzXlruRbkCQ0JPjdZ33H2XuCKmY0dDN6RqCSbX7dIan6uIVzhLlxeeiwu xhjzHXN9dtrkk8nSWNN95lo+y600Q7hkX3IIH5e5zVAo7MhmRTKVqIdNl LYYEu+etQBMYKEk6AqzlpIf908h2y8lxqyu8CwEI/jhnCueK0Enczc5yn 0+tXMlX0KFfLBf5jvlkv4LdMn7wl7pgbsi13fOJhdzhN20y0r6b9MpMGJ g==; X-CSE-ConnectionGUID: y1KRrYn6TOmWwoba0pIoyA== X-CSE-MsgGUID: ExPX6FNTQQKnHoNRVOaKHw== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="46074449" X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="46074449" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 06:46:11 -0700 X-CSE-ConnectionGUID: Y13jcE+NTGCxlldh5X9J6w== X-CSE-MsgGUID: EHTx3sGVTtKMKxnpeZYoIw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="135659144" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa005.jf.intel.com with ESMTP; 16 Apr 2025 06:46:11 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 3B4BF715; Wed, 16 Apr 2025 16:46:09 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, sergei.shtylyov@gmail.com, Niklas Neronin Subject: [PATCH v2 02/11] usb: xhci: move device slot enabling register write Date: Wed, 16 Apr 2025 16:45:01 +0300 Message-ID: <20250416134510.2406543-3-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416134510.2406543-1-niklas.neronin@linux.intel.com> References: <20250416134510.2406543-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 Refactor the setting of the Number of Device Slots Enabled field into a separate function, relocating it to xhci_init(). The xHCI driver consistently sets the number of enabled device slots to the maximum value. The new function is named to reflect this behavior. Remove the "// " prefix from trace messages, as it is unnecessary and distracting. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-mem.c | 15 +-------------- drivers/usb/host/xhci.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index d309e8e9d508..dbf0187086db 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2385,23 +2385,10 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) struct xhci_interrupter *ir; struct device *dev = xhci_to_hcd(xhci)->self.sysdev; dma_addr_t dma; - unsigned int val, val2; + unsigned int val; u64 val_64; u32 temp; - /* - * Program the Number of Device Slots Enabled field in the CONFIG - * register with the max value of slots the HC can handle. - */ - val = HCS_MAX_SLOTS(readl(&xhci->cap_regs->hcs_params1)); - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// xHC can handle at most %d device slots.", val); - val2 = readl(&xhci->op_regs->config_reg); - val |= (val2 & ~HCS_SLOTS_MASK); - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Setting Max device slots reg = 0x%x.", val); - writel(val, &xhci->op_regs->config_reg); - /* * xHCI section 5.4.6 - Device Context array must be * "physically contiguous and 64-byte (cache line) aligned". diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index ec2e4a2d8af0..4de51ba851d8 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -477,6 +477,24 @@ static void xhci_hcd_page_size(struct xhci_hcd *xhci) xhci->page_size >> 10); } +static void xhci_enable_max_dev_slots(struct xhci_hcd *xhci) +{ + u32 config_reg; + u32 max_slots; + + max_slots = HCS_MAX_SLOTS(xhci->hcs_params1); + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xHC can handle at most %d device slots", + max_slots); + + config_reg = readl(&xhci->op_regs->config_reg); + config_reg &= ~HCS_SLOTS_MASK; + config_reg |= max_slots; + + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Setting Max device slots reg = 0x%x", + config_reg); + writel(config_reg, &xhci->op_regs->config_reg); +} + /* * Initialize memory for HCD and xHC (one-time init). * @@ -502,6 +520,9 @@ static int xhci_init(struct usb_hcd *hcd) if (retval) return retval; + /* Set the Number of Device Slots Enabled to the maximum supported value */ + xhci_enable_max_dev_slots(xhci); + /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { xhci->quirks |= XHCI_COMP_MODE_QUIRK; From patchwork Wed Apr 16 13:45:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 881828 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 F1C2E221F08 for ; Wed, 16 Apr 2025 13:46:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811175; cv=none; b=DRJ1Rj/37y9WDUh3mhIsQ6IPqe2vBYm616ppE7daGvaLZ5JF34+KWBWIM/jzg2rZyieVNqG642SDyPRPEC6c1eMoj/yjxcbdQkuW86psig2a0ga2IdsBvCSCFK6Btuzkp+kHtOtRr8E8BCnBJaQmqv3kiAqFjgSmFO2oFulX1Yk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811175; c=relaxed/simple; bh=tMqhvHGC+mGP7wO51UlauYDKJnp3Abykw/yyKT5N4bs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mCUwbdtf6dgE9rhJwtJnHE5tLPwPhxfpTF2RvJXGbdoJ67zBTskFo7P523rP+QMAAGrzIY+XUy25fZZ1EWZjlq8TsnUyqZWtrbZosMSArNEc8Hveu1uz61OqKUqQ7amAowAT15o4yrIhjlOaI6G3egFJxajiK5KL0jLxp1yiKZk= 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=dejtS77x; arc=none smtp.client-ip=198.175.65.14 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="dejtS77x" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744811173; x=1776347173; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tMqhvHGC+mGP7wO51UlauYDKJnp3Abykw/yyKT5N4bs=; b=dejtS77xR0K58N++vL4qfLMiOwsPjvLnC8LWrziVNBoR9f8biCyRtsW4 HVLzy1BpVz5p8EWtLQSk4+KnznmASxYHT+gDfj808NCIQgR5WxbkGVok/ S1fjeLj7k+eF3l9oRlOiuviMi1MgSlWT5G5KJ02DdwStIk08FcvARecno gjigtzFAg3fOxAIb4WA0FtYuF1l2w8K9GRPELWrbZ9N502slUHm6jJAiJ olgpjNl8vOssBRZARopsUoA0AzjLqw7Q3UnTwEUg3JN2K3tVZQpOeAtP5 paBFIjhamciFRm0z9N5xsPrSVGrn0NxLFVQssdHN0ZtC1/MShUvQcCJBM Q==; X-CSE-ConnectionGUID: 8nTdwaZGRNirMvJnT3qGJg== X-CSE-MsgGUID: BI7zDBOEQpWc1dCe5rJwUw== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="50168103" X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="50168103" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 06:46:12 -0700 X-CSE-ConnectionGUID: 0EyeKj0fTxGJASmXu+AeOA== X-CSE-MsgGUID: 9QRER1ojTeyMEjdVd7aCbg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="135290228" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa005.fm.intel.com with ESMTP; 16 Apr 2025 06:46:11 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 0732478A; Wed, 16 Apr 2025 16:46:09 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, sergei.shtylyov@gmail.com, Niklas Neronin Subject: [PATCH v2 03/11] usb: xhci: move command ring pointer write Date: Wed, 16 Apr 2025 16:45:02 +0300 Message-ID: <20250416134510.2406543-4-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416134510.2406543-1-niklas.neronin@linux.intel.com> References: <20250416134510.2406543-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 Move command ring pointer write from xhci_mem_init() to xhci_init(), and utilize the xhci_set_cmd_ring_deq() function. The xhci_set_cmd_ring_deq() function is nearly identical to the Command Ring Control register code in xhci_mem_init(). The only notable change is the use of: xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, xhci->cmd_ring->dequeue) instead of: xhci->cmd_ring->first_seg->dma but they are effectively the same in this context. The former represents the exact position of the dequeue pointer, while the latter is the first DMA in the first segment. Before use, the dequeue pointer is at the first DMA in the first segment. The xhci_set_cmd_ring_deq() function is moved without modification, except for (long unsigned long) -> (unsigned long long) due to checkpatch.pl. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-mem.c | 10 ---------- drivers/usb/host/xhci.c | 37 ++++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index dbf0187086db..46156e99bbbe 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2386,7 +2386,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) struct device *dev = xhci_to_hcd(xhci)->self.sysdev; dma_addr_t dma; unsigned int val; - u64 val_64; u32 temp; /* @@ -2449,15 +2448,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) xhci_dbg_trace(xhci, trace_xhci_dbg_init, "First segment DMA is 0x%pad", &xhci->cmd_ring->first_seg->dma); - /* Set the address in the Command Ring Control register */ - val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); - val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | - (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) | - xhci->cmd_ring->cycle_state; - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Setting command ring address to 0x%016llx", val_64); - xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); - /* Reserve one command ring TRB for disabling LPM. * Since the USB core grabs the shared usb_bus bandwidth mutex before * disabling LPM, we only need to reserve one TRB for all devices. diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 4de51ba851d8..92c32a80acae 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -495,6 +495,23 @@ static void xhci_enable_max_dev_slots(struct xhci_hcd *xhci) writel(config_reg, &xhci->op_regs->config_reg); } +static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) +{ + u64 val_64; + + /* step 2: initialize command ring buffer */ + val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); + val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | + (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, + xhci->cmd_ring->dequeue) & + (u64) ~CMD_RING_RSVD_BITS) | + xhci->cmd_ring->cycle_state; + xhci_dbg_trace(xhci, trace_xhci_dbg_init, + "// Setting command ring address to 0x%llx", + (unsigned long long) val_64); + xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); +} + /* * Initialize memory for HCD and xHC (one-time init). * @@ -523,6 +540,9 @@ static int xhci_init(struct usb_hcd *hcd) /* Set the Number of Device Slots Enabled to the maximum supported value */ xhci_enable_max_dev_slots(xhci); + /* Set the address in the Command Ring Control register */ + xhci_set_cmd_ring_deq(xhci); + /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { xhci->quirks |= XHCI_COMP_MODE_QUIRK; @@ -793,23 +813,6 @@ static void xhci_restore_registers(struct xhci_hcd *xhci) } } -static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) -{ - u64 val_64; - - /* step 2: initialize command ring buffer */ - val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); - val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | - (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, - xhci->cmd_ring->dequeue) & - (u64) ~CMD_RING_RSVD_BITS) | - xhci->cmd_ring->cycle_state; - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Setting command ring address to 0x%llx", - (long unsigned long) val_64); - xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); -} - /* * The whole command ring must be cleared to zero when we suspend the host. * From patchwork Wed Apr 16 13:45:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 882252 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 1BDCC2222C2 for ; Wed, 16 Apr 2025 13:46:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811177; cv=none; b=D7SMIvS3FfQ1tO2EeF/X/CumrhaBJSqo7va+SH3w1+GNPgaD2WrjU8zUFB9V7Qp/jStbN3a/FcUee22xjH4AZ3VuOytoNkh6R21DwkATgLfiGrZ4kWKygddQYPhZtkc+UbSKQAYk4mK6Pr+IBgqWDQH9zfocg473nwvwisRWl3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811177; c=relaxed/simple; bh=wJnWSPeCwr/mHgLXXcu8ynzG+SzgG81JVUfuiQwdJQE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C0X4THCBYED3AY41w5ceB0Mg6ltw/0vZWcpO20LSx647ubdFRpWz1qrLMZJ4yr0bb057tW3z92xDsQUMURDHDzk2BnBNhEHeNyaUKdPw/9U/C8xwiBkVkUEVcRhx7gvMT4iV28ckyBKDn8G+zvWALdk/C5v9NlUMX+ZBl2UxH+k= 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=E4jEgs0H; arc=none smtp.client-ip=198.175.65.20 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="E4jEgs0H" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744811175; x=1776347175; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wJnWSPeCwr/mHgLXXcu8ynzG+SzgG81JVUfuiQwdJQE=; b=E4jEgs0HVHeILkVF+dsclMqUTwM1qy1zL3KkzQ1tn+7bupUjG/udT4B9 L9SI6ABa5vay20ze0rFc1MoAKlXbYpX56cNBUatS6IruECuextIcwBudI nGRgFO///MgwEBHtbodjcs9bCK93LIcTpyQlQ9nxoJlSbF053Xg8VYe6C SCX/GPiWMdlGQcnuBFAzp/lFRpH1gk4IIPWwG38+c2/usCdX4xXIJEwpB cc7bztbfbJkvYJs7pqW//y2LvWLVs3lRhiVXiHQrkLw85yGwKxD5EeDvL EZ/LZFe75beAZc2NXFK10VNUu9RdsnWylfDUB5MTeh7PrDGs36WKLozg9 w==; X-CSE-ConnectionGUID: oVSe+Ud3T7W1T5URQ3kqfA== X-CSE-MsgGUID: b0gHmxbLTlmmPsP/eU+W7w== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="46074455" X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="46074455" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 06:46:12 -0700 X-CSE-ConnectionGUID: rpVTDSqsT7OWchjFsG6sJw== X-CSE-MsgGUID: mMrcdi/NTwi/5fwQIV0XGg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="135659158" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa005.jf.intel.com with ESMTP; 16 Apr 2025 06:46:12 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id C9972260; Wed, 16 Apr 2025 16:46:10 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, sergei.shtylyov@gmail.com, Niklas Neronin Subject: [PATCH v2 04/11] usb: xhci: refactor xhci_set_cmd_ring_deq() Date: Wed, 16 Apr 2025 16:45:03 +0300 Message-ID: <20250416134510.2406543-5-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416134510.2406543-1-niklas.neronin@linux.intel.com> References: <20250416134510.2406543-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 Refactor xhci_set_cmd_ring_deq() making the code more understandable by using more descriptive constants and separating operations logically. - Remove 'CMD_RING_RSVD_BITS' the macro is misleading, the reserved bits are 5:4, yet the mask is for bits 5:0. - Introduce masks 'CMD_RING_PTR_MASK' and 'CMD_RING_CYCLE' to clearly define the bits for the Command Ring pointer and Command Ring Cycle. - Simplifying the process of setting the command ring address by separating the DMA address calculation and the Command Ring Control register (crcr) updates. - Remove the "// " prefix from trace messages, as it is unnecessary and distracting. Note: In the current implementation, the cycle bit is not cleared before applying the OR operation. Although this hasn't caused issues so far because the bit is '0' before reaching this function, the bit is now cleared before being set to prevent potential future problems and simplify the process. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci.c | 26 ++++++++++++++------------ drivers/usb/host/xhci.h | 8 ++++---- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 92c32a80acae..d4f3da2c074b 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -497,19 +497,21 @@ static void xhci_enable_max_dev_slots(struct xhci_hcd *xhci) static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) { - u64 val_64; + dma_addr_t deq_dma; + u64 crcr; - /* step 2: initialize command ring buffer */ - val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); - val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | - (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, - xhci->cmd_ring->dequeue) & - (u64) ~CMD_RING_RSVD_BITS) | - xhci->cmd_ring->cycle_state; - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Setting command ring address to 0x%llx", - (unsigned long long) val_64); - xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); + deq_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, xhci->cmd_ring->dequeue); + deq_dma &= CMD_RING_PTR_MASK; + + crcr = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); + crcr &= ~CMD_RING_PTR_MASK; + crcr |= deq_dma; + + crcr &= ~CMD_RING_CYCLE; + crcr |= xhci->cmd_ring->cycle_state; + + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Setting command ring address to 0x%llx", crcr); + xhci_write_64(xhci, crcr, &xhci->op_regs->cmd_ring); } /* diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 7eaabe4f6c87..bfb02dbd9fc7 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -191,16 +191,16 @@ struct xhci_op_regs { #define DEV_NOTE_FWAKE ENABLE_DEV_NOTE(1) /* CRCR - Command Ring Control Register - cmd_ring bitmasks */ -/* bit 0 is the command ring cycle state */ +/* bit 0 - Cycle bit indicates the ownership of the command ring */ +#define CMD_RING_CYCLE (1 << 0) /* stop ring operation after completion of the currently executing command */ #define CMD_RING_PAUSE (1 << 1) /* stop ring immediately - abort the currently executing command */ #define CMD_RING_ABORT (1 << 2) /* true: command ring is running */ #define CMD_RING_RUNNING (1 << 3) -/* bits 4:5 reserved and should be preserved */ -/* Command Ring pointer - bit mask for the lower 32 bits. */ -#define CMD_RING_RSVD_BITS (0x3f) +/* bits 63:6 - Command Ring pointer */ +#define CMD_RING_PTR_MASK GENMASK_ULL(63, 6) /* CONFIG - Configure Register - config_reg bitmasks */ /* bits 0:7 - maximum number of device slots enabled (NumSlotsEn) */ From patchwork Wed Apr 16 13:45:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 881827 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 15B532222C1 for ; Wed, 16 Apr 2025 13:46:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811176; cv=none; b=FjQN5x1klhL8C3GaTqYpi+WE/75GbusCMkGVtumzN9VOjBkAC2Wzi+wtd2nhLixur8ui2pLPwsLg9Xx7SNCBLDygMnaazxxTKVUTLEdPsxXmExGWNcMiNV0uqNZi9KLik3Nia1vrlp77/q8R55EPxQl2n1lqt6oa60GF/3/0K24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811176; c=relaxed/simple; bh=EjeFrOL5eAp0/SdAcdF2XgvSTf4oY3qxoSe+f7PX0x4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=toCsZc6ipsF+RRCZcEpyLxC84gAEKKUAdD2oRR8uSvJ3vIXVHfP+7Sjq31ssgtwqimxLfIFFt/w6jWS6fQe/bG5yRe2IYAD7U9Z/rgZLo2MJNOUUPBkA01o1gmTNMZq9Y4y1lZnmJeZFegWmXaVLGXt5QKZ/3PEeW5+blgIp86k= 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=MFeomQCu; arc=none smtp.client-ip=198.175.65.14 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="MFeomQCu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744811175; x=1776347175; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EjeFrOL5eAp0/SdAcdF2XgvSTf4oY3qxoSe+f7PX0x4=; b=MFeomQCultBLSRymCXeLC2/Xe59D/BKcgZ27rcRQ0051opSxD7fy260v ZJ0HdtD5G7QvSaggiFPHzlEPeRXHEeRD5bUb6aFSGyGBYaaNCuiBtGowE iVx5IwdfEovv02+z6JB1mvkMMXggSU9T1ZAdTUpBgjIIwQ8r6cfE0wEXk KEKClkDArTqCTtPBNxgtv9ZoP46uqCCQE/VWYSRQPzE9UsYq8gGsiNlLq ik8MJVFcJ/j4g8N8jw9os9ZLbkM1qB/wgK7ldjHTBt/2At34QVB4wB3J4 2tqjBhxASm3xL2KPaxogiKkOp9TnTJeNbPDTbPhaiWPNxZQjhj/SQaQmw w==; X-CSE-ConnectionGUID: SiJNWMZmTYSqhHoiavf06g== X-CSE-MsgGUID: 5ySUErX3Rdq7odpF6lZR9Q== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="50168105" X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="50168105" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 06:46:14 -0700 X-CSE-ConnectionGUID: 2juTqg7DRMqq8wRgkv7cvg== X-CSE-MsgGUID: nOXo4LOkSRaU2N/XA8MYCg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="135290234" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa005.fm.intel.com with ESMTP; 16 Apr 2025 06:46:12 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 687CC81D; Wed, 16 Apr 2025 16:46:11 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, sergei.shtylyov@gmail.com, Niklas Neronin Subject: [PATCH v2 05/11] usb: xhci: move DCBAA pointer write Date: Wed, 16 Apr 2025 16:45:04 +0300 Message-ID: <20250416134510.2406543-6-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416134510.2406543-1-niklas.neronin@linux.intel.com> References: <20250416134510.2406543-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 Move the Device Context Base Address Array (DCBAA) pointer write from xhci_mem_init() to xhci_init(). This is part of the ongoing effort to separate allocation and initialization. Signed-off-by: Niklas Neronin --- v2: * Add "Array" to "Set Device Context Base Address pointer" comment. drivers/usb/host/xhci-mem.c | 1 - drivers/usb/host/xhci.c | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 46156e99bbbe..19f756a57cb7 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2400,7 +2400,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Device context base array address = 0x%pad (DMA), %p (virt)", &xhci->dcbaa->dma, xhci->dcbaa); - xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr); /* * Initialize the ring segment pool. The ring must be a contiguous diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index d4f3da2c074b..ef93c1ae5215 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -545,6 +545,9 @@ static int xhci_init(struct usb_hcd *hcd) /* Set the address in the Command Ring Control register */ xhci_set_cmd_ring_deq(xhci); + /* Set Device Context Base Address Array pointer */ + xhci_write_64(xhci, xhci->dcbaa->dma, &xhci->op_regs->dcbaa_ptr); + /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { xhci->quirks |= XHCI_COMP_MODE_QUIRK; From patchwork Wed Apr 16 13:45:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 882253 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 CAD3D2222BC for ; Wed, 16 Apr 2025 13:46:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811176; cv=none; b=WOqifNWFzHO8wyaVeOcFWVi8zUU7kktO+RaczFa9RxScTh9WnkdgvEUnuLktHltF04uBMWoflhhe0+klhBxHQJVpie3f7T+JmaT6NIrwYeuJdxKx6Ola40Lk3UH774b/l9XGdPduM2FR/oGvyQyqVexA4gK+Rb7feBLl6tAnA/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811176; c=relaxed/simple; bh=SpVzuFuhhHYWD7hiQD8LBpIz1PPXCTHuYNotsp919J8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L2y1SyOXel1AMZWZzkJugViux18YTPdNVGhhKSzME6P7XeSCfWPZJks4g62iT+WeX0tlamrn9w4GZKvx6LBS+iediHPnsvuzz8+1Xy+n4oAm/d4FdQ3JV5JrUIHw2tpxJSFkTlvPpYftnQu9k7hALVWIb0ygxbxN2FBfD8L3nLY= 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=F5mDkDVs; arc=none smtp.client-ip=198.175.65.20 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="F5mDkDVs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744811174; x=1776347174; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SpVzuFuhhHYWD7hiQD8LBpIz1PPXCTHuYNotsp919J8=; b=F5mDkDVsJD9CW86Gbafn2mgBAQWiswLWnrjDAZ7vdlRP0453xJLrhUT0 yAv/y5Et/VsGTwXfBneo0+EIGtDtDWkN1abJWu+qQIaqkNCofmKs9K9Sa qJCQuAQQDL6vhbTOEYTICG97BjWYLeyNozoXgu2oiq8OxNENcFZQyZHBx Cb4conSqKGiGuKUsR683LbRg44OUJwMtFxn+Q2cpv5DXLJoiDOTHEep/x bGO7VYYJgXriGInKXeCcyrolFPc2m3HJBBNYMYKZBZeW8b+xaYpzajtD1 VaUxc9dYn8hZybgE7WOb9ADkeZQpLXuk6MgdhOd85PWCnTD4MKbdXG2M6 A==; X-CSE-ConnectionGUID: Q4PyWWQfSnqEbnEV8rVlLg== X-CSE-MsgGUID: EcJEPqedRzSdW8hptdL2Iw== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="46074460" X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="46074460" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 06:46:14 -0700 X-CSE-ConnectionGUID: OoJ8pXYfRsyRd3emSoikmA== X-CSE-MsgGUID: aQMCxdAuRLGL81GKjWx0+A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="135659168" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa005.jf.intel.com with ESMTP; 16 Apr 2025 06:46:14 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 1E136715; Wed, 16 Apr 2025 16:46:12 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, sergei.shtylyov@gmail.com, Niklas Neronin Subject: [PATCH v2 06/11] usb: xhci: move doorbell array pointer assignment Date: Wed, 16 Apr 2025 16:45:05 +0300 Message-ID: <20250416134510.2406543-7-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416134510.2406543-1-niklas.neronin@linux.intel.com> References: <20250416134510.2406543-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 Move the assignment of the doorbell array pointer from xhci_mem_init() to xhci_init(). The assignment now utilizes the newly introduced xhci_set_doorbell_ptr() function. Doorbell Array Offset mask (DBOFF_MASK) is updated to directly specify its bit range as 31:2, rather than using inverted reserved bits 1:0. This change simplifies the mask representation, making it more intuitive and easier to understand. Remove the "// " prefix from trace messages, as it is unnecessary and distracting. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-caps.h | 4 ++-- drivers/usb/host/xhci-mem.c | 8 -------- drivers/usb/host/xhci.c | 13 +++++++++++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/usb/host/xhci-caps.h b/drivers/usb/host/xhci-caps.h index f6b9a00a0ab9..4b8ff4815644 100644 --- a/drivers/usb/host/xhci-caps.h +++ b/drivers/usb/host/xhci-caps.h @@ -62,8 +62,8 @@ #define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32) -/* db_off bitmask - bits 0:1 reserved */ -#define DBOFF_MASK (~0x3) +/* db_off bitmask - bits 31:2 Doorbell Array Offset */ +#define DBOFF_MASK (0xfffffffc) /* run_regs_off bitmask - bits 0:4 reserved */ #define RTSOFF_MASK (~0x1f) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 19f756a57cb7..391dc2282360 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2385,7 +2385,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) struct xhci_interrupter *ir; struct device *dev = xhci_to_hcd(xhci)->self.sysdev; dma_addr_t dma; - unsigned int val; u32 temp; /* @@ -2453,13 +2452,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) */ xhci->cmd_ring_reserved_trbs++; - val = readl(&xhci->cap_regs->db_off); - val &= DBOFF_MASK; - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Doorbell array is located at offset 0x%x from cap regs base addr", - val); - xhci->dba = (void __iomem *) xhci->cap_regs + val; - /* Allocate and set up primary interrupter 0 with an event ring. */ xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Allocating primary event ring"); diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index ef93c1ae5215..00aae0619ccd 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -514,6 +514,16 @@ static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) xhci_write_64(xhci, crcr, &xhci->op_regs->cmd_ring); } +static void xhci_set_doorbell_ptr(struct xhci_hcd *xhci) +{ + u32 offset; + + offset = readl(&xhci->cap_regs->db_off) & DBOFF_MASK; + xhci->dba = (void __iomem *)xhci->cap_regs + offset; + xhci_dbg_trace(xhci, trace_xhci_dbg_init, + "Doorbell array is located at offset 0x%x from cap regs base addr", offset); +} + /* * Initialize memory for HCD and xHC (one-time init). * @@ -548,6 +558,9 @@ static int xhci_init(struct usb_hcd *hcd) /* Set Device Context Base Address Array pointer */ xhci_write_64(xhci, xhci->dcbaa->dma, &xhci->op_regs->dcbaa_ptr); + /* Set Doorbell array pointer */ + xhci_set_doorbell_ptr(xhci); + /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { xhci->quirks |= XHCI_COMP_MODE_QUIRK; From patchwork Wed Apr 16 13:45:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 882251 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 698962222DD for ; Wed, 16 Apr 2025 13:46:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811178; cv=none; b=IVf7G+PSHLVtIa8qVcDMp6JZhe9Ch7QoVrGFyJXjkZWJMPn++L1kLZJWldvhXmfHwKw02PKHtrhXUY80cWZr4nTInUKzg4DABNWZWJ5nZJBYw98mowJyD+P1ABIk8vx1xcbFNfiSClBSoSc6pRIX9Zeb3uMNgs36U/0AaBZHDx4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811178; c=relaxed/simple; bh=HMHrBwIhg4x+Pu1NWtumKmwftkteBGg4w6T8P4FotfU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EQ+djWbKqtkgqyWsyJAhcd4labHEm66zkS+XH7LiSVriCr3YvaIxyIXO8b9ImWJaMvJljonhVlX6ROVLVkPG7oh7T6tNs5WA3lqKtLZgilHexGmhXERXP32WLPZgU2zbtLlez2Rov/4icK3sx4RylDBYsSJy1+3P2N06U0vY2jM= 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=m5LZCwuC; arc=none smtp.client-ip=198.175.65.20 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="m5LZCwuC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744811176; x=1776347176; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HMHrBwIhg4x+Pu1NWtumKmwftkteBGg4w6T8P4FotfU=; b=m5LZCwuCn+F03Wu0F26PU+lKVQ8ZYpDAuFuU/Wk/i7xCWkIs0XGoRD0b DRWNH5ixIsy6l3cFvup7UMaF8ENX+qCi2mDNykxirgze2c6rWJt1d8wHw tBqtwxlpBSzRAbYVRh//gq8genpHEyMNQ1N9i1qMSBe+o974Kp6SXHoji 8/o19O1N3TpnLcFRy5AVbVVEvu0gCTJy941yCj03Brrfr1HybPZ1mECb+ Py3jKsz/O03YizPFJByOyc3hHIcAxsoA1Fueg5DOn4kLP/l1XyOJPb0Nf nhC7dvdjJa83MYFJ64MYttqFKIWEB77kZ8p7VbJK4SAAHGQ95q83/7Qa+ w==; X-CSE-ConnectionGUID: cD8rX60WQL+b5mkFuk0/uw== X-CSE-MsgGUID: QjtC1mMCQ4uY6gURUQ3XWQ== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="46074464" X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="46074464" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 06:46:15 -0700 X-CSE-ConnectionGUID: lzlzodhxSdmKSxsZnjkR1g== X-CSE-MsgGUID: taVICWsgTfS9UBXmlz04pA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="135659173" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa005.jf.intel.com with ESMTP; 16 Apr 2025 06:46:14 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id A5F1578A; Wed, 16 Apr 2025 16:46:12 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, sergei.shtylyov@gmail.com, Niklas Neronin Subject: [PATCH v2 07/11] usb: xhci: move enabling of USB 3 device notifications Date: Wed, 16 Apr 2025 16:45:06 +0300 Message-ID: <20250416134510.2406543-8-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416134510.2406543-1-niklas.neronin@linux.intel.com> References: <20250416134510.2406543-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 Relocated the enabling of USB 3.0 device notifications from xhci_mem_init() to xhci_init(). Introduced xhci_set_dev_notifications() function to handle the notification settings. Simplify 'DEV_NOTE_FWAKE' masks by directly using the 'ENABLE_DEV_NOTE' value (1 << 1) instead of using the 'ENABLE_DEV_NOTE' macro. Macro 'ENABLE_DEV_NOTE' is removed. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-mem.c | 10 ---------- drivers/usb/host/xhci.c | 17 +++++++++++++++++ drivers/usb/host/xhci.h | 3 +-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 391dc2282360..226013ee443a 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2385,7 +2385,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) struct xhci_interrupter *ir; struct device *dev = xhci_to_hcd(xhci)->self.sysdev; dma_addr_t dma; - u32 temp; /* * xHCI section 5.4.6 - Device Context array must be @@ -2472,15 +2471,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) if (xhci_setup_port_arrays(xhci, flags)) goto fail; - /* Enable USB 3.0 device notifications for function remote wake, which - * is necessary for allowing USB 3.0 devices to do remote wakeup from - * U3 (device suspend). - */ - temp = readl(&xhci->op_regs->dev_notification); - temp &= ~DEV_NOTE_MASK; - temp |= DEV_NOTE_FWAKE; - writel(temp, &xhci->op_regs->dev_notification); - return 0; fail: diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 00aae0619ccd..18d8637773cb 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -524,6 +524,20 @@ static void xhci_set_doorbell_ptr(struct xhci_hcd *xhci) "Doorbell array is located at offset 0x%x from cap regs base addr", offset); } +/* + * Enable USB 3.0 device notifications for function remote wake, which is necessary + * for allowing USB 3.0 devices to do remote wakeup from U3 (device suspend). + */ +static void xhci_set_dev_notifications(struct xhci_hcd *xhci) +{ + u32 dev_notf; + + dev_notf = readl(&xhci->op_regs->dev_notification); + dev_notf &= ~DEV_NOTE_MASK; + dev_notf |= DEV_NOTE_FWAKE; + writel(dev_notf, &xhci->op_regs->dev_notification); +} + /* * Initialize memory for HCD and xHC (one-time init). * @@ -561,6 +575,9 @@ static int xhci_init(struct usb_hcd *hcd) /* Set Doorbell array pointer */ xhci_set_doorbell_ptr(xhci); + /* Set USB 3.0 device notifications for function remote wake */ + xhci_set_dev_notifications(xhci); + /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { xhci->quirks |= XHCI_COMP_MODE_QUIRK; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index bfb02dbd9fc7..c05c3eab005b 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -184,11 +184,10 @@ struct xhci_op_regs { * notification type that matches a bit set in this bit field. */ #define DEV_NOTE_MASK (0xffff) -#define ENABLE_DEV_NOTE(x) (1 << (x)) /* Most of the device notification types should only be used for debug. * SW does need to pay attention to function wake notifications. */ -#define DEV_NOTE_FWAKE ENABLE_DEV_NOTE(1) +#define DEV_NOTE_FWAKE (1 << 1) /* CRCR - Command Ring Control Register - cmd_ring bitmasks */ /* bit 0 - Cycle bit indicates the ownership of the command ring */ From patchwork Wed Apr 16 13:45:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 881825 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 A7220222566 for ; Wed, 16 Apr 2025 13:46:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811178; cv=none; b=dn/OPCiHfm/kOvBxe6hZxb5icr9R2t6RQtI44EvR07UFfCKDfU3aYtfh1EdgAQJFuSK/nd9dA2+p+NWoJCGs4PMtScVi97uWWvnAY1mUBsxjqpbNwzsuVE16+JVF5Sd3psK6wCfYoJAdaN7g/MjLwyNLSJ2t332WOw+j/U1WAEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811178; c=relaxed/simple; bh=zLrYJFb+GK+TbyRnoLgeAbEj9plTO60qKVfsRuKziGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kc2FyGp8CF/5PBbIY+lKtEVFqw13Ul1S1eaBAopaa24XyrK3jv8IA71TwlgFMTXzCAu64FX4x7fxcrwbABCtLRPtsTjktlE4onuQNR8/lDEpiBBK9kIiifaeSPZZd/CP9IPwlPtVsJaqrH60w6u+pbysfXDX1Uxi+/zauy2cKxk= 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=VRlDAFHg; arc=none smtp.client-ip=198.175.65.20 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="VRlDAFHg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744811176; x=1776347176; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zLrYJFb+GK+TbyRnoLgeAbEj9plTO60qKVfsRuKziGk=; b=VRlDAFHgczOZjjRaZAut78spqwiqSC+4YOcCDc1kueOCMNWznxssMKy2 usOkhy+oVDzxWz9+e5/SUQZvG5tzelGPzmZ0XSWqdTaTff3T8d5yno9IM jOcQwC8oDNMQ8m5V698HPMRMX7k0xkF343R8+8j087SCZjj0WZCGTE+im Cnp6EcIa+KB2hSrdy8s3UL05NazqyPXVxyrADh6ZT9if0nKubP/3y9gXW 6VjutJGpfQOzaB/JuS/bsSMCncJS5aXwnrFrVfhlKnKo5V7VYcSpfQ0AC gdtv/SWwqjATMLzAwucE9IorGKZorOFXE/bONLQ8d/2DZb6zy1Z4CWQvV A==; X-CSE-ConnectionGUID: 66qh4kTBT4GPNyULsMwenA== X-CSE-MsgGUID: w5occoLGQWyv5ycTDp27ew== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="46074466" X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="46074466" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 06:46:15 -0700 X-CSE-ConnectionGUID: 95OFqUyFRt2f9jCpZO8uJg== X-CSE-MsgGUID: pVSJ/CZwQBiMucnbQ9Xj7Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="135659177" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa005.jf.intel.com with ESMTP; 16 Apr 2025 06:46:14 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 56D78260; Wed, 16 Apr 2025 16:46:13 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, sergei.shtylyov@gmail.com, Niklas Neronin Subject: [PATCH v2 08/11] usb: xhci: remove error handling from xhci_add_interrupter() Date: Wed, 16 Apr 2025 16:45:07 +0300 Message-ID: <20250416134510.2406543-9-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416134510.2406543-1-niklas.neronin@linux.intel.com> References: <20250416134510.2406543-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 Remove redundant error handling from xhci_add_interrupter() instead of trying to accommodate them in future changes. ======== Reasoning for the removal ======== Function xhci_add_interrupter() is invoked in two scenarios: Primary Interrupter Setup (ID 0): The maximum number of interrupters is always greater than zero, and the primary interrupter is always allocated as part of the driver's initialization process. In case of failure, the xHCI driver errors and exits. Secondary Interrupter Creation (ID >= 1): The interrupter is pre-allocated, and an empty slot is identified before invoking xhci_add_interrupter(). In both cases, the existing error handling within xhci_add_interrupter() is redundant and unnecessary. Upcoming Changes: In the subsequent commit, interrupter initialization will move from xhci_mem_init() to xhci_init(). This change is necessary to facilitate the ability to restart the xHCI driver without re-allocating memory. As a result, the allocated interrupter must be stored in the interrupters pointer array before initialization. Consequently, xhci_create_secondary_interrupter() would need to handle pointer removal for allocated 'interrupters' array upon failure, although xhci_add_interrupter() will never fail. Signed-off-by: Niklas Neronin --- v2: * Set 'err' to '0' in case of available interrupt index. Due to rebase. drivers/usb/host/xhci-mem.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 226013ee443a..75ad30d52507 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2287,24 +2287,13 @@ xhci_alloc_interrupter(struct xhci_hcd *xhci, unsigned int segs, gfp_t flags) return ir; } -static int +static void xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir, unsigned int intr_num) { u64 erst_base; u32 erst_size; - if (intr_num >= xhci->max_interrupters) { - xhci_warn(xhci, "Can't add interrupter %d, max interrupters %d\n", - intr_num, xhci->max_interrupters); - return -EINVAL; - } - - if (xhci->interrupters[intr_num]) { - xhci_warn(xhci, "Interrupter %d\n already set up", intr_num); - return -EINVAL; - } - xhci->interrupters[intr_num] = ir; ir->intr_num = intr_num; ir->ir_set = &xhci->run_regs->ir_set[intr_num]; @@ -2325,8 +2314,6 @@ xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir, /* Set the event ring dequeue address of this interrupter */ xhci_set_hc_event_deq(xhci, ir); - - return 0; } struct xhci_interrupter * @@ -2351,13 +2338,16 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs, /* Find available secondary interrupter, interrupter 0 is reserved for primary */ for (i = 1; i < xhci->max_interrupters; i++) { if (!xhci->interrupters[i]) { - err = xhci_add_interrupter(xhci, ir, i); + xhci_add_interrupter(xhci, ir, i); + err = 0; break; } } } else { - if (!xhci->interrupters[intr_num]) - err = xhci_add_interrupter(xhci, ir, intr_num); + if (!xhci->interrupters[intr_num]) { + xhci_add_interrupter(xhci, ir, intr_num); + err = 0; + } } spin_unlock_irq(&xhci->lock); @@ -2461,8 +2451,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) if (!ir) goto fail; - if (xhci_add_interrupter(xhci, ir, 0)) - goto fail; + xhci_add_interrupter(xhci, ir, 0); ir->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; From patchwork Wed Apr 16 13:45:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 881826 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 F06F52222D1 for ; Wed, 16 Apr 2025 13:46:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811177; cv=none; b=Y/EkMGR4hprsjWVncD68fyTPeohRMhS2nH5TY3XidEUadz1KrOC37lR6ADFOnKUcJ9BBw2GYwDkrLJ+Umx8D7jA9Y5TSNbbjtKF3fEfQNUblrX0VFXzz9RfpYdNpz4gOckdwAskj1df6pgcfPD1FTlSA8YkdJxxpCwbKvWbFwTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811177; c=relaxed/simple; bh=tfv9k20NMxxTGkuACHVfh8qjkJ1Shl2CSvwK/I2/aGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pD+RBf/m2RT3x9EUm39p7tYQJzxwEhNef3BOoLDVuUx62KFvTZLwxMD1E7tCVj54WXU3/f2traX5BLLsOjuj7lTVkvdNyiT6EedmNOYj5IPd+biw/EII69R0ig7UL9/Y/I9VgzaLjri8In0DyA1anq/B81stnNcv9Kmrf8bxV0I= 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=JmxOwPFe; arc=none smtp.client-ip=198.175.65.14 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="JmxOwPFe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744811176; x=1776347176; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tfv9k20NMxxTGkuACHVfh8qjkJ1Shl2CSvwK/I2/aGw=; b=JmxOwPFex0HSAGGV/MqmAXw1KaZpnNn2LOW1a1HyJ2eVf+NQHM6ZIDQc PPW3EVrQ8z3VwiJaTJg7SYd6FJEiTMBZFbD+E8nhJGZtLABiP9Dq1aMZt ke+Xr/c6p3dDVFzpR8ojL05CKCxL26OoB1cbMOf75uvO0Y/52prlgvRQs 1RqQBhp/6zZwGqxRwcC4oO/wucCU19Kkhel3EWxh6LnfoOmSpFz7xJ82f ncG3a9lvPjWtgYZsRjlValM3uMB1g0JCj8yq1J/hJWHx2HFCtM/XgRC9t Lzl/r4lnTYNSaIh3i82qOIkjPkNGQkGw2T4tFz12Sa4Hk6cGXyn5x/UEA A==; X-CSE-ConnectionGUID: 6DEJ9NtaR4+vJgWc/txSbQ== X-CSE-MsgGUID: lTcFLeKSQM+1uZKvuhwpVw== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="50168109" X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="50168109" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 06:46:16 -0700 X-CSE-ConnectionGUID: gk+w/gQET2GJKLDvB05eSw== X-CSE-MsgGUID: jRwdgdBWSRSXWTiUYd2rMQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="135290236" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa005.fm.intel.com with ESMTP; 16 Apr 2025 06:46:15 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 0547981D; Wed, 16 Apr 2025 16:46:13 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, sergei.shtylyov@gmail.com, Niklas Neronin Subject: [PATCH v2 09/11] usb: xhci: move initialization of the primary interrupter Date: Wed, 16 Apr 2025 16:45:08 +0300 Message-ID: <20250416134510.2406543-10-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416134510.2406543-1-niklas.neronin@linux.intel.com> References: <20250416134510.2406543-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 Move the primary interrupter (0) initialization from xhci_mem_init() to xhci_init(). This change requires us to save the allocated interrupter somewhere before initialization. Therefore, store it in the 'interrupters' array and rework xhci_add_interrupter() to retrieve the interrupter from the array. This is part of the ongoing effort to separate allocation and initialization. Signed-off-by: Niklas Neronin --- v2: * Add the same logic to specific 'intr_num'. Due to rebase. drivers/usb/host/xhci-mem.c | 22 +++++++++------------- drivers/usb/host/xhci.c | 4 ++++ drivers/usb/host/xhci.h | 1 + 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 75ad30d52507..007536879c24 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2287,14 +2287,13 @@ xhci_alloc_interrupter(struct xhci_hcd *xhci, unsigned int segs, gfp_t flags) return ir; } -static void -xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir, - unsigned int intr_num) +void xhci_add_interrupter(struct xhci_hcd *xhci, unsigned int intr_num) { + struct xhci_interrupter *ir; u64 erst_base; u32 erst_size; - xhci->interrupters[intr_num] = ir; + ir = xhci->interrupters[intr_num]; ir->intr_num = intr_num; ir->ir_set = &xhci->run_regs->ir_set[intr_num]; @@ -2338,14 +2337,16 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs, /* Find available secondary interrupter, interrupter 0 is reserved for primary */ for (i = 1; i < xhci->max_interrupters; i++) { if (!xhci->interrupters[i]) { - xhci_add_interrupter(xhci, ir, i); + xhci->interrupters[i] = ir; + xhci_add_interrupter(xhci, i); err = 0; break; } } } else { if (!xhci->interrupters[intr_num]) { - xhci_add_interrupter(xhci, ir, intr_num); + xhci->interrupters[intr_num] = ir; + xhci_add_interrupter(xhci, intr_num); err = 0; } } @@ -2372,7 +2373,6 @@ EXPORT_SYMBOL_GPL(xhci_create_secondary_interrupter); int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) { - struct xhci_interrupter *ir; struct device *dev = xhci_to_hcd(xhci)->self.sysdev; dma_addr_t dma; @@ -2447,14 +2447,10 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) xhci->interrupters = kcalloc_node(xhci->max_interrupters, sizeof(*xhci->interrupters), flags, dev_to_node(dev)); - ir = xhci_alloc_interrupter(xhci, 0, flags); - if (!ir) + xhci->interrupters[0] = xhci_alloc_interrupter(xhci, 0, flags); + if (!xhci->interrupters[0]) goto fail; - xhci_add_interrupter(xhci, ir, 0); - - ir->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; - if (scratchpad_alloc(xhci, flags)) goto fail; if (xhci_setup_port_arrays(xhci, flags)) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 18d8637773cb..1cc58d10776d 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -578,6 +578,10 @@ static int xhci_init(struct usb_hcd *hcd) /* Set USB 3.0 device notifications for function remote wake */ xhci_set_dev_notifications(xhci); + /* Initialize the Primary interrupter */ + xhci_add_interrupter(xhci, 0); + xhci->interrupters[0]->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; + /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { xhci->quirks |= XHCI_COMP_MODE_QUIRK; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index c05c3eab005b..97da9f2853f3 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1945,6 +1945,7 @@ void xhci_process_cancelled_tds(struct xhci_virt_ep *ep); void xhci_update_erst_dequeue(struct xhci_hcd *xhci, struct xhci_interrupter *ir, bool clear_ehb); +void xhci_add_interrupter(struct xhci_hcd *xhci, unsigned int intr_num); /* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, From patchwork Wed Apr 16 13:45:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 882250 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 7DB36222585 for ; Wed, 16 Apr 2025 13:46:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811179; cv=none; b=jV4Z2qaPFQBY1NkM0C9Wglw8TAkyjP/GGrZyZhY6BkT9C6vRvRdRCEDrgGB4hem2p8wT4+MX4+JOVPLocEKiQVEc1QP8inIl6/9sgjUnth5oqbOCsL2x5nDg5eICpVILT26VR+Nz1TrhepGUDXCzWW20XAq+5EKgZ3EeTeshHZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811179; c=relaxed/simple; bh=1Lz8KKBu9PZJ72w195lWYKl2VTg6lorL3JnsjbcTlZg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cWg/XEES0N5TT1WNRnLweO0LMtDBEqJ5mknECSz30GZRy7WbBNjsoRdb49Vg+k/8x0x5N+7/FkBB4p0pI9eyBtbf8Yq5C1gxholTWBLvLJcxT1ODcP4JMj3KdCW5ph4A6/rgiQfnk0SmDx/G9Kmrk6HwRVKBrCc3N9btN36xSD4= 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=nxutgpwL; arc=none smtp.client-ip=198.175.65.20 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="nxutgpwL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744811177; x=1776347177; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1Lz8KKBu9PZJ72w195lWYKl2VTg6lorL3JnsjbcTlZg=; b=nxutgpwL5axcImEAlT+MeJJGF7M+4zYZi5J5OuelTF02amzFD5V4dMhf mrIgrlrTwnWvRthuqK/3LPaM3K7acwtlMbr6WJxX/Hg8kqx0J2S3ccgIq 1hucqG2jE/zhN6M8a8YhXu54NQbF18sLeWLMTqbz5LNgWs7ykWEN/nb5y teaBgnNbKESWLaqVjQ4isYHN9B9XQU45W5szSA7BedzCgUq55iNdOIc98 /aixkc5f2yiGx24OXZUR3ZmsQexnB6Siq7l4uWzK5V+2fwS1oMZYwraAb ek769wS2tgWaSnWzwrrX2sI/WNTkwp9clPyfzP7w5LydUcvjTtI6B7h2s Q==; X-CSE-ConnectionGUID: 6IBpqr2lRDqNGCAflpVNeg== X-CSE-MsgGUID: J96nuUzyRhy7mGtwHRSZ9g== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="46074469" X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="46074469" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 06:46:16 -0700 X-CSE-ConnectionGUID: qWmfg0cvSOynJnAUiEilkg== X-CSE-MsgGUID: WycA1XraT8yPdAMxNX8rfw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="135659182" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa005.jf.intel.com with ESMTP; 16 Apr 2025 06:46:16 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id A9A66715; Wed, 16 Apr 2025 16:46:14 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, sergei.shtylyov@gmail.com, Niklas Neronin Subject: [PATCH v2 10/11] usb: xhci: add individual allocation checks in xhci_mem_init() Date: Wed, 16 Apr 2025 16:45:09 +0300 Message-ID: <20250416134510.2406543-11-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416134510.2406543-1-niklas.neronin@linux.intel.com> References: <20250416134510.2406543-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 Break up the existing multi-allocation checks into individual checks. Add missing allocation check for 'xhci->interrupters'. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-mem.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 007536879c24..3edb231af199 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2403,11 +2403,13 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) else xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size); + if (!xhci->segment_pool) + goto fail; /* See Table 46 and Note on Figure 55 */ xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev, 2112, 64, xhci->page_size); - if (!xhci->segment_pool || !xhci->device_pool) + if (!xhci->device_pool) goto fail; /* Linear stream context arrays don't have any boundary restrictions, @@ -2416,6 +2418,9 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) xhci->small_streams_pool = dma_pool_create("xHCI 256 byte stream ctx arrays", dev, SMALL_STREAM_ARRAY_SIZE, 16, 0); + if (!xhci->small_streams_pool) + goto fail; + xhci->medium_streams_pool = dma_pool_create("xHCI 1KB stream ctx arrays", dev, MEDIUM_STREAM_ARRAY_SIZE, 16, 0); @@ -2423,7 +2428,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) * will be allocated with dma_alloc_coherent() */ - if (!xhci->small_streams_pool || !xhci->medium_streams_pool) + if (!xhci->medium_streams_pool) goto fail; /* Set up the command ring to have one segments for now. */ @@ -2446,6 +2451,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) "Allocating primary event ring"); xhci->interrupters = kcalloc_node(xhci->max_interrupters, sizeof(*xhci->interrupters), flags, dev_to_node(dev)); + if (!xhci->interrupters) + goto fail; xhci->interrupters[0] = xhci_alloc_interrupter(xhci, 0, flags); if (!xhci->interrupters[0]) From patchwork Wed Apr 16 13:45:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 881824 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 5EDC8223311 for ; Wed, 16 Apr 2025 13:46:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811179; cv=none; b=YyK+qvfPA4FCqUX5An8qjd1dM7e1haGF47z6JFiujFiWRdhLPXn5G+XjYR1sPvUiNeXlMdrRqO2zRMgF9YBk1va5qtdASvBFuLKMeaiKH1fZ7460Qy6pMv/jDgx2zwaE+YM+Fq5t2jXqwvEeLaXdwjjTeUb8zQHhCMexL5Pdl4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744811179; c=relaxed/simple; bh=Ko1i9bR/AX90oO/5GzzEgrmGcrLh31IMN/9kk9InFxE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qD/KeXzYkuUz2blHGa1AAbs+xPQB+p0Y9a0djvFqRFkZOdfuHW2NoXdB+DkyaHC8jVLJEZXTJJLXb/w+uPX2jjJL49Yww/vgDsMlLFVsji9nRpLrAGa85Wj8gSbbgZzDTs/XB6WtS2A+mNSQrpXfizQqmWDFiYJWFqtjk5mspL8= 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=Q1Q7wxzo; arc=none smtp.client-ip=198.175.65.20 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="Q1Q7wxzo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744811178; x=1776347178; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ko1i9bR/AX90oO/5GzzEgrmGcrLh31IMN/9kk9InFxE=; b=Q1Q7wxzoHSdWDiCeZ3uOcTxQMbcD4Uee+1ocxhWXiIg31fF+yN5KuuOd rvZUhjYneCuS42nRA8EhmqpXUkq1fiGhBOsTRON6wJ/wgVrf0mVklbKeI A7hLx7x+mxsG2ibQGOYNK6IpdDGUr/1ySF82biafb7PdyQqOD5Z252lsF TZoxymn9LpquyV7s8KiXc4JMXQcBYmV1TeTj6Jvm+ZDgfzhuXBZUSqv6C GIOkaHcveT9SkjTdmpKz3FAc10TqtR01oUWRybUxLkN2Eb9moOaWxKeAx 2qnz4BkBJQ5tdi0RbLqhwcVWfR9OLvY1zpOEUN+WuRm4rpFwPCnzWgQ4B A==; X-CSE-ConnectionGUID: 8kfr0S75RnyHh0y7f1ysBQ== X-CSE-MsgGUID: KlIjapdqSi+ocNJIymXVJQ== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="46074472" X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="46074472" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2025 06:46:17 -0700 X-CSE-ConnectionGUID: wlkYcjXHTUiWTme1aig0Sg== X-CSE-MsgGUID: 5lFR31FWTJSeAEnpgNN/Ug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,216,1739865600"; d="scan'208";a="135659187" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa005.jf.intel.com with ESMTP; 16 Apr 2025 06:46:16 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 5674578A; Wed, 16 Apr 2025 16:46:15 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, sergei.shtylyov@gmail.com, Niklas Neronin Subject: [PATCH v2 11/11] usb: xhci: cleanup xhci_mem_init() Date: Wed, 16 Apr 2025 16:45:10 +0300 Message-ID: <20250416134510.2406543-12-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250416134510.2406543-1-niklas.neronin@linux.intel.com> References: <20250416134510.2406543-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 Cleanup indentation, spacing and comment formats. Remove the "// " prefix from trace messages, as it is unnecessary and distracting. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-mem.c | 46 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 3edb231af199..8945329e064d 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2380,14 +2380,14 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) * xHCI section 5.4.6 - Device Context array must be * "physically contiguous and 64-byte (cache line) aligned". */ - xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma, - flags); + xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma, flags); if (!xhci->dcbaa) goto fail; + xhci->dcbaa->dma = dma; xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Device context base array address = 0x%pad (DMA), %p (virt)", - &xhci->dcbaa->dma, xhci->dcbaa); + "Device context base array address = 0x%pad (DMA), %p (virt)", + &xhci->dcbaa->dma, xhci->dcbaa); /* * Initialize the ring segment pool. The ring must be a contiguous @@ -2407,27 +2407,26 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) goto fail; /* See Table 46 and Note on Figure 55 */ - xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev, - 2112, 64, xhci->page_size); + xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev, 2112, 64, + xhci->page_size); if (!xhci->device_pool) goto fail; - /* Linear stream context arrays don't have any boundary restrictions, + /* + * Linear stream context arrays don't have any boundary restrictions, * and only need to be 16-byte aligned. */ - xhci->small_streams_pool = - dma_pool_create("xHCI 256 byte stream ctx arrays", - dev, SMALL_STREAM_ARRAY_SIZE, 16, 0); + xhci->small_streams_pool = dma_pool_create("xHCI 256 byte stream ctx arrays", + dev, SMALL_STREAM_ARRAY_SIZE, 16, 0); if (!xhci->small_streams_pool) goto fail; - xhci->medium_streams_pool = - dma_pool_create("xHCI 1KB stream ctx arrays", - dev, MEDIUM_STREAM_ARRAY_SIZE, 16, 0); - /* Any stream context array bigger than MEDIUM_STREAM_ARRAY_SIZE - * will be allocated with dma_alloc_coherent() + /* + * Any stream context array bigger than MEDIUM_STREAM_ARRAY_SIZE will be + * allocated with dma_alloc_coherent(). */ - + xhci->medium_streams_pool = dma_pool_create("xHCI 1KB stream ctx arrays", + dev, MEDIUM_STREAM_ARRAY_SIZE, 16, 0); if (!xhci->medium_streams_pool) goto fail; @@ -2435,20 +2434,20 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) xhci->cmd_ring = xhci_ring_alloc(xhci, 1, TYPE_COMMAND, 0, flags); if (!xhci->cmd_ring) goto fail; - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "Allocated command ring at %p", xhci->cmd_ring); - xhci_dbg_trace(xhci, trace_xhci_dbg_init, "First segment DMA is 0x%pad", - &xhci->cmd_ring->first_seg->dma); - /* Reserve one command ring TRB for disabling LPM. + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Allocated command ring at %p", xhci->cmd_ring); + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "First segment DMA is 0x%pad", + &xhci->cmd_ring->first_seg->dma); + + /* + * Reserve one command ring TRB for disabling LPM. * Since the USB core grabs the shared usb_bus bandwidth mutex before * disabling LPM, we only need to reserve one TRB for all devices. */ xhci->cmd_ring_reserved_trbs++; /* Allocate and set up primary interrupter 0 with an event ring. */ - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "Allocating primary event ring"); + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Allocating primary event ring"); xhci->interrupters = kcalloc_node(xhci->max_interrupters, sizeof(*xhci->interrupters), flags, dev_to_node(dev)); if (!xhci->interrupters) @@ -2460,6 +2459,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) if (scratchpad_alloc(xhci, flags)) goto fail; + if (xhci_setup_port_arrays(xhci, flags)) goto fail;