Linux ATA/IDE development
 help / color / mirror / Atom feed
From: Niklas Cassel <cassel@kernel.org>
To: Damien Le Moal <dlemoal@kernel.org>, Niklas Cassel <cassel@kernel.org>
Cc: Werner Fischer <devlists@wefi.net>,
	Daniel Drake <drake@endlessos.org>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Jian-Hong Pan <jhp@endlessos.org>,
	Dieter Mummenschanz <dmummenschanz@web.de>,
	Mario Limonciello <mario.limonciello@amd.com>,
	linux-ide@vger.kernel.org
Subject: [PATCH v2 4/5] ata: ahci: do not enable LPM on external ports
Date: Tue,  6 Feb 2024 22:13:45 +0100	[thread overview]
Message-ID: <20240206211352.1664816-5-cassel@kernel.org> (raw)
In-Reply-To: <20240206211352.1664816-1-cassel@kernel.org>

AHCI 1.3.3, 7.3.1.1 Software Flow for Hot Plug Removal Detection states:
"To reliably detect hot plug removals, software must disable interface
power management.

Software should perform the following initialization on a port after a
device is attached:
-Set PxSCTL.IPM to 3h to disable interface power management state
 transitions.
-Set PxCMD.ALPE to ‘0’ to disable aggressive power management.
-Ensure PxIE.PRCE is set to ‘1’ to enable interrupts on hot plug removals.
-Disable device initiated interface power management by issuing the
 appropriate SET FEATURES command."

Further, AHCI 1.3.3, 7.3 Native Hot Plug Support states:
"The HBA shall set the PxSERR.DIAG.X bit to ‘1’ when a COMINIT is received
from the device. Hot plug insertions are detected via the PxIS.PCS bit
that directly reflects the PxSERR.DIAG.X bit. The HBA shall set the
PxSERR.DIAG.N bit to ‘1’ when the HBA’s internal PhyRdy signal changes
state.

Hot plug removals are detected via the PxIS.PRCS bit that directly
reflects the PxSERR.DIAG.N bit. Note that PxSERR.DIAG.N is also set
to ‘1’ on insertions and during interface power management entry/exit."

ahci_set_lpm() already disables the PxIS.PRCS interrupt if setting a
LPM policy != ATA_LPM_MAX_POWER, so we cannot detect hot plug removals
when LPM policy != ATA_LPM_MAX_POWER.

We do have PxIS.PCS interrupt enabled even for LPM policy !=
ATA_LPM_MAX_POWER, so we should theoretically still be able to detect
hot plug insertions even when LPM is enabled.

However, in practise, for LPM policy ATA_LPM_MED_POWER_WITH_DIPM,
ATA_LPM_MIN_POWER_WITH_PARTIAL, and ATA_LPM_MIN_POWER, if there is
no link enabled, sata_link_scr_lpm() will set SControl.DET = 0x4,
which will transition the port to the "P:Offline" state.

The P:Offline mode is described in SATA Gold 3.5a:
4.1.1.103 Phy offline:
"In this mode the host Phy is forced off and the host Phy does not
recognize nor respond to COMINIT or COMWAKE. This mode is entered by
setting the DET field of the SControl register to 0100b. This is a
mechanism for the host to turn off its Phy."

So in the P:Offline state the PHY does not recognize the unsolicited
COMINIT which is sent on a hot plug insertion.

While we could change sata_link_scr_lpm() to never power off an external
port for LPM policy != ATA_LPM_MAX_POWER (in order be able to handle hot
plug insertions), we still would not be able to handle hot plug removals.

Thus, simply modify ahci_update_initial_lpm_policy() to not enable LPM if
the port advertises itself as an external port, as this function is
already being used to set/override the initial LPM policy.

Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
 drivers/ata/ahci.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 346a0f9ef246..9d052ff2b86c 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1665,6 +1665,15 @@ static void ahci_update_initial_lpm_policy(struct ata_port *ap)
 	if (!(hpriv->flags & AHCI_HFLAG_USE_LPM_POLICY))
 		return;
 
+	/*
+	 * AHCI contains a known incompatibility between LPM and hot-plug
+	 * removal events, see 7.3.1 Hot Plug Removal Detection and Power
+	 * Management Interaction in AHCI 1.3.1. Therefore, do not enable
+	 * LPM if the port advertises itself as an external port.
+	 */
+	if (ap->pflags & ATA_PFLAG_EXTERNAL)
+		return;
+
 	/* user modified policy via module param */
 	if (mobile_lpm_policy != -1) {
 		policy = mobile_lpm_policy;
-- 
2.43.0


  parent reply	other threads:[~2024-02-06 21:14 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-06 21:13 [PATCH v2 0/5] drop low power policy board type Niklas Cassel
2024-02-06 21:13 ` [PATCH v2 1/5] ata: ahci: move marking of external port earlier Niklas Cassel
2024-02-06 21:13 ` [PATCH v2 2/5] ata: ahci: a hotplug capable port is an external port Niklas Cassel
2024-06-13  6:34   ` Thomas Weißschuh
2024-06-13  8:29     ` Damien Le Moal
2024-06-13 12:56       ` Thomas Weißschuh
2024-06-13 13:13       ` Niklas Cassel
2024-06-13 13:38         ` Niklas Cassel
2024-06-13 14:49           ` Thomas Weißschuh
2024-06-13 15:37             ` Niklas Cassel
2024-06-13 17:33               ` Thomas Weißschuh
2024-06-13 17:54                 ` Niklas Cassel
2024-02-06 21:13 ` [PATCH v2 3/5] ata: ahci: drop hpriv param from ahci_update_initial_lpm_policy() Niklas Cassel
2024-02-07  4:19   ` Jian-Hong Pan
2024-02-06 21:13 ` Niklas Cassel [this message]
2024-02-08 23:34   ` [PATCH v2 4/5] ata: ahci: do not enable LPM on external ports Damien Le Moal
2024-02-06 21:13 ` [PATCH v2 5/5] ata: ahci: Drop low power policy board type Niklas Cassel
2024-02-07  4:19   ` Jian-Hong Pan
2024-02-06 21:54 ` [PATCH v2 0/5] drop " Mario Limonciello
2024-02-07  4:30   ` Jian-Hong Pan
2024-02-07  6:35 ` Mika Westerberg
2024-02-08 23:43 ` Damien Le Moal
2024-02-09 10:01 ` Niklas Cassel

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=20240206211352.1664816-5-cassel@kernel.org \
    --to=cassel@kernel.org \
    --cc=devlists@wefi.net \
    --cc=dlemoal@kernel.org \
    --cc=dmummenschanz@web.de \
    --cc=drake@endlessos.org \
    --cc=jhp@endlessos.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=mika.westerberg@linux.intel.com \
    /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