[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260106053749.61440-3-superm1@kernel.org>
Date: Mon, 5 Jan 2026 23:37:49 -0600
From: "Mario Limonciello (AMD)" <superm1@...nel.org>
To: Mika Westerberg <mika.westerberg@...ux.intel.com>
Cc: linux-usb@...r.kernel.org (open list:THUNDERBOLT DRIVER),
linux-kernel@...r.kernel.org,
Andreas Noever <andreas.noever@...il.com>,
Michael Jamet <michael.jamet@...el.com>,
Yehezkel Bernat <YehezkelShB@...il.com>,
"Mario Limonciello (AMD)" <superm1@...nel.org>
Subject: [PATCH v2 2/2] thunderbolt: Reset NHI during S4 restore_noirq() callback
When a machine is restored from S4 if the firmware CM has created
tunnels there can be an incongruity of expectation from the kernel
when compared to booting from S5.
For example this incongruity can lead to problems like the display
not working properly if the firmware CM didn't turn it on pre-OS
but the OS had it on before entering S4.
Add an extra restore_noirq() callback to explicitly reset the NHI
before running the rest of the resume sequence. This will allow
the standard discovery and probing routines to run and create the
tunnels as expected.
Signed-off-by: Mario Limonciello (AMD) <superm1@...nel.org>
---
drivers/thunderbolt/nhi.c | 15 +++++++++++++--
drivers/thunderbolt/tb.c | 29 ++++++++++++++++-------------
drivers/thunderbolt/tb.h | 1 +
3 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
index ea2a5a06ee710..17cc4ddd9cc79 100644
--- a/drivers/thunderbolt/nhi.c
+++ b/drivers/thunderbolt/nhi.c
@@ -47,7 +47,7 @@
#define QUIRK_AUTO_CLEAR_INT BIT(0)
#define QUIRK_E2E BIT(1)
-static bool host_reset = true;
+bool host_reset = true;
module_param(host_reset, bool, 0444);
MODULE_PARM_DESC(host_reset, "reset USB4 host router (default: true)");
@@ -1108,6 +1108,17 @@ static int nhi_resume_noirq(struct device *dev)
return tb_domain_resume_noirq(tb);
}
+static int nhi_restore_noirq(struct device *dev)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+ struct tb *tb = pci_get_drvdata(pdev);
+ struct tb_nhi *nhi = tb->nhi;
+
+ nhi_reset(nhi);
+
+ return nhi_resume_noirq(dev);
+}
+
static int nhi_suspend(struct device *dev)
{
struct pci_dev *pdev = to_pci_dev(dev);
@@ -1449,7 +1460,7 @@ static const struct dev_pm_ops nhi_pm_ops = {
* pci-tunnels stay alive.
*/
.thaw_noirq = nhi_thaw_noirq,
- .restore_noirq = nhi_resume_noirq,
+ .restore_noirq = nhi_restore_noirq,
.suspend = nhi_suspend,
.poweroff_noirq = nhi_poweroff_noirq,
.poweroff = nhi_suspend,
diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 4f5f1dfc0fbf1..bc6ca313dd9f3 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -3115,7 +3115,6 @@ static int tb_resume_noirq(struct tb *tb)
struct tb_cm *tcm = tb_priv(tb);
struct tb_tunnel *tunnel, *n;
unsigned int usb3_delay = 0;
- LIST_HEAD(tunnels);
tb_dbg(tb, "resuming...\n");
@@ -3131,18 +3130,22 @@ static int tb_resume_noirq(struct tb *tb)
tb_free_unplugged_children(tb->root_switch);
tb_restore_children(tb->root_switch);
- /*
- * If we get here from suspend to disk the boot firmware or the
- * restore kernel might have created tunnels of its own. Since
- * we cannot be sure they are usable for us we find and tear
- * them down.
- */
- tb_switch_discover_tunnels(tb->root_switch, &tunnels, false);
- list_for_each_entry_safe_reverse(tunnel, n, &tunnels, list) {
- if (tb_tunnel_is_usb3(tunnel))
- usb3_delay = 500;
- tb_tunnel_deactivate(tunnel);
- tb_tunnel_put(tunnel);
+ if (!host_reset) {
+ /*
+ * If we get here from suspend to disk the boot firmware or the
+ * restore kernel might have created tunnels of its own. Since
+ * we cannot be sure they are usable for us we find and tear
+ * them down.
+ */
+ LIST_HEAD(tunnels);
+
+ tb_switch_discover_tunnels(tb->root_switch, &tunnels, false);
+ list_for_each_entry_safe_reverse(tunnel, n, &tunnels, list) {
+ if (tb_tunnel_is_usb3(tunnel))
+ usb3_delay = 500;
+ tb_tunnel_deactivate(tunnel);
+ tb_tunnel_put(tunnel);
+ }
}
/* Re-create our tunnels now */
diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
index e96474f17067a..050d92f82b12f 100644
--- a/drivers/thunderbolt/tb.h
+++ b/drivers/thunderbolt/tb.h
@@ -763,6 +763,7 @@ extern const struct device_type tb_domain_type;
extern const struct device_type tb_retimer_type;
extern const struct device_type tb_switch_type;
extern const struct device_type usb4_port_device_type;
+extern bool host_reset;
int tb_domain_init(void);
void tb_domain_exit(void);
--
2.43.0
Powered by blists - more mailing lists