mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 0/7] thunderbolt: Add support platform NHI driver
Date: Tue, 10 Nov 2026 19:48:48 +0800	[thread overview]
Message-ID: <20261110114925.722014-1-chunfeng.yun@mediatek.com> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="y", Size: 4947 bytes --]

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

-- 
2.45.2


             reply	other threads:[~2026-11-10 11:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 11:48 Chunfeng Yun [this message]
2026-11-10 11:48 ` [PATCH v2 1/7] thunderbolt: Prefix NHI core functions with tb_ and tb_ring_ Chunfeng Yun
2026-11-10 12:42   ` Konrad Dybcio
2026-11-10 11:48 ` [PATCH v2 2/7] thunderbolt: Move ICM mailbox functions to icm.c and internalize interrupt work Chunfeng Yun
2026-11-10 14:24   ` Mika Westerberg
2026-11-10 11:48 ` [PATCH v2 3/7] thunderbolt: Make PCIe NHI support opt-in Chunfeng Yun
2026-11-10 11:48 ` [PATCH v2 4/7] thunderbolt: add platform NHI driver Chunfeng Yun
2026-11-10 12:43   ` Konrad Dybcio
2026-11-10 14:37   ` Mika Westerberg
2026-11-10 11:48 ` [PATCH v2 5/7] thunderbolt: increase the lane adapter link-up timeout value Chunfeng Yun
2026-11-10 14:39   ` Mika Westerberg
2026-11-10 11:48 ` [PATCH v2 6/7] thunderbolt: decouple the waiting time of TB_PORT_UNPLUGGED and TB_PORT_UP Chunfeng Yun
2026-11-10 14:40   ` Mika Westerberg
2026-11-10 11:48 ` [PATCH v2 7/7] thunderbolt: prevent pcie tunnel activation/teardown warnings Chunfeng Yun
2026-11-10 14:50   ` Mika Westerberg

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=20261110114925.722014-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®