From: Luca Lauro via B4 Relay <devnull+famlauro93l.gmail.com@kernel.org>
To: Sascha Hauer <s.hauer@pengutronix.de>,
"open list:BAREBOX" <barebox@lists.infradead.org>
Cc: Luca Lauro <famlauro93l@gmail.com>
Subject: [PATCH v3 13/15] ata: ahci: add FLUSH EXT and STANDBY IMMEDIATE support during shutdown
Date: Sun, 02 Aug 2026 15:16:29 +0200 [thread overview]
Message-ID: <20260802-rn102-rn104-series-v3-13-f7685a279fb5@gmail.com> (raw)
In-Reply-To: <20260802-rn102-rn104-series-v3-0-f7685a279fb5@gmail.com>
From: Luca Lauro <famlauro93l@gmail.com>
Some AHCI controllers require ATA FLUSH EXT and STANDBY IMMEDIATE to be
issued before poweroff to ensure data integrity and proper device
shutdown. This patch introduces ahci_port_shutdown(), which sends these
commands using ahci_ata_nodata(), and integrates it into a new AHCI
poweroff handler.
Signed-off-by: Luca Lauro <famlauro93l@gmail.com>
---
drivers/ata/ahci.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 2504f4d19a..a9a3f43f21 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -48,6 +48,9 @@
#define ahci_debug(ahci, fmt, arg...) \
dev_dbg(ahci->dev, fmt, ##arg)
+#define ATA_CMD_FLUSH_EXT 0xEA
+#define ATA_CMD_STANDBYNOW1 0xE0
+
#ifndef PCI_VENDOR_ID_MARVELL_EXT
#define PCI_VENDOR_ID_MARVELL_EXT 0x1b4b
#endif
@@ -680,6 +683,63 @@ static int ahci_probe(struct device *dev)
return ret;
}
+/* Issue FLUSH EXT + STANDBY IMMEDIATE */
+static void ahci_port_shutdown(struct ahci_port *port)
+{
+ if (!port->cmd_tbl || !port->cmd_slot)
+ return;
+
+ if (!ahci_link_ok(port, 0))
+ return;
+
+ if (ahci_ata_nodata(port, ATA_CMD_FLUSH_EXT, 0))
+ ahci_port_info(port, "FLUSH EXT failed\n");
+
+ if (ahci_ata_nodata(port, ATA_CMD_STANDBYNOW1, 0))
+ ahci_port_info(port, "STANDBY IMMEDIATE failed\n");
+}
+
+/* Full poweroff sequence */
+static void ahci_poweroff(struct poweroff_handler *handler, unsigned long flags)
+{
+ struct ahci_device *ahci;
+ int i, n_ports;
+
+ list_for_each_entry(ahci, &ahci_devices, list) {
+
+ if (!ahci->mmio_base)
+ continue;
+
+ /* FLUSH + STANDBY on all active ports */
+ n_ports = max_t(int, ahci->n_ports, fls(ahci->port_map));
+
+ for (i = 0; i < n_ports; i++) {
+ struct ahci_port *port = &ahci->ports[i];
+
+ if (!(ahci->port_map & (1 << i)))
+ continue;
+
+ ahci_port_shutdown(port);
+ }
+
+ /* (optional) shutsown controller after commands
+ * ahci_shutdown_host(ahci);
+ */
+ }
+}
+
+static struct poweroff_handler ahci_po_handler = {
+ .poweroff = ahci_poweroff,
+ .priority = 200, /* higher than gpio-poweroff */
+};
+
+static int ahci_register_poweroff(void)
+{
+ poweroff_handler_register(&ahci_po_handler);
+ return 0;
+}
+postcore_initcall(ahci_register_poweroff);
+
static __maybe_unused struct of_device_id ahci_dt_ids[] = {
{
.compatible = "calxeda,hb-ahci",
--
2.47.3
next prev parent reply other threads:[~2026-08-02 14:16 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-02 13:16 [PATCH v3 00/15] ARM: mvebu: add Netgear RN102/RN104 support and related drivers Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 01/15] ARM: mvebu: add Netgear RN102 support Luca Lauro via B4 Relay
2026-08-03 12:53 ` Sascha Hauer
2026-08-03 13:43 ` Marco Felsch
2026-08-02 13:16 ` [PATCH v3 02/15] ARM: mvebu: enable RN102 in mvebu_defconfig Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 03/15] ARM: mvebu: improve Netgear RN104 support Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 04/15] ARM: mvebu: rename PUTC_LL to MVEBU_PUTC_LL Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 05/15] drivers: fan: add fan subsystem, core API and G76x fan controller driver Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 06/15] commands: add fan control command Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 07/15] usb: ehci: add Marvell EHCI host controller driver Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 08/15] usb: ehci: initialize periodic_queue_dma Luca Lauro via B4 Relay
2026-08-03 21:27 ` Sascha Hauer
2026-08-02 13:16 ` [PATCH v3 09/15] ata: ahci: add PCI AHCI and Marvell 9170 controller support Luca Lauro via B4 Relay
2026-08-03 21:33 ` Sascha Hauer
2026-08-02 13:16 ` [PATCH v3 10/15] ata: ahci: fix zero-length DMA handling Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 11/15] ata: ahci: add helper for ATA commands without data Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 12/15] ata: ahci: improve AHCI port bring-up sequence Luca Lauro via B4 Relay
2026-08-02 13:16 ` Luca Lauro via B4 Relay [this message]
2026-08-03 21:52 ` [PATCH v3 13/15] ata: ahci: add FLUSH EXT and STANDBY IMMEDIATE support during shutdown Sascha Hauer
2026-08-02 13:16 ` [PATCH v3 14/15] ata: ahci: add shutdown helpers for AHCI controllers Luca Lauro via B4 Relay
2026-08-03 21:55 ` Sascha Hauer
2026-08-02 13:16 ` [PATCH v3 15/15] ata: ahci: cleanup legacy code and remove unused paths Luca Lauro via B4 Relay
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=20260802-rn102-rn104-series-v3-13-f7685a279fb5@gmail.com \
--to=devnull+famlauro93l.gmail.com@kernel.org \
--cc=barebox@lists.infradead.org \
--cc=famlauro93l@gmail.com \
--cc=s.hauer@pengutronix.de \
/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