aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2006-05-15 07:57:47 -0400
committerTejun Heo <htejun@gmail.com>2006-05-15 07:57:47 -0400
commit81952c5497b40ae56835bd0d6537f8c6bdea07e7 (patch)
treefa2db695c56e481c271c7249197ad3b4a98b6087 /drivers
parent34bf21704c848fe00c516d1c8f163db08b70b137 (diff)
[PATCH] libata: use new SCR and on/offline functions
Use new SCR and on/offline functions. Note that for LLDD which know it implements SCR callbacks, SCR functions are guaranteed to succeed and ata_port_online() == !ata_port_offline(). Signed-off-by: Tejun Heo <htejun@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/scsi/ahci.c6
-rw-r--r--drivers/scsi/libata-core.c107
-rw-r--r--drivers/scsi/sata_mv.c16
-rw-r--r--drivers/scsi/sata_sil24.c6
4 files changed, 75 insertions, 60 deletions
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index c33255404ee5..c2298fb131d8 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -567,7 +567,7 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
567 567
568 DPRINTK("ENTER\n"); 568 DPRINTK("ENTER\n");
569 569
570 if (!sata_dev_present(ap)) { 570 if (ata_port_offline(ap)) {
571 DPRINTK("PHY reports no device\n"); 571 DPRINTK("PHY reports no device\n");
572 *class = ATA_DEV_NONE; 572 *class = ATA_DEV_NONE;
573 return 0; 573 return 0;
@@ -640,7 +640,7 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
640 msleep(150); 640 msleep(150);
641 641
642 *class = ATA_DEV_NONE; 642 *class = ATA_DEV_NONE;
643 if (sata_dev_present(ap)) { 643 if (ata_port_online(ap)) {
644 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { 644 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) {
645 rc = -EIO; 645 rc = -EIO;
646 reason = "device not ready"; 646 reason = "device not ready";
@@ -670,7 +670,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
670 rc = sata_std_hardreset(ap, class); 670 rc = sata_std_hardreset(ap, class);
671 ahci_start_engine(ap); 671 ahci_start_engine(ap);
672 672
673 if (rc == 0 && sata_dev_present(ap)) 673 if (rc == 0 && ata_port_online(ap))
674 *class = ahci_dev_classify(ap); 674 *class = ahci_dev_classify(ap);
675 if (*class == ATA_DEV_UNKNOWN) 675 if (*class == ATA_DEV_UNKNOWN)
676 *class = ATA_DEV_NONE; 676 *class = ATA_DEV_NONE;
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index b9c5cbf0b786..56f0af208345 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -1494,13 +1494,11 @@ static void sata_print_link_status(struct ata_port *ap)
1494{ 1494{
1495 u32 sstatus, scontrol, tmp; 1495 u32 sstatus, scontrol, tmp;
1496 1496
1497 if (!ap->ops->scr_read) 1497 if (sata_scr_read(ap, SCR_STATUS, &sstatus))
1498 return; 1498 return;
1499 sata_scr_read(ap, SCR_CONTROL, &scontrol);
1499 1500
1500 sstatus = scr_read(ap, SCR_STATUS); 1501 if (ata_port_online(ap)) {
1501 scontrol = scr_read(ap, SCR_CONTROL);
1502
1503 if (sata_dev_present(ap)) {
1504 tmp = (sstatus >> 4) & 0xf; 1502 tmp = (sstatus >> 4) & 0xf;
1505 printk(KERN_INFO 1503 printk(KERN_INFO
1506 "ata%u: SATA link up %s (SStatus %X SControl %X)\n", 1504 "ata%u: SATA link up %s (SStatus %X SControl %X)\n",
@@ -1531,17 +1529,18 @@ void __sata_phy_reset(struct ata_port *ap)
1531 1529
1532 if (ap->flags & ATA_FLAG_SATA_RESET) { 1530 if (ap->flags & ATA_FLAG_SATA_RESET) {
1533 /* issue phy wake/reset */ 1531 /* issue phy wake/reset */
1534 scr_write_flush(ap, SCR_CONTROL, 0x301); 1532 sata_scr_write_flush(ap, SCR_CONTROL, 0x301);
1535 /* Couldn't find anything in SATA I/II specs, but 1533 /* Couldn't find anything in SATA I/II specs, but
1536 * AHCI-1.1 10.4.2 says at least 1 ms. */ 1534 * AHCI-1.1 10.4.2 says at least 1 ms. */
1537 mdelay(1); 1535 mdelay(1);
1538 } 1536 }
1539 scr_write_flush(ap, SCR_CONTROL, 0x300); /* phy wake/clear reset */ 1537 /* phy wake/clear reset */
1538 sata_scr_write_flush(ap, SCR_CONTROL, 0x300);
1540 1539
1541 /* wait for phy to become ready, if necessary */ 1540 /* wait for phy to become ready, if necessary */
1542 do { 1541 do {
1543 msleep(200); 1542 msleep(200);
1544 sstatus = scr_read(ap, SCR_STATUS); 1543 sata_scr_read(ap, SCR_STATUS, &sstatus);
1545 if ((sstatus & 0xf) != 1) 1544 if ((sstatus & 0xf) != 1)
1546 break; 1545 break;
1547 } while (time_before(jiffies, timeout)); 1546 } while (time_before(jiffies, timeout));
@@ -1550,7 +1549,7 @@ void __sata_phy_reset(struct ata_port *ap)
1550 sata_print_link_status(ap); 1549 sata_print_link_status(ap);
1551 1550
1552 /* TODO: phy layer with polling, timeouts, etc. */ 1551 /* TODO: phy layer with polling, timeouts, etc. */
1553 if (sata_dev_present(ap)) 1552 if (!ata_port_offline(ap))
1554 ata_port_probe(ap); 1553 ata_port_probe(ap);
1555 else 1554 else
1556 ata_port_disable(ap); 1555 ata_port_disable(ap);
@@ -1638,11 +1637,12 @@ void ata_port_disable(struct ata_port *ap)
1638 */ 1637 */
1639int sata_down_spd_limit(struct ata_port *ap) 1638int sata_down_spd_limit(struct ata_port *ap)
1640{ 1639{
1641 u32 spd, mask; 1640 u32 sstatus, spd, mask;
1642 int highbit; 1641 int rc, highbit;
1643 1642
1644 if (ap->cbl != ATA_CBL_SATA || !ap->ops->scr_read) 1643 rc = sata_scr_read(ap, SCR_STATUS, &sstatus);
1645 return -EOPNOTSUPP; 1644 if (rc)
1645 return rc;
1646 1646
1647 mask = ap->sata_spd_limit; 1647 mask = ap->sata_spd_limit;
1648 if (mask <= 1) 1648 if (mask <= 1)
@@ -1650,7 +1650,7 @@ int sata_down_spd_limit(struct ata_port *ap)
1650 highbit = fls(mask) - 1; 1650 highbit = fls(mask) - 1;
1651 mask &= ~(1 << highbit); 1651 mask &= ~(1 << highbit);
1652 1652
1653 spd = (scr_read(ap, SCR_STATUS) >> 4) & 0xf; 1653 spd = (sstatus >> 4) & 0xf;
1654 if (spd <= 1) 1654 if (spd <= 1)
1655 return -EINVAL; 1655 return -EINVAL;
1656 spd--; 1656 spd--;
@@ -1700,11 +1700,9 @@ int sata_set_spd_needed(struct ata_port *ap)
1700{ 1700{
1701 u32 scontrol; 1701 u32 scontrol;
1702 1702
1703 if (ap->cbl != ATA_CBL_SATA || !ap->ops->scr_read) 1703 if (sata_scr_read(ap, SCR_CONTROL, &scontrol))
1704 return 0; 1704 return 0;
1705 1705
1706 scontrol = scr_read(ap, SCR_CONTROL);
1707
1708 return __sata_set_spd_needed(ap, &scontrol); 1706 return __sata_set_spd_needed(ap, &scontrol);
1709} 1707}
1710 1708
@@ -1719,20 +1717,22 @@ int sata_set_spd_needed(struct ata_port *ap)
1719 * 1717 *
1720 * RETURNS: 1718 * RETURNS:
1721 * 0 if spd doesn't need to be changed, 1 if spd has been 1719 * 0 if spd doesn't need to be changed, 1 if spd has been
1722 * changed. -EOPNOTSUPP if SCR registers are inaccessible. 1720 * changed. Negative errno if SCR registers are inaccessible.
1723 */ 1721 */
1724int sata_set_spd(struct ata_port *ap) 1722int sata_set_spd(struct ata_port *ap)
1725{ 1723{
1726 u32 scontrol; 1724 u32 scontrol;
1725 int rc;
1727 1726
1728 if (ap->cbl != ATA_CBL_SATA || !ap->ops->scr_read) 1727 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol)))
1729 return -EOPNOTSUPP; 1728 return rc;
1730 1729
1731 scontrol = scr_read(ap, SCR_CONTROL);
1732 if (!__sata_set_spd_needed(ap, &scontrol)) 1730 if (!__sata_set_spd_needed(ap, &scontrol))
1733 return 0; 1731 return 0;
1734 1732
1735 scr_write(ap, SCR_CONTROL, scontrol); 1733 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol)))
1734 return rc;
1735
1736 return 1; 1736 return 1;
1737} 1737}
1738 1738
@@ -2336,20 +2336,26 @@ static int sata_phy_resume(struct ata_port *ap)
2336{ 2336{
2337 unsigned long timeout = jiffies + (HZ * 5); 2337 unsigned long timeout = jiffies + (HZ * 5);
2338 u32 scontrol, sstatus; 2338 u32 scontrol, sstatus;
2339 int rc;
2340
2341 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol)))
2342 return rc;
2339 2343
2340 scontrol = scr_read(ap, SCR_CONTROL);
2341 scontrol = (scontrol & 0x0f0) | 0x300; 2344 scontrol = (scontrol & 0x0f0) | 0x300;
2342 scr_write_flush(ap, SCR_CONTROL, scontrol); 2345
2346 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol)))
2347 return rc;
2343 2348
2344 /* Wait for phy to become ready, if necessary. */ 2349 /* Wait for phy to become ready, if necessary. */
2345 do { 2350 do {
2346 msleep(200); 2351 msleep(200);
2347 sstatus = scr_read(ap, SCR_STATUS); 2352 if ((rc = sata_scr_read(ap, SCR_STATUS, &sstatus)))
2353 return rc;
2348 if ((sstatus & 0xf) != 1) 2354 if ((sstatus & 0xf) != 1)
2349 return 0; 2355 return 0;
2350 } while (time_before(jiffies, timeout)); 2356 } while (time_before(jiffies, timeout));
2351 2357
2352 return -1; 2358 return -EBUSY;
2353} 2359}
2354 2360
2355/** 2361/**
@@ -2367,21 +2373,20 @@ static int sata_phy_resume(struct ata_port *ap)
2367 */ 2373 */
2368void ata_std_probeinit(struct ata_port *ap) 2374void ata_std_probeinit(struct ata_port *ap)
2369{ 2375{
2370 if ((ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read) { 2376 u32 scontrol;
2371 u32 spd;
2372
2373 /* resume link */
2374 sata_phy_resume(ap);
2375 2377
2376 /* init sata_spd_limit to the current value */ 2378 /* resume link */
2377 spd = (scr_read(ap, SCR_CONTROL) & 0xf0) >> 4; 2379 sata_phy_resume(ap);
2378 if (spd)
2379 ap->sata_spd_limit &= (1 << spd) - 1;
2380 2380
2381 /* wait for device */ 2381 /* init sata_spd_limit to the current value */
2382 if (sata_dev_present(ap)) 2382 if (sata_scr_read(ap, SCR_CONTROL, &scontrol) == 0) {
2383 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 2383 int spd = (scontrol >> 4) & 0xf;
2384 ap->sata_spd_limit &= (1 << spd) - 1;
2384 } 2385 }
2386
2387 /* wait for device */
2388 if (ata_port_online(ap))
2389 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
2385} 2390}
2386 2391
2387/** 2392/**
@@ -2406,7 +2411,7 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
2406 2411
2407 DPRINTK("ENTER\n"); 2412 DPRINTK("ENTER\n");
2408 2413
2409 if (ap->ops->scr_read && !sata_dev_present(ap)) { 2414 if (ata_port_offline(ap)) {
2410 classes[0] = ATA_DEV_NONE; 2415 classes[0] = ATA_DEV_NONE;
2411 goto out; 2416 goto out;
2412 } 2417 }
@@ -2457,6 +2462,7 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
2457int sata_std_hardreset(struct ata_port *ap, unsigned int *class) 2462int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
2458{ 2463{
2459 u32 scontrol; 2464 u32 scontrol;
2465 int rc;
2460 2466
2461 DPRINTK("ENTER\n"); 2467 DPRINTK("ENTER\n");
2462 2468
@@ -2466,17 +2472,25 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
2466 * reconfiguration. This works for at least ICH7 AHCI 2472 * reconfiguration. This works for at least ICH7 AHCI
2467 * and Sil3124. 2473 * and Sil3124.
2468 */ 2474 */
2469 scontrol = scr_read(ap, SCR_CONTROL); 2475 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol)))
2476 return rc;
2477
2470 scontrol = (scontrol & 0x0f0) | 0x302; 2478 scontrol = (scontrol & 0x0f0) | 0x302;
2471 scr_write_flush(ap, SCR_CONTROL, scontrol); 2479
2480 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol)))
2481 return rc;
2472 2482
2473 sata_set_spd(ap); 2483 sata_set_spd(ap);
2474 } 2484 }
2475 2485
2476 /* issue phy wake/reset */ 2486 /* issue phy wake/reset */
2477 scontrol = scr_read(ap, SCR_CONTROL); 2487 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol)))
2488 return rc;
2489
2478 scontrol = (scontrol & 0x0f0) | 0x301; 2490 scontrol = (scontrol & 0x0f0) | 0x301;
2479 scr_write_flush(ap, SCR_CONTROL, scontrol); 2491
2492 if ((rc = sata_scr_write_flush(ap, SCR_CONTROL, scontrol)))
2493 return rc;
2480 2494
2481 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1 2495 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1
2482 * 10.4.2 says at least 1 ms. 2496 * 10.4.2 says at least 1 ms.
@@ -2487,7 +2501,7 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
2487 sata_phy_resume(ap); 2501 sata_phy_resume(ap);
2488 2502
2489 /* TODO: phy layer with polling, timeouts, etc. */ 2503 /* TODO: phy layer with polling, timeouts, etc. */
2490 if (!sata_dev_present(ap)) { 2504 if (ata_port_offline(ap)) {
2491 *class = ATA_DEV_NONE; 2505 *class = ATA_DEV_NONE;
2492 DPRINTK("EXIT, link offline\n"); 2506 DPRINTK("EXIT, link offline\n");
2493 return 0; 2507 return 0;
@@ -2527,8 +2541,7 @@ void ata_std_postreset(struct ata_port *ap, unsigned int *classes)
2527 DPRINTK("ENTER\n"); 2541 DPRINTK("ENTER\n");
2528 2542
2529 /* print link status */ 2543 /* print link status */
2530 if (ap->cbl == ATA_CBL_SATA) 2544 sata_print_link_status(ap);
2531 sata_print_link_status(ap);
2532 2545
2533 /* re-enable interrupts */ 2546 /* re-enable interrupts */
2534 if (ap->ioaddr.ctl_addr) /* FIXME: hack. create a hook instead */ 2547 if (ap->ioaddr.ctl_addr) /* FIXME: hack. create a hook instead */
@@ -2575,7 +2588,7 @@ int ata_std_probe_reset(struct ata_port *ap, unsigned int *classes)
2575 ata_reset_fn_t hardreset; 2588 ata_reset_fn_t hardreset;
2576 2589
2577 hardreset = NULL; 2590 hardreset = NULL;
2578 if (ap->cbl == ATA_CBL_SATA && ap->ops->scr_read) 2591 if (sata_scr_valid(ap))
2579 hardreset = sata_std_hardreset; 2592 hardreset = sata_std_hardreset;
2580 2593
2581 return ata_drive_probe_reset(ap, ata_std_probeinit, 2594 return ata_drive_probe_reset(ap, ata_std_probeinit,
diff --git a/drivers/scsi/sata_mv.c b/drivers/scsi/sata_mv.c
index 181917ac0426..748569b615fc 100644
--- a/drivers/scsi/sata_mv.c
+++ b/drivers/scsi/sata_mv.c
@@ -1309,8 +1309,8 @@ static void mv_err_intr(struct ata_port *ap)
1309 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1309 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1310 1310
1311 if (EDMA_ERR_SERR & edma_err_cause) { 1311 if (EDMA_ERR_SERR & edma_err_cause) {
1312 serr = scr_read(ap, SCR_ERROR); 1312 sata_scr_read(ap, SCR_ERROR, &serr);
1313 scr_write_flush(ap, SCR_ERROR, serr); 1313 sata_scr_write_flush(ap, SCR_ERROR, serr);
1314 } 1314 }
1315 if (EDMA_ERR_SELF_DIS & edma_err_cause) { 1315 if (EDMA_ERR_SELF_DIS & edma_err_cause) {
1316 struct mv_port_priv *pp = ap->private_data; 1316 struct mv_port_priv *pp = ap->private_data;
@@ -1934,15 +1934,16 @@ static void __mv_phy_reset(struct ata_port *ap, int can_sleep)
1934 1934
1935 /* Issue COMRESET via SControl */ 1935 /* Issue COMRESET via SControl */
1936comreset_retry: 1936comreset_retry:
1937 scr_write_flush(ap, SCR_CONTROL, 0x301); 1937 sata_scr_write_flush(ap, SCR_CONTROL, 0x301);
1938 __msleep(1, can_sleep); 1938 __msleep(1, can_sleep);
1939 1939
1940 scr_write_flush(ap, SCR_CONTROL, 0x300); 1940 sata_scr_write_flush(ap, SCR_CONTROL, 0x300);
1941 __msleep(20, can_sleep); 1941 __msleep(20, can_sleep);
1942 1942
1943 timeout = jiffies + msecs_to_jiffies(200); 1943 timeout = jiffies + msecs_to_jiffies(200);
1944 do { 1944 do {
1945 sstatus = scr_read(ap, SCR_STATUS) & 0x3; 1945 sata_scr_read(ap, SCR_STATUS, &sstatus);
1946 sstatus &= 0x3;
1946 if ((sstatus == 3) || (sstatus == 0)) 1947 if ((sstatus == 3) || (sstatus == 0))
1947 break; 1948 break;
1948 1949
@@ -1959,11 +1960,12 @@ comreset_retry:
1959 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), 1960 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS),
1960 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); 1961 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL));
1961 1962
1962 if (sata_dev_present(ap)) { 1963 if (ata_port_online(ap)) {
1963 ata_port_probe(ap); 1964 ata_port_probe(ap);
1964 } else { 1965 } else {
1966 sata_scr_read(ap, SCR_STATUS, &sstatus);
1965 printk(KERN_INFO "ata%u: no device found (phy stat %08x)\n", 1967 printk(KERN_INFO "ata%u: no device found (phy stat %08x)\n",
1966 ap->id, scr_read(ap, SCR_STATUS)); 1968 ap->id, sstatus);
1967 ata_port_disable(ap); 1969 ata_port_disable(ap);
1968 return; 1970 return;
1969 } 1971 }
diff --git a/drivers/scsi/sata_sil24.c b/drivers/scsi/sata_sil24.c
index 45b9e37c191e..bedc787dafd1 100644
--- a/drivers/scsi/sata_sil24.c
+++ b/drivers/scsi/sata_sil24.c
@@ -464,7 +464,7 @@ static int sil24_softreset(struct ata_port *ap, unsigned int *class)
464 464
465 DPRINTK("ENTER\n"); 465 DPRINTK("ENTER\n");
466 466
467 if (!sata_dev_present(ap)) { 467 if (ata_port_offline(ap)) {
468 DPRINTK("PHY reports no device\n"); 468 DPRINTK("PHY reports no device\n");
469 *class = ATA_DEV_NONE; 469 *class = ATA_DEV_NONE;
470 goto out; 470 goto out;
@@ -531,7 +531,7 @@ static int sil24_hardreset(struct ata_port *ap, unsigned int *class)
531 sata_set_spd(ap); 531 sata_set_spd(ap);
532 532
533 tout_msec = 100; 533 tout_msec = 100;
534 if (sata_dev_present(ap)) 534 if (ata_port_online(ap))
535 tout_msec = 5000; 535 tout_msec = 5000;
536 536
537 writel(PORT_CS_DEV_RST, port + PORT_CTRL_STAT); 537 writel(PORT_CS_DEV_RST, port + PORT_CTRL_STAT);
@@ -544,7 +544,7 @@ static int sil24_hardreset(struct ata_port *ap, unsigned int *class)
544 msleep(100); 544 msleep(100);
545 545
546 if (tmp & PORT_CS_DEV_RST) { 546 if (tmp & PORT_CS_DEV_RST) {
547 if (!sata_dev_present(ap)) 547 if (ata_port_offline(ap))
548 return 0; 548 return 0;
549 reason = "link not ready"; 549 reason = "link not ready";
550 goto err; 550 goto err;