From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=60.244.123.138 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796459649; b=eTkoWZUIVVT0jQJ4WsmrZwnsm7sApP+J2W/7heDwTj9qeZ/Nr7ITdXKvJBkRt9sCe/ui /NgdcWCTWdk4iC5BQoEvB5F+sXp3aoGmXKuSPsCS15D0WoGFLPGIO+ZqXdB9/juhNCMCg F5RpVBR1iayZYij4dv8kni/Qxths2SaCRPR8j5qgCUspNnATOX3zAgk8eU8TV0RrQODeI usudUrN5h7VYS5q6ypAwajBnHK+m0DwIZt32tI5rtsVUzVTbKO4fpMCphcTlHR0od1KCP Up9Gll7Vo6ZyM7J8+SAZj8BhOADY5opKsufS6cWf9QvYdSZsFW2GYtzoT8l0hHIxEgA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796459649; h=DMARC-Filter:X-UUID:DKIM-Signature:X-CID-P-RULE:X-CID-O-INFO: X-CID-META:X-CID-BVR:X-CID-BAS:X-CID-FACTOR:X-CID-RHF:X-UUID:Received: Received:Received:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: Content-Type:X-MTK; bh=uXMTsGe/duJVQEJYfGdIjMCtAVWFmLW7ZVZ8Siek6ZI=; b=Q6jcISNytZOTVi9BAbnT8EkypwkuD/bG5ak/j8gcbAboAsDmi2M3W17FfaL2QgD+P9gn 1sILVM/QQcg5t9PTRCciLrKQjsZzPPeATUMfR5/eSmXx5qnXlDgi7K3igJpnDXgT6ywyt a+/QDf6lsYwcbIsLk/q+Jl3AUzxBlIRA/35QP4lzJtj4FYpwwrxIvHbaNp6mAlToxxWds 5NgxF8Ns7YRX0j6DYnHA1l0WIOQSPNfXO1IkDNeUUXJO7+tzZ0WqIOuKQWNIs0fY+iHXq rB1eRq1y14zU/x50n1OAXAq/5DmanCjjKOxq3qGyjwN9MgNDuPVaKJ94b85K923pnyA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=G14ZjLSD; arc=none smtp.remote-ip=60.244.123.138 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC283606A33F; Sat, 5 Dec 2026 08:34:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BC283606A33F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=G14ZjLSD X-UUID: a10f3bd6f08611f1b9cf3d4034dccee2-20261205 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=uXMTsGe/duJVQEJYfGdIjMCtAVWFmLW7ZVZ8Siek6ZI=; b=G14ZjLSDcYqT8ZnRY1FJpHRscbZiiZ/+AN2dgXJ7rQ0EXxwTD15MNQWZZmEfE35ttxI1CuqzPUj0iPriPo5yiKIe5AwLX3xOnvfqn2Rx7M8F8C5uehgqw0qTWfsT0M/bmylya5fYDVWTAaR0/rRfE6C93NvduNGyHwB9N8e23p4=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.22,REQID:c5ff3e09-5e12-404d-bd5f-49a40f357ef5,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:d36851b,CLOUDID:6a993767-4b51-4c95-bb1b-80ac6aad9c96,B ulkID:nil,BulkQuantity:0,SF:81|82|102|836|865|888|898,TC:-5,Content:0|15|5 0|99,EDM:-3,IP:nil,URL:0,File:130,RT:0,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0 ,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: a10f3bd6f08611f1b9cf3d4034dccee2-20261205 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 322595322; Sat, 05 Dec 2026 16:34:04 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Sat, 5 Dec 2026 16:34:03 +0800 Received: from gcnsap21.gcn.mediatek.inc (10.17.81.22) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.2562.56 via Frontend Transport; Sat, 5 Dec 2026 16:34:03 +0800 From: Chunfeng Yun To: Mika Westerberg CC: Andreas Noever , Konrad Dybcio , Sven Peter , Yehezkel Bernat , Matthias Brugger , Greg Kroah-Hartman , AngeloGioacchino Del Regno , , , , , Chunfeng Yun Subject: [PATCH v4 08/14] thunderbolt: Decouple ICM probe from NHI core via .select_cm hook Date: Sat, 5 Dec 2026 16:33:33 +0800 Message-ID: <20261205083342.4009278-9-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261205083342.4009278-1-chunfeng.yun@mediatek.com> References: <20261205083342.4009278-1-chunfeng.yun@mediatek.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-MTK: N 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 Signed-off-by: Chunfeng Yun --- 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