From patchwork Thu May 15 13:55:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890572 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 12600198823 for ; Thu, 15 May 2025 13:56:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317392; cv=none; b=LgsRPYs84nq2KwC+Yo016tzHLDz7KH4c2tCaYjPl0FgazCGR5VgHgTQT1oWHMIll6N/v0a2Xc/ngk7pOgftcQszVWlG+1YSwwEQA/f+8BQGWuB+D5BlFNiVivX2647lch5JO2IEy+qChKcV4LUppxTo1z00t4RkjKTiPsYSqSkw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317392; c=relaxed/simple; bh=ScoFeJpto2ARbUmsCalrnyX52pQexxvIr2G37W8CNzs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KDVzNLeD1H2pIpfHdfWC6OrIV2abBDtlM4suzxiQwf5tfPk9pcQXMuiju8rNfox5w/9zhxooxrUR3retfBOaInqCDAS6bMfiDDgXYvEP14NT6OpkAmN7fp/Jf+WJWa7tvceetipRBpnqwWnNnOnPh7wbWu171rJvZrvbhETCU5A= 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=PJTXmQef; arc=none smtp.client-ip=198.175.65.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="PJTXmQef" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317392; x=1778853392; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ScoFeJpto2ARbUmsCalrnyX52pQexxvIr2G37W8CNzs=; b=PJTXmQefPl9o5nEIp+oy2DKiSrm22jAkOWw2K7edWMEf7o6MSRZfuvV1 XgxW1kpGyC2m4i//pdM4Fks9wG+imIY0NnPM1aC8DI0UBQpe2Wy1QjnkN nI5aAiv1mJl4FgI1PuXwVGmmLWBPz7J6Fxcegb7+7q0f6RS8nOeeBjjSg vF/pLiPo/pLfs1qCsFQ5OPAi88c32ip3mJQ/gyfkLDndycUPo2GJQoOEu atKFOVCzw8q2fBYK3rcbVZElSn35D2MKJcPwntDMGWK/bt5oH45pZA3pH X1ARi+6tJBgnWVoZ6IHnhZHJE7L/DjvlmUxqI9mf6/fI4XkqblOv84JbE g==; X-CSE-ConnectionGUID: 0Tdflsm+TK6hABr+ls5Ilg== X-CSE-MsgGUID: NfE/OIAFQC2z6TQO779cYw== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60269987" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60269987" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:31 -0700 X-CSE-ConnectionGUID: bS88wonTR/WqSNw0LHggEw== X-CSE-MsgGUID: 2ooEJOarTjeMa8Pczp3Kug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372040" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:29 -0700 From: Mathias Nyman To: Cc: , Michal Pecio , Mathias Nyman Subject: [PATCH 01/24] usb: xhci: Don't log transfer ring segment list on errors Date: Thu, 15 May 2025 16:55:58 +0300 Message-ID: <20250515135621.335595-2-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Michal Pecio The error message above used to span two lines, rarely more. A recent cleanup concentrated useful information from it in one line, but then it added printing the list of all ring segments, which is even longer than before. It provides no new information in usual cases and little in unusual ones, but adds noise to the log. Drop it. Signed-off-by: Michal Pecio Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index d4e157e66473..e70bf7a27556 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2978,9 +2978,6 @@ static int handle_tx_event(struct xhci_hcd *xhci, (unsigned long long)xhci_trb_virt_to_dma(td->start_seg, td->start_trb), (unsigned long long)xhci_trb_virt_to_dma(td->end_seg, td->end_trb)); - xhci_for_each_ring_seg(ep_ring->first_seg, ep_seg) - xhci_warn(xhci, "Ring seg %u dma %pad\n", ep_seg->num, &ep_seg->dma); - return -ESHUTDOWN; err_out: From patchwork Thu May 15 13:55:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890877 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 90F731AAE13 for ; Thu, 15 May 2025 13:56:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317394; cv=none; b=M0miNQOWsnSHUDGz8floeSzqIfVeMhXw/6uMszyJkD2hqlBeqhc9o+yJpicQxdnkt9oXl3lTxHiQl1ILXF5JYdCK2jgD2OVWjZEs+R/i2I1Ml08k7H+L1kakN+fP+8p3tilFst23UkimzuDaRWQtV/9NBQGet0Z8u9bUxjVMZGk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317394; c=relaxed/simple; bh=6zU/1hgDrUuv4rR5E2kPlwrn6enjWEiecou5TXh8szI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H6fgn21BEqP0aHXTRKkPbSAlv/4mB4X2jA9VR5pPx8jkEKzbONV7SZlUxKkGZK5VGHm8srMSOE8ZfmC1EwodkDPvh1eLzssemJnE0XoJbB4pgsW73oM165PFS+oPwxEpMTPkZ4ChMNFSw5FqdimODIeOWsTzOHNnoiMqD9gdSZ0= 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=bs6ZW4v7; arc=none smtp.client-ip=198.175.65.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="bs6ZW4v7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317393; x=1778853393; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6zU/1hgDrUuv4rR5E2kPlwrn6enjWEiecou5TXh8szI=; b=bs6ZW4v7RiK4pIUogG5CfuRMxbXtIxV/aoopc9MdihexbdJRW8Yt0piO WI8L1SVV6JozeGHbns1Oywhcg0xM37MibY7gvFD0TcIqFO0RZroGBarWk SsCm5iNDJ5BmJGfeIVr7EcoPHn8QbSbtKm5ZIpeMAEh/1LO1KFwYKoB49 t4lO02n+ZUBaYi30bdEv++UepRDr/2mlhFKsDZPV19K1Mn9WuRSGAZ6ab kdUfnjD9VGtSwf51S6hhbdAGZiK23flTxHy9Kp1P7DzAJD+CBLn10C0S9 vzjVTOsxMAcRP5Zs5MZ7Dj4UJXnWQgiyawGbeuZkzuFIPlQ5drLqvEfck w==; X-CSE-ConnectionGUID: L8AB0eRvQ66lUzUEl+drFw== X-CSE-MsgGUID: lYZ7fqkmRkynDeoQqBLB3Q== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60269993" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60269993" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:33 -0700 X-CSE-ConnectionGUID: VlKvYMa+TP+rBj3l+2FXEA== X-CSE-MsgGUID: YLXMkjA2QreaKqpKKaCHtg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372067" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:31 -0700 From: Mathias Nyman To: Cc: , Xu Rao , Mathias Nyman Subject: [PATCH 02/24] usb: xhci: Add debugfs support for xHCI port bandwidth Date: Thu, 15 May 2025 16:55:59 +0300 Message-ID: <20250515135621.335595-3-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Xu Rao In many projects, you need to obtain the available bandwidth of the xhci roothub port. Refer to xhci rev1_2 and use the TRB_GET_BW command to obtain it. hardware tested: 03:00.3 USB controller: Advanced Micro Devices, Inc. [AMD] Raven USB 3.1 (prog-if 30 [XHCI]) Subsystem: Huawei Technologies Co., Ltd. Raven USB 3.1 Flags: bus master, fast devsel, latency 0, IRQ 30 Memory at c0300000 (64-bit, non-prefetchable) [size=1M] Capabilities: [48] Vendor Specific Information: Len=08 Capabilities: [50] Power Management version 3 Capabilities: [64] Express Endpoint, MSI 00 Capabilities: [a0] MSI: Enable- Count=1/8 Maskable- 64bit+ Capabilities: [c0] MSI-X: Enable+ Count=8 Masked- Kernel driver in use: xhci_hcd test progress: 1. cd /sys/kernel/debug/usb/xhci/0000:03:00.3/port_bandwidth# ls FS_BW HS_BW SS_BW 2. test fs speed device cat FS_BW port[1] available bw: 90%. port[2] available bw: 90%. port[3] available bw: 90%. port[4] available bw: 90%. port[5] available bw: 0%. port[6] available bw: 0%. port[7] available bw: 0%. port[8] available bw: 0%. plug in fs usb audio ID 0d8c:013c cat FS_BW port[1] available bw: 76%. port[2] available bw: 76%. port[3] available bw: 76%. port[4] available bw: 76%. port[5] available bw: 0%. port[6] available bw: 0%. port[7] available bw: 0%. port[8] available bw: 0%. 3. test hs speed device cat HS_BW port[1] available bw: 79%. port[2] available bw: 79%. port[3] available bw: 79%. port[4] available bw: 79%. port[5] available bw: 0%. port[6] available bw: 0%. port[7] available bw: 0%. port[8] available bw: 0%. plug in hs usb video ID 0408:1040 cat HS_BW port[1] available bw: 39%. port[2] available bw: 39%. port[3] available bw: 39%. port[4] available bw: 39%. port[5] available bw: 0%. port[6] available bw: 0%. port[7] available bw: 0%. port[8] available bw: 0%. 4.cat SS_BW port[1] available bw: 0%. port[2] available bw: 0%. port[3] available bw: 0%. port[4] available bw: 0%. port[5] available bw: 90%. port[6] available bw: 90%. port[7] available bw: 90%. port[8] available bw: 90%. Signed-off-by: Xu Rao Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-debugfs.c | 108 ++++++++++++++++++++++++++++++++ drivers/usb/host/xhci-mem.c | 45 ++++++++++++- drivers/usb/host/xhci-ring.c | 13 ++++ drivers/usb/host/xhci.c | 36 +++++++++++ drivers/usb/host/xhci.h | 14 +++++ 5 files changed, 215 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c index 1f5ef174abea..c6d44977193f 100644 --- a/drivers/usb/host/xhci-debugfs.c +++ b/drivers/usb/host/xhci-debugfs.c @@ -631,6 +631,112 @@ static void xhci_debugfs_create_ports(struct xhci_hcd *xhci, } } +static int xhci_port_bw_show(struct xhci_hcd *xhci, u8 dev_speed, + struct seq_file *s) +{ + unsigned int num_ports; + unsigned int i; + int ret; + struct xhci_container_ctx *ctx; + struct usb_hcd *hcd = xhci_to_hcd(xhci); + struct device *dev = hcd->self.controller; + + ret = pm_runtime_get_sync(dev); + if (ret < 0) + return ret; + + num_ports = HCS_MAX_PORTS(xhci->hcs_params1); + + ctx = xhci_alloc_port_bw_ctx(xhci, 0); + if (!ctx) { + pm_runtime_put_sync(dev); + return -ENOMEM; + } + + /* get roothub port bandwidth */ + ret = xhci_get_port_bandwidth(xhci, ctx, dev_speed); + if (ret) + goto err_out; + + /* print all roothub ports available bandwidth + * refer to xhci rev1_2 protocol 6.2.6 , byte 0 is reserved + */ + for (i = 1; i < num_ports+1; i++) + seq_printf(s, "port[%d] available bw: %d%%.\n", i, + ctx->bytes[i]); +err_out: + pm_runtime_put_sync(dev); + xhci_free_port_bw_ctx(xhci, ctx); + return ret; +} + +static int xhci_ss_bw_show(struct seq_file *s, void *unused) +{ + int ret; + struct xhci_hcd *xhci = (struct xhci_hcd *)s->private; + + ret = xhci_port_bw_show(xhci, USB_SPEED_SUPER, s); + return ret; +} + +static int xhci_hs_bw_show(struct seq_file *s, void *unused) +{ + int ret; + struct xhci_hcd *xhci = (struct xhci_hcd *)s->private; + + ret = xhci_port_bw_show(xhci, USB_SPEED_HIGH, s); + return ret; +} + +static int xhci_fs_bw_show(struct seq_file *s, void *unused) +{ + int ret; + struct xhci_hcd *xhci = (struct xhci_hcd *)s->private; + + ret = xhci_port_bw_show(xhci, USB_SPEED_FULL, s); + return ret; +} + +static struct xhci_file_map bw_context_files[] = { + {"SS_BW", xhci_ss_bw_show, }, + {"HS_BW", xhci_hs_bw_show, }, + {"FS_BW", xhci_fs_bw_show, }, +}; + +static int bw_context_open(struct inode *inode, struct file *file) +{ + int i; + struct xhci_file_map *f_map; + const char *file_name = file_dentry(file)->d_iname; + + for (i = 0; i < ARRAY_SIZE(bw_context_files); i++) { + f_map = &bw_context_files[i]; + + if (strcmp(f_map->name, file_name) == 0) + break; + } + + return single_open(file, f_map->show, inode->i_private); +} + +static const struct file_operations bw_fops = { + .open = bw_context_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static void xhci_debugfs_create_bandwidth(struct xhci_hcd *xhci, + struct dentry *parent) +{ + parent = debugfs_create_dir("port_bandwidth", parent); + + xhci_debugfs_create_files(xhci, bw_context_files, + ARRAY_SIZE(bw_context_files), + xhci, + parent, &bw_fops); +} + void xhci_debugfs_init(struct xhci_hcd *xhci) { struct device *dev = xhci_to_hcd(xhci)->self.controller; @@ -681,6 +787,8 @@ void xhci_debugfs_init(struct xhci_hcd *xhci) xhci->debugfs_slots = debugfs_create_dir("devices", xhci->debugfs_root); xhci_debugfs_create_ports(xhci, xhci->debugfs_root); + + xhci_debugfs_create_bandwidth(xhci, xhci->debugfs_root); } void xhci_debugfs_exit(struct xhci_hcd *xhci) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index ed36df46b140..7ff6a47d3198 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -484,6 +484,35 @@ void xhci_free_container_ctx(struct xhci_hcd *xhci, kfree(ctx); } +struct xhci_container_ctx *xhci_alloc_port_bw_ctx(struct xhci_hcd *xhci, + gfp_t flags) +{ + struct xhci_container_ctx *ctx; + struct device *dev = xhci_to_hcd(xhci)->self.sysdev; + + ctx = kzalloc_node(sizeof(*ctx), flags, dev_to_node(dev)); + if (!ctx) + return NULL; + + ctx->size = GET_PORT_BW_ARRAY_SIZE; + + ctx->bytes = dma_pool_zalloc(xhci->port_bw_pool, flags, &ctx->dma); + if (!ctx->bytes) { + kfree(ctx); + return NULL; + } + return ctx; +} + +void xhci_free_port_bw_ctx(struct xhci_hcd *xhci, + struct xhci_container_ctx *ctx) +{ + if (!ctx) + return; + dma_pool_free(xhci->port_bw_pool, ctx->bytes, ctx->dma); + kfree(ctx); +} + struct xhci_input_control_ctx *xhci_get_input_control_ctx( struct xhci_container_ctx *ctx) { @@ -1912,6 +1941,11 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed small stream array pool"); + dma_pool_destroy(xhci->port_bw_pool); + xhci->port_bw_pool = NULL; + xhci_dbg_trace(xhci, trace_xhci_dbg_init, + "Freed xhci port bw array pool"); + dma_pool_destroy(xhci->medium_streams_pool); xhci->medium_streams_pool = NULL; xhci_dbg_trace(xhci, trace_xhci_dbg_init, @@ -2475,7 +2509,16 @@ 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) + /* refer to xhci rev1_2 protocol 5.3.3 max ports is 255. + * refer to xhci rev1_2 protocol 6.4.3.14 port bandwidth buffer need + * to be 16-byte aligned. + */ + xhci->port_bw_pool = + dma_pool_create("xHCI 256 port bw ctx arrays", + dev, GET_PORT_BW_ARRAY_SIZE, 16, 0); + + if (!xhci->small_streams_pool || !xhci->medium_streams_pool || + !xhci->port_bw_pool) goto fail; /* Set up the command ring to have one segments for now. */ diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index e70bf7a27556..9607f75b8d2a 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1899,6 +1899,8 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, case TRB_NEC_GET_FW: xhci_handle_cmd_nec_get_fw(xhci, event); break; + case TRB_GET_BW: + break; default: /* Skip over unknown commands on the event ring */ xhci_info(xhci, "INFO unknown command type %d\n", cmd_type); @@ -4445,6 +4447,17 @@ int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, command_must_succeed); } +/* Queue a get root hub port bandwidth command TRB */ +int xhci_queue_get_port_bw(struct xhci_hcd *xhci, + struct xhci_command *cmd, dma_addr_t in_ctx_ptr, + u8 dev_speed, bool command_must_succeed) +{ + return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), + upper_32_bits(in_ctx_ptr), 0, + TRB_TYPE(TRB_GET_BW) | DEV_SPEED_FOR_TRB(dev_speed), + command_must_succeed); +} + /* Queue an evaluate context command TRB */ int xhci_queue_evaluate_context(struct xhci_hcd *xhci, struct xhci_command *cmd, dma_addr_t in_ctx_ptr, u32 slot_id, bool command_must_succeed) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index b6267fc37b08..fd9d41fe3224 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -3090,6 +3090,42 @@ void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) } EXPORT_SYMBOL_GPL(xhci_reset_bandwidth); +/* Get the available bandwidth of the ports under the xhci roothub */ +int xhci_get_port_bandwidth(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, + u8 dev_speed) +{ + struct xhci_command *cmd; + unsigned long flags; + int ret; + + if (!ctx || !xhci) + return -EINVAL; + + cmd = xhci_alloc_command(xhci, true, GFP_KERNEL); + if (!cmd) + return -ENOMEM; + + cmd->in_ctx = ctx; + + /* get xhci port bandwidth, refer to xhci rev1_2 protocol 4.6.15 */ + spin_lock_irqsave(&xhci->lock, flags); + + ret = xhci_queue_get_port_bw(xhci, cmd, ctx->dma, dev_speed, 0); + if (ret) { + spin_unlock_irqrestore(&xhci->lock, flags); + goto err_out; + } + xhci_ring_cmd_db(xhci); + spin_unlock_irqrestore(&xhci->lock, flags); + + wait_for_completion(cmd->completion); +err_out: + kfree(cmd->completion); + kfree(cmd); + + return ret; +} + static void xhci_setup_input_ctx_for_config_ep(struct xhci_hcd *xhci, struct xhci_container_ctx *in_ctx, struct xhci_container_ctx *out_ctx, diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index df9ed8a74af6..f8198ec02981 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -589,6 +589,7 @@ struct xhci_stream_info { #define SMALL_STREAM_ARRAY_SIZE 256 #define MEDIUM_STREAM_ARRAY_SIZE 1024 +#define GET_PORT_BW_ARRAY_SIZE 256 /* Some Intel xHCI host controllers need software to keep track of the bus * bandwidth. Keep track of endpoint info here. Each root port is allocated @@ -1006,6 +1007,9 @@ enum xhci_setup_dev { /* bits 16:23 are the virtual function ID */ /* bits 24:31 are the slot ID */ +/* bits 19:16 are the dev speed */ +#define DEV_SPEED_FOR_TRB(p) ((p) << 16) + /* Stop Endpoint TRB - ep_index to endpoint ID for this TRB */ #define SUSPEND_PORT_FOR_TRB(p) (((p) & 1) << 23) #define TRB_TO_SUSPEND_PORT(p) (((p) & (1 << 23)) >> 23) @@ -1558,6 +1562,7 @@ struct xhci_hcd { struct dma_pool *device_pool; struct dma_pool *segment_pool; struct dma_pool *small_streams_pool; + struct dma_pool *port_bw_pool; struct dma_pool *medium_streams_pool; /* Host controller watchdog timer structures */ @@ -1850,6 +1855,10 @@ struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci, int type, gfp_t flags); void xhci_free_container_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx); +struct xhci_container_ctx *xhci_alloc_port_bw_ctx(struct xhci_hcd *xhci, + gfp_t flags); +void xhci_free_port_bw_ctx(struct xhci_hcd *xhci, + struct xhci_container_ctx *ctx); struct xhci_interrupter * xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs, u32 imod_interval, unsigned int intr_num); @@ -1923,6 +1932,11 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd, dma_addr_t in_ctx_ptr, u32 slot_id, bool command_must_succeed); +int xhci_queue_get_port_bw(struct xhci_hcd *xhci, + struct xhci_command *cmd, dma_addr_t in_ctx_ptr, + u8 dev_speed, bool command_must_succeed); +int xhci_get_port_bandwidth(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, + u8 dev_speed); int xhci_queue_evaluate_context(struct xhci_hcd *xhci, struct xhci_command *cmd, dma_addr_t in_ctx_ptr, u32 slot_id, bool command_must_succeed); int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd, From patchwork Thu May 15 13:56:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890571 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 055BD15573F for ; Thu, 15 May 2025 13:56:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317395; cv=none; b=K6jD8RppmI7TuZSIPbVYZeLB8ICSoOTDG1XqWko922aP/FaJOwoRt63VXG38S6sJc1KVRWwkImq+kyPiyrMNOXU2VIN6QPTmVNreMZu2JvAek4RzJVCLhvOUHGgswPbFRoaIJwXoV7jujTBXW5uaNP0mOx+eQZbR00VQVKNvIn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317395; c=relaxed/simple; bh=/Z6ELDNh51tsdwgqg5Cze5zClI2U+WqoTwT4A1Uay3k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CD1SIqfCCN1zlRR10kM3ETFEhPJp/98w1ZfyvHP4R9WLGFJJatdu1wcFiPnjvJcCOb+RmpQctQ8rhm62gmJJktvj4SxLkfHNLyEnz3+jZFEGD/TnniFIuJBMD+77Iz+TWumynU5/XCBhPH6aLqWt6dLjuxlkSEdvCRg5kJ10xBc= 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=M5SVJCeQ; arc=none smtp.client-ip=198.175.65.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="M5SVJCeQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317394; x=1778853394; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/Z6ELDNh51tsdwgqg5Cze5zClI2U+WqoTwT4A1Uay3k=; b=M5SVJCeQLFw8XiEN+gISuHHFPuTsEXIytNIk6FAfwz1AmSlfQxOlRs5E Q9cLh8AekamnbekLxBrMZDQZ6gmc0BW2XudIAKOCwSp3VKjBHYXVKIMQ/ ZRbYF4T55KegkDf3uwIsVEjoC+UM7ZtUGg6CHFcueDklhnrgyrU7ybY07 HQCotH0Lkl1sfc/Bk2V/5+Bj+3UzZ9Qz2PrcHgO8Jd9tN26QJLPg0deO8 RAVlihj3uyx7V8B63q+5rFosmv1P4DVW0G1eX627Na4zsF0KAzz4ILILb yZbyeISyTzdrlkuMtZoR9lu8DaprSl4m7Gz1Go/4dFZsxA4D7RpojOPf+ A==; X-CSE-ConnectionGUID: R6nY6z4jTfS7NAd9FEbirw== X-CSE-MsgGUID: 4OJR3Oo7QMeBPPMZ1maK7A== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60269998" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60269998" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:34 -0700 X-CSE-ConnectionGUID: CPnIROJDTDqDfzmyZe4YaQ== X-CSE-MsgGUID: 115JENeAQJKdyZH2J/NyqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372081" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:32 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 03/24] usb: xhci: relocate pre-allocation initialization Date: Thu, 15 May 2025 16:56:00 +0300 Message-ID: <20250515135621.335595-4-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin 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 Signed-off-by: Mathias Nyman --- 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 7ff6a47d3198..a7955e02905c 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2414,22 +2414,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; @@ -2438,15 +2422,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 @@ -2567,9 +2542,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 fd9d41fe3224..b073e9d91665 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -461,6 +461,21 @@ static int xhci_all_ports_seen_u0(struct xhci_hcd *xhci) return (xhci->port_status_u0 == ((1 << xhci->usb3_rhub.num_ports) - 1)); } +static void xhci_hcd_page_size(struct xhci_hcd *xhci) +{ + u32 page_size; + + page_size = readl(&xhci->op_regs->page_size) & XHCI_PAGE_SIZE_MASK; + if (!is_power_of_2(page_size)) { + xhci_warn(xhci, "Invalid page size register = 0x%x\n", page_size); + /* Fallback to 4K page size, since that's common */ + page_size = 1; + } + + xhci->page_size = page_size << 12; + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "HCD page size set to %iK", + xhci->page_size >> 10); +} /* * Initialize memory for HCD and xHC (one-time init). @@ -474,11 +489,18 @@ static int xhci_init(struct usb_hcd *hcd) struct xhci_hcd *xhci = hcd_to_xhci(hcd); int retval; - xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_init"); + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Starting %s", __func__); spin_lock_init(&xhci->lock); + INIT_LIST_HEAD(&xhci->cmd_list); + INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout); + init_completion(&xhci->cmd_ring_stop_completion); + xhci_hcd_page_size(xhci); + memset(xhci->devs, 0, MAX_HC_SLOTS * sizeof(*xhci->devs)); + retval = xhci_mem_init(xhci, GFP_KERNEL); - xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished xhci_init"); + if (retval) + return retval; /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { @@ -486,7 +508,8 @@ static int xhci_init(struct usb_hcd *hcd) compliance_mode_recovery_timer_init(xhci); } - return retval; + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished %s", __func__); + return 0; } /*-------------------------------------------------------------------------*/ From patchwork Thu May 15 13:56:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890876 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 9615918D620 for ; Thu, 15 May 2025 13:56:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317397; cv=none; b=R6Mw22U7I88ZHhj08RxIJGvpkssYos5TLTt1Y8RwGa8oFfj507kMWXPfQUOzEtQlWh+15sxZWgL1aoBxzWbJj39SvwsgU6f5oJAhfCULVuN0WvvZc3LOspvrCOTT3z/oaLVkkRSeL9fZ4zZmnI1Rt2xXfOjLHEOO7LggG17POS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317397; c=relaxed/simple; bh=ov6UnBrgg4JHzjssCs44OetyQP4W4ytVmHrTR54gu5I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ShCHJbwe6X0WInnFfKYuhBgLBckGIZsI5hx3R7uAWa6Uy0eLKTyIsAAxTNFgsJN8sB/0bgmS9C9MACxQLTuLpSsEtCl0jppDXXPNV3+/mfZLqAvCraAc7oX6lx1WcWy8iyyEk4ag1+IKPMpwYFDN2tL4Vi2Uz6/D7zQiMIkDwA8= 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=ZSSte6al; arc=none smtp.client-ip=198.175.65.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="ZSSte6al" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317396; x=1778853396; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ov6UnBrgg4JHzjssCs44OetyQP4W4ytVmHrTR54gu5I=; b=ZSSte6alejDRrlxPqB5oLi96EkChUHxOT9jxlWG2U1kcPW4ABq/JDKpo dUIDQL3a1WviO4F8ObEmQOX7mtKJLBQQxDsiD5+daUK5DIfsH+FynaivI 1oFxVMTcAd/rIMbYZloYnJ5fVWCp2efGZqWiPhO29FLnUY8XxFGsGCF6x GnC+x/fq8Dw1VwGCzbA+CFWnyA18/ZdoHH2yyoC6M9EPxnxLYczm2K8rN pqyE+r6xuiJy9+/Y+0YwJd4DtX9sffPNHfu7cltYrAImaQ8uGjvNf+y34 Y6yflbaQwdNQE0Ip6FSGxRNOB5qfe6/wU0NnAQ+Yl4Z2b7BQuKwhsrnsT A==; X-CSE-ConnectionGUID: Dj+EDBCZQeGHFEszIIE8/g== X-CSE-MsgGUID: sQnq8u4BRo2jWRZq2zMjPA== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270001" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270001" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:36 -0700 X-CSE-ConnectionGUID: OEj9nYyETfmUVGdYUloiPw== X-CSE-MsgGUID: ADJyqbLETmaYUxHKJZpMCg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372094" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:34 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 04/24] usb: xhci: move device slot enabling register write Date: Thu, 15 May 2025 16:56:01 +0300 Message-ID: <20250515135621.335595-5-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin 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 Signed-off-by: Mathias Nyman --- 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 a7955e02905c..e03109a24a50 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2419,23 +2419,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 b073e9d91665..ec0a2fa7d003 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -477,6 +477,24 @@ static void xhci_hcd_page_size(struct xhci_hcd *xhci) xhci->page_size >> 10); } +static void xhci_enable_max_dev_slots(struct xhci_hcd *xhci) +{ + u32 config_reg; + u32 max_slots; + + max_slots = HCS_MAX_SLOTS(xhci->hcs_params1); + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xHC can handle at most %d device slots", + max_slots); + + config_reg = readl(&xhci->op_regs->config_reg); + config_reg &= ~HCS_SLOTS_MASK; + config_reg |= max_slots; + + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Setting Max device slots reg = 0x%x", + config_reg); + writel(config_reg, &xhci->op_regs->config_reg); +} + /* * Initialize memory for HCD and xHC (one-time init). * @@ -502,6 +520,9 @@ static int xhci_init(struct usb_hcd *hcd) if (retval) return retval; + /* Set the Number of Device Slots Enabled to the maximum supported value */ + xhci_enable_max_dev_slots(xhci); + /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { xhci->quirks |= XHCI_COMP_MODE_QUIRK; From patchwork Thu May 15 13:56:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890570 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 2894C1DB363 for ; Thu, 15 May 2025 13:56:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317399; cv=none; b=EAsd4uXOYmvOKrn/qg5itYYPArs2Fz4x1us+FHnzLXxlAXTPjm2cJYepKeTdhq1UDvrwEDK94YJovPrPJvqvmbPl2cHCK0KR9klYky5gdYbfcMxV4qglbcEaGDlniuPOHNJ2kBNq3pqs1nT6pAPrwWLpmVmi+5pItwR6vwgAbnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317399; c=relaxed/simple; bh=b9N8R68n2gSAraT4c70RJhIwiqxAWTj9BopWmH/mwWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y5YtjMFAnFPaVKH9hG36X3bUEizqpwitQ2kr2okT2lkRrSPWmiM9IXuv0J7TEZu/AZaQq542VnUhbaz5cKhyyqzFzXypyqHxQkPXiBLCwq9paDAgWHpMI9MZoOpRzEChEVgTJiyyI1okNsteerOsT15G7ioe202bYC7dsotp7QE= 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=EznvBFwj; arc=none smtp.client-ip=198.175.65.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="EznvBFwj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317398; x=1778853398; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b9N8R68n2gSAraT4c70RJhIwiqxAWTj9BopWmH/mwWk=; b=EznvBFwjEU/ZmHvYbjwYCK4akD62VSsWaPxkcxZGs9Sh/kZEea/Z9yTh IZQGC2XaQTtU+R6YUDqMKY8nmZHsEpuAVzXiSp1PkCXbnMoqMn3ONzEJ8 wzplqmo9E7wsseynNiq6DcryTIzkza4mcftHc8Hb/zWBI93+W7rvkhewG Y1fg8yKxxH1STbGKfwQW5pEdn5eU93tJDSzlhKHAK8rXWuzEIq2ULOY4R dAp4B447iGK9+USy4f4CJ5t8woKmE7tyrcTzuizTBIsRL9N/zNPMyUsEI 2WoaZZ1/CyIUCxQgoC1H8/o55XvhTlx1I0jC6MVZlnTcnOD4PAUlDcm74 A==; X-CSE-ConnectionGUID: GX/suECQQze6EyerBy2gBg== X-CSE-MsgGUID: EcX77zaoSpW4ND71jdT6YA== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270005" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270005" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:37 -0700 X-CSE-ConnectionGUID: 2MlU1N+3Rrmj6m0fRLU6ZA== X-CSE-MsgGUID: YTsEeSeKQJKknHWei3j+5A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372107" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:35 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 05/24] usb: xhci: move command ring pointer write Date: Thu, 15 May 2025 16:56:02 +0300 Message-ID: <20250515135621.335595-6-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin 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 Signed-off-by: Mathias Nyman --- 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 e03109a24a50..c4b94f7bacfb 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2420,7 +2420,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; /* @@ -2492,15 +2491,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 ec0a2fa7d003..66a9106d8b31 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -495,6 +495,23 @@ static void xhci_enable_max_dev_slots(struct xhci_hcd *xhci) writel(config_reg, &xhci->op_regs->config_reg); } +static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) +{ + u64 val_64; + + /* step 2: initialize command ring buffer */ + val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); + val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | + (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, + xhci->cmd_ring->dequeue) & + (u64) ~CMD_RING_RSVD_BITS) | + xhci->cmd_ring->cycle_state; + xhci_dbg_trace(xhci, trace_xhci_dbg_init, + "// Setting command ring address to 0x%llx", + (unsigned long long) val_64); + xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); +} + /* * Initialize memory for HCD and xHC (one-time init). * @@ -523,6 +540,9 @@ static int xhci_init(struct usb_hcd *hcd) /* Set the Number of Device Slots Enabled to the maximum supported value */ xhci_enable_max_dev_slots(xhci); + /* Set the address in the Command Ring Control register */ + xhci_set_cmd_ring_deq(xhci); + /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { xhci->quirks |= XHCI_COMP_MODE_QUIRK; @@ -793,23 +813,6 @@ static void xhci_restore_registers(struct xhci_hcd *xhci) } } -static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) -{ - u64 val_64; - - /* step 2: initialize command ring buffer */ - val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); - val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | - (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, - xhci->cmd_ring->dequeue) & - (u64) ~CMD_RING_RSVD_BITS) | - xhci->cmd_ring->cycle_state; - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Setting command ring address to 0x%llx", - (long unsigned long) val_64); - xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); -} - /* * The whole command ring must be cleared to zero when we suspend the host. * From patchwork Thu May 15 13:56:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890875 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 C20771990CD for ; Thu, 15 May 2025 13:56:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317400; cv=none; b=UNvxUKVTTG8ZoQTODFtrvf7hzbyL5Gj82fhgad2PrfJvxXNCOA+AcXCuEdqS5QGbjC1Naro4ks0QIkUZ+DCBavNvWB5CWVcdzr0gX5Pgn39ayPEiNgHMchosgmtY6nt2VdVlAscP+c/13ScvoychXX39fGTDnFtI3243PBbtPC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317400; c=relaxed/simple; bh=QZEDhRWPpLWiESbs7p40U6GD/qNi90W6pV5/ykEMmHA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YlPsFr1MY10jKvuxMp4pTE2iQsZVKuEmqmJHGE8glxyGlG6W1bTQ5SLv9gRrp98one7wtFfCwxGAjxGKd1AAGhHJaQBfOu+rVjLILmkCIFHTLvTHhzxJkWYQaa+7leQ9ige04jfqy1NCQ6HCrLOpBiESDYdcZs27zW8nXedw3no= 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=XXbNkKKz; arc=none smtp.client-ip=198.175.65.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="XXbNkKKz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317399; x=1778853399; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QZEDhRWPpLWiESbs7p40U6GD/qNi90W6pV5/ykEMmHA=; b=XXbNkKKzaS82ePDiUPaQm8sjFxh3KKmbEILcqMj+Z9xj1+LkJSlaVeR8 JOqx8iodimQNVIJ2raXmkpM/IuvY3DPDDaYwdtztc/2p34OsgTH85aki+ 7HvL0OXUwtALm75zQuZP1XIjxxroX8Ev+kw67Ppubq/1vswz0Qu4OORzq rRDPhEV4lobZFxXFf/OuiQBzAEr5Cf2ttvaZfIFdaz1EM8KMXRJWx6fu/ kAV7szjlFWTIy/MAK66iFtB0CBG4mqcudzOzAmV8k9QCKS1Pmlb7QD/tc AP+Ex1K+qM3zm4H9r0pXW3NGDD8wgyrDZ6pRsiHfnZrRWrPMnjNDesK22 g==; X-CSE-ConnectionGUID: kk717/0FRiS0on4T24MGJw== X-CSE-MsgGUID: KFUeY6YrRRO3KXcWUKRQXA== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270009" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270009" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:39 -0700 X-CSE-ConnectionGUID: wgE1TPn9S+yh6R670BeAww== X-CSE-MsgGUID: 3ZsPSkIZSvyAVIgvRShriw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372120" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:37 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 06/24] usb: xhci: refactor xhci_set_cmd_ring_deq() Date: Thu, 15 May 2025 16:56:03 +0300 Message-ID: <20250515135621.335595-7-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin 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 Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 28 +++++++++++++++------------- drivers/usb/host/xhci.h | 8 ++++---- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 66a9106d8b31..4c9174c5c7c7 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -497,19 +497,21 @@ static void xhci_enable_max_dev_slots(struct xhci_hcd *xhci) static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) { - u64 val_64; - - /* 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); + dma_addr_t deq_dma; + u64 crcr; + + 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 f8198ec02981..6c1758f8fd01 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 Thu May 15 13:56:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890569 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 98F7E1E3761 for ; Thu, 15 May 2025 13:56:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317402; cv=none; b=gAiWuAOs7MrDs3IJU1PmSJfD8nU3hgyovlxyq/Xkrhzm8Lxi+0htJ+4XIZskRxReE/eCxn+M1CKHhJ2g7l+Y87mVsSw6lCvlWwAHeRxjORn1ECXASlau/7wx/lr8ZDdLVJogQAzdvesO9gj7fjZaggKrZ/qWihEXbSMZ2ODjEjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317402; c=relaxed/simple; bh=urSmvmg72cnrRySazUZGliv/lQ2oOuNBAQJMvUdez7Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RrUU/vauMLpv7HQuypKBJQ0Dy+ZWuie38Ieyq753+tHdrqzzrHdQOIeHlyzlEpgHvwgr1px2N62P0jfHxtrtCyz2g4lbGOShJHrO5vIUDI6+So9/2H3gq/hf1Ivi29ID2qrWGmwxEUaDzW3kmMyl+ElI3wrdQNn7Qb2gIO8IKwI= 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=aDbNj4oI; arc=none smtp.client-ip=198.175.65.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="aDbNj4oI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317401; x=1778853401; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=urSmvmg72cnrRySazUZGliv/lQ2oOuNBAQJMvUdez7Q=; b=aDbNj4oISk3I6a9rx2/hHnY8yru79XQ+U0pICAQb7d/JCZMcQ1jMgbWl RGF+NufnGaGsjdam7QzkmD3maHPCwV80edBgz1n5Q20ceBDIuyx0Qj+mz AH1cwZOQHSd79xqZxTaW/r/j1CYJJP2V4jpOfUsuLNLAcgQTQ24B1duO5 UrneNuY0r8Sc65lHXyDOy7OXrGp7+2vNSAA6QcYK/whC/8orYkKI1RKbl 1GjR4RPUrFEjGzg3A2y04/2GyPh8x2dvP43w0F9YarLJgivEgDwtiqYYe W+EOBp7WOyFWXC5EYvBQT7+MGiiOTPwTP7JgqfcylT4b4eu3omWitzcg7 Q==; X-CSE-ConnectionGUID: kc6VRpZVRqCbOs0oXcV3mw== X-CSE-MsgGUID: nPLWRmg6Sjms/9z/DZEvAQ== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270013" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270013" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:41 -0700 X-CSE-ConnectionGUID: emdIgi45TG2Ftve9s2gkSw== X-CSE-MsgGUID: YWluSq8MTRylakpuihUQXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372130" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:39 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 07/24] usb: xhci: move DCBAA pointer write Date: Thu, 15 May 2025 16:56:04 +0300 Message-ID: <20250515135621.335595-8-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin 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 Signed-off-by: Mathias Nyman --- 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 c4b94f7bacfb..ac96f0155cab 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2434,7 +2434,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 4c9174c5c7c7..e8c262865188 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -545,6 +545,9 @@ static int xhci_init(struct usb_hcd *hcd) /* Set the address in the Command Ring Control register */ xhci_set_cmd_ring_deq(xhci); + /* Set Device Context Base Address Array pointer */ + xhci_write_64(xhci, xhci->dcbaa->dma, &xhci->op_regs->dcbaa_ptr); + /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { xhci->quirks |= XHCI_COMP_MODE_QUIRK; From patchwork Thu May 15 13:56:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890874 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 60272189915 for ; Thu, 15 May 2025 13:56:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317403; cv=none; b=OkUIUjrBolu57nt1AqUc/4yI61is0YVzLHLiqEeDUgU+e1ry/OM99pLz8tjC7Ksa1338atxtWQI/+/KfuIbWEGs6IbtZPS2RHiP+7kVgp7VCZHHJIMIVqrEYyGotrchzJAhX+je/J+QsAldn4FXv5elAz0k5LOHO7X7NAted8J0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317403; c=relaxed/simple; bh=Hkf238qAzYuhFYf8BimZrM4mszOFfj9yxXGC5DxjBNw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GEVvAqN6kQrQZGMquhJp4974RYyv6bId2+6dM1q7x2OHb9MAN+tYPjow18k3hdR6mBKvUv8hwsNwhRuHPcoYI06kskdrUcUF0NdyTK3Ay4FxAcQihHM8eHSqOgOum7+EocEcgEIaf2Kkf3r+Nf8QENFWx0wg6WEzhQ8iycNAI3g= 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=UYfKQ/vi; arc=none smtp.client-ip=198.175.65.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="UYfKQ/vi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317403; x=1778853403; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Hkf238qAzYuhFYf8BimZrM4mszOFfj9yxXGC5DxjBNw=; b=UYfKQ/vi5HLHsoUQ65EWSjCCzKhAHqpFy/NhLoqXqtGSgeBe1llFJpnU ty3laIqGLPYZGrDEwckmXNeRXyTsE9LZWh5IVdRql3GGPQaVuk0Nmt0EC HTlPm0nmOY0AYT9I0OdIziq4Hjzw9xKWrp1X++Fp0fYMu676cBXSImmVy V6/4J8O7N1ZY26ugPm4V7tMAO51CnVEQz7TSG5NMMDGWm/k1KdJaScNBI OnoZzkoCLlJsynCFg6TOu3rnD5+swAUyjykq/XLh7lUNKNf0BjuC0+D/6 ul+O+mPHKGiIr8dpR73+aTW3ahkOpc/Eks3gA8lytxpr4VHNPQIxtY3qi A==; X-CSE-ConnectionGUID: ReUibY4nSJWkoenGR2UcBw== X-CSE-MsgGUID: k42F6JOnT7+zd1C74oTVuA== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270018" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270018" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:42 -0700 X-CSE-ConnectionGUID: 7PF1ET4eQf+3a1vzYkL2OQ== X-CSE-MsgGUID: Ht/sC+uIRQqL7TkpZ/bpJw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372152" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:40 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 08/24] usb: xhci: move doorbell array pointer assignment Date: Thu, 15 May 2025 16:56:05 +0300 Message-ID: <20250515135621.335595-9-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin 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 Signed-off-by: Mathias Nyman --- 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 ac96f0155cab..2f4dbb67b1bf 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2419,7 +2419,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; /* @@ -2496,13 +2495,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 e8c262865188..0639d8b7372b 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -514,6 +514,16 @@ static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) xhci_write_64(xhci, crcr, &xhci->op_regs->cmd_ring); } +static void xhci_set_doorbell_ptr(struct xhci_hcd *xhci) +{ + u32 offset; + + offset = readl(&xhci->cap_regs->db_off) & DBOFF_MASK; + xhci->dba = (void __iomem *)xhci->cap_regs + offset; + xhci_dbg_trace(xhci, trace_xhci_dbg_init, + "Doorbell array is located at offset 0x%x from cap regs base addr", offset); +} + /* * Initialize memory for HCD and xHC (one-time init). * @@ -548,6 +558,9 @@ static int xhci_init(struct usb_hcd *hcd) /* Set Device Context Base Address Array pointer */ xhci_write_64(xhci, xhci->dcbaa->dma, &xhci->op_regs->dcbaa_ptr); + /* Set Doorbell array pointer */ + xhci_set_doorbell_ptr(xhci); + /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { xhci->quirks |= XHCI_COMP_MODE_QUIRK; From patchwork Thu May 15 13:56:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890568 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 A09241A0BD6 for ; Thu, 15 May 2025 13:56:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317405; cv=none; b=uwDCa3V+G6N3FPXFtCjaAYXKgYtKIAF+lcHtu3My1pAI6nmOzTqhOpNRhGycsZmp7lcLTHV45KTUTq7rPjlSHRcXn10ko2plZCKqY11gOpUMqKBPM2YpyQbyGWNQxpCInwztqaH/4e83AJGJj2e4xfeT42upwdTXLHRPJckGZ5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317405; c=relaxed/simple; bh=x3oV9MLHveOCbwIE/3DhSHNMvsocQkvK1JQip0Z+NnI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dn+kdnD/cqUbc+s+Vqh3GLdJFeee8Sp4IRya4ybi7MvTbHs7LOqq7pZpjl52tr0GUny7f38fgfobzCXLoM7N8tzC/TlzWdcqJatOT2s/P6rXIMcQ6wZH0UiAY6RBdkkRPxWSVWCRL21Zh5MsTXHbGbncUXLebfBUzui7iLKKXmo= 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=SfhZabhs; arc=none smtp.client-ip=198.175.65.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="SfhZabhs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317404; x=1778853404; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=x3oV9MLHveOCbwIE/3DhSHNMvsocQkvK1JQip0Z+NnI=; b=SfhZabhsoplmuvPAypjSQvJXtKAh4LhcnXHre5F5D270VhbvWle6hxQ3 42SIR8Mmt5V+S5gj7Lvp3DHfK3n4fhqciY3ZMUcAZAL7oMPLdcduksDnG FadoW1vHUZR5wdyWPo+YhWdhNDL03w1aKvHiXASw/0DWT/F9zo0nxZiUI SNllZ+hYdrZ+ofaWU+ATnVqI4Al69wg0Wgz9Eb3FRak3/SsUn2iHxWF+C IGhTmmSxTuLtXCBxA8NMf7hYtjMtJN3ialQolxRb1swy8RGTlEc4UF3A6 F51f/5B4Ojf0P7GC3XbK53STMiEJgP/+GAwM5C4wdeT14LirCNy/0OQKa g==; X-CSE-ConnectionGUID: F+vlt0ibT92ZM3i61JW91A== X-CSE-MsgGUID: DxLi6VVFRSCMpo8VE5PX9w== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270023" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270023" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:44 -0700 X-CSE-ConnectionGUID: PR8vwcy5RciUj7TqWtXW7A== X-CSE-MsgGUID: vVGHSN2MQVOuohAT9WpTYA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372174" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:42 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 09/24] usb: xhci: move enabling of USB 3 device notifications Date: Thu, 15 May 2025 16:56:06 +0300 Message-ID: <20250515135621.335595-10-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin 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 Signed-off-by: Mathias Nyman --- 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 2f4dbb67b1bf..718354bd7fb2 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2419,7 +2419,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 @@ -2515,15 +2514,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 0639d8b7372b..fa80cc30c3fe 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -524,6 +524,20 @@ static void xhci_set_doorbell_ptr(struct xhci_hcd *xhci) "Doorbell array is located at offset 0x%x from cap regs base addr", offset); } +/* + * Enable USB 3.0 device notifications for function remote wake, which is necessary + * for allowing USB 3.0 devices to do remote wakeup from U3 (device suspend). + */ +static void xhci_set_dev_notifications(struct xhci_hcd *xhci) +{ + u32 dev_notf; + + dev_notf = readl(&xhci->op_regs->dev_notification); + dev_notf &= ~DEV_NOTE_MASK; + dev_notf |= DEV_NOTE_FWAKE; + writel(dev_notf, &xhci->op_regs->dev_notification); +} + /* * Initialize memory for HCD and xHC (one-time init). * @@ -561,6 +575,9 @@ static int xhci_init(struct usb_hcd *hcd) /* Set Doorbell array pointer */ xhci_set_doorbell_ptr(xhci); + /* Set USB 3.0 device notifications for function remote wake */ + xhci_set_dev_notifications(xhci); + /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { xhci->quirks |= XHCI_COMP_MODE_QUIRK; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 6c1758f8fd01..31d945c4ac07 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 Thu May 15 13:56:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890873 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 4B92A189915 for ; Thu, 15 May 2025 13:56:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317406; cv=none; b=nckPVWGfTVpFTIyDcZRLBnX0Ci0ry6QrUuZa+25WeX3FeBchj9VoYT+WzWOlFPtSOBNTyu392PpquWS5HnZVM5OI67xSownZ017vwCck0JVPzGGu+SqNEvNfpSLOl1oSJXXWjrOw+trqHHVEPdP2KBRVua8ZHR+khePqrk5MtMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317406; c=relaxed/simple; bh=0libbAjaInygRtFKsO5/DBr/KSzoVJPMib1L4sSZjfE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FBsCWiLbIGfMlzxsvPZR2g355yqMMVe7W6FNADMiXuQtP9EvRNPR1T88Pjwll+4HKvFxdX/MrfaoKSVXoa9aK4Fl8wcBGCkqgIOWhtPBQp8HkH/cyqgsfakypGNWX5KummV3Sfgv4nVyd85/wHwTuYJYcNQS6b8ILTS1y+3sbJA= 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=IoXnfsPz; arc=none smtp.client-ip=198.175.65.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="IoXnfsPz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317406; x=1778853406; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0libbAjaInygRtFKsO5/DBr/KSzoVJPMib1L4sSZjfE=; b=IoXnfsPztFi+5JIhjrLndNcPMI497NKUVGPsoKoQfRpgPznI16paqzXe kKXqraKRBXMPvxzCiK/yaWGJnZiu3Y7nrqTuYnLRc0oI/JKDb83Bhimg6 e4gBKxDMBYsKcMTAF2FWkVXAw86VuDsV5sBqCRGBi3WxDBGUHu8iOY9yV CJbUykmtfWEcCv+axHpAeIrXUcn9nmWb8/L+CK0ZH0vhq98VuPwi+iE14 9UqXJ0RldX+VyTNj5uM+SuvXm7U6c4gQykkZhMFw/74bsrqzdhFOPa/Vl T4C29puWSZpmw0MSmXhNJvp7i3/MfypJS3/CGfW1onkI8dQ6PrY1dB2AL w==; X-CSE-ConnectionGUID: UV1wbi5JQX+WVreKd3O28w== X-CSE-MsgGUID: PTdNXNytRpev6l607tW8iw== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270031" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270031" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:46 -0700 X-CSE-ConnectionGUID: z4OwKEifQ/OqfBQi0CSJzQ== X-CSE-MsgGUID: oiNn7PjEQ/SAQ+huEyKhBA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372194" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:43 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 10/24] usb: xhci: remove error handling from xhci_add_interrupter() Date: Thu, 15 May 2025 16:56:07 +0300 Message-ID: <20250515135621.335595-11-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin 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 Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 718354bd7fb2..bfb01c432b23 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2321,24 +2321,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]; @@ -2359,8 +2348,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 * @@ -2385,13 +2372,16 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs, /* Find available secondary interrupter, interrupter 0 is reserved for primary */ for (i = 1; i < xhci->max_interrupters; i++) { if (!xhci->interrupters[i]) { - err = xhci_add_interrupter(xhci, ir, i); + xhci_add_interrupter(xhci, ir, i); + err = 0; break; } } } else { - if (!xhci->interrupters[intr_num]) - err = xhci_add_interrupter(xhci, ir, intr_num); + if (!xhci->interrupters[intr_num]) { + xhci_add_interrupter(xhci, ir, intr_num); + err = 0; + } } spin_unlock_irq(&xhci->lock); @@ -2504,8 +2494,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 Thu May 15 13:56:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890567 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 5FDBF1A2557 for ; Thu, 15 May 2025 13:56:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317408; cv=none; b=UcvCy25vTwbIguhy5T9OuAjx/Zo3uuRgkWGoF9iN2DPTGFJK1IHYiSNgxcYOJ6QeRTmc3mq3I7sCeOBFWXMxEEid5RZV53DyqtjWshRfapj6cMAVdqiHmpTWo+haDS4PM8TNJ/W8g+yJerogx5TEmLE/kysuNjaPWyu/bpEA8RI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317408; c=relaxed/simple; bh=yal4PAWwTc0iA37X+F1mnuFRea+QSnhIdr3sxrXBnEw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ovUjVsvnd4Aq2zaR8CTVoYnmGqMviPdkPrCdg1r/lY7zLJ+wSXJFkDURSqx/bXcEPJUIms+g7ipQ8GnI7UJjJIJSRqFzxBVtZOYvSb+bXXDx1TQv0R4bcYvu+FFIPnxY3zBdhbsqTMfrZ2XKBtaLiComQ7hk5feqdaTT1qeEkLE= 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=W9or2SgC; arc=none smtp.client-ip=198.175.65.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="W9or2SgC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317408; x=1778853408; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yal4PAWwTc0iA37X+F1mnuFRea+QSnhIdr3sxrXBnEw=; b=W9or2SgCxw3aqOzJD9lj6x1j46BT0w4CsIJ6YTwcVDRgE2HfK5upGoNn V39DL1jQYTIbvziA+DEgrpaHErl1G/Zz9CXszKhG7AYYwUR8hXGSYQFdG C+W2bGc7s3RumStXjT3lq4Vw1a981Ys6hlE/6sWFyNRD1x56uQJVQJFZo PUx6FRnYa6aI2LgArfxml0kzr7lvPh7eSiQQcAo6yUUVdyRfeDPRuwndB 77jba9Y+Od0NMuiFuimh7Yr7e2N2XON9Y3y7cQaoBe/DMHeW2mscdEN07 S8sjA5RnxHrBs3xPGKjMKMmd7WGyNbGBYuwFhRs0bz6GcgeWnp6rc9Ylf w==; X-CSE-ConnectionGUID: ofetMobqTtWFfAyoHPjN+A== X-CSE-MsgGUID: IEJqPxAYThyJ8PUU1InFdw== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270038" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270038" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:47 -0700 X-CSE-ConnectionGUID: Z6KxzsHxQAa+h/FC43JwzA== X-CSE-MsgGUID: vc/1jNuMS6GCHrdW6v1GPw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372210" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:45 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 11/24] usb: xhci: move initialization of the primary interrupter Date: Thu, 15 May 2025 16:56:08 +0300 Message-ID: <20250515135621.335595-12-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin 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 Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 22 +++++++++------------- drivers/usb/host/xhci.c | 4 ++++ drivers/usb/host/xhci.h | 1 + 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index bfb01c432b23..eb076f5ed1d0 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2321,14 +2321,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]; @@ -2372,14 +2371,16 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs, /* Find available secondary interrupter, interrupter 0 is reserved for primary */ for (i = 1; i < xhci->max_interrupters; i++) { if (!xhci->interrupters[i]) { - xhci_add_interrupter(xhci, ir, i); + xhci->interrupters[i] = ir; + xhci_add_interrupter(xhci, i); err = 0; break; } } } else { if (!xhci->interrupters[intr_num]) { - xhci_add_interrupter(xhci, ir, intr_num); + xhci->interrupters[intr_num] = ir; + xhci_add_interrupter(xhci, intr_num); err = 0; } } @@ -2406,7 +2407,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; @@ -2490,14 +2490,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 fa80cc30c3fe..c6b517401c94 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -578,6 +578,10 @@ static int xhci_init(struct usb_hcd *hcd) /* Set USB 3.0 device notifications for function remote wake */ xhci_set_dev_notifications(xhci); + /* Initialize the Primary interrupter */ + xhci_add_interrupter(xhci, 0); + xhci->interrupters[0]->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; + /* Initializing Compliance Mode Recovery Data If Needed */ if (xhci_compliance_mode_recovery_timer_quirk_check()) { xhci->quirks |= XHCI_COMP_MODE_QUIRK; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 31d945c4ac07..b0b16cd7df91 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1959,6 +1959,7 @@ void xhci_process_cancelled_tds(struct xhci_virt_ep *ep); void xhci_update_erst_dequeue(struct xhci_hcd *xhci, struct xhci_interrupter *ir, bool clear_ehb); +void xhci_add_interrupter(struct xhci_hcd *xhci, unsigned int intr_num); /* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, From patchwork Thu May 15 13:56:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890872 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 D7BEE189915 for ; Thu, 15 May 2025 13:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317410; cv=none; b=AYa0WRQoTXIpSkTKNCtuxM6ZwgDID9BTj74Euny9yrKmkaQ46t7HclDeC0nCCUAfhBtBB7wCLBaQIvA7goxTfdgSpdUDpQp1B6hGIOXx4x1ymUcQSkyFc89pPWnFNOOmjPZgfVwKqTxWpXM8/oI71+CrbyNTimBA6BtKxshnBXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317410; c=relaxed/simple; bh=AVIiMIWQZy/uanVXoizLMAyWlSQaKi2tM9mgsQkhkKE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OiOfPr5IKiAI559mveSk7qs4TBQwOXlxPYdpm53ek3IcwPcFvsjq81CjUIzLsPbTs56n8gtnuFv7J0K2Q7FcntDc/IodT5tiyfHqoICyQOH+ueReM8NuNf/cm9rSeopK0nI0eFNexnOs2Eo4N3it6Vn1z6cZiC6Z6BhEqu8GqVo= 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=VakCIPHs; arc=none smtp.client-ip=198.175.65.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="VakCIPHs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317409; x=1778853409; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AVIiMIWQZy/uanVXoizLMAyWlSQaKi2tM9mgsQkhkKE=; b=VakCIPHs1utOjS4nTbUTzBDOFPx4GlvPupV6JnLQfodWPiHMiA/Mui/Q QY8ekS9h8BTvJ7xzPMIYiAEL4Q2LqaQZfB7hl8a7Vd9lFK+O7MRqG83+M IOmR0vOR696wSiZcX9cBpG4wgnVvNCrdfmTaogKAg5+ps6RVZ5UT1PsR0 HCdjBcdspGIvA+wqgz2L4B1KnzmO7w48qYXFTThr3HI0BUPfdjbI7iYr0 dclfE38dw7cXhAwW1+mMJENefgBoZ8eSdZPNe65RJ6060xVgjjh6fnps1 ioge6lsarE1eopZwWLBv8tbYxNG8OmY0d9+90vVYhcjiINmI+L51MTXDV A==; X-CSE-ConnectionGUID: CzNOtP8WS8GkTmnOpIFwbg== X-CSE-MsgGUID: TSs1hIIbQ4SJ0C+QPKDYLA== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270040" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270040" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:49 -0700 X-CSE-ConnectionGUID: Gmn7atP5RKigh3niad84/w== X-CSE-MsgGUID: zpap/U4lRZWsGMibA8LBsA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372237" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:47 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 12/24] usb: xhci: add individual allocation checks in xhci_mem_init() Date: Thu, 15 May 2025 16:56:09 +0300 Message-ID: <20250515135621.335595-13-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin Break up the existing multi-allocation checks into individual checks. Add missing allocation check for 'xhci->interrupters'. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index eb076f5ed1d0..8cadd785ac0e 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2437,11 +2437,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, @@ -2450,12 +2452,17 @@ 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); /* Any stream context array bigger than MEDIUM_STREAM_ARRAY_SIZE * will be allocated with dma_alloc_coherent() */ + if (!xhci->medium_streams_pool) + goto fail; /* refer to xhci rev1_2 protocol 5.3.3 max ports is 255. * refer to xhci rev1_2 protocol 6.4.3.14 port bandwidth buffer need @@ -2464,9 +2471,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) xhci->port_bw_pool = dma_pool_create("xHCI 256 port bw ctx arrays", dev, GET_PORT_BW_ARRAY_SIZE, 16, 0); - - if (!xhci->small_streams_pool || !xhci->medium_streams_pool || - !xhci->port_bw_pool) + if (!xhci->port_bw_pool) goto fail; /* Set up the command ring to have one segments for now. */ @@ -2489,6 +2494,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 Thu May 15 13:56:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890566 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 282431A2557 for ; Thu, 15 May 2025 13:56:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317411; cv=none; b=bu5Y4OR7UsqyqZbCqC2mCI3QFwrsqa1N/s/9TjRy3mOtfZdNT3tQ+RrZY8kGcC9k0w4ZqtNNnPaMHvQtKm3zP6LxZuNTg0zudbneFTot0nBAKBped90MidnydCJBqfA0A5kX4yROdt16whlTp/5fO/DqM6zY274a9+SBGwisDjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317411; c=relaxed/simple; bh=+OYHLXnnZ8oWDQqUhk9kc18xUGV79y4C3n2wGzzm69k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MHu9T40rxhPYXN17Jq7Kih8xUwYyI6FkQUJxzshcXl37rca2PC3VHUll5FP2l+3hF4zRSjOxg2TluBDtwInfqVNHKmMWwTcZ4cH7dq/lJ/ZFLYpUWPtdwGmRqINvzXG7818RpuAu4qYaW7XfTpa22rXhDN8CAoBT+Q2s9b9UT6c= 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=dl6D2yDD; arc=none smtp.client-ip=198.175.65.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="dl6D2yDD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317411; x=1778853411; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+OYHLXnnZ8oWDQqUhk9kc18xUGV79y4C3n2wGzzm69k=; b=dl6D2yDD8SHuSBlf8/OkHZMbzAyhL5Bb+VkL1fCLR7YkeZb9COpkI4wN 2a9DoCWjp9UufgjTzL9nCaWsSzRHSbUhJBgACX/PrRQtrJdbx1FCqgWpe UNGzqJhjFj5o2VvNHQtMVPeB7K6wvo125s6ZgYiHSZelxFd+BR1aSUhY1 gwsmXxGsK04m1tTkxS4Q4p059UA7AnG/HXqrRD7pt7r6CuRgrv+7nDsXx vDeB8vQiOBqdx+MqvaPzYjrYMoOOxZFxETCfYl+DOqmZdZy8QB+HqIvAh 4dbYWN+5k85a7y5HYjhOGRLV4SRJuyz8Vjhr2nVuDqQQaSOqriECAqEGL Q==; X-CSE-ConnectionGUID: gGl6NlwASBmaFOfnXLy0aw== X-CSE-MsgGUID: IUimQOyWT26wHFHCJQVgXw== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270047" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270047" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:50 -0700 X-CSE-ConnectionGUID: y+0UwViMSreANGS1N4M2gQ== X-CSE-MsgGUID: A9Jug/sTQAG72Rw1Ib0DrA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372257" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:48 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 13/24] usb: xhci: cleanup xhci_mem_init() Date: Thu, 15 May 2025 16:56:10 +0300 Message-ID: <20250515135621.335595-14-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin Cleanup indentation, spacing and comment formats. Remove the "// " prefix from trace messages, as it is unnecessary and distracting. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 52 +++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 8cadd785ac0e..08513e5d321a 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2414,14 +2414,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 @@ -2441,36 +2441,37 @@ 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; - /* refer to xhci rev1_2 protocol 5.3.3 max ports is 255. + /* + * refer to xhci rev1_2 protocol 5.3.3 max ports is 255. * refer to xhci rev1_2 protocol 6.4.3.14 port bandwidth buffer need * to be 16-byte aligned. */ - xhci->port_bw_pool = - dma_pool_create("xHCI 256 port bw ctx arrays", - dev, GET_PORT_BW_ARRAY_SIZE, 16, 0); + xhci->port_bw_pool = dma_pool_create("xHCI 256 port bw ctx arrays", + dev, GET_PORT_BW_ARRAY_SIZE, 16, 0); if (!xhci->port_bw_pool) goto fail; @@ -2478,20 +2479,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, "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); + &xhci->cmd_ring->first_seg->dma); - /* Reserve one command ring TRB for disabling LPM. + /* + * 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) @@ -2503,6 +2504,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; From patchwork Thu May 15 13:56:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890871 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 C74D11AF0C7 for ; Thu, 15 May 2025 13:56:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317413; cv=none; b=q3ymfwIzSsyUgIp3RTb4WVfIqp93HfEr1VFSl5GIVGmLrfdoOULjXBPNiGlrVBU+HODg73noenUPLqTrYzWqRQhqRbxvGMF5Emei6DzVw4RWgRWES6pATdKs6HiW6iJcmRiJ8xUujIPZXS/qApQ1HI3fI/sy5X5xO51xHVNYyt0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317413; c=relaxed/simple; bh=SB6/qac79QA5rG03Zep6Ww6TysQENB1XznR99XO5N/U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WwFu5OK4JjONmuqgc96s03Qp2v6aH8RE8Ld9PpqkXUxH9KxWusFahBAW3Yqe/aIJ9xSucEOPWXe9GIBVor1G17Xog7zF+hA4/z3625vh5CJT8CGkdmCwohxcTwcfzn9EK+MwGjsEFZ/j78heKQHrDRybHzmifgR1F7ORHd7xTQM= 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=fexOLHT/; arc=none smtp.client-ip=198.175.65.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="fexOLHT/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317412; x=1778853412; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SB6/qac79QA5rG03Zep6Ww6TysQENB1XznR99XO5N/U=; b=fexOLHT/+wjeTUnVBlxED2Jv/6eHE+2bnDaGwY4ei4Bu/Zsl4vDZIHie 6/nQ2SWs6wah7lS6eJnoWukoh0cMsregJexiq7qV4C597sAdYxHYSFEeP ezGw+bN7tbpT1xbJxeRfTkrvHDxe11Ev2Vk2fgeDuWSzrgbIGYtgLEZfl 8Zi1OLoOJ5E6LX6SOXcVAOcl/PdKspQR30oPf/FgqUEO5kFBXRVZ/qKQJ EhCwz3NJQEN5+xWgXS0DW/dX+V/ld0qd2zPG47v5fM8+Lmm1SQjs9/2WF A0EUhX40AHRrih+ZdI54WWhgHR4hP5c+DpqFcvc83o6McnXTcxGlbkj0o w==; X-CSE-ConnectionGUID: 5OxHqr/jQVicmvJwS2c4ew== X-CSE-MsgGUID: W+O8ibPQTiiItWjXy2/RWQ== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270055" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270055" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:52 -0700 X-CSE-ConnectionGUID: WsxHU7cOTCOr95RDPM8a5g== X-CSE-MsgGUID: lGcspmqDQxigH4glauCQbA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372277" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:50 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 14/24] usb: xhci: set requested IMODI to the closest supported value Date: Thu, 15 May 2025 16:56:11 +0300 Message-ID: <20250515135621.335595-15-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin The function configures the Interrupt Moderation Interval (IMODI) via bits 15:0 in the Interrupt Moderation Register. The IMODI value is specified in increments of 250 nanoseconds. For instance, an IMODI register value of 16 corresponds to 4000 nanoseconds, resulting in an interrupt every ~1ms. Currently, the function fails when a requested IMODI value is too large, only logging a warning message for secondary interrupters. Prevent this by automatically adjusting the IMODI value to the nearest supported value. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 5 +---- drivers/usb/host/xhci.c | 7 +++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 08513e5d321a..dcfe7774e9ed 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2393,10 +2393,7 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs, return NULL; } - err = xhci_set_interrupter_moderation(ir, imod_interval); - if (err) - xhci_warn(xhci, "Failed to set interrupter %d moderation to %uns\n", - i, imod_interval); + xhci_set_interrupter_moderation(ir, imod_interval); xhci_dbg(xhci, "Add secondary interrupter %d, max interrupters %d\n", ir->intr_num, xhci->max_interrupters); diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index c6b517401c94..c3a1a67b6563 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -355,12 +355,15 @@ int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, { u32 imod; - if (!ir || !ir->ir_set || imod_interval > U16_MAX * 250) + if (!ir || !ir->ir_set) return -EINVAL; + /* IMODI value in IMOD register is in 250ns increments */ + imod_interval = umin(imod_interval / 250, ER_IRQ_INTERVAL_MASK); + imod = readl(&ir->ir_set->irq_control); imod &= ~ER_IRQ_INTERVAL_MASK; - imod |= (imod_interval / 250) & ER_IRQ_INTERVAL_MASK; + imod |= imod_interval; writel(imod, &ir->ir_set->irq_control); return 0; From patchwork Thu May 15 13:56:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890565 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 CAC3A1F4E39 for ; Thu, 15 May 2025 13:56:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317415; cv=none; b=sJS6dRUoY5JM1lD2TXc3frxqBqUFfgm3OUVQBQCWzmeR4dRi90oEo4EJeL7N6rv37K2slvEic29lgSM8kMZ3IcRjyWmcLTMrPw/T3XxJ+GoVQ/lRyeaVlnGoBMWZflp/XYK7lALNsPKPVbQsbHi5CSLCw51qjiP7Ko1xXHLquqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317415; c=relaxed/simple; bh=l5IVKatMUFrq0KHqFhtXf+4Ua0sowlFP1pm3oYP/Q9o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eSDBI30qi9oTDlxNln73j/J/GH/i+TVtjRKvncBlzMk9cPRMoM7Uq0jn/FGZoykFbUOjnBoK8RJ1ioNF94yBHLOuGVZerEpN13isab5w+hWuxrARQW28qthu07CBw+XIZUc8Bx42Jd7QA/CNQcENzn4CtEktCX4phbV1UD/3z/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=RSUSgHid; arc=none smtp.client-ip=198.175.65.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="RSUSgHid" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317414; x=1778853414; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l5IVKatMUFrq0KHqFhtXf+4Ua0sowlFP1pm3oYP/Q9o=; b=RSUSgHidx//HFEmCa+bclxQmcyL7Pf3x2BwZPOhqhUe8kAngUvT1Raki w6KRi4ZV0RgRMW0IP0yNRktQ/Gw20NzaVT6P8T8yF+wMCwJMOEER2FB/K A0b6hF8GRL3Ka/RjQ1wMEagMSsn3FPKMIfSykLjZDklOR5DaMlevdW5cX g54aCM+kFUzrDeJ79EirJrq97Qr/ljKCLukjg5uxMs6H1hkog710j8y8y sPMw5CRKMhsGEDq1BF0RRuK1azfaq72AuWWZiHCH1kyQ5pTorlmrxiP5T yNvBAOambxVNJth9vjnWEsOonarHW7Sgs3Z664R919gDH4C5CZPHEon6z w==; X-CSE-ConnectionGUID: seQR6vS6TUOQlk/MYBuumg== X-CSE-MsgGUID: BzN2yxWYRh2nL2SQEiBLYQ== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270063" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270063" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:54 -0700 X-CSE-ConnectionGUID: +tulBT5+Tk6w6OoTW526Pw== X-CSE-MsgGUID: Uuq64x39SZW/4w6a/GLxLQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372291" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:52 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 15/24] usb: xhci: improve Interrupt Management register macros Date: Thu, 15 May 2025 16:56:12 +0300 Message-ID: <20250515135621.335595-16-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin The Interrupt Management register (IMAN), contains three fields: - Bit 0: Interrupt Pending (IP) - Bit 1: Interrupt Enable (IE) - Bits 31:2: RsvdP (Reserved and Preserved) Currently, there are multiple macros for both the IP and IE fields. Consolidates them into single mask macros for better clarity and maintainability. Comment "THIS IS BUGGY - FIXME - IP IS WRITE 1 TO CLEAR" refers to the fact that both macros 'ER_IRQ_ENABLE' and 'ER_IRQ_DISABLE' clear the IP bit by writing '0' before modifying the IE bit. However, the IP bit is actually cleared by writing '1'. To prevent any regression, this behavior has not been altered. Instead, when the IE bit is modified, the IP macro is used explicitly to highlight this "quirk". Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 8 ++++++-- drivers/usb/host/xhci.h | 14 ++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index c3a1a67b6563..472589679af3 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -331,7 +331,9 @@ int xhci_enable_interrupter(struct xhci_interrupter *ir) return -EINVAL; iman = readl(&ir->ir_set->irq_pending); - writel(ER_IRQ_ENABLE(iman), &ir->ir_set->irq_pending); + iman &= ~IMAN_IP; + iman |= IMAN_IE; + writel(iman, &ir->ir_set->irq_pending); return 0; } @@ -344,7 +346,9 @@ int xhci_disable_interrupter(struct xhci_interrupter *ir) return -EINVAL; iman = readl(&ir->ir_set->irq_pending); - writel(ER_IRQ_DISABLE(iman), &ir->ir_set->irq_pending); + iman &= ~IMAN_IP; + iman &= ~IMAN_IE; + writel(iman, &ir->ir_set->irq_pending); return 0; } diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index b0b16cd7df91..28c4ad7534c1 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -152,10 +152,6 @@ struct xhci_op_regs { #define XHCI_RESET_LONG_USEC (10 * 1000 * 1000) #define XHCI_RESET_SHORT_USEC (250 * 1000) -/* IMAN - Interrupt Management Register */ -#define IMAN_IE (1 << 1) -#define IMAN_IP (1 << 0) - /* USBSTS - USB status - status bitmasks */ /* HC not running - set to 1 when run/stop bit is cleared. */ #define STS_HALT XHCI_STS_HALT @@ -240,12 +236,10 @@ struct xhci_intr_reg { }; /* irq_pending bitmasks */ -#define ER_IRQ_PENDING(p) ((p) & 0x1) -/* bits 2:31 need to be preserved */ -/* THIS IS BUGGY - FIXME - IP IS WRITE 1 TO CLEAR */ -#define ER_IRQ_CLEAR(p) ((p) & 0xfffffffe) -#define ER_IRQ_ENABLE(p) ((ER_IRQ_CLEAR(p)) | 0x2) -#define ER_IRQ_DISABLE(p) ((ER_IRQ_CLEAR(p)) & ~(0x2)) +/* bit 0 - Interrupt Pending (IP), whether there is an interrupt pending. Write-1-to-clear. */ +#define IMAN_IP (1 << 0) +/* bit 1 - Interrupt Enable (IE), whether the interrupter is capable of generating an interrupt */ +#define IMAN_IE (1 << 1) /* irq_control bitmasks */ /* Minimum interval between interrupts (in 250ns intervals). The interval From patchwork Thu May 15 13:56:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890870 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 BDE4C1F582A for ; Thu, 15 May 2025 13:56:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317417; cv=none; b=i3GZz2tQn0uMjDpuXTj/J0jyOhyrOvjfS275QHi+kQ6Bt8I3+ECgwkUwA+S5kPcS4yCU833xrYdohtZ10zB4sW7j/GKYDNO94mvfAUZzyKIaFfTldn6sLwK6PDwscOmSoDKAhMCafTkp0UoMOaY9PxHx656Ki+lvf7PQA4xD678= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317417; c=relaxed/simple; bh=hpBBAyn6Jojy6JZR07ETLPDrDcOall1hmF5KaLE7QsM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qqv8c0wZ3IDqEW2147wZQd6WrU4ESPdmSfxw65QC/Af0zmnBYATgSrfBlnzz7pDc9ZbfF5cvpmBKV8rCHp1VWM7N+FVkZduy0uVjulpXiJZPM89h/jccBZzR25glUzkwWk+Txoj27VadbHiVbobGgle6GWLPVzoybzXcq6fMuYs= 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=CKDZ6vkD; arc=none smtp.client-ip=198.175.65.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="CKDZ6vkD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317416; x=1778853416; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hpBBAyn6Jojy6JZR07ETLPDrDcOall1hmF5KaLE7QsM=; b=CKDZ6vkD3DS35DRirfmZLWeuWsQ6P5drsMBlil+31H48Kx4MaydzpsNT zRMPnqk7Uw6o+Iv4ULlIxuCGvshnBuUQ+YKaf19LCpMXHTW1SOKaIeSdC 86d53gPBt8ipoBdHYaIzgWrRr3+vUNsk2pT7cI1mdkwXO8wkY7eq6eW1d 68Sr605r53D8MDhX9Lqo4Dj03ajRpNIc01zWSZEzRT2Rhjo+/Bw76cGUt ++iwo3ofuClj0Cl+8qm++3nr2i8D92SJn39tup2/pvwm2oxpL1xvW/tO5 GgCr+k4U+YWVUk0gJp9+6qD2vaBizI53OyrDih4WndRR2rl8sNAa6vUKU g==; X-CSE-ConnectionGUID: oPVkNr7kTGmnw7Vhv9irkQ== X-CSE-MsgGUID: GFSeoKp/SkiUWSekdaOLwQ== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270074" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270074" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:56 -0700 X-CSE-ConnectionGUID: fV61yj6VQZyOWdzy1OTX0g== X-CSE-MsgGUID: I40NIcTNQqyWSWTg5ezQmw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372312" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:53 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 16/24] usb: xhci: guarantee that IMAN register is flushed Date: Thu, 15 May 2025 16:56:13 +0300 Message-ID: <20250515135621.335595-17-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin Add read call to guarantee that the write to the IMAN register has been flushed. xHCI specification 1.2, section 5.5.2.1, Note: "Most systems have write buffers that minimize overhead, but this may require a read operation to guarantee that the write has been flushed from the posted buffer." Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 3 +++ drivers/usb/host/xhci.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 9607f75b8d2a..91a9ad687704 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3088,6 +3088,9 @@ static void xhci_clear_interrupt_pending(struct xhci_interrupter *ir) irq_pending = readl(&ir->ir_set->irq_pending); irq_pending |= IMAN_IP; writel(irq_pending, &ir->ir_set->irq_pending); + + /* Read operation to guarantee the write has been flushed from posted buffers */ + readl(&ir->ir_set->irq_pending); } } diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 472589679af3..8cdb1a01a3ed 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -335,6 +335,8 @@ int xhci_enable_interrupter(struct xhci_interrupter *ir) iman |= IMAN_IE; writel(iman, &ir->ir_set->irq_pending); + /* Read operation to guarantee the write has been flushed from posted buffers */ + readl(&ir->ir_set->irq_pending); return 0; } @@ -350,6 +352,7 @@ int xhci_disable_interrupter(struct xhci_interrupter *ir) iman &= ~IMAN_IE; writel(iman, &ir->ir_set->irq_pending); + readl(&ir->ir_set->irq_pending); return 0; } From patchwork Thu May 15 13:56:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890564 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 63E8F1F7580 for ; Thu, 15 May 2025 13:56:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317418; cv=none; b=ENS2/Pp8r3BjT+FYl7a6EpDLjHtBgk1ynw23/BSBL8kuMC4NQq1BtvMggDRhreRRhV9c9jdk8NKcQkPha5gTTF9tDbLrA9Ey+vZJ0MGaFyjIpBSzx/fHpCt1H8QkVYkhbu5iCzhrrEfiS/nBeO+Bc0OUOFvaSpgnZ1eTk3g/S1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317418; c=relaxed/simple; bh=SU5S+vcTaKKuSKuMX5VoeYyPyuLtmdQubi15vwTw4rc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cACugbCrCpp9ZOW7HdAHn+Bf01RhPTA6SIuKCn9+MCvUAIPmBNa4R+rxRBzN/gEUELoGtxkeCqjwOyV99Qh2FZVvpi++irJm2g79tun4RPIh2+7hi4wOyyH4xzZKVPYAOejSAyFJZRrYT/ls2M19vdCyJz7QOxk9IF2F0339g+M= 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=kS+bDoaR; arc=none smtp.client-ip=198.175.65.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="kS+bDoaR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317418; x=1778853418; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SU5S+vcTaKKuSKuMX5VoeYyPyuLtmdQubi15vwTw4rc=; b=kS+bDoaRZ3saS2dEaRl7bBfMwGNKEA6bb53EjL8/k9K7s/CGu3wmosqZ 5mUf7y2Xzs9Yi1BodHGrt5rS6vtCL1AeLyAT1rxpl4lX1l3ldg/CwaPeY aEkWH14hdFp8Z3ft4rmKma6F7kGoVquzVn1Jo8n7hCoZRL4hheDUb5sRs VmBNoHNOveh5mbMM4htID+r/4Kmqa1uB1qd7wjKufNj7MZwWlVFcLWPxc /5pWlqS46uzgJRd9IXMm/FUugqWTbSWSbei/VDTgy/ElV8A0d1hHq5nMK ugH5aIpcv4hSaurF7JRY/+nDF28MqnL09MWxty/JjVZdGII66nWgDL/Ic Q==; X-CSE-ConnectionGUID: w5CH2Y8BQzOMHxuv+NXCBw== X-CSE-MsgGUID: G+pLR7xaSiubVwufz9X2gg== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270078" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270078" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:58 -0700 X-CSE-ConnectionGUID: wHxdnbIvTC6v42Gkyorqkw== X-CSE-MsgGUID: VFMNI56DQYe0zw/yGQagcg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372330" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:55 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 17/24] usb: xhci: remove '0' write to write-1-to-clear register Date: Thu, 15 May 2025 16:56:14 +0300 Message-ID: <20250515135621.335595-18-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin xHCI specification 1.2, section 5.5.2.1. Interrupt Pending bit is RW1C (Write-1-to-clear), which means that writing '0' to is has no effect and is removed. The Interrupt Pending (IP) bit is cleared at the start of interrupt handling; xhci_clear_interrupt_pending(). This could theoretically cause a new interrupt to be issued before the xhci driver reaches the interrupter disable functions. To address this, the IP bit is read after Interrupt Enable is disabled, and a debug message is issued if the IP bit is still set. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-hub.c | 2 +- drivers/usb/host/xhci-ring.c | 2 +- drivers/usb/host/xhci.c | 13 +++++++------ drivers/usb/host/xhci.h | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 486347776cb2..92bb84f8132a 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -1907,7 +1907,7 @@ int xhci_bus_resume(struct usb_hcd *hcd) * prevent port event interrupts from interfering * with usb2 port resume process */ - xhci_disable_interrupter(xhci->interrupters[0]); + xhci_disable_interrupter(xhci, xhci->interrupters[0]); disabled_irq = true; } } diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 91a9ad687704..9efa0d1735df 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3167,7 +3167,7 @@ void xhci_skip_sec_intr_events(struct xhci_hcd *xhci, dma_addr_t deq; /* disable irq, ack pending interrupt and ack all pending events */ - xhci_disable_interrupter(ir); + xhci_disable_interrupter(xhci, ir); /* last acked event trb is in erdp reg */ erdp_reg = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 8cdb1a01a3ed..6c4bbabc3a70 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -331,7 +331,6 @@ int xhci_enable_interrupter(struct xhci_interrupter *ir) return -EINVAL; iman = readl(&ir->ir_set->irq_pending); - iman &= ~IMAN_IP; iman |= IMAN_IE; writel(iman, &ir->ir_set->irq_pending); @@ -340,7 +339,7 @@ int xhci_enable_interrupter(struct xhci_interrupter *ir) return 0; } -int xhci_disable_interrupter(struct xhci_interrupter *ir) +int xhci_disable_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir) { u32 iman; @@ -348,11 +347,13 @@ int xhci_disable_interrupter(struct xhci_interrupter *ir) return -EINVAL; iman = readl(&ir->ir_set->irq_pending); - iman &= ~IMAN_IP; iman &= ~IMAN_IE; writel(iman, &ir->ir_set->irq_pending); - readl(&ir->ir_set->irq_pending); + iman = readl(&ir->ir_set->irq_pending); + if (iman & IMAN_IP) + xhci_dbg(xhci, "%s: Interrupt pending\n", __func__); + return 0; } @@ -754,7 +755,7 @@ void xhci_stop(struct usb_hcd *hcd) "// Disabling event ring interrupts"); temp = readl(&xhci->op_regs->status); writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); - xhci_disable_interrupter(ir); + xhci_disable_interrupter(xhci, ir); xhci_dbg_trace(xhci, trace_xhci_dbg_init, "cleaning up memory"); xhci_mem_cleanup(xhci); @@ -1189,7 +1190,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool power_lost, bool is_auto_resume) xhci_dbg(xhci, "// Disabling event ring interrupts\n"); temp = readl(&xhci->op_regs->status); writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); - xhci_disable_interrupter(xhci->interrupters[0]); + xhci_disable_interrupter(xhci, xhci->interrupters[0]); xhci_dbg(xhci, "cleaning up memory\n"); xhci_mem_cleanup(xhci); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 28c4ad7534c1..fc6b97add7fa 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1900,7 +1900,7 @@ int xhci_alloc_tt_info(struct xhci_hcd *xhci, int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, u32 imod_interval); int xhci_enable_interrupter(struct xhci_interrupter *ir); -int xhci_disable_interrupter(struct xhci_interrupter *ir); +int xhci_disable_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir); /* xHCI ring, segment, TRB, and TD functions */ dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb); From patchwork Thu May 15 13:56:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890869 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 079B51C7013 for ; Thu, 15 May 2025 13:56:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317420; cv=none; b=OynelbE2i1jevWx/hVVbS5byMkbIFc+/y7OoVplRoR9yvovKHw0BrLA5s5X7KBjLs4aeEyt5Gm4QeUidMGMse53SPfIymnr+pkzUUuxXsp6ZdAVB3aUkt9+CSRQtAM68KWINrLupTQYjBKskhqZcKhfuy/0eDm4A+lku1hS1wFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317420; c=relaxed/simple; bh=SXiypzDrS+KRMHOqGROjYTVYCkDONtv+xUn4GsxUIE4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X+ow+rRH9/rw3RK23iQ8gJN5USml8RQkVkdSujmkDCpQHeditWi2kR7pVGxKq9ktSlo76iRyAjSWY4pm7jVzsXh9iQr4JMmN7zxTeNz2RkBqP+iB7Y+3FYqYmECxkWTDAOAPnvjwJuyaHjrOH5ns+37NE36pzkD4g6k9tzE8KPE= 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=aON0iA8I; arc=none smtp.client-ip=198.175.65.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="aON0iA8I" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317419; x=1778853419; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SXiypzDrS+KRMHOqGROjYTVYCkDONtv+xUn4GsxUIE4=; b=aON0iA8ITitr2G/xv+DhWT/Y5BZRvu7nCMiPaDjs9tGTsE91c/sbqWKF aQD50jaNbBr14kL6E1RePlMTrFZnm3oK+LcUdrnW61M5SOsbFU6pFb9dT JwRVUw6ieyfE0RIkHe90WwnBAypr4rm/tbnD329k1KBT3kpAF1YYpICRA GfiVsqpiMLw14h8trJZJxtpsk4LQhlm2h5W76xV4HkDaq5e4bmN2qHgVc oRUQR1nN00kx8qlAsPwxDljcMtHOCW4TA2ZV2EPqQ8EbCcKzLkVAJCH6m J2g9MHfoHvy9r9WjTRFHCfZ6p+xTUs25L4V0VocKLjGcfuPiLSyvEsJBV g==; X-CSE-ConnectionGUID: gZOB8gT9Qx+1RiJwtwTP+A== X-CSE-MsgGUID: mtlGQN3IT82ScO/a32c9AQ== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270082" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270082" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:56:59 -0700 X-CSE-ConnectionGUID: w5x6/XFbTp2WYuiRkgyGtA== X-CSE-MsgGUID: yUrobXpaRma4FiITXWkR0g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372345" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:57 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 18/24] usb: xhci: rework Event Ring Segment Table Size mask Date: Thu, 15 May 2025 16:56:15 +0300 Message-ID: <20250515135621.335595-19-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin Event Ring Segment Table Size Register contain two fields: - Bits 15:0: Event Ring Segment Table Size - Bits 31:16: RsvdZ (Reserved and Zero) The current mask 'ERST_SIZE_MASK' refers to the RsvdZ bits (31:16). Change the mask to refer to bits 15:0, which are the Event Ring Segment Table Size bits. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 4 ++-- drivers/usb/host/xhci.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index dcfe7774e9ed..ec2c4851c689 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1831,7 +1831,7 @@ xhci_remove_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir) */ if (ir->ir_set) { tmp = readl(&ir->ir_set->erst_size); - tmp &= ERST_SIZE_MASK; + tmp &= ~ERST_SIZE_MASK; writel(tmp, &ir->ir_set->erst_size); xhci_update_erst_dequeue(xhci, ir, true); @@ -2333,7 +2333,7 @@ void xhci_add_interrupter(struct xhci_hcd *xhci, unsigned int intr_num) /* set ERST count with the number of entries in the segment table */ erst_size = readl(&ir->ir_set->erst_size); - erst_size &= ERST_SIZE_MASK; + erst_size &= ~ERST_SIZE_MASK; erst_size |= ir->event_ring->num_segs; writel(erst_size, &ir->ir_set->erst_size); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index fc6b97add7fa..19dd47d76140 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -251,8 +251,8 @@ struct xhci_intr_reg { #define ER_IRQ_COUNTER_MASK (0xffff << 16) /* erst_size bitmasks */ -/* Preserve bits 16:31 of erst_size */ -#define ERST_SIZE_MASK (0xffff << 16) +/* bits 15:0 - Event Ring Segment Table Size, number of ERST entries */ +#define ERST_SIZE_MASK (0xffff) /* erst_base bitmasks */ #define ERST_BASE_RSVDP (GENMASK_ULL(5, 0)) From patchwork Thu May 15 13:56:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890563 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 AFD4C1FECD3 for ; Thu, 15 May 2025 13:57:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317422; cv=none; b=FnDXTxwQdTsUboLQlThIWpN0gsM2ege6yNfJOd4XJtJ0wCbsMPu1fd1ocXMCaCUqGPAV44M0xm2uVbwUM9pvEKfXS7cAMZhQemAh2feec8fXvL8GLtEKldTXlSKCwZHsSaKVps9xnOiX8E86TCetl/98lHso1gay5vFpQLZrDb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317422; c=relaxed/simple; bh=ZnPVSt0T1VO8v43cvOGNjk4r5PSCnocyhK1LdwZ8Dto=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YDyQ/7zMKquE633px4wzqbyFWBS2LG/+z8JlDrCxCiz0jVKmTKsBJNHRknCwbZk4UvfeeWR7S9KbBFbU10oLoVeaZDiISOpHf4M3ZnZI+2cBbJXo647fU1+bFOGJh3iE12cjG6hEBXjpwuBVO468Cg/dwu3IU8+SjpHyhr9FqLM= 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=HTDiUd29; arc=none smtp.client-ip=198.175.65.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="HTDiUd29" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317421; x=1778853421; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZnPVSt0T1VO8v43cvOGNjk4r5PSCnocyhK1LdwZ8Dto=; b=HTDiUd292nVmM17tkDjbnQZb2c3TIb2SRpDRFtCPD/U1RcxYNqAfmuli WL62YfP/0+QYd/XfJrCcdKDS5UReYo6cggfN9/gqTkr8Vf9ZHHqkw8FoH MCXfkz8MW8luoWiSxOFuM+3g9494Sz+XVPzaijb1qZMIsEvbLXrkQiudQ unPhBNI26WV9adH+Rox2WHUIAUuCzX1foizs++W0phxkFUzux+V5BNKxS hf8JwitcBtl2E1eHizwu7HEgsq9vjMTPLtBvj7NEFt0fP0kEy/BqnAK+L QTvBOYqYDpG2EKXFJfunnKO94ryWLXhJxgoKzefBK0fv5wNJH3pp2rf+q w==; X-CSE-ConnectionGUID: K8m61cEKQSmAERPv5FgXrw== X-CSE-MsgGUID: jRyB7HIeRi+4gquXl8ICpw== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270085" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270085" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:57:01 -0700 X-CSE-ConnectionGUID: ziil7t5KSYOwyDqqrzaFXw== X-CSE-MsgGUID: DbDtb2IxQeewcQkw/bbnbg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372363" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:56:59 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 19/24] usb: xhci: rework Event Ring Segment Table Address mask Date: Thu, 15 May 2025 16:56:16 +0300 Message-ID: <20250515135621.335595-20-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin Event Ring Segment Table Base Address Register contain two fields: - Bits 5:0: RsvdP (Reserved and Preserved) - Bits 63:6: Event Ring Segment Table Base Address Currently, an inverted RsvdP mask (ERST_BASE_RSVDP) is used to extract bits 63:6. Replaces the inverted mask with a non-inverted mask, 'ERST_BASE_ADDRESS_MASK', which makes the code easier to read. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 4 ++-- drivers/usb/host/xhci.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index ec2c4851c689..bd745a0f2f78 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2338,8 +2338,8 @@ void xhci_add_interrupter(struct xhci_hcd *xhci, unsigned int intr_num) writel(erst_size, &ir->ir_set->erst_size); erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); - erst_base &= ERST_BASE_RSVDP; - erst_base |= ir->erst.erst_dma_addr & ~ERST_BASE_RSVDP; + erst_base &= ~ERST_BASE_ADDRESS_MASK; + erst_base |= ir->erst.erst_dma_addr & ERST_BASE_ADDRESS_MASK; if (xhci->quirks & XHCI_WRITE_64_HI_LO) hi_lo_writeq(erst_base, &ir->ir_set->erst_base); else diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 19dd47d76140..7865e21f0b1f 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -255,7 +255,8 @@ struct xhci_intr_reg { #define ERST_SIZE_MASK (0xffff) /* erst_base bitmasks */ -#define ERST_BASE_RSVDP (GENMASK_ULL(5, 0)) +/* bits 63:6 - Event Ring Segment Table Base Address Register */ +#define ERST_BASE_ADDRESS_MASK GENMASK_ULL(63, 6) /* erst_dequeue bitmasks */ /* Dequeue ERST Segment Index (DESI) - Segment number (or alias) From patchwork Thu May 15 13:56:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890868 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 47F7C19E99E for ; Thu, 15 May 2025 13:57:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317423; cv=none; b=OmcWFcUESbBpxPzr9+A9sAISZxJ39DcwAQVwe7Dgjff4qX+TmgIqpeh/5+DlM20jKU713/NeX9flERUx2BH1swsADvoaP2tpl3ZBTBxKPqhso9XZDSQOZxpXBFUGnFqKbVkWrz4Etcn9XbH6GZ5kg1cFLii7+18lzNm86/jEUMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317423; c=relaxed/simple; bh=DpG26/AwLNnDH13mRaJw8plDnODYPHbzK9krmrHUPSs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IRp+Wrycitlfo278int9N9lirThtZxeP8biTb2pYBqVpaYIzX0W9DeidAFdQrGq1XHz/x+H/DiZa65IPLPtudDnkwlWihKKR2ux9SO8MEr1iHZ/clSPETyeJq+Z9nLxBwYD3dVY4p4xTKVJoA/sJBrcSulm5fbP6w/aVAQD/BmA= 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=UAAbEpZ8; arc=none smtp.client-ip=198.175.65.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="UAAbEpZ8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317423; x=1778853423; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DpG26/AwLNnDH13mRaJw8plDnODYPHbzK9krmrHUPSs=; b=UAAbEpZ8OEF5j1tf0vRqMrCaGYwKsAkkclkC+7XaxPJbmlbPcNTDTwbU 9ZRj/iBHoj5pp00+WPuKgQzqzrBCOMNszXGl6xY2X6x+GFQhlGK2nZCQ9 8/deq90g9OJIpe56C6uKlX61ooo8jH2ECmdpz4kQmmzaqUqeRLinBwB8O em7beGH8+xpNhsg+VuZLIRetBiMP/Mr4lLQVoqiaCIUgGUm7uyf6mW1me TLsUbTVJ3jFxS/ZJ/M+0m1WhjzCvOi3KzwI9X2mcv0Bg2XGzbsP9umHtJ PL0D9w4nV6CNBVcYbVJkfCz8AF9B3DNTea5ARgg2Pw8iSTrpgEFYSGNWu Q==; X-CSE-ConnectionGUID: BKHm49OyROezhwDFFbcLDQ== X-CSE-MsgGUID: G6NfDM1HQdOn6ODJsmtSUg== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270089" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270089" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:57:03 -0700 X-CSE-ConnectionGUID: YmJ7dm/5QhmXdi3I3VC/hw== X-CSE-MsgGUID: oYIbv8ksRxKhjkY320HTQw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372386" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:57:01 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 20/24] usb: xhci: cleanup IMOD register comments Date: Thu, 15 May 2025 16:56:17 +0300 Message-ID: <20250515135621.335595-21-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin Patch does not contain any functional changes. Add missing macro descriptions with specific bit definitions for each data field and reordered them accordingly. Remove "HW use only" from Interrupt Moderation Counter. xHCI Specification 1.2, section 5.5.2.2, states "This counter may be directly written by software at any time to alter the interrupt rate." Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.h | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 7865e21f0b1f..4a4ce6784bf0 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -210,14 +210,13 @@ struct xhci_op_regs { #define XHCI_PAGE_SIZE_MASK 0xffff /** - * struct xhci_intr_reg - Interrupt Register Set - * @irq_pending: IMAN - Interrupt Management Register. Used to enable + * struct xhci_intr_reg - Interrupt Register Set, v1.2 section 5.5.2. + * @irq_pending: IMAN - Interrupt Management Register. Used to enable * interrupts and check for pending interrupts. - * @irq_control: IMOD - Interrupt Moderation Register. - * Used to throttle interrupts. - * @erst_size: Number of segments in the Event Ring Segment Table (ERST). - * @erst_base: ERST base address. - * @erst_dequeue: Event ring dequeue pointer. + * @irq_control: IMOD - Interrupt Moderation Register. Used to throttle interrupts. + * @erst_size: ERSTSZ - Number of segments in the Event Ring Segment Table (ERST). + * @erst_base: ERSTBA - Event ring segment table base address. + * @erst_dequeue: ERDP - Event ring dequeue pointer. * * Each interrupter (defined by a MSI-X vector) has an event ring and an Event * Ring Segment Table (ERST) associated with it. The event ring is comprised of @@ -242,12 +241,13 @@ struct xhci_intr_reg { #define IMAN_IE (1 << 1) /* irq_control bitmasks */ -/* Minimum interval between interrupts (in 250ns intervals). The interval - * between interrupts will be longer if there are no events on the event ring. - * Default is 4000 (1 ms). +/* + * bits 15:0 - Interrupt Moderation Interval, the minimum interval between interrupts + * (in 250ns intervals). The interval between interrupts will be longer if there are no + * events on the event ring. Default is 4000 (1 ms). */ #define ER_IRQ_INTERVAL_MASK (0xffff) -/* Counter used to count down the time to the next interrupt - HW use only */ +/* bits 31:16 - Interrupt Moderation Counter, used to count down the time to the next interrupt */ #define ER_IRQ_COUNTER_MASK (0xffff << 16) /* erst_size bitmasks */ @@ -259,15 +259,18 @@ struct xhci_intr_reg { #define ERST_BASE_ADDRESS_MASK GENMASK_ULL(63, 6) /* erst_dequeue bitmasks */ -/* Dequeue ERST Segment Index (DESI) - Segment number (or alias) - * where the current dequeue pointer lies. This is an optional HW hint. +/* + * bits 2:0 - Dequeue ERST Segment Index (DESI), is the segment number (or alias) where the + * current dequeue pointer lies. This is an optional HW hint. */ #define ERST_DESI_MASK (0x7) -/* Event Handler Busy (EHB) - is the event ring scheduled to be serviced by +/* + * bit 3 - Event Handler Busy (EHB), whether the event ring is scheduled to be serviced by * a work queue (or delayed service routine)? */ #define ERST_EHB (1 << 3) -#define ERST_PTR_MASK (GENMASK_ULL(63, 4)) +/* bits 63:4 - Event Ring Dequeue Pointer */ +#define ERST_PTR_MASK GENMASK_ULL(63, 4) /** * struct xhci_run_regs From patchwork Thu May 15 13:56:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890562 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 E3743208994 for ; Thu, 15 May 2025 13:57:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317425; cv=none; b=Dwia6dSw31c96f0rfVloWi5RYntLnc/g535e1U8h9eTMShFGvK9nrObgaj5yguJYMVkOhnPeeCWAhEjewB78+ce33JruIxxcHxgs4RRC8pIuR3wG186eFcxQQOCdnnXWIi6C52rtxRL5Wgrz0Pxs1+LqVreH3mlg2EMVcSUgEJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317425; c=relaxed/simple; bh=UN+z83K9KdPUceqsoBAVrOBbdAo3NalO16EplV8qwF8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WutgrA70MZNSqOBf3VwPkn0hdTBxTAHMcUvdMPnanDcDDyzDcqxTIKZavPfABI6wI8VRq2O+1BGg6TvASwI01dFxCtEeugdEPdi8dV5qSAjuoUaV5HXOJFHDIyjwZ4q4QWuAdsJewZoq9iu2S7ZvNtWKbJuor3O35F7q/uFL2lg= 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=Vn7yswd6; arc=none smtp.client-ip=198.175.65.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="Vn7yswd6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317424; x=1778853424; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UN+z83K9KdPUceqsoBAVrOBbdAo3NalO16EplV8qwF8=; b=Vn7yswd6ivfUJ4F95tiDiTxdv0LOwlzQ0yxcrxvKtD0IlEH8CjV3xIfV Az6uLj3NY1s4MHwu7e6X+HrE/syUq7I+CVJjh6IZh7FCwD/dqYAHo6kYC YnZZUOXT8CjKpwOeCD42xs5jFhDl9phi6rgByMktUPkjFYixUTeHERZFX 4EfLxmnf2UiJODX6SiromVTy3fyThVB+KQNfvE7Dw3Z8UHWxcpeKZcH+f f9FfS/g3upe9VXObxe9ec4e7zFj3HkY4DxDwhl5B0rO9j4TuQ2Vz7t5AY 5yAJdVjXxbqA89s+XIHUpB+QIdUpJBXOQqQxE3AJjcoHNdbRc4ikKYFKT A==; X-CSE-ConnectionGUID: hVPRL01wSR6s14uKbnu8hw== X-CSE-MsgGUID: mSSfwcMaQci/YQsDz7IxfQ== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270097" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270097" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:57:04 -0700 X-CSE-ConnectionGUID: jeof90TzR0uJ8dsSOuuJ/w== X-CSE-MsgGUID: wn33ycFqTT6qMos/eZNQnw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372410" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:57:02 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 21/24] usb: xhci: rename 'irq_pending' to 'iman' Date: Thu, 15 May 2025 16:56:18 +0300 Message-ID: <20250515135621.335595-22-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin The Interrupt Register Set contains Interrupt Management register (IMAN). The IMAN register contains the following fields: - Bit 0: Interrupt Pending (IP) - Bit 1: Interrupt Enable (IE) - Bits 31:2: RsvdP (Reserved and Preserved) Tn the xhci driver, the pointer currently named 'irq_pending' refers to the IMAN register. However, the name "irq_pending" only describes one of the fields within the IMAN register, rather than the entire register itself. To improve clarity and better align with the xHCI specification, the pointer is renamed to 'iman'. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 10 +++++----- drivers/usb/host/xhci.c | 16 ++++++++-------- drivers/usb/host/xhci.h | 8 ++++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 9efa0d1735df..e3c823e1caee 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3083,14 +3083,14 @@ void xhci_update_erst_dequeue(struct xhci_hcd *xhci, static void xhci_clear_interrupt_pending(struct xhci_interrupter *ir) { if (!ir->ip_autoclear) { - u32 irq_pending; + u32 iman; - irq_pending = readl(&ir->ir_set->irq_pending); - irq_pending |= IMAN_IP; - writel(irq_pending, &ir->ir_set->irq_pending); + iman = readl(&ir->ir_set->iman); + iman |= IMAN_IP; + writel(iman, &ir->ir_set->iman); /* Read operation to guarantee the write has been flushed from posted buffers */ - readl(&ir->ir_set->irq_pending); + readl(&ir->ir_set->iman); } } diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 6c4bbabc3a70..3450762fc7bd 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -330,12 +330,12 @@ int xhci_enable_interrupter(struct xhci_interrupter *ir) if (!ir || !ir->ir_set) return -EINVAL; - iman = readl(&ir->ir_set->irq_pending); + iman = readl(&ir->ir_set->iman); iman |= IMAN_IE; - writel(iman, &ir->ir_set->irq_pending); + writel(iman, &ir->ir_set->iman); /* Read operation to guarantee the write has been flushed from posted buffers */ - readl(&ir->ir_set->irq_pending); + readl(&ir->ir_set->iman); return 0; } @@ -346,11 +346,11 @@ int xhci_disable_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir) if (!ir || !ir->ir_set) return -EINVAL; - iman = readl(&ir->ir_set->irq_pending); + iman = readl(&ir->ir_set->iman); iman &= ~IMAN_IE; - writel(iman, &ir->ir_set->irq_pending); + writel(iman, &ir->ir_set->iman); - iman = readl(&ir->ir_set->irq_pending); + iman = readl(&ir->ir_set->iman); if (iman & IMAN_IP) xhci_dbg(xhci, "%s: Interrupt pending\n", __func__); @@ -834,7 +834,7 @@ static void xhci_save_registers(struct xhci_hcd *xhci) ir->s3_erst_size = readl(&ir->ir_set->erst_size); ir->s3_erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); ir->s3_erst_dequeue = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); - ir->s3_irq_pending = readl(&ir->ir_set->irq_pending); + ir->s3_iman = readl(&ir->ir_set->iman); ir->s3_irq_control = readl(&ir->ir_set->irq_control); } } @@ -858,7 +858,7 @@ static void xhci_restore_registers(struct xhci_hcd *xhci) writel(ir->s3_erst_size, &ir->ir_set->erst_size); xhci_write_64(xhci, ir->s3_erst_base, &ir->ir_set->erst_base); xhci_write_64(xhci, ir->s3_erst_dequeue, &ir->ir_set->erst_dequeue); - writel(ir->s3_irq_pending, &ir->ir_set->irq_pending); + writel(ir->s3_iman, &ir->ir_set->iman); writel(ir->s3_irq_control, &ir->ir_set->irq_control); } } diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 4a4ce6784bf0..62d12d23617f 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -211,7 +211,7 @@ struct xhci_op_regs { /** * struct xhci_intr_reg - Interrupt Register Set, v1.2 section 5.5.2. - * @irq_pending: IMAN - Interrupt Management Register. Used to enable + * @iman: IMAN - Interrupt Management Register. Used to enable * interrupts and check for pending interrupts. * @irq_control: IMOD - Interrupt Moderation Register. Used to throttle interrupts. * @erst_size: ERSTSZ - Number of segments in the Event Ring Segment Table (ERST). @@ -226,7 +226,7 @@ struct xhci_op_regs { * updates the dequeue pointer. */ struct xhci_intr_reg { - __le32 irq_pending; + __le32 iman; __le32 irq_control; __le32 erst_size; __le32 rsvd; @@ -234,7 +234,7 @@ struct xhci_intr_reg { __le64 erst_dequeue; }; -/* irq_pending bitmasks */ +/* iman bitmasks */ /* bit 0 - Interrupt Pending (IP), whether there is an interrupt pending. Write-1-to-clear. */ #define IMAN_IP (1 << 0) /* bit 1 - Interrupt Enable (IE), whether the interrupter is capable of generating an interrupt */ @@ -1452,7 +1452,7 @@ struct xhci_interrupter { bool ip_autoclear; u32 isoc_bei_interval; /* For interrupter registers save and restore over suspend/resume */ - u32 s3_irq_pending; + u32 s3_iman; u32 s3_irq_control; u32 s3_erst_size; u64 s3_erst_base; From patchwork Thu May 15 13:56:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890867 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 7477419E99E for ; Thu, 15 May 2025 13:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317427; cv=none; b=hHpe8o1KWMYUdhnfJdFEa3HSeOXi74Vx/NxfZTo7A4HLtW3ORNqu7bQy1LzL3xlOtk4G+RyYOMuIgKq0ve6fJ2e2hqcMQNQLvI52QcTkFDbBv4AthNjnFJSUJr46IfYhlf7osQwfHrhqCzrX1wytRL+nqH+sVyaeqJbleRMFfKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317427; c=relaxed/simple; bh=0jJ2KWQsIclt6DFM38ynvWMOaZtsJUxTtg173Rx5I1A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nch8L4CAkB9Fc6M9epY7CKmuE8gklxjhcueKrxMO7V0p0oVpQCkDBnnR+KwNtO32Gb/OdWzoMHs41bMcNlUcA7OQXgOD6j3Y3xQ9hmUcgzPi+VQKAnjC17SNITj22ELHA1j03KF5HuWrFUFiWpMQmA9VeEFW/S2kXMQluCccPdw= 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=K/4jQ4t3; arc=none smtp.client-ip=198.175.65.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="K/4jQ4t3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317426; x=1778853426; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0jJ2KWQsIclt6DFM38ynvWMOaZtsJUxTtg173Rx5I1A=; b=K/4jQ4t3Obr7oPz/Cmun3iR1aU8I2yK7k9mugMPzoJDqajJzwRJg8X3d 0wMuZ/IRBCqHGG2ZVtqiPN81iHdsvCIsS0po6m+Q/FDCnItbAfOQPy+4i U5QUKr6TNvgEFubFkVp+L2tzM/+pLvy7IrQPbRL/kWUONiAKo89Caxjw/ ni9Y/GK+3OMJ54lnBoYASsvKXvXRIV5I2+zCdSLjKwJmZ8dlGvZyedBKZ gfvuwD3an+rqExfS6qDHH2IBnGWq8EPOTLr+6BiWnImHGmGoi9QoRPLmN aWXF2OtovH921la0FFaOEmKEyVFDdPhtIYTy2QtQJnXghcNxIw6NWEj4n w==; X-CSE-ConnectionGUID: oRKbhMj1QueoQBhY2Xxliw== X-CSE-MsgGUID: 9yvvVGihQAaLDv47qeQNEg== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270105" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270105" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:57:06 -0700 X-CSE-ConnectionGUID: fCmnpkwGTLmCQnFmI6yoTg== X-CSE-MsgGUID: 0vI/NzepRQ2DJ8CYbTGcvw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372423" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:57:04 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 22/24] usb: xhci: rename 'irq_control' to 'imod' Date: Thu, 15 May 2025 16:56:19 +0300 Message-ID: <20250515135621.335595-23-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin The Interrupt Register Set contains Interrupt Moderation register (IMOD). The IMOD register contains the following fields: - Bits 15:0: Interrupt Moderation Interval (IMODI) - Bits 31:16: Interrupt Moderation Counter (IMODC) In the xHCI driver, the pointer currently named 'irq_control' refers to the IMOD register. However, the name 'irq_control' does not accurately describe the register or its contents, and the xHCI specification does not use the term "irq control" or "interrupt control" for this register. To improve clarity and better align with the xHCI specification, the pointer is renamed to 'imod'. Additionally, the IMOD register fields IMODI & IMODC have their own masks, which are also renamed for consistency: * 'ER_IRQ_INTERVAL_MASK' -> 'IMODI_MASK' * 'ER_IRQ_COUNTER_MASK' -> 'IMODC_MASK' Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 12 ++++++------ drivers/usb/host/xhci.h | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 3450762fc7bd..9769c68b2e9f 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -367,12 +367,12 @@ int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, return -EINVAL; /* IMODI value in IMOD register is in 250ns increments */ - imod_interval = umin(imod_interval / 250, ER_IRQ_INTERVAL_MASK); + imod_interval = umin(imod_interval / 250, IMODI_MASK); - imod = readl(&ir->ir_set->irq_control); - imod &= ~ER_IRQ_INTERVAL_MASK; + imod = readl(&ir->ir_set->imod); + imod &= ~IMODI_MASK; imod |= imod_interval; - writel(imod, &ir->ir_set->irq_control); + writel(imod, &ir->ir_set->imod); return 0; } @@ -835,7 +835,7 @@ static void xhci_save_registers(struct xhci_hcd *xhci) ir->s3_erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); ir->s3_erst_dequeue = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); ir->s3_iman = readl(&ir->ir_set->iman); - ir->s3_irq_control = readl(&ir->ir_set->irq_control); + ir->s3_imod = readl(&ir->ir_set->imod); } } @@ -859,7 +859,7 @@ static void xhci_restore_registers(struct xhci_hcd *xhci) xhci_write_64(xhci, ir->s3_erst_base, &ir->ir_set->erst_base); xhci_write_64(xhci, ir->s3_erst_dequeue, &ir->ir_set->erst_dequeue); writel(ir->s3_iman, &ir->ir_set->iman); - writel(ir->s3_irq_control, &ir->ir_set->irq_control); + writel(ir->s3_imod, &ir->ir_set->imod); } } diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 62d12d23617f..49887a303e43 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -213,7 +213,7 @@ struct xhci_op_regs { * struct xhci_intr_reg - Interrupt Register Set, v1.2 section 5.5.2. * @iman: IMAN - Interrupt Management Register. Used to enable * interrupts and check for pending interrupts. - * @irq_control: IMOD - Interrupt Moderation Register. Used to throttle interrupts. + * @imod: IMOD - Interrupt Moderation Register. Used to throttle interrupts. * @erst_size: ERSTSZ - Number of segments in the Event Ring Segment Table (ERST). * @erst_base: ERSTBA - Event ring segment table base address. * @erst_dequeue: ERDP - Event ring dequeue pointer. @@ -227,7 +227,7 @@ struct xhci_op_regs { */ struct xhci_intr_reg { __le32 iman; - __le32 irq_control; + __le32 imod; __le32 erst_size; __le32 rsvd; __le64 erst_base; @@ -240,15 +240,15 @@ struct xhci_intr_reg { /* bit 1 - Interrupt Enable (IE), whether the interrupter is capable of generating an interrupt */ #define IMAN_IE (1 << 1) -/* irq_control bitmasks */ +/* imod bitmasks */ /* * bits 15:0 - Interrupt Moderation Interval, the minimum interval between interrupts * (in 250ns intervals). The interval between interrupts will be longer if there are no * events on the event ring. Default is 4000 (1 ms). */ -#define ER_IRQ_INTERVAL_MASK (0xffff) +#define IMODI_MASK (0xffff) /* bits 31:16 - Interrupt Moderation Counter, used to count down the time to the next interrupt */ -#define ER_IRQ_COUNTER_MASK (0xffff << 16) +#define IMODC_MASK (0xffff << 16) /* erst_size bitmasks */ /* bits 15:0 - Event Ring Segment Table Size, number of ERST entries */ @@ -1453,7 +1453,7 @@ struct xhci_interrupter { u32 isoc_bei_interval; /* For interrupter registers save and restore over suspend/resume */ u32 s3_iman; - u32 s3_irq_control; + u32 s3_imod; u32 s3_erst_size; u64 s3_erst_base; u64 s3_erst_dequeue; From patchwork Thu May 15 13:56:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890561 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 0ECFC198833 for ; Thu, 15 May 2025 13:57:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317428; cv=none; b=PpRoIrIKPz6LAg3qLfimOch/AxwAXBOshksh+te9K6S0FDtpufP/cLbnjpzokdUx5AcxkjKjR4KDgdPy6+UHMPwbIY6lbCOtazetG90/XrV1xCAaZDClW3TO/1pd8avJd6l3DBJ5TAKG8eubGP5ZVp/SNPFPwF3YlkJS8ls9U3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317428; c=relaxed/simple; bh=fHt1Q37+hSpmb+4RlUzon/peOqB+pG7j5DWBJIOE5eI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iNuc2hN9gOPi6x6ntdzgzYrn00dr05oUJleRVN++G5R68pJoBZ/JS6RcyAmG6aPTVfJSQOT7UtsFP928YyJP9BrRTcMTn2dhUVggdRZaFDGsITKC/OeCH/oHKhxofHcVLT7Ep66zSFjl5QD4uIsA696G8VLyEGIJkuDhuSP0sJI= 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=f3CvUmno; arc=none smtp.client-ip=198.175.65.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="f3CvUmno" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317428; x=1778853428; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fHt1Q37+hSpmb+4RlUzon/peOqB+pG7j5DWBJIOE5eI=; b=f3CvUmnoUwFGvPkmWY9Bp3oTcwoRFn2lnPYT3n8f+GeAkqugMUEPPT1D Xr6sCqvPzEMEGWeaKWBBf2YqR10ApxOjpdeUVVJ12Fy+ANJjKGCwhhb9Z 83ORa4LEyK5GYXFnAY4Ph6DA56bBnlvAOeBy/WmSABIeF9xcdZq6tg/mQ gBDTtbqePioMQu+G3bpZo3l0GfTyyE+SEuBfObCDk02q+xKv+X8RKvNTR 9ECpkLVo1Y4TiivVydq3Y5rUnWXEIeC6BbFhD1sRkvmaLKaKTqxtxcDbC Yr916PyJ8mjVQvEIntrVPwALa5DstyEd0/UBv98oRWZTdAvgQvcer5Wn4 g==; X-CSE-ConnectionGUID: gbvltt54QRmoGb68hkPx6Q== X-CSE-MsgGUID: QSfNqhoeTTO9ifnRJFcf1Q== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270110" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270110" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:57:07 -0700 X-CSE-ConnectionGUID: y75w/r3dQv68/+K3HGPq4Q== X-CSE-MsgGUID: 1QCAq5KdTiqV9Y4Nmw9H3w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372440" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:57:05 -0700 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 23/24] usb: xhci: add warning message specifying which Set TR Deq failed Date: Thu, 15 May 2025 16:56:20 +0300 Message-ID: <20250515135621.335595-24-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Niklas Neronin Currently, errors from the Set TR Deq command are not handled. Add a warning message to specify the slot, endpoint, and TRB address when a Set TR Deq command fails. This additional information will aid in debugging such failures. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index e3c823e1caee..eff6b84dc915 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1448,6 +1448,11 @@ static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, unsigned int ep_state; unsigned int slot_state; + xhci_warn(xhci, "Set TR Deq error for TRB 0x%llx in slot %d ep %u\n", + (unsigned long long)xhci_trb_virt_to_dma(ep->queued_deq_seg, + ep->queued_deq_ptr), + slot_id, ep_index); + switch (cmd_comp_code) { case COMP_TRB_ERROR: xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because of stream ID configuration\n"); From patchwork Thu May 15 13:56:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 890866 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 4722E20C47C for ; Thu, 15 May 2025 13:57:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317430; cv=none; b=pzAdd919qvRKstba5T09IBJ3cF0EglCg7qmbB+4Gb5xhS7O/D5haCLL4pO6y0Xv+rPFUsWCChinbTM62QA0SQaqZ0KbY5hfEKBjLDUdiaqlaqei/dkyH37Ox3U/F2qCn+VJoDEDbn22DmsZqwwiNqPabvSC+qoBuaWb8bLPYkls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747317430; c=relaxed/simple; bh=OPYAJ6P7PxPxXwYkuk5OUY5zNJFkKO37Ga+TLCNsGc4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bMfsgy54RXQKkrHVeRoJ77jxazDHMcE683lmdXFb/wB7vy2u+TmhlkoC0JzmU7rzkeYuF0z6hdC9b6fmqLpy+MEGDrD+wyKyRdAvBORNox9J2aEnk0JeyU9rX+gwv2Lxp6DUU+iuPACsDLk8ZSgHnltdJuBN2wod8bKXegqy9Z0= 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=aEsajQuh; arc=none smtp.client-ip=198.175.65.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="aEsajQuh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747317430; x=1778853430; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OPYAJ6P7PxPxXwYkuk5OUY5zNJFkKO37Ga+TLCNsGc4=; b=aEsajQuhn1oYEuRbH8X2MaZGxCsUI8fQwai29aYeXcs7cSAvnNDVXsaL RrPFfw04Ub6+eUrTgcowJMeRzPKQGi9JZZGmAJeCB1jb57cheK3Vlg450 CimWNsyBiUhRhNVwVR/zTXX2UthEj3GV/AG98ngXacNMHc3hHDZB4fR44 BZ2vMOOmVE/4wcHPBLyxj0/u8Gmv6CMHeNZKUXf4O1plftvq6HAky1biP 4OF42xk7J9vP7lm9j3JTCFRJVyes3iVGEUo/E0yb0OlxdaI/ckPhUifX3 Q0KkaOllFbctlKJGSbT8LBwThPdgb0kItPpTS0s30LM8WrxfZKmhmnAdJ w==; X-CSE-ConnectionGUID: LKpt9qf6QtOaF5njXrLmrQ== X-CSE-MsgGUID: 63ChEpOsQX6dqrjRquA2Lg== X-IronPort-AV: E=McAfee;i="6700,10204,11434"; a="60270117" X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="60270117" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2025 06:57:09 -0700 X-CSE-ConnectionGUID: wKBCMOCZQhqzQ8i062Mz5g== X-CSE-MsgGUID: YALbe7knSwGUF6QtTlBw5g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,291,1739865600"; d="scan'208";a="139372463" Received: from unknown (HELO mnyman-desk.fi.intel.com) ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2025 06:57:07 -0700 From: Mathias Nyman To: Cc: , Amardeep Rai , Kannappan R , Mathias Nyman Subject: [PATCH 24/24] xhci: Add host support for eUSB2 double isochronous bandwidth devices Date: Thu, 15 May 2025 16:56:21 +0300 Message-ID: <20250515135621.335595-25-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515135621.335595-1-mathias.nyman@linux.intel.com> References: <20250515135621.335595-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Amardeep Rai Detect eUSB2 double isoc bw capable hosts and devices, and set the proper xhci endpoint context values such as 'Mult', 'Max Burst Size', and 'Max ESIT Payload' to enable the double isochronous bandwidth endpoints. Intel xHC uses the endpoint context 'Mult' field for eUSB2 isoc endpoints even if hosts supporting Large ESIT Payload Capability should normally ignore the mult field. Signed-off-by: Amardeep Rai Co-developed-by: Kannappan R Signed-off-by: Kannappan R Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-caps.h | 2 ++ drivers/usb/host/xhci-mem.c | 62 ++++++++++++++++++++++++++++-------- drivers/usb/host/xhci-ring.c | 6 ++-- drivers/usb/host/xhci.c | 17 +++++++++- drivers/usb/host/xhci.h | 19 +++++++++++ 5 files changed, 89 insertions(+), 17 deletions(-) diff --git a/drivers/usb/host/xhci-caps.h b/drivers/usb/host/xhci-caps.h index 4b8ff4815644..723a56052439 100644 --- a/drivers/usb/host/xhci-caps.h +++ b/drivers/usb/host/xhci-caps.h @@ -89,3 +89,5 @@ #define HCC2_GSC(p) ((p) & (1 << 8)) /* true: HC support Virtualization Based Trusted I/O Capability */ #define HCC2_VTC(p) ((p) & (1 << 9)) +/* true: HC support Double BW on a eUSB2 HS ISOC EP */ +#define HCC2_EUSB2_DIC(p) ((p) & (1 << 11)) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index bd745a0f2f78..494f9eacab84 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1328,18 +1328,36 @@ static unsigned int xhci_get_endpoint_interval(struct usb_device *udev, return interval; } -/* The "Mult" field in the endpoint context is only set for SuperSpeed isoc eps. +/* + * xHCs without LEC use the "Mult" field in the endpoint context for SuperSpeed + * isoc eps, and High speed isoc eps that support bandwidth doubling. Standard * High speed endpoint descriptors can define "the number of additional * transaction opportunities per microframe", but that goes in the Max Burst * endpoint context field. */ -static u32 xhci_get_endpoint_mult(struct usb_device *udev, - struct usb_host_endpoint *ep) +static u32 xhci_get_endpoint_mult(struct xhci_hcd *xhci, + struct usb_device *udev, + struct usb_host_endpoint *ep) { - if (udev->speed < USB_SPEED_SUPER || - !usb_endpoint_xfer_isoc(&ep->desc)) + bool lec; + + /* xhci 1.1 with LEC set does not use mult field, except intel eusb2 */ + lec = xhci->hci_version > 0x100 && HCC2_LEC(xhci->hcc_params2); + + /* eusb2 double isoc bw devices are the only usb2 devices using mult */ + if (xhci_eusb2_is_isoc_bw_double(udev, ep)) { + if (!lec || xhci->quirks & XHCI_INTEL_HOST) + return 1; + } + + /* Oherwise only isoc transfers on hosts without LEC uses mult field */ + if (!usb_endpoint_xfer_isoc(&ep->desc) || lec) return 0; - return ep->ss_ep_comp.bmAttributes; + + if (udev->speed >= USB_SPEED_SUPER) + return ep->ss_ep_comp.bmAttributes; + + return 0; } static u32 xhci_get_endpoint_max_burst(struct usb_device *udev, @@ -1351,8 +1369,18 @@ static u32 xhci_get_endpoint_max_burst(struct usb_device *udev, if (udev->speed == USB_SPEED_HIGH && (usb_endpoint_xfer_isoc(&ep->desc) || - usb_endpoint_xfer_int(&ep->desc))) - return usb_endpoint_maxp_mult(&ep->desc) - 1; + usb_endpoint_xfer_int(&ep->desc))) { + if (xhci_eusb2_is_isoc_bw_double(udev, ep)) + /* + * eUSB2 double isoc bw endpoints max packet field + * service opportunity bits 12:11 are not valid, so set + * the ctx burst to max service opportunity "2" as these + * eps support transferring over 3072 bytes per interval + */ + return 2; + else + return usb_endpoint_maxp_mult(&ep->desc) - 1; + } return 0; } @@ -1400,6 +1428,10 @@ static u32 xhci_get_max_esit_payload(struct usb_device *udev, if (udev->speed >= USB_SPEED_SUPER) return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval); + /* High speed eusb2 double isoc bw with over 3072 bytes per esit */ + if (xhci_eusb2_is_isoc_bw_double(udev, ep)) + return le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval); + max_packet = usb_endpoint_maxp(&ep->desc); max_burst = usb_endpoint_maxp_mult(&ep->desc); /* A 0 in max burst means 1 transfer per ESIT */ @@ -1437,6 +1469,13 @@ int xhci_endpoint_init(struct xhci_hcd *xhci, ring_type = usb_endpoint_type(&ep->desc); + /* Ensure host supports double isoc bandwidth for eusb2 devices */ + if (xhci_eusb2_is_isoc_bw_double(udev, ep) && + !HCC2_EUSB2_DIC(xhci->hcc_params2)) { + dev_dbg(&udev->dev, "Double Isoc Bandwidth not supported by xhci\n"); + return -EINVAL; + } + /* * Get values to fill the endpoint context, mostly from ep descriptor. * The average TRB buffer lengt for bulk endpoints is unclear as we @@ -1456,8 +1495,8 @@ int xhci_endpoint_init(struct xhci_hcd *xhci, } } - mult = xhci_get_endpoint_mult(udev, ep); - max_packet = usb_endpoint_maxp(&ep->desc); + mult = xhci_get_endpoint_mult(xhci, udev, ep); + max_packet = xhci_usb_endpoint_maxp(udev, ep); max_burst = xhci_get_endpoint_max_burst(udev, ep); avg_trb_len = max_esit_payload; @@ -1478,9 +1517,6 @@ int xhci_endpoint_init(struct xhci_hcd *xhci, /* xHCI 1.0 and 1.1 indicates that ctrl ep avg TRB Length should be 8 */ if (usb_endpoint_xfer_control(&ep->desc) && xhci->hci_version >= 0x100) avg_trb_len = 8; - /* xhci 1.1 with LEC support doesn't use mult field, use RsvdZ */ - if ((xhci->hci_version > 0x100) && HCC2_LEC(xhci->hcc_params2)) - mult = 0; /* Set up the endpoint ring */ virt_dev->eps[ep_index].new_ring = diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index eff6b84dc915..f94626d8bcce 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3549,7 +3549,7 @@ static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred, if ((xhci->quirks & XHCI_MTK_HOST) && (xhci->hci_version < 0x100)) trb_buff_len = 0; - maxp = usb_endpoint_maxp(&urb->ep->desc); + maxp = xhci_usb_endpoint_maxp(urb->dev, urb->ep); total_packet_count = DIV_ROUND_UP(td_total_len, maxp); /* Queueing functions don't count the current TRB into transferred */ @@ -3566,7 +3566,7 @@ static int xhci_align_td(struct xhci_hcd *xhci, struct urb *urb, u32 enqd_len, u32 new_buff_len; size_t len; - max_pkt = usb_endpoint_maxp(&urb->ep->desc); + max_pkt = xhci_usb_endpoint_maxp(urb->dev, urb->ep); unalign = (enqd_len + *trb_buff_len) % max_pkt; /* we got lucky, last normal TRB data on segment is packet aligned */ @@ -4137,7 +4137,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, addr = start_addr + urb->iso_frame_desc[i].offset; td_len = urb->iso_frame_desc[i].length; td_remain_len = td_len; - max_pkt = usb_endpoint_maxp(&urb->ep->desc); + max_pkt = xhci_usb_endpoint_maxp(urb->dev, urb->ep); total_pkt_count = DIV_ROUND_UP(td_len, max_pkt); /* A zero-length transfer still involves at least one packet. */ diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 9769c68b2e9f..2ac383929b1c 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1353,7 +1353,7 @@ static bool xhci_urb_temp_buffer_required(struct usb_hcd *hcd, struct scatterlist *tail_sg; tail_sg = urb->sg; - max_pkt = usb_endpoint_maxp(&urb->ep->desc); + max_pkt = xhci_usb_endpoint_maxp(urb->dev, urb->ep); if (!urb->num_sgs) return ret; @@ -2940,6 +2940,21 @@ int xhci_stop_endpoint_sync(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, int } EXPORT_SYMBOL_GPL(xhci_stop_endpoint_sync); +/* + * xhci_usb_endpoint_maxp - get endpoint max packet size + * @host_ep: USB host endpoint to be checked + * + * Returns max packet from the correct descriptor + */ + +int xhci_usb_endpoint_maxp(struct usb_device *udev, + struct usb_host_endpoint *host_ep) +{ + if (xhci_eusb2_is_isoc_bw_double(udev, host_ep)) + return le16_to_cpu(host_ep->eusb2_isoc_ep_comp.wMaxPacketSize); + return usb_endpoint_maxp(&host_ep->desc); +} + /* Issue a configure endpoint command or evaluate context command * and wait for it to finish. */ diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 49887a303e43..e0c5238c9327 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1735,6 +1735,23 @@ static inline bool xhci_has_one_roothub(struct xhci_hcd *xhci) (!xhci->usb2_rhub.num_ports || !xhci->usb3_rhub.num_ports); } +/* + * USB 2.0 specification, chapter 5.6.4 Isochronous Transfer Bus Access + * Constraint. A high speed endpoint can move up to 3072 bytes per microframe + * (or 192Mb/s). + */ +#define MAX_ISOC_XFER_SIZE_HS 3072 + +static inline bool xhci_eusb2_is_isoc_bw_double(struct usb_device *udev, + struct usb_host_endpoint *ep) +{ + return le16_to_cpu(udev->descriptor.bcdUSB) == 0x220 && + usb_endpoint_xfer_isoc(&ep->desc) && + le16_to_cpu(ep->desc.wMaxPacketSize) == 0 && + le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval) > + MAX_ISOC_XFER_SIZE_HS; +} + #define xhci_dbg(xhci, fmt, args...) \ dev_dbg(xhci_to_hcd(xhci)->self.controller , fmt , ## args) #define xhci_err(xhci, fmt, args...) \ @@ -1958,6 +1975,8 @@ void xhci_update_erst_dequeue(struct xhci_hcd *xhci, struct xhci_interrupter *ir, bool clear_ehb); void xhci_add_interrupter(struct xhci_hcd *xhci, unsigned int intr_num); +int xhci_usb_endpoint_maxp(struct usb_device *udev, + struct usb_host_endpoint *host_ep); /* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,