diff options
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r-- | drivers/scsi/libata-core.c | 798 |
1 files changed, 478 insertions, 320 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index bd147207f25..3387fe35c54 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); |
68 | static void ata_set_mode(struct ata_port *ap); | ||
69 | static unsigned int ata_dev_set_xfermode(struct ata_port *ap, | 68 | static unsigned int ata_dev_set_xfermode(struct ata_port *ap, |
70 | struct ata_device *dev); | 69 | struct ata_device *dev); |
71 | static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev); | 70 | static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev); |
@@ -77,6 +76,10 @@ int atapi_enabled = 1; | |||
77 | module_param(atapi_enabled, int, 0444); | 76 | module_param(atapi_enabled, int, 0444); |
78 | MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)"); | 77 | MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)"); |
79 | 78 | ||
79 | int atapi_dmadir = 0; | ||
80 | module_param(atapi_dmadir, int, 0444); | ||
81 | MODULE_PARM_DESC(atapi_dmadir, "Enable ATAPI DMADIR bridge support (0=off, 1=on)"); | ||
82 | |||
80 | int libata_fua = 0; | 83 | int libata_fua = 0; |
81 | module_param_named(fua, libata_fua, int, 0444); | 84 | module_param_named(fua, libata_fua, int, 0444); |
82 | MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)"); | 85 | MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)"); |
@@ -397,9 +400,21 @@ static const char *ata_mode_string(unsigned int xfer_mask) | |||
397 | return "<n/a>"; | 400 | return "<n/a>"; |
398 | } | 401 | } |
399 | 402 | ||
400 | static void ata_dev_disable(struct ata_port *ap, struct ata_device *dev) | 403 | static const char *sata_spd_string(unsigned int spd) |
404 | { | ||
405 | static const char * const spd_str[] = { | ||
406 | "1.5 Gbps", | ||
407 | "3.0 Gbps", | ||
408 | }; | ||
409 | |||
410 | if (spd == 0 || (spd - 1) >= ARRAY_SIZE(spd_str)) | ||
411 | return "<unknown>"; | ||
412 | return spd_str[spd - 1]; | ||
413 | } | ||
414 | |||
415 | void ata_dev_disable(struct ata_port *ap, struct ata_device *dev) | ||
401 | { | 416 | { |
402 | if (ata_dev_present(dev)) { | 417 | if (ata_dev_enabled(dev)) { |
403 | printk(KERN_WARNING "ata%u: dev %u disabled\n", | 418 | printk(KERN_WARNING "ata%u: dev %u disabled\n", |
404 | ap->id, dev->devno); | 419 | ap->id, dev->devno); |
405 | dev->class++; | 420 | dev->class++; |
@@ -949,6 +964,7 @@ void ata_qc_complete_internal(struct ata_queued_cmd *qc) | |||
949 | * @ap: Port to which the command is sent | 964 | * @ap: Port to which the command is sent |
950 | * @dev: Device to which the command is sent | 965 | * @dev: Device to which the command is sent |
951 | * @tf: Taskfile registers for the command and the result | 966 | * @tf: Taskfile registers for the command and the result |
967 | * @cdb: CDB for packet command | ||
952 | * @dma_dir: Data tranfer direction of the command | 968 | * @dma_dir: Data tranfer direction of the command |
953 | * @buf: Data buffer of the command | 969 | * @buf: Data buffer of the command |
954 | * @buflen: Length of data buffer | 970 | * @buflen: Length of data buffer |
@@ -963,10 +979,9 @@ void ata_qc_complete_internal(struct ata_queued_cmd *qc) | |||
963 | * None. Should be called with kernel context, might sleep. | 979 | * None. Should be called with kernel context, might sleep. |
964 | */ | 980 | */ |
965 | 981 | ||
966 | static unsigned | 982 | unsigned ata_exec_internal(struct ata_port *ap, struct ata_device *dev, |
967 | ata_exec_internal(struct ata_port *ap, struct ata_device *dev, | 983 | struct ata_taskfile *tf, const u8 *cdb, |
968 | struct ata_taskfile *tf, | 984 | int dma_dir, void *buf, unsigned int buflen) |
969 | int dma_dir, void *buf, unsigned int buflen) | ||
970 | { | 985 | { |
971 | u8 command = tf->command; | 986 | u8 command = tf->command; |
972 | struct ata_queued_cmd *qc; | 987 | struct ata_queued_cmd *qc; |
@@ -980,6 +995,8 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev, | |||
980 | BUG_ON(qc == NULL); | 995 | BUG_ON(qc == NULL); |
981 | 996 | ||
982 | qc->tf = *tf; | 997 | qc->tf = *tf; |
998 | if (cdb) | ||
999 | memcpy(qc->cdb, cdb, ATAPI_CDB_LEN); | ||
983 | qc->dma_dir = dma_dir; | 1000 | qc->dma_dir = dma_dir; |
984 | if (dma_dir != DMA_NONE) { | 1001 | if (dma_dir != DMA_NONE) { |
985 | ata_sg_init_one(qc, buf, buflen); | 1002 | ata_sg_init_one(qc, buf, buflen); |
@@ -1030,7 +1047,7 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev, | |||
1030 | * | 1047 | * |
1031 | * Kill the following code as soon as those drivers are fixed. | 1048 | * Kill the following code as soon as those drivers are fixed. |
1032 | */ | 1049 | */ |
1033 | if (ap->flags & ATA_FLAG_PORT_DISABLED) { | 1050 | if (ap->flags & ATA_FLAG_DISABLED) { |
1034 | err_mask |= AC_ERR_SYSTEM; | 1051 | err_mask |= AC_ERR_SYSTEM; |
1035 | ata_port_probe(ap); | 1052 | ata_port_probe(ap); |
1036 | } | 1053 | } |
@@ -1129,7 +1146,7 @@ static int ata_dev_read_id(struct ata_port *ap, struct ata_device *dev, | |||
1129 | 1146 | ||
1130 | tf.protocol = ATA_PROT_PIO; | 1147 | tf.protocol = ATA_PROT_PIO; |
1131 | 1148 | ||
1132 | err_mask = ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE, | 1149 | err_mask = ata_exec_internal(ap, dev, &tf, NULL, DMA_FROM_DEVICE, |
1133 | id, sizeof(id[0]) * ATA_ID_WORDS); | 1150 | id, sizeof(id[0]) * ATA_ID_WORDS); |
1134 | if (err_mask) { | 1151 | if (err_mask) { |
1135 | rc = -EIO; | 1152 | rc = -EIO; |
@@ -1210,7 +1227,7 @@ static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev, | |||
1210 | unsigned int xfer_mask; | 1227 | unsigned int xfer_mask; |
1211 | int i, rc; | 1228 | int i, rc; |
1212 | 1229 | ||
1213 | if (!ata_dev_present(dev)) { | 1230 | if (!ata_dev_enabled(dev)) { |
1214 | DPRINTK("ENTER/EXIT (host %u, dev %u) -- nodev\n", | 1231 | DPRINTK("ENTER/EXIT (host %u, dev %u) -- nodev\n", |
1215 | ap->id, dev->devno); | 1232 | ap->id, dev->devno); |
1216 | return 0; | 1233 | return 0; |
@@ -1226,7 +1243,7 @@ static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev, | |||
1226 | id[84], id[85], id[86], id[87], id[88]); | 1243 | id[84], id[85], id[86], id[87], id[88]); |
1227 | 1244 | ||
1228 | /* initialize to-be-configured parameters */ | 1245 | /* initialize to-be-configured parameters */ |
1229 | dev->flags = 0; | 1246 | dev->flags &= ~ATA_DFLAG_CFG_MASK; |
1230 | dev->max_sectors = 0; | 1247 | dev->max_sectors = 0; |
1231 | dev->cdb_len = 0; | 1248 | dev->cdb_len = 0; |
1232 | dev->n_sectors = 0; | 1249 | dev->n_sectors = 0; |
@@ -1349,16 +1366,24 @@ err_out_nosup: | |||
1349 | * PCI/etc. bus probe sem. | 1366 | * PCI/etc. bus probe sem. |
1350 | * | 1367 | * |
1351 | * RETURNS: | 1368 | * RETURNS: |
1352 | * Zero on success, non-zero on error. | 1369 | * Zero on success, negative errno otherwise. |
1353 | */ | 1370 | */ |
1354 | 1371 | ||
1355 | static int ata_bus_probe(struct ata_port *ap) | 1372 | static int ata_bus_probe(struct ata_port *ap) |
1356 | { | 1373 | { |
1357 | unsigned int classes[ATA_MAX_DEVICES]; | 1374 | unsigned int classes[ATA_MAX_DEVICES]; |
1358 | unsigned int i, rc, found = 0; | 1375 | int tries[ATA_MAX_DEVICES]; |
1376 | int i, rc, down_xfermask; | ||
1377 | struct ata_device *dev; | ||
1359 | 1378 | ||
1360 | ata_port_probe(ap); | 1379 | ata_port_probe(ap); |
1361 | 1380 | ||
1381 | for (i = 0; i < ATA_MAX_DEVICES; i++) | ||
1382 | tries[i] = ATA_PROBE_MAX_TRIES; | ||
1383 | |||
1384 | retry: | ||
1385 | down_xfermask = 0; | ||
1386 | |||
1362 | /* reset and determine device classes */ | 1387 | /* reset and determine device classes */ |
1363 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 1388 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
1364 | classes[i] = ATA_DEV_UNKNOWN; | 1389 | classes[i] = ATA_DEV_UNKNOWN; |
@@ -1372,7 +1397,7 @@ static int ata_bus_probe(struct ata_port *ap) | |||
1372 | } else { | 1397 | } else { |
1373 | ap->ops->phy_reset(ap); | 1398 | ap->ops->phy_reset(ap); |
1374 | 1399 | ||
1375 | if (!(ap->flags & ATA_FLAG_PORT_DISABLED)) | 1400 | if (!(ap->flags & ATA_FLAG_DISABLED)) |
1376 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 1401 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
1377 | classes[i] = ap->device[i].class; | 1402 | classes[i] = ap->device[i].class; |
1378 | 1403 | ||
@@ -1385,43 +1410,74 @@ static int ata_bus_probe(struct ata_port *ap) | |||
1385 | 1410 | ||
1386 | /* read IDENTIFY page and configure devices */ | 1411 | /* read IDENTIFY page and configure devices */ |
1387 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 1412 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
1388 | struct ata_device *dev = &ap->device[i]; | 1413 | dev = &ap->device[i]; |
1389 | |||
1390 | dev->class = classes[i]; | 1414 | dev->class = classes[i]; |
1391 | 1415 | ||
1392 | if (!ata_dev_present(dev)) | 1416 | if (!tries[i]) { |
1393 | continue; | 1417 | ata_down_xfermask_limit(ap, dev, 1); |
1394 | 1418 | ata_dev_disable(ap, dev); | |
1395 | WARN_ON(dev->id != NULL); | ||
1396 | if (ata_dev_read_id(ap, dev, &dev->class, 1, &dev->id)) { | ||
1397 | dev->class = ATA_DEV_NONE; | ||
1398 | continue; | ||
1399 | } | 1419 | } |
1400 | 1420 | ||
1401 | if (ata_dev_configure(ap, dev, 1)) { | 1421 | if (!ata_dev_enabled(dev)) |
1402 | ata_dev_disable(ap, dev); | ||
1403 | continue; | 1422 | continue; |
1404 | } | ||
1405 | 1423 | ||
1406 | found = 1; | 1424 | kfree(dev->id); |
1425 | dev->id = NULL; | ||
1426 | rc = ata_dev_read_id(ap, dev, &dev->class, 1, &dev->id); | ||
1427 | if (rc) | ||
1428 | goto fail; | ||
1429 | |||
1430 | rc = ata_dev_configure(ap, dev, 1); | ||
1431 | if (rc) | ||
1432 | goto fail; | ||
1407 | } | 1433 | } |
1408 | 1434 | ||
1409 | if (!found) | 1435 | /* configure transfer mode */ |
1410 | goto err_out_disable; | 1436 | if (ap->ops->set_mode) { |
1437 | /* FIXME: make ->set_mode handle no device case and | ||
1438 | * return error code and failing device on failure as | ||
1439 | * ata_set_mode() does. | ||
1440 | */ | ||
1441 | for (i = 0; i < ATA_MAX_DEVICES; i++) | ||
1442 | if (ata_dev_enabled(&ap->device[i])) { | ||
1443 | ap->ops->set_mode(ap); | ||
1444 | break; | ||
1445 | } | ||
1446 | rc = 0; | ||
1447 | } else { | ||
1448 | rc = ata_set_mode(ap, &dev); | ||
1449 | if (rc) { | ||
1450 | down_xfermask = 1; | ||
1451 | goto fail; | ||
1452 | } | ||
1453 | } | ||
1411 | 1454 | ||
1412 | if (ap->ops->set_mode) | 1455 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
1413 | ap->ops->set_mode(ap); | 1456 | if (ata_dev_enabled(&ap->device[i])) |
1414 | else | 1457 | return 0; |
1415 | ata_set_mode(ap); | ||
1416 | 1458 | ||
1417 | if (ap->flags & ATA_FLAG_PORT_DISABLED) | 1459 | /* no device present, disable port */ |
1418 | goto err_out_disable; | 1460 | ata_port_disable(ap); |
1461 | ap->ops->port_disable(ap); | ||
1462 | return -ENODEV; | ||
1419 | 1463 | ||
1420 | return 0; | 1464 | fail: |
1465 | switch (rc) { | ||
1466 | case -EINVAL: | ||
1467 | case -ENODEV: | ||
1468 | tries[dev->devno] = 0; | ||
1469 | break; | ||
1470 | case -EIO: | ||
1471 | ata_down_sata_spd_limit(ap); | ||
1472 | /* fall through */ | ||
1473 | default: | ||
1474 | tries[dev->devno]--; | ||
1475 | if (down_xfermask && | ||
1476 | ata_down_xfermask_limit(ap, dev, tries[dev->devno] == 1)) | ||
1477 | tries[dev->devno] = 0; | ||
1478 | } | ||
1421 | 1479 | ||
1422 | err_out_disable: | 1480 | goto retry; |
1423 | ap->ops->port_disable(ap); | ||
1424 | return -1; | ||
1425 | } | 1481 | } |
1426 | 1482 | ||
1427 | /** | 1483 | /** |
@@ -1437,7 +1493,7 @@ err_out_disable: | |||
1437 | 1493 | ||
1438 | void ata_port_probe(struct ata_port *ap) | 1494 | void ata_port_probe(struct ata_port *ap) |
1439 | { | 1495 | { |
1440 | ap->flags &= ~ATA_FLAG_PORT_DISABLED; | 1496 | ap->flags &= ~ATA_FLAG_DISABLED; |
1441 | } | 1497 | } |
1442 | 1498 | ||
1443 | /** | 1499 | /** |
@@ -1451,27 +1507,23 @@ void ata_port_probe(struct ata_port *ap) | |||
1451 | */ | 1507 | */ |
1452 | static void sata_print_link_status(struct ata_port *ap) | 1508 | static void sata_print_link_status(struct ata_port *ap) |
1453 | { | 1509 | { |
1454 | u32 sstatus, tmp; | 1510 | u32 sstatus, scontrol, tmp; |
1455 | const char *speed; | ||
1456 | 1511 | ||
1457 | if (!ap->ops->scr_read) | 1512 | if (!ap->ops->scr_read) |
1458 | return; | 1513 | return; |
1459 | 1514 | ||
1460 | sstatus = scr_read(ap, SCR_STATUS); | 1515 | sstatus = scr_read(ap, SCR_STATUS); |
1516 | scontrol = scr_read(ap, SCR_CONTROL); | ||
1461 | 1517 | ||
1462 | if (sata_dev_present(ap)) { | 1518 | if (sata_dev_present(ap)) { |
1463 | tmp = (sstatus >> 4) & 0xf; | 1519 | tmp = (sstatus >> 4) & 0xf; |
1464 | if (tmp & (1 << 0)) | 1520 | printk(KERN_INFO |
1465 | speed = "1.5"; | 1521 | "ata%u: SATA link up %s (SStatus %X SControl %X)\n", |
1466 | else if (tmp & (1 << 1)) | 1522 | ap->id, sata_spd_string(tmp), sstatus, scontrol); |
1467 | speed = "3.0"; | ||
1468 | else | ||
1469 | speed = "<unknown>"; | ||
1470 | printk(KERN_INFO "ata%u: SATA link up %s Gbps (SStatus %X)\n", | ||
1471 | ap->id, speed, sstatus); | ||
1472 | } else { | 1523 | } else { |
1473 | printk(KERN_INFO "ata%u: SATA link down (SStatus %X)\n", | 1524 | printk(KERN_INFO |
1474 | ap->id, sstatus); | 1525 | "ata%u: SATA link down (SStatus %X SControl %X)\n", |
1526 | ap->id, sstatus, scontrol); | ||
1475 | } | 1527 | } |
1476 | } | 1528 | } |
1477 | 1529 | ||
@@ -1518,7 +1570,7 @@ void __sata_phy_reset(struct ata_port *ap) | |||
1518 | else | 1570 | else |
1519 | ata_port_disable(ap); | 1571 | ata_port_disable(ap); |
1520 | 1572 | ||
1521 | if (ap->flags & ATA_FLAG_PORT_DISABLED) | 1573 | if (ap->flags & ATA_FLAG_DISABLED) |
1522 | return; | 1574 | return; |
1523 | 1575 | ||
1524 | if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { | 1576 | if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { |
@@ -1543,7 +1595,7 @@ void __sata_phy_reset(struct ata_port *ap) | |||
1543 | void sata_phy_reset(struct ata_port *ap) | 1595 | void sata_phy_reset(struct ata_port *ap) |
1544 | { | 1596 | { |
1545 | __sata_phy_reset(ap); | 1597 | __sata_phy_reset(ap); |
1546 | if (ap->flags & ATA_FLAG_PORT_DISABLED) | 1598 | if (ap->flags & ATA_FLAG_DISABLED) |
1547 | return; | 1599 | return; |
1548 | ata_bus_reset(ap); | 1600 | ata_bus_reset(ap); |
1549 | } | 1601 | } |
@@ -1560,7 +1612,7 @@ void sata_phy_reset(struct ata_port *ap) | |||
1560 | struct ata_device *ata_dev_pair(struct ata_port *ap, struct ata_device *adev) | 1612 | struct ata_device *ata_dev_pair(struct ata_port *ap, struct ata_device *adev) |
1561 | { | 1613 | { |
1562 | struct ata_device *pair = &ap->device[1 - adev->devno]; | 1614 | struct ata_device *pair = &ap->device[1 - adev->devno]; |
1563 | if (!ata_dev_present(pair)) | 1615 | if (!ata_dev_enabled(pair)) |
1564 | return NULL; | 1616 | return NULL; |
1565 | return pair; | 1617 | return pair; |
1566 | } | 1618 | } |
@@ -1582,7 +1634,121 @@ void ata_port_disable(struct ata_port *ap) | |||
1582 | { | 1634 | { |
1583 | ap->device[0].class = ATA_DEV_NONE; | 1635 | ap->device[0].class = ATA_DEV_NONE; |
1584 | ap->device[1].class = ATA_DEV_NONE; | 1636 | ap->device[1].class = ATA_DEV_NONE; |
1585 | ap->flags |= ATA_FLAG_PORT_DISABLED; | 1637 | ap->flags |= ATA_FLAG_DISABLED; |
1638 | } | ||
1639 | |||
1640 | /** | ||
1641 | * ata_down_sata_spd_limit - adjust SATA spd limit downward | ||
1642 | * @ap: Port to adjust SATA spd limit for | ||
1643 | * | ||
1644 | * Adjust SATA spd limit of @ap downward. Note that this | ||
1645 | * function only adjusts the limit. The change must be applied | ||
1646 | * using ata_set_sata_spd(). | ||
1647 | * | ||
1648 | * LOCKING: | ||
1649 | * Inherited from caller. | ||
1650 | * | ||
1651 | * RETURNS: | ||
1652 | * 0 on success, negative errno on failure | ||
1653 | */ | ||
1654 | int ata_down_sata_spd_limit(struct ata_port *ap) | ||
1655 | { | ||
1656 | u32 spd, mask; | ||
1657 | int highbit; | ||
1658 | |||
1659 | if (ap->cbl != ATA_CBL_SATA || !ap->ops->scr_read) | ||
1660 | return -EOPNOTSUPP; | ||
1661 | |||
1662 | mask = ap->sata_spd_limit; | ||
1663 | if (mask <= 1) | ||
1664 | return -EINVAL; | ||
1665 | highbit = fls(mask) - 1; | ||
1666 | mask &= ~(1 << highbit); | ||
1667 | |||
1668 | spd = (scr_read(ap, SCR_STATUS) >> 4) & 0xf; | ||
1669 | if (spd <= 1) | ||
1670 | return -EINVAL; | ||
1671 | spd--; | ||
1672 | mask &= (1 << spd) - 1; | ||
1673 | if (!mask) | ||
1674 | return -EINVAL; | ||
1675 | |||
1676 | ap->sata_spd_limit = mask; | ||
1677 | |||
1678 | printk(KERN_WARNING "ata%u: limiting SATA link speed to %s\n", | ||
1679 | ap->id, sata_spd_string(fls(mask))); | ||
1680 | |||
1681 | return 0; | ||
1682 | } | ||
1683 | |||
1684 | static int __ata_set_sata_spd_needed(struct ata_port *ap, u32 *scontrol) | ||
1685 | { | ||
1686 | u32 spd, limit; | ||
1687 | |||
1688 | if (ap->sata_spd_limit == UINT_MAX) | ||
1689 | limit = 0; | ||
1690 | else | ||
1691 | limit = fls(ap->sata_spd_limit); | ||
1692 | |||
1693 | spd = (*scontrol >> 4) & 0xf; | ||
1694 | *scontrol = (*scontrol & ~0xf0) | ((limit & 0xf) << 4); | ||
1695 | |||
1696 | return spd != limit; | ||
1697 | } | ||
1698 | |||
1699 | /** | ||
1700 | * ata_set_sata_spd_needed - is SATA spd configuration needed | ||
1701 | * @ap: Port in question | ||
1702 | * | ||
1703 | * Test whether the spd limit in SControl matches | ||
1704 | * @ap->sata_spd_limit. This function is used to determine | ||
1705 | * whether hardreset is necessary to apply SATA spd | ||
1706 | * configuration. | ||
1707 | * | ||
1708 | * LOCKING: | ||
1709 | * Inherited from caller. | ||
1710 | * | ||
1711 | * RETURNS: | ||
1712 | * 1 if SATA spd configuration is needed, 0 otherwise. | ||
1713 | */ | ||
1714 | int ata_set_sata_spd_needed(struct ata_port *ap) | ||
1715 | { | ||
1716 | u32 scontrol; | ||
1717 | |||
1718 | if (ap->cbl != ATA_CBL_SATA || !ap->ops->scr_read) | ||
1719 | return 0; | ||
1720 | |||
1721 | scontrol = scr_read(ap, SCR_CONTROL); | ||
1722 | |||
1723 | return __ata_set_sata_spd_needed(ap, &scontrol); | ||
1724 | } | ||
1725 | |||
1726 | /** | ||
1727 | * ata_set_sata_spd - set SATA spd according to spd limit | ||
1728 | * @ap: Port to set SATA spd for | ||
1729 | * | ||
1730 | * Set SATA spd of @ap according to sata_spd_limit. | ||
1731 | * | ||
1732 | * LOCKING: | ||
1733 | * Inherited from caller. | ||
1734 | * | ||
1735 | * RETURNS: | ||
1736 | * 0 if spd doesn't need to be changed, 1 if spd has been | ||
1737 | * changed. -EOPNOTSUPP if SCR registers are inaccessible. | ||
1738 | */ | ||
1739 | static int ata_set_sata_spd(struct ata_port *ap) | ||
1740 | { | ||
1741 | u32 scontrol; | ||
1742 | |||
1743 | if (ap->cbl != ATA_CBL_SATA || !ap->ops->scr_read) | ||
1744 | return -EOPNOTSUPP; | ||
1745 | |||
1746 | scontrol = scr_read(ap, SCR_CONTROL); | ||
1747 | if (!__ata_set_sata_spd_needed(ap, &scontrol)) | ||
1748 | return 0; | ||
1749 | |||
1750 | scr_write(ap, SCR_CONTROL, scontrol); | ||
1751 | return 1; | ||
1586 | } | 1752 | } |
1587 | 1753 | ||
1588 | /* | 1754 | /* |
@@ -1733,11 +1899,62 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed, | |||
1733 | return 0; | 1899 | return 0; |
1734 | } | 1900 | } |
1735 | 1901 | ||
1902 | /** | ||
1903 | * ata_down_xfermask_limit - adjust dev xfer masks downward | ||
1904 | * @ap: Port associated with device @dev | ||
1905 | * @dev: Device to adjust xfer masks | ||
1906 | * @force_pio0: Force PIO0 | ||
1907 | * | ||
1908 | * Adjust xfer masks of @dev downward. Note that this function | ||
1909 | * does not apply the change. Invoking ata_set_mode() afterwards | ||
1910 | * will apply the limit. | ||
1911 | * | ||
1912 | * LOCKING: | ||
1913 | * Inherited from caller. | ||
1914 | * | ||
1915 | * RETURNS: | ||
1916 | * 0 on success, negative errno on failure | ||
1917 | */ | ||
1918 | int ata_down_xfermask_limit(struct ata_port *ap, struct ata_device *dev, | ||
1919 | int force_pio0) | ||
1920 | { | ||
1921 | unsigned long xfer_mask; | ||
1922 | int highbit; | ||
1923 | |||
1924 | xfer_mask = ata_pack_xfermask(dev->pio_mask, dev->mwdma_mask, | ||
1925 | dev->udma_mask); | ||
1926 | |||
1927 | if (!xfer_mask) | ||
1928 | goto fail; | ||
1929 | /* don't gear down to MWDMA from UDMA, go directly to PIO */ | ||
1930 | if (xfer_mask & ATA_MASK_UDMA) | ||
1931 | xfer_mask &= ~ATA_MASK_MWDMA; | ||
1932 | |||
1933 | highbit = fls(xfer_mask) - 1; | ||
1934 | xfer_mask &= ~(1 << highbit); | ||
1935 | if (force_pio0) | ||
1936 | xfer_mask &= 1 << ATA_SHIFT_PIO; | ||
1937 | if (!xfer_mask) | ||
1938 | goto fail; | ||
1939 | |||
1940 | ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, | ||
1941 | &dev->udma_mask); | ||
1942 | |||
1943 | printk(KERN_WARNING "ata%u: dev %u limiting speed to %s\n", | ||
1944 | ap->id, dev->devno, ata_mode_string(xfer_mask)); | ||
1945 | |||
1946 | return 0; | ||
1947 | |||
1948 | fail: | ||
1949 | return -EINVAL; | ||
1950 | } | ||
1951 | |||
1736 | static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev) | 1952 | static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev) |
1737 | { | 1953 | { |
1738 | unsigned int err_mask; | 1954 | unsigned int err_mask; |
1739 | int rc; | 1955 | int rc; |
1740 | 1956 | ||
1957 | dev->flags &= ~ATA_DFLAG_PIO; | ||
1741 | if (dev->xfer_shift == ATA_SHIFT_PIO) | 1958 | if (dev->xfer_shift == ATA_SHIFT_PIO) |
1742 | dev->flags |= ATA_DFLAG_PIO; | 1959 | dev->flags |= ATA_DFLAG_PIO; |
1743 | 1960 | ||
@@ -1750,12 +1967,8 @@ static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev) | |||
1750 | } | 1967 | } |
1751 | 1968 | ||
1752 | rc = ata_dev_revalidate(ap, dev, 0); | 1969 | rc = ata_dev_revalidate(ap, dev, 0); |
1753 | if (rc) { | 1970 | if (rc) |
1754 | printk(KERN_ERR | ||
1755 | "ata%u: failed to revalidate after set xfermode\n", | ||
1756 | ap->id); | ||
1757 | return rc; | 1971 | return rc; |
1758 | } | ||
1759 | 1972 | ||
1760 | DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n", | 1973 | DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n", |
1761 | dev->xfer_shift, (int)dev->xfer_mode); | 1974 | dev->xfer_shift, (int)dev->xfer_mode); |
@@ -1766,118 +1979,107 @@ static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev) | |||
1766 | return 0; | 1979 | return 0; |
1767 | } | 1980 | } |
1768 | 1981 | ||
1769 | static int ata_host_set_pio(struct ata_port *ap) | ||
1770 | { | ||
1771 | int i; | ||
1772 | |||
1773 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | ||
1774 | struct ata_device *dev = &ap->device[i]; | ||
1775 | |||
1776 | if (!ata_dev_present(dev)) | ||
1777 | continue; | ||
1778 | |||
1779 | if (!dev->pio_mode) { | ||
1780 | printk(KERN_WARNING "ata%u: no PIO support for device %d.\n", ap->id, i); | ||
1781 | return -1; | ||
1782 | } | ||
1783 | |||
1784 | dev->xfer_mode = dev->pio_mode; | ||
1785 | dev->xfer_shift = ATA_SHIFT_PIO; | ||
1786 | if (ap->ops->set_piomode) | ||
1787 | ap->ops->set_piomode(ap, dev); | ||
1788 | } | ||
1789 | |||
1790 | return 0; | ||
1791 | } | ||
1792 | |||
1793 | static void ata_host_set_dma(struct ata_port *ap) | ||
1794 | { | ||
1795 | int i; | ||
1796 | |||
1797 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | ||
1798 | struct ata_device *dev = &ap->device[i]; | ||
1799 | |||
1800 | if (!ata_dev_present(dev) || !dev->dma_mode) | ||
1801 | continue; | ||
1802 | |||
1803 | dev->xfer_mode = dev->dma_mode; | ||
1804 | dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode); | ||
1805 | if (ap->ops->set_dmamode) | ||
1806 | ap->ops->set_dmamode(ap, dev); | ||
1807 | } | ||
1808 | } | ||
1809 | |||
1810 | /** | 1982 | /** |
1811 | * ata_set_mode - Program timings and issue SET FEATURES - XFER | 1983 | * ata_set_mode - Program timings and issue SET FEATURES - XFER |
1812 | * @ap: port on which timings will be programmed | 1984 | * @ap: port on which timings will be programmed |
1985 | * @r_failed_dev: out paramter for failed device | ||
1813 | * | 1986 | * |
1814 | * Set ATA device disk transfer mode (PIO3, UDMA6, etc.). | 1987 | * Set ATA device disk transfer mode (PIO3, UDMA6, etc.). If |
1988 | * ata_set_mode() fails, pointer to the failing device is | ||
1989 | * returned in @r_failed_dev. | ||
1815 | * | 1990 | * |
1816 | * LOCKING: | 1991 | * LOCKING: |
1817 | * PCI/etc. bus probe sem. | 1992 | * PCI/etc. bus probe sem. |
1993 | * | ||
1994 | * RETURNS: | ||
1995 | * 0 on success, negative errno otherwise | ||
1818 | */ | 1996 | */ |
1819 | static void ata_set_mode(struct ata_port *ap) | 1997 | int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev) |
1820 | { | 1998 | { |
1821 | int i, rc, used_dma = 0; | 1999 | struct ata_device *dev; |
2000 | int i, rc = 0, used_dma = 0, found = 0; | ||
1822 | 2001 | ||
1823 | /* step 1: calculate xfer_mask */ | 2002 | /* step 1: calculate xfer_mask */ |
1824 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2003 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
1825 | struct ata_device *dev = &ap->device[i]; | ||
1826 | unsigned int pio_mask, dma_mask; | 2004 | unsigned int pio_mask, dma_mask; |
1827 | 2005 | ||
1828 | if (!ata_dev_present(dev)) | 2006 | dev = &ap->device[i]; |
2007 | |||
2008 | if (!ata_dev_enabled(dev)) | ||
1829 | continue; | 2009 | continue; |
1830 | 2010 | ||
1831 | ata_dev_xfermask(ap, dev); | 2011 | ata_dev_xfermask(ap, dev); |
1832 | 2012 | ||
1833 | /* TODO: let LLDD filter dev->*_mask here */ | ||
1834 | |||
1835 | pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0); | 2013 | pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0); |
1836 | dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask); | 2014 | dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask); |
1837 | dev->pio_mode = ata_xfer_mask2mode(pio_mask); | 2015 | dev->pio_mode = ata_xfer_mask2mode(pio_mask); |
1838 | dev->dma_mode = ata_xfer_mask2mode(dma_mask); | 2016 | dev->dma_mode = ata_xfer_mask2mode(dma_mask); |
1839 | 2017 | ||
2018 | found = 1; | ||
1840 | if (dev->dma_mode) | 2019 | if (dev->dma_mode) |
1841 | used_dma = 1; | 2020 | used_dma = 1; |
1842 | } | 2021 | } |
2022 | if (!found) | ||
2023 | goto out; | ||
1843 | 2024 | ||
1844 | /* step 2: always set host PIO timings */ | 2025 | /* step 2: always set host PIO timings */ |
1845 | rc = ata_host_set_pio(ap); | 2026 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
1846 | if (rc) | 2027 | dev = &ap->device[i]; |
1847 | goto err_out; | 2028 | if (!ata_dev_enabled(dev)) |
2029 | continue; | ||
2030 | |||
2031 | if (!dev->pio_mode) { | ||
2032 | printk(KERN_WARNING "ata%u: dev %u no PIO support\n", | ||
2033 | ap->id, dev->devno); | ||
2034 | rc = -EINVAL; | ||
2035 | goto out; | ||
2036 | } | ||
2037 | |||
2038 | dev->xfer_mode = dev->pio_mode; | ||
2039 | dev->xfer_shift = ATA_SHIFT_PIO; | ||
2040 | if (ap->ops->set_piomode) | ||
2041 | ap->ops->set_piomode(ap, dev); | ||
2042 | } | ||
1848 | 2043 | ||
1849 | /* step 3: set host DMA timings */ | 2044 | /* step 3: set host DMA timings */ |
1850 | ata_host_set_dma(ap); | 2045 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
2046 | dev = &ap->device[i]; | ||
2047 | |||
2048 | if (!ata_dev_enabled(dev) || !dev->dma_mode) | ||
2049 | continue; | ||
2050 | |||
2051 | dev->xfer_mode = dev->dma_mode; | ||
2052 | dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode); | ||
2053 | if (ap->ops->set_dmamode) | ||
2054 | ap->ops->set_dmamode(ap, dev); | ||
2055 | } | ||
1851 | 2056 | ||
1852 | /* step 4: update devices' xfer mode */ | 2057 | /* step 4: update devices' xfer mode */ |
1853 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2058 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
1854 | struct ata_device *dev = &ap->device[i]; | 2059 | dev = &ap->device[i]; |
1855 | 2060 | ||
1856 | if (!ata_dev_present(dev)) | 2061 | if (!ata_dev_enabled(dev)) |
1857 | continue; | 2062 | continue; |
1858 | 2063 | ||
1859 | if (ata_dev_set_mode(ap, dev)) | 2064 | rc = ata_dev_set_mode(ap, dev); |
1860 | goto err_out; | 2065 | if (rc) |
2066 | goto out; | ||
1861 | } | 2067 | } |
1862 | 2068 | ||
1863 | /* | 2069 | /* Record simplex status. If we selected DMA then the other |
1864 | * Record simplex status. If we selected DMA then the other | 2070 | * host channels are not permitted to do so. |
1865 | * host channels are not permitted to do so. | ||
1866 | */ | 2071 | */ |
1867 | |||
1868 | if (used_dma && (ap->host_set->flags & ATA_HOST_SIMPLEX)) | 2072 | if (used_dma && (ap->host_set->flags & ATA_HOST_SIMPLEX)) |
1869 | ap->host_set->simplex_claimed = 1; | 2073 | ap->host_set->simplex_claimed = 1; |
1870 | 2074 | ||
1871 | /* | 2075 | /* step5: chip specific finalisation */ |
1872 | * Chip specific finalisation | ||
1873 | */ | ||
1874 | if (ap->ops->post_set_mode) | 2076 | if (ap->ops->post_set_mode) |
1875 | ap->ops->post_set_mode(ap); | 2077 | ap->ops->post_set_mode(ap); |
1876 | 2078 | ||
1877 | return; | 2079 | out: |
1878 | 2080 | if (rc) | |
1879 | err_out: | 2081 | *r_failed_dev = dev; |
1880 | ata_port_disable(ap); | 2082 | return rc; |
1881 | } | 2083 | } |
1882 | 2084 | ||
1883 | /** | 2085 | /** |
@@ -2055,7 +2257,7 @@ static unsigned int ata_bus_softreset(struct ata_port *ap, | |||
2055 | * Obtains host_set lock. | 2257 | * Obtains host_set lock. |
2056 | * | 2258 | * |
2057 | * SIDE EFFECTS: | 2259 | * SIDE EFFECTS: |
2058 | * Sets ATA_FLAG_PORT_DISABLED if bus reset fails. | 2260 | * Sets ATA_FLAG_DISABLED if bus reset fails. |
2059 | */ | 2261 | */ |
2060 | 2262 | ||
2061 | void ata_bus_reset(struct ata_port *ap) | 2263 | void ata_bus_reset(struct ata_port *ap) |
@@ -2132,9 +2334,11 @@ err_out: | |||
2132 | static int sata_phy_resume(struct ata_port *ap) | 2334 | static int sata_phy_resume(struct ata_port *ap) |
2133 | { | 2335 | { |
2134 | unsigned long timeout = jiffies + (HZ * 5); | 2336 | unsigned long timeout = jiffies + (HZ * 5); |
2135 | u32 sstatus; | 2337 | u32 scontrol, sstatus; |
2136 | 2338 | ||
2137 | scr_write_flush(ap, SCR_CONTROL, 0x300); | 2339 | scontrol = scr_read(ap, SCR_CONTROL); |
2340 | scontrol = (scontrol & 0x0f0) | 0x300; | ||
2341 | scr_write_flush(ap, SCR_CONTROL, scontrol); | ||
2138 | 2342 | ||
2139 | /* Wait for phy to become ready, if necessary. */ | 2343 | /* Wait for phy to become ready, if necessary. */ |
2140 | do { | 2344 | do { |
@@ -2163,7 +2367,14 @@ static int sata_phy_resume(struct ata_port *ap) | |||
2163 | void ata_std_probeinit(struct ata_port *ap) | 2367 | void ata_std_probeinit(struct ata_port *ap) |
2164 | { | 2368 | { |
2165 | if ((ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read) { | 2369 | if ((ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read) { |
2370 | u32 spd; | ||
2371 | |||
2166 | sata_phy_resume(ap); | 2372 | sata_phy_resume(ap); |
2373 | |||
2374 | spd = (scr_read(ap, SCR_CONTROL) & 0xf0) >> 4; | ||
2375 | if (spd) | ||
2376 | ap->sata_spd_limit &= (1 << spd) - 1; | ||
2377 | |||
2167 | if (sata_dev_present(ap)) | 2378 | if (sata_dev_present(ap)) |
2168 | ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); | 2379 | ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); |
2169 | } | 2380 | } |
@@ -2247,18 +2458,34 @@ int ata_std_softreset(struct ata_port *ap, int verbose, unsigned int *classes) | |||
2247 | */ | 2458 | */ |
2248 | int sata_std_hardreset(struct ata_port *ap, int verbose, unsigned int *class) | 2459 | int sata_std_hardreset(struct ata_port *ap, int verbose, unsigned int *class) |
2249 | { | 2460 | { |
2461 | u32 scontrol; | ||
2462 | |||
2250 | DPRINTK("ENTER\n"); | 2463 | DPRINTK("ENTER\n"); |
2251 | 2464 | ||
2252 | /* Issue phy wake/reset */ | 2465 | if (ata_set_sata_spd_needed(ap)) { |
2253 | scr_write_flush(ap, SCR_CONTROL, 0x301); | 2466 | /* SATA spec says nothing about how to reconfigure |
2467 | * spd. To be on the safe side, turn off phy during | ||
2468 | * reconfiguration. This works for at least ICH7 AHCI | ||
2469 | * and Sil3124. | ||
2470 | */ | ||
2471 | scontrol = scr_read(ap, SCR_CONTROL); | ||
2472 | scontrol = (scontrol & 0x0f0) | 0x302; | ||
2473 | scr_write_flush(ap, SCR_CONTROL, scontrol); | ||
2254 | 2474 | ||
2255 | /* | 2475 | ata_set_sata_spd(ap); |
2256 | * Couldn't find anything in SATA I/II specs, but AHCI-1.1 | 2476 | } |
2477 | |||
2478 | /* issue phy wake/reset */ | ||
2479 | scontrol = scr_read(ap, SCR_CONTROL); | ||
2480 | scontrol = (scontrol & 0x0f0) | 0x301; | ||
2481 | scr_write_flush(ap, SCR_CONTROL, scontrol); | ||
2482 | |||
2483 | /* Couldn't find anything in SATA I/II specs, but AHCI-1.1 | ||
2257 | * 10.4.2 says at least 1 ms. | 2484 | * 10.4.2 says at least 1 ms. |
2258 | */ | 2485 | */ |
2259 | msleep(1); | 2486 | msleep(1); |
2260 | 2487 | ||
2261 | /* Bring phy back */ | 2488 | /* bring phy back */ |
2262 | sata_phy_resume(ap); | 2489 | sata_phy_resume(ap); |
2263 | 2490 | ||
2264 | /* TODO: phy layer with polling, timeouts, etc. */ | 2491 | /* TODO: phy layer with polling, timeouts, etc. */ |
@@ -2365,16 +2592,16 @@ int ata_std_probe_reset(struct ata_port *ap, unsigned int *classes) | |||
2365 | ata_std_postreset, classes); | 2592 | ata_std_postreset, classes); |
2366 | } | 2593 | } |
2367 | 2594 | ||
2368 | static int do_probe_reset(struct ata_port *ap, ata_reset_fn_t reset, | 2595 | int ata_do_reset(struct ata_port *ap, |
2369 | ata_postreset_fn_t postreset, | 2596 | ata_reset_fn_t reset, ata_postreset_fn_t postreset, |
2370 | unsigned int *classes) | 2597 | int verbose, unsigned int *classes) |
2371 | { | 2598 | { |
2372 | int i, rc; | 2599 | int i, rc; |
2373 | 2600 | ||
2374 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 2601 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
2375 | classes[i] = ATA_DEV_UNKNOWN; | 2602 | classes[i] = ATA_DEV_UNKNOWN; |
2376 | 2603 | ||
2377 | rc = reset(ap, 0, classes); | 2604 | rc = reset(ap, verbose, classes); |
2378 | if (rc) | 2605 | if (rc) |
2379 | return rc; | 2606 | return rc; |
2380 | 2607 | ||
@@ -2394,7 +2621,7 @@ static int do_probe_reset(struct ata_port *ap, ata_reset_fn_t reset, | |||
2394 | if (postreset) | 2621 | if (postreset) |
2395 | postreset(ap, classes); | 2622 | postreset(ap, classes); |
2396 | 2623 | ||
2397 | return classes[0] != ATA_DEV_UNKNOWN ? 0 : -ENODEV; | 2624 | return 0; |
2398 | } | 2625 | } |
2399 | 2626 | ||
2400 | /** | 2627 | /** |
@@ -2438,22 +2665,46 @@ int ata_drive_probe_reset(struct ata_port *ap, ata_probeinit_fn_t probeinit, | |||
2438 | if (probeinit) | 2665 | if (probeinit) |
2439 | probeinit(ap); | 2666 | probeinit(ap); |
2440 | 2667 | ||
2441 | if (softreset) { | 2668 | if (softreset && !ata_set_sata_spd_needed(ap)) { |
2442 | rc = do_probe_reset(ap, softreset, postreset, classes); | 2669 | rc = ata_do_reset(ap, softreset, postreset, 0, classes); |
2443 | if (rc == 0) | 2670 | if (rc == 0 && classes[0] != ATA_DEV_UNKNOWN) |
2444 | return 0; | 2671 | goto done; |
2672 | printk(KERN_INFO "ata%u: softreset failed, will try " | ||
2673 | "hardreset in 5 secs\n", ap->id); | ||
2674 | ssleep(5); | ||
2445 | } | 2675 | } |
2446 | 2676 | ||
2447 | if (!hardreset) | 2677 | if (!hardreset) |
2448 | return rc; | 2678 | goto done; |
2449 | 2679 | ||
2450 | rc = do_probe_reset(ap, hardreset, postreset, classes); | 2680 | while (1) { |
2451 | if (rc == 0 || rc != -ENODEV) | 2681 | rc = ata_do_reset(ap, hardreset, postreset, 0, classes); |
2452 | return rc; | 2682 | if (rc == 0) { |
2683 | if (classes[0] != ATA_DEV_UNKNOWN) | ||
2684 | goto done; | ||
2685 | break; | ||
2686 | } | ||
2687 | |||
2688 | if (ata_down_sata_spd_limit(ap)) | ||
2689 | goto done; | ||
2690 | |||
2691 | printk(KERN_INFO "ata%u: hardreset failed, will retry " | ||
2692 | "in 5 secs\n", ap->id); | ||
2693 | ssleep(5); | ||
2694 | } | ||
2695 | |||
2696 | if (softreset) { | ||
2697 | printk(KERN_INFO "ata%u: hardreset succeeded without " | ||
2698 | "classification, will retry softreset in 5 secs\n", | ||
2699 | ap->id); | ||
2700 | ssleep(5); | ||
2453 | 2701 | ||
2454 | if (softreset) | 2702 | rc = ata_do_reset(ap, softreset, postreset, 0, classes); |
2455 | rc = do_probe_reset(ap, softreset, postreset, classes); | 2703 | } |
2456 | 2704 | ||
2705 | done: | ||
2706 | if (rc == 0 && classes[0] == ATA_DEV_UNKNOWN) | ||
2707 | rc = -ENODEV; | ||
2457 | return rc; | 2708 | return rc; |
2458 | } | 2709 | } |
2459 | 2710 | ||
@@ -2537,15 +2788,14 @@ static int ata_dev_same_device(struct ata_port *ap, struct ata_device *dev, | |||
2537 | int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev, | 2788 | int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev, |
2538 | int post_reset) | 2789 | int post_reset) |
2539 | { | 2790 | { |
2540 | unsigned int class; | 2791 | unsigned int class = dev->class; |
2541 | u16 *id; | 2792 | u16 *id = NULL; |
2542 | int rc; | 2793 | int rc; |
2543 | 2794 | ||
2544 | if (!ata_dev_present(dev)) | 2795 | if (!ata_dev_enabled(dev)) { |
2545 | return -ENODEV; | 2796 | rc = -ENODEV; |
2546 | 2797 | goto fail; | |
2547 | class = dev->class; | 2798 | } |
2548 | id = NULL; | ||
2549 | 2799 | ||
2550 | /* allocate & read ID data */ | 2800 | /* allocate & read ID data */ |
2551 | rc = ata_dev_read_id(ap, dev, &class, post_reset, &id); | 2801 | rc = ata_dev_read_id(ap, dev, &class, post_reset, &id); |
@@ -2562,7 +2812,9 @@ int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev, | |||
2562 | dev->id = id; | 2812 | dev->id = id; |
2563 | 2813 | ||
2564 | /* configure device according to the new ID */ | 2814 | /* configure device according to the new ID */ |
2565 | return ata_dev_configure(ap, dev, 0); | 2815 | rc = ata_dev_configure(ap, dev, 0); |
2816 | if (rc == 0) | ||
2817 | return 0; | ||
2566 | 2818 | ||
2567 | fail: | 2819 | fail: |
2568 | printk(KERN_ERR "ata%u: dev %u revalidation failed (errno=%d)\n", | 2820 | printk(KERN_ERR "ata%u: dev %u revalidation failed (errno=%d)\n", |
@@ -2664,23 +2916,34 @@ static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev) | |||
2664 | unsigned long xfer_mask; | 2916 | unsigned long xfer_mask; |
2665 | int i; | 2917 | int i; |
2666 | 2918 | ||
2667 | xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, | 2919 | xfer_mask = ata_pack_xfermask(ap->pio_mask, |
2668 | ap->udma_mask); | 2920 | ap->mwdma_mask, ap->udma_mask); |
2921 | |||
2922 | /* Apply cable rule here. Don't apply it early because when | ||
2923 | * we handle hot plug the cable type can itself change. | ||
2924 | */ | ||
2925 | if (ap->cbl == ATA_CBL_PATA40) | ||
2926 | xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA); | ||
2669 | 2927 | ||
2670 | /* FIXME: Use port-wide xfermask for now */ | 2928 | /* FIXME: Use port-wide xfermask for now */ |
2671 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2929 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
2672 | struct ata_device *d = &ap->device[i]; | 2930 | struct ata_device *d = &ap->device[i]; |
2673 | if (!ata_dev_present(d)) | 2931 | |
2932 | if (ata_dev_absent(d)) | ||
2933 | continue; | ||
2934 | |||
2935 | if (ata_dev_disabled(d)) { | ||
2936 | /* to avoid violating device selection timing */ | ||
2937 | xfer_mask &= ata_pack_xfermask(d->pio_mask, | ||
2938 | UINT_MAX, UINT_MAX); | ||
2674 | continue; | 2939 | continue; |
2675 | xfer_mask &= ata_pack_xfermask(d->pio_mask, d->mwdma_mask, | 2940 | } |
2676 | d->udma_mask); | 2941 | |
2942 | xfer_mask &= ata_pack_xfermask(d->pio_mask, | ||
2943 | d->mwdma_mask, d->udma_mask); | ||
2677 | xfer_mask &= ata_id_xfermask(d->id); | 2944 | xfer_mask &= ata_id_xfermask(d->id); |
2678 | if (ata_dma_blacklisted(d)) | 2945 | if (ata_dma_blacklisted(d)) |
2679 | xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); | 2946 | xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); |
2680 | /* Apply cable rule here. Don't apply it early because when | ||
2681 | we handle hot plug the cable type can itself change */ | ||
2682 | if (ap->cbl == ATA_CBL_PATA40) | ||
2683 | xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA); | ||
2684 | } | 2947 | } |
2685 | 2948 | ||
2686 | if (ata_dma_blacklisted(dev)) | 2949 | if (ata_dma_blacklisted(dev)) |
@@ -2691,11 +2954,12 @@ static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev) | |||
2691 | if (hs->simplex_claimed) | 2954 | if (hs->simplex_claimed) |
2692 | xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); | 2955 | xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); |
2693 | } | 2956 | } |
2957 | |||
2694 | if (ap->ops->mode_filter) | 2958 | if (ap->ops->mode_filter) |
2695 | xfer_mask = ap->ops->mode_filter(ap, dev, xfer_mask); | 2959 | xfer_mask = ap->ops->mode_filter(ap, dev, xfer_mask); |
2696 | 2960 | ||
2697 | ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, | 2961 | ata_unpack_xfermask(xfer_mask, &dev->pio_mask, |
2698 | &dev->udma_mask); | 2962 | &dev->mwdma_mask, &dev->udma_mask); |
2699 | } | 2963 | } |
2700 | 2964 | ||
2701 | /** | 2965 | /** |
@@ -2729,7 +2993,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_port *ap, | |||
2729 | tf.protocol = ATA_PROT_NODATA; | 2993 | tf.protocol = ATA_PROT_NODATA; |
2730 | tf.nsect = dev->xfer_mode; | 2994 | tf.nsect = dev->xfer_mode; |
2731 | 2995 | ||
2732 | err_mask = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0); | 2996 | err_mask = ata_exec_internal(ap, dev, &tf, NULL, DMA_NONE, NULL, 0); |
2733 | 2997 | ||
2734 | DPRINTK("EXIT, err_mask=%x\n", err_mask); | 2998 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
2735 | return err_mask; | 2999 | return err_mask; |
@@ -2769,7 +3033,7 @@ static unsigned int ata_dev_init_params(struct ata_port *ap, | |||
2769 | tf.nsect = sectors; | 3033 | tf.nsect = sectors; |
2770 | tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ | 3034 | tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ |
2771 | 3035 | ||
2772 | err_mask = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0); | 3036 | err_mask = ata_exec_internal(ap, dev, &tf, NULL, DMA_NONE, NULL, 0); |
2773 | 3037 | ||
2774 | DPRINTK("EXIT, err_mask=%x\n", err_mask); | 3038 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
2775 | return err_mask; | 3039 | return err_mask; |
@@ -3157,7 +3421,7 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc) | |||
3157 | 3421 | ||
3158 | /** | 3422 | /** |
3159 | * ata_pio_poll - poll using PIO, depending on current state | 3423 | * ata_pio_poll - poll using PIO, depending on current state |
3160 | * @ap: the target ata_port | 3424 | * @qc: qc in progress |
3161 | * | 3425 | * |
3162 | * LOCKING: | 3426 | * LOCKING: |
3163 | * None. (executing in kernel thread context) | 3427 | * None. (executing in kernel thread context) |
@@ -3165,17 +3429,13 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc) | |||
3165 | * RETURNS: | 3429 | * RETURNS: |
3166 | * timeout value to use | 3430 | * timeout value to use |
3167 | */ | 3431 | */ |
3168 | 3432 | static unsigned long ata_pio_poll(struct ata_queued_cmd *qc) | |
3169 | static unsigned long ata_pio_poll(struct ata_port *ap) | ||
3170 | { | 3433 | { |
3171 | struct ata_queued_cmd *qc; | 3434 | struct ata_port *ap = qc->ap; |
3172 | u8 status; | 3435 | u8 status; |
3173 | unsigned int poll_state = HSM_ST_UNKNOWN; | 3436 | unsigned int poll_state = HSM_ST_UNKNOWN; |
3174 | unsigned int reg_state = HSM_ST_UNKNOWN; | 3437 | unsigned int reg_state = HSM_ST_UNKNOWN; |
3175 | 3438 | ||
3176 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
3177 | WARN_ON(qc == NULL); | ||
3178 | |||
3179 | switch (ap->hsm_task_state) { | 3439 | switch (ap->hsm_task_state) { |
3180 | case HSM_ST: | 3440 | case HSM_ST: |
3181 | case HSM_ST_POLL: | 3441 | case HSM_ST_POLL: |
@@ -3209,7 +3469,7 @@ static unsigned long ata_pio_poll(struct ata_port *ap) | |||
3209 | 3469 | ||
3210 | /** | 3470 | /** |
3211 | * ata_pio_complete - check if drive is busy or idle | 3471 | * ata_pio_complete - check if drive is busy or idle |
3212 | * @ap: the target ata_port | 3472 | * @qc: qc to complete |
3213 | * | 3473 | * |
3214 | * LOCKING: | 3474 | * LOCKING: |
3215 | * None. (executing in kernel thread context) | 3475 | * None. (executing in kernel thread context) |
@@ -3217,10 +3477,9 @@ static unsigned long ata_pio_poll(struct ata_port *ap) | |||
3217 | * RETURNS: | 3477 | * RETURNS: |
3218 | * Non-zero if qc completed, zero otherwise. | 3478 | * Non-zero if qc completed, zero otherwise. |
3219 | */ | 3479 | */ |
3220 | 3480 | static int ata_pio_complete(struct ata_queued_cmd *qc) | |
3221 | static int ata_pio_complete (struct ata_port *ap) | ||
3222 | { | 3481 | { |
3223 | struct ata_queued_cmd *qc; | 3482 | struct ata_port *ap = qc->ap; |
3224 | u8 drv_stat; | 3483 | u8 drv_stat; |
3225 | 3484 | ||
3226 | /* | 3485 | /* |
@@ -3241,9 +3500,6 @@ static int ata_pio_complete (struct ata_port *ap) | |||
3241 | } | 3500 | } |
3242 | } | 3501 | } |
3243 | 3502 | ||
3244 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
3245 | WARN_ON(qc == NULL); | ||
3246 | |||
3247 | drv_stat = ata_wait_idle(ap); | 3503 | drv_stat = ata_wait_idle(ap); |
3248 | if (!ata_ok(drv_stat)) { | 3504 | if (!ata_ok(drv_stat)) { |
3249 | qc->err_mask |= __ac_err_mask(drv_stat); | 3505 | qc->err_mask |= __ac_err_mask(drv_stat); |
@@ -3579,15 +3835,14 @@ err_out: | |||
3579 | 3835 | ||
3580 | /** | 3836 | /** |
3581 | * ata_pio_block - start PIO on a block | 3837 | * ata_pio_block - start PIO on a block |
3582 | * @ap: the target ata_port | 3838 | * @qc: qc to transfer block for |
3583 | * | 3839 | * |
3584 | * LOCKING: | 3840 | * LOCKING: |
3585 | * None. (executing in kernel thread context) | 3841 | * None. (executing in kernel thread context) |
3586 | */ | 3842 | */ |
3587 | 3843 | static void ata_pio_block(struct ata_queued_cmd *qc) | |
3588 | static void ata_pio_block(struct ata_port *ap) | ||
3589 | { | 3844 | { |
3590 | struct ata_queued_cmd *qc; | 3845 | struct ata_port *ap = qc->ap; |
3591 | u8 status; | 3846 | u8 status; |
3592 | 3847 | ||
3593 | /* | 3848 | /* |
@@ -3609,9 +3864,6 @@ static void ata_pio_block(struct ata_port *ap) | |||
3609 | } | 3864 | } |
3610 | } | 3865 | } |
3611 | 3866 | ||
3612 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
3613 | WARN_ON(qc == NULL); | ||
3614 | |||
3615 | /* check error */ | 3867 | /* check error */ |
3616 | if (status & (ATA_ERR | ATA_DF)) { | 3868 | if (status & (ATA_ERR | ATA_DF)) { |
3617 | qc->err_mask |= AC_ERR_DEV; | 3869 | qc->err_mask |= AC_ERR_DEV; |
@@ -3640,15 +3892,13 @@ static void ata_pio_block(struct ata_port *ap) | |||
3640 | } | 3892 | } |
3641 | } | 3893 | } |
3642 | 3894 | ||
3643 | static void ata_pio_error(struct ata_port *ap) | 3895 | static void ata_pio_error(struct ata_queued_cmd *qc) |
3644 | { | 3896 | { |
3645 | struct ata_queued_cmd *qc; | 3897 | struct ata_port *ap = qc->ap; |
3646 | |||
3647 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
3648 | WARN_ON(qc == NULL); | ||
3649 | 3898 | ||
3650 | if (qc->tf.command != ATA_CMD_PACKET) | 3899 | if (qc->tf.command != ATA_CMD_PACKET) |
3651 | printk(KERN_WARNING "ata%u: PIO error\n", ap->id); | 3900 | printk(KERN_WARNING "ata%u: dev %u PIO error\n", |
3901 | ap->id, qc->dev->devno); | ||
3652 | 3902 | ||
3653 | /* make sure qc->err_mask is available to | 3903 | /* make sure qc->err_mask is available to |
3654 | * know what's wrong and recover | 3904 | * know what's wrong and recover |
@@ -3662,7 +3912,8 @@ static void ata_pio_error(struct ata_port *ap) | |||
3662 | 3912 | ||
3663 | static void ata_pio_task(void *_data) | 3913 | static void ata_pio_task(void *_data) |
3664 | { | 3914 | { |
3665 | struct ata_port *ap = _data; | 3915 | struct ata_queued_cmd *qc = _data; |
3916 | struct ata_port *ap = qc->ap; | ||
3666 | unsigned long timeout; | 3917 | unsigned long timeout; |
3667 | int qc_completed; | 3918 | int qc_completed; |
3668 | 3919 | ||
@@ -3675,33 +3926,33 @@ fsm_start: | |||
3675 | return; | 3926 | return; |
3676 | 3927 | ||
3677 | case HSM_ST: | 3928 | case HSM_ST: |
3678 | ata_pio_block(ap); | 3929 | ata_pio_block(qc); |
3679 | break; | 3930 | break; |
3680 | 3931 | ||
3681 | case HSM_ST_LAST: | 3932 | case HSM_ST_LAST: |
3682 | qc_completed = ata_pio_complete(ap); | 3933 | qc_completed = ata_pio_complete(qc); |
3683 | break; | 3934 | break; |
3684 | 3935 | ||
3685 | case HSM_ST_POLL: | 3936 | case HSM_ST_POLL: |
3686 | case HSM_ST_LAST_POLL: | 3937 | case HSM_ST_LAST_POLL: |
3687 | timeout = ata_pio_poll(ap); | 3938 | timeout = ata_pio_poll(qc); |
3688 | break; | 3939 | break; |
3689 | 3940 | ||
3690 | case HSM_ST_TMOUT: | 3941 | case HSM_ST_TMOUT: |
3691 | case HSM_ST_ERR: | 3942 | case HSM_ST_ERR: |
3692 | ata_pio_error(ap); | 3943 | ata_pio_error(qc); |
3693 | return; | 3944 | return; |
3694 | } | 3945 | } |
3695 | 3946 | ||
3696 | if (timeout) | 3947 | if (timeout) |
3697 | ata_port_queue_task(ap, ata_pio_task, ap, timeout); | 3948 | ata_port_queue_task(ap, ata_pio_task, qc, timeout); |
3698 | else if (!qc_completed) | 3949 | else if (!qc_completed) |
3699 | goto fsm_start; | 3950 | goto fsm_start; |
3700 | } | 3951 | } |
3701 | 3952 | ||
3702 | /** | 3953 | /** |
3703 | * atapi_packet_task - Write CDB bytes to hardware | 3954 | * atapi_packet_task - Write CDB bytes to hardware |
3704 | * @_data: Port to which ATAPI device is attached. | 3955 | * @_data: qc in progress |
3705 | * | 3956 | * |
3706 | * When device has indicated its readiness to accept | 3957 | * When device has indicated its readiness to accept |
3707 | * a CDB, this function is called. Send the CDB. | 3958 | * a CDB, this function is called. Send the CDB. |
@@ -3712,17 +3963,12 @@ fsm_start: | |||
3712 | * LOCKING: | 3963 | * LOCKING: |
3713 | * Kernel thread context (may sleep) | 3964 | * Kernel thread context (may sleep) |
3714 | */ | 3965 | */ |
3715 | |||
3716 | static void atapi_packet_task(void *_data) | 3966 | static void atapi_packet_task(void *_data) |
3717 | { | 3967 | { |
3718 | struct ata_port *ap = _data; | 3968 | struct ata_queued_cmd *qc = _data; |
3719 | struct ata_queued_cmd *qc; | 3969 | struct ata_port *ap = qc->ap; |
3720 | u8 status; | 3970 | u8 status; |
3721 | 3971 | ||
3722 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
3723 | WARN_ON(qc == NULL); | ||
3724 | WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE)); | ||
3725 | |||
3726 | /* sleep-wait for BSY to clear */ | 3972 | /* sleep-wait for BSY to clear */ |
3727 | DPRINTK("busy wait\n"); | 3973 | DPRINTK("busy wait\n"); |
3728 | if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) { | 3974 | if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) { |
@@ -3762,7 +4008,7 @@ static void atapi_packet_task(void *_data) | |||
3762 | 4008 | ||
3763 | /* PIO commands are handled by polling */ | 4009 | /* PIO commands are handled by polling */ |
3764 | ap->hsm_task_state = HSM_ST; | 4010 | ap->hsm_task_state = HSM_ST; |
3765 | ata_port_queue_task(ap, ata_pio_task, ap, 0); | 4011 | ata_port_queue_task(ap, ata_pio_task, qc, 0); |
3766 | } | 4012 | } |
3767 | 4013 | ||
3768 | return; | 4014 | return; |
@@ -3772,99 +4018,6 @@ err_out: | |||
3772 | } | 4018 | } |
3773 | 4019 | ||
3774 | /** | 4020 | /** |
3775 | * ata_qc_timeout - Handle timeout of queued command | ||
3776 | * @qc: Command that timed out | ||
3777 | * | ||
3778 | * Some part of the kernel (currently, only the SCSI layer) | ||
3779 | * has noticed that the active command on port @ap has not | ||
3780 | * completed after a specified length of time. Handle this | ||
3781 | * condition by disabling DMA (if necessary) and completing | ||
3782 | * transactions, with error if necessary. | ||
3783 | * | ||
3784 | * This also handles the case of the "lost interrupt", where | ||
3785 | * for some reason (possibly hardware bug, possibly driver bug) | ||
3786 | * an interrupt was not delivered to the driver, even though the | ||
3787 | * transaction completed successfully. | ||
3788 | * | ||
3789 | * LOCKING: | ||
3790 | * Inherited from SCSI layer (none, can sleep) | ||
3791 | */ | ||
3792 | |||
3793 | static void ata_qc_timeout(struct ata_queued_cmd *qc) | ||
3794 | { | ||
3795 | struct ata_port *ap = qc->ap; | ||
3796 | struct ata_host_set *host_set = ap->host_set; | ||
3797 | u8 host_stat = 0, drv_stat; | ||
3798 | unsigned long flags; | ||
3799 | |||
3800 | DPRINTK("ENTER\n"); | ||
3801 | |||
3802 | ap->hsm_task_state = HSM_ST_IDLE; | ||
3803 | |||
3804 | spin_lock_irqsave(&host_set->lock, flags); | ||
3805 | |||
3806 | switch (qc->tf.protocol) { | ||
3807 | |||
3808 | case ATA_PROT_DMA: | ||
3809 | case ATA_PROT_ATAPI_DMA: | ||
3810 | host_stat = ap->ops->bmdma_status(ap); | ||
3811 | |||
3812 | /* before we do anything else, clear DMA-Start bit */ | ||
3813 | ap->ops->bmdma_stop(qc); | ||
3814 | |||
3815 | /* fall through */ | ||
3816 | |||
3817 | default: | ||
3818 | ata_altstatus(ap); | ||
3819 | drv_stat = ata_chk_status(ap); | ||
3820 | |||
3821 | /* ack bmdma irq events */ | ||
3822 | ap->ops->irq_clear(ap); | ||
3823 | |||
3824 | printk(KERN_ERR "ata%u: command 0x%x timeout, stat 0x%x host_stat 0x%x\n", | ||
3825 | ap->id, qc->tf.command, drv_stat, host_stat); | ||
3826 | |||
3827 | /* complete taskfile transaction */ | ||
3828 | qc->err_mask |= ac_err_mask(drv_stat); | ||
3829 | break; | ||
3830 | } | ||
3831 | |||
3832 | spin_unlock_irqrestore(&host_set->lock, flags); | ||
3833 | |||
3834 | ata_eh_qc_complete(qc); | ||
3835 | |||
3836 | DPRINTK("EXIT\n"); | ||
3837 | } | ||
3838 | |||
3839 | /** | ||
3840 | * ata_eng_timeout - Handle timeout of queued command | ||
3841 | * @ap: Port on which timed-out command is active | ||
3842 | * | ||
3843 | * Some part of the kernel (currently, only the SCSI layer) | ||
3844 | * has noticed that the active command on port @ap has not | ||
3845 | * completed after a specified length of time. Handle this | ||
3846 | * condition by disabling DMA (if necessary) and completing | ||
3847 | * transactions, with error if necessary. | ||
3848 | * | ||
3849 | * This also handles the case of the "lost interrupt", where | ||
3850 | * for some reason (possibly hardware bug, possibly driver bug) | ||
3851 | * an interrupt was not delivered to the driver, even though the | ||
3852 | * transaction completed successfully. | ||
3853 | * | ||
3854 | * LOCKING: | ||
3855 | * Inherited from SCSI layer (none, can sleep) | ||
3856 | */ | ||
3857 | |||
3858 | void ata_eng_timeout(struct ata_port *ap) | ||
3859 | { | ||
3860 | DPRINTK("ENTER\n"); | ||
3861 | |||
3862 | ata_qc_timeout(ata_qc_from_tag(ap, ap->active_tag)); | ||
3863 | |||
3864 | DPRINTK("EXIT\n"); | ||
3865 | } | ||
3866 | |||
3867 | /** | ||
3868 | * ata_qc_new - Request an available ATA command, for queueing | 4021 | * ata_qc_new - Request an available ATA command, for queueing |
3869 | * @ap: Port associated with device @dev | 4022 | * @ap: Port associated with device @dev |
3870 | * @dev: Device from whom we request an available command structure | 4023 | * @dev: Device from whom we request an available command structure |
@@ -4068,26 +4221,26 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc) | |||
4068 | ata_qc_set_polling(qc); | 4221 | ata_qc_set_polling(qc); |
4069 | ata_tf_to_host(ap, &qc->tf); | 4222 | ata_tf_to_host(ap, &qc->tf); |
4070 | ap->hsm_task_state = HSM_ST; | 4223 | ap->hsm_task_state = HSM_ST; |
4071 | ata_port_queue_task(ap, ata_pio_task, ap, 0); | 4224 | ata_port_queue_task(ap, ata_pio_task, qc, 0); |
4072 | break; | 4225 | break; |
4073 | 4226 | ||
4074 | case ATA_PROT_ATAPI: | 4227 | case ATA_PROT_ATAPI: |
4075 | ata_qc_set_polling(qc); | 4228 | ata_qc_set_polling(qc); |
4076 | ata_tf_to_host(ap, &qc->tf); | 4229 | ata_tf_to_host(ap, &qc->tf); |
4077 | ata_port_queue_task(ap, atapi_packet_task, ap, 0); | 4230 | ata_port_queue_task(ap, atapi_packet_task, qc, 0); |
4078 | break; | 4231 | break; |
4079 | 4232 | ||
4080 | case ATA_PROT_ATAPI_NODATA: | 4233 | case ATA_PROT_ATAPI_NODATA: |
4081 | ap->flags |= ATA_FLAG_NOINTR; | 4234 | ap->flags |= ATA_FLAG_NOINTR; |
4082 | ata_tf_to_host(ap, &qc->tf); | 4235 | ata_tf_to_host(ap, &qc->tf); |
4083 | ata_port_queue_task(ap, atapi_packet_task, ap, 0); | 4236 | ata_port_queue_task(ap, atapi_packet_task, qc, 0); |
4084 | break; | 4237 | break; |
4085 | 4238 | ||
4086 | case ATA_PROT_ATAPI_DMA: | 4239 | case ATA_PROT_ATAPI_DMA: |
4087 | ap->flags |= ATA_FLAG_NOINTR; | 4240 | ap->flags |= ATA_FLAG_NOINTR; |
4088 | ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ | 4241 | ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ |
4089 | ap->ops->bmdma_setup(qc); /* set up bmdma */ | 4242 | ap->ops->bmdma_setup(qc); /* set up bmdma */ |
4090 | ata_port_queue_task(ap, atapi_packet_task, ap, 0); | 4243 | ata_port_queue_task(ap, atapi_packet_task, qc, 0); |
4091 | break; | 4244 | break; |
4092 | 4245 | ||
4093 | default: | 4246 | default: |
@@ -4209,7 +4362,7 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs) | |||
4209 | 4362 | ||
4210 | ap = host_set->ports[i]; | 4363 | ap = host_set->ports[i]; |
4211 | if (ap && | 4364 | if (ap && |
4212 | !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { | 4365 | !(ap->flags & (ATA_FLAG_DISABLED | ATA_FLAG_NOINTR))) { |
4213 | struct ata_queued_cmd *qc; | 4366 | struct ata_queued_cmd *qc; |
4214 | 4367 | ||
4215 | qc = ata_qc_from_tag(ap, ap->active_tag); | 4368 | qc = ata_qc_from_tag(ap, ap->active_tag); |
@@ -4241,7 +4394,7 @@ static int ata_do_simple_cmd(struct ata_port *ap, struct ata_device *dev, | |||
4241 | tf.flags |= ATA_TFLAG_DEVICE; | 4394 | tf.flags |= ATA_TFLAG_DEVICE; |
4242 | tf.protocol = ATA_PROT_NODATA; | 4395 | tf.protocol = ATA_PROT_NODATA; |
4243 | 4396 | ||
4244 | err = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0); | 4397 | err = ata_exec_internal(ap, dev, &tf, NULL, DMA_NONE, NULL, 0); |
4245 | if (err) | 4398 | if (err) |
4246 | printk(KERN_ERR "%s: ata command failed: %d\n", | 4399 | printk(KERN_ERR "%s: ata command failed: %d\n", |
4247 | __FUNCTION__, err); | 4400 | __FUNCTION__, err); |
@@ -4287,10 +4440,12 @@ static int ata_start_drive(struct ata_port *ap, struct ata_device *dev) | |||
4287 | int ata_device_resume(struct ata_port *ap, struct ata_device *dev) | 4440 | int ata_device_resume(struct ata_port *ap, struct ata_device *dev) |
4288 | { | 4441 | { |
4289 | if (ap->flags & ATA_FLAG_SUSPENDED) { | 4442 | if (ap->flags & ATA_FLAG_SUSPENDED) { |
4443 | struct ata_device *failed_dev; | ||
4290 | ap->flags &= ~ATA_FLAG_SUSPENDED; | 4444 | ap->flags &= ~ATA_FLAG_SUSPENDED; |
4291 | ata_set_mode(ap); | 4445 | while (ata_set_mode(ap, &failed_dev)) |
4446 | ata_dev_disable(ap, failed_dev); | ||
4292 | } | 4447 | } |
4293 | if (!ata_dev_present(dev)) | 4448 | if (!ata_dev_enabled(dev)) |
4294 | return 0; | 4449 | return 0; |
4295 | if (dev->class == ATA_DEV_ATA) | 4450 | if (dev->class == ATA_DEV_ATA) |
4296 | ata_start_drive(ap, dev); | 4451 | ata_start_drive(ap, dev); |
@@ -4308,7 +4463,7 @@ int ata_device_resume(struct ata_port *ap, struct ata_device *dev) | |||
4308 | */ | 4463 | */ |
4309 | int ata_device_suspend(struct ata_port *ap, struct ata_device *dev, pm_message_t state) | 4464 | int ata_device_suspend(struct ata_port *ap, struct ata_device *dev, pm_message_t state) |
4310 | { | 4465 | { |
4311 | if (!ata_dev_present(dev)) | 4466 | if (!ata_dev_enabled(dev)) |
4312 | return 0; | 4467 | return 0; |
4313 | if (dev->class == ATA_DEV_ATA) | 4468 | if (dev->class == ATA_DEV_ATA) |
4314 | ata_flush_cache(ap, dev); | 4469 | ata_flush_cache(ap, dev); |
@@ -4428,7 +4583,7 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host, | |||
4428 | host->unique_id = ata_unique_id++; | 4583 | host->unique_id = ata_unique_id++; |
4429 | host->max_cmd_len = 12; | 4584 | host->max_cmd_len = 12; |
4430 | 4585 | ||
4431 | ap->flags = ATA_FLAG_PORT_DISABLED; | 4586 | ap->flags = ATA_FLAG_DISABLED; |
4432 | ap->id = host->unique_id; | 4587 | ap->id = host->unique_id; |
4433 | ap->host = host; | 4588 | ap->host = host; |
4434 | ap->ctl = ATA_DEVCTL_OBS; | 4589 | ap->ctl = ATA_DEVCTL_OBS; |
@@ -4443,6 +4598,7 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host, | |||
4443 | ap->flags |= ent->host_flags; | 4598 | ap->flags |= ent->host_flags; |
4444 | ap->ops = ent->port_ops; | 4599 | ap->ops = ent->port_ops; |
4445 | ap->cbl = ATA_CBL_NONE; | 4600 | ap->cbl = ATA_CBL_NONE; |
4601 | ap->sata_spd_limit = UINT_MAX; | ||
4446 | ap->active_tag = ATA_TAG_POISON; | 4602 | ap->active_tag = ATA_TAG_POISON; |
4447 | ap->last_ctl = 0xFF; | 4603 | ap->last_ctl = 0xFF; |
4448 | 4604 | ||
@@ -4898,7 +5054,6 @@ EXPORT_SYMBOL_GPL(ata_sg_init); | |||
4898 | EXPORT_SYMBOL_GPL(ata_sg_init_one); | 5054 | EXPORT_SYMBOL_GPL(ata_sg_init_one); |
4899 | EXPORT_SYMBOL_GPL(__ata_qc_complete); | 5055 | EXPORT_SYMBOL_GPL(__ata_qc_complete); |
4900 | EXPORT_SYMBOL_GPL(ata_qc_issue_prot); | 5056 | EXPORT_SYMBOL_GPL(ata_qc_issue_prot); |
4901 | EXPORT_SYMBOL_GPL(ata_eng_timeout); | ||
4902 | EXPORT_SYMBOL_GPL(ata_tf_load); | 5057 | EXPORT_SYMBOL_GPL(ata_tf_load); |
4903 | EXPORT_SYMBOL_GPL(ata_tf_read); | 5058 | EXPORT_SYMBOL_GPL(ata_tf_read); |
4904 | EXPORT_SYMBOL_GPL(ata_noop_dev_select); | 5059 | EXPORT_SYMBOL_GPL(ata_noop_dev_select); |
@@ -4944,8 +5099,6 @@ EXPORT_SYMBOL_GPL(ata_host_intr); | |||
4944 | EXPORT_SYMBOL_GPL(ata_id_string); | 5099 | EXPORT_SYMBOL_GPL(ata_id_string); |
4945 | EXPORT_SYMBOL_GPL(ata_id_c_string); | 5100 | EXPORT_SYMBOL_GPL(ata_id_c_string); |
4946 | EXPORT_SYMBOL_GPL(ata_scsi_simulate); | 5101 | EXPORT_SYMBOL_GPL(ata_scsi_simulate); |
4947 | EXPORT_SYMBOL_GPL(ata_eh_qc_complete); | ||
4948 | EXPORT_SYMBOL_GPL(ata_eh_qc_retry); | ||
4949 | 5102 | ||
4950 | EXPORT_SYMBOL_GPL(ata_pio_need_iordy); | 5103 | EXPORT_SYMBOL_GPL(ata_pio_need_iordy); |
4951 | EXPORT_SYMBOL_GPL(ata_timing_compute); | 5104 | EXPORT_SYMBOL_GPL(ata_timing_compute); |
@@ -4967,3 +5120,8 @@ EXPORT_SYMBOL_GPL(ata_device_suspend); | |||
4967 | EXPORT_SYMBOL_GPL(ata_device_resume); | 5120 | EXPORT_SYMBOL_GPL(ata_device_resume); |
4968 | EXPORT_SYMBOL_GPL(ata_scsi_device_suspend); | 5121 | EXPORT_SYMBOL_GPL(ata_scsi_device_suspend); |
4969 | EXPORT_SYMBOL_GPL(ata_scsi_device_resume); | 5122 | EXPORT_SYMBOL_GPL(ata_scsi_device_resume); |
5123 | |||
5124 | EXPORT_SYMBOL_GPL(ata_scsi_error); | ||
5125 | EXPORT_SYMBOL_GPL(ata_eng_timeout); | ||
5126 | EXPORT_SYMBOL_GPL(ata_eh_qc_complete); | ||
5127 | EXPORT_SYMBOL_GPL(ata_eh_qc_retry); | ||