From patchwork Fri Apr 11 09:11:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 14047886 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 2DED027CB39 for ; Fri, 11 Apr 2025 09:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362759; cv=none; b=qEOmHV5JpKldf5osQmb8vuhBiVbdGutILW1fjnC3w2e4e5jOMVlwwEKAt2pQJWvpFEEn2Ddo6owmDXRLaLgopX/NsflvoR2sWC8t5HpC9/u4iEjojuwVPq/4utNZygAHFhNK00HlImhvZFFAm+8jj1y0B6Dgr06OGWh5LPXWVkU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362759; c=relaxed/simple; bh=8HSgT548SJtyjGc/dP+XJalXIk45cGYogs5L6Q5PJFo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gmc+mWyxokAHML7xxpT18ZPiuDD2ayyNzpGu3Sn/cDkBxhjNS/6PNRbWdV6XuhDo4kO7RSV6z6s/0GdUnbZpAWDttDXSSFwLAjhEeL/Sb4rrgujgf4wfV+5LndlrdYHIndRg4dRDj9EMuik24plDMlvuQ+xPXIpx0WNG6Y3UHxw= 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=lsxwGrn9; arc=none smtp.client-ip=192.198.163.13 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="lsxwGrn9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744362758; x=1775898758; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8HSgT548SJtyjGc/dP+XJalXIk45cGYogs5L6Q5PJFo=; b=lsxwGrn97ddGVKrygqTfYoUMFDoXDIdK1/UpW7RM8ZqoeXlgDLqtEzKu sGYJti9kgdgW7fzlojeuAy2ivXuIystIdivHHm6XEnrVCVOKBdLE9zPwN X6QdZvXosiDXB+uuwDYHcgWZHoN4xBRPMfqPMmA1FrjtvdwTmh/aEBFKl uVK9WVQMqg9TlJDXwS59HLP05KDWBxqSIlNbgXzIwB0830W7yfxhvafLh 7zHMaXelkajH9sbYGkEHYDOQDNtcuPjU/Y2IKN9T4cvUiDdDSKX/qdlwX mwANSjcMJ0Lq8h7ox5PZSjooqCLQhsrx4DL/oU1FUPXX1JxzFXfesCWjz w==; X-CSE-ConnectionGUID: rWi2GA/0QrCfIljfNdpZpw== X-CSE-MsgGUID: zuYD6yIbQ2arWodaCB6/aA== X-IronPort-AV: E=McAfee;i="6700,10204,11400"; a="48617948" X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="48617948" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2025 02:12:37 -0700 X-CSE-ConnectionGUID: /IymIXf9RieVwqOuu14cag== X-CSE-MsgGUID: Catcd6o6RD2rPQ6sPA8Vrw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="166335666" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 11 Apr 2025 02:12:37 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 1A64E78B; Fri, 11 Apr 2025 12:12:35 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 01/11] usb: xhci: relocate pre-allocation initialization Date: Fri, 11 Apr 2025 12:11:45 +0300 Message-ID: <20250411091155.3386971-2-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250411091155.3386971-1-niklas.neronin@linux.intel.com> References: <20250411091155.3386971-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 d698095fc88d..eb07445687bb 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2371,22 +2371,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; @@ -2395,15 +2379,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 @@ -2515,9 +2490,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 0452b8d65832..abc5115a2839 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -460,6 +460,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). @@ -473,11 +488,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()) { @@ -485,7 +507,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 Fri Apr 11 09:11:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 14047887 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 EC4841C5F09 for ; Fri, 11 Apr 2025 09:12:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362773; cv=none; b=igxvUu2y51OpLPSilm5qDs4z2U4ounccZ5KsFi8+1nIjlOYmEHQ7bE4dz9srRSl/0AKe40W0aM4ofdiemspbQNIHBtlIcslRsK53Ai31NQRg9VZpZAHl/kDQyn1Anl3Ii6sNF2+g0InO/mwU0DcSm6xwVycgJrVoULGdnYCnt7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362773; c=relaxed/simple; bh=OhPnpowHE7D5rebclwYiIVH7ahH+eDMDc4a937snweA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ag4ajSHILzgm7Qcfjz1EWhAYG+WTom1NdcWzu8Ww/4lP7e5ZfUf2LBMeopq1O8WH93mWIzySPrP1JvX5+Jtdelh19WDBbMNGtSS8WtLhv2uSqjPacQUOHhNZBAP6JW2DXXVKR11lRK3U56FYrEuOBV0sqY05+KKkJPmJJjOr9rQ= 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=fE4vHTbF; arc=none smtp.client-ip=198.175.65.19 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="fE4vHTbF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744362772; x=1775898772; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OhPnpowHE7D5rebclwYiIVH7ahH+eDMDc4a937snweA=; b=fE4vHTbFWnysq57weMB4Mi/0TV8ZWKv3n98cGy/lfW4sqVcPVjoGiyzS WM7pcwsC6Wno7vmTZoLxhNiKxRzTfKQUnYZXIex+daeupUiJPrzFuZMh+ qVjBDSYGF1m1WSLuo45MLsXoTY9CgGAb5UiIpnvpRI9/3f+FFVYMlUyyr /0YKfYA2jWcQDgHEqVwU/QsGv7oO7n6tTLJz3cuHHfLBQKk3CU4HI2vVd piOZYjNZnAlwgKvTjUt8XLE3+ha8vN5pBzBEllFyX8xkX0DtBaMZPZe58 B5lPb2zdU2+aoqviGy/5RBzwXCU73gFW7uaTLSMlm03X2En7lOFh/zA0H g==; X-CSE-ConnectionGUID: 089Qnj6uTdu2AJLKBeJzEw== X-CSE-MsgGUID: E6B/bIhyQb2ugGt3nr+Eeg== X-IronPort-AV: E=McAfee;i="6700,10204,11400"; a="45798945" X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="45798945" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2025 02:12:51 -0700 X-CSE-ConnectionGUID: dFkEt5jWSOi0EU2ngEZqVw== X-CSE-MsgGUID: el6gu9QJTA2MP771qvDMrg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="134008505" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 11 Apr 2025 02:12:51 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 0FE5357F; Fri, 11 Apr 2025 12:12:48 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 02/11] usb: xhci: move device slot enabling register write Date: Fri, 11 Apr 2025 12:11:46 +0300 Message-ID: <20250411091155.3386971-3-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250411091155.3386971-1-niklas.neronin@linux.intel.com> References: <20250411091155.3386971-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 eb07445687bb..5086d6108d3e 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2376,23 +2376,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 abc5115a2839..1e4850542a2e 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -476,6 +476,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). * @@ -501,6 +519,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 Fri Apr 11 09:11:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 14047888 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 68CC5298981 for ; Fri, 11 Apr 2025 09:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362775; cv=none; b=dOJmCydz8/ZIV1wUwrqDaUDH7J86shR/lGCYQUznclT7JH/O0Tw47uXBDeMp7kS3iW5qTN5PwvGkIe5tVYowIBiCgVOMStwVq/R3YKvRjAiL/qMpEE5iH3okqv4EdQDt3aEMDb24+1lX5MXjau5qjp9sZebiHUSb3xHA62BazTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362775; c=relaxed/simple; bh=BYCDvvDLIUyHq/FI86zXrAuIh1pVjoLyzqFItbyHmPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y2a1b6x2KwHMEz8BAiXcDcDgdpksFMKlx9GFw8zHrVWgQkwqLiet7+XhdxXcH1TNv8Zs2WxLrqhJ4TKpNL6E7n0HGVmzsTaYnVVoZ0f83yTwoM1aSfAk3SxPSniFDCzJErBFJAguXZfymhZUiPdrQDBdWOuRJuGy5wxjYH9M8xc= 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=HOU2bS36; arc=none smtp.client-ip=198.175.65.19 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="HOU2bS36" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744362774; x=1775898774; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BYCDvvDLIUyHq/FI86zXrAuIh1pVjoLyzqFItbyHmPg=; b=HOU2bS36PsjNUlvZuPltDEYvF6W9ILGz8dwNB+FFu0oucpSuCJHXZi9N uk+45li73kDlWYvHIyKIXVT5HWcD2y7x2XeX18z8OpZwJPfHeG+UKeVh8 m7R3APTEiYtjdKNQ10jx3HoCNfykTQ+6riYwhVrv/Vb994NeplLle9nkx jqGduGxSrBKuBuqtkg5/agLo4uYGl/rx8UaHyvo8l5S1cRPCzG2LcmqvV hfkpHZXiWtJbkYrJDaGU8O7/hflCohcUeM33XrLem8AVS93bc41XkplZH lKg3AnGQLy4d7s14KLzRwypR+SKzkyiBoaTjyc0zKIcNAk06muK7Pz40m A==; X-CSE-ConnectionGUID: +AZ6VUnJQIyTWxQYf2uLrA== X-CSE-MsgGUID: g6rkZUXtTcOX5Bw0dkyMOQ== X-IronPort-AV: E=McAfee;i="6700,10204,11400"; a="45798946" X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="45798946" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2025 02:12:53 -0700 X-CSE-ConnectionGUID: D9XvQ6LgRh+NDaaMnFDw7g== X-CSE-MsgGUID: 90+JmPjHRT+uY9BvIzjJdg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="134008545" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 11 Apr 2025 02:12:52 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id DD8F078B; Fri, 11 Apr 2025 12:12:50 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 03/11] usb: xhci: move command ring pointer write Date: Fri, 11 Apr 2025 12:11:47 +0300 Message-ID: <20250411091155.3386971-4-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250411091155.3386971-1-niklas.neronin@linux.intel.com> References: <20250411091155.3386971-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 5086d6108d3e..47b804aa328d 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2377,7 +2377,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; /* @@ -2440,15 +2439,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 1e4850542a2e..278bd32d7b55 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -494,6 +494,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). * @@ -522,6 +539,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; @@ -792,23 +812,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 Fri Apr 11 09:11:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 14047889 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 EBC442989A2 for ; Fri, 11 Apr 2025 09:12:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362776; cv=none; b=ok5K8GgT7ZPbkJP/dAqS9iMNC+Cuut5wfWkb+/UBb3OKrPWMkQDli8qrPOrBoA/EU3RFamNYfRawGyytiRyNs3fxW/DCnpqI2+VQC79RCqqXkhbik0DowSnF0T9RgJ68RjqMMfBAA/Sjq45Yqtvf3f+wSDKLiR7zoEyhuPHAJPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362776; c=relaxed/simple; bh=2R+0L8t6kb8FM2xzPGLJqpSfjRKBwkFrAGU5ZdntspI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HQqc3mGjOQC+c0Fg2m28KnQWZmoPpPFxOoOu6R9XlWkZXhuhnGHKBaQzOdwn/DQeCwQsPO8oyy4NT/jHS9b+jyPIIQf0t/pR4+Wu00dOgT78GSjD9uG90A9JTg0nlvvxtShKZ0gtUEPLMz0+LskcXhs7H7ItMKW/imyqmJSFDGM= 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=XbiraLEO; arc=none smtp.client-ip=198.175.65.19 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="XbiraLEO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744362775; x=1775898775; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2R+0L8t6kb8FM2xzPGLJqpSfjRKBwkFrAGU5ZdntspI=; b=XbiraLEOC66bgQ/ELVL23xG5v7cj5Faa2MXCkOmCbbXMn4/TMcsQUPQB BUCJNX2+P3kC3/yarA5tMteMNk4CIFgxoGi34CIbS7Yi9VzYH3+UkeUa1 mMxEUOwdEPWeR8bGi+ss3ltW2X/c9n2ScGGY4nFwhpDXveNYcYHMTznLi o343hSlg95U/y7UOn+8osETD7OA0k2ODjD/3Fr6+/rlUAs7/SIBavzBlM OBuvqlIwIeR3fSqOf7xqS+qkDEs1vOIFE4Bi/DQTXkYizp6xW9c8V9DY7 QDR/xWPHClJ2BFFIdz7+pi3W9Db0I1LMWn4wPKcpsHGSxKTpCTKEVaTp5 Q==; X-CSE-ConnectionGUID: pOgyEw1WR2+pOWAbR6JNag== X-CSE-MsgGUID: RuFWBHAeTrC7CWbMHuZk3g== X-IronPort-AV: E=McAfee;i="6700,10204,11400"; a="45798949" X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="45798949" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2025 02:12:55 -0700 X-CSE-ConnectionGUID: 2Sit9EzeSX2D85LOXEehjw== X-CSE-MsgGUID: 4Z+4tK0wTE+Ms/hI+ApBXQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="134008607" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 11 Apr 2025 02:12:54 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id BF7E357F; Fri, 11 Apr 2025 12:12:52 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 04/11] usb: xhci: refactor xhci_set_cmd_ring_deq() Date: Fri, 11 Apr 2025 12:11:48 +0300 Message-ID: <20250411091155.3386971-5-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250411091155.3386971-1-niklas.neronin@linux.intel.com> References: <20250411091155.3386971-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 278bd32d7b55..5f630e74b323 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -496,19 +496,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 37860f1e3aba..38058006f79b 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 Fri Apr 11 09:11:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 14047890 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 0AD312989B1 for ; Fri, 11 Apr 2025 09:12:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362777; cv=none; b=k6+Oxmm69RIOuHqoVMaflnvGhWhwgpHiieaEDzbN3kmUXVrJL4YL+hztWzQPH0TkgMBgIhx519VLDo+g7Gq86c2xr4RqZ+OZgSPjqHEgkSX2fIai27n7KFtba2Qk2G8E28TJiMei9AwE3edQAc47yR3NZ243qXurYfaIfSBnnYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362777; c=relaxed/simple; bh=kOZZ8kyvXReJEhVz31UF8zyLlyzuXgYE006SAQVR8eA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QQbgZoGSLsntJI/c+j2/bij1sVmQZVRPYf3NEcfmp+eB/cvh27lgKV83h2WDfsgmzmfmQ6jo9b825NRXKHPGYIBZ3j0wY5lupPXz4bjnskhQxeVEYNoiyHyq5OUCk8CSSb4/sWuNZldZOiAcTo2zCHAtTOiogOfY4Kwgrv6xawg= 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=busm01bW; arc=none smtp.client-ip=198.175.65.19 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="busm01bW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744362776; x=1775898776; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kOZZ8kyvXReJEhVz31UF8zyLlyzuXgYE006SAQVR8eA=; b=busm01bWVBWHlMW+evwLIV/mil0ExUrH3j3JRtvq209TI6VQaWOMchye 7C++/iMIrL/LS21/qz/2GJe4FEBdOEallO/ZSlOs/wCSzeqEw5pYH0kv+ bOR0oacMf0Pv8IlA49KeCFescRWgpjSJ4YTD1YnyEcq5GAY1rA25y1/nZ H97I0+KuFFV0FLYTuN6wyTBrPPdFUdXDYoLpdPkb6EAzXQz3k0v8+iWIp UU797+X6+uZfD7MGI+jbwrYYGr2JUi4cJx5wMNYR2QI24AKnf6bsDsYGW BLLoO+UYVC8H2v9avZdhe59AE3J1xiabyerB8ZEcmIejfm4pNvkrkZRZy g==; X-CSE-ConnectionGUID: eXS/W02PQvqjvbcG/bC9Eg== X-CSE-MsgGUID: NDqth6uWQ5uHI/E0j9nKdw== X-IronPort-AV: E=McAfee;i="6700,10204,11400"; a="45798950" X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="45798950" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2025 02:12:56 -0700 X-CSE-ConnectionGUID: cCSDhHqpQyqqRMuAkPRf+w== X-CSE-MsgGUID: 2VPPjhyER/2VEjLr46BHJw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="134008632" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 11 Apr 2025 02:12:55 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id D9A8578B; Fri, 11 Apr 2025 12:12:53 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 05/11] usb: xhci: move DCBAA pointer write Date: Fri, 11 Apr 2025 12:11:49 +0300 Message-ID: <20250411091155.3386971-6-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250411091155.3386971-1-niklas.neronin@linux.intel.com> References: <20250411091155.3386971-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 --- 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 47b804aa328d..4e6289d9a89a 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2391,7 +2391,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 5f630e74b323..431c922b3f2d 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -544,6 +544,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 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 Fri Apr 11 09:11:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 14047891 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 E52EE29899B for ; Fri, 11 Apr 2025 09:12:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362778; cv=none; b=NZUwb5S5NcZ3GPgZ11uv9NrfT4XhvLceBohEDlJP1LWRTW3NNmwrAGKuGIR8GvlkU8pNhPgIW9VpyUK/J3RLCAO1hnD+rMYvGVWqvKPfJB9N6xJcdcb31yOReKHf9y40I4eWtSnBZ3VYRVslKHIirDuILiWmxpw9u6Nm2698ADU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362778; c=relaxed/simple; bh=reKwCvZKTUUhdeikCJyBd0C1N9/axccVxpC2XNP93E4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UNliGNZmdeEGyX3WVoc6caQS3lITXm7slaxYFBt62X22EzHS7A3a1nKC7qW7e7ZCvuB/UexWGiSZs4b7eMpdKx0r3gEQAjyaZtQaNlMZt0OqfA70ogt1GVoKHF197012rnLptcvpIh5+0VdvWhxcxFL/Eahr/WB6i+7LSBIOF2c= 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=G6lQuKhx; arc=none smtp.client-ip=198.175.65.19 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="G6lQuKhx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744362777; x=1775898777; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=reKwCvZKTUUhdeikCJyBd0C1N9/axccVxpC2XNP93E4=; b=G6lQuKhx6eg9+vYRqdtzdMXiS0ImwDUVaY/XsdzFhuwKOBRq3hX/rnvM 2iRRVlBj+dNAKlRd5XSpWBesaSm2674vr/PqTHGOGShrg0GX7waQ4/sP2 DkHJ8y9t6Ehi8YfFCsx2r+nxpapA49GYMf/DB0ShxX5YTywAQBotTPgym sZOMGVLSsLFyUnwOET2a8QfJbHP2BWQ6B/IltQ5f8Kzw1yzLGUtJ2g11B 2vslv0vZ8ei4nARO9KPSqbXbgObJgu+kvoEVCMITl20pW/N1jOFXlBYHJ 6bonwRs135owNaCgyEnIeBYLqjV5gwqjnubgFRYm/txDdzHP+XrU7Szo7 A==; X-CSE-ConnectionGUID: jFGRwyc4QTKEOzfDFdIsSQ== X-CSE-MsgGUID: yP982odwS/mRE8mjc/16OQ== X-IronPort-AV: E=McAfee;i="6700,10204,11400"; a="45798951" X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="45798951" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2025 02:12:57 -0700 X-CSE-ConnectionGUID: nf2WkqOZSd2t5ICK1hge+A== X-CSE-MsgGUID: oDGP/K2JQGSTe75+k9AVqQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="134008641" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 11 Apr 2025 02:12:56 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 30E8957F; Fri, 11 Apr 2025 12:12:55 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 06/11] usb: xhci: move doorbell array pointer assignment Date: Fri, 11 Apr 2025 12:11:50 +0300 Message-ID: <20250411091155.3386971-7-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250411091155.3386971-1-niklas.neronin@linux.intel.com> References: <20250411091155.3386971-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 4e6289d9a89a..7525713f0774 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2376,7 +2376,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; /* @@ -2444,13 +2443,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 431c922b3f2d..e5e5a50d9617 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -513,6 +513,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). * @@ -547,6 +557,9 @@ static int xhci_init(struct usb_hcd *hcd) /* Set Device Context Base Address 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 Fri Apr 11 09:11:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 14047892 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 2A34C2989B8 for ; Fri, 11 Apr 2025 09:12:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362779; cv=none; b=CLu+KhzL3VW3VJ7qUBgl9jeh8Ck8gjWRWYe8Kqjf9Cy6FU2nyHiqZIlVWbWpKWEljptodPUXifR7czVEkZh61ce31/9JAkW2BrIy6v0XaKT9Kj/Me/n7h1L3G73gngwPC/kBlPoIavKGFHgCShyHOaGwURes+kPO2kxfpw399tc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362779; c=relaxed/simple; bh=9RWcNJQ8wa5b9yrpW4pxaw70ckjZelb1DIicyWORdW4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TvulzrWqUhS0fbC/Rc1VmyDD4sU8s3yubdNTdXXsXV20cXLqyfh1L8+/L4pDmpBkKy99fBncsi2a/BgG8IiDU/KQ1OJNe4II9+2JOgcLdYF8/HrCVQtzRYacP1LRYzzHpULykvWtntukZIe0H8kk1bcptr/ORDIaWaEgUmTuEdE= 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=Yg1J1Dpk; arc=none smtp.client-ip=198.175.65.19 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="Yg1J1Dpk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744362778; x=1775898778; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9RWcNJQ8wa5b9yrpW4pxaw70ckjZelb1DIicyWORdW4=; b=Yg1J1Dpk2w2EXbyH3I2yqNpf83Mc2wsvs/om99+ChgbjNeGs4W+6yWa2 xYpFJMvt75V7n+QHNOekd+dNXBDeCkSVnLeJzkksG3U/XL92izmpT/1aW 9zzfQgFh2ZxIoWeTA/LZCTI1ZhIWJviy3pC3ttLM2uUwfUtBAMQtgaqna zYdJqhTf/ji6XRB+Mz6jBuc8bhsUCxru7ULmSejx8c++Cgt0NTnDmdVs3 G4pKnrMY+oAFz/Rf9EurskIfPaefyvSQX/GkUi73wLSCpzf6IT1EyhOfa Vkxwp0ecOMgKhD/C4n9gR/oH4opcCpO+ilAgvwS1RpwJdVssk8ZkDnVJq w==; X-CSE-ConnectionGUID: 9pnd2J27RO6iDUBzjo3rBg== X-CSE-MsgGUID: pQ+u/W1mT+2bF431LpsD8g== X-IronPort-AV: E=McAfee;i="6700,10204,11400"; a="45798952" X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="45798952" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2025 02:12:58 -0700 X-CSE-ConnectionGUID: BKbwxje2SRaOVjZdBpxC1A== X-CSE-MsgGUID: qtCpP0IkTEKhq8Upp+5Hxg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="134008656" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 11 Apr 2025 02:12:57 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 3D8FC78B; Fri, 11 Apr 2025 12:12:56 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 07/11] usb: xhci: move enabling of USB 3 device notifications Date: Fri, 11 Apr 2025 12:11:51 +0300 Message-ID: <20250411091155.3386971-8-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250411091155.3386971-1-niklas.neronin@linux.intel.com> References: <20250411091155.3386971-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 7525713f0774..1b05704a1852 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2376,7 +2376,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 @@ -2463,15 +2462,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 e5e5a50d9617..8fe217cdf80f 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -523,6 +523,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). * @@ -560,6 +574,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 38058006f79b..b8e6ce888032 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 Fri Apr 11 09:11:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 14047893 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 0690F298CA3 for ; Fri, 11 Apr 2025 09:12:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362780; cv=none; b=US8CJIOq0usfunDpNDPEz4RKLv7Y8Pk7dbBE4jr7KXNGPMHqJ/mZMUMdO7lOZ7pW9fqJC/IJ8/X69t4PnD9GLUrxLCiy+vUlYNIYaV9/r/s9ZPzrbzQFq5rQQ03HxU66BN+DENhOq40883mV1S8s6ZBDgMfoUeJH7suoYxypWYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362780; c=relaxed/simple; bh=Jf5KNj5OTRe+FFcvyJ6IqcKVRutJTblT9MnjKfrD0bU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ABAivxKMs6kldiPT4IVgF8RMnUC1AE3dU4XVv4xjjjtLIUi3WlzQIGepmEHvLsNTvRSq9pUTb0pA/TyIrA8QltytFuNjAgUBdR4v5C89obu5F2G41XU/aQR+KY3g5n7fLif8IIJVmYwW7gzTOTNTquYRTTXatuYJcxWlm/bLEP8= 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=AdQY6lLk; arc=none smtp.client-ip=198.175.65.19 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="AdQY6lLk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744362779; x=1775898779; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jf5KNj5OTRe+FFcvyJ6IqcKVRutJTblT9MnjKfrD0bU=; b=AdQY6lLkbH5QCKFoURnZ6cARxbpNcsOihsY6YAkaBldw4aUWGeRtkhU0 B+5ESF8/l8RrF3tK37pf/FWKXo4Qx+wYKzTdev8QVlrC+NAIeQO3G175j BRCujIL/C/lbVO+OULBAxVK4iQvYiD2jFswQXQ1lFzcymRFsy38BZTPTq eZE3xMuhes1XPSQCX6CTz1LzD10TzPlHvlQrEY0IqrLVmx6D1XPY3CuuR ud2GQACTKFYzQjir0XlXx5hsgsOJBGZnnn00jQ6qF0VX4JbLvSrJpLGrq Zp/v/KU/8hxZmNJ67BtByUa9pxfUWXbf6NN53l2G2w73Z7ijQS+nGU45E g==; X-CSE-ConnectionGUID: ryOdmOlCQFqwixdmnGFbXw== X-CSE-MsgGUID: BEnGzvp8RmmJmifaCSsgUg== X-IronPort-AV: E=McAfee;i="6700,10204,11400"; a="45798954" X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="45798954" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2025 02:12:59 -0700 X-CSE-ConnectionGUID: nToYSc3dTp+YKt1zynUPAw== X-CSE-MsgGUID: 0j1pyjl+TZKirGgE+TVxxg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="134008666" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 11 Apr 2025 02:12:58 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 1E6A057F; Fri, 11 Apr 2025 12:12:57 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 08/11] usb: xhci: remove error handling from xhci_add_interrupter() Date: Fri, 11 Apr 2025 12:11:52 +0300 Message-ID: <20250411091155.3386971-9-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250411091155.3386971-1-niklas.neronin@linux.intel.com> References: <20250411091155.3386971-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 --- drivers/usb/host/xhci-mem.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 1b05704a1852..ce632a288c41 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2282,24 +2282,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]; @@ -2320,8 +2309,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 * @@ -2331,7 +2318,7 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs, struct xhci_hcd *xhci = hcd_to_xhci(hcd); struct xhci_interrupter *ir; unsigned int i; - int err = -ENOSPC; + int err; if (!xhci->interrupters || xhci->max_interrupters <= 1) return NULL; @@ -2345,14 +2332,14 @@ 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] == NULL) { - err = xhci_add_interrupter(xhci, ir, i); + xhci_add_interrupter(xhci, ir, i); break; } } spin_unlock_irq(&xhci->lock); - if (err) { + if (i == xhci->max_interrupters) { xhci_warn(xhci, "Failed to add secondary interrupter, max interrupters %d\n", xhci->max_interrupters); xhci_free_interrupter(xhci, ir); @@ -2452,8 +2439,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 Fri Apr 11 09:11:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 14047894 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 BC920298CA5 for ; Fri, 11 Apr 2025 09:12:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362781; cv=none; b=Ul8KhKwrujwC+CkyeRdSMADcFvyrAZCBCMFKPKjq6/QnVVl8IaoHepx2OM/covjhwZ3QmpF4rJroZGpGMUZuvtZRNcWGd2waKKbqrqQgS6xMrUXI871XZCZckUUUrkicBivuVemz5riwLcl3M6VkagUbIJofYfr1Nw3JGspjaiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362781; c=relaxed/simple; bh=G/2dOQgkDxcM8anKzzLP2er/JP7B+cRI/BiFND3iUPQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d0IBb5y1UqRU3jvPxkA4025Zsg0nTocz9bXNCngDx+uPEj4Dbztv/XI4AXX7v0gah99xJrDpi4Xxmrcsil/y99QpKHwQOuRr3QfXE0iaj4gShqgjBNBzcHn4XG7QbtB1gbCXCVB2brh1E9RCoDhZ+PAC8AYxnC03+Xzw4+sLdhM= 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=kx8KHB7r; arc=none smtp.client-ip=198.175.65.19 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="kx8KHB7r" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744362780; x=1775898780; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=G/2dOQgkDxcM8anKzzLP2er/JP7B+cRI/BiFND3iUPQ=; b=kx8KHB7rOgUbWP93Zbv60o9j//9eqv2Y345iGC1n3BlSE61O+bydLrGC yOWM0xIlY+V3Q+WGILnaGGjD+HnqsAwcdhAmgIe7GGdPj4+zZgIaVyH4c rGkFlU1jIcjlwo9nF41YYo64fe0KZ4bUiy4bO8m//I3yqBEJXPiqou2/v +t9OQEa1wlRCJKqa1F4hRp3SO8hRt/J/mE/gmNuhOqy3FI/pwIu380Cgk 5zB26HzCs508n67pNKOTNfbaJkqEWpRy5OPLbGY92X6urgbr67IY0rr/U VGZYUgsPPIiTolP8A8oWSg+opQUocv9qwTMkHqm3pREG6BOh7Jy4zb3bF Q==; X-CSE-ConnectionGUID: fwaScDfRSieuh3oy3/bXMw== X-CSE-MsgGUID: LPYYK8nmQwyIU5PJ+CrQpw== X-IronPort-AV: E=McAfee;i="6700,10204,11400"; a="45798955" X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="45798955" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2025 02:13:00 -0700 X-CSE-ConnectionGUID: Etl636DsQaqSDYqgLKOeuw== X-CSE-MsgGUID: fYaIsW5kTTmmuHLLtn7wwg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="134008686" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 11 Apr 2025 02:12:59 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id EAD6A7BC; Fri, 11 Apr 2025 12:12:57 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 09/11] usb: xhci: move initialization of the primary interrupter Date: Fri, 11 Apr 2025 12:11:53 +0300 Message-ID: <20250411091155.3386971-10-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250411091155.3386971-1-niklas.neronin@linux.intel.com> References: <20250411091155.3386971-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 --- drivers/usb/host/xhci-mem.c | 19 +++++++------------ drivers/usb/host/xhci.c | 4 ++++ drivers/usb/host/xhci.h | 1 + 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index ce632a288c41..2d1f320e5fd6 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2282,14 +2282,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]; @@ -2332,7 +2331,8 @@ 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] == NULL) { - xhci_add_interrupter(xhci, ir, i); + xhci->interrupters[i] = ir; + xhci_add_interrupter(xhci, i); break; } } @@ -2360,7 +2360,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; @@ -2435,14 +2434,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 8fe217cdf80f..c7380ebdb680 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -577,6 +577,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 b8e6ce888032..4c32ad36c493 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1934,6 +1934,7 @@ unsigned int count_trbs(u64 addr, u64 len); int xhci_stop_endpoint_sync(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, int suspend, gfp_t gfp_flags); void xhci_process_cancelled_tds(struct xhci_virt_ep *ep); +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 Fri Apr 11 09:11:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 14047895 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 5D6E7298CB6 for ; Fri, 11 Apr 2025 09:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362782; cv=none; b=lFhTOJKs5tZGVzNi6yxR+8f/bsEDxZ7ct69mm8qdUt61ckLfnVqZ/zkk1MxBfJxUvXtxD9monDxuhglonb6/4rhk1fUryQ4DKYpSzMUPyAAmMW7//9F/wtd1POE7IG9ViRTFnCeLFSfRdy2DdvmGVW1oh2w5kLopUtHFwpIYans= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362782; c=relaxed/simple; bh=J53z98lnqHeakF7LnnF19xXHKf3xvK1fGryDtkrGUYQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=STIGvpXCv4TxZDd1EXxZ0WuWGAvKUT3uz6ZaQt26y6Q0oqDJatPziHcZlKJ0yfVshwI38UGBlPpwyPx44anBDjF2BV/tqnZn5nWew4h3HfoQ0OHwoJ8BSG2Fr6kUlbEcWU5nb3DdeJq/TiVSgltXXV5WXt6C1VOed/K9H/l/B9E= 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=IUEjLPQM; arc=none smtp.client-ip=198.175.65.19 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="IUEjLPQM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744362782; x=1775898782; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J53z98lnqHeakF7LnnF19xXHKf3xvK1fGryDtkrGUYQ=; b=IUEjLPQMA5lxEv5NPswfkru1Bvch7ddz3qAAD3ZiVKJ7AxjgK2oFkHfP u/ODV4tKAtL89goVDrqcp3USs9uV3vHReqNcRuY7Us300TIJ253ViLLn/ Cvrc+FGatRYgid9UxXG45kACkIWhzc5ioDKitbj47xyPk4aMGqXCWbl5T ofqksZtbxM1c6zg2t/k6JB8cW/V82X9gYTaZVFEntcjaUX6/IS7U97ibW Qy6Mv2w0AgUMpkWOkJttmPMUsizogGYUCnjy0i4txrbbQBYjYvcY2OjZ/ xDcRMRPQ9CqZUMSjU1lg3herxt6plJPHJQWfIso2J7Gl+qESQvd801Mw0 g==; X-CSE-ConnectionGUID: PPaH4LjxTfSkqFmx30iE2Q== X-CSE-MsgGUID: h5yn2chyRWCkb8fNgkT06A== X-IronPort-AV: E=McAfee;i="6700,10204,11400"; a="45798957" X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="45798957" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2025 02:13:01 -0700 X-CSE-ConnectionGUID: GxBGvxbRQwCf4k67nUubKQ== X-CSE-MsgGUID: PuEYSjajSjGJXhaqewkHjQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="134008702" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 11 Apr 2025 02:13:00 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id CAE0378B; Fri, 11 Apr 2025 12:12:58 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 10/11] usb: xhci: add individual allocation checks in xhci_mem_init() Date: Fri, 11 Apr 2025 12:11:54 +0300 Message-ID: <20250411091155.3386971-11-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250411091155.3386971-1-niklas.neronin@linux.intel.com> References: <20250411091155.3386971-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 2d1f320e5fd6..a45d96a5ef5f 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2390,11 +2390,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, @@ -2403,6 +2405,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); @@ -2410,7 +2415,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. */ @@ -2433,6 +2438,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 Fri Apr 11 09:11:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Neronin X-Patchwork-Id: 14047896 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 EAD11298CAE for ; Fri, 11 Apr 2025 09:13:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362784; cv=none; b=aJGSvKIKwFAY6MS1RIybAxuORpq+XnZTeXXy8UD5tZrskPZfntJ6NFZFcqZAO1U87+YTsBliNdG4x0VdK6noJZajfb6voGtGtfidWaQ4BMkKsS/NCWPCDipiaKWJ/mTq/tr5+LUWD8rsjCPXDL7xD+dPPEG+pep2KsLMLi/ObXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744362784; c=relaxed/simple; bh=eah2lxqCDe87SYlOVI0A+m91YeKZHzdW0jK9nLJkYHc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qh9w6HMbL6CeX+BsupXbxNHefbzgLfNTnQ9SOcoW0Xma1K7U22XXYEfwTkGnWn9hyuxjaBWr5xU+QMlAxM5VMhYyaGlvzt4QpKcL4BoAXctm8hUxt6ulvWNaF3dUSRcs/0dQa/Cn6Kk6VdZlRW3vx6TvpgxwvRY6i8aqFIiUV2U= 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=m31NEyfs; arc=none smtp.client-ip=198.175.65.19 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="m31NEyfs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744362783; x=1775898783; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eah2lxqCDe87SYlOVI0A+m91YeKZHzdW0jK9nLJkYHc=; b=m31NEyfsWrPcpRPVSgU6Co18Kj14blZNVesy74cFe6LQowJQlOTWv0qJ gDRI4jNvMC6u6D++IlTyRhVr0XT+M9cvUDh+Z8f0TYRWTL2mtOtQa5ksJ 2OxnNQoWGgHUUxy8JrGKYu45unLX8YujiJuhysbOn7El/j+ERCiutU4uR qbdMkzY1jZYwFNXahe0pzfxVgpWByFZXT5AI1h6whfaOb/v0XfHXXdyJJ XS5702ksh1f0hGL98EOsUuy2jtc3ZtSOiHPY2Vn/RnKCjykjLB63EBT2u 1b8OfZs86mM8lu1M0jV+Bf7bG2QZpTFtnKzfHITmQk2Fjri009yhzq9bx Q==; X-CSE-ConnectionGUID: ZEAn4j+uTnCP+/5nlF1Kyw== X-CSE-MsgGUID: lVZNx/zvRe2IjphViyPN0w== X-IronPort-AV: E=McAfee;i="6700,10204,11400"; a="45798961" X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="45798961" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2025 02:13:02 -0700 X-CSE-ConnectionGUID: 6cIx6iHxQnevTUjHbLY0mQ== X-CSE-MsgGUID: M4b75oK3Q+C4WwOiDgfoOg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,203,1739865600"; d="scan'208";a="134008717" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 11 Apr 2025 02:13:01 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 2695A57F; Fri, 11 Apr 2025 12:13:00 +0300 (EEST) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 11/11] usb: xhci: cleanup xhci_mem_init() Date: Fri, 11 Apr 2025 12:11:55 +0300 Message-ID: <20250411091155.3386971-12-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250411091155.3386971-1-niklas.neronin@linux.intel.com> References: <20250411091155.3386971-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 a45d96a5ef5f..1066c5d8ad83 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2367,14 +2367,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 @@ -2394,27 +2394,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; @@ -2422,20 +2421,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) @@ -2447,6 +2446,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;