The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
Cc: YehezkelShB@gmail.com, andreas.noever@gmail.com,
	bhelgaas@google.com, bp@alien8.de, dave.hansen@linux.intel.com,
	dev@deq.rocks, dmitry.kasatkin@gmail.com,
	eric.snowberg@oracle.com, hansg@kernel.org, hpa@zytor.com,
	ilpo.jarvinen@linux.intel.com, jarkko@kernel.org,
	jmorris@namei.org, keyrings@vger.kernel.org,
	linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-pci@vger.kernel.org, linux-security-module@vger.kernel.org,
	linux-usb@vger.kernel.org, mingo@redhat.com, paul@paul-moore.com,
	platform-driver-x86@vger.kernel.org, roberto.sassu@huawei.com,
	serge@hallyn.com, tglx@kernel.org, westeri@kernel.org,
	x86@kernel.org, zohar@linux.ibm.com
Subject: Re: [PATCH v5 2/2] thunderbolt: Add device links for Apple T2 NHI
Date: Thu, 30 Jul 2026 13:32:09 +0200	[thread overview]
Message-ID: <20260730113209.GF20844@black.igk.intel.com> (raw)
In-Reply-To: <20260729183524.1199-1-atharvatiwarilinuxdev@gmail.com>

Hi,

On Wed, Jul 29, 2026 at 02:35:24PM -0400, Atharva Tiwari wrote:
> > We should not be calling PCI functions anymore from the SW CM core. We have
> > pci.c for that.
> 
> That is outside the scope of this patch, this should be another patch.

Agree. It should be preparatory patch for the series.

> > I wonder if we can put this to pci.c, rename it to tb_pci_add_links()
> > instead.
> 
> Same thing as before, its outside the scope of this patch.
> 
> > BTW, why you need to differentiate T2 vs. the rest of Apple x86? Don't this
> > variable do?
> 
> Because the Patchset is specifically for T2 Macs.

Yes but don't x86_apple_machine is true for T2 macs as well? Why need a
separate variable?

> > I'm not fan of __free() and the like so let's not use it here.
> >
> > Also you don't need to scan all the slots. Just look for the tunneled
> > downstream ports based on their PCI IDs like we do already.
> 
> Could you please point me to the "like we do already" code you're referring to?

Yes see below.

> > This is unrelated change.
> 
> Its not. the patch specifically says T2 macs, and Titan ridge is only on T2 Macs
> so we dont need to use has_apple_t2_chip for that.

I meant the extra empty line that your patch adds.

In addition to rename and move to pci.c (as separate patch) something like
this (completely untested) I had in mind. Does that make sense? It does not
add the Titan Ridge IDs, you can add them to the discrete part then.

diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index ddeba0861a2b..3ad6ece6b808 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -3397,32 +3397,30 @@ static const struct tb_cm_ops tb_cm_ops = {
 	.disconnect_xdomain_paths = tb_disconnect_xdomain_paths,
 };
 
