From: Niklas Neronin <niklas.neronin@linux.intel.com>
To: mathias.nyman@linux.intel.com
Cc: linux-usb@vger.kernel.org,
Niklas Neronin <niklas.neronin@linux.intel.com>
Subject: [PATCH v3 03/12] usb: xhci: rework Port Link State macros
Date: Thu, 3 Dec 2026 15:42:35 +0100 [thread overview]
Message-ID: <20261203144244.1680587-4-niklas.neronin@linux.intel.com> (raw)
In-Reply-To: <20261203144244.1680587-1-niklas.neronin@linux.intel.com>
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
next prev parent reply other threads:[~2026-12-03 14:43 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-12-03 14:59 ` [PATCH v3 03/12] usb: xhci: rework Port Link State macros 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203144244.1680587-4-niklas.neronin@linux.intel.com \
--to=niklas.neronin@linux.intel.com \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.