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: 880520 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: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: 880519 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: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: 880518 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: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: 880517 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: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: 880516 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])