aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libata-core.c
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2006-05-31 05:27:48 -0400
committerTejun Heo <htejun@gmail.com>2006-05-31 05:27:48 -0400
commitf5914a461eb9703773226a0813f6ffcae10c0861 (patch)
tree3441af53250530c3135a8fa55f06dd7bc62da037 /drivers/scsi/libata-core.c
parentd7bb4cc7575929a60b0a718daa1bce87bea9a9cc (diff)
[PATCH] libata-hp-prep: add prereset() method and implement ata_std_prereset()
With hotplug, every reset might be a probing reset and thus something similar to probe_init() is needed. prereset() method is called before a series of resets to a port and is the counterpart of postreset(). prereset() can tell EH to use different type of reset or skip reset by modifying ehc->i.action. This patch also implements ata_std_prereset(). Most controllers should be able to use this function directly or with some wrapping. After hotplug, different controllers need different actions to resume the PHY and detect the newly attached device. Controllers can be categorized as follows. * Controllers which can wait for the first D2H FIS after hotplug. Note that if the waiting is implemented by polling TF status, there needs to be a way to set BSY on PHY status change. It can be implemented by hardware or with the help of the driver. * Controllers which can wait for the first D2H FIS after sending COMRESET. These controllers need to issue COMRESET to wait for the first FIS. Note that the received D2H FIS could be the first D2H FIS after POR (power-on-reset) or D2H FIS in response to the COMRESET. Some controllers use COMRESET as TF status synchronization point and clear TF automatically (sata_sil). * Controllers which cannot wait for the first D2H FIS reliably. Blindly issuing SRST to spinning-up device often results in command issue failure or timeout, causing extended delay. For these controllers, ata_std_prereset() explicitly waits ATA_SPINUP_WAIT (currently 8s) to give newly attached device time to spin up, then issues reset. Note that failing to getting ready in ATA_SPINUP_WAIT is not critical. libata will retry. So, the timeout needs to be long enough to spin up most devices. LLDDs can tell ata_std_prereset() which of above action is needed with ATA_FLAG_HRST_TO_RESUME and ATA_FLAG_SKIP_D2H_BSY flags. These flags are PHY-specific property and will be moved to ata_link later. While at it, this patch unifies function typedef's such that they all have named arguments. Signed-off-by: Tejun Heo <htejun@gmail.com>
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r--drivers/scsi/libata-core.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 4823ecefb8a1..2531a701d6e9 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -2525,6 +2525,90 @@ int sata_phy_resume(struct ata_port *ap, const unsigned long *params)
2525 return sata_phy_debounce(ap, params); 2525 return sata_phy_debounce(ap, params);
2526} 2526}
2527 2527
2528static void ata_wait_spinup(struct ata_port *ap)
2529{
2530 struct ata_eh_context *ehc = &ap->eh_context;
2531 unsigned long end, secs;
2532 int rc;
2533
2534 /* first, debounce phy if SATA */
2535 if (ap->cbl == ATA_CBL_SATA) {
2536 rc = sata_phy_debounce(ap, sata_deb_timing_eh);
2537
2538 /* if debounced successfully and offline, no need to wait */
2539 if ((rc == 0 || rc == -EOPNOTSUPP) && ata_port_offline(ap))
2540 return;
2541 }
2542
2543 /* okay, let's give the drive time to spin up */
2544 end = ehc->i.hotplug_timestamp + ATA_SPINUP_WAIT * HZ / 1000;
2545 secs = ((end - jiffies) + HZ - 1) / HZ;
2546
2547 if (time_after(jiffies, end))
2548 return;
2549
2550 if (secs > 5)
2551 ata_port_printk(ap, KERN_INFO, "waiting for device to spin up "
2552 "(%lu secs)\n", secs);
2553
2554 schedule_timeout_uninterruptible(end - jiffies);
2555}
2556
2557/**
2558 * ata_std_prereset - prepare for reset
2559 * @ap: ATA port to be reset
2560 *
2561 * @ap is about to be reset. Initialize it.
2562 *
2563 * LOCKING:
2564 * Kernel thread context (may sleep)
2565 *
2566 * RETURNS:
2567 * 0 on success, -errno otherwise.
2568 */
2569int ata_std_prereset(struct ata_port *ap)
2570{
2571 struct ata_eh_context *ehc = &ap->eh_context;
2572 const unsigned long *timing;
2573 int rc;
2574
2575 /* hotplug? */
2576 if (ehc->i.flags & ATA_EHI_HOTPLUGGED) {
2577 if (ap->flags & ATA_FLAG_HRST_TO_RESUME)
2578 ehc->i.action |= ATA_EH_HARDRESET;
2579 if (ap->flags & ATA_FLAG_SKIP_D2H_BSY)
2580 ata_wait_spinup(ap);
2581 }
2582
2583 /* if we're about to do hardreset, nothing more to do */
2584 if (ehc->i.action & ATA_EH_HARDRESET)
2585 return 0;
2586
2587 /* if SATA, resume phy */
2588 if (ap->cbl == ATA_CBL_SATA) {
2589 if (ap->flags & ATA_FLAG_LOADING)
2590 timing = sata_deb_timing_boot;
2591 else
2592 timing = sata_deb_timing_eh;
2593
2594 rc = sata_phy_resume(ap, timing);
2595 if (rc && rc != -EOPNOTSUPP) {
2596 /* phy resume failed */
2597 ata_port_printk(ap, KERN_WARNING, "failed to resume "
2598 "link for reset (errno=%d)\n", rc);
2599 return rc;
2600 }
2601 }
2602
2603 /* Wait for !BSY if the controller can wait for the first D2H
2604 * Reg FIS and we don't know that no device is attached.
2605 */
2606 if (!(ap->flags & ATA_FLAG_SKIP_D2H_BSY) && !ata_port_offline(ap))
2607 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
2608
2609 return 0;
2610}
2611
2528/** 2612/**
2529 * ata_std_probeinit - initialize probing 2613 * ata_std_probeinit - initialize probing
2530 * @ap: port to be probed 2614 * @ap: port to be probed
@@ -5840,6 +5924,7 @@ EXPORT_SYMBOL_GPL(sata_phy_reset);
5840EXPORT_SYMBOL_GPL(__sata_phy_reset); 5924EXPORT_SYMBOL_GPL(__sata_phy_reset);
5841EXPORT_SYMBOL_GPL(ata_bus_reset); 5925EXPORT_SYMBOL_GPL(ata_bus_reset);
5842EXPORT_SYMBOL_GPL(ata_std_probeinit); 5926EXPORT_SYMBOL_GPL(ata_std_probeinit);
5927EXPORT_SYMBOL_GPL(ata_std_prereset);
5843EXPORT_SYMBOL_GPL(ata_std_softreset); 5928EXPORT_SYMBOL_GPL(ata_std_softreset);
5844EXPORT_SYMBOL_GPL(sata_std_hardreset); 5929EXPORT_SYMBOL_GPL(sata_std_hardreset);
5845EXPORT_SYMBOL_GPL(ata_std_postreset); 5930EXPORT_SYMBOL_GPL(ata_std_postreset);