aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/libata-eh.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ata/libata-eh.c')
-rw-r--r--drivers/ata/libata-eh.c299
1 files changed, 229 insertions, 70 deletions
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 21a81cd148e4..4e31071acc02 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -46,9 +46,26 @@
46#include "libata.h" 46#include "libata.h"
47 47
48enum { 48enum {
49 /* speed down verdicts */
49 ATA_EH_SPDN_NCQ_OFF = (1 << 0), 50 ATA_EH_SPDN_NCQ_OFF = (1 << 0),
50 ATA_EH_SPDN_SPEED_DOWN = (1 << 1), 51 ATA_EH_SPDN_SPEED_DOWN = (1 << 1),
51 ATA_EH_SPDN_FALLBACK_TO_PIO = (1 << 2), 52 ATA_EH_SPDN_FALLBACK_TO_PIO = (1 << 2),
53 ATA_EH_SPDN_KEEP_ERRORS = (1 << 3),
54
55 /* error flags */
56 ATA_EFLAG_IS_IO = (1 << 0),
57 ATA_EFLAG_DUBIOUS_XFER = (1 << 1),
58
59 /* error categories */
60 ATA_ECAT_NONE = 0,
61 ATA_ECAT_ATA_BUS = 1,
62 ATA_ECAT_TOUT_HSM = 2,
63 ATA_ECAT_UNK_DEV = 3,
64 ATA_ECAT_DUBIOUS_NONE = 4,
65 ATA_ECAT_DUBIOUS_ATA_BUS = 5,
66 ATA_ECAT_DUBIOUS_TOUT_HSM = 6,
67 ATA_ECAT_DUBIOUS_UNK_DEV = 7,
68 ATA_ECAT_NR = 8,
52}; 69};
53 70
54/* Waiting in ->prereset can never be reliable. It's sometimes nice 71/* Waiting in ->prereset can never be reliable. It's sometimes nice
@@ -213,12 +230,13 @@ void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset,
213 if (offset < 0) 230 if (offset < 0)
214 ata_port_desc(ap, "%s %s%llu@0x%llx", name, type, len, start); 231 ata_port_desc(ap, "%s %s%llu@0x%llx", name, type, len, start);
215 else 232 else
216 ata_port_desc(ap, "%s 0x%llx", name, start + offset); 233 ata_port_desc(ap, "%s 0x%llx", name,
234 start + (unsigned long long)offset);
217} 235}
218 236
219#endif /* CONFIG_PCI */ 237#endif /* CONFIG_PCI */
220 238
221static void ata_ering_record(struct ata_ering *ering, int is_io, 239static void ata_ering_record(struct ata_ering *ering, unsigned int eflags,
222 unsigned int err_mask) 240 unsigned int err_mask)
223{ 241{
224 struct ata_ering_entry *ent; 242 struct ata_ering_entry *ent;
@@ -229,11 +247,20 @@ static void ata_ering_record(struct ata_ering *ering, int is_io,
229 ering->cursor %= ATA_ERING_SIZE; 247 ering->cursor %= ATA_ERING_SIZE;
230 248
231 ent = &ering->ring[ering->cursor]; 249 ent = &ering->ring[ering->cursor];
232 ent->is_io = is_io; 250 ent->eflags = eflags;
233 ent->err_mask = err_mask; 251 ent->err_mask = err_mask;
234 ent->timestamp = get_jiffies_64(); 252 ent->timestamp = get_jiffies_64();
235} 253}
236 254
255static struct ata_ering_entry *ata_ering_top(struct ata_ering *ering)
256{
257 struct ata_ering_entry *ent = &ering->ring[ering->cursor];
258
259 if (ent->err_mask)
260 return ent;
261 return NULL;
262}
263
237static void ata_ering_clear(struct ata_ering *ering) 264static void ata_ering_clear(struct ata_ering *ering)
238{ 265{
239 memset(ering, 0, sizeof(*ering)); 266 memset(ering, 0, sizeof(*ering));
@@ -445,9 +472,20 @@ void ata_scsi_error(struct Scsi_Host *host)
445 spin_lock_irqsave(ap->lock, flags); 472 spin_lock_irqsave(ap->lock, flags);
446 473
447 __ata_port_for_each_link(link, ap) { 474 __ata_port_for_each_link(link, ap) {
475 struct ata_eh_context *ehc = &link->eh_context;
476 struct ata_device *dev;
477
448 memset(&link->eh_context, 0, sizeof(link->eh_context)); 478 memset(&link->eh_context, 0, sizeof(link->eh_context));
449 link->eh_context.i = link->eh_info; 479 link->eh_context.i = link->eh_info;
450 memset(&link->eh_info, 0, sizeof(link->eh_info)); 480 memset(&link->eh_info, 0, sizeof(link->eh_info));
481
482 ata_link_for_each_dev(dev, link) {
483 int devno = dev->devno;
484
485 ehc->saved_xfer_mode[devno] = dev->xfer_mode;
486 if (ata_ncq_enabled(dev))
487 ehc->saved_ncq_enabled |= 1 << devno;
488 }
451 } 489 }
452 490
453 ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS; 491 ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS;
@@ -1260,10 +1298,10 @@ static unsigned int atapi_eh_request_sense(struct ata_queued_cmd *qc)
1260 1298
1261 /* is it pointless to prefer PIO for "safety reasons"? */ 1299 /* is it pointless to prefer PIO for "safety reasons"? */
1262 if (ap->flags & ATA_FLAG_PIO_DMA) { 1300 if (ap->flags & ATA_FLAG_PIO_DMA) {
1263 tf.protocol = ATA_PROT_ATAPI_DMA; 1301 tf.protocol = ATAPI_PROT_DMA;
1264 tf.feature |= ATAPI_PKT_DMA; 1302 tf.feature |= ATAPI_PKT_DMA;
1265 } else { 1303 } else {
1266 tf.protocol = ATA_PROT_ATAPI; 1304 tf.protocol = ATAPI_PROT_PIO;
1267 tf.lbam = SCSI_SENSE_BUFFERSIZE; 1305 tf.lbam = SCSI_SENSE_BUFFERSIZE;
1268 tf.lbah = 0; 1306 tf.lbah = 0;
1269 } 1307 }
@@ -1451,20 +1489,29 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
1451 return action; 1489 return action;
1452} 1490}
1453 1491
1454static int ata_eh_categorize_error(int is_io, unsigned int err_mask) 1492static int ata_eh_categorize_error(unsigned int eflags, unsigned int err_mask,
1493 int *xfer_ok)
1455{ 1494{
1495 int base = 0;
1496
1497 if (!(eflags & ATA_EFLAG_DUBIOUS_XFER))
1498 *xfer_ok = 1;
1499
1500 if (!*xfer_ok)
1501 base = ATA_ECAT_DUBIOUS_NONE;
1502
1456 if (err_mask & AC_ERR_ATA_BUS) 1503 if (err_mask & AC_ERR_ATA_BUS)
1457 return 1; 1504 return base + ATA_ECAT_ATA_BUS;
1458 1505
1459 if (err_mask & AC_ERR_TIMEOUT) 1506 if (err_mask & AC_ERR_TIMEOUT)
1460 return 2; 1507 return base + ATA_ECAT_TOUT_HSM;
1461 1508
1462 if (is_io) { 1509 if (eflags & ATA_EFLAG_IS_IO) {
1463 if (err_mask & AC_ERR_HSM) 1510 if (err_mask & AC_ERR_HSM)
1464 return 2; 1511 return base + ATA_ECAT_TOUT_HSM;
1465 if ((err_mask & 1512 if ((err_mask &
1466 (AC_ERR_DEV|AC_ERR_MEDIA|AC_ERR_INVALID)) == AC_ERR_DEV) 1513 (AC_ERR_DEV|AC_ERR_MEDIA|AC_ERR_INVALID)) == AC_ERR_DEV)
1467 return 3; 1514 return base + ATA_ECAT_UNK_DEV;
1468 } 1515 }
1469 1516
1470 return 0; 1517 return 0;
@@ -1472,18 +1519,22 @@ static int ata_eh_categorize_error(int is_io, unsigned int err_mask)
1472 1519
1473struct speed_down_verdict_arg { 1520struct speed_down_verdict_arg {
1474 u64 since; 1521 u64 since;
1475 int nr_errors[4]; 1522 int xfer_ok;
1523 int nr_errors[ATA_ECAT_NR];
1476}; 1524};
1477 1525
1478static int speed_down_verdict_cb(struct ata_ering_entry *ent, void *void_arg) 1526static int speed_down_verdict_cb(struct ata_ering_entry *ent, void *void_arg)
1479{ 1527{
1480 struct speed_down_verdict_arg *arg = void_arg; 1528 struct speed_down_verdict_arg *arg = void_arg;
1481 int cat = ata_eh_categorize_error(ent->is_io, ent->err_mask); 1529 int cat;
1482 1530
1483 if (ent->timestamp < arg->since) 1531 if (ent->timestamp < arg->since)
1484 return -1; 1532 return -1;
1485 1533
1534 cat = ata_eh_categorize_error(ent->eflags, ent->err_mask,
1535 &arg->xfer_ok);
1486 arg->nr_errors[cat]++; 1536 arg->nr_errors[cat]++;
1537
1487 return 0; 1538 return 0;
1488} 1539}
1489 1540
@@ -1495,22 +1546,48 @@ static int speed_down_verdict_cb(struct ata_ering_entry *ent, void *void_arg)
1495 * whether NCQ needs to be turned off, transfer speed should be 1546 * whether NCQ needs to be turned off, transfer speed should be
1496 * stepped down, or falling back to PIO is necessary. 1547 * stepped down, or falling back to PIO is necessary.
1497 * 1548 *
1498 * Cat-1 is ATA_BUS error for any command. 1549 * ECAT_ATA_BUS : ATA_BUS error for any command
1550 *
1551 * ECAT_TOUT_HSM : TIMEOUT for any command or HSM violation for
1552 * IO commands
1553 *
1554 * ECAT_UNK_DEV : Unknown DEV error for IO commands
1555 *
1556 * ECAT_DUBIOUS_* : Identical to above three but occurred while
1557 * data transfer hasn't been verified.
1558 *
1559 * Verdicts are
1560 *
1561 * NCQ_OFF : Turn off NCQ.
1562 *
1563 * SPEED_DOWN : Speed down transfer speed but don't fall back
1564 * to PIO.
1565 *
1566 * FALLBACK_TO_PIO : Fall back to PIO.
1567 *
1568 * Even if multiple verdicts are returned, only one action is
1569 * taken per error. An action triggered by non-DUBIOUS errors
1570 * clears ering, while one triggered by DUBIOUS_* errors doesn't.
1571 * This is to expedite speed down decisions right after device is
1572 * initially configured.
1499 * 1573 *
1500 * Cat-2 is TIMEOUT for any command or HSM violation for known 1574 * The followings are speed down rules. #1 and #2 deal with
1501 * supported commands. 1575 * DUBIOUS errors.
1502 * 1576 *
1503 * Cat-3 is is unclassified DEV error for known supported 1577 * 1. If more than one DUBIOUS_ATA_BUS or DUBIOUS_TOUT_HSM errors
1504 * command. 1578 * occurred during last 5 mins, SPEED_DOWN and FALLBACK_TO_PIO.
1505 * 1579 *
1506 * NCQ needs to be turned off if there have been more than 3 1580 * 2. If more than one DUBIOUS_TOUT_HSM or DUBIOUS_UNK_DEV errors
1507 * Cat-2 + Cat-3 errors during last 10 minutes. 1581 * occurred during last 5 mins, NCQ_OFF.
1508 * 1582 *
1509 * Speed down is necessary if there have been more than 3 Cat-1 + 1583 * 3. If more than 8 ATA_BUS, TOUT_HSM or UNK_DEV errors
1510 * Cat-2 errors or 10 Cat-3 errors during last 10 minutes. 1584 * ocurred during last 5 mins, FALLBACK_TO_PIO
1511 * 1585 *
1512 * Falling back to PIO mode is necessary if there have been more 1586 * 4. If more than 3 TOUT_HSM or UNK_DEV errors occurred
1513 * than 10 Cat-1 + Cat-2 + Cat-3 errors during last 5 minutes. 1587 * during last 10 mins, NCQ_OFF.
1588 *
1589 * 5. If more than 3 ATA_BUS or TOUT_HSM errors, or more than 6
1590 * UNK_DEV errors occurred during last 10 mins, SPEED_DOWN.
1514 * 1591 *
1515 * LOCKING: 1592 * LOCKING:
1516 * Inherited from caller. 1593 * Inherited from caller.
@@ -1525,23 +1602,38 @@ static unsigned int ata_eh_speed_down_verdict(struct ata_device *dev)
1525 struct speed_down_verdict_arg arg; 1602 struct speed_down_verdict_arg arg;
1526 unsigned int verdict = 0; 1603 unsigned int verdict = 0;
1527 1604
1528 /* scan past 10 mins of error history */ 1605 /* scan past 5 mins of error history */
1529 memset(&arg, 0, sizeof(arg)); 1606 memset(&arg, 0, sizeof(arg));
1530 arg.since = j64 - min(j64, j10mins); 1607 arg.since = j64 - min(j64, j5mins);
1531 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); 1608 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg);
1532 1609
1533 if (arg.nr_errors[2] + arg.nr_errors[3] > 3) 1610 if (arg.nr_errors[ATA_ECAT_DUBIOUS_ATA_BUS] +
1534 verdict |= ATA_EH_SPDN_NCQ_OFF; 1611 arg.nr_errors[ATA_ECAT_DUBIOUS_TOUT_HSM] > 1)
1535 if (arg.nr_errors[1] + arg.nr_errors[2] > 3 || arg.nr_errors[3] > 10) 1612 verdict |= ATA_EH_SPDN_SPEED_DOWN |
1536 verdict |= ATA_EH_SPDN_SPEED_DOWN; 1613 ATA_EH_SPDN_FALLBACK_TO_PIO | ATA_EH_SPDN_KEEP_ERRORS;
1537 1614
1538 /* scan past 3 mins of error history */ 1615 if (arg.nr_errors[ATA_ECAT_DUBIOUS_TOUT_HSM] +
1616 arg.nr_errors[ATA_ECAT_DUBIOUS_UNK_DEV] > 1)
1617 verdict |= ATA_EH_SPDN_NCQ_OFF | ATA_EH_SPDN_KEEP_ERRORS;
1618
1619 if (arg.nr_errors[ATA_ECAT_ATA_BUS] +
1620 arg.nr_errors[ATA_ECAT_TOUT_HSM] +
1621 arg.nr_errors[ATA_ECAT_UNK_DEV] > 6)
1622 verdict |= ATA_EH_SPDN_FALLBACK_TO_PIO;
1623
1624 /* scan past 10 mins of error history */
1539 memset(&arg, 0, sizeof(arg)); 1625 memset(&arg, 0, sizeof(arg));
1540 arg.since = j64 - min(j64, j5mins); 1626 arg.since = j64 - min(j64, j10mins);
1541 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); 1627 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg);
1542 1628
1543 if (arg.nr_errors[1] + arg.nr_errors[2] + arg.nr_errors[3] > 10) 1629 if (arg.nr_errors[ATA_ECAT_TOUT_HSM] +
1544 verdict |= ATA_EH_SPDN_FALLBACK_TO_PIO; 1630 arg.nr_errors[ATA_ECAT_UNK_DEV] > 3)
1631 verdict |= ATA_EH_SPDN_NCQ_OFF;
1632
1633 if (arg.nr_errors[ATA_ECAT_ATA_BUS] +
1634 arg.nr_errors[ATA_ECAT_TOUT_HSM] > 3 ||
1635 arg.nr_errors[ATA_ECAT_UNK_DEV] > 6)
1636 verdict |= ATA_EH_SPDN_SPEED_DOWN;
1545 1637
1546 return verdict; 1638 return verdict;
1547} 1639}
@@ -1549,7 +1641,7 @@ static unsigned int ata_eh_speed_down_verdict(struct ata_device *dev)
1549/** 1641/**
1550 * ata_eh_speed_down - record error and speed down if necessary 1642 * ata_eh_speed_down - record error and speed down if necessary
1551 * @dev: Failed device 1643 * @dev: Failed device
1552 * @is_io: Did the device fail during normal IO? 1644 * @eflags: mask of ATA_EFLAG_* flags
1553 * @err_mask: err_mask of the error 1645 * @err_mask: err_mask of the error
1554 * 1646 *
1555 * Record error and examine error history to determine whether 1647 * Record error and examine error history to determine whether
@@ -1563,18 +1655,20 @@ static unsigned int ata_eh_speed_down_verdict(struct ata_device *dev)
1563 * RETURNS: 1655 * RETURNS:
1564 * Determined recovery action. 1656 * Determined recovery action.
1565 */ 1657 */
1566static unsigned int ata_eh_speed_down(struct ata_device *dev, int is_io, 1658static unsigned int ata_eh_speed_down(struct ata_device *dev,
1567 unsigned int err_mask) 1659 unsigned int eflags, unsigned int err_mask)
1568{ 1660{
1661 struct ata_link *link = dev->link;
1662 int xfer_ok = 0;
1569 unsigned int verdict; 1663 unsigned int verdict;
1570 unsigned int action = 0; 1664 unsigned int action = 0;
1571 1665
1572 /* don't bother if Cat-0 error */ 1666 /* don't bother if Cat-0 error */
1573 if (ata_eh_categorize_error(is_io, err_mask) == 0) 1667 if (ata_eh_categorize_error(eflags, err_mask, &xfer_ok) == 0)
1574 return 0; 1668 return 0;
1575 1669
1576 /* record error and determine whether speed down is necessary */ 1670 /* record error and determine whether speed down is necessary */
1577 ata_ering_record(&dev->ering, is_io, err_mask); 1671 ata_ering_record(&dev->ering, eflags, err_mask);
1578 verdict = ata_eh_speed_down_verdict(dev); 1672 verdict = ata_eh_speed_down_verdict(dev);
1579 1673
1580 /* turn off NCQ? */ 1674 /* turn off NCQ? */
@@ -1590,7 +1684,7 @@ static unsigned int ata_eh_speed_down(struct ata_device *dev, int is_io,
1590 /* speed down? */ 1684 /* speed down? */
1591 if (verdict & ATA_EH_SPDN_SPEED_DOWN) { 1685 if (verdict & ATA_EH_SPDN_SPEED_DOWN) {
1592 /* speed down SATA link speed if possible */ 1686 /* speed down SATA link speed if possible */
1593 if (sata_down_spd_limit(dev->link) == 0) { 1687 if (sata_down_spd_limit(link) == 0) {
1594 action |= ATA_EH_HARDRESET; 1688 action |= ATA_EH_HARDRESET;
1595 goto done; 1689 goto done;
1596 } 1690 }
@@ -1618,10 +1712,10 @@ static unsigned int ata_eh_speed_down(struct ata_device *dev, int is_io,
1618 } 1712 }
1619 1713
1620 /* Fall back to PIO? Slowing down to PIO is meaningless for 1714 /* Fall back to PIO? Slowing down to PIO is meaningless for
1621 * SATA. Consider it only for PATA. 1715 * SATA ATA devices. Consider it only for PATA and SATAPI.
1622 */ 1716 */
1623 if ((verdict & ATA_EH_SPDN_FALLBACK_TO_PIO) && (dev->spdn_cnt >= 2) && 1717 if ((verdict & ATA_EH_SPDN_FALLBACK_TO_PIO) && (dev->spdn_cnt >= 2) &&
1624 (dev->link->ap->cbl != ATA_CBL_SATA) && 1718 (link->ap->cbl != ATA_CBL_SATA || dev->class == ATA_DEV_ATAPI) &&
1625 (dev->xfer_shift != ATA_SHIFT_PIO)) { 1719 (dev->xfer_shift != ATA_SHIFT_PIO)) {
1626 if (ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO) == 0) { 1720 if (ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO) == 0) {
1627 dev->spdn_cnt = 0; 1721 dev->spdn_cnt = 0;
@@ -1633,7 +1727,8 @@ static unsigned int ata_eh_speed_down(struct ata_device *dev, int is_io,
1633 return 0; 1727 return 0;
1634 done: 1728 done:
1635 /* device has been slowed down, blow error history */ 1729 /* device has been slowed down, blow error history */
1636 ata_ering_clear(&dev->ering); 1730 if (!(verdict & ATA_EH_SPDN_KEEP_ERRORS))
1731 ata_ering_clear(&dev->ering);
1637 return action; 1732 return action;
1638} 1733}
1639 1734
@@ -1653,8 +1748,8 @@ static void ata_eh_link_autopsy(struct ata_link *link)
1653 struct ata_port *ap = link->ap; 1748 struct ata_port *ap = link->ap;
1654 struct ata_eh_context *ehc = &link->eh_context; 1749 struct ata_eh_context *ehc = &link->eh_context;
1655 struct ata_device *dev; 1750 struct ata_device *dev;
1656 unsigned int all_err_mask = 0; 1751 unsigned int all_err_mask = 0, eflags = 0;
1657 int tag, is_io = 0; 1752 int tag;
1658 u32 serror; 1753 u32 serror;
1659 int rc; 1754 int rc;
1660 1755
@@ -1713,15 +1808,15 @@ static void ata_eh_link_autopsy(struct ata_link *link)
1713 ehc->i.dev = qc->dev; 1808 ehc->i.dev = qc->dev;
1714 all_err_mask |= qc->err_mask; 1809 all_err_mask |= qc->err_mask;
1715 if (qc->flags & ATA_QCFLAG_IO) 1810 if (qc->flags & ATA_QCFLAG_IO)
1716 is_io = 1; 1811 eflags |= ATA_EFLAG_IS_IO;
1717 } 1812 }
1718 1813
1719 /* enforce default EH actions */ 1814 /* enforce default EH actions */
1720 if (ap->pflags & ATA_PFLAG_FROZEN || 1815 if (ap->pflags & ATA_PFLAG_FROZEN ||
1721 all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT)) 1816 all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT))
1722 ehc->i.action |= ATA_EH_SOFTRESET; 1817 ehc->i.action |= ATA_EH_SOFTRESET;
1723 else if ((is_io && all_err_mask) || 1818 else if (((eflags & ATA_EFLAG_IS_IO) && all_err_mask) ||
1724 (!is_io && (all_err_mask & ~AC_ERR_DEV))) 1819 (!(eflags & ATA_EFLAG_IS_IO) && (all_err_mask & ~AC_ERR_DEV)))
1725 ehc->i.action |= ATA_EH_REVALIDATE; 1820 ehc->i.action |= ATA_EH_REVALIDATE;
1726 1821
1727 /* If we have offending qcs and the associated failed device, 1822 /* If we have offending qcs and the associated failed device,
@@ -1743,8 +1838,11 @@ static void ata_eh_link_autopsy(struct ata_link *link)
1743 ata_dev_enabled(link->device)))) 1838 ata_dev_enabled(link->device))))
1744 dev = link->device; 1839 dev = link->device;
1745 1840
1746 if (dev) 1841 if (dev) {
1747 ehc->i.action |= ata_eh_speed_down(dev, is_io, all_err_mask); 1842 if (dev->flags & ATA_DFLAG_DUBIOUS_XFER)
1843 eflags |= ATA_EFLAG_DUBIOUS_XFER;
1844 ehc->i.action |= ata_eh_speed_down(dev, eflags, all_err_mask);
1845 }
1748 1846
1749 DPRINTK("EXIT\n"); 1847 DPRINTK("EXIT\n");
1750} 1848}
@@ -1880,8 +1978,8 @@ static void ata_eh_link_report(struct ata_link *link)
1880 [ATA_PROT_PIO] = "pio", 1978 [ATA_PROT_PIO] = "pio",
1881 [ATA_PROT_DMA] = "dma", 1979 [ATA_PROT_DMA] = "dma",
1882 [ATA_PROT_NCQ] = "ncq", 1980 [ATA_PROT_NCQ] = "ncq",
1883 [ATA_PROT_ATAPI] = "pio", 1981 [ATAPI_PROT_PIO] = "pio",
1884 [ATA_PROT_ATAPI_DMA] = "dma", 1982 [ATAPI_PROT_DMA] = "dma",
1885 }; 1983 };
1886 1984
1887 snprintf(data_buf, sizeof(data_buf), " %s %u %s", 1985 snprintf(data_buf, sizeof(data_buf), " %s %u %s",
@@ -1889,7 +1987,7 @@ static void ata_eh_link_report(struct ata_link *link)
1889 dma_str[qc->dma_dir]); 1987 dma_str[qc->dma_dir]);
1890 } 1988 }
1891 1989
1892 if (is_atapi_taskfile(&qc->tf)) 1990 if (ata_is_atapi(qc->tf.protocol))
1893 snprintf(cdb_buf, sizeof(cdb_buf), 1991 snprintf(cdb_buf, sizeof(cdb_buf),
1894 "cdb %02x %02x %02x %02x %02x %02x %02x %02x " 1992 "cdb %02x %02x %02x %02x %02x %02x %02x %02x "
1895 "%02x %02x %02x %02x %02x %02x %02x %02x\n ", 1993 "%02x %02x %02x %02x %02x %02x %02x %02x\n ",
@@ -2329,6 +2427,58 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
2329 return rc; 2427 return rc;
2330} 2428}
2331 2429
2430/**
2431 * ata_set_mode - Program timings and issue SET FEATURES - XFER
2432 * @link: link on which timings will be programmed
2433 * @r_failed_dev: out paramter for failed device
2434 *
2435 * Set ATA device disk transfer mode (PIO3, UDMA6, etc.). If
2436 * ata_set_mode() fails, pointer to the failing device is
2437 * returned in @r_failed_dev.
2438 *
2439 * LOCKING:
2440 * PCI/etc. bus probe sem.
2441 *
2442 * RETURNS:
2443 * 0 on success, negative errno otherwise
2444 */
2445int ata_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
2446{
2447 struct ata_port *ap = link->ap;
2448 struct ata_device *dev;
2449 int rc;
2450
2451 /* if data transfer is verified, clear DUBIOUS_XFER on ering top */
2452 ata_link_for_each_dev(dev, link) {
2453 if (!(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) {
2454 struct ata_ering_entry *ent;
2455
2456 ent = ata_ering_top(&dev->ering);
2457 if (ent)
2458 ent->eflags &= ~ATA_EFLAG_DUBIOUS_XFER;
2459 }
2460 }
2461
2462 /* has private set_mode? */
2463 if (ap->ops->set_mode)
2464 rc = ap->ops->set_mode(link, r_failed_dev);
2465 else
2466 rc = ata_do_set_mode(link, r_failed_dev);
2467
2468 /* if transfer mode has changed, set DUBIOUS_XFER on device */
2469 ata_link_for_each_dev(dev, link) {
2470 struct ata_eh_context *ehc = &link->eh_context;
2471 u8 saved_xfer_mode = ehc->saved_xfer_mode[dev->devno];
2472 u8 saved_ncq = !!(ehc->saved_ncq_enabled & (1 << dev->devno));
2473
2474 if (dev->xfer_mode != saved_xfer_mode ||
2475 ata_ncq_enabled(dev) != saved_ncq)
2476 dev->flags |= ATA_DFLAG_DUBIOUS_XFER;
2477 }
2478
2479 return rc;
2480}
2481
2332static int ata_link_nr_enabled(struct ata_link *link) 2482static int ata_link_nr_enabled(struct ata_link *link)
2333{ 2483{
2334 struct ata_device *dev; 2484 struct ata_device *dev;
@@ -2375,6 +2525,24 @@ static int ata_eh_skip_recovery(struct ata_link *link)
2375 return 1; 2525 return 1;
2376} 2526}
2377 2527
2528static int ata_eh_schedule_probe(struct ata_device *dev)
2529{
2530 struct ata_eh_context *ehc = &dev->link->eh_context;
2531
2532 if (!(ehc->i.probe_mask & (1 << dev->devno)) ||
2533 (ehc->did_probe_mask & (1 << dev->devno)))
2534 return 0;
2535
2536 ata_eh_detach_dev(dev);
2537 ata_dev_init(dev);
2538 ehc->did_probe_mask |= (1 << dev->devno);
2539 ehc->i.action |= ATA_EH_SOFTRESET;
2540 ehc->saved_xfer_mode[dev->devno] = 0;
2541 ehc->saved_ncq_enabled &= ~(1 << dev->devno);
2542
2543 return 1;
2544}
2545
2378static int ata_eh_handle_dev_fail(struct ata_device *dev, int err) 2546static int ata_eh_handle_dev_fail(struct ata_device *dev, int err)
2379{ 2547{
2380 struct ata_eh_context *ehc = &dev->link->eh_context; 2548 struct ata_eh_context *ehc = &dev->link->eh_context;
@@ -2406,16 +2574,9 @@ static int ata_eh_handle_dev_fail(struct ata_device *dev, int err)
2406 if (ata_link_offline(dev->link)) 2574 if (ata_link_offline(dev->link))
2407 ata_eh_detach_dev(dev); 2575 ata_eh_detach_dev(dev);
2408 2576
2409 /* probe if requested */ 2577 /* schedule probe if necessary */
2410 if ((ehc->i.probe_mask & (1 << dev->devno)) && 2578 if (ata_eh_schedule_probe(dev))
2411 !(ehc->did_probe_mask & (1 << dev->devno))) {
2412 ata_eh_detach_dev(dev);
2413 ata_dev_init(dev);
2414
2415 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; 2579 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
2416 ehc->did_probe_mask |= (1 << dev->devno);
2417 ehc->i.action |= ATA_EH_SOFTRESET;
2418 }
2419 2580
2420 return 1; 2581 return 1;
2421 } else { 2582 } else {
@@ -2492,14 +2653,9 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
2492 if (dev->flags & ATA_DFLAG_DETACH) 2653 if (dev->flags & ATA_DFLAG_DETACH)
2493 ata_eh_detach_dev(dev); 2654 ata_eh_detach_dev(dev);
2494 2655
2495 if (!ata_dev_enabled(dev) && 2656 /* schedule probe if necessary */
2496 ((ehc->i.probe_mask & (1 << dev->devno)) && 2657 if (!ata_dev_enabled(dev))
2497 !(ehc->did_probe_mask & (1 << dev->devno)))) { 2658 ata_eh_schedule_probe(dev);
2498 ata_eh_detach_dev(dev);
2499 ata_dev_init(dev);
2500 ehc->did_probe_mask |= (1 << dev->devno);
2501 ehc->i.action |= ATA_EH_SOFTRESET;
2502 }
2503 } 2659 }
2504 } 2660 }
2505 2661
@@ -2747,6 +2903,7 @@ static void ata_eh_handle_port_suspend(struct ata_port *ap)
2747 if (ap->ops->port_suspend) 2903 if (ap->ops->port_suspend)
2748 rc = ap->ops->port_suspend(ap, ap->pm_mesg); 2904 rc = ap->ops->port_suspend(ap, ap->pm_mesg);
2749 2905
2906 ata_acpi_set_state(ap, PMSG_SUSPEND);
2750 out: 2907 out:
2751 /* report result */ 2908 /* report result */
2752 spin_lock_irqsave(ap->lock, flags); 2909 spin_lock_irqsave(ap->lock, flags);
@@ -2792,6 +2949,8 @@ static void ata_eh_handle_port_resume(struct ata_port *ap)
2792 2949
2793 WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED)); 2950 WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
2794 2951
2952 ata_acpi_set_state(ap, PMSG_ON);
2953
2795 if (ap->ops->port_resume) 2954 if (ap->ops->port_resume)
2796 rc = ap->ops->port_resume(ap); 2955 rc = ap->ops->port_resume(ap);
2797 2956