* [PATCH v3 0/5] usb: xhci: add Port Register struct and tracing
@ 2025-10-28 14:12 Niklas Neronin
2025-10-28 14:12 ` [PATCH v3 1/5] usb: xhci: rework xhci_decode_portsc() Niklas Neronin
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Niklas Neronin @ 2025-10-28 14:12 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
The aim of this patch set is to introduce tracing for PORTSC writes and
implement a Port Register Set struct. This is the first part in a larger
series of changes.
Introduces a new struct for the Host Controller USB Port Register Set.
The current implementation accesses these registers through a single
'__le32' pointer, which, in conjunction with a macro, navigates to the
specific register using (base address + offset).
Currently, how its accessed | Register Name
--------------------------------------------------------------------------
port->addr | Port Status and Control
port->addr + PORTPMSC | Port Power Management Status and Control
port->addr + PORTLI | Port Link Info
port->addr + PORTHLPMC | Port Hardware LPM Control
After, how its accessed | Register Name
--------------------------------------------------------------------------
port->port_reg->portsc | Port Status and Control
port->port_reg->portpmsc | Port Power Management Status and Control
port->port_reg->portli | Port Link Info
port->port_reg->porthlmpc | Port Hardware LPM Control
These changes make it easier for future modification and their review.
v3 changes:
* Rebased on top of 6.18-rc1.
* Further simplified and generalized xhci_decode_portsc().
* Changed PORTSC read/write functions names.
* Added EXPORT_SYMBOL_GPL() to PORTSC read/write.
* Folded rename patch into Port Register struct implementation patch.
v2 changes:
* Fix acronym spelling to PORTSC from PORTCS, in all commit messages.
* Add patch introducing xhci_get_portsc().
Niklas Neronin (5):
usb: xhci: rework xhci_decode_portsc()
usb: xhci: add tracing for PORTSC register writes
usb: xhci: add helper to read PORTSC register
usb: xhci: add USB Port Register Set struct
usb: xhci: implement USB Port Register Set struct
drivers/usb/host/xhci-debugfs.c | 6 +-
drivers/usb/host/xhci-hub.c | 115 ++++++++++++++++----------------
drivers/usb/host/xhci-mem.c | 3 +-
drivers/usb/host/xhci-pci.c | 4 +-
drivers/usb/host/xhci-ring.c | 2 +-
drivers/usb/host/xhci-tegra.c | 12 ++--
drivers/usb/host/xhci-trace.h | 5 ++
drivers/usb/host/xhci.c | 48 ++++++++-----
drivers/usb/host/xhci.h | 102 +++++++++++++++-------------
9 files changed, 159 insertions(+), 138 deletions(-)
--
2.50.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 1/5] usb: xhci: rework xhci_decode_portsc()
2025-10-28 14:12 [PATCH v3 0/5] usb: xhci: add Port Register struct and tracing Niklas Neronin
@ 2025-10-28 14:12 ` Niklas Neronin
2025-10-28 14:12 ` [PATCH v3 2/5] usb: xhci: add tracing for PORTSC register writes Niklas Neronin
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Niklas Neronin @ 2025-10-28 14:12 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
Rework xhci_decode_portsc(), which is used for PORTSC tracing, to make
the output more compact and general.
The function now first prints the multi-bit fields (port speed and link
state), followed by the abbreviated names of each individual bit as
defined in the xHCI specification. This reduces message length and makes
the output easier to read.
This change prepares for upcoming patches that will trace all PORTSC
writes, requiring the same decoding logic to handle both reads and writes.
This is particularly important for Read-Write-1-to-Clear (RW1C) bits,
where the semantics differ between read and write operations. For
example, when reading the Port Enabled bit, a set bit means the port is
enabled; when writing, a set bit indicates the port is being disabled.
The decoder now also includes the following fields:
Port Link State Write Strobe (LWS)
Device Removable (DR)
Warm Port Reset (WPR)
==== Examples Traces ====
Before:
0x00201201 Powered Connected Disabled Link:U0 PortSpeed:4 Change: PRC Wake:
0x0a0002a0 Powered Not-connected Disabled Link:RxDetect PortSpeed:0 \
Change: Wake: WCE WOE
After:
0x00201201 Speed=4 Link=U0 CCS PP PRC
0x0a0002a0 Speed=0 Link=RxDetect PP WCE WOE
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
v3:
* Further simplified and generalized xhci_decode_portsc().
drivers/usb/host/xhci.h | 59 +++++++++++++++++++++++++----------------
1 file changed, 36 insertions(+), 23 deletions(-)
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 58a51f09cceb..8e1311f90fdb 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -2399,25 +2399,48 @@ static inline const char *xhci_decode_portsc(char *str, u32 portsc)
if (portsc == ~(u32)0)
return str;
- ret += sprintf(str + ret, "%s %s %s Link:%s PortSpeed:%d ",
- portsc & PORT_POWER ? "Powered" : "Powered-off",
- portsc & PORT_CONNECT ? "Connected" : "Not-connected",
- portsc & PORT_PE ? "Enabled" : "Disabled",
- xhci_portsc_link_state_string(portsc),
- DEV_PORT_SPEED(portsc));
+ ret += sprintf(str + ret, "Speed=%d ", DEV_PORT_SPEED(portsc));
+ ret += sprintf(str + ret, "Link=%s ", xhci_portsc_link_state_string(portsc));
+ /* RO/ROS: Read-only */
+ if (portsc & PORT_CONNECT)
+ ret += sprintf(str + ret, "CCS ");
if (portsc & PORT_OC)
- ret += sprintf(str + ret, "OverCurrent ");
- if (portsc & PORT_RESET)
- ret += sprintf(str + ret, "In-Reset ");
+ ret += sprintf(str + ret, "OCA "); /* No set for USB2 ports */
+ if (portsc & PORT_CAS)
+ ret += sprintf(str + ret, "CAS ");
+ if (portsc & PORT_DEV_REMOVE)
+ ret += sprintf(str + ret, "DR ");
- ret += sprintf(str + ret, "Change: ");
+ /* RWS; writing 1 sets the bit, writing 0 clears the bit. */
+ if (portsc & PORT_POWER)
+ ret += sprintf(str + ret, "PP ");
+ if (portsc & PORT_WKCONN_E)
+ ret += sprintf(str + ret, "WCE ");
+ if (portsc & PORT_WKDISC_E)
+ ret += sprintf(str + ret, "WDE ");
+ if (portsc & PORT_WKOC_E)
+ ret += sprintf(str + ret, "WOE ");
+
+ /* RW; writing 1 sets the bit, writing 0 clears the bit */
+ if (portsc & PORT_LINK_STROBE)
+ ret += sprintf(str + ret, "LWS "); /* LWS 0 write is ignored */
+
+ /* RW1S; writing 1 sets the bit, writing 0 has no effect */
+ if (portsc & PORT_RESET)
+ ret += sprintf(str + ret, "PR ");
+ if (portsc & PORT_WR)
+ ret += sprintf(str + ret, "WPR "); /* RsvdZ for USB2 ports */
+
+ /* RW1CS; writing 1 clears the bit, writing 0 has no effect. */
+ if (portsc & PORT_PE)
+ ret += sprintf(str + ret, "PED ");
if (portsc & PORT_CSC)
ret += sprintf(str + ret, "CSC ");
if (portsc & PORT_PEC)
- ret += sprintf(str + ret, "PEC ");
+ ret += sprintf(str + ret, "PEC "); /* No set for USB3 ports */
if (portsc & PORT_WRC)
- ret += sprintf(str + ret, "WRC ");
+ ret += sprintf(str + ret, "WRC "); /* RsvdZ for USB2 ports */
if (portsc & PORT_OCC)
ret += sprintf(str + ret, "OCC ");
if (portsc & PORT_RC)
@@ -2425,17 +2448,7 @@ static inline const char *xhci_decode_portsc(char *str, u32 portsc)
if (portsc & PORT_PLC)
ret += sprintf(str + ret, "PLC ");
if (portsc & PORT_CEC)
- ret += sprintf(str + ret, "CEC ");
- if (portsc & PORT_CAS)
- ret += sprintf(str + ret, "CAS ");
-
- ret += sprintf(str + ret, "Wake: ");
- if (portsc & PORT_WKCONN_E)
- ret += sprintf(str + ret, "WCE ");
- if (portsc & PORT_WKDISC_E)
- ret += sprintf(str + ret, "WDE ");
- if (portsc & PORT_WKOC_E)
- ret += sprintf(str + ret, "WOE ");
+ ret += sprintf(str + ret, "CEC "); /* RsvdZ for USB2 ports */
return str;
}
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 2/5] usb: xhci: add tracing for PORTSC register writes
2025-10-28 14:12 [PATCH v3 0/5] usb: xhci: add Port Register struct and tracing Niklas Neronin
2025-10-28 14:12 ` [PATCH v3 1/5] usb: xhci: rework xhci_decode_portsc() Niklas Neronin
@ 2025-10-28 14:12 ` Niklas Neronin
2025-10-28 14:12 ` [PATCH v3 3/5] usb: xhci: add helper to read PORTSC register Niklas Neronin
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Niklas Neronin @ 2025-10-28 14:12 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
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 <niklas.neronin@linux.intel.com>
---
v3:
* Change xhci_set_portsc() to xhci_portsc_writel().
* Added EXPORT_SYMBOL_GPL() to xhci_portsc_writel().
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 c6d44977193f..df99fffc6120 100644
--- a/drivers/usb/host/xhci-debugfs.c
+++ b/drivers/usb/host/xhci-debugfs.c
@@ -367,7 +367,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 b3a59ce1b3f4..2766c2b8e075 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -570,7 +570,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",
@@ -578,7 +578,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;
@@ -621,8 +621,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);
@@ -659,11 +659,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);
@@ -805,7 +805,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,
@@ -835,7 +835,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 */
@@ -848,7 +848,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);
}
}
@@ -1371,7 +1371,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;
}
@@ -1500,7 +1500,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",
@@ -1514,7 +1514,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:
@@ -1603,8 +1603,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);
@@ -1829,7 +1828,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);
@@ -1863,7 +1862,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;
@@ -1942,7 +1941,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 f67a4d956204..b1192648aee7 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -919,7 +919,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 9abc904f1749..481becbcbf81 100644
--- a/drivers/usb/host/xhci-trace.h
+++ b/drivers/usb/host/xhci-trace.h
@@ -575,6 +575,11 @@ DEFINE_EVENT(xhci_log_portsc, xhci_hub_status_data,
TP_ARGS(port, portsc)
);
+DEFINE_EVENT(xhci_log_portsc, xhci_portsc_writel,
+ TP_PROTO(struct xhci_port *port, u32 portsc),
+ TP_ARGS(port, 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 0cb45b95e4f5..84e109dbabe8 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -41,6 +41,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, 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;
@@ -909,7 +916,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 8e1311f90fdb..3b6b2d0d4c60 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1961,6 +1961,7 @@ void xhci_update_erst_dequeue(struct xhci_hcd *xhci,
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);
+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.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 3/5] usb: xhci: add helper to read PORTSC register
2025-10-28 14:12 [PATCH v3 0/5] usb: xhci: add Port Register struct and tracing Niklas Neronin
2025-10-28 14:12 ` [PATCH v3 1/5] usb: xhci: rework xhci_decode_portsc() Niklas Neronin
2025-10-28 14:12 ` [PATCH v3 2/5] usb: xhci: add tracing for PORTSC register writes Niklas Neronin
@ 2025-10-28 14:12 ` Niklas Neronin
2025-10-31 3:08 ` Peter Chen (CIX)
2025-10-28 14:12 ` [PATCH v3 4/5] usb: xhci: add USB Port Register Set struct Niklas Neronin
2025-10-28 14:12 ` [PATCH v3 5/5] usb: xhci: implement " Niklas Neronin
4 siblings, 1 reply; 7+ messages in thread
From: Niklas Neronin @ 2025-10-28 14:12 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin, Peter Chen
Add a dedicated helper function to read the USB Port Status and Control
(PORTSC) register. This complements xhci_portsc_writel() and improves code
clarity by providing a clear counterpart for reading the register.
Suggested-by: Peter Chen <peter.chen@kernel.org>
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
v3:
* Change xhci_get_portsc() to xhci_portsc_readl().
* Added EXPORT_SYMBOL_GPL() to xhci_portsc_readl().
drivers/usb/host/xhci-debugfs.c | 4 +-
drivers/usb/host/xhci-hub.c | 68 ++++++++++++++++-----------------
drivers/usb/host/xhci-pci.c | 2 +-
drivers/usb/host/xhci-ring.c | 2 +-
drivers/usb/host/xhci-tegra.c | 12 +++---
drivers/usb/host/xhci.c | 14 +++++--
drivers/usb/host/xhci.h | 1 +
7 files changed, 55 insertions(+), 48 deletions(-)
diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c
index df99fffc6120..d32ac8f84691 100644
--- a/drivers/usb/host/xhci-debugfs.c
+++ b/drivers/usb/host/xhci-debugfs.c
@@ -329,7 +329,7 @@ static int xhci_portsc_show(struct seq_file *s, void *unused)
u32 portsc;
char str[XHCI_MSG_MAX];
- portsc = readl(port->addr);
+ portsc = xhci_portsc_readl(port);
seq_printf(s, "%s\n", xhci_decode_portsc(str, portsc));
return 0;
@@ -359,7 +359,7 @@ static ssize_t xhci_port_write(struct file *file, const char __user *ubuf,
return count;
spin_lock_irqsave(&xhci->lock, flags);
/* compliance mode can only be enabled on ports in RxDetect */
- portsc = readl(port->addr);
+ portsc = xhci_portsc_readl(port);
if ((portsc & PORT_PLS_MASK) != XDEV_RXDETECT) {
spin_unlock_irqrestore(&xhci->lock, flags);
return -EPERM;
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 2766c2b8e075..0158861f6309 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -299,7 +299,7 @@ static void xhci_usb2_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
*/
memset(port_removable, 0, sizeof(port_removable));
for (i = 0; i < ports; i++) {
- portsc = readl(rhub->ports[i]->addr);
+ portsc = xhci_portsc_readl(rhub->ports[i]);
/* If a device is removable, PORTSC reports a 0, same as in the
* hub descriptor DeviceRemovable bits.
*/
@@ -356,7 +356,7 @@ static void xhci_usb3_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
port_removable = 0;
/* bit 0 is reserved, bit 1 is for port 1, etc. */
for (i = 0; i < ports; i++) {
- portsc = readl(rhub->ports[i]->addr);
+ portsc = xhci_portsc_readl(rhub->ports[i]);
if (portsc & PORT_DEV_REMOVE)
port_removable |= 1 << (i + 1);
}
@@ -566,13 +566,13 @@ static void xhci_disable_port(struct xhci_hcd *xhci, struct xhci_port *port)
return;
}
- portsc = readl(port->addr);
+ portsc = xhci_portsc_readl(port);
portsc = xhci_port_state_to_neutral(portsc);
/* Write 1 to disable the port */
xhci_portsc_writel(port, portsc | PORT_PE);
- portsc = readl(port->addr);
+ portsc = xhci_portsc_readl(port);
xhci_dbg(xhci, "disable port %d-%d, portsc: 0x%x\n",
hcd->self.busnum, port->hcd_portnum + 1, portsc);
}
@@ -622,7 +622,7 @@ static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue,
}
/* Change bits are all write 1 to clear */
xhci_portsc_writel(port, port_status | status);
- port_status = readl(port->addr);
+ port_status = xhci_portsc_readl(port);
xhci_dbg(xhci, "clear port%d %s change, portsc: 0x%x\n",
wIndex + 1, port_change_bit, port_status);
@@ -650,7 +650,7 @@ static void xhci_set_port_power(struct xhci_hcd *xhci, struct xhci_port *port,
u32 temp;
hcd = port->rhub->hcd;
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
xhci_dbg(xhci, "set port power %d-%d %s, portsc: 0x%x\n",
hcd->self.busnum, port->hcd_portnum + 1, on ? "ON" : "OFF", temp);
@@ -660,7 +660,7 @@ static void xhci_set_port_power(struct xhci_hcd *xhci, struct xhci_port *port,
if (on) {
/* Power on */
xhci_portsc_writel(port, temp | PORT_POWER);
- readl(port->addr);
+ xhci_portsc_readl(port);
} else {
/* Power off */
xhci_portsc_writel(port, temp & ~PORT_POWER);
@@ -801,7 +801,7 @@ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
u32 temp;
u32 portsc;
- portsc = readl(port->addr);
+ portsc = xhci_portsc_readl(port);
temp = xhci_port_state_to_neutral(portsc);
temp &= ~PORT_PLS_MASK;
temp |= PORT_LINK_STROBE | link_state;
@@ -817,7 +817,7 @@ static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci,
{
u32 temp;
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
temp = xhci_port_state_to_neutral(temp);
if (wake_mask & USB_PORT_FEAT_REMOTE_WAKE_CONNECT)
@@ -844,7 +844,7 @@ void xhci_test_and_clear_bit(struct xhci_hcd *xhci, struct xhci_port *port,
{
u32 temp;
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
if (temp & port_bit) {
temp = xhci_port_state_to_neutral(temp);
temp |= port_bit;
@@ -1002,7 +1002,7 @@ static int xhci_handle_usb2_port_link_resume(struct xhci_port *port,
}
xhci_ring_device(xhci, port->slot_id);
} else {
- int port_status = readl(port->addr);
+ int port_status = xhci_portsc_readl(port);
xhci_warn(xhci, "Port resume timed out, port %d-%d: 0x%x\n",
hcd->self.busnum, wIndex + 1, port_status);
@@ -1263,7 +1263,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
wIndex--;
port = ports[portnum1 - 1];
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
if (temp == ~(u32)0) {
xhci_hc_died(xhci);
retval = -ENODEV;
@@ -1309,7 +1309,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
port = ports[portnum1 - 1];
wIndex--;
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
if (temp == ~(u32)0) {
xhci_hc_died(xhci);
retval = -ENODEV;
@@ -1319,7 +1319,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
/* FIXME: What new port features do we need to support? */
switch (wValue) {
case USB_PORT_FEAT_SUSPEND:
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
if ((temp & PORT_PLS_MASK) != XDEV_U0) {
/* Resume the port to U0 first */
xhci_set_link_state(xhci, port, XDEV_U0);
@@ -1331,7 +1331,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
* a port unless the port reports that it is in the
* enabled (PED = ‘1’,PLS < ‘3’) state.
*/
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
if ((temp & PORT_PE) == 0 || (temp & PORT_RESET)
|| (temp & PORT_PLS_MASK) >= XDEV_U3) {
xhci_warn(xhci, "USB core suspending port %d-%d not in U0/U1/U2\n",
@@ -1354,11 +1354,11 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
msleep(10); /* wait device to enter */
spin_lock_irqsave(&xhci->lock, flags);
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
bus_state->suspended_ports |= 1 << wIndex;
break;
case USB_PORT_FEAT_LINK_STATE:
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
/* Disable port */
if (link_state == USB_SS_PORT_LS_SS_DISABLED) {
xhci_dbg(xhci, "Disable port %d-%d\n",
@@ -1372,7 +1372,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
PORT_OCC | PORT_RC | PORT_PLC |
PORT_CEC;
xhci_portsc_writel(port, temp | PORT_PE);
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
break;
}
@@ -1381,7 +1381,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
xhci_dbg(xhci, "Enable port %d-%d\n",
hcd->self.busnum, portnum1);
xhci_set_link_state(xhci, port, link_state);
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
break;
}
@@ -1414,7 +1414,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
hcd->self.busnum, portnum1);
xhci_set_link_state(xhci, port, link_state);
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
break;
}
/* Port must be enabled */
@@ -1462,7 +1462,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
xhci_dbg(xhci, "missing U0 port change event for port %d-%d\n",
hcd->self.busnum, portnum1);
spin_lock_irqsave(&xhci->lock, flags);
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
break;
}
@@ -1480,12 +1480,12 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
spin_unlock_irqrestore(&xhci->lock, flags);
while (retries--) {
usleep_range(4000, 8000);
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
if ((temp & PORT_PLS_MASK) == XDEV_U3)
break;
}
spin_lock_irqsave(&xhci->lock, flags);
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
bus_state->suspended_ports |= 1 << wIndex;
}
break;
@@ -1502,20 +1502,20 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
temp = (temp | PORT_RESET);
xhci_portsc_writel(port, temp);
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
xhci_dbg(xhci, "set port reset, actual port %d-%d status = 0x%x\n",
hcd->self.busnum, portnum1, temp);
break;
case USB_PORT_FEAT_REMOTE_WAKE_MASK:
xhci_set_remote_wake_mask(xhci, port, wake_mask);
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
xhci_dbg(xhci, "set port remote wake mask, actual port %d-%d status = 0x%x\n",
hcd->self.busnum, portnum1, temp);
break;
case USB_PORT_FEAT_BH_PORT_RESET:
temp |= PORT_WR;
xhci_portsc_writel(port, temp);
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
break;
case USB_PORT_FEAT_U1_TIMEOUT:
if (hcd->speed < HCD_USB3)
@@ -1547,7 +1547,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
goto error;
}
/* unblock any posted writes */
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
break;
case ClearPortFeature:
if (!portnum1 || portnum1 > max_ports)
@@ -1556,7 +1556,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
port = ports[portnum1 - 1];
wIndex--;
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
if (temp == ~(u32)0) {
xhci_hc_died(xhci);
retval = -ENODEV;
@@ -1566,7 +1566,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
temp = xhci_port_state_to_neutral(temp);
switch (wValue) {
case USB_PORT_FEAT_SUSPEND:
- temp = readl(port->addr);
+ temp = xhci_portsc_readl(port);
xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n");
xhci_dbg(xhci, "PORTSC %04x\n", temp);
if (temp & PORT_RESET)
@@ -1681,7 +1681,7 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
/* For each port, did anything change? If so, set that bit in buf. */
for (i = 0; i < max_ports; i++) {
- temp = readl(ports[i]->addr);
+ temp = xhci_portsc_readl(ports[i]);
if (temp == ~(u32)0) {
xhci_hc_died(xhci);
retval = -ENODEV;
@@ -1750,7 +1750,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
u32 t1, t2;
int retries = 10;
retry:
- t1 = readl(ports[port_index]->addr);
+ t1 = xhci_portsc_readl(ports[port_index]);
t2 = xhci_port_state_to_neutral(t1);
portsc_buf[port_index] = 0;
@@ -1849,7 +1849,7 @@ static bool xhci_port_missing_cas_quirk(struct xhci_port *port)
{
u32 portsc;
- portsc = readl(port->addr);
+ portsc = xhci_portsc_readl(port);
/* if any of these are set we are not stuck */
if (portsc & (PORT_CONNECT | PORT_CAS))
@@ -1864,7 +1864,7 @@ static bool xhci_port_missing_cas_quirk(struct xhci_port *port)
portsc |= PORT_WR;
xhci_portsc_writel(port, portsc);
/* flush write */
- readl(port->addr);
+ xhci_portsc_readl(port);
return true;
}
@@ -1911,7 +1911,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
}
port_index = max_ports;
while (port_index--) {
- portsc = readl(ports[port_index]->addr);
+ portsc = xhci_portsc_readl(ports[port_index]);
/* warm reset CAS limited ports stuck in polling/compliance */
if ((xhci->quirks & XHCI_MISSING_CAS) &&
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index b1192648aee7..2ba0261a29c1 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -898,7 +898,7 @@ static int xhci_pci_poweroff_late(struct usb_hcd *hcd, bool do_wakeup)
for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) {
port = &xhci->hw_ports[i];
- portsc = readl(port->addr);
+ portsc = xhci_portsc_readl(port);
if ((portsc & PORT_PLS_MASK) != XDEV_U3)
continue;
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 8e209aa33ea7..47ca7783b633 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2026,7 +2026,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
hcd = port->rhub->hcd;
bus_state = &port->rhub->bus_state;
hcd_portnum = port->hcd_portnum;
- portsc = readl(port->addr);
+ portsc = xhci_portsc_readl(port);
xhci_dbg(xhci, "Port change event, %d-%d, id %d, portsc: 0x%x\n",
hcd->self.busnum, hcd_portnum + 1, port_id, portsc);
diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c
index 5255b1002893..1e23f198a005 100644
--- a/drivers/usb/host/xhci-tegra.c
+++ b/drivers/usb/host/xhci-tegra.c
@@ -2036,7 +2036,7 @@ static bool xhci_hub_ports_suspended(struct xhci_hub *hub)
u32 value;
for (i = 0; i < hub->num_ports; i++) {
- value = readl(hub->ports[i]->addr);
+ value = xhci_portsc_readl(hub->ports[i]);
if ((value & PORT_PE) == 0)
continue;
@@ -2162,7 +2162,7 @@ static void tegra_xhci_enable_phy_sleepwalk_wake(struct tegra_xusb *tegra)
if (!is_host_mode_phy(tegra, i, j))
continue;
- portsc = readl(rhub->ports[index]->addr);
+ portsc = xhci_portsc_readl(rhub->ports[index]);
speed = tegra_xhci_portsc_to_speed(tegra, portsc);
tegra_xusb_padctl_enable_phy_sleepwalk(padctl, phy, speed);
tegra_xusb_padctl_enable_phy_wake(padctl, phy);
@@ -2257,7 +2257,7 @@ static int tegra_xusb_enter_elpg(struct tegra_xusb *tegra, bool is_auto_resume)
for (i = 0; i < xhci->usb2_rhub.num_ports; i++) {
if (!xhci->usb2_rhub.ports[i])
continue;
- portsc = readl(xhci->usb2_rhub.ports[i]->addr);
+ portsc = xhci_portsc_readl(xhci->usb2_rhub.ports[i]);
tegra->lp0_utmi_pad_mask &= ~BIT(i);
if (((portsc & PORT_PLS_MASK) == XDEV_U3) || ((portsc & DEV_SPEED_MASK) == XDEV_FS))
tegra->lp0_utmi_pad_mask |= BIT(i);
@@ -2790,7 +2790,7 @@ static int tegra_xhci_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value,
while (i--) {
if (!test_bit(i, &bus_state->resuming_ports))
continue;
- portsc = readl(ports[i]->addr);
+ portsc = xhci_portsc_readl(ports[i]);
if ((portsc & PORT_PLS_MASK) == XDEV_RESUME)
tegra_phy_xusb_utmi_pad_power_on(
tegra_xusb_get_phy(tegra, "usb2", (int) i));
@@ -2808,7 +2808,7 @@ static int tegra_xhci_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value,
if (!index || index > rhub->num_ports)
return -EPIPE;
ports = rhub->ports;
- portsc = readl(ports[port]->addr);
+ portsc = xhci_portsc_readl(ports[port]);
if (portsc & PORT_CONNECT)
tegra_phy_xusb_utmi_pad_power_on(phy);
}
@@ -2827,7 +2827,7 @@ static int tegra_xhci_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value,
if ((type_req == ClearPortFeature) && (value == USB_PORT_FEAT_C_CONNECTION)) {
ports = rhub->ports;
- portsc = readl(ports[port]->addr);
+ portsc = xhci_portsc_readl(ports[port]);
if (!(portsc & PORT_CONNECT)) {
/* We don't suspend the PAD while HNP role swap happens on the OTG
* port
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 84e109dbabe8..6b47b218cb24 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -48,6 +48,12 @@ void xhci_portsc_writel(struct xhci_port *port, u32 val)
}
EXPORT_SYMBOL_GPL(xhci_portsc_writel);
+u32 xhci_portsc_readl(struct xhci_port *port)
+{
+ return readl(port->addr);
+}
+EXPORT_SYMBOL_GPL(xhci_portsc_readl);
+
static bool td_on_ring(struct xhci_td *td, struct xhci_ring *ring)
{
struct xhci_segment *seg;
@@ -380,7 +386,7 @@ static void compliance_mode_recovery(struct timer_list *t)
return;
for (i = 0; i < rhub->num_ports; i++) {
- temp = readl(rhub->ports[i]->addr);
+ temp = xhci_portsc_readl(rhub->ports[i]);
if ((temp & PORT_PLS_MASK) == USB_SS_PORT_LS_COMP_MOD) {
/*
* Compliance Mode Detected. Letting USB Core
@@ -903,7 +909,7 @@ static void xhci_disable_hub_port_wake(struct xhci_hcd *xhci,
spin_lock_irqsave(&xhci->lock, flags);
for (i = 0; i < rhub->num_ports; i++) {
- portsc = readl(rhub->ports[i]->addr);
+ portsc = xhci_portsc_readl(rhub->ports[i]);
t1 = xhci_port_state_to_neutral(portsc);
t2 = t1;
@@ -943,7 +949,7 @@ static bool xhci_pending_portevent(struct xhci_hcd *xhci)
port_index = xhci->usb2_rhub.num_ports;
ports = xhci->usb2_rhub.ports;
while (port_index--) {
- portsc = readl(ports[port_index]->addr);
+ portsc = xhci_portsc_readl(ports[port_index]);
if (portsc & PORT_CHANGE_MASK ||
(portsc & PORT_PLS_MASK) == XDEV_RESUME)
return true;
@@ -951,7 +957,7 @@ static bool xhci_pending_portevent(struct xhci_hcd *xhci)
port_index = xhci->usb3_rhub.num_ports;
ports = xhci->usb3_rhub.ports;
while (port_index--) {
- portsc = readl(ports[port_index]->addr);
+ portsc = xhci_portsc_readl(ports[port_index]);
if (portsc & (PORT_CHANGE_MASK | PORT_CAS) ||
(portsc & PORT_PLS_MASK) == XDEV_RESUME)
return true;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 3b6b2d0d4c60..bddf9c15d813 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1962,6 +1962,7 @@ 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);
void xhci_portsc_writel(struct xhci_port *port, u32 val);
+u32 xhci_portsc_readl(struct xhci_port *port);
/* xHCI roothub code */
void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 4/5] usb: xhci: add USB Port Register Set struct
2025-10-28 14:12 [PATCH v3 0/5] usb: xhci: add Port Register struct and tracing Niklas Neronin
` (2 preceding siblings ...)
2025-10-28 14:12 ` [PATCH v3 3/5] usb: xhci: add helper to read PORTSC register Niklas Neronin
@ 2025-10-28 14:12 ` Niklas Neronin
2025-10-28 14:12 ` [PATCH v3 5/5] usb: xhci: implement " Niklas Neronin
4 siblings, 0 replies; 7+ messages in thread
From: Niklas Neronin @ 2025-10-28 14:12 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
Introduce a new struct for the Host Controller USB Port Register Set to
enhance readability and maintainability.
The Host Controller Operational Registers (struct 'xhci_op_regs') span from
offset 0x0 to 0x3FF and consist of fixed fields. Following these fixed
fields are the Host Controller USB Port Register Sets, which are dynamic
and repeat from 1 to MaxPorts, as defined by HCSPARAMS1.
Currently, the struct 'xhci_op_regs' includes:
__le32 port_status_base; The first PORTSC
__le32 port_power_base; The first PORTPMSC
__le32 port_link_base; The first PORTLI
__le32 reserved5; The first PORTHLPMC, not reserved
__le32 reserved6[NUM_PORT_REGS*254]; Port registers 2 to MaxPorts
Replace this with the simpler:
struct xhci_port_regs port_regs[]; Port registers 1 to MaxPorts
Host Controller USB Port Register Set:
| Offset | Mnemonic | Register Name
--------------------------------------------------------------------------
| 0x0 | PORTSC | Port Status and Control
| 0x4 | PORTPMSC | Port Power Management Status and Control
| 0x8 | PORTLI | Port Link Info
| 0xC | PORTHLPMC | Port Hardware LPM Control
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-mem.c | 3 +--
drivers/usb/host/xhci.h | 36 ++++++++++++++++--------------------
2 files changed, 17 insertions(+), 22 deletions(-)
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 6e5b6057de79..ea3cfc229cd0 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2201,8 +2201,7 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
return -ENOMEM;
for (i = 0; i < num_ports; i++) {
- xhci->hw_ports[i].addr = &xhci->op_regs->port_status_base +
- NUM_PORT_REGS * i;
+ xhci->hw_ports[i].addr = &xhci->op_regs->port_regs[i].portsc;
xhci->hw_ports[i].hw_portnum = i;
init_completion(&xhci->hw_ports[i].rexit_done);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index bddf9c15d813..d3ba50462589 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -66,14 +66,25 @@ struct xhci_cap_regs {
/* Reserved up to (CAPLENGTH - 0x1C) */
};
-/* Number of registers per port */
-#define NUM_PORT_REGS 4
-
#define PORTSC 0
#define PORTPMSC 1
#define PORTLI 2
#define PORTHLPMC 3
+/*
+ * struct xhci_port_regs - Host Controller USB Port Register Set. xHCI spec 5.4.8
+ * @portsc: Port Status and Control
+ * @portpmsc: Port Power Management Status and Control
+ * @portli: Port Link Info
+ * @porthlmpc: Port Hardware LPM Control
+ */
+struct xhci_port_regs {
+ __le32 portsc;
+ __le32 portpmsc;
+ __le32 portli;
+ __le32 porthlmpc;
+};
+
/**
* struct xhci_op_regs - xHCI Host Controller Operational Registers.
* @command: USBCMD - xHC command register
@@ -85,16 +96,7 @@ struct xhci_cap_regs {
* @cmd_ring: CRP - 64-bit Command Ring Pointer
* @dcbaa_ptr: DCBAAP - 64-bit Device Context Base Address Array Pointer
* @config_reg: CONFIG - Configure Register
- * @port_status_base: PORTSCn - base address for Port Status and Control
- * Each port has a Port Status and Control register,
- * followed by a Port Power Management Status and Control
- * register, a Port Link Info register, and a reserved
- * register.
- * @port_power_base: PORTPMSCn - base address for
- * Port Power Management Status and Control
- * @port_link_base: PORTLIn - base address for Port Link Info (current
- * Link PM state and control) for USB 2.1 and USB 3.0
- * devices.
+ * @port_regs: Port Register Sets, from 1 to MaxPorts (defined by HCSPARAMS1).
*/
struct xhci_op_regs {
__le32 command;
@@ -110,13 +112,7 @@ struct xhci_op_regs {
__le32 config_reg;
/* rsvd: offset 0x3C-3FF */
__le32 reserved4[241];
- /* port 1 registers, which serve as a base address for other ports */
- __le32 port_status_base;
- __le32 port_power_base;
- __le32 port_link_base;
- __le32 reserved5;
- /* registers for ports 2-255 */
- __le32 reserved6[NUM_PORT_REGS*254];
+ struct xhci_port_regs port_regs[];
};
/* USBCMD - USB command - command bitmasks */
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 5/5] usb: xhci: implement USB Port Register Set struct
2025-10-28 14:12 [PATCH v3 0/5] usb: xhci: add Port Register struct and tracing Niklas Neronin
` (3 preceding siblings ...)
2025-10-28 14:12 ` [PATCH v3 4/5] usb: xhci: add USB Port Register Set struct Niklas Neronin
@ 2025-10-28 14:12 ` Niklas Neronin
4 siblings, 0 replies; 7+ messages in thread
From: Niklas Neronin @ 2025-10-28 14:12 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
Previously, each port's 'addr' field pointed to the base of the Host
Controller USB Port Register Set, and specific registers were accessed
using macros such as (port->addr + PORTPMSC).
This patch replaces the raw '__le32 __iomem *addr' pointer with a typed
'struct xhci_port_regs __iomem *port_reg' pointer. With this change,
individual registers can be accessed directly through the structure
fields:
Before:
port->addr
port->addr + PORTPMSC
port->addr + PORTLI
port->addr + PORTHLPMC
After:
port->port_reg->portsc
port->port_reg->portpmsc
port->port_reg->portli
port->port_reg->porthlpmc
This improves code readability and makes register access more intuitive
by using named struct members instead of pointer arithmetic and macros.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
v3:
* Folded 'addr' rename patch into this patch patch.
drivers/usb/host/xhci-hub.c | 16 ++++++++--------
drivers/usb/host/xhci-mem.c | 2 +-
drivers/usb/host/xhci.c | 29 ++++++++++++++---------------
drivers/usb/host/xhci.h | 7 +------
4 files changed, 24 insertions(+), 30 deletions(-)
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 0158861f6309..d3c241788250 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -683,9 +683,9 @@ static void xhci_port_set_test_mode(struct xhci_hcd *xhci,
/* xhci only supports test mode for usb2 ports */
port = xhci->usb2_rhub.ports[wIndex];
- temp = readl(port->addr + PORTPMSC);
+ temp = readl(&port->port_reg->portpmsc);
temp |= test_mode << PORT_TEST_MODE_SHIFT;
- writel(temp, port->addr + PORTPMSC);
+ writel(temp, &port->port_reg->portpmsc);
xhci->test_mode = test_mode;
if (test_mode == USB_TEST_FORCE_ENABLE)
xhci_start(xhci);
@@ -1288,7 +1288,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
retval = -EINVAL;
break;
}
- port_li = readl(port->addr + PORTLI);
+ port_li = readl(&port->port_reg->portli);
status = xhci_get_ext_port_status(temp, port_li);
put_unaligned_le32(status, &buf[4]);
}
@@ -1520,18 +1520,18 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
case USB_PORT_FEAT_U1_TIMEOUT:
if (hcd->speed < HCD_USB3)
goto error;
- temp = readl(port->addr + PORTPMSC);
+ temp = readl(&port->port_reg->portpmsc);
temp &= ~PORT_U1_TIMEOUT_MASK;
temp |= PORT_U1_TIMEOUT(timeout);
- writel(temp, port->addr + PORTPMSC);
+ writel(temp, &port->port_reg->portpmsc);
break;
case USB_PORT_FEAT_U2_TIMEOUT:
if (hcd->speed < HCD_USB3)
goto error;
- temp = readl(port->addr + PORTPMSC);
+ temp = readl(&port->port_reg->portpmsc);
temp &= ~PORT_U2_TIMEOUT_MASK;
temp |= PORT_U2_TIMEOUT(timeout);
- writel(temp, port->addr + PORTPMSC);
+ writel(temp, &port->port_reg->portpmsc);
break;
case USB_PORT_FEAT_TEST:
/* 4.19.6 Port Test Modes (USB2 Test Mode) */
@@ -1962,7 +1962,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
/* poll for U0 link state complete, both USB2 and USB3 */
for_each_set_bit(port_index, &bus_state->bus_suspended, BITS_PER_LONG) {
- sret = xhci_handshake(ports[port_index]->addr, PORT_PLC,
+ sret = xhci_handshake(&ports[port_index]->port_reg->portsc, PORT_PLC,
PORT_PLC, 10 * 1000);
if (sret) {
xhci_warn(xhci, "port %d-%d resume PLC timeout\n",
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index ea3cfc229cd0..9a6a8d9f3770 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2201,7 +2201,7 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
return -ENOMEM;
for (i = 0; i < num_ports; i++) {
- xhci->hw_ports[i].addr = &xhci->op_regs->port_regs[i].portsc;
+ xhci->hw_ports[i].port_reg = &xhci->op_regs->port_regs[i];
xhci->hw_ports[i].hw_portnum = i;
init_completion(&xhci->hw_ports[i].rexit_done);
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 6b47b218cb24..593b9d3aa9b6 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -44,13 +44,13 @@ 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, val);
- writel(val, port->addr);
+ writel(val, &port->port_reg->portsc);
}
EXPORT_SYMBOL_GPL(xhci_portsc_writel);
u32 xhci_portsc_readl(struct xhci_port *port)
{
- return readl(port->addr);
+ return readl(&port->port_reg->portsc);
}
EXPORT_SYMBOL_GPL(xhci_portsc_readl);
@@ -4649,7 +4649,7 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
{
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
struct xhci_port **ports;
- __le32 __iomem *pm_addr, *hlpm_addr;
+ struct xhci_port_regs __iomem *port_reg;
u32 pm_val, hlpm_val, field;
unsigned int port_num;
unsigned long flags;
@@ -4674,9 +4674,8 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
ports = xhci->usb2_rhub.ports;
port_num = udev->portnum - 1;
- pm_addr = ports[port_num]->addr + PORTPMSC;
- pm_val = readl(pm_addr);
- hlpm_addr = ports[port_num]->addr + PORTHLPMC;
+ port_reg = ports[port_num]->port_reg;
+ pm_val = readl(&port_reg->portpmsc);
xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n",
str_enable_disable(enable), port_num + 1);
@@ -4705,30 +4704,30 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
spin_lock_irqsave(&xhci->lock, flags);
hlpm_val = xhci_calculate_usb2_hw_lpm_params(udev);
- writel(hlpm_val, hlpm_addr);
+ writel(hlpm_val, &port_reg->porthlmpc);
/* flush write */
- readl(hlpm_addr);
+ readl(&port_reg->porthlmpc);
} else {
hird = xhci_calculate_hird_besl(xhci, udev);
}
pm_val &= ~PORT_HIRD_MASK;
pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id);
- writel(pm_val, pm_addr);
- pm_val = readl(pm_addr);
+ writel(pm_val, &port_reg->portpmsc);
+ pm_val = readl(&port_reg->portpmsc);
pm_val |= PORT_HLE;
- writel(pm_val, pm_addr);
+ writel(pm_val, &port_reg->portpmsc);
/* flush write */
- readl(pm_addr);
+ readl(&port_reg->portpmsc);
} else {
pm_val &= ~(PORT_HLE | PORT_RWE | PORT_HIRD_MASK | PORT_L1DS_MASK);
- writel(pm_val, pm_addr);
+ writel(pm_val, &port_reg->portpmsc);
/* flush write */
- readl(pm_addr);
+ readl(&port_reg->portpmsc);
if (udev->usb2_hw_lpm_besl_capable) {
spin_unlock_irqrestore(&xhci->lock, flags);
xhci_change_max_exit_latency(xhci, udev, 0);
- readl_poll_timeout(ports[port_num]->addr, pm_val,
+ readl_poll_timeout(&ports[port_num]->port_reg->portsc, pm_val,
(pm_val & PORT_PLS_MASK) == XDEV_U0,
100, 10000);
return 0;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index d3ba50462589..adabe26b413b 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -66,11 +66,6 @@ struct xhci_cap_regs {
/* Reserved up to (CAPLENGTH - 0x1C) */
};
-#define PORTSC 0
-#define PORTPMSC 1
-#define PORTLI 2
-#define PORTHLPMC 3
-
/*
* struct xhci_port_regs - Host Controller USB Port Register Set. xHCI spec 5.4.8
* @portsc: Port Status and Control
@@ -1470,7 +1465,7 @@ struct xhci_port_cap {
};
struct xhci_port {
- __le32 __iomem *addr;
+ struct xhci_port_regs __iomem *port_reg;
int hw_portnum;
int hcd_portnum;
struct xhci_hub *rhub;
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 3/5] usb: xhci: add helper to read PORTSC register
2025-10-28 14:12 ` [PATCH v3 3/5] usb: xhci: add helper to read PORTSC register Niklas Neronin
@ 2025-10-31 3:08 ` Peter Chen (CIX)
0 siblings, 0 replies; 7+ messages in thread
From: Peter Chen (CIX) @ 2025-10-31 3:08 UTC (permalink / raw)
To: Niklas Neronin; +Cc: mathias.nyman, linux-usb
On 25-10-28 15:12:40, Niklas Neronin wrote:
> Add a dedicated helper function to read the USB Port Status and Control
> (PORTSC) register. This complements xhci_portsc_writel() and improves code
> clarity by providing a clear counterpart for reading the register.
>
> Suggested-by: Peter Chen <peter.chen@kernel.org>
> Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
Thanks, Niklas. It could observe port link status changing easier,
and help debugging some hardware issues.
Reviewed-by: Peter Chen <peter.chen@kerne.org>
Peter
> ---
> v3:
> * Change xhci_get_portsc() to xhci_portsc_readl().
> * Added EXPORT_SYMBOL_GPL() to xhci_portsc_readl().
>
> drivers/usb/host/xhci-debugfs.c | 4 +-
> drivers/usb/host/xhci-hub.c | 68 ++++++++++++++++-----------------
> drivers/usb/host/xhci-pci.c | 2 +-
> drivers/usb/host/xhci-ring.c | 2 +-
> drivers/usb/host/xhci-tegra.c | 12 +++---
> drivers/usb/host/xhci.c | 14 +++++--
> drivers/usb/host/xhci.h | 1 +
> 7 files changed, 55 insertions(+), 48 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c
> index df99fffc6120..d32ac8f84691 100644
> --- a/drivers/usb/host/xhci-debugfs.c
> +++ b/drivers/usb/host/xhci-debugfs.c
> @@ -329,7 +329,7 @@ static int xhci_portsc_show(struct seq_file *s, void *unused)
> u32 portsc;
> char str[XHCI_MSG_MAX];
>
> - portsc = readl(port->addr);
> + portsc = xhci_portsc_readl(port);
> seq_printf(s, "%s\n", xhci_decode_portsc(str, portsc));
>
> return 0;
> @@ -359,7 +359,7 @@ static ssize_t xhci_port_write(struct file *file, const char __user *ubuf,
> return count;
> spin_lock_irqsave(&xhci->lock, flags);
> /* compliance mode can only be enabled on ports in RxDetect */
> - portsc = readl(port->addr);
> + portsc = xhci_portsc_readl(port);
> if ((portsc & PORT_PLS_MASK) != XDEV_RXDETECT) {
> spin_unlock_irqrestore(&xhci->lock, flags);
> return -EPERM;
> diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
> index 2766c2b8e075..0158861f6309 100644
> --- a/drivers/usb/host/xhci-hub.c
> +++ b/drivers/usb/host/xhci-hub.c
> @@ -299,7 +299,7 @@ static void xhci_usb2_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
> */
> memset(port_removable, 0, sizeof(port_removable));
> for (i = 0; i < ports; i++) {
> - portsc = readl(rhub->ports[i]->addr);
> + portsc = xhci_portsc_readl(rhub->ports[i]);
> /* If a device is removable, PORTSC reports a 0, same as in the
> * hub descriptor DeviceRemovable bits.
> */
> @@ -356,7 +356,7 @@ static void xhci_usb3_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
> port_removable = 0;
> /* bit 0 is reserved, bit 1 is for port 1, etc. */
> for (i = 0; i < ports; i++) {
> - portsc = readl(rhub->ports[i]->addr);
> + portsc = xhci_portsc_readl(rhub->ports[i]);
> if (portsc & PORT_DEV_REMOVE)
> port_removable |= 1 << (i + 1);
> }
> @@ -566,13 +566,13 @@ static void xhci_disable_port(struct xhci_hcd *xhci, struct xhci_port *port)
> return;
> }
>
> - portsc = readl(port->addr);
> + portsc = xhci_portsc_readl(port);
> portsc = xhci_port_state_to_neutral(portsc);
>
> /* Write 1 to disable the port */
> xhci_portsc_writel(port, portsc | PORT_PE);
>
> - portsc = readl(port->addr);
> + portsc = xhci_portsc_readl(port);
> xhci_dbg(xhci, "disable port %d-%d, portsc: 0x%x\n",
> hcd->self.busnum, port->hcd_portnum + 1, portsc);
> }
> @@ -622,7 +622,7 @@ static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue,
> }
> /* Change bits are all write 1 to clear */
> xhci_portsc_writel(port, port_status | status);
> - port_status = readl(port->addr);
> + port_status = xhci_portsc_readl(port);
>
> xhci_dbg(xhci, "clear port%d %s change, portsc: 0x%x\n",
> wIndex + 1, port_change_bit, port_status);
> @@ -650,7 +650,7 @@ static void xhci_set_port_power(struct xhci_hcd *xhci, struct xhci_port *port,
> u32 temp;
>
> hcd = port->rhub->hcd;
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
>
> xhci_dbg(xhci, "set port power %d-%d %s, portsc: 0x%x\n",
> hcd->self.busnum, port->hcd_portnum + 1, on ? "ON" : "OFF", temp);
> @@ -660,7 +660,7 @@ static void xhci_set_port_power(struct xhci_hcd *xhci, struct xhci_port *port,
> if (on) {
> /* Power on */
> xhci_portsc_writel(port, temp | PORT_POWER);
> - readl(port->addr);
> + xhci_portsc_readl(port);
> } else {
> /* Power off */
> xhci_portsc_writel(port, temp & ~PORT_POWER);
> @@ -801,7 +801,7 @@ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
> u32 temp;
> u32 portsc;
>
> - portsc = readl(port->addr);
> + portsc = xhci_portsc_readl(port);
> temp = xhci_port_state_to_neutral(portsc);
> temp &= ~PORT_PLS_MASK;
> temp |= PORT_LINK_STROBE | link_state;
> @@ -817,7 +817,7 @@ static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci,
> {
> u32 temp;
>
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> temp = xhci_port_state_to_neutral(temp);
>
> if (wake_mask & USB_PORT_FEAT_REMOTE_WAKE_CONNECT)
> @@ -844,7 +844,7 @@ void xhci_test_and_clear_bit(struct xhci_hcd *xhci, struct xhci_port *port,
> {
> u32 temp;
>
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> if (temp & port_bit) {
> temp = xhci_port_state_to_neutral(temp);
> temp |= port_bit;
> @@ -1002,7 +1002,7 @@ static int xhci_handle_usb2_port_link_resume(struct xhci_port *port,
> }
> xhci_ring_device(xhci, port->slot_id);
> } else {
> - int port_status = readl(port->addr);
> + int port_status = xhci_portsc_readl(port);
>
> xhci_warn(xhci, "Port resume timed out, port %d-%d: 0x%x\n",
> hcd->self.busnum, wIndex + 1, port_status);
> @@ -1263,7 +1263,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
>
> wIndex--;
> port = ports[portnum1 - 1];
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> if (temp == ~(u32)0) {
> xhci_hc_died(xhci);
> retval = -ENODEV;
> @@ -1309,7 +1309,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
>
> port = ports[portnum1 - 1];
> wIndex--;
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> if (temp == ~(u32)0) {
> xhci_hc_died(xhci);
> retval = -ENODEV;
> @@ -1319,7 +1319,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
> /* FIXME: What new port features do we need to support? */
> switch (wValue) {
> case USB_PORT_FEAT_SUSPEND:
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> if ((temp & PORT_PLS_MASK) != XDEV_U0) {
> /* Resume the port to U0 first */
> xhci_set_link_state(xhci, port, XDEV_U0);
> @@ -1331,7 +1331,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
> * a port unless the port reports that it is in the
> * enabled (PED = ‘1’,PLS < ‘3’) state.
> */
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> if ((temp & PORT_PE) == 0 || (temp & PORT_RESET)
> || (temp & PORT_PLS_MASK) >= XDEV_U3) {
> xhci_warn(xhci, "USB core suspending port %d-%d not in U0/U1/U2\n",
> @@ -1354,11 +1354,11 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
> msleep(10); /* wait device to enter */
> spin_lock_irqsave(&xhci->lock, flags);
>
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> bus_state->suspended_ports |= 1 << wIndex;
> break;
> case USB_PORT_FEAT_LINK_STATE:
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> /* Disable port */
> if (link_state == USB_SS_PORT_LS_SS_DISABLED) {
> xhci_dbg(xhci, "Disable port %d-%d\n",
> @@ -1372,7 +1372,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
> PORT_OCC | PORT_RC | PORT_PLC |
> PORT_CEC;
> xhci_portsc_writel(port, temp | PORT_PE);
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> break;
> }
>
> @@ -1381,7 +1381,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
> xhci_dbg(xhci, "Enable port %d-%d\n",
> hcd->self.busnum, portnum1);
> xhci_set_link_state(xhci, port, link_state);
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> break;
> }
>
> @@ -1414,7 +1414,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
> hcd->self.busnum, portnum1);
> xhci_set_link_state(xhci, port, link_state);
>
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> break;
> }
> /* Port must be enabled */
> @@ -1462,7 +1462,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
> xhci_dbg(xhci, "missing U0 port change event for port %d-%d\n",
> hcd->self.busnum, portnum1);
> spin_lock_irqsave(&xhci->lock, flags);
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> break;
> }
>
> @@ -1480,12 +1480,12 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
> spin_unlock_irqrestore(&xhci->lock, flags);
> while (retries--) {
> usleep_range(4000, 8000);
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> if ((temp & PORT_PLS_MASK) == XDEV_U3)
> break;
> }
> spin_lock_irqsave(&xhci->lock, flags);
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> bus_state->suspended_ports |= 1 << wIndex;
> }
> break;
> @@ -1502,20 +1502,20 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
> temp = (temp | PORT_RESET);
> xhci_portsc_writel(port, temp);
>
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> xhci_dbg(xhci, "set port reset, actual port %d-%d status = 0x%x\n",
> hcd->self.busnum, portnum1, temp);
> break;
> case USB_PORT_FEAT_REMOTE_WAKE_MASK:
> xhci_set_remote_wake_mask(xhci, port, wake_mask);
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> xhci_dbg(xhci, "set port remote wake mask, actual port %d-%d status = 0x%x\n",
> hcd->self.busnum, portnum1, temp);
> break;
> case USB_PORT_FEAT_BH_PORT_RESET:
> temp |= PORT_WR;
> xhci_portsc_writel(port, temp);
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> break;
> case USB_PORT_FEAT_U1_TIMEOUT:
> if (hcd->speed < HCD_USB3)
> @@ -1547,7 +1547,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
> goto error;
> }
> /* unblock any posted writes */
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> break;
> case ClearPortFeature:
> if (!portnum1 || portnum1 > max_ports)
> @@ -1556,7 +1556,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
> port = ports[portnum1 - 1];
>
> wIndex--;
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> if (temp == ~(u32)0) {
> xhci_hc_died(xhci);
> retval = -ENODEV;
> @@ -1566,7 +1566,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
> temp = xhci_port_state_to_neutral(temp);
> switch (wValue) {
> case USB_PORT_FEAT_SUSPEND:
> - temp = readl(port->addr);
> + temp = xhci_portsc_readl(port);
> xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n");
> xhci_dbg(xhci, "PORTSC %04x\n", temp);
> if (temp & PORT_RESET)
> @@ -1681,7 +1681,7 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
>
> /* For each port, did anything change? If so, set that bit in buf. */
> for (i = 0; i < max_ports; i++) {
> - temp = readl(ports[i]->addr);
> + temp = xhci_portsc_readl(ports[i]);
> if (temp == ~(u32)0) {
> xhci_hc_died(xhci);
> retval = -ENODEV;
> @@ -1750,7 +1750,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
> u32 t1, t2;
> int retries = 10;
> retry:
> - t1 = readl(ports[port_index]->addr);
> + t1 = xhci_portsc_readl(ports[port_index]);
> t2 = xhci_port_state_to_neutral(t1);
> portsc_buf[port_index] = 0;
>
> @@ -1849,7 +1849,7 @@ static bool xhci_port_missing_cas_quirk(struct xhci_port *port)
> {
> u32 portsc;
>
> - portsc = readl(port->addr);
> + portsc = xhci_portsc_readl(port);
>
> /* if any of these are set we are not stuck */
> if (portsc & (PORT_CONNECT | PORT_CAS))
> @@ -1864,7 +1864,7 @@ static bool xhci_port_missing_cas_quirk(struct xhci_port *port)
> portsc |= PORT_WR;
> xhci_portsc_writel(port, portsc);
> /* flush write */
> - readl(port->addr);
> + xhci_portsc_readl(port);
> return true;
> }
>
> @@ -1911,7 +1911,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
> }
> port_index = max_ports;
> while (port_index--) {
> - portsc = readl(ports[port_index]->addr);
> + portsc = xhci_portsc_readl(ports[port_index]);
>
> /* warm reset CAS limited ports stuck in polling/compliance */
> if ((xhci->quirks & XHCI_MISSING_CAS) &&
> diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
> index b1192648aee7..2ba0261a29c1 100644
> --- a/drivers/usb/host/xhci-pci.c
> +++ b/drivers/usb/host/xhci-pci.c
> @@ -898,7 +898,7 @@ static int xhci_pci_poweroff_late(struct usb_hcd *hcd, bool do_wakeup)
>
> for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) {
> port = &xhci->hw_ports[i];
> - portsc = readl(port->addr);
> + portsc = xhci_portsc_readl(port);
>
> if ((portsc & PORT_PLS_MASK) != XDEV_U3)
> continue;
> diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
> index 8e209aa33ea7..47ca7783b633 100644
> --- a/drivers/usb/host/xhci-ring.c
> +++ b/drivers/usb/host/xhci-ring.c
> @@ -2026,7 +2026,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
> hcd = port->rhub->hcd;
> bus_state = &port->rhub->bus_state;
> hcd_portnum = port->hcd_portnum;
> - portsc = readl(port->addr);
> + portsc = xhci_portsc_readl(port);
>
> xhci_dbg(xhci, "Port change event, %d-%d, id %d, portsc: 0x%x\n",
> hcd->self.busnum, hcd_portnum + 1, port_id, portsc);
> diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c
> index 5255b1002893..1e23f198a005 100644
> --- a/drivers/usb/host/xhci-tegra.c
> +++ b/drivers/usb/host/xhci-tegra.c
> @@ -2036,7 +2036,7 @@ static bool xhci_hub_ports_suspended(struct xhci_hub *hub)
> u32 value;
>
> for (i = 0; i < hub->num_ports; i++) {
> - value = readl(hub->ports[i]->addr);
> + value = xhci_portsc_readl(hub->ports[i]);
> if ((value & PORT_PE) == 0)
> continue;
>
> @@ -2162,7 +2162,7 @@ static void tegra_xhci_enable_phy_sleepwalk_wake(struct tegra_xusb *tegra)
> if (!is_host_mode_phy(tegra, i, j))
> continue;
>
> - portsc = readl(rhub->ports[index]->addr);
> + portsc = xhci_portsc_readl(rhub->ports[index]);
> speed = tegra_xhci_portsc_to_speed(tegra, portsc);
> tegra_xusb_padctl_enable_phy_sleepwalk(padctl, phy, speed);
> tegra_xusb_padctl_enable_phy_wake(padctl, phy);
> @@ -2257,7 +2257,7 @@ static int tegra_xusb_enter_elpg(struct tegra_xusb *tegra, bool is_auto_resume)
> for (i = 0; i < xhci->usb2_rhub.num_ports; i++) {
> if (!xhci->usb2_rhub.ports[i])
> continue;
> - portsc = readl(xhci->usb2_rhub.ports[i]->addr);
> + portsc = xhci_portsc_readl(xhci->usb2_rhub.ports[i]);
> tegra->lp0_utmi_pad_mask &= ~BIT(i);
> if (((portsc & PORT_PLS_MASK) == XDEV_U3) || ((portsc & DEV_SPEED_MASK) == XDEV_FS))
> tegra->lp0_utmi_pad_mask |= BIT(i);
> @@ -2790,7 +2790,7 @@ static int tegra_xhci_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value,
> while (i--) {
> if (!test_bit(i, &bus_state->resuming_ports))
> continue;
> - portsc = readl(ports[i]->addr);
> + portsc = xhci_portsc_readl(ports[i]);
> if ((portsc & PORT_PLS_MASK) == XDEV_RESUME)
> tegra_phy_xusb_utmi_pad_power_on(
> tegra_xusb_get_phy(tegra, "usb2", (int) i));
> @@ -2808,7 +2808,7 @@ static int tegra_xhci_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value,
> if (!index || index > rhub->num_ports)
> return -EPIPE;
> ports = rhub->ports;
> - portsc = readl(ports[port]->addr);
> + portsc = xhci_portsc_readl(ports[port]);
> if (portsc & PORT_CONNECT)
> tegra_phy_xusb_utmi_pad_power_on(phy);
> }
> @@ -2827,7 +2827,7 @@ static int tegra_xhci_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value,
>
> if ((type_req == ClearPortFeature) && (value == USB_PORT_FEAT_C_CONNECTION)) {
> ports = rhub->ports;
> - portsc = readl(ports[port]->addr);
> + portsc = xhci_portsc_readl(ports[port]);
> if (!(portsc & PORT_CONNECT)) {
> /* We don't suspend the PAD while HNP role swap happens on the OTG
> * port
> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> index 84e109dbabe8..6b47b218cb24 100644
> --- a/drivers/usb/host/xhci.c
> +++ b/drivers/usb/host/xhci.c
> @@ -48,6 +48,12 @@ void xhci_portsc_writel(struct xhci_port *port, u32 val)
> }
> EXPORT_SYMBOL_GPL(xhci_portsc_writel);
>
> +u32 xhci_portsc_readl(struct xhci_port *port)
> +{
> + return readl(port->addr);
> +}
> +EXPORT_SYMBOL_GPL(xhci_portsc_readl);
> +
> static bool td_on_ring(struct xhci_td *td, struct xhci_ring *ring)
> {
> struct xhci_segment *seg;
> @@ -380,7 +386,7 @@ static void compliance_mode_recovery(struct timer_list *t)
> return;
>
> for (i = 0; i < rhub->num_ports; i++) {
> - temp = readl(rhub->ports[i]->addr);
> + temp = xhci_portsc_readl(rhub->ports[i]);
> if ((temp & PORT_PLS_MASK) == USB_SS_PORT_LS_COMP_MOD) {
> /*
> * Compliance Mode Detected. Letting USB Core
> @@ -903,7 +909,7 @@ static void xhci_disable_hub_port_wake(struct xhci_hcd *xhci,
> spin_lock_irqsave(&xhci->lock, flags);
>
> for (i = 0; i < rhub->num_ports; i++) {
> - portsc = readl(rhub->ports[i]->addr);
> + portsc = xhci_portsc_readl(rhub->ports[i]);
> t1 = xhci_port_state_to_neutral(portsc);
> t2 = t1;
>
> @@ -943,7 +949,7 @@ static bool xhci_pending_portevent(struct xhci_hcd *xhci)
> port_index = xhci->usb2_rhub.num_ports;
> ports = xhci->usb2_rhub.ports;
> while (port_index--) {
> - portsc = readl(ports[port_index]->addr);
> + portsc = xhci_portsc_readl(ports[port_index]);
> if (portsc & PORT_CHANGE_MASK ||
> (portsc & PORT_PLS_MASK) == XDEV_RESUME)
> return true;
> @@ -951,7 +957,7 @@ static bool xhci_pending_portevent(struct xhci_hcd *xhci)
> port_index = xhci->usb3_rhub.num_ports;
> ports = xhci->usb3_rhub.ports;
> while (port_index--) {
> - portsc = readl(ports[port_index]->addr);
> + portsc = xhci_portsc_readl(ports[port_index]);
> if (portsc & (PORT_CHANGE_MASK | PORT_CAS) ||
> (portsc & PORT_PLS_MASK) == XDEV_RESUME)
> return true;
> diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
> index 3b6b2d0d4c60..bddf9c15d813 100644
> --- a/drivers/usb/host/xhci.h
> +++ b/drivers/usb/host/xhci.h
> @@ -1962,6 +1962,7 @@ 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);
> void xhci_portsc_writel(struct xhci_port *port, u32 val);
> +u32 xhci_portsc_readl(struct xhci_port *port);
>
> /* xHCI roothub code */
> void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
> --
> 2.50.1
>
--
Best regards,
Peter
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-10-31 3:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-28 14:12 [PATCH v3 0/5] usb: xhci: add Port Register struct and tracing Niklas Neronin
2025-10-28 14:12 ` [PATCH v3 1/5] usb: xhci: rework xhci_decode_portsc() Niklas Neronin
2025-10-28 14:12 ` [PATCH v3 2/5] usb: xhci: add tracing for PORTSC register writes Niklas Neronin
2025-10-28 14:12 ` [PATCH v3 3/5] usb: xhci: add helper to read PORTSC register Niklas Neronin
2025-10-31 3:08 ` Peter Chen (CIX)
2025-10-28 14:12 ` [PATCH v3 4/5] usb: xhci: add USB Port Register Set struct Niklas Neronin
2025-10-28 14:12 ` [PATCH v3 5/5] usb: xhci: implement " Niklas Neronin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox