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