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 | |
Tejun Heo | 5ddf24c | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 562 | static int ata_eh_nr_in_flight(struct ata_port *ap) |
| 563 | { |
| 564 | unsigned int tag; |
| 565 | int nr = 0; |
| 566 | |
| 567 | /* count only non-internal commands */ |
| 568 | for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++) |
| 569 | if (ata_qc_from_tag(ap, tag)) |
| 570 | nr++; |
| 571 | |
| 572 | return nr; |
| 573 | } |
| 574 | |
| 575 | void ata_eh_fastdrain_timerfn(unsigned long arg) |
| 576 | { |
| 577 | struct ata_port *ap = (void *)arg; |
| 578 | unsigned long flags; |
| 579 | int cnt; |
| 580 | |
| 581 | spin_lock_irqsave(ap->lock, flags); |
| 582 | |
| 583 | cnt = ata_eh_nr_in_flight(ap); |
| 584 | |
| 585 | /* are we done? */ |
| 586 | if (!cnt) |
| 587 | goto out_unlock; |
| 588 | |
| 589 | if (cnt == ap->fastdrain_cnt) { |
| 590 | unsigned int tag; |
| 591 | |
| 592 | /* No progress during the last interval, tag all |
| 593 | * in-flight qcs as timed out and freeze the port. |
| 594 | */ |
| 595 | for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++) { |
| 596 | struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag); |
| 597 | if (qc) |
| 598 | qc->err_mask |= AC_ERR_TIMEOUT; |
| 599 | } |
| 600 | |
| 601 | ata_port_freeze(ap); |
| 602 | } else { |
| 603 | /* some qcs have finished, give it another chance */ |
| 604 | ap->fastdrain_cnt = cnt; |
| 605 | ap->fastdrain_timer.expires = |
| 606 | jiffies + ATA_EH_FASTDRAIN_INTERVAL; |
| 607 | add_timer(&ap->fastdrain_timer); |
| 608 | } |
| 609 | |
| 610 | out_unlock: |
| 611 | spin_unlock_irqrestore(ap->lock, flags); |
| 612 | } |
| 613 | |
| 614 | /** |
| 615 | * ata_eh_set_pending - set ATA_PFLAG_EH_PENDING and activate fast drain |
| 616 | * @ap: target ATA port |
| 617 | * @fastdrain: activate fast drain |
| 618 | * |
| 619 | * Set ATA_PFLAG_EH_PENDING and activate fast drain if @fastdrain |
| 620 | * is non-zero and EH wasn't pending before. Fast drain ensures |
| 621 | * that EH kicks in in timely manner. |
| 622 | * |
| 623 | * LOCKING: |
| 624 | * spin_lock_irqsave(host lock) |
| 625 | */ |
| 626 | static void ata_eh_set_pending(struct ata_port *ap, int fastdrain) |
| 627 | { |
| 628 | int cnt; |
| 629 | |
| 630 | /* already scheduled? */ |
| 631 | if (ap->pflags & ATA_PFLAG_EH_PENDING) |
| 632 | return; |
| 633 | |
| 634 | ap->pflags |= ATA_PFLAG_EH_PENDING; |
| 635 | |
| 636 | if (!fastdrain) |
| 637 | return; |
| 638 | |
| 639 | /* do we have in-flight qcs? */ |
| 640 | cnt = ata_eh_nr_in_flight(ap); |
| 641 | if (!cnt) |
| 642 | return; |
| 643 | |
| 644 | /* activate fast drain */ |
| 645 | ap->fastdrain_cnt = cnt; |
| 646 | ap->fastdrain_timer.expires = jiffies + ATA_EH_FASTDRAIN_INTERVAL; |
| 647 | add_timer(&ap->fastdrain_timer); |
| 648 | } |
| 649 | |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 650 | /** |
| 651 | * ata_qc_schedule_eh - schedule qc for error handling |
| 652 | * @qc: command to schedule error handling for |
| 653 | * |
| 654 | * Schedule error handling for @qc. EH will kick in as soon as |
| 655 | * other commands are drained. |
| 656 | * |
| 657 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 658 | * spin_lock_irqsave(host lock) |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 659 | */ |
| 660 | void ata_qc_schedule_eh(struct ata_queued_cmd *qc) |
| 661 | { |
| 662 | struct ata_port *ap = qc->ap; |
| 663 | |
| 664 | WARN_ON(!ap->ops->error_handler); |
| 665 | |
| 666 | qc->flags |= ATA_QCFLAG_FAILED; |
Tejun Heo | 5ddf24c | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 667 | ata_eh_set_pending(ap, 1); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 668 | |
| 669 | /* The following will fail if timeout has already expired. |
| 670 | * ata_scsi_error() takes care of such scmds on EH entry. |
| 671 | * Note that ATA_QCFLAG_FAILED is unconditionally set after |
| 672 | * this function completes. |
| 673 | */ |
| 674 | scsi_req_abort_cmd(qc->scsicmd); |
| 675 | } |
| 676 | |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 677 | /** |
| 678 | * ata_port_schedule_eh - schedule error handling without a qc |
| 679 | * @ap: ATA port to schedule EH for |
| 680 | * |
| 681 | * Schedule error handling for @ap. EH will kick in as soon as |
| 682 | * all commands are drained. |
| 683 | * |
| 684 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 685 | * spin_lock_irqsave(host lock) |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 686 | */ |
| 687 | void ata_port_schedule_eh(struct ata_port *ap) |
| 688 | { |
| 689 | WARN_ON(!ap->ops->error_handler); |
| 690 | |
Tejun Heo | f4d6d00 | 2007-05-01 11:50:15 +0200 | [diff] [blame] | 691 | if (ap->pflags & ATA_PFLAG_INITIALIZING) |
| 692 | return; |
| 693 | |
Tejun Heo | 5ddf24c | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 694 | ata_eh_set_pending(ap, 1); |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 695 | scsi_schedule_eh(ap->scsi_host); |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 696 | |
| 697 | DPRINTK("port EH scheduled\n"); |
| 698 | } |
| 699 | |
Tejun Heo | dbd8261 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 700 | 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] | 701 | { |
| 702 | int tag, nr_aborted = 0; |
| 703 | |
| 704 | WARN_ON(!ap->ops->error_handler); |
| 705 | |
Tejun Heo | 5ddf24c | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 706 | /* we're gonna abort all commands, no need for fast drain */ |
| 707 | ata_eh_set_pending(ap, 0); |
| 708 | |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 709 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
| 710 | struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag); |
| 711 | |
Tejun Heo | dbd8261 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 712 | if (qc && (!link || qc->dev->link == link)) { |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 713 | qc->flags |= ATA_QCFLAG_FAILED; |
| 714 | ata_qc_complete(qc); |
| 715 | nr_aborted++; |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | if (!nr_aborted) |
| 720 | ata_port_schedule_eh(ap); |
| 721 | |
| 722 | return nr_aborted; |
| 723 | } |
| 724 | |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 725 | /** |
Tejun Heo | dbd8261 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 726 | * ata_link_abort - abort all qc's on the link |
| 727 | * @link: ATA link to abort qc's for |
| 728 | * |
| 729 | * Abort all active qc's active on @link and schedule EH. |
| 730 | * |
| 731 | * LOCKING: |
| 732 | * spin_lock_irqsave(host lock) |
| 733 | * |
| 734 | * RETURNS: |
| 735 | * Number of aborted qc's. |
| 736 | */ |
| 737 | int ata_link_abort(struct ata_link *link) |
| 738 | { |
| 739 | return ata_do_link_abort(link->ap, link); |
| 740 | } |
| 741 | |
| 742 | /** |
| 743 | * ata_port_abort - abort all qc's on the port |
| 744 | * @ap: ATA port to abort qc's for |
| 745 | * |
| 746 | * Abort all active qc's of @ap and schedule EH. |
| 747 | * |
| 748 | * LOCKING: |
| 749 | * spin_lock_irqsave(host_set lock) |
| 750 | * |
| 751 | * RETURNS: |
| 752 | * Number of aborted qc's. |
| 753 | */ |
| 754 | int ata_port_abort(struct ata_port *ap) |
| 755 | { |
| 756 | return ata_do_link_abort(ap, NULL); |
| 757 | } |
| 758 | |
| 759 | /** |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 760 | * __ata_port_freeze - freeze port |
| 761 | * @ap: ATA port to freeze |
| 762 | * |
| 763 | * This function is called when HSM violation or some other |
| 764 | * condition disrupts normal operation of the port. Frozen port |
| 765 | * is not allowed to perform any operation until the port is |
| 766 | * thawed, which usually follows a successful reset. |
| 767 | * |
| 768 | * ap->ops->freeze() callback can be used for freezing the port |
| 769 | * hardware-wise (e.g. mask interrupt and stop DMA engine). If a |
| 770 | * port cannot be frozen hardware-wise, the interrupt handler |
| 771 | * must ack and clear interrupts unconditionally while the port |
| 772 | * is frozen. |
| 773 | * |
| 774 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 775 | * spin_lock_irqsave(host lock) |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 776 | */ |
| 777 | static void __ata_port_freeze(struct ata_port *ap) |
| 778 | { |
| 779 | WARN_ON(!ap->ops->error_handler); |
| 780 | |
| 781 | if (ap->ops->freeze) |
| 782 | ap->ops->freeze(ap); |
| 783 | |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 784 | ap->pflags |= ATA_PFLAG_FROZEN; |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 785 | |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 786 | DPRINTK("ata%u port frozen\n", ap->print_id); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | /** |
| 790 | * ata_port_freeze - abort & freeze port |
| 791 | * @ap: ATA port to freeze |
| 792 | * |
| 793 | * Abort and freeze @ap. |
| 794 | * |
| 795 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 796 | * spin_lock_irqsave(host lock) |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 797 | * |
| 798 | * RETURNS: |
| 799 | * Number of aborted commands. |
| 800 | */ |
| 801 | int ata_port_freeze(struct ata_port *ap) |
| 802 | { |
| 803 | int nr_aborted; |
| 804 | |
| 805 | WARN_ON(!ap->ops->error_handler); |
| 806 | |
| 807 | nr_aborted = ata_port_abort(ap); |
| 808 | __ata_port_freeze(ap); |
| 809 | |
| 810 | return nr_aborted; |
| 811 | } |
| 812 | |
| 813 | /** |
Tejun Heo | 7d77b24 | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 814 | * sata_async_notification - SATA async notification handler |
| 815 | * @ap: ATA port where async notification is received |
| 816 | * |
| 817 | * Handler to be called when async notification via SDB FIS is |
| 818 | * received. This function schedules EH if necessary. |
| 819 | * |
| 820 | * LOCKING: |
| 821 | * spin_lock_irqsave(host lock) |
| 822 | * |
| 823 | * RETURNS: |
| 824 | * 1 if EH is scheduled, 0 otherwise. |
| 825 | */ |
| 826 | int sata_async_notification(struct ata_port *ap) |
| 827 | { |
| 828 | u32 sntf; |
| 829 | int rc; |
| 830 | |
| 831 | if (!(ap->flags & ATA_FLAG_AN)) |
| 832 | return 0; |
| 833 | |
| 834 | rc = sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf); |
| 835 | if (rc == 0) |
| 836 | sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf); |
| 837 | |
| 838 | if (!ap->nr_pmp_links || rc) { |
| 839 | /* PMP is not attached or SNTF is not available */ |
| 840 | if (!ap->nr_pmp_links) { |
| 841 | /* PMP is not attached. Check whether ATAPI |
| 842 | * AN is configured. If so, notify media |
| 843 | * change. |
| 844 | */ |
| 845 | struct ata_device *dev = ap->link.device; |
| 846 | |
| 847 | if ((dev->class == ATA_DEV_ATAPI) && |
| 848 | (dev->flags & ATA_DFLAG_AN)) |
| 849 | ata_scsi_media_change_notify(dev); |
| 850 | return 0; |
| 851 | } else { |
| 852 | /* PMP is attached but SNTF is not available. |
| 853 | * ATAPI async media change notification is |
| 854 | * not used. The PMP must be reporting PHY |
| 855 | * status change, schedule EH. |
| 856 | */ |
| 857 | ata_port_schedule_eh(ap); |
| 858 | return 1; |
| 859 | } |
| 860 | } else { |
| 861 | /* PMP is attached and SNTF is available */ |
| 862 | struct ata_link *link; |
| 863 | |
| 864 | /* check and notify ATAPI AN */ |
| 865 | ata_port_for_each_link(link, ap) { |
| 866 | if (!(sntf & (1 << link->pmp))) |
| 867 | continue; |
| 868 | |
| 869 | if ((link->device->class == ATA_DEV_ATAPI) && |
| 870 | (link->device->flags & ATA_DFLAG_AN)) |
| 871 | ata_scsi_media_change_notify(link->device); |
| 872 | } |
| 873 | |
| 874 | /* If PMP is reporting that PHY status of some |
| 875 | * downstream ports has changed, schedule EH. |
| 876 | */ |
| 877 | if (sntf & (1 << SATA_PMP_CTRL_PORT)) { |
| 878 | ata_port_schedule_eh(ap); |
| 879 | return 1; |
| 880 | } |
| 881 | |
| 882 | return 0; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | /** |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 887 | * ata_eh_freeze_port - EH helper to freeze port |
| 888 | * @ap: ATA port to freeze |
| 889 | * |
| 890 | * Freeze @ap. |
| 891 | * |
| 892 | * LOCKING: |
| 893 | * None. |
| 894 | */ |
| 895 | void ata_eh_freeze_port(struct ata_port *ap) |
| 896 | { |
| 897 | unsigned long flags; |
| 898 | |
| 899 | if (!ap->ops->error_handler) |
| 900 | return; |
| 901 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 902 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 903 | __ata_port_freeze(ap); |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 904 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | /** |
| 908 | * ata_port_thaw_port - EH helper to thaw port |
| 909 | * @ap: ATA port to thaw |
| 910 | * |
| 911 | * Thaw frozen port @ap. |
| 912 | * |
| 913 | * LOCKING: |
| 914 | * None. |
| 915 | */ |
| 916 | void ata_eh_thaw_port(struct ata_port *ap) |
| 917 | { |
| 918 | unsigned long flags; |
| 919 | |
| 920 | if (!ap->ops->error_handler) |
| 921 | return; |
| 922 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 923 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 924 | |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 925 | ap->pflags &= ~ATA_PFLAG_FROZEN; |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 926 | |
| 927 | if (ap->ops->thaw) |
| 928 | ap->ops->thaw(ap); |
| 929 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 930 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 931 | |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 932 | DPRINTK("ata%u port thawed\n", ap->print_id); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 933 | } |
| 934 | |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 935 | static void ata_eh_scsidone(struct scsi_cmnd *scmd) |
| 936 | { |
| 937 | /* nada */ |
| 938 | } |
| 939 | |
| 940 | static void __ata_eh_qc_complete(struct ata_queued_cmd *qc) |
| 941 | { |
| 942 | struct ata_port *ap = qc->ap; |
| 943 | struct scsi_cmnd *scmd = qc->scsicmd; |
| 944 | unsigned long flags; |
| 945 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 946 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 947 | qc->scsidone = ata_eh_scsidone; |
| 948 | __ata_qc_complete(qc); |
| 949 | WARN_ON(ata_tag_valid(qc->tag)); |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 950 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 951 | |
| 952 | scsi_eh_finish_cmd(scmd, &ap->eh_done_q); |
| 953 | } |
| 954 | |
| 955 | /** |
| 956 | * ata_eh_qc_complete - Complete an active ATA command from EH |
| 957 | * @qc: Command to complete |
| 958 | * |
| 959 | * Indicate to the mid and upper layers that an ATA command has |
| 960 | * completed. To be used from EH. |
| 961 | */ |
| 962 | void ata_eh_qc_complete(struct ata_queued_cmd *qc) |
| 963 | { |
| 964 | struct scsi_cmnd *scmd = qc->scsicmd; |
| 965 | scmd->retries = scmd->allowed; |
| 966 | __ata_eh_qc_complete(qc); |
| 967 | } |
| 968 | |
| 969 | /** |
| 970 | * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH |
| 971 | * @qc: Command to retry |
| 972 | * |
| 973 | * Indicate to the mid and upper layers that an ATA command |
| 974 | * should be retried. To be used from EH. |
| 975 | * |
| 976 | * SCSI midlayer limits the number of retries to scmd->allowed. |
| 977 | * scmd->retries is decremented for commands which get retried |
| 978 | * due to unrelated failures (qc->err_mask is zero). |
| 979 | */ |
| 980 | void ata_eh_qc_retry(struct ata_queued_cmd *qc) |
| 981 | { |
| 982 | struct scsi_cmnd *scmd = qc->scsicmd; |
| 983 | if (!qc->err_mask && scmd->retries) |
| 984 | scmd->retries--; |
| 985 | __ata_eh_qc_complete(qc); |
| 986 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 987 | |
| 988 | /** |
Tejun Heo | 0ea035a | 2006-05-31 18:28:01 +0900 | [diff] [blame] | 989 | * ata_eh_detach_dev - detach ATA device |
| 990 | * @dev: ATA device to detach |
| 991 | * |
| 992 | * Detach @dev. |
| 993 | * |
| 994 | * LOCKING: |
| 995 | * None. |
| 996 | */ |
Tejun Heo | fb7fd61 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 997 | void ata_eh_detach_dev(struct ata_device *dev) |
Tejun Heo | 0ea035a | 2006-05-31 18:28:01 +0900 | [diff] [blame] | 998 | { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 999 | struct ata_link *link = dev->link; |
| 1000 | struct ata_port *ap = link->ap; |
Tejun Heo | 0ea035a | 2006-05-31 18:28:01 +0900 | [diff] [blame] | 1001 | unsigned long flags; |
| 1002 | |
| 1003 | ata_dev_disable(dev); |
| 1004 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1005 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 0ea035a | 2006-05-31 18:28:01 +0900 | [diff] [blame] | 1006 | |
| 1007 | dev->flags &= ~ATA_DFLAG_DETACH; |
| 1008 | |
| 1009 | if (ata_scsi_offline_dev(dev)) { |
| 1010 | dev->flags |= ATA_DFLAG_DETACHED; |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 1011 | ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG; |
Tejun Heo | 0ea035a | 2006-05-31 18:28:01 +0900 | [diff] [blame] | 1012 | } |
| 1013 | |
Tejun Heo | beb07c1 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1014 | /* clear per-dev EH actions */ |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1015 | ata_eh_clear_action(link, dev, &link->eh_info, ATA_EH_PERDEV_MASK); |
| 1016 | 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] | 1017 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1018 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 0ea035a | 2006-05-31 18:28:01 +0900 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | /** |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1022 | * ata_eh_about_to_do - about to perform eh_action |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1023 | * @link: target ATA link |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1024 | * @dev: target ATA dev for per-dev action (can be NULL) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1025 | * @action: action about to be performed |
| 1026 | * |
| 1027 | * Called just before performing EH actions to clear related bits |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1028 | * in @link->eh_info such that eh actions are not unnecessarily |
| 1029 | * repeated. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1030 | * |
| 1031 | * LOCKING: |
| 1032 | * None. |
| 1033 | */ |
Tejun Heo | fb7fd61 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1034 | void ata_eh_about_to_do(struct ata_link *link, struct ata_device *dev, |
| 1035 | unsigned int action) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1036 | { |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1037 | struct ata_port *ap = link->ap; |
| 1038 | struct ata_eh_info *ehi = &link->eh_info; |
| 1039 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1040 | unsigned long flags; |
| 1041 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1042 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 1043 | |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 1044 | /* Reset is represented by combination of actions and EHI |
| 1045 | * flags. Suck in all related bits before clearing eh_info to |
| 1046 | * avoid losing requested action. |
| 1047 | */ |
| 1048 | if (action & ATA_EH_RESET_MASK) { |
| 1049 | ehc->i.action |= ehi->action & ATA_EH_RESET_MASK; |
| 1050 | ehc->i.flags |= ehi->flags & ATA_EHI_RESET_MODIFIER_MASK; |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 1051 | |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 1052 | /* make sure all reset actions are cleared & clear EHI flags */ |
| 1053 | action |= ATA_EH_RESET_MASK; |
| 1054 | ehi->flags &= ~ATA_EHI_RESET_MODIFIER_MASK; |
| 1055 | } |
| 1056 | |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1057 | ata_eh_clear_action(link, dev, ehi, action); |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 1058 | |
| 1059 | if (!(ehc->i.flags & ATA_EHI_QUIET)) |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 1060 | ap->pflags |= ATA_PFLAG_RECOVERED; |
| 1061 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1062 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | /** |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1066 | * ata_eh_done - EH action complete |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1067 | * @ap: target ATA port |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1068 | * @dev: target ATA dev for per-dev action (can be NULL) |
| 1069 | * @action: action just completed |
| 1070 | * |
| 1071 | * Called right after performing EH actions to clear related bits |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1072 | * in @link->eh_context. |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1073 | * |
| 1074 | * LOCKING: |
| 1075 | * None. |
| 1076 | */ |
Tejun Heo | fb7fd61 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1077 | void ata_eh_done(struct ata_link *link, struct ata_device *dev, |
| 1078 | unsigned int action) |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1079 | { |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1080 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1081 | |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 1082 | /* if reset is complete, clear all reset actions & reset modifier */ |
| 1083 | if (action & ATA_EH_RESET_MASK) { |
| 1084 | action |= ATA_EH_RESET_MASK; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1085 | ehc->i.flags &= ~ATA_EHI_RESET_MODIFIER_MASK; |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 1086 | } |
| 1087 | |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1088 | ata_eh_clear_action(link, dev, &ehc->i, action); |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | /** |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1092 | * ata_err_string - convert err_mask to descriptive string |
| 1093 | * @err_mask: error mask to convert to string |
| 1094 | * |
| 1095 | * Convert @err_mask to descriptive string. Errors are |
| 1096 | * prioritized according to severity and only the most severe |
| 1097 | * error is reported. |
| 1098 | * |
| 1099 | * LOCKING: |
| 1100 | * None. |
| 1101 | * |
| 1102 | * RETURNS: |
| 1103 | * Descriptive string for @err_mask |
| 1104 | */ |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1105 | static const char *ata_err_string(unsigned int err_mask) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1106 | { |
| 1107 | if (err_mask & AC_ERR_HOST_BUS) |
| 1108 | return "host bus error"; |
| 1109 | if (err_mask & AC_ERR_ATA_BUS) |
| 1110 | return "ATA bus error"; |
| 1111 | if (err_mask & AC_ERR_TIMEOUT) |
| 1112 | return "timeout"; |
| 1113 | if (err_mask & AC_ERR_HSM) |
| 1114 | return "HSM violation"; |
| 1115 | if (err_mask & AC_ERR_SYSTEM) |
| 1116 | return "internal error"; |
| 1117 | if (err_mask & AC_ERR_MEDIA) |
| 1118 | return "media error"; |
| 1119 | if (err_mask & AC_ERR_INVALID) |
| 1120 | return "invalid argument"; |
| 1121 | if (err_mask & AC_ERR_DEV) |
| 1122 | return "device error"; |
| 1123 | return "unknown error"; |
| 1124 | } |
| 1125 | |
| 1126 | /** |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1127 | * ata_read_log_page - read a specific log page |
| 1128 | * @dev: target device |
| 1129 | * @page: page to read |
| 1130 | * @buf: buffer to store read page |
| 1131 | * @sectors: number of sectors to read |
| 1132 | * |
| 1133 | * Read log page using READ_LOG_EXT command. |
| 1134 | * |
| 1135 | * LOCKING: |
| 1136 | * Kernel thread context (may sleep). |
| 1137 | * |
| 1138 | * RETURNS: |
| 1139 | * 0 on success, AC_ERR_* mask otherwise. |
| 1140 | */ |
| 1141 | static unsigned int ata_read_log_page(struct ata_device *dev, |
| 1142 | u8 page, void *buf, unsigned int sectors) |
| 1143 | { |
| 1144 | struct ata_taskfile tf; |
| 1145 | unsigned int err_mask; |
| 1146 | |
| 1147 | DPRINTK("read log page - page %d\n", page); |
| 1148 | |
| 1149 | ata_tf_init(dev, &tf); |
| 1150 | tf.command = ATA_CMD_READ_LOG_EXT; |
| 1151 | tf.lbal = page; |
| 1152 | tf.nsect = sectors; |
| 1153 | tf.hob_nsect = sectors >> 8; |
| 1154 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_LBA48 | ATA_TFLAG_DEVICE; |
| 1155 | tf.protocol = ATA_PROT_PIO; |
| 1156 | |
| 1157 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE, |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1158 | buf, sectors * ATA_SECT_SIZE, 0); |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1159 | |
| 1160 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
| 1161 | return err_mask; |
| 1162 | } |
| 1163 | |
| 1164 | /** |
| 1165 | * ata_eh_read_log_10h - Read log page 10h for NCQ error details |
| 1166 | * @dev: Device to read log page 10h from |
| 1167 | * @tag: Resulting tag of the failed command |
| 1168 | * @tf: Resulting taskfile registers of the failed command |
| 1169 | * |
| 1170 | * Read log page 10h to obtain NCQ error details and clear error |
| 1171 | * condition. |
| 1172 | * |
| 1173 | * LOCKING: |
| 1174 | * Kernel thread context (may sleep). |
| 1175 | * |
| 1176 | * RETURNS: |
| 1177 | * 0 on success, -errno otherwise. |
| 1178 | */ |
| 1179 | static int ata_eh_read_log_10h(struct ata_device *dev, |
| 1180 | int *tag, struct ata_taskfile *tf) |
| 1181 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1182 | u8 *buf = dev->link->ap->sector_buf; |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1183 | unsigned int err_mask; |
| 1184 | u8 csum; |
| 1185 | int i; |
| 1186 | |
| 1187 | err_mask = ata_read_log_page(dev, ATA_LOG_SATA_NCQ, buf, 1); |
| 1188 | if (err_mask) |
| 1189 | return -EIO; |
| 1190 | |
| 1191 | csum = 0; |
| 1192 | for (i = 0; i < ATA_SECT_SIZE; i++) |
| 1193 | csum += buf[i]; |
| 1194 | if (csum) |
| 1195 | ata_dev_printk(dev, KERN_WARNING, |
| 1196 | "invalid checksum 0x%x on log page 10h\n", csum); |
| 1197 | |
| 1198 | if (buf[0] & 0x80) |
| 1199 | return -ENOENT; |
| 1200 | |
| 1201 | *tag = buf[0] & 0x1f; |
| 1202 | |
| 1203 | tf->command = buf[2]; |
| 1204 | tf->feature = buf[3]; |
| 1205 | tf->lbal = buf[4]; |
| 1206 | tf->lbam = buf[5]; |
| 1207 | tf->lbah = buf[6]; |
| 1208 | tf->device = buf[7]; |
| 1209 | tf->hob_lbal = buf[8]; |
| 1210 | tf->hob_lbam = buf[9]; |
| 1211 | tf->hob_lbah = buf[10]; |
| 1212 | tf->nsect = buf[12]; |
| 1213 | tf->hob_nsect = buf[13]; |
| 1214 | |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
| 1218 | /** |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1219 | * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE |
| 1220 | * @dev: device to perform REQUEST_SENSE to |
| 1221 | * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long) |
| 1222 | * |
| 1223 | * Perform ATAPI REQUEST_SENSE after the device reported CHECK |
| 1224 | * SENSE. This function is EH helper. |
| 1225 | * |
| 1226 | * LOCKING: |
| 1227 | * Kernel thread context (may sleep). |
| 1228 | * |
| 1229 | * RETURNS: |
| 1230 | * 0 on success, AC_ERR_* mask on failure |
| 1231 | */ |
Albert Lee | 5628776 | 2007-04-02 11:30:46 +0800 | [diff] [blame] | 1232 | static unsigned int atapi_eh_request_sense(struct ata_queued_cmd *qc) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1233 | { |
Albert Lee | 5628776 | 2007-04-02 11:30:46 +0800 | [diff] [blame] | 1234 | struct ata_device *dev = qc->dev; |
| 1235 | unsigned char *sense_buf = qc->scsicmd->sense_buffer; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1236 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1237 | struct ata_taskfile tf; |
| 1238 | u8 cdb[ATAPI_CDB_LEN]; |
| 1239 | |
| 1240 | DPRINTK("ATAPI request sense\n"); |
| 1241 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1242 | /* FIXME: is this needed? */ |
| 1243 | memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE); |
| 1244 | |
Albert Lee | 5628776 | 2007-04-02 11:30:46 +0800 | [diff] [blame] | 1245 | /* initialize sense_buf with the error register, |
| 1246 | * for the case where they are -not- overwritten |
| 1247 | */ |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1248 | sense_buf[0] = 0x70; |
Albert Lee | 5628776 | 2007-04-02 11:30:46 +0800 | [diff] [blame] | 1249 | sense_buf[2] = qc->result_tf.feature >> 4; |
| 1250 | |
Jeff Garzik | a617c09 | 2007-05-21 20:14:23 -0400 | [diff] [blame] | 1251 | /* some devices time out if garbage left in tf */ |
Albert Lee | 5628776 | 2007-04-02 11:30:46 +0800 | [diff] [blame] | 1252 | ata_tf_init(dev, &tf); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1253 | |
| 1254 | memset(cdb, 0, ATAPI_CDB_LEN); |
| 1255 | cdb[0] = REQUEST_SENSE; |
| 1256 | cdb[4] = SCSI_SENSE_BUFFERSIZE; |
| 1257 | |
| 1258 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 1259 | tf.command = ATA_CMD_PACKET; |
| 1260 | |
| 1261 | /* is it pointless to prefer PIO for "safety reasons"? */ |
| 1262 | if (ap->flags & ATA_FLAG_PIO_DMA) { |
| 1263 | tf.protocol = ATA_PROT_ATAPI_DMA; |
| 1264 | tf.feature |= ATAPI_PKT_DMA; |
| 1265 | } else { |
| 1266 | tf.protocol = ATA_PROT_ATAPI; |
Tejun Heo | f2dfc1a | 2007-12-12 12:12:46 +0900 | [diff] [blame] | 1267 | tf.lbam = SCSI_SENSE_BUFFERSIZE; |
| 1268 | tf.lbah = 0; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | return ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE, |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1272 | sense_buf, SCSI_SENSE_BUFFERSIZE, 0); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | /** |
| 1276 | * ata_eh_analyze_serror - analyze SError for a failed port |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1277 | * @link: ATA link to analyze SError for |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1278 | * |
| 1279 | * Analyze SError if available and further determine cause of |
| 1280 | * failure. |
| 1281 | * |
| 1282 | * LOCKING: |
| 1283 | * None. |
| 1284 | */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1285 | static void ata_eh_analyze_serror(struct ata_link *link) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1286 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1287 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1288 | u32 serror = ehc->i.serror; |
| 1289 | unsigned int err_mask = 0, action = 0; |
Tejun Heo | f9df58c | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 1290 | u32 hotplug_mask; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1291 | |
| 1292 | if (serror & SERR_PERSISTENT) { |
| 1293 | err_mask |= AC_ERR_ATA_BUS; |
| 1294 | action |= ATA_EH_HARDRESET; |
| 1295 | } |
| 1296 | if (serror & |
| 1297 | (SERR_DATA_RECOVERED | SERR_COMM_RECOVERED | SERR_DATA)) { |
| 1298 | err_mask |= AC_ERR_ATA_BUS; |
| 1299 | action |= ATA_EH_SOFTRESET; |
| 1300 | } |
| 1301 | if (serror & SERR_PROTOCOL) { |
| 1302 | err_mask |= AC_ERR_HSM; |
| 1303 | action |= ATA_EH_SOFTRESET; |
| 1304 | } |
| 1305 | if (serror & SERR_INTERNAL) { |
| 1306 | err_mask |= AC_ERR_SYSTEM; |
Tejun Heo | 771b8da | 2007-03-14 01:20:51 +0900 | [diff] [blame] | 1307 | action |= ATA_EH_HARDRESET; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1308 | } |
Tejun Heo | f9df58c | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 1309 | |
| 1310 | /* Determine whether a hotplug event has occurred. Both |
| 1311 | * SError.N/X are considered hotplug events for enabled or |
| 1312 | * host links. For disabled PMP links, only N bit is |
| 1313 | * considered as X bit is left at 1 for link plugging. |
| 1314 | */ |
| 1315 | hotplug_mask = 0; |
| 1316 | |
| 1317 | if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link)) |
| 1318 | hotplug_mask = SERR_PHYRDY_CHG | SERR_DEV_XCHG; |
| 1319 | else |
| 1320 | hotplug_mask = SERR_PHYRDY_CHG; |
| 1321 | |
| 1322 | if (serror & hotplug_mask) |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 1323 | ata_ehi_hotplugged(&ehc->i); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1324 | |
| 1325 | ehc->i.err_mask |= err_mask; |
| 1326 | ehc->i.action |= action; |
| 1327 | } |
| 1328 | |
| 1329 | /** |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1330 | * ata_eh_analyze_ncq_error - analyze NCQ error |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1331 | * @link: ATA link to analyze NCQ error for |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1332 | * |
| 1333 | * Read log page 10h, determine the offending qc and acquire |
| 1334 | * error status TF. For NCQ device errors, all LLDDs have to do |
| 1335 | * is setting AC_ERR_DEV in ehi->err_mask. This function takes |
| 1336 | * care of the rest. |
| 1337 | * |
| 1338 | * LOCKING: |
| 1339 | * Kernel thread context (may sleep). |
| 1340 | */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1341 | static void ata_eh_analyze_ncq_error(struct ata_link *link) |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1342 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1343 | struct ata_port *ap = link->ap; |
| 1344 | struct ata_eh_context *ehc = &link->eh_context; |
| 1345 | struct ata_device *dev = link->device; |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1346 | struct ata_queued_cmd *qc; |
| 1347 | struct ata_taskfile tf; |
| 1348 | int tag, rc; |
| 1349 | |
| 1350 | /* if frozen, we can't do much */ |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 1351 | if (ap->pflags & ATA_PFLAG_FROZEN) |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1352 | return; |
| 1353 | |
| 1354 | /* is it NCQ device error? */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1355 | if (!link->sactive || !(ehc->i.err_mask & AC_ERR_DEV)) |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1356 | return; |
| 1357 | |
| 1358 | /* has LLDD analyzed already? */ |
| 1359 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
| 1360 | qc = __ata_qc_from_tag(ap, tag); |
| 1361 | |
| 1362 | if (!(qc->flags & ATA_QCFLAG_FAILED)) |
| 1363 | continue; |
| 1364 | |
| 1365 | if (qc->err_mask) |
| 1366 | return; |
| 1367 | } |
| 1368 | |
| 1369 | /* okay, this error is ours */ |
| 1370 | rc = ata_eh_read_log_10h(dev, &tag, &tf); |
| 1371 | if (rc) { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1372 | ata_link_printk(link, KERN_ERR, "failed to read log page 10h " |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1373 | "(errno=%d)\n", rc); |
| 1374 | return; |
| 1375 | } |
| 1376 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1377 | if (!(link->sactive & (1 << tag))) { |
| 1378 | ata_link_printk(link, KERN_ERR, "log page 10h reported " |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1379 | "inactive tag %d\n", tag); |
| 1380 | return; |
| 1381 | } |
| 1382 | |
| 1383 | /* we've got the perpetrator, condemn it */ |
| 1384 | qc = __ata_qc_from_tag(ap, tag); |
| 1385 | memcpy(&qc->result_tf, &tf, sizeof(tf)); |
Tejun Heo | 5335b72 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 1386 | qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ; |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1387 | ehc->i.err_mask &= ~AC_ERR_DEV; |
| 1388 | } |
| 1389 | |
| 1390 | /** |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1391 | * ata_eh_analyze_tf - analyze taskfile of a failed qc |
| 1392 | * @qc: qc to analyze |
| 1393 | * @tf: Taskfile registers to analyze |
| 1394 | * |
| 1395 | * Analyze taskfile of @qc and further determine cause of |
| 1396 | * failure. This function also requests ATAPI sense data if |
| 1397 | * avaliable. |
| 1398 | * |
| 1399 | * LOCKING: |
| 1400 | * Kernel thread context (may sleep). |
| 1401 | * |
| 1402 | * RETURNS: |
| 1403 | * Determined recovery action |
| 1404 | */ |
| 1405 | static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc, |
| 1406 | const struct ata_taskfile *tf) |
| 1407 | { |
| 1408 | unsigned int tmp, action = 0; |
| 1409 | u8 stat = tf->command, err = tf->feature; |
| 1410 | |
| 1411 | if ((stat & (ATA_BUSY | ATA_DRQ | ATA_DRDY)) != ATA_DRDY) { |
| 1412 | qc->err_mask |= AC_ERR_HSM; |
| 1413 | return ATA_EH_SOFTRESET; |
| 1414 | } |
| 1415 | |
Tejun Heo | a51d644 | 2007-03-20 15:24:11 +0900 | [diff] [blame] | 1416 | if (stat & (ATA_ERR | ATA_DF)) |
| 1417 | qc->err_mask |= AC_ERR_DEV; |
| 1418 | else |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1419 | return 0; |
| 1420 | |
| 1421 | switch (qc->dev->class) { |
| 1422 | case ATA_DEV_ATA: |
| 1423 | if (err & ATA_ICRC) |
| 1424 | qc->err_mask |= AC_ERR_ATA_BUS; |
| 1425 | if (err & ATA_UNC) |
| 1426 | qc->err_mask |= AC_ERR_MEDIA; |
| 1427 | if (err & ATA_IDNF) |
| 1428 | qc->err_mask |= AC_ERR_INVALID; |
| 1429 | break; |
| 1430 | |
| 1431 | case ATA_DEV_ATAPI: |
Tejun Heo | a569a30 | 2006-11-21 10:40:51 +0900 | [diff] [blame] | 1432 | if (!(qc->ap->pflags & ATA_PFLAG_FROZEN)) { |
Albert Lee | 5628776 | 2007-04-02 11:30:46 +0800 | [diff] [blame] | 1433 | tmp = atapi_eh_request_sense(qc); |
Tejun Heo | a569a30 | 2006-11-21 10:40:51 +0900 | [diff] [blame] | 1434 | if (!tmp) { |
| 1435 | /* ATA_QCFLAG_SENSE_VALID is used to |
| 1436 | * tell atapi_qc_complete() that sense |
| 1437 | * data is already valid. |
| 1438 | * |
| 1439 | * TODO: interpret sense data and set |
| 1440 | * appropriate err_mask. |
| 1441 | */ |
| 1442 | qc->flags |= ATA_QCFLAG_SENSE_VALID; |
| 1443 | } else |
| 1444 | qc->err_mask |= tmp; |
| 1445 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | if (qc->err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT | AC_ERR_ATA_BUS)) |
| 1449 | action |= ATA_EH_SOFTRESET; |
| 1450 | |
| 1451 | return action; |
| 1452 | } |
| 1453 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1454 | 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] | 1455 | { |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1456 | if (err_mask & AC_ERR_ATA_BUS) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1457 | return 1; |
| 1458 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1459 | if (err_mask & AC_ERR_TIMEOUT) |
| 1460 | return 2; |
| 1461 | |
| 1462 | if (is_io) { |
| 1463 | if (err_mask & AC_ERR_HSM) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1464 | return 2; |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1465 | if ((err_mask & |
| 1466 | (AC_ERR_DEV|AC_ERR_MEDIA|AC_ERR_INVALID)) == AC_ERR_DEV) |
| 1467 | return 3; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | return 0; |
| 1471 | } |
| 1472 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1473 | struct speed_down_verdict_arg { |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1474 | u64 since; |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1475 | int nr_errors[4]; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1476 | }; |
| 1477 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1478 | 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] | 1479 | { |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1480 | struct speed_down_verdict_arg *arg = void_arg; |
| 1481 | int cat = ata_eh_categorize_error(ent->is_io, ent->err_mask); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1482 | |
| 1483 | if (ent->timestamp < arg->since) |
| 1484 | return -1; |
| 1485 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1486 | arg->nr_errors[cat]++; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1487 | return 0; |
| 1488 | } |
| 1489 | |
| 1490 | /** |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1491 | * ata_eh_speed_down_verdict - Determine speed down verdict |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1492 | * @dev: Device of interest |
| 1493 | * |
| 1494 | * This function examines error ring of @dev and determines |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1495 | * whether NCQ needs to be turned off, transfer speed should be |
| 1496 | * stepped down, or falling back to PIO is necessary. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1497 | * |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1498 | * Cat-1 is ATA_BUS error for any command. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1499 | * |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1500 | * Cat-2 is TIMEOUT for any command or HSM violation for known |
| 1501 | * supported commands. |
| 1502 | * |
| 1503 | * Cat-3 is is unclassified DEV error for known supported |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1504 | * command. |
| 1505 | * |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1506 | * NCQ needs to be turned off if there have been more than 3 |
| 1507 | * Cat-2 + Cat-3 errors during last 10 minutes. |
| 1508 | * |
| 1509 | * Speed down is necessary if there have been more than 3 Cat-1 + |
| 1510 | * Cat-2 errors or 10 Cat-3 errors during last 10 minutes. |
| 1511 | * |
| 1512 | * Falling back to PIO mode is necessary if there have been more |
| 1513 | * than 10 Cat-1 + Cat-2 + Cat-3 errors during last 5 minutes. |
| 1514 | * |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1515 | * LOCKING: |
| 1516 | * Inherited from caller. |
| 1517 | * |
| 1518 | * RETURNS: |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1519 | * OR of ATA_EH_SPDN_* flags. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1520 | */ |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1521 | static unsigned int ata_eh_speed_down_verdict(struct ata_device *dev) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1522 | { |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1523 | const u64 j5mins = 5LLU * 60 * HZ, j10mins = 10LLU * 60 * HZ; |
| 1524 | u64 j64 = get_jiffies_64(); |
| 1525 | struct speed_down_verdict_arg arg; |
| 1526 | unsigned int verdict = 0; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1527 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1528 | /* scan past 10 mins of error history */ |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1529 | memset(&arg, 0, sizeof(arg)); |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1530 | arg.since = j64 - min(j64, j10mins); |
| 1531 | ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1532 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1533 | if (arg.nr_errors[2] + arg.nr_errors[3] > 3) |
| 1534 | verdict |= ATA_EH_SPDN_NCQ_OFF; |
| 1535 | if (arg.nr_errors[1] + arg.nr_errors[2] > 3 || arg.nr_errors[3] > 10) |
| 1536 | verdict |= ATA_EH_SPDN_SPEED_DOWN; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1537 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1538 | /* scan past 3 mins of error history */ |
| 1539 | memset(&arg, 0, sizeof(arg)); |
| 1540 | arg.since = j64 - min(j64, j5mins); |
| 1541 | ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1542 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1543 | if (arg.nr_errors[1] + arg.nr_errors[2] + arg.nr_errors[3] > 10) |
| 1544 | verdict |= ATA_EH_SPDN_FALLBACK_TO_PIO; |
| 1545 | |
| 1546 | return verdict; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | /** |
| 1550 | * ata_eh_speed_down - record error and speed down if necessary |
| 1551 | * @dev: Failed device |
| 1552 | * @is_io: Did the device fail during normal IO? |
| 1553 | * @err_mask: err_mask of the error |
| 1554 | * |
| 1555 | * Record error and examine error history to determine whether |
| 1556 | * adjusting transmission speed is necessary. It also sets |
| 1557 | * transmission limits appropriately if such adjustment is |
| 1558 | * necessary. |
| 1559 | * |
| 1560 | * LOCKING: |
| 1561 | * Kernel thread context (may sleep). |
| 1562 | * |
| 1563 | * RETURNS: |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1564 | * Determined recovery action. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1565 | */ |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1566 | static unsigned int ata_eh_speed_down(struct ata_device *dev, int is_io, |
| 1567 | unsigned int err_mask) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1568 | { |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1569 | unsigned int verdict; |
| 1570 | unsigned int action = 0; |
| 1571 | |
| 1572 | /* don't bother if Cat-0 error */ |
| 1573 | if (ata_eh_categorize_error(is_io, err_mask) == 0) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1574 | return 0; |
| 1575 | |
| 1576 | /* record error and determine whether speed down is necessary */ |
| 1577 | ata_ering_record(&dev->ering, is_io, err_mask); |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1578 | verdict = ata_eh_speed_down_verdict(dev); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1579 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1580 | /* turn off NCQ? */ |
| 1581 | if ((verdict & ATA_EH_SPDN_NCQ_OFF) && |
| 1582 | (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ | |
| 1583 | ATA_DFLAG_NCQ_OFF)) == ATA_DFLAG_NCQ) { |
| 1584 | dev->flags |= ATA_DFLAG_NCQ_OFF; |
| 1585 | ata_dev_printk(dev, KERN_WARNING, |
| 1586 | "NCQ disabled due to excessive errors\n"); |
| 1587 | goto done; |
| 1588 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1589 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1590 | /* speed down? */ |
| 1591 | if (verdict & ATA_EH_SPDN_SPEED_DOWN) { |
| 1592 | /* speed down SATA link speed if possible */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1593 | if (sata_down_spd_limit(dev->link) == 0) { |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1594 | action |= ATA_EH_HARDRESET; |
| 1595 | goto done; |
| 1596 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1597 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1598 | /* lower transfer mode */ |
| 1599 | if (dev->spdn_cnt < 2) { |
| 1600 | static const int dma_dnxfer_sel[] = |
| 1601 | { ATA_DNXFER_DMA, ATA_DNXFER_40C }; |
| 1602 | static const int pio_dnxfer_sel[] = |
| 1603 | { ATA_DNXFER_PIO, ATA_DNXFER_FORCE_PIO0 }; |
| 1604 | int sel; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1605 | |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1606 | if (dev->xfer_shift != ATA_SHIFT_PIO) |
| 1607 | sel = dma_dnxfer_sel[dev->spdn_cnt]; |
| 1608 | else |
| 1609 | sel = pio_dnxfer_sel[dev->spdn_cnt]; |
| 1610 | |
| 1611 | dev->spdn_cnt++; |
| 1612 | |
| 1613 | if (ata_down_xfermask_limit(dev, sel) == 0) { |
| 1614 | action |= ATA_EH_SOFTRESET; |
| 1615 | goto done; |
| 1616 | } |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | /* Fall back to PIO? Slowing down to PIO is meaningless for |
| 1621 | * SATA. Consider it only for PATA. |
| 1622 | */ |
| 1623 | if ((verdict & ATA_EH_SPDN_FALLBACK_TO_PIO) && (dev->spdn_cnt >= 2) && |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1624 | (dev->link->ap->cbl != ATA_CBL_SATA) && |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1625 | (dev->xfer_shift != ATA_SHIFT_PIO)) { |
| 1626 | if (ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO) == 0) { |
| 1627 | dev->spdn_cnt = 0; |
| 1628 | action |= ATA_EH_SOFTRESET; |
| 1629 | goto done; |
| 1630 | } |
| 1631 | } |
| 1632 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1633 | return 0; |
Tejun Heo | 7d47e8d | 2007-02-02 16:22:31 +0900 | [diff] [blame] | 1634 | done: |
| 1635 | /* device has been slowed down, blow error history */ |
| 1636 | ata_ering_clear(&dev->ering); |
| 1637 | return action; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | /** |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 1641 | * ata_eh_link_autopsy - analyze error and determine recovery action |
| 1642 | * @link: host link to perform autopsy on |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1643 | * |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1644 | * Analyze why @link failed and determine which recovery actions |
| 1645 | * are needed. This function also sets more detailed AC_ERR_* |
| 1646 | * values and fills sense data for ATAPI CHECK SENSE. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1647 | * |
| 1648 | * LOCKING: |
| 1649 | * Kernel thread context (may sleep). |
| 1650 | */ |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 1651 | static void ata_eh_link_autopsy(struct ata_link *link) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1652 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1653 | struct ata_port *ap = link->ap; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1654 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | dfcc173 | 2007-10-31 10:17:05 +0900 | [diff] [blame] | 1655 | struct ata_device *dev; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1656 | unsigned int all_err_mask = 0; |
| 1657 | int tag, is_io = 0; |
| 1658 | u32 serror; |
| 1659 | int rc; |
| 1660 | |
| 1661 | DPRINTK("ENTER\n"); |
| 1662 | |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 1663 | if (ehc->i.flags & ATA_EHI_NO_AUTOPSY) |
| 1664 | return; |
| 1665 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1666 | /* obtain and analyze SError */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1667 | rc = sata_scr_read(link, SCR_ERROR, &serror); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1668 | if (rc == 0) { |
| 1669 | ehc->i.serror |= serror; |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1670 | ata_eh_analyze_serror(link); |
Tejun Heo | 4e57c51 | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 1671 | } else if (rc != -EOPNOTSUPP) { |
| 1672 | /* SError read failed, force hardreset and probing */ |
| 1673 | ata_ehi_schedule_probe(&ehc->i); |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1674 | ehc->i.action |= ATA_EH_HARDRESET; |
Tejun Heo | 4e57c51 | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 1675 | ehc->i.err_mask |= AC_ERR_OTHER; |
| 1676 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1677 | |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1678 | /* analyze NCQ failure */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1679 | ata_eh_analyze_ncq_error(link); |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1680 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1681 | /* any real error trumps AC_ERR_OTHER */ |
| 1682 | if (ehc->i.err_mask & ~AC_ERR_OTHER) |
| 1683 | ehc->i.err_mask &= ~AC_ERR_OTHER; |
| 1684 | |
| 1685 | all_err_mask |= ehc->i.err_mask; |
| 1686 | |
| 1687 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
| 1688 | struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); |
| 1689 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1690 | if (!(qc->flags & ATA_QCFLAG_FAILED) || qc->dev->link != link) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1691 | continue; |
| 1692 | |
| 1693 | /* inherit upper level err_mask */ |
| 1694 | qc->err_mask |= ehc->i.err_mask; |
| 1695 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1696 | /* analyze TF */ |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1697 | ehc->i.action |= ata_eh_analyze_tf(qc, &qc->result_tf); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1698 | |
| 1699 | /* DEV errors are probably spurious in case of ATA_BUS error */ |
| 1700 | if (qc->err_mask & AC_ERR_ATA_BUS) |
| 1701 | qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_MEDIA | |
| 1702 | AC_ERR_INVALID); |
| 1703 | |
| 1704 | /* any real error trumps unknown error */ |
| 1705 | if (qc->err_mask & ~AC_ERR_OTHER) |
| 1706 | qc->err_mask &= ~AC_ERR_OTHER; |
| 1707 | |
| 1708 | /* SENSE_VALID trumps dev/unknown error and revalidation */ |
Tejun Heo | f90f082 | 2007-10-26 16:12:41 +0900 | [diff] [blame] | 1709 | if (qc->flags & ATA_QCFLAG_SENSE_VALID) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1710 | qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1711 | |
| 1712 | /* accumulate error info */ |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1713 | ehc->i.dev = qc->dev; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1714 | all_err_mask |= qc->err_mask; |
| 1715 | if (qc->flags & ATA_QCFLAG_IO) |
| 1716 | is_io = 1; |
| 1717 | } |
| 1718 | |
Tejun Heo | a20f33f | 2006-05-16 12:58:24 +0900 | [diff] [blame] | 1719 | /* enforce default EH actions */ |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 1720 | if (ap->pflags & ATA_PFLAG_FROZEN || |
Tejun Heo | a20f33f | 2006-05-16 12:58:24 +0900 | [diff] [blame] | 1721 | all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT)) |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1722 | ehc->i.action |= ATA_EH_SOFTRESET; |
Tejun Heo | f90f082 | 2007-10-26 16:12:41 +0900 | [diff] [blame] | 1723 | else if ((is_io && all_err_mask) || |
| 1724 | (!is_io && (all_err_mask & ~AC_ERR_DEV))) |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1725 | ehc->i.action |= ATA_EH_REVALIDATE; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1726 | |
Tejun Heo | dfcc173 | 2007-10-31 10:17:05 +0900 | [diff] [blame] | 1727 | /* If we have offending qcs and the associated failed device, |
| 1728 | * perform per-dev EH action only on the offending device. |
| 1729 | */ |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1730 | if (ehc->i.dev) { |
Tejun Heo | 4528e4d | 2006-07-08 20:17:26 +0900 | [diff] [blame] | 1731 | ehc->i.dev_action[ehc->i.dev->devno] |= |
| 1732 | ehc->i.action & ATA_EH_PERDEV_MASK; |
| 1733 | ehc->i.action &= ~ATA_EH_PERDEV_MASK; |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 1734 | } |
| 1735 | |
Tejun Heo | 2695e36 | 2008-01-10 13:41:23 +0900 | [diff] [blame] | 1736 | /* propagate timeout to host link */ |
| 1737 | if ((all_err_mask & AC_ERR_TIMEOUT) && !ata_is_host_link(link)) |
| 1738 | ap->link.eh_context.i.err_mask |= AC_ERR_TIMEOUT; |
| 1739 | |
| 1740 | /* record error and consider speeding down */ |
Tejun Heo | dfcc173 | 2007-10-31 10:17:05 +0900 | [diff] [blame] | 1741 | dev = ehc->i.dev; |
Tejun Heo | 2695e36 | 2008-01-10 13:41:23 +0900 | [diff] [blame] | 1742 | if (!dev && ((ata_link_max_devices(link) == 1 && |
| 1743 | ata_dev_enabled(link->device)))) |
| 1744 | dev = link->device; |
Tejun Heo | dfcc173 | 2007-10-31 10:17:05 +0900 | [diff] [blame] | 1745 | |
| 1746 | if (dev) |
| 1747 | ehc->i.action |= ata_eh_speed_down(dev, is_io, all_err_mask); |
| 1748 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1749 | DPRINTK("EXIT\n"); |
| 1750 | } |
| 1751 | |
| 1752 | /** |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 1753 | * ata_eh_autopsy - analyze error and determine recovery action |
| 1754 | * @ap: host port to perform autopsy on |
| 1755 | * |
| 1756 | * Analyze all links of @ap and determine why they failed and |
| 1757 | * which recovery actions are needed. |
| 1758 | * |
| 1759 | * LOCKING: |
| 1760 | * Kernel thread context (may sleep). |
| 1761 | */ |
Tejun Heo | fb7fd61 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1762 | void ata_eh_autopsy(struct ata_port *ap) |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 1763 | { |
| 1764 | struct ata_link *link; |
| 1765 | |
Tejun Heo | 2695e36 | 2008-01-10 13:41:23 +0900 | [diff] [blame] | 1766 | ata_port_for_each_link(link, ap) |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 1767 | ata_eh_link_autopsy(link); |
Tejun Heo | 2695e36 | 2008-01-10 13:41:23 +0900 | [diff] [blame] | 1768 | |
| 1769 | /* Autopsy of fanout ports can affect host link autopsy. |
| 1770 | * Perform host link autopsy last. |
| 1771 | */ |
| 1772 | if (ap->nr_pmp_links) |
| 1773 | ata_eh_link_autopsy(&ap->link); |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | /** |
| 1777 | * ata_eh_link_report - report error handling to user |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1778 | * @link: ATA link EH is going on |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1779 | * |
| 1780 | * Report EH to user. |
| 1781 | * |
| 1782 | * LOCKING: |
| 1783 | * None. |
| 1784 | */ |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 1785 | static void ata_eh_link_report(struct ata_link *link) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1786 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1787 | struct ata_port *ap = link->ap; |
| 1788 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1789 | const char *frozen, *desc; |
Tejun Heo | a1e10f7 | 2007-08-18 13:28:49 +0900 | [diff] [blame] | 1790 | char tries_buf[6]; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1791 | int tag, nr_failed = 0; |
| 1792 | |
Tejun Heo | 94ff3d5 | 2007-10-09 14:57:56 +0900 | [diff] [blame] | 1793 | if (ehc->i.flags & ATA_EHI_QUIET) |
| 1794 | return; |
| 1795 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1796 | desc = NULL; |
| 1797 | if (ehc->i.desc[0] != '\0') |
| 1798 | desc = ehc->i.desc; |
| 1799 | |
| 1800 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
| 1801 | struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); |
| 1802 | |
Tejun Heo | e027bd3 | 2007-10-26 16:19:26 +0900 | [diff] [blame] | 1803 | if (!(qc->flags & ATA_QCFLAG_FAILED) || qc->dev->link != link || |
| 1804 | ((qc->flags & ATA_QCFLAG_QUIET) && |
| 1805 | qc->err_mask == AC_ERR_DEV)) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1806 | continue; |
| 1807 | if (qc->flags & ATA_QCFLAG_SENSE_VALID && !qc->err_mask) |
| 1808 | continue; |
| 1809 | |
| 1810 | nr_failed++; |
| 1811 | } |
| 1812 | |
| 1813 | if (!nr_failed && !ehc->i.err_mask) |
| 1814 | return; |
| 1815 | |
| 1816 | frozen = ""; |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 1817 | if (ap->pflags & ATA_PFLAG_FROZEN) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1818 | frozen = " frozen"; |
| 1819 | |
Tejun Heo | a1e10f7 | 2007-08-18 13:28:49 +0900 | [diff] [blame] | 1820 | memset(tries_buf, 0, sizeof(tries_buf)); |
| 1821 | if (ap->eh_tries < ATA_EH_MAX_TRIES) |
| 1822 | snprintf(tries_buf, sizeof(tries_buf) - 1, " t%d", |
| 1823 | ap->eh_tries); |
| 1824 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1825 | if (ehc->i.dev) { |
Tejun Heo | e8ee845 | 2006-05-15 21:03:46 +0900 | [diff] [blame] | 1826 | ata_dev_printk(ehc->i.dev, KERN_ERR, "exception Emask 0x%x " |
Tejun Heo | a1e10f7 | 2007-08-18 13:28:49 +0900 | [diff] [blame] | 1827 | "SAct 0x%x SErr 0x%x action 0x%x%s%s\n", |
| 1828 | ehc->i.err_mask, link->sactive, ehc->i.serror, |
| 1829 | ehc->i.action, frozen, tries_buf); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1830 | if (desc) |
Tejun Heo | b64bbc3 | 2007-07-16 14:29:39 +0900 | [diff] [blame] | 1831 | ata_dev_printk(ehc->i.dev, KERN_ERR, "%s\n", desc); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1832 | } else { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1833 | ata_link_printk(link, KERN_ERR, "exception Emask 0x%x " |
Tejun Heo | a1e10f7 | 2007-08-18 13:28:49 +0900 | [diff] [blame] | 1834 | "SAct 0x%x SErr 0x%x action 0x%x%s%s\n", |
| 1835 | ehc->i.err_mask, link->sactive, ehc->i.serror, |
| 1836 | ehc->i.action, frozen, tries_buf); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1837 | if (desc) |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1838 | ata_link_printk(link, KERN_ERR, "%s\n", desc); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1839 | } |
| 1840 | |
Robert Hancock | 1333e19 | 2007-10-02 11:22:02 -0400 | [diff] [blame] | 1841 | if (ehc->i.serror) |
| 1842 | ata_port_printk(ap, KERN_ERR, |
| 1843 | "SError: { %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s}\n", |
| 1844 | ehc->i.serror & SERR_DATA_RECOVERED ? "RecovData " : "", |
| 1845 | ehc->i.serror & SERR_COMM_RECOVERED ? "RecovComm " : "", |
| 1846 | ehc->i.serror & SERR_DATA ? "UnrecovData " : "", |
| 1847 | ehc->i.serror & SERR_PERSISTENT ? "Persist " : "", |
| 1848 | ehc->i.serror & SERR_PROTOCOL ? "Proto " : "", |
| 1849 | ehc->i.serror & SERR_INTERNAL ? "HostInt " : "", |
| 1850 | ehc->i.serror & SERR_PHYRDY_CHG ? "PHYRdyChg " : "", |
| 1851 | ehc->i.serror & SERR_PHY_INT_ERR ? "PHYInt " : "", |
| 1852 | ehc->i.serror & SERR_COMM_WAKE ? "CommWake " : "", |
| 1853 | ehc->i.serror & SERR_10B_8B_ERR ? "10B8B " : "", |
| 1854 | ehc->i.serror & SERR_DISPARITY ? "Dispar " : "", |
| 1855 | ehc->i.serror & SERR_CRC ? "BadCRC " : "", |
| 1856 | ehc->i.serror & SERR_HANDSHAKE ? "Handshk " : "", |
| 1857 | ehc->i.serror & SERR_LINK_SEQ_ERR ? "LinkSeq " : "", |
| 1858 | ehc->i.serror & SERR_TRANS_ST_ERROR ? "TrStaTrns " : "", |
| 1859 | ehc->i.serror & SERR_UNRECOG_FIS ? "UnrecFIS " : "", |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1860 | ehc->i.serror & SERR_DEV_XCHG ? "DevExch " : ""); |
Robert Hancock | 1333e19 | 2007-10-02 11:22:02 -0400 | [diff] [blame] | 1861 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1862 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
| 1863 | struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); |
Tejun Heo | 8a93758 | 2006-11-14 22:36:12 +0900 | [diff] [blame] | 1864 | struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf; |
Tejun Heo | abb6a88 | 2007-11-28 23:16:09 +0900 | [diff] [blame] | 1865 | const u8 *cdb = qc->cdb; |
| 1866 | char data_buf[20] = ""; |
| 1867 | char cdb_buf[70] = ""; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1868 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1869 | if (!(qc->flags & ATA_QCFLAG_FAILED) || |
| 1870 | qc->dev->link != link || !qc->err_mask) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1871 | continue; |
| 1872 | |
Tejun Heo | abb6a88 | 2007-11-28 23:16:09 +0900 | [diff] [blame] | 1873 | if (qc->dma_dir != DMA_NONE) { |
| 1874 | static const char *dma_str[] = { |
| 1875 | [DMA_BIDIRECTIONAL] = "bidi", |
| 1876 | [DMA_TO_DEVICE] = "out", |
| 1877 | [DMA_FROM_DEVICE] = "in", |
| 1878 | }; |
| 1879 | static const char *prot_str[] = { |
| 1880 | [ATA_PROT_PIO] = "pio", |
| 1881 | [ATA_PROT_DMA] = "dma", |
| 1882 | [ATA_PROT_NCQ] = "ncq", |
| 1883 | [ATA_PROT_ATAPI] = "pio", |
| 1884 | [ATA_PROT_ATAPI_DMA] = "dma", |
| 1885 | }; |
| 1886 | |
| 1887 | snprintf(data_buf, sizeof(data_buf), " %s %u %s", |
| 1888 | prot_str[qc->tf.protocol], qc->nbytes, |
| 1889 | dma_str[qc->dma_dir]); |
| 1890 | } |
| 1891 | |
| 1892 | if (is_atapi_taskfile(&qc->tf)) |
| 1893 | snprintf(cdb_buf, sizeof(cdb_buf), |
| 1894 | "cdb %02x %02x %02x %02x %02x %02x %02x %02x " |
| 1895 | "%02x %02x %02x %02x %02x %02x %02x %02x\n ", |
| 1896 | cdb[0], cdb[1], cdb[2], cdb[3], |
| 1897 | cdb[4], cdb[5], cdb[6], cdb[7], |
| 1898 | cdb[8], cdb[9], cdb[10], cdb[11], |
| 1899 | cdb[12], cdb[13], cdb[14], cdb[15]); |
| 1900 | |
Tejun Heo | 8a93758 | 2006-11-14 22:36:12 +0900 | [diff] [blame] | 1901 | ata_dev_printk(qc->dev, KERN_ERR, |
| 1902 | "cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x " |
Tejun Heo | abb6a88 | 2007-11-28 23:16:09 +0900 | [diff] [blame] | 1903 | "tag %d%s\n %s" |
Tejun Heo | 8a93758 | 2006-11-14 22:36:12 +0900 | [diff] [blame] | 1904 | "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] | 1905 | "Emask 0x%x (%s)%s\n", |
Tejun Heo | 8a93758 | 2006-11-14 22:36:12 +0900 | [diff] [blame] | 1906 | cmd->command, cmd->feature, cmd->nsect, |
| 1907 | cmd->lbal, cmd->lbam, cmd->lbah, |
| 1908 | cmd->hob_feature, cmd->hob_nsect, |
| 1909 | cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah, |
Tejun Heo | abb6a88 | 2007-11-28 23:16:09 +0900 | [diff] [blame] | 1910 | cmd->device, qc->tag, data_buf, cdb_buf, |
Tejun Heo | 8a93758 | 2006-11-14 22:36:12 +0900 | [diff] [blame] | 1911 | res->command, res->feature, res->nsect, |
| 1912 | res->lbal, res->lbam, res->lbah, |
| 1913 | res->hob_feature, res->hob_nsect, |
| 1914 | res->hob_lbal, res->hob_lbam, res->hob_lbah, |
Tejun Heo | 5335b72 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 1915 | res->device, qc->err_mask, ata_err_string(qc->err_mask), |
| 1916 | qc->err_mask & AC_ERR_NCQ ? " <F>" : ""); |
Robert Hancock | 1333e19 | 2007-10-02 11:22:02 -0400 | [diff] [blame] | 1917 | |
| 1918 | if (res->command & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1919 | ATA_ERR)) { |
Robert Hancock | 1333e19 | 2007-10-02 11:22:02 -0400 | [diff] [blame] | 1920 | if (res->command & ATA_BUSY) |
| 1921 | ata_dev_printk(qc->dev, KERN_ERR, |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1922 | "status: { Busy }\n"); |
Robert Hancock | 1333e19 | 2007-10-02 11:22:02 -0400 | [diff] [blame] | 1923 | else |
| 1924 | ata_dev_printk(qc->dev, KERN_ERR, |
| 1925 | "status: { %s%s%s%s}\n", |
| 1926 | res->command & ATA_DRDY ? "DRDY " : "", |
| 1927 | res->command & ATA_DF ? "DF " : "", |
| 1928 | res->command & ATA_DRQ ? "DRQ " : "", |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1929 | res->command & ATA_ERR ? "ERR " : ""); |
Robert Hancock | 1333e19 | 2007-10-02 11:22:02 -0400 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | if (cmd->command != ATA_CMD_PACKET && |
| 1933 | (res->feature & (ATA_ICRC | ATA_UNC | ATA_IDNF | |
| 1934 | ATA_ABORTED))) |
| 1935 | ata_dev_printk(qc->dev, KERN_ERR, |
| 1936 | "error: { %s%s%s%s}\n", |
| 1937 | res->feature & ATA_ICRC ? "ICRC " : "", |
| 1938 | res->feature & ATA_UNC ? "UNC " : "", |
| 1939 | res->feature & ATA_IDNF ? "IDNF " : "", |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1940 | res->feature & ATA_ABORTED ? "ABRT " : ""); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 1941 | } |
| 1942 | } |
| 1943 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 1944 | /** |
| 1945 | * ata_eh_report - report error handling to user |
| 1946 | * @ap: ATA port to report EH about |
| 1947 | * |
| 1948 | * Report EH to user. |
| 1949 | * |
| 1950 | * LOCKING: |
| 1951 | * None. |
| 1952 | */ |
Tejun Heo | fb7fd61 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1953 | void ata_eh_report(struct ata_port *ap) |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 1954 | { |
| 1955 | struct ata_link *link; |
| 1956 | |
| 1957 | __ata_port_for_each_link(link, ap) |
| 1958 | ata_eh_link_report(link); |
| 1959 | } |
| 1960 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1961 | 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] | 1962 | unsigned int *classes, unsigned long deadline) |
Tejun Heo | d87fa38 | 2006-05-31 18:28:24 +0900 | [diff] [blame] | 1963 | { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1964 | struct ata_device *dev; |
| 1965 | int rc; |
Tejun Heo | d87fa38 | 2006-05-31 18:28:24 +0900 | [diff] [blame] | 1966 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1967 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1968 | classes[dev->devno] = ATA_DEV_UNKNOWN; |
Tejun Heo | d87fa38 | 2006-05-31 18:28:24 +0900 | [diff] [blame] | 1969 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1970 | rc = reset(link, classes, deadline); |
Tejun Heo | d87fa38 | 2006-05-31 18:28:24 +0900 | [diff] [blame] | 1971 | if (rc) |
| 1972 | return rc; |
| 1973 | |
| 1974 | /* If any class isn't ATA_DEV_UNKNOWN, consider classification |
| 1975 | * is complete and convert all ATA_DEV_UNKNOWN to |
| 1976 | * ATA_DEV_NONE. |
| 1977 | */ |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1978 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1979 | if (classes[dev->devno] != ATA_DEV_UNKNOWN) |
Tejun Heo | d87fa38 | 2006-05-31 18:28:24 +0900 | [diff] [blame] | 1980 | break; |
| 1981 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1982 | if (dev) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1983 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 1984 | if (classes[dev->devno] == ATA_DEV_UNKNOWN) |
| 1985 | classes[dev->devno] = ATA_DEV_NONE; |
| 1986 | } |
| 1987 | } |
Tejun Heo | d87fa38 | 2006-05-31 18:28:24 +0900 | [diff] [blame] | 1988 | |
| 1989 | return 0; |
| 1990 | } |
| 1991 | |
Tejun Heo | ae791c0 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1992 | static int ata_eh_followup_srst_needed(struct ata_link *link, |
| 1993 | int rc, int classify, |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 1994 | const unsigned int *classes) |
| 1995 | { |
Tejun Heo | ae791c0 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1996 | if (link->flags & ATA_LFLAG_NO_SRST) |
| 1997 | return 0; |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 1998 | if (rc == -EAGAIN) |
| 1999 | return 1; |
| 2000 | if (rc != 0) |
| 2001 | return 0; |
Tejun Heo | 3495de7 | 2007-09-23 13:19:53 +0900 | [diff] [blame] | 2002 | if ((link->ap->flags & ATA_FLAG_PMP) && ata_is_host_link(link)) |
| 2003 | return 1; |
Tejun Heo | ae791c0 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 2004 | if (classify && !(link->flags & ATA_LFLAG_ASSUME_CLASS) && |
| 2005 | classes[0] == ATA_DEV_UNKNOWN) |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 2006 | return 1; |
| 2007 | return 0; |
| 2008 | } |
| 2009 | |
Tejun Heo | fb7fd61 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 2010 | int ata_eh_reset(struct ata_link *link, int classify, |
| 2011 | ata_prereset_fn_t prereset, ata_reset_fn_t softreset, |
| 2012 | ata_reset_fn_t hardreset, ata_postreset_fn_t postreset) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2013 | { |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2014 | const int max_tries = ARRAY_SIZE(ata_eh_reset_timeouts); |
Tejun Heo | afaa5c3 | 2007-10-09 15:06:10 +0900 | [diff] [blame] | 2015 | struct ata_port *ap = link->ap; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2016 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 2017 | unsigned int *classes = ehc->classes; |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2018 | unsigned int lflags = link->flags; |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 2019 | int verbose = !(ehc->i.flags & ATA_EHI_QUIET); |
Tejun Heo | 31daabd | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 2020 | int try = 0; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2021 | struct ata_device *dev; |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2022 | unsigned long deadline, now; |
Tejun Heo | 0e06d9c | 2007-10-24 15:21:26 +0900 | [diff] [blame] | 2023 | unsigned int tmp_action; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2024 | ata_reset_fn_t reset; |
Tejun Heo | afaa5c3 | 2007-10-09 15:06:10 +0900 | [diff] [blame] | 2025 | unsigned long flags; |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2026 | u32 sstatus; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2027 | int rc; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2028 | |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 2029 | /* about to reset */ |
Tejun Heo | afaa5c3 | 2007-10-09 15:06:10 +0900 | [diff] [blame] | 2030 | spin_lock_irqsave(ap->lock, flags); |
| 2031 | ap->pflags |= ATA_PFLAG_RESETTING; |
| 2032 | spin_unlock_irqrestore(ap->lock, flags); |
| 2033 | |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2034 | 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] | 2035 | |
Tejun Heo | cdeab11 | 2007-10-29 16:41:09 +0900 | [diff] [blame] | 2036 | ata_link_for_each_dev(dev, link) { |
| 2037 | /* If we issue an SRST then an ATA drive (not ATAPI) |
| 2038 | * may change configuration and be in PIO0 timing. If |
| 2039 | * we do a hard reset (or are coming from power on) |
| 2040 | * this is true for ATA or ATAPI. Until we've set a |
| 2041 | * suitable controller mode we should not touch the |
| 2042 | * bus as we may be talking too fast. |
| 2043 | */ |
| 2044 | dev->pio_mode = XFER_PIO_0; |
| 2045 | |
| 2046 | /* If the controller has a pio mode setup function |
| 2047 | * then use it to set the chipset to rights. Don't |
| 2048 | * touch the DMA setup as that will be dealt with when |
| 2049 | * configuring devices. |
| 2050 | */ |
| 2051 | if (ap->ops->set_piomode) |
| 2052 | ap->ops->set_piomode(ap, dev); |
| 2053 | } |
| 2054 | |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2055 | /* Determine which reset to use and record in ehc->i.action. |
| 2056 | * prereset() may examine and modify it. |
| 2057 | */ |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2058 | if (softreset && (!hardreset || (!(lflags & ATA_LFLAG_NO_SRST) && |
Tejun Heo | ae791c0 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 2059 | !sata_set_spd_needed(link) && |
Tejun Heo | 0e06d9c | 2007-10-24 15:21:26 +0900 | [diff] [blame] | 2060 | !(ehc->i.action & ATA_EH_HARDRESET)))) |
| 2061 | tmp_action = ATA_EH_SOFTRESET; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2062 | else |
Tejun Heo | 0e06d9c | 2007-10-24 15:21:26 +0900 | [diff] [blame] | 2063 | tmp_action = ATA_EH_HARDRESET; |
| 2064 | |
| 2065 | ehc->i.action = (ehc->i.action & ~ATA_EH_RESET_MASK) | tmp_action; |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2066 | |
| 2067 | if (prereset) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2068 | rc = prereset(link, jiffies + ATA_EH_PRERESET_TIMEOUT); |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2069 | if (rc) { |
Alan Cox | c961922 | 2006-09-26 17:53:38 +0100 | [diff] [blame] | 2070 | if (rc == -ENOENT) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2071 | ata_link_printk(link, KERN_DEBUG, |
Tejun Heo | 4aa9ab6 | 2007-03-12 17:24:08 +0900 | [diff] [blame] | 2072 | "port disabled. ignoring.\n"); |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2073 | ehc->i.action &= ~ATA_EH_RESET_MASK; |
Tejun Heo | 4aa9ab6 | 2007-03-12 17:24:08 +0900 | [diff] [blame] | 2074 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2075 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2076 | classes[dev->devno] = ATA_DEV_NONE; |
Tejun Heo | 4aa9ab6 | 2007-03-12 17:24:08 +0900 | [diff] [blame] | 2077 | |
| 2078 | rc = 0; |
Alan Cox | c961922 | 2006-09-26 17:53:38 +0100 | [diff] [blame] | 2079 | } else |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2080 | ata_link_printk(link, KERN_ERR, |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2081 | "prereset failed (errno=%d)\n", rc); |
Tejun Heo | fccb6ea | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 2082 | goto out; |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2083 | } |
| 2084 | } |
| 2085 | |
| 2086 | /* prereset() might have modified ehc->i.action */ |
| 2087 | if (ehc->i.action & ATA_EH_HARDRESET) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2088 | reset = hardreset; |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2089 | else if (ehc->i.action & ATA_EH_SOFTRESET) |
| 2090 | reset = softreset; |
| 2091 | else { |
| 2092 | /* prereset told us not to reset, bang classes and return */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2093 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2094 | classes[dev->devno] = ATA_DEV_NONE; |
Tejun Heo | fccb6ea | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 2095 | rc = 0; |
| 2096 | goto out; |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | /* did prereset() screw up? if so, fix up to avoid oopsing */ |
| 2100 | if (!reset) { |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2101 | if (softreset) |
| 2102 | reset = softreset; |
| 2103 | else |
| 2104 | reset = hardreset; |
| 2105 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2106 | |
| 2107 | retry: |
Tejun Heo | 31daabd | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 2108 | deadline = jiffies + ata_eh_reset_timeouts[try++]; |
| 2109 | |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 2110 | /* shut up during boot probing */ |
| 2111 | if (verbose) |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2112 | ata_link_printk(link, KERN_INFO, "%s resetting link\n", |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 2113 | reset == softreset ? "soft" : "hard"); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2114 | |
Tejun Heo | 13abf50 | 2006-07-10 23:18:46 +0900 | [diff] [blame] | 2115 | /* mark that this EH session started with reset */ |
Tejun Heo | 0d64a23 | 2007-04-23 02:41:05 +0900 | [diff] [blame] | 2116 | if (reset == hardreset) |
| 2117 | ehc->i.flags |= ATA_EHI_DID_HARDRESET; |
| 2118 | else |
| 2119 | ehc->i.flags |= ATA_EHI_DID_SOFTRESET; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2120 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2121 | rc = ata_do_reset(link, reset, classes, deadline); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2122 | |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 2123 | if (reset == hardreset && |
Tejun Heo | ae791c0 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 2124 | ata_eh_followup_srst_needed(link, rc, classify, classes)) { |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 2125 | /* okay, let's do follow-up softreset */ |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 2126 | reset = softreset; |
| 2127 | |
| 2128 | if (!reset) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2129 | ata_link_printk(link, KERN_ERR, |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 2130 | "follow-up softreset required " |
| 2131 | "but no softreset avaliable\n"); |
Tejun Heo | fccb6ea | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 2132 | rc = -EINVAL; |
Tejun Heo | 08cf69d | 2007-10-31 10:17:04 +0900 | [diff] [blame] | 2133 | goto fail; |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 2134 | } |
| 2135 | |
Tejun Heo | 955e57d | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2136 | ata_eh_about_to_do(link, NULL, ATA_EH_RESET_MASK); |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2137 | rc = ata_do_reset(link, reset, classes, deadline); |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 2138 | } |
| 2139 | |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2140 | /* -EAGAIN can happen if we skipped followup SRST */ |
| 2141 | if (rc && rc != -EAGAIN) |
| 2142 | goto fail; |
Tejun Heo | ae791c0 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 2143 | |
Tejun Heo | 08cf69d | 2007-10-31 10:17:04 +0900 | [diff] [blame] | 2144 | /* was classification successful? */ |
| 2145 | if (classify && classes[0] == ATA_DEV_UNKNOWN && |
| 2146 | !(lflags & ATA_LFLAG_ASSUME_CLASS)) { |
| 2147 | if (try < max_tries) { |
| 2148 | ata_link_printk(link, KERN_WARNING, |
| 2149 | "classification failed\n"); |
| 2150 | rc = -EINVAL; |
| 2151 | goto fail; |
| 2152 | } |
| 2153 | |
| 2154 | ata_link_printk(link, KERN_WARNING, |
| 2155 | "classfication failed, assuming ATA\n"); |
| 2156 | lflags |= ATA_LFLAG_ASSUME_ATA; |
| 2157 | } |
| 2158 | |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2159 | ata_link_for_each_dev(dev, link) { |
| 2160 | /* After the reset, the device state is PIO 0 and the |
| 2161 | * controller state is undefined. Reset also wakes up |
| 2162 | * drives from sleeping mode. |
| 2163 | */ |
| 2164 | dev->pio_mode = XFER_PIO_0; |
| 2165 | dev->flags &= ~ATA_DFLAG_SLEEPING; |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 2166 | |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2167 | if (ata_link_offline(link)) |
| 2168 | continue; |
Tejun Heo | 664faf0 | 2006-05-31 18:27:50 +0900 | [diff] [blame] | 2169 | |
Tejun Heo | 4ccd332 | 2008-01-08 20:26:12 +0900 | [diff] [blame] | 2170 | /* apply class override */ |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2171 | if (lflags & ATA_LFLAG_ASSUME_ATA) |
| 2172 | classes[dev->devno] = ATA_DEV_ATA; |
| 2173 | else if (lflags & ATA_LFLAG_ASSUME_SEMB) |
| 2174 | classes[dev->devno] = ATA_DEV_SEMB_UNSUP; /* not yet */ |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2175 | } |
| 2176 | |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2177 | /* record current link speed */ |
| 2178 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0) |
| 2179 | link->sata_spd = (sstatus >> 4) & 0xf; |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2180 | |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2181 | if (postreset) |
| 2182 | postreset(link, classes); |
Tejun Heo | 20952b6 | 2006-05-31 18:27:23 +0900 | [diff] [blame] | 2183 | |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2184 | /* reset successful, schedule revalidation */ |
| 2185 | ata_eh_done(link, NULL, ehc->i.action & ATA_EH_RESET_MASK); |
| 2186 | ehc->i.action |= ATA_EH_REVALIDATE; |
Tejun Heo | ae791c0 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 2187 | |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2188 | rc = 0; |
Tejun Heo | fccb6ea | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 2189 | out: |
| 2190 | /* clear hotplug flag */ |
| 2191 | ehc->i.flags &= ~ATA_EHI_HOTPLUGGED; |
Tejun Heo | afaa5c3 | 2007-10-09 15:06:10 +0900 | [diff] [blame] | 2192 | |
| 2193 | spin_lock_irqsave(ap->lock, flags); |
| 2194 | ap->pflags &= ~ATA_PFLAG_RESETTING; |
| 2195 | spin_unlock_irqrestore(ap->lock, flags); |
| 2196 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2197 | return rc; |
Tejun Heo | 416dc9e | 2007-10-31 10:17:03 +0900 | [diff] [blame] | 2198 | |
| 2199 | fail: |
| 2200 | if (rc == -ERESTART || try >= max_tries) |
| 2201 | goto out; |
| 2202 | |
| 2203 | now = jiffies; |
| 2204 | if (time_before(now, deadline)) { |
| 2205 | unsigned long delta = deadline - now; |
| 2206 | |
| 2207 | ata_link_printk(link, KERN_WARNING, "reset failed " |
| 2208 | "(errno=%d), retrying in %u secs\n", |
| 2209 | rc, (jiffies_to_msecs(delta) + 999) / 1000); |
| 2210 | |
| 2211 | while (delta) |
| 2212 | delta = schedule_timeout_uninterruptible(delta); |
| 2213 | } |
| 2214 | |
| 2215 | if (rc == -EPIPE || try == max_tries - 1) |
| 2216 | sata_down_spd_limit(link); |
| 2217 | if (hardreset) |
| 2218 | reset = hardreset; |
| 2219 | goto retry; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2220 | } |
| 2221 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2222 | static int ata_eh_revalidate_and_attach(struct ata_link *link, |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2223 | struct ata_device **r_failed_dev) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2224 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2225 | struct ata_port *ap = link->ap; |
| 2226 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2227 | struct ata_device *dev; |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2228 | unsigned int new_mask = 0; |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2229 | unsigned long flags; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2230 | int rc = 0; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2231 | |
| 2232 | DPRINTK("ENTER\n"); |
| 2233 | |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2234 | /* For PATA drive side cable detection to work, IDENTIFY must |
| 2235 | * be done backwards such that PDIAG- is released by the slave |
| 2236 | * device before the master device is identified. |
| 2237 | */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2238 | ata_link_for_each_dev_reverse(dev, link) { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2239 | unsigned int action = ata_eh_dev_action(dev); |
| 2240 | unsigned int readid_flags = 0; |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 2241 | |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 2242 | if (ehc->i.flags & ATA_EHI_DID_RESET) |
| 2243 | readid_flags |= ATA_READID_POSTRESET; |
| 2244 | |
Tejun Heo | 9666f40 | 2007-05-04 21:27:47 +0200 | [diff] [blame] | 2245 | if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) { |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 2246 | WARN_ON(dev->class == ATA_DEV_PMP); |
| 2247 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2248 | if (ata_link_offline(link)) { |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2249 | rc = -EIO; |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2250 | goto err; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2251 | } |
| 2252 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2253 | ata_eh_about_to_do(link, dev, ATA_EH_REVALIDATE); |
Tejun Heo | 422c9da | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 2254 | rc = ata_dev_revalidate(dev, ehc->classes[dev->devno], |
| 2255 | readid_flags); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2256 | if (rc) |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2257 | goto err; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2258 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2259 | ata_eh_done(link, dev, ATA_EH_REVALIDATE); |
Tejun Heo | 47005f2 | 2006-06-19 18:27:23 +0900 | [diff] [blame] | 2260 | |
Tejun Heo | baa1e78 | 2006-11-01 18:39:27 +0900 | [diff] [blame] | 2261 | /* Configuration may have changed, reconfigure |
| 2262 | * transfer mode. |
| 2263 | */ |
| 2264 | ehc->i.flags |= ATA_EHI_SETMODE; |
| 2265 | |
zhao, forrest | 3057ac3 | 2006-06-12 12:01:34 +0800 | [diff] [blame] | 2266 | /* schedule the scsi_rescan_device() here */ |
| 2267 | queue_work(ata_aux_wq, &(ap->scsi_rescan_task)); |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2268 | } else if (dev->class == ATA_DEV_UNKNOWN && |
| 2269 | ehc->tries[dev->devno] && |
| 2270 | ata_class_enabled(ehc->classes[dev->devno])) { |
| 2271 | dev->class = ehc->classes[dev->devno]; |
| 2272 | |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 2273 | if (dev->class == ATA_DEV_PMP) |
| 2274 | rc = sata_pmp_attach(dev); |
| 2275 | else |
| 2276 | rc = ata_dev_read_id(dev, &dev->class, |
| 2277 | readid_flags, dev->id); |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2278 | switch (rc) { |
| 2279 | case 0: |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2280 | new_mask |= 1 << dev->devno; |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2281 | break; |
| 2282 | case -ENOENT: |
Tejun Heo | 55a8e2c | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 2283 | /* IDENTIFY was issued to non-existent |
| 2284 | * device. No need to reset. Just |
| 2285 | * thaw and kill the device. |
| 2286 | */ |
| 2287 | ata_eh_thaw_port(ap); |
| 2288 | dev->class = ATA_DEV_UNKNOWN; |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2289 | break; |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2290 | default: |
| 2291 | dev->class = ATA_DEV_UNKNOWN; |
| 2292 | goto err; |
Tejun Heo | 55a8e2c | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 2293 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2294 | } |
| 2295 | } |
| 2296 | |
Tejun Heo | c1c4e8d | 2007-04-23 02:05:53 +0900 | [diff] [blame] | 2297 | /* PDIAG- should have been released, ask cable type if post-reset */ |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2298 | if (ata_is_host_link(link) && ap->ops->cable_detect && |
| 2299 | (ehc->i.flags & ATA_EHI_DID_RESET)) |
Tejun Heo | c1c4e8d | 2007-04-23 02:05:53 +0900 | [diff] [blame] | 2300 | ap->cbl = ap->ops->cable_detect(ap); |
| 2301 | |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2302 | /* Configure new devices forward such that user doesn't see |
| 2303 | * device detection messages backwards. |
| 2304 | */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2305 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 2306 | if (!(new_mask & (1 << dev->devno)) || |
| 2307 | dev->class == ATA_DEV_PMP) |
Tejun Heo | 8c3c52a | 2007-03-22 22:24:19 +0900 | [diff] [blame] | 2308 | continue; |
| 2309 | |
| 2310 | ehc->i.flags |= ATA_EHI_PRINTINFO; |
| 2311 | rc = ata_dev_configure(dev); |
| 2312 | ehc->i.flags &= ~ATA_EHI_PRINTINFO; |
| 2313 | if (rc) |
| 2314 | goto err; |
| 2315 | |
| 2316 | spin_lock_irqsave(ap->lock, flags); |
| 2317 | ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG; |
| 2318 | spin_unlock_irqrestore(ap->lock, flags); |
| 2319 | |
| 2320 | /* new device discovered, configure xfermode */ |
| 2321 | ehc->i.flags |= ATA_EHI_SETMODE; |
| 2322 | } |
| 2323 | |
| 2324 | return 0; |
| 2325 | |
| 2326 | err: |
| 2327 | *r_failed_dev = dev; |
| 2328 | DPRINTK("EXIT rc=%d\n", rc); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2329 | return rc; |
| 2330 | } |
| 2331 | |
Tejun Heo | 6f1d1e3 | 2007-11-27 19:28:55 +0900 | [diff] [blame^] | 2332 | /** |
| 2333 | * ata_set_mode - Program timings and issue SET FEATURES - XFER |
| 2334 | * @link: link on which timings will be programmed |
| 2335 | * @r_failed_dev: out paramter for failed device |
| 2336 | * |
| 2337 | * Set ATA device disk transfer mode (PIO3, UDMA6, etc.). If |
| 2338 | * ata_set_mode() fails, pointer to the failing device is |
| 2339 | * returned in @r_failed_dev. |
| 2340 | * |
| 2341 | * LOCKING: |
| 2342 | * PCI/etc. bus probe sem. |
| 2343 | * |
| 2344 | * RETURNS: |
| 2345 | * 0 on success, negative errno otherwise |
| 2346 | */ |
| 2347 | int ata_set_mode(struct ata_link *link, struct ata_device **r_failed_dev) |
| 2348 | { |
| 2349 | struct ata_port *ap = link->ap; |
| 2350 | |
| 2351 | /* has private set_mode? */ |
| 2352 | if (ap->ops->set_mode) |
| 2353 | return ap->ops->set_mode(link, r_failed_dev); |
| 2354 | return ata_do_set_mode(link, r_failed_dev); |
| 2355 | } |
| 2356 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2357 | static int ata_link_nr_enabled(struct ata_link *link) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2358 | { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2359 | struct ata_device *dev; |
| 2360 | int cnt = 0; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2361 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2362 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2363 | if (ata_dev_enabled(dev)) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2364 | cnt++; |
| 2365 | return cnt; |
| 2366 | } |
| 2367 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2368 | static int ata_link_nr_vacant(struct ata_link *link) |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2369 | { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2370 | struct ata_device *dev; |
| 2371 | int cnt = 0; |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2372 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2373 | ata_link_for_each_dev(dev, link) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2374 | if (dev->class == ATA_DEV_UNKNOWN) |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2375 | cnt++; |
| 2376 | return cnt; |
| 2377 | } |
| 2378 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2379 | static int ata_eh_skip_recovery(struct ata_link *link) |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2380 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2381 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2382 | struct ata_device *dev; |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2383 | |
Tejun Heo | f9df58c | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 2384 | /* skip disabled links */ |
| 2385 | if (link->flags & ATA_LFLAG_DISABLED) |
| 2386 | return 1; |
| 2387 | |
Tejun Heo | 7c8c2cf | 2006-07-10 23:18:23 +0900 | [diff] [blame] | 2388 | /* thaw frozen port, resume link and recover failed devices */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2389 | if ((link->ap->pflags & ATA_PFLAG_FROZEN) || |
| 2390 | (ehc->i.flags & ATA_EHI_RESUME_LINK) || ata_link_nr_enabled(link)) |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2391 | return 0; |
| 2392 | |
| 2393 | /* skip if class codes for all vacant slots are ATA_DEV_NONE */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2394 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2395 | if (dev->class == ATA_DEV_UNKNOWN && |
| 2396 | ehc->classes[dev->devno] != ATA_DEV_NONE) |
| 2397 | return 0; |
| 2398 | } |
| 2399 | |
| 2400 | return 1; |
| 2401 | } |
| 2402 | |
Tejun Heo | 02c05a2 | 2007-11-27 19:28:54 +0900 | [diff] [blame] | 2403 | static int ata_eh_schedule_probe(struct ata_device *dev) |
| 2404 | { |
| 2405 | struct ata_eh_context *ehc = &dev->link->eh_context; |
| 2406 | |
| 2407 | if (!(ehc->i.probe_mask & (1 << dev->devno)) || |
| 2408 | (ehc->did_probe_mask & (1 << dev->devno))) |
| 2409 | return 0; |
| 2410 | |
| 2411 | ata_eh_detach_dev(dev); |
| 2412 | ata_dev_init(dev); |
| 2413 | ehc->did_probe_mask |= (1 << dev->devno); |
| 2414 | ehc->i.action |= ATA_EH_SOFTRESET; |
| 2415 | |
| 2416 | return 1; |
| 2417 | } |
| 2418 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2419 | 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] | 2420 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2421 | struct ata_eh_context *ehc = &dev->link->eh_context; |
Tejun Heo | fee7ca7 | 2007-07-01 19:05:58 +0900 | [diff] [blame] | 2422 | |
| 2423 | ehc->tries[dev->devno]--; |
| 2424 | |
| 2425 | switch (err) { |
| 2426 | case -ENODEV: |
| 2427 | /* device missing or wrong IDENTIFY data, schedule probing */ |
| 2428 | ehc->i.probe_mask |= (1 << dev->devno); |
| 2429 | case -EINVAL: |
| 2430 | /* give it just one more chance */ |
| 2431 | ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1); |
| 2432 | case -EIO: |
Tejun Heo | 4fb4615 | 2007-10-29 16:45:05 +0900 | [diff] [blame] | 2433 | if (ehc->tries[dev->devno] == 1 && dev->pio_mode > XFER_PIO_0) { |
Tejun Heo | fee7ca7 | 2007-07-01 19:05:58 +0900 | [diff] [blame] | 2434 | /* This is the last chance, better to slow |
| 2435 | * down than lose it. |
| 2436 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2437 | sata_down_spd_limit(dev->link); |
Tejun Heo | fee7ca7 | 2007-07-01 19:05:58 +0900 | [diff] [blame] | 2438 | ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); |
| 2439 | } |
| 2440 | } |
| 2441 | |
| 2442 | if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) { |
| 2443 | /* disable device if it has used up all its chances */ |
| 2444 | ata_dev_disable(dev); |
| 2445 | |
| 2446 | /* detach if offline */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2447 | if (ata_link_offline(dev->link)) |
Tejun Heo | fee7ca7 | 2007-07-01 19:05:58 +0900 | [diff] [blame] | 2448 | ata_eh_detach_dev(dev); |
| 2449 | |
Tejun Heo | 02c05a2 | 2007-11-27 19:28:54 +0900 | [diff] [blame] | 2450 | /* schedule probe if necessary */ |
| 2451 | if (ata_eh_schedule_probe(dev)) |
Tejun Heo | fee7ca7 | 2007-07-01 19:05:58 +0900 | [diff] [blame] | 2452 | ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2453 | |
| 2454 | return 1; |
Tejun Heo | fee7ca7 | 2007-07-01 19:05:58 +0900 | [diff] [blame] | 2455 | } else { |
| 2456 | /* soft didn't work? be haaaaard */ |
| 2457 | if (ehc->i.flags & ATA_EHI_DID_RESET) |
| 2458 | ehc->i.action |= ATA_EH_HARDRESET; |
| 2459 | else |
| 2460 | ehc->i.action |= ATA_EH_SOFTRESET; |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2461 | |
| 2462 | return 0; |
Tejun Heo | fee7ca7 | 2007-07-01 19:05:58 +0900 | [diff] [blame] | 2463 | } |
| 2464 | } |
| 2465 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2466 | /** |
| 2467 | * ata_eh_recover - recover host port after error |
| 2468 | * @ap: host port to recover |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2469 | * @prereset: prereset method (can be NULL) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2470 | * @softreset: softreset method (can be NULL) |
| 2471 | * @hardreset: hardreset method (can be NULL) |
| 2472 | * @postreset: postreset method (can be NULL) |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2473 | * @r_failed_link: out parameter for failed link |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2474 | * |
| 2475 | * This is the alpha and omega, eum and yang, heart and soul of |
| 2476 | * libata exception handling. On entry, actions required to |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2477 | * recover each link and hotplug requests are recorded in the |
| 2478 | * link's eh_context. This function executes all the operations |
| 2479 | * with appropriate retrials and fallbacks to resurrect failed |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2480 | * devices, detach goners and greet newcomers. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2481 | * |
| 2482 | * LOCKING: |
| 2483 | * Kernel thread context (may sleep). |
| 2484 | * |
| 2485 | * RETURNS: |
| 2486 | * 0 on success, -errno on failure. |
| 2487 | */ |
Tejun Heo | fb7fd61 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 2488 | int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, |
| 2489 | ata_reset_fn_t softreset, ata_reset_fn_t hardreset, |
| 2490 | ata_postreset_fn_t postreset, |
| 2491 | struct ata_link **r_failed_link) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2492 | { |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2493 | struct ata_link *link; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2494 | struct ata_device *dev; |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2495 | int nr_failed_devs, nr_disabled_devs; |
| 2496 | int reset, rc; |
Tejun Heo | f9df58c | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 2497 | unsigned long flags; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2498 | |
| 2499 | DPRINTK("ENTER\n"); |
| 2500 | |
| 2501 | /* prep for recovery */ |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2502 | ata_port_for_each_link(link, ap) { |
| 2503 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2504 | |
Tejun Heo | f9df58c | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 2505 | /* re-enable link? */ |
| 2506 | if (ehc->i.action & ATA_EH_ENABLE_LINK) { |
| 2507 | ata_eh_about_to_do(link, NULL, ATA_EH_ENABLE_LINK); |
| 2508 | spin_lock_irqsave(ap->lock, flags); |
| 2509 | link->flags &= ~ATA_LFLAG_DISABLED; |
| 2510 | spin_unlock_irqrestore(ap->lock, flags); |
| 2511 | ata_eh_done(link, NULL, ATA_EH_ENABLE_LINK); |
| 2512 | } |
| 2513 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2514 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | fd995f7 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 2515 | if (link->flags & ATA_LFLAG_NO_RETRY) |
| 2516 | ehc->tries[dev->devno] = 1; |
| 2517 | else |
| 2518 | ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; |
Tejun Heo | 79a55b7 | 2007-01-18 17:22:18 +0900 | [diff] [blame] | 2519 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2520 | /* collect port action mask recorded in dev actions */ |
| 2521 | ehc->i.action |= ehc->i.dev_action[dev->devno] & |
| 2522 | ~ATA_EH_PERDEV_MASK; |
| 2523 | ehc->i.dev_action[dev->devno] &= ATA_EH_PERDEV_MASK; |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2524 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2525 | /* process hotplug request */ |
| 2526 | if (dev->flags & ATA_DFLAG_DETACH) |
| 2527 | ata_eh_detach_dev(dev); |
| 2528 | |
Tejun Heo | 02c05a2 | 2007-11-27 19:28:54 +0900 | [diff] [blame] | 2529 | /* schedule probe if necessary */ |
| 2530 | if (!ata_dev_enabled(dev)) |
| 2531 | ata_eh_schedule_probe(dev); |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2532 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2533 | } |
| 2534 | |
| 2535 | retry: |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2536 | rc = 0; |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2537 | nr_failed_devs = 0; |
| 2538 | nr_disabled_devs = 0; |
| 2539 | reset = 0; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2540 | |
Tejun Heo | aeb2ecd | 2006-06-12 14:11:43 +0900 | [diff] [blame] | 2541 | /* if UNLOADING, finish immediately */ |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 2542 | if (ap->pflags & ATA_PFLAG_UNLOADING) |
Tejun Heo | aeb2ecd | 2006-06-12 14:11:43 +0900 | [diff] [blame] | 2543 | goto out; |
| 2544 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2545 | /* prep for EH */ |
| 2546 | ata_port_for_each_link(link, ap) { |
| 2547 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2548 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2549 | /* skip EH if possible. */ |
| 2550 | if (ata_eh_skip_recovery(link)) |
| 2551 | ehc->i.action = 0; |
| 2552 | |
| 2553 | /* do we need to reset? */ |
| 2554 | if (ehc->i.action & ATA_EH_RESET_MASK) |
| 2555 | reset = 1; |
| 2556 | |
| 2557 | ata_link_for_each_dev(dev, link) |
| 2558 | ehc->classes[dev->devno] = ATA_DEV_UNKNOWN; |
| 2559 | } |
Tejun Heo | 084fe63 | 2006-05-31 18:28:03 +0900 | [diff] [blame] | 2560 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2561 | /* reset */ |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2562 | if (reset) { |
Tejun Heo | b06ce3e | 2007-10-09 15:06:48 +0900 | [diff] [blame] | 2563 | /* if PMP is attached, this function only deals with |
| 2564 | * downstream links, port should stay thawed. |
| 2565 | */ |
| 2566 | if (!ap->nr_pmp_links) |
| 2567 | ata_eh_freeze_port(ap); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2568 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2569 | ata_port_for_each_link(link, ap) { |
| 2570 | struct ata_eh_context *ehc = &link->eh_context; |
| 2571 | |
| 2572 | if (!(ehc->i.action & ATA_EH_RESET_MASK)) |
| 2573 | continue; |
| 2574 | |
| 2575 | rc = ata_eh_reset(link, ata_link_nr_vacant(link), |
| 2576 | prereset, softreset, hardreset, |
| 2577 | postreset); |
| 2578 | if (rc) { |
| 2579 | ata_link_printk(link, KERN_ERR, |
| 2580 | "reset failed, giving up\n"); |
| 2581 | goto out; |
| 2582 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2583 | } |
| 2584 | |
Tejun Heo | b06ce3e | 2007-10-09 15:06:48 +0900 | [diff] [blame] | 2585 | if (!ap->nr_pmp_links) |
| 2586 | ata_eh_thaw_port(ap); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2587 | } |
| 2588 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2589 | /* the rest */ |
| 2590 | ata_port_for_each_link(link, ap) { |
| 2591 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2592 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2593 | /* revalidate existing devices and attach new ones */ |
| 2594 | rc = ata_eh_revalidate_and_attach(link, &dev); |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2595 | if (rc) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2596 | goto dev_fail; |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2597 | |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 2598 | /* if PMP got attached, return, pmp EH will take care of it */ |
| 2599 | if (link->device->class == ATA_DEV_PMP) { |
| 2600 | ehc->i.action = 0; |
| 2601 | return 0; |
| 2602 | } |
| 2603 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2604 | /* configure transfer mode if necessary */ |
| 2605 | if (ehc->i.flags & ATA_EHI_SETMODE) { |
| 2606 | rc = ata_set_mode(link, &dev); |
| 2607 | if (rc) |
| 2608 | goto dev_fail; |
| 2609 | ehc->i.flags &= ~ATA_EHI_SETMODE; |
| 2610 | } |
| 2611 | |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 2612 | if (ehc->i.action & ATA_EHI_LPM) |
| 2613 | ata_link_for_each_dev(dev, link) |
| 2614 | ata_dev_enable_pm(dev, ap->pm_policy); |
| 2615 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2616 | /* this link is okay now */ |
| 2617 | ehc->i.flags = 0; |
| 2618 | continue; |
| 2619 | |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 2620 | dev_fail: |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2621 | nr_failed_devs++; |
| 2622 | if (ata_eh_handle_dev_fail(dev, rc)) |
| 2623 | nr_disabled_devs++; |
| 2624 | |
Tejun Heo | b06ce3e | 2007-10-09 15:06:48 +0900 | [diff] [blame] | 2625 | if (ap->pflags & ATA_PFLAG_FROZEN) { |
| 2626 | /* PMP reset requires working host port. |
| 2627 | * Can't retry if it's frozen. |
| 2628 | */ |
| 2629 | if (ap->nr_pmp_links) |
| 2630 | goto out; |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2631 | break; |
Tejun Heo | b06ce3e | 2007-10-09 15:06:48 +0900 | [diff] [blame] | 2632 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2633 | } |
| 2634 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2635 | if (nr_failed_devs) { |
| 2636 | if (nr_failed_devs != nr_disabled_devs) { |
| 2637 | ata_port_printk(ap, KERN_WARNING, "failed to recover " |
| 2638 | "some devices, retrying in 5 secs\n"); |
| 2639 | ssleep(5); |
| 2640 | } else { |
| 2641 | /* no device left to recover, repeat fast */ |
| 2642 | msleep(500); |
| 2643 | } |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2644 | |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2645 | goto retry; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2646 | } |
| 2647 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2648 | out: |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2649 | if (rc && r_failed_link) |
| 2650 | *r_failed_link = link; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2651 | |
| 2652 | DPRINTK("EXIT, rc=%d\n", rc); |
| 2653 | return rc; |
| 2654 | } |
| 2655 | |
| 2656 | /** |
| 2657 | * ata_eh_finish - finish up EH |
| 2658 | * @ap: host port to finish EH for |
| 2659 | * |
| 2660 | * Recovery is complete. Clean up EH states and retry or finish |
| 2661 | * failed qcs. |
| 2662 | * |
| 2663 | * LOCKING: |
| 2664 | * None. |
| 2665 | */ |
Tejun Heo | fb7fd61 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 2666 | void ata_eh_finish(struct ata_port *ap) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2667 | { |
| 2668 | int tag; |
| 2669 | |
| 2670 | /* retry or finish qcs */ |
| 2671 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
| 2672 | struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); |
| 2673 | |
| 2674 | if (!(qc->flags & ATA_QCFLAG_FAILED)) |
| 2675 | continue; |
| 2676 | |
| 2677 | if (qc->err_mask) { |
| 2678 | /* FIXME: Once EH migration is complete, |
| 2679 | * generate sense data in this function, |
| 2680 | * considering both err_mask and tf. |
Tejun Heo | f90f082 | 2007-10-26 16:12:41 +0900 | [diff] [blame] | 2681 | * |
| 2682 | * There's no point in retrying invalid |
| 2683 | * (detected by libata) and non-IO device |
| 2684 | * errors (rejected by device). Finish them |
| 2685 | * immediately. |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2686 | */ |
Tejun Heo | f90f082 | 2007-10-26 16:12:41 +0900 | [diff] [blame] | 2687 | if ((qc->err_mask & AC_ERR_INVALID) || |
| 2688 | (!(qc->flags & ATA_QCFLAG_IO) && |
| 2689 | qc->err_mask == AC_ERR_DEV)) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2690 | ata_eh_qc_complete(qc); |
| 2691 | else |
| 2692 | ata_eh_qc_retry(qc); |
| 2693 | } else { |
| 2694 | if (qc->flags & ATA_QCFLAG_SENSE_VALID) { |
| 2695 | ata_eh_qc_complete(qc); |
| 2696 | } else { |
| 2697 | /* feed zero TF to sense generation */ |
| 2698 | memset(&qc->result_tf, 0, sizeof(qc->result_tf)); |
| 2699 | ata_eh_qc_retry(qc); |
| 2700 | } |
| 2701 | } |
| 2702 | } |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 2703 | |
| 2704 | /* make sure nr_active_links is zero after EH */ |
| 2705 | WARN_ON(ap->nr_active_links); |
| 2706 | ap->nr_active_links = 0; |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | /** |
| 2710 | * ata_do_eh - do standard error handling |
| 2711 | * @ap: host port to handle error for |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2712 | * @prereset: prereset method (can be NULL) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2713 | * @softreset: softreset method (can be NULL) |
| 2714 | * @hardreset: hardreset method (can be NULL) |
| 2715 | * @postreset: postreset method (can be NULL) |
| 2716 | * |
| 2717 | * Perform standard error handling sequence. |
| 2718 | * |
| 2719 | * LOCKING: |
| 2720 | * Kernel thread context (may sleep). |
| 2721 | */ |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 2722 | void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset, |
| 2723 | ata_reset_fn_t softreset, ata_reset_fn_t hardreset, |
| 2724 | ata_postreset_fn_t postreset) |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2725 | { |
Tejun Heo | 9b1e265 | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 2726 | struct ata_device *dev; |
| 2727 | int rc; |
| 2728 | |
| 2729 | ata_eh_autopsy(ap); |
| 2730 | ata_eh_report(ap); |
| 2731 | |
| 2732 | rc = ata_eh_recover(ap, prereset, softreset, hardreset, postreset, |
| 2733 | NULL); |
| 2734 | if (rc) { |
| 2735 | ata_link_for_each_dev(dev, &ap->link) |
| 2736 | ata_dev_disable(dev); |
| 2737 | } |
| 2738 | |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 2739 | ata_eh_finish(ap); |
| 2740 | } |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2741 | |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 2742 | #ifdef CONFIG_PM |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2743 | /** |
| 2744 | * ata_eh_handle_port_suspend - perform port suspend operation |
| 2745 | * @ap: port to suspend |
| 2746 | * |
| 2747 | * Suspend @ap. |
| 2748 | * |
| 2749 | * LOCKING: |
| 2750 | * Kernel thread context (may sleep). |
| 2751 | */ |
| 2752 | static void ata_eh_handle_port_suspend(struct ata_port *ap) |
| 2753 | { |
| 2754 | unsigned long flags; |
| 2755 | int rc = 0; |
| 2756 | |
| 2757 | /* are we suspending? */ |
| 2758 | spin_lock_irqsave(ap->lock, flags); |
| 2759 | if (!(ap->pflags & ATA_PFLAG_PM_PENDING) || |
| 2760 | ap->pm_mesg.event == PM_EVENT_ON) { |
| 2761 | spin_unlock_irqrestore(ap->lock, flags); |
| 2762 | return; |
| 2763 | } |
| 2764 | spin_unlock_irqrestore(ap->lock, flags); |
| 2765 | |
| 2766 | WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED); |
| 2767 | |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 2768 | /* tell ACPI we're suspending */ |
| 2769 | rc = ata_acpi_on_suspend(ap); |
| 2770 | if (rc) |
| 2771 | goto out; |
| 2772 | |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2773 | /* suspend */ |
| 2774 | ata_eh_freeze_port(ap); |
| 2775 | |
| 2776 | if (ap->ops->port_suspend) |
| 2777 | rc = ap->ops->port_suspend(ap, ap->pm_mesg); |
| 2778 | |
Shaohua Li | bd3adca | 2007-11-02 09:32:38 +0800 | [diff] [blame] | 2779 | ata_acpi_set_state(ap, PMSG_SUSPEND); |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 2780 | out: |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2781 | /* report result */ |
| 2782 | spin_lock_irqsave(ap->lock, flags); |
| 2783 | |
| 2784 | ap->pflags &= ~ATA_PFLAG_PM_PENDING; |
| 2785 | if (rc == 0) |
| 2786 | ap->pflags |= ATA_PFLAG_SUSPENDED; |
Tejun Heo | 64578a3 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 2787 | else if (ap->pflags & ATA_PFLAG_FROZEN) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2788 | ata_port_schedule_eh(ap); |
| 2789 | |
| 2790 | if (ap->pm_result) { |
| 2791 | *ap->pm_result = rc; |
| 2792 | ap->pm_result = NULL; |
| 2793 | } |
| 2794 | |
| 2795 | spin_unlock_irqrestore(ap->lock, flags); |
| 2796 | |
| 2797 | return; |
| 2798 | } |
| 2799 | |
| 2800 | /** |
| 2801 | * ata_eh_handle_port_resume - perform port resume operation |
| 2802 | * @ap: port to resume |
| 2803 | * |
| 2804 | * Resume @ap. |
| 2805 | * |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2806 | * LOCKING: |
| 2807 | * Kernel thread context (may sleep). |
| 2808 | */ |
| 2809 | static void ata_eh_handle_port_resume(struct ata_port *ap) |
| 2810 | { |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2811 | unsigned long flags; |
Tejun Heo | 9666f40 | 2007-05-04 21:27:47 +0200 | [diff] [blame] | 2812 | int rc = 0; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2813 | |
| 2814 | /* are we resuming? */ |
| 2815 | spin_lock_irqsave(ap->lock, flags); |
| 2816 | if (!(ap->pflags & ATA_PFLAG_PM_PENDING) || |
| 2817 | ap->pm_mesg.event != PM_EVENT_ON) { |
| 2818 | spin_unlock_irqrestore(ap->lock, flags); |
| 2819 | return; |
| 2820 | } |
| 2821 | spin_unlock_irqrestore(ap->lock, flags); |
| 2822 | |
Tejun Heo | 9666f40 | 2007-05-04 21:27:47 +0200 | [diff] [blame] | 2823 | WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED)); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2824 | |
Shaohua Li | bd3adca | 2007-11-02 09:32:38 +0800 | [diff] [blame] | 2825 | ata_acpi_set_state(ap, PMSG_ON); |
| 2826 | |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2827 | if (ap->ops->port_resume) |
| 2828 | rc = ap->ops->port_resume(ap); |
| 2829 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 2830 | /* tell ACPI that we're resuming */ |
| 2831 | ata_acpi_on_resume(ap); |
| 2832 | |
Tejun Heo | 9666f40 | 2007-05-04 21:27:47 +0200 | [diff] [blame] | 2833 | /* report result */ |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 2834 | spin_lock_irqsave(ap->lock, flags); |
| 2835 | ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED); |
| 2836 | if (ap->pm_result) { |
| 2837 | *ap->pm_result = rc; |
| 2838 | ap->pm_result = NULL; |
| 2839 | } |
| 2840 | spin_unlock_irqrestore(ap->lock, flags); |
| 2841 | } |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 2842 | #endif /* CONFIG_PM */ |