Re: [PATCH v3 3/8] thunderbolt: Make PCIe NHI support opt-in

From: Mika Westerberg

Date: Tue Nov 24 2026 - 11:31:09 EST


On Mon, Nov 23, 2026 at 07:36:50PM +0800, Chunfeng Yun wrote:
> From: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
>
> 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.
>
> Signed-off-by: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
> Signed-off-by: Chunfeng Yun <chunfeng.yun@xxxxxxxxxxxx>
> ---
> v3:
> Added 'default USB4' to CONFIG_USB4_PCI in Kconfig;
> Exported tb_xdomain_remove symbol immediately after its definition;
>
> 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 | 12 ++++++++++-
> 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, 71 insertions(+), 40 deletions(-)
>
> diff --git a/drivers/thunderbolt/Kconfig b/drivers/thunderbolt/Kconfig
> index 294b3227a545..80960555a364 100644
> --- a/drivers/thunderbolt/Kconfig
> +++ b/drivers/thunderbolt/Kconfig
> @@ -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,17 @@ menuconfig USB4
>
> if USB4
>
> +config USB4_PCI
> + tristate "Support for PCIe-attached USB4 and Thunderbolt controllers"
> + depends on PCI
> + default USB4
> + 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)
> diff --git a/drivers/thunderbolt/Makefile b/drivers/thunderbolt/Makefile
> index beb054c3126b..a563bf2b0345 100644
> --- a/drivers/thunderbolt/Makefile
> +++ b/drivers/thunderbolt/Makefile
> @@ -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
> diff --git a/drivers/thunderbolt/ctl.c b/drivers/thunderbolt/ctl.c
> index 965988b18608..96717a0a94b1 100644
> --- a/drivers/thunderbolt/ctl.c
> +++ b/drivers/thunderbolt/ctl.c
> @@ -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);

Why these need to be exported? All the config stuff happens inside USB4
fabric and that's not dependent on how the controller is connected to the
SoC.

Can we get the absolute minimum that is needed? The platform/PCI sides pretty
much need to get the resources/interrupts and then call the core driver.