From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09A25445AF4 for ; Tue, 18 Aug 2026 09:50:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787046623; cv=none; b=kJVBa9uAwpjo3tUtifLiDpeJTCW+ylnwuJm4lhu+i+574yotUMKu1YK1NY8/3vWKnYWZOAlD38EmFWUMiBmLbWzCDQWzJ0m2wSEKur0doRxICaqECgDFZ+lM9qXs+PFV8IWjwYz7g3ePq/ciJNpTNJqOmJFNNOVM45hKDnSdo+4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787046623; c=relaxed/simple; bh=jxzMQaiqawHQ/SOA9j7dDopTxyxQQALlbtrm64Kdsbc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pGUfo2uexTnv3X0+ua/vRDn0/3n+Ky3wCuyFaYGQbwC9PXU7syX9MPU5Y6hGD/JjYUtWS9gUGnIxP7LvMr3oKpSzQ5Mb+vpQ8PPxNV25zI84b662lVszEuRSqStZTJP0gILX7vCJdlZorXu7GmvGZ+rcvfdsFSK0SGMlo3JJqgs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=snhdaJpe; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="snhdaJpe" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-c9e7391839cso4313490a12.0 for ; Tue, 18 Aug 2026 02:50:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787046621; x=1787651421; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0wanu+zA8D4wAauqMrLFvx0gIfo6i0DJuB1JPGvu6HU=; b=snhdaJpe9kqeUB/go73FcvaMLwFDiepTKMHnyU5m32xLkeCB5nLLcFYXE5zav669PE 8SR1p0wTBNzEGUqKKqdoNmRPyasI4FJpzjCcymiw19d8kBbkca2KPIB6f8U5hVAonXcf Iog2Tw6A2IiikPyN6XTF2XHbiY0u9uHavrsqEiJM63lr8in6Btbby5C9ndCsuk6onLho 0QBBoCuXl62vElyuR9lYzywdja7m26PakMYSMckob+tEPFKr3j5jooCpbpbO3um+hUFi ObqFwO0ZdELeaj5+LLZGRc0xHxNyyPsRUYO2jWcSl0yi9qEiq36RnshtKzi4e9vq+cnM 8UaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787046621; x=1787651421; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=0wanu+zA8D4wAauqMrLFvx0gIfo6i0DJuB1JPGvu6HU=; b=NtQzORfTPKWv5SBUCOoJBduIqmxynv9n+lqvujh+sBeN9b5cocvks9tBNJRxyQxNX9 Lh1CE+HTbITAb4GxUfx+DUE6/X8jlpAzg9zJG8DbIFpfLcUnCMWKITLWafyHsnpg2ZmG g6OD3VCubQLA7JnUb4GuuIYhTCqRTaRuWKvMRneyVnSiDmzbKyf1PkxStRQwe8t+YQvA EU1ufsiEkWcRVPfUsLHYWNuFr+HT2Wmt8a3pI1XivpdYfUvCnwRlnmCBXCHuGVkh1K93 fG17oLmmCTtwB9CzDXVwEbJE+g7CdSgJRBY119U4zr0PQliLfMBgx05U9XwJ8bByrmsg FecQ== X-Forwarded-Encrypted: i=1; AHgh+Rr1i5WOcKPOpxV0zKBor8aeC25nqJkuTIv9jbm6zt7mg3vMERZ+1DnM/cb12WqIVHLFUsj6GxaM8kxOJLM=@vger.kernel.org X-Gm-Message-State: AOJu0YyhTCz+CUfF2gc4W6lvX/laSlBrLGWdameUwvgDxSBXKvl5eoLa vHdkRmx97giEAU7cgw/7GpH0ewIGLenT/zc9cvLwWw3LXTeO5ytovV/Xcb0Y X-Gm-Gg: AR+sD10qjpCdaPT/BdVJeS6uruXgegVuAsupQND+ukjOw25TEefx3BvKRF6xG4eI0Fu uRP01CfvgYGUxUz7jHjtoAiYBZ21pR/ALItb/tIPT6mLTa9ITMb/JZNe+UjRj8RzwDWYmfC1Xrn SKlVRiwLtt4xGvS3veROMnApIl+nuX9/xvzw9X1xCB/sniuQ4Za8FlP8kS725eij+qYNfTIYXwq s6AHFHX055EPqULTAu7hoS2dUv5VCtK1IUwobk9OO1dKptN7p1Y9q1LVN70AHodqXkkH6fwq1cD Vis3BYTlE/Od3qR4BRmaSsLwZ1UuQal2EFDGoliYxeBAelqmrrcHBC+oRCBmBn+GVAKch14nF39 6GquxVP/wwdZVOEF4TlUnku3fwdjIsG+gL78fwWHjJQsU7xGVO3b2rQsHuVty0WBN7Bmuyd+Wp4 TYAnEZa80A2kcBx02i7fz4W2Le5jPQZojb4EnXfLB2eLH9f33exOJ976B+xY8v6ILWXljK8rV1L hMP6V1ZN5iPH6YyRwGNhfg= X-Received: by 2002:a17:90b:1c0a:b0:38a:c3f:3b87 with SMTP id 98e67ed59e1d1-3933b8721acmr28569070a91.12.1787046621291; Tue, 18 Aug 2026 02:50:21 -0700 (PDT) Received: from at-Standard-PC-Q35-ICH9-2009.. ([14.97.72.18]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-326798cb9f5sm18466759eec.13.2026.08.18.02.50.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 02:50:20 -0700 (PDT) From: Atharva Tiwari To: Cc: Atharva Tiwari , Mika Westerberg , Andreas Noever , Mika Westerberg , Yehezkel Bernat , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 1/3] thunderbolt: Shift tb_apple_add_links to pci.c Date: Tue, 18 Aug 2026 05:50:02 -0400 Message-ID: <20260818095010.1857-2-atharvatiwarilinuxdev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260818095010.1857-1-atharvatiwarilinuxdev@gmail.com> References: <20260818095010.1857-1-atharvatiwarilinuxdev@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Shift tb_apple_add_links to pci.c as tb_apple_add_links calls pci functions. Suggested-by: Mika Westerberg Signed-off-by: Atharva Tiwari --- drivers/thunderbolt/pci.c | 71 ++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/tb.c | 72 +-------------------------------------- drivers/thunderbolt/tb.h | 1 + 3 files changed, 73 insertions(+), 71 deletions(-) diff --git a/drivers/thunderbolt/pci.c b/drivers/thunderbolt/pci.c index bbd186c29..83a4e1ba9 100644 --- a/drivers/thunderbolt/pci.c +++ b/drivers/thunderbolt/pci.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "nhi.h" #include "nhi_regs.h" @@ -261,6 +262,51 @@ static const struct tb_nhi_ops pci_nhi_default_ops = { .init_interrupts = nhi_pci_init_msi, }; +static bool tb_pci_add_links_discrete(struct pci_dev *nhi_pdev) +{ + struct pci_dev *pdev, *upstream = pci_upstream_bridge(nhi_pdev); + bool ret = false; + + while (upstream) { + if (!pci_is_pcie(upstream)) + return false; + if (pci_pcie_type(upstream) == PCI_EXP_TYPE_UPSTREAM) + break; + upstream = pci_upstream_bridge(upstream); + } + + if (!upstream) + return false; + + /* + * For each hotplug downstream port, create add device link + * back to NHI so that PCIe tunnels can be re-established after + * sleep. + */ + 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_pdev->dev, + DL_FLAG_AUTOREMOVE_SUPPLIER | + DL_FLAG_PM_RUNTIME); + if (link) { + dev_dbg(&nhi_pdev->dev, "created link from %s\n", + dev_name(&pdev->dev)); + ret = true; + } else { + dev_warn(&nhi_pdev->dev, "device link creation from %s failed\n", + dev_name(&pdev->dev)); + } + } + + return ret; +} /* Ice Lake specific NHI operations */ #define ICL_LC_MAILBOX_TIMEOUT 500 /* ms */ @@ -444,6 +490,31 @@ static const struct tb_nhi_ops icl_nhi_ops = { .init_interrupts = nhi_pci_init_msi, }; +/* + * 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. + */ +bool tb_pci_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_pdev); + default: + return false; + } +} + static int nhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { struct device *dev = &pdev->dev; diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c index f43f2d952..9c2fc7ff1 100644 --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c @@ -10,7 +10,6 @@ #include #include #include -#include #include "tb.h" #include "tb_regs.h" @@ -3302,75 +3301,6 @@ 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) -{ - struct pci_dev *nhi_pdev = to_pci_dev(nhi->dev); - struct pci_dev *upstream, *pdev; - bool ret; - - 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; - } - - upstream = pci_upstream_bridge(nhi_pdev); - while (upstream) { - if (!pci_is_pcie(upstream)) - return false; - if (pci_pcie_type(upstream) == PCI_EXP_TYPE_UPSTREAM) - break; - upstream = pci_upstream_bridge(upstream); - } - - if (!upstream) - return false; - - /* - * For each hotplug downstream port, create add device link - * back to NHI so that PCIe tunnels can be re-established after - * sleep. - */ - 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)); - } - } - - return ret; -} - struct tb *tb_probe(struct tb_nhi *nhi) { struct tb_cm *tcm; @@ -3400,7 +3330,7 @@ struct tb *tb_probe(struct tb_nhi *nhi) * before the PCIe/USB stack is resumed so complain here if we * found them missing. */ - if (!tb_apple_add_links(nhi) && !tb_acpi_add_links(nhi)) + if (!tb_pci_add_links(nhi) && !tb_acpi_add_links(nhi)) tb_warn(tb, "device links to tunneled native ports are missing!\n"); return tb; diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h index ec9192b61..6a285fe7f 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -1506,6 +1506,7 @@ static inline bool usb4_port_device_is_offline(const struct usb4_port *usb4) } void tb_check_quirks(struct tb_switch *sw); +bool tb_pci_add_links(struct tb_nhi *nhi); #ifdef CONFIG_ACPI bool tb_acpi_add_links(struct tb_nhi *nhi); -- 2.43.0