* Re: [PATCH v2] ata: ahci: Do not enable LPM if no LPM states are supported by the HBA
2024-06-18 15:28 [PATCH v2] ata: ahci: Do not enable LPM if no LPM states are supported by the HBA Niklas Cassel
@ 2024-06-18 15:49 ` Mario Limonciello
2024-06-18 15:54 ` Mika Westerberg
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Mario Limonciello @ 2024-06-18 15:49 UTC (permalink / raw)
To: Niklas Cassel, Damien Le Moal, Mika Westerberg, Jian-Hong Pan
Cc: stable, linux-ide
On 6/18/2024 10:28, Niklas Cassel wrote:
> LPM consists of HIPM (host initiated power management) and DIPM
> (device initiated power management).
>
> ata_eh_set_lpm() will only enable HIPM if both the HBA and the device
> supports it.
>
> However, DIPM will be enabled as long as the device supports it.
> The HBA will later reject the device's request to enter a power state
> that it does not support (Slumber/Partial/DevSleep) (DevSleep is never
> initiated by the device).
>
> For a HBA that doesn't support any LPM states, simply don't set a LPM
> policy such that all the HIPM/DIPM probing/enabling will be skipped.
>
> Not enabling HIPM or DIPM in the first place is safer than relying on
> the device following the AHCI specification and respecting the NAK.
> (There are comments in the code that some devices misbehave when
> receiving a NAK.)
>
> Performing this check in ahci_update_initial_lpm_policy() also has the
> advantage that a HBA that doesn't support any LPM states will take the
> exact same code paths as a port that is external/hot plug capable.
>
> Side note: the port in ata_port_dbg() has not been given a unique id yet,
> but this is not overly important as the debug print is disabled unless
> explicitly enabled using dynamic debug. A follow-up series will make sure
> that the unique id assignment will be done earlier. For now, the important
> thing is that the function returns before setting the LPM policy.
>
> Fixes: 7627a0edef54 ("ata: ahci: Drop low power policy board type")
> Cc: stable@vger.kernel.org
> Signed-off-by: Niklas Cassel <cassel@kernel.org>
> ---
> Changes since v1: Add debug print as suggested by Mika.
>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
> drivers/ata/ahci.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> index 07d66d2c5f0d..5eb38fbbbecd 100644
> --- a/drivers/ata/ahci.c
> +++ b/drivers/ata/ahci.c
> @@ -1735,6 +1735,14 @@ static void ahci_update_initial_lpm_policy(struct ata_port *ap)
> if (ap->pflags & ATA_PFLAG_EXTERNAL)
> return;
>
> + /* If no LPM states are supported by the HBA, do not bother with LPM */
> + if ((ap->host->flags & ATA_HOST_NO_PART) &&
> + (ap->host->flags & ATA_HOST_NO_SSC) &&
> + (ap->host->flags & ATA_HOST_NO_DEVSLP)) {
> + ata_port_dbg(ap, "no LPM states supported, not enabling LPM\n");
> + return;
> + }
> +
> /* user modified policy via module param */
> if (mobile_lpm_policy != -1) {
> policy = mobile_lpm_policy;
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] ata: ahci: Do not enable LPM if no LPM states are supported by the HBA
2024-06-18 15:28 [PATCH v2] ata: ahci: Do not enable LPM if no LPM states are supported by the HBA Niklas Cassel
2024-06-18 15:49 ` Mario Limonciello
@ 2024-06-18 15:54 ` Mika Westerberg
2024-06-19 3:45 ` Damien Le Moal
2024-06-19 11:36 ` Niklas Cassel
3 siblings, 0 replies; 6+ messages in thread
From: Mika Westerberg @ 2024-06-18 15:54 UTC (permalink / raw)
To: Niklas Cassel
Cc: Damien Le Moal, Mario Limonciello, Jian-Hong Pan, stable,
linux-ide
On Tue, Jun 18, 2024 at 05:28:29PM +0200, Niklas Cassel wrote:
> LPM consists of HIPM (host initiated power management) and DIPM
> (device initiated power management).
>
> ata_eh_set_lpm() will only enable HIPM if both the HBA and the device
> supports it.
>
> However, DIPM will be enabled as long as the device supports it.
> The HBA will later reject the device's request to enter a power state
> that it does not support (Slumber/Partial/DevSleep) (DevSleep is never
> initiated by the device).
>
> For a HBA that doesn't support any LPM states, simply don't set a LPM
> policy such that all the HIPM/DIPM probing/enabling will be skipped.
>
> Not enabling HIPM or DIPM in the first place is safer than relying on
> the device following the AHCI specification and respecting the NAK.
> (There are comments in the code that some devices misbehave when
> receiving a NAK.)
>
> Performing this check in ahci_update_initial_lpm_policy() also has the
> advantage that a HBA that doesn't support any LPM states will take the
> exact same code paths as a port that is external/hot plug capable.
>
> Side note: the port in ata_port_dbg() has not been given a unique id yet,
> but this is not overly important as the debug print is disabled unless
> explicitly enabled using dynamic debug. A follow-up series will make sure
> that the unique id assignment will be done earlier. For now, the important
> thing is that the function returns before setting the LPM policy.
>
> Fixes: 7627a0edef54 ("ata: ahci: Drop low power policy board type")
> Cc: stable@vger.kernel.org
> Signed-off-by: Niklas Cassel <cassel@kernel.org>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] ata: ahci: Do not enable LPM if no LPM states are supported by the HBA
2024-06-18 15:28 [PATCH v2] ata: ahci: Do not enable LPM if no LPM states are supported by the HBA Niklas Cassel
2024-06-18 15:49 ` Mario Limonciello
2024-06-18 15:54 ` Mika Westerberg
@ 2024-06-19 3:45 ` Damien Le Moal
2024-06-19 10:13 ` Niklas Cassel
2024-06-19 11:36 ` Niklas Cassel
3 siblings, 1 reply; 6+ messages in thread
From: Damien Le Moal @ 2024-06-19 3:45 UTC (permalink / raw)
To: Niklas Cassel, Mario Limonciello, Mika Westerberg, Jian-Hong Pan
Cc: stable, linux-ide
On 6/19/24 00:28, Niklas Cassel wrote:
> LPM consists of HIPM (host initiated power management) and DIPM
> (device initiated power management).
>
> ata_eh_set_lpm() will only enable HIPM if both the HBA and the device
> supports it.
>
> However, DIPM will be enabled as long as the device supports it.
> The HBA will later reject the device's request to enter a power state
> that it does not support (Slumber/Partial/DevSleep) (DevSleep is never
> initiated by the device).
>
> For a HBA that doesn't support any LPM states, simply don't set a LPM
> policy such that all the HIPM/DIPM probing/enabling will be skipped.
>
> Not enabling HIPM or DIPM in the first place is safer than relying on
> the device following the AHCI specification and respecting the NAK.
> (There are comments in the code that some devices misbehave when
> receiving a NAK.)
>
> Performing this check in ahci_update_initial_lpm_policy() also has the
> advantage that a HBA that doesn't support any LPM states will take the
> exact same code paths as a port that is external/hot plug capable.
>
> Side note: the port in ata_port_dbg() has not been given a unique id yet,
> but this is not overly important as the debug print is disabled unless
> explicitly enabled using dynamic debug. A follow-up series will make sure
> that the unique id assignment will be done earlier. For now, the important
> thing is that the function returns before setting the LPM policy.
>
> Fixes: 7627a0edef54 ("ata: ahci: Drop low power policy board type")
> Cc: stable@vger.kernel.org
> Signed-off-by: Niklas Cassel <cassel@kernel.org>
> ---
> Changes since v1: Add debug print as suggested by Mika.
>
> drivers/ata/ahci.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> index 07d66d2c5f0d..5eb38fbbbecd 100644
> --- a/drivers/ata/ahci.c
> +++ b/drivers/ata/ahci.c
> @@ -1735,6 +1735,14 @@ static void ahci_update_initial_lpm_policy(struct ata_port *ap)
> if (ap->pflags & ATA_PFLAG_EXTERNAL)
> return;
>
> + /* If no LPM states are supported by the HBA, do not bother with LPM */
> + if ((ap->host->flags & ATA_HOST_NO_PART) &&
> + (ap->host->flags & ATA_HOST_NO_SSC) &&
> + (ap->host->flags & ATA_HOST_NO_DEVSLP)) {
Nit: Maybe:
#define ATA_HOST_NO_LPM \
(ATA_HOST_NO_PART | ATA_HOST_NO_SSC | ATA_HOST_NO_DEVSLP)
and then the if becomes:
if ((ap->host->flags & ATA_HOST_NO_LPM) == ATA_HOST_NO_LPM) {
But no strong feelings about it. So:
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
> + ata_port_dbg(ap, "no LPM states supported, not enabling LPM\n");
> + return;
> + }
> +
> /* user modified policy via module param */
> if (mobile_lpm_policy != -1) {
> policy = mobile_lpm_policy;
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] ata: ahci: Do not enable LPM if no LPM states are supported by the HBA
2024-06-19 3:45 ` Damien Le Moal
@ 2024-06-19 10:13 ` Niklas Cassel
0 siblings, 0 replies; 6+ messages in thread
From: Niklas Cassel @ 2024-06-19 10:13 UTC (permalink / raw)
To: Damien Le Moal
Cc: Mario Limonciello, Mika Westerberg, Jian-Hong Pan, stable,
linux-ide
On Wed, Jun 19, 2024 at 12:45:51PM +0900, Damien Le Moal wrote:
> On 6/19/24 00:28, Niklas Cassel wrote:
> > LPM consists of HIPM (host initiated power management) and DIPM
> > (device initiated power management).
> >
> > ata_eh_set_lpm() will only enable HIPM if both the HBA and the device
> > supports it.
> >
> > However, DIPM will be enabled as long as the device supports it.
> > The HBA will later reject the device's request to enter a power state
> > that it does not support (Slumber/Partial/DevSleep) (DevSleep is never
> > initiated by the device).
> >
> > For a HBA that doesn't support any LPM states, simply don't set a LPM
> > policy such that all the HIPM/DIPM probing/enabling will be skipped.
> >
> > Not enabling HIPM or DIPM in the first place is safer than relying on
> > the device following the AHCI specification and respecting the NAK.
> > (There are comments in the code that some devices misbehave when
> > receiving a NAK.)
> >
> > Performing this check in ahci_update_initial_lpm_policy() also has the
> > advantage that a HBA that doesn't support any LPM states will take the
> > exact same code paths as a port that is external/hot plug capable.
> >
> > Side note: the port in ata_port_dbg() has not been given a unique id yet,
> > but this is not overly important as the debug print is disabled unless
> > explicitly enabled using dynamic debug. A follow-up series will make sure
> > that the unique id assignment will be done earlier. For now, the important
> > thing is that the function returns before setting the LPM policy.
> >
> > Fixes: 7627a0edef54 ("ata: ahci: Drop low power policy board type")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Niklas Cassel <cassel@kernel.org>
> > ---
> > Changes since v1: Add debug print as suggested by Mika.
> >
> > drivers/ata/ahci.c | 8 ++++++++
> > 1 file changed, 8 insertions(+)
> >
> > diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> > index 07d66d2c5f0d..5eb38fbbbecd 100644
> > --- a/drivers/ata/ahci.c
> > +++ b/drivers/ata/ahci.c
> > @@ -1735,6 +1735,14 @@ static void ahci_update_initial_lpm_policy(struct ata_port *ap)
> > if (ap->pflags & ATA_PFLAG_EXTERNAL)
> > return;
> >
> > + /* If no LPM states are supported by the HBA, do not bother with LPM */
> > + if ((ap->host->flags & ATA_HOST_NO_PART) &&
> > + (ap->host->flags & ATA_HOST_NO_SSC) &&
> > + (ap->host->flags & ATA_HOST_NO_DEVSLP)) {
>
> Nit: Maybe:
>
> #define ATA_HOST_NO_LPM \
> (ATA_HOST_NO_PART | ATA_HOST_NO_SSC | ATA_HOST_NO_DEVSLP)
>
> and then the if becomes:
>
> if ((ap->host->flags & ATA_HOST_NO_LPM) == ATA_HOST_NO_LPM) {
>
> But no strong feelings about it. So:
>
> Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Thank you for the R-b and your suggestion.
Personally, I do not think that your suggestion is significantly easier to
read than what is already there (especially with the comment to give
context).
My brain always has to read a:
if ((foo & bar) == bar)
twice anyway.
I guess a:
if (!ata_host_has_lpm(ap->host))
would be clearer, but considering that we wouldn't be able to use this
helper function anywhere else in the libata subsystem, I'm not sure if
it is worth it, so I will just apply this patch as is.
Kind regards,
Niklas
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] ata: ahci: Do not enable LPM if no LPM states are supported by the HBA
2024-06-18 15:28 [PATCH v2] ata: ahci: Do not enable LPM if no LPM states are supported by the HBA Niklas Cassel
` (2 preceding siblings ...)
2024-06-19 3:45 ` Damien Le Moal
@ 2024-06-19 11:36 ` Niklas Cassel
3 siblings, 0 replies; 6+ messages in thread
From: Niklas Cassel @ 2024-06-19 11:36 UTC (permalink / raw)
To: Damien Le Moal, Mario Limonciello, Mika Westerberg, Jian-Hong Pan,
Niklas Cassel
Cc: stable, linux-ide
On Tue, 18 Jun 2024 17:28:29 +0200, Niklas Cassel wrote:
> LPM consists of HIPM (host initiated power management) and DIPM
> (device initiated power management).
>
> ata_eh_set_lpm() will only enable HIPM if both the HBA and the device
> supports it.
>
> However, DIPM will be enabled as long as the device supports it.
> The HBA will later reject the device's request to enter a power state
> that it does not support (Slumber/Partial/DevSleep) (DevSleep is never
> initiated by the device).
>
> [...]
Applied to libata/linux.git (for-6.10-fixes), thanks!
[1/1] ata: ahci: Do not enable LPM if no LPM states are supported by the HBA
https://git.kernel.org/libata/linux/c/fa997b05
Kind regards,
--
Niklas Cassel <cassel@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread