From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 C115F3F65FC for ; Mon, 17 Aug 2026 10:13:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786961635; cv=none; b=B8Mme39f6Q6TFmMZkMBfVg3acVdekGXWCgSTxuSXLnB4coxM7BvMH+zBqKipSnvLj/UFMvV7vqL+WroFfndTkw9R9PFAUcJ56ogCr3mGVWNYXInG6J+5G17N+nXVsQEXo0Q0iLidvYqD6ohIQDiSlpeNTmLlodrCIcYHq5Wcg9I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786961635; c=relaxed/simple; bh=CizFxtplh31MaoRyDhQUklAVO5brshVhPT06PE0+8xg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TueGz9EFTFYHarBMjvW1HJ9ZSRfkiuWuB6U4kpT6HDwaxlCxpwskc/NWBm1DY/GYNr2+HcGUP/1cRNYQemhKZHgvnOcl8NlI0YLsn+NqAHer8eIRZxqWQhrz+KvuZ+45w17a/UNwZdOJ7U1rtKIAeerMSAoYMPgqiLUnxT+eyc0= 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=OI7IT0r1; arc=none smtp.client-ip=209.85.216.47 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="OI7IT0r1" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-3811f512167so4523092a91.3 for ; Mon, 17 Aug 2026 03:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786961632; x=1787566432; 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=CeECLjqLcEJPD/Rw00vUe8sjoJNKjBRQIoIZeyp3OHU=; b=OI7IT0r1Bolw6qa/o0tSxBizGX35sJpLMwghqvi6DLyNVOfhfQLj8+x8wnEUWfVYIR +OFvr9KEaSrJcmsW+rNzPyflqsCoh+HxWSbY7kslKeroVLzxDmAlKtcxJaFQ/rUoJKj7 clJUPQq9Qhz9C1Fb9fHsxTNNqrxKbf9hwFqceSFbHZBP9kXh+oHhDGzisf4qLcUZ4+lq v3VYD/BAMk/GplaXojSigbY0vlWdw6yOwoI9nMxCUeuhJduhMGCml2HT4KK2ePvfWMQh zxwLdVAe5TmzLzI7DPuEpXuGyNU88WlMl75gP5GMKo+LGcQZ8RznRqTy725Dtk/6TMow Eenw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786961632; x=1787566432; 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=CeECLjqLcEJPD/Rw00vUe8sjoJNKjBRQIoIZeyp3OHU=; b=YAQgeQ8lrievFSsGvQ89pHq2Mm2vebDtcvawGGaFCzkCjNoXZ6CmcotWjCX9jXKxW/ SGbk+eKo+KjbWtzC9iI3H1bUr5ptiTi0jmsbOwFqTBBQOzTp+/YRCnbQBMDNX39Up/+3 uPp3NX7/wctY/+g1wSgfuBIyWM2v+ysmJH97l27EES4G7ZuIc8mvwKCb8hbxwKnTBMLw TCv/mDfevNIG+J0mgVYSVdA6IOvQU9ouysCHfTiPe5EOQwVBhQhZuFpmWMmWw8PjztML VhvcpoKbEqCpcPA8Af67QvQx1E+M+vtdFbx3kTxtXBBLcv8RD7aDpCJhsqCKRXCMuq4y 2VKQ== X-Forwarded-Encrypted: i=1; AHgh+Roflo0OGFQuz3zh/8zPIB0R5SuZl3ug0piKFdF/b4xU0k9RKjHuEU3sAEJGnKWagiNq2Sj1pDmiBWgUqkY=@vger.kernel.org X-Gm-Message-State: AOJu0Ywpq2gWh2qedJlqN3LOc0J8QKU63WugdVMxq1lQAd3qKCCYUSRP o8XDAFDnPRO4p1zwvaCVf8oQzYYjeZfMccI7+eyESdVO8F31aIqmpgo= X-Gm-Gg: AR+sD13Px/vF6bpNxNdbH576LfzUArJtUkP8dRZFEpSvD9+EPvYJb8DJ4rG2GspW+HG R7Gf8tUVKf+j1O8xPjcGrHfAd1RKIIFwEbi1zAbaxyEpXSCZ6wbYkh8CGnXXZA68N4aWgudV8DL du1NxwoX32mvhWRftclSMR76pTw8s9H4Gr+dQ9etQ3T4NOJ1x/PiDKeu5qxX4miIVi299+TFULa Qf8sxRMYBzeSbFm4n9N3HxWBvwymfGVqXIkCoNezkEn2MFgkoTTHdIUNicbsBytjxORJ1o4f1rx u9ZgE95aXxb6gl7aBeSo+/gtscw6IhubT7FuPq9vv/T0FtvJLKmhMA0UumI/GDygFrjHcOp/v2S 0pT9B9BIbAH20+U3IgfXNGpclhHU3daFqs4hCP2rvVv8VFYy22kBLnlIuesK2FKgXsVffzK0n78 F1IbWOEayNx0TTsmub1rSsJeHJ/EdPuvAq81YQpxGpaOaXPuWAQpLIfvk4nLkI7ucZk8RGUMwMQ tRj5RU+Ppo9fVQabxpI3A== X-Received: by 2002:a17:90b:3c0e:b0:393:1d92:db5 with SMTP id 98e67ed59e1d1-3933b8f1451mr25461296a91.10.1786961631875; Mon, 17 Aug 2026 03:13:51 -0700 (PDT) Received: from at-Standard-PC-Q35-ICH9-2009.. ([27.59.94.1]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-326761d3539sm4864117eec.0.2026.08.17.03.13.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2026 03:13:51 -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 v8 1/3] thunderbolt: Shift tb_apple_add_links to pci.c Date: Mon, 17 Aug 2026 06:13:22 -0400 Message-ID: <20260817101329.1517-2-atharvatiwarilinuxdev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260817101329.1517-1-atharvatiwarilinuxdev@gmail.com> References: <20260817101329.1517-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 | 73 +++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/tb.c | 72 +------------------------------------- drivers/thunderbolt/tb.h | 1 + 3 files changed, 75 insertions(+), 71 deletions(-) diff --git a/drivers/thunderbolt/pci.c b/drivers/thunderbolt/pci.c index bbd186c29..c3d5a36ab 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,53 @@ 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. + */ + pci_lock_rescan_remove(); + 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)); + } + } + pci_unlock_rescan_remove(); + + return ret; +} /* Ice Lake specific NHI operations */ #define ICL_LC_MAILBOX_TIMEOUT 500 /* ms */ @@ -444,6 +492,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