linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hanna Hawa <hhhawa@amazon.com>
To: <axboe@kernel.dk>, <hdegoede@redhat.com>
Cc: <linux-ide@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<dwmw@amazon.co.uk>, <benh@amazon.com>, <ronenk@amazon.com>,
	<talel@amazon.com>, <jonnyc@amazon.com>, <hanochu@amazon.com>,
	<barakw@amazon.com>, <hhhawa@amazon.com>
Subject: [PATCH 1/2] ata: libahci: move ahci platform shutdown function to libahci
Date: Mon, 9 Dec 2019 16:32:08 +0000	[thread overview]
Message-ID: <20191209163209.26284-2-hhhawa@amazon.com> (raw)
In-Reply-To: <20191209163209.26284-1-hhhawa@amazon.com>

Move ahci platform shutdown function to libahci as preparation to add
shutdown handler for PCIe AHCI.

Signed-off-by: Hanna Hawa <hhhawa@amazon.com>
---
 drivers/ata/ahci.h             |  1 +
 drivers/ata/libahci.c          | 33 +++++++++++++++++++++++++++++++++
 drivers/ata/libahci_platform.c | 20 +-------------------
 3 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
index 3dbf398c92ea..df84dfdf9037 100644
--- a/drivers/ata/ahci.h
+++ b/drivers/ata/ahci.h
@@ -418,6 +418,7 @@ void ahci_set_em_messages(struct ahci_host_priv *hpriv,
 int ahci_reset_em(struct ata_host *host);
 void ahci_print_info(struct ata_host *host, const char *scc_s);
 int ahci_host_activate(struct ata_host *host, struct scsi_host_template *sht);
+void ahci_common_shutdown(struct ata_host *host);
 void ahci_error_handler(struct ata_port *ap);
 u32 ahci_handle_port_intr(struct ata_host *host, u32 irq_masked);
 
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index bff369d9a1a7..f5dd5d66c442 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -2602,6 +2602,39 @@ int ahci_host_activate(struct ata_host *host, struct scsi_host_template *sht)
 }
 EXPORT_SYMBOL_GPL(ahci_host_activate);
 
+/**
+ * ahci_common_shutdown - Disable interrupts and stop DMA for host ports
+ * @host: target ATA host
+ *
+ * This common function is called during system shutdown and performs the
+ * minimal deconfiguration required to ensure that an ahci host cannot corrupt
+ * or otherwise interfere with a new kernel being started with kexec.
+ */
+void ahci_common_shutdown(struct ata_host *host)
+{
+	struct ahci_host_priv *hpriv = host->private_data;
+	void __iomem *mmio = hpriv->mmio;
+	int i;
+
+	for (i = 0; i < host->n_ports; i++) {
+		struct ata_port *ap = host->ports[i];
+
+		/* Disable port interrupts */
+		if (ap->ops->freeze)
+			ap->ops->freeze(ap);
+
+		/* Stop the port DMA engines */
+		if (ap->ops->port_stop)
+			ap->ops->port_stop(ap);
+	}
+
+	/* Disable and clear host interrupts */
+	writel(readl(mmio + HOST_CTL) & ~HOST_IRQ_EN, mmio + HOST_CTL);
+	readl(mmio + HOST_CTL); /* flush */
+	writel(GENMASK(host->n_ports, 0), mmio + HOST_IRQ_STAT);
+}
+EXPORT_SYMBOL_GPL(ahci_common_shutdown);
+
 MODULE_AUTHOR("Jeff Garzik");
 MODULE_DESCRIPTION("Common AHCI SATA low-level routines");
 MODULE_LICENSE("GPL");
diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c
index 8befce036af8..dd2bfa3986f8 100644
--- a/drivers/ata/libahci_platform.c
+++ b/drivers/ata/libahci_platform.c
@@ -680,26 +680,8 @@ static void ahci_host_stop(struct ata_host *host)
 void ahci_platform_shutdown(struct platform_device *pdev)
 {
 	struct ata_host *host = platform_get_drvdata(pdev);
-	struct ahci_host_priv *hpriv = host->private_data;
-	void __iomem *mmio = hpriv->mmio;
-	int i;
-
-	for (i = 0; i < host->n_ports; i++) {
-		struct ata_port *ap = host->ports[i];
-
-		/* Disable port interrupts */
-		if (ap->ops->freeze)
-			ap->ops->freeze(ap);
 
-		/* Stop the port DMA engines */
-		if (ap->ops->port_stop)
-			ap->ops->port_stop(ap);
-	}
-
-	/* Disable and clear host interrupts */
-	writel(readl(mmio + HOST_CTL) & ~HOST_IRQ_EN, mmio + HOST_CTL);
-	readl(mmio + HOST_CTL); /* flush */
-	writel(GENMASK(host->n_ports, 0), mmio + HOST_IRQ_STAT);
+	ahci_common_shutdown(host);
 }
 EXPORT_SYMBOL_GPL(ahci_platform_shutdown);
 
-- 
2.17.1


  reply	other threads:[~2019-12-09 16:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-09 16:32 [PATCH 0/2] ata: ahci: Add shutdown handler Hanna Hawa
2019-12-09 16:32 ` Hanna Hawa [this message]
2019-12-09 16:32 ` [PATCH 2/2] " Hanna Hawa
2019-12-10  9:43 ` [PATCH 0/2] " Hans de Goede

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=20191209163209.26284-2-hhhawa@amazon.com \
    --to=hhhawa@amazon.com \
    --cc=axboe@kernel.dk \
    --cc=barakw@amazon.com \
    --cc=benh@amazon.com \
    --cc=dwmw@amazon.co.uk \
    --cc=hanochu@amazon.com \
    --cc=hdegoede@redhat.com \
    --cc=jonnyc@amazon.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ronenk@amazon.com \
    --cc=talel@amazon.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;
as well as URLs for NNTP newsgroup(s).