Skip to contentSkip to conversation

thunderbolt: Add support platform NHI driver

PATCH New Chunfeng Yun 5 participants 35 messages Nov 10 – Nov 20

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover thunderbolt: Add support platform NHI driver

Historically, the USB4 / Thunderbolt subsystem has had a hard dependency on PCI, bundling the core framework, the PCIe-attached Native Host Interface (NHI) driver (pci.c), and the Intel Connection Manager (icm.c) into a single module (thunderbolt.ko).

Modern ARM64 SoCs (such as MediaTek MT8901 / MT8992) integrate the USB4 host router / NHI directly as an MMIO platform device rather than sitting on an external PCIe bus. Furthermore, embedded and SoC-based platforms often do not include PCIe-attached host routers or require Intel ICM support, making a mandatory PCI dependency and bundled PCIe code undesirable.

This series decouples PCIe NHI and Intel ICM support from the Thunderbolt core framework, introduces a generic platform NHI driver supporting DT and ACPI bindings, and addresses link training timing and race condition issues observed during suspend/resume and authorization.

Overview of Changes
===================

1. Modularization & Namespace Cleanups (Patches 1-3)
- Patches 1 & 2 clean up internal interfaces before exporting. Core NHI functions are prefixed with standard tb_/tb_ring_ namespace prefixes. Intel ICM mailbox helpers (nhi_mailbox_cmd/mode) are moved into icm.c and made static, and interrupt work initialization is internalized in tb_nhi_probe().
- Patch 3 drops the hard "depends on PCI" from CONFIG_USB4, introduces CONFIG_USB4_PCI to build PCIe NHI and ICM as an opt-in module (thunderbolt_pci.ko), and adds a .select_cm() hook in tb_nhi_ops to allow connection manager selection without core hardcoding.

2. Platform NHI Driver (Patch 4)
- Introduces CONFIG_USB4_PLATFORM (thunderbolt_platform.ko), adding support for memory-mapped USB4 NHIs via Device Tree ("usb4-nhi-platform") and ACPI ("ACPI0015").
- Implements platform-specific tb_nhi_ops hooks and runtime PM.
- Adds support for an optional dedicated wakeup interrupt from an always-on power domain, necessary for SoCs where the primary NHI MAC/PHY power domain is gated during suspend.

3. Link Training and Disconnect Improvements (Patches 5-6)
- Patch 5 increases the port link training timeout in tb_wait_for_port() from 1s to 2s. According to the USB4 specification, Phase 5 (Link Equalization) alone may take up to 1000 ms. When combined with Phases 2-4 (~200 ms) and retimer command transaction delays across dual-retimer topologies, physical link establishment can legitimately exceed 1.2s–1.5s, which previously led to spurious disconnects during wakeups.
- Patch 6 decouples the TB_PORT_UNPLUGGED wait time from the overall 2s link-up timeout. Under normal link training, the port enters TB_PORT_CONNECTING within ~200 ms. Capping TB_PORT_UNPLUGGED retries to 400 ms allows genuine device disconnect wakeups to be handled promptly without waiting the full 2s.

4. Prevent Authorization/Teardown Race Warnings (Patch 7)
- Prevents WARNING splats in tb_path_activate() and tb_disconnect_pci() when sysfs 'authorized' is modified while a downstream router is lost or unplugged during suspend/resume. Checking sw->is_unplugged avoids redundant lookups and activation attempts on already-freed tunnels.

Testing
=======
This series has been tested on MediaTek ARM64 SoC platforms with an integrated platform USB4 NHI, verifying:
- Cold boot, device discovery, and tunnel allocation (PCIe, USB3).
- System/runtime Suspend and wake-on-connect/disconnect/remote wakeup.
- Concurrent sysfs authorization changes during disconnect events.
- Verification of modular builds with CONFIG_USB4_PCI=m and CONFIG_USB4_PLATFORM=m.

Chunfeng Yun (6):
thunderbolt: Prefix NHI core functions with tb_ and tb_ring_
thunderbolt: Move ICM mailbox functions to icm.c and internalize
interrupt work
thunderbolt: add platform NHI driver
thunderbolt: increase the lane adapter link-up timeout value
thunderbolt: decouple the waiting time of TB_PORT_UNPLUGGED and
TB_PORT_UP
thunderbolt: prevent pcie tunnel activation/teardown warnings

Konrad Dybcio (1):
thunderbolt: Make PCIe NHI support opt-in

 drivers/thunderbolt/Kconfig    |  20 +++-
 drivers/thunderbolt/Makefile   |  10 +-
 drivers/thunderbolt/ctl.c      |   6 +-
 drivers/thunderbolt/domain.c   |  14 ++-
 drivers/thunderbolt/icm.c      |  59 +++++++++++
 drivers/thunderbolt/nhi.c      |  92 ++++--------------
 drivers/thunderbolt/nhi.h      |  16 ++-
 drivers/thunderbolt/pci.c      |  50 ++++------
 drivers/thunderbolt/platform.c | 172 +++++++++++++++++++++++++++++++++
 drivers/thunderbolt/switch.c   |  26 ++++-
 drivers/thunderbolt/tb.c       |   7 ++
 drivers/thunderbolt/tb.h       |   2 -
 drivers/thunderbolt/tunnel.c   |   1 +
 drivers/thunderbolt/xdomain.c  |   5 +
 include/linux/thunderbolt.h    |   4 +
 15 files changed, 356 insertions(+), 128 deletions(-)
 create mode 100644 drivers/thunderbolt/platform.c
Signature · 1 line
2.45.2
#1 lore raw

PATCH v2 1/7 thunderbolt: Prefix NHI core functions with tb_ and tb_ring_

In preparation for modularizing PCIe NHI support and allowing PCIe and platform NHI drivers to be built as separate modules atop the Thunderbolt core framework, several NHI functions and structures will need to be exported.

Currently, several of these functions lack standard subsystem prefixes, risking namespace pollution or collisions across the flat kernel symbol namespace:

- ring_msix() lacks any subsystem prefix and diverges from all other exported ring functions in the driver, which use the "tb_ring_" prefix.
- nhi_probe(), nhi_shutdown(), and nhi_pm_ops lack the standard "tb_" prefix used across the Thunderbolt public interface (such as struct tb_nhi and struct tb_nhi_ops).
- nhi_msi() is named after PCI MSI, even though the ISR simply schedules the interrupt work and can serve as a generic ISR for non-PCIe platform controllers as well.

Rename these functions and symbols to conform to Thunderbolt subsystem naming conventions before exporting them:

- ring_msix       -> tb_ring_msix
- nhi_msi         -> tb_nhi_isr
- nhi_probe       -> tb_nhi_probe
- nhi_shutdown    -> tb_nhi_shutdown
- nhi_pm_ops      -> tb_nhi_pm_ops

---
new patch

---
 drivers/thunderbolt/nhi.c | 14 +++++++-------
 drivers/thunderbolt/nhi.h | 10 +++++-----
 drivers/thunderbolt/pci.c | 10 +++++-----
 3 files changed, 17 insertions(+), 17 deletions(-)
drivers/thunderbolt/nhi.c +7 -7
index e99a3fcc4a29..c574c336f25b 100644
@@ -535,7 +535,7 @@ static void ring_clear_msix(const struct tb_ring *ring)
 			  4 * (ring->nhi->hop_count / 32));
 }
 
-irqreturn_t ring_msix(int irq, void *data)
+irqreturn_t tb_ring_msix(int irq, void *data)
 {
 	struct tb_ring *ring = data;
 
@@ -935,7 +935,7 @@ void tb_ring_free(struct tb_ring *ring)
 
 	/*
 	 * ring->work can no longer be scheduled (it is scheduled only
-	 * by nhi_interrupt_work, ring_stop and ring_msix). Wait for it
+	 * by nhi_interrupt_work, ring_stop and tb_ring_msix). Wait for it
 	 * to finish before freeing the ring.
 	 */
 	flush_work(&ring->work);
@@ -1072,7 +1072,7 @@ void nhi_interrupt_work(struct work_struct *work)
 	spin_unlock_irq(&nhi->lock);
 }
 
-irqreturn_t nhi_msi(int irq, void *data)
+irqreturn_t tb_nhi_isr(int irq, void *data)
 {
 	struct tb_nhi *nhi = data;
 	schedule_work(&nhi->interrupt_work);
@@ -1216,7 +1216,7 @@ static int nhi_runtime_resume(struct device *dev)
 	return tb_domain_runtime_resume(tb);
 }
 
-void nhi_shutdown(struct tb_nhi *nhi)
+void tb_nhi_shutdown(struct tb_nhi *nhi)
 {
 	int i;
 
@@ -1306,7 +1306,7 @@ static struct tb *nhi_select_cm(struct tb_nhi *nhi)
 	return tb;
 }
 
-int nhi_probe(struct tb_nhi *nhi)
+int tb_nhi_probe(struct tb_nhi *nhi)
 {
 	struct device *dev = nhi->dev;
 	struct tb *tb;
@@ -1371,7 +1371,7 @@ int nhi_probe(struct tb_nhi *nhi)
 		 */
 		tb_domain_put(tb);
 		wait_for_completion(&nhi->domain_released);
-		nhi_shutdown(nhi);
+		tb_nhi_shutdown(nhi);
 		return dev_err_probe(dev, res, "failed to add domain\n");
 	}
 	dev_set_drvdata(dev, tb);
@@ -1391,7 +1391,7 @@ int nhi_probe(struct tb_nhi *nhi)
  * the tunnels asap. A corresponding pci quirk blocks the downstream bridges
  * resume_noirq until we are done.
  */
-const struct dev_pm_ops nhi_pm_ops = {
+const struct dev_pm_ops tb_nhi_pm_ops = {
 	.suspend_noirq = nhi_suspend_noirq,
 	.resume_noirq = nhi_resume_noirq,
 	.freeze_noirq = nhi_freeze_noirq,  /*
drivers/thunderbolt/nhi.h +5 -5
index 88af9ab9fde7..a36c62c49a5c 100644
@@ -32,11 +32,11 @@ enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi);
 void nhi_enable_int_throttling(struct tb_nhi *nhi);
 void nhi_disable_interrupts(struct tb_nhi *nhi);
 void nhi_interrupt_work(struct work_struct *work);
-irqreturn_t nhi_msi(int irq, void *data);
-irqreturn_t ring_msix(int irq, void *data);
-int nhi_probe(struct tb_nhi *nhi);
-void nhi_shutdown(struct tb_nhi *nhi);
-extern const struct dev_pm_ops nhi_pm_ops;
+irqreturn_t tb_nhi_isr(int irq, void *data);
+irqreturn_t tb_ring_msix(int irq, void *data);
+int tb_nhi_probe(struct tb_nhi *nhi);
+void tb_nhi_shutdown(struct tb_nhi *nhi);
+extern const struct dev_pm_ops tb_nhi_pm_ops;
 
 /**
  * struct tb_nhi_ops - NHI specific optional operations
drivers/thunderbolt/pci.c +5 -5
index 4408229d8ac7..2f0abf4d27a3 100644
@@ -212,7 +212,7 @@ static int nhi_pci_init_msi(struct tb_nhi *nhi)
 		if (irq < 0)
 			return irq;
 
-		res = devm_request_irq(&pdev->dev, irq, nhi_msi,
+		res = devm_request_irq(&pdev->dev, irq, tb_nhi_isr,
 				       IRQF_NO_SUSPEND, "thunderbolt", nhi);
 		if (res)
 			return res;
@@ -281,7 +281,7 @@ static int nhi_pci_ring_request_msix(struct tb_ring *ring, bool no_suspend)
 	ring->irq = ret;
 
 	irqflags = no_suspend ? IRQF_NO_SUSPEND : 0;
-	ret = request_irq(ring->irq, ring_msix, irqflags, "thunderbolt", ring);
+	ret = request_irq(ring->irq, tb_ring_msix, irqflags, "thunderbolt", ring);
 	if (ret)
 		goto err_ida_remove;
 
@@ -588,7 +588,7 @@ static int nhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	pci_set_master(pdev);
 
-	return nhi_probe(&nhi_pci->nhi);
+	return tb_nhi_probe(&nhi_pci->nhi);
 }
 
 static void nhi_pci_do_remove(struct pci_dev *pdev, bool reset)
@@ -610,7 +610,7 @@ static void nhi_pci_do_remove(struct pci_dev *pdev, bool reset)
 
 	tb_domain_remove(tb);
 	wait_for_completion(&nhi->domain_released);
-	nhi_shutdown(nhi);
+	tb_nhi_shutdown(nhi);
 }
 
 static void nhi_pci_remove(struct pci_dev *pdev)
@@ -724,7 +724,7 @@ static struct pci_driver nhi_driver = {
 	.probe = nhi_pci_probe,
 	.remove = nhi_pci_remove,
 	.shutdown = nhi_pci_shutdown,
-	.driver.pm = &nhi_pm_ops,
+	.driver.pm = &tb_nhi_pm_ops,
 };
 
 static int __init nhi_init(void)
Signature · 1 line
2.45.2
#2 lore raw

Re: [PATCH v2 1/7] thunderbolt: Prefix NHI core functions with tb_ and tb_ring_

Sashiko has reviewed this patch and found no issues.
Quoted 21 lines

In preparation for modularizing PCIe NHI support and allowing PCIe and platform NHI drivers to be built as separate modules atop the Thunderbolt core framework, several NHI functions and structures will need to be exported.

Currently, several of these functions lack standard subsystem prefixes, risking namespace pollution or collisions across the flat kernel symbol namespace:

- ring_msix() lacks any subsystem prefix and diverges from all other exported ring functions in the driver, which use the "tb_ring_" prefix.
- nhi_probe(), nhi_shutdown(), and nhi_pm_ops lack the standard "tb_" prefix used across the Thunderbolt public interface (such as struct tb_nhi and struct tb_nhi_ops).
- nhi_msi() is named after PCI MSI, even though the ISR simply schedules the interrupt work and can serve as a generic ISR for non-PCIe platform controllers as well.

Rename these functions and symbols to conform to Thunderbolt subsystem naming conventions before exporting them:

Quoted 7 lines
- ring_msix       -> tb_ring_msix
- nhi_msi         -> tb_nhi_isr
- nhi_probe       -> tb_nhi_probe
- nhi_shutdown    -> tb_nhi_shutdown
- nhi_pm_ops      -> tb_nhi_pm_ops

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH v2 1/7] thunderbolt: Prefix NHI core functions with tb_ and tb_ring_

In reply to Chunfeng Yun
Quoted 18 lines · Chunfeng Yun

In preparation for modularizing PCIe NHI support and allowing PCIe and platform NHI drivers to be built as separate modules atop the Thunderbolt core framework, several NHI functions and structures will need to be exported.

Currently, several of these functions lack standard subsystem prefixes, risking namespace pollution or collisions across the flat kernel symbol namespace:

- ring_msix() lacks any subsystem prefix and diverges from all other exported ring functions in the driver, which use the "tb_ring_" prefix.
- nhi_probe(), nhi_shutdown(), and nhi_pm_ops lack the standard "tb_" prefix used across the Thunderbolt public interface (such as struct tb_nhi and struct tb_nhi_ops).
- nhi_msi() is named after PCI MSI, even though the ISR simply schedules the interrupt work and can serve as a generic ISR for non-PCIe platform controllers as well.

Quoted 4 lines

Rename these functions and symbols to conform to Thunderbolt subsystem naming conventions before exporting them:

- ring_msix -> tb_ring_msix

Maybe nhi_ instead? tb is used for the software connection manager- related functions

Konrad

#4 lore raw

Re: [PATCH v2 1/7] thunderbolt: Prefix NHI core functions with tb_ and tb_ring_

Quoted 33 lines · Konrad Dybcio

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 27 lines · Chunfeng Yun

In preparation for modularizing PCIe NHI support and allowing PCIe and platform NHI drivers to be built as separate modules atop the Thunderbolt core framework, several NHI functions and structures will
need to be exported.

Currently, several of these functions lack standard subsystem prefixes,
risking namespace pollution or collisions across the flat kernel symbol
namespace:

- ring_msix() lacks any subsystem prefix and diverges from all other
  exported ring functions in the driver, which use the "tb_ring_" prefix.
- nhi_probe(), nhi_shutdown(), and nhi_pm_ops lack the standard "tb_"
  prefix used across the Thunderbolt public interface (such as struct
  tb_nhi and struct tb_nhi_ops).
- nhi_msi() is named after PCI MSI, even though the ISR simply schedules
  the interrupt work and can serve as a generic ISR for non-PCIe platform
  controllers as well.

Quoted 8 lines
Quoted 5 lines

Rename these functions and symbols to conform to Thunderbolt subsystem
naming conventions before exporting them:

- ring_msix       -> tb_ring_msix

Maybe nhi_ instead? tb is used for the software connection manager- related functions

I checked the header file include/linux/thunderbolt.h, almost all functions use prefix tb_ or tb_ring_ except one using usb4_, so use tb_ here

thanks

Quoted 2 lines

Konrad

#5 lore raw

PATCH v2 2/7 thunderbolt: Move ICM mailbox functions to icm.c and internalize interrupt work

In reply to Chunfeng Yun

In preparation for modularizing PCIe NHI and ICM support as a separate driver, clean up internal helper functions so that they do not need to be exported:

nhi_mailbox_cmd() and nhi_mailbox_mode() are only used by the Intel firmware Connection Manager (icm.c) to exchange mailbox commands with firmware running on Intel PCIe NHIs. The Thunderbolt core framework, software connection manager, and non-PCIe platform controllers do not use this mailbox interface. Move both functions into icm.c and mark them static.

nhi_interrupt_work was previously initialized in pci.c within nhi_pci_init_msi(), requiring it to be visible across files. Move INIT_WORK(&nhi->interrupt_work, ...) into tb_nhi_probe() so that the workqueue item is initialized by the NHI core and nhi_interrupt_work() can be marked static in nhi.c.

---
new patch

---
 drivers/thunderbolt/icm.c | 59 ++++++++++++++++++++++++++++++++++++
 drivers/thunderbolt/nhi.c | 64 ++-------------------------------------
 drivers/thunderbolt/nhi.h |  3 --
 drivers/thunderbolt/pci.c |  2 --
 4 files changed, 62 insertions(+), 66 deletions(-)
drivers/thunderbolt/icm.c +59 -0
index a295a5e6cc9c..736f551cd567 100644
@@ -45,6 +45,7 @@
 #define ICM_RETRIES			3
 #define ICM_APPROVE_TIMEOUT		10000	/* ms */
 #define ICM_MAX_LINK			4
+#define ICM_MAILBOX_TIMEOUT		500 /* ms */
 
 static bool start_icm;
 module_param(start_icm, bool, 0444);
@@ -269,6 +270,64 @@ static int pcie2cio_write(struct icm *icm, enum tb_cfg_space cs,
 	return pci2cio_wait_completion(icm, 5000);
 }
 
+/**
+ * nhi_mailbox_cmd() - Send a command through NHI mailbox
+ * @nhi: Pointer to the NHI structure
+ * @cmd: Command to send
+ * @data: Data to be send with the command
+ *
+ * Sends mailbox command to the firmware running on NHI.
+ *
+ * Return: %0 on success, negative errno otherwise.
+ */
+static int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data)
+{
+	ktime_t timeout;
+	u32 val;
+
+	iowrite32(data, nhi->iobase + REG_INMAIL_DATA);
+
+	val = ioread32(nhi->iobase + REG_INMAIL_CMD);
+	val &= ~(REG_INMAIL_CMD_MASK | REG_INMAIL_ERROR);
+	val |= REG_INMAIL_OP_REQUEST | cmd;
+	iowrite32(val, nhi->iobase + REG_INMAIL_CMD);
+
+	timeout = ktime_add_ms(ktime_get(), ICM_MAILBOX_TIMEOUT);
+	do {
+		val = ioread32(nhi->iobase + REG_INMAIL_CMD);
+		if (!(val & REG_INMAIL_OP_REQUEST))
+			break;
+		usleep_range(10, 20);
+	} while (ktime_before(ktime_get(), timeout));
+
+	if (val & REG_INMAIL_OP_REQUEST)
+		return -ETIMEDOUT;
+	if (val & REG_INMAIL_ERROR)
+		return -EIO;
+
+	return 0;
+}
+
+/**
+ * nhi_mailbox_mode() - Return current firmware operation mode
+ * @nhi: Pointer to the NHI structure
+ *
+ * The function reads current firmware operation mode using NHI mailbox
+ * registers and returns it to the caller.
+ *
+ * Return: &enum nhi_fw_mode.
+ */
+static enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi)
+{
+	u32 val;
+
+	val = ioread32(nhi->iobase + REG_OUTMAIL_CMD);
+	val &= REG_OUTMAIL_CMD_OPMODE_MASK;
+	val >>= REG_OUTMAIL_CMD_OPMODE_SHIFT;
+
+	return (enum nhi_fw_mode)val;
+}
+
 static bool icm_match(const struct tb_cfg_request *req,
 		      const struct ctl_pkg *pkg)
 {
drivers/thunderbolt/nhi.c +3 -61

82 lines not on this page · raw message

drivers/thunderbolt/nhi.h +0 -3
index a36c62c49a5c..3dd6ace6150d 100644
@@ -27,11 +27,8 @@ enum nhi_mailbox_cmd {
 	NHI_MAILBOX_ALLOW_ALL_DEVS = 0x23,
 };
 
-int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data);
-enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi);
 void nhi_enable_int_throttling(struct tb_nhi *nhi);
 void nhi_disable_interrupts(struct tb_nhi *nhi);
-void nhi_interrupt_work(struct work_struct *work);
 irqreturn_t tb_nhi_isr(int irq, void *data);
 irqreturn_t tb_ring_msix(int irq, void *data);
 int tb_nhi_probe(struct tb_nhi *nhi);
drivers/thunderbolt/pci.c +0 -2
index 2f0abf4d27a3..275389903090 100644
@@ -206,8 +206,6 @@ static int nhi_pci_init_msi(struct tb_nhi *nhi)
 		if (nvec < 0)
 			return nvec;
 
-		INIT_WORK(&nhi->interrupt_work, nhi_interrupt_work);
-
 		irq = pci_irq_vector(pdev, 0);
 		if (irq < 0)
 			return irq;
Signature · 1 line
2.45.2
#6 lore raw

Re: [PATCH v2 2/7] thunderbolt: Move ICM mailbox functions to icm.c and internalize interrupt work

Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

In preparation for modularizing PCIe NHI and ICM support as a separate driver, clean up internal helper functions so that they do not need to be exported:

nhi_mailbox_cmd() and nhi_mailbox_mode() are only used by the Intel firmware Connection Manager (icm.c) to exchange mailbox commands with firmware running on Intel PCIe NHIs. The Thunderbolt core framework, software connection manager, and non-PCIe platform controllers do not use this mailbox interface. Move both functions into icm.c and mark them static.

Quoted 7 lines

nhi_interrupt_work was previously initialized in pci.c within nhi_pci_init_msi(), requiring it to be visible across files. Move INIT_WORK(&nhi->interrupt_work, ...) into tb_nhi_probe() so that the workqueue item is initialized by the NHI core and nhi_interrupt_work() can be marked static in nhi.c.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#7 lore raw

Re: [PATCH v2 2/7] thunderbolt: Move ICM mailbox functions to icm.c and internalize interrupt work

In reply to Chunfeng Yun
Quoted 185 lines · Chunfeng Yun

In preparation for modularizing PCIe NHI and ICM support as a separate driver, clean up internal helper functions so that they do not need to be exported:

nhi_mailbox_cmd() and nhi_mailbox_mode() are only used by the Intel firmware Connection Manager (icm.c) to exchange mailbox commands with firmware running on Intel PCIe NHIs. The Thunderbolt core framework, software connection manager, and non-PCIe platform controllers do not use this mailbox interface. Move both functions into icm.c and mark them static.

nhi_interrupt_work was previously initialized in pci.c within nhi_pci_init_msi(), requiring it to be visible across files. Move INIT_WORK(&nhi->interrupt_work, ...) into tb_nhi_probe() so that the workqueue item is initialized by the NHI core and nhi_interrupt_work() can be marked static in nhi.c.

---
new patch

---
 drivers/thunderbolt/icm.c | 59 ++++++++++++++++++++++++++++++++++++
 drivers/thunderbolt/nhi.c | 64 ++-------------------------------------
 drivers/thunderbolt/nhi.h |  3 --
 drivers/thunderbolt/pci.c |  2 --
 4 files changed, 62 insertions(+), 66 deletions(-)
drivers/thunderbolt/icm.c +59 -0
index a295a5e6cc9c..736f551cd567 100644
@@ -45,6 +45,7 @@
 #define ICM_RETRIES			3
 #define ICM_APPROVE_TIMEOUT		10000	/* ms */
 #define ICM_MAX_LINK			4
+#define ICM_MAILBOX_TIMEOUT		500 /* ms */
 
 static bool start_icm;
 module_param(start_icm, bool, 0444);
@@ -269,6 +270,64 @@ static int pcie2cio_write(struct icm *icm, enum tb_cfg_space cs,
 	return pci2cio_wait_completion(icm, 5000);
 }
 
+/**
+ * nhi_mailbox_cmd() - Send a command through NHI mailbox
+ * @nhi: Pointer to the NHI structure
+ * @cmd: Command to send
+ * @data: Data to be send with the command
+ *
+ * Sends mailbox command to the firmware running on NHI.
+ *
+ * Return: %0 on success, negative errno otherwise.
+ */
+static int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data)
+{
+	ktime_t timeout;
+	u32 val;
+
+	iowrite32(data, nhi->iobase + REG_INMAIL_DATA);
+
+	val = ioread32(nhi->iobase + REG_INMAIL_CMD);
+	val &= ~(REG_INMAIL_CMD_MASK | REG_INMAIL_ERROR);
+	val |= REG_INMAIL_OP_REQUEST | cmd;
+	iowrite32(val, nhi->iobase + REG_INMAIL_CMD);
+
+	timeout = ktime_add_ms(ktime_get(), ICM_MAILBOX_TIMEOUT);
+	do {
+		val = ioread32(nhi->iobase + REG_INMAIL_CMD);
+		if (!(val & REG_INMAIL_OP_REQUEST))
+			break;
+		usleep_range(10, 20);
+	} while (ktime_before(ktime_get(), timeout));
+
+	if (val & REG_INMAIL_OP_REQUEST)
+		return -ETIMEDOUT;
+	if (val & REG_INMAIL_ERROR)
+		return -EIO;
+
+	return 0;
+}
+
+/**
+ * nhi_mailbox_mode() - Return current firmware operation mode
+ * @nhi: Pointer to the NHI structure
+ *
+ * The function reads current firmware operation mode using NHI mailbox
+ * registers and returns it to the caller.
+ *
+ * Return: &enum nhi_fw_mode.
+ */
+static enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi)
+{
+	u32 val;
+
+	val = ioread32(nhi->iobase + REG_OUTMAIL_CMD);
+	val &= REG_OUTMAIL_CMD_OPMODE_MASK;
+	val >>= REG_OUTMAIL_CMD_OPMODE_SHIFT;
+
+	return (enum nhi_fw_mode)val;
+}
+
 static bool icm_match(const struct tb_cfg_request *req,
 		      const struct ctl_pkg *pkg)
 {
drivers/thunderbolt/nhi.c +1 -61
index c574c336f25b..1e3a58636d3d 100644
@@ -35,8 +35,6 @@
  */
 #define RING_E2E_RESERVED_HOPID	RING_FIRST_USABLE_HOPID
 
-#define NHI_MAILBOX_TIMEOUT	500 /* ms */
-
 static bool host_reset = true;
 module_param(host_reset, bool, 0444);
 MODULE_PARM_DESC(host_reset, "reset USB4 host router (default: true)");
@@ -964,65 +962,7 @@ int tb_ring_throttling(struct tb_ring *ring, unsigned int interval_nsec)
 }
 EXPORT_SYMBOL_GPL(tb_ring_throttling);
 
-/**
- * nhi_mailbox_cmd() - Send a command through NHI mailbox
- * @nhi: Pointer to the NHI structure
- * @cmd: Command to send
- * @data: Data to be send with the command
- *
- * Sends mailbox command to the firmware running on NHI.
- *
- * Return: %0 on success, negative errno otherwise.
- */
-int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data)
-{
-	ktime_t timeout;
-	u32 val;
-
-	iowrite32(data, nhi->iobase + REG_INMAIL_DATA);
-
-	val = ioread32(nhi->iobase + REG_INMAIL_CMD);
-	val &= ~(REG_INMAIL_CMD_MASK | REG_INMAIL_ERROR);
-	val |= REG_INMAIL_OP_REQUEST | cmd;
-	iowrite32(val, nhi->iobase + REG_INMAIL_CMD);
-
-	timeout = ktime_add_ms(ktime_get(), NHI_MAILBOX_TIMEOUT);
-	do {
-		val = ioread32(nhi->iobase + REG_INMAIL_CMD);
-		if (!(val & REG_INMAIL_OP_REQUEST))
-			break;
-		usleep_range(10, 20);
-	} while (ktime_before(ktime_get(), timeout));
-
-	if (val & REG_INMAIL_OP_REQUEST)
-		return -ETIMEDOUT;
-	if (val & REG_INMAIL_ERROR)
-		return -EIO;
-
-	return 0;
-}
-
-/**
- * nhi_mailbox_mode() - Return current firmware operation mode
- * @nhi: Pointer to the NHI structure
- *
- * The function reads current firmware operation mode using NHI mailbox
- * registers and returns it to the caller.
- *
- * Return: &enum nhi_fw_mode.
- */
-enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi)
-{
-	u32 val;
-
-	val = ioread32(nhi->iobase + REG_OUTMAIL_CMD);
-	val &= REG_OUTMAIL_CMD_OPMODE_MASK;
-	val >>= REG_OUTMAIL_CMD_OPMODE_SHIFT;
-
-	return (enum nhi_fw_mode)val;
-}
-
-void nhi_interrupt_work(struct work_struct *work)
+static void nhi_interrupt_work(struct work_struct *work)
 {
 	struct tb_nhi *nhi = container_of(work, typeof(*nhi), interrupt_work);
 	int value = 0; /* Suppress uninitialized usage warning. */

drivers/thunderbolt/nhi.c int tb_nhi_probe(struct tb_nhi *nhi) · line 1275

Quoted 5 lines
drivers/thunderbolt/nhi.c +2 -0
@@ -1331,6 +1271,8 @@ int tb_nhi_probe(struct tb_nhi *nhi)
 	if (!nhi->tx_rings || !nhi->rx_rings || !nhi->interrupt_mask)
 		return -ENOMEM;
 
+    INIT_WORK(&nhi->interrupt_work, nhi_interrupt_work);
+

This has weird indent.

Quoted 34 lines
drivers/thunderbolt/nhi.c +0 -0
 	nhi_reset(nhi);
 
 	/* In case someone left them on. */
drivers/thunderbolt/nhi.h +0 -3
index a36c62c49a5c..3dd6ace6150d 100644
@@ -27,11 +27,8 @@ enum nhi_mailbox_cmd {
 	NHI_MAILBOX_ALLOW_ALL_DEVS = 0x23,
 };
 
-int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data);
-enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi);
 void nhi_enable_int_throttling(struct tb_nhi *nhi);
 void nhi_disable_interrupts(struct tb_nhi *nhi);
-void nhi_interrupt_work(struct work_struct *work);
 irqreturn_t tb_nhi_isr(int irq, void *data);
 irqreturn_t tb_ring_msix(int irq, void *data);
 int tb_nhi_probe(struct tb_nhi *nhi);
drivers/thunderbolt/pci.c +0 -2
index 2f0abf4d27a3..275389903090 100644
@@ -206,8 +206,6 @@ static int nhi_pci_init_msi(struct tb_nhi *nhi)
 		if (nvec < 0)
 			return nvec;
 
-		INIT_WORK(&nhi->interrupt_work, nhi_interrupt_work);
-
 		irq = pci_irq_vector(pdev, 0);
 		if (irq < 0)
 			return irq;
Signature · 1 line
2.45.2
#8 lore raw

Re: [PATCH v2 2/7] thunderbolt: Move ICM mailbox functions to icm.c and internalize interrupt work

Quoted 28 lines · Mika Westerberg
Quoted 28 lines
drivers/thunderbolt/nhi.c +0 -0
@@ -35,8 +35,6 @@
   */
  #define RING_E2E_RESERVED_HOPID	RING_FIRST_USABLE_HOPID

drivers/thunderbolt/nhi.c +0 -2
-#define NHI_MAILBOX_TIMEOUT	500 /* ms */
-

 static bool host_reset = true; module_param(host_reset, bool, 0444); MODULE_PARM_DESC(host_reset, "reset USB4 host router (default:
true)");

drivers/thunderbolt/nhi.c +1 -2
@@ -964,65 +962,7 @@ int tb_ring_throttling(struct tb_ring *ring,
 unsigned int interval_nsec)
  }
  EXPORT_SYMBOL_GPL(tb_ring_throttling);
...
-
-void nhi_interrupt_work(struct work_struct *work)
+static void nhi_interrupt_work(struct work_struct *work)

 {
  struct tb_nhi *nhi = container_of(work, typeof(*nhi), interrupt_work);
  int value = 0; /* Suppress uninitialized usage warning. */

drivers/thunderbolt/nhi.c +0 -0
@@ -1331,6 +1271,8 @@ int tb_nhi_probe(struct tb_nhi *nhi)

  if (!nhi->tx_rings || !nhi->rx_rings || !nhi-

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

interrupt_mask)

  return -ENOMEM;

+    INIT_WORK(&nhi->interrupt_work, nhi_interrupt_work); +

This has weird indent.

will fix it, thanks

Quoted 7 lines
Quoted 7 lines

  nhi_reset(nhi);

  /* In case someone left them on. */

drivers/thunderbolt/nhi.h +0 -0
index a36c62c49a5c..3dd6ace6150d 100644
#9 lore raw

PATCH v2 3/7 thunderbolt: Make PCIe NHI support opt-in

In reply to Chunfeng Yun

From: Konrad Dybcio <[email protected]>

Currently, the USB4/Thunderbolt subsystem directly depends on PCI, tightly bundling the core framework with the PCIe-attached Native Host Interface (NHI) driver (pci.c) and the Intel Connection Manager (icm.c) into a single module (thunderbolt.o).

With support for platform/SoC-attached USB4 host controllers coming in (such as on ARM64 systems), the core USB4 framework should no longer have a hard dependency on PCI. Furthermore, embedded or SoC systems without PCIe-attached host routers should be able to omit PCIe NHI support to reduce kernel footprint.

Decouple the PCIe NHI and ICM drivers from the core framework:

1. Kconfig & Makefile:
- Remove "depends on PCI" from CONFIG_USB4.
- Introduce CONFIG_USB4_PCI to build PCIe NHI and ICM support as a separate module (thunderbolt_pci.ko).

2. Driver Registration:
- Make the core thunderbolt module standalone by converting tb_domain_init/exit() to postcore_initcall() and module_exit().
- Register the PCIe driver in thunderbolt_pci via module_pci_driver().

3. Connection Manager Selection:
- Add an optional .select_cm() hook to struct tb_nhi_ops so that the PCIe driver can invoke icm_probe() for legacy/firmware-CM controllers without hardcoding ICM calls into the core nhi.c.

4. Symbol Exports:
- Export necessary APIs required by pci and platform drivers.

---
v2:
cherry-pick the patch of Konrad to fix the issues of this series, and also do some changes:

* Renamed CONFIG_USB4_PCIE and thunderbolt_pcie.ko to CONFIG_USB4_PCI and thunderbolt_pci.ko.
* Updated exported NHI symbols to standard tb_ / tb_ring_ prefixes (e.g., ring_msix → tb_ring_msix, nhi_msi → tb_nhi_isr).
* Eliminated exports for nhi_mailbox_* and nhi_interrupt_work by keeping them internal/static (handled by preparatory patches in v2).
* Added missing trailing semicolon to module_pci_driver(nhi_driver);.
* Expanded the commit message;
* Fix cherry-pick conflict caused by .reset_interface();

---
 drivers/thunderbolt/Kconfig   | 11 +++++++++-
 drivers/thunderbolt/Makefile  |  7 +++++--
 drivers/thunderbolt/ctl.c     |  6 +++++-
 drivers/thunderbolt/domain.c  | 14 +++++++++++--
 drivers/thunderbolt/nhi.c     | 14 ++++++-------
 drivers/thunderbolt/nhi.h     |  2 ++
 drivers/thunderbolt/pci.c     | 39 +++++++++++++----------------------
 drivers/thunderbolt/switch.c  |  9 ++++++++
 drivers/thunderbolt/tb.h      |  2 --
 drivers/thunderbolt/tunnel.c  |  1 +
 drivers/thunderbolt/xdomain.c |  5 +++++
 11 files changed, 70 insertions(+), 40 deletions(-)
drivers/thunderbolt/Kconfig +10 -1
index 294b3227a545..605af440457a 100644
@@ -1,7 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 menuconfig USB4
 	tristate "Unified support for USB4 and Thunderbolt"
-	depends on PCI
 	select APPLE_PROPERTIES if EFI_STUB && X86
 	select CRC32
 	select CRYPTO_LIB_SHA256
@@ -18,6 +17,16 @@ menuconfig USB4
 
 if USB4
 
+config USB4_PCI
+	depends on PCI
+	tristate "Support for PCIe-attached USB4 and Thunderbolt controllers"
+	help
+	  Say Y here to add support for the USB4 and Thunderbolt host
+	  routers attached over the PCIe bus, commonly found on x86 PCs.
+
+	  To compile this driver a module, choose M here. The module will be
+	  called thunderbolt_pci.
+
 config USB4_CONFIGFS
 	def_tristate USB4
 	depends on CONFIGFS_FS && !(USB4=y && CONFIGFS_FS=m)
drivers/thunderbolt/Makefile +5 -2
index beb054c3126b..a563bf2b0345 100644
@@ -1,10 +1,13 @@
 # SPDX-License-Identifier: GPL-2.0-only
 ccflags-y := -I$(src)
 obj-${CONFIG_USB4} := thunderbolt.o
-thunderbolt-objs := nhi.o ctl.o tb.o switch.o cap.o pci.o path.o tunnel.o eeprom.o
-thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o tmu.o usb4.o
+thunderbolt-objs := nhi.o ctl.o tb.o switch.o cap.o path.o tunnel.o eeprom.o
+thunderbolt-objs += domain.o dma_port.o property.o xdomain.o lc.o tmu.o usb4.o
 thunderbolt-objs += usb4_port.o nvm.o retimer.o quirks.o clx.o
 
+obj-${CONFIG_USB4_PCI} += thunderbolt_pci.o
+thunderbolt_pci-y := pci.o icm.o
+
 thunderbolt-${CONFIG_ACPI} += acpi.o
 thunderbolt-$(CONFIG_DEBUG_FS) += debugfs.o
 thunderbolt-$(CONFIG_USB4_CONFIGFS) += configfs.o
drivers/thunderbolt/ctl.c +5 -1
index 965988b18608..96717a0a94b1 100644
@@ -9,7 +9,6 @@
 #include <linux/crc32.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
-#include <linux/pci.h>
 #include <linux/dmapool.h>
 #include <linux/workqueue.h>
 
@@ -96,6 +95,7 @@ struct tb_cfg_request *tb_cfg_request_alloc(void)
 
 	return req;
 }
+EXPORT_SYMBOL_GPL(tb_cfg_request_alloc);
 
 /**
  * tb_cfg_request_get() - Increase refcount of a request
@@ -128,6 +128,7 @@ void tb_cfg_request_put(struct tb_cfg_request *req)
 	kref_put(&req->kref, tb_cfg_request_destroy);
 	mutex_unlock(&tb_cfg_request_lock);
 }
+EXPORT_SYMBOL_GPL(tb_cfg_request_put);
 
 static int tb_cfg_request_enqueue(struct tb_ctl *ctl,
 				  struct tb_cfg_request *req)
@@ -575,6 +576,7 @@ int tb_cfg_request(struct tb_ctl *ctl, struct tb_cfg_request *req,
 	tb_cfg_request_dequeue(req);
 	return ret;
 }
+EXPORT_SYMBOL_GPL(tb_cfg_request);
 
 /**
  * tb_cfg_request_cancel() - Cancel a control request
@@ -634,6 +636,7 @@ struct tb_cfg_result tb_cfg_request_sync(struct tb_ctl *ctl,
 
 	return req->result;
 }
+EXPORT_SYMBOL_GPL(tb_cfg_request_sync);
 
 /* public interface, alloc/start/stop/free */
 
@@ -1009,6 +1012,7 @@ struct tb_cfg_result tb_cfg_read_raw(struct tb_ctl *ctl, void *buffer,
 		memcpy(buffer, &reply.data, 4 * length);
 	return res;
 }
+EXPORT_SYMBOL_GPL(tb_cfg_read_raw);
 
 /**
  * tb_cfg_write_raw() - write from buffer into config space
drivers/thunderbolt/domain.c +12 -2
index 24611f05b3cd..114ddd5be25b 100644
@@ -313,6 +313,7 @@ const struct bus_type tb_bus_type = {
 	.remove = tb_service_remove,
 	.shutdown = tb_service_shutdown,
 };
+EXPORT_SYMBOL_GPL(tb_bus_type);
 
 static void tb_domain_release(struct device *dev)
 {
@@ -421,6 +422,7 @@ struct tb *tb_domain_alloc(struct tb_nhi *nhi, int timeout_msec, size_t privsize
 
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(tb_domain_alloc);
 
 /**
  * tb_domain_add() - Add domain to the system
@@ -514,6 +516,7 @@ void tb_domain_remove(struct tb *tb)
 
 	device_unregister(&tb->dev);
 }
+EXPORT_SYMBOL_GPL(tb_domain_remove);
 
 /**
  * tb_domain_suspend_noirq() - Suspend a domain
@@ -880,8 +883,9 @@ int tb_domain_unregister_unplugged_xdomains(struct tb *tb)
 
 	return ctx.n;
 }
+EXPORT_SYMBOL_GPL(tb_domain_unregister_unplugged_xdomains);
 
-int tb_domain_init(void)
+static int __init tb_domain_init(void)
 {
 	int ret;
 
@@ -907,7 +911,7 @@ int tb_domain_init(void)
 	return ret;
 }
 
-void tb_domain_exit(void)
+static void __exit tb_domain_exit(void)
 {
 	bus_unregister(&tb_bus_type);
 	ida_destroy(&tb_domain_ida);
@@ -917,3 +921,9 @@ void tb_domain_exit(void)
 	tb_debugfs_exit();
 	tb_configfs_exit();
 }
+
+postcore_initcall(tb_domain_init);
+module_exit(tb_domain_exit);
+
+MODULE_DESCRIPTION("Thunderbolt/USB4 core driver");
+MODULE_LICENSE("GPL");
drivers/thunderbolt/nhi.c +7 -7
index 1e3a58636d3d..9662d1dd410f 100644
@@ -546,6 +546,7 @@ irqreturn_t tb_ring_msix(int irq, void *data)
 
 	return IRQ_HANDLED;
 }
+EXPORT_SYMBOL_GPL(tb_ring_msix);
 
 static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring)
 {
@@ -1018,6 +1019,7 @@ irqreturn_t tb_nhi_isr(int irq, void *data)
 	schedule_work(&nhi->interrupt_work);
 	return IRQ_HANDLED;
 }
+EXPORT_SYMBOL_GPL(tb_nhi_isr);
 
 static int __nhi_suspend_noirq(struct device *dev, bool wakeup)
 {
@@ -1175,6 +1177,7 @@ void tb_nhi_shutdown(struct tb_nhi *nhi)
 	if (nhi->ops->shutdown)
 		nhi->ops->shutdown(nhi);
 }
+EXPORT_SYMBOL_GPL(tb_nhi_shutdown);
 
 static void nhi_reset(struct tb_nhi *nhi)
 {
@@ -1216,13 +1219,8 @@ static struct tb *nhi_select_cm(struct tb_nhi *nhi)
 	 * USB4 case is simple. If we got control of any of the
 	 * capabilities, we use software CM.
 	 */
-	if (!tb_acpi_is_native()) {
-		/*
-		 * Either firmware based CM is running (we did not get
-		 * control from the firmware) or this is pre-USB4 PC so
-		 * try first firmware CM and then fallback to software CM.
-		 */
-		tb = icm_probe(nhi);
+	if (!tb_acpi_is_native() && nhi->ops->select_cm) {
+		tb = nhi->ops->select_cm(nhi);
 		if (tb)
 			return tb;
 	}
@@ -1327,6 +1325,7 @@ int tb_nhi_probe(struct tb_nhi *nhi)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(tb_nhi_probe);
 
 /*
  * The tunneled pci bridges are siblings of us. Use resume_noirq to reenable
@@ -1349,3 +1348,4 @@ const struct dev_pm_ops tb_nhi_pm_ops = {
 	.runtime_suspend = nhi_runtime_suspend,
 	.runtime_resume = nhi_runtime_resume,
 };
+EXPORT_SYMBOL_GPL(tb_nhi_pm_ops);
drivers/thunderbolt/nhi.h +2 -0
index 3dd6ace6150d..65f9daf36068 100644
@@ -50,6 +50,7 @@ extern const struct dev_pm_ops tb_nhi_pm_ops;
  * @release_ring_irq: NHI specific interrupt release hook
  * @is_present: Whether the device is currently present on the parent bus
  * @init_interrupts: NHI specific interrupt initialization hook
+ * @select_cm: optional hook to select a custom CM
  */
 struct tb_nhi_ops {
 	int (*init)(struct tb_nhi *nhi);
@@ -65,6 +66,7 @@ struct tb_nhi_ops {
 	void (*release_ring_irq)(struct tb_ring *ring);
 	bool (*is_present)(struct tb_nhi *nhi);
 	int (*init_interrupts)(struct tb_nhi *nhi);
+	struct tb * (*select_cm)(struct tb_nhi *nhi);
 };
 
 /*
drivers/thunderbolt/pci.c +14 -25
index 275389903090..9379c598a221 100644
@@ -325,6 +325,16 @@ static bool nhi_pci_is_present(struct tb_nhi *nhi)
 	return pci_device_is_present(to_pci_dev(nhi->dev));
 }
 
+static struct tb *nhi_pci_select_cm(struct tb_nhi *nhi)
+{
+	/*
+	 * Either the firmware-based CM is running (we did not get
+	 * control from the firmware) or this is a pre-USB4 PC, so
+	 * first try using the firmware CM and then fallback to software CM.
+	 */
+	return icm_probe(nhi);
+}
+
 static const struct tb_nhi_ops pci_nhi_default_ops = {
 	.add_links = nhi_pci_add_links,
 	.pre_nvm_auth = nhi_pci_start_dma_port,
@@ -334,6 +344,7 @@ static const struct tb_nhi_ops pci_nhi_default_ops = {
 	.shutdown = nhi_pci_release_irq,
 	.is_present = nhi_pci_is_present,
 	.init_interrupts = nhi_pci_init_msi,
+	.select_cm = nhi_pci_select_cm,
 };
 
 /* Ice Lake specific NHI operations */
@@ -552,6 +563,7 @@ static const struct tb_nhi_ops icl_nhi_ops = {
 	.release_ring_irq = nhi_pci_ring_release_msix,
 	.is_present = nhi_pci_is_present,
 	.init_interrupts = nhi_pci_init_msi,
+	.select_cm = nhi_pci_select_cm,
 };
 
 static int nhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
@@ -713,7 +725,7 @@ static struct pci_device_id nhi_ids[] = {
 };
 
 MODULE_DEVICE_TABLE(pci, nhi_ids);
-MODULE_DESCRIPTION("Thunderbolt/USB4 core driver");
+MODULE_DESCRIPTION("PCIe-attached Thunderbolt/USB4 host interface driver");
 MODULE_LICENSE("GPL");
 
 static struct pci_driver nhi_driver = {
@@ -724,27 +736,4 @@ static struct pci_driver nhi_driver = {
 	.shutdown = nhi_pci_shutdown,
 	.driver.pm = &tb_nhi_pm_ops,
 };
-
-static int __init nhi_init(void)
-{
-	int ret;
-
-	ret = tb_domain_init();
-	if (ret)
-		return ret;
-
-	ret = pci_register_driver(&nhi_driver);
-	if (ret)
-		tb_domain_exit();
-
-	return ret;
-}
-
-static void __exit nhi_unload(void)
-{
-	pci_unregister_driver(&nhi_driver);
-	tb_domain_exit();
-}
-
-rootfs_initcall(nhi_init);
-module_exit(nhi_unload);
+module_pci_driver(nhi_driver);
drivers/thunderbolt/switch.c +9 -0
index d22d8db8f890..7ff3da79da76 100644
@@ -2396,6 +2396,7 @@ const struct device_type tb_switch_type = {
 	.uevent = tb_switch_uevent,
 	.pm = &tb_switch_pm_ops,
 };
+EXPORT_SYMBOL_GPL(tb_switch_type);
 
 static int tb_switch_get_generation(struct tb_switch *sw)
 {
@@ -2571,6 +2572,7 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent,
 
 	return ERR_PTR(ret);
 }
+EXPORT_SYMBOL_GPL(tb_switch_alloc);
 
 /**
  * tb_switch_alloc_safe_mode() - allocate a switch that is in safe mode
@@ -2610,6 +2612,7 @@ tb_switch_alloc_safe_mode(struct tb *tb, struct device *parent, u64 route)
 
 	return sw;
 }
+EXPORT_SYMBOL_GPL(tb_switch_alloc_safe_mode);
 
 /**
  * tb_switch_configure() - Uploads configuration to the switch
@@ -3438,6 +3441,7 @@ int tb_switch_add(struct tb_switch *sw)
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(tb_switch_add);
 
 /**
  * tb_switch_remove() - Remove and release a switch
@@ -3483,6 +3487,7 @@ void tb_switch_remove(struct tb_switch *sw)
 		dev_info(&sw->dev, "device disconnected\n");
 	device_unregister(&sw->dev);
 }
+EXPORT_SYMBOL_GPL(tb_switch_remove);
 
 /**
  * tb_sw_set_unplugged() - set is_unplugged on switch and downstream switches
@@ -3828,6 +3833,7 @@ struct tb_switch *tb_switch_find_by_link_depth(struct tb *tb, u8 link, u8 depth)
 
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(tb_switch_find_by_link_depth);
 
 /**
  * tb_switch_find_by_uuid() - Find switch by UUID
@@ -3854,6 +3860,7 @@ struct tb_switch *tb_switch_find_by_uuid(struct tb *tb, const uuid_t *uuid)
 
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(tb_switch_find_by_uuid);
 
 /**
  * tb_switch_find_by_route() - Find switch by route string
@@ -3883,6 +3890,7 @@ struct tb_switch *tb_switch_find_by_route(struct tb *tb, u64 route)
 
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(tb_switch_find_by_route);
 
 /**
  * tb_switch_find_port() - return the first port of @type on @sw or NULL
@@ -3903,6 +3911,7 @@ struct tb_port *tb_switch_find_port(struct tb_switch *sw,
 
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(tb_switch_find_port);
 
 /*
  * Can be used for read/write a specified PCIe bridge for any Thunderbolt 3
drivers/thunderbolt/tb.h +0 -2
index e86845762e22..6dfdc47e05d2 100644
@@ -768,8 +768,6 @@ 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;
 
-int tb_domain_init(void);
-void tb_domain_exit(void);
 int tb_xdomain_init(void);
 void tb_xdomain_exit(void);
 
drivers/thunderbolt/tunnel.c +1 -0
index 2b911372001c..c92f181f181d 100644
@@ -274,6 +274,7 @@ void tb_tunnel_event(struct tb *tb, enum tb_tunnel_event event,
 	kfree(envp[1]);
 	kfree(envp[0]);
 }
+EXPORT_SYMBOL_GPL(tb_tunnel_event);
 
 static inline void tb_tunnel_set_active(struct tb_tunnel *tunnel, bool active)
 {
drivers/thunderbolt/xdomain.c +5 -0
index b187a60663f5..af82b86a0348 100644
@@ -86,6 +86,7 @@ bool tb_is_xdomain_enabled(void)
 {
 	return tb_xdomain_enabled && tb_acpi_is_xdomain_allowed();
 }
+EXPORT_SYMBOL_GPL(tb_is_xdomain_enabled);
 
 static bool tb_xdomain_match(const struct tb_cfg_request *req,
 			     const struct ctl_pkg *pkg)
@@ -2196,6 +2197,7 @@ struct tb_xdomain *tb_xdomain_alloc(struct tb *tb, struct device *parent,
 
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(tb_xdomain_alloc);
 
 /**
  * tb_xdomain_add() - Add XDomain to the bus
@@ -2211,6 +2213,7 @@ void tb_xdomain_add(struct tb_xdomain *xd)
 	/* Start exchanging properties with the other host */
 	start_handshake(xd);
 }
+EXPORT_SYMBOL_GPL(tb_xdomain_add);
 
 static int unregister_service(struct device *dev, void *data)
 {
@@ -2270,6 +2273,7 @@ void tb_xdomain_unregister(struct tb_xdomain *xd)
 	dev_info(&xd->dev, "host disconnected\n");
 	device_unregister(&xd->dev);
 }
+EXPORT_SYMBOL_GPL(tb_xdomain_remove);
 
 /**
  * tb_xdomain_lane_bonding_enable() - Enable lane bonding on XDomain
@@ -2593,6 +2597,7 @@ struct tb_xdomain *tb_xdomain_find_by_link_depth(struct tb *tb, u8 link,
 	xd = switch_find_xdomain(tb->root_switch, &lookup);
 	return tb_xdomain_get(xd);
 }
+EXPORT_SYMBOL_GPL(tb_xdomain_find_by_link_depth);
 
 /**
  * tb_xdomain_find_by_route() - Find an XDomain by route string
Signature · 1 line
2.45.2
#10 lore raw

Re: [PATCH v2 3/7] thunderbolt: Make PCIe NHI support opt-in

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] thunderbolt: missing default USB4 on CONFIG_USB4_PCI breaks existing configs - [Low] thunderbolt…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] thunderbolt: missing default USB4 on CONFIG_USB4_PCI breaks existing configs
- [Low] thunderbolt: misplaced EXPORT_SYMBOL_GPL(tb_xdomain_remove) in xdomain.c
--

commit 20bc8cfb6a438440bc1447d0b676bf03b1cdb691
Author: Konrad Dybcio <[email protected]>

thunderbolt: Make PCIe NHI support opt-in

This commit decouples PCIe NHI and ICM support from the core USB4/Thunderbolt framework into a separate thunderbolt_pci module controlled by CONFIG_USB4_PCI.

Quoted 15 lines
drivers/thunderbolt/Kconfig +0 -1
index 294b3227a5458..605af440457a1 100644
@@ -1,7 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 menuconfig USB4
 	tristate "Unified support for USB4 and Thunderbolt"
-	depends on PCI
 	select APPLE_PROPERTIES if EFI_STUB && X86
 	select CRC32
 	select CRYPTO_LIB_SHA256
@@ -18,6 +17,16 @@ menuconfig USB4
 
 if USB4

drivers/thunderbolt/Kconfig menuconfig USB4 · line 28

Quoted 10 lines
drivers/thunderbolt/Kconfig +9 -0
 
+config USB4_PCI
+	depends on PCI
+	tristate "Support for PCIe-attached USB4 and Thunderbolt controllers"
+	help
+	  Say Y here to add support for the USB4 and Thunderbolt host
+	  routers attached over the PCIe bus, commonly found on x86 PCs.
+
+	  To compile this driver a module, choose M here. The module will be
+	  called thunderbolt_pci.

[Severity: High]
Should USB4_PCI default to USB4?

Without a default, make olddefconfig on existing configs with CONFIG_USB4 enabled (as well as in-tree defconfigs such as loongson64_defconfig) will set CONFIG_USB4_PCI=n and drop PCIe controller support. On ACPI systems with a PCIe host router, having CONFIG_USB4 enabled while CONFIG_USB4_PCI is disabled still causes acpi_bus_osc_negotiate_platform_control() to claim native OS USB4 control via _OSC (disabling the firmware Connection Manager) with no OS NHI driver bound, and causes typec_has_usb4_host_interface() to wait for a usb4_port component that is never registered.

[ ... ]

Quoted 4 lines
drivers/thunderbolt/xdomain.c +0 -0
index 16e818c1af1c0..d2dd6dec5b474 100644

[ ... ]

drivers/thunderbolt/xdomain.c void tb_xdomain_unregister(struct tb_xdomain *xd) · line 2276

Quoted 5 lines
drivers/thunderbolt/xdomain.c +1 -0
@@ -2270,6 +2273,7 @@ void tb_xdomain_unregister(struct tb_xdomain *xd)
 	dev_info(&xd->dev, "host disconnected\n");
 	device_unregister(&xd->dev);
 }
+EXPORT_SYMBOL_GPL(tb_xdomain_remove);

[Severity: Low]
EXPORT_SYMBOL_GPL(tb_xdomain_remove) is placed after tb_xdomain_unregister() instead of immediately after tb_xdomain_remove().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#11 lore raw

Re: [PATCH v2 3/7] thunderbolt: Make PCIe NHI support opt-in

Quoted 53 lines · On 二, 2026-11-10 at 12:09 +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] thunderbolt: missing default USB4 on CONFIG_USB4_PCI breaks existing configs
- [Low] thunderbolt: misplaced EXPORT_SYMBOL_GPL(tb_xdomain_remove) in
  xdomain.c
--

commit 20bc8cfb6a438440bc1447d0b676bf03b1cdb691
Author: Konrad Dybcio <[email protected]>

thunderbolt: Make PCIe NHI support opt-in

This commit decouples PCIe NHI and ICM support from the core USB4/Thunderbolt
framework into a separate thunderbolt_pci module controlled by CONFIG_USB4_PCI.

Quoted 29 lines
drivers/thunderbolt/Kconfig +0 -0
index 294b3227a5458..605af440457a1 100644
@@ -1,7 +1,6 @@
  # SPDX-License-Identifier: GPL-2.0-only

 menuconfig USB4
  tristate "Unified support for USB4 and Thunderbolt"

drivers/thunderbolt/Kconfig +0 -1
-	depends on PCI

  select APPLE_PROPERTIES if EFI_STUB && X86 select CRC32
  select CRYPTO_LIB_SHA256

drivers/thunderbolt/Kconfig +0 -0
@@ -18,6 +17,16 @@ menuconfig USB4


 if USB4

drivers/thunderbolt/Kconfig +3 -0
+config USB4_PCI
+	depends on PCI
+	tristate "Support for PCIe-attached USB4 and Thunderbolt

controllers"

drivers/thunderbolt/Kconfig +2 -0
+	help
+	  Say Y here to add support for the USB4 and Thunderbolt

host

drivers/thunderbolt/Kconfig +1 -0
+	  routers attached over the PCIe bus, commonly found on

x86 PCs.

drivers/thunderbolt/Kconfig +2 -0
+
+	  To compile this driver a module, choose M here. The

module will be

drivers/thunderbolt/Kconfig menuconfig USB4 · line 28

Quoted 1 line
drivers/thunderbolt/Kconfig +1 -0
+	  called thunderbolt_pci.

[Severity: High]
Should USB4_PCI default to USB4?

Quoted 15 lines

Without a default, make olddefconfig on existing configs with CONFIG_USB4
enabled (as well as in-tree defconfigs such as loongson64_defconfig) will set
CONFIG_USB4_PCI=n and drop PCIe controller support.  On ACPI systems with a
PCIe host router, having CONFIG_USB4 enabled while CONFIG_USB4_PCI is disabled
still causes acpi_bus_osc_negotiate_platform_control() to claim native OS
USB4 control via _OSC (disabling the firmware Connection Manager) with no OS
NHI driver bound, and causes typec_has_usb4_host_interface() to wait for a
usb4_port component that is never registered.

Make sense, will fix it

Quoted 11 lines

[ ... ]

Quoted 5 lines
drivers/thunderbolt/xdomain.c +0 -0
index 16e818c1af1c0..d2dd6dec5b474 100644

[ ... ]

Quoted 11 lines

drivers/thunderbolt/xdomain.c void tb_xdomain_unregister(struct tb_xdomain · line 2277

Quoted 6 lines
drivers/thunderbolt/xdomain.c +1 -0
@@ -2270,6 +2273,7 @@ void tb_xdomain_unregister(struct tb_xdomain
 *xd)
  	dev_info(&xd->dev, "host disconnected\n");
  	device_unregister(&xd->dev);
  }
+EXPORT_SYMBOL_GPL(tb_xdomain_remove);

[Severity: Low] EXPORT_SYMBOL_GPL(tb_xdomain_remove) is placed after tb_xdomain_unregister()
instead of immediately after tb_xdomain_remove().

My bad, will fix it

Thanks

Quoted 1 line
#12 lore raw

PATCH v2 4/7 thunderbolt: add platform NHI driver

In reply to Chunfeng Yun

Historically, the Thunderbolt/USB4 Native Host Interface (NHI) controller has been exposed as a PCI device handled by drivers/thunderbolt/pci.c. However, some SoCs (such as MediaTek mt8901/mt8992) integrate the NHI as a memory-mapped platform device described via Device Tree or ACPI.

To support platform-attached NHI controllers:

Introduce platform.c to register a platform driver matching "usb4-nhi-platform" (OF) and "ACPI0015" (ACPI); Implement platform tb_nhi_ops hooks for pm, interrupts related;

Support an optional dedicated wake interrupt: on integrated SoCs, the MAC/PHY reside in a power domain whose clocks and power can be gated during sleep, preventing the primary NHI interrupt from acting as a wakeup source; so add an optional dedicated wakeup interrupt which comes from the always-on power domain.

Clean up the unused nhi_enable_int_throttling() prototype.

---
v2 changes:
* Added CONFIG_USB4_PLATFORM to build the platform driver as a separate module (thunderbolt_platform.ko), instead of statically embedding it into thunderbolt.o.
* Renamed plat.c to platform.c, renamed internal functions from nhi_plat_* to nhi_platform_*, and updated the Device Tree compatible string from "thunderbolt-platform" to "usb4-nhi-platform".
* Removed domain lifecycle changes (domain.c) and PCI driver cleanups (pci.c) from this patch, handled by previous patches.
* Squashed the optional dedicated wake IRQ support (previously a separate patch in v1) directly into this patch.
* Replaced the custom local ISR with the shared tb_nhi_isr(), adopted the renamed tb_nhi_probe() / tb_nhi_shutdown() / tb_nhi_pm_ops interfaces, and added -EPROBE_DEFER handling for the wake IRQ.

---
 drivers/thunderbolt/Kconfig    |   9 ++
 drivers/thunderbolt/Makefile   |   3 +
 drivers/thunderbolt/nhi.h      |   1 -
 drivers/thunderbolt/pci.c      |   1 +
 drivers/thunderbolt/platform.c | 172 +++++++++++++++++++++++++++++++++
 include/linux/thunderbolt.h    |   4 +
 6 files changed, 189 insertions(+), 1 deletion(-)
 create mode 100644 drivers/thunderbolt/platform.c
drivers/thunderbolt/Kconfig +9 -0
index 605af440457a..846ab51df7ab 100644
@@ -27,6 +27,15 @@ config USB4_PCI
 	  To compile this driver a module, choose M here. The module will be
 	  called thunderbolt_pci.
 
+config USB4_PLATFORM
+	tristate "Support for platform USB4 and Thunderbolt controllers"
+	help
+	  Say Y here to add support the USB4 and Thunderbolt host routers
+	  for a platform device on such as ARM64 SoCs.
+
+	  To compile this driver a module, choose M here. The module will be
+	  called thunderbolt_platform.
+
 config USB4_CONFIGFS
 	def_tristate USB4
 	depends on CONFIGFS_FS && !(USB4=y && CONFIGFS_FS=m)
drivers/thunderbolt/Makefile +3 -0
index a563bf2b0345..334fa4ebdfc8 100644
@@ -8,6 +8,9 @@ thunderbolt-objs += usb4_port.o nvm.o retimer.o quirks.o clx.o
 obj-${CONFIG_USB4_PCI} += thunderbolt_pci.o
 thunderbolt_pci-y := pci.o icm.o
 
+obj-${CONFIG_USB4_PLATFORM} += thunderbolt_platform.o
+thunderbolt_platform-y := platform.o
+
 thunderbolt-${CONFIG_ACPI} += acpi.o
 thunderbolt-$(CONFIG_DEBUG_FS) += debugfs.o
 thunderbolt-$(CONFIG_USB4_CONFIGFS) += configfs.o
drivers/thunderbolt/nhi.h +0 -1
index 65f9daf36068..ef5d24d81251 100644
@@ -27,7 +27,6 @@ enum nhi_mailbox_cmd {
 	NHI_MAILBOX_ALLOW_ALL_DEVS = 0x23,
 };
 
-void nhi_enable_int_throttling(struct tb_nhi *nhi);
 void nhi_disable_interrupts(struct tb_nhi *nhi);
 irqreturn_t tb_nhi_isr(int irq, void *data);
 irqreturn_t tb_ring_msix(int irq, void *data);
drivers/thunderbolt/pci.c +1 -0
index 9379c598a221..698f47ec63da 100644
@@ -736,4 +736,5 @@ static struct pci_driver nhi_driver = {
 	.shutdown = nhi_pci_shutdown,
 	.driver.pm = &tb_nhi_pm_ops,
 };
+
 module_pci_driver(nhi_driver);
drivers/thunderbolt/platform.c new file +172 -0

172 lines not on this page · raw message

include/linux/thunderbolt.h +4 -0
index 57502da29080..72497acac254 100644
@@ -511,6 +511,8 @@ void tb_service_properties_changed(struct tb_service *svc);
  * @going_away: The host controller device is about to disappear so when
  *		this flag is set, avoid touching the hardware anymore.
  * @iommu_dma_protection: An IOMMU will isolate external-facing ports.
+ * @irq: interrupt number of NHI.
+ * @wake_irq: optional dedicated wakeup interrupt.
  * @interrupt_work: Work scheduled to handle ring interrupt when no
  *		    MSI-X is used.
  * @hop_count: Number of rings (end point hops) supported by NHI.
@@ -532,6 +534,8 @@ struct tb_nhi {
 	u32 *interrupt_mask;
 	bool going_away;
 	bool iommu_dma_protection;
+	int irq;
+	int wake_irq;
 	struct work_struct interrupt_work;
 	u32 hop_count;
 	unsigned long quirks;
Signature · 1 line
2.45.2
#13 lore raw

Re: [PATCH v2 4/7] thunderbolt: add platform NHI driver

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] thunderbolt: broken system PM when sharing tb_nhi_pm_ops on platform_driver - [Medium] thunderbolt…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] thunderbolt: broken system PM when sharing tb_nhi_pm_ops on platform_driver
- [Medium] thunderbolt: missing cleanup in nhi_platform_init_irq() and tb_nhi_probe()
--

commit 185e80648753aea8ed254f3effc097c624617d73
Author: Chunfeng Yun <[email protected]>

thunderbolt: add platform NHI driver

This commit adds a platform driver for Thunderbolt/USB4 Native Host Interface (NHI) controllers integrated as memory-mapped platform devices via Device Tree or ACPI, including support for an optional dedicated wakeup interrupt.

Quoted 6 lines
drivers/thunderbolt/platform.c new file +0 -0
new file mode 100644
index 0000000000000..3562b6c7ea7db
@@ -0,0 +1,172 @@

[ ... ]

Quoted 41 lines
drivers/thunderbolt/platform.c new file +41 -0
+static int nhi_platform_init(struct tb_nhi *nhi)
+{
+	/* avoid device link fail for pcie tunnel */
+	pm_runtime_set_active(nhi->dev);
+	pm_runtime_get_noresume(nhi->dev);
+	pm_runtime_enable(nhi->dev);
+
+	device_set_wakeup_capable(nhi->dev, true);
+	device_enable_async_suspend(nhi->dev);
+
+	return 0;
+}
+
+static void nhi_platform_clear_wake_irq(void *dev)
+{
+	dev_pm_clear_wake_irq(dev);
+}
+
+static int nhi_platform_init_irq(struct tb_nhi *nhi)
+{
+	struct device *dev = nhi->dev;
+	int ret;
+
+	ret = devm_request_irq(dev, nhi->irq, tb_nhi_isr, IRQF_NO_SUSPEND,
+			       dev_name(dev), nhi);
+	if (ret)
+		return dev_err_probe(dev, ret, "request irq failed\n");
+
+	if (nhi->wake_irq) {
+		ret = dev_pm_set_dedicated_wake_irq(dev, nhi->wake_irq);
+		if (ret) {
+			return dev_err_probe(dev, ret, "set wake irq %d failed\n", nhi->wake_irq);
+		}
+
+		dev_info(dev, "wake irq %d\n", nhi->wake_irq);
+
+		ret = devm_add_action_or_reset(dev, nhi_platform_clear_wake_irq, dev);
+	}
+
+	return ret;
+}

drivers/thunderbolt/platform.c line 70

Quoted 10 lines
drivers/thunderbolt/platform.c new file +10 -0
+
+static void nhi_platform_exit(struct tb_nhi *nhi)
+{
+	devm_free_irq(nhi->dev, nhi->irq, nhi);
+	flush_work(&nhi->interrupt_work);
+
+	pm_runtime_put_noidle(nhi->dev);
+	pm_runtime_disable(nhi->dev);
+	pm_runtime_set_suspended(nhi->dev);
+}

[Severity: Medium]
Does a probe failure before tb_domain_add() bypass nhi_platform_exit(), leaving nhi->interrupt_work unflushed and runtime PM enabled on the unbound device?

In tb_nhi_probe(), tb_nhi_shutdown() is only called if tb_domain_add() fails:

drivers/thunderbolt/nhi.c:tb_nhi_probe() {
	...
	res = nhi->ops->init_interrupts(nhi);
	if (res)
		return dev_err_probe(dev, res, "cannot enable interrupts, aborting\n");

	spin_lock_init(&nhi->lock);

	res = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
	if (res)
		return dev_err_probe(dev, res, "failed to set DMA mask\n");

	if (nhi->ops->init) {
		res = nhi->ops->init(nhi);
		if (res)
			return dev_err_probe(dev, res, "NHI specific init failed\n");
	}

	init_completion(&nhi->domain_released);

	tb = nhi_select_cm(nhi);
	if (!tb)
		return dev_err_probe(dev, -ENODEV,
			"failed to determine connection manager, aborting\n");
	...
}

If dev_pm_set_dedicated_wake_irq() fails in nhi_platform_init_irq(), or if dma_set_mask_and_coherent() or nhi_select_cm() fails in tb_nhi_probe(), devres frees nhi->irq, unmaps nhi->iobase, and frees nhi without ever flushing nhi->interrupt_work, which can cause a use-after-free if tb_nhi_isr() scheduled the work item. In addition, if nhi_select_cm() fails after nhi_platform_init() has run, runtime PM stays enabled with an elevated usage count, so pm_runtime_reinit() in device_unbind_cleanup() bails out and a subsequent re-probe warns on unbalanced pm_runtime_enable().

[ ... ]

drivers/thunderbolt/platform.c line 167

Quoted 11 lines
drivers/thunderbolt/platform.c new file +11 -0
+static struct platform_driver nhi_platform_driver = {
+	.probe = nhi_platform_probe,
+	.remove = nhi_platform_remove,
+	.shutdown = nhi_platform_shutdown,
+	.driver = {
+		.name = "thunderbolt",
+		.of_match_table = of_match_ptr(nhi_platform_of_match),
+		.acpi_match_table = ACPI_PTR(nhi_platform_acpi_match),
+		.pm = &tb_nhi_pm_ops,
+	},
+};

[Severity: High]
Can system suspend and resume run while the platform NHI is runtime-suspended when using tb_nhi_pm_ops directly on a platform_driver?

On PCI, pci_pm_suspend() runtime-resumes the device before calling the driver's .suspend and .suspend_noirq callbacks. Neither the platform bus, genpd, nor nhi_suspend() does that, and device_wakeup_enable() prevents direct_complete. If the controller has autosuspended before system suspend:

1. nhi_suspend_noirq() -> tb_domain_suspend_noirq() runs while the device is runtime-suspended (with clocks or power domains gated) and calls tb_ctl_stop() on rings already stopped by nhi_runtime_suspend(), triggering dev_WARN() in tb_ring_stop().
2. On resume, nhi_resume_noirq() -> tb_domain_resume_noirq() calls tb_ctl_start(), touching MMIO while runtime status is still RPM_SUSPENDED and queuing ctl->rx_packets[] onto ctl->rx->in_flight.
3. In the complete phase, nhi_complete() sees pm_runtime_suspended(dev) is

    still true and calls pm_runtime_resume(dev) -> nhi_runtime_resume() ->

tb_ctl_start() a second time:

drivers/thunderbolt/nhi.c:nhi_complete() {
	struct tb *tb = dev_get_drvdata(dev);

	/*
	 * If we were runtime suspended when system suspend started,
	 * schedule runtime resume now. It should bring the domain back
	 * to functional state.
	 */
	if (pm_runtime_suspended(dev))
		pm_runtime_resume(dev);
	else
		tb_domain_complete(tb);
}

The second tb_ctl_start() warns that the rings are already started and calls tb_ctl_rx_submit() -> __tb_ring_enqueue() -> list_add_tail() on ctl->rx_packets[] frames that are already linked in ctl->rx->in_flight, corrupting the ring list.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#14 lore raw

Re: [PATCH v2 4/7] thunderbolt: add platform NHI driver

Quoted 8 lines · On 二, 2026-11-10 at 12:15 +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] thunderbolt: broken system PM when sharing tb_nhi_pm_ops on platform_driver
- [Medium] thunderbolt: missing cleanup in nhi_platform_init_irq() and
  tb_nhi_probe()
--

Will fix it

Thanks

Quoted 2 lines
#15 lore raw

Re: [PATCH v2 4/7] thunderbolt: add platform NHI driver

In reply to Chunfeng Yun
Quoted 21 lines · Chunfeng Yun

Historically, the Thunderbolt/USB4 Native Host Interface (NHI) controller has been exposed as a PCI device handled by drivers/thunderbolt/pci.c. However, some SoCs (such as MediaTek mt8901/mt8992) integrate the NHI as a memory-mapped platform device described via Device Tree or ACPI.

To support platform-attached NHI controllers:

Introduce platform.c to register a platform driver matching "usb4-nhi-platform" (OF) and "ACPI0015" (ACPI); Implement platform tb_nhi_ops hooks for pm, interrupts related;

Support an optional dedicated wake interrupt: on integrated SoCs, the MAC/PHY reside in a power domain whose clocks and power can be gated during sleep, preventing the primary NHI interrupt from acting as a wakeup source; so add an optional dedicated wakeup interrupt which comes from the always-on power domain.

Clean up the unused nhi_enable_int_throttling() prototype.

Quoted 8 lines

---
v2 changes:
* Added CONFIG_USB4_PLATFORM to build the platform driver as a separate module (thunderbolt_platform.ko), instead of statically embedding it into thunderbolt.o.
* Renamed plat.c to platform.c, renamed internal functions from nhi_plat_* to nhi_platform_*, and updated the Device Tree compatible string from "thunderbolt-platform" to "usb4-nhi-platform".

There are still no dt-bindings for this meaning it can't be merged. You also haven't answered Sven and mine's concerns about this being actually used.

Konrad

#16 lore raw

Re: [PATCH v2 4/7] thunderbolt: add platform NHI driver

Quoted 40 lines · Konrad Dybcio

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 21 lines · Chunfeng Yun

Historically, the Thunderbolt/USB4 Native Host Interface (NHI) controller has been exposed as a PCI device handled by drivers/thunderbolt/pci.c. However, some SoCs (such as MediaTek mt8901/mt8992) integrate the NHI as a memory-mapped platform device described via Device Tree or ACPI.

To support platform-attached NHI controllers:

Introduce platform.c to register a platform driver matching "usb4-nhi-platform" (OF) and "ACPI0015" (ACPI); Implement platform tb_nhi_ops hooks for pm, interrupts related;

Support an optional dedicated wake interrupt: on integrated SoCs, the MAC/PHY reside in a power domain whose clocks and power can be gated during sleep, preventing the primary NHI interrupt from acting as a wakeup source; so add an optional dedicated wakeup interrupt which comes from the always-on power domain.

Clean up the unused nhi_enable_int_throttling() prototype.

Quoted 12 lines

---
v2 changes:
* Added CONFIG_USB4_PLATFORM to build the platform driver as a separate
  module (thunderbolt_platform.ko), instead of statically embedding it
  into thunderbolt.o.
* Renamed plat.c to platform.c, renamed internal functions from nhi_plat_*
  to nhi_platform_*, and updated the Device Tree compatible string from
  "thunderbolt-platform" to "usb4-nhi-platform".

Quoted 3 lines

There are still no dt-bindings for this meaning it can't be merged. You also haven't answered Sven and mine's concerns about this being actually used.

Sorry, I missed your comments on v1 before sending out v2, already answered your comments.

Thanks

Quoted 2 lines

Konrad

#17 lore raw

Re: [PATCH v2 4/7] thunderbolt: add platform NHI driver

In reply to Chunfeng Yun
Quoted 97 lines · Chunfeng Yun

Historically, the Thunderbolt/USB4 Native Host Interface (NHI) controller has been exposed as a PCI device handled by drivers/thunderbolt/pci.c. However, some SoCs (such as MediaTek mt8901/mt8992) integrate the NHI as a memory-mapped platform device described via Device Tree or ACPI.

To support platform-attached NHI controllers:

Introduce platform.c to register a platform driver matching "usb4-nhi-platform" (OF) and "ACPI0015" (ACPI); Implement platform tb_nhi_ops hooks for pm, interrupts related;

Support an optional dedicated wake interrupt: on integrated SoCs, the MAC/PHY reside in a power domain whose clocks and power can be gated during sleep, preventing the primary NHI interrupt from acting as a wakeup source; so add an optional dedicated wakeup interrupt which comes from the always-on power domain.

Clean up the unused nhi_enable_int_throttling() prototype.

---
v2 changes:
* Added CONFIG_USB4_PLATFORM to build the platform driver as a separate module (thunderbolt_platform.ko), instead of statically embedding it into thunderbolt.o.
* Renamed plat.c to platform.c, renamed internal functions from nhi_plat_* to nhi_platform_*, and updated the Device Tree compatible string from "thunderbolt-platform" to "usb4-nhi-platform".
* Removed domain lifecycle changes (domain.c) and PCI driver cleanups (pci.c) from this patch, handled by previous patches.
* Squashed the optional dedicated wake IRQ support (previously a separate patch in v1) directly into this patch.
* Replaced the custom local ISR with the shared tb_nhi_isr(), adopted the renamed tb_nhi_probe() / tb_nhi_shutdown() / tb_nhi_pm_ops interfaces, and added -EPROBE_DEFER handling for the wake IRQ.

---
 drivers/thunderbolt/Kconfig    |   9 ++
 drivers/thunderbolt/Makefile   |   3 +
 drivers/thunderbolt/nhi.h      |   1 -
 drivers/thunderbolt/pci.c      |   1 +
 drivers/thunderbolt/platform.c | 172 +++++++++++++++++++++++++++++++++
 include/linux/thunderbolt.h    |   4 +
 6 files changed, 189 insertions(+), 1 deletion(-)
 create mode 100644 drivers/thunderbolt/platform.c
drivers/thunderbolt/Kconfig +9 -0
index 605af440457a..846ab51df7ab 100644
@@ -27,6 +27,15 @@ config USB4_PCI
 	  To compile this driver a module, choose M here. The module will be
 	  called thunderbolt_pci.
 
+config USB4_PLATFORM
+	tristate "Support for platform USB4 and Thunderbolt controllers"
+	help
+	  Say Y here to add support the USB4 and Thunderbolt host routers
+	  for a platform device on such as ARM64 SoCs.
+
+	  To compile this driver a module, choose M here. The module will be
+	  called thunderbolt_platform.
+
 config USB4_CONFIGFS
 	def_tristate USB4
 	depends on CONFIGFS_FS && !(USB4=y && CONFIGFS_FS=m)
drivers/thunderbolt/Makefile +3 -0
index a563bf2b0345..334fa4ebdfc8 100644
@@ -8,6 +8,9 @@ thunderbolt-objs += usb4_port.o nvm.o retimer.o quirks.o clx.o
 obj-${CONFIG_USB4_PCI} += thunderbolt_pci.o
 thunderbolt_pci-y := pci.o icm.o
 
+obj-${CONFIG_USB4_PLATFORM} += thunderbolt_platform.o
+thunderbolt_platform-y := platform.o
+
 thunderbolt-${CONFIG_ACPI} += acpi.o
 thunderbolt-$(CONFIG_DEBUG_FS) += debugfs.o
 thunderbolt-$(CONFIG_USB4_CONFIGFS) += configfs.o
drivers/thunderbolt/nhi.h +0 -1
index 65f9daf36068..ef5d24d81251 100644
@@ -27,7 +27,6 @@ enum nhi_mailbox_cmd {
 	NHI_MAILBOX_ALLOW_ALL_DEVS = 0x23,
 };
 
-void nhi_enable_int_throttling(struct tb_nhi *nhi);
 void nhi_disable_interrupts(struct tb_nhi *nhi);
 irqreturn_t tb_nhi_isr(int irq, void *data);
 irqreturn_t tb_ring_msix(int irq, void *data);
drivers/thunderbolt/pci.c +0 -0
index 9379c598a221..698f47ec63da 100644

drivers/thunderbolt/pci.c static struct pci_driver nhi_driver = { · line 739

Quoted 4 lines
drivers/thunderbolt/pci.c +1 -0
@@ -736,4 +736,5 @@ static struct pci_driver nhi_driver = {
 	.shutdown = nhi_pci_shutdown,
 	.driver.pm = &tb_nhi_pm_ops,
 };
+

I guess this is unintented change?

Quoted 19 lines
drivers/thunderbolt/pci.c +0 -0
 module_pci_driver(nhi_driver);
drivers/thunderbolt/platform.c new file +12 -0
new file mode 100644
index 000000000000..3562b6c7ea7d
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Thunderbolt driver - NHI driver (Platform bus specific implementation)
+ *
+ * Author: Chunfeng Yun <[email protected]>
+ */
+
+#include <linux/acpi.h>
+#include <linux/interrupt.h>
+#include <linux/errno.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>

drivers/thunderbolt/platform.c line 22

Quoted 10 lines
drivers/thunderbolt/platform.c new file +10 -0
+#include <linux/pm_runtime.h>
+#include <linux/pm_wakeirq.h>
+#include <linux/slab.h>
+
+#include "nhi.h"
+#include "tb.h"
+
+static int nhi_platform_init(struct tb_nhi *nhi)
+{
+	/* avoid device link fail for pcie tunnel */

Do you have the ACPI _DSD there in place? Then I don't think you need these. And "pcie" -> "PCIe" everywhere (except in code).

drivers/thunderbolt/platform.c line 28

Quoted 6 lines
drivers/thunderbolt/platform.c new file +6 -0
+	pm_runtime_set_active(nhi->dev);
+	pm_runtime_get_noresume(nhi->dev);
+	pm_runtime_enable(nhi->dev);
+
+	device_set_wakeup_capable(nhi->dev, true);
+	device_enable_async_suspend(nhi->dev);

I also suggest not to enable all the fancy power management until you have the basic stuff like tunneling fully functional.

Quoted 8 lines
drivers/thunderbolt/platform.c new file +8 -0
+
+	return 0;
+}
+
+static void nhi_platform_clear_wake_irq(void *dev)
+{
+	dev_pm_clear_wake_irq(dev);
+}

drivers/thunderbolt/platform.c line 46

Quoted 10 lines
drivers/thunderbolt/platform.c new file +10 -0
+
+static int nhi_platform_init_irq(struct tb_nhi *nhi)
+{
+	struct device *dev = nhi->dev;
+	int ret;
+
+	ret = devm_request_irq(dev, nhi->irq, tb_nhi_isr, IRQF_NO_SUSPEND,
+			       dev_name(dev), nhi);
+	if (ret)
+		return dev_err_probe(dev, ret, "request irq failed\n");

failed to request interrupt

Please be consistent with the rest of the driver.

drivers/thunderbolt/platform.c line 51

Quoted 5 lines
drivers/thunderbolt/platform.c new file +5 -0
+
+	if (nhi->wake_irq) {
+		ret = dev_pm_set_dedicated_wake_irq(dev, nhi->wake_irq);
+		if (ret) {
+			return dev_err_probe(dev, ret, "set wake irq %d failed\n", nhi->wake_irq);

Split this into 2 lines.

drivers/thunderbolt/platform.c line 54

Quoted 3 lines
drivers/thunderbolt/platform.c new file +3 -0
+		}
+
+		dev_info(dev, "wake irq %d\n", nhi->wake_irq);

Remove this. The driver should be silent when it works. You can add debug but I don't think this is useful.

drivers/thunderbolt/platform.c line 56

Quoted 2 lines
drivers/thunderbolt/platform.c new file +2 -0
+
+		ret = devm_add_action_or_reset(dev, nhi_platform_clear_wake_irq, dev);

Can you pass dev_pm_clear_wake_irq directly here?

drivers/thunderbolt/platform.c line 64

Quoted 8 lines
drivers/thunderbolt/platform.c new file +8 -0
+	}
+
+	return ret;
+}
+
+static void nhi_platform_exit(struct tb_nhi *nhi)
+{
+	devm_free_irq(nhi->dev, nhi->irq, nhi);

Isn't it released automatically?

Quoted 9 lines
drivers/thunderbolt/platform.c new file +9 -0
+	flush_work(&nhi->interrupt_work);
+
+	pm_runtime_put_noidle(nhi->dev);
+	pm_runtime_disable(nhi->dev);
+	pm_runtime_set_suspended(nhi->dev);
+}
+
+static const struct tb_nhi_ops nhi_platform_default_ops = {
+	.init = nhi_platform_init,

drivers/thunderbolt/platform.c line 83

Quoted 10 lines
drivers/thunderbolt/platform.c new file +10 -0
+	.shutdown = nhi_platform_exit,
+	.init_interrupts = nhi_platform_init_irq,
+};
+
+static int nhi_platform_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct tb_nhi *nhi;
+
+	nhi = devm_kzalloc(dev, sizeof(*nhi), GFP_KERNEL);

devm_kzalloc_obj()

Quoted 5 lines
drivers/thunderbolt/platform.c new file +5 -0
+	if (!nhi)
+		return -ENOMEM;
+
+	nhi->dev = dev;
+	nhi->ops = &nhi_platform_default_ops;

drivers/thunderbolt/platform.c line 98

Quoted 10 lines
drivers/thunderbolt/platform.c new file +10 -0
+
+	nhi->iobase = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(nhi->iobase))
+		return PTR_ERR(nhi->iobase);
+
+	nhi->irq = platform_get_irq(pdev, 0);
+	if (nhi->irq < 0)
+		return nhi->irq;
+
+	/* ignore error */

This should explain why it's okay to ignore the error.

Quoted 4 lines
drivers/thunderbolt/platform.c new file +4 -0
+	nhi->wake_irq = platform_get_irq_optional(pdev, 1);
+	if (nhi->wake_irq == -EPROBE_DEFER)
+		return nhi->wake_irq;
+	else if (nhi->wake_irq < 0)

drivers/thunderbolt/platform.c line 112

Quoted 10 lines
drivers/thunderbolt/platform.c new file +10 -0
+		nhi->wake_irq = 0;
+
+	return tb_nhi_probe(nhi);
+}
+
+static void nhi_platform_do_remove(struct platform_device *pdev, bool reset)
+{
+	struct device *dev = &pdev->dev;
+	struct tb *tb = platform_get_drvdata(pdev);
+	struct tb_nhi *nhi = tb->nhi;

Reverse-christmas tree if possible:

	struct tb *tb = platform_get_drvdata(pdev);
	struct device *dev = &pdev->dev;
	struct tb_nhi *nhi = tb->nhi;

drivers/thunderbolt/platform.c line 116

Quoted 4 lines
drivers/thunderbolt/platform.c new file +4 -0
+
+	/*
+	 * On system shutdown/reboot force a host router reset so the
+	 * CM asserts DPR on connected tbt3 devices before the router tree

Thunderbolt 3

Quoted 19 lines
drivers/thunderbolt/platform.c new file +19 -0
+	 * is removed (see tb_stop()).
+	 */
+	if (reset)
+		nhi->host_reset = true;
+
+	pm_runtime_get_sync(dev);
+	pm_runtime_dont_use_autosuspend(dev);
+
+	tb_domain_remove(tb);
+	wait_for_completion(&nhi->domain_released);
+	tb_nhi_shutdown(nhi);
+}
+
+static void nhi_platform_remove(struct platform_device *pdev)
+{
+	nhi_platform_do_remove(pdev, false);
+}
+
+static void nhi_platform_shutdown(struct platform_device *pdev)

drivers/thunderbolt/platform.c line 145

Quoted 10 lines
drivers/thunderbolt/platform.c new file +10 -0
+{
+	nhi_platform_do_remove(pdev, true);
+}
+
+
+#ifdef CONFIG_OF
+static const struct of_device_id nhi_platform_of_match[] = {
+	{ .compatible = "usb4-nhi-platform" },
+	{ }
+};

I think this was agreed to be dropped for now.

Quoted 51 lines
drivers/thunderbolt/platform.c new file +27 -0
+MODULE_DEVICE_TABLE(of, nhi_platform_of_match);
+#endif
+
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id nhi_platform_acpi_match[] = {
+	{ "ACPI0015", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, nhi_platform_acpi_match);
+#endif
+
+static struct platform_driver nhi_platform_driver = {
+	.probe = nhi_platform_probe,
+	.remove = nhi_platform_remove,
+	.shutdown = nhi_platform_shutdown,
+	.driver = {
+		.name = "thunderbolt",
+		.of_match_table = of_match_ptr(nhi_platform_of_match),
+		.acpi_match_table = ACPI_PTR(nhi_platform_acpi_match),
+		.pm = &tb_nhi_pm_ops,
+	},
+};
+
+module_platform_driver(nhi_platform_driver);
+MODULE_ALIAS("platform:thunderbolt");
+MODULE_DESCRIPTION("Thunderbolt/USB4 platform host interface driver");
+MODULE_LICENSE("GPL v2");
include/linux/thunderbolt.h +4 -0
index 57502da29080..72497acac254 100644
@@ -511,6 +511,8 @@ void tb_service_properties_changed(struct tb_service *svc);
  * @going_away: The host controller device is about to disappear so when
  *		this flag is set, avoid touching the hardware anymore.
  * @iommu_dma_protection: An IOMMU will isolate external-facing ports.
+ * @irq: interrupt number of NHI.
+ * @wake_irq: optional dedicated wakeup interrupt.
  * @interrupt_work: Work scheduled to handle ring interrupt when no
  *		    MSI-X is used.
  * @hop_count: Number of rings (end point hops) supported by NHI.
@@ -532,6 +534,8 @@ struct tb_nhi {
 	u32 *interrupt_mask;
 	bool going_away;
 	bool iommu_dma_protection;
+	int irq;
+	int wake_irq;
 	struct work_struct interrupt_work;
 	u32 hop_count;
 	unsigned long quirks;
Signature · 1 line
2.45.2
#18 lore raw

Re: [PATCH v2 4/7] thunderbolt: add platform NHI driver

Quoted 18 lines · Mika Westerberg
Quoted 10 lines · Chunfeng Yun


-void nhi_enable_int_throttling(struct tb_nhi *nhi); void nhi_disable_interrupts(struct tb_nhi *nhi); irqreturn_t tb_nhi_isr(int irq, void *data); irqreturn_t tb_ring_msix(int irq, void *data);

drivers/thunderbolt/pci.c +0 -0
index 9379c598a221..698f47ec63da 100644

drivers/thunderbolt/pci.c static struct pci_driver nhi_driver = { · line 739

Quoted 4 lines
drivers/thunderbolt/pci.c +1 -0
@@ -736,4 +736,5 @@ static struct pci_driver nhi_driver = {
  	.shutdown = nhi_pci_shutdown,
  	.driver.pm = &tb_nhi_pm_ops,
  };
+

I guess this is unintented change?

will drop it

Quoted 25 lines
Quoted 25 lines
drivers/thunderbolt/pci.c +0 -0
  module_pci_driver(nhi_driver);
drivers/thunderbolt/platform.c new file +3 -0
new file mode 100644
index 000000000000..3562b6c7ea7d
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Thunderbolt driver - NHI driver (Platform bus specific

implementation)
+ *
+ * Author: Chunfeng Yun <[email protected]>
+ */

drivers/thunderbolt/platform.c new file +10 -0
+
+#include <linux/acpi.h>
+#include <linux/interrupt.h>
+#include <linux/errno.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/pm_wakeirq.h>
+#include <linux/slab.h>
+
Quoted 8 lines

drivers/thunderbolt/platform.c line 22

Quoted 6 lines
drivers/thunderbolt/platform.c new file +6 -0
+#include "nhi.h"
+#include "tb.h"
+
+static int nhi_platform_init(struct tb_nhi *nhi)
+{
+	/* avoid device link fail for pcie tunnel */

Do you have the ACPI _DSD there in place?

Yes, we use the same uefi as WoA which pass Windows HLK and usb-if certitfication

Quoted 2 lines

Then I don't think you need
these. And "pcie" -> "PCIe" everywhere (except in code).

ACK

Quoted 11 lines

drivers/thunderbolt/platform.c line 28

Quoted 7 lines
drivers/thunderbolt/platform.c new file +6 -0
+	pm_runtime_set_active(nhi->dev);
+	pm_runtime_get_noresume(nhi->dev);
+	pm_runtime_enable(nhi->dev);
+
+	device_set_wakeup_capable(nhi->dev, true);
+	device_enable_async_suspend(nhi->dev);

I also suggest not to enable all the fancy power management until you have
the basic stuff like tunneling fully functional.

I'm not sure understand what you mean.

if you mean the function test:
I already test usb4net, usb3 tunnel, PCIe tunnel and dp tunnel data transfers, and also runtime suspend/resume and system suspend/resume.

if you mean when to enable pm:
do you mean enable pm at the enable of tb_nhi_probe()?

+ pm_runtime_set_active(nhi->dev);
+ pm_runtime_get_noresume(nhi->dev);
+ pm_runtime_enable(nhi->dev);

these three line shall be put before nhi_select_cm(), otherwise, it fail to link PCIe devices, and I will check it again.

+ device_set_wakeup_capable(nhi->dev, true);
+ device_enable_async_suspend(nhi->dev);

these two line can be put at the end of probe.

if you have any suggestions, please describe more details, I will try it.

Quoted 24 lines
Quoted 20 lines
drivers/thunderbolt/platform.c new file +15 -0
+
+	return 0;
+}
+
+static void nhi_platform_clear_wake_irq(void *dev)
+{
+	dev_pm_clear_wake_irq(dev);
+}
+
+static int nhi_platform_init_irq(struct tb_nhi *nhi)
+{
+	struct device *dev = nhi->dev;
+	int ret;
+
+	ret = devm_request_irq(dev, nhi->irq, tb_nhi_isr,

IRQF_NO_SUSPEND,

drivers/thunderbolt/platform.c new file +3 -0
+			       dev_name(dev), nhi);
+	if (ret)
+		return dev_err_probe(dev, ret, "request irq
Quoted 1 line

failed\n");

failed to request interrupt

Quoted 1 line

Please be consistent with the rest of the driver.

ACK

Quoted 10 lines
Quoted 8 lines
drivers/thunderbolt/platform.c new file +3 -0
+
+	if (nhi->wake_irq) {
+		ret = dev_pm_set_dedicated_wake_irq(dev, nhi-
Quoted 1 line

wake_irq);

drivers/thunderbolt/platform.c new file +2 -0
+		if (ret) {
+			return dev_err_probe(dev, ret, "set wake

irq %d failed\n", nhi->wake_irq);

Split this into 2 lines.

ACK

Quoted 8 lines

drivers/thunderbolt/platform.c line 54

Quoted 4 lines
drivers/thunderbolt/platform.c new file +3 -0
+		}
+
+		dev_info(dev, "wake irq %d\n", nhi->wake_irq);

Remove this. The driver should be silent when it works. You can add debug
but I don't think this is useful.

ACK

Quoted 6 lines
Quoted 4 lines
drivers/thunderbolt/platform.c new file +2 -0
+
+		ret = devm_add_action_or_reset(dev,

nhi_platform_clear_wake_irq, dev);

Can you pass dev_pm_clear_wake_irq directly here?

the parameter type do not match which cause build warning

kernel/mediatek/drivers/thunderbolt/platform.c:8:
kernel/mediatek/drivers/thunderbolt/platform.c: In function 'nhi_platform_init_irq':
kernel/mediatek/drivers/thunderbolt/platform.c:53:53: error: passing argument 2 of '__devm_add_action_or_reset' from incompatible pointer type [-Werror=incompatible-pointer-types]
53 | ret = devm_add_action_or_reset(dev,

dev_pm_clear_wake_irq, dev);
      |                                                    
^~~~~~~~~~~~~~~~~~~~~
      |                                                     |
      |                                                     void

(*)(struct device *) upstream/k7/kernel/mediatek/include/linux/device/devres.h:283:41: note:
in definition of macro 'devm_add_action_or_reset'
283 | __devm_add_action_or_reset(dev, action, data, #action)
| ^~~~~~
upstream/k7/kernel/mediatek/include/linux/device/devres.h:271:73: note:
expected 'void (*)(void *)' but argument is of type 'void (*)(struct device *)'
271 | static inline int __devm_add_action_or_reset(struct device
*dev, void (*action)(void *),

Quoted 11 lines

drivers/thunderbolt/platform.c line 64

Quoted 9 lines
drivers/thunderbolt/platform.c new file +8 -0
+	}
+
+	return ret;
+}
+
+static void nhi_platform_exit(struct tb_nhi *nhi)
+{
+	devm_free_irq(nhi->dev, nhi->irq, nhi);

Isn't it released automatically?

refer to nhi_pci_exit() which give the reason that avoid queuing the interrupt_work again, I will add a common in next version.

Quoted 14 lines
Quoted 14 lines
drivers/thunderbolt/platform.c new file +13 -0
+	flush_work(&nhi->interrupt_work);
+
+	pm_runtime_put_noidle(nhi->dev);
+	pm_runtime_disable(nhi->dev);
+	pm_runtime_set_suspended(nhi->dev);
+}
+
+static const struct tb_nhi_ops nhi_platform_default_ops = {
+	.init = nhi_platform_init,
+	.shutdown = nhi_platform_exit,
+	.init_interrupts = nhi_platform_init_irq,
+};
+
Quoted 8 lines

drivers/thunderbolt/platform.c line 83

Quoted 6 lines
drivers/thunderbolt/platform.c new file +6 -0
+static int nhi_platform_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct tb_nhi *nhi;
+
+	nhi = devm_kzalloc(dev, sizeof(*nhi), GFP_KERNEL);

devm_kzalloc_obj()

ACK

Quoted 10 lines
Quoted 10 lines
drivers/thunderbolt/platform.c new file +9 -0
+	if (!nhi)
+		return -ENOMEM;
+
+	nhi->dev = dev;
+	nhi->ops = &nhi_platform_default_ops;
+
+	nhi->iobase = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(nhi->iobase))
+		return PTR_ERR(nhi->iobase);
Quoted 8 lines

drivers/thunderbolt/platform.c line 98

Quoted 6 lines
drivers/thunderbolt/platform.c new file +6 -0
+
+	nhi->irq = platform_get_irq(pdev, 0);
+	if (nhi->irq < 0)
+		return nhi->irq;
+
+	/* ignore error */

This should explain why it's okay to ignore the error.

ACK, it is implementation specific, so make it optional

Quoted 10 lines
Quoted 10 lines
drivers/thunderbolt/platform.c new file +9 -0
+	nhi->wake_irq = platform_get_irq_optional(pdev, 1);
+	if (nhi->wake_irq == -EPROBE_DEFER)
+		return nhi->wake_irq;
+	else if (nhi->wake_irq < 0)
+		nhi->wake_irq = 0;
+
+	return tb_nhi_probe(nhi);
+}
+
Quoted 8 lines

drivers/thunderbolt/platform.c line 112

Quoted 6 lines

+static void nhi_platform_do_remove(struct platform_device *pdev, bool reset)

drivers/thunderbolt/platform.c new file +4 -0
+{
+	struct device *dev = &pdev->dev;
+	struct tb *tb = platform_get_drvdata(pdev);
+	struct tb_nhi *nhi = tb->nhi;

Reverse-christmas tree if possible:

ACK

Quoted 5 lines
	struct tb *tb = platform_get_drvdata(pdev);
	struct device *dev = &pdev->dev;
	struct tb_nhi *nhi = tb->nhi;
Quoted 8 lines
Quoted 6 lines
drivers/thunderbolt/platform.c new file +3 -0
+
+	/*
+	 * On system shutdown/reboot force a host router reset so

the

drivers/thunderbolt/platform.c new file +1 -0
+	 * CM asserts DPR on connected tbt3 devices before the

router tree

Thunderbolt 3

ACK

Quoted 24 lines
Quoted 24 lines
drivers/thunderbolt/platform.c new file +23 -0
+	 * is removed (see tb_stop()).
+	 */
+	if (reset)
+		nhi->host_reset = true;
+
+	pm_runtime_get_sync(dev);
+	pm_runtime_dont_use_autosuspend(dev);
+
+	tb_domain_remove(tb);
+	wait_for_completion(&nhi->domain_released);
+	tb_nhi_shutdown(nhi);
+}
+
+static void nhi_platform_remove(struct platform_device *pdev)
+{
+	nhi_platform_do_remove(pdev, false);
+}
+
+static void nhi_platform_shutdown(struct platform_device *pdev)
+{
+	nhi_platform_do_remove(pdev, true);
+}
+
Quoted 8 lines

drivers/thunderbolt/platform.c line 145

Quoted 6 lines
drivers/thunderbolt/platform.c new file +6 -0
+
+#ifdef CONFIG_OF
+static const struct of_device_id nhi_platform_of_match[] = {
+	{ .compatible = "usb4-nhi-platform" },
+	{ }
+};

I think this was agreed to be dropped for now.

will drop it

Thanks

Quoted 61 lines
Quoted 61 lines
drivers/thunderbolt/platform.c new file +18 -0
+MODULE_DEVICE_TABLE(of, nhi_platform_of_match);
+#endif
+
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id nhi_platform_acpi_match[] = {
+	{ "ACPI0015", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, nhi_platform_acpi_match);
+#endif
+
+static struct platform_driver nhi_platform_driver = {
+	.probe = nhi_platform_probe,
+	.remove = nhi_platform_remove,
+	.shutdown = nhi_platform_shutdown,
+	.driver = {
+		.name = "thunderbolt",
+		.of_match_table =

of_match_ptr(nhi_platform_of_match),

drivers/thunderbolt/platform.c new file +1 -0
+		.acpi_match_table =

ACPI_PTR(nhi_platform_acpi_match),

drivers/thunderbolt/platform.c new file +7 -0
+		.pm = &tb_nhi_pm_ops,
+	},
+};
+
+module_platform_driver(nhi_platform_driver);
+MODULE_ALIAS("platform:thunderbolt");
+MODULE_DESCRIPTION("Thunderbolt/USB4 platform host interface

driver");

drivers/thunderbolt/platform.c new file +1 -0
+MODULE_LICENSE("GPL v2");
include/linux/thunderbolt.h +0 -0
index 57502da29080..72497acac254 100644
@@ -511,6 +511,8 @@ void tb_service_properties_changed(struct
 tb_service *svc);
   * @going_away: The host controller device is about to disappear

so when
  * this flag is set, avoid touching the hardware
anymore.
  * @iommu_dma_protection: An IOMMU will isolate external-facing ports.
+ * @irq: interrupt number of NHI.
+ * @wake_irq: optional dedicated wakeup interrupt.
  * @interrupt_work: Work scheduled to handle ring interrupt when no
  *     MSI-X is used.
  * @hop_count: Number of rings (end point hops) supported by NHI.

include/linux/thunderbolt.h +2 -0
@@ -532,6 +534,8 @@ struct tb_nhi {
  	u32 *interrupt_mask;
  	bool going_away;
  	bool iommu_dma_protection;
+	int irq;
+	int wake_irq;
  	struct work_struct interrupt_work;
  	u32 hop_count;
  	unsigned long quirks;
Signature · 1 line
2.45.2
#19 lore raw

Re: [PATCH v2 4/7] thunderbolt: add platform NHI driver

Hi,

Quoted 91 lines · Chunfeng Yun (云春峰)
Quoted 18 lines · Mika Westerberg
Quoted 10 lines · Chunfeng Yun


-void nhi_enable_int_throttling(struct tb_nhi *nhi); void nhi_disable_interrupts(struct tb_nhi *nhi); irqreturn_t tb_nhi_isr(int irq, void *data); irqreturn_t tb_ring_msix(int irq, void *data);

drivers/thunderbolt/pci.c +0 -0
index 9379c598a221..698f47ec63da 100644

drivers/thunderbolt/pci.c static struct pci_driver nhi_driver = { · line 739

Quoted 4 lines
drivers/thunderbolt/pci.c +1 -0
@@ -736,4 +736,5 @@ static struct pci_driver nhi_driver = {
  	.shutdown = nhi_pci_shutdown,
  	.driver.pm = &tb_nhi_pm_ops,
  };
+

I guess this is unintented change?

will drop it

Quoted 25 lines
Quoted 25 lines
drivers/thunderbolt/pci.c +0 -0
  module_pci_driver(nhi_driver);
drivers/thunderbolt/platform.c new file +3 -0
new file mode 100644
index 000000000000..3562b6c7ea7d
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Thunderbolt driver - NHI driver (Platform bus specific

implementation)
+ *
+ * Author: Chunfeng Yun <[email protected]>
+ */

drivers/thunderbolt/platform.c new file +10 -0
+
+#include <linux/acpi.h>
+#include <linux/interrupt.h>
+#include <linux/errno.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/pm_wakeirq.h>
+#include <linux/slab.h>
+
Quoted 8 lines

drivers/thunderbolt/platform.c line 22

Quoted 6 lines
drivers/thunderbolt/platform.c new file +6 -0
+#include "nhi.h"
+#include "tb.h"
+
+static int nhi_platform_init(struct tb_nhi *nhi)
+{
+	/* avoid device link fail for pcie tunnel */

Do you have the ACPI _DSD there in place?

Yes, we use the same uefi as WoA which pass Windows HLK and usb-if certitfication

Quoted 2 lines

Then I don't think you need
these. And "pcie" -> "PCIe" everywhere (except in code).

ACK

Quoted 11 lines

drivers/thunderbolt/platform.c line 28

Quoted 7 lines
drivers/thunderbolt/platform.c new file +6 -0
+	pm_runtime_set_active(nhi->dev);
+	pm_runtime_get_noresume(nhi->dev);
+	pm_runtime_enable(nhi->dev);
+
+	device_set_wakeup_capable(nhi->dev, true);
+	device_enable_async_suspend(nhi->dev);

I also suggest not to enable all the fancy power management until you have
the basic stuff like tunneling fully functional.

I'm not sure understand what you mean.

if you mean the function test:
I already test usb4net, usb3 tunnel, PCIe tunnel and dp tunnel data transfers, and also runtime suspend/resume and system suspend/resume.

if you mean when to enable pm:
do you mean enable pm at the enable of tb_nhi_probe()?

drivers/thunderbolt/platform.c new file +3 -0
+	pm_runtime_set_active(nhi->dev);
+	pm_runtime_get_noresume(nhi->dev);
+	pm_runtime_enable(nhi->dev);

these three line shall be put before nhi_select_cm(), otherwise, it fail to link PCIe devices, and I will check it again.

drivers/thunderbolt/platform.c new file +2 -0
+	device_set_wakeup_capable(nhi->dev, true);
+	device_enable_async_suspend(nhi->dev);
Quoted 1 line

these two line can be put at the end of probe.

I meant device_enable_async_suspend() it's not stricly required and we don't do it elsewhere so I would leave it out now and then add it everywhere later.

Quoted 71 lines

if you have any suggestions, please describe more details, I will try it.

Quoted 24 lines
Quoted 20 lines
drivers/thunderbolt/platform.c new file +15 -0
+
+	return 0;
+}
+
+static void nhi_platform_clear_wake_irq(void *dev)
+{
+	dev_pm_clear_wake_irq(dev);
+}
+
+static int nhi_platform_init_irq(struct tb_nhi *nhi)
+{
+	struct device *dev = nhi->dev;
+	int ret;
+
+	ret = devm_request_irq(dev, nhi->irq, tb_nhi_isr,

IRQF_NO_SUSPEND,

drivers/thunderbolt/platform.c new file +3 -0
+			       dev_name(dev), nhi);
+	if (ret)
+		return dev_err_probe(dev, ret, "request irq
Quoted 1 line

failed\n");

failed to request interrupt

Quoted 1 line

Please be consistent with the rest of the driver.

ACK

Quoted 10 lines
Quoted 8 lines
drivers/thunderbolt/platform.c new file +3 -0
+
+	if (nhi->wake_irq) {
+		ret = dev_pm_set_dedicated_wake_irq(dev, nhi-
Quoted 1 line

wake_irq);

drivers/thunderbolt/platform.c new file +2 -0
+		if (ret) {
+			return dev_err_probe(dev, ret, "set wake

irq %d failed\n", nhi->wake_irq);

Split this into 2 lines.

ACK

Quoted 8 lines

drivers/thunderbolt/platform.c line 54

Quoted 4 lines
drivers/thunderbolt/platform.c new file +3 -0
+		}
+
+		dev_info(dev, "wake irq %d\n", nhi->wake_irq);

Remove this. The driver should be silent when it works. You can add debug
but I don't think this is useful.

ACK

Quoted 6 lines
Quoted 4 lines
drivers/thunderbolt/platform.c new file +2 -0
+
+		ret = devm_add_action_or_reset(dev,

nhi_platform_clear_wake_irq, dev);

Can you pass dev_pm_clear_wake_irq directly here?

the parameter type do not match which cause build warning

kernel/mediatek/drivers/thunderbolt/platform.c:8:
kernel/mediatek/drivers/thunderbolt/platform.c: In function 'nhi_platform_init_irq':
kernel/mediatek/drivers/thunderbolt/platform.c:53:53: error: passing argument 2 of '__devm_add_action_or_reset' from incompatible pointer type [-Werror=incompatible-pointer-types]
53 | ret = devm_add_action_or_reset(dev,

dev_pm_clear_wake_irq, dev);
      |                                                    
^~~~~~~~~~~~~~~~~~~~~
      |                                                     |
      |                                                     void
Quoted 10 lines

(*)(struct device *) upstream/k7/kernel/mediatek/include/linux/device/devres.h:283:41: note:
in definition of macro 'devm_add_action_or_reset'
283 | __devm_add_action_or_reset(dev, action, data, #action)
| ^~~~~~
upstream/k7/kernel/mediatek/include/linux/device/devres.h:271:73: note:
expected 'void (*)(void *)' but argument is of type 'void (*)(struct device *)'
271 | static inline int __devm_add_action_or_reset(struct device
*dev, void (*action)(void *),

Oh right it has different prototyp so you need the wrapper. Then it's okay.

#20 lore raw

Re: [PATCH v2 4/7] thunderbolt: add platform NHI driver

Quoted 97 lines · On 二, 2026-11-17 at 13:52 +0100, [email protected] wrote:

Hi,

Quoted 94 lines · Chunfeng Yun (云春峰)
Quoted 10 lines · Mika Westerberg
Quoted 9 lines · Chunfeng Yun


-void nhi_enable_int_throttling(struct tb_nhi *nhi); void nhi_disable_interrupts(struct tb_nhi *nhi); irqreturn_t tb_nhi_isr(int irq, void *data); irqreturn_t tb_ring_msix(int irq, void *data);

drivers/thunderbolt/pci.c +0 -1
index 9379c598a221..698f47ec63da 100644
--- a/drivers/thunderbolt/pci.c
Quoted 9 lines

drivers/thunderbolt/pci.c static struct pci_driver nhi_driver = { · line 739

Quoted 6 lines

+++ b/drivers/thunderbolt/pci.c

drivers/thunderbolt/pci.c +1 -0
@@ -736,4 +736,5 @@ static struct pci_driver nhi_driver = {
  	.shutdown = nhi_pci_shutdown,
  	.driver.pm = &tb_nhi_pm_ops,
  };
+

I guess this is unintented change?

will drop it

Quoted 25 lines
Quoted 25 lines
drivers/thunderbolt/pci.c +0 -0
  module_pci_driver(nhi_driver);
drivers/thunderbolt/platform.c new file +3 -0
new file mode 100644
index 000000000000..3562b6c7ea7d
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Thunderbolt driver - NHI driver (Platform bus specific

implementation)
+ *
+ * Author: Chunfeng Yun <[email protected]>
+ */

drivers/thunderbolt/platform.c new file +10 -0
+
+#include <linux/acpi.h>
+#include <linux/interrupt.h>
+#include <linux/errno.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/pm_wakeirq.h>
+#include <linux/slab.h>
+
Quoted 8 lines

drivers/thunderbolt/platform.c line 22

Quoted 6 lines
drivers/thunderbolt/platform.c new file +6 -0
+#include "nhi.h"
+#include "tb.h"
+
+static int nhi_platform_init(struct tb_nhi *nhi)
+{
+	/* avoid device link fail for pcie tunnel */

Do you have the ACPI _DSD there in place?

Yes, we use the same uefi as WoA which pass Windows HLK and usb-if certitfication

Quoted 2 lines

Then I don't think you need
these. And "pcie" -> "PCIe" everywhere (except in code).

ACK

Quoted 12 lines

drivers/thunderbolt/platform.c line 28

Quoted 7 lines
drivers/thunderbolt/platform.c new file +6 -0
+	pm_runtime_set_active(nhi->dev);
+	pm_runtime_get_noresume(nhi->dev);
+	pm_runtime_enable(nhi->dev);
+
+	device_set_wakeup_capable(nhi->dev, true);
+	device_enable_async_suspend(nhi->dev);

I also suggest not to enable all the fancy power management until you
have
the basic stuff like tunneling fully functional.

I'm not sure understand what you mean.

if you mean the function test:
I already test usb4net, usb3 tunnel, PCIe tunnel and dp tunnel data transfers, and also runtime suspend/resume and system suspend/resume.

if you mean when to enable pm:
do you mean enable pm at the enable of tb_nhi_probe()?

drivers/thunderbolt/platform.c new file +3 -0
+	pm_runtime_set_active(nhi->dev);
+	pm_runtime_get_noresume(nhi->dev);
+	pm_runtime_enable(nhi->dev);

these three line shall be put before nhi_select_cm(), otherwise, it fail to link PCIe devices, and I will check it again.

drivers/thunderbolt/platform.c new file +2 -0
+	device_set_wakeup_capable(nhi->dev, true);
+	device_enable_async_suspend(nhi->dev);
Quoted 6 lines
Quoted 1 line

these two line can be put at the end of probe.

I meant device_enable_async_suspend() it's not stricly required and we
don't do it elsewhere so I would leave it out now and then add it everywhere later.

I look at the PCI core code, seems it already enables async suspend for every PCI device during device enumeration by default.

see: pci_pm_init() (drivers/pci/pci.c)

Unlike the PCI bus, the platform bus does not automatically enable it for platform devices, but for usb devices, usually enable it because the standardized tree topology with well-defined dependencies.

Due to we explicitly create dev-link with xHCI/PCIe controller devices, it is safe to enable it, then keep the same way as thunderbolt/pci.c does.

Thanks

Quoted 9 lines
Quoted 9 lines

if you have any suggestions, please describe more details, I will try
it.

Quoted 3 lines
Quoted 3 lines
#21 lore raw

Re: [PATCH v2 4/7] thunderbolt: add platform NHI driver

Hi,

Quoted 15 lines · Chunfeng Yun (云春峰)
Quoted 9 lines
Quoted 4 lines
drivers/thunderbolt/platform.c new file +2 -0
+	device_set_wakeup_capable(nhi->dev, true);
+	device_enable_async_suspend(nhi->dev);

these two line can be put at the end of probe.

I meant device_enable_async_suspend() it's not stricly required and we
don't do it elsewhere so I would leave it out now and then add it everywhere later.

I look at the PCI core code, seems it already enables async suspend for every PCI device during device enumeration by default.

see: pci_pm_init() (drivers/pci/pci.c)

Quoted 7 lines

Unlike the PCI bus, the platform bus does not automatically enable it for platform devices, but for usb devices, usually enable it because the standardized tree topology with well-defined dependencies.

Due to we explicitly create dev-link with xHCI/PCIe controller devices, it is safe to enable it, then keep the same way as thunderbolt/pci.c does.

Okay works for me then.

#22 lore raw

PATCH v2 5/7 thunderbolt: increase the lane adapter link-up timeout value

In reply to Chunfeng Yun

when plug into a USB3 device into USB4 hub's downstream facing port to trigger usb4 driver wakeup, encounter the lane link up timeout issue, then cause usb3 hub disconnect:

usb4_hi NVDA8100:00: 0:1: failed to reach state TB_PORT_UP. Ignoring port... usb4_hi NVDA8100:00: 0:1: lost during suspend, disconnecting usb4_hi NVDA8100:00: 0:4 <-> 1:20 (USB3): deactivating
usb4_hi NVDA8100:00: deactivating USB3 Down path from 0:4 to 1:20 usb4_hi NVDA8100:00: deactivating USB3 Up path from 1:20 to 0:4
...
thunderbolt 0-1: device disconnected
usb 2-1: USB disconnect, device number 10

Completes link training at ~1.48s (with two retimer) and transitions to TB_PORT_UP after change the timeout to 2s;

In the USB4 spec, Phase 5 (Link Equalization) alone is allowed up to 1000 ms. When add tPhase2~4 (200 ms), and retimer transaction delays (tCmdResponse = 50 ms), the physical link is allowed by spec to take 1200 ms to 1500 ms+ to complete initialization.

---
v2: change timeout from 2.5s to 2s

---
 drivers/thunderbolt/switch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/thunderbolt/switch.c +2 -2
index 7ff3da79da76..7daee83c7ed8 100644
@@ -486,7 +486,7 @@ int tb_port_state(struct tb_port *port)
  * @port: Port to wait
  * @wait_if_unplugged: Wait also when port is unplugged
  *
- * Wait up to 1 second for a port to reach state TB_PORT_UP. If
+ * Wait up to 2 seconds for a port to reach state TB_PORT_UP. If
  * wait_if_unplugged is set then we also wait if the port is in state
  * TB_PORT_UNPLUGGED (it takes a while for the device to be registered after
  * switch resume). Otherwise we only wait if a device is registered but the link
@@ -500,7 +500,7 @@ int tb_port_state(struct tb_port *port)
  */
 int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
 {
-	int retries = 10;
+	int retries = 20;
 	int state;
 	if (!port->cap_phy) {
 		tb_port_WARN(port, "does not have PHY\n");
Signature · 1 line
2.45.2
#23 lore raw

Re: [PATCH v2 5/7] thunderbolt: increase the lane adapter link-up timeout value

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] thunderbolt: stale timeout in tb_wait_for_port() Return kernel-doc --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] thunderbolt: stale timeout in tb_wait_for_port() Return kernel-doc
--

commit 129c5b50481921f9094356b0de883693a15e937e
Author: Chunfeng Yun <[email protected]>

thunderbolt: increase the lane adapter link-up timeout value

This commit increases the retry count in tb_wait_for_port() from 10 to 20, extending the timeout for a port to reach TB_PORT_UP from 1 second to 2 seconds.

Quoted 14 lines
drivers/thunderbolt/switch.c +1 -1
index 7ff3da79da763..7daee83c7ed80 100644
@@ -486,7 +486,7 @@ int tb_port_state(struct tb_port *port)
  * @port: Port to wait
  * @wait_if_unplugged: Wait also when port is unplugged
  *
- * Wait up to 1 second for a port to reach state TB_PORT_UP. If
+ * Wait up to 2 seconds for a port to reach state TB_PORT_UP. If
  * wait_if_unplugged is set then we also wait if the port is in state
  * TB_PORT_UNPLUGGED (it takes a while for the device to be registered after
  * switch resume). Otherwise we only wait if a device is registered but the link

drivers/thunderbolt/switch.c int tb_port_state(struct tb_port *port) · line 506

Quoted 8 lines
drivers/thunderbolt/switch.c +1 -1
@@ -500,7 +500,7 @@ int tb_port_state(struct tb_port *port)
  */
 int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
 {
-	int retries = 10;
+	int retries = 20;
 	int state;
 	if (!port->cap_phy) {
 		tb_port_WARN(port, "does not have PHY\n");

[Severity: Low]
Should the Return section of the tb_wait_for_port() kernel-doc comment also be updated from "within one second" to two seconds?

drivers/thunderbolt/switch.c:
* Return:
* * %0 - If the port is not connected or failed to reach
* state %TB_PORT_UP within one second.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#24 lore raw

Re: [PATCH v2 5/7] thunderbolt: increase the lane adapter link-up timeout value

Quoted 39 lines · On 二, 2026-11-10 at 11:55 +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] thunderbolt: stale timeout in tb_wait_for_port() Return kernel-doc
--

commit 129c5b50481921f9094356b0de883693a15e937e
Author: Chunfeng Yun <[email protected]>

thunderbolt: increase the lane adapter link-up timeout value

This commit increases the retry count in tb_wait_for_port() from 10 to 20,
extending the timeout for a port to reach TB_PORT_UP from 1 second to 2 seconds.

Quoted 23 lines
drivers/thunderbolt/switch.c +1 -1
index 7ff3da79da763..7daee83c7ed80 100644
@@ -486,7 +486,7 @@ int tb_port_state(struct tb_port *port)
   * @port: Port to wait
   * @wait_if_unplugged: Wait also when port is unplugged
   *
- * Wait up to 1 second for a port to reach state TB_PORT_UP. If
+ * Wait up to 2 seconds for a port to reach state TB_PORT_UP. If
   * wait_if_unplugged is set then we also wait if the port is in

state
  * TB_PORT_UNPLUGGED (it takes a while for the device to be registered after
  * switch resume). Otherwise we only wait if a device is registered but the link

drivers/thunderbolt/switch.c +1 -1
@@ -500,7 +500,7 @@ int tb_port_state(struct tb_port *port)
   */
  int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
  {
-	int retries = 10;
+	int retries = 20;
Quoted 8 lines

drivers/thunderbolt/switch.c int tb_port_state(struct tb_port *port) · line 506

Quoted 3 lines
drivers/thunderbolt/switch.c +0 -0
  	int state;
  	if (!port->cap_phy) {
  		tb_port_WARN(port, "does not have PHY\n");

[Severity: Low]
Should the Return section of the tb_wait_for_port() kernel-doc comment also
be updated from "within one second" to two seconds?

Sure, will modify it

Quoted 6 lines

drivers/thunderbolt/switch.c:
 * Return:
 * * %0 - If the port is not connected or failed to reach *   state %TB_PORT_UP within one second.

#25 lore raw

Re: [PATCH v2 5/7] thunderbolt: increase the lane adapter link-up timeout value

In reply to Chunfeng Yun
Quoted 2 lines · Chunfeng Yun

when plug into a USB3 device into USB4 hub's downstream facing port to trigger usb4 driver wakeup, encounter the lane link up timeout

USB4

Quoted 1 line

issue, then cause usb3 hub disconnect:

USB3

Everywhere.

Quoted 2 lines

usb4_hi NVDA8100:00: 0:1: failed to reach state TB_PORT_UP. Ignoring port...

What's usb4_hi?

Quoted 8 lines

usb4_hi NVDA8100:00: 0:1: lost during suspend, disconnecting usb4_hi NVDA8100:00: 0:4 <-> 1:20 (USB3): deactivating usb4_hi NVDA8100:00: deactivating USB3 Down path from 0:4 to 1:20 usb4_hi NVDA8100:00: deactivating USB3 Up path from 1:20 to 0:4
...
thunderbolt 0-1: device disconnected
usb 2-1: USB disconnect, device number 10

Quoted 7 lines

Completes link training at ~1.48s (with two retimer) and transitions to TB_PORT_UP after change the timeout to 2s;

In the USB4 spec, Phase 5 (Link Equalization) alone is allowed up to 1000 ms. When add tPhase2~4 (200 ms), and retimer transaction delays (tCmdResponse = 50 ms), the physical link is allowed by spec to take 1200 ms to 1500 ms+ to complete initialization.

Okay that makes sense.

Quoted 31 lines

---
v2: change timeout from 2.5s to 2s

---
 drivers/thunderbolt/switch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/thunderbolt/switch.c +2 -2
index 7ff3da79da76..7daee83c7ed8 100644
@@ -486,7 +486,7 @@ int tb_port_state(struct tb_port *port)
  * @port: Port to wait
  * @wait_if_unplugged: Wait also when port is unplugged
  *
- * Wait up to 1 second for a port to reach state TB_PORT_UP. If
+ * Wait up to 2 seconds for a port to reach state TB_PORT_UP. If
  * wait_if_unplugged is set then we also wait if the port is in state
  * TB_PORT_UNPLUGGED (it takes a while for the device to be registered after
  * switch resume). Otherwise we only wait if a device is registered but the link
@@ -500,7 +500,7 @@ int tb_port_state(struct tb_port *port)
  */
 int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
 {
-	int retries = 10;
+	int retries = 20;
 	int state;
 	if (!port->cap_phy) {
 		tb_port_WARN(port, "does not have PHY\n");
Signature · 1 line
2.45.2
#26 lore raw

Re: [PATCH v2 5/7] thunderbolt: increase the lane adapter link-up timeout value

Quoted 5 lines · Mika Westerberg
Quoted 2 lines · Chunfeng Yun

when plug into a USB3 device into USB4 hub's downstream facing port to trigger usb4 driver wakeup, encounter the lane link up timeout

USB4

ACK

Quoted 6 lines
Quoted 2 lines

issue, then cause usb3 hub disconnect:

USB3

Everywhere.

OK

Quoted 6 lines
Quoted 4 lines

usb4_hi NVDA8100:00: 0:1: failed to reach state TB_PORT_UP. Ignoring port...

What's usb4_hi?

Sorry, forget update logs, it is the log from the draft usb4 platform driver to test functions which change the driver name as 'usb4_hi', I will reproduce it and get new logs.

Thanks

Quoted 58 lines
Quoted 13 lines

usb4_hi NVDA8100:00: 0:1: lost during suspend, disconnecting usb4_hi NVDA8100:00: 0:4 <-> 1:20 (USB3): deactivating usb4_hi NVDA8100:00: deactivating USB3 Down path from 0:4 to 1:20 usb4_hi NVDA8100:00: deactivating USB3 Up path from 1:20 to 0:4
...
thunderbolt 0-1: device disconnected
usb 2-1: USB disconnect, device number 10

Completes link training at ~1.48s (with two retimer) and transitions
to TB_PORT_UP after change the timeout to 2s;

Quoted 7 lines

In the USB4 spec, Phase 5 (Link Equalization) alone is allowed up to
1000 ms. When add tPhase2~4 (200 ms), and retimer transaction delays
(tCmdResponse = 50 ms), the physical link is allowed by spec to take
1200 ms to 1500 ms+ to complete initialization.

Okay that makes sense.

Quoted 35 lines

---
v2: change timeout from 2.5s to 2s
---
 drivers/thunderbolt/switch.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/thunderbolt/switch.c +1 -1
index 7ff3da79da76..7daee83c7ed8 100644
@@ -486,7 +486,7 @@ int tb_port_state(struct tb_port *port)
   * @port: Port to wait
   * @wait_if_unplugged: Wait also when port is unplugged
   *
- * Wait up to 1 second for a port to reach state TB_PORT_UP. If
+ * Wait up to 2 seconds for a port to reach state TB_PORT_UP. If
   * wait_if_unplugged is set then we also wait if the port is in

state
  * TB_PORT_UNPLUGGED (it takes a while for the device to be registered after
  * switch resume). Otherwise we only wait if a device is registered but the link

drivers/thunderbolt/switch.c +1 -1
@@ -500,7 +500,7 @@ int tb_port_state(struct tb_port *port)
   */
  int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
  {
-	int retries = 10;
+	int retries = 20;
  	int state;
  	if (!port->cap_phy) {
  		tb_port_WARN(port, "does not have PHY\n");
Signature · 1 line
2.45.2
#27 lore raw

PATCH v2 6/7 thunderbolt: decouple the waiting time of TB_PORT_UNPLUGGED and TB_PORT_UP

In reply to Chunfeng Yun

When usb4 is woke up by device disconnect, no need wait for 2s, usually the phase2~4 takes at most about 200ms, and enters to TB_PORT_CONNECTING, if it is still in TB_PORT_UNPLUGGED after 400ms, treat it as disconnected.

---
new changes

---
 drivers/thunderbolt/switch.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/thunderbolt/switch.c +5 -3
index 7daee83c7ed8..e12546bfb869 100644
@@ -489,8 +489,9 @@ int tb_port_state(struct tb_port *port)
  * Wait up to 2 seconds for a port to reach state TB_PORT_UP. If
  * wait_if_unplugged is set then we also wait if the port is in state
  * TB_PORT_UNPLUGGED (it takes a while for the device to be registered after
- * switch resume). Otherwise we only wait if a device is registered but the link
- * has not yet been established.
+ * switch resume, Wait at most 400 ms for link to start connecting,
+ * if timeout, means the device is disconnected). Otherwise we only wait
+ * if a device is registered but the link has not yet been established.
  *
  * Return:
  * * %0 - If the port is not connected or failed to reach
@@ -501,6 +502,7 @@ int tb_port_state(struct tb_port *port)
 int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
 {
 	int retries = 20;
+	int unplugged_retries = 4;
 	int state;
 	if (!port->cap_phy) {
 		tb_port_WARN(port, "does not have PHY\n");
@@ -519,7 +521,7 @@ int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
 			return 0;
 
 		case TB_PORT_UNPLUGGED:
-			if (wait_if_unplugged) {
+			if (wait_if_unplugged && unplugged_retries--) {
 				/* used during resume */
 				tb_port_dbg(port,
 					    "is unplugged (state: 7), retrying...\n");
Signature · 1 line
2.45.2
#28 lore raw

Re: [PATCH v2 6/7] thunderbolt: decouple the waiting time of TB_PORT_UNPLUGGED and TB_PORT_UP

Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

When usb4 is woke up by device disconnect, no need wait for 2s, usually the phase2~4 takes at most about 200ms, and enters to TB_PORT_CONNECTING, if it is still in TB_PORT_UNPLUGGED after 400ms, treat it as disconnected.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#29 lore raw

Re: [PATCH v2 6/7] thunderbolt: decouple the waiting time of TB_PORT_UNPLUGGED and TB_PORT_UP

In reply to Chunfeng Yun
Quoted 17 lines · Chunfeng Yun

When usb4 is woke up by device disconnect, no need wait for 2s, usually the phase2~4 takes at most about 200ms, and enters to TB_PORT_CONNECTING, if it is still in TB_PORT_UNPLUGGED after 400ms, treat it as disconnected.

---
new changes

---
 drivers/thunderbolt/switch.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/thunderbolt/switch.c +0 -0
index 7daee83c7ed8..e12546bfb869 100644

drivers/thunderbolt/switch.c int tb_port_state(struct tb_port *port) · line 492

Quoted 6 lines
drivers/thunderbolt/switch.c +1 -2
@@ -489,8 +489,9 @@ int tb_port_state(struct tb_port *port)
  * Wait up to 2 seconds for a port to reach state TB_PORT_UP. If
  * wait_if_unplugged is set then we also wait if the port is in state
  * TB_PORT_UNPLUGGED (it takes a while for the device to be registered after
- * switch resume). Otherwise we only wait if a device is registered but the link
- * has not yet been established.
+ * switch resume, Wait at most 400 ms for link to start connecting,

router

drivers/thunderbolt/switch.c int tb_port_state(struct tb_port *port) · line 505

Quoted 10 lines
drivers/thunderbolt/switch.c +3 -0
+ * if timeout, means the device is disconnected). Otherwise we only wait
+ * if a device is registered but the link has not yet been established.
  *
  * Return:
  * * %0 - If the port is not connected or failed to reach
@@ -501,6 +502,7 @@ int tb_port_state(struct tb_port *port)
 int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
 {
 	int retries = 20;
+	int unplugged_retries = 4;

Reverse-christmas tree

Quoted 14 lines
drivers/thunderbolt/switch.c +1 -1
 	int state;
 	if (!port->cap_phy) {
 		tb_port_WARN(port, "does not have PHY\n");
@@ -519,7 +521,7 @@ int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
 			return 0;
 
 		case TB_PORT_UNPLUGGED:
-			if (wait_if_unplugged) {
+			if (wait_if_unplugged && unplugged_retries--) {
 				/* used during resume */
 				tb_port_dbg(port,
 					    "is unplugged (state: 7), retrying...\n");
Signature · 1 line
2.45.2
#30 lore raw

Re: [PATCH v2 6/7] thunderbolt: decouple the waiting time of TB_PORT_UNPLUGGED and TB_PORT_UP

Quoted 24 lines · Mika Westerberg
Quoted 23 lines · Chunfeng Yun

When usb4 is woke up by device disconnect, no need wait for 2s, usually the phase2~4 takes at most about 200ms, and enters to TB_PORT_CONNECTING, if it is still in TB_PORT_UNPLUGGED after 400ms,
treat it as disconnected.

---
new changes
---
 drivers/thunderbolt/switch.c | 8 +++++---

 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/thunderbolt/switch.c +0 -0
index 7daee83c7ed8..e12546bfb869 100644
@@ -489,8 +489,9 @@ int tb_port_state(struct tb_port *port)
   * Wait up to 2 seconds for a port to reach state TB_PORT_UP. If
   * wait_if_unplugged is set then we also wait if the port is in

state
  * TB_PORT_UNPLUGGED (it takes a while for the device to be

Quoted 8 lines
Quoted 6 lines

registered after
- * switch resume). Otherwise we only wait if a device is registered but the link
- * has not yet been established.
+ * switch resume, Wait at most 400 ms for link to start connecting,

router

ACK

Quoted 15 lines

drivers/thunderbolt/switch.c int tb_port_state(struct tb_port *port) · line 505

Quoted 13 lines

+ * if timeout, means the device is disconnected). Otherwise we only wait
+ * if a device is registered but the link has not yet been established.
  *
  * Return:
  * * %0 - If the port is not connected or failed to reach

drivers/thunderbolt/switch.c +1 -0
@@ -501,6 +502,7 @@ int tb_port_state(struct tb_port *port)
  int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
  {
  	int retries = 20;
+	int unplugged_retries = 4;

Reverse-christmas tree

ACK

Thanks

Quoted 18 lines
Quoted 18 lines
drivers/thunderbolt/switch.c +0 -0
  	int state;
  	if (!port->cap_phy) {
  		tb_port_WARN(port, "does not have PHY\n");
@@ -519,7 +521,7 @@ int tb_wait_for_port(struct tb_port *port, bool
 wait_if_unplugged)
  			return 0;


  case TB_PORT_UNPLUGGED:

drivers/thunderbolt/switch.c +1 -1
-			if (wait_if_unplugged) {
+			if (wait_if_unplugged &&

unplugged_retries--) {
  /* used during resume */ tb_port_dbg(port,
      "is unplugged (state:
7), retrying...\n");

Signature · 1 line
2.45.2
#31 lore raw

PATCH v2 7/7 thunderbolt: prevent pcie tunnel activation/teardown warnings

In reply to Chunfeng Yun

When usb4 enter sleep mode, echo 1 to authorized of sysfile, will wakeup usb4 driver, but fail to create pcie tunnel, cause the warning due to a race condition between router disconnect during resume and user authorization

[  278.831186] usb4_hi NVDA8100:00: 0:1: is unplugged (state: 7), retrying...
[  278.943031] usb4_hi NVDA8100:00: 0:1: failed to reach state TB_PORT_UP. Ignoring port...
[  278.951125] usb4_hi NVDA8100:00: 0:1: lost during suspend, disconnecting
...
[  279.013763] usb4_hi NVDA8100:00: 0:7 <-> 1:9 (PCI): activating
[  279.019587] usb4_hi NVDA8100:00: activating PCIe Down path from 0:7 to 1:9
[  279.026468] usb4_hi NVDA8100:00: 1:1: Writing hop 1
[  279.031335] usb4_hi NVDA8100:00: 1:1:  In HopID: 8 => Out port: 9 Out HopID: 8
[  279.038546] usb4_hi NVDA8100:00: 1:1:   Weight: 1 Priority: 3 Credits: 32 Drop: 0 PM: 0
[  279.046536] usb4_hi NVDA8100:00: 1:1:    Counter enabled: 0 Counter index: 2047
[  279.053834] usb4_hi NVDA8100:00: 1:1:   Flow Control (In/Eg): 1/0 Shared Buffer (In/Eg): 0/0
[  279.062259] usb4_hi NVDA8100:00: 1:1:   Unknown1: 0x0 Unknown2: 0x0 Unknown3: 0x0
[  279.069730] ------------[ cut here ]------------
[  279.074335] usb4_hi NVDA8100:00: PCIe Down path activation failed
[  279.080426] WARNING: CPU: 5 PID: 2433 at drivers/thunderbolt/path.c:587 tb_path_activate+0x1a4/0x5b0
...
[  279.220285] Call trace:
[  279.222722]  tb_path_activate+0x1a4/0x5b0 (P)
[  279.227068]  tb_tunnel_activate+0x140/0x498
[  279.231241]  tb_tunnel_pci+0x180/0x490
[  279.234980]  tb_domain_approve_switch+0x74/0xb0
[  279.239500]  authorized_store+0x214/0x270
[  279.243498]  dev_attr_store+0x20/0x70
...
[  279.288888] ---[ end trace 0000000000000000 ]---
[  279.293497] usb4_hi NVDA8100:00: 0:7 <-> 1:9 (PCI): activation failed

When usb4 enter sleep mode, echo 0 to authorized of sysfile, will wakeup usb4 driver, but fail to disconnect pcie due to the PCIe tunnel had already been torn down and freed if the port is fail to resume,

[  545.887822] usb4_hi NVDA8100:00: 0:1: is unplugged (state: 7), retrying...
[  545.998689] usb4_hi NVDA8100:00: 0:1: failed to reach state TB_PORT_UP. Ignoring port...
[  546.006778] usb4_hi NVDA8100:00: 0:1: lost during suspend, disconnecting
[  546.013474] usb4_hi NVDA8100:00: 0:4 <-> 1:16 (USB3): deactivating
[  546.020449] usb4_hi NVDA8100:00: deactivating USB3 Down path from 0:4 to 1:16
[  546.027959] usb4_hi NVDA8100:00: deactivating USB3 Up path from 1:16 to 0:4
[  546.035649] usb4_hi NVDA8100:00: 0:7 <-> 1:9 (PCI): deactivating
[  546.042463] usb4_hi NVDA8100:00: deactivating PCIe Down path from 0:7 to 1:9
[  546.050320] usb4_hi NVDA8100:00: deactivating PCIe Up path from 1:9 to 0:7
[  546.057790] usb4_hi NVDA8100:00: 0: TMU: mode change off -> bi-directional, HiFi requested
[  546.067910] usb4_hi NVDA8100:00: 0: TMU: mode set to: bi-directional, HiFi
[  546.076120] usb4_hi NVDA8100:00: 0:1: total credits changed 66 -> 66
[  546.082844] usb4_hi NVDA8100:00: 1: link width set to symmetric, dual lanes
[  546.089815] ------------[ cut here ]------------
[  546.094420] WARNING: CPU: 7 PID: 2433 at drivers/thunderbolt/tb.c:2245 tb_disconnect_pci+0x108/0x120
...
[  546.238810] Call trace:
[  546.241246]  tb_disconnect_pci+0x108/0x120 (P)
[  546.245680]  tb_domain_disapprove_switch+0x24/0x60
[  546.250464]  disapprove_switch+0xbc/0xe8
[  546.254378]  authorized_store+0x19c/0x270
[  546.258378]  dev_attr_store+0x20/0x70
...
[  546.303767] ---[ end trace 0000000000000000 ]---

The check prevents a redundant lookup and eliminates the warning

---
v2: no changes

---
 drivers/thunderbolt/switch.c | 5 +++++
 drivers/thunderbolt/tb.c     | 7 +++++++
 2 files changed, 12 insertions(+)
drivers/thunderbolt/switch.c +5 -0
index e12546bfb869..6e9f439ebf3f 100644
@@ -1850,6 +1850,11 @@ static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val)
 	if (!!sw->authorized == !!val)
 		goto unlock;
 
+	if (sw->is_unplugged) {
+		ret = -ENODEV;
+		goto unlock;
+	}
+
 	switch (val) {
 	/* Disapprove switch */
 	case 0:
drivers/thunderbolt/tb.c +7 -0
index 57c11ba13459..69310622d786 100644
@@ -2266,6 +2266,10 @@ static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw)
 	struct tb_tunnel *tunnel;
 	struct tb_port *up;
 
+	/* If the switch has already been unplugged, tunnels are already freed */
+	if (sw->is_unplugged)
+		return 0;
+
 	up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP);
 	if (WARN_ON(!up))
 		return -ENODEV;
@@ -2288,6 +2292,9 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)
 	struct tb_cm *tcm = tb_priv(tb);
 	struct tb_tunnel *tunnel;
 
+	if (sw->is_unplugged)
+		return -ENODEV;
+
 	up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP);
 	if (!up)
 		return 0;
Signature · 1 line
2.45.2
#32 lore raw

Re: [PATCH v2 7/7] thunderbolt: prevent pcie tunnel activation/teardown warnings

Sashiko has reviewed this patch and found no issues.
Quoted 18 lines

When usb4 enter sleep mode, echo 1 to authorized of sysfile, will wakeup usb4 driver, but fail to create pcie tunnel, cause the warning due to a race condition between router disconnect during resume and user authorization

[  278.831186] usb4_hi NVDA8100:00: 0:1: is unplugged (state: 7), retrying...
[  278.943031] usb4_hi NVDA8100:00: 0:1: failed to reach state TB_PORT_UP. Ignoring port...
[  278.951125] usb4_hi NVDA8100:00: 0:1: lost during suspend, disconnecting
...
[  279.013763] usb4_hi NVDA8100:00: 0:7 <-> 1:9 (PCI): activating
[  279.019587] usb4_hi NVDA8100:00: activating PCIe Down path from 0:7 to 1:9
[  279.026468] usb4_hi NVDA8100:00: 1:1: Writing hop 1
[  279.031335] usb4_hi NVDA8100:00: 1:1:  In HopID: 8 => Out port: 9 Out HopID: 8
[  279.038546] usb4_hi NVDA8100:00: 1:1:   Weight: 1 Priority: 3 Credits: 32 Drop: 0 PM: 0
[  279.046536] usb4_hi NVDA8100:00: 1:1:    Counter enabled: 0 Counter index: 2047
[ ... ]
[  546.303767] ---[ end trace 0000000000000000 ]---
Quoted 3 lines

The check prevents a redundant lookup and eliminates the warning

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#33 lore raw

Re: [PATCH v2 7/7] thunderbolt: prevent pcie tunnel activation/teardown warnings

In reply to Chunfeng Yun
Quoted 4 lines · Chunfeng Yun

When usb4 enter sleep mode, echo 1 to authorized of sysfile, will wakeup usb4 driver, but fail to create pcie tunnel, cause the warning due to a race condition between router disconnect during resume and user authorization

This is hard to understand.

Also PCIe, USB4 and so on.

Quoted 28 lines
[  278.831186] usb4_hi NVDA8100:00: 0:1: is unplugged (state: 7), retrying...
[  278.943031] usb4_hi NVDA8100:00: 0:1: failed to reach state TB_PORT_UP. Ignoring port...
[  278.951125] usb4_hi NVDA8100:00: 0:1: lost during suspend, disconnecting
...
[  279.013763] usb4_hi NVDA8100:00: 0:7 <-> 1:9 (PCI): activating
[  279.019587] usb4_hi NVDA8100:00: activating PCIe Down path from 0:7 to 1:9
[  279.026468] usb4_hi NVDA8100:00: 1:1: Writing hop 1
[  279.031335] usb4_hi NVDA8100:00: 1:1:  In HopID: 8 => Out port: 9 Out HopID: 8
[  279.038546] usb4_hi NVDA8100:00: 1:1:   Weight: 1 Priority: 3 Credits: 32 Drop: 0 PM: 0
[  279.046536] usb4_hi NVDA8100:00: 1:1:    Counter enabled: 0 Counter index: 2047
[  279.053834] usb4_hi NVDA8100:00: 1:1:   Flow Control (In/Eg): 1/0 Shared Buffer (In/Eg): 0/0
[  279.062259] usb4_hi NVDA8100:00: 1:1:   Unknown1: 0x0 Unknown2: 0x0 Unknown3: 0x0
[  279.069730] ------------[ cut here ]------------
[  279.074335] usb4_hi NVDA8100:00: PCIe Down path activation failed
[  279.080426] WARNING: CPU: 5 PID: 2433 at drivers/thunderbolt/path.c:587 tb_path_activate+0x1a4/0x5b0
...
[  279.220285] Call trace:
[  279.222722]  tb_path_activate+0x1a4/0x5b0 (P)
[  279.227068]  tb_tunnel_activate+0x140/0x498
[  279.231241]  tb_tunnel_pci+0x180/0x490
[  279.234980]  tb_domain_approve_switch+0x74/0xb0
[  279.239500]  authorized_store+0x214/0x270
[  279.243498]  dev_attr_store+0x20/0x70
...
[  279.288888] ---[ end trace 0000000000000000 ]---
[  279.293497] usb4_hi NVDA8100:00: 0:7 <-> 1:9 (PCI): activation failed
Quoted 4 lines

When usb4 enter sleep mode, echo 0 to authorized of sysfile, will wakeup usb4 driver, but fail to disconnect pcie due to the PCIe tunnel had already been torn down and freed if the port is fail to resume,

Please put the steps like:

1) Boot the system, nothing connected.
2) Once booted up, connected device.
3) Authorize PCIe tunnel via echo 1 > ..
...

So that we can see what are the steps you reproduce this. The above is really hard to follow at least to me.

Quoted 57 lines
[  545.887822] usb4_hi NVDA8100:00: 0:1: is unplugged (state: 7), retrying...
[  545.998689] usb4_hi NVDA8100:00: 0:1: failed to reach state TB_PORT_UP. Ignoring port...
[  546.006778] usb4_hi NVDA8100:00: 0:1: lost during suspend, disconnecting
[  546.013474] usb4_hi NVDA8100:00: 0:4 <-> 1:16 (USB3): deactivating
[  546.020449] usb4_hi NVDA8100:00: deactivating USB3 Down path from 0:4 to 1:16
[  546.027959] usb4_hi NVDA8100:00: deactivating USB3 Up path from 1:16 to 0:4
[  546.035649] usb4_hi NVDA8100:00: 0:7 <-> 1:9 (PCI): deactivating
[  546.042463] usb4_hi NVDA8100:00: deactivating PCIe Down path from 0:7 to 1:9
[  546.050320] usb4_hi NVDA8100:00: deactivating PCIe Up path from 1:9 to 0:7
[  546.057790] usb4_hi NVDA8100:00: 0: TMU: mode change off -> bi-directional, HiFi requested
[  546.067910] usb4_hi NVDA8100:00: 0: TMU: mode set to: bi-directional, HiFi
[  546.076120] usb4_hi NVDA8100:00: 0:1: total credits changed 66 -> 66
[  546.082844] usb4_hi NVDA8100:00: 1: link width set to symmetric, dual lanes
[  546.089815] ------------[ cut here ]------------
[  546.094420] WARNING: CPU: 7 PID: 2433 at drivers/thunderbolt/tb.c:2245 tb_disconnect_pci+0x108/0x120
...
[  546.238810] Call trace:
[  546.241246]  tb_disconnect_pci+0x108/0x120 (P)
[  546.245680]  tb_domain_disapprove_switch+0x24/0x60
[  546.250464]  disapprove_switch+0xbc/0xe8
[  546.254378]  authorized_store+0x19c/0x270
[  546.258378]  dev_attr_store+0x20/0x70
...
[  546.303767] ---[ end trace 0000000000000000 ]---

The check prevents a redundant lookup and eliminates the warning

---
v2: no changes

---
 drivers/thunderbolt/switch.c | 5 +++++
 drivers/thunderbolt/tb.c     | 7 +++++++
 2 files changed, 12 insertions(+)
drivers/thunderbolt/switch.c +5 -0
index e12546bfb869..6e9f439ebf3f 100644
@@ -1850,6 +1850,11 @@ static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val)
 	if (!!sw->authorized == !!val)
 		goto unlock;
 
+	if (sw->is_unplugged) {
+		ret = -ENODEV;
+		goto unlock;
+	}
+
 	switch (val) {
 	/* Disapprove switch */
 	case 0:
drivers/thunderbolt/tb.c +0 -0
index 57c11ba13459..69310622d786 100644

drivers/thunderbolt/tb.c static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw) · line 2269

Quoted 4 lines
drivers/thunderbolt/tb.c +1 -0
@@ -2266,6 +2266,10 @@ static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw)
 	struct tb_tunnel *tunnel;
 	struct tb_port *up;
 
+	/* If the switch has already been unplugged, tunnels are already freed */

router

everywhere

drivers/thunderbolt/tb.c static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw) · line 2272

Quoted 3 lines
drivers/thunderbolt/tb.c +3 -0
+	if (sw->is_unplugged)
+		return 0;
+

Actually I'm thinking that we can just get rid of the WARN_ON()s instead. If the router is gone we cannot find the upstream port nor the tunnel and that's fine so just return error instead.

Quoted 15 lines
drivers/thunderbolt/tb.c +3 -0
 	up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP);
 	if (WARN_ON(!up))
 		return -ENODEV;
@@ -2288,6 +2292,9 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)
 	struct tb_cm *tcm = tb_priv(tb);
 	struct tb_tunnel *tunnel;
 
+	if (sw->is_unplugged)
+		return -ENODEV;
+
 	up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP);
 	if (!up)
 		return 0;
Signature · 1 line
2.45.2
#34 lore raw

Re: [PATCH v2 7/7] thunderbolt: prevent pcie tunnel activation/teardown warnings

Quoted 57 lines · Mika Westerberg
Quoted 4 lines · Chunfeng Yun

When usb4 enter sleep mode, echo 1 to authorized of sysfile, will wakeup usb4 driver, but fail to create pcie tunnel, cause the warning due to a race condition between router disconnect during resume and user authorization

This is hard to understand.

Also PCIe, USB4 and so on.

Quoted 40 lines

[  278.831186] usb4_hi NVDA8100:00: 0:1: is unplugged (state: 7), retrying...
[  278.943031] usb4_hi NVDA8100:00: 0:1: failed to reach state TB_PORT_UP. Ignoring port...
[  278.951125] usb4_hi NVDA8100:00: 0:1: lost during suspend, disconnecting
...
[  279.013763] usb4_hi NVDA8100:00: 0:7 <-> 1:9 (PCI): activating [  279.019587] usb4_hi NVDA8100:00: activating PCIe Down path from 0:7 to 1:9
[  279.026468] usb4_hi NVDA8100:00: 1:1: Writing hop 1 [  279.031335] usb4_hi NVDA8100:00: 1:1:  In HopID: 8 => Out port:
9 Out HopID: 8
[  279.038546] usb4_hi NVDA8100:00: 1:1:   Weight: 1 Priority: 3
Credits: 32 Drop: 0 PM: 0
[  279.046536] usb4_hi NVDA8100:00: 1:1:    Counter enabled: 0 Counter index: 2047
[  279.053834] usb4_hi NVDA8100:00: 1:1:   Flow Control (In/Eg):
1/0 Shared Buffer (In/Eg): 0/0
[  279.062259] usb4_hi NVDA8100:00: 1:1:   Unknown1: 0x0 Unknown2:
0x0 Unknown3: 0x0
[  279.069730] ------------[ cut here ]------------
[  279.074335] usb4_hi NVDA8100:00: PCIe Down path activation failed
[  279.080426] WARNING: CPU: 5 PID: 2433 at drivers/thunderbolt/path.c:587 tb_path_activate+0x1a4/0x5b0
...
[  279.220285] Call trace:
[  279.222722]  tb_path_activate+0x1a4/0x5b0 (P)
[  279.227068]  tb_tunnel_activate+0x140/0x498
[  279.231241]  tb_tunnel_pci+0x180/0x490
[  279.234980]  tb_domain_approve_switch+0x74/0xb0
[  279.239500]  authorized_store+0x214/0x270
[  279.243498]  dev_attr_store+0x20/0x70
...
[  279.288888] ---[ end trace 0000000000000000 ]---
[  279.293497] usb4_hi NVDA8100:00: 0:7 <-> 1:9 (PCI): activation failed

Quoted 4 lines

When usb4 enter sleep mode, echo 0 to authorized of sysfile, will wakeup usb4 driver, but fail to disconnect pcie due to the PCIe tunnel had already been torn down and freed if the port is fail to resume,

Please put the steps like:

Quoted 9 lines

1) Boot the system, nothing connected.
2) Once booted up, connected device.
3) Authorize PCIe tunnel via echo 1 > ..
...

So that we can see what are the steps you reproduce this. The above is
really hard to follow at least to me.

case 1:
1. connect a usb4 hub and wait for usb4 enter sleep mode
2. echo 1 > /sys/bus/thunderbolt/devices/0-1/authorized

case 2: (based on step 1/2)
3. make sure PCIe tunnel is created, and wait for usb4 entr sleep mode again
4. echo 0 > /sys/bus/thunderbolt/devices/0-1/authorized

I try to reproduce the case 1, and find there is no WARN log in case 1,

tb_tunnel_pci()

      --> tb_tunnel_activate()
              --> tb_pci_pre_activate() will return -ENODEV due to

router is unplugged

so it will not call tb_path_activate() anymore, even it is called, it will not print
dump stack anymore which is fixed by the patch:
"062191adfde0 thunderbolt: Log path activation failures without WARN backtraces"

[  188.674233] thunderbolt NVDA8100:00: 0:1: is connected, link is not
up (state: 1), retrying...
[  188.745743] usb 1-1: USB disconnect, device number 2
[  188.745751] usb 1-1.5: USB disconnect, device number 3
[  188.778643] thunderbolt NVDA8100:00: 0:1: is unplugged (state: 7),
retrying...
[  188.882504] thunderbolt NVDA8100:00: 0:1: is unplugged (state: 7),
retrying...
[  188.986645] thunderbolt NVDA8100:00: 0:1: is unplugged (state: 7),
retrying...
-bash: echo: write error: Input/[  189.090663] thunderbolt NVDA8100:00:
0:1: is unplugged (state: 7)
[  189.090671] thunderbolt NVDA8100:00: 0:1: lost during suspend,
disconnecting
[  189.090677] thunderbolt NVDA8100:00: 0:4 <-> 1:16 (USB3):
deactivating
[  189.090963] thunderbolt NVDA8100:00: deactivating USB3 Down path
from 0:4 to 1:16
[  189.091109] thunderbolt NVDA8100:00: deactivating USB3 Up path from
1:16 to 0:4
[  189.091163] thunderbolt NVDA8100:00: 0: TMU: mode change off -> bi-
directional, HiFi requested
[  189.091461] thunderbolt NVDA8100:00: 0: TMU: mode set to: bi-
directional, HiFi
[  189.091518] thunderbolt NVDA8100:00: 0:7 <-> 1:9 (PCI): activating
[  189.091532] tb_tunnel_activate pre_act -19
[  189.091534] thunderbolt NVDA8100:00: 1:9: PCIe tunnel activation
failed, aborting
[  189.091598] thunderbolt NVDA8100:00: 0:5: DP IN resource available

after hotplug

for the case 2, still have WARN logs

[  352.346879] thunderbolt NVDA8100:00: 0:1: is connected, link is not
up (state: 1), retrying...
[  352.450898] thunderbolt NVDA8100:00: 0:1: is connected, link is not
up (state: 1), retrying...
[  352.534038] usb 1-1: USB disconnect, device number 6
[  352.534046] usb 1-1.5: USB disconnect, device number 7
[  352.554670] thunderbolt NVDA8100:00: 0:1: is unplugged (state: 7),
retrying...
[  352.658951] thunderbolt NVDA8100:00: 0:1: is unplugged (state: 7),
retrying...
[  352.763164] thunderbolt NVDA8100:00: 0:1: is unplugged (state: 7),
retrying...
[  352.867149] thunderbolt NVDA8100:00: 0:1: is unplugged (state: 7)
[  352.867156] thunderbolt NVDA8100:00: 0:1: lost during suspend,
disconnecting
[  352.867161] thunderbolt NVDA8100:00: 0:4 <-> 1:16 (USB3):
deactivating
[  352.867693] thunderbolt NVDA8100:00: deactivating USB3 Down path
from 0:4 to 1:16
[  352.867719] thunderbolt NVDA8100:00: deactivating USB3 Up path from
1:16 to 0:4
[  352.867761] thunderbolt NVDA8100:00: 0:7 <-> 1:9 (PCI): deactivating
[  352.867779] thunderbolt NVDA8100:00: deactivating PCIe Down path
from 0:7 to 1:9
[  352.867794] thunderbolt NVDA8100:00: deactivating PCIe Up path from
1:9 to 0:7
[  352.867810] thunderbolt NVDA8100:00: 0: TMU: mode change off -> bi-
directional, HiFi requested
[  352.867863] thunderbolt NVDA8100:00: 0: TMU: mode set to: bi-
directional, HiFi
[  352.867907] ------------[ cut here ]------------
[  352.867908] WARNING: drivers/thunderbolt/tb.c:2273 at
tb_disconnect_pci+0x98/0xa0, CPU#7: bash/3497
[  352.952671] Modules linked in: arm_smccc_trng rng_core sbsa_gwdt
i2c_dev ipmi_ssif
[  352.960233] CPU: 7 UID: 0 PID: 3497 Comm: bash Not tainted 7.3.0-
rc7-arm64 #44 PREEMPT(full)
[  352.968745] Hardware name: JMJWOA-Generic 0000-0000/SKU 1, BIOS
2024.5.0-g10bafb2392 07/20/2026
[  352.977429] pstate: 61400009 (nZCv daif +PAN -UAO -TCO +DIT -SSBS
BTYPE=--)
[  352.984379] pc : tb_disconnect_pci+0x98/0xa0
[  352.988638] lr : tb_disconnect_pci+0x90/0xa0
[  352.992897] sp : ffffffc0845dbbb0
[  352.996199] x29: ffffffc0845dbbb0 x28: ffffff80a9083c00 x27:
0000000000000000
[  353.003323] x26: 0000000000000000 x25: 0000000000000000 x24:
0000000000000000
[  353.010445] x23: ffffffc0845dbc7b x22: 0000000000000002 x21:
0000000000000000
[  353.017567] x20: ffffff80b0705800 x19: 0000000000000000 x18:
0000000000000000
[  353.024689] x17: 000000040044ffff x16: 000000b2b5593510 x15:
0000000000000010
[  353.029889] usb 2-1: USB disconnect, device number 4
[  353.036762] x14: 0000000000000000 x13: 203a6f7420746573 x12:
0000000000000000
[  353.043886] x11: ffffffc081928580 x10: 0000000000000000 x9 :
ffffff80a9544b18
[  353.051009] x8 : ffffff80a9083c00 x7 : ffffff80a9083c00 x6 :
0000000000000000
[  353.058131] x5 : ffffff80a9544b68 x4 : ffffff80a9544b68 x3 :
ffffff80b1aba708
[  353.065253] x2 : 0000000000000000 x1 : 0000000000000000 x0 :
0000000000000000
[  353.072376] Call trace:
[  353.074811]  tb_disconnect_pci+0x98/0xa0 (P)
[  353.079071]  tb_domain_disapprove_switch+0x18/0x28
[  353.083853]  disapprove_switch+0x70/0xc0
[  353.087765]  authorized_store+0x114/0x1bc
[  353.091764]  dev_attr_store+0x14/0x24
[  353.095419]  sysfs_kf_write+0x4c/0x64
[  353.099073]  kernfs_fop_write_iter+0xb4/0x168
[  353.103419]  vfs_write+0x118/0x178
[  353.106811]  ksys_write+0x6c/0xd0
[  353.110116]  __arm64_sys_write+0x14/0x1c
[  353.114028]  invoke_syscall+0xa4/0x104
[  353.117766]  el0_svc_common.constprop.0+0xb0/0xcc
[  353.122458]  do_el0_svc+0x1c/0x24
[  353.125762]  el0_svc+0x12c/0x178
[  353.128981]  el0t_64_sync_handler+0x70/0x108
[  353.133241]  el0t_64_sync+0x154/0x158
[  353.136893] ---[ end trace 0000000000000000 ]---
Quoted 83 lines
Quoted 77 lines

[  545.887822] usb4_hi NVDA8100:00: 0:1: is unplugged (state: 7), retrying...
[  545.998689] usb4_hi NVDA8100:00: 0:1: failed to reach state TB_PORT_UP. Ignoring port...
[  546.006778] usb4_hi NVDA8100:00: 0:1: lost during suspend, disconnecting
[  546.013474] usb4_hi NVDA8100:00: 0:4 <-> 1:16 (USB3):
deactivating
[  546.020449] usb4_hi NVDA8100:00: deactivating USB3 Down path from 0:4 to 1:16
[  546.027959] usb4_hi NVDA8100:00: deactivating USB3 Up path from 1:16 to 0:4
[  546.035649] usb4_hi NVDA8100:00: 0:7 <-> 1:9 (PCI): deactivating [  546.042463] usb4_hi NVDA8100:00: deactivating PCIe Down path from 0:7 to 1:9
[  546.050320] usb4_hi NVDA8100:00: deactivating PCIe Up path from 1:9 to 0:7
[  546.057790] usb4_hi NVDA8100:00: 0: TMU: mode change off -> bi- directional, HiFi requested
[  546.067910] usb4_hi NVDA8100:00: 0: TMU: mode set to: bi- directional, HiFi
[  546.076120] usb4_hi NVDA8100:00: 0:1: total credits changed 66 -

Quoted 1 line

66

[  546.082844] usb4_hi NVDA8100:00: 1: link width set to symmetric, dual lanes
[  546.089815] ------------[ cut here ]------------
[  546.094420] WARNING: CPU: 7 PID: 2433 at drivers/thunderbolt/tb.c:2245 tb_disconnect_pci+0x108/0x120
...
[  546.238810] Call trace:
[  546.241246]  tb_disconnect_pci+0x108/0x120 (P)
[  546.245680]  tb_domain_disapprove_switch+0x24/0x60
[  546.250464]  disapprove_switch+0xbc/0xe8
[  546.254378]  authorized_store+0x19c/0x270
[  546.258378]  dev_attr_store+0x20/0x70
...
[  546.303767] ---[ end trace 0000000000000000 ]---

The check prevents a redundant lookup and eliminates the warning

---
v2: no changes
---
 drivers/thunderbolt/switch.c | 5 +++++
 drivers/thunderbolt/tb.c     | 7 +++++++

 2 files changed, 12 insertions(+)
drivers/thunderbolt/switch.c +0 -0
index e12546bfb869..6e9f439ebf3f 100644
@@ -1850,6 +1850,11 @@ static int tb_switch_set_authorized(struct
 tb_switch *sw, unsigned int val)
  	if (!!sw->authorized == !!val)
  		goto unlock;

drivers/thunderbolt/switch.c +5 -0
+	if (sw->is_unplugged) {
+		ret = -ENODEV;
+		goto unlock;
+	}
+

  switch (val) {
  /* Disapprove switch */
  case 0:

drivers/thunderbolt/tb.c +0 -0
index 57c11ba13459..69310622d786 100644
@@ -2266,6 +2266,10 @@ static int tb_disconnect_pci(struct tb *tb,
 struct tb_switch *sw)
  	struct tb_tunnel *tunnel;
  	struct tb_port *up;

drivers/thunderbolt/tb.c +1 -0
+	/* If the switch has already been unplugged, tunnels are
Quoted 1 line

already freed */

router

everywhere

Quoted 9 lines

drivers/thunderbolt/tb.c static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw) · line 2272

Quoted 3 lines
drivers/thunderbolt/tb.c +3 -0
+	if (sw->is_unplugged)
+		return 0;
+

Actually I'm thinking that we can just get rid of the WARN_ON()s instead.
If the router is gone we cannot find the upstream port nor the tunnel and
that's fine so just return error instead.

Make sense, I will drop the change for case-1, and modify the change for case-2

Thanks

Quoted 17 lines
Quoted 17 lines

  up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP); if (WARN_ON(!up))
  return -ENODEV;

drivers/thunderbolt/tb.c +0 -0
@@ -2288,6 +2292,9 @@ static int tb_tunnel_pci(struct tb *tb,
 struct tb_switch *sw)
  	struct tb_cm *tcm = tb_priv(tb);
  	struct tb_tunnel *tunnel;

drivers/thunderbolt/tb.c +3 -0
+	if (sw->is_unplugged)
+		return -ENODEV;
+

  up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP); if (!up)
  return 0;

Signature · 1 line
2.45.2