From: Chunfeng Yun <chunfeng.yun@mediatek.com>
To: Mika Westerberg <westeri@kernel.org>
Cc: Andreas Noever <andreas.noever@gmail.com>,
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>,
Sven Peter <sven@kernel.org>,
Yehezkel Bernat <YehezkelShB@gmail.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
<linux-kernel@vger.kernel.org>, <linux-usb@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>,
Chunfeng Yun <chunfeng.yun@mediatek.com>
Subject: [PATCH v4 00/14] thunderbolt: Add platform NHI driver and modularize PCIe NHI
Date: Sat, 5 Dec 2026 16:33:25 +0800 [thread overview]
Message-ID: <20261205083342.4009278-1-chunfeng.yun@mediatek.com> (raw)
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 and NHI directly as a memory-mapped platform device described
via ACPI ("ACPI0015"). Furthermore, embedded and SoC-based platforms
often lack PCIe-attached host routers and do not require Intel ICM
support, making a mandatory PCI dependency and bundled PCIe code
undesirable.
This series:
1. Fixes an initialization race and error unwind issue in nhi_probe().
2. Refactors and encapsulates internal subsystem interfaces (interrupt
handling, router device type checks, bus walks, and teardown).
3. Decouples PCIe NHI and Intel ICM support from the core framework into
an opt-in module (thunderbolt_pci.ko).
4. Makes struct tb_nhi_ops optional for simple drivers.
5. Introduces a standalone platform NHI driver (thunderbolt_platform.ko).
6. Improves link training timeouts and disconnect handling under dynamic
runtime conditions.
Overview of Changes
===================
1. Standalone Core Bugfix (Patch 1)
- Fixes initialization order and error unwind paths in nhi_probe().
Initializes &nhi->lock and configures the DMA mask before enabling
interrupts to prevent race conditions with early interrupts, and
consolidates post-interrupt failure paths to invoke nhi_shutdown().
2. Subsystem Interface Encapsulation (Patches 2-8)
In preparation for modularizing PCIe NHI support, several internal
abstractions are cleaned up to avoid leaking core internals across
module boundaries:
- Patch 2 renames core ring and NHI symbols to use standard tb_/tb_ring_
prefixes.
- Patch 3 internalizes non-MSI-X interrupt request and work handling
into nhi.c, allowing nhi_isr(), nhi_interrupt_work(), and
nhi_disable_interrupts() to become static, and drops the
.init_interrupts callback from struct tb_nhi_ops.
- Patch 4 encapsulates router type checking within switch.c by moving
tb_to_switch() out-of-line and introducing tb_switch_has_children(),
keeping struct device_type tb_switch_type private to switch.c.
- Patch 5 encapsulates the bus iteration for runtime resume completion
into domain.c as tb_domain_complete_rpm(), keeping tb_bus_type
private to domain.c.
- Patch 6 consolidates domain and NHI teardown into tb_nhi_remove(),
making nhi_shutdown() static and eliminating the need to export
tb_domain_remove() and nhi_shutdown().
- Patch 7 moves Intel ICM mailbox helpers (nhi_mailbox_cmd/mode) into
icm.c as static functions.
- Patch 8 decouples ICM probing from the NHI core by introducing an
optional .select_cm() hook in struct tb_nhi_ops.
3. Modularizing PCIe NHI & Making Ops Optional (Patches 9-10)
- Patch 9 drops the hard "depends on PCI" from CONFIG_USB4, adds
CONFIG_USB4_PCI (defaulting to USB4) to build PCIe NHI and ICM as
thunderbolt_pci.ko, and exports the minimal set of remaining APIs.
Thanks to patches 2-8, internal structures like tb_bus_type and
tb_switch_type do not need to be exported.
- Patch 10 makes struct tb_nhi_ops completely optional by introducing
the TB_NHI_HAS_OP() helper macro and dropping the mandatory
"if (!nhi->ops)" check in tb_nhi_probe(), allowing platform drivers
to operate without any ops table.
4. Platform NHI Driver (Patch 11)
- Introduces CONFIG_USB4_PLATFORM (thunderbolt_platform.ko), adding
support for memory-mapped USB4 NHIs via ACPI ("ACPI0015").
- Supports an optional dedicated wakeup interrupt from an always-on
power domain (registered via dev_pm_set_dedicated_wake_irq()),
necessary for SoCs where the primary NHI power domain is gated
during system sleep.
5. Link Training and Disconnect Improvements (Patches 12-14)
- Patch 12 increases the port link training timeout in
tb_wait_for_port() from 1s to 2s to accommodate Phase 5 equalization
and retimer propagation delays across multi-retimer topologies
during wakeups.
- Patch 13 decouples TB_PORT_UNPLUGGED wait time from the overall 2s
link-up timeout, capping it to 400ms so genuine disconnects are
handled promptly.
- Patch 14 drops an unnecessary WARN_ON() in tb_disconnect_pci() when
userspace deauthorizes a router after a tunnel was already torn down.
Differences since v3
====================
- Re-ordered the nhi_probe() error handling and race condition fix to
Patch 1 as a standalone bugfix with a Fixes: tag.
- Decomposed the previous monolithic modularization patch into discrete
preparatory encapsulation patches (Patches 2-8):
* Internalized primary interrupt request and work into nhi.c.
* Encapsulated router type checks (tb_to_switch / tb_switch_has_children)
in switch.c.
* Encapsulated rpm_complete bus walk in domain.c.
* Consolidated teardown into tb_nhi_remove().
* Decoupled ICM mailbox helpers and probe logic.
- Avoided exporting tb_bus_type, tb_switch_type, tb_domain_remove, and
nhi_shutdown in the PCIe modularization patch.
- Added TB_NHI_HAS_OP() and made struct tb_nhi_ops optional (Patch 10).
- In the platform driver (Patch 11):
* Wrapped wake_irq in a local driver structure (struct tb_nhi_platform)
instead of modifying include/linux/thunderbolt.h.
* Corrected wake IRQ registration order by setting wakeup capability
before dev_pm_set_dedicated_wake_irq().
* Added cleanup for sysfs wakeup nodes on error and device removal.
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.
- Link training across wakeups with dual-retimer topologies.
- Concurrent sysfs deauthorization during disconnect events (verifying
absence of WARN_ON splats).
- Modular builds with CONFIG_USB4=m, CONFIG_USB4_PCI=m, and
CONFIG_USB4_PLATFORM=m, as well as built-in configurations.
Chunfeng Yun (13):
thunderbolt: Fix error handling and unwind paths in nhi_probe()
thunderbolt: Prefix NHI core symbols with tb_ and tb_ring_
thunderbolt: Internalize non-MSI-X interrupt request and work in NHI
core
thunderbolt: Encapsulate router device type checks in switch.c
thunderbolt: Move rpm_complete bus walk to domain.c
thunderbolt: Consolidate domain and NHI teardown into tb_nhi_remove()
thunderbolt: Move ICM mailbox functions to icm.c
thunderbolt: Decouple ICM probe from NHI core via .select_cm hook
thunderbolt: Make nhi->ops optional
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: Drop WARN_ON() in tb_disconnect_pci()
Konrad Dybcio (1):
thunderbolt: Make PCIe NHI support opt-in
drivers/thunderbolt/Kconfig | 22 +++-
drivers/thunderbolt/Makefile | 10 +-
drivers/thunderbolt/ctl.c | 6 +-
drivers/thunderbolt/domain.c | 37 +++++-
drivers/thunderbolt/icm.c | 76 ++++++++++---
drivers/thunderbolt/nhi.c | 200 +++++++++++++++------------------
drivers/thunderbolt/nhi.h | 20 ++--
drivers/thunderbolt/pci.c | 124 +++++++-------------
drivers/thunderbolt/platform.c | 155 +++++++++++++++++++++++++
drivers/thunderbolt/switch.c | 63 +++++++++--
drivers/thunderbolt/tb.c | 4 +-
drivers/thunderbolt/tb.h | 12 +-
drivers/thunderbolt/tunnel.c | 1 +
drivers/thunderbolt/xdomain.c | 5 +
include/linux/thunderbolt.h | 2 +
15 files changed, 490 insertions(+), 247 deletions(-)
create mode 100644 drivers/thunderbolt/platform.c
--
2.45.2
next reply other threads:[~2026-12-05 8:34 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 8:33 Chunfeng Yun [this message]
2026-12-05 8:33 ` [PATCH v4 01/14] thunderbolt: Fix error handling and unwind paths in nhi_probe() Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 02/14] thunderbolt: Prefix NHI core symbols with tb_ and tb_ring_ Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 03/14] thunderbolt: Internalize non-MSI-X interrupt request and work in NHI core Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 04/14] thunderbolt: Encapsulate router device type checks in switch.c Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 05/14] thunderbolt: Move rpm_complete bus walk to domain.c Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 06/14] thunderbolt: Consolidate domain and NHI teardown into tb_nhi_remove() Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 07/14] thunderbolt: Move ICM mailbox functions to icm.c Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 08/14] thunderbolt: Decouple ICM probe from NHI core via .select_cm hook Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 09/14] thunderbolt: Make PCIe NHI support opt-in Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 10/14] thunderbolt: Make nhi->ops optional Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 11/14] thunderbolt: Add platform NHI driver Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 12/14] thunderbolt: Increase the lane adapter link-up timeout value Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 13/14] thunderbolt: Decouple the waiting time of TB_PORT_UNPLUGGED and TB_PORT_UP Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 14/14] thunderbolt: Drop WARN_ON() in tb_disconnect_pci() Chunfeng Yun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205083342.4009278-1-chunfeng.yun@mediatek.com \
--to=chunfeng.yun@mediatek.com \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=gregkh@linuxfoundation.org \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-usb@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=sven@kernel.org \
--cc=westeri@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®