[PATCH] ahci: libahci: clear pending interrupt status

From: Szuying Chen
Date: Wed Aug 30 2023 - 23:09:44 EST


This patch adds the function to clear pending interrupt before COMRESET.
It follows the AHCI1.3.1 - section6.2.2.2 specification.

Signed-off-by: Szuying Chen <Chloe_Chen@xxxxxxxxxxxxxx>
---
drivers/ata/libahci.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index 06aec35f88f2..1ae788251a6c 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -1584,6 +1584,23 @@ static int ahci_pmp_retry_softreset(struct ata_link *link, unsigned int *class,
return rc;
}

+static void PortClearPendingInterrupt(struct ata_port *ap)
+{
+ struct ahci_host_priv *hpriv = ap->host->private_data;
+ void __iomem *port_mmio = ahci_port_base(ap);
+ u32 tmp;
+
+ /* clear port SERR */
+ tmp = readl(port_mmio + PORT_SCR_ERR);
+ writel(tmp, port_mmio + PORT_SCR_ERR);
+
+ /* clear port IRQ */
+ tmp = readl(port_mmio + PORT_IRQ_STAT);
+ writel(tmp, port_mmio + PORT_IRQ_STAT);
+
+ writel(1 << ap->port_no, hpriv->mmio + HOST_IRQ_STAT);
+}
+
int ahci_do_hardreset(struct ata_link *link, unsigned int *class,
unsigned long deadline, bool *online)
{
@@ -1602,6 +1619,9 @@ int ahci_do_hardreset(struct ata_link *link, unsigned int *class,
tf.status = ATA_BUSY;
ata_tf_to_fis(&tf, 0, 0, d2h_fis);

+ /* clear pending Interrupt */
+ PortClearPendingInterrupt(ap);
+
rc = sata_link_hardreset(link, timing, deadline, online,
ahci_check_ready);

--
2.39.2