Skip to content

Commit

Permalink
libata: add @ap to ata_wait_register() and introduce ata_msleep()
Browse files Browse the repository at this point in the history
Add optional @ap argument to ata_wait_register() and replace msleep()
calls with ata_msleep() which take optional @ap in addition to the
duration.  These will be used to implement EH exclusion.

This patch doesn't cause any behavior difference.

Signed-off-by: Tejun Heo <[email protected]>
Signed-off-by: Jeff Garzik <[email protected]>
  • Loading branch information
htejun authored and Jeff Garzik committed Oct 22, 2010
1 parent a97c400 commit 97750ce
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 48 deletions.
18 changes: 9 additions & 9 deletions drivers/ata/libahci.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ int ahci_stop_engine(struct ata_port *ap)
writel(tmp, port_mmio + PORT_CMD);

/* wait for engine to stop. This could be as long as 500 msec */
tmp = ata_wait_register(port_mmio + PORT_CMD,
tmp = ata_wait_register(ap, port_mmio + PORT_CMD,
PORT_CMD_LIST_ON, PORT_CMD_LIST_ON, 1, 500);
if (tmp & PORT_CMD_LIST_ON)
return -EIO;
Expand Down Expand Up @@ -614,7 +614,7 @@ static int ahci_stop_fis_rx(struct ata_port *ap)
writel(tmp, port_mmio + PORT_CMD);

/* wait for completion, spec says 500ms, give it 1000 */
tmp = ata_wait_register(port_mmio + PORT_CMD, PORT_CMD_FIS_ON,
tmp = ata_wait_register(ap, port_mmio + PORT_CMD, PORT_CMD_FIS_ON,
PORT_CMD_FIS_ON, 10, 1000);
if (tmp & PORT_CMD_FIS_ON)
return -EBUSY;
Expand Down Expand Up @@ -671,7 +671,7 @@ static int ahci_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
readl(port_mmio + PORT_CMD);

/* wait 10ms to be sure we've come out of LPM state */
msleep(10);
ata_msleep(ap, 10);
} else {
cmd |= PORT_CMD_ALPE;
if (policy == ATA_LPM_MIN_POWER)
Expand Down Expand Up @@ -740,7 +740,7 @@ static void ahci_start_port(struct ata_port *ap)
emp->led_state,
4);
if (rc == -EBUSY)
msleep(1);
ata_msleep(ap, 1);
else
break;
}
Expand Down Expand Up @@ -799,7 +799,7 @@ int ahci_reset_controller(struct ata_host *host)
* reset must complete within 1 second, or
* the hardware should be considered fried.
*/
tmp = ata_wait_register(mmio + HOST_CTL, HOST_RESET,
tmp = ata_wait_register(NULL, mmio + HOST_CTL, HOST_RESET,
HOST_RESET, 10, 1000);

if (tmp & HOST_RESET) {
Expand Down Expand Up @@ -1179,7 +1179,7 @@ int ahci_kick_engine(struct ata_port *ap)
writel(tmp, port_mmio + PORT_CMD);

rc = 0;
tmp = ata_wait_register(port_mmio + PORT_CMD,
tmp = ata_wait_register(ap, port_mmio + PORT_CMD,
PORT_CMD_CLO, PORT_CMD_CLO, 1, 500);
if (tmp & PORT_CMD_CLO)
rc = -EIO;
Expand Down Expand Up @@ -1209,8 +1209,8 @@ static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
writel(1, port_mmio + PORT_CMD_ISSUE);

if (timeout_msec) {
tmp = ata_wait_register(port_mmio + PORT_CMD_ISSUE, 0x1, 0x1,
1, timeout_msec);
tmp = ata_wait_register(ap, port_mmio + PORT_CMD_ISSUE,
0x1, 0x1, 1, timeout_msec);
if (tmp & 0x1) {
ahci_kick_engine(ap);
return -EBUSY;
Expand Down Expand Up @@ -1257,7 +1257,7 @@ int ahci_do_softreset(struct ata_link *link, unsigned int *class,
}

/* spec says at least 5us, but be generous and sleep for 1ms */
msleep(1);
ata_msleep(ap, 1);

/* issue the second D2H Register FIS */
tf.ctl &= ~ATA_SRST;
Expand Down
21 changes: 14 additions & 7 deletions drivers/ata/libata-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3404,7 +3404,7 @@ int ata_wait_ready(struct ata_link *link, unsigned long deadline,
warned = 1;
}

msleep(50);
ata_msleep(link->ap, 50);
}
}

Expand All @@ -3425,7 +3425,7 @@ int ata_wait_ready(struct ata_link *link, unsigned long deadline,
int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
int (*check_ready)(struct ata_link *link))
{
msleep(ATA_WAIT_AFTER_RESET);
ata_msleep(link->ap, ATA_WAIT_AFTER_RESET);

return ata_wait_ready(link, deadline, check_ready);
}
Expand Down Expand Up @@ -3473,7 +3473,7 @@ int sata_link_debounce(struct ata_link *link, const unsigned long *params,
last_jiffies = jiffies;

while (1) {
msleep(interval);
ata_msleep(link->ap, interval);
if ((rc = sata_scr_read(link, SCR_STATUS, &cur)))
return rc;
cur &= 0xf;
Expand Down Expand Up @@ -3538,7 +3538,7 @@ int sata_link_resume(struct ata_link *link, const unsigned long *params,
* immediately after resuming. Delay 200ms before
* debouncing.
*/
msleep(200);
ata_msleep(link->ap, 200);

/* is SControl restored correctly? */
if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
Expand Down Expand Up @@ -3742,7 +3742,7 @@ int sata_link_hardreset(struct ata_link *link, const unsigned long *timing,
/* Couldn't find anything in SATA I/II specs, but AHCI-1.1
* 10.4.2 says at least 1 ms.
*/
msleep(1);
ata_msleep(link->ap, 1);

/* bring link back */
rc = sata_link_resume(link, timing, deadline);
Expand Down Expand Up @@ -6483,8 +6483,14 @@ int ata_ratelimit(void)
return __ratelimit(&ratelimit);
}

void ata_msleep(struct ata_port *ap, unsigned int msecs)
{
msleep(msecs);
}

/**
* ata_wait_register - wait until register value changes
* @ap: ATA port to wait register for, can be NULL
* @reg: IO-mapped register
* @mask: Mask to apply to read register value
* @val: Wait condition
Expand All @@ -6506,7 +6512,7 @@ int ata_ratelimit(void)
* RETURNS:
* The final register value.
*/
u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask, u32 val,
unsigned long interval, unsigned long timeout)
{
unsigned long deadline;
Expand All @@ -6521,7 +6527,7 @@ u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
deadline = ata_deadline(jiffies, timeout);

while ((tmp & mask) == val && time_before(jiffies, deadline)) {
msleep(interval);
ata_msleep(ap, interval);
tmp = ioread32(reg);
}

Expand Down Expand Up @@ -6605,6 +6611,7 @@ EXPORT_SYMBOL_GPL(ata_std_postreset);
EXPORT_SYMBOL_GPL(ata_dev_classify);
EXPORT_SYMBOL_GPL(ata_dev_pair);
EXPORT_SYMBOL_GPL(ata_ratelimit);
EXPORT_SYMBOL_GPL(ata_msleep);
EXPORT_SYMBOL_GPL(ata_wait_register);
EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/libata-eh.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ void ata_port_wait_eh(struct ata_port *ap)

/* make sure SCSI EH is complete */
if (scsi_host_in_recovery(ap->scsi_host)) {
msleep(10);
ata_msleep(ap, 10);
goto retry;
}
}
Expand Down
12 changes: 6 additions & 6 deletions drivers/ata/libata-sff.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ int ata_sff_busy_sleep(struct ata_port *ap,
timeout = ata_deadline(timer_start, tmout_pat);
while (status != 0xff && (status & ATA_BUSY) &&
time_before(jiffies, timeout)) {
msleep(50);
ata_msleep(ap, 50);
status = ata_sff_busy_wait(ap, ATA_BUSY, 3);
}

Expand All @@ -234,7 +234,7 @@ int ata_sff_busy_sleep(struct ata_port *ap,
timeout = ata_deadline(timer_start, tmout);
while (status != 0xff && (status & ATA_BUSY) &&
time_before(jiffies, timeout)) {
msleep(50);
ata_msleep(ap, 50);
status = ap->ops->sff_check_status(ap);
}

Expand Down Expand Up @@ -360,7 +360,7 @@ static void ata_dev_select(struct ata_port *ap, unsigned int device,

if (wait) {
if (can_sleep && ap->link.device[device].class == ATA_DEV_ATAPI)
msleep(150);
ata_msleep(ap, 150);
ata_wait_idle(ap);
}
}
Expand Down Expand Up @@ -1356,7 +1356,7 @@ static void ata_sff_pio_task(struct work_struct *work)
*/
status = ata_sff_busy_wait(ap, ATA_BUSY, 5);
if (status & ATA_BUSY) {
msleep(2);
ata_msleep(ap, 2);
status = ata_sff_busy_wait(ap, ATA_BUSY, 10);
if (status & ATA_BUSY) {
ata_sff_queue_pio_task(link, ATA_SHORT_PAUSE);
Expand Down Expand Up @@ -1937,7 +1937,7 @@ int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask,
unsigned int dev1 = devmask & (1 << 1);
int rc, ret = 0;

msleep(ATA_WAIT_AFTER_RESET);
ata_msleep(ap, ATA_WAIT_AFTER_RESET);

/* always check readiness of the master device */
rc = ata_sff_wait_ready(link, deadline);
Expand Down Expand Up @@ -1966,7 +1966,7 @@ int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask,
lbal = ioread8(ioaddr->lbal_addr);
if ((nsect == 1) && (lbal == 1))
break;
msleep(50); /* give drive a breather */
ata_msleep(ap, 50); /* give drive a breather */
}

rc = ata_sff_wait_ready(link, deadline);
Expand Down
4 changes: 2 additions & 2 deletions drivers/ata/pata_bf54x.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ static void bfin_bus_post_reset(struct ata_port *ap, unsigned int devmask)
dev1 = 0;
break;
}
msleep(50); /* give drive a breather */
ata_msleep(ap, 50); /* give drive a breather */
}
if (dev1)
ata_sff_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
Expand Down Expand Up @@ -1087,7 +1087,7 @@ static unsigned int bfin_bus_softreset(struct ata_port *ap,
*
* Old drivers/ide uses the 2mS rule and then waits for ready
*/
msleep(150);
ata_msleep(ap, 150);

/* Before we perform post reset processing we want to see if
* the bus shows 0xFF because the odd clown forgets the D7
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_samsung_cf.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ static int pata_s3c_wait_after_reset(struct ata_link *link,
{
int rc;

msleep(ATA_WAIT_AFTER_RESET);
ata_msleep(link->ap, ATA_WAIT_AFTER_RESET);

/* always check readiness of the master device */
rc = ata_sff_wait_ready(link, deadline);
Expand Down
4 changes: 2 additions & 2 deletions drivers/ata/pata_scc.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ static int scc_wait_after_reset(struct ata_link *link, unsigned int devmask,
*
* Old drivers/ide uses the 2mS rule and then waits for ready.
*/
msleep(150);
ata_msleep(ap, 150);

/* always check readiness of the master device */
rc = ata_sff_wait_ready(link, deadline);
Expand Down Expand Up @@ -559,7 +559,7 @@ static int scc_wait_after_reset(struct ata_link *link, unsigned int devmask,
lbal = in_be32(ioaddr->lbal_addr);
if ((nsect == 1) && (lbal == 1))
break;
msleep(50); /* give drive a breather */
ata_msleep(ap, 50); /* give drive a breather */
}

rc = ata_sff_wait_ready(link, deadline);
Expand Down
19 changes: 10 additions & 9 deletions drivers/ata/sata_fsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ static void sata_fsl_port_stop(struct ata_port *ap)
iowrite32(temp, hcr_base + HCONTROL);

/* Poll for controller to go offline - should happen immediately */
ata_wait_register(hcr_base + HSTATUS, ONLINE, ONLINE, 1, 1);
ata_wait_register(ap, hcr_base + HSTATUS, ONLINE, ONLINE, 1, 1);

ap->private_data = NULL;
dma_free_coherent(dev, SATA_FSL_PORT_PRIV_DMA_SZ,
Expand Down Expand Up @@ -729,7 +729,8 @@ static int sata_fsl_hardreset(struct ata_link *link, unsigned int *class,
iowrite32(temp, hcr_base + HCONTROL);

/* Poll for controller to go offline */
temp = ata_wait_register(hcr_base + HSTATUS, ONLINE, ONLINE, 1, 500);
temp = ata_wait_register(ap, hcr_base + HSTATUS, ONLINE, ONLINE,
1, 500);

if (temp & ONLINE) {
ata_port_printk(ap, KERN_ERR,
Expand All @@ -752,7 +753,7 @@ static int sata_fsl_hardreset(struct ata_link *link, unsigned int *class,
/*
* PHY reset should remain asserted for atleast 1ms
*/
msleep(1);
ata_msleep(ap, 1);

/*
* Now, bring the host controller online again, this can take time
Expand All @@ -766,7 +767,7 @@ static int sata_fsl_hardreset(struct ata_link *link, unsigned int *class,
temp |= HCONTROL_PMP_ATTACHED;
iowrite32(temp, hcr_base + HCONTROL);

temp = ata_wait_register(hcr_base + HSTATUS, ONLINE, 0, 1, 500);
temp = ata_wait_register(ap, hcr_base + HSTATUS, ONLINE, 0, 1, 500);

if (!(temp & ONLINE)) {
ata_port_printk(ap, KERN_ERR,
Expand All @@ -784,7 +785,7 @@ static int sata_fsl_hardreset(struct ata_link *link, unsigned int *class,
* presence
*/

temp = ata_wait_register(hcr_base + HSTATUS, 0xFF, 0, 1, 500);
temp = ata_wait_register(ap, hcr_base + HSTATUS, 0xFF, 0, 1, 500);
if ((!(temp & 0x10)) || ata_link_offline(link)) {
ata_port_printk(ap, KERN_WARNING,
"No Device OR PHYRDY change,Hstatus = 0x%x\n",
Expand All @@ -797,7 +798,7 @@ static int sata_fsl_hardreset(struct ata_link *link, unsigned int *class,
* Wait for the first D2H from device,i.e,signature update notification
*/
start_jiffies = jiffies;
temp = ata_wait_register(hcr_base + HSTATUS, 0xFF, 0x10,
temp = ata_wait_register(ap, hcr_base + HSTATUS, 0xFF, 0x10,
500, jiffies_to_msecs(deadline - start_jiffies));

if ((temp & 0xFF) != 0x18) {
Expand Down Expand Up @@ -880,7 +881,7 @@ static int sata_fsl_softreset(struct ata_link *link, unsigned int *class,
iowrite32(pmp, CQPMP + hcr_base);
iowrite32(1, CQ + hcr_base);

temp = ata_wait_register(CQ + hcr_base, 0x1, 0x1, 1, 5000);
temp = ata_wait_register(ap, CQ + hcr_base, 0x1, 0x1, 1, 5000);
if (temp & 0x1) {
ata_port_printk(ap, KERN_WARNING, "ATA_SRST issue failed\n");

Expand All @@ -896,7 +897,7 @@ static int sata_fsl_softreset(struct ata_link *link, unsigned int *class,
goto err;
}

msleep(1);
ata_msleep(ap, 1);

/*
* SATA device enters reset state after receving a Control register
Expand All @@ -915,7 +916,7 @@ static int sata_fsl_softreset(struct ata_link *link, unsigned int *class,
if (pmp != SATA_PMP_CTRL_PORT)
iowrite32(pmp, CQPMP + hcr_base);
iowrite32(1, CQ + hcr_base);
msleep(150); /* ?? */
ata_msleep(ap, 150); /* ?? */

/*
* The above command would have signalled an interrupt on command
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/sata_inic162x.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ static int inic_hardreset(struct ata_link *link, unsigned int *class,

writew(IDMA_CTL_RST_ATA, idma_ctl);
readw(idma_ctl); /* flush */
msleep(1);
ata_msleep(ap, 1);
writew(0, idma_ctl);

rc = sata_link_resume(link, timing, deadline);
Expand Down
Loading

0 comments on commit 97750ce

Please sign in to comment.