aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libata-core.c
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2006-05-31 05:27:46 -0400
committerTejun Heo <htejun@gmail.com>2006-05-31 05:27:46 -0400
commitd7bb4cc7575929a60b0a718daa1bce87bea9a9cc (patch)
treeff4cd9715f5ba608795bc4a1b7b86ffd2cf4f99c /drivers/scsi/libata-core.c
parenta9beec95352ff675f27d74c3cb97dc258d022497 (diff)
[PATCH] libata-hp-prep: implement sata_phy_debounce()
With hotplug, PHY always needs to be debounced before a reset as any reset might find new devices. Extract PHY waiting code from sata_phy_resume() and extend it to include SStatus debouncing. Note that sata_phy_debounce() is superset of what used to be done inside sata_phy_resume(). Three default debounce timing parameters are defined to be used by hot/boot plug. As resume failure during probing will be properly handled as errors, timeout doesn't have to be long as before. probeinit() uses the same timeout to retain the original behavior. Signed-off-by: Tejun Heo <htejun@gmail.com>
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r--drivers/scsi/libata-core.c107
1 files changed, 93 insertions, 14 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index a9f79b47b4c3..4823ecefb8a1 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -61,6 +61,11 @@
61 61
62#include "libata.h" 62#include "libata.h"
63 63
64/* debounce timing parameters in msecs { interval, duration, timeout } */
65const unsigned long sata_deb_timing_boot[] = { 5, 100, 2000 };
66const unsigned long sata_deb_timing_eh[] = { 25, 500, 2000 };
67const unsigned long sata_deb_timing_before_fsrst[] = { 100, 2000, 5000 };
68
64static unsigned int ata_dev_init_params(struct ata_device *dev, 69static unsigned int ata_dev_init_params(struct ata_device *dev,
65 u16 heads, u16 sectors); 70 u16 heads, u16 sectors);
66static unsigned int ata_dev_set_xfermode(struct ata_device *dev); 71static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
@@ -2427,10 +2432,81 @@ err_out:
2427 DPRINTK("EXIT\n"); 2432 DPRINTK("EXIT\n");
2428} 2433}
2429 2434
2430static int sata_phy_resume(struct ata_port *ap) 2435/**
2436 * sata_phy_debounce - debounce SATA phy status
2437 * @ap: ATA port to debounce SATA phy status for
2438 * @params: timing parameters { interval, duratinon, timeout } in msec
2439 *
2440 * Make sure SStatus of @ap reaches stable state, determined by
2441 * holding the same value where DET is not 1 for @duration polled
2442 * every @interval, before @timeout. Timeout constraints the
2443 * beginning of the stable state. Because, after hot unplugging,
2444 * DET gets stuck at 1 on some controllers, this functions waits
2445 * until timeout then returns 0 if DET is stable at 1.
2446 *
2447 * LOCKING:
2448 * Kernel thread context (may sleep)
2449 *
2450 * RETURNS:
2451 * 0 on success, -errno on failure.
2452 */
2453int sata_phy_debounce(struct ata_port *ap, const unsigned long *params)
2431{ 2454{
2432 unsigned long timeout = jiffies + (HZ * 5); 2455 unsigned long interval_msec = params[0];
2433 u32 scontrol, sstatus; 2456 unsigned long duration = params[1] * HZ / 1000;
2457 unsigned long timeout = jiffies + params[2] * HZ / 1000;
2458 unsigned long last_jiffies;
2459 u32 last, cur;
2460 int rc;
2461
2462 if ((rc = sata_scr_read(ap, SCR_STATUS, &cur)))
2463 return rc;
2464 cur &= 0xf;
2465
2466 last = cur;
2467 last_jiffies = jiffies;
2468
2469 while (1) {
2470 msleep(interval_msec);
2471 if ((rc = sata_scr_read(ap, SCR_STATUS, &cur)))
2472 return rc;
2473 cur &= 0xf;
2474
2475 /* DET stable? */
2476 if (cur == last) {
2477 if (cur == 1 && time_before(jiffies, timeout))
2478 continue;
2479 if (time_after(jiffies, last_jiffies + duration))
2480 return 0;
2481 continue;
2482 }
2483
2484 /* unstable, start over */
2485 last = cur;
2486 last_jiffies = jiffies;
2487
2488 /* check timeout */
2489 if (time_after(jiffies, timeout))
2490 return -EBUSY;
2491 }
2492}
2493
2494/**
2495 * sata_phy_resume - resume SATA phy
2496 * @ap: ATA port to resume SATA phy for
2497 * @params: timing parameters { interval, duratinon, timeout } in msec
2498 *
2499 * Resume SATA phy of @ap and debounce it.
2500 *
2501 * LOCKING:
2502 * Kernel thread context (may sleep)
2503 *
2504 * RETURNS:
2505 * 0 on success, -errno on failure.
2506 */
2507int sata_phy_resume(struct ata_port *ap, const unsigned long *params)
2508{
2509 u32 scontrol;
2434 int rc; 2510 int rc;
2435 2511
2436 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol))) 2512 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol)))
@@ -2441,16 +2517,12 @@ static int sata_phy_resume(struct ata_port *ap)
2441 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol))) 2517 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol)))
2442 return rc; 2518 return rc;
2443 2519
2444 /* Wait for phy to become ready, if necessary. */ 2520 /* Some PHYs react badly if SStatus is pounded immediately
2445 do { 2521 * after resuming. Delay 200ms before debouncing.
2446 msleep(200); 2522 */
2447 if ((rc = sata_scr_read(ap, SCR_STATUS, &sstatus))) 2523 msleep(200);
2448 return rc;
2449 if ((sstatus & 0xf) != 1)
2450 return 0;
2451 } while (time_before(jiffies, timeout));
2452 2524
2453 return -EBUSY; 2525 return sata_phy_debounce(ap, params);
2454} 2526}
2455 2527
2456/** 2528/**
@@ -2468,8 +2540,10 @@ static int sata_phy_resume(struct ata_port *ap)
2468 */ 2540 */
2469void ata_std_probeinit(struct ata_port *ap) 2541void ata_std_probeinit(struct ata_port *ap)
2470{ 2542{
2543 static const unsigned long deb_timing[] = { 5, 100, 5000 };
2544
2471 /* resume link */ 2545 /* resume link */
2472 sata_phy_resume(ap); 2546 sata_phy_resume(ap, deb_timing);
2473 2547
2474 /* wait for device */ 2548 /* wait for device */
2475 if (ata_port_online(ap)) 2549 if (ata_port_online(ap))
@@ -2585,7 +2659,7 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
2585 msleep(1); 2659 msleep(1);
2586 2660
2587 /* bring phy back */ 2661 /* bring phy back */
2588 sata_phy_resume(ap); 2662 sata_phy_resume(ap, sata_deb_timing_eh);
2589 2663
2590 /* TODO: phy layer with polling, timeouts, etc. */ 2664 /* TODO: phy layer with polling, timeouts, etc. */
2591 if (ata_port_offline(ap)) { 2665 if (ata_port_offline(ap)) {
@@ -5718,6 +5792,9 @@ u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
5718 * Do not depend on ABI/API stability. 5792 * Do not depend on ABI/API stability.
5719 */ 5793 */
5720 5794
5795EXPORT_SYMBOL_GPL(sata_deb_timing_boot);
5796EXPORT_SYMBOL_GPL(sata_deb_timing_eh);
5797EXPORT_SYMBOL_GPL(sata_deb_timing_before_fsrst);
5721EXPORT_SYMBOL_GPL(ata_std_bios_param); 5798EXPORT_SYMBOL_GPL(ata_std_bios_param);
5722EXPORT_SYMBOL_GPL(ata_std_ports); 5799EXPORT_SYMBOL_GPL(ata_std_ports);
5723EXPORT_SYMBOL_GPL(ata_device_add); 5800EXPORT_SYMBOL_GPL(ata_device_add);
@@ -5757,6 +5834,8 @@ EXPORT_SYMBOL_GPL(ata_bmdma_error_handler);
5757EXPORT_SYMBOL_GPL(ata_bmdma_post_internal_cmd); 5834EXPORT_SYMBOL_GPL(ata_bmdma_post_internal_cmd);
5758EXPORT_SYMBOL_GPL(ata_port_probe); 5835EXPORT_SYMBOL_GPL(ata_port_probe);
5759EXPORT_SYMBOL_GPL(sata_set_spd); 5836EXPORT_SYMBOL_GPL(sata_set_spd);
5837EXPORT_SYMBOL_GPL(sata_phy_debounce);
5838EXPORT_SYMBOL_GPL(sata_phy_resume);
5760EXPORT_SYMBOL_GPL(sata_phy_reset); 5839EXPORT_SYMBOL_GPL(sata_phy_reset);
5761EXPORT_SYMBOL_GPL(__sata_phy_reset); 5840EXPORT_SYMBOL_GPL(__sata_phy_reset);
5762EXPORT_SYMBOL_GPL(ata_bus_reset); 5841EXPORT_SYMBOL_GPL(ata_bus_reset);