summaryrefslogtreecommitdiffstats
path: root/drivers/ata/libata-core.c
diff options
context:
space:
mode:
authorDamien Le Moal <dlemoal@kernel.org>2023-08-28 16:01:58 +0900
committerDamien Le Moal <dlemoal@kernel.org>2023-10-03 09:39:49 +0900
commit5b6fba546da246b3d0dd8465c07783e22629cc53 (patch)
tree0bb25a059e71f1d0e0b4c9c99ff4f78dbcd3f947 /drivers/ata/libata-core.c
parentcfead0dd81de95f52f416a676d4697484e093c8b (diff)
downloadlinux-stable-5b6fba546da246b3d0dd8465c07783e22629cc53.tar.gz
linux-stable-5b6fba546da246b3d0dd8465c07783e22629cc53.tar.bz2
linux-stable-5b6fba546da246b3d0dd8465c07783e22629cc53.zip
ata: libata-core: Detach a port devices on shutdown
Modify ata_pci_shutdown_one() to schedule EH to unload a port devices before freezing and thawing the port. This ensures that drives are cleanly disabled and transitioned to standby power mode when a PCI adapter is removed or the system is powered off. Signed-off-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Hannes Reinecke <hare@suse.de> Tested-by: Chia-Lin Kao (AceLan) <acelan.kao@canonical.com> Tested-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'drivers/ata/libata-core.c')
-rw-r--r--drivers/ata/libata-core.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 2b7b88e74c2b..a4d5d2fcf3b9 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -6164,10 +6164,24 @@ EXPORT_SYMBOL_GPL(ata_pci_remove_one);
void ata_pci_shutdown_one(struct pci_dev *pdev)
{
struct ata_host *host = pci_get_drvdata(pdev);
+ struct ata_port *ap;
+ unsigned long flags;
int i;
+ /* Tell EH to disable all devices */
for (i = 0; i < host->n_ports; i++) {
- struct ata_port *ap = host->ports[i];
+ ap = host->ports[i];
+ spin_lock_irqsave(ap->lock, flags);
+ ap->pflags |= ATA_PFLAG_UNLOADING;
+ ata_port_schedule_eh(ap);
+ spin_unlock_irqrestore(ap->lock, flags);
+ }
+
+ for (i = 0; i < host->n_ports; i++) {
+ ap = host->ports[i];
+
+ /* Wait for EH to complete before freezing the port */
+ ata_port_wait_eh(ap);
ap->pflags |= ATA_PFLAG_FROZEN;