]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
scsi: ata: Stop disk on restart if ACPI power resources are found
authorMarkus Probst <markus.probst@posteo.de>
Tue, 4 Nov 2025 14:24:34 +0000 (14:24 +0000)
committerMartin K. Petersen <martin.petersen@oracle.com>
Sat, 8 Nov 2025 18:24:56 +0000 (13:24 -0500)
Some embedded devices have the ability to control whether power is
provided to the disks via the SATA power connector or not. ACPI power
resources are usually off by default, thus making it unclear if the
specific power resource will retain its state after a restart. If power
resources are defined on ATA ports / devices in ACPI, we should stop the
disk on SYSTEM_RESTART, to ensure the disk will not lose power while
active.

Add a new function, ata_acpi_dev_manage_restart(), that will be used to
determine if a disk should be stopped before restarting the system. If a
usable ACPI power resource has been found, it is assumed that the disk
will lose power after a restart and should be stopped to avoid unclean
shutdown due to power loss.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Markus Probst <markus.probst@posteo.de>
Link: https://patch.msgid.link/20251104142413.322347-4-markus.probst@posteo.de
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/ata/libata-acpi.c
drivers/ata/libata-scsi.c
drivers/ata/libata.h

index 4782e0f22d7f8e1d86b26b588894bbf4fd93767f..15e18d50dcc6dcd6cc75eee6a5b43cabfb0644a7 100644 (file)
@@ -245,6 +245,32 @@ void ata_acpi_bind_dev(struct ata_device *dev)
                                   ata_acpi_dev_uevent);
 }
 
+/**
+ * ata_acpi_dev_manage_restart - if the disk should be stopped (spun down) on
+ *                               system restart.
+ * @dev: target ATA device
+ *
+ * RETURNS:
+ * true if the disk should be stopped, otherwise false.
+ */
+bool ata_acpi_dev_manage_restart(struct ata_device *dev)
+{
+       struct device *tdev;
+
+       /*
+        * If ATA_FLAG_ACPI_SATA is set, the acpi fwnode is attached to the
+        * ata_device instead of the ata_port.
+        */
+       if (dev->link->ap->flags & ATA_FLAG_ACPI_SATA)
+               tdev = &dev->tdev;
+       else
+               tdev = &dev->link->ap->tdev;
+
+       if (!is_acpi_device_node(tdev->fwnode))
+               return false;
+       return acpi_bus_power_manageable(ACPI_HANDLE(tdev));
+}
+
 /**
  * ata_acpi_port_power_on - set the power state of the ata port to D0
  * @ap: target ATA port
index b43a3196e2be83d50f528de7b88574d159a4a1a4..026122bb6f2f2039376ca374f3c38c57d1ac828c 100644 (file)
@@ -1095,6 +1095,7 @@ int ata_scsi_dev_config(struct scsi_device *sdev, struct queue_limits *lim,
                 */
                sdev->manage_runtime_start_stop = 1;
                sdev->manage_shutdown = 1;
+               sdev->manage_restart = ata_acpi_dev_manage_restart(dev);
                sdev->force_runtime_start_on_system_start = 1;
        }
 
index 8cc7227f2d941461bdbc781973c12364999166cd..0e7ecac73680987d8b65bc4319cf0eb0858f5fab 100644 (file)
@@ -131,6 +131,7 @@ extern void ata_acpi_set_state(struct ata_port *ap, pm_message_t state);
 extern void ata_acpi_bind_port(struct ata_port *ap);
 extern void ata_acpi_bind_dev(struct ata_device *dev);
 extern void ata_acpi_port_power_on(struct ata_port *ap);
+extern bool ata_acpi_dev_manage_restart(struct ata_device *dev);
 extern acpi_handle ata_dev_acpi_handle(struct ata_device *dev);
 #else
 static inline void ata_acpi_dissociate(struct ata_host *host) { }
@@ -142,6 +143,7 @@ static inline void ata_acpi_set_state(struct ata_port *ap,
 static inline void ata_acpi_bind_port(struct ata_port *ap) {}
 static inline void ata_acpi_bind_dev(struct ata_device *dev) {}
 static inline void ata_acpi_port_power_on(struct ata_port *ap) {}
+static inline bool ata_acpi_dev_manage_restart(struct ata_device *dev) { return 0; }
 #endif
 
 /* libata-scsi.c */