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