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 06/12] usb: xhci: rework USB2 PORTPMSC macros
Date: Thu, 3 Dec 2026 15:42:38 +0100 [thread overview]
Message-ID: <20261203144244.1680587-7-niklas.neronin@linux.intel.com> (raw)
In-Reply-To: <20261203144244.1680587-1-niklas.neronin@linux.intel.com>
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
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 ` [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 ` Niklas Neronin [this message]
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-7-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox