Support power resources in ata ports
cover Support power resources in ata ports
This series adds support for power resources defined in acpi for ata ports. A device can define a power resource in an ata port, which then gets turned on right before the port is probed. This can be useful for devices, which have ata ports that are:
a: powered down by default
b: can be individually powered on
like in every synology nas device that supports a feature they call "deep-sleep". If thats the case it will be assumed, that the power resource won't survive reboots and therefore the disk will be stopped.
I will maybe extend it later to allow
- setting a delay between the probes (embedded devices have limited
power and if the disks are all spin up at the same time it would cause a power peak)
- powering down the ata ports (removing power from the disks) while
the disk is spin down (saving power and possibly disk lifetime)
For details, look at the individual commit messages.
Markus Probst (2):
Add manage_restart device attribute to scsi_disk Power on ata ports defined in ACPI before probing ports
drivers/ata/libata-acpi.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/ata/libata-core.c | 21 ++++++++++++++ drivers/ata/libata-scsi.c | 1 + drivers/ata/libata.h | 4 +++ drivers/scsi/sd.c | 35 +++++++++++++++++++++++- include/linux/libata.h | 1 + include/scsi/scsi_device.h | 6 ++++ 7 files changed, 135 insertions(+), 1 deletion(-)
PATCH 1/2 Add manage_restart device attribute to scsi_disk
there is already manage_shutdown, manage_system_start_stop and manage_runtime_start_stop device attributes that allows the high-level device driver (sd) manage the device power state, expect for the system_state SYSTEM_RESTART. With this device attribute, it is possible to let the high-level device driver (sd) manage the device power state for SYSTEM_RESTART too.
--- drivers/scsi/sd.c | 35 ++++++++++++++++++++++++++++++++++- include/scsi/scsi_device.h | 6 ++++++ 2 files changed, 40 insertions(+), 1 deletion(-)
drivers/scsi/sd.c +34 -1
@@ -318,6 +318,36 @@ static ssize_t manage_shutdown_store(struct device *dev, }static DEVICE_ATTR_RW (manage_shutdown); +static ssize_t manage_restart_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct scsi_disk *sdkp =to_scsi_disk (dev); +struct scsi_device *sdp = sdkp->device; + +return sysfs_emit (buf,"%u\n" , sdp->manage_restart); +} + + +static ssize_t manage_restart_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct scsi_disk *sdkp =to_scsi_disk (dev); +struct scsi_device *sdp = sdkp->device; +bool v; + +if (!capable (CAP_SYS_ADMIN )) +return -EACCES ; + +if (kstrtobool (buf, &v)) +return -EINVAL ; + + sdp->manage_restart = v; + +return count; +} +static DEVICE_ATTR_RW (manage_restart); +static ssize_t allow_restart_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -654,6 +684,7 @@ static struct attribute *sd_disk_attrs[] = { &dev_attr_manage_system_start_stop.attr, &dev_attr_manage_runtime_start_stop.attr, &dev_attr_manage_shutdown.attr, + &dev_attr_manage_restart.attr, &dev_attr_protection_type.attr, &dev_attr_protection_mode.attr, &dev_attr_app_tag_own.attr,
@@ -4175,7 +4206,9 @@ static void sd_shutdown(struct device *dev) (system_state == SYSTEM_POWER_OFF && sdkp->device->manage_shutdown) || (system_state == SYSTEM_RUNNING && - sdkp->device->manage_runtime_start_stop)) { + sdkp->device->manage_runtime_start_stop) || + (system_state == SYSTEM_RESTART && + sdkp->device->manage_restart)) {sd_printk (KERN_NOTICE , sdkp,"Stopping disk\n" );sd_start_stop_device (sdkp,0 ); }
include/scsi/scsi_device.h +6 -0
@@ -178,6 +178,12 @@ struct scsi_device {*/ unsigned manage_shutdown:1; +/* +* If true, let the high-level device driver (sd) manage the device +* power state for system restart (reboot) operations. +*/ + unsigned manage_restart:1; +/* * If set and if the device is runtime suspended, ask the high-level * device driver (sd) to force a runtime resume of the device.
Signature · 1 line
2.49.1
PATCH 2/2 Power on ata ports defined in ACPI before probing ports
some devices (for example every synology nas with "deep sleep" support) have the ability to power on and off each ata port individually. This turns the specific port on, if power manageable in acpi, before probing it.
This can later be extended to power down the ata ports (removing power from a disk) while the disk is spin down.
--- drivers/ata/libata-acpi.c | 68 +++++++++++++++++++++++++++++++++++++++ drivers/ata/libata-core.c | 21 ++++++++++++ drivers/ata/libata-scsi.c | 1 + drivers/ata/libata.h | 4 +++ include/linux/libata.h | 1 + 5 files changed, 95 insertions(+)
drivers/ata/libata-acpi.c +68 -0
@@ -245,6 +245,74 @@ void ata_acpi_bind_dev(struct ata_device *dev) ata_acpi_dev_uevent); } +/** +* ata_acpi_dev_manage_restart - if the disk should be stopped (spin 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) +{ +// If the device is power manageable and we assume the disk loses power on reboot. +if (dev->link->ap->flags &ATA_FLAG_ACPI_SATA ) { +if (!is_acpi_device_node (dev->tdev.fwnode)) +return false; +return acpi_bus_power_manageable (ACPI_HANDLE (&dev->tdev)); + } + +if (!is_acpi_device_node (dev->link->ap->tdev.fwnode)) +return false; +return acpi_bus_power_manageable (ACPI_HANDLE (&dev->link->ap->tdev)); +} + +/** +* ata_acpi_port_set_power_state - set the power state of the ata port +* @ap: target ATA port +* +* This function is called at the begin of ata_port_probe. +*/ +void ata_acpi_port_set_power_state (struct ata_port *ap,bool enable) +{ +acpi_handle handle; +unsigned char state; +int i; + +if (libata_noacpi) +return ; + +if (enable) + state =ACPI_STATE_D0 ; +else + state =ACPI_STATE_D3_COLD ; + +if (ap->flags &ATA_FLAG_ACPI_SATA ) { +for (i =0 ; i <ATA_MAX_DEVICES ; i++) { +if (!is_acpi_device_node (ap->link.device[i].tdev.fwnode)) +continue ; + handle =ACPI_HANDLE (&ap->link.device[i].tdev); +if (!acpi_bus_power_manageable (handle)) +continue ; +if (!acpi_bus_set_power (handle, state)) +ata_dev_info (&ap->link.device[i],"acpi: power was set to %d\n" , + enable); +else +ata_dev_info (&ap->link.device[i],"acpi: power failed to be set\n" ); + } + }else { +if (!is_acpi_device_node (ap->tdev.fwnode)) +return ; + handle =ACPI_HANDLE (&ap->tdev); +if (!acpi_bus_power_manageable (handle)) +return ; + +if (!acpi_bus_set_power (handle, state)) +ata_port_info (ap,"acpi: power was set to %d\n" , enable); +else +ata_port_info (ap,"acpi: power failed to be set\n" ); + } +} +/** * ata_acpi_dissociate - dissociate ATA host from ACPI objects * @host: target ATA host
drivers/ata/libata-core.c +21 -0
@@ -5899,11 +5899,32 @@ void ata_host_init(struct ata_host *host, struct device *dev, }EXPORT_SYMBOL_GPL (ata_host_init); +static inline void ata_port_set_power_state (struct ata_port *ap,bool enable) +{ +ata_acpi_port_set_power_state (ap, enable); +// Maybe add a way with device tree and regulators too? +} + +/** +* ata_dev_manage_restart - if the disk should be stopped (spin down) on system restart. +* @dev: target ATA device +* +* RETURNS: +* true if the disk should be stopped, otherwise false +*/ +bool ata_dev_manage_restart (struct ata_device *dev) +{ +return ata_acpi_dev_manage_restart (dev); +} +EXPORT_SYMBOL_GPL (ata_dev_manage_restart); +void ata_port_probe (struct ata_port *ap) {struct ata_eh_info *ehi = &ap->link.eh_info;unsigned long flags; +ata_port_set_power_state (ap, true); +/* kick EH for boot probing */ spin_lock_irqsave (ap->lock, flags);
drivers/ata/libata-scsi.c +1 -0
@@ -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_dev_manage_restart (dev); sdev->force_runtime_start_on_system_start =1 ; }
drivers/ata/libata.h +4 -0
@@ -130,6 +130,8 @@ extern void ata_acpi_on_disable(struct ata_device *dev);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_set_power_state (struct ata_port *ap,bool enable); +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) { }
@@ -140,6 +142,8 @@ static inline void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) { }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_set_power_state (struct ata_port *ap,bool enable) {} +static inline bool ata_acpi_dev_manage_restart (struct ata_device *dev) {return false; }#endif /* libata-scsi.c */
include/linux/libata.h +1 -0
@@ -1302,6 +1302,7 @@ extern int sata_link_debounce(struct ata_link *link,extern int sata_link_scr_lpm (struct ata_link *link,enum ata_lpm_policy policy,bool spm_wakeup);extern int ata_slave_link_init (struct ata_port *ap); +extern bool ata_dev_manage_restart (struct ata_device *dev);extern void ata_port_probe (struct ata_port *ap);extern struct ata_port *ata_port_alloc (struct ata_host *host);extern void ata_port_free (struct ata_port *ap);
Signature · 1 line
2.49.1
Damien Le Moal
maintainerRe: [PATCH 2/2] Power on ata ports defined in ACPI before probing ports
Quoted 4 lines · Markus Probst
some devices (for example every synology nas with "deep sleep" support) have the ability to power on and off each ata port individually. This turns the specific port on, if power manageable in acpi, before probing it.
Please add "ata: " prefix to the commit titel and capitalize the first letter of sentences.
The commit message above should also be improved. E.g. The "This" in "This turns on..." is unclear (I am assuming you mean "this patch" ?).
Quoted 18 lines
This can later be extended to power down the ata ports (removing power from a disk) while the disk is spin down.
Signed-off-by Markus Probst <[email protected]>--- drivers/ata/libata-acpi.c | 68 +++++++++++++++++++++++++++++++++++++++ drivers/ata/libata-core.c | 21 ++++++++++++ drivers/ata/libata-scsi.c | 1 + drivers/ata/libata.h | 4 +++ include/linux/libata.h | 1 + 5 files changed, 95 insertions(+)drivers/ata/libata-acpi.c +0
-0
drivers/ata/libata-acpi.c void ata_acpi_bind_dev(struct ata_device *dev) · line 249
Quoted 5 lines
drivers/ata/libata-acpi.c +2
-0@@ -245,6 +245,74 @@ void ata_acpi_bind_dev(struct ata_device *dev) ata_acpi_dev_uevent); } +/** +* ata_acpi_dev_manage_restart - if the disk should be stopped (spin down) on system restart.
Long line. Please split at 80 chars.
drivers/ata/libata-acpi.c void ata_acpi_bind_dev(struct ata_device *dev) · line 257
Quoted 8 lines
drivers/ata/libata-acpi.c +8
-0+* @dev: target ATA device +* +* RETURNS: +* true if the disk should be stopped, otherwise false +*/ +bool ata_acpi_dev_manage_restart (struct ata_device *dev) +{ +// If the device is power manageable and we assume the disk loses power on reboot.
This is not C++. Please use C style comments and split the long line.
Quoted 6 lines
drivers/ata/libata-acpi.c +6
-0+if (dev->link->ap->flags &ATA_FLAG_ACPI_SATA ) { +if (!is_acpi_device_node (dev->tdev.fwnode)) +return false; +return acpi_bus_power_manageable (ACPI_HANDLE (&dev->tdev)); + } +
drivers/ata/libata-acpi.c void ata_acpi_bind_dev(struct ata_device *dev) · line 273
Quoted 10 lines
drivers/ata/libata-acpi.c +10
-0+if (!is_acpi_device_node (dev->link->ap->tdev.fwnode)) +return false; +return acpi_bus_power_manageable (ACPI_HANDLE (&dev->link->ap->tdev)); +} + +/** +* ata_acpi_port_set_power_state - set the power state of the ata port +* @ap: target ATA port +* +* This function is called at the begin of ata_port_probe.
...at the beginning of ata_port_probe().
Quoted 18 lines
drivers/ata/libata-acpi.c +18
-0+*/ +void ata_acpi_port_set_power_state (struct ata_port *ap,bool enable) +{ +acpi_handle handle; +unsigned char state; +int i; + +if (libata_noacpi) +return ; + +if (enable) + state =ACPI_STATE_D0 ; +else + state =ACPI_STATE_D3_COLD ; + +if (ap->flags &ATA_FLAG_ACPI_SATA ) { +for (i =0 ; i <ATA_MAX_DEVICES ; i++) { +if (!is_acpi_device_node (ap->link.device[i].tdev.fwnode))
drivers/ata/libata-acpi.c void ata_acpi_bind_dev(struct ata_device *dev) · line 301
Quoted 10 lines
drivers/ata/libata-acpi.c +10
-0+continue ; + handle =ACPI_HANDLE (&ap->link.device[i].tdev); +if (!acpi_bus_power_manageable (handle)) +continue ; +if (!acpi_bus_set_power (handle, state)) +ata_dev_info (&ap->link.device[i],"acpi: power was set to %d\n" , + enable); +else +ata_dev_info (&ap->link.device[i],"acpi: power failed to be set\n" ); + }
Add a return here to avoid the else.
drivers/ata/libata-acpi.c void ata_acpi_bind_dev(struct ata_device *dev) · line 310
Quoted 9 lines
drivers/ata/libata-acpi.c +9
-0+ }else { +if (!is_acpi_device_node (ap->tdev.fwnode)) +return ; + handle =ACPI_HANDLE (&ap->tdev); +if (!acpi_bus_power_manageable (handle)) +return ; + +if (!acpi_bus_set_power (handle, state)) +ata_port_info (ap,"acpi: power was set to %d\n" , enable);
ata_port_debug(ap, "acpi: power %sabled\n",
enable ? "en" : "dis");
drivers/ata/libata-acpi.c void ata_acpi_bind_dev(struct ata_device *dev) · line 312
Quoted 2 lines
drivers/ata/libata-acpi.c +2
-0+else +ata_port_info (ap,"acpi: power failed to be set\n" );
ata_port_err(ap, "acpi: failed to set power state\n");
Overall, this hunk is the same as what is done in the loop above. So maybe create a helper function instead of repeating the same procedure.
Quoted 11 lines
drivers/ata/libata-acpi.c +3
-0+ } +} +/** * ata_acpi_dissociate - dissociate ATA host from ACPI objects * @host: target ATA host drivers/ata/libata-core.c +0
-0
drivers/ata/libata-core.c void ata_host_init(struct ata_host *host, struct device *dev, · line 5905
Quoted 7 lines
drivers/ata/libata-core.c +4
-0@@ -5899,11 +5899,32 @@ void ata_host_init(struct ata_host *host, struct device *dev, }EXPORT_SYMBOL_GPL (ata_host_init); +static inline void ata_port_set_power_state (struct ata_port *ap,bool enable) +{ +ata_acpi_port_set_power_state (ap, enable); +// Maybe add a way with device tree and regulators too?
Drop this comment please.
Quoted 4 lines
drivers/ata/libata-core.c +4
-0+} + +/** +* ata_dev_manage_restart - if the disk should be stopped (spin down) on system restart.
drivers/ata/libata-core.c void ata_host_init(struct ata_host *host, struct device *dev, · line 5919
Quoted 10 lines
drivers/ata/libata-core.c +10
-0+* @dev: target ATA device +* +* RETURNS: +* true if the disk should be stopped, otherwise false +*/ +bool ata_dev_manage_restart (struct ata_device *dev) +{ +return ata_acpi_dev_manage_restart (dev); +} +EXPORT_SYMBOL_GPL (ata_dev_manage_restart);
Why the export ? libata-core and libata-scsi are compiled together as libata.ko. The export should not be needed.
Quoted 57 lines
drivers/ata/libata-core.c +3
-0+void ata_port_probe (struct ata_port *ap) {struct ata_eh_info *ehi = &ap->link.eh_info;unsigned long flags; +ata_port_set_power_state (ap, true); +/* kick EH for boot probing */ spin_lock_irqsave (ap->lock, flags);drivers/ata/libata-scsi.c +1
-0@@ -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_dev_manage_restart (dev); sdev->force_runtime_start_on_system_start =1 ; }drivers/ata/libata.h +4
-0@@ -130,6 +130,8 @@ extern void ata_acpi_on_disable(struct ata_device *dev);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_set_power_state (struct ata_port *ap,bool enable); +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) { }@@ -140,6 +142,8 @@ static inline void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) { }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_set_power_state (struct ata_port *ap,bool enable) {} +static inline bool ata_acpi_dev_manage_restart (struct ata_device *dev) {return false; }#endif /* libata-scsi.c */ include/linux/libata.h +1
-0@@ -1302,6 +1302,7 @@ extern int sata_link_debounce(struct ata_link *link,extern int sata_link_scr_lpm (struct ata_link *link,enum ata_lpm_policy policy,bool spm_wakeup);extern int ata_slave_link_init (struct ata_port *ap); +extern bool ata_dev_manage_restart (struct ata_device *dev);extern void ata_port_probe (struct ata_port *ap);extern struct ata_port *ata_port_alloc (struct ata_host *host);extern void ata_port_free (struct ata_port *ap);
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH 2/2] Power on ata ports defined in ACPI before probing ports
Quoted 136 lines · Damien Le Moal
Quoted 7 lines · Markus Probst
some devices (for example every synology nas with "deep sleep" support)
have the ability to power on and off each ata port individually. This
turns the specific port on, if power manageable in acpi, before probing
it.Please add "ata: " prefix to the commit titel and capitalize the first letter of
sentences.The commit message above should also be improved. E.g. The "This" in "This turns
on..." is unclear (I am assuming you mean "this patch" ?).Quoted 22 lines
This can later be extended to power down the ata ports (removing power
from a disk) while the disk is spin down.Signed-off-by Markus Probst <[email protected]>---
drivers/ata/libata-acpi.c | 68
+++++++++++++++++++++++++++++++++++++++
drivers/ata/libata-core.c | 21 ++++++++++++
drivers/ata/libata-scsi.c | 1 +
drivers/ata/libata.h | 4 +++
include/linux/libata.h | 1 +5 files changed, 95 insertions(+)drivers/ata/libata-acpi.c +0
-0@@ -245,6 +245,74 @@ void ata_acpi_bind_dev(struct ata_device *dev) ata_acpi_dev_uevent); }Quoted 4 lines
+/**
+ *ata_acpi_dev_manage_restart- if the disk should be stopped (spin down) on system restart.Long line. Please split at 80 chars.
Quoted 9 lines
+ * @dev: target ATA device
+ *
+ * RETURNS:
+ * true if the disk should be stopped, otherwise false
+ */drivers/ata/libata-acpi.c +3
-0+bool ata_acpi_dev_manage_restart (struct ata_device *dev) +{ +// If the device is power manageable and we assume the disk loses power on reboot.
This is not C++. Please use C style comments and split the long line.
Quoted 15 lines
drivers/ata/libata-acpi.c +4
-0+if (dev->link->ap->flags &ATA_FLAG_ACPI_SATA ) { +if (!is_acpi_device_node (dev->tdev.fwnode)) +return false; + return acpi_bus_power_manageable(ACPI_HANDLE(&dev-Quoted 1 line
tdev));
drivers/ata/libata-acpi.c +5
-0+ } + +if (!is_acpi_device_node (dev->link->ap->tdev.fwnode)) +return false; + return acpi_bus_power_manageable(ACPI_HANDLE(&dev->link-Quoted 1 line
ap->tdev));drivers/ata/libata-acpi.c +4
-0+} + +/** +* ata_acpi_port_set_power_state - set the power state of the ata Quoted 4 lines
port
+ * @ap: target ATA port
+ *
+ * This function is called at the begin ofata_port_probe....at the beginning of
ata_port_probe().Quoted 32 lines
+ */
+voidata_acpi_port_set_power_state(struct ata_port *ap, bool enable)drivers/ata/libata-acpi.c +16
-0+{ + acpi_handle handle; + unsigned char state; + int i; + + if (libata_noacpi) + return; + + if (enable) + state = ACPI_STATE_D0; + else + state = ACPI_STATE_D3_COLD; + + if (ap->flags & ATA_FLAG_ACPI_SATA) { + for (i = 0; i < ATA_MAX_DEVICES; i++) { + if (!is_acpi_device_node(ap-Quoted 1 line
link.device[i].tdev.fwnode))
drivers/ata/libata-acpi.c +2
-0+continue ; + handle = ACPI_HANDLE(&ap-Quoted 1 line
link.device[i].tdev);
drivers/ata/libata-acpi.c +4
-0+if (!acpi_bus_power_manageable (handle)) +continue ; +if (!acpi_bus_set_power (handle, state)) + ata_dev_info(&ap->link.device[i],"acpi: power was set to %d\n",
drivers/ata/libata-acpi.c +3
-0+ enable); + else + ata_dev_info(&ap->link.device[i],"acpi: power failed to be set\n");
drivers/ata/libata-acpi.c
Quoted 1 line
drivers/ata/libata-acpi.c +1
-0+ }Add a return here to avoid the else.
Quoted 10 lines
drivers/ata/libata-acpi.c +9
-0+ }else { +if (!is_acpi_device_node (ap->tdev.fwnode)) +return ; + handle =ACPI_HANDLE (&ap->tdev); +if (!acpi_bus_power_manageable (handle)) +return ; + +if (!acpi_bus_set_power (handle, state)) + ata_port_info(ap, "acpi: power was set to%d\n", enable);
ata_port_debug(ap, "acpi: power %sabled\n",
enable ? "en" : "dis");Quoted 3 lines
drivers/ata/libata-acpi.c +2
-0+else + ata_port_info(ap, "acpi: power failed tobe set\n");
ata_port_err(ap, "acpi: failed to set power state\n");
Quoted 3 lines
Overall, this hunk is the same as what is done in the loop above. So maybe
create a helper function instead of repeating the same procedure.
I don't think this can be avoided while still having proper log messages.
In the first hunk the power state will be set on a ata_device, on the second hunk on a ata_port.
Quoted 103 lines
Quoted 18 lines
drivers/ata/libata-acpi.c +3
-0+ } +} +/**
*ata_acpi_dissociate- dissociate ATA host from ACPI objects
* @host: target ATA hostdrivers/ata/libata-core.c +0
-0@@ -5899,11 +5899,32 @@ void ata_host_init(struct ata_host *host,struct device *dev, } EXPORT_SYMBOL_GPL(ata_host_init);
+static inline voidata_port_set_power_state(struct ata_port *ap, bool enable)drivers/ata/libata-core.c void ata_host_init(struct ata_host *host, struct device *dev, · line 5905
Quoted 3 lines
drivers/ata/libata-core.c +3
-0+{ +ata_acpi_port_set_power_state (ap, enable); +// Maybe add a way with device tree and regulators too? Drop this comment please.
Quoted 10 lines
drivers/ata/libata-core.c +4
-0+} + +/** +* ata_dev_manage_restart - if the disk should be stopped (spin down) on system restart.
+ * @dev: target ATA device
+ *
+ * RETURNS:
+ * true if the disk should be stopped, otherwise false
+ */drivers/ata/libata-core.c void ata_host_init(struct ata_host *host, struct device *dev, · line 5919
Quoted 5 lines
drivers/ata/libata-core.c +5
-0+bool ata_dev_manage_restart (struct ata_device *dev) +{ +return ata_acpi_dev_manage_restart (dev); +} +EXPORT_SYMBOL_GPL (ata_dev_manage_restart);Why the export ? libata-core and libata-scsi are compiled together as libata.ko.
The export should not be needed.Quoted 59 lines
+
voidata_port_probe(struct ata_port *ap)
{
structata_eh_info*ehi =&ap->link.eh_info; unsigned long flags;drivers/ata/libata-core.c +2
-0+ata_port_set_power_state (ap, true); +/* kick EH for boot probing */
spin_lock_irqsave(ap->lock, flags);drivers/ata/libata-scsi.c +1
-0@@ -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_dev_manage_restart (dev); sdev->force_runtime_start_on_system_start = 1;}
drivers/ata/libata.h +0
-0@@ -130,6 +130,8 @@ extern void ata_acpi_on_disable(struct ata_device *dev);extern void
ata_acpi_set_state(struct ata_port *ap, pm_message_t state);
extern voidata_acpi_bind_port(struct ata_port *ap); extern voidata_acpi_bind_dev(struct ata_device *dev); +extern voidata_acpi_port_set_power_state(struct ata_port *ap, bool enable);
+extern boolata_acpi_dev_manage_restart(struct ata_device *dev); externacpi_handleata_dev_acpi_handle(struct ata_device *dev); #else
static inline voidata_acpi_dissociate(struct ata_host *host){ }drivers/ata/libata.h +2
-0@@ -140,6 +142,8 @@ static inline void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) { } 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_set_power_state (struct ata_port *ap,bool enable) {} +static inline bool ata_acpi_dev_manage_restart (struct ata_device *dev) {return false; }#endif
/*libata-scsi.c*/include/linux/libata.h +0
-0@@ -1302,6 +1302,7 @@ extern int sata_link_debounce(struct ata_link *link,
Quoted 9 lines
Quoted 8 lines
extern int sata_link_scr_lpm(struct
ata_link*link, enumata_lpm_policypolicy,
boolspm_wakeup);
extern intata_slave_link_init(struct ata_port *ap); +extern boolata_dev_manage_restart(struct ata_device *dev); extern voidata_port_probe(struct ata_port *ap); extern structata_port*ata_port_alloc(structata_host*host); extern voidata_port_free(struct ata_port *ap);
Thanks
- Markus Probst
Niklas Cassel
maintainerRe: [PATCH 2/2] Power on ata ports defined in ACPI before probing ports
In reply to Markus ProbstQuoted 1 line · Markus Probst
some devices (for example every synology nas with "deep sleep" support)
Some devices?
I assume you mean the HBA and not the devices connected to the HBA.
Quoted 6 lines
have the ability to power on and off each ata port individually. This turns the specific port on, if power manageable in acpi, before probing it.
This can later be extended to power down the ata ports (removing power from a disk) while the disk is spin down.
Spun down?
Overall this commit message needs some serious improvement.
I have no idea what Synology NAS with "deep sleep" support is.
We don't add support for vendor specific features.
Please reference the proper ATA ACS / AHCI / SATA / ACPI specification, including the version of said specification and which section in that specification.
Kind regards,
Niklas
Re: [PATCH 2/2] Power on ata ports defined in ACPI before probing ports
Quoted 6 lines · Niklas Cassel
Quoted 2 lines · Markus Probst
some devices (for example every synology nas with "deep sleep" support)
Some devices?
I assume you mean the HBA and not the devices connected to the HBA.
Embedded devices. There are 2 connectors to a sata disk. One for the data connection to the sata controller. Another one to the power supply (so the disk gets the power). This patch tells the power supply for the disk to give the disk power (if one is defined in acpi).
Quoted 8 lines
Quoted 8 lines
have the ability to power on and off each ata port individually. This
turns the specific port on, if power manageable in acpi, before probing
it.
Quoted 5 lines
Quoted 3 lines
This can later be extended to power down the ata ports (removing power
from a disk) while the disk is spin down.Spun down?
Yes
Quoted 5 lines
Overall this commit message needs some serious improvement.
I have no idea what Synology NAS with "deep sleep" support is.
Synology produces NAS devices. Some of those devices have something they call "deep sleep". In this case, if a sata disk gets power is controlled by a gpio and is *off by default*.
Quoted 2 lines
We don't add support for vendor specific features.
"deep sleep" allows to power down disks while they are spun down (removing power from the disk). If thats not wanted in the linux kernel fine.
If you were referring to this patch instead (which just powers on the disks, via a generic acpi way that is not vendor specific or proprietary):
I think that the sata disks in those devices get power is not a feature, its hardware support. Otherwise you can't access the disks at all.
Quoted 5 lines
Please reference the proper ATA ACS / AHCI / SATA / ACPI specification,
including the version of said specification and which section in that specification.
Ports on the SATA Controller are declared as devices in ACPI. (see ACPI 6.5, Section 9.7.3.2, the SATA namespace example. The only time the SATA namespace is even mentioned).
According to ACPI 6.5, Section 3.4.1, the os has to get information about the power management features the device supports while it enumerates the device (the linux kernel already does this for the ata port/device). According to ACPI 6.5, Section 3.4.2 "The OS must turn on power to the device before it can send commands to the device." (this does not happen yet)
Quoted 4 lines
Kind regards,
Niklas
Thanks
- Markus Probst
Quoted 643 lines
Quoted 643 lines
Quoted 643 lines
Quoted 643 lines
Quoted 643 lines
Quoted 643 lines
Quoted 643 lines
Quoted 643 lines
Quoted 643 lines
Quoted 643 lines
Quoted 643 lines
Quoted 643 lines
Quoted 643 lines
Niklas Cassel
maintainerRe: [PATCH 2/2] Power on ata ports defined in ACPI before probing ports
Quoted 11 lines · Markus Probst
Quoted 6 lines · Niklas Cassel
Quoted 2 lines · Markus Probst
some devices (for example every synology nas with "deep sleep" support)
Some devices?
I assume you mean the HBA and not the devices connected to the HBA.Embedded devices. There are 2 connectors to a sata disk. One for the data connection to the sata controller. Another one to the power supply (so the disk gets the power). This patch tells the power supply for the disk to give the disk power (if one is defined in acpi).
Ok, please add this to the commit message.
Quoted 3 lines
Synology produces NAS devices. Some of those devices have something they call "deep sleep". In this case, if a sata disk gets power is controlled by a gpio and is *off by default*.
Please add this to the commit message.
We already have DevSleep, which is a feature implemented in the SATA specification, where the HBA asserts a signal (DEVSLP, which on some boards is just a GPIO), while this signal is asserted the device may completely power down its PHY, and it may also choose to power down other subsystems, as long as it can meet the exit latency requirements. (The device should exit DevSleep when the DEVSLP signal is deasserted.)
For more info see e.g.
https://sata-io.org/sites/default/files/documents/SATADevSleep-and-RTD3-WP-037-20120102-2_final.pdf
Since this patch implements something similar to DevSleep, but rather, IIUC, for the SATA power itself?
How is SATA power supplied tied to a port in ACPI? If you have a desktop you have a PSU, and don't really know which supply is for which port.
In SATA, we also have PxSCTL (SRC2: SControl) where we can completely disable a port and port the PHY in offline mode, see:
https://github.com/torvalds/linux/blob/v6.17/drivers/ata/libata-sata.c#L415-L419
So, considering how many ways we already have to disable/power off a port, you might understand why I think it is extra important that you document exactly how, and why we need yet another way to disable/power on/off a port.
Kind regards,
Niklas
Damien Le Moal
maintainerRe: [PATCH 1/2] Add manage_restart device attribute to scsi_disk
In reply to Markus ProbstQuoted 18 lines · Markus Probst
there is already
manage_shutdown,manage_system_start_stopandmanage_runtime_start_stopdevice attributes that allows the high-level device driver (sd) manage the device power state, expect for thesystem_stateSYSTEM_RESTART. With this device attribute, it is possible to let the high-level device driver (sd) manage the device power state forSYSTEM_RESTARTtoo.Signed-off-by Markus Probst <[email protected]>--- drivers/scsi/sd.c | 35 ++++++++++++++++++++++++++++++++++- include/scsi/scsi_device.h | 6 ++++++ 2 files changed, 40 insertions(+), 1 deletion(-)drivers/scsi/sd.c +0
-0
drivers/scsi/sd.c static ssize_t manage_shutdown_store(struct device *dev, · line 325
Quoted 8 lines
drivers/scsi/sd.c +5
-0@@ -318,6 +318,36 @@ static ssize_t manage_shutdown_store(struct device *dev, }static DEVICE_ATTR_RW (manage_shutdown); +static ssize_t manage_restart_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct scsi_disk *sdkp =to_scsi_disk (dev); +struct scsi_device *sdp = sdkp->device;
sdp is not really needed.
drivers/scsi/sd.c static ssize_t manage_shutdown_store(struct device *dev, · line 336
Quoted 11 lines
drivers/scsi/sd.c +11
-0+ +return sysfs_emit (buf,"%u\n" , sdp->manage_restart); +} + + +static ssize_t manage_restart_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct scsi_disk *sdkp =to_scsi_disk (dev); +struct scsi_device *sdp = sdkp->device;
Same here.
Quoted 41 lines
drivers/scsi/sd.c +18
-1+bool v; + +if (!capable (CAP_SYS_ADMIN )) +return -EACCES ; + +if (kstrtobool (buf, &v)) +return -EINVAL ; + + sdp->manage_restart = v; + +return count; +} +static DEVICE_ATTR_RW (manage_restart); +static ssize_t allow_restart_show (struct device *dev,struct device_attribute *attr,char *buf) {@@ -654,6 +684,7 @@ static struct attribute *sd_disk_attrs[] = { &dev_attr_manage_system_start_stop.attr, &dev_attr_manage_runtime_start_stop.attr, &dev_attr_manage_shutdown.attr, + &dev_attr_manage_restart.attr, &dev_attr_protection_type.attr, &dev_attr_protection_mode.attr, &dev_attr_app_tag_own.attr,@@ -4175,7 +4206,9 @@ static void sd_shutdown(struct device *dev) (system_state == SYSTEM_POWER_OFF && sdkp->device->manage_shutdown) || (system_state == SYSTEM_RUNNING && - sdkp->device->manage_runtime_start_stop)) { + sdkp->device->manage_runtime_start_stop) || + (system_state == SYSTEM_RESTART && + sdkp->device->manage_restart)) {sd_printk (KERN_NOTICE , sdkp,"Stopping disk\n" );sd_start_stop_device (sdkp,0 ); }include/scsi/scsi_device.h +0
-0
include/scsi/scsi_device.h struct scsi_device { · line 183
Quoted 6 lines
include/scsi/scsi_device.h +3
-0@@ -178,6 +178,12 @@ struct scsi_device {*/ unsigned manage_shutdown:1; +/* +* If true, let the high-level device driver (sd) manage the device +* power state for system restart (reboot) operations.
What about cold boot ? Same is needed, no ? The name "manage_restart" is a bit confusing since we already have manage_system_start_stop, manage_runtime_start_stop and manage_shutdown. I do not have a better suggestion though.
Quoted 6 lines
include/scsi/scsi_device.h +3
-0+*/ + unsigned manage_restart:1; +/* * If set and if the device is runtime suspended, ask the high-level * device driver (sd) to force a runtime resume of the device.
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH 1/2] Add manage_restart device attribute to scsi_disk
Quoted 27 lines · Damien Le Moal
Quoted 26 lines · Markus Probst
there is already
manage_shutdown,manage_system_start_stopandmanage_runtime_start_stopdevice attributes that allows the high- level
device driver (sd) manage the device power state, expect for thesystem_stateSYSTEM_RESTART. With this device attribute, it is possible to
let the high-level device driver (sd) manage the device power state forSYSTEM_RESTARTtoo.Signed-off-by Markus Probst <[email protected]>---
drivers/scsi/sd.c | 35
++++++++++++++++++++++++++++++++++-
include/scsi/scsi_device.h | 6 ++++++2 files changed, 40 insertions(+), 1 deletion(-)drivers/scsi/sd.c +0
-0@@ -318,6 +318,36 @@ static ssize_t manage_shutdown_store(structdevice *dev, } static DEVICE_ATTR_RW(manage_shutdown);
Quoted 8 lines
drivers/scsi/sd.c static ssize_t manage_shutdown_store(struct device *dev, · line 325
Quoted 6 lines
drivers/scsi/sd.c +2
-0+static ssize_t manage_restart_show(struct device *dev, + struct device_attribute *attr,char *buf)
drivers/scsi/sd.c +3
-0+{ +struct scsi_disk *sdkp =to_scsi_disk (dev); +struct scsi_device *sdp = sdkp->device;sdp is not really needed.
Then it would be inconsistent with manage_shutdown_*, manage_runtime_start_stop_*, manage_system_start_stop_*, there it has the sdp variable declared.
Quoted 59 lines
drivers/scsi/sd.c static ssize_t manage_shutdown_store(struct device *dev, · line 336
Quoted 12 lines
drivers/scsi/sd.c +11
-0+ +return sysfs_emit (buf,"%u\n" , sdp->manage_restart); +} + + +static ssize_t manage_restart_store (struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ +struct scsi_disk *sdkp =to_scsi_disk (dev); +struct scsi_device *sdp = sdkp->device;Same here.
Quoted 44 lines
drivers/scsi/sd.c +14
-0+bool v; + +if (!capable (CAP_SYS_ADMIN )) +return -EACCES ; + +if (kstrtobool (buf, &v)) +return -EINVAL ; + + sdp->manage_restart = v; + +return count; +} +static DEVICE_ATTR_RW (manage_restart); +static
ssize_t
allow_restart_show(struct device *dev, structdevice_attribute*attr, char *buf)
{drivers/scsi/sd.c +1
-0@@ -654,6 +684,7 @@ static struct attribute *sd_disk_attrs[] = { &dev_attr_manage_system_start_stop.attr, &dev_attr_manage_runtime_start_stop.attr, &dev_attr_manage_shutdown.attr, + &dev_attr_manage_restart.attr, &dev_attr_protection_type.attr, &dev_attr_protection_mode.attr, &dev_attr_app_tag_own.attr,@@ -4175,7 +4206,9 @@ static void sd_shutdown(struct device *dev)(
system_state==SYSTEM_POWER_OFF&&
sdkp->device->manage_shutdown) ||
(system_state==SYSTEM_RUNNING&&drivers/scsi/sd.c +3
-1- sdkp->device->manage_runtime_start_stop)) { + sdkp->device->manage_runtime_start_stop) || + (system_state == SYSTEM_RESTART && + sdkp->device->manage_restart)) {
sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");sd_start_stop_device(sdkp, 0);
}include/scsi/scsi_device.h +0
-0@@ -178,6 +178,12 @@ struct scsi_device {*/
Quoted 8 lines
include/scsi/scsi_device.h struct scsi_device { · line 183
Quoted 6 lines
include/scsi/scsi_device.h +0
-0unsigned manage_shutdown:1;include/scsi/scsi_device.h +2
-0+/* +* If true, let the high-level device driver (sd) manage the device
include/scsi/scsi_device.h +1
-0+* power state for system restart (reboot) operations. What about cold boot ? Same is needed, no ?
Not sure what you mean with cold boot here.
Quoted 5 lines
The name "
manage_restart" is a bit
confusing since we already havemanage_system_start_stop,manage_runtime_start_stopandmanage_shutdown. I do not have a better suggestion
though.
In that case, we could remove the DEVICE_ATTR_RW(manage_restart), so it would not be exposed to userspace yet and can later by changed without breaking userspace?
Quoted 10 lines
Quoted 9 lines
include/scsi/scsi_device.h +3
-0+*/ + unsigned manage_restart:1; +/*
* If set and if the device is runtime suspended, ask the high-level
* device driver (sd) to force a runtime resume of the device.
Thanks
- Markus Probst
v2 cover Support power resources defined in acpi on ata
In reply to Markus ProbstThis series adds support for power resources defined in acpi for ata ports/devices. A device can define a power resource in an ata port/device, which then gets powered on right before the port is probed. This can be useful for devices, which have ata ports that are:
a: powered down by default
b: can be individually powered on
like in some synology nas devices. If thats the case it will be assumed, that the power resource won't survive reboots and therefore the disk will be stopped.
Changes since v1:
- improved commit messages
- addressed style issues (too long lines and docs)
- removed ata_dev_manage_restart() and ata_port_set_power_state() methods
- improved log messages in ata_acpi_port_set_power_state
Markus Probst (2):
scsi: sd: Add manage_restart device attribute to scsi_disk
ata: Use ACPI methods to power on ata ports
drivers/ata/libata-acpi.c | 70 ++++++++++++++++++++++++++++++++++++++ drivers/ata/libata-core.c | 2 ++ drivers/ata/libata-scsi.c | 1 + drivers/ata/libata.h | 4 +++ drivers/scsi/sd.c | 35 ++++++++++++++++++- include/scsi/scsi_device.h | 6 ++++ 6 files changed, 117 insertions(+), 1 deletion(-)
Signature · 1 line
2.49.1
PATCH v2 1/2 scsi: sd: Add manage_restart device attribute to scsi_disk
In addition to the already existing manage_shutdown, manage_system_start_stop and manage_runtime_start_stop device scsi_disk attributes, add manage_restart, which allows the high-level device driver (sd) to manage the device power state for SYSTEM_RESTART if set to 1.
--- drivers/scsi/sd.c | 35 ++++++++++++++++++++++++++++++++++- include/scsi/scsi_device.h | 6 ++++++ 2 files changed, 40 insertions(+), 1 deletion(-)
drivers/scsi/sd.c +34 -1
@@ -318,6 +318,36 @@ static ssize_t manage_shutdown_store(struct device *dev, }static DEVICE_ATTR_RW (manage_shutdown); +static ssize_t manage_restart_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct scsi_disk *sdkp =to_scsi_disk (dev); +struct scsi_device *sdp = sdkp->device; + +return sysfs_emit (buf,"%u\n" , sdp->manage_restart); +} + + +static ssize_t manage_restart_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct scsi_disk *sdkp =to_scsi_disk (dev); +struct scsi_device *sdp = sdkp->device; +bool v; + +if (!capable (CAP_SYS_ADMIN )) +return -EACCES ; + +if (kstrtobool (buf, &v)) +return -EINVAL ; + + sdp->manage_restart = v; + +return count; +} +static DEVICE_ATTR_RW (manage_restart); +static ssize_t allow_restart_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -654,6 +684,7 @@ static struct attribute *sd_disk_attrs[] = { &dev_attr_manage_system_start_stop.attr, &dev_attr_manage_runtime_start_stop.attr, &dev_attr_manage_shutdown.attr, + &dev_attr_manage_restart.attr, &dev_attr_protection_type.attr, &dev_attr_protection_mode.attr, &dev_attr_app_tag_own.attr,
@@ -4175,7 +4206,9 @@ static void sd_shutdown(struct device *dev) (system_state == SYSTEM_POWER_OFF && sdkp->device->manage_shutdown) || (system_state == SYSTEM_RUNNING && - sdkp->device->manage_runtime_start_stop)) { + sdkp->device->manage_runtime_start_stop) || + (system_state == SYSTEM_RESTART && + sdkp->device->manage_restart)) {sd_printk (KERN_NOTICE , sdkp,"Stopping disk\n" );sd_start_stop_device (sdkp,0 ); }
include/scsi/scsi_device.h +6 -0
@@ -178,6 +178,12 @@ struct scsi_device {*/ unsigned manage_shutdown:1; +/* +* If true, let the high-level device driver (sd) manage the device +* power state for system restart (reboot) operations. +*/ + unsigned manage_restart:1; +/* * If set and if the device is runtime suspended, ask the high-level * device driver (sd) to force a runtime resume of the device.
Signature · 1 line
2.49.1
PATCH v2 2/2 ata: Use ACPI methods to power on ata ports
In reply to Markus ProbstSome embedded devices, including many Synology NAS devices, have the ability to control whether a ATA port has power or not.
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 a power failure. Also add a new function, ata_acpi_port_set_power_state(), that will be used to power on an ata port if usable ACPI power resources are found. It will be called right before probing the port, therefore the port will be powered on just in time.
--- drivers/ata/libata-acpi.c | 70 +++++++++++++++++++++++++++++++++++++++ drivers/ata/libata-core.c | 2 ++ drivers/ata/libata-scsi.c | 1 + drivers/ata/libata.h | 4 +++ 4 files changed, 77 insertions(+)
drivers/ata/libata-acpi.c +70 -0
@@ -245,6 +245,76 @@ void ata_acpi_bind_dev(struct ata_device *dev) ata_acpi_dev_uevent); } +/** +* ata_acpi_dev_manage_restart - if the disk should be stopped (spin 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) +{ +// If the device is power manageable and we assume the disk loses power +// on reboot. +if (dev->link->ap->flags &ATA_FLAG_ACPI_SATA ) { +if (!is_acpi_device_node (dev->tdev.fwnode)) +return 0 ; +return acpi_bus_power_manageable (ACPI_HANDLE (&dev->tdev)); + } + +if (!is_acpi_device_node (dev->link->ap->tdev.fwnode)) +return 0 ; +return acpi_bus_power_manageable (ACPI_HANDLE (&dev->link->ap->tdev)); +} + +/** +* ata_acpi_port_set_power_state - set the power state of the ata port +* @ap: target ATA port +* +* This function is called at the beginning of ata_port_probe. +*/ +void ata_acpi_port_set_power_state (struct ata_port *ap,bool enable) +{ +acpi_handle handle; +unsigned char state; +int i; + +if (libata_noacpi) +return ; + +if (enable) + state =ACPI_STATE_D0 ; +else + state =ACPI_STATE_D3_COLD ; + +if (ap->flags &ATA_FLAG_ACPI_SATA ) { +for (i =0 ; i <ATA_MAX_DEVICES ; i++) { +if (!is_acpi_device_node (ap->link.device[i].tdev.fwnode)) +continue ; + handle =ACPI_HANDLE (&ap->link.device[i].tdev); +if (!acpi_bus_power_manageable (handle)) +continue ; +if (!acpi_bus_set_power (handle, state)) +ata_dev_dbg (&ap->link.device[i],"acpi: power was %s\n" , + enable ?"en" :"dis" ); +else +ata_dev_err (&ap->link.device[i],"acpi: failed to set power state\n" ); + } +return ; + } +if (!is_acpi_device_node (ap->tdev.fwnode)) +return ; + handle =ACPI_HANDLE (&ap->tdev); +if (!acpi_bus_power_manageable (handle)) +return ; + +if (!acpi_bus_set_power (handle, state)) +ata_port_dbg (ap,"acpi: power %sabled\n" , enable ?"en" :"dis" ); +else +ata_port_err (ap,"acpi: failed to set power state\n" ); +} +/** * ata_acpi_dissociate - dissociate ATA host from ACPI objects * @host: target ATA host
drivers/ata/libata-core.c +2 -0
@@ -5904,6 +5904,8 @@ void ata_port_probe(struct ata_port *ap)struct ata_eh_info *ehi = &ap->link.eh_info;unsigned long flags; +ata_acpi_port_set_power_state (ap, true); +/* kick EH for boot probing */ spin_lock_irqsave (ap->lock, flags);
drivers/ata/libata-scsi.c +1 -0
@@ -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 ; }
drivers/ata/libata.h +4 -0
@@ -130,6 +130,8 @@ extern void ata_acpi_on_disable(struct ata_device *dev);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_set_power_state (struct ata_port *ap,bool enable); +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) { }
@@ -140,6 +142,8 @@ static inline void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) { }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_set_power_state (struct ata_port *ap,bool enable) {} +static inline bool ata_acpi_dev_manage_restart (struct ata_device *dev) {return 0 ; }#endif /* libata-scsi.c */
Signature · 1 line
2.49.1
Niklas Cassel
maintainerRe: [PATCH v2 2/2] ata: Use ACPI methods to power on ata ports
Quoted 2 lines · Markus Probst
Some embedded devices, including many Synology NAS devices, have the ability to control whether a ATA port has power or not.
In V1, you mentioned that it was to control the SATA power supply, now you mention the ATA port. I am confused.
If it is for the ATA port, then SATA already has support for this, using PxSCTL.
How does this ACPI way to control power interact with the regular way to control power for a port using PxSCTL?
Quoted 28 lines
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 a power failure. Also add a new function,ata_acpi_port_set_power_state(), that will be used to power on an ata port if usable ACPI power resources are found. It will be called right before probing the port, therefore the port will be powered on just in time.Signed-off-by Markus Probst <[email protected]>--- drivers/ata/libata-acpi.c | 70 +++++++++++++++++++++++++++++++++++++++ drivers/ata/libata-core.c | 2 ++ drivers/ata/libata-scsi.c | 1 + drivers/ata/libata.h | 4 +++ 4 files changed, 77 insertions(+)drivers/ata/libata-acpi.c +2
-0@@ -245,6 +245,76 @@ void ata_acpi_bind_dev(struct ata_device *dev) ata_acpi_dev_uevent); } +/** +* ata_acpi_dev_manage_restart - if the disk should be stopped (spin down) on
drivers/ata/libata-acpi.c void ata_acpi_bind_dev(struct ata_device *dev) · line 259
Quoted 10 lines
drivers/ata/libata-acpi.c +10
-0+* 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) +{ +// If the device is power manageable and we assume the disk loses power +// on reboot.
Like Damien mentioned earlier, please no C++ style comments.
Kind regards,
Niklas
Niklas Cassel
maintainerRe: [PATCH v2 2/2] ata: Use ACPI methods to power on ata ports
Also, when sending a new version, please avoid linking using In-Reply-To to previous versions of the same series, as it creates an "unmanageable forest of references in email clients", see:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#explicit-in-reply-to-headers
Kind regards,
Niklas
Re: [PATCH v2 2/2] ata: Use ACPI methods to power on ata ports
In reply to Niklas CasselQuoted 7 lines · Niklas Cassel
Quoted 3 lines · Markus Probst
Some embedded devices, including many Synology NAS devices, have the
ability to control whether a ATA port has power or not.In V1, you mentioned that it was to control the SATA power supply, now you mention the ATA port. I am confused.
The power supply associated with the ata port (or to be more precise, it controls the power gate to the SATA Power connector for the specific disk, at least in the synology example). It sets the power state defined in ACPI on the ata port. I might need to update the wording used in the patches to make it more clear.
Quoted 60 lines
If it is for the ATA port, then SATA already has support for this, using PxSCTL.
How does this ACPI way to control power interact with the regular way to control power for a port using PxSCTL?
Quoted 47 lines
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 a power
failure. Also add a new function,ata_acpi_port_set_power_state(), that
will be used to power on an ata port if usable ACPI power resources are
found. It will be called right before probing the port, therefore the port
will be powered on just in time.Signed-off-by Markus Probst <[email protected]>---
drivers/ata/libata-acpi.c | 70
+++++++++++++++++++++++++++++++++++++++
drivers/ata/libata-core.c | 2 ++
drivers/ata/libata-scsi.c | 1 +
drivers/ata/libata.h | 4 +++4 files changed, 77 insertions(+)drivers/ata/libata-acpi.c +0
-0@@ -245,6 +245,76 @@ void ata_acpi_bind_dev(struct ata_device *dev) ata_acpi_dev_uevent); }
+/**
+ *ata_acpi_dev_manage_restart- if the disk should be stopped (spin down) on
+ * system restart.
+ * @dev: target ATA device
+ *
+ * RETURNS:
+ * true if the disk should be stopped, otherwise false
+ */drivers/ata/libata-acpi.c +3
-0+bool ata_acpi_dev_manage_restart (struct ata_device *dev) +{ +// If the device is power manageable and we assume the disk loses power
drivers/ata/libata-acpi.c void ata_acpi_bind_dev(struct ata_device *dev) · line 259
Quoted 1 line
drivers/ata/libata-acpi.c +1
-0+// on reboot. Like Damien mentioned earlier, please no C++ style comments.
Quoted 2 lines
Kind regards,
Niklas
Also for the questions sent to the v1 patch:
Quoted 3 lines
Since this patch implements something similar to DevSleep, but rather,
IIUC, for the SATA power itself?
Yes
Quoted 1 line
How is SATA power supplied tied to a port in ACPI? If you have a
desktop
Quoted 1 line
you have a PSU, and don't really know which supply is for which port.
It is not for desktop computers, but for embedded devices.
Quoted 1 line
So, considering how many ways we already have to disable/power off a
port,
Quoted 1 line
you might understand why I think it is extra important that you
document
Quoted 1 line
exactly how, and why we need yet another way to disable/power on/off
a port.
In this case,
- According to ACPI spec, if a device has a power resource defined it has to be turned on before we are able send commands to the device
- Because there is hardware out there, that is perfectly capable of running upstream linux, which doesn't use one of the methods you mentioned for controlling the power. Same did apply for the USB VBus power, despite there being "USB_PORT_FEAT_POWER" in the spec and it also got in the kernel, see commit f7ac7787ad361e31a7972e2854ed8dc2eedfac3b.
I will try to add a short version of the reason written above in the commit message.
Thanks,
- Markus Probst
kernel test robot
build botRe: [PATCH v2 2/2] ata: Use ACPI methods to power on ata ports
In reply to Markus Probstkernel test robot noticed the following build warnings:
Hi Markus,
kernel test robot noticed the following build warnings:
[auto build test WARNING on jejb-scsi/for-next]
[also build test WARNING on mkp-scsi/for-next linus/master v6.17 next-20251009] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Markus-Probst/scsi-sd-Add-manage_restart-device-attribute-to-scsi_disk/20251010-111134 base: https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next patch link: https://lore.kernel.org/r/20251009112433.108643-3-markus.probst%40posteo.de patch subject: [PATCH v2 2/2] ata: Use ACPI methods to power on ata ports config: x86_64-randconfig-071-20251010 (https://download.01.org/0day-ci/archive/20251010/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251010/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> Warning: drivers/ata/libata-acpi.c:277 function parameter 'enable' not described in 'ata_acpi_port_set_power_state'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki