Linux USB
 help / color / mirror / Atom feed
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 10/22] usb: xhci: rework USB2 PORTHLPMC macros
Date: Mon, 13 Jul 2026 12:47:24 +0200	[thread overview]
Message-ID: <20260713104738.629612-11-niklas.neronin@linux.intel.com> (raw)
In-Reply-To: <20260713104738.629612-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.

Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
 drivers/usb/host/xhci-port.h | 17 +++++++++++------
 drivers/usb/host/xhci.c      |  3 ++-
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h
index 1ec0ee01e552..3aa23e143521 100644
--- a/drivers/usb/host/xhci-port.h
+++ b/drivers/usb/host/xhci-port.h
@@ -172,13 +172,18 @@
 /* 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)
-
-/* use 512 microseconds as USB2 LPM L1 default timeout. */
+/* USB2 Port Hardware LPM Control Register (PORTHLPMC) 5.4.11.2 */
+/* bits 1:0 - Host Initiated Resume Duration Mode */
+#define PORT_HIRDM_MASK		GENMASK(1, 0)
+/*
+ * bits 9:2 - L1 Timeout, can be 128us to 65280us (0xff), in 128us increments.
+ * The default timeout is 128us.
+ */
+#define PORT_L1_TIMEOUT_MASK	GENMASK(9, 2)
 #define XHCI_L1_TIMEOUT		512
+/* bits 13:10 - Best Effort Service Latency Deep */
+#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 edfb2e0739f0..9ae4f6b3e5ec 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4654,7 +4654,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


  parent reply	other threads:[~2026-07-13 10:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13 10:47 [PATCH 00/22] usb: xhci: rework xHCI Port macros Niklas Neronin
2026-07-13 10:47 ` [PATCH 01/22] usb: xhci: replace bit shifts with the BIT() macro in xhci-port.h Niklas Neronin
2026-07-13 10:47 ` [PATCH 02/22] usb: xhci: rework Port Speed macros Niklas Neronin
2026-07-13 10:47 ` [PATCH 03/22] usb: xhci: rework Port Link State macros Niklas Neronin
2026-07-13 10:47 ` [PATCH 04/22] usb: xhci: rework Port Indicator Control macro Niklas Neronin
2026-07-13 10:47 ` [PATCH 05/22] usb: xhci: rework USB3 PORTPMSC macros Niklas Neronin
2026-07-13 10:47 ` [PATCH 06/22] usb: xhci: rework USB2 " Niklas Neronin
2026-07-13 10:47 ` [PATCH 07/22] usb: xhci: rework USB3 PORTLI macros Niklas Neronin
2026-07-13 10:47 ` [PATCH 08/22] usb: xhci: rework USB2 " Niklas Neronin
2026-07-13 10:47 ` [PATCH 09/22] usb: xhci: rework USB3 PORTHLPMC macros Niklas Neronin
2026-07-13 10:47 ` Niklas Neronin [this message]
2026-07-13 10:47 ` [PATCH 11/22] usb: xhci: update port register bitfield comments for consistency Niklas Neronin
2026-07-13 10:47 ` [PATCH 12/22] usb: xhci: rename port register macros to xHCI spec abbreviations Niklas Neronin
2026-07-13 10:47 ` [PATCH 13/22] usb: xhci: replace magic numbers with Port macros Niklas Neronin
2026-07-13 10:47 ` [PATCH 14/22] usb: xhci: update PORTSC aggregate macros Niklas Neronin
2026-07-13 10:47 ` [PATCH 15/22] usb: xhci: consolidate PORTSC RW1CS bit macros Niklas Neronin
2026-07-13 10:47 ` [PATCH 16/22] usb: xhci: relocate all port register macros to xhci-port.h Niklas Neronin
2026-07-13 10:47 ` [PATCH 17/22] usb: xhci: preserve RW bits in xhci_port_state_to_neutral() Niklas Neronin
2026-07-13 10:47 ` [PATCH 18/22] usb: xhci: improve xhci_port_missing_cas_quirk() Niklas Neronin
2026-07-13 10:47 ` [PATCH 19/22] usb: xhci: use neutral helper when resuming ports Niklas Neronin
2026-07-13 10:47 ` [PATCH 20/22] usb: xhci: remove redundant PORTSC ops in xhci_hub_control() Niklas Neronin
2026-07-13 10:47 ` [PATCH 21/22] usb: xhci: move struct 'xhci_port' specific macro Niklas Neronin
2026-07-13 10:47 ` [PATCH 22/22] usb: xhci: rename 'temp' PORTSC variables to 'portcs' Niklas Neronin

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=20260713104738.629612-11-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