public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Mario Limonciello (AMD)" <superm1@kernel.org>
To: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: linux-usb@vger.kernel.org (open list:THUNDERBOLT DRIVER),
	linux-kernel@vger.kernel.org,
	Andreas Noever <andreas.noever@gmail.com>,
	Michael Jamet <michael.jamet@intel.com>,
	Yehezkel Bernat <YehezkelShB@gmail.com>,
	"Mario Limonciello (AMD)" <superm1@kernel.org>
Subject: [PATCH v2 2/2] thunderbolt: Reset NHI during S4 restore_noirq() callback
Date: Mon,  5 Jan 2026 23:37:49 -0600	[thread overview]
Message-ID: <20260106053749.61440-3-superm1@kernel.org> (raw)
In-Reply-To: <20260106053749.61440-1-superm1@kernel.org>

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@kernel.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


  parent reply	other threads:[~2026-01-06  5:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-06  5:37 [PATCH v2 0/2] thunderbolt: Fix S4 resume incongruities Mario Limonciello (AMD)
2026-01-06  5:37 ` [PATCH v2 1/2] thunderbolt: Move nhi_reset before pmops declaration Mario Limonciello (AMD)
2026-01-06  5:37 ` Mario Limonciello (AMD) [this message]
2026-01-07  9:33 ` [PATCH v2 0/2] thunderbolt: Fix S4 resume incongruities Mika Westerberg
2026-01-07 20:50   ` Mario Limonciello
2026-01-08 11:42     ` Mika Westerberg
2026-01-08 19:18       ` Mario Limonciello
2026-01-09  7:23         ` Mika Westerberg
2026-01-09 15:38           ` Mario Limonciello
2026-01-10  0:42           ` Katiyar, Pooja
2026-01-13 18:44             ` Mario Limonciello (AMD) (kernel.org)
2026-01-17 16:57               ` Katiyar, Pooja
2026-01-19 19:59                 ` Mario Limonciello (AMD) (kernel.org)
2026-01-19 22:13                   ` Kenneth Crudup
2026-01-29 23:13                     ` Katiyar, Pooja
2026-01-30  1:39                       ` Kenneth Crudup
2026-01-30  1:42                         ` Kenneth Crudup
2026-02-04  0:50                           ` Katiyar, Pooja

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=20260106053749.61440-3-superm1@kernel.org \
    --to=superm1@kernel.org \
    --cc=YehezkelShB@gmail.com \
    --cc=andreas.noever@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=michael.jamet@intel.com \
    --cc=mika.westerberg@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