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