Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 1 | /* |
| 2 | * libata-eh.c - libata error handling |
| 3 | * |
| 4 | * Maintained by: Jeff Garzik <jgarzik@pobox.com> |
| 5 | * Please ALWAYS copy linux-ide@vger.kernel.org |
| 6 | * on emails. |
| 7 | * |
| 8 | * Copyright 2006 Tejun Heo <htejun@gmail.com> |
| 9 | * |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; see the file COPYING. If not, write to |
| 23 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, |
| 24 | * USA. |
| 25 | * |
| 26 | * |
| 27 | * libata documentation is available via 'make {ps|pdf}docs', |
| 28 | * as Documentation/DocBook/libata.* |
| 29 | * |
| 30 | * Hardware documentation available from http://www.t13.org/ and |
| 31 | * http://www.sata-io.org/ |
| 32 | * |
| 33 | */ |
| 34 | |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 35 | #include <linux/kernel.h> |
| 36 | #include <scsi/scsi.h> |
| 37 | #include <scsi/scsi_host.h> |
| 38 | #include <scsi/scsi_eh.h> |
| 39 | #include <scsi/scsi_device.h> |
| 40 | #include <scsi/scsi_cmnd.h> |
Jeff Garzik | c6fd280 | 2006-08-10 07:31:37 -0400 | [diff] [blame] | 41 | #include "../scsi/scsi_transport_api.h" |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 42 | |
| 43 | #include <linux/libata.h> |
| 44 | |
| 45 | #include "libata.h" |
| 46 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 47 | enum { |
| 48 | ATA_EH_SPDN_NCQ_OFF = (1 << 0), |
| 49 | ATA_EH_SPDN_SPEED_DOWN = (1 << 1), |
| 50 | ATA_EH_SPDN_FALLBACK_TO_PIO = (1 << 2), |
| 51 | }; |
| 52 | |
Tejun Heo | 31daabd | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 53 | /* Waiting in ->prereset can never be reliable. It's sometimes nice |
| 54 | * to wait there but it can't be depended upon; otherwise, we wouldn't |
| 55 | * be resetting. Just give it enough time for most drives to spin up. |
| 56 | */ |
| 57 | enum { |
| 58 | ATA_EH_PRERESET_TIMEOUT = 10 * HZ, |
Tejun Heo | 5ddf24c | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 59 | ATA_EH_FASTDRAIN_INTERVAL = 3 * HZ, |
Tejun Heo | 31daabd | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | /* The following table determines how we sequence resets. Each entry |
| 63 | * represents timeout for that try. The first try can be soft or |
| 64 | * hardreset. All others are hardreset if available. In most cases |
| 65 | * the first reset w/ 10sec timeout should succeed. Following entries |
| 66 | * are mostly for error handling, hotplug and retarded devices. |
| 67 | */ |
| 68 | static const unsigned long ata_eh_reset_timeouts[] = { |
| 69 | 10 * HZ, /* most drives spin up by 10sec */ |
| 70 | 10 * HZ, /* > 99% working drives spin up before 20sec */ |
| 71 | 35 * HZ, /* give > 30 secs of idleness for retarded devices */ |
| 72 | 5 * HZ, /* and sweet one last chance */ |
| 73 | /* > 1 min has elapsed, give up */ |
| 74 | }; |
| 75 | |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 76 | static void __ata_port_freeze(struct ata_port *ap); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 77 | static void ata_eh_finish(struct ata_port *ap); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 78 | #ifdef CONFIG_PM |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 79 | static void ata_eh_handle_port_suspend(struct ata_port *ap); |
| 80 | static void ata_eh_handle_port_resume(struct ata_port *ap); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 81 | #else /* CONFIG_PM */ |
| 82 | static void ata_eh_handle_port_suspend(struct ata_port *ap) |
| 83 | { } |
| 84 | |
| 85 | static void ata_eh_handle_port_resume(struct ata_port *ap) |
| 86 | { } |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 87 | #endif /* CONFIG_PM */ |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 88 | |
Tejun Heo | b64bbc3 | 2007-07-16 14:29:39 +0900 | [diff] [blame] | 89 | static void __ata_ehi_pushv_desc(struct ata_eh_info *ehi, const char *fmt, |
| 90 | va_list args) |
| 91 | { |
| 92 | ehi->desc_len += vscnprintf(ehi->desc + ehi->desc_len, |
| 93 | ATA_EH_DESC_LEN - ehi->desc_len, |
| 94 | fmt, args); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * __ata_ehi_push_desc - push error description without adding separator |
| 99 | * @ehi: target EHI |
| 100 | * @fmt: printf format string |
| 101 | * |
| 102 | * Format string according to @fmt and append it to @ehi->desc. |
| 103 | * |
| 104 | * LOCKING: |
| 105 | * spin_lock_irqsave(host lock) |
| 106 | */ |
| 107 | void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...) |
| 108 | { |
| 109 | va_list args; |
| 110 | |
| 111 | va_start(args, fmt); |
| 112 | __ata_ehi_pushv_desc(ehi, fmt, args); |
| 113 | va_end(args); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * ata_ehi_push_desc - push error description with separator |
| 118 | * @ehi: target EHI |
| 119 | * @fmt: printf format string |
| 120 | * |
| 121 | * Format string according to @fmt and append it to @ehi->desc. |
| 122 | * If @ehi->desc is not empty, ", " is added in-between. |
| 123 | * |
| 124 | * LOCKING: |
| 125 | * spin_lock_irqsave(host lock) |
| 126 | */ |
| 127 | void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...) |
| 128 | { |
| 129 | va_list args; |
| 130 | |
| 131 | if (ehi->desc_len) |
| 132 | __ata_ehi_push_desc(ehi, ", "); |
| 133 | |
| 134 | va_start(args, fmt); |
| 135 | __ata_ehi_pushv_desc(ehi, fmt, args); |
| 136 | va_end(args); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * ata_ehi_clear_desc - clean error description |
| 141 | * @ehi: target EHI |
| 142 | * |
| 143 | * Clear @ehi->desc. |
| 144 | * |
| 145 | * LOCKING: |
| 146 | * spin_lock_irqsave(host lock) |
| 147 | */ |
| 148 | void ata_ehi_clear_desc(struct ata_eh_info *ehi) |
| 149 | { |
| 150 | ehi->desc[0] = '\0'; |
| 151 | ehi->desc_len = 0; |
| 152 | } |
| 153 | |
Tejun Heo | 0c247c5 | 2006-05-15 20:58:19 +0900 | [diff] [blame] | 154 | static void ata_ering_record(struct ata_ering *ering, int is_io, |
| 155 | unsigned int err_mask) |
| 156 | { |
| 157 | struct ata_ering_entry *ent; |
| 158 | |
| 159 | WARN_ON(!err_mask); |
| 160 | |
| 161 | ering->cursor++; |
| 162 | ering->cursor %= ATA_ERING_SIZE; |
| 163 | |
| 164 | ent = &ering->ring[ering->cursor]; |
| 165 | ent->is_io = is_io; |
| 166 | ent->err_mask = err_mask; |
| 167 | ent->timestamp = get_jiffies_64(); |
| 168 | } |
| 169 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 170 | static void ata_ering_clear(struct ata_ering *ering) |
Tejun Heo | 0c247c5 | 2006-05-15 20:58:19 +0900 | [diff] [blame] | 171 | { |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 172 | memset(ering, 0, sizeof(*ering)); |
Tejun Heo | 0c247c5 | 2006-05-15 20:58:19 +0900 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static int ata_ering_map(struct ata_ering *ering, |
| 176 | int (*map_fn)(struct ata_ering_entry *, void *), |
| 177 | void *arg) |
| 178 | { |
| 179 | int idx, rc = 0; |
| 180 | struct ata_ering_entry *ent; |
| 181 | |
| 182 | idx = ering->cursor; |
| 183 | do { |
| 184 | ent = &ering->ring[idx]; |
| 185 | if (!ent->err_mask) |
| 186 | break; |
| 187 | rc = map_fn(ent, arg); |
| 188 | if (rc) |
| 189 | break; |
| 190 | idx = (idx - 1 + ATA_ERING_SIZE) % ATA_ERING_SIZE; |
| 191 | } while (idx != ering->cursor); |
| 192 | |
| 193 | return rc; |
| 194 | } |
| 195 | |
Tejun Heo | 64f65ca | 2006-06-24 20:30:18 +0900 | [diff] [blame] | 196 | static unsigned int ata_eh_dev_action(struct ata_device *dev) |
| 197 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 198 | struct ata_eh_context *ehc = &dev->link->eh_context; |
Tejun Heo | 64f65ca | 2006-06-24 20:30:18 +0900 | [diff] [blame] | 199 | |
| 200 | return ehc->i.action | ehc->i.dev_action[dev->devno]; |
| 201 | } |
| 202 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 203 | static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev, |
Tejun Heo | af181c2 | 2006-06-24 20:30:18 +0900 | [diff] [blame] | 204 | struct ata_eh_info *ehi, unsigned int action) |
| 205 | { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 206 | struct ata_device *tdev; |
Tejun Heo | af181c2 | 2006-06-24 20:30:18 +0900 | [diff] [blame] | 207 | |
| 208 | if (!dev) { |
| 209 | ehi->action &= ~action; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 210 | ata_link_for_each_dev(tdev, link) |
| 211 | ehi->dev_action[tdev->devno] &= ~action; |
Tejun Heo | af181c2 | 2006-06-24 20:30:18 +0900 | [diff] [blame] | 212 | } else { |
| 213 | /* doesn't make sense for port-wide EH actions */ |
| 214 | WARN_ON(!(action & ATA_EH_PERDEV_MASK)); |
| 215 | |
| 216 | /* break ehi->action into ehi->dev_action */ |
| 217 | if (ehi->action & action) { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 218 | ata_link_for_each_dev(tdev, link) |
| 219 | ehi->dev_action[tdev->devno] |= |
| 220 | ehi->action & action; |
Tejun Heo | af181c2 | 2006-06-24 20:30:18 +0900 | [diff] [blame] | 221 | ehi->action &= ~action; |
| 222 | } |
| 223 | |
| 224 | /* turn off the specified per-dev action */ |
| 225 | ehi->dev_action[dev->devno] &= ~action; |
| 226 | } |
| 227 | } |
| 228 | |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 229 | /** |
| 230 | * ata_scsi_timed_out - SCSI layer time out callback |
| 231 | * @cmd: timed out SCSI command |
| 232 | * |
| 233 | * Handles SCSI layer timeout. We race with normal completion of |
| 234 | * the qc for @cmd. If the qc is already gone, we lose and let |
| 235 | * the scsi command finish (EH_HANDLED). Otherwise, the qc has |
| 236 | * timed out and EH should be invoked. Prevent ata_qc_complete() |
| 237 | * from finishing it by setting EH_SCHEDULED and return |
| 238 | * EH_NOT_HANDLED. |
| 239 | * |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 240 | * TODO: kill this function once old EH is gone. |
| 241 | * |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 242 | * LOCKING: |
| 243 | * Called from timer context |
| 244 | * |
| 245 | * RETURNS: |
| 246 | * EH_HANDLED or EH_NOT_HANDLED |
| 247 | */ |
| 248 | enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd) |
| 249 | { |
| 250 | struct Scsi_Host *host = cmd->device->host; |
Jeff Garzik | 35bb94b | 2006-04-11 13:12:34 -0400 | [diff] [blame] | 251 | struct ata_port *ap = ata_shost_to_port(host); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 252 | unsigned long flags; |
| 253 | struct ata_queued_cmd *qc; |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 254 | enum scsi_eh_timer_return ret; |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 255 | |
| 256 | DPRINTK("ENTER\n"); |
| 257 | |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 258 | if (ap->ops->error_handler) { |
| 259 | ret = EH_NOT_HANDLED; |
| 260 | goto out; |
| 261 | } |
| 262 | |
| 263 | ret = EH_HANDLED; |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 264 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 265 | qc = ata_qc_from_tag(ap, ap->link.active_tag); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 266 | if (qc) { |
| 267 | WARN_ON(qc->scsicmd != cmd); |
| 268 | qc->flags |= ATA_QCFLAG_EH_SCHEDULED; |
| 269 | qc->err_mask |= AC_ERR_TIMEOUT; |
| 270 | ret = EH_NOT_HANDLED; |
| 271 | } |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 272 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 273 | |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 274 | out: |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 275 | DPRINTK("EXIT, ret=%d\n", ret); |
| 276 | return ret; |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * ata_scsi_error - SCSI layer error handler callback |
| 281 | * @host: SCSI host on which error occurred |
| 282 | * |
| 283 | * Handles SCSI-layer-thrown error events. |
| 284 | * |
| 285 | * LOCKING: |
| 286 | * Inherited from SCSI layer (none, can sleep) |
| 287 | * |
| 288 | * RETURNS: |
| 289 | * Zero. |
| 290 | */ |
Jeff Garzik | 381544b | 2006-04-11 13:04:39 -0400 | [diff] [blame] | 291 | void ata_scsi_error(struct Scsi_Host *host) |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 292 | { |
Jeff Garzik | 35bb94b | 2006-04-11 13:12:34 -0400 | [diff] [blame] | 293 | struct ata_port *ap = ata_shost_to_port(host); |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 294 | int i, repeat_cnt = ATA_EH_MAX_REPEAT; |
| 295 | unsigned long flags; |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 296 | |
| 297 | DPRINTK("ENTER\n"); |
| 298 | |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 299 | /* synchronize with port task */ |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 300 | ata_port_flush_task(ap); |
| 301 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 302 | /* synchronize with host lock and sort out timeouts */ |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 303 | |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 304 | /* For new EH, all qcs are finished in one of three ways - |
| 305 | * normal completion, error completion, and SCSI timeout. |
| 306 | * Both cmpletions can race against SCSI timeout. When normal |
| 307 | * completion wins, the qc never reaches EH. When error |
| 308 | * completion wins, the qc has ATA_QCFLAG_FAILED set. |
| 309 | * |
| 310 | * When SCSI timeout wins, things are a bit more complex. |
| 311 | * Normal or error completion can occur after the timeout but |
| 312 | * before this point. In such cases, both types of |
| 313 | * completions are honored. A scmd is determined to have |
| 314 | * timed out iff its associated qc is active and not failed. |
| 315 | */ |
| 316 | if (ap->ops->error_handler) { |
| 317 | struct scsi_cmnd *scmd, *tmp; |
| 318 | int nr_timedout = 0; |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 319 | |
Tejun Heo | e30349d | 2006-07-03 03:02:15 +0900 | [diff] [blame] | 320 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 321 | |
| 322 | list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) { |
| 323 | struct ata_queued_cmd *qc; |
| 324 | |
| 325 | for (i = 0; i < ATA_MAX_QUEUE; i++) { |
| 326 | qc = __ata_qc_from_tag(ap, i); |
| 327 | if (qc->flags & ATA_QCFLAG_ACTIVE && |
| 328 | qc->scsicmd == scmd) |
| 329 | break; |
| 330 | } |
| 331 | |
| 332 | if (i < ATA_MAX_QUEUE) { |
| 333 | /* the scmd has an associated qc */ |
| 334 | if (!(qc->flags & ATA_QCFLAG_FAILED)) { |
| 335 | /* which hasn't failed yet, timeout */ |
| 336 | qc->err_mask |= AC_ERR_TIMEOUT; |
| 337 | qc->flags |= ATA_QCFLAG_FAILED; |
| 338 | nr_timedout++; |
| 339 | } |
| 340 | } else { |
| 341 | /* Normal completion occurred after |
| 342 | * SCSI timeout but before this point. |
| 343 | * Successfully complete it. |
| 344 | */ |
| 345 | scmd->retries = scmd->allowed; |
| 346 | scsi_eh_finish_cmd(scmd, &ap->eh_done_q); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | /* If we have timed out qcs. They belong to EH from |
| 351 | * this point but the state of the controller is |
| 352 | * unknown. Freeze the port to make sure the IRQ |
| 353 | * handler doesn't diddle with those qcs. This must |
| 354 | * be done atomically w.r.t. setting QCFLAG_FAILED. |
| 355 | */ |
| 356 | if (nr_timedout) |
| 357 | __ata_port_freeze(ap); |
| 358 | |
Tejun Heo | e30349d | 2006-07-03 03:02:15 +0900 | [diff] [blame] | 359 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 360 | } else |
Tejun Heo | e30349d | 2006-07-03 03:02:15 +0900 | [diff] [blame] | 361 | spin_unlock_wait(ap->lock); |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 362 | |
| 363 | repeat: |
| 364 | /* invoke error handler */ |
| 365 | if (ap->ops->error_handler) { |
Tejun Heo | 5ddf24c | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 366 | /* kill fast drain timer */ |
| 367 | del_timer_sync(&ap->fastdrain_timer); |
| 368 | |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 369 | /* process port resume request */ |
| 370 | ata_eh_handle_port_resume(ap); |
| 371 | |
Tejun Heo | f3e81b1 | 2006-05-15 20:58:21 +0900 | [diff] [blame] | 372 | /* fetch & clear EH info */ |
Tejun Heo | e30349d | 2006-07-03 03:02:15 +0900 | [diff] [blame] | 373 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | f3e81b1 | 2006-05-15 20:58:21 +0900 | [diff] [blame] | 374 | |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 375 | memset(&ap->link.eh_context, 0, sizeof(ap->link.eh_context)); |
| 376 | ap->link.eh_context.i = ap->link.eh_info; |
| 377 | memset(&ap->link.eh_info, 0, sizeof(ap->link.eh_info)); |
Tejun Heo | f3e81b1 | 2006-05-15 20:58:21 +0900 | [diff] [blame] | 378 | |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 379 | ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS; |
| 380 | ap->pflags &= ~ATA_PFLAG_EH_PENDING; |
Tejun Heo | f3e81b1 | 2006-05-15 20:58:21 +0900 | [diff] [blame] | 381 | |
Tejun Heo | e30349d | 2006-07-03 03:02:15 +0900 | [diff] [blame] | 382 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 383 | |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 384 | /* invoke EH, skip if unloading or suspended */ |
| 385 | if (!(ap->pflags & (ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED))) |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 386 | ap->ops->error_handler(ap); |
| 387 | else |
| 388 | ata_eh_finish(ap); |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 389 | |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 390 | /* process port suspend request */ |
| 391 | ata_eh_handle_port_suspend(ap); |
| 392 | |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 393 | /* Exception might have happend after ->error_handler |
| 394 | * recovered the port but before this point. Repeat |
| 395 | * EH in such case. |
| 396 | */ |
Tejun Heo | e30349d | 2006-07-03 03:02:15 +0900 | [diff] [blame] | 397 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 398 | |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 399 | if (ap->pflags & ATA_PFLAG_EH_PENDING) { |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 400 | if (--repeat_cnt) { |
| 401 | ata_port_printk(ap, KERN_INFO, |
| 402 | "EH pending after completion, " |
| 403 | "repeating EH (cnt=%d)\n", repeat_cnt); |
Tejun Heo | e30349d | 2006-07-03 03:02:15 +0900 | [diff] [blame] | 404 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 405 | goto repeat; |
| 406 | } |
| 407 | ata_port_printk(ap, KERN_ERR, "EH pending after %d " |
| 408 | "tries, giving up\n", ATA_EH_MAX_REPEAT); |
Tejun Heo | 914616a | 2007-06-25 21:47:11 +0900 | [diff] [blame] | 409 | ap->pflags &= ~ATA_PFLAG_EH_PENDING; |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 410 | } |
| 411 | |
Tejun Heo | f3e81b1 | 2006-05-15 20:58:21 +0900 | [diff] [blame] | 412 | /* this run is complete, make sure EH info is clear */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 413 | memset(&ap->link.eh_info, 0, sizeof(ap->link.eh_info)); |
Tejun Heo | f3e81b1 | 2006-05-15 20:58:21 +0900 | [diff] [blame] | 414 | |
Tejun Heo | e30349d | 2006-07-03 03:02:15 +0900 | [diff] [blame] | 415 | /* Clear host_eh_scheduled while holding ap->lock such |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 416 | * that if exception occurs after this point but |
| 417 | * before EH completion, SCSI midlayer will |
| 418 | * re-initiate EH. |
| 419 | */ |
| 420 | host->host_eh_scheduled = 0; |
| 421 | |
Tejun Heo | e30349d | 2006-07-03 03:02:15 +0900 | [diff] [blame] | 422 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 423 | } else { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 424 | WARN_ON(ata_qc_from_tag(ap, ap->link.active_tag) == NULL); |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 425 | ap->ops->eng_timeout(ap); |
| 426 | } |
| 427 | |
| 428 | /* finish or retry handled scmd's and clean up */ |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 429 | WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q)); |
| 430 | |
| 431 | scsi_eh_flush_done_q(&ap->eh_done_q); |
| 432 | |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 433 | /* clean up */ |
Tejun Heo | e30349d | 2006-07-03 03:02:15 +0900 | [diff] [blame] | 434 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 435 | |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 436 | if (ap->pflags & ATA_PFLAG_LOADING) |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 437 | ap->pflags &= ~ATA_PFLAG_LOADING; |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 438 | else if (ap->pflags & ATA_PFLAG_SCSI_HOTPLUG) |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame] | 439 | queue_delayed_work(ata_aux_wq, &ap->hotplug_task, 0); |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 440 | |
| 441 | if (ap->pflags & ATA_PFLAG_RECOVERED) |
| 442 | ata_port_printk(ap, KERN_INFO, "EH complete\n"); |
Tejun Heo | 580b210 | 2006-05-31 18:28:05 +0900 | [diff] [blame] | 443 | |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 444 | ap->pflags &= ~(ATA_PFLAG_SCSI_HOTPLUG | ATA_PFLAG_RECOVERED); |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 445 | |
Tejun Heo | c6cf9e9 | 2006-05-31 18:27:27 +0900 | [diff] [blame] | 446 | /* tell wait_eh that we're done */ |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 447 | ap->pflags &= ~ATA_PFLAG_EH_IN_PROGRESS; |
Tejun Heo | c6cf9e9 | 2006-05-31 18:27:27 +0900 | [diff] [blame] | 448 | wake_up_all(&ap->eh_wait_q); |
| 449 | |
Tejun Heo | e30349d | 2006-07-03 03:02:15 +0900 | [diff] [blame] | 450 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 451 | |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 452 | DPRINTK("EXIT\n"); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | /** |
Tejun Heo | c6cf9e9 | 2006-05-31 18:27:27 +0900 | [diff] [blame] | 456 | * ata_port_wait_eh - Wait for the currently pending EH to complete |
| 457 | * @ap: Port to wait EH for |
| 458 | * |
| 459 | * Wait until the currently pending EH is complete. |
| 460 | * |
| 461 | * LOCKING: |
| 462 | * Kernel thread context (may sleep). |
| 463 | */ |
| 464 | void ata_port_wait_eh(struct ata_port *ap) |
| 465 | { |
| 466 | unsigned long flags; |
| 467 | DEFINE_WAIT(wait); |
| 468 | |
| 469 | retry: |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 470 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | c6cf9e9 | 2006-05-31 18:27:27 +0900 | [diff] [blame] | 471 | |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 472 | while (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) { |
Tejun Heo | c6cf9e9 | 2006-05-31 18:27:27 +0900 | [diff] [blame] | 473 | prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE); |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 474 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | c6cf9e9 | 2006-05-31 18:27:27 +0900 | [diff] [blame] | 475 | schedule(); |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 476 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | c6cf9e9 | 2006-05-31 18:27:27 +0900 | [diff] [blame] | 477 | } |
Tejun Heo | 0a1b622 | 2006-06-11 11:01:38 +0900 | [diff] [blame] | 478 | finish_wait(&ap->eh_wait_q, &wait); |
Tejun Heo | c6cf9e9 | 2006-05-31 18:27:27 +0900 | [diff] [blame] | 479 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 480 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | c6cf9e9 | 2006-05-31 18:27:27 +0900 | [diff] [blame] | 481 | |
| 482 | /* make sure SCSI EH is complete */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 483 | if (scsi_host_in_recovery(ap->scsi_host)) { |
Tejun Heo | c6cf9e9 | 2006-05-31 18:27:27 +0900 | [diff] [blame] | 484 | msleep(10); |
| 485 | goto retry; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | /** |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 490 | * ata_qc_timeout - Handle timeout of queued command |
| 491 | * @qc: Command that timed out |
| 492 | * |
| 493 | * Some part of the kernel (currently, only the SCSI layer) |
| 494 | * has noticed that the active command on port @ap has not |
| 495 | * completed after a specified length of time. Handle this |
| 496 | * condition by disabling DMA (if necessary) and completing |
| 497 | * transactions, with error if necessary. |
| 498 | * |
| 499 | * This also handles the case of the "lost interrupt", where |
| 500 | * for some reason (possibly hardware bug, possibly driver bug) |
| 501 | * an interrupt was not delivered to the driver, even though the |
| 502 | * transaction completed successfully. |
| 503 | * |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 504 | * TODO: kill this function once old EH is gone. |
| 505 | * |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 506 | * LOCKING: |
| 507 | * Inherited from SCSI layer (none, can sleep) |
| 508 | */ |
| 509 | static void ata_qc_timeout(struct ata_queued_cmd *qc) |
| 510 | { |
| 511 | struct ata_port *ap = qc->ap; |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 512 | u8 host_stat = 0, drv_stat; |
| 513 | unsigned long flags; |
| 514 | |
| 515 | DPRINTK("ENTER\n"); |
| 516 | |
| 517 | ap->hsm_task_state = HSM_ST_IDLE; |
| 518 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 519 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 520 | |
| 521 | switch (qc->tf.protocol) { |
| 522 | |
| 523 | case ATA_PROT_DMA: |
| 524 | case ATA_PROT_ATAPI_DMA: |
| 525 | host_stat = ap->ops->bmdma_status(ap); |
| 526 | |
| 527 | /* before we do anything else, clear DMA-Start bit */ |
| 528 | ap->ops->bmdma_stop(qc); |
| 529 | |
| 530 | /* fall through */ |
| 531 | |
| 532 | default: |
| 533 | ata_altstatus(ap); |
| 534 | drv_stat = ata_chk_status(ap); |
| 535 | |
| 536 | /* ack bmdma irq events */ |
| 537 | ap->ops->irq_clear(ap); |
| 538 | |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 539 | ata_dev_printk(qc->dev, KERN_ERR, "command 0x%x timeout, " |
| 540 | "stat 0x%x host_stat 0x%x\n", |
| 541 | qc->tf.command, drv_stat, host_stat); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 542 | |
| 543 | /* complete taskfile transaction */ |
Jeff Garzik | c13b56a | 2006-04-02 10:34:24 -0400 | [diff] [blame] | 544 | qc->err_mask |= AC_ERR_TIMEOUT; |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 545 | break; |
| 546 | } |
| 547 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 548 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 549 | |
| 550 | ata_eh_qc_complete(qc); |
| 551 | |
| 552 | DPRINTK("EXIT\n"); |
| 553 | } |
| 554 | |
| 555 | /** |
| 556 | * ata_eng_timeout - Handle timeout of queued command |
| 557 | * @ap: Port on which timed-out command is active |
| 558 | * |
| 559 | * Some part of the kernel (currently, only the SCSI layer) |
| 560 | * has noticed that the active command on port @ap has not |
| 561 | * completed after a specified length of time. Handle this |
| 562 | * condition by disabling DMA (if necessary) and completing |
| 563 | * transactions, with error if necessary. |
| 564 | * |
| 565 | * This also handles the case of the "lost interrupt", where |
| 566 | * for some reason (possibly hardware bug, possibly driver bug) |
| 567 | * an interrupt was not delivered to the driver, even though the |
| 568 | * transaction completed successfully. |
| 569 | * |
Tejun Heo | ad9e276 | 2006-05-15 20:58:12 +0900 | [diff] [blame] | 570 | * TODO: kill this function once old EH is gone. |
| 571 | * |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 572 | * LOCKING: |
| 573 | * Inherited from SCSI layer (none, can sleep) |
| 574 | */ |
| 575 | void ata_eng_timeout(struct ata_port *ap) |
| 576 | { |
| 577 | DPRINTK("ENTER\n"); |
| 578 | |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 579 | ata_qc_timeout(ata_qc_from_tag(ap, ap->link.active_tag)); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 580 | |
| 581 | DPRINTK("EXIT\n"); |
| 582 | } |
| 583 | |
Tejun Heo | 5ddf24c | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 584 | static int ata_eh_nr_in_flight(struct ata_port *ap) |
| 585 | { |
| 586 | unsigned int tag; |
| 587 | int nr = 0; |
| 588 | |
| 589 | /* count only non-internal commands */ |
| 590 | for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++) |
| 591 | if (ata_qc_from_tag(ap, tag)) |
| 592 | nr++; |
| 593 | |
| 594 | return nr; |
| 595 | } |
| 596 | |
| 597 | void ata_eh_fastdrain_timerfn(unsigned long arg) |
| 598 | { |
| 599 | struct ata_port *ap = (void *)arg; |
| 600 | unsigned long flags; |
| 601 | int cnt; |
| 602 | |
| 603 | spin_lock_irqsave(ap->lock, flags); |
| 604 | |
| 605 | cnt = ata_eh_nr_in_flight(ap); |
| 606 | |
| 607 | /* are we done? */ |
| 608 | if (!cnt) |
| 609 | goto out_unlock; |
| 610 | |
| 611 | if (cnt == ap->fastdrain_cnt) { |
| 612 | unsigned int tag; |
| 613 | |
| 614 | /* No progress during the last interval, tag all |
| 615 | * in-flight qcs as timed out and freeze the port. |
| 616 | */ |
| 617 | for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++) { |
| 618 | struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag); |
| 619 | if (qc) |
| 620 | qc->err_mask |= AC_ERR_TIMEOUT; |
| 621 | } |
| 622 | |
| 623 | ata_port_freeze(ap); |
| 624 | } else { |
| 625 | /* some qcs have finished, give it another chance */ |
| 626 | ap->fastdrain_cnt = cnt; |
| 627 | ap->fastdrain_timer.expires = |
| 628 | jiffies + ATA_EH_FASTDRAIN_INTERVAL; |
| 629 | add_timer(&ap->fastdrain_timer); |
| 630 | } |
| 631 | |
| 632 | out_unlock: |
| 633 | spin_unlock_irqrestore(ap->lock, flags); |
| 634 | } |
| 635 | |
| 636 | /** |
| 637 | * ata_eh_set_pending - set ATA_PFLAG_EH_PENDING and activate fast drain |
| 638 | * @ap: target ATA port |
| 639 | * @fastdrain: activate fast drain |
| 640 | * |
| 641 | * Set ATA_PFLAG_EH_PENDING and activate fast drain if @fastdrain |
| 642 | * is non-zero and EH wasn't pending before. Fast drain ensures |
| 643 | * that EH kicks in in timely manner. |
| 644 | * |
| 645 | * LOCKING: |
| 646 | * spin_lock_irqsave(host lock) |
| 647 | */ |
| 648 | static void ata_eh_set_pending(struct ata_port *ap, int fastdrain) |
| 649 | { |
| 650 | int cnt; |
| 651 | |
| 652 | /* already scheduled? */ |
| 653 | if (ap->pflags & ATA_PFLAG_EH_PENDING) |
| 654 | return; |
| 655 | |
| 656 | ap->pflags |= ATA_PFLAG_EH_PENDING; |
| 657 | |
| 658 | if (!fastdrain) |
| 659 | return; |
| 660 | |
| 661 | /* do we have in-flight qcs? */ |
| 662 | cnt = ata_eh_nr_in_flight(ap); |
| 663 | if (!cnt) |
| 664 | return; |
| 665 | |
| 666 | /* activate fast drain */ |
| 667 | ap->fastdrain_cnt = cnt; |
| 668 | ap->fastdrain_timer.expires = jiffies + ATA_EH_FASTDRAIN_INTERVAL; |
| 669 | add_timer(&ap->fastdrain_timer); |
| 670 | } |
| 671 | |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 672 | /** |
| 673 | * ata_qc_schedule_eh - schedule qc for error handling |
| 674 | * @qc: command to schedule error handling for |
| 675 | * |
| 676 | * Schedule error handling for @qc. EH will kick in as soon as |
| 677 | * other commands are drained. |
| 678 | * |
| 679 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 680 | * spin_lock_irqsave(host lock) |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 681 | */ |
| 682 | void ata_qc_schedule_eh(struct ata_queued_cmd *qc) |
| 683 | { |
| 684 | struct ata_port *ap = qc->ap; |
| 685 | |
| 686 | WARN_ON(!ap->ops->error_handler); |
| 687 | |
| 688 | qc->flags |= ATA_QCFLAG_FAILED; |
Tejun Heo | 5ddf24c | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 689 | ata_eh_set_pending(ap, 1); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 690 | |
| 691 | /* The following will fail if timeout has already expired. |
| 692 | * ata_scsi_error() takes care of such scmds on EH entry. |
| 693 | * Note that ATA_QCFLAG_FAILED is unconditionally set after |
| 694 | * this function completes. |
| 695 | */ |
| 696 | scsi_req_abort_cmd(qc->scsicmd); |
| 697 | } |
| 698 | |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 699 | /** |
| 700 | * ata_port_schedule_eh - schedule error handling without a qc |
| 701 | * @ap: ATA port to schedule EH for |
| 702 | * |
| 703 | * Schedule error handling for @ap. EH will kick in as soon as |
| 704 | * all commands are drained. |
| 705 | * |
| 706 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 707 | * spin_lock_irqsave(host lock) |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 708 | */ |
| 709 | void ata_port_schedule_eh(struct ata_port *ap) |
| 710 | { |
| 711 | WARN_ON(!ap->ops->error_handler); |
| 712 | |
Tejun Heo | f4d6d00 | 2007-05-01 11:50:15 +0200 | [diff] [blame] | 713 | if (ap->pflags & ATA_PFLAG_INITIALIZING) |
| 714 | return; |
| 715 | |
Tejun Heo | 5ddf24c | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 716 | ata_eh_set_pending(ap, 1); |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 717 | scsi_schedule_eh(ap->scsi_host); |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 718 | |
| 719 | DPRINTK("port EH scheduled\n"); |
| 720 | } |
| 721 | |
Tejun Heo | dbd8261 | 2007-08-06 18:36:23 +0900 | [diff] [blame^] | 722 | static int ata_do_link_abort(struct ata_port *ap, struct ata_link *link) |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 723 | { |
| 724 | int tag, nr_aborted = 0; |
| 725 | |
| 726 | WARN_ON(!ap->ops->error_handler); |
| 727 | |
Tejun Heo | 5ddf24c | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 728 | /* we're gonna abort all commands, no need for fast drain */ |
| 729 | ata_eh_set_pending(ap, 0); |
| 730 | |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 731 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
| 732 | struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag); |
| 733 | |
Tejun Heo | dbd8261 | 2007-08-06 18:36:23 +0900 | [diff] [blame^] | 734 | if (qc && (!link || qc->dev->link == link)) { |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 735 | qc->flags |= ATA_QCFLAG_FAILED; |
| 736 | ata_qc_complete(qc); |
| 737 | nr_aborted++; |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | if (!nr_aborted) |
| 742 | ata_port_schedule_eh(ap); |
| 743 | |
| 744 | return nr_aborted; |
| 745 | } |
| 746 | |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 747 | /** |
Tejun Heo | dbd8261 | 2007-08-06 18:36:23 +0900 | [diff] [blame^] | 748 | * ata_link_abort - abort all qc's on the link |
| 749 | * @link: ATA link to abort qc's for |
| 750 | * |
| 751 | * Abort all active qc's active on @link and schedule EH. |
| 752 | * |
| 753 | * LOCKING: |
| 754 | * spin_lock_irqsave(host lock) |
| 755 | * |
| 756 | * RETURNS: |
| 757 | * Number of aborted qc's. |
| 758 | */ |
| 759 | int ata_link_abort(struct ata_link *link) |
| 760 | { |
| 761 | return ata_do_link_abort(link->ap, link); |
| 762 | } |
| 763 | |
| 764 | /** |
| 765 | * ata_port_abort - abort all qc's on the port |
| 766 | * @ap: ATA port to abort qc's for |
| 767 | * |
| 768 | * Abort all active qc's of @ap and schedule EH. |
| 769 | * |
| 770 | * LOCKING: |
| 771 | * spin_lock_irqsave(host_set lock) |
| 772 | * |
| 773 | * RETURNS: |
| 774 | * Number of aborted qc's. |
| 775 | */ |
| 776 | int ata_port_abort(struct ata_port *ap) |
| 777 | { |
| 778 | return ata_do_link_abort(ap, NULL); |
| 779 | } |
| 780 | |
| 781 | /** |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 782 | * __ata_port_freeze - freeze port |
| 783 | * @ap: ATA port to freeze |
| 784 | * |
| 785 | * This function is called when HSM violation or some other |
| 786 | * condition disrupts normal operation of the port. Frozen port |
| 787 | * is not allowed to perform any operation until the port is |
| 788 | * thawed, which usually follows a successful reset. |
| 789 | * |
| 790 | * ap->ops->freeze() callback can be used for freezing the port |
| 791 | * hardware-wise (e.g. mask interrupt and stop DMA engine). If a |
| 792 | * port cannot be frozen hardware-wise, the interrupt handler |
| 793 | * must ack and clear interrupts unconditionally while the port |
| 794 | * is frozen. |
| 795 | * |
| 796 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 797 | * spin_lock_irqsave(host lock) |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 798 | */ |
| 799 | static void __ata_port_freeze(struct ata_port *ap) |
| 800 | { |
| 801 | WARN_ON(!ap->ops->error_handler); |
| 802 | |
| 803 | if (ap->ops->freeze) |
| 804 | ap->ops->freeze(ap); |
| 805 | |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 806 | ap->pflags |= ATA_PFLAG_FROZEN; |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 807 | |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 808 | DPRINTK("ata%u port frozen\n", ap->print_id); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | /** |
| 812 | * ata_port_freeze - abort & freeze port |
| 813 | * @ap: ATA port to freeze |
| 814 | * |
| 815 | * Abort and freeze @ap. |
| 816 | * |
| 817 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 818 | * spin_lock_irqsave(host lock) |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 819 | * |
| 820 | * RETURNS: |
| 821 | * Number of aborted commands. |
| 822 | */ |
| 823 | int ata_port_freeze(struct ata_port *ap) |
| 824 | { |
| 825 | int nr_aborted; |
| 826 | |
| 827 | WARN_ON(!ap->ops->error_handler); |
| 828 | |
| 829 | nr_aborted = ata_port_abort(ap); |
| 830 | __ata_port_freeze(ap); |
| 831 | |
| 832 | return nr_aborted; |
| 833 | } |
| 834 | |
| 835 | /** |
| 836 | * ata_eh_freeze_port - EH helper to freeze port |
| 837 | * @ap: ATA port to freeze |
| 838 | * |
| 839 | * Freeze @ap. |
| 840 | * |
| 841 | * LOCKING: |
| 842 | * None. |
| 843 | */ |
| 844 | void ata_eh_freeze_port(struct ata_port *ap) |
| 845 | { |
| 846 | unsigned long flags; |
| 847 | |
| 848 | if (!ap->ops->error_handler) |
| 849 | return; |
| 850 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 851 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 852 | __ata_port_freeze(ap); |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 853 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | /** |
| 857 | * ata_port_thaw_port - EH helper to thaw port |
| 858 | * @ap: ATA port to thaw |
| 859 | * |
| 860 | * Thaw frozen port @ap. |
| 861 | * |
| 862 | * LOCKING: |
| 863 | * None. |
| 864 | */ |
| 865 | void ata_eh_thaw_port(struct ata_port *ap) |
| 866 | { |
| 867 | unsigned long flags; |
| 868 | |
| 869 | if (!ap->ops->error_handler) |
| 870 | return; |
| 871 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 872 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 873 | |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 874 | ap->pflags &= ~ATA_PFLAG_FROZEN; |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 875 | |
| 876 | if (ap->ops->thaw) |
| 877 | ap->ops->thaw(ap); |
| 878 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 879 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 880 | |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 881 | DPRINTK("ata%u port thawed\n", ap->print_id); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 882 | } |
| 883 | |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 884 | static void ata_eh_scsidone(struct scsi_cmnd *scmd) |
| 885 | { |
| 886 | /* nada */ |
| 887 | } |
| 888 | |
| 889 | static void __ata_eh_qc_complete(struct ata_queued_cmd *qc) |
| 890 | { |
| 891 | struct ata_port *ap = qc->ap; |
| 892 | struct scsi_cmnd *scmd = qc->scsicmd; |
| 893 | unsigned long flags; |
| 894 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 895 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 896 | qc->scsidone = ata_eh_scsidone; |
| 897 | __ata_qc_complete(qc); |
| 898 | WARN_ON(ata_tag_valid(qc->tag)); |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 899 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 900 | |
| 901 | scsi_eh_finish_cmd(scmd, &ap->eh_done_q); |
| 902 | } |
| 903 | |
| 904 | /** |
| 905 | * ata_eh_qc_complete - Complete an active ATA command from EH |
| 906 | * @qc: Command to complete |
| 907 | * |
| 908 | * Indicate to the mid and upper layers that an ATA command has |
| 909 | * completed. To be used from EH. |
| 910 | */ |
| 911 | void ata_eh_qc_complete(struct ata_queued_cmd *qc) |
| 912 | { |
| 913 | struct scsi_cmnd *scmd = qc->scsicmd; |
| 914 | scmd->retries = scmd->allowed; |
| 915 | __ata_eh_qc_complete(qc); |
| 916 | } |
| 917 | |
| 918 | /** |
| 919 | * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH |
| 920 | * @qc: Command to retry |
| 921 | * |
| 922 | * Indicate to the mid and upper layers that an ATA command |
| 923 | * should be retried. To be used from EH. |
| 924 | * |
| 925 | * SCSI midlayer limits the number of retries to scmd->allowed. |
| 926 | * scmd->retries is decremented for commands which get retried |
| 927 | * due to unrelated failures (qc->err_mask is zero). |
| 928 | */ |
| 929 | void ata_eh_qc_retry(struct ata_queued_cmd *qc) |
| 930 | { |
| 931 | struct scsi_cmnd *scmd = qc->scsicmd; |
| 932 | if (!qc->err_mask && scmd->retries) |
| 933 | scmd->retries--; |
| 934 | __ata_eh_qc_complete(qc); |
| 935 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 936 | |
| 937 | /** |
Tejun Heo | 0ea035a | 2006-05-31 18:28:01 +0900 | [diff] [blame] | 938 | * ata_eh_detach_dev - detach ATA device |
| 939 | * @dev: ATA device to detach |
| 940 | * |
| 941 | * Detach @dev. |
| 942 | * |
| 943 | * LOCKING: |
| 944 | * None. |
| 945 | */ |
| 946 | static void ata_eh_detach_dev(struct ata_device *dev) |
| 947 | { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 948 | struct ata_link *link = dev->link; |
| 949 | struct ata_port *ap = link->ap; |
Tejun Heo | 0ea035a | 2006-05-31 18:28:01 +0900 | [diff] [blame] | 950 | unsigned long flags; |
| 951 | |
| 952 | ata_dev_disable(dev); |
| 953 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 954 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 0ea035a | 2006-05-31 18:28:01 +0900 | [diff] [blame] | 955 | |
| 956 | dev->flags &= ~ATA_DFLAG_DETACH; |
| 957 | |
| 958 | if (ata_scsi_offline_dev(dev)) { |
| 959 | dev->flags |= ATA_DFLAG_DETACHED; |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 960 | ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG; |
Tejun Heo | 0ea035a | 2006-05-31 18:28:01 +0900 | [diff] [blame] | 961 | } |
| 962 | |
Tejun Heo | beb07c1 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 963 | /* clear per-dev EH actions */ |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 964 | ata_eh_clear_action(link, dev, &link->eh_info, ATA_EH_PERDEV_MASK); |
| 965 | ata_eh_clear_action(link, dev, &link->eh_context.i, ATA_EH_PERDEV_MASK); |
Tejun Heo | beb07c1 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 966 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 967 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 0ea035a | 2006-05-31 18:28:01 +0900 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | /** |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 971 | * ata_eh_about_to_do - about to perform eh_action |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 972 | * @link: target ATA link |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 973 | * @dev: target ATA dev for per-dev action (can be NULL) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 974 | * @action: action about to be performed |
| 975 | * |
| 976 | * Called just before performing EH actions to clear related bits |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 977 | * in @link->eh_info such that eh actions are not unnecessarily |
| 978 | * repeated. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 979 | * |
| 980 | * LOCKING: |
| 981 | * None. |
| 982 | */ |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 983 | static void ata_eh_about_to_do(struct ata_link *link, struct ata_device *dev, |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 984 | unsigned int action) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 985 | { |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 986 | struct ata_port *ap = link->ap; |
| 987 | struct ata_eh_info *ehi = &link->eh_info; |
| 988 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 989 | unsigned long flags; |
| 990 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 991 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 992 | |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 993 | /* Reset is represented by combination of actions and EHI |
| 994 | * flags. Suck in all related bits before clearing eh_info to |
| 995 | * avoid losing requested action. |
| 996 | */ |
| 997 | if (action & ATA_EH_RESET_MASK) { |
| 998 | ehc->i.action |= ehi->action & ATA_EH_RESET_MASK; |
| 999 | ehc->i.flags |= ehi->flags & ATA_EHI_RESET_MODIFIER_MASK; |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 1000 | |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 1001 | /* make sure all reset actions are cleared & clear EHI flags */ |
| 1002 | action |= ATA_EH_RESET_MASK; |
| 1003 | ehi->flags &= ~ATA_EHI_RESET_MODIFIER_MASK; |
| 1004 | } |
| 1005 | |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1006 | ata_eh_clear_action(link, dev, ehi, action); |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 1007 | |
| 1008 | if (!(ehc->i.flags & ATA_EHI_QUIET)) |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 1009 | ap->pflags |= ATA_PFLAG_RECOVERED; |
| 1010 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1011 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | /** |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1015 | * ata_eh_done - EH action complete |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1016 | * @ap: target ATA port |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1017 | * @dev: target ATA dev for per-dev action (can be NULL) |
| 1018 | * @action: action just completed |
| 1019 | * |
| 1020 | * Called right after performing EH actions to clear related bits |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1021 | * in @link->eh_context. |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1022 | * |
| 1023 | * LOCKING: |
| 1024 | * None. |
| 1025 | */ |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1026 | static void ata_eh_done(struct ata_link *link, struct ata_device *dev, |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1027 | unsigned int action) |
| 1028 | { |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1029 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1030 | |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 1031 | /* if reset is complete, clear all reset actions & reset modifier */ |
| 1032 | if (action & ATA_EH_RESET_MASK) { |
| 1033 | action |= ATA_EH_RESET_MASK; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1034 | ehc->i.flags &= ~ATA_EHI_RESET_MODIFIER_MASK; |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 1035 | } |
| 1036 | |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1037 | ata_eh_clear_action(link, dev, &ehc->i, action); |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | /** |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1041 | * ata_err_string - convert err_mask to descriptive string |
| 1042 | * @err_mask: error mask to convert to string |
| 1043 | * |
| 1044 | * Convert @err_mask to descriptive string. Errors are |
| 1045 | * prioritized according to severity and only the most severe |
| 1046 | * error is reported. |
| 1047 | * |
| 1048 | * LOCKING: |
| 1049 | * None. |
| 1050 | * |
| 1051 | * RETURNS: |
| 1052 | * Descriptive string for @err_mask |
| 1053 | */ |
| 1054 | static const char * ata_err_string(unsigned int err_mask) |
| 1055 | { |
| 1056 | if (err_mask & AC_ERR_HOST_BUS) |
| 1057 | return "host bus error"; |
| 1058 | if (err_mask & AC_ERR_ATA_BUS) |
| 1059 | return "ATA bus error"; |
| 1060 | if (err_mask & AC_ERR_TIMEOUT) |
| 1061 | return "timeout"; |
| 1062 | if (err_mask & AC_ERR_HSM) |
| 1063 | return "HSM violation"; |
| 1064 | if (err_mask & AC_ERR_SYSTEM) |
| 1065 | return "internal error"; |
| 1066 | if (err_mask & AC_ERR_MEDIA) |
| 1067 | return "media error"; |
| 1068 | if (err_mask & AC_ERR_INVALID) |
| 1069 | return "invalid argument"; |
| 1070 | if (err_mask & AC_ERR_DEV) |
| 1071 | return "device error"; |
| 1072 | return "unknown error"; |
| 1073 | } |
| 1074 | |
| 1075 | /** |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1076 | * ata_read_log_page - read a specific log page |
| 1077 | * @dev: target device |
| 1078 | * @page: page to read |
| 1079 | * @buf: buffer to store read page |
| 1080 | * @sectors: number of sectors to read |
| 1081 | * |
| 1082 | * Read log page using READ_LOG_EXT command. |
| 1083 | * |
| 1084 | * LOCKING: |
| 1085 | * Kernel thread context (may sleep). |
| 1086 | * |
| 1087 | * RETURNS: |
| 1088 | * 0 on success, AC_ERR_* mask otherwise. |
| 1089 | */ |
| 1090 | static unsigned int ata_read_log_page(struct ata_device *dev, |
| 1091 | u8 page, void *buf, unsigned int sectors) |
| 1092 | { |
| 1093 | struct ata_taskfile tf; |
| 1094 | unsigned int err_mask; |
| 1095 | |
| 1096 | DPRINTK("read log page - page %d\n", page); |
| 1097 | |
| 1098 | ata_tf_init(dev, &tf); |
| 1099 | tf.command = ATA_CMD_READ_LOG_EXT; |
| 1100 | tf.lbal = page; |
| 1101 | tf.nsect = sectors; |
| 1102 | tf.hob_nsect = sectors >> 8; |
| 1103 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_LBA48 | ATA_TFLAG_DEVICE; |
| 1104 | tf.protocol = ATA_PROT_PIO; |
| 1105 | |
| 1106 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE, |
| 1107 | buf, sectors * ATA_SECT_SIZE); |
| 1108 | |
| 1109 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
| 1110 | return err_mask; |
| 1111 | } |
| 1112 | |
| 1113 | /** |
| 1114 | * ata_eh_read_log_10h - Read log page 10h for NCQ error details |
| 1115 | * @dev: Device to read log page 10h from |
| 1116 | * @tag: Resulting tag of the failed command |
| 1117 | * @tf: Resulting taskfile registers of the failed command |
| 1118 | * |
| 1119 | * Read log page 10h to obtain NCQ error details and clear error |
| 1120 | * condition. |
| 1121 | * |
| 1122 | * LOCKING: |
| 1123 | * Kernel thread context (may sleep). |
| 1124 | * |
| 1125 | * RETURNS: |
| 1126 | * 0 on success, -errno otherwise. |
| 1127 | */ |
| 1128 | static int ata_eh_read_log_10h(struct ata_device *dev, |
| 1129 | int *tag, struct ata_taskfile *tf) |
| 1130 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1131 | u8 *buf = dev->link->ap->sector_buf; |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1132 | unsigned int err_mask; |
| 1133 | u8 csum; |
| 1134 | int i; |
| 1135 | |
| 1136 | err_mask = ata_read_log_page(dev, ATA_LOG_SATA_NCQ, buf, 1); |
| 1137 | if (err_mask) |
| 1138 | return -EIO; |
| 1139 | |
| 1140 | csum = 0; |
| 1141 | for (i = 0; i < ATA_SECT_SIZE; i++) |
| 1142 | csum += buf[i]; |
| 1143 | if (csum) |
| 1144 | ata_dev_printk(dev, KERN_WARNING, |
| 1145 | "invalid checksum 0x%x on log page 10h\n", csum); |
| 1146 | |
| 1147 | if (buf[0] & 0x80) |
| 1148 | return -ENOENT; |
| 1149 | |
| 1150 | *tag = buf[0] & 0x1f; |
| 1151 | |
| 1152 | tf->command = buf[2]; |
| 1153 | tf->feature = buf[3]; |
| 1154 | tf->lbal = buf[4]; |
| 1155 | tf->lbam = buf[5]; |
| 1156 | tf->lbah = buf[6]; |
| 1157 | tf->device = buf[7]; |
| 1158 | tf->hob_lbal = buf[8]; |
| 1159 | tf->hob_lbam = buf[9]; |
| 1160 | tf->hob_lbah = buf[10]; |
| 1161 | tf->nsect = buf[12]; |
| 1162 | tf->hob_nsect = buf[13]; |
| 1163 | |
| 1164 | return 0; |
| 1165 | } |
| 1166 | |
| 1167 | /** |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1168 | * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE |
| 1169 | * @dev: device to perform REQUEST_SENSE to |
| 1170 | * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long) |
| 1171 | * |
| 1172 | * Perform ATAPI REQUEST_SENSE after the device reported CHECK |
| 1173 | * SENSE. This function is EH helper. |
| 1174 | * |
| 1175 | * LOCKING: |
| 1176 | * Kernel thread context (may sleep). |
| 1177 | * |
| 1178 | * RETURNS: |
| 1179 | * 0 on success, AC_ERR_* mask on failure |
| 1180 | */ |
Albert Lee | 5628776 | 2007-04-02 11:30:46 +0800 | [diff] [blame] | 1181 | static unsigned int atapi_eh_request_sense(struct ata_queued_cmd *qc) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1182 | { |
Albert Lee | 5628776 | 2007-04-02 11:30:46 +0800 | [diff] [blame] | 1183 | struct ata_device *dev = qc->dev; |
| 1184 | unsigned char *sense_buf = qc->scsicmd->sense_buffer; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1185 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1186 | struct ata_taskfile tf; |
| 1187 | u8 cdb[ATAPI_CDB_LEN]; |
| 1188 | |
| 1189 | DPRINTK("ATAPI request sense\n"); |
| 1190 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1191 | /* FIXME: is this needed? */ |
| 1192 | memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE); |
| 1193 | |
Albert Lee | 5628776 | 2007-04-02 11:30:46 +0800 | [diff] [blame] | 1194 | /* initialize sense_buf with the error register, |
| 1195 | * for the case where they are -not- overwritten |
| 1196 | */ |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1197 | sense_buf[0] = 0x70; |
Albert Lee | 5628776 | 2007-04-02 11:30:46 +0800 | [diff] [blame] | 1198 | sense_buf[2] = qc->result_tf.feature >> 4; |
| 1199 | |
Jeff Garzik | a617c09 | 2007-05-21 20:14:23 -0400 | [diff] [blame] | 1200 | /* some devices time out if garbage left in tf */ |
Albert Lee | 5628776 | 2007-04-02 11:30:46 +0800 | [diff] [blame] | 1201 | ata_tf_init(dev, &tf); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1202 | |
| 1203 | memset(cdb, 0, ATAPI_CDB_LEN); |
| 1204 | cdb[0] = REQUEST_SENSE; |
| 1205 | cdb[4] = SCSI_SENSE_BUFFERSIZE; |
| 1206 | |
| 1207 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 1208 | tf.command = ATA_CMD_PACKET; |
| 1209 | |
| 1210 | /* is it pointless to prefer PIO for "safety reasons"? */ |
| 1211 | if (ap->flags & ATA_FLAG_PIO_DMA) { |
| 1212 | tf.protocol = ATA_PROT_ATAPI_DMA; |
| 1213 | tf.feature |= ATAPI_PKT_DMA; |
| 1214 | } else { |
| 1215 | tf.protocol = ATA_PROT_ATAPI; |
| 1216 | tf.lbam = (8 * 1024) & 0xff; |
| 1217 | tf.lbah = (8 * 1024) >> 8; |
| 1218 | } |
| 1219 | |
| 1220 | return ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE, |
| 1221 | sense_buf, SCSI_SENSE_BUFFERSIZE); |
| 1222 | } |
| 1223 | |
| 1224 | /** |
| 1225 | * ata_eh_analyze_serror - analyze SError for a failed port |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1226 | * @link: ATA link to analyze SError for |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1227 | * |
| 1228 | * Analyze SError if available and further determine cause of |
| 1229 | * failure. |
| 1230 | * |
| 1231 | * LOCKING: |
| 1232 | * None. |
| 1233 | */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1234 | static void ata_eh_analyze_serror(struct ata_link *link) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1235 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1236 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1237 | u32 serror = ehc->i.serror; |
| 1238 | unsigned int err_mask = 0, action = 0; |
| 1239 | |
| 1240 | if (serror & SERR_PERSISTENT) { |
| 1241 | err_mask |= AC_ERR_ATA_BUS; |
| 1242 | action |= ATA_EH_HARDRESET; |
| 1243 | } |
| 1244 | if (serror & |
| 1245 | (SERR_DATA_RECOVERED | SERR_COMM_RECOVERED | SERR_DATA)) { |
| 1246 | err_mask |= AC_ERR_ATA_BUS; |
| 1247 | action |= ATA_EH_SOFTRESET; |
| 1248 | } |
| 1249 | if (serror & SERR_PROTOCOL) { |
| 1250 | err_mask |= AC_ERR_HSM; |
| 1251 | action |= ATA_EH_SOFTRESET; |
| 1252 | } |
| 1253 | if (serror & SERR_INTERNAL) { |
| 1254 | err_mask |= AC_ERR_SYSTEM; |
Tejun Heo | 771b8da | 2007-03-14 01:20:51 +0900 | [diff] [blame] | 1255 | action |= ATA_EH_HARDRESET; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1256 | } |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 1257 | if (serror & (SERR_PHYRDY_CHG | SERR_DEV_XCHG)) |
| 1258 | ata_ehi_hotplugged(&ehc->i); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1259 | |
| 1260 | ehc->i.err_mask |= err_mask; |
| 1261 | ehc->i.action |= action; |
| 1262 | } |
| 1263 | |
| 1264 | /** |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1265 | * ata_eh_analyze_ncq_error - analyze NCQ error |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1266 | * @link: ATA link to analyze NCQ error for |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1267 | * |
| 1268 | * Read log page 10h, determine the offending qc and acquire |
| 1269 | * error status TF. For NCQ device errors, all LLDDs have to do |
| 1270 | * is setting AC_ERR_DEV in ehi->err_mask. This function takes |
| 1271 | * care of the rest. |
| 1272 | * |
| 1273 | * LOCKING: |
| 1274 | * Kernel thread context (may sleep). |
| 1275 | */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1276 | static void ata_eh_analyze_ncq_error(struct ata_link *link) |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1277 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1278 | struct ata_port *ap = link->ap; |
| 1279 | struct ata_eh_context *ehc = &link->eh_context; |
| 1280 | struct ata_device *dev = link->device; |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1281 | struct ata_queued_cmd *qc; |
| 1282 | struct ata_taskfile tf; |
| 1283 | int tag, rc; |
| 1284 | |
| 1285 | /* if frozen, we can't do much */ |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 1286 | if (ap->pflags & ATA_PFLAG_FROZEN) |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1287 | return; |
| 1288 | |
| 1289 | /* is it NCQ device error? */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1290 | if (!link->sactive || !(ehc->i.err_mask & AC_ERR_DEV)) |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1291 | return; |
| 1292 | |
| 1293 | /* has LLDD analyzed already? */ |
| 1294 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
| 1295 | qc = __ata_qc_from_tag(ap, tag); |
| 1296 | |
| 1297 | if (!(qc->flags & ATA_QCFLAG_FAILED)) |
| 1298 | continue; |
| 1299 | |
| 1300 | if (qc->err_mask) |
| 1301 | return; |
| 1302 | } |
| 1303 | |
| 1304 | /* okay, this error is ours */ |
| 1305 | rc = ata_eh_read_log_10h(dev, &tag, &tf); |
| 1306 | if (rc) { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1307 | ata_link_printk(link, KERN_ERR, "failed to read log page 10h " |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1308 | "(errno=%d)\n", rc); |
| 1309 | return; |
| 1310 | } |
| 1311 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1312 | if (!(link->sactive & (1 << tag))) { |
| 1313 | ata_link_printk(link, KERN_ERR, "log page 10h reported " |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1314 | "inactive tag %d\n", tag); |
| 1315 | return; |
| 1316 | } |
| 1317 | |
| 1318 | /* we've got the perpetrator, condemn it */ |
| 1319 | qc = __ata_qc_from_tag(ap, tag); |
| 1320 | memcpy(&qc->result_tf, &tf, sizeof(tf)); |
Tejun Heo | 5335b72 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 1321 | qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ; |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1322 | ehc->i.err_mask &= ~AC_ERR_DEV; |
| 1323 | } |
| 1324 | |
| 1325 | /** |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1326 | * ata_eh_analyze_tf - analyze taskfile of a failed qc |
| 1327 | * @qc: qc to analyze |
| 1328 | * @tf: Taskfile registers to analyze |
| 1329 | * |
| 1330 | * Analyze taskfile of @qc and further determine cause of |
| 1331 | * failure. This function also requests ATAPI sense data if |
| 1332 | * avaliable. |
| 1333 | * |
| 1334 | * LOCKING: |
| 1335 | * Kernel thread context (may sleep). |
| 1336 | * |
| 1337 | * RETURNS: |
| 1338 | * Determined recovery action |
| 1339 | */ |
| 1340 | static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc, |
| 1341 | const struct ata_taskfile *tf) |
| 1342 | { |
| 1343 | unsigned int tmp, action = 0; |
| 1344 | u8 stat = tf->command, err = tf->feature; |
| 1345 | |
| 1346 | if ((stat & (ATA_BUSY | ATA_DRQ | ATA_DRDY)) != ATA_DRDY) { |
| 1347 | qc->err_mask |= AC_ERR_HSM; |
| 1348 | return ATA_EH_SOFTRESET; |
| 1349 | } |
| 1350 | |
Tejun Heo | a51d644 | 2007-03-20 15:24:11 +0900 | [diff] [blame] | 1351 | if (stat & (ATA_ERR | ATA_DF)) |
| 1352 | qc->err_mask |= AC_ERR_DEV; |
| 1353 | else |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1354 | return 0; |
| 1355 | |
| 1356 | switch (qc->dev->class) { |
| 1357 | case ATA_DEV_ATA: |
| 1358 | if (err & ATA_ICRC) |
| 1359 | qc->err_mask |= AC_ERR_ATA_BUS; |
| 1360 | if (err & ATA_UNC) |
| 1361 | qc->err_mask |= AC_ERR_MEDIA; |
| 1362 | if (err & ATA_IDNF) |
| 1363 | qc->err_mask |= AC_ERR_INVALID; |
| 1364 | break; |
| 1365 | |
| 1366 | case ATA_DEV_ATAPI: |
Tejun Heo | a569a30 | 2006-11-21 10:40:51 +0900 | [diff] [blame] | 1367 | if (!(qc->ap->pflags & ATA_PFLAG_FROZEN)) { |
Albert Lee | 5628776 | 2007-04-02 11:30:46 +0800 | [diff] [blame] | 1368 | tmp = atapi_eh_request_sense(qc); |
Tejun Heo | a569a30 | 2006-11-21 10:40:51 +0900 | [diff] [blame] | 1369 | if (!tmp) { |
| 1370 | /* ATA_QCFLAG_SENSE_VALID is used to |
| 1371 | * tell atapi_qc_complete() that sense |
| 1372 | * data is already valid. |
| 1373 | * |
| 1374 | * TODO: interpret sense data and set |
| 1375 | * appropriate err_mask. |
| 1376 | */ |
| 1377 | qc->flags |= ATA_QCFLAG_SENSE_VALID; |
| 1378 | } else |
| 1379 | qc->err_mask |= tmp; |
| 1380 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | if (qc->err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT | AC_ERR_ATA_BUS)) |
| 1384 | action |= ATA_EH_SOFTRESET; |
| 1385 | |
| 1386 | return action; |
| 1387 | } |
| 1388 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1389 | static int ata_eh_categorize_error(int is_io, unsigned int err_mask) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1390 | { |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1391 | if (err_mask & AC_ERR_ATA_BUS) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1392 | return 1; |
| 1393 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1394 | if (err_mask & AC_ERR_TIMEOUT) |
| 1395 | return 2; |
| 1396 | |
| 1397 | if (is_io) { |
| 1398 | if (err_mask & AC_ERR_HSM) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1399 | return 2; |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1400 | if ((err_mask & |
| 1401 | (AC_ERR_DEV|AC_ERR_MEDIA|AC_ERR_INVALID)) == AC_ERR_DEV) |
| 1402 | return 3; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | return 0; |
| 1406 | } |
| 1407 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1408 | struct speed_down_verdict_arg { |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1409 | u64 since; |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1410 | int nr_errors[4]; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1411 | }; |
| 1412 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1413 | static int speed_down_verdict_cb(struct ata_ering_entry *ent, void *void_arg) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1414 | { |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1415 | struct speed_down_verdict_arg *arg = void_arg; |
| 1416 | int cat = ata_eh_categorize_error(ent->is_io, ent->err_mask); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1417 | |
| 1418 | if (ent->timestamp < arg->since) |
| 1419 | return -1; |
| 1420 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1421 | arg->nr_errors[cat]++; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1422 | return 0; |
| 1423 | } |
| 1424 | |
| 1425 | /** |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1426 | * ata_eh_speed_down_verdict - Determine speed down verdict |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1427 | * @dev: Device of interest |
| 1428 | * |
| 1429 | * This function examines error ring of @dev and determines |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1430 | * whether NCQ needs to be turned off, transfer speed should be |
| 1431 | * stepped down, or falling back to PIO is necessary. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1432 | * |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1433 | * Cat-1 is ATA_BUS error for any command. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1434 | * |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1435 | * Cat-2 is TIMEOUT for any command or HSM violation for known |
| 1436 | * supported commands. |
| 1437 | * |
| 1438 | * Cat-3 is is unclassified DEV error for known supported |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1439 | * command. |
| 1440 | * |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1441 | * NCQ needs to be turned off if there have been more than 3 |
| 1442 | * Cat-2 + Cat-3 errors during last 10 minutes. |
| 1443 | * |
| 1444 | * Speed down is necessary if there have been more than 3 Cat-1 + |
| 1445 | * Cat-2 errors or 10 Cat-3 errors during last 10 minutes. |
| 1446 | * |
| 1447 | * Falling back to PIO mode is necessary if there have been more |
| 1448 | * than 10 Cat-1 + Cat-2 + Cat-3 errors during last 5 minutes. |
| 1449 | * |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1450 | * LOCKING: |
| 1451 | * Inherited from caller. |
| 1452 | * |
| 1453 | * RETURNS: |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1454 | * OR of ATA_EH_SPDN_* flags. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1455 | */ |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1456 | static unsigned int ata_eh_speed_down_verdict(struct ata_device *dev) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1457 | { |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1458 | const u64 j5mins = 5LLU * 60 * HZ, j10mins = 10LLU * 60 * HZ; |
| 1459 | u64 j64 = get_jiffies_64(); |
| 1460 | struct speed_down_verdict_arg arg; |
| 1461 | unsigned int verdict = 0; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1462 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1463 | /* scan past 10 mins of error history */ |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1464 | memset(&arg, 0, sizeof(arg)); |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1465 | arg.since = j64 - min(j64, j10mins); |
| 1466 | ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1467 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1468 | if (arg.nr_errors[2] + arg.nr_errors[3] > 3) |
| 1469 | verdict |= ATA_EH_SPDN_NCQ_OFF; |
| 1470 | if (arg.nr_errors[1] + arg.nr_errors[2] > 3 || arg.nr_errors[3] > 10) |
| 1471 | verdict |= ATA_EH_SPDN_SPEED_DOWN; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1472 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1473 | /* scan past 3 mins of error history */ |
| 1474 | memset(&arg, 0, sizeof(arg)); |
| 1475 | arg.since = j64 - min(j64, j5mins); |
| 1476 | ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1477 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1478 | if (arg.nr_errors[1] + arg.nr_errors[2] + arg.nr_errors[3] > 10) |
| 1479 | verdict |= ATA_EH_SPDN_FALLBACK_TO_PIO; |
| 1480 | |
| 1481 | return verdict; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | /** |
| 1485 | * ata_eh_speed_down - record error and speed down if necessary |
| 1486 | * @dev: Failed device |
| 1487 | * @is_io: Did the device fail during normal IO? |
| 1488 | * @err_mask: err_mask of the error |
| 1489 | * |
| 1490 | * Record error and examine error history to determine whether |
| 1491 | * adjusting transmission speed is necessary. It also sets |
| 1492 | * transmission limits appropriately if such adjustment is |
| 1493 | * necessary. |
| 1494 | * |
| 1495 | * LOCKING: |
| 1496 | * Kernel thread context (may sleep). |
| 1497 | * |
| 1498 | * RETURNS: |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1499 | * Determined recovery action. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1500 | */ |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1501 | static unsigned int ata_eh_speed_down(struct ata_device *dev, int is_io, |
| 1502 | unsigned int err_mask) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1503 | { |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1504 | unsigned int verdict; |
| 1505 | unsigned int action = 0; |
| 1506 | |
| 1507 | /* don't bother if Cat-0 error */ |
| 1508 | if (ata_eh_categorize_error(is_io, err_mask) == 0) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1509 | return 0; |
| 1510 | |
| 1511 | /* record error and determine whether speed down is necessary */ |
| 1512 | ata_ering_record(&dev->ering, is_io, err_mask); |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1513 | verdict = ata_eh_speed_down_verdict(dev); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1514 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1515 | /* turn off NCQ? */ |
| 1516 | if ((verdict & ATA_EH_SPDN_NCQ_OFF) && |
| 1517 | (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ | |
| 1518 | ATA_DFLAG_NCQ_OFF)) == ATA_DFLAG_NCQ) { |
| 1519 | dev->flags |= ATA_DFLAG_NCQ_OFF; |
| 1520 | ata_dev_printk(dev, KERN_WARNING, |
| 1521 | "NCQ disabled due to excessive errors\n"); |
| 1522 | goto done; |
| 1523 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1524 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1525 | /* speed down? */ |
| 1526 | if (verdict & ATA_EH_SPDN_SPEED_DOWN) { |
| 1527 | /* speed down SATA link speed if possible */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1528 | if (sata_down_spd_limit(dev->link) == 0) { |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1529 | action |= ATA_EH_HARDRESET; |
| 1530 | goto done; |
| 1531 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1532 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1533 | /* lower transfer mode */ |
| 1534 | if (dev->spdn_cnt < 2) { |
| 1535 | static const int dma_dnxfer_sel[] = |
| 1536 | { ATA_DNXFER_DMA, ATA_DNXFER_40C }; |
| 1537 | static const int pio_dnxfer_sel[] = |
| 1538 | { ATA_DNXFER_PIO, ATA_DNXFER_FORCE_PIO0 }; |
| 1539 | int sel; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1540 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1541 | if (dev->xfer_shift != ATA_SHIFT_PIO) |
| 1542 | sel = dma_dnxfer_sel[dev->spdn_cnt]; |
| 1543 | else |
| 1544 | sel = pio_dnxfer_sel[dev->spdn_cnt]; |
| 1545 | |
| 1546 | dev->spdn_cnt++; |
| 1547 | |
| 1548 | if (ata_down_xfermask_limit(dev, sel) == 0) { |
| 1549 | action |= ATA_EH_SOFTRESET; |
| 1550 | goto done; |
| 1551 | } |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | /* Fall back to PIO? Slowing down to PIO is meaningless for |
| 1556 | * SATA. Consider it only for PATA. |
| 1557 | */ |
| 1558 | if ((verdict & ATA_EH_SPDN_FALLBACK_TO_PIO) && (dev->spdn_cnt >= 2) && |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1559 | (dev->link->ap->cbl != ATA_CBL_SATA) && |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1560 | (dev->xfer_shift != ATA_SHIFT_PIO)) { |
| 1561 | if (ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO) == 0) { |
| 1562 | dev->spdn_cnt = 0; |
| 1563 | action |= ATA_EH_SOFTRESET; |
| 1564 | goto done; |
| 1565 | } |
| 1566 | } |
| 1567 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1568 | return 0; |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1569 | done: |
| 1570 | /* device has been slowed down, blow error history */ |
| 1571 | ata_ering_clear(&dev->ering); |
| 1572 | return action; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | /** |
| 1576 | * ata_eh_autopsy - analyze error and determine recovery action |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1577 | * @link: ATA link to perform autopsy on |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1578 | * |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1579 | * Analyze why @link failed and determine which recovery actions |
| 1580 | * are needed. This function also sets more detailed AC_ERR_* |
| 1581 | * values and fills sense data for ATAPI CHECK SENSE. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1582 | * |
| 1583 | * LOCKING: |
| 1584 | * Kernel thread context (may sleep). |
| 1585 | */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1586 | static void ata_eh_autopsy(struct ata_link *link) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1587 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1588 | struct ata_port *ap = link->ap; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1589 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1590 | unsigned int all_err_mask = 0; |
| 1591 | int tag, is_io = 0; |
| 1592 | u32 serror; |
| 1593 | int rc; |
| 1594 | |
| 1595 | DPRINTK("ENTER\n"); |
| 1596 | |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 1597 | if (ehc->i.flags & ATA_EHI_NO_AUTOPSY) |
| 1598 | return; |
| 1599 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1600 | /* obtain and analyze SError */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1601 | rc = sata_scr_read(link, SCR_ERROR, &serror); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1602 | if (rc == 0) { |
| 1603 | ehc->i.serror |= serror; |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1604 | ata_eh_analyze_serror(link); |
Tejun Heo | 4e57c51 | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 1605 | } else if (rc != -EOPNOTSUPP) { |
| 1606 | /* SError read failed, force hardreset and probing */ |
| 1607 | ata_ehi_schedule_probe(&ehc->i); |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1608 | ehc->i.action |= ATA_EH_HARDRESET; |
Tejun Heo | 4e57c51 | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 1609 | ehc->i.err_mask |= AC_ERR_OTHER; |
| 1610 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1611 | |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1612 | /* analyze NCQ failure */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1613 | ata_eh_analyze_ncq_error(link); |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1614 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1615 | /* any real error trumps AC_ERR_OTHER */ |
| 1616 | if (ehc->i.err_mask & ~AC_ERR_OTHER) |
| 1617 | ehc->i.err_mask &= ~AC_ERR_OTHER; |
| 1618 | |
| 1619 | all_err_mask |= ehc->i.err_mask; |
| 1620 | |
| 1621 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
| 1622 | struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); |
| 1623 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1624 | if (!(qc->flags & ATA_QCFLAG_FAILED) || qc->dev->link != link) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1625 | continue; |
| 1626 | |
| 1627 | /* inherit upper level err_mask */ |
| 1628 | qc->err_mask |= ehc->i.err_mask; |
| 1629 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1630 | /* analyze TF */ |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1631 | ehc->i.action |= ata_eh_analyze_tf(qc, &qc->result_tf); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1632 | |
| 1633 | /* DEV errors are probably spurious in case of ATA_BUS error */ |
| 1634 | if (qc->err_mask & AC_ERR_ATA_BUS) |
| 1635 | qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_MEDIA | |
| 1636 | AC_ERR_INVALID); |
| 1637 | |
| 1638 | /* any real error trumps unknown error */ |
| 1639 | if (qc->err_mask & ~AC_ERR_OTHER) |
| 1640 | qc->err_mask &= ~AC_ERR_OTHER; |
| 1641 | |
| 1642 | /* SENSE_VALID trumps dev/unknown error and revalidation */ |
| 1643 | if (qc->flags & ATA_QCFLAG_SENSE_VALID) { |
| 1644 | qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER); |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1645 | ehc->i.action &= ~ATA_EH_REVALIDATE; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | /* accumulate error info */ |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1649 | ehc->i.dev = qc->dev; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1650 | all_err_mask |= qc->err_mask; |
| 1651 | if (qc->flags & ATA_QCFLAG_IO) |
| 1652 | is_io = 1; |
| 1653 | } |
| 1654 | |
Tejun Heo | a20f33f | 2006-05-16 12:58:24 +0900 | [diff] [blame] | 1655 | /* enforce default EH actions */ |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 1656 | if (ap->pflags & ATA_PFLAG_FROZEN || |
Tejun Heo | a20f33f | 2006-05-16 12:58:24 +0900 | [diff] [blame] | 1657 | all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT)) |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1658 | ehc->i.action |= ATA_EH_SOFTRESET; |
Tejun Heo | a20f33f | 2006-05-16 12:58:24 +0900 | [diff] [blame] | 1659 | else if (all_err_mask) |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1660 | ehc->i.action |= ATA_EH_REVALIDATE; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1661 | |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1662 | /* if we have offending qcs and the associated failed device */ |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1663 | if (ehc->i.dev) { |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1664 | /* speed down */ |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1665 | ehc->i.action |= ata_eh_speed_down(ehc->i.dev, is_io, |
| 1666 | all_err_mask); |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1667 | |
| 1668 | /* perform per-dev EH action only on the offending device */ |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1669 | ehc->i.dev_action[ehc->i.dev->devno] |= |
| 1670 | ehc->i.action & ATA_EH_PERDEV_MASK; |
| 1671 | ehc->i.action &= ~ATA_EH_PERDEV_MASK; |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1672 | } |
| 1673 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1674 | DPRINTK("EXIT\n"); |
| 1675 | } |
| 1676 | |
| 1677 | /** |
| 1678 | * ata_eh_report - report error handling to user |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1679 | * @link: ATA link EH is going on |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1680 | * |
| 1681 | * Report EH to user. |
| 1682 | * |
| 1683 | * LOCKING: |
| 1684 | * None. |
| 1685 | */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1686 | static void ata_eh_report(struct ata_link *link) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1687 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1688 | struct ata_port *ap = link->ap; |
| 1689 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1690 | const char *frozen, *desc; |
| 1691 | int tag, nr_failed = 0; |
| 1692 | |
| 1693 | desc = NULL; |
| 1694 | if (ehc->i.desc[0] != '\0') |
| 1695 | desc = ehc->i.desc; |
| 1696 | |
| 1697 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
| 1698 | struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); |
| 1699 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1700 | if (!(qc->flags & ATA_QCFLAG_FAILED) || qc->dev->link != link) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1701 | continue; |
| 1702 | if (qc->flags & ATA_QCFLAG_SENSE_VALID && !qc->err_mask) |
| 1703 | continue; |
| 1704 | |
| 1705 | nr_failed++; |
| 1706 | } |
| 1707 | |
| 1708 | if (!nr_failed && !ehc->i.err_mask) |
| 1709 | return; |
| 1710 | |
| 1711 | frozen = ""; |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 1712 | if (ap->pflags & ATA_PFLAG_FROZEN) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1713 | frozen = " frozen"; |
| 1714 | |
| 1715 | if (ehc->i.dev) { |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1716 | ata_dev_printk(ehc->i.dev, KERN_ERR, "exception Emask 0x%x " |
| 1717 | "SAct 0x%x SErr 0x%x action 0x%x%s\n", |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1718 | ehc->i.err_mask, link->sactive, |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1719 | ehc->i.serror, ehc->i.action, frozen); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1720 | if (desc) |
Tejun Heo | b64bbc3 | 2007-07-16 14:29:39 +0900 | [diff] [blame] | 1721 | ata_dev_printk(ehc->i.dev, KERN_ERR, "%s\n", desc); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1722 | } else { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1723 | ata_link_printk(link, KERN_ERR, "exception Emask 0x%x " |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1724 | "SAct 0x%x SErr 0x%x action 0x%x%s\n", |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1725 | ehc->i.err_mask, link->sactive, |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1726 | ehc->i.serror, ehc->i.action, frozen); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1727 | if (desc) |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1728 | ata_link_printk(link, KERN_ERR, "%s\n", desc); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
Tejun Heo | 8a93758 | 2006-11-14 22:36:12 +0900 | [diff] [blame] | 1732 | static const char *dma_str[] = { |
| 1733 | [DMA_BIDIRECTIONAL] = "bidi", |
| 1734 | [DMA_TO_DEVICE] = "out", |
| 1735 | [DMA_FROM_DEVICE] = "in", |
| 1736 | [DMA_NONE] = "", |
| 1737 | }; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1738 | struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); |
Tejun Heo | 8a93758 | 2006-11-14 22:36:12 +0900 | [diff] [blame] | 1739 | struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1740 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1741 | if (!(qc->flags & ATA_QCFLAG_FAILED) || |
| 1742 | qc->dev->link != link || !qc->err_mask) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1743 | continue; |
| 1744 | |
Tejun Heo | 8a93758 | 2006-11-14 22:36:12 +0900 | [diff] [blame] | 1745 | ata_dev_printk(qc->dev, KERN_ERR, |
| 1746 | "cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x " |
Tejun Heo | 664e850 | 2006-11-20 16:05:34 +0900 | [diff] [blame] | 1747 | "tag %d cdb 0x%x data %u %s\n " |
Tejun Heo | 8a93758 | 2006-11-14 22:36:12 +0900 | [diff] [blame] | 1748 | "res %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x " |
Tejun Heo | 5335b72 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 1749 | "Emask 0x%x (%s)%s\n", |
Tejun Heo | 8a93758 | 2006-11-14 22:36:12 +0900 | [diff] [blame] | 1750 | cmd->command, cmd->feature, cmd->nsect, |
| 1751 | cmd->lbal, cmd->lbam, cmd->lbah, |
| 1752 | cmd->hob_feature, cmd->hob_nsect, |
| 1753 | cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah, |
Tejun Heo | 726f078 | 2007-01-03 17:30:39 +0900 | [diff] [blame] | 1754 | cmd->device, qc->tag, qc->cdb[0], qc->nbytes, |
Tejun Heo | 664e850 | 2006-11-20 16:05:34 +0900 | [diff] [blame] | 1755 | dma_str[qc->dma_dir], |
Tejun Heo | 8a93758 | 2006-11-14 22:36:12 +0900 | [diff] [blame] | 1756 | res->command, res->feature, res->nsect, |
| 1757 | res->lbal, res->lbam, res->lbah, |
| 1758 | res->hob_feature, res->hob_nsect, |
| 1759 | res->hob_lbal, res->hob_lbam, res->hob_lbah, |
Tejun Heo | 5335b72 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 1760 | res->device, qc->err_mask, ata_err_string(qc->err_mask), |
| 1761 | qc->err_mask & AC_ERR_NCQ ? " <F>" : ""); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1762 | } |
| 1763 | } |
| 1764 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1765 | static int ata_do_reset(struct ata_link *link, ata_reset_fn_t reset, |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 1766 | unsigned int *classes, unsigned long deadline) |
Tejun Heo | d87fa38 | 2006-05-31 18:28:24 +0900 | [diff] [blame] | 1767 | { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1768 | struct ata_device *dev; |
| 1769 | int rc; |
Tejun Heo | d87fa38 | 2006-05-31 18:28:24 +0900 | [diff] [blame] | 1770 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1771 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1772 | classes[dev->devno] = ATA_DEV_UNKNOWN; |
Tejun Heo | d87fa38 | 2006-05-31 18:28:24 +0900 | [diff] [blame] | 1773 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1774 | rc = reset(link, classes, deadline); |
Tejun Heo | d87fa38 | 2006-05-31 18:28:24 +0900 | [diff] [blame] | 1775 | if (rc) |
| 1776 | return rc; |
| 1777 | |
| 1778 | /* If any class isn't ATA_DEV_UNKNOWN, consider classification |
| 1779 | * is complete and convert all ATA_DEV_UNKNOWN to |
| 1780 | * ATA_DEV_NONE. |
| 1781 | */ |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1782 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1783 | if (classes[dev->devno] != ATA_DEV_UNKNOWN) |
Tejun Heo | d87fa38 | 2006-05-31 18:28:24 +0900 | [diff] [blame] | 1784 | break; |
| 1785 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1786 | if (dev) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1787 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1788 | if (classes[dev->devno] == ATA_DEV_UNKNOWN) |
| 1789 | classes[dev->devno] = ATA_DEV_NONE; |
| 1790 | } |
| 1791 | } |
Tejun Heo | d87fa38 | 2006-05-31 18:28:24 +0900 | [diff] [blame] | 1792 | |
| 1793 | return 0; |
| 1794 | } |
| 1795 | |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 1796 | static int ata_eh_followup_srst_needed(int rc, int classify, |
| 1797 | const unsigned int *classes) |
| 1798 | { |
| 1799 | if (rc == -EAGAIN) |
| 1800 | return 1; |
| 1801 | if (rc != 0) |
| 1802 | return 0; |
| 1803 | if (classify && classes[0] == ATA_DEV_UNKNOWN) |
| 1804 | return 1; |
| 1805 | return 0; |
| 1806 | } |
| 1807 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1808 | static int ata_eh_reset(struct ata_link *link, int classify, |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 1809 | ata_prereset_fn_t prereset, ata_reset_fn_t softreset, |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1810 | ata_reset_fn_t hardreset, ata_postreset_fn_t postreset) |
| 1811 | { |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1812 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 1813 | unsigned int *classes = ehc->classes; |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 1814 | int verbose = !(ehc->i.flags & ATA_EHI_QUIET); |
Tejun Heo | 31daabd | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 1815 | int try = 0; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1816 | struct ata_device *dev; |
Tejun Heo | 31daabd | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 1817 | unsigned long deadline; |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 1818 | unsigned int action; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1819 | ata_reset_fn_t reset; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1820 | int rc; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1821 | |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 1822 | /* about to reset */ |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1823 | ata_eh_about_to_do(link, NULL, ehc->i.action & ATA_EH_RESET_MASK); |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 1824 | |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 1825 | /* Determine which reset to use and record in ehc->i.action. |
| 1826 | * prereset() may examine and modify it. |
| 1827 | */ |
| 1828 | action = ehc->i.action; |
| 1829 | ehc->i.action &= ~ATA_EH_RESET_MASK; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1830 | if (softreset && (!hardreset || (!sata_set_spd_needed(link) && |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 1831 | !(action & ATA_EH_HARDRESET)))) |
| 1832 | ehc->i.action |= ATA_EH_SOFTRESET; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1833 | else |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 1834 | ehc->i.action |= ATA_EH_HARDRESET; |
| 1835 | |
| 1836 | if (prereset) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1837 | rc = prereset(link, jiffies + ATA_EH_PRERESET_TIMEOUT); |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 1838 | if (rc) { |
Alan Cox | c961922 | 2006-09-26 17:53:38 +0100 | [diff] [blame] | 1839 | if (rc == -ENOENT) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1840 | ata_link_printk(link, KERN_DEBUG, |
Tejun Heo | 4aa9ab6 | 2007-03-12 17:24:08 +0900 | [diff] [blame] | 1841 | "port disabled. ignoring.\n"); |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1842 | ehc->i.action &= ~ATA_EH_RESET_MASK; |
Tejun Heo | 4aa9ab6 | 2007-03-12 17:24:08 +0900 | [diff] [blame] | 1843 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1844 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1845 | classes[dev->devno] = ATA_DEV_NONE; |
Tejun Heo | 4aa9ab6 | 2007-03-12 17:24:08 +0900 | [diff] [blame] | 1846 | |
| 1847 | rc = 0; |
Alan Cox | c961922 | 2006-09-26 17:53:38 +0100 | [diff] [blame] | 1848 | } else |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1849 | ata_link_printk(link, KERN_ERR, |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 1850 | "prereset failed (errno=%d)\n", rc); |
Tejun Heo | fccb6ea | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 1851 | goto out; |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | /* prereset() might have modified ehc->i.action */ |
| 1856 | if (ehc->i.action & ATA_EH_HARDRESET) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1857 | reset = hardreset; |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 1858 | else if (ehc->i.action & ATA_EH_SOFTRESET) |
| 1859 | reset = softreset; |
| 1860 | else { |
| 1861 | /* prereset told us not to reset, bang classes and return */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1862 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1863 | classes[dev->devno] = ATA_DEV_NONE; |
Tejun Heo | fccb6ea | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 1864 | rc = 0; |
| 1865 | goto out; |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | /* did prereset() screw up? if so, fix up to avoid oopsing */ |
| 1869 | if (!reset) { |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 1870 | if (softreset) |
| 1871 | reset = softreset; |
| 1872 | else |
| 1873 | reset = hardreset; |
| 1874 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1875 | |
| 1876 | retry: |
Tejun Heo | 31daabd | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 1877 | deadline = jiffies + ata_eh_reset_timeouts[try++]; |
| 1878 | |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 1879 | /* shut up during boot probing */ |
| 1880 | if (verbose) |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1881 | ata_link_printk(link, KERN_INFO, "%s resetting link\n", |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 1882 | reset == softreset ? "soft" : "hard"); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1883 | |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 1884 | /* mark that this EH session started with reset */ |
Tejun Heo | 0d64a23 | 2007-04-23 02:41:05 +0900 | [diff] [blame] | 1885 | if (reset == hardreset) |
| 1886 | ehc->i.flags |= ATA_EHI_DID_HARDRESET; |
| 1887 | else |
| 1888 | ehc->i.flags |= ATA_EHI_DID_SOFTRESET; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1889 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1890 | rc = ata_do_reset(link, reset, classes, deadline); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1891 | |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 1892 | if (reset == hardreset && |
| 1893 | ata_eh_followup_srst_needed(rc, classify, classes)) { |
| 1894 | /* okay, let's do follow-up softreset */ |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 1895 | reset = softreset; |
| 1896 | |
| 1897 | if (!reset) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1898 | ata_link_printk(link, KERN_ERR, |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 1899 | "follow-up softreset required " |
| 1900 | "but no softreset avaliable\n"); |
Tejun Heo | fccb6ea | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 1901 | rc = -EINVAL; |
| 1902 | goto out; |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 1903 | } |
| 1904 | |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1905 | ata_eh_about_to_do(link, NULL, ATA_EH_RESET_MASK); |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1906 | rc = ata_do_reset(link, reset, classes, deadline); |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 1907 | |
| 1908 | if (rc == 0 && classify && |
| 1909 | classes[0] == ATA_DEV_UNKNOWN) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1910 | ata_link_printk(link, KERN_ERR, |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 1911 | "classification failed\n"); |
Tejun Heo | fccb6ea | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 1912 | rc = -EINVAL; |
| 1913 | goto out; |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 1914 | } |
| 1915 | } |
| 1916 | |
Tejun Heo | 31daabd | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 1917 | if (rc && try < ARRAY_SIZE(ata_eh_reset_timeouts)) { |
| 1918 | unsigned long now = jiffies; |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 1919 | |
Tejun Heo | 31daabd | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 1920 | if (time_before(now, deadline)) { |
| 1921 | unsigned long delta = deadline - jiffies; |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 1922 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1923 | ata_link_printk(link, KERN_WARNING, "reset failed " |
Tejun Heo | 31daabd | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 1924 | "(errno=%d), retrying in %u secs\n", |
| 1925 | rc, (jiffies_to_msecs(delta) + 999) / 1000); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1926 | |
Tejun Heo | 31daabd | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 1927 | schedule_timeout_uninterruptible(delta); |
| 1928 | } |
| 1929 | |
Tejun Heo | f154515 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 1930 | if (rc == -EPIPE || |
Tejun Heo | 31daabd | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 1931 | try == ARRAY_SIZE(ata_eh_reset_timeouts) - 1) |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1932 | sata_down_spd_limit(link); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1933 | if (hardreset) |
| 1934 | reset = hardreset; |
| 1935 | goto retry; |
| 1936 | } |
| 1937 | |
| 1938 | if (rc == 0) { |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 1939 | u32 sstatus; |
| 1940 | |
Tejun Heo | 20952b6 | 2006-05-31 18:27:23 +0900 | [diff] [blame] | 1941 | /* After the reset, the device state is PIO 0 and the |
| 1942 | * controller state is undefined. Record the mode. |
| 1943 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1944 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1945 | dev->pio_mode = XFER_PIO_0; |
Tejun Heo | 20952b6 | 2006-05-31 18:27:23 +0900 | [diff] [blame] | 1946 | |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 1947 | /* record current link speed */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1948 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0) |
| 1949 | link->sata_spd = (sstatus >> 4) & 0xf; |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 1950 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1951 | if (postreset) |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1952 | postreset(link, classes); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1953 | |
| 1954 | /* reset successful, schedule revalidation */ |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1955 | ata_eh_done(link, NULL, ehc->i.action & ATA_EH_RESET_MASK); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1956 | ehc->i.action |= ATA_EH_REVALIDATE; |
| 1957 | } |
Tejun Heo | fccb6ea | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 1958 | out: |
| 1959 | /* clear hotplug flag */ |
| 1960 | ehc->i.flags &= ~ATA_EHI_HOTPLUGGED; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1961 | return rc; |
| 1962 | } |
| 1963 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1964 | static int ata_eh_revalidate_and_attach(struct ata_link *link, |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 1965 | struct ata_device **r_failed_dev) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1966 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1967 | struct ata_port *ap = link->ap; |
| 1968 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1969 | struct ata_device *dev; |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 1970 | unsigned int new_mask = 0; |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 1971 | unsigned long flags; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1972 | int rc = 0; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1973 | |
| 1974 | DPRINTK("ENTER\n"); |
| 1975 | |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 1976 | /* For PATA drive side cable detection to work, IDENTIFY must |
| 1977 | * be done backwards such that PDIAG- is released by the slave |
| 1978 | * device before the master device is identified. |
| 1979 | */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1980 | ata_link_for_each_dev_reverse(dev, link) { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1981 | unsigned int action = ata_eh_dev_action(dev); |
| 1982 | unsigned int readid_flags = 0; |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1983 | |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 1984 | if (ehc->i.flags & ATA_EHI_DID_RESET) |
| 1985 | readid_flags |= ATA_READID_POSTRESET; |
| 1986 | |
Tejun Heo | 9666f40 | 2007-05-04 21:27:47 +0200 | [diff] [blame] | 1987 | if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1988 | if (ata_link_offline(link)) { |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1989 | rc = -EIO; |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 1990 | goto err; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1991 | } |
| 1992 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1993 | ata_eh_about_to_do(link, dev, ATA_EH_REVALIDATE); |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 1994 | rc = ata_dev_revalidate(dev, readid_flags); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1995 | if (rc) |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 1996 | goto err; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1997 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1998 | ata_eh_done(link, dev, ATA_EH_REVALIDATE); |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1999 | |
Tejun Heo | baa1e78 | 2006-11-01 18:39:27 +0900 | [diff] [blame] | 2000 | /* Configuration may have changed, reconfigure |
| 2001 | * transfer mode. |
| 2002 | */ |
| 2003 | ehc->i.flags |= ATA_EHI_SETMODE; |
| 2004 | |
zhao, forrest | 3057ac3 | 2006-06-12 12:01:34 +0800 | [diff] [blame] | 2005 | /* schedule the scsi_rescan_device() here */ |
| 2006 | queue_work(ata_aux_wq, &(ap->scsi_rescan_task)); |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2007 | } else if (dev->class == ATA_DEV_UNKNOWN && |
| 2008 | ehc->tries[dev->devno] && |
| 2009 | ata_class_enabled(ehc->classes[dev->devno])) { |
| 2010 | dev->class = ehc->classes[dev->devno]; |
| 2011 | |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 2012 | rc = ata_dev_read_id(dev, &dev->class, readid_flags, |
| 2013 | dev->id); |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2014 | switch (rc) { |
| 2015 | case 0: |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2016 | new_mask |= 1 << dev->devno; |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2017 | break; |
| 2018 | case -ENOENT: |
Tejun Heo | 55a8e2c | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 2019 | /* IDENTIFY was issued to non-existent |
| 2020 | * device. No need to reset. Just |
| 2021 | * thaw and kill the device. |
| 2022 | */ |
| 2023 | ata_eh_thaw_port(ap); |
| 2024 | dev->class = ATA_DEV_UNKNOWN; |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2025 | break; |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2026 | default: |
| 2027 | dev->class = ATA_DEV_UNKNOWN; |
| 2028 | goto err; |
Tejun Heo | 55a8e2c | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 2029 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2030 | } |
| 2031 | } |
| 2032 | |
Tejun Heo | c1c4e8d | 2007-04-23 02:05:53 +0900 | [diff] [blame] | 2033 | /* PDIAG- should have been released, ask cable type if post-reset */ |
| 2034 | if ((ehc->i.flags & ATA_EHI_DID_RESET) && ap->ops->cable_detect) |
| 2035 | ap->cbl = ap->ops->cable_detect(ap); |
| 2036 | |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2037 | /* Configure new devices forward such that user doesn't see |
| 2038 | * device detection messages backwards. |
| 2039 | */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2040 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2041 | if (!(new_mask & (1 << dev->devno))) |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2042 | continue; |
| 2043 | |
| 2044 | ehc->i.flags |= ATA_EHI_PRINTINFO; |
| 2045 | rc = ata_dev_configure(dev); |
| 2046 | ehc->i.flags &= ~ATA_EHI_PRINTINFO; |
| 2047 | if (rc) |
| 2048 | goto err; |
| 2049 | |
| 2050 | spin_lock_irqsave(ap->lock, flags); |
| 2051 | ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG; |
| 2052 | spin_unlock_irqrestore(ap->lock, flags); |
| 2053 | |
| 2054 | /* new device discovered, configure xfermode */ |
| 2055 | ehc->i.flags |= ATA_EHI_SETMODE; |
| 2056 | } |
| 2057 | |
| 2058 | return 0; |
| 2059 | |
| 2060 | err: |
| 2061 | *r_failed_dev = dev; |
| 2062 | DPRINTK("EXIT rc=%d\n", rc); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2063 | return rc; |
| 2064 | } |
| 2065 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2066 | static int ata_link_nr_enabled(struct ata_link *link) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2067 | { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2068 | struct ata_device *dev; |
| 2069 | int cnt = 0; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2070 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2071 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2072 | if (ata_dev_enabled(dev)) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2073 | cnt++; |
| 2074 | return cnt; |
| 2075 | } |
| 2076 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2077 | static int ata_link_nr_vacant(struct ata_link *link) |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2078 | { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2079 | struct ata_device *dev; |
| 2080 | int cnt = 0; |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2081 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2082 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2083 | if (dev->class == ATA_DEV_UNKNOWN) |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2084 | cnt++; |
| 2085 | return cnt; |
| 2086 | } |
| 2087 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2088 | static int ata_eh_skip_recovery(struct ata_link *link) |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2089 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2090 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2091 | struct ata_device *dev; |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2092 | |
Tejun Heo | 7c8c2cf | 2006-07-10 23:18:23 +0900 | [diff] [blame] | 2093 | /* thaw frozen port, resume link and recover failed devices */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2094 | if ((link->ap->pflags & ATA_PFLAG_FROZEN) || |
| 2095 | (ehc->i.flags & ATA_EHI_RESUME_LINK) || ata_link_nr_enabled(link)) |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2096 | return 0; |
| 2097 | |
| 2098 | /* skip if class codes for all vacant slots are ATA_DEV_NONE */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2099 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2100 | if (dev->class == ATA_DEV_UNKNOWN && |
| 2101 | ehc->classes[dev->devno] != ATA_DEV_NONE) |
| 2102 | return 0; |
| 2103 | } |
| 2104 | |
| 2105 | return 1; |
| 2106 | } |
| 2107 | |
Tejun Heo | fee7ca7 | 2007-07-01 19:05:58 +0900 | [diff] [blame] | 2108 | static void ata_eh_handle_dev_fail(struct ata_device *dev, int err) |
| 2109 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2110 | struct ata_eh_context *ehc = &dev->link->eh_context; |
Tejun Heo | fee7ca7 | 2007-07-01 19:05:58 +0900 | [diff] [blame] | 2111 | |
| 2112 | ehc->tries[dev->devno]--; |
| 2113 | |
| 2114 | switch (err) { |
| 2115 | case -ENODEV: |
| 2116 | /* device missing or wrong IDENTIFY data, schedule probing */ |
| 2117 | ehc->i.probe_mask |= (1 << dev->devno); |
| 2118 | case -EINVAL: |
| 2119 | /* give it just one more chance */ |
| 2120 | ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1); |
| 2121 | case -EIO: |
| 2122 | if (ehc->tries[dev->devno] == 1) { |
| 2123 | /* This is the last chance, better to slow |
| 2124 | * down than lose it. |
| 2125 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2126 | sata_down_spd_limit(dev->link); |
Tejun Heo | fee7ca7 | 2007-07-01 19:05:58 +0900 | [diff] [blame] | 2127 | ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) { |
| 2132 | /* disable device if it has used up all its chances */ |
| 2133 | ata_dev_disable(dev); |
| 2134 | |
| 2135 | /* detach if offline */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2136 | if (ata_link_offline(dev->link)) |
Tejun Heo | fee7ca7 | 2007-07-01 19:05:58 +0900 | [diff] [blame] | 2137 | ata_eh_detach_dev(dev); |
| 2138 | |
| 2139 | /* probe if requested */ |
| 2140 | if ((ehc->i.probe_mask & (1 << dev->devno)) && |
| 2141 | !(ehc->did_probe_mask & (1 << dev->devno))) { |
| 2142 | ata_eh_detach_dev(dev); |
| 2143 | ata_dev_init(dev); |
| 2144 | |
| 2145 | ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; |
| 2146 | ehc->did_probe_mask |= (1 << dev->devno); |
| 2147 | ehc->i.action |= ATA_EH_SOFTRESET; |
| 2148 | } |
| 2149 | } else { |
| 2150 | /* soft didn't work? be haaaaard */ |
| 2151 | if (ehc->i.flags & ATA_EHI_DID_RESET) |
| 2152 | ehc->i.action |= ATA_EH_HARDRESET; |
| 2153 | else |
| 2154 | ehc->i.action |= ATA_EH_SOFTRESET; |
| 2155 | } |
| 2156 | } |
| 2157 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2158 | /** |
| 2159 | * ata_eh_recover - recover host port after error |
| 2160 | * @ap: host port to recover |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2161 | * @prereset: prereset method (can be NULL) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2162 | * @softreset: softreset method (can be NULL) |
| 2163 | * @hardreset: hardreset method (can be NULL) |
| 2164 | * @postreset: postreset method (can be NULL) |
| 2165 | * |
| 2166 | * This is the alpha and omega, eum and yang, heart and soul of |
| 2167 | * libata exception handling. On entry, actions required to |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2168 | * recover the port and hotplug requests are recorded in |
| 2169 | * eh_context. This function executes all the operations with |
| 2170 | * appropriate retrials and fallbacks to resurrect failed |
| 2171 | * devices, detach goners and greet newcomers. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2172 | * |
| 2173 | * LOCKING: |
| 2174 | * Kernel thread context (may sleep). |
| 2175 | * |
| 2176 | * RETURNS: |
| 2177 | * 0 on success, -errno on failure. |
| 2178 | */ |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2179 | static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, |
| 2180 | ata_reset_fn_t softreset, ata_reset_fn_t hardreset, |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2181 | ata_postreset_fn_t postreset) |
| 2182 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2183 | struct ata_link *link = &ap->link; |
| 2184 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2185 | struct ata_device *dev; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2186 | int rc; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2187 | |
| 2188 | DPRINTK("ENTER\n"); |
| 2189 | |
| 2190 | /* prep for recovery */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2191 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2192 | ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2193 | |
Tejun Heo | 79a55b7 | 2007-01-18 17:22:18 +0900 | [diff] [blame] | 2194 | /* collect port action mask recorded in dev actions */ |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2195 | ehc->i.action |= |
| 2196 | ehc->i.dev_action[dev->devno] & ~ATA_EH_PERDEV_MASK; |
| 2197 | ehc->i.dev_action[dev->devno] &= ATA_EH_PERDEV_MASK; |
Tejun Heo | 79a55b7 | 2007-01-18 17:22:18 +0900 | [diff] [blame] | 2198 | |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2199 | /* process hotplug request */ |
| 2200 | if (dev->flags & ATA_DFLAG_DETACH) |
| 2201 | ata_eh_detach_dev(dev); |
| 2202 | |
| 2203 | if (!ata_dev_enabled(dev) && |
| 2204 | ((ehc->i.probe_mask & (1 << dev->devno)) && |
| 2205 | !(ehc->did_probe_mask & (1 << dev->devno)))) { |
| 2206 | ata_eh_detach_dev(dev); |
| 2207 | ata_dev_init(dev); |
| 2208 | ehc->did_probe_mask |= (1 << dev->devno); |
| 2209 | ehc->i.action |= ATA_EH_SOFTRESET; |
| 2210 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | retry: |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2214 | rc = 0; |
| 2215 | |
Tejun Heo | aeb2ecd | 2006-06-12 14:11:43 +0900 | [diff] [blame] | 2216 | /* if UNLOADING, finish immediately */ |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 2217 | if (ap->pflags & ATA_PFLAG_UNLOADING) |
Tejun Heo | aeb2ecd | 2006-06-12 14:11:43 +0900 | [diff] [blame] | 2218 | goto out; |
| 2219 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2220 | /* skip EH if possible. */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2221 | if (ata_eh_skip_recovery(link)) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2222 | ehc->i.action = 0; |
| 2223 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2224 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2225 | ehc->classes[dev->devno] = ATA_DEV_UNKNOWN; |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2226 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2227 | /* reset */ |
| 2228 | if (ehc->i.action & ATA_EH_RESET_MASK) { |
| 2229 | ata_eh_freeze_port(ap); |
| 2230 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2231 | rc = ata_eh_reset(link, ata_link_nr_vacant(link), prereset, |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2232 | softreset, hardreset, postreset); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2233 | if (rc) { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2234 | ata_link_printk(link, KERN_ERR, |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2235 | "reset failed, giving up\n"); |
| 2236 | goto out; |
| 2237 | } |
| 2238 | |
| 2239 | ata_eh_thaw_port(ap); |
| 2240 | } |
| 2241 | |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2242 | /* revalidate existing devices and attach new ones */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2243 | rc = ata_eh_revalidate_and_attach(link, &dev); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2244 | if (rc) |
| 2245 | goto dev_fail; |
| 2246 | |
Tejun Heo | baa1e78 | 2006-11-01 18:39:27 +0900 | [diff] [blame] | 2247 | /* configure transfer mode if necessary */ |
| 2248 | if (ehc->i.flags & ATA_EHI_SETMODE) { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2249 | rc = ata_set_mode(link, &dev); |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2250 | if (rc) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2251 | goto dev_fail; |
Tejun Heo | baa1e78 | 2006-11-01 18:39:27 +0900 | [diff] [blame] | 2252 | ehc->i.flags &= ~ATA_EHI_SETMODE; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | goto out; |
| 2256 | |
| 2257 | dev_fail: |
Tejun Heo | fee7ca7 | 2007-07-01 19:05:58 +0900 | [diff] [blame] | 2258 | ata_eh_handle_dev_fail(dev, rc); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2259 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2260 | if (ata_link_nr_enabled(link)) { |
| 2261 | ata_link_printk(link, KERN_WARNING, "failed to recover some " |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2262 | "devices, retrying in 5 secs\n"); |
| 2263 | ssleep(5); |
| 2264 | } else { |
| 2265 | /* no device left, repeat fast */ |
| 2266 | msleep(500); |
| 2267 | } |
| 2268 | |
| 2269 | goto retry; |
| 2270 | |
| 2271 | out: |
| 2272 | if (rc) { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2273 | ata_link_for_each_dev(dev, link); |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2274 | ata_dev_disable(dev); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | DPRINTK("EXIT, rc=%d\n", rc); |
| 2278 | return rc; |
| 2279 | } |
| 2280 | |
| 2281 | /** |
| 2282 | * ata_eh_finish - finish up EH |
| 2283 | * @ap: host port to finish EH for |
| 2284 | * |
| 2285 | * Recovery is complete. Clean up EH states and retry or finish |
| 2286 | * failed qcs. |
| 2287 | * |
| 2288 | * LOCKING: |
| 2289 | * None. |
| 2290 | */ |
| 2291 | static void ata_eh_finish(struct ata_port *ap) |
| 2292 | { |
| 2293 | int tag; |
| 2294 | |
| 2295 | /* retry or finish qcs */ |
| 2296 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
| 2297 | struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); |
| 2298 | |
| 2299 | if (!(qc->flags & ATA_QCFLAG_FAILED)) |
| 2300 | continue; |
| 2301 | |
| 2302 | if (qc->err_mask) { |
| 2303 | /* FIXME: Once EH migration is complete, |
| 2304 | * generate sense data in this function, |
| 2305 | * considering both err_mask and tf. |
| 2306 | */ |
| 2307 | if (qc->err_mask & AC_ERR_INVALID) |
| 2308 | ata_eh_qc_complete(qc); |
| 2309 | else |
| 2310 | ata_eh_qc_retry(qc); |
| 2311 | } else { |
| 2312 | if (qc->flags & ATA_QCFLAG_SENSE_VALID) { |
| 2313 | ata_eh_qc_complete(qc); |
| 2314 | } else { |
| 2315 | /* feed zero TF to sense generation */ |
| 2316 | memset(&qc->result_tf, 0, sizeof(qc->result_tf)); |
| 2317 | ata_eh_qc_retry(qc); |
| 2318 | } |
| 2319 | } |
| 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | /** |
| 2324 | * ata_do_eh - do standard error handling |
| 2325 | * @ap: host port to handle error for |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2326 | * @prereset: prereset method (can be NULL) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2327 | * @softreset: softreset method (can be NULL) |
| 2328 | * @hardreset: hardreset method (can be NULL) |
| 2329 | * @postreset: postreset method (can be NULL) |
| 2330 | * |
| 2331 | * Perform standard error handling sequence. |
| 2332 | * |
| 2333 | * LOCKING: |
| 2334 | * Kernel thread context (may sleep). |
| 2335 | */ |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2336 | void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset, |
| 2337 | ata_reset_fn_t softreset, ata_reset_fn_t hardreset, |
| 2338 | ata_postreset_fn_t postreset) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2339 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2340 | ata_eh_autopsy(&ap->link); |
| 2341 | ata_eh_report(&ap->link); |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2342 | ata_eh_recover(ap, prereset, softreset, hardreset, postreset); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2343 | ata_eh_finish(ap); |
| 2344 | } |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2345 | |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 2346 | #ifdef CONFIG_PM |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2347 | /** |
| 2348 | * ata_eh_handle_port_suspend - perform port suspend operation |
| 2349 | * @ap: port to suspend |
| 2350 | * |
| 2351 | * Suspend @ap. |
| 2352 | * |
| 2353 | * LOCKING: |
| 2354 | * Kernel thread context (may sleep). |
| 2355 | */ |
| 2356 | static void ata_eh_handle_port_suspend(struct ata_port *ap) |
| 2357 | { |
| 2358 | unsigned long flags; |
| 2359 | int rc = 0; |
| 2360 | |
| 2361 | /* are we suspending? */ |
| 2362 | spin_lock_irqsave(ap->lock, flags); |
| 2363 | if (!(ap->pflags & ATA_PFLAG_PM_PENDING) || |
| 2364 | ap->pm_mesg.event == PM_EVENT_ON) { |
| 2365 | spin_unlock_irqrestore(ap->lock, flags); |
| 2366 | return; |
| 2367 | } |
| 2368 | spin_unlock_irqrestore(ap->lock, flags); |
| 2369 | |
| 2370 | WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED); |
| 2371 | |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 2372 | /* tell ACPI we're suspending */ |
| 2373 | rc = ata_acpi_on_suspend(ap); |
| 2374 | if (rc) |
| 2375 | goto out; |
| 2376 | |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2377 | /* suspend */ |
| 2378 | ata_eh_freeze_port(ap); |
| 2379 | |
| 2380 | if (ap->ops->port_suspend) |
| 2381 | rc = ap->ops->port_suspend(ap, ap->pm_mesg); |
| 2382 | |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 2383 | out: |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2384 | /* report result */ |
| 2385 | spin_lock_irqsave(ap->lock, flags); |
| 2386 | |
| 2387 | ap->pflags &= ~ATA_PFLAG_PM_PENDING; |
| 2388 | if (rc == 0) |
| 2389 | ap->pflags |= ATA_PFLAG_SUSPENDED; |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 2390 | else if (ap->pflags & ATA_PFLAG_FROZEN) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2391 | ata_port_schedule_eh(ap); |
| 2392 | |
| 2393 | if (ap->pm_result) { |
| 2394 | *ap->pm_result = rc; |
| 2395 | ap->pm_result = NULL; |
| 2396 | } |
| 2397 | |
| 2398 | spin_unlock_irqrestore(ap->lock, flags); |
| 2399 | |
| 2400 | return; |
| 2401 | } |
| 2402 | |
| 2403 | /** |
| 2404 | * ata_eh_handle_port_resume - perform port resume operation |
| 2405 | * @ap: port to resume |
| 2406 | * |
| 2407 | * Resume @ap. |
| 2408 | * |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2409 | * LOCKING: |
| 2410 | * Kernel thread context (may sleep). |
| 2411 | */ |
| 2412 | static void ata_eh_handle_port_resume(struct ata_port *ap) |
| 2413 | { |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2414 | unsigned long flags; |
Tejun Heo | 9666f40 | 2007-05-04 21:27:47 +0200 | [diff] [blame] | 2415 | int rc = 0; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2416 | |
| 2417 | /* are we resuming? */ |
| 2418 | spin_lock_irqsave(ap->lock, flags); |
| 2419 | if (!(ap->pflags & ATA_PFLAG_PM_PENDING) || |
| 2420 | ap->pm_mesg.event != PM_EVENT_ON) { |
| 2421 | spin_unlock_irqrestore(ap->lock, flags); |
| 2422 | return; |
| 2423 | } |
| 2424 | spin_unlock_irqrestore(ap->lock, flags); |
| 2425 | |
Tejun Heo | 9666f40 | 2007-05-04 21:27:47 +0200 | [diff] [blame] | 2426 | WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED)); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2427 | |
| 2428 | if (ap->ops->port_resume) |
| 2429 | rc = ap->ops->port_resume(ap); |
| 2430 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 2431 | /* tell ACPI that we're resuming */ |
| 2432 | ata_acpi_on_resume(ap); |
| 2433 | |
Tejun Heo | 9666f40 | 2007-05-04 21:27:47 +0200 | [diff] [blame] | 2434 | /* report result */ |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2435 | spin_lock_irqsave(ap->lock, flags); |
| 2436 | ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED); |
| 2437 | if (ap->pm_result) { |
| 2438 | *ap->pm_result = rc; |
| 2439 | ap->pm_result = NULL; |
| 2440 | } |
| 2441 | spin_unlock_irqrestore(ap->lock, flags); |
| 2442 | } |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 2443 | #endif /* CONFIG_PM */ |