Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 4E0641A3160 for ; Mon, 31 Aug 2026 21:10:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788210645; cv=none; b=QEp0UVs17ESzeiqGtapSY0vI2flZUvNB1MyKrUOAUJG0YpB+gmDFsr90zxkFsoFxamYRDDZjsOIBiDxK4vJM09628zLLK/njZAPx4v3ie3QGcWdslWELm+GcZ3XqT6WnGrmbBEmRyA7ASV86IhoUT4J4Wra4nhZuC+Efd1Bk1HM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788210645; c=relaxed/simple; bh=4MkQ7BH1REKA/WFMb2Gmda2IsfNyMpp5R6xjfrX/Mr4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hs86vjhKSCDSzrAynsFbLNyA84LnYum2VKmUmzE5aUe9Cc3iW0ZF68+k4SdIGSnF/SPiMoWoT6AbrruRi364Jq852tqkjjBr60ZrMZHIZpqMOaVnIdHubrG3kEeho7UXWG9wVv4GGYZnXMmjPiGuktN1hsIHGmSm+FOQ74lB9zU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MXBgbvWV; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MXBgbvWV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6DE31F000E9; Mon, 31 Aug 2026 21:10:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788210641; bh=uEH2e8NR3y8gz/UrN17jq4KBNExmaUkH6eo9Xd8KauY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MXBgbvWVIwncHHbJyP1ABAtxBvmNW8a0uD8kOhmUs0GCKp/isqWEFmUQL1LbPlr+y shqOkzajm8TuMcYKdfmU0apKsS2MdPCQtAhCTImEvEJPo0doHZDcugSozApf8RbFwt xljOAItAtHMqwEoALBzhkdduAIHEmYbI+oZNHCbXNU1f68cZDhBrdWX1hmttoTgXlK +RS/sTHEDRnh42xVhPC7XFNhEQaaLY67+3gXKQZckduo8SKrmRSPmqmXQOhAJcWlED kGk3a8mve/5AWDzWKp071vPtm2s9sj2aOJZRXN/zXN+/VKOYAtWXbKEgWIcsac2H9z Jc0HEWbBCtRSA== From: Sasha Levin To: stable@vger.kernel.org Cc: Niklas Neronin , Mathias Nyman , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 6.6.y 1/7] usb: xhci: add tracing for PORTSC register writes Date: Mon, 31 Aug 2026 17:10:08 -0400 Message-ID: <20260831211039.1799106-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026083121-usher-contest-f49c@gregkh> References: <2026083121-usher-contest-f49c@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Niklas Neronin [ Upstream commit 829738e59f1fad90ef7b63d6a1a4de9d5d22544a ] Introduce a dedicated write function for the USB Port Register Set (PORTSC) that includes tracing capabilities for values written to the PORTSC register. This enhancement minimizes code duplication and improves debugging. The PORTSC register is part of the Host Controller USB Port Register Set, comprising 4 x 32-bit registers. As the first register, PORTSC is accessed directly via 'port->addr'. Future commits will introduce a dedicated Port register struct to further streamline access. By adding the xhci_portsc_writel() function prior to these changes, we significantly reduce the number of same line modifications required. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman Link: https://patch.msgid.link/20251119142417.2820519-6-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman [ dep note: dropped the context-only xhci.h hunk pulling in xhci_stop_endpoint_sync()/xhci_update_erst_dequeue()/xhci_add_interrupter()/ xhci_usb_endpoint_maxp() declarations from upstream's parent commit - those functions do not exist in this tree yet and are unrelated to this change; only the new xhci_portsc_writel() declaration is kept. Also, this tree's xhci_log_portsc trace event class still uses the older TP_PROTO(u32 portnum, u32 portsc) signature (the later conversion to struct xhci_port * is not present here), so the new xhci_portsc_writel tracepoint and its call site were adapted to use port->hcd_portnum instead of struct xhci_port * to match. ] Stable-dep-of: 78203d5b54a4 ("usb: xhci: bail out of setup if the controller is inaccessible") Signed-off-by: Sasha Levin --- drivers/usb/host/xhci-debugfs.c | 2 +- drivers/usb/host/xhci-hub.c | 33 ++++++++++++++++----------------- drivers/usb/host/xhci-pci.c | 2 +- drivers/usb/host/xhci-trace.h | 5 +++++ drivers/usb/host/xhci.c | 9 ++++++++- drivers/usb/host/xhci.h | 1 + 6 files changed, 32 insertions(+), 20 deletions(-) diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c index 15a8402ee8a17..3e3cdf497e452 100644 --- a/drivers/usb/host/xhci-debugfs.c +++ b/drivers/usb/host/xhci-debugfs.c @@ -387,7 +387,7 @@ static ssize_t xhci_port_write(struct file *file, const char __user *ubuf, portsc = xhci_port_state_to_neutral(portsc); portsc &= ~PORT_PLS_MASK; portsc |= PORT_LINK_STROBE | XDEV_COMP_MODE; - writel(portsc, port->addr); + xhci_portsc_writel(port, portsc); spin_unlock_irqrestore(&xhci->lock, flags); } else { return -EINVAL; diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 61642c8d529fd..56f0af4a40d8c 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -601,7 +601,7 @@ static void xhci_disable_port(struct xhci_hcd *xhci, struct xhci_port *port) portsc = xhci_port_state_to_neutral(portsc); /* Write 1 to disable the port */ - writel(portsc | PORT_PE, port->addr); + xhci_portsc_writel(port, portsc | PORT_PE); portsc = readl(port->addr); xhci_dbg(xhci, "disable port %d-%d, portsc: 0x%x\n", @@ -609,7 +609,7 @@ static void xhci_disable_port(struct xhci_hcd *xhci, struct xhci_port *port) } static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue, - u16 wIndex, __le32 __iomem *addr, u32 port_status) + u16 wIndex, struct xhci_port *port, u32 port_status) { char *port_change_bit; u32 status; @@ -652,8 +652,8 @@ static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue, return; } /* Change bits are all write 1 to clear */ - writel(port_status | status, addr); - port_status = readl(addr); + xhci_portsc_writel(port, port_status | status); + port_status = readl(port->addr); xhci_dbg(xhci, "clear port%d %s change, portsc: 0x%x\n", wIndex + 1, port_change_bit, port_status); @@ -690,11 +690,11 @@ static void xhci_set_port_power(struct xhci_hcd *xhci, struct xhci_port *port, if (on) { /* Power on */ - writel(temp | PORT_POWER, port->addr); + xhci_portsc_writel(port, temp | PORT_POWER); readl(port->addr); } else { /* Power off */ - writel(temp & ~PORT_POWER, port->addr); + xhci_portsc_writel(port, temp & ~PORT_POWER); } spin_unlock_irqrestore(&xhci->lock, *flags); @@ -793,7 +793,7 @@ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, temp = xhci_port_state_to_neutral(portsc); temp &= ~PORT_PLS_MASK; temp |= PORT_LINK_STROBE | link_state; - writel(temp, port->addr); + xhci_portsc_writel(port, temp); xhci_dbg(xhci, "Set port %d-%d link state, portsc: 0x%x, write 0x%x", port->rhub->hcd->self.busnum, port->hcd_portnum + 1, @@ -823,7 +823,7 @@ static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci, else temp &= ~PORT_WKOC_E; - writel(temp, port->addr); + xhci_portsc_writel(port, temp); } /* Test and clear port RWC bit */ @@ -836,7 +836,7 @@ void xhci_test_and_clear_bit(struct xhci_hcd *xhci, struct xhci_port *port, if (temp & port_bit) { temp = xhci_port_state_to_neutral(temp); temp |= port_bit; - writel(temp, port->addr); + xhci_portsc_writel(port, temp); } } @@ -1365,7 +1365,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, temp |= PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | PORT_RC | PORT_PLC | PORT_CEC; - writel(temp | PORT_PE, port->addr); + xhci_portsc_writel(port, temp | PORT_PE); temp = readl(port->addr); break; } @@ -1496,7 +1496,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, break; case USB_PORT_FEAT_RESET: temp = (temp | PORT_RESET); - writel(temp, port->addr); + xhci_portsc_writel(port, temp); temp = readl(port->addr); xhci_dbg(xhci, "set port reset, actual port %d-%d status = 0x%x\n", @@ -1510,7 +1510,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, break; case USB_PORT_FEAT_BH_PORT_RESET: temp |= PORT_WR; - writel(temp, port->addr); + xhci_portsc_writel(port, temp); temp = readl(port->addr); break; case USB_PORT_FEAT_U1_TIMEOUT: @@ -1601,8 +1601,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, case USB_PORT_FEAT_C_ENABLE: case USB_PORT_FEAT_C_PORT_LINK_STATE: case USB_PORT_FEAT_C_PORT_CONFIG_ERROR: - xhci_clear_port_change_bit(xhci, wValue, wIndex, - port->addr, temp); + xhci_clear_port_change_bit(xhci, wValue, wIndex, port, temp); break; case USB_PORT_FEAT_ENABLE: xhci_disable_port(xhci, port); @@ -1830,7 +1829,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd) spin_lock_irqsave(&xhci->lock, flags); } } - writel(portsc_buf[port_index], ports[port_index]->addr); + xhci_portsc_writel(ports[port_index], portsc_buf[port_index]); } hcd->state = HC_STATE_SUSPENDED; bus_state->next_statechange = jiffies + msecs_to_jiffies(10); @@ -1864,7 +1863,7 @@ static bool xhci_port_missing_cas_quirk(struct xhci_port *port) /* clear wakeup/change bits, and do a warm port reset */ portsc &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS); portsc |= PORT_WR; - writel(portsc, port->addr); + xhci_portsc_writel(port, portsc); /* flush write */ readl(port->addr); return true; @@ -1944,7 +1943,7 @@ int xhci_bus_resume(struct usb_hcd *hcd) } /* disable wake for all ports, write new link state if needed */ portsc &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS); - writel(portsc, ports[port_index]->addr); + xhci_portsc_writel(ports[port_index], portsc); } /* USB2 specific resume signaling delay and U0 link state transition */ diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index d5ba5a34625be..0b4e1a5895d35 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -964,7 +964,7 @@ static int xhci_pci_poweroff_late(struct usb_hcd *hcd, bool do_wakeup) xhci_dbg(xhci, "port %d-%d in U3 without wakeup, disable it\n", port->rhub->hcd->self.busnum, port->hcd_portnum + 1); portsc = xhci_port_state_to_neutral(portsc); - writel(portsc | PORT_PE, port->addr); + xhci_portsc_writel(port, portsc | PORT_PE); } return 0; diff --git a/drivers/usb/host/xhci-trace.h b/drivers/usb/host/xhci-trace.h index d6b32f2ad90ec..57955c1b5b9a3 100644 --- a/drivers/usb/host/xhci-trace.h +++ b/drivers/usb/host/xhci-trace.h @@ -540,6 +540,11 @@ DEFINE_EVENT(xhci_log_portsc, xhci_hub_status_data, TP_ARGS(portnum, portsc) ); +DEFINE_EVENT(xhci_log_portsc, xhci_portsc_writel, + TP_PROTO(u32 portnum, u32 portsc), + TP_ARGS(portnum, portsc) +); + DECLARE_EVENT_CLASS(xhci_log_doorbell, TP_PROTO(u32 slot, u32 doorbell), TP_ARGS(slot, doorbell), diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 210b5727d1a63..5d7a29c6c2a47 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -39,6 +39,13 @@ static unsigned long long quirks; module_param(quirks, ullong, S_IRUGO); MODULE_PARM_DESC(quirks, "Bit flags for quirks to be enabled as default"); +void xhci_portsc_writel(struct xhci_port *port, u32 val) +{ + trace_xhci_portsc_writel(port->hcd_portnum, val); + writel(val, port->addr); +} +EXPORT_SYMBOL_GPL(xhci_portsc_writel); + static bool td_on_ring(struct xhci_td *td, struct xhci_ring *ring) { struct xhci_segment *seg = ring->first_seg; @@ -826,7 +833,7 @@ static void xhci_disable_hub_port_wake(struct xhci_hcd *xhci, t2 |= PORT_CSC; if (t1 != t2) { - writel(t2, rhub->ports[i]->addr); + xhci_portsc_writel(rhub->ports[i], t2); xhci_dbg(xhci, "config port %d-%d wake bits, portsc: 0x%x, write: 0x%x\n", rhub->hcd->self.busnum, i + 1, portsc, t2); } diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index bb7e73df297ab..229964a1dce31 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1974,6 +1974,7 @@ void xhci_cleanup_command_queue(struct xhci_hcd *xhci); void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring); unsigned int count_trbs(u64 addr, u64 len); void xhci_process_cancelled_tds(struct xhci_virt_ep *ep); +void xhci_portsc_writel(struct xhci_port *port, u32 val); /* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, -- 2.53.0