Commit 91c4a2e0 authored by Tejun Heo's avatar Tejun Heo Committed by Jeff Garzik

ahci: separate out ahci_exec_polled_cmd()

Separate out ahci_exec_polled_cmd() from ahci_softreset().  This will
be used to implement ahci_pmp_read/write().  ahci_exec_polled_cmd()
performs reset_engine before returning if the command fails (times
out).  This is to improve robustness.
Signed-off-by: default avatarTejun Heo <htejun@gmail.com>
Signed-off-by: default avatarJeff Garzik <jeff@garzik.org>
parent d2e75dff
...@@ -993,17 +993,42 @@ static int ahci_kick_engine(struct ata_port *ap, int force_restart) ...@@ -993,17 +993,42 @@ static int ahci_kick_engine(struct ata_port *ap, int force_restart)
return rc; return rc;
} }
static int ahci_softreset(struct ata_port *ap, unsigned int *class, static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
unsigned long deadline) struct ata_taskfile *tf, int is_cmd, u16 flags,
unsigned long timeout_msec)
{ {
const u32 cmd_fis_len = 5; /* five dwords */
struct ahci_port_priv *pp = ap->private_data; struct ahci_port_priv *pp = ap->private_data;
void __iomem *port_mmio = ahci_port_base(ap); void __iomem *port_mmio = ahci_port_base(ap);
const u32 cmd_fis_len = 5; /* five dwords */ u8 *fis = pp->cmd_tbl;
u32 tmp;
/* prep the command */
ata_tf_to_fis(tf, pmp, is_cmd, fis);
ahci_fill_cmd_slot(pp, 0, cmd_fis_len | flags | (pmp << 12));
/* issue & wait */
writel(1, port_mmio + PORT_CMD_ISSUE);
if (timeout_msec) {
tmp = ata_wait_register(port_mmio + PORT_CMD_ISSUE, 0x1, 0x1,
1, timeout_msec);
if (tmp & 0x1) {
ahci_kick_engine(ap, 1);
return -EBUSY;
}
} else
readl(port_mmio + PORT_CMD_ISSUE); /* flush */
return 0;
}
static int ahci_softreset(struct ata_port *ap, unsigned int *class,
unsigned long deadline)
{
const char *reason = NULL; const char *reason = NULL;
unsigned long now, msecs; unsigned long now, msecs;
struct ata_taskfile tf; struct ata_taskfile tf;
u32 tmp;
u8 *fis;
int rc; int rc;
DPRINTK("ENTER\n"); DPRINTK("ENTER\n");
...@@ -1021,7 +1046,6 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class, ...@@ -1021,7 +1046,6 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class,
"failed to reset engine (errno=%d)", rc); "failed to reset engine (errno=%d)", rc);
ata_tf_init(ap->device, &tf); ata_tf_init(ap->device, &tf);
fis = pp->cmd_tbl;
/* issue the first D2H Register FIS */ /* issue the first D2H Register FIS */
msecs = 0; msecs = 0;
...@@ -1029,16 +1053,9 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class, ...@@ -1029,16 +1053,9 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class,
if (time_after(now, deadline)) if (time_after(now, deadline))
msecs = jiffies_to_msecs(deadline - now); msecs = jiffies_to_msecs(deadline - now);
ahci_fill_cmd_slot(pp, 0,
cmd_fis_len | AHCI_CMD_RESET | AHCI_CMD_CLR_BUSY);
tf.ctl |= ATA_SRST; tf.ctl |= ATA_SRST;
ata_tf_to_fis(&tf, 0, 0, fis); if (ahci_exec_polled_cmd(ap, 0, &tf, 0,
AHCI_CMD_RESET | AHCI_CMD_CLR_BUSY, msecs)) {
writel(1, port_mmio + PORT_CMD_ISSUE);
tmp = ata_wait_register(port_mmio + PORT_CMD_ISSUE, 0x1, 0x1, 1, msecs);
if (tmp & 0x1) {
rc = -EIO; rc = -EIO;
reason = "1st FIS failed"; reason = "1st FIS failed";
goto fail; goto fail;
...@@ -1048,13 +1065,8 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class, ...@@ -1048,13 +1065,8 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class,
msleep(1); msleep(1);
/* issue the second D2H Register FIS */ /* issue the second D2H Register FIS */
ahci_fill_cmd_slot(pp, 0, cmd_fis_len);
tf.ctl &= ~ATA_SRST; tf.ctl &= ~ATA_SRST;
ata_tf_to_fis(&tf, 0, 0, fis); ahci_exec_polled_cmd(ap, 0, &tf, 0, 0, 0);
writel(1, port_mmio + PORT_CMD_ISSUE);
readl(port_mmio + PORT_CMD_ISSUE); /* flush */
/* spec mandates ">= 2ms" before checking status. /* spec mandates ">= 2ms" before checking status.
* We wait 150ms, because that was the magic delay used for * We wait 150ms, because that was the magic delay used for
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment