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=1796459652; b=a7HVdI0Kol+PvnqAluc293D3drwRQKci1yg0dKv+bfczWR9auWYaRZ/CiN/ytRQJwQwg JryoBxRvIaWKvNLNmooUpP5dkRg4I4383g3C6wpbb8MiZAcO6KNOzfdL7Jc4T5+pGanzm ax+iKoEzpQ83eeTGaKkMDynguDa0Wph1dMGWZTcukRmITmEBgggSvAbogWoyk0UcB/H7c RlEHFklfK9mAzan3AHbKxfEZwlMz96JlfYRv46BeZbV98OvnRnz10UMC22/nHDz15beTy 4WEUHtGgdEwSR678tgEAAonYz+gUKw6zsSlpwzvOTLx4ou514WC39CtVNuDOUi3F1dw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796459652; 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=0SzHv6xG6Qe4XOXqDYmGE7dfKtj+Q4HxGvl4P5WpgXQ=; b=G6CINRhwlcfdy0pT+R4CvLkNyOO70N+FMdjCoOoKaqnEAzJeGWBEQOkGXDdUygoxQsoj pC78YcS6EqzyhgC0cVVt8tgex628spEYXqA0AHUPnr/t5w24YDv8c3XzVwtDq2r6O9LWD OXQqnbEeqA2lUhBGfi+/gZEqYEsZSwLUHCcKLllYJCQJG1IsmRuwJgd5zgrleMunc6J90 L+og6BeRl89dd3mOZ8cb+eD8+JwTbxmbZSwY1GMiPL8Tr7lm8tlOlYWGo39nvvQn6Ifvh nR8FTDwknMFqTe3W+nlSrlLX4N4W+0lopLOOlSn7VepXO0mjctEBHKX2P+LdTSIbg0w== 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="nsE/tGXK"; 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 5F39B606A6B0; Sat, 5 Dec 2026 08:34:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5F39B606A6B0 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) header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=nsE/tGXK X-UUID: a047f2e2f08611f1b9cf3d4034dccee2-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=0SzHv6xG6Qe4XOXqDYmGE7dfKtj+Q4HxGvl4P5WpgXQ=; b=nsE/tGXK2nvMzVjCuQGoKj45p8ylLOQR7gm5i71wZGkXODwEE2QK6Qc8bR/iz0vYP4A2utO3oA2uTpbr8eE+1VyyAe36kK4Rso8maRZm7so0ZEhkrsiUkEoFWBueg1jS9puQ4Ca8Bd35IwnrsKW4YAjsF8uXAR6h9ES5F98pb8Q=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.22,REQID:8fa1fe32-8606-4aa8-8c49-eb2c86289fad,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:50993767-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: a047f2e2f08611f1b9cf3d4034dccee2-20261205 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1039981875; Sat, 05 Dec 2026 16:34:03 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by MTKMBS09N1.mediatek.inc (172.21.101.35) 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:02 +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:01 +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 06/14] thunderbolt: Consolidate domain and NHI teardown into tb_nhi_remove() Date: Sat, 5 Dec 2026 16:33:31 +0800 Message-ID: <20261205083342.4009278-7-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, the remove and shutdown paths in pci.c manually do several core teardown steps which breaks abstraction symmetry with tb_nhi_probe() and exposes internal teardown primitives (tb_domain_remove, nhi_shutdown) across file and module boundaries. Consolidate this teardown sequence into a symmetric tb_nhi_remove() helper in nhi.c, and make nhi_shutdown() static to nhi.c. Backend bus drivers (PCI and platform) only need to handle their bus-specific power management before calling tb_nhi_remove(). Signed-off-by: Chunfeng Yun --- new patch --- drivers/thunderbolt/nhi.c | 31 ++++++++++++++++++++++++++++++- drivers/thunderbolt/nhi.h | 2 +- drivers/thunderbolt/pci.c | 16 +++------------- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c index 16562a8cd4a7..d55e1f03b68a 100644 --- a/drivers/thunderbolt/nhi.c +++ b/drivers/thunderbolt/nhi.c @@ -1216,7 +1216,7 @@ static int nhi_runtime_resume(struct device *dev) return tb_domain_runtime_resume(tb); } -void nhi_shutdown(struct tb_nhi *nhi) +static void nhi_shutdown(struct tb_nhi *nhi) { int i; @@ -1407,6 +1407,35 @@ int tb_nhi_probe(struct tb_nhi *nhi) return res; } +/** + * tb_nhi_remove() - Remove and release NHI instance and its domain + * @nhi: Pointer to the NHI structure + * @reset: Whether to force a host router reset (e.g. on shutdown/reboot) + * + * Common teardown sequence across all bus types. Stops and unregisters + * the domain, waits for domain release, and shuts down the NHI hardware. + */ +void tb_nhi_remove(struct tb_nhi *nhi, bool reset) +{ + struct device *dev = nhi->dev; + struct tb *tb = dev_get_drvdata(dev); + + /* + * On system shutdown/reboot force a host router reset so the + * connection manager asserts DPR on connected Thunderbolt 3 devices + * before the router tree is removed (see tb_stop()). + */ + if (reset) + nhi->host_reset = true; + + pm_runtime_get_sync(dev); + pm_runtime_dont_use_autosuspend(dev); + + tb_domain_remove(tb); + wait_for_completion(&nhi->domain_released); + nhi_shutdown(nhi); +} + /* * The tunneled pci bridges are siblings of us. Use resume_noirq to reenable * the tunnels asap. A corresponding pci quirk blocks the downstream bridges diff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h index 24a52f5f3fca..9aa167321cfe 100644 --- a/drivers/thunderbolt/nhi.h +++ b/drivers/thunderbolt/nhi.h @@ -31,7 +31,7 @@ int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data); enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi); irqreturn_t tb_ring_msix(int irq, void *data); int tb_nhi_probe(struct tb_nhi *nhi); -void nhi_shutdown(struct tb_nhi *nhi); +void tb_nhi_remove(struct tb_nhi *nhi, bool reset); extern const struct dev_pm_ops tb_nhi_pm_ops; /** diff --git a/drivers/thunderbolt/pci.c b/drivers/thunderbolt/pci.c index c1f9ed93c364..4b985e1c4363 100644 --- a/drivers/thunderbolt/pci.c +++ b/drivers/thunderbolt/pci.c @@ -568,21 +568,11 @@ static void nhi_pci_do_remove(struct pci_dev *pdev, bool reset) struct tb *tb = pci_get_drvdata(pdev); struct tb_nhi *nhi = tb->nhi; - /* - * On system shutdown/reboot force a host router reset so the - * connection manager asserts DPR on connected Thunderbolt 3 devices - * before the router tree is removed (see tb_stop()). - */ - if (reset) - nhi->host_reset = true; - - pm_runtime_get_sync(&pdev->dev); - pm_runtime_dont_use_autosuspend(&pdev->dev); + /* Restore PCI device to forbid state */ pm_runtime_forbid(&pdev->dev); - tb_domain_remove(tb); - wait_for_completion(&nhi->domain_released); - nhi_shutdown(nhi); + tb_nhi_remove(nhi, reset); + nhi_pci_release_msi(nhi_to_pci(nhi)); } -- 2.45.2