-/*
- * During suspend the Thunderbolt controller is reset and all PCIe
- * tunnels are lost. The NHI driver will try to reestablish all tunnels
- * during resume. This adds device links between the tunneled PCIe
- * downstream ports and the NHI so that the device core will make sure
- * NHI is resumed first before the rest.
- */
-static bool tb_apple_add_links(struct tb_nhi *nhi)
+static bool add_link(struct device *dev, struct device *nhi)
 {
-	struct pci_dev *nhi_pdev = to_pci_dev(nhi->dev);
-	struct pci_dev *upstream, *pdev;
-	bool ret;
+	const struct device_link *link;
 
-	if (!x86_apple_machine)
-		return false;
-
-	switch (nhi_pdev->device) {
-	case PCI_DEVICE_ID_INTEL_LIGHT_RIDGE:
-	case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C:
-	case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_NHI:
-	case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI:
-		break;
-	default:
-		return false;
+	link = device_link_add(dev, nhi, DL_FLAG_AUTOREMOVE_SUPPLIER |
+				DL_FLAG_PM_RUNTIME);
+	if (link) {
+		dev_dbg(nhi, "created link from %s\n",
+			dev_name(dev));
+		return true;
+	} else {
+		dev_warn(nhi, "device link creation from %s failed\n",
+			 dev_name(dev));
 	}
 
+	return false;
+}
+
+static bool
+tb_pci_add_links_discrete(struct tb_nhi *nhi, struct pci_dev *nhi_pdev)
+{
+	struct pci_dev *upstream, *pdev;
+	bool ret;
+
 	upstream = pci_upstream_bridge(nhi_pdev);
 	while (upstream) {
 		if (!pci_is_pcie(upstream))
@@ -3442,30 +3440,80 @@ static bool tb_apple_add_links(struct tb_nhi *nhi)
 	 */
 	ret = false;
 	for_each_pci_bridge(pdev, upstream->subordinate) {
-		const struct device_link *link;
-
 		if (!pci_is_pcie(pdev))
 			continue;
 		if (pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM ||
 		    !pdev->is_pciehp)
 			continue;
 
-		link = device_link_add(&pdev->dev, nhi->dev,
-				       DL_FLAG_AUTOREMOVE_SUPPLIER |
-				       DL_FLAG_PM_RUNTIME);
-		if (link) {
-			dev_dbg(nhi->dev, "created link from %s\n",
-				dev_name(&pdev->dev));
-			ret = true;
-		} else {
-			dev_warn(nhi->dev, "device link creation from %s failed\n",
-				 dev_name(&pdev->dev));
+		ret = add_link(&pdev->dev, nhi->dev);
+	}
+
+	return ret;
+}
+
+static bool
+tb_pci_add_links_integrated(struct tb_nhi *nhi, struct pci_dev *nhi_pdev)
+{
+	struct pci_bus *bus = nhi_pdev->bus;
+	struct pci_dev *pdev;
+	bool ret = false;
+
+	/*
+	 * On intergrated the tunneled PCIe root ports are directly
+	 * under the host bridge.
+	 */
+	if (!pci_is_root_bus(bus))
+		return false;
+
+	for_each_pci_bridge(pdev, bus) {
+		switch (nhi_pdev->device) {
+		case PCI_DEVICE_ID_INTEL_ICL_NHI0:
+			if (pdev->device == 0x8a1d || pdev->device == 0x8a1fb)
+				ret = add_link(&pdev->dev, nhi->dev);
+			break;
+		case PCI_DEVICE_ID_INTEL_ICL_NHI1:
+			if (pdev->device == 0x8a21 || pdev->device == 0x8a23)
+				ret = add_link(&pdev->dev, nhi->dev);
+			break;
+		default:
+			break;
 		}
 	}
 
 	return ret;
 }
 
+/*
+ * During suspend the Thunderbolt controller is reset and all PCIe
+ * tunnels are lost. The NHI driver will try to reestablish all tunnels
+ * during resume. This adds device links between the tunneled PCIe
+ * downstream ports and the NHI so that the device core will make sure
+ * NHI is resumed first before the rest.
+ */
+static bool tb_apple_add_links(struct tb_nhi *nhi)
+{
+	struct pci_dev *nhi_pdev = to_pci_dev(nhi->dev);
+
+	if (!x86_apple_machine)
+		return false;
+
+	switch (nhi_pdev->device) {
+	case PCI_DEVICE_ID_INTEL_LIGHT_RIDGE:
+	case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C:
+	case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_NHI:
+	case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI:
+		return tb_pci_add_links_discrete(nhi, nhi_pdev);
+
+	case PCI_DEVICE_ID_INTEL_ICL_NHI0:
+	case PCI_DEVICE_ID_INTEL_ICL_NHI1:
+		return tb_pci_add_links_integrated(nhi, nhi_pdev);
+
+	default:
+		return false;
+	}
+}
+
 struct tb *tb_probe(struct tb_nhi *nhi)
 {
 	struct tb_cm *tcm;


      reply	other threads:[~2026-07-30 11:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27 21:18 [PATCH v5 0/2] Add Apple T2 NHI device links Atharva Tiwari
2026-07-27 21:18 ` [PATCH v5 1/2] treewide: Add a flag to detect the Apple T2 chip Atharva Tiwari
2026-07-28  0:58   ` Borislav Petkov
2026-07-27 21:18 ` [PATCH v5 2/2] thunderbolt: Add device links for Apple T2 NHI Atharva Tiwari
2026-07-28  4:48   ` Mika Westerberg
2026-07-29 18:35     ` Atharva Tiwari
2026-07-30 11:32       ` Mika Westerberg [this message]

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=20260730113209.GF20844@black.igk.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=YehezkelShB@gmail.com \
    --cc=andreas.noever@gmail.com \
    --cc=atharvatiwarilinuxdev@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dev@deq.rocks \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eric.snowberg@oracle.com \
    --cc=hansg@kernel.org \
    --cc=hpa@zytor.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jarkko@kernel.org \
    --cc=jmorris@namei.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=roberto.sassu@huawei.com \
    --cc=serge@hallyn.com \
    --cc=tglx@kernel.org \
    --cc=westeri@kernel.org \
    --cc=x86@kernel.org \
    --cc=zohar@linux.ibm.com \
    /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