From: Mario Limonciello <mario.limonciello@amd.com>
To: <bhelgaas@google.com>
Cc: "Mario Limonciello (AMD)" <superm1@kernel.org>,
<linux-pci@vger.kernel.org>
Subject: [PATCH] PCI: pciehp: Disable link and turn off slot power while removing
Date: Wed, 6 May 2026 11:43:50 -0500 [thread overview]
Message-ID: <20260506164353.1278571-1-mario.limonciello@amd.com> (raw)
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
next reply other threads:[~2026-05-06 16:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-06 16:43 Mario Limonciello [this message]
2026-05-06 17:55 ` [PATCH] PCI: pciehp: Disable link and turn off slot power while removing 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260506164353.1278571-1-mario.limonciello@amd.com \
--to=mario.limonciello@amd.com \
--cc=bhelgaas@google.com \
--cc=linux-pci@vger.kernel.org \
--cc=superm1@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox