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 20/22] usb: xhci: remove redundant PORTSC ops in xhci_hub_control()
Date: Mon, 13 Jul 2026 12:47:34 +0200 [thread overview]
Message-ID: <20260713104738.629612-21-niklas.neronin@linux.intel.com> (raw)
In-Reply-To: <20260713104738.629612-1-niklas.neronin@linux.intel.com>
xhci_hub_control() performs multiple redundant calls to xhci_portsc_readl()
and xhci_port_state_to_neutral().
Rework xhci_hub_control() to read PORTSC once, and again only after
it has been written back. Also move calls to xhci_port_state_to_neutral()
closer to the corresponding write sites.
This reduces duplicate operations and makes it clearer when the local
'portsc' value is in a neutral (write-safe) state.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-hub.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 06192ae95526..dbf1183a6813 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1238,23 +1238,21 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
retval = -ENODEV;
break;
}
- portsc = xhci_port_state_to_neutral(portsc);
/* FIXME: What new port features do we need to support? */
switch (wValue) {
case USB_PORT_FEAT_SUSPEND:
- portsc = xhci_portsc_readl(port);
if (FIELD_GET(PORT_PLS_MASK, portsc) != PLS_U0) {
/* Resume the port to U0 first */
xhci_set_link_state(xhci, port, PLS_U0);
spin_unlock_irqrestore(&xhci->lock, flags);
msleep(10);
spin_lock_irqsave(&xhci->lock, flags);
+ portsc = xhci_portsc_readl(port);
}
/* In spec software should not attempt to suspend
* a port unless the port reports that it is in the
* enabled (PED = ‘1’,PLS < ‘3’) state.
*/
- portsc = xhci_portsc_readl(port);
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",
@@ -1282,7 +1280,6 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
break;
case USB_PORT_FEAT_LINK_STATE:
link_state = (wIndex & 0xff00) >> 3;
- portsc = xhci_portsc_readl(port);
/* Disable port */
if (link_state == USB_SS_PORT_LS_SS_DISABLED) {
xhci_dbg(xhci, "Disable port %d-%d\n",
@@ -1334,8 +1331,8 @@ 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, PLS_COMP_MODE);
+ xhci_set_link_state(xhci, port, PLS_COMP_MODE);
portsc = xhci_portsc_readl(port);
break;
}
@@ -1407,7 +1404,6 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
break;
}
spin_lock_irqsave(&xhci->lock, flags);
- portsc = xhci_portsc_readl(port);
bus_state->suspended_ports |= 1 << portnum;
}
break;
@@ -1421,6 +1417,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 = xhci_port_state_to_neutral(portsc);
portsc |= PORT_PR;
xhci_portsc_writel(port, portsc);
@@ -1436,6 +1433,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 = xhci_port_state_to_neutral(portsc);
portsc |= PORT_WPR;
xhci_portsc_writel(port, portsc);
portsc = xhci_portsc_readl(port);
@@ -1472,8 +1470,6 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
default:
goto error;
}
- /* unblock any posted writes */
- portsc = xhci_portsc_readl(port);
break;
case ClearPortFeature:
portnum = (wIndex & 0xff) - 1;
@@ -1488,10 +1484,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
break;
}
/* FIXME: What new port features do we need to support? */
- portsc = xhci_port_state_to_neutral(portsc);
switch (wValue) {
case USB_PORT_FEAT_SUSPEND:
- portsc = xhci_portsc_readl(port);
xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n");
xhci_dbg(xhci, "PORTSC %04x\n", portsc);
if (portsc & PORT_PR)
@@ -1528,6 +1522,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
case USB_PORT_FEAT_C_ENABLE:
case USB_PORT_FEAT_C_PORT_LINK_STATE:
case USB_PORT_FEAT_C_PORT_CONFIG_ERROR:
+ portsc = xhci_port_state_to_neutral(portsc);
xhci_clear_port_change_bit(xhci, wValue, port, portsc);
break;
case USB_PORT_FEAT_ENABLE:
--
2.50.1
next prev parent reply other threads:[~2026-07-13 10:49 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 ` [PATCH 10/22] usb: xhci: rework USB2 " Niklas Neronin
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 ` Niklas Neronin [this message]
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-21-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