Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI: pciehp: Disable link and turn off slot power while removing
@ 2026-05-06 16:43 Mario Limonciello
  2026-05-06 17:55 ` Lukas Wunner
  2026-05-06 20:58 ` sashiko-bot
  0 siblings, 2 replies; 6+ messages in thread
From: Mario Limonciello @ 2026-05-06 16:43 UTC (permalink / raw)
  To: bhelgaas; +Cc: Mario Limonciello (AMD), linux-pci

From: "Mario Limonciello (AMD)" <superm1@kernel.org>

When a hotplug slot is removed, pciehp still leaves both the slot and link
active. If a device is still physically connected, platform firmware
may continue to poll the link. On some systems with Thunderbolt 3 devices
connected this prevents the system from shutting down until the device is
disconnected.

To fix this add code to pciehp_power_off_slot() to reverse the init
sequence from pciehp_power_on_slot() (power on, then enable link becomes
disable link, then power off).

Call this cleanup when releasing the controller so the link is disabled
during driver removal.

Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
 drivers/pci/hotplug/pciehp_hpc.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 4c62140a3cb44..6705dcaf1ad0c 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -348,6 +348,11 @@ static int pciehp_link_enable(struct controller *ctrl)
 	return __pciehp_link_set(ctrl, true);
 }
 
+static int pciehp_link_disable(struct controller *ctrl)
+{
+	return __pciehp_link_set(ctrl, false);
+}
+
 int pciehp_get_raw_indicator_status(struct hotplug_slot *hotplug_slot,
 				    u8 *status)
 {
@@ -558,6 +563,12 @@ int pciehp_power_on_slot(struct controller *ctrl)
 
 void pciehp_power_off_slot(struct controller *ctrl)
 {
+	int retval;
+
+	retval = pciehp_link_disable(ctrl);
+	if (retval)
+		ctrl_err(ctrl, "%s: Can not disable the link!\n", __func__);
+
 	pcie_write_cmd(ctrl, PCI_EXP_SLTCTL_PWR_OFF, PCI_EXP_SLTCTL_PCC);
 	ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__,
 		 pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL,
@@ -1096,6 +1107,8 @@ struct controller *pcie_init(struct pcie_device *dev)
 void pciehp_release_ctrl(struct controller *ctrl)
 {
 	cancel_delayed_work_sync(&ctrl->button_work);
+	if (POWER_CTRL(ctrl))
+		pciehp_power_off_slot(ctrl);
 	kfree(ctrl);
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-05-07  5:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-06 16:43 [PATCH] PCI: pciehp: Disable link and turn off slot power while removing Mario Limonciello
2026-05-06 17:55 ` Lukas Wunner
2026-05-06 19:16   ` Mario Limonciello
2026-05-07  4:26     ` Lukas Wunner
2026-05-07  5:03       ` Mario Limonciello
2026-05-06 20:58 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox