Re: [PATCH] thunderbolt: Make PCIe NHI support opt-in

From: Mika Westerberg

Date: Wed Sep 16 2026 - 04:26:02 EST


Hi,

On Tue, Sep 15, 2026 at 07:04:10PM +0200, Konrad Dybcio wrote:
> From: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
>
> With more implementations coming in, one may desire not to enable
> support for the PCIe-attached NHIs. Allow it to be built as a module
> atop the framework.

Is it so that Qualcomm platform does not support PCIe tunneling at all
then?

> Signed-off-by: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
> ---
> The diff came out a little messy.. compile-tested with CONFIG_PCI=n and
> tested USB4_PCIE=m/=y on a NUC with an Alpine Ridge controller
> ---
> drivers/thunderbolt/Kconfig | 11 ++++++++++-
> drivers/thunderbolt/Makefile | 7 +++++--
> drivers/thunderbolt/ctl.c | 6 +++++-
> drivers/thunderbolt/domain.c | 14 ++++++++++++--
> drivers/thunderbolt/nhi.c | 18 +++++++++++-------
> 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, 74 insertions(+), 40 deletions(-)
>
> diff --git a/drivers/thunderbolt/Kconfig b/drivers/thunderbolt/Kconfig
> index 294b3227a545..81fca3bfcdd7 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,16 @@ menuconfig USB4
>
> if USB4
>
> +config USB4_PCIE
> + depends on PCI
> + tristate "Support for PCIe-attached USB4 and Thunderbolt controllers"

I think USB4_PCI and so on.

> + 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_pcie.

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..fc808c6b23e6 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_PCIE} += thunderbolt_pcie.o
> +thunderbolt_pcie-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);
>
> /**
> * 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
> diff --git a/drivers/thunderbolt/domain.c b/drivers/thunderbolt/domain.c
> index 12c88509a54f..1c76fd8151ca 100644
> --- a/drivers/thunderbolt/domain.c
> +++ b/drivers/thunderbolt/domain.c
> @@ -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
> @@ -904,8 +907,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;
>
> @@ -931,7 +935,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);
> @@ -941,3 +945,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");
> diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
> index 020db5a1f029..9b1165b2a484 100644
> --- a/drivers/thunderbolt/nhi.c
> +++ b/drivers/thunderbolt/nhi.c
> @@ -548,6 +548,7 @@ irqreturn_t ring_msix(int irq, void *data)
>
> return IRQ_HANDLED;
> }
> +EXPORT_SYMBOL_GPL(ring_msix);

We need to think what is going to be exported and how. For example here
ring_msix is pretty common name so if nothing else it needs to be properly
namespaced and that should be the first patch in the series.

Secondly I think it would be good to have this whole thing as part of a
patch series that adds the Qualcomm controller support so we have an
explanation there why we are doing all this.

>
> static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring)
> {
> @@ -1001,6 +1002,7 @@ int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data)
>
> return 0;
> }
> +EXPORT_SYMBOL_GPL(nhi_mailbox_cmd);
>
> /**
> * nhi_mailbox_mode() - Return current firmware operation mode
> @@ -1021,6 +1023,7 @@ enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi)
>
> return (enum nhi_fw_mode)val;
> }
> +EXPORT_SYMBOL_GPL(nhi_mailbox_mode);

We really need to think what should be exported and what not. This for
example I think we can move inside pci.c because there is really no user
outside of Intel PCIe based systems for these.

Ideally export the minimal.