[PATCH v4 08/14] thunderbolt: Decouple ICM probe from NHI core via .select_cm hook
From: Chunfeng Yun
Date: Sat Dec 05 2026 - 03:34:20 EST
Currently, nhi_select_cm() in nhi.c directly invokes icm_probe() when
operating in non-native ACPI mode. This tightly couples the generic NHI
core with the Intel Connection Manager (ICM), which is specific to PCIe
controllers.
To allow the NHI core to support non-PCIe platform devices (which only
use software CM) and to cleanly decouple ICM from the core framework,
introduce an optional .select_cm() callback to struct tb_nhi_ops.
Move the icm_probe() call into pci.c as nhi_pci_select_cm(). Non-PCIe
drivers can omit this hook to automatically use the standard software
connection manager.
Signed-off-by: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
Signed-off-by: Chunfeng Yun <chunfeng.yun@xxxxxxxxxxxx>
---
new patch, split from the patch 3/8 of v3 series
---
drivers/thunderbolt/nhi.c | 9 ++-------
drivers/thunderbolt/nhi.h | 2 ++
drivers/thunderbolt/pci.c | 12 ++++++++++++
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
index 0b13ddf6c99d..384493d80839 100644
--- a/drivers/thunderbolt/nhi.c
+++ b/drivers/thunderbolt/nhi.c
@@ -1225,13 +1225,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;
}
diff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h
index e3f19e63f2ba..837bbc87c63f 100644
--- a/drivers/thunderbolt/nhi.h
+++ b/drivers/thunderbolt/nhi.h
@@ -46,6 +46,7 @@ extern const struct dev_pm_ops tb_nhi_pm_ops;
* @request_ring_irq: NHI specific interrupt retrieval hook
* @release_ring_irq: NHI specific interrupt release hook
* @is_present: Whether the device is currently present on the parent bus
+ * @select_cm: Optional hook to select a custom CM
*/
struct tb_nhi_ops {
int (*init)(struct tb_nhi *nhi);
@@ -60,6 +61,7 @@ struct tb_nhi_ops {
int (*request_ring_irq)(struct tb_ring *ring, bool no_suspend);
void (*release_ring_irq)(struct tb_ring *ring);
bool (*is_present)(struct tb_nhi *nhi);
+ struct tb *(*select_cm)(struct tb_nhi *nhi);
};
/*
diff --git a/drivers/thunderbolt/pci.c b/drivers/thunderbolt/pci.c
index 4b985e1c4363..379677362b40 100644
--- a/drivers/thunderbolt/pci.c
+++ b/drivers/thunderbolt/pci.c
@@ -311,6 +311,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,
@@ -318,6 +328,7 @@ static const struct tb_nhi_ops pci_nhi_default_ops = {
.request_ring_irq = nhi_pci_ring_request_msix,
.release_ring_irq = nhi_pci_ring_release_msix,
.is_present = nhi_pci_is_present,
+ .select_cm = nhi_pci_select_cm,
};
/* Ice Lake specific NHI operations */
@@ -518,6 +529,7 @@ static const struct tb_nhi_ops icl_nhi_ops = {
.request_ring_irq = nhi_pci_ring_request_msix,
.release_ring_irq = nhi_pci_ring_release_msix,
.is_present = nhi_pci_is_present,
+ .select_cm = nhi_pci_select_cm,
};
static int nhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
--
2.45.2