From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 21F61386568 for ; Mon, 24 Aug 2026 18:43:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787597010; cv=none; b=DZnZvVwEY4ELaWU4crVEHu4cjodtQeeyBX6363KlhZg/Xlu+6gBi2MY1+X5xiG/NhYjLiUj7AzXT63kwLbS+iRwohgOvpJgZDswXgYCauP1TuM0j++Jfll1Nclc0djDi6C/7wgwfRG0CmgAkAaET39M5nPC6S9Fxr86/0MbhnWI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787597010; c=relaxed/simple; bh=jxzMQaiqawHQ/SOA9j7dDopTxyxQQALlbtrm64Kdsbc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YhgPKK9pqUo8TNcNvNnwOLh6DiGEmkDqu4dDwcRtkgn0JD76N263nQYCWoBwBX1kW16usGO+XIwnRCAIShApc9iKkwleI3e8p+5mcxWjIRDZf5WMe4S8xgpF5e/MM7c4a5Bu3OdySMehrW/Zxe/yDWz+5LfyDOcjjCKFbPjj+UI= 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=YmZzlch6; arc=none smtp.client-ip=209.85.215.178 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="YmZzlch6" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-cb5b8572b70so4585874a12.2 for ; Mon, 24 Aug 2026 11:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787597008; x=1788201808; 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=YmZzlch6dGLLxnZqIdAPifFuKFWQjwuJbZ07oAqcx/uscuWX8IDlQbFlTj1AeNjq7G FiwQFDHLDt9XhIU3lcZTbeh9VTLM7AySkjYhFrA1ZTNEoa9YhEDPy1MZbM2eeIJ2Apar M4E3oUu6mfux1JW4aCPGuW3OLVUeZJsr1qDsV8Dnk//SbpclB6BHsv+U7mwXCTeJNZrq s/xNmwqEIKlCZbfLQjmBPc8ZWIxfPv5cQQ/Zjncc8xHN92rpEmIhorCc+0vAf9AOYvEL Rz8pEiNSwpwCkFseXP/dW/6IWsVI3gwBiUmJhFVfyQp7KuoANet+ptJxgcTWLKFHznBq lVTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787597008; x=1788201808; 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=TAcWEk4g7WigdTav0v7Ax84y6J3h4R93CIBMZIqtPtLa4/cKNsJRE4t3PW4nxU9meJ Poxm00S8gk5wgG8qJKs+HpP3hUq1SMTUltBdgEzRZdfTysM0NcH2qYKK9DIVkNWbaiF/ kYxnq9hC2d7u64T2CAbhKOhqzKmbjtq8YwPOjCsaKg6vYbBI1zdYKL/TIFxBD5cVdcjq Fa+9obWg6QYFYiMT//6ru23h/1TWlnHUfci/tSdwf2USh60/CN8UqbP24QHf6cBCXDKX hnvul0CMDGiFSpt2HzB839QoqkXIHJgHVeGtQCWhpTROFA+hXEN1SflTrp7rU4XZppXX HPVw== X-Forwarded-Encrypted: i=1; AHgh+Rqs8kVJg9qxUMWq/dzNJamydHxGAUDI6rXts8JROsBOj8JaNEUeZfM/r1ZAuZLpLdAguMQ4x0p6RikxW+8=@vger.kernel.org X-Gm-Message-State: AFuF++lL0llQY5GB16RSdJBjDndeiBT+JN2iMt0pciygcUq9iXIlFWMu PyO4/2UfBevhNel8xcruECN9ZERzNkS9UoN87+sqYyn6zm2Nor5ZP6fmkQ+x1Vo= X-Gm-Gg: AR+sD13ijlOPBjEBKTuK8VcGH3uL5gHo9mrbgR1Z4+w37vF+eCewo3+eARIwb/3vZZY aeDRC2XoL0VRRhmIy56efrJhZ/F34moO7NbJZAq1zyYEBjJI8tr9M2jxrDgutOz7J/5M1OH+oVR gB2vJdAg16yVCpbOB2/6qMeHLtYyRqgXbLnxK2McmbnEle3OqTZUP64fxUeIujZHYlE/hmLdWWL xLVwrIIUTVMyIkc9UiTq4ss9UnicLSogXE6NJYOy0EzGWoTzBqDVbEphJRSmdn9oj3y+PoU6fxT gZi3IEZg1fbraaGl9Yj1zMfY98L2O0oDAx9/NbusD+xiHyBxso0ODojTS1syUcvyaGWcR3AzlW+ s2+V4X0QAPzcNNBB8l5MpcThAftsGkkIKASEF4iPiMOHY/1kXHKdds8GlF1noOT7ttOoQTxJgcd skLOO5OeppDNUYxYduZfbblx6D+t6HIzfSZd5aOo1biimBw+ptjYgxSIHrSddeYaQog1bHv3ZXz t0i4L5UqICEDNqLLBPEFZMl X-Received: by 2002:a05:6a20:9c8c:b0:3c3:b57b:627d with SMTP id adf61e73a8af0-3cd30063b97mr58971485637.12.1787597008427; Mon, 24 Aug 2026 11:43:28 -0700 (PDT) Received: from at-Standard-PC-Q35-ICH9-2009.. ([223.228.8.56]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-327f91d2d1esm29781367eec.17.2026.08.24.11.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 11:43:27 -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 RESEND v9 1/3] thunderbolt: Shift tb_apple_add_links to pci.c Date: Mon, 24 Aug 2026 14:42:54 -0400 Message-ID: <20260824184305.1234-2-atharvatiwarilinuxdev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260824184305.1234-1-atharvatiwarilinuxdev@gmail.com> References: <20260824184305.1234-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