aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libata-core.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2006-04-02 10:30:40 -0400
committerJeff Garzik <jeff@garzik.org>2006-04-02 10:30:40 -0400
commit029f5468b5b5f93a09bf90326fdcb9124079658d (patch)
treef869fb02ad1ca49e0920e073b22cbb96a184ccae /drivers/scsi/libata-core.c
parent8e181c14f2baa5be9b7f7c3917b7d4ecf7529110 (diff)
parent1ad8e7f9eb051b040880e45337ed74bfd916ef7f (diff)
Merge branch 'upstream'
Conflicts: drivers/scsi/libata-core.c drivers/scsi/pdc_adma.c drivers/scsi/sata_mv.c drivers/scsi/sata_nv.c drivers/scsi/sata_promise.c drivers/scsi/sata_qstor.c drivers/scsi/sata_sx4.c drivers/scsi/sata_vsc.c include/linux/libata.h
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r--drivers/scsi/libata-core.c408
1 files changed, 329 insertions, 79 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 597e9e8bcd2c..9de48dd4234a 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -65,7 +65,6 @@ static unsigned int ata_dev_init_params(struct ata_port *ap,
65 struct ata_device *dev, 65 struct ata_device *dev,
66 u16 heads, 66 u16 heads,
67 u16 sectors); 67 u16 sectors);
68static int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev);
69static unsigned int ata_dev_set_xfermode(struct ata_port *ap, 68static unsigned int ata_dev_set_xfermode(struct ata_port *ap,
70 struct ata_device *dev); 69 struct ata_device *dev);
71static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev); 70static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev);
@@ -409,7 +408,7 @@ static const char *sata_spd_string(unsigned int spd)
409 return spd_str[spd - 1]; 408 return spd_str[spd - 1];
410} 409}
411 410
412static void ata_dev_disable(struct ata_port *ap, struct ata_device *dev) 411void ata_dev_disable(struct ata_port *ap, struct ata_device *dev)
413{ 412{
414 if (ata_dev_enabled(dev)) { 413 if (ata_dev_enabled(dev)) {
415 printk(KERN_WARNING "ata%u: dev %u disabled\n", 414 printk(KERN_WARNING "ata%u: dev %u disabled\n",
@@ -961,6 +960,7 @@ void ata_qc_complete_internal(struct ata_queued_cmd *qc)
961 * @ap: Port to which the command is sent 960 * @ap: Port to which the command is sent
962 * @dev: Device to which the command is sent 961 * @dev: Device to which the command is sent
963 * @tf: Taskfile registers for the command and the result 962 * @tf: Taskfile registers for the command and the result
963 * @cdb: CDB for packet command
964 * @dma_dir: Data tranfer direction of the command 964 * @dma_dir: Data tranfer direction of the command
965 * @buf: Data buffer of the command 965 * @buf: Data buffer of the command
966 * @buflen: Length of data buffer 966 * @buflen: Length of data buffer
@@ -975,10 +975,9 @@ void ata_qc_complete_internal(struct ata_queued_cmd *qc)
975 * None. Should be called with kernel context, might sleep. 975 * None. Should be called with kernel context, might sleep.
976 */ 976 */
977 977
978static unsigned 978unsigned ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
979ata_exec_internal(struct ata_port *ap, struct ata_device *dev, 979 struct ata_taskfile *tf, const u8 *cdb,
980 struct ata_taskfile *tf, 980 int dma_dir, void *buf, unsigned int buflen)
981 int dma_dir, void *buf, unsigned int buflen)
982{ 981{
983 u8 command = tf->command; 982 u8 command = tf->command;
984 struct ata_queued_cmd *qc; 983 struct ata_queued_cmd *qc;
@@ -992,6 +991,8 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
992 BUG_ON(qc == NULL); 991 BUG_ON(qc == NULL);
993 992
994 qc->tf = *tf; 993 qc->tf = *tf;
994 if (cdb)
995 memcpy(qc->cdb, cdb, ATAPI_CDB_LEN);
995 qc->dma_dir = dma_dir; 996 qc->dma_dir = dma_dir;
996 if (dma_dir != DMA_NONE) { 997 if (dma_dir != DMA_NONE) {
997 ata_sg_init_one(qc, buf, buflen); 998 ata_sg_init_one(qc, buf, buflen);
@@ -1042,7 +1043,7 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
1042 * 1043 *
1043 * Kill the following code as soon as those drivers are fixed. 1044 * Kill the following code as soon as those drivers are fixed.
1044 */ 1045 */
1045 if (ap->flags & ATA_FLAG_PORT_DISABLED) { 1046 if (ap->flags & ATA_FLAG_DISABLED) {
1046 err_mask |= AC_ERR_SYSTEM; 1047 err_mask |= AC_ERR_SYSTEM;
1047 ata_port_probe(ap); 1048 ata_port_probe(ap);
1048 } 1049 }
@@ -1141,7 +1142,7 @@ static int ata_dev_read_id(struct ata_port *ap, struct ata_device *dev,
1141 1142
1142 tf.protocol = ATA_PROT_PIO; 1143 tf.protocol = ATA_PROT_PIO;
1143 1144
1144 err_mask = ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE, 1145 err_mask = ata_exec_internal(ap, dev, &tf, NULL, DMA_FROM_DEVICE,
1145 id, sizeof(id[0]) * ATA_ID_WORDS); 1146 id, sizeof(id[0]) * ATA_ID_WORDS);
1146 if (err_mask) { 1147 if (err_mask) {
1147 rc = -EIO; 1148 rc = -EIO;
@@ -1238,7 +1239,7 @@ static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev,
1238 id[84], id[85], id[86], id[87], id[88]); 1239 id[84], id[85], id[86], id[87], id[88]);
1239 1240
1240 /* initialize to-be-configured parameters */ 1241 /* initialize to-be-configured parameters */
1241 dev->flags = 0; 1242 dev->flags &= ~ATA_DFLAG_CFG_MASK;
1242 dev->max_sectors = 0; 1243 dev->max_sectors = 0;
1243 dev->cdb_len = 0; 1244 dev->cdb_len = 0;
1244 dev->n_sectors = 0; 1245 dev->n_sectors = 0;
@@ -1381,11 +1382,18 @@ err_out_nosup:
1381static int ata_bus_probe(struct ata_port *ap) 1382static int ata_bus_probe(struct ata_port *ap)
1382{ 1383{
1383 unsigned int classes[ATA_MAX_DEVICES]; 1384 unsigned int classes[ATA_MAX_DEVICES];
1384 int i, rc, found = 0; 1385 int tries[ATA_MAX_DEVICES];
1386 int i, rc, down_xfermask;
1385 struct ata_device *dev; 1387 struct ata_device *dev;
1386 1388
1387 ata_port_probe(ap); 1389 ata_port_probe(ap);
1388 1390
1391 for (i = 0; i < ATA_MAX_DEVICES; i++)
1392 tries[i] = ATA_PROBE_MAX_TRIES;
1393
1394 retry:
1395 down_xfermask = 0;
1396
1389 /* reset and determine device classes */ 1397 /* reset and determine device classes */
1390 for (i = 0; i < ATA_MAX_DEVICES; i++) 1398 for (i = 0; i < ATA_MAX_DEVICES; i++)
1391 classes[i] = ATA_DEV_UNKNOWN; 1399 classes[i] = ATA_DEV_UNKNOWN;
@@ -1399,7 +1407,7 @@ static int ata_bus_probe(struct ata_port *ap)
1399 } else { 1407 } else {
1400 ap->ops->phy_reset(ap); 1408 ap->ops->phy_reset(ap);
1401 1409
1402 if (!(ap->flags & ATA_FLAG_PORT_DISABLED)) 1410 if (!(ap->flags & ATA_FLAG_DISABLED))
1403 for (i = 0; i < ATA_MAX_DEVICES; i++) 1411 for (i = 0; i < ATA_MAX_DEVICES; i++)
1404 classes[i] = ap->device[i].class; 1412 classes[i] = ap->device[i].class;
1405 1413
@@ -1415,21 +1423,23 @@ static int ata_bus_probe(struct ata_port *ap)
1415 dev = &ap->device[i]; 1423 dev = &ap->device[i];
1416 dev->class = classes[i]; 1424 dev->class = classes[i];
1417 1425
1418 if (!ata_dev_enabled(dev)) 1426 if (!tries[i]) {
1419 continue; 1427 ata_down_xfermask_limit(ap, dev, 1);
1420 1428 ata_dev_disable(ap, dev);
1421 WARN_ON(dev->id != NULL);
1422 if (ata_dev_read_id(ap, dev, &dev->class, 1, &dev->id)) {
1423 dev->class = ATA_DEV_NONE;
1424 continue;
1425 } 1429 }
1426 1430
1427 if (ata_dev_configure(ap, dev, 1)) { 1431 if (!ata_dev_enabled(dev))
1428 ata_dev_disable(ap, dev);
1429 continue; 1432 continue;
1430 }
1431 1433
1432 found = 1; 1434 kfree(dev->id);
1435 dev->id = NULL;
1436 rc = ata_dev_read_id(ap, dev, &dev->class, 1, &dev->id);
1437 if (rc)
1438 goto fail;
1439
1440 rc = ata_dev_configure(ap, dev, 1);
1441 if (rc)
1442 goto fail;
1433 } 1443 }
1434 1444
1435 /* configure transfer mode */ 1445 /* configure transfer mode */
@@ -1438,12 +1448,18 @@ static int ata_bus_probe(struct ata_port *ap)
1438 * return error code and failing device on failure as 1448 * return error code and failing device on failure as
1439 * ata_set_mode() does. 1449 * ata_set_mode() does.
1440 */ 1450 */
1441 if (found) 1451 for (i = 0; i < ATA_MAX_DEVICES; i++)
1442 ap->ops->set_mode(ap); 1452 if (ata_dev_enabled(&ap->device[i])) {
1453 ap->ops->set_mode(ap);
1454 break;
1455 }
1443 rc = 0; 1456 rc = 0;
1444 } else { 1457 } else {
1445 while (ata_set_mode(ap, &dev)) 1458 rc = ata_set_mode(ap, &dev);
1446 ata_dev_disable(ap, dev); 1459 if (rc) {
1460 down_xfermask = 1;
1461 goto fail;
1462 }
1447 } 1463 }
1448 1464
1449 for (i = 0; i < ATA_MAX_DEVICES; i++) 1465 for (i = 0; i < ATA_MAX_DEVICES; i++)
@@ -1454,6 +1470,24 @@ static int ata_bus_probe(struct ata_port *ap)
1454 ata_port_disable(ap); 1470 ata_port_disable(ap);
1455 ap->ops->port_disable(ap); 1471 ap->ops->port_disable(ap);
1456 return -ENODEV; 1472 return -ENODEV;
1473
1474 fail:
1475 switch (rc) {
1476 case -EINVAL:
1477 case -ENODEV:
1478 tries[dev->devno] = 0;
1479 break;
1480 case -EIO:
1481 ata_down_sata_spd_limit(ap);
1482 /* fall through */
1483 default:
1484 tries[dev->devno]--;
1485 if (down_xfermask &&
1486 ata_down_xfermask_limit(ap, dev, tries[dev->devno] == 1))
1487 tries[dev->devno] = 0;
1488 }
1489
1490 goto retry;
1457} 1491}
1458 1492
1459/** 1493/**
@@ -1469,7 +1503,7 @@ static int ata_bus_probe(struct ata_port *ap)
1469 1503
1470void ata_port_probe(struct ata_port *ap) 1504void ata_port_probe(struct ata_port *ap)
1471{ 1505{
1472 ap->flags &= ~ATA_FLAG_PORT_DISABLED; 1506 ap->flags &= ~ATA_FLAG_DISABLED;
1473} 1507}
1474 1508
1475/** 1509/**
@@ -1543,7 +1577,7 @@ void __sata_phy_reset(struct ata_port *ap)
1543 else 1577 else
1544 ata_port_disable(ap); 1578 ata_port_disable(ap);
1545 1579
1546 if (ap->flags & ATA_FLAG_PORT_DISABLED) 1580 if (ap->flags & ATA_FLAG_DISABLED)
1547 return; 1581 return;
1548 1582
1549 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { 1583 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) {
@@ -1568,7 +1602,7 @@ void __sata_phy_reset(struct ata_port *ap)
1568void sata_phy_reset(struct ata_port *ap) 1602void sata_phy_reset(struct ata_port *ap)
1569{ 1603{
1570 __sata_phy_reset(ap); 1604 __sata_phy_reset(ap);
1571 if (ap->flags & ATA_FLAG_PORT_DISABLED) 1605 if (ap->flags & ATA_FLAG_DISABLED)
1572 return; 1606 return;
1573 ata_bus_reset(ap); 1607 ata_bus_reset(ap);
1574} 1608}
@@ -1607,7 +1641,121 @@ void ata_port_disable(struct ata_port *ap)
1607{ 1641{
1608 ap->device[0].class = ATA_DEV_NONE; 1642 ap->device[0].class = ATA_DEV_NONE;
1609 ap->device[1].class = ATA_DEV_NONE; 1643 ap->device[1].class = ATA_DEV_NONE;
1610 ap->flags |= ATA_FLAG_PORT_DISABLED; 1644 ap->flags |= ATA_FLAG_DISABLED;
1645}
1646
1647/**
1648 * ata_down_sata_spd_limit - adjust SATA spd limit downward
1649 * @ap: Port to adjust SATA spd limit for
1650 *
1651 * Adjust SATA spd limit of @ap downward. Note that this
1652 * function only adjusts the limit. The change must be applied
1653 * using ata_set_sata_spd().
1654 *
1655 * LOCKING:
1656 * Inherited from caller.
1657 *
1658 * RETURNS:
1659 * 0 on success, negative errno on failure
1660 */
1661int ata_down_sata_spd_limit(struct ata_port *ap)
1662{
1663 u32 spd, mask;
1664 int highbit;
1665
1666 if (ap->cbl != ATA_CBL_SATA || !ap->ops->scr_read)
1667 return -EOPNOTSUPP;
1668
1669 mask = ap->sata_spd_limit;
1670 if (mask <= 1)
1671 return -EINVAL;
1672 highbit = fls(mask) - 1;
1673 mask &= ~(1 << highbit);
1674
1675 spd = (scr_read(ap, SCR_STATUS) >> 4) & 0xf;
1676 if (spd <= 1)
1677 return -EINVAL;
1678 spd--;
1679 mask &= (1 << spd) - 1;
1680 if (!mask)
1681 return -EINVAL;
1682
1683 ap->sata_spd_limit = mask;
1684
1685 printk(KERN_WARNING "ata%u: limiting SATA link speed to %s\n",
1686 ap->id, sata_spd_string(fls(mask)));
1687
1688 return 0;
1689}
1690
1691static int __ata_set_sata_spd_needed(struct ata_port *ap, u32 *scontrol)
1692{
1693 u32 spd, limit;
1694
1695 if (ap->sata_spd_limit == UINT_MAX)
1696 limit = 0;
1697 else
1698 limit = fls(ap->sata_spd_limit);
1699
1700 spd = (*scontrol >> 4) & 0xf;
1701 *scontrol = (*scontrol & ~0xf0) | ((limit & 0xf) << 4);
1702
1703 return spd != limit;
1704}
1705
1706/**
1707 * ata_set_sata_spd_needed - is SATA spd configuration needed
1708 * @ap: Port in question
1709 *
1710 * Test whether the spd limit in SControl matches
1711 * @ap->sata_spd_limit. This function is used to determine
1712 * whether hardreset is necessary to apply SATA spd
1713 * configuration.
1714 *
1715 * LOCKING:
1716 * Inherited from caller.
1717 *
1718 * RETURNS:
1719 * 1 if SATA spd configuration is needed, 0 otherwise.
1720 */
1721int ata_set_sata_spd_needed(struct ata_port *ap)
1722{
1723 u32 scontrol;
1724
1725 if (ap->cbl != ATA_CBL_SATA || !ap->ops->scr_read)
1726 return 0;
1727
1728 scontrol = scr_read(ap, SCR_CONTROL);
1729
1730 return __ata_set_sata_spd_needed(ap, &scontrol);
1731}
1732
1733/**
1734 * ata_set_sata_spd - set SATA spd according to spd limit
1735 * @ap: Port to set SATA spd for
1736 *
1737 * Set SATA spd of @ap according to sata_spd_limit.
1738 *
1739 * LOCKING:
1740 * Inherited from caller.
1741 *
1742 * RETURNS:
1743 * 0 if spd doesn't need to be changed, 1 if spd has been
1744 * changed. -EOPNOTSUPP if SCR registers are inaccessible.
1745 */
1746static int ata_set_sata_spd(struct ata_port *ap)
1747{
1748 u32 scontrol;
1749
1750 if (ap->cbl != ATA_CBL_SATA || !ap->ops->scr_read)
1751 return -EOPNOTSUPP;
1752
1753 scontrol = scr_read(ap, SCR_CONTROL);
1754 if (!__ata_set_sata_spd_needed(ap, &scontrol))
1755 return 0;
1756
1757 scr_write(ap, SCR_CONTROL, scontrol);
1758 return 1;
1611} 1759}
1612 1760
1613/* 1761/*
@@ -1758,11 +1906,62 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
1758 return 0; 1906 return 0;
1759} 1907}
1760 1908
1909/**
1910 * ata_down_xfermask_limit - adjust dev xfer masks downward
1911 * @ap: Port associated with device @dev
1912 * @dev: Device to adjust xfer masks
1913 * @force_pio0: Force PIO0
1914 *
1915 * Adjust xfer masks of @dev downward. Note that this function
1916 * does not apply the change. Invoking ata_set_mode() afterwards
1917 * will apply the limit.
1918 *
1919 * LOCKING:
1920 * Inherited from caller.
1921 *
1922 * RETURNS:
1923 * 0 on success, negative errno on failure
1924 */
1925int ata_down_xfermask_limit(struct ata_port *ap, struct ata_device *dev,
1926 int force_pio0)
1927{
1928 unsigned long xfer_mask;
1929 int highbit;
1930
1931 xfer_mask = ata_pack_xfermask(dev->pio_mask, dev->mwdma_mask,
1932 dev->udma_mask);
1933
1934 if (!xfer_mask)
1935 goto fail;
1936 /* don't gear down to MWDMA from UDMA, go directly to PIO */
1937 if (xfer_mask & ATA_MASK_UDMA)
1938 xfer_mask &= ~ATA_MASK_MWDMA;
1939
1940 highbit = fls(xfer_mask) - 1;
1941 xfer_mask &= ~(1 << highbit);
1942 if (force_pio0)
1943 xfer_mask &= 1 << ATA_SHIFT_PIO;
1944 if (!xfer_mask)
1945 goto fail;
1946
1947 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask,
1948 &dev->udma_mask);
1949
1950 printk(KERN_WARNING "ata%u: dev %u limiting speed to %s\n",
1951 ap->id, dev->devno, ata_mode_string(xfer_mask));
1952
1953 return 0;
1954
1955 fail:
1956 return -EINVAL;
1957}
1958
1761static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev) 1959static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
1762{ 1960{
1763 unsigned int err_mask; 1961 unsigned int err_mask;
1764 int rc; 1962 int rc;
1765 1963
1964 dev->flags &= ~ATA_DFLAG_PIO;
1766 if (dev->xfer_shift == ATA_SHIFT_PIO) 1965 if (dev->xfer_shift == ATA_SHIFT_PIO)
1767 dev->flags |= ATA_DFLAG_PIO; 1966 dev->flags |= ATA_DFLAG_PIO;
1768 1967
@@ -1775,12 +1974,8 @@ static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
1775 } 1974 }
1776 1975
1777 rc = ata_dev_revalidate(ap, dev, 0); 1976 rc = ata_dev_revalidate(ap, dev, 0);
1778 if (rc) { 1977 if (rc)
1779 printk(KERN_ERR
1780 "ata%u: failed to revalidate after set xfermode\n",
1781 ap->id);
1782 return rc; 1978 return rc;
1783 }
1784 1979
1785 DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n", 1980 DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n",
1786 dev->xfer_shift, (int)dev->xfer_mode); 1981 dev->xfer_shift, (int)dev->xfer_mode);
@@ -1806,7 +2001,7 @@ static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
1806 * RETURNS: 2001 * RETURNS:
1807 * 0 on success, negative errno otherwise 2002 * 0 on success, negative errno otherwise
1808 */ 2003 */
1809static int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev) 2004int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
1810{ 2005{
1811 struct ata_device *dev; 2006 struct ata_device *dev;
1812 int i, rc = 0, used_dma = 0, found = 0; 2007 int i, rc = 0, used_dma = 0, found = 0;
@@ -2069,7 +2264,7 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
2069 * Obtains host_set lock. 2264 * Obtains host_set lock.
2070 * 2265 *
2071 * SIDE EFFECTS: 2266 * SIDE EFFECTS:
2072 * Sets ATA_FLAG_PORT_DISABLED if bus reset fails. 2267 * Sets ATA_FLAG_DISABLED if bus reset fails.
2073 */ 2268 */
2074 2269
2075void ata_bus_reset(struct ata_port *ap) 2270void ata_bus_reset(struct ata_port *ap)
@@ -2179,7 +2374,14 @@ static int sata_phy_resume(struct ata_port *ap)
2179void ata_std_probeinit(struct ata_port *ap) 2374void ata_std_probeinit(struct ata_port *ap)
2180{ 2375{
2181 if ((ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read) { 2376 if ((ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read) {
2377 u32 spd;
2378
2182 sata_phy_resume(ap); 2379 sata_phy_resume(ap);
2380
2381 spd = (scr_read(ap, SCR_CONTROL) & 0xf0) >> 4;
2382 if (spd)
2383 ap->sata_spd_limit &= (1 << spd) - 1;
2384
2183 if (sata_dev_present(ap)) 2385 if (sata_dev_present(ap))
2184 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 2386 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
2185 } 2387 }
@@ -2267,18 +2469,30 @@ int sata_std_hardreset(struct ata_port *ap, int verbose, unsigned int *class)
2267 2469
2268 DPRINTK("ENTER\n"); 2470 DPRINTK("ENTER\n");
2269 2471
2270 /* Issue phy wake/reset */ 2472 if (ata_set_sata_spd_needed(ap)) {
2473 /* SATA spec says nothing about how to reconfigure
2474 * spd. To be on the safe side, turn off phy during
2475 * reconfiguration. This works for at least ICH7 AHCI
2476 * and Sil3124.
2477 */
2478 scontrol = scr_read(ap, SCR_CONTROL);
2479 scontrol = (scontrol & 0x0f0) | 0x302;
2480 scr_write_flush(ap, SCR_CONTROL, scontrol);
2481
2482 ata_set_sata_spd(ap);
2483 }
2484
2485 /* issue phy wake/reset */
2271 scontrol = scr_read(ap, SCR_CONTROL); 2486 scontrol = scr_read(ap, SCR_CONTROL);
2272 scontrol = (scontrol & 0x0f0) | 0x301; 2487 scontrol = (scontrol & 0x0f0) | 0x301;
2273 scr_write_flush(ap, SCR_CONTROL, scontrol); 2488 scr_write_flush(ap, SCR_CONTROL, scontrol);
2274 2489
2275 /* 2490 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1
2276 * Couldn't find anything in SATA I/II specs, but AHCI-1.1
2277 * 10.4.2 says at least 1 ms. 2491 * 10.4.2 says at least 1 ms.
2278 */ 2492 */
2279 msleep(1); 2493 msleep(1);
2280 2494
2281 /* Bring phy back */ 2495 /* bring phy back */
2282 sata_phy_resume(ap); 2496 sata_phy_resume(ap);
2283 2497
2284 /* TODO: phy layer with polling, timeouts, etc. */ 2498 /* TODO: phy layer with polling, timeouts, etc. */
@@ -2385,9 +2599,9 @@ int ata_std_probe_reset(struct ata_port *ap, unsigned int *classes)
2385 ata_std_postreset, classes); 2599 ata_std_postreset, classes);
2386} 2600}
2387 2601
2388static int ata_do_reset(struct ata_port *ap, 2602int ata_do_reset(struct ata_port *ap,
2389 ata_reset_fn_t reset, ata_postreset_fn_t postreset, 2603 ata_reset_fn_t reset, ata_postreset_fn_t postreset,
2390 int verbose, unsigned int *classes) 2604 int verbose, unsigned int *classes)
2391{ 2605{
2392 int i, rc; 2606 int i, rc;
2393 2607
@@ -2458,21 +2672,42 @@ int ata_drive_probe_reset(struct ata_port *ap, ata_probeinit_fn_t probeinit,
2458 if (probeinit) 2672 if (probeinit)
2459 probeinit(ap); 2673 probeinit(ap);
2460 2674
2461 if (softreset) { 2675 if (softreset && !ata_set_sata_spd_needed(ap)) {
2462 rc = ata_do_reset(ap, softreset, postreset, 0, classes); 2676 rc = ata_do_reset(ap, softreset, postreset, 0, classes);
2463 if (rc == 0 && classes[0] != ATA_DEV_UNKNOWN) 2677 if (rc == 0 && classes[0] != ATA_DEV_UNKNOWN)
2464 goto done; 2678 goto done;
2679 printk(KERN_INFO "ata%u: softreset failed, will try "
2680 "hardreset in 5 secs\n", ap->id);
2681 ssleep(5);
2465 } 2682 }
2466 2683
2467 if (!hardreset) 2684 if (!hardreset)
2468 goto done; 2685 goto done;
2469 2686
2470 rc = ata_do_reset(ap, hardreset, postreset, 0, classes); 2687 while (1) {
2471 if (rc || classes[0] != ATA_DEV_UNKNOWN) 2688 rc = ata_do_reset(ap, hardreset, postreset, 0, classes);
2472 goto done; 2689 if (rc == 0) {
2690 if (classes[0] != ATA_DEV_UNKNOWN)
2691 goto done;
2692 break;
2693 }
2694
2695 if (ata_down_sata_spd_limit(ap))
2696 goto done;
2697
2698 printk(KERN_INFO "ata%u: hardreset failed, will retry "
2699 "in 5 secs\n", ap->id);
2700 ssleep(5);
2701 }
2702
2703 if (softreset) {
2704 printk(KERN_INFO "ata%u: hardreset succeeded without "
2705 "classification, will retry softreset in 5 secs\n",
2706 ap->id);
2707 ssleep(5);
2473 2708
2474 if (softreset)
2475 rc = ata_do_reset(ap, softreset, postreset, 0, classes); 2709 rc = ata_do_reset(ap, softreset, postreset, 0, classes);
2710 }
2476 2711
2477 done: 2712 done:
2478 if (rc == 0 && classes[0] == ATA_DEV_UNKNOWN) 2713 if (rc == 0 && classes[0] == ATA_DEV_UNKNOWN)
@@ -2560,15 +2795,14 @@ static int ata_dev_same_device(struct ata_port *ap, struct ata_device *dev,
2560int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev, 2795int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev,
2561 int post_reset) 2796 int post_reset)
2562{ 2797{
2563 unsigned int class; 2798 unsigned int class = dev->class;
2564 u16 *id; 2799 u16 *id = NULL;
2565 int rc; 2800 int rc;
2566 2801
2567 if (!ata_dev_enabled(dev)) 2802 if (!ata_dev_enabled(dev)) {
2568 return -ENODEV; 2803 rc = -ENODEV;
2569 2804 goto fail;
2570 class = dev->class; 2805 }
2571 id = NULL;
2572 2806
2573 /* allocate & read ID data */ 2807 /* allocate & read ID data */
2574 rc = ata_dev_read_id(ap, dev, &class, post_reset, &id); 2808 rc = ata_dev_read_id(ap, dev, &class, post_reset, &id);
@@ -2585,7 +2819,9 @@ int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev,
2585 dev->id = id; 2819 dev->id = id;
2586 2820
2587 /* configure device according to the new ID */ 2821 /* configure device according to the new ID */
2588 return ata_dev_configure(ap, dev, 0); 2822 rc = ata_dev_configure(ap, dev, 0);
2823 if (rc == 0)
2824 return 0;
2589 2825
2590 fail: 2826 fail:
2591 printk(KERN_ERR "ata%u: dev %u revalidation failed (errno=%d)\n", 2827 printk(KERN_ERR "ata%u: dev %u revalidation failed (errno=%d)\n",
@@ -2687,23 +2923,34 @@ static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev)
2687 unsigned long xfer_mask; 2923 unsigned long xfer_mask;
2688 int i; 2924 int i;
2689 2925
2690 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, 2926 xfer_mask = ata_pack_xfermask(ap->pio_mask,
2691 ap->udma_mask); 2927 ap->mwdma_mask, ap->udma_mask);
2928
2929 /* Apply cable rule here. Don't apply it early because when
2930 * we handle hot plug the cable type can itself change.
2931 */
2932 if (ap->cbl == ATA_CBL_PATA40)
2933 xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
2692 2934
2693 /* FIXME: Use port-wide xfermask for now */ 2935 /* FIXME: Use port-wide xfermask for now */
2694 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2936 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2695 struct ata_device *d = &ap->device[i]; 2937 struct ata_device *d = &ap->device[i];
2696 if (!ata_dev_enabled(d)) 2938
2939 if (ata_dev_absent(d))
2697 continue; 2940 continue;
2698 xfer_mask &= ata_pack_xfermask(d->pio_mask, d->mwdma_mask, 2941
2699 d->udma_mask); 2942 if (ata_dev_disabled(d)) {
2943 /* to avoid violating device selection timing */
2944 xfer_mask &= ata_pack_xfermask(d->pio_mask,
2945 UINT_MAX, UINT_MAX);
2946 continue;
2947 }
2948
2949 xfer_mask &= ata_pack_xfermask(d->pio_mask,
2950 d->mwdma_mask, d->udma_mask);
2700 xfer_mask &= ata_id_xfermask(d->id); 2951 xfer_mask &= ata_id_xfermask(d->id);
2701 if (ata_dma_blacklisted(d)) 2952 if (ata_dma_blacklisted(d))
2702 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 2953 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
2703 /* Apply cable rule here. Don't apply it early because when
2704 we handle hot plug the cable type can itself change */
2705 if (ap->cbl == ATA_CBL_PATA40)
2706 xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
2707 } 2954 }
2708 2955
2709 if (ata_dma_blacklisted(dev)) 2956 if (ata_dma_blacklisted(dev))
@@ -2714,11 +2961,12 @@ static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev)
2714 if (hs->simplex_claimed) 2961 if (hs->simplex_claimed)
2715 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 2962 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
2716 } 2963 }
2964
2717 if (ap->ops->mode_filter) 2965 if (ap->ops->mode_filter)
2718 xfer_mask = ap->ops->mode_filter(ap, dev, xfer_mask); 2966 xfer_mask = ap->ops->mode_filter(ap, dev, xfer_mask);
2719 2967
2720 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, 2968 ata_unpack_xfermask(xfer_mask, &dev->pio_mask,
2721 &dev->udma_mask); 2969 &dev->mwdma_mask, &dev->udma_mask);
2722} 2970}
2723 2971
2724/** 2972/**
@@ -2752,7 +3000,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_port *ap,
2752 tf.protocol = ATA_PROT_NODATA; 3000 tf.protocol = ATA_PROT_NODATA;
2753 tf.nsect = dev->xfer_mode; 3001 tf.nsect = dev->xfer_mode;
2754 3002
2755 err_mask = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0); 3003 err_mask = ata_exec_internal(ap, dev, &tf, NULL, DMA_NONE, NULL, 0);
2756 3004
2757 DPRINTK("EXIT, err_mask=%x\n", err_mask); 3005 DPRINTK("EXIT, err_mask=%x\n", err_mask);
2758 return err_mask; 3006 return err_mask;
@@ -2792,7 +3040,7 @@ static unsigned int ata_dev_init_params(struct ata_port *ap,
2792 tf.nsect = sectors; 3040 tf.nsect = sectors;
2793 tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ 3041 tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */
2794 3042
2795 err_mask = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0); 3043 err_mask = ata_exec_internal(ap, dev, &tf, NULL, DMA_NONE, NULL, 0);
2796 3044
2797 DPRINTK("EXIT, err_mask=%x\n", err_mask); 3045 DPRINTK("EXIT, err_mask=%x\n", err_mask);
2798 return err_mask; 3046 return err_mask;
@@ -3838,8 +4086,8 @@ fsm_start:
3838 4086
3839static void ata_pio_task(void *_data) 4087static void ata_pio_task(void *_data)
3840{ 4088{
3841 struct ata_port *ap = _data; 4089 struct ata_queued_cmd *qc = _data;
3842 struct ata_queued_cmd *qc; 4090 struct ata_port *ap = qc->ap;
3843 u8 status; 4091 u8 status;
3844 int poll_next; 4092 int poll_next;
3845 4093
@@ -4392,7 +4640,7 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
4392 4640
4393 ap = host_set->ports[i]; 4641 ap = host_set->ports[i];
4394 if (ap && 4642 if (ap &&
4395 !(ap->flags & ATA_FLAG_PORT_DISABLED)) { 4643 !(ap->flags & ATA_FLAG_DISABLED)) {
4396 struct ata_queued_cmd *qc; 4644 struct ata_queued_cmd *qc;
4397 4645
4398 qc = ata_qc_from_tag(ap, ap->active_tag); 4646 qc = ata_qc_from_tag(ap, ap->active_tag);
@@ -4424,7 +4672,7 @@ static int ata_do_simple_cmd(struct ata_port *ap, struct ata_device *dev,
4424 tf.flags |= ATA_TFLAG_DEVICE; 4672 tf.flags |= ATA_TFLAG_DEVICE;
4425 tf.protocol = ATA_PROT_NODATA; 4673 tf.protocol = ATA_PROT_NODATA;
4426 4674
4427 err = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0); 4675 err = ata_exec_internal(ap, dev, &tf, NULL, DMA_NONE, NULL, 0);
4428 if (err) 4676 if (err)
4429 printk(KERN_ERR "%s: ata command failed: %d\n", 4677 printk(KERN_ERR "%s: ata command failed: %d\n",
4430 __FUNCTION__, err); 4678 __FUNCTION__, err);
@@ -4613,7 +4861,7 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
4613 host->unique_id = ata_unique_id++; 4861 host->unique_id = ata_unique_id++;
4614 host->max_cmd_len = 12; 4862 host->max_cmd_len = 12;
4615 4863
4616 ap->flags = ATA_FLAG_PORT_DISABLED; 4864 ap->flags = ATA_FLAG_DISABLED;
4617 ap->id = host->unique_id; 4865 ap->id = host->unique_id;
4618 ap->host = host; 4866 ap->host = host;
4619 ap->ctl = ATA_DEVCTL_OBS; 4867 ap->ctl = ATA_DEVCTL_OBS;
@@ -4628,6 +4876,7 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
4628 ap->flags |= ent->host_flags; 4876 ap->flags |= ent->host_flags;
4629 ap->ops = ent->port_ops; 4877 ap->ops = ent->port_ops;
4630 ap->cbl = ATA_CBL_NONE; 4878 ap->cbl = ATA_CBL_NONE;
4879 ap->sata_spd_limit = UINT_MAX;
4631 ap->active_tag = ATA_TAG_POISON; 4880 ap->active_tag = ATA_TAG_POISON;
4632 ap->last_ctl = 0xFF; 4881 ap->last_ctl = 0xFF;
4633 4882
@@ -5083,7 +5332,6 @@ EXPORT_SYMBOL_GPL(ata_sg_init);
5083EXPORT_SYMBOL_GPL(ata_sg_init_one); 5332EXPORT_SYMBOL_GPL(ata_sg_init_one);
5084EXPORT_SYMBOL_GPL(__ata_qc_complete); 5333EXPORT_SYMBOL_GPL(__ata_qc_complete);
5085EXPORT_SYMBOL_GPL(ata_qc_issue_prot); 5334EXPORT_SYMBOL_GPL(ata_qc_issue_prot);
5086EXPORT_SYMBOL_GPL(ata_eng_timeout);
5087EXPORT_SYMBOL_GPL(ata_tf_load); 5335EXPORT_SYMBOL_GPL(ata_tf_load);
5088EXPORT_SYMBOL_GPL(ata_tf_read); 5336EXPORT_SYMBOL_GPL(ata_tf_read);
5089EXPORT_SYMBOL_GPL(ata_noop_dev_select); 5337EXPORT_SYMBOL_GPL(ata_noop_dev_select);
@@ -5123,15 +5371,12 @@ EXPORT_SYMBOL_GPL(ata_busy_sleep);
5123EXPORT_SYMBOL_GPL(ata_port_queue_task); 5371EXPORT_SYMBOL_GPL(ata_port_queue_task);
5124EXPORT_SYMBOL_GPL(ata_scsi_ioctl); 5372EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
5125EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); 5373EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
5126EXPORT_SYMBOL_GPL(ata_scsi_error);
5127EXPORT_SYMBOL_GPL(ata_scsi_slave_config); 5374EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
5128EXPORT_SYMBOL_GPL(ata_scsi_release); 5375EXPORT_SYMBOL_GPL(ata_scsi_release);
5129EXPORT_SYMBOL_GPL(ata_host_intr); 5376EXPORT_SYMBOL_GPL(ata_host_intr);
5130EXPORT_SYMBOL_GPL(ata_id_string); 5377EXPORT_SYMBOL_GPL(ata_id_string);
5131EXPORT_SYMBOL_GPL(ata_id_c_string); 5378EXPORT_SYMBOL_GPL(ata_id_c_string);
5132EXPORT_SYMBOL_GPL(ata_scsi_simulate); 5379EXPORT_SYMBOL_GPL(ata_scsi_simulate);
5133EXPORT_SYMBOL_GPL(ata_eh_qc_complete);
5134EXPORT_SYMBOL_GPL(ata_eh_qc_retry);
5135 5380
5136EXPORT_SYMBOL_GPL(ata_pio_need_iordy); 5381EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
5137EXPORT_SYMBOL_GPL(ata_timing_compute); 5382EXPORT_SYMBOL_GPL(ata_timing_compute);
@@ -5153,3 +5398,8 @@ EXPORT_SYMBOL_GPL(ata_device_suspend);
5153EXPORT_SYMBOL_GPL(ata_device_resume); 5398EXPORT_SYMBOL_GPL(ata_device_resume);
5154EXPORT_SYMBOL_GPL(ata_scsi_device_suspend); 5399EXPORT_SYMBOL_GPL(ata_scsi_device_suspend);
5155EXPORT_SYMBOL_GPL(ata_scsi_device_resume); 5400EXPORT_SYMBOL_GPL(ata_scsi_device_resume);
5401
5402EXPORT_SYMBOL_GPL(ata_scsi_error);
5403EXPORT_SYMBOL_GPL(ata_eng_timeout);
5404EXPORT_SYMBOL_GPL(ata_eh_qc_complete);
5405EXPORT_SYMBOL_GPL(ata_eh_qc_retry);