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.c225
1 files changed, 97 insertions, 128 deletions
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index a5830329eda4..d94359a24d41 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -873,9 +873,9 @@ int sata_async_notification(struct ata_port *ap)
873 if (rc == 0) 873 if (rc == 0)
874 sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf); 874 sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf);
875 875
876 if (!ap->nr_pmp_links || rc) { 876 if (!sata_pmp_attached(ap) || rc) {
877 /* PMP is not attached or SNTF is not available */ 877 /* PMP is not attached or SNTF is not available */
878 if (!ap->nr_pmp_links) { 878 if (!sata_pmp_attached(ap)) {
879 /* PMP is not attached. Check whether ATAPI 879 /* PMP is not attached. Check whether ATAPI
880 * AN is configured. If so, notify media 880 * AN is configured. If so, notify media
881 * change. 881 * change.
@@ -1079,19 +1079,6 @@ void ata_eh_about_to_do(struct ata_link *link, struct ata_device *dev,
1079 1079
1080 spin_lock_irqsave(ap->lock, flags); 1080 spin_lock_irqsave(ap->lock, flags);
1081 1081
1082 /* Reset is represented by combination of actions and EHI
1083 * flags. Suck in all related bits before clearing eh_info to
1084 * avoid losing requested action.
1085 */
1086 if (action & ATA_EH_RESET_MASK) {
1087 ehc->i.action |= ehi->action & ATA_EH_RESET_MASK;
1088 ehc->i.flags |= ehi->flags & ATA_EHI_RESET_MODIFIER_MASK;
1089
1090 /* make sure all reset actions are cleared & clear EHI flags */
1091 action |= ATA_EH_RESET_MASK;
1092 ehi->flags &= ~ATA_EHI_RESET_MODIFIER_MASK;
1093 }
1094
1095 ata_eh_clear_action(link, dev, ehi, action); 1082 ata_eh_clear_action(link, dev, ehi, action);
1096 1083
1097 if (!(ehc->i.flags & ATA_EHI_QUIET)) 1084 if (!(ehc->i.flags & ATA_EHI_QUIET))
@@ -1117,12 +1104,6 @@ void ata_eh_done(struct ata_link *link, struct ata_device *dev,
1117{ 1104{
1118 struct ata_eh_context *ehc = &link->eh_context; 1105 struct ata_eh_context *ehc = &link->eh_context;
1119 1106
1120 /* if reset is complete, clear all reset actions & reset modifier */
1121 if (action & ATA_EH_RESET_MASK) {
1122 action |= ATA_EH_RESET_MASK;
1123 ehc->i.flags &= ~ATA_EHI_RESET_MODIFIER_MASK;
1124 }
1125
1126 ata_eh_clear_action(link, dev, &ehc->i, action); 1107 ata_eh_clear_action(link, dev, &ehc->i, action);
1127} 1108}
1128 1109
@@ -1329,20 +1310,20 @@ static void ata_eh_analyze_serror(struct ata_link *link)
1329 1310
1330 if (serror & SERR_PERSISTENT) { 1311 if (serror & SERR_PERSISTENT) {
1331 err_mask |= AC_ERR_ATA_BUS; 1312 err_mask |= AC_ERR_ATA_BUS;
1332 action |= ATA_EH_HARDRESET; 1313 action |= ATA_EH_RESET;
1333 } 1314 }
1334 if (serror & 1315 if (serror &
1335 (SERR_DATA_RECOVERED | SERR_COMM_RECOVERED | SERR_DATA)) { 1316 (SERR_DATA_RECOVERED | SERR_COMM_RECOVERED | SERR_DATA)) {
1336 err_mask |= AC_ERR_ATA_BUS; 1317 err_mask |= AC_ERR_ATA_BUS;
1337 action |= ATA_EH_SOFTRESET; 1318 action |= ATA_EH_RESET;
1338 } 1319 }
1339 if (serror & SERR_PROTOCOL) { 1320 if (serror & SERR_PROTOCOL) {
1340 err_mask |= AC_ERR_HSM; 1321 err_mask |= AC_ERR_HSM;
1341 action |= ATA_EH_SOFTRESET; 1322 action |= ATA_EH_RESET;
1342 } 1323 }
1343 if (serror & SERR_INTERNAL) { 1324 if (serror & SERR_INTERNAL) {
1344 err_mask |= AC_ERR_SYSTEM; 1325 err_mask |= AC_ERR_SYSTEM;
1345 action |= ATA_EH_HARDRESET; 1326 action |= ATA_EH_RESET;
1346 } 1327 }
1347 1328
1348 /* Determine whether a hotplug event has occurred. Both 1329 /* Determine whether a hotplug event has occurred. Both
@@ -1448,7 +1429,7 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
1448 1429
1449 if ((stat & (ATA_BUSY | ATA_DRQ | ATA_DRDY)) != ATA_DRDY) { 1430 if ((stat & (ATA_BUSY | ATA_DRQ | ATA_DRDY)) != ATA_DRDY) {
1450 qc->err_mask |= AC_ERR_HSM; 1431 qc->err_mask |= AC_ERR_HSM;
1451 return ATA_EH_SOFTRESET; 1432 return ATA_EH_RESET;
1452 } 1433 }
1453 1434
1454 if (stat & (ATA_ERR | ATA_DF)) 1435 if (stat & (ATA_ERR | ATA_DF))
@@ -1484,7 +1465,7 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
1484 } 1465 }
1485 1466
1486 if (qc->err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT | AC_ERR_ATA_BUS)) 1467 if (qc->err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT | AC_ERR_ATA_BUS))
1487 action |= ATA_EH_SOFTRESET; 1468 action |= ATA_EH_RESET;
1488 1469
1489 return action; 1470 return action;
1490} 1471}
@@ -1685,7 +1666,7 @@ static unsigned int ata_eh_speed_down(struct ata_device *dev,
1685 if (verdict & ATA_EH_SPDN_SPEED_DOWN) { 1666 if (verdict & ATA_EH_SPDN_SPEED_DOWN) {
1686 /* speed down SATA link speed if possible */ 1667 /* speed down SATA link speed if possible */
1687 if (sata_down_spd_limit(link) == 0) { 1668 if (sata_down_spd_limit(link) == 0) {
1688 action |= ATA_EH_HARDRESET; 1669 action |= ATA_EH_RESET;
1689 goto done; 1670 goto done;
1690 } 1671 }
1691 1672
@@ -1705,7 +1686,7 @@ static unsigned int ata_eh_speed_down(struct ata_device *dev,
1705 dev->spdn_cnt++; 1686 dev->spdn_cnt++;
1706 1687
1707 if (ata_down_xfermask_limit(dev, sel) == 0) { 1688 if (ata_down_xfermask_limit(dev, sel) == 0) {
1708 action |= ATA_EH_SOFTRESET; 1689 action |= ATA_EH_RESET;
1709 goto done; 1690 goto done;
1710 } 1691 }
1711 } 1692 }
@@ -1719,7 +1700,7 @@ static unsigned int ata_eh_speed_down(struct ata_device *dev,
1719 (dev->xfer_shift != ATA_SHIFT_PIO)) { 1700 (dev->xfer_shift != ATA_SHIFT_PIO)) {
1720 if (ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO) == 0) { 1701 if (ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO) == 0) {
1721 dev->spdn_cnt = 0; 1702 dev->spdn_cnt = 0;
1722 action |= ATA_EH_SOFTRESET; 1703 action |= ATA_EH_RESET;
1723 goto done; 1704 goto done;
1724 } 1705 }
1725 } 1706 }
@@ -1764,9 +1745,9 @@ static void ata_eh_link_autopsy(struct ata_link *link)
1764 ehc->i.serror |= serror; 1745 ehc->i.serror |= serror;
1765 ata_eh_analyze_serror(link); 1746 ata_eh_analyze_serror(link);
1766 } else if (rc != -EOPNOTSUPP) { 1747 } else if (rc != -EOPNOTSUPP) {
1767 /* SError read failed, force hardreset and probing */ 1748 /* SError read failed, force reset and probing */
1768 ata_ehi_schedule_probe(&ehc->i); 1749 ehc->i.probe_mask |= ATA_ALL_DEVICES;
1769 ehc->i.action |= ATA_EH_HARDRESET; 1750 ehc->i.action |= ATA_EH_RESET;
1770 ehc->i.err_mask |= AC_ERR_OTHER; 1751 ehc->i.err_mask |= AC_ERR_OTHER;
1771 } 1752 }
1772 1753
@@ -1804,6 +1785,11 @@ static void ata_eh_link_autopsy(struct ata_link *link)
1804 if (qc->flags & ATA_QCFLAG_SENSE_VALID) 1785 if (qc->flags & ATA_QCFLAG_SENSE_VALID)
1805 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER); 1786 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER);
1806 1787
1788 /* determine whether the command is worth retrying */
1789 if (!(qc->err_mask & AC_ERR_INVALID) &&
1790 ((qc->flags & ATA_QCFLAG_IO) || qc->err_mask != AC_ERR_DEV))
1791 qc->flags |= ATA_QCFLAG_RETRY;
1792
1807 /* accumulate error info */ 1793 /* accumulate error info */
1808 ehc->i.dev = qc->dev; 1794 ehc->i.dev = qc->dev;
1809 all_err_mask |= qc->err_mask; 1795 all_err_mask |= qc->err_mask;
@@ -1814,7 +1800,7 @@ static void ata_eh_link_autopsy(struct ata_link *link)
1814 /* enforce default EH actions */ 1800 /* enforce default EH actions */
1815 if (ap->pflags & ATA_PFLAG_FROZEN || 1801 if (ap->pflags & ATA_PFLAG_FROZEN ||
1816 all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT)) 1802 all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT))
1817 ehc->i.action |= ATA_EH_SOFTRESET; 1803 ehc->i.action |= ATA_EH_RESET;
1818 else if (((eflags & ATA_EFLAG_IS_IO) && all_err_mask) || 1804 else if (((eflags & ATA_EFLAG_IS_IO) && all_err_mask) ||
1819 (!(eflags & ATA_EFLAG_IS_IO) && (all_err_mask & ~AC_ERR_DEV))) 1805 (!(eflags & ATA_EFLAG_IS_IO) && (all_err_mask & ~AC_ERR_DEV)))
1820 ehc->i.action |= ATA_EH_REVALIDATE; 1806 ehc->i.action |= ATA_EH_REVALIDATE;
@@ -1867,7 +1853,7 @@ void ata_eh_autopsy(struct ata_port *ap)
1867 /* Autopsy of fanout ports can affect host link autopsy. 1853 /* Autopsy of fanout ports can affect host link autopsy.
1868 * Perform host link autopsy last. 1854 * Perform host link autopsy last.
1869 */ 1855 */
1870 if (ap->nr_pmp_links) 1856 if (sata_pmp_attached(ap))
1871 ata_eh_link_autopsy(&ap->link); 1857 ata_eh_link_autopsy(&ap->link);
1872} 1858}
1873 1859
@@ -2066,41 +2052,29 @@ static int ata_do_reset(struct ata_link *link, ata_reset_fn_t reset,
2066 classes[dev->devno] = ATA_DEV_UNKNOWN; 2052 classes[dev->devno] = ATA_DEV_UNKNOWN;
2067 2053
2068 rc = reset(link, classes, deadline); 2054 rc = reset(link, classes, deadline);
2069 if (rc)
2070 return rc;
2071 2055
2072 /* If any class isn't ATA_DEV_UNKNOWN, consider classification 2056 /* convert all ATA_DEV_UNKNOWN to ATA_DEV_NONE */
2073 * is complete and convert all ATA_DEV_UNKNOWN to
2074 * ATA_DEV_NONE.
2075 */
2076 ata_link_for_each_dev(dev, link) 2057 ata_link_for_each_dev(dev, link)
2077 if (classes[dev->devno] != ATA_DEV_UNKNOWN) 2058 if (classes[dev->devno] == ATA_DEV_UNKNOWN)
2078 break; 2059 classes[dev->devno] = ATA_DEV_NONE;
2079
2080 if (dev) {
2081 ata_link_for_each_dev(dev, link) {
2082 if (classes[dev->devno] == ATA_DEV_UNKNOWN)
2083 classes[dev->devno] = ATA_DEV_NONE;
2084 }
2085 }
2086 2060
2087 return 0; 2061 return rc;
2088} 2062}
2089 2063
2090static int ata_eh_followup_srst_needed(struct ata_link *link, 2064static int ata_eh_followup_srst_needed(struct ata_link *link,
2091 int rc, int classify, 2065 int rc, int classify,
2092 const unsigned int *classes) 2066 const unsigned int *classes)
2093{ 2067{
2094 if (link->flags & ATA_LFLAG_NO_SRST) 2068 if ((link->flags & ATA_LFLAG_NO_SRST) || ata_link_offline(link))
2095 return 0; 2069 return 0;
2096 if (rc == -EAGAIN) 2070 if (rc == -EAGAIN) {
2097 return 1; 2071 if (classify)
2072 return 1;
2073 rc = 0;
2074 }
2098 if (rc != 0) 2075 if (rc != 0)
2099 return 0; 2076 return 0;
2100 if ((link->ap->flags & ATA_FLAG_PMP) && ata_is_host_link(link)) 2077 if (sata_pmp_supported(link->ap) && ata_is_host_link(link))
2101 return 1;
2102 if (classify && !(link->flags & ATA_LFLAG_ASSUME_CLASS) &&
2103 classes[0] == ATA_DEV_UNKNOWN)
2104 return 1; 2078 return 1;
2105 return 0; 2079 return 0;
2106} 2080}
@@ -2118,7 +2092,6 @@ int ata_eh_reset(struct ata_link *link, int classify,
2118 int try = 0; 2092 int try = 0;
2119 struct ata_device *dev; 2093 struct ata_device *dev;
2120 unsigned long deadline, now; 2094 unsigned long deadline, now;
2121 unsigned int tmp_action;
2122 ata_reset_fn_t reset; 2095 ata_reset_fn_t reset;
2123 unsigned long flags; 2096 unsigned long flags;
2124 u32 sstatus; 2097 u32 sstatus;
@@ -2129,7 +2102,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2129 ap->pflags |= ATA_PFLAG_RESETTING; 2102 ap->pflags |= ATA_PFLAG_RESETTING;
2130 spin_unlock_irqrestore(ap->lock, flags); 2103 spin_unlock_irqrestore(ap->lock, flags);
2131 2104
2132 ata_eh_about_to_do(link, NULL, ehc->i.action & ATA_EH_RESET_MASK); 2105 ata_eh_about_to_do(link, NULL, ATA_EH_RESET);
2133 2106
2134 ata_link_for_each_dev(dev, link) { 2107 ata_link_for_each_dev(dev, link) {
2135 /* If we issue an SRST then an ATA drive (not ATAPI) 2108 /* If we issue an SRST then an ATA drive (not ATAPI)
@@ -2159,17 +2132,20 @@ int ata_eh_reset(struct ata_link *link, int classify,
2159 goto done; 2132 goto done;
2160 } 2133 }
2161 2134
2162 /* Determine which reset to use and record in ehc->i.action. 2135 /* prefer hardreset */
2163 * prereset() may examine and modify it. 2136 ehc->i.action &= ~ATA_EH_RESET;
2164 */ 2137 if (hardreset) {
2165 if (softreset && (!hardreset || (!(lflags & ATA_LFLAG_NO_SRST) && 2138 reset = hardreset;
2166 !sata_set_spd_needed(link) && 2139 ehc->i.action = ATA_EH_HARDRESET;
2167 !(ehc->i.action & ATA_EH_HARDRESET)))) 2140 } else if (softreset) {
2168 tmp_action = ATA_EH_SOFTRESET; 2141 reset = softreset;
2169 else 2142 ehc->i.action = ATA_EH_SOFTRESET;
2170 tmp_action = ATA_EH_HARDRESET; 2143 } else {
2171 2144 ata_link_printk(link, KERN_ERR, "BUG: no reset method, "
2172 ehc->i.action = (ehc->i.action & ~ATA_EH_RESET_MASK) | tmp_action; 2145 "please report to linux-ide@vger.kernel.org\n");
2146 dump_stack();
2147 return -EINVAL;
2148 }
2173 2149
2174 if (prereset) { 2150 if (prereset) {
2175 rc = prereset(link, jiffies + ATA_EH_PRERESET_TIMEOUT); 2151 rc = prereset(link, jiffies + ATA_EH_PRERESET_TIMEOUT);
@@ -2177,7 +2153,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2177 if (rc == -ENOENT) { 2153 if (rc == -ENOENT) {
2178 ata_link_printk(link, KERN_DEBUG, 2154 ata_link_printk(link, KERN_DEBUG,
2179 "port disabled. ignoring.\n"); 2155 "port disabled. ignoring.\n");
2180 ehc->i.action &= ~ATA_EH_RESET_MASK; 2156 ehc->i.action &= ~ATA_EH_RESET;
2181 2157
2182 ata_link_for_each_dev(dev, link) 2158 ata_link_for_each_dev(dev, link)
2183 classes[dev->devno] = ATA_DEV_NONE; 2159 classes[dev->devno] = ATA_DEV_NONE;
@@ -2190,12 +2166,8 @@ int ata_eh_reset(struct ata_link *link, int classify,
2190 } 2166 }
2191 } 2167 }
2192 2168
2193 /* prereset() might have modified ehc->i.action */ 2169 /* prereset() might have cleared ATA_EH_RESET */
2194 if (ehc->i.action & ATA_EH_HARDRESET) 2170 if (!(ehc->i.action & ATA_EH_RESET)) {
2195 reset = hardreset;
2196 else if (ehc->i.action & ATA_EH_SOFTRESET)
2197 reset = softreset;
2198 else {
2199 /* prereset told us not to reset, bang classes and return */ 2171 /* prereset told us not to reset, bang classes and return */
2200 ata_link_for_each_dev(dev, link) 2172 ata_link_for_each_dev(dev, link)
2201 classes[dev->devno] = ATA_DEV_NONE; 2173 classes[dev->devno] = ATA_DEV_NONE;
@@ -2203,14 +2175,6 @@ int ata_eh_reset(struct ata_link *link, int classify,
2203 goto out; 2175 goto out;
2204 } 2176 }
2205 2177
2206 /* did prereset() screw up? if so, fix up to avoid oopsing */
2207 if (!reset) {
2208 if (softreset)
2209 reset = softreset;
2210 else
2211 reset = hardreset;
2212 }
2213
2214 retry: 2178 retry:
2215 deadline = jiffies + ata_eh_reset_timeouts[try++]; 2179 deadline = jiffies + ata_eh_reset_timeouts[try++];
2216 2180
@@ -2240,7 +2204,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2240 goto fail; 2204 goto fail;
2241 } 2205 }
2242 2206
2243 ata_eh_about_to_do(link, NULL, ATA_EH_RESET_MASK); 2207 ata_eh_about_to_do(link, NULL, ATA_EH_RESET);
2244 rc = ata_do_reset(link, reset, classes, deadline); 2208 rc = ata_do_reset(link, reset, classes, deadline);
2245 } 2209 }
2246 2210
@@ -2248,21 +2212,6 @@ int ata_eh_reset(struct ata_link *link, int classify,
2248 if (rc && rc != -EAGAIN) 2212 if (rc && rc != -EAGAIN)
2249 goto fail; 2213 goto fail;
2250 2214
2251 /* was classification successful? */
2252 if (classify && classes[0] == ATA_DEV_UNKNOWN &&
2253 !(lflags & ATA_LFLAG_ASSUME_CLASS)) {
2254 if (try < max_tries) {
2255 ata_link_printk(link, KERN_WARNING,
2256 "classification failed\n");
2257 rc = -EINVAL;
2258 goto fail;
2259 }
2260
2261 ata_link_printk(link, KERN_WARNING,
2262 "classfication failed, assuming ATA\n");
2263 lflags |= ATA_LFLAG_ASSUME_ATA;
2264 }
2265
2266 done: 2215 done:
2267 ata_link_for_each_dev(dev, link) { 2216 ata_link_for_each_dev(dev, link) {
2268 /* After the reset, the device state is PIO 0 and the 2217 /* After the reset, the device state is PIO 0 and the
@@ -2290,7 +2239,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2290 postreset(link, classes); 2239 postreset(link, classes);
2291 2240
2292 /* reset successful, schedule revalidation */ 2241 /* reset successful, schedule revalidation */
2293 ata_eh_done(link, NULL, ehc->i.action & ATA_EH_RESET_MASK); 2242 ata_eh_done(link, NULL, ATA_EH_RESET);
2294 ehc->i.action |= ATA_EH_REVALIDATE; 2243 ehc->i.action |= ATA_EH_REVALIDATE;
2295 2244
2296 rc = 0; 2245 rc = 0;
@@ -2305,6 +2254,11 @@ int ata_eh_reset(struct ata_link *link, int classify,
2305 return rc; 2254 return rc;
2306 2255
2307 fail: 2256 fail:
2257 /* if SCR isn't accessible on a fan-out port, PMP needs to be reset */
2258 if (!ata_is_host_link(link) &&
2259 sata_scr_read(link, SCR_STATUS, &sstatus))
2260 rc = -ERESTART;
2261
2308 if (rc == -ERESTART || try >= max_tries) 2262 if (rc == -ERESTART || try >= max_tries)
2309 goto out; 2263 goto out;
2310 2264
@@ -2515,6 +2469,7 @@ static int ata_link_nr_vacant(struct ata_link *link)
2515 2469
2516static int ata_eh_skip_recovery(struct ata_link *link) 2470static int ata_eh_skip_recovery(struct ata_link *link)
2517{ 2471{
2472 struct ata_port *ap = link->ap;
2518 struct ata_eh_context *ehc = &link->eh_context; 2473 struct ata_eh_context *ehc = &link->eh_context;
2519 struct ata_device *dev; 2474 struct ata_device *dev;
2520 2475
@@ -2522,9 +2477,13 @@ static int ata_eh_skip_recovery(struct ata_link *link)
2522 if (link->flags & ATA_LFLAG_DISABLED) 2477 if (link->flags & ATA_LFLAG_DISABLED)
2523 return 1; 2478 return 1;
2524 2479
2525 /* thaw frozen port, resume link and recover failed devices */ 2480 /* thaw frozen port and recover failed devices */
2526 if ((link->ap->pflags & ATA_PFLAG_FROZEN) || 2481 if ((ap->pflags & ATA_PFLAG_FROZEN) || ata_link_nr_enabled(link))
2527 (ehc->i.flags & ATA_EHI_RESUME_LINK) || ata_link_nr_enabled(link)) 2482 return 0;
2483
2484 /* reset at least once if reset is requested */
2485 if ((ehc->i.action & ATA_EH_RESET) &&
2486 !(ehc->i.flags & ATA_EHI_DID_RESET))
2528 return 0; 2487 return 0;
2529 2488
2530 /* skip if class codes for all vacant slots are ATA_DEV_NONE */ 2489 /* skip if class codes for all vacant slots are ATA_DEV_NONE */
@@ -2548,7 +2507,7 @@ static int ata_eh_schedule_probe(struct ata_device *dev)
2548 ata_eh_detach_dev(dev); 2507 ata_eh_detach_dev(dev);
2549 ata_dev_init(dev); 2508 ata_dev_init(dev);
2550 ehc->did_probe_mask |= (1 << dev->devno); 2509 ehc->did_probe_mask |= (1 << dev->devno);
2551 ehc->i.action |= ATA_EH_SOFTRESET; 2510 ehc->i.action |= ATA_EH_RESET;
2552 ehc->saved_xfer_mode[dev->devno] = 0; 2511 ehc->saved_xfer_mode[dev->devno] = 0;
2553 ehc->saved_ncq_enabled &= ~(1 << dev->devno); 2512 ehc->saved_ncq_enabled &= ~(1 << dev->devno);
2554 2513
@@ -2592,12 +2551,7 @@ static int ata_eh_handle_dev_fail(struct ata_device *dev, int err)
2592 2551
2593 return 1; 2552 return 1;
2594 } else { 2553 } else {
2595 /* soft didn't work? be haaaaard */ 2554 ehc->i.action |= ATA_EH_RESET;
2596 if (ehc->i.flags & ATA_EHI_DID_RESET)
2597 ehc->i.action |= ATA_EH_HARDRESET;
2598 else
2599 ehc->i.action |= ATA_EH_SOFTRESET;
2600
2601 return 0; 2555 return 0;
2602 } 2556 }
2603} 2557}
@@ -2690,7 +2644,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
2690 ehc->i.action = 0; 2644 ehc->i.action = 0;
2691 2645
2692 /* do we need to reset? */ 2646 /* do we need to reset? */
2693 if (ehc->i.action & ATA_EH_RESET_MASK) 2647 if (ehc->i.action & ATA_EH_RESET)
2694 reset = 1; 2648 reset = 1;
2695 2649
2696 ata_link_for_each_dev(dev, link) 2650 ata_link_for_each_dev(dev, link)
@@ -2702,13 +2656,13 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
2702 /* if PMP is attached, this function only deals with 2656 /* if PMP is attached, this function only deals with
2703 * downstream links, port should stay thawed. 2657 * downstream links, port should stay thawed.
2704 */ 2658 */
2705 if (!ap->nr_pmp_links) 2659 if (!sata_pmp_attached(ap))
2706 ata_eh_freeze_port(ap); 2660 ata_eh_freeze_port(ap);
2707 2661
2708 ata_port_for_each_link(link, ap) { 2662 ata_port_for_each_link(link, ap) {
2709 struct ata_eh_context *ehc = &link->eh_context; 2663 struct ata_eh_context *ehc = &link->eh_context;
2710 2664
2711 if (!(ehc->i.action & ATA_EH_RESET_MASK)) 2665 if (!(ehc->i.action & ATA_EH_RESET))
2712 continue; 2666 continue;
2713 2667
2714 rc = ata_eh_reset(link, ata_link_nr_vacant(link), 2668 rc = ata_eh_reset(link, ata_link_nr_vacant(link),
@@ -2721,7 +2675,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
2721 } 2675 }
2722 } 2676 }
2723 2677
2724 if (!ap->nr_pmp_links) 2678 if (!sata_pmp_attached(ap))
2725 ata_eh_thaw_port(ap); 2679 ata_eh_thaw_port(ap);
2726 } 2680 }
2727 2681
@@ -2765,7 +2719,7 @@ dev_fail:
2765 /* PMP reset requires working host port. 2719 /* PMP reset requires working host port.
2766 * Can't retry if it's frozen. 2720 * Can't retry if it's frozen.
2767 */ 2721 */
2768 if (ap->nr_pmp_links) 2722 if (sata_pmp_attached(ap))
2769 goto out; 2723 goto out;
2770 break; 2724 break;
2771 } 2725 }
@@ -2817,18 +2771,11 @@ void ata_eh_finish(struct ata_port *ap)
2817 /* FIXME: Once EH migration is complete, 2771 /* FIXME: Once EH migration is complete,
2818 * generate sense data in this function, 2772 * generate sense data in this function,
2819 * considering both err_mask and tf. 2773 * considering both err_mask and tf.
2820 *
2821 * There's no point in retrying invalid
2822 * (detected by libata) and non-IO device
2823 * errors (rejected by device). Finish them
2824 * immediately.
2825 */ 2774 */
2826 if ((qc->err_mask & AC_ERR_INVALID) || 2775 if (qc->flags & ATA_QCFLAG_RETRY)
2827 (!(qc->flags & ATA_QCFLAG_IO) &&
2828 qc->err_mask == AC_ERR_DEV))
2829 ata_eh_qc_complete(qc);
2830 else
2831 ata_eh_qc_retry(qc); 2776 ata_eh_qc_retry(qc);
2777 else
2778 ata_eh_qc_complete(qc);
2832 } else { 2779 } else {
2833 if (qc->flags & ATA_QCFLAG_SENSE_VALID) { 2780 if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
2834 ata_eh_qc_complete(qc); 2781 ata_eh_qc_complete(qc);
@@ -2848,6 +2795,7 @@ void ata_eh_finish(struct ata_port *ap)
2848/** 2795/**
2849 * ata_do_eh - do standard error handling 2796 * ata_do_eh - do standard error handling
2850 * @ap: host port to handle error for 2797 * @ap: host port to handle error for
2798 *
2851 * @prereset: prereset method (can be NULL) 2799 * @prereset: prereset method (can be NULL)
2852 * @softreset: softreset method (can be NULL) 2800 * @softreset: softreset method (can be NULL)
2853 * @hardreset: hardreset method (can be NULL) 2801 * @hardreset: hardreset method (can be NULL)
@@ -2878,6 +2826,27 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
2878 ata_eh_finish(ap); 2826 ata_eh_finish(ap);
2879} 2827}
2880 2828
2829/**
2830 * ata_std_error_handler - standard error handler
2831 * @ap: host port to handle error for
2832 *
2833 * Standard error handler
2834 *
2835 * LOCKING:
2836 * Kernel thread context (may sleep).
2837 */
2838void ata_std_error_handler(struct ata_port *ap)
2839{
2840 struct ata_port_operations *ops = ap->ops;
2841 ata_reset_fn_t hardreset = ops->hardreset;
2842
2843 /* ignore built-in hardreset if SCR access is not available */
2844 if (ata_is_builtin_hardreset(hardreset) && !sata_scr_valid(&ap->link))
2845 hardreset = NULL;
2846
2847 ata_do_eh(ap, ops->prereset, ops->softreset, hardreset, ops->postreset);
2848}
2849
2881#ifdef CONFIG_PM 2850#ifdef CONFIG_PM
2882/** 2851/**
2883 * ata_eh_handle_port_suspend - perform port suspend operation 2852 * ata_eh_handle_port_suspend - perform port suspend operation