* [PATCH v3 00/12] usb: xhci: rework xHCI Port macros
@ 2026-12-03 14:42 Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 01/12] usb: xhci: use BIT() for single bit port register flags Niklas Neronin
` (12 more replies)
0 siblings, 13 replies; 17+ messages in thread
From: Niklas Neronin @ 2026-12-03 14:42 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
This series cleans up the xHCI port register macros in xhci-port.h:
PORTSC, PORTPMSC, PORTLI and PORTHLPMC.
Many fields are defined as pre-shifted values, together with helper
macros that mask, shift and compare them. This series defines each
field with GENMASK()/BIT(), uses plain field values, and accesses the
fields with FIELD_GET(), FIELD_PREP() and FIELD_MODIFY(). Register
comments are aligned with the xHCI specification, and the PORTSC
field macros are renamed to the spec abbreviations.
This is part 1 of the port register cleanup.
v3 changes:
* Dropped the second half of the original patch series. The remaining
patches are relatively small reworks. The second half will be
submitted separately.
* Updated all commit messages.
Niklas Neronin (12):
usb: xhci: use BIT() for single bit port register flags
usb: xhci: rework Port Speed macros
usb: xhci: rework Port Link State macros
usb: xhci: rework Port Indicator Control macro
usb: xhci: rework USB3 PORTPMSC macros
usb: xhci: rework USB2 PORTPMSC macros
usb: xhci: rework USB3 PORTLI macros
usb: xhci: rework USB2 PORTLI macros
usb: xhci: document USB3 PORTHLPMC register layout
usb: xhci: rework USB2 PORTHLPMC macros
usb: xhci: update port register bitfield comments for consistency
usb: xhci: rename PORTSC field macros to xHCI spec abbreviations
drivers/usb/dwc3/host.c | 2 +-
drivers/usb/early/xhci-dbc.c | 4 +-
drivers/usb/host/xhci-debugfs.c | 23 +--
drivers/usb/host/xhci-hub.c | 225 ++++++++++++------------
drivers/usb/host/xhci-pci.c | 4 +-
drivers/usb/host/xhci-port.h | 293 ++++++++++++++++++--------------
drivers/usb/host/xhci-ring.c | 25 ++-
drivers/usb/host/xhci-tegra.c | 23 +--
drivers/usb/host/xhci.c | 24 +--
drivers/usb/host/xhci.h | 65 ++++---
10 files changed, 370 insertions(+), 318 deletions(-)
--
2.50.1
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v3 01/12] usb: xhci: use BIT() for single bit port register flags
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
@ 2026-12-03 14:42 ` Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 02/12] usb: xhci: rework Port Speed macros Niklas Neronin
` (11 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Niklas Neronin @ 2026-12-03 14:42 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
Replace open-coded (1 << n) shifts with BIT(n) for the single-bit flags
in the PORTSC and PORTPMSC register definitions. This matches common
kernel style and makes the bitfield definitions easier to read.
BIT_ULL() is not needed because all port registers are 32 bits wide.
Multi-bit field masks are left as they are, converting them to
GENMASK() is done separately.
No functional change.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-port.h | 44 +++++++++++++++++++-----------------
1 file changed, 23 insertions(+), 21 deletions(-)
diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
index 889b5fb0fcd8..45e081a9c510 100644
--- a/drivers/usb/host/xhci-port.h
+++ b/drivers/usb/host/xhci-port.h
@@ -1,15 +1,17 @@
/* SPDX-License-Identifier: GPL-2.0 */
+#include <linux/bits.h>
+
/* PORTSC - Port Status and Control Register - port_status_base bitmasks */
/* true: device connected */
-#define PORT_CONNECT (1 << 0)
+#define PORT_CONNECT BIT(0)
/* true: port enabled */
-#define PORT_PE (1 << 1)
+#define PORT_PE BIT(1)
/* bit 2 reserved and zeroed */
/* true: port has an over-current condition */
-#define PORT_OC (1 << 3)
+#define PORT_OC BIT(3)
/* true: port reset signaling asserted */
-#define PORT_RESET (1 << 4)
+#define PORT_RESET BIT(4)
/* Port Link State - bits 5:8
* A read gives the current link PM state of the port,
* a write with Link State Write Strobe set sets the link state.
@@ -30,7 +32,7 @@
#define XDEV_RESUME (0xf << 5)
/* true: port has power (see HCC_PPC) */
-#define PORT_POWER (1 << 9)
+#define PORT_POWER BIT(9)
/* bits 10:13 indicate device speed:
* 0 - undefined speed - port hasn't be initialized by a reset yet
* 1 - full speed
@@ -66,21 +68,21 @@
#define PORT_LED_GREEN (2 << 14)
#define PORT_LED_MASK (3 << 14)
/* Port Link State Write Strobe - set this when changing link state */
-#define PORT_LINK_STROBE (1 << 16)
+#define PORT_LINK_STROBE BIT(16)
/* true: connect status change */
-#define PORT_CSC (1 << 17)
+#define PORT_CSC BIT(17)
/* true: port enable change */
-#define PORT_PEC (1 << 18)
+#define PORT_PEC BIT(18)
/* true: warm reset for a USB 3.0 device is done. A "hot" reset puts the port
* into an enabled state, and the device into the default state. A "warm" reset
* also resets the link, forcing the device through the link training sequence.
* SW can also look at the Port Reset register to see when warm reset is done.
*/
-#define PORT_WRC (1 << 19)
+#define PORT_WRC BIT(19)
/* true: over-current change */
-#define PORT_OCC (1 << 20)
+#define PORT_OCC BIT(20)
/* true: reset change - 1 to 0 transition of PORT_RESET */
-#define PORT_RC (1 << 21)
+#define PORT_RC BIT(21)
/* port link status change - set on some port link state transitions:
* Transition Reason
* ------------------------------------------------------------------------------
@@ -94,9 +96,9 @@
* - U0 to disabled L1 entry error with USB 2.1 device
* - Any state to inactive Error on USB 3.0 port
*/
-#define PORT_PLC (1 << 22)
+#define PORT_PLC BIT(22)
/* port configure error change - port failed to configure its link partner */
-#define PORT_CEC (1 << 23)
+#define PORT_CEC BIT(23)
#define PORT_CHANGE_MASK (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \
PORT_RC | PORT_PLC | PORT_CEC)
@@ -105,18 +107,18 @@
* Sx state. Warm port reset should be perfomed to clear this bit and move port
* to connected state.
*/
-#define PORT_CAS (1 << 24)
+#define PORT_CAS BIT(24)
/* wake on connect (enable) */
-#define PORT_WKCONN_E (1 << 25)
+#define PORT_WKCONN_E BIT(25)
/* wake on disconnect (enable) */
-#define PORT_WKDISC_E (1 << 26)
+#define PORT_WKDISC_E BIT(26)
/* wake on over-current (enable) */
-#define PORT_WKOC_E (1 << 27)
+#define PORT_WKOC_E BIT(27)
/* bits 28:29 reserved */
/* true: device is non-removable - for USB 3.0 roothub emulation */
-#define PORT_DEV_REMOVE (1 << 30)
+#define PORT_DEV_REMOVE BIT(30)
/* Initiate a warm port reset - complete when PORT_WRC is '1' */
-#define PORT_WR (1 << 31)
+#define PORT_WR BIT(31)
/* We mark duplicate entries with -1 */
#define DUPLICATE_ENTRY ((u8)(-1))
@@ -135,12 +137,12 @@
/* USB2 Protocol PORTSPMSC */
#define PORT_L1S_MASK 7
#define PORT_L1S_SUCCESS 1
-#define PORT_RWE (1 << 3)
+#define PORT_RWE BIT(3)
#define PORT_HIRD(p) (((p) & 0xf) << 4)
#define PORT_HIRD_MASK (0xf << 4)
#define PORT_L1DS_MASK (0xff << 8)
#define PORT_L1DS(p) (((p) & 0xff) << 8)
-#define PORT_HLE (1 << 16)
+#define PORT_HLE BIT(16)
#define PORT_TEST_MODE_SHIFT 28
/* USB3 Protocol PORTLI Port Link Information */
--
2.50.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v3 02/12] usb: xhci: rework Port Speed macros
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 01/12] usb: xhci: use BIT() for single bit port register flags Niklas Neronin
@ 2026-12-03 14:42 ` Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 03/12] usb: xhci: rework Port Link State macros Niklas Neronin
` (10 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Niklas Neronin @ 2026-12-03 14:42 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
The PORTSC Port Speed macros are defined as values pre-shifted into
bits 13:10, along with a set of DEV_*SPEED() helpers that mask and
compare them.
Replace DEV_SPEED_MASK with PORT_SPEED_MASK, defined using GENMASK(),
and replace the pre-shifted XDEV_* speed IDs with plain PORT_SPEED_*
field values. Callers now use FIELD_GET() to extract the field and
compare it directly. Remove the DEV_*SPEED() and DEV_PORT_SPEED()
helpers.
DEV_UNDEFSPEED() and DEV_SUPERSPEEDPLUS() have no users and are dropped.
The SLOT_SPEED_* macros describe Slot Context bits 23:20 and were
built by shifting the pre-shifted PORTSC values again. Move them next
to the other Slot Context 'dev_info' definitions in xhci.h and shift
the speed ID by 20 directly.
Update the Port Speed comment to list all speed IDs defined in xHCI
specification section 7.2.2.1.1.
No functional change.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-debugfs.c | 6 ++---
drivers/usb/host/xhci-hub.c | 8 +++---
drivers/usb/host/xhci-port.h | 46 ++++++++++++++-------------------
drivers/usb/host/xhci-ring.c | 4 +--
drivers/usb/host/xhci-tegra.c | 13 ++++++----
drivers/usb/host/xhci.h | 13 ++++++++--
6 files changed, 48 insertions(+), 42 deletions(-)
diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c
index 2aa01d99f23d..79bc1f7d745a 100644
--- a/drivers/usb/host/xhci-debugfs.c
+++ b/drivers/usb/host/xhci-debugfs.c
@@ -715,7 +715,7 @@ 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, DEV_PORT_SPEED(XDEV_SS), s);
+ ret = xhci_port_bw_show(xhci, PORT_SPEED_SS, s);
return ret;
}
@@ -724,7 +724,7 @@ 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, DEV_PORT_SPEED(XDEV_HS), s);
+ ret = xhci_port_bw_show(xhci, PORT_SPEED_HS, s);
return ret;
}
@@ -733,7 +733,7 @@ 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, DEV_PORT_SPEED(XDEV_FS), s);
+ ret = xhci_port_bw_show(xhci, PORT_SPEED_FS, s);
return ret;
}
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 55430b673f1e..ff9d9b26f810 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -376,9 +376,11 @@ static void xhci_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
static unsigned int xhci_port_speed(int portsc)
{
- if (DEV_LOWSPEED(portsc))
+ u32 port_speed = FIELD_GET(PORT_SPEED_MASK, portsc);
+
+ if (port_speed == PORT_SPEED_LS)
return USB_PORT_STAT_LOW_SPEED;
- if (DEV_HIGHSPEED(portsc))
+ if (port_speed == PORT_SPEED_HS)
return USB_PORT_STAT_HIGH_SPEED;
/*
* FIXME: Yes, we should check for full speed, but the core uses that as
@@ -1007,7 +1009,7 @@ static u32 xhci_get_ext_port_status(u32 portsc, u32 port_li)
int speed_id;
/* only support rx and tx lane counts of 1 in usb3.1 spec */
- speed_id = DEV_PORT_SPEED(portsc);
+ speed_id = FIELD_GET(PORT_SPEED_MASK, portsc);
ext_stat |= speed_id; /* bits 3:0, RX speed id */
ext_stat |= speed_id << 4; /* bits 7:4, TX speed id */
diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
index 45e081a9c510..ec822f2f92d0 100644
--- a/drivers/usb/host/xhci-port.h
+++ b/drivers/usb/host/xhci-port.h
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
+#include <linux/bitfield.h>
#include <linux/bits.h>
/* PORTSC - Port Status and Control Register - port_status_base bitmasks */
@@ -33,35 +34,26 @@
/* true: port has power (see HCC_PPC) */
#define PORT_POWER BIT(9)
-/* bits 10:13 indicate device speed:
- * 0 - undefined speed - port hasn't be initialized by a reset yet
- * 1 - full speed
- * 2 - low speed
- * 3 - high speed
- * 4 - super speed
- * 5-15 reserved
+/*
+ * bits 13:10 - Port Speed
+ * Values defined in xHCI specification 7.2.2.1.1:
+ * 0 - undefined speed - port hasn't been initialized by a reset yet
+ * 1 - Full-speed
+ * 2 - Low-speed
+ * 3 - High-speed
+ * 4 - SuperSpeed Gen1 x1
+ * 5 - SuperSpeed Gen2 x1
+ * 6 - SuperSpeed Gen1 x2
+ * 7 - SuperSpeed Gen2 x2
+ * 8-15 Reserved
*/
-#define DEV_SPEED_MASK (0xf << 10)
-#define XDEV_FS (0x1 << 10)
-#define XDEV_LS (0x2 << 10)
-#define XDEV_HS (0x3 << 10)
-#define XDEV_SS (0x4 << 10)
-#define XDEV_SSP (0x5 << 10)
-#define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0<<10))
-#define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS)
-#define DEV_LOWSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_LS)
-#define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS)
-#define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS)
-#define DEV_SUPERSPEEDPLUS(p) (((p) & DEV_SPEED_MASK) == XDEV_SSP)
-#define DEV_SUPERSPEED_ANY(p) (((p) & DEV_SPEED_MASK) >= XDEV_SS)
-#define DEV_PORT_SPEED(p) (((p) >> 10) & 0x0f)
+#define PORT_SPEED_MASK GENMASK(13, 10)
+#define PORT_SPEED_FS 1
+#define PORT_SPEED_LS 2
+#define PORT_SPEED_HS 3
+#define PORT_SPEED_SS 4
+#define PORT_SPEED_SSP 5
-/* Bits 20:23 in the Slot Context are the speed for the device */
-#define SLOT_SPEED_FS (XDEV_FS << 10)
-#define SLOT_SPEED_LS (XDEV_LS << 10)
-#define SLOT_SPEED_HS (XDEV_HS << 10)
-#define SLOT_SPEED_SS (XDEV_SS << 10)
-#define SLOT_SPEED_SSP (XDEV_SSP << 10)
/* Port Indicator Control */
#define PORT_LED_OFF (0 << 14)
#define PORT_LED_AMBER (1 << 14)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index a1fa188680f5..676f71d8305b 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2142,7 +2142,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
goto cleanup;
}
- if (DEV_SUPERSPEED_ANY(portsc)) {
+ if (FIELD_GET(PORT_SPEED_MASK, portsc) >= PORT_SPEED_SS) {
xhci_dbg(xhci, "remote wake SS port %d\n", port_id);
/* Set a flag to say the port signaled remote wakeup,
* so we can tell the difference between the end of
@@ -2175,7 +2175,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
}
if ((portsc & PORT_PLC) &&
- DEV_SUPERSPEED_ANY(portsc) &&
+ FIELD_GET(PORT_SPEED_MASK, portsc) >= PORT_SPEED_SS &&
((portsc & PORT_PLS_MASK) == XDEV_U0 ||
(portsc & PORT_PLS_MASK) == XDEV_U1 ||
(portsc & PORT_PLS_MASK) == XDEV_U2)) {
diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c
index 1a14aea58b0b..b31c7b087fc7 100644
--- a/drivers/usb/host/xhci-tegra.c
+++ b/drivers/usb/host/xhci-tegra.c
@@ -2107,16 +2107,18 @@ static void tegra_xusb_restore_context(struct tegra_xusb *tegra)
static enum usb_device_speed tegra_xhci_portsc_to_speed(struct tegra_xusb *tegra, u32 portsc)
{
- if (DEV_LOWSPEED(portsc))
+ u32 port_speed = FIELD_GET(PORT_SPEED_MASK, portsc);
+
+ if (port_speed == PORT_SPEED_LS)
return USB_SPEED_LOW;
- if (DEV_HIGHSPEED(portsc))
+ if (port_speed == PORT_SPEED_HS)
return USB_SPEED_HIGH;
- if (DEV_FULLSPEED(portsc))
+ if (port_speed == PORT_SPEED_FS)
return USB_SPEED_FULL;
- if (DEV_SUPERSPEED_ANY(portsc))
+ if (port_speed >= PORT_SPEED_SS)
return USB_SPEED_SUPER;
return USB_SPEED_UNKNOWN;
@@ -2255,7 +2257,8 @@ static int tegra_xusb_enter_elpg(struct tegra_xusb *tegra, bool is_auto_resume)
continue;
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))
+ if (((portsc & PORT_PLS_MASK) == XDEV_U3) ||
+ (FIELD_GET(PORT_SPEED_MASK, portsc) == PORT_SPEED_FS))
tegra->lp0_utmi_pad_mask |= BIT(i);
}
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index ec4bfeb4887c..61b132027963 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -12,6 +12,7 @@
#ifndef __LINUX_XHCI_HCD_H
#define __LINUX_XHCI_HCD_H
+#include <linux/bitfield.h>
#include <linux/bits.h>
#include <linux/usb.h>
#include <linux/timer.h>
@@ -362,9 +363,17 @@ struct xhci_slot_ctx {
/* dev_info bitmasks */
/* Route String - 0:19 */
#define ROUTE_STRING_MASK (0xfffff)
-/* Device speed - values defined by PORTSC Device Speed field - 20:23 */
+/*
+ * bits 23:20 - Device speed, values defined by PORTSC Speed field
+ * xHCI version 1.2 onwards these bits are Reserved
+ */
#define DEV_SPEED (0xf << 20)
#define GET_DEV_SPEED(n) (((n) & DEV_SPEED) >> 20)
+#define SLOT_SPEED_FS (PORT_SPEED_FS << 20)
+#define SLOT_SPEED_LS (PORT_SPEED_LS << 20)
+#define SLOT_SPEED_HS (PORT_SPEED_HS << 20)
+#define SLOT_SPEED_SS (PORT_SPEED_SS << 20)
+#define SLOT_SPEED_SSP (PORT_SPEED_SSP << 20)
/* bit 24 reserved */
/* Is this LS/FS device connected through a HS hub? - bit 25 */
#define DEV_MTT BIT(25)
@@ -2412,7 +2421,7 @@ static inline const char *xhci_decode_portsc(char *str, u32 portsc)
if (portsc == ~(u32)0)
return str;
- ret += sprintf(str + ret, "Speed=%d ", DEV_PORT_SPEED(portsc));
+ ret += sprintf(str + ret, "Speed=%lu ", FIELD_GET(PORT_SPEED_MASK, portsc));
ret += sprintf(str + ret, "Link=%s ", xhci_portsc_link_state_string(portsc));
/* RO/ROS: Read-only */
--
2.50.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v3 03/12] usb: xhci: rework Port Link State macros
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 01/12] usb: xhci: use BIT() for single bit port register flags Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 02/12] usb: xhci: rework Port Speed macros Niklas Neronin
@ 2026-12-03 14:42 ` Niklas Neronin
2026-12-03 14:59 ` sashiko-bot
2026-12-03 14:42 ` [PATCH v3 04/12] usb: xhci: rework Port Indicator Control macro Niklas Neronin
` (9 subsequent siblings)
12 siblings, 1 reply; 17+ messages in thread
From: Niklas Neronin @ 2026-12-03 14:42 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
The PORTSC Port Link State (PLS) values are defined pre-shifted into
bits 8:5, and callers mask and compare the raw register value.
Define PORT_PLS_MASK with GENMASK() and replace the pre-shifted XDEV_*
link states with plain PLS_* field values. Use FIELD_GET() to read the
field and FIELD_MODIFY() to update it. xhci_set_link_state() now takes
an unshifted link state.
xhci_hub_report_usb3_link_state() reports the PLS value read from PORTSC,
but overrides it in some cases with the pre-shifted USB_SS_PORT_LS_*
values from ch11.h. Since the reported value comes from PORTSC,
use the PLS_* values throughout, and write the result into 'wPortStatus'
bits 8:5 with FIELD_MODIFY(). The USB 3 hub link state encoding and bit
position are identical to the xHCI PLS field, so the reported status
does not change.
For the same reason, compliance_mode_recovery() now compares against
PLS_COMP_MODE instead of USB_SS_PORT_LS_COMP_MOD.
Update the Port Link State comment to note the default value, the LWS
requirement for writes, and the reserved values 12-14.
No functional change.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-debugfs.c | 6 +-
drivers/usb/host/xhci-hub.c | 113 ++++++++++++++++----------------
drivers/usb/host/xhci-pci.c | 2 +-
drivers/usb/host/xhci-port.h | 37 ++++++-----
drivers/usb/host/xhci-ring.c | 17 +++--
drivers/usb/host/xhci-tegra.c | 6 +-
drivers/usb/host/xhci.c | 8 +--
drivers/usb/host/xhci.h | 28 ++++----
8 files changed, 109 insertions(+), 108 deletions(-)
diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c
index 79bc1f7d745a..e61ee722e2cd 100644
--- a/drivers/usb/host/xhci-debugfs.c
+++ b/drivers/usb/host/xhci-debugfs.c
@@ -361,13 +361,13 @@ static ssize_t xhci_port_write(struct file *file, const char __user *ubuf,
spin_lock_irqsave(&xhci->lock, flags);
/* compliance mode can only be enabled on ports in RxDetect */
portsc = xhci_portsc_readl(port);
- if ((portsc & PORT_PLS_MASK) != XDEV_RXDETECT) {
+ if (FIELD_GET(PORT_PLS_MASK, portsc) != PLS_RXDETECT) {
spin_unlock_irqrestore(&xhci->lock, flags);
return -EPERM;
}
portsc = xhci_port_state_to_neutral(portsc);
- portsc &= ~PORT_PLS_MASK;
- portsc |= PORT_LINK_STROBE | XDEV_COMP_MODE;
+ FIELD_MODIFY(PORT_PLS_MASK, &portsc, PLS_COMP_MODE);
+ portsc |= PORT_LINK_STROBE;
xhci_portsc_writel(port, portsc);
spin_unlock_irqrestore(&xhci->lock, flags);
} else {
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index ff9d9b26f810..db492ac33016 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -801,8 +801,8 @@ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
portsc = xhci_portsc_readl(port);
temp = xhci_port_state_to_neutral(portsc);
- temp &= ~PORT_PLS_MASK;
- temp |= PORT_LINK_STROBE | link_state;
+ FIELD_MODIFY(PORT_PLS_MASK, &temp, link_state);
+ temp |= PORT_LINK_STROBE;
xhci_portsc_writel(port, temp);
xhci_dbg(xhci, "Set port %d-%d link state, portsc: 0x%x, write 0x%x",
@@ -853,7 +853,7 @@ void xhci_test_and_clear_bit(struct xhci_hcd *xhci, struct xhci_port *port,
/* Updates Link Status for super Speed port */
static void xhci_hub_report_usb3_link_state(struct xhci_hcd *xhci, u32 *status, u32 portsc)
{
- u32 pls = portsc & PORT_PLS_MASK;
+ u32 pls = FIELD_GET(PORT_PLS_MASK, portsc);
/*
* CAS indicates that a warm reset is required, it may be set in any
@@ -864,18 +864,18 @@ static void xhci_hub_report_usb3_link_state(struct xhci_hcd *xhci, u32 *status,
* If not already in Compliance or Inactive state,
* report Compliance Mode so the hub logic triggers a warm reset.
*/
- if (pls != XDEV_COMP_MODE && pls != XDEV_INACTIVE)
- pls = USB_SS_PORT_LS_COMP_MOD;
+ if (pls != PLS_COMP_MODE && pls != PLS_INACTIVE)
+ pls = PLS_COMP_MODE;
/* Signal a connection change to force a reset */
*status |= USB_PORT_STAT_CONNECTION;
- } else if (pls == XDEV_RESUME) {
+ } else if (pls == PLS_RESUME) {
/*
* Resume is an internal xHCI-only state and must not be exposed
* to usbcore. Report it as U3 so transfers are blocked.
*/
- pls = USB_SS_PORT_LS_U3;
- } else if (pls == XDEV_COMP_MODE) {
+ pls = PLS_U3;
+ } else if (pls == PLS_COMP_MODE) {
/*
* Some hardware may enter Compliance Mode without CAS.
* Fake a connection event so usbcore notices and resets the port.
@@ -885,7 +885,7 @@ static void xhci_hub_report_usb3_link_state(struct xhci_hcd *xhci, u32 *status,
}
/* update status field */
- *status |= pls;
+ FIELD_MODIFY(PORT_PLS_MASK, status, pls);
}
/*
@@ -898,7 +898,7 @@ static void xhci_hub_report_usb3_link_state(struct xhci_hcd *xhci, u32 *status,
static void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 portsc, int portnum)
{
u32 all_ports_seen_u0 = ((1 << xhci->usb3_rhub.num_ports) - 1);
- bool port_in_u0 = ((portsc & PORT_PLS_MASK) == XDEV_U0);
+ bool port_in_u0 = (FIELD_GET(PORT_PLS_MASK, portsc) == PLS_U0);
if (!(xhci->quirks & XHCI_COMP_MODE_QUIRK))
return;
@@ -968,7 +968,7 @@ static int xhci_handle_usb2_port_link_resume(struct xhci_port *port,
port->rexit_active = true;
xhci_test_and_clear_bit(xhci, port, PORT_PLC);
- xhci_set_link_state(xhci, port, XDEV_U0);
+ xhci_set_link_state(xhci, port, PLS_U0);
spin_unlock_irqrestore(&xhci->lock, *flags);
time_left = wait_for_completion_timeout(
@@ -1031,7 +1031,7 @@ static void xhci_get_usb3_port_status(struct xhci_port *port, u32 *status,
bus_state = &port->rhub->bus_state;
xhci = hcd_to_xhci(port->rhub->hcd);
hcd = port->rhub->hcd;
- link_state = portsc & PORT_PLS_MASK;
+ link_state = FIELD_GET(PORT_PLS_MASK, portsc);
portnum = port->hcd_portnum;
/* USB3 specific wPortChange bits
@@ -1043,7 +1043,7 @@ static void xhci_get_usb3_port_status(struct xhci_port *port, u32 *status,
* irq won't be generated.
*/
- if (portsc & PORT_PLC && (link_state != XDEV_RESUME))
+ if (portsc & PORT_PLC && (link_state != PLS_RESUME))
*status |= USB_PORT_STAT_C_LINK_STATE << 16;
if (portsc & PORT_WRC)
*status |= USB_PORT_STAT_C_BH_RESET << 16;
@@ -1055,9 +1055,9 @@ static void xhci_get_usb3_port_status(struct xhci_port *port, u32 *status,
*status |= USB_SS_PORT_STAT_POWER;
/* no longer suspended or resuming */
- if (link_state != XDEV_U3 &&
- link_state != XDEV_RESUME &&
- link_state != XDEV_RECOVERY) {
+ if (link_state != PLS_U3 &&
+ link_state != PLS_RESUME &&
+ link_state != PLS_RECOVERY) {
/* remote wake resume signaling complete */
if (bus_state->port_remote_wakeup & (1 << portnum)) {
bus_state->port_remote_wakeup &= ~(1 << portnum);
@@ -1079,7 +1079,7 @@ static void xhci_get_usb2_port_status(struct xhci_port *port, u32 *status,
int err;
bus_state = &port->rhub->bus_state;
- link_state = portsc & PORT_PLS_MASK;
+ link_state = FIELD_GET(PORT_PLS_MASK, portsc);
portnum = port->hcd_portnum;
/* USB2 wPortStatus bits */
@@ -1087,17 +1087,17 @@ static void xhci_get_usb2_port_status(struct xhci_port *port, u32 *status,
*status |= USB_PORT_STAT_POWER;
/* link state is only valid if port is powered */
- if (link_state == XDEV_U3)
+ if (link_state == PLS_U3)
*status |= USB_PORT_STAT_SUSPEND;
- if (link_state == XDEV_U2)
+ if (link_state == PLS_U2)
*status |= USB_PORT_STAT_L1;
- if (link_state == XDEV_U0) {
+ if (link_state == PLS_U0) {
if (bus_state->suspended_ports & (1 << portnum)) {
bus_state->suspended_ports &= ~(1 << portnum);
bus_state->port_c_suspend |= 1 << portnum;
}
}
- if (link_state == XDEV_RESUME) {
+ if (link_state == PLS_RESUME) {
err = xhci_handle_usb2_port_link_resume(port, portsc,
flags);
if (err < 0)
@@ -1112,7 +1112,7 @@ static void xhci_get_usb2_port_status(struct xhci_port *port, u32 *status,
* or resuming. Port either resumed to U0/U1/U2, disconnected, or in a
* error state. Resume related variables should be cleared in all those cases.
*/
- if (link_state != XDEV_U3 && link_state != XDEV_RESUME) {
+ if (link_state != PLS_U3 && link_state != PLS_RESUME) {
if (port->resume_timestamp ||
test_bit(portnum, &bus_state->resuming_ports)) {
port->resume_timestamp = 0;
@@ -1170,7 +1170,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd, struct xhci_bus_state *bus_
/* track connect and link error status when hub is polling */
if (!(portsc & PORT_RESET)) {
- port->link_inactive = (portsc & PORT_PLS_MASK) == XDEV_INACTIVE;
+ port->link_inactive = (FIELD_GET(PORT_PLS_MASK, portsc) == PLS_INACTIVE);
port->connected = !!(portsc & PORT_CONNECT);
}
@@ -1294,9 +1294,9 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
switch (wValue) {
case USB_PORT_FEAT_SUSPEND:
portsc = xhci_portsc_readl(port);
- if ((portsc & PORT_PLS_MASK) != XDEV_U0) {
+ if (FIELD_GET(PORT_PLS_MASK, portsc) != PLS_U0) {
/* Resume the port to U0 first */
- xhci_set_link_state(xhci, port, XDEV_U0);
+ xhci_set_link_state(xhci, port, PLS_U0);
spin_unlock_irqrestore(&xhci->lock, flags);
msleep(10);
spin_lock_irqsave(&xhci->lock, flags);
@@ -1307,7 +1307,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
*/
portsc = xhci_portsc_readl(port);
if ((portsc & PORT_PE) == 0 || (portsc & PORT_RESET) ||
- (portsc & PORT_PLS_MASK) >= XDEV_U3) {
+ FIELD_GET(PORT_PLS_MASK, portsc) >= PLS_U3) {
xhci_warn(xhci, "USB core suspending port %d-%d not in U0/U1/U2\n",
hcd->self.busnum, portnum + 1);
goto error;
@@ -1322,7 +1322,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
xhci_stop_device(xhci, port->slot_id, 1);
spin_lock_irqsave(&xhci->lock, flags);
- xhci_set_link_state(xhci, port, XDEV_U3);
+ xhci_set_link_state(xhci, port, PLS_U3);
spin_unlock_irqrestore(&xhci->lock, flags);
msleep(10); /* wait device to enter */
@@ -1355,7 +1355,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
if (link_state == USB_SS_PORT_LS_RX_DETECT) {
xhci_dbg(xhci, "Enable port %d-%d\n",
hcd->self.busnum, portnum + 1);
- xhci_set_link_state(xhci, port, XDEV_RXDETECT);
+ xhci_set_link_state(xhci, port, PLS_RXDETECT);
portsc = xhci_portsc_readl(port);
break;
}
@@ -1387,7 +1387,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
xhci_dbg(xhci, "Enable compliance mode transition for port %d-%d\n",
hcd->self.busnum, portnum + 1);
- xhci_set_link_state(xhci, port, XDEV_COMP_MODE);
+ xhci_set_link_state(xhci, port, PLS_COMP_MODE);
portsc = xhci_portsc_readl(port);
break;
@@ -1412,22 +1412,22 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
* completion
*/
if (link_state == USB_SS_PORT_LS_U0) {
- u32 pls = portsc & PORT_PLS_MASK;
+ u32 pls = FIELD_GET(PORT_PLS_MASK, portsc);
bool wait_u0 = false;
/* already in U0 */
- if (pls == XDEV_U0)
+ if (pls == PLS_U0)
break;
- if (pls == XDEV_U3 ||
- pls == XDEV_RESUME ||
- pls == XDEV_RECOVERY) {
+ if (pls == PLS_U3 ||
+ pls == PLS_RESUME ||
+ pls == PLS_RECOVERY) {
wait_u0 = true;
reinit_completion(&port->u3exit_done);
}
- if (pls <= XDEV_U3) /* U1, U2, U3 */
- xhci_set_link_state(xhci, port, XDEV_U0);
+ if (pls <= PLS_U3) /* U1, U2, U3 */
+ xhci_set_link_state(xhci, port, PLS_U0);
if (!wait_u0) {
- if (pls > XDEV_U3)
+ if (pls > PLS_U3)
goto error;
break;
}
@@ -1451,12 +1451,12 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
xhci_stop_device(xhci, port->slot_id, 1);
spin_lock_irqsave(&xhci->lock, flags);
}
- xhci_set_link_state(xhci, port, XDEV_U3);
+ xhci_set_link_state(xhci, port, PLS_U3);
spin_unlock_irqrestore(&xhci->lock, flags);
while (retries--) {
usleep_range(4000, 8000);
portsc = xhci_portsc_readl(port);
- if ((portsc & PORT_PLS_MASK) == XDEV_U3)
+ if (FIELD_GET(PORT_PLS_MASK, portsc) == PLS_U3)
break;
}
spin_lock_irqsave(&xhci->lock, flags);
@@ -1551,17 +1551,17 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
xhci_dbg(xhci, "PORTSC %04x\n", portsc);
if (portsc & PORT_RESET)
goto error;
- if ((portsc & PORT_PLS_MASK) == XDEV_U3) {
+ if (FIELD_GET(PORT_PLS_MASK, portsc) == PLS_U3) {
if ((portsc & PORT_PE) == 0)
goto error;
set_bit(portnum, &bus_state->resuming_ports);
usb_hcd_start_port_resume(&hcd->self, portnum);
- xhci_set_link_state(xhci, port, XDEV_RESUME);
+ xhci_set_link_state(xhci, port, PLS_RESUME);
spin_unlock_irqrestore(&xhci->lock, flags);
msleep(USB_RESUME_TIMEOUT);
spin_lock_irqsave(&xhci->lock, flags);
- xhci_set_link_state(xhci, port, XDEV_U0);
+ xhci_set_link_state(xhci, port, PLS_U0);
clear_bit(portnum, &bus_state->resuming_ports);
usb_hcd_end_port_resume(&hcd->self, portnum);
}
@@ -1739,7 +1739,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
* prevent suspend as port might be stuck
*/
if ((hcd->speed >= HCD_USB3) && retries-- &&
- (t1 & PORT_PLS_MASK) == XDEV_POLLING) {
+ FIELD_GET(PORT_PLS_MASK, t1) == PLS_POLLING) {
spin_unlock_irqrestore(&xhci->lock, flags);
msleep(XHCI_PORT_POLLING_LFPS_TIME);
spin_lock_irqsave(&xhci->lock, flags);
@@ -1755,7 +1755,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
return -EBUSY;
}
/* suspend ports in U0, or bail out for new connect changes */
- if ((t1 & PORT_PE) && (t1 & PORT_PLS_MASK) == XDEV_U0) {
+ if ((t1 & PORT_PE) && FIELD_GET(PORT_PLS_MASK, t1) == PLS_U0) {
if ((t1 & PORT_CSC) && wake_enabled) {
bus_state->bus_suspended = 0;
spin_unlock_irqrestore(&xhci->lock, flags);
@@ -1764,8 +1764,8 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
}
xhci_dbg(xhci, "port %d-%d not suspended\n",
hcd->self.busnum, port_index + 1);
- t2 &= ~PORT_PLS_MASK;
- t2 |= PORT_LINK_STROBE | XDEV_U3;
+ FIELD_MODIFY(PORT_PLS_MASK, &t2, PLS_U3);
+ t2 |= PORT_LINK_STROBE;
set_bit(port_index, &bus_state->bus_suspended);
}
/* USB core sets remote wake mask for USB 3.0 hubs,
@@ -1828,6 +1828,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
static bool xhci_port_missing_cas_quirk(struct xhci_port *port)
{
u32 portsc;
+ u32 pls;
portsc = xhci_portsc_readl(port);
@@ -1835,8 +1836,8 @@ static bool xhci_port_missing_cas_quirk(struct xhci_port *port)
if (portsc & (PORT_CONNECT | PORT_CAS))
return false;
- if (((portsc & PORT_PLS_MASK) != XDEV_POLLING) &&
- ((portsc & PORT_PLS_MASK) != XDEV_COMP_MODE))
+ pls = FIELD_GET(PORT_PLS_MASK, portsc);
+ if (pls != PLS_POLLING && pls != PLS_COMP_MODE)
return false;
/* clear wakeup/change bits, and do a warm port reset */
@@ -1877,9 +1878,9 @@ int xhci_bus_resume(struct usb_hcd *hcd)
/* bus specific resume for ports we suspended at bus_suspend */
if (hcd->speed >= HCD_USB3) {
- next_state = XDEV_U0;
+ next_state = PLS_U0;
} else {
- next_state = XDEV_RESUME;
+ next_state = PLS_RESUME;
if (bus_state->bus_suspended) {
/*
* prevent port event interrupts from interfering
@@ -1904,13 +1905,13 @@ int xhci_bus_resume(struct usb_hcd *hcd)
}
/* resume if we suspended the link, and it is still suspended */
if (test_bit(port_index, &bus_state->bus_suspended))
- switch (portsc & PORT_PLS_MASK) {
- case XDEV_U3:
+ switch (FIELD_GET(PORT_PLS_MASK, portsc)) {
+ case PLS_U3:
portsc = xhci_port_state_to_neutral(portsc);
- portsc &= ~PORT_PLS_MASK;
- portsc |= PORT_LINK_STROBE | next_state;
+ FIELD_MODIFY(PORT_PLS_MASK, &portsc, next_state);
+ portsc |= PORT_LINK_STROBE;
break;
- case XDEV_RESUME:
+ case PLS_RESUME:
/* resume already initiated */
break;
default:
@@ -1936,7 +1937,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
/* Clear PLC to poll it later for U0 transition */
xhci_test_and_clear_bit(xhci, ports[port_index],
PORT_PLC);
- xhci_set_link_state(xhci, ports[port_index], XDEV_U0);
+ xhci_set_link_state(xhci, ports[port_index], PLS_U0);
}
}
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index e278db940a58..e71906889b12 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -922,7 +922,7 @@ static int xhci_pci_poweroff_late(struct usb_hcd *hcd, bool do_wakeup)
port = &xhci->hw_ports[i];
portsc = xhci_portsc_readl(port);
- if ((portsc & PORT_PLS_MASK) != XDEV_U3)
+ if (FIELD_GET(PORT_PLS_MASK, portsc) != PLS_U3)
continue;
if (!port->slot_id || !xhci->devs[port->slot_id]) {
diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
index ec822f2f92d0..bf6e6e4d8ec6 100644
--- a/drivers/usb/host/xhci-port.h
+++ b/drivers/usb/host/xhci-port.h
@@ -13,25 +13,26 @@
#define PORT_OC BIT(3)
/* true: port reset signaling asserted */
#define PORT_RESET BIT(4)
-/* Port Link State - bits 5:8
- * A read gives the current link PM state of the port,
- * a write with Link State Write Strobe set sets the link state.
+/*
+ * bits 8:5 - Port Link State, by default '5'.
+ * Reading gives the current link PM state of the port.
+ * Writing sets the link state, Port Link State Write Strobe (LWS) must be set.
*/
-#define PORT_PLS_MASK (0xf << 5)
-#define XDEV_U0 (0x0 << 5)
-#define XDEV_U1 (0x1 << 5)
-#define XDEV_U2 (0x2 << 5)
-#define XDEV_U3 (0x3 << 5)
-#define XDEV_DISABLED (0x4 << 5)
-#define XDEV_RXDETECT (0x5 << 5)
-#define XDEV_INACTIVE (0x6 << 5)
-#define XDEV_POLLING (0x7 << 5)
-#define XDEV_RECOVERY (0x8 << 5)
-#define XDEV_HOT_RESET (0x9 << 5)
-#define XDEV_COMP_MODE (0xa << 5)
-#define XDEV_TEST_MODE (0xb << 5)
-#define XDEV_RESUME (0xf << 5)
-
+#define PORT_PLS_MASK GENMASK(8, 5)
+#define PLS_U0 0
+#define PLS_U1 1
+#define PLS_U2 2
+#define PLS_U3 3
+#define PLS_DISABLED 4
+#define PLS_RXDETECT 5
+#define PLS_INACTIVE 6
+#define PLS_POLLING 7
+#define PLS_RECOVERY 8
+#define PLS_HOT_RESET 9
+#define PLS_COMP_MODE 10
+#define PLS_TEST_MODE 11
+/* Values 12-14 are Reserved */
+#define PLS_RESUME 15
/* true: port has power (see HCC_PPC) */
#define PORT_POWER BIT(9)
/*
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 676f71d8305b..8117e7fe8da2 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2112,7 +2112,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
bus_state = &port->rhub->bus_state;
hcd_portnum = port->hcd_portnum;
portsc = xhci_portsc_readl(port);
- pls = portsc & PORT_PLS_MASK;
+ pls = FIELD_GET(PORT_PLS_MASK, portsc);
xhci_dbg(xhci, "Port change event, %d-%d, id %d, portsc: 0x%x\n",
hcd->self.busnum, hcd_portnum + 1, port_id, portsc);
@@ -2129,11 +2129,12 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
* Link status is not relible while port is in reset.
*/
if (!(portsc & PORT_RESET)) {
- port->link_inactive = (pls == XDEV_INACTIVE);
+ port->link_inactive = (pls == PLS_INACTIVE);
port->connected = !!(portsc & PORT_CONNECT);
}
- if ((portsc & PORT_PLC) && (portsc & PORT_PLS_MASK) == XDEV_RESUME) {
+ pls = FIELD_GET(PORT_PLS_MASK, portsc);
+ if ((portsc & PORT_PLC) && pls == PLS_RESUME) {
xhci_dbg(xhci, "port resume event for port %d\n", port_id);
cmd_reg = readl(&xhci->op_regs->command);
@@ -2151,7 +2152,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
bus_state->port_remote_wakeup |= 1 << hcd_portnum;
xhci_test_and_clear_bit(xhci, port, PORT_PLC);
usb_hcd_start_port_resume(&hcd->self, hcd_portnum);
- xhci_set_link_state(xhci, port, XDEV_U0);
+ xhci_set_link_state(xhci, port, PLS_U0);
/* Need to wait until the next link state change
* indicates the device is actually in U0.
*/
@@ -2174,11 +2175,9 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
}
}
- if ((portsc & PORT_PLC) &&
- FIELD_GET(PORT_SPEED_MASK, portsc) >= PORT_SPEED_SS &&
- ((portsc & PORT_PLS_MASK) == XDEV_U0 ||
- (portsc & PORT_PLS_MASK) == XDEV_U1 ||
- (portsc & PORT_PLS_MASK) == XDEV_U2)) {
+ pls = FIELD_GET(PORT_PLS_MASK, portsc);
+ if ((portsc & PORT_PLC) && pls <= PLS_U2 &&
+ FIELD_GET(PORT_SPEED_MASK, portsc) >= PORT_SPEED_SS) {
xhci_dbg(xhci, "resume SS port %d finished\n", port_id);
complete(&port->u3exit_done);
/* We've just brought the device into U0/1/2 through either the
diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c
index b31c7b087fc7..275d29b50ebd 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)
if ((value & PORT_PE) == 0)
continue;
- if ((value & PORT_PLS_MASK) != XDEV_U3) {
+ if (FIELD_GET(PORT_PLS_MASK, value) != PLS_U3) {
dev_info(dev, "%u-%u isn't suspended: %#010x\n",
hub->hcd->self.busnum, i + 1, value);
status = false;
@@ -2257,7 +2257,7 @@ static int tegra_xusb_enter_elpg(struct tegra_xusb *tegra, bool is_auto_resume)
continue;
portsc = xhci_portsc_readl(xhci->usb2_rhub.ports[i]);
tegra->lp0_utmi_pad_mask &= ~BIT(i);
- if (((portsc & PORT_PLS_MASK) == XDEV_U3) ||
+ if ((FIELD_GET(PORT_PLS_MASK, portsc) == PLS_U3) ||
(FIELD_GET(PORT_SPEED_MASK, portsc) == PORT_SPEED_FS))
tegra->lp0_utmi_pad_mask |= BIT(i);
}
@@ -2836,7 +2836,7 @@ static int tegra_xhci_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value,
if (!test_bit(i, &bus_state->resuming_ports))
continue;
portsc = xhci_portsc_readl(ports[i]);
- if ((portsc & PORT_PLS_MASK) == XDEV_RESUME)
+ if (FIELD_GET(PORT_PLS_MASK, portsc) == PLS_RESUME)
tegra_phy_xusb_utmi_pad_power_on(
tegra_xusb_get_phy(tegra, "usb2", (int) i));
}
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index fc1b0a6b0429..884a3214484c 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -377,7 +377,7 @@ static void compliance_mode_recovery(struct timer_list *t)
for (i = 0; i < rhub->num_ports; i++) {
temp = xhci_portsc_readl(rhub->ports[i]);
- if ((temp & PORT_PLS_MASK) == USB_SS_PORT_LS_COMP_MOD) {
+ if (FIELD_GET(PORT_PLS_MASK, temp) == PLS_COMP_MODE) {
/*
* Compliance Mode Detected. Letting USB Core
* handle the Warm Reset
@@ -929,7 +929,7 @@ static bool xhci_pending_portevent(struct xhci_hcd *xhci)
while (port_index--) {
portsc = xhci_portsc_readl(ports[port_index]);
if (portsc & PORT_CHANGE_MASK ||
- (portsc & PORT_PLS_MASK) == XDEV_RESUME)
+ FIELD_GET(PORT_PLS_MASK, portsc) == PLS_RESUME)
return true;
}
port_index = xhci->usb3_rhub.num_ports;
@@ -937,7 +937,7 @@ static bool xhci_pending_portevent(struct xhci_hcd *xhci)
while (port_index--) {
portsc = xhci_portsc_readl(ports[port_index]);
if (portsc & (PORT_CHANGE_MASK | PORT_CAS) ||
- (portsc & PORT_PLS_MASK) == XDEV_RESUME)
+ FIELD_GET(PORT_PLS_MASK, portsc) == PLS_RESUME)
return true;
}
return false;
@@ -4752,7 +4752,7 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
spin_unlock_irqrestore(&xhci->lock, flags);
xhci_change_max_exit_latency(xhci, udev, 0);
readl_poll_timeout(&ports[port_num]->port_reg->portsc, pm_val,
- (pm_val & PORT_PLS_MASK) == XDEV_U0,
+ FIELD_GET(PORT_PLS_MASK, pm_val) == PLS_U0,
100, 10000);
return 0;
}
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 61b132027963..18af4285a688 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -2379,32 +2379,32 @@ static inline const char *xhci_decode_slot_context(char *str,
static inline const char *xhci_portsc_link_state_string(u32 portsc)
{
- switch (portsc & PORT_PLS_MASK) {
- case XDEV_U0:
+ switch (FIELD_GET(PORT_PLS_MASK, portsc)) {
+ case PLS_U0:
return "U0";
- case XDEV_U1:
+ case PLS_U1:
return "U1";
- case XDEV_U2:
+ case PLS_U2:
return "U2";
- case XDEV_U3:
+ case PLS_U3:
return "U3";
- case XDEV_DISABLED:
+ case PLS_DISABLED:
return "Disabled";
- case XDEV_RXDETECT:
+ case PLS_RXDETECT:
return "RxDetect";
- case XDEV_INACTIVE:
+ case PLS_INACTIVE:
return "Inactive";
- case XDEV_POLLING:
+ case PLS_POLLING:
return "Polling";
- case XDEV_RECOVERY:
+ case PLS_RECOVERY:
return "Recovery";
- case XDEV_HOT_RESET:
+ case PLS_HOT_RESET:
return "Hot Reset";
- case XDEV_COMP_MODE:
+ case PLS_COMP_MODE:
return "Compliance mode";
- case XDEV_TEST_MODE:
+ case PLS_TEST_MODE:
return "Test mode";
- case XDEV_RESUME:
+ case PLS_RESUME:
return "Resume";
default:
break;
--
2.50.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v3 04/12] usb: xhci: rework Port Indicator Control macro
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
` (2 preceding siblings ...)
2026-12-03 14:42 ` [PATCH v3 03/12] usb: xhci: rework Port Link State macros Niklas Neronin
@ 2026-12-03 14:42 ` Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 05/12] usb: xhci: rework USB3 PORTPMSC macros Niklas Neronin
` (8 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Niklas Neronin @ 2026-12-03 14:42 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
Define the PORTSC Port Indicator Control field mask with GENMASK() and
make the indicator values plain field values. Rename the macros after
the xHCI specification abbreviation (PIC):
The macros currently have no users.
No functional change.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-port.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
index bf6e6e4d8ec6..40e403a46b20 100644
--- a/drivers/usb/host/xhci-port.h
+++ b/drivers/usb/host/xhci-port.h
@@ -55,11 +55,11 @@
#define PORT_SPEED_SS 4
#define PORT_SPEED_SSP 5
-/* Port Indicator Control */
-#define PORT_LED_OFF (0 << 14)
-#define PORT_LED_AMBER (1 << 14)
-#define PORT_LED_GREEN (2 << 14)
-#define PORT_LED_MASK (3 << 14)
+/* bits 15:14 - Port Indicator Control */
+#define PORT_PIC_MASK GENMASK(15, 14)
+#define PIC_OFF 0
+#define PIC_AMBER 1
+#define PIC_GREEN 2
/* Port Link State Write Strobe - set this when changing link state */
#define PORT_LINK_STROBE BIT(16)
/* true: connect status change */
--
2.50.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v3 05/12] usb: xhci: rework USB3 PORTPMSC macros
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
` (3 preceding siblings ...)
2026-12-03 14:42 ` [PATCH v3 04/12] usb: xhci: rework Port Indicator Control macro Niklas Neronin
@ 2026-12-03 14:42 ` Niklas Neronin
2026-12-03 14:50 ` sashiko-bot
2026-12-03 14:42 ` [PATCH v3 06/12] usb: xhci: rework USB2 " Niklas Neronin
` (7 subsequent siblings)
12 siblings, 1 reply; 17+ messages in thread
From: Niklas Neronin @ 2026-12-03 14:42 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
Replace the PORT_U1_TIMEOUT() and PORT_U2_TIMEOUT() helpers with
GENMASK() based field masks, and use FIELD_MODIFY() to update the
U1/U2 Timeout fields.
While at it, update the PORTPMSC comments to match xHCI 5.4.9.1:
- document the valid, reserved and infinite U1/U2 Timeout values
- add the Force Link PM Accept (FLA) bit and RsvdP bits 31:17
- drop the "Bits 24:31 for port testing" note, which applies to the
USB2 PORTPMSC register, not the USB3 one
No functional change.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-hub.c | 6 ++----
drivers/usb/host/xhci-port.h | 21 ++++++++++++---------
2 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index db492ac33016..58d18a1c3064 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1499,8 +1499,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
timeout = (wIndex & 0xff00) >> 8;
portpmsc = readl(&port->port_reg->portpmsc);
- portpmsc &= ~PORT_U1_TIMEOUT_MASK;
- portpmsc |= PORT_U1_TIMEOUT(timeout);
+ FIELD_MODIFY(PORT_U1_TIMEOUT_MASK, &portpmsc, timeout);
writel(portpmsc, &port->port_reg->portpmsc);
break;
case USB_PORT_FEAT_U2_TIMEOUT:
@@ -1509,8 +1508,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
timeout = (wIndex & 0xff00) >> 8;
portpmsc = readl(&port->port_reg->portpmsc);
- portpmsc &= ~PORT_U2_TIMEOUT_MASK;
- portpmsc |= PORT_U2_TIMEOUT(timeout);
+ FIELD_MODIFY(PORT_U2_TIMEOUT_MASK, &portpmsc, timeout);
writel(portpmsc, &port->port_reg->portpmsc);
break;
case USB_PORT_FEAT_TEST:
diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
index 40e403a46b20..fc87d4cacfbe 100644
--- a/drivers/usb/host/xhci-port.h
+++ b/drivers/usb/host/xhci-port.h
@@ -116,16 +116,19 @@
/* We mark duplicate entries with -1 */
#define DUPLICATE_ENTRY ((u8)(-1))
-/* Port Power Management Status and Control - port_power_base bitmasks */
-/* Inactivity timer value for transitions into U1, in microseconds.
- * Timeout can be up to 127us. 0xFF means an infinite timeout.
+/* USB3 Port Power Management Status and Control (PORTPMSC) 5.4.9.1 */
+/*
+ * bits 7:0 - U1 Timeout, inactivity timer value for transitions into U1.
+ * Timeout can be 0 to 127us, in 1us increments and 0xff is infinite timeout.
*/
-#define PORT_U1_TIMEOUT(p) ((p) & 0xff)
-#define PORT_U1_TIMEOUT_MASK 0xff
-/* Inactivity timer value for transitions into U2 */
-#define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8)
-#define PORT_U2_TIMEOUT_MASK (0xff << 8)
-/* Bits 24:31 for port testing */
+#define PORT_U1_TIMEOUT_MASK GENMASK(7, 0)
+/*
+ * bits 15:8 - U2 Timeout, inactivity timer value for transitions into U2.
+ * Timeout can be 0 to 65024us, in 256us increments and 0xff is infinite timeout.
+ */
+#define PORT_U2_TIMEOUT_MASK GENMASK(15, 8)
+/* bit 16 - Force Link PM Accept (FLA) */
+/* bits 31:17 - RsvdP */
/* USB2 Protocol PORTSPMSC */
#define PORT_L1S_MASK 7
--
2.50.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v3 06/12] usb: xhci: rework USB2 PORTPMSC macros
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
` (4 preceding siblings ...)
2026-12-03 14:42 ` [PATCH v3 05/12] usb: xhci: rework USB3 PORTPMSC macros Niklas Neronin
@ 2026-12-03 14:42 ` Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 07/12] usb: xhci: rework USB3 PORTLI macros Niklas Neronin
` (6 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Niklas Neronin @ 2026-12-03 14:42 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
Define macros to describe only the bit masks, and use the standard
FIELD_* helpers to extract, set, and update field values.
By consolidating macro usage and eliminating custom helpers, the code
becomes simpler and easier to follow. The use of standard bitfield
macros improves readability and enforces consistent register field
handling.
Rename bits 7:4 mask from the legacy HIRD definition to BESL, as per xHCI
specification.
Raname xhci_port_set_test_mode() local variabel 'temp' to 'portpmsc'.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-hub.c | 8 ++++----
drivers/usb/host/xhci-port.h | 28 ++++++++++++++++++----------
drivers/usb/host/xhci.c | 7 ++++---
3 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 58d18a1c3064..2b0522efc29a 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -678,14 +678,14 @@ static void xhci_set_port_power(struct xhci_hcd *xhci, struct xhci_port *port,
static void xhci_port_set_test_mode(struct xhci_hcd *xhci, u16 test_mode, int portnum)
{
- u32 temp;
+ u32 portpmsc;
struct xhci_port *port;
/* xhci only supports test mode for usb2 ports */
port = xhci->usb2_rhub.ports[portnum];
- temp = readl(&port->port_reg->portpmsc);
- temp |= test_mode << PORT_TEST_MODE_SHIFT;
- writel(temp, &port->port_reg->portpmsc);
+ portpmsc = readl(&port->port_reg->portpmsc);
+ FIELD_MODIFY(PORT_TEST_MODE_MASK, &portpmsc, test_mode);
+ writel(portpmsc, &port->port_reg->portpmsc);
xhci->test_mode = test_mode;
if (test_mode == USB_TEST_FORCE_ENABLE)
xhci_start(xhci);
diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
index fc87d4cacfbe..d6af7b878586 100644
--- a/drivers/usb/host/xhci-port.h
+++ b/drivers/usb/host/xhci-port.h
@@ -130,16 +130,24 @@
/* bit 16 - Force Link PM Accept (FLA) */
/* bits 31:17 - RsvdP */
-/* USB2 Protocol PORTSPMSC */
-#define PORT_L1S_MASK 7
-#define PORT_L1S_SUCCESS 1
-#define PORT_RWE BIT(3)
-#define PORT_HIRD(p) (((p) & 0xf) << 4)
-#define PORT_HIRD_MASK (0xf << 4)
-#define PORT_L1DS_MASK (0xff << 8)
-#define PORT_L1DS(p) (((p) & 0xff) << 8)
-#define PORT_HLE BIT(16)
-#define PORT_TEST_MODE_SHIFT 28
+/* USB2 Port Power Management Status and Control (PORTPMSC) 5.4.9.2 */
+/* bits 2:0 - L1 Status */
+#define PORT_L1S_MASK GENMASK(2, 0)
+/* bit 3 - Remote Wake Enable */
+#define PORT_RWE BIT(3)
+/*
+ * bits 7:4 - Best Effort Service Latency
+ * Some host controllers may implement the pre-2011 USB 2.0 LPM definition,
+ * where this field is interpreted as Host Initiated Resume Duration (HIRD).
+ */
+#define PORT_BESL_MASK GENMASK(7, 4)
+/* bits 15:8 - L1 Device Slot */
+#define PORT_L1DS_MASK GENMASK(15, 8)
+/* bit 16 - Hardware LPM Enable */
+#define PORT_HLE BIT(16)
+/* bits 27:17 - RsvdP */
+/* bits 31:28 - Port Test Control */
+#define PORT_TEST_MODE_MASK GENMASK(31, 28)
/* USB3 Protocol PORTLI Port Link Information */
#define PORT_LEC(p) ((p) & 0xffff)
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 884a3214484c..7a42361608f6 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4735,8 +4735,9 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
hird = xhci_calculate_hird_besl(xhci, udev);
}
- pm_val &= ~PORT_HIRD_MASK;
- pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id);
+ FIELD_MODIFY(PORT_BESL_MASK, &pm_val, hird);
+ FIELD_MODIFY(PORT_L1DS_MASK, &pm_val, udev->slot_id);
+ pm_val |= PORT_RWE;
writel(pm_val, &port_reg->portpmsc);
pm_val = readl(&port_reg->portpmsc);
pm_val |= PORT_HLE;
@@ -4744,7 +4745,7 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
/* flush write */
readl(&port_reg->portpmsc);
} else {
- pm_val &= ~(PORT_HLE | PORT_RWE | PORT_HIRD_MASK | PORT_L1DS_MASK);
+ pm_val &= ~(PORT_HLE | PORT_RWE | PORT_BESL_MASK | PORT_L1DS_MASK);
writel(pm_val, &port_reg->portpmsc);
/* flush write */
readl(&port_reg->portpmsc);
--
2.50.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v3 07/12] usb: xhci: rework USB3 PORTLI macros
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
` (5 preceding siblings ...)
2026-12-03 14:42 ` [PATCH v3 06/12] usb: xhci: rework USB2 " Niklas Neronin
@ 2026-12-03 14:42 ` Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 08/12] usb: xhci: rework USB2 " Niklas Neronin
` (5 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Niklas Neronin @ 2026-12-03 14:42 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
Replace the PORT_LEC(), PORT_RX_LANES() and PORT_TX_LANES() helpers
with GENMASK() based field masks, and use FIELD_GET() to extract the
fields. Rename the lane count masks after the xHCI specification
abbreviations (RLC, TLC).
Adjust the debugfs format specifiers to %lu to match the FIELD_GET()
result type.
No functional change.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-debugfs.c | 6 ++++--
drivers/usb/host/xhci-hub.c | 4 ++--
drivers/usb/host/xhci-port.h | 12 ++++++++----
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c
index e61ee722e2cd..8a73d3ee3481 100644
--- a/drivers/usb/host/xhci-debugfs.c
+++ b/drivers/usb/host/xhci-debugfs.c
@@ -402,8 +402,10 @@ static int xhci_portli_show(struct seq_file *s, void *unused)
/* PORTLI fields are valid if port is a USB3 or eUSB2V2 port */
if (port->rhub == &xhci->usb3_rhub)
- seq_printf(s, "0x%08x LEC=%u RLC=%u TLC=%u\n", portli,
- PORT_LEC(portli), PORT_RX_LANES(portli), PORT_TX_LANES(portli));
+ seq_printf(s, "0x%08x LEC=%lu RLC=%lu TLC=%lu\n", portli,
+ FIELD_GET(PORT_LEC_MASK, portli),
+ FIELD_GET(PORT_RLC_MASK, portli),
+ FIELD_GET(PORT_TLC_MASK, portli));
else if (xhci->hcc_params2 & HCC2_E2V2C)
seq_printf(s, "0x%08x RDR=%u TDR=%u\n", portli,
PORTLI_RDR(portli), PORTLI_TDR(portli));
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 2b0522efc29a..5de1ea5d5454 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1013,8 +1013,8 @@ static u32 xhci_get_ext_port_status(u32 portsc, u32 port_li)
ext_stat |= speed_id; /* bits 3:0, RX speed id */
ext_stat |= speed_id << 4; /* bits 7:4, TX speed id */
- ext_stat |= PORT_RX_LANES(port_li) << 8; /* bits 11:8 Rx lane count */
- ext_stat |= PORT_TX_LANES(port_li) << 12; /* bits 15:12 Tx lane count */
+ ext_stat |= FIELD_GET(PORT_RLC_MASK, port_li) << 8; /* bits 11:8 Rx lane count */
+ ext_stat |= FIELD_GET(PORT_TLC_MASK, port_li) << 12; /* bits 15:12 Tx lane count */
return ext_stat;
}
diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
index d6af7b878586..23986b8ed36d 100644
--- a/drivers/usb/host/xhci-port.h
+++ b/drivers/usb/host/xhci-port.h
@@ -149,10 +149,14 @@
/* bits 31:28 - Port Test Control */
#define PORT_TEST_MODE_MASK GENMASK(31, 28)
-/* USB3 Protocol PORTLI Port Link Information */
-#define PORT_LEC(p) ((p) & 0xffff)
-#define PORT_RX_LANES(p) (((p) >> 16) & 0xf)
-#define PORT_TX_LANES(p) (((p) >> 20) & 0xf)
+/* USB3 Port Link Info Register (PORTLI) 5.4.10.1 */
+/* bits 15:0 - Link Error Count */
+#define PORT_LEC_MASK GENMASK(15, 0)
+/* bits 19:16 - Rx Lane Count */
+#define PORT_RLC_MASK GENMASK(19, 16)
+/* bits 23:20 - Tx Lane Count */
+#define PORT_TLC_MASK GENMASK(23, 20)
+/* bits 31:24 - RsvdP */
/* eUSB2v2 protocol PORTLI Port Link information, RsvdP for normal USB2 */
#define PORTLI_RDR(p) ((p) & 0xf)
--
2.50.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v3 08/12] usb: xhci: rework USB2 PORTLI macros
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
` (6 preceding siblings ...)
2026-12-03 14:42 ` [PATCH v3 07/12] usb: xhci: rework USB3 PORTLI macros Niklas Neronin
@ 2026-12-03 14:42 ` Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 09/12] usb: xhci: document USB3 PORTHLPMC register layout Niklas Neronin
` (4 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Niklas Neronin @ 2026-12-03 14:42 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
Replace the PORTLI_RDR() and PORTLI_TDR() helpers with GENMASK() based
field masks, and use FIELD_GET() to extract the Rx/Tx Data Rate fields.
The macros are renamed to PORT_RDR_MASK and PORT_TDR_MASK, matching the
naming used for the USB3 PORTLI fields.
The RDR and TDR fields are only defined for eUSB2v2 ports, i.e. when the
controller reports E2V2C=1; on normal USB2 ports the register is RsvdP.
No functional change.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-debugfs.c | 5 +++--
drivers/usb/host/xhci-port.h | 13 ++++++++++---
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c
index 8a73d3ee3481..02729682c7e2 100644
--- a/drivers/usb/host/xhci-debugfs.c
+++ b/drivers/usb/host/xhci-debugfs.c
@@ -407,8 +407,9 @@ static int xhci_portli_show(struct seq_file *s, void *unused)
FIELD_GET(PORT_RLC_MASK, portli),
FIELD_GET(PORT_TLC_MASK, portli));
else if (xhci->hcc_params2 & HCC2_E2V2C)
- seq_printf(s, "0x%08x RDR=%u TDR=%u\n", portli,
- PORTLI_RDR(portli), PORTLI_TDR(portli));
+ seq_printf(s, "0x%08x RDR=%lu TDR=%lu\n", portli,
+ FIELD_GET(PORT_RDR_MASK, portli),
+ FIELD_GET(PORT_TDR_MASK, portli));
else
seq_printf(s, "0x%08x RsvdP\n", portli);
diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
index 23986b8ed36d..63efb0170c3e 100644
--- a/drivers/usb/host/xhci-port.h
+++ b/drivers/usb/host/xhci-port.h
@@ -158,9 +158,16 @@
#define PORT_TLC_MASK GENMASK(23, 20)
/* bits 31:24 - RsvdP */
-/* eUSB2v2 protocol PORTLI Port Link information, RsvdP for normal USB2 */
-#define PORTLI_RDR(p) ((p) & 0xf)
-#define PORTLI_TDR(p) (((p) >> 4) & 0xf)
+/*
+ * USB2 Port Link Info Register (PORTLI), xHCI 5.4.10.2
+ * Fields are only defined for eUSB2v2 ports (HCC2_E2V2C = 1),
+ * otherwise the whole register is RsvdP.
+ */
+/* bits 3:0 - Rx Data Rate (RDR) */
+#define PORT_RDR_MASK GENMASK(3, 0)
+/* bits 7:4 - Tx Data Rate (TDR) */
+#define PORT_TDR_MASK GENMASK(7, 4)
+/* bits 31:8 - RsvdP */
/* USB2 Protocol PORTHLPMC */
#define PORT_HIRDM(p)((p) & 3)
--
2.50.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v3 09/12] usb: xhci: document USB3 PORTHLPMC register layout
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
` (7 preceding siblings ...)
2026-12-03 14:42 ` [PATCH v3 08/12] usb: xhci: rework USB2 " Niklas Neronin
@ 2026-12-03 14:42 ` Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 10/12] usb: xhci: rework USB2 PORTHLPMC macros Niklas Neronin
` (3 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Niklas Neronin @ 2026-12-03 14:42 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
Add comments describing the USB3 Port Hardware LPM Control
(PORTHLPMC) register fields as defined by the xHCI specification.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-port.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
index 63efb0170c3e..664aa19f00b3 100644
--- a/drivers/usb/host/xhci-port.h
+++ b/drivers/usb/host/xhci-port.h
@@ -169,6 +169,10 @@
#define PORT_TDR_MASK GENMASK(7, 4)
/* bits 31:8 - RsvdP */
+/* USB3 Port Hardware LPM Control Register (PORTHLPMC) 5.4.11.1 */
+/* bits 15:0 - Link Soft Error Count, if LSECC=1 else RsvdP */
+/* bits 31:16 - RsvdP */
+
/* USB2 Protocol PORTHLPMC */
#define PORT_HIRDM(p)((p) & 3)
#define PORT_L1_TIMEOUT(p)(((p) & 0xff) << 2)
--
2.50.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v3 10/12] usb: xhci: rework USB2 PORTHLPMC macros
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
` (8 preceding siblings ...)
2026-12-03 14:42 ` [PATCH v3 09/12] usb: xhci: document USB3 PORTHLPMC register layout Niklas Neronin
@ 2026-12-03 14:42 ` Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 11/12] usb: xhci: update port register bitfield comments for consistency Niklas Neronin
` (2 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Niklas Neronin @ 2026-12-03 14:42 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
Replace the PORT_HIRDM(), PORT_L1_TIMEOUT() and PORT_BESLD() helpers
with GENMASK() based field masks, and use FIELD_PREP() to build the
PORTHLPMC value in xhci_calculate_usb2_hw_lpm_params().
While at it, document the PORTHLPMC register layout as described in
xHCI 5.4.11.2.
No functional change.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-port.h | 19 +++++++++++++------
drivers/usb/host/xhci.c | 3 ++-
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
index 664aa19f00b3..c0a23caad40e 100644
--- a/drivers/usb/host/xhci-port.h
+++ b/drivers/usb/host/xhci-port.h
@@ -173,13 +173,20 @@
/* bits 15:0 - Link Soft Error Count, if LSECC=1 else RsvdP */
/* bits 31:16 - RsvdP */
-/* USB2 Protocol PORTHLPMC */
-#define PORT_HIRDM(p)((p) & 3)
-#define PORT_L1_TIMEOUT(p)(((p) & 0xff) << 2)
-#define PORT_BESLD(p)(((p) & 0xf) << 10)
-
+/* USB2 Port Hardware LPM Control Register (PORTHLPMC), xHCI 5.4.11.2 */
+/* bits 1:0 - Host Initiated Resume Duration Mode (HIRDM) */
+#define PORT_HIRDM_MASK GENMASK(1, 0)
+/*
+ * bits 9:2 - L1 Timeout, L1 inactivity timer value.
+ * 0x00: 128 us (default).
+ * 0x01-0xff: 256 us to 65280 us, in 256 us increments.
+ */
+#define PORT_L1_TIMEOUT_MASK GENMASK(9, 2)
/* use 512 microseconds as USB2 LPM L1 default timeout. */
-#define XHCI_L1_TIMEOUT 512
+#define XHCI_L1_TIMEOUT 512
+/* bits 13:10 - Best Effort Service Latency Deep (BESLD) */
+#define PORT_BESLD_MASK GENMASK(13, 10)
+/* bits 31:14 - RsvdP */
/* Set default HIRD/BESL value to 4 (350/400us) for USB2 L1 LPM resume latency.
* Safe to use with mixed HIRD and BESL systems (host and device) and is used
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 7a42361608f6..c9a68c42d769 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4665,7 +4665,8 @@ static int xhci_calculate_usb2_hw_lpm_params(struct usb_device *udev)
hirdm = 1;
}
- return PORT_BESLD(besld) | PORT_L1_TIMEOUT(l1) | PORT_HIRDM(hirdm);
+ return FIELD_PREP(PORT_BESLD_MASK, besld) | FIELD_PREP(PORT_L1_TIMEOUT_MASK, l1) |
+ FIELD_PREP(PORT_HIRDM_MASK, hirdm);
}
static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
--
2.50.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v3 11/12] usb: xhci: update port register bitfield comments for consistency
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
` (9 preceding siblings ...)
2026-12-03 14:42 ` [PATCH v3 10/12] usb: xhci: rework USB2 PORTHLPMC macros Niklas Neronin
@ 2026-12-03 14:42 ` Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 12/12] usb: xhci: rename PORTSC field macros to xHCI spec abbreviations Niklas Neronin
2026-12-03 14:59 ` [PATCH v3 00/12] usb: xhci: rework xHCI Port macros sashiko-bot
12 siblings, 0 replies; 17+ messages in thread
From: Niklas Neronin @ 2026-12-03 14:42 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
Update comments in xhci-port.h to improve readability and ensure a
consistent format across all Port Register bit fields.
Each field comment now includes the bit range and the field name and
its valid value range or meaning where applicable:
/* <bit range> - <Field name>, <notes> */
The updates are based on the xHCI specification, revision 1.2.
While at it:
- move PORT_CHANGE_MASK below the PORTSC bit definitions
- fix the XHCI_DEFAULT_BESL location reference in xhci.c, the macro
is defined in xhci-port.h
No functional change.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-port.h | 65 ++++++++++++++++++++----------------
drivers/usb/host/xhci.c | 2 +-
2 files changed, 37 insertions(+), 30 deletions(-)
diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
index c0a23caad40e..3cb28394be3f 100644
--- a/drivers/usb/host/xhci-port.h
+++ b/drivers/usb/host/xhci-port.h
@@ -1,17 +1,21 @@
/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * xHCI Host Controller USB Port Register Set
+ * xHCI Specification Section 5.4, Revision 1.2.
+ */
#include <linux/bitfield.h>
#include <linux/bits.h>
-/* PORTSC - Port Status and Control Register - port_status_base bitmasks */
-/* true: device connected */
+/* Port Status and Control (PORTSC) 5.4.8 */
+/* bit 0 - Current Connect Status */
#define PORT_CONNECT BIT(0)
-/* true: port enabled */
+/* bit 1 - Port Enabled/Disabled */
#define PORT_PE BIT(1)
-/* bit 2 reserved and zeroed */
-/* true: port has an over-current condition */
+/* bit 2 - RsvdZ */
+/* bit 3 - Over-current Active */
#define PORT_OC BIT(3)
-/* true: port reset signaling asserted */
+/* bit 4 - Port Reset */
#define PORT_RESET BIT(4)
/*
* bits 8:5 - Port Link State, by default '5'.
@@ -33,7 +37,7 @@
#define PLS_TEST_MODE 11
/* Values 12-14 are Reserved */
#define PLS_RESUME 15
-/* true: port has power (see HCC_PPC) */
+/* bit 9 - Port Power, see HCC_PPC */
#define PORT_POWER BIT(9)
/*
* bits 13:10 - Port Speed
@@ -60,23 +64,26 @@
#define PIC_OFF 0
#define PIC_AMBER 1
#define PIC_GREEN 2
-/* Port Link State Write Strobe - set this when changing link state */
+/* bit 16 - Port Link State Write Strobe, set this when changing link state */
#define PORT_LINK_STROBE BIT(16)
-/* true: connect status change */
+/* bit 17 - Connect Status Change */
#define PORT_CSC BIT(17)
-/* true: port enable change */
+/* bit 18 - Port Enabled/Disabled Change */
#define PORT_PEC BIT(18)
-/* true: warm reset for a USB 3.0 device is done. A "hot" reset puts the port
+/*
+ * bit 19 - Warm Port Reset Change
+ * Warm reset for a USB 3.0 device is done. A "hot" reset puts the port
* into an enabled state, and the device into the default state. A "warm" reset
* also resets the link, forcing the device through the link training sequence.
* SW can also look at the Port Reset register to see when warm reset is done.
*/
#define PORT_WRC BIT(19)
-/* true: over-current change */
+/* bit 20 - Over-current Change */
#define PORT_OCC BIT(20)
-/* true: reset change - 1 to 0 transition of PORT_RESET */
+/* bit 21 - Port Reset Change */
#define PORT_RC BIT(21)
-/* port link status change - set on some port link state transitions:
+/*
+ * bit 22 - Port Link State Change, set on some port link state transitions:
* Transition Reason
* ------------------------------------------------------------------------------
* - U3 to Resume Wakeup signaling from a device
@@ -90,28 +97,27 @@
* - Any state to inactive Error on USB 3.0 port
*/
#define PORT_PLC BIT(22)
-/* port configure error change - port failed to configure its link partner */
+/* bit 23 - Port Config Error Change, port failed to configure its link partner */
#define PORT_CEC BIT(23)
-#define PORT_CHANGE_MASK (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \
- PORT_RC | PORT_PLC | PORT_CEC)
-
-
-/* Cold Attach Status - xHC can set this bit to report device attached during
- * Sx state. Warm port reset should be perfomed to clear this bit and move port
- * to connected state.
+/*
+ * bit 24 - Cold Attach Status
+ * xHC can set this bit to report device attached during Sx state.
+ * Warm port reset should be perfomed to clear this bit and move port to connected state.
*/
#define PORT_CAS BIT(24)
-/* wake on connect (enable) */
+/* bit 25 - Wake on Connect Enable */
#define PORT_WKCONN_E BIT(25)
-/* wake on disconnect (enable) */
+/* bit 26 - Wake on Disconnect Enable */
#define PORT_WKDISC_E BIT(26)
-/* wake on over-current (enable) */
+/* bit 27 - Wake on Over-current Enable */
#define PORT_WKOC_E BIT(27)
-/* bits 28:29 reserved */
-/* true: device is non-removable - for USB 3.0 roothub emulation */
+/* bits 29:28 - RsvdZ */
+/* bit 30 - Device Removable, for USB 3.0 roothub emulation */
#define PORT_DEV_REMOVE BIT(30)
-/* Initiate a warm port reset - complete when PORT_WRC is '1' */
+/* bit 31 - Warm Port Reset, complete when PORT_WRC is '1' */
#define PORT_WR BIT(31)
+#define PORT_CHANGE_MASK (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \
+ PORT_RC | PORT_PLC | PORT_CEC)
/* We mark duplicate entries with -1 */
#define DUPLICATE_ENTRY ((u8)(-1))
@@ -188,7 +194,8 @@
#define PORT_BESLD_MASK GENMASK(13, 10)
/* bits 31:14 - RsvdP */
-/* Set default HIRD/BESL value to 4 (350/400us) for USB2 L1 LPM resume latency.
+/*
+ * Set default HIRD/BESL value to 4 (350/400us) for USB2 L1 LPM resume latency.
* Safe to use with mixed HIRD and BESL systems (host and device) and is used
* by other operating systems.
*
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index c9a68c42d769..5837ec9fb495 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4710,7 +4710,7 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
if (udev->usb2_hw_lpm_besl_capable) {
/* if device doesn't have a preferred BESL value use a
* default one which works with mixed HIRD and BESL
- * systems. See XHCI_DEFAULT_BESL definition in xhci.h
+ * systems. See XHCI_DEFAULT_BESL definition in xhci-port.h
*/
field = le32_to_cpu(udev->bos->ext_cap->bmAttributes);
if ((field & USB_BESL_SUPPORT) &&
--
2.50.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v3 12/12] usb: xhci: rename PORTSC field macros to xHCI spec abbreviations
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
` (10 preceding siblings ...)
2026-12-03 14:42 ` [PATCH v3 11/12] usb: xhci: update port register bitfield comments for consistency Niklas Neronin
@ 2026-12-03 14:42 ` Niklas Neronin
2026-12-03 14:54 ` sashiko-bot
2026-12-03 14:59 ` [PATCH v3 00/12] usb: xhci: rework xHCI Port macros sashiko-bot
12 siblings, 1 reply; 17+ messages in thread
From: Niklas Neronin @ 2026-12-03 14:42 UTC (permalink / raw)
To: mathias.nyman; +Cc: linux-usb, Niklas Neronin
The PORTSC field macros currently use two naming schemes. Some use the
xHCI specification abbreviations (e.g. PORT_CSC, PORT_PEC, PORT_CAS) and
others use driver-specific names (e.g. PORT_CONNECT, PORT_PE, PORT_OC).
The driver-specific names don't follow a consistent pattern, which
makes them harder to search for and to match against the specification.
Rename the remaining driver-specific macros to their xHCI specification
(section 5.4.8) abbreviations:
PORT_CONNECT -> PORT_CCS
PORT_PE -> PORT_PED
PORT_OC -> PORT_OCA
PORT_RESET -> PORT_PR
PORT_POWER -> PORT_PP
PORT_LINK_STROBE -> PORT_LWS
PORT_RC -> PORT_PRC
PORT_WKCONN_E -> PORT_WCE
PORT_WKDISC_E -> PORT_WDE
PORT_WKOC_E -> PORT_WOE
PORT_DEV_REMOVE -> PORT_DR
PORT_WR -> PORT_WPR
Each macro name is now the spec abbreviation, so the "(XXX)" suffixes
in the bitfield comments are no longer needed and are dropped.
The dwc3 host glue (drivers/usb/dwc3/host.c) and the early xHCI debug
capability driver (drivers/usb/early/xhci-dbc.c) include xhci-port.h,
so they are updated to the new names as well.
The cdnsp gadget driver has its own copy of these definitions and is not
affected.
Compared objdump -dr output before and after the change: the object code
is identical.
No functional change intended.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/dwc3/host.c | 2 +-
drivers/usb/early/xhci-dbc.c | 4 +-
drivers/usb/host/xhci-debugfs.c | 2 +-
drivers/usb/host/xhci-hub.c | 94 ++++++++++++++++-----------------
drivers/usb/host/xhci-pci.c | 2 +-
drivers/usb/host/xhci-port.h | 30 +++++------
drivers/usb/host/xhci-ring.c | 6 +--
drivers/usb/host/xhci-tegra.c | 6 +--
drivers/usb/host/xhci.c | 4 +-
drivers/usb/host/xhci.h | 24 ++++-----
10 files changed, 87 insertions(+), 87 deletions(-)
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index cd1e5204ac3a..f33ca596cde6 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -54,7 +54,7 @@ static void dwc3_power_off_all_roothub_ports(struct dwc3 *dwc)
for (i = 1; i <= port_num; i++) {
offset = op_regs_base + XHCI_PORTSC_BASE + 0x10 * (i - 1);
reg = readl(xhci_regs + offset);
- reg &= ~PORT_POWER;
+ reg &= ~PORT_PP;
writel(reg, xhci_regs + offset);
}
diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c
index 41118bba9197..ec2efd0e92eb 100644
--- a/drivers/usb/early/xhci-dbc.c
+++ b/drivers/usb/early/xhci-dbc.c
@@ -359,8 +359,8 @@ static void xdbc_do_reset_debug_port(u32 id, u32 count)
for (i = id; i < (id + count); i++) {
portsc = ops_reg + 0x400 + i * 0x10;
val = readl(portsc);
- if (!(val & PORT_CONNECT))
- writel(val | PORT_RESET, portsc);
+ if (!(val & PORT_CCS))
+ writel(val | PORT_PR, portsc);
}
}
diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c
index 02729682c7e2..fb4c216253c1 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);
FIELD_MODIFY(PORT_PLS_MASK, &portsc, PLS_COMP_MODE);
- portsc |= PORT_LINK_STROBE;
+ portsc |= PORT_LWS;
xhci_portsc_writel(port, portsc);
spin_unlock_irqrestore(&xhci->lock, flags);
} else {
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 5de1ea5d5454..627b8353c399 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -17,9 +17,9 @@
#include "xhci.h"
#include "xhci-trace.h"
-#define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E)
+#define PORT_WAKE_BITS (PORT_WOE | PORT_WDE | PORT_WCE)
#define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \
- PORT_RC | PORT_PLC | PORT_PE)
+ PORT_PRC | PORT_PLC | PORT_PED)
/* Default sublink speed attribute of each lane */
static u32 ssp_cap_default_ssa[] = {
@@ -302,7 +302,7 @@ static void xhci_usb2_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
/* If a device is removable, PORTSC reports a 0, same as in the
* hub descriptor DeviceRemovable bits.
*/
- if (portsc & PORT_DEV_REMOVE)
+ if (portsc & PORT_DR)
/* This math is hairy because bit 0 of DeviceRemovable
* is reserved, and bit 1 is for port 1, etc.
*/
@@ -356,7 +356,7 @@ static void xhci_usb3_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
/* bit 0 is reserved, bit 1 is for port 1, etc. */
for (i = 0; i < ports; i++) {
portsc = xhci_portsc_readl(rhub->ports[i]);
- if (portsc & PORT_DEV_REMOVE)
+ if (portsc & PORT_DR)
port_removable |= 1 << (i + 1);
}
@@ -571,7 +571,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 */
- xhci_portsc_writel(port, portsc | PORT_PE);
+ xhci_portsc_writel(port, portsc | PORT_PED);
portsc = xhci_portsc_readl(port);
xhci_dbg(xhci, "disable port %d-%d, portsc: 0x%x\n",
@@ -586,7 +586,7 @@ static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue, struct
switch (wValue) {
case USB_PORT_FEAT_C_RESET:
- status = PORT_RC;
+ status = PORT_PRC;
port_change_bit = "reset";
break;
case USB_PORT_FEAT_C_BH_PORT_RESET:
@@ -660,11 +660,11 @@ 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);
+ xhci_portsc_writel(port, temp | PORT_PP);
xhci_portsc_readl(port);
} else {
/* Power off */
- xhci_portsc_writel(port, temp & ~PORT_POWER);
+ xhci_portsc_writel(port, temp & ~PORT_PP);
}
spin_unlock_irqrestore(&xhci->lock, *flags);
@@ -802,7 +802,7 @@ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
portsc = xhci_portsc_readl(port);
temp = xhci_port_state_to_neutral(portsc);
FIELD_MODIFY(PORT_PLS_MASK, &temp, link_state);
- temp |= PORT_LINK_STROBE;
+ temp |= PORT_LWS;
xhci_portsc_writel(port, temp);
xhci_dbg(xhci, "Set port %d-%d link state, portsc: 0x%x, write 0x%x",
@@ -819,19 +819,19 @@ static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci,
temp = xhci_port_state_to_neutral(temp);
if (wake_mask & USB_PORT_FEAT_REMOTE_WAKE_CONNECT)
- temp |= PORT_WKCONN_E;
+ temp |= PORT_WCE;
else
- temp &= ~PORT_WKCONN_E;
+ temp &= ~PORT_WCE;
if (wake_mask & USB_PORT_FEAT_REMOTE_WAKE_DISCONNECT)
- temp |= PORT_WKDISC_E;
+ temp |= PORT_WDE;
else
- temp &= ~PORT_WKDISC_E;
+ temp &= ~PORT_WDE;
if (wake_mask & USB_PORT_FEAT_REMOTE_WAKE_OVER_CURRENT)
- temp |= PORT_WKOC_E;
+ temp |= PORT_WOE;
else
- temp &= ~PORT_WKOC_E;
+ temp &= ~PORT_WOE;
xhci_portsc_writel(port, temp);
}
@@ -929,7 +929,7 @@ static int xhci_handle_usb2_port_link_resume(struct xhci_port *port,
xhci = hcd_to_xhci(hcd);
portnum = port->hcd_portnum;
- if ((portsc & PORT_RESET) || !(portsc & PORT_PE)) {
+ if ((portsc & PORT_PR) || !(portsc & PORT_PED)) {
return -EINVAL;
}
/* did port event handler already start resume timing? */
@@ -1051,7 +1051,7 @@ static void xhci_get_usb3_port_status(struct xhci_port *port, u32 *status,
*status |= USB_PORT_STAT_C_CONFIG_ERROR << 16;
/* USB3 specific wPortStatus bits */
- if (portsc & PORT_POWER)
+ if (portsc & PORT_PP)
*status |= USB_SS_PORT_STAT_POWER;
/* no longer suspended or resuming */
@@ -1083,7 +1083,7 @@ static void xhci_get_usb2_port_status(struct xhci_port *port, u32 *status,
portnum = port->hcd_portnum;
/* USB2 wPortStatus bits */
- if (portsc & PORT_POWER) {
+ if (portsc & PORT_PP) {
*status |= USB_PORT_STAT_POWER;
/* link state is only valid if port is powered */
@@ -1153,25 +1153,25 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd, struct xhci_bus_state *bus_
status |= USB_PORT_STAT_C_ENABLE << 16;
if (portsc & PORT_OCC)
status |= USB_PORT_STAT_C_OVERCURRENT << 16;
- if (portsc & PORT_RC)
+ if (portsc & PORT_PRC)
status |= USB_PORT_STAT_C_RESET << 16;
/* common wPortStatus bits */
- if (portsc & PORT_CONNECT) {
+ if (portsc & PORT_CCS) {
status |= USB_PORT_STAT_CONNECTION;
status |= xhci_port_speed(portsc);
}
- if (portsc & PORT_PE)
+ if (portsc & PORT_PED)
status |= USB_PORT_STAT_ENABLE;
- if (portsc & PORT_OC)
+ if (portsc & PORT_OCA)
status |= USB_PORT_STAT_OVERCURRENT;
- if (portsc & PORT_RESET)
+ if (portsc & PORT_PR)
status |= USB_PORT_STAT_RESET;
/* track connect and link error status when hub is polling */
- if (!(portsc & PORT_RESET)) {
+ if (!(portsc & PORT_PR)) {
port->link_inactive = (FIELD_GET(PORT_PLS_MASK, portsc) == PLS_INACTIVE);
- port->connected = !!(portsc & PORT_CONNECT);
+ port->connected = !!(portsc & PORT_CCS);
}
/* USB2 and USB3 specific bits, including Port Link State */
@@ -1306,7 +1306,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
* enabled (PED = '1',PLS < '3') state.
*/
portsc = xhci_portsc_readl(port);
- if ((portsc & PORT_PE) == 0 || (portsc & PORT_RESET) ||
+ if ((portsc & PORT_PED) == 0 || (portsc & PORT_PR) ||
FIELD_GET(PORT_PLS_MASK, portsc) >= PLS_U3) {
xhci_warn(xhci, "USB core suspending port %d-%d not in U0/U1/U2\n",
hcd->self.busnum, portnum + 1);
@@ -1344,9 +1344,9 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
* connection event.
*/
portsc |= PORT_CSC | PORT_PEC | PORT_WRC |
- PORT_OCC | PORT_RC | PORT_PLC |
+ PORT_OCC | PORT_PRC | PORT_PLC |
PORT_CEC;
- xhci_portsc_writel(port, portsc | PORT_PE);
+ xhci_portsc_writel(port, portsc | PORT_PED);
portsc = xhci_portsc_readl(port);
break;
}
@@ -1380,7 +1380,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
break;
}
- if ((portsc & PORT_CONNECT)) {
+ if ((portsc & PORT_CCS)) {
xhci_warn(xhci, "Can't set compliance mode when port is connected\n");
goto error;
}
@@ -1393,7 +1393,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
break;
}
/* Port must be enabled */
- if (!(portsc & PORT_PE)) {
+ if (!(portsc & PORT_PED)) {
retval = -ENODEV;
break;
}
@@ -1474,7 +1474,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
xhci_set_port_power(xhci, port, true, &flags);
break;
case USB_PORT_FEAT_RESET:
- portsc |= PORT_RESET;
+ portsc |= PORT_PR;
xhci_portsc_writel(port, portsc);
portsc = xhci_portsc_readl(port);
@@ -1489,7 +1489,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
hcd->self.busnum, portnum + 1, portsc);
break;
case USB_PORT_FEAT_BH_PORT_RESET:
- portsc |= PORT_WR;
+ portsc |= PORT_WPR;
xhci_portsc_writel(port, portsc);
portsc = xhci_portsc_readl(port);
break;
@@ -1547,10 +1547,10 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
portsc = xhci_portsc_readl(port);
xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n");
xhci_dbg(xhci, "PORTSC %04x\n", portsc);
- if (portsc & PORT_RESET)
+ if (portsc & PORT_PR)
goto error;
if (FIELD_GET(PORT_PLS_MASK, portsc) == PLS_U3) {
- if ((portsc & PORT_PE) == 0)
+ if ((portsc & PORT_PED) == 0)
goto error;
set_bit(portnum, &bus_state->resuming_ports);
@@ -1674,9 +1674,9 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
buf[(i + 1) / 8] |= 1 << (i + 1) % 8;
status = 1;
}
- if ((temp & PORT_RC))
+ if ((temp & PORT_PRC))
reset_change = true;
- if (temp & PORT_OC)
+ if (temp & PORT_OCA)
status = 1;
}
if (!status && !reset_change) {
@@ -1746,14 +1746,14 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
goto retry;
}
/* bail out if port detected a over-current condition */
- if (t1 & PORT_OC) {
+ if (t1 & PORT_OCA) {
bus_state->bus_suspended = 0;
spin_unlock_irqrestore(&xhci->lock, flags);
xhci_dbg(xhci, "Bus suspend bailout, port over-current detected\n");
return -EBUSY;
}
/* suspend ports in U0, or bail out for new connect changes */
- if ((t1 & PORT_PE) && FIELD_GET(PORT_PLS_MASK, t1) == PLS_U0) {
+ if ((t1 & PORT_PED) && FIELD_GET(PORT_PLS_MASK, t1) == PLS_U0) {
if ((t1 & PORT_CSC) && wake_enabled) {
bus_state->bus_suspended = 0;
spin_unlock_irqrestore(&xhci->lock, flags);
@@ -1763,7 +1763,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
xhci_dbg(xhci, "port %d-%d not suspended\n",
hcd->self.busnum, port_index + 1);
FIELD_MODIFY(PORT_PLS_MASK, &t2, PLS_U3);
- t2 |= PORT_LINK_STROBE;
+ t2 |= PORT_LWS;
set_bit(port_index, &bus_state->bus_suspended);
}
/* USB core sets remote wake mask for USB 3.0 hubs,
@@ -1771,12 +1771,12 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
* is enabled, so also enable remote wake here.
*/
if (wake_enabled) {
- if (t1 & PORT_CONNECT) {
- t2 |= PORT_WKOC_E | PORT_WKDISC_E;
- t2 &= ~PORT_WKCONN_E;
+ if (t1 & PORT_CCS) {
+ t2 |= PORT_WOE | PORT_WDE;
+ t2 &= ~PORT_WCE;
} else {
- t2 |= PORT_WKOC_E | PORT_WKCONN_E;
- t2 &= ~PORT_WKDISC_E;
+ t2 |= PORT_WOE | PORT_WCE;
+ t2 &= ~PORT_WDE;
}
if ((xhci->quirks & XHCI_U2_DISABLE_WAKE) &&
@@ -1831,7 +1831,7 @@ static bool xhci_port_missing_cas_quirk(struct xhci_port *port)
portsc = xhci_portsc_readl(port);
/* if any of these are set we are not stuck */
- if (portsc & (PORT_CONNECT | PORT_CAS))
+ if (portsc & (PORT_CCS | PORT_CAS))
return false;
pls = FIELD_GET(PORT_PLS_MASK, portsc);
@@ -1840,7 +1840,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;
+ portsc |= PORT_WPR;
xhci_portsc_writel(port, portsc);
/* flush write */
xhci_portsc_readl(port);
@@ -1907,7 +1907,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
case PLS_U3:
portsc = xhci_port_state_to_neutral(portsc);
FIELD_MODIFY(PORT_PLS_MASK, &portsc, next_state);
- portsc |= PORT_LINK_STROBE;
+ portsc |= PORT_LWS;
break;
case PLS_RESUME:
/* resume already initiated */
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index e71906889b12..6502c2bc92e6 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -941,7 +941,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);
- xhci_portsc_writel(port, portsc | PORT_PE);
+ xhci_portsc_writel(port, portsc | PORT_PED);
}
return 0;
diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
index 3cb28394be3f..46975524a7fe 100644
--- a/drivers/usb/host/xhci-port.h
+++ b/drivers/usb/host/xhci-port.h
@@ -9,14 +9,14 @@
/* Port Status and Control (PORTSC) 5.4.8 */
/* bit 0 - Current Connect Status */
-#define PORT_CONNECT BIT(0)
+#define PORT_CCS BIT(0)
/* bit 1 - Port Enabled/Disabled */
-#define PORT_PE BIT(1)
+#define PORT_PED BIT(1)
/* bit 2 - RsvdZ */
/* bit 3 - Over-current Active */
-#define PORT_OC BIT(3)
+#define PORT_OCA BIT(3)
/* bit 4 - Port Reset */
-#define PORT_RESET BIT(4)
+#define PORT_PR BIT(4)
/*
* bits 8:5 - Port Link State, by default '5'.
* Reading gives the current link PM state of the port.
@@ -38,7 +38,7 @@
/* Values 12-14 are Reserved */
#define PLS_RESUME 15
/* bit 9 - Port Power, see HCC_PPC */
-#define PORT_POWER BIT(9)
+#define PORT_PP BIT(9)
/*
* bits 13:10 - Port Speed
* Values defined in xHCI specification 7.2.2.1.1:
@@ -65,7 +65,7 @@
#define PIC_AMBER 1
#define PIC_GREEN 2
/* bit 16 - Port Link State Write Strobe, set this when changing link state */
-#define PORT_LINK_STROBE BIT(16)
+#define PORT_LWS BIT(16)
/* bit 17 - Connect Status Change */
#define PORT_CSC BIT(17)
/* bit 18 - Port Enabled/Disabled Change */
@@ -81,7 +81,7 @@
/* bit 20 - Over-current Change */
#define PORT_OCC BIT(20)
/* bit 21 - Port Reset Change */
-#define PORT_RC BIT(21)
+#define PORT_PRC BIT(21)
/*
* bit 22 - Port Link State Change, set on some port link state transitions:
* Transition Reason
@@ -106,18 +106,18 @@
*/
#define PORT_CAS BIT(24)
/* bit 25 - Wake on Connect Enable */
-#define PORT_WKCONN_E BIT(25)
+#define PORT_WCE BIT(25)
/* bit 26 - Wake on Disconnect Enable */
-#define PORT_WKDISC_E BIT(26)
+#define PORT_WDE BIT(26)
/* bit 27 - Wake on Over-current Enable */
-#define PORT_WKOC_E BIT(27)
+#define PORT_WOE BIT(27)
/* bits 29:28 - RsvdZ */
/* bit 30 - Device Removable, for USB 3.0 roothub emulation */
-#define PORT_DEV_REMOVE BIT(30)
+#define PORT_DR BIT(30)
/* bit 31 - Warm Port Reset, complete when PORT_WRC is '1' */
-#define PORT_WR BIT(31)
+#define PORT_WPR BIT(31)
#define PORT_CHANGE_MASK (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \
- PORT_RC | PORT_PLC | PORT_CEC)
+ PORT_PRC | PORT_PLC | PORT_CEC)
/* We mark duplicate entries with -1 */
#define DUPLICATE_ENTRY ((u8)(-1))
@@ -169,9 +169,9 @@
* Fields are only defined for eUSB2v2 ports (HCC2_E2V2C = 1),
* otherwise the whole register is RsvdP.
*/
-/* bits 3:0 - Rx Data Rate (RDR) */
+/* bits 3:0 - Rx Data Rate */
#define PORT_RDR_MASK GENMASK(3, 0)
-/* bits 7:4 - Tx Data Rate (TDR) */
+/* bits 7:4 - Tx Data Rate */
#define PORT_TDR_MASK GENMASK(7, 4)
/* bits 31:8 - RsvdP */
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 8117e7fe8da2..0b4d41933f16 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2128,9 +2128,9 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
* Tag broken links to avoid retries while hub driver sorts it out.
* Link status is not relible while port is in reset.
*/
- if (!(portsc & PORT_RESET)) {
+ if (!(portsc & PORT_PR)) {
port->link_inactive = (pls == PLS_INACTIVE);
- port->connected = !!(portsc & PORT_CONNECT);
+ port->connected = !!(portsc & PORT_CCS);
}
pls = FIELD_GET(PORT_PLS_MASK, portsc);
@@ -2213,7 +2213,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
if (hcd->speed < HCD_USB3) {
xhci_test_and_clear_bit(xhci, port, PORT_PLC);
if ((xhci->quirks & XHCI_RESET_PLL_ON_DISCONNECT) &&
- (portsc & PORT_CSC) && !(portsc & PORT_CONNECT))
+ (portsc & PORT_CSC) && !(portsc & PORT_CCS))
xhci_cavium_reset_phy_quirk(xhci);
}
diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c
index 275d29b50ebd..f25d8e9eb7f5 100644
--- a/drivers/usb/host/xhci-tegra.c
+++ b/drivers/usb/host/xhci-tegra.c
@@ -2033,7 +2033,7 @@ static bool xhci_hub_ports_suspended(struct xhci_hub *hub)
for (i = 0; i < hub->num_ports; i++) {
value = xhci_portsc_readl(hub->ports[i]);
- if ((value & PORT_PE) == 0)
+ if ((value & PORT_PED) == 0)
continue;
if (FIELD_GET(PORT_PLS_MASK, value) != PLS_U3) {
@@ -2854,7 +2854,7 @@ static int tegra_xhci_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value,
return -EPIPE;
ports = rhub->ports;
portsc = xhci_portsc_readl(ports[port]);
- if (portsc & PORT_CONNECT)
+ if (portsc & PORT_CCS)
tegra_phy_xusb_utmi_pad_power_on(phy);
}
}
@@ -2873,7 +2873,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 = xhci_portsc_readl(ports[port]);
- if (!(portsc & PORT_CONNECT)) {
+ if (!(portsc & PORT_CCS)) {
/* 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 5837ec9fb495..20751f9696b5 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -31,7 +31,7 @@
#define DRIVER_AUTHOR "Sarah Sharp"
#define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver"
-#define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E)
+#define PORT_WAKE_BITS (PORT_WOE | PORT_WDE | PORT_WCE)
/* Some 0.95 hardware can't handle the chain bit on a Link TRB being cleared */
static int link_quirk;
@@ -896,7 +896,7 @@ static void xhci_disable_hub_port_wake(struct xhci_hcd *xhci,
t2 &= ~PORT_WAKE_BITS;
/* Don't touch csc bit if connected or connect change is set */
- if (!(portsc & (PORT_CSC | PORT_CONNECT)))
+ if (!(portsc & (PORT_CSC | PORT_CCS)))
t2 |= PORT_CSC;
if (t1 != t2) {
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 18af4285a688..8db2a1bfc31b 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -2425,37 +2425,37 @@ static inline const char *xhci_decode_portsc(char *str, u32 portsc)
ret += sprintf(str + ret, "Link=%s ", xhci_portsc_link_state_string(portsc));
/* RO/ROS: Read-only */
- if (portsc & PORT_CONNECT)
+ if (portsc & PORT_CCS)
ret += sprintf(str + ret, "CCS ");
- if (portsc & PORT_OC)
+ if (portsc & PORT_OCA)
ret += sprintf(str + ret, "OCA "); /* No set for USB2 ports */
if (portsc & PORT_CAS)
ret += sprintf(str + ret, "CAS ");
- if (portsc & PORT_DEV_REMOVE)
+ if (portsc & PORT_DR)
ret += sprintf(str + ret, "DR ");
/* RWS; writing 1 sets the bit, writing 0 clears the bit. */
- if (portsc & PORT_POWER)
+ if (portsc & PORT_PP)
ret += sprintf(str + ret, "PP ");
- if (portsc & PORT_WKCONN_E)
+ if (portsc & PORT_WCE)
ret += sprintf(str + ret, "WCE ");
- if (portsc & PORT_WKDISC_E)
+ if (portsc & PORT_WDE)
ret += sprintf(str + ret, "WDE ");
- if (portsc & PORT_WKOC_E)
+ if (portsc & PORT_WOE)
ret += sprintf(str + ret, "WOE ");
/* RW; writing 1 sets the bit, writing 0 clears the bit */
- if (portsc & PORT_LINK_STROBE)
+ if (portsc & PORT_LWS)
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)
+ if (portsc & PORT_PR)
ret += sprintf(str + ret, "PR ");
- if (portsc & PORT_WR)
+ if (portsc & PORT_WPR)
ret += sprintf(str + ret, "WPR "); /* RsvdZ for USB2 ports */
/* RW1CS; writing 1 clears the bit, writing 0 has no effect. */
- if (portsc & PORT_PE)
+ if (portsc & PORT_PED)
ret += sprintf(str + ret, "PED ");
if (portsc & PORT_CSC)
ret += sprintf(str + ret, "CSC ");
@@ -2465,7 +2465,7 @@ static inline const char *xhci_decode_portsc(char *str, u32 portsc)
ret += sprintf(str + ret, "WRC "); /* RsvdZ for USB2 ports */
if (portsc & PORT_OCC)
ret += sprintf(str + ret, "OCC ");
- if (portsc & PORT_RC)
+ if (portsc & PORT_PRC)
ret += sprintf(str + ret, "PRC ");
if (portsc & PORT_PLC)
ret += sprintf(str + ret, "PLC ");
--
2.50.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v3 05/12] usb: xhci: rework USB3 PORTPMSC macros
2026-12-03 14:42 ` [PATCH v3 05/12] usb: xhci: rework USB3 PORTPMSC macros Niklas Neronin
@ 2026-12-03 14:50 ` sashiko-bot
0 siblings, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-12-03 14:50 UTC (permalink / raw)
To: Niklas Neronin; +Cc: linux-usb
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: xhci: PORTPMSC comments omit reserved values claimed in
commit message
--
commit 566b043ef88e37f2c0ec0cdfe002e8e9bd68833e
Author: Niklas Neronin <niklas.neronin@linux.intel.com>
usb: xhci: rework USB3 PORTPMSC macros
This commit replaces PORT_U1_TIMEOUT() and PORT_U2_TIMEOUT() with
GENMASK() masks and FIELD_MODIFY(), and updates the USB3 PORTPMSC
register comments in xhci-port.h.
> - document the valid, reserved and infinite U1/U2 Timeout values
[ ... ]
> diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
> index 40e403a46b20e..fc87d4cacfbe5 100644
> --- a/drivers/usb/host/xhci-port.h
> +++ b/drivers/usb/host/xhci-port.h
> @@ -116,16 +116,19 @@
> /* We mark duplicate entries with -1 */
> #define DUPLICATE_ENTRY ((u8)(-1))
>
> -/* Port Power Management Status and Control - port_power_base bitmasks */
> -/* Inactivity timer value for transitions into U1, in microseconds.
> - * Timeout can be up to 127us. 0xFF means an infinite timeout.
> +/* USB3 Port Power Management Status and Control (PORTPMSC) 5.4.9.1 */
> +/*
> + * bits 7:0 - U1 Timeout, inactivity timer value for transitions into U1.
> + * Timeout can be 0 to 127us, in 1us increments and 0xff is infinite timeout.
> + */
> +#define PORT_U1_TIMEOUT_MASK GENMASK(7, 0)
> +/*
> + * bits 15:8 - U2 Timeout, inactivity timer value for transitions into U2.
> + * Timeout can be 0 to 65024us, in 256us increments and 0xff is infinite timeout.
> */
> -#define PORT_U1_TIMEOUT(p) ((p) & 0xff)
> -#define PORT_U1_TIMEOUT_MASK 0xff
> -/* Inactivity timer value for transitions into U2 */
> -#define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8)
> -#define PORT_U2_TIMEOUT_MASK (0xff << 8)
> -/* Bits 24:31 for port testing */
> +#define PORT_U2_TIMEOUT_MASK GENMASK(15, 8)
[Severity: Low]
The commit message says the comments document the reserved U1/U2 Timeout
values, but neither comment mentions reserved values. In xHCI 5.4.9.1,
values 0x80 to 0xfe are reserved for U1 Timeout, while U2 Timeout has no
reserved encodings since 0x00 through 0xfe cover 0 to 65024us.
Should the U1 Timeout comment note that 0x80 to 0xfe are reserved, or
should the commit message be updated to match the comments?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203144244.1680587-1-niklas.neronin@linux.intel.com?part=5
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 12/12] usb: xhci: rename PORTSC field macros to xHCI spec abbreviations
2026-12-03 14:42 ` [PATCH v3 12/12] usb: xhci: rename PORTSC field macros to xHCI spec abbreviations Niklas Neronin
@ 2026-12-03 14:54 ` sashiko-bot
0 siblings, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-12-03 14:54 UTC (permalink / raw)
To: Niklas Neronin; +Cc: linux-usb
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: xhci: leftover (HIRDM) and (BESLD) comment suffixes in
xhci-port.h
--
commit ede0c330cbe2f7e6299b961bb18175f88934c294
Author: Niklas Neronin <niklas.neronin@linux.intel.com>
usb: xhci: rename PORTSC field macros to xHCI spec abbreviations
This commit renames the remaining driver-specific PORTSC field macros in
xhci-port.h and their users to their xHCI specification abbreviations,
and drops the now-redundant abbreviation suffixes from bitfield comments.
> diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
> index 3cb28394be3fd..46975524a7fea 100644
> --- a/drivers/usb/host/xhci-port.h
> +++ b/drivers/usb/host/xhci-port.h
[ ... ]
> @@ -169,9 +169,9 @@
> * Fields are only defined for eUSB2v2 ports (HCC2_E2V2C = 1),
> * otherwise the whole register is RsvdP.
> */
> -/* bits 3:0 - Rx Data Rate (RDR) */
> +/* bits 3:0 - Rx Data Rate */
> #define PORT_RDR_MASK GENMASK(3, 0)
> -/* bits 7:4 - Tx Data Rate (TDR) */
> +/* bits 7:4 - Tx Data Rate */
> #define PORT_TDR_MASK GENMASK(7, 4)
> /* bits 31:8 - RsvdP */
[Severity: Low]
Should the (HIRDM) and (BESLD) suffixes on the PORT_HIRDM_MASK and
PORT_BESLD_MASK comments right below in the USB2 PORTHLPMC section also
be dropped? Their macro names already use those spec abbreviations, so
keeping them leaves the comment cleanup stated in the commit message
incomplete.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203144244.1680587-1-niklas.neronin@linux.intel.com?part=12
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 03/12] usb: xhci: rework Port Link State macros
2026-12-03 14:42 ` [PATCH v3 03/12] usb: xhci: rework Port Link State macros Niklas Neronin
@ 2026-12-03 14:59 ` sashiko-bot
0 siblings, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-12-03 14:59 UTC (permalink / raw)
To: Niklas Neronin; +Cc: linux-usb
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: xhci: redundant FIELD_GET(PORT_PLS_MASK) calls in
handle_port_status()
--
commit ee9d70e142f86a51d9ccfe785b68150e454c910c
Author: Niklas Neronin <niklas.neronin@linux.intel.com>
usb: xhci: rework Port Link State macros
This commit replaces the pre-shifted XDEV_* Port Link State macros with
unshifted PLS_* values defined against GENMASK(8, 5), and updates callers
to use FIELD_GET() and FIELD_MODIFY().
> diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
> index 676f71d8305b1..8117e7fe8da2f 100644
> --- a/drivers/usb/host/xhci-ring.c
> +++ b/drivers/usb/host/xhci-ring.c
> @@ -2112,7 +2112,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
> bus_state = &port->rhub->bus_state;
> hcd_portnum = port->hcd_portnum;
> portsc = xhci_portsc_readl(port);
> - pls = portsc & PORT_PLS_MASK;
> + pls = FIELD_GET(PORT_PLS_MASK, portsc);
>
> xhci_dbg(xhci, "Port change event, %d-%d, id %d, portsc: 0x%x\n",
> hcd->self.busnum, hcd_portnum + 1, port_id, portsc);
> @@ -2129,11 +2129,12 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
> * Link status is not relible while port is in reset.
> */
> if (!(portsc & PORT_RESET)) {
> - port->link_inactive = (pls == XDEV_INACTIVE);
> + port->link_inactive = (pls == PLS_INACTIVE);
> port->connected = !!(portsc & PORT_CONNECT);
> }
>
> - if ((portsc & PORT_PLC) && (portsc & PORT_PLS_MASK) == XDEV_RESUME) {
> + pls = FIELD_GET(PORT_PLS_MASK, portsc);
> + if ((portsc & PORT_PLC) && pls == PLS_RESUME) {
> xhci_dbg(xhci, "port resume event for port %d\n", port_id);
>
> cmd_reg = readl(&xhci->op_regs->command);
[ ... ]
> @@ -2174,11 +2175,9 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
> }
> }
>
> - if ((portsc & PORT_PLC) &&
> - FIELD_GET(PORT_SPEED_MASK, portsc) >= PORT_SPEED_SS &&
> - ((portsc & PORT_PLS_MASK) == XDEV_U0 ||
> - (portsc & PORT_PLS_MASK) == XDEV_U1 ||
> - (portsc & PORT_PLS_MASK) == XDEV_U2)) {
> + pls = FIELD_GET(PORT_PLS_MASK, portsc);
> + if ((portsc & PORT_PLC) && pls <= PLS_U2 &&
> + FIELD_GET(PORT_SPEED_MASK, portsc) >= PORT_SPEED_SS) {
[Severity: Low]
Are these two extra pls = FIELD_GET(PORT_PLS_MASK, portsc) assignments
needed? handle_port_status() already extracts pls right after reading
portsc, and neither portsc nor pls is modified afterwards, so repeating
the extraction can mislead readers into thinking portsc was re-read from
hardware.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203144244.1680587-1-niklas.neronin@linux.intel.com?part=3
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 00/12] usb: xhci: rework xHCI Port macros
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
` (11 preceding siblings ...)
2026-12-03 14:42 ` [PATCH v3 12/12] usb: xhci: rename PORTSC field macros to xHCI spec abbreviations Niklas Neronin
@ 2026-12-03 14:59 ` sashiko-bot
12 siblings, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-12-03 14:59 UTC (permalink / raw)
To: Niklas Neronin; +Cc: linux-usb
Sashiko has finished reviewing this 12-patch series:
- Patches 1, 2, 4, and 6-11: no issues found.
- Patch 3 ("usb: xhci: rework Port Link State macros"): 1 potential
issue (1 Low)
- Patch 5 ("usb: xhci: rework USB3 PORTPMSC macros"): 1 potential issue
(1 Low)
- Patch 12 ("usb: xhci: rename PORTSC field macros to xHCI spec a..."):
1 potential issue (1 Low)
Detailed reviews have been sent as separate replies to patches 3, 5, and
12.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203144244.1680587-1-niklas.neronin@linux.intel.com
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2026-12-03 14:59 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 14:42 [PATCH v3 00/12] usb: xhci: rework xHCI Port macros Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 01/12] usb: xhci: use BIT() for single bit port register flags Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 02/12] usb: xhci: rework Port Speed macros Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 03/12] usb: xhci: rework Port Link State macros Niklas Neronin
2026-12-03 14:59 ` sashiko-bot
2026-12-03 14:42 ` [PATCH v3 04/12] usb: xhci: rework Port Indicator Control macro Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 05/12] usb: xhci: rework USB3 PORTPMSC macros Niklas Neronin
2026-12-03 14:50 ` sashiko-bot
2026-12-03 14:42 ` [PATCH v3 06/12] usb: xhci: rework USB2 " Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 07/12] usb: xhci: rework USB3 PORTLI macros Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 08/12] usb: xhci: rework USB2 " Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 09/12] usb: xhci: document USB3 PORTHLPMC register layout Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 10/12] usb: xhci: rework USB2 PORTHLPMC macros Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 11/12] usb: xhci: update port register bitfield comments for consistency Niklas Neronin
2026-12-03 14:42 ` [PATCH v3 12/12] usb: xhci: rename PORTSC field macros to xHCI spec abbreviations Niklas Neronin
2026-12-03 14:54 ` sashiko-bot
2026-12-03 14:59 ` [PATCH v3 00/12] usb: xhci: rework xHCI Port macros sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox