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