Lines Matching +full:non +full:- +full:descriptive

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * libata-eh.c - libata error handling
6 * Please ALWAYS copy linux-ide@vger.kernel.org
12 * as Documentation/driver-api/libata.rst
15 * http://www.sata-io.org/
63 /* Waiting in ->prereset can never be reliable. It's
127 * ehc->cmd_timeout_idx keeps track of which timeout to use per
164 ehi->desc_len += vscnprintf(ehi->desc + ehi->desc_len, in __ata_ehi_pushv_desc()
165 ATA_EH_DESC_LEN - ehi->desc_len, in __ata_ehi_pushv_desc()
170 * __ata_ehi_push_desc - push error description without adding separator
174 * Format string according to @fmt and append it to @ehi->desc.
189 * ata_ehi_push_desc - push error description with separator
193 * Format string according to @fmt and append it to @ehi->desc.
194 * If @ehi->desc is not empty, ", " is added in-between.
203 if (ehi->desc_len) in ata_ehi_push_desc()
212 * ata_ehi_clear_desc - clean error description
215 * Clear @ehi->desc.
222 ehi->desc[0] = '\0'; in ata_ehi_clear_desc()
223 ehi->desc_len = 0; in ata_ehi_clear_desc()
227 * ata_port_desc - append port description
233 * in-between. This function is to be used while initializing
243 WARN_ON(!(ap->pflags & ATA_PFLAG_INITIALIZING)); in ata_port_desc()
245 if (ap->link.eh_info.desc_len) in ata_port_desc()
246 __ata_ehi_push_desc(&ap->link.eh_info, " "); in ata_port_desc()
249 __ata_ehi_pushv_desc(&ap->link.eh_info, fmt, args); in ata_port_desc()
256 * ata_port_pbar_desc - append PCI BAR description
273 struct pci_dev *pdev = to_pci_dev(ap->host->dev); in ata_port_pbar_desc()
306 return -1; in ata_lookup_timeout_table()
310 * ata_internal_cmd_timeout - determine timeout for an internal command
324 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_internal_cmd_timeout()
331 idx = ehc->cmd_timeout_idx[dev->devno][ent]; in ata_internal_cmd_timeout()
336 * ata_internal_cmd_timed_out - notification for internal command timeout
349 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_internal_cmd_timed_out()
356 idx = ehc->cmd_timeout_idx[dev->devno][ent]; in ata_internal_cmd_timed_out()
358 ehc->cmd_timeout_idx[dev->devno][ent]++; in ata_internal_cmd_timed_out()
368 ering->cursor++; in ata_ering_record()
369 ering->cursor %= ATA_ERING_SIZE; in ata_ering_record()
371 ent = &ering->ring[ering->cursor]; in ata_ering_record()
372 ent->eflags = eflags; in ata_ering_record()
373 ent->err_mask = err_mask; in ata_ering_record()
374 ent->timestamp = get_jiffies_64(); in ata_ering_record()
379 struct ata_ering_entry *ent = &ering->ring[ering->cursor]; in ata_ering_top()
381 if (ent->err_mask) in ata_ering_top()
393 idx = ering->cursor; in ata_ering_map()
395 ent = &ering->ring[idx]; in ata_ering_map()
396 if (!ent->err_mask) in ata_ering_map()
401 idx = (idx - 1 + ATA_ERING_SIZE) % ATA_ERING_SIZE; in ata_ering_map()
402 } while (idx != ering->cursor); in ata_ering_map()
409 ent->eflags |= ATA_EFLAG_OLD_ER; in ata_ering_clear_cb()
420 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_dev_action()
422 return ehc->i.action | ehc->i.dev_action[dev->devno]; in ata_eh_dev_action()
431 ehi->action &= ~action; in ata_eh_clear_action()
433 ehi->dev_action[tdev->devno] &= ~action; in ata_eh_clear_action()
435 /* doesn't make sense for port-wide EH actions */ in ata_eh_clear_action()
438 /* break ehi->action into ehi->dev_action */ in ata_eh_clear_action()
439 if (ehi->action & action) { in ata_eh_clear_action()
441 ehi->dev_action[tdev->devno] |= in ata_eh_clear_action()
442 ehi->action & action; in ata_eh_clear_action()
443 ehi->action &= ~action; in ata_eh_clear_action()
446 /* turn off the specified per-dev action */ in ata_eh_clear_action()
447 ehi->dev_action[dev->devno] &= ~action; in ata_eh_clear_action()
452 * ata_eh_acquire - acquire EH ownership
464 mutex_lock(&ap->host->eh_mutex); in ata_eh_acquire()
465 WARN_ON_ONCE(ap->host->eh_owner); in ata_eh_acquire()
466 ap->host->eh_owner = current; in ata_eh_acquire()
470 * ata_eh_release - release EH ownership
481 WARN_ON_ONCE(ap->host->eh_owner != current); in ata_eh_release()
482 ap->host->eh_owner = NULL; in ata_eh_release()
483 mutex_unlock(&ap->host->eh_mutex); in ata_eh_release()
496 sata_scr_write(link, SCR_CONTROL, link->saved_scontrol & 0xff0); in ata_eh_unload()
502 spin_lock_irqsave(ap->lock, flags); in ata_eh_unload()
505 ap->pflags &= ~ATA_PFLAG_EH_PENDING; /* clear pending from freeze */ in ata_eh_unload()
506 ap->pflags |= ATA_PFLAG_UNLOADED; in ata_eh_unload()
508 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_unload()
512 * ata_scsi_error - SCSI layer error handler callback
515 * Handles SCSI-layer-thrown error events.
531 spin_lock_irqsave(host->host_lock, flags); in ata_scsi_error()
532 list_splice_init(&host->eh_cmd_q, &eh_work_q); in ata_scsi_error()
533 spin_unlock_irqrestore(host->host_lock, flags); in ata_scsi_error()
548 * ata_scsi_cmd_error_handler - error callback for a list of commands
554 * ap->eh_done_q. This function is the first part of the libata error
568 /* For new EH, all qcs are finished in one of three ways - in ata_scsi_cmd_error_handler()
580 spin_lock_irqsave(ap->lock, flags); in ata_scsi_cmd_error_handler()
581 if (ap->ops->error_handler) { in ata_scsi_cmd_error_handler()
585 /* This must occur under the ap->lock as we don't want in ata_scsi_cmd_error_handler()
589 non-notified command and completes much like an IRQ handler. in ata_scsi_cmd_error_handler()
594 if (ap->ops->lost_interrupt) in ata_scsi_cmd_error_handler()
595 ap->ops->lost_interrupt(ap); in ata_scsi_cmd_error_handler()
601 if (qc->flags & ATA_QCFLAG_ACTIVE && in ata_scsi_cmd_error_handler()
602 qc->scsicmd == scmd) in ata_scsi_cmd_error_handler()
608 if (!(qc->flags & ATA_QCFLAG_FAILED)) { in ata_scsi_cmd_error_handler()
610 qc->err_mask |= AC_ERR_TIMEOUT; in ata_scsi_cmd_error_handler()
611 qc->flags |= ATA_QCFLAG_FAILED; in ata_scsi_cmd_error_handler()
619 scmd->retries = scmd->allowed; in ata_scsi_cmd_error_handler()
620 scsi_eh_finish_cmd(scmd, &ap->eh_done_q); in ata_scsi_cmd_error_handler()
635 ap->eh_tries = ATA_EH_MAX_TRIES; in ata_scsi_cmd_error_handler()
637 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_cmd_error_handler()
643 * ata_scsi_port_error_handler - recover the port after the commands
655 if (ap->ops->error_handler) { in ata_scsi_port_error_handler()
662 del_timer_sync(&ap->fastdrain_timer); in ata_scsi_port_error_handler()
668 spin_lock_irqsave(ap->lock, flags); in ata_scsi_port_error_handler()
671 struct ata_eh_context *ehc = &link->eh_context; in ata_scsi_port_error_handler()
674 memset(&link->eh_context, 0, sizeof(link->eh_context)); in ata_scsi_port_error_handler()
675 link->eh_context.i = link->eh_info; in ata_scsi_port_error_handler()
676 memset(&link->eh_info, 0, sizeof(link->eh_info)); in ata_scsi_port_error_handler()
679 int devno = dev->devno; in ata_scsi_port_error_handler()
681 ehc->saved_xfer_mode[devno] = dev->xfer_mode; in ata_scsi_port_error_handler()
683 ehc->saved_ncq_enabled |= 1 << devno; in ata_scsi_port_error_handler()
687 ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS; in ata_scsi_port_error_handler()
688 ap->pflags &= ~ATA_PFLAG_EH_PENDING; in ata_scsi_port_error_handler()
689 ap->excl_link = NULL; /* don't maintain exclusion over EH */ in ata_scsi_port_error_handler()
691 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
694 if (!(ap->pflags & (ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED))) in ata_scsi_port_error_handler()
695 ap->ops->error_handler(ap); in ata_scsi_port_error_handler()
698 if ((ap->pflags & ATA_PFLAG_UNLOADING) && in ata_scsi_port_error_handler()
699 !(ap->pflags & ATA_PFLAG_UNLOADED)) in ata_scsi_port_error_handler()
707 /* Exception might have happened after ->error_handler in ata_scsi_port_error_handler()
711 spin_lock_irqsave(ap->lock, flags); in ata_scsi_port_error_handler()
713 if (ap->pflags & ATA_PFLAG_EH_PENDING) { in ata_scsi_port_error_handler()
714 if (--ap->eh_tries) { in ata_scsi_port_error_handler()
715 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
721 ap->pflags &= ~ATA_PFLAG_EH_PENDING; in ata_scsi_port_error_handler()
726 memset(&link->eh_info, 0, sizeof(link->eh_info)); in ata_scsi_port_error_handler()
729 * ap->lock such that if exception occurs after this in ata_scsi_port_error_handler()
731 * re-initiate EH. in ata_scsi_port_error_handler()
733 ap->ops->end_eh(ap); in ata_scsi_port_error_handler()
735 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
738 WARN_ON(ata_qc_from_tag(ap, ap->link.active_tag) == NULL); in ata_scsi_port_error_handler()
739 ap->ops->eng_timeout(ap); in ata_scsi_port_error_handler()
742 scsi_eh_flush_done_q(&ap->eh_done_q); in ata_scsi_port_error_handler()
745 spin_lock_irqsave(ap->lock, flags); in ata_scsi_port_error_handler()
747 if (ap->pflags & ATA_PFLAG_LOADING) in ata_scsi_port_error_handler()
748 ap->pflags &= ~ATA_PFLAG_LOADING; in ata_scsi_port_error_handler()
749 else if ((ap->pflags & ATA_PFLAG_SCSI_HOTPLUG) && in ata_scsi_port_error_handler()
750 !(ap->flags & ATA_FLAG_SAS_HOST)) in ata_scsi_port_error_handler()
751 schedule_delayed_work(&ap->hotplug_task, 0); in ata_scsi_port_error_handler()
753 if (ap->pflags & ATA_PFLAG_RECOVERED) in ata_scsi_port_error_handler()
756 ap->pflags &= ~(ATA_PFLAG_SCSI_HOTPLUG | ATA_PFLAG_RECOVERED); in ata_scsi_port_error_handler()
759 ap->pflags &= ~ATA_PFLAG_EH_IN_PROGRESS; in ata_scsi_port_error_handler()
760 wake_up_all(&ap->eh_wait_q); in ata_scsi_port_error_handler()
762 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
767 * ata_port_wait_eh - Wait for the currently pending EH to complete
781 spin_lock_irqsave(ap->lock, flags); in ata_port_wait_eh()
783 while (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) { in ata_port_wait_eh()
784 prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE); in ata_port_wait_eh()
785 spin_unlock_irqrestore(ap->lock, flags); in ata_port_wait_eh()
787 spin_lock_irqsave(ap->lock, flags); in ata_port_wait_eh()
789 finish_wait(&ap->eh_wait_q, &wait); in ata_port_wait_eh()
791 spin_unlock_irqrestore(ap->lock, flags); in ata_port_wait_eh()
794 if (scsi_host_in_recovery(ap->scsi_host)) { in ata_port_wait_eh()
807 /* count only non-internal commands */ in ata_eh_nr_in_flight()
822 spin_lock_irqsave(ap->lock, flags); in ata_eh_fastdrain_timerfn()
830 if (cnt == ap->fastdrain_cnt) { in ata_eh_fastdrain_timerfn()
835 * in-flight qcs as timed out and freeze the port. in ata_eh_fastdrain_timerfn()
839 qc->err_mask |= AC_ERR_TIMEOUT; in ata_eh_fastdrain_timerfn()
845 ap->fastdrain_cnt = cnt; in ata_eh_fastdrain_timerfn()
846 ap->fastdrain_timer.expires = in ata_eh_fastdrain_timerfn()
848 add_timer(&ap->fastdrain_timer); in ata_eh_fastdrain_timerfn()
852 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_fastdrain_timerfn()
856 * ata_eh_set_pending - set ATA_PFLAG_EH_PENDING and activate fast drain
861 * is non-zero and EH wasn't pending before. Fast drain ensures
872 if (ap->pflags & ATA_PFLAG_EH_PENDING) in ata_eh_set_pending()
875 ap->pflags |= ATA_PFLAG_EH_PENDING; in ata_eh_set_pending()
880 /* do we have in-flight qcs? */ in ata_eh_set_pending()
886 ap->fastdrain_cnt = cnt; in ata_eh_set_pending()
887 ap->fastdrain_timer.expires = in ata_eh_set_pending()
889 add_timer(&ap->fastdrain_timer); in ata_eh_set_pending()
893 * ata_qc_schedule_eh - schedule qc for error handling
904 struct ata_port *ap = qc->ap; in ata_qc_schedule_eh()
906 WARN_ON(!ap->ops->error_handler); in ata_qc_schedule_eh()
908 qc->flags |= ATA_QCFLAG_FAILED; in ata_qc_schedule_eh()
916 blk_abort_request(qc->scsicmd->request); in ata_qc_schedule_eh()
920 * ata_std_sched_eh - non-libsas ata_ports issue eh with this common routine
928 WARN_ON(!ap->ops->error_handler); in ata_std_sched_eh()
930 if (ap->pflags & ATA_PFLAG_INITIALIZING) in ata_std_sched_eh()
934 scsi_schedule_eh(ap->scsi_host); in ata_std_sched_eh()
941 * ata_std_end_eh - non-libsas ata_ports complete eh with this common routine
945 * shost, so host fields can be directly manipulated under ap->lock, in
946 * the libsas case we need to hold a lock at the ha->level to coordinate
954 struct Scsi_Host *host = ap->scsi_host; in ata_std_end_eh()
956 host->host_eh_scheduled = 0; in ata_std_end_eh()
962 * ata_port_schedule_eh - schedule error handling without a qc
974 ap->ops->sched_eh(ap); in ata_port_schedule_eh()
982 WARN_ON(!ap->ops->error_handler); in ata_do_link_abort()
989 if (qc && (!link || qc->dev->link == link)) { in ata_do_link_abort()
990 qc->flags |= ATA_QCFLAG_FAILED; in ata_do_link_abort()
1003 * ata_link_abort - abort all qc's on the link
1016 return ata_do_link_abort(link->ap, link); in ata_link_abort()
1020 * ata_port_abort - abort all qc's on the port
1037 * __ata_port_freeze - freeze port
1045 * ap->ops->freeze() callback can be used for freezing the port
1046 * hardware-wise (e.g. mask interrupt and stop DMA engine). If a
1047 * port cannot be frozen hardware-wise, the interrupt handler
1056 WARN_ON(!ap->ops->error_handler); in __ata_port_freeze()
1058 if (ap->ops->freeze) in __ata_port_freeze()
1059 ap->ops->freeze(ap); in __ata_port_freeze()
1061 ap->pflags |= ATA_PFLAG_FROZEN; in __ata_port_freeze()
1063 DPRINTK("ata%u port frozen\n", ap->print_id); in __ata_port_freeze()
1067 * ata_port_freeze - abort & freeze port
1084 WARN_ON(!ap->ops->error_handler); in ata_port_freeze()
1093 * sata_async_notification - SATA async notification handler
1110 if (!(ap->flags & ATA_FLAG_AN)) in sata_async_notification()
1113 rc = sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf); in sata_async_notification()
1115 sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf); in sata_async_notification()
1124 struct ata_device *dev = ap->link.device; in sata_async_notification()
1126 if ((dev->class == ATA_DEV_ATAPI) && in sata_async_notification()
1127 (dev->flags & ATA_DFLAG_AN)) in sata_async_notification()
1145 if (!(sntf & (1 << link->pmp))) in sata_async_notification()
1148 if ((link->device->class == ATA_DEV_ATAPI) && in sata_async_notification()
1149 (link->device->flags & ATA_DFLAG_AN)) in sata_async_notification()
1150 ata_scsi_media_change_notify(link->device); in sata_async_notification()
1166 * ata_eh_freeze_port - EH helper to freeze port
1178 if (!ap->ops->error_handler) in ata_eh_freeze_port()
1181 spin_lock_irqsave(ap->lock, flags); in ata_eh_freeze_port()
1183 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_freeze_port()
1187 * ata_port_thaw_port - EH helper to thaw port
1199 if (!ap->ops->error_handler) in ata_eh_thaw_port()
1202 spin_lock_irqsave(ap->lock, flags); in ata_eh_thaw_port()
1204 ap->pflags &= ~ATA_PFLAG_FROZEN; in ata_eh_thaw_port()
1206 if (ap->ops->thaw) in ata_eh_thaw_port()
1207 ap->ops->thaw(ap); in ata_eh_thaw_port()
1209 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_thaw_port()
1211 DPRINTK("ata%u port thawed\n", ap->print_id); in ata_eh_thaw_port()
1221 struct ata_port *ap = qc->ap; in __ata_eh_qc_complete()
1222 struct scsi_cmnd *scmd = qc->scsicmd; in __ata_eh_qc_complete()
1225 spin_lock_irqsave(ap->lock, flags); in __ata_eh_qc_complete()
1226 qc->scsidone = ata_eh_scsidone; in __ata_eh_qc_complete()
1228 WARN_ON(ata_tag_valid(qc->tag)); in __ata_eh_qc_complete()
1229 spin_unlock_irqrestore(ap->lock, flags); in __ata_eh_qc_complete()
1231 scsi_eh_finish_cmd(scmd, &ap->eh_done_q); in __ata_eh_qc_complete()
1235 * ata_eh_qc_complete - Complete an active ATA command from EH
1243 struct scsi_cmnd *scmd = qc->scsicmd; in ata_eh_qc_complete()
1244 scmd->retries = scmd->allowed; in ata_eh_qc_complete()
1249 * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
1255 * SCSI midlayer limits the number of retries to scmd->allowed.
1256 * scmd->allowed is incremented for commands which get retried
1257 * due to unrelated failures (qc->err_mask is zero).
1261 struct scsi_cmnd *scmd = qc->scsicmd; in ata_eh_qc_retry()
1262 if (!qc->err_mask) in ata_eh_qc_retry()
1263 scmd->allowed++; in ata_eh_qc_retry()
1268 * ata_dev_disable - disable ATA device
1281 if (ata_msg_drv(dev->link->ap)) in ata_dev_disable()
1285 dev->class++; in ata_dev_disable()
1290 ata_ering_clear(&dev->ering); in ata_dev_disable()
1294 * ata_eh_detach_dev - detach ATA device
1304 struct ata_link *link = dev->link; in ata_eh_detach_dev()
1305 struct ata_port *ap = link->ap; in ata_eh_detach_dev()
1306 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_detach_dev()
1311 spin_lock_irqsave(ap->lock, flags); in ata_eh_detach_dev()
1313 dev->flags &= ~ATA_DFLAG_DETACH; in ata_eh_detach_dev()
1316 dev->flags |= ATA_DFLAG_DETACHED; in ata_eh_detach_dev()
1317 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG; in ata_eh_detach_dev()
1320 /* clear per-dev EH info */ in ata_eh_detach_dev()
1321 ata_eh_clear_action(link, dev, &link->eh_info, ATA_EH_PERDEV_MASK); in ata_eh_detach_dev()
1322 ata_eh_clear_action(link, dev, &link->eh_context.i, ATA_EH_PERDEV_MASK); in ata_eh_detach_dev()
1323 ehc->saved_xfer_mode[dev->devno] = 0; in ata_eh_detach_dev()
1324 ehc->saved_ncq_enabled &= ~(1 << dev->devno); in ata_eh_detach_dev()
1326 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_detach_dev()
1330 * ata_eh_about_to_do - about to perform eh_action
1332 * @dev: target ATA dev for per-dev action (can be NULL)
1336 * in @link->eh_info such that eh actions are not unnecessarily
1345 struct ata_port *ap = link->ap; in ata_eh_about_to_do()
1346 struct ata_eh_info *ehi = &link->eh_info; in ata_eh_about_to_do()
1347 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_about_to_do()
1350 spin_lock_irqsave(ap->lock, flags); in ata_eh_about_to_do()
1357 if (!(ehc->i.flags & ATA_EHI_QUIET) && link != ap->slave_link) in ata_eh_about_to_do()
1358 ap->pflags |= ATA_PFLAG_RECOVERED; in ata_eh_about_to_do()
1360 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_about_to_do()
1364 * ata_eh_done - EH action complete
1366 * @dev: target ATA dev for per-dev action (can be NULL)
1370 * in @link->eh_context.
1378 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_done()
1380 ata_eh_clear_action(link, dev, &ehc->i, action); in ata_eh_done()
1384 * ata_err_string - convert err_mask to descriptive string
1387 * Convert @err_mask to descriptive string. Errors are
1395 * Descriptive string for @err_mask
1423 * ata_eh_read_log_10h - Read log page 10h for NCQ error details
1435 * 0 on success, -errno otherwise.
1440 u8 *buf = dev->link->ap->sector_buf; in ata_eh_read_log_10h()
1447 return -EIO; in ata_eh_read_log_10h()
1457 return -ENOENT; in ata_eh_read_log_10h()
1461 tf->command = buf[2]; in ata_eh_read_log_10h()
1462 tf->feature = buf[3]; in ata_eh_read_log_10h()
1463 tf->lbal = buf[4]; in ata_eh_read_log_10h()
1464 tf->lbam = buf[5]; in ata_eh_read_log_10h()
1465 tf->lbah = buf[6]; in ata_eh_read_log_10h()
1466 tf->device = buf[7]; in ata_eh_read_log_10h()
1467 tf->hob_lbal = buf[8]; in ata_eh_read_log_10h()
1468 tf->hob_lbam = buf[9]; in ata_eh_read_log_10h()
1469 tf->hob_lbah = buf[10]; in ata_eh_read_log_10h()
1470 tf->nsect = buf[12]; in ata_eh_read_log_10h()
1471 tf->hob_nsect = buf[13]; in ata_eh_read_log_10h()
1472 if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id)) in ata_eh_read_log_10h()
1473 tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16]; in ata_eh_read_log_10h()
1479 * atapi_eh_tur - perform ATAPI TEST_UNIT_READY
1510 * ata_eh_request_sense - perform REQUEST_SENSE_DATA_EXT
1523 struct ata_device *dev = qc->dev; in ata_eh_request_sense()
1527 if (qc->ap->pflags & ATA_PFLAG_FROZEN) { in ata_eh_request_sense()
1532 if (!cmd || qc->flags & ATA_QCFLAG_SENSE_VALID) in ata_eh_request_sense()
1535 if (!ata_id_sense_reporting_enabled(dev->id)) { in ata_eh_request_sense()
1536 ata_dev_warn(qc->dev, "sense data reporting disabled\n"); in ata_eh_request_sense()
1552 qc->flags |= ATA_QCFLAG_SENSE_VALID; in ata_eh_request_sense()
1560 * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE
1579 struct ata_port *ap = dev->link->ap; in atapi_eh_request_sense()
1587 * for the case where they are -not- overwritten in atapi_eh_request_sense()
1599 if (ap->flags & ATA_FLAG_PIO_DMA) { in atapi_eh_request_sense()
1613 * ata_eh_analyze_serror - analyze SError for a failed port
1624 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_analyze_serror()
1625 u32 serror = ehc->i.serror; in ata_eh_analyze_serror()
1647 if (link->lpm_policy > ATA_LPM_MAX_POWER) in ata_eh_analyze_serror()
1649 else if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link)) in ata_eh_analyze_serror()
1655 ata_ehi_hotplugged(&ehc->i); in ata_eh_analyze_serror()
1657 ehc->i.err_mask |= err_mask; in ata_eh_analyze_serror()
1658 ehc->i.action |= action; in ata_eh_analyze_serror()
1662 * ata_eh_analyze_ncq_error - analyze NCQ error
1667 * is setting AC_ERR_DEV in ehi->err_mask. This function takes
1675 struct ata_port *ap = link->ap; in ata_eh_analyze_ncq_error()
1676 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_analyze_ncq_error()
1677 struct ata_device *dev = link->device; in ata_eh_analyze_ncq_error()
1683 if (ap->pflags & ATA_PFLAG_FROZEN) in ata_eh_analyze_ncq_error()
1687 if (!link->sactive || !(ehc->i.err_mask & AC_ERR_DEV)) in ata_eh_analyze_ncq_error()
1692 if (!(qc->flags & ATA_QCFLAG_FAILED)) in ata_eh_analyze_ncq_error()
1695 if (qc->err_mask) in ata_eh_analyze_ncq_error()
1708 if (!(link->sactive & (1 << tag))) { in ata_eh_analyze_ncq_error()
1716 memcpy(&qc->result_tf, &tf, sizeof(tf)); in ata_eh_analyze_ncq_error()
1717 qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48; in ata_eh_analyze_ncq_error()
1718 qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ; in ata_eh_analyze_ncq_error()
1719 if (dev->class == ATA_DEV_ZAC && in ata_eh_analyze_ncq_error()
1720 ((qc->result_tf.command & ATA_SENSE) || qc->result_tf.auxiliary)) { in ata_eh_analyze_ncq_error()
1723 sense_key = (qc->result_tf.auxiliary >> 16) & 0xff; in ata_eh_analyze_ncq_error()
1724 asc = (qc->result_tf.auxiliary >> 8) & 0xff; in ata_eh_analyze_ncq_error()
1725 ascq = qc->result_tf.auxiliary & 0xff; in ata_eh_analyze_ncq_error()
1726 ata_scsi_set_sense(dev, qc->scsicmd, sense_key, asc, ascq); in ata_eh_analyze_ncq_error()
1727 ata_scsi_set_sense_information(dev, qc->scsicmd, in ata_eh_analyze_ncq_error()
1728 &qc->result_tf); in ata_eh_analyze_ncq_error()
1729 qc->flags |= ATA_QCFLAG_SENSE_VALID; in ata_eh_analyze_ncq_error()
1732 ehc->i.err_mask &= ~AC_ERR_DEV; in ata_eh_analyze_ncq_error()
1736 * ata_eh_analyze_tf - analyze taskfile of a failed qc
1754 u8 stat = tf->command, err = tf->feature; in ata_eh_analyze_tf()
1757 qc->err_mask |= AC_ERR_HSM; in ata_eh_analyze_tf()
1762 qc->err_mask |= AC_ERR_DEV; in ata_eh_analyze_tf()
1773 switch (qc->dev->class) { in ata_eh_analyze_tf()
1776 ata_eh_request_sense(qc, qc->scsicmd); in ata_eh_analyze_tf()
1780 qc->err_mask |= AC_ERR_ATA_BUS; in ata_eh_analyze_tf()
1782 qc->err_mask |= AC_ERR_MEDIA; in ata_eh_analyze_tf()
1784 qc->err_mask |= AC_ERR_INVALID; in ata_eh_analyze_tf()
1788 if (!(qc->ap->pflags & ATA_PFLAG_FROZEN)) { in ata_eh_analyze_tf()
1789 tmp = atapi_eh_request_sense(qc->dev, in ata_eh_analyze_tf()
1790 qc->scsicmd->sense_buffer, in ata_eh_analyze_tf()
1791 qc->result_tf.feature >> 4); in ata_eh_analyze_tf()
1793 qc->flags |= ATA_QCFLAG_SENSE_VALID; in ata_eh_analyze_tf()
1795 qc->err_mask |= tmp; in ata_eh_analyze_tf()
1799 if (qc->flags & ATA_QCFLAG_SENSE_VALID) { in ata_eh_analyze_tf()
1800 int ret = scsi_check_sense(qc->scsicmd); in ata_eh_analyze_tf()
1811 qc->flags |= ATA_QCFLAG_RETRY; in ata_eh_analyze_tf()
1812 qc->err_mask |= AC_ERR_OTHER; in ata_eh_analyze_tf()
1814 qc->err_mask |= AC_ERR_HSM; in ata_eh_analyze_tf()
1817 if (qc->err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT | AC_ERR_ATA_BUS)) in ata_eh_analyze_tf()
1862 if ((ent->eflags & ATA_EFLAG_OLD_ER) || (ent->timestamp < arg->since)) in speed_down_verdict_cb()
1863 return -1; in speed_down_verdict_cb()
1865 cat = ata_eh_categorize_error(ent->eflags, ent->err_mask, in speed_down_verdict_cb()
1866 &arg->xfer_ok); in speed_down_verdict_cb()
1867 arg->nr_errors[cat]++; in speed_down_verdict_cb()
1873 * ata_eh_speed_down_verdict - Determine speed down verdict
1900 * taken per error. An action triggered by non-DUBIOUS errors
1938 arg.since = j64 - min(j64, j5mins); in ata_eh_speed_down_verdict()
1939 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); in ata_eh_speed_down_verdict()
1957 arg.since = j64 - min(j64, j10mins); in ata_eh_speed_down_verdict()
1958 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); in ata_eh_speed_down_verdict()
1973 * ata_eh_speed_down - record error and speed down if necessary
1997 /* don't bother if Cat-0 error */ in ata_eh_speed_down()
2002 ata_ering_record(&dev->ering, eflags, err_mask); in ata_eh_speed_down()
2007 (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ | in ata_eh_speed_down()
2009 dev->flags |= ATA_DFLAG_NCQ_OFF; in ata_eh_speed_down()
2023 if (dev->spdn_cnt < 2) { in ata_eh_speed_down()
2030 if (dev->xfer_shift != ATA_SHIFT_PIO) in ata_eh_speed_down()
2031 sel = dma_dnxfer_sel[dev->spdn_cnt]; in ata_eh_speed_down()
2033 sel = pio_dnxfer_sel[dev->spdn_cnt]; in ata_eh_speed_down()
2035 dev->spdn_cnt++; in ata_eh_speed_down()
2047 if ((verdict & ATA_EH_SPDN_FALLBACK_TO_PIO) && (dev->spdn_cnt >= 2) && in ata_eh_speed_down()
2048 (link->ap->cbl != ATA_CBL_SATA || dev->class == ATA_DEV_ATAPI) && in ata_eh_speed_down()
2049 (dev->xfer_shift != ATA_SHIFT_PIO)) { in ata_eh_speed_down()
2051 dev->spdn_cnt = 0; in ata_eh_speed_down()
2061 ata_ering_clear(&dev->ering); in ata_eh_speed_down()
2066 * ata_eh_worth_retry - analyze error and decide whether to retry
2071 * because the drive itself has probably already taken 10-30 seconds
2076 if (qc->err_mask & AC_ERR_MEDIA) in ata_eh_worth_retry()
2078 if (qc->flags & ATA_QCFLAG_IO) in ata_eh_worth_retry()
2080 if (qc->err_mask & AC_ERR_INVALID) in ata_eh_worth_retry()
2082 return qc->err_mask != AC_ERR_DEV; /* retry if not dev error */ in ata_eh_worth_retry()
2086 * ata_eh_quiet - check if we need to be quiet about a command error
2094 if (qc->scsicmd && in ata_eh_quiet()
2095 qc->scsicmd->request->rq_flags & RQF_QUIET) in ata_eh_quiet()
2096 qc->flags |= ATA_QCFLAG_QUIET; in ata_eh_quiet()
2097 return qc->flags & ATA_QCFLAG_QUIET; in ata_eh_quiet()
2101 * ata_eh_link_autopsy - analyze error and determine recovery action
2113 struct ata_port *ap = link->ap; in ata_eh_link_autopsy()
2114 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_link_autopsy()
2124 if (ehc->i.flags & ATA_EHI_NO_AUTOPSY) in ata_eh_link_autopsy()
2130 ehc->i.serror |= serror; in ata_eh_link_autopsy()
2132 } else if (rc != -EOPNOTSUPP) { in ata_eh_link_autopsy()
2134 ehc->i.probe_mask |= ATA_ALL_DEVICES; in ata_eh_link_autopsy()
2135 ehc->i.action |= ATA_EH_RESET; in ata_eh_link_autopsy()
2136 ehc->i.err_mask |= AC_ERR_OTHER; in ata_eh_link_autopsy()
2143 if (ehc->i.err_mask & ~AC_ERR_OTHER) in ata_eh_link_autopsy()
2144 ehc->i.err_mask &= ~AC_ERR_OTHER; in ata_eh_link_autopsy()
2146 all_err_mask |= ehc->i.err_mask; in ata_eh_link_autopsy()
2149 if (!(qc->flags & ATA_QCFLAG_FAILED) || in ata_eh_link_autopsy()
2150 ata_dev_phys_link(qc->dev) != link) in ata_eh_link_autopsy()
2154 qc->err_mask |= ehc->i.err_mask; in ata_eh_link_autopsy()
2157 ehc->i.action |= ata_eh_analyze_tf(qc, &qc->result_tf); in ata_eh_link_autopsy()
2160 if (qc->err_mask & AC_ERR_ATA_BUS) in ata_eh_link_autopsy()
2161 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_MEDIA | in ata_eh_link_autopsy()
2165 if (qc->err_mask & ~AC_ERR_OTHER) in ata_eh_link_autopsy()
2166 qc->err_mask &= ~AC_ERR_OTHER; in ata_eh_link_autopsy()
2175 if (qc->flags & ATA_QCFLAG_SENSE_VALID) in ata_eh_link_autopsy()
2176 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER); in ata_eh_link_autopsy()
2178 qc->flags |= ATA_QCFLAG_RETRY; in ata_eh_link_autopsy()
2181 ehc->i.dev = qc->dev; in ata_eh_link_autopsy()
2182 all_err_mask |= qc->err_mask; in ata_eh_link_autopsy()
2183 if (qc->flags & ATA_QCFLAG_IO) in ata_eh_link_autopsy()
2195 ehc->i.flags |= ATA_EHI_QUIET; in ata_eh_link_autopsy()
2198 if (ap->pflags & ATA_PFLAG_FROZEN || in ata_eh_link_autopsy()
2200 ehc->i.action |= ATA_EH_RESET; in ata_eh_link_autopsy()
2203 ehc->i.action |= ATA_EH_REVALIDATE; in ata_eh_link_autopsy()
2206 * perform per-dev EH action only on the offending device. in ata_eh_link_autopsy()
2208 if (ehc->i.dev) { in ata_eh_link_autopsy()
2209 ehc->i.dev_action[ehc->i.dev->devno] |= in ata_eh_link_autopsy()
2210 ehc->i.action & ATA_EH_PERDEV_MASK; in ata_eh_link_autopsy()
2211 ehc->i.action &= ~ATA_EH_PERDEV_MASK; in ata_eh_link_autopsy()
2216 ap->link.eh_context.i.err_mask |= AC_ERR_TIMEOUT; in ata_eh_link_autopsy()
2219 dev = ehc->i.dev; in ata_eh_link_autopsy()
2221 ata_dev_enabled(link->device)))) in ata_eh_link_autopsy()
2222 dev = link->device; in ata_eh_link_autopsy()
2225 if (dev->flags & ATA_DFLAG_DUBIOUS_XFER) in ata_eh_link_autopsy()
2227 ehc->i.action |= ata_eh_speed_down(dev, eflags, all_err_mask); in ata_eh_link_autopsy()
2228 trace_ata_eh_link_autopsy(dev, ehc->i.action, all_err_mask); in ata_eh_link_autopsy()
2234 * ata_eh_autopsy - analyze error and determine recovery action
2254 if (ap->slave_link) { in ata_eh_autopsy()
2255 struct ata_eh_context *mehc = &ap->link.eh_context; in ata_eh_autopsy()
2256 struct ata_eh_context *sehc = &ap->slave_link->eh_context; in ata_eh_autopsy()
2259 sehc->i.flags |= mehc->i.flags & ATA_EHI_TO_SLAVE_MASK; in ata_eh_autopsy()
2262 ata_eh_link_autopsy(ap->slave_link); in ata_eh_autopsy()
2265 ata_eh_about_to_do(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS); in ata_eh_autopsy()
2266 mehc->i.action |= sehc->i.action; in ata_eh_autopsy()
2267 mehc->i.dev_action[1] |= sehc->i.dev_action[1]; in ata_eh_autopsy()
2268 mehc->i.flags |= sehc->i.flags; in ata_eh_autopsy()
2269 ata_eh_done(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS); in ata_eh_autopsy()
2276 ata_eh_link_autopsy(&ap->link); in ata_eh_autopsy()
2280 * ata_get_cmd_descript - get description for ATA command
2352 { ATA_CMD_TRUSTED_NONDATA, "TRUSTED NON-DATA" }, in ata_get_cmd_descript()
2402 * ata_eh_link_report - report error handling to user
2412 struct ata_port *ap = link->ap; in ata_eh_link_report()
2413 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_link_report()
2419 if (ehc->i.flags & ATA_EHI_QUIET) in ata_eh_link_report()
2423 if (ehc->i.desc[0] != '\0') in ata_eh_link_report()
2424 desc = ehc->i.desc; in ata_eh_link_report()
2427 if (!(qc->flags & ATA_QCFLAG_FAILED) || in ata_eh_link_report()
2428 ata_dev_phys_link(qc->dev) != link || in ata_eh_link_report()
2429 ((qc->flags & ATA_QCFLAG_QUIET) && in ata_eh_link_report()
2430 qc->err_mask == AC_ERR_DEV)) in ata_eh_link_report()
2432 if (qc->flags & ATA_QCFLAG_SENSE_VALID && !qc->err_mask) in ata_eh_link_report()
2438 if (!nr_failed && !ehc->i.err_mask) in ata_eh_link_report()
2442 if (ap->pflags & ATA_PFLAG_FROZEN) in ata_eh_link_report()
2445 if (ap->eh_tries < ATA_EH_MAX_TRIES) in ata_eh_link_report()
2447 ap->eh_tries); in ata_eh_link_report()
2449 if (ehc->i.dev) { in ata_eh_link_report()
2450 ata_dev_err(ehc->i.dev, "exception Emask 0x%x " in ata_eh_link_report()
2452 ehc->i.err_mask, link->sactive, ehc->i.serror, in ata_eh_link_report()
2453 ehc->i.action, frozen, tries_buf); in ata_eh_link_report()
2455 ata_dev_err(ehc->i.dev, "%s\n", desc); in ata_eh_link_report()
2459 ehc->i.err_mask, link->sactive, ehc->i.serror, in ata_eh_link_report()
2460 ehc->i.action, frozen, tries_buf); in ata_eh_link_report()
2466 if (ehc->i.serror) in ata_eh_link_report()
2469 ehc->i.serror & SERR_DATA_RECOVERED ? "RecovData " : "", in ata_eh_link_report()
2470 ehc->i.serror & SERR_COMM_RECOVERED ? "RecovComm " : "", in ata_eh_link_report()
2471 ehc->i.serror & SERR_DATA ? "UnrecovData " : "", in ata_eh_link_report()
2472 ehc->i.serror & SERR_PERSISTENT ? "Persist " : "", in ata_eh_link_report()
2473 ehc->i.serror & SERR_PROTOCOL ? "Proto " : "", in ata_eh_link_report()
2474 ehc->i.serror & SERR_INTERNAL ? "HostInt " : "", in ata_eh_link_report()
2475 ehc->i.serror & SERR_PHYRDY_CHG ? "PHYRdyChg " : "", in ata_eh_link_report()
2476 ehc->i.serror & SERR_PHY_INT_ERR ? "PHYInt " : "", in ata_eh_link_report()
2477 ehc->i.serror & SERR_COMM_WAKE ? "CommWake " : "", in ata_eh_link_report()
2478 ehc->i.serror & SERR_10B_8B_ERR ? "10B8B " : "", in ata_eh_link_report()
2479 ehc->i.serror & SERR_DISPARITY ? "Dispar " : "", in ata_eh_link_report()
2480 ehc->i.serror & SERR_CRC ? "BadCRC " : "", in ata_eh_link_report()
2481 ehc->i.serror & SERR_HANDSHAKE ? "Handshk " : "", in ata_eh_link_report()
2482 ehc->i.serror & SERR_LINK_SEQ_ERR ? "LinkSeq " : "", in ata_eh_link_report()
2483 ehc->i.serror & SERR_TRANS_ST_ERROR ? "TrStaTrns " : "", in ata_eh_link_report()
2484 ehc->i.serror & SERR_UNRECOG_FIS ? "UnrecFIS " : "", in ata_eh_link_report()
2485 ehc->i.serror & SERR_DEV_XCHG ? "DevExch " : ""); in ata_eh_link_report()
2489 struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf; in ata_eh_link_report()
2493 if (!(qc->flags & ATA_QCFLAG_FAILED) || in ata_eh_link_report()
2494 ata_dev_phys_link(qc->dev) != link || !qc->err_mask) in ata_eh_link_report()
2497 if (qc->dma_dir != DMA_NONE) { in ata_eh_link_report()
2505 switch (qc->tf.protocol) { in ata_eh_link_report()
2535 prot_str, qc->nbytes, dma_str[qc->dma_dir]); in ata_eh_link_report()
2538 if (ata_is_atapi(qc->tf.protocol)) { in ata_eh_link_report()
2539 const u8 *cdb = qc->cdb; in ata_eh_link_report()
2540 size_t cdb_len = qc->dev->cdb_len; in ata_eh_link_report()
2542 if (qc->scsicmd) { in ata_eh_link_report()
2543 cdb = qc->scsicmd->cmnd; in ata_eh_link_report()
2544 cdb_len = qc->scsicmd->cmd_len; in ata_eh_link_report()
2549 const char *descr = ata_get_cmd_descript(cmd->command); in ata_eh_link_report()
2551 ata_dev_err(qc->dev, "failed command: %s\n", in ata_eh_link_report()
2555 ata_dev_err(qc->dev, in ata_eh_link_report()
2560 cmd->command, cmd->feature, cmd->nsect, in ata_eh_link_report()
2561 cmd->lbal, cmd->lbam, cmd->lbah, in ata_eh_link_report()
2562 cmd->hob_feature, cmd->hob_nsect, in ata_eh_link_report()
2563 cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah, in ata_eh_link_report()
2564 cmd->device, qc->tag, data_buf, cdb_buf, in ata_eh_link_report()
2565 res->command, res->feature, res->nsect, in ata_eh_link_report()
2566 res->lbal, res->lbam, res->lbah, in ata_eh_link_report()
2567 res->hob_feature, res->hob_nsect, in ata_eh_link_report()
2568 res->hob_lbal, res->hob_lbam, res->hob_lbah, in ata_eh_link_report()
2569 res->device, qc->err_mask, ata_err_string(qc->err_mask), in ata_eh_link_report()
2570 qc->err_mask & AC_ERR_NCQ ? " <F>" : ""); in ata_eh_link_report()
2573 if (res->command & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | in ata_eh_link_report()
2575 if (res->command & ATA_BUSY) in ata_eh_link_report()
2576 ata_dev_err(qc->dev, "status: { Busy }\n"); in ata_eh_link_report()
2578 ata_dev_err(qc->dev, "status: { %s%s%s%s%s}\n", in ata_eh_link_report()
2579 res->command & ATA_DRDY ? "DRDY " : "", in ata_eh_link_report()
2580 res->command & ATA_DF ? "DF " : "", in ata_eh_link_report()
2581 res->command & ATA_DRQ ? "DRQ " : "", in ata_eh_link_report()
2582 res->command & ATA_SENSE ? "SENSE " : "", in ata_eh_link_report()
2583 res->command & ATA_ERR ? "ERR " : ""); in ata_eh_link_report()
2586 if (cmd->command != ATA_CMD_PACKET && in ata_eh_link_report()
2587 (res->feature & (ATA_ICRC | ATA_UNC | ATA_AMNF | in ata_eh_link_report()
2589 ata_dev_err(qc->dev, "error: { %s%s%s%s%s}\n", in ata_eh_link_report()
2590 res->feature & ATA_ICRC ? "ICRC " : "", in ata_eh_link_report()
2591 res->feature & ATA_UNC ? "UNC " : "", in ata_eh_link_report()
2592 res->feature & ATA_AMNF ? "AMNF " : "", in ata_eh_link_report()
2593 res->feature & ATA_IDNF ? "IDNF " : "", in ata_eh_link_report()
2594 res->feature & ATA_ABORTED ? "ABRT " : ""); in ata_eh_link_report()
2600 * ata_eh_report - report error handling to user
2624 classes[dev->devno] = ATA_DEV_UNKNOWN; in ata_do_reset()
2631 if ((link->flags & ATA_LFLAG_NO_SRST) || ata_link_offline(link)) in ata_eh_followup_srst_needed()
2633 if (rc == -EAGAIN) in ata_eh_followup_srst_needed()
2635 if (sata_pmp_supported(link->ap) && ata_is_host_link(link)) in ata_eh_followup_srst_needed()
2644 struct ata_port *ap = link->ap; in ata_eh_reset()
2645 struct ata_link *slave = ap->slave_link; in ata_eh_reset()
2646 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_reset()
2647 struct ata_eh_context *sehc = slave ? &slave->eh_context : NULL; in ata_eh_reset()
2648 unsigned int *classes = ehc->classes; in ata_eh_reset()
2649 unsigned int lflags = link->flags; in ata_eh_reset()
2650 int verbose = !(ehc->i.flags & ATA_EHI_QUIET); in ata_eh_reset()
2665 if (link->flags & ATA_LFLAG_RST_ONCE) in ata_eh_reset()
2667 if (link->flags & ATA_LFLAG_NO_HRST) in ata_eh_reset()
2669 if (link->flags & ATA_LFLAG_NO_SRST) in ata_eh_reset()
2673 if (ehc->i.flags & ATA_EHI_DID_RESET) { in ata_eh_reset()
2675 WARN_ON(time_after(ehc->last_reset, now)); in ata_eh_reset()
2676 deadline = ata_deadline(ehc->last_reset, in ata_eh_reset()
2679 schedule_timeout_uninterruptible(deadline - now); in ata_eh_reset()
2682 spin_lock_irqsave(ap->lock, flags); in ata_eh_reset()
2683 ap->pflags |= ATA_PFLAG_RESETTING; in ata_eh_reset()
2684 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_reset()
2696 dev->pio_mode = XFER_PIO_0; in ata_eh_reset()
2697 dev->dma_mode = 0xff; in ata_eh_reset()
2704 if (ap->ops->set_piomode) in ata_eh_reset()
2705 ap->ops->set_piomode(ap, dev); in ata_eh_reset()
2710 ehc->i.action &= ~ATA_EH_RESET; in ata_eh_reset()
2713 ehc->i.action |= ATA_EH_HARDRESET; in ata_eh_reset()
2716 ehc->i.action |= ATA_EH_SOFTRESET; in ata_eh_reset()
2724 sehc->i.action &= ~ATA_EH_RESET; in ata_eh_reset()
2725 sehc->i.action |= ehc->i.action; in ata_eh_reset()
2732 * -ENOENT or clear ATA_EH_RESET. in ata_eh_reset()
2734 if (slave && (rc == 0 || rc == -ENOENT)) { in ata_eh_reset()
2738 if (tmp != -ENOENT) in ata_eh_reset()
2741 ehc->i.action |= sehc->i.action; in ata_eh_reset()
2745 if (rc == -ENOENT) { in ata_eh_reset()
2746 ata_link_dbg(link, "port disabled--ignoring\n"); in ata_eh_reset()
2747 ehc->i.action &= ~ATA_EH_RESET; in ata_eh_reset()
2750 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2763 if (reset && !(ehc->i.action & ATA_EH_RESET)) { in ata_eh_reset()
2765 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2766 if ((ap->pflags & ATA_PFLAG_FROZEN) && in ata_eh_reset()
2789 ehc->last_reset = jiffies; in ata_eh_reset()
2791 ehc->i.flags |= ATA_EHI_DID_HARDRESET; in ata_eh_reset()
2793 ehc->i.flags |= ATA_EHI_DID_SOFTRESET; in ata_eh_reset()
2796 if (rc && rc != -EAGAIN) { in ata_eh_reset()
2812 case -EAGAIN: in ata_eh_reset()
2813 rc = -EAGAIN; in ata_eh_reset()
2823 /* perform follow-up SRST if necessary */ in ata_eh_reset()
2830 "follow-up softreset required but no softreset available\n"); in ata_eh_reset()
2832 rc = -EINVAL; in ata_eh_reset()
2852 * Post-reset processing in ata_eh_reset()
2859 dev->pio_mode = XFER_PIO_0; in ata_eh_reset()
2860 dev->flags &= ~ATA_DFLAG_SLEEPING; in ata_eh_reset()
2867 classes[dev->devno] = ATA_DEV_ATA; in ata_eh_reset()
2869 classes[dev->devno] = ATA_DEV_SEMB_UNSUP; in ata_eh_reset()
2874 link->sata_spd = (sstatus >> 4) & 0xf; in ata_eh_reset()
2876 slave->sata_spd = (sstatus >> 4) & 0xf; in ata_eh_reset()
2898 * information and re-thaw the port if frozen. As reset is the in ata_eh_reset()
2902 spin_lock_irqsave(link->ap->lock, flags); in ata_eh_reset()
2903 memset(&link->eh_info, 0, sizeof(link->eh_info)); in ata_eh_reset()
2905 memset(&slave->eh_info, 0, sizeof(link->eh_info)); in ata_eh_reset()
2906 ap->pflags &= ~ATA_PFLAG_EH_PENDING; in ata_eh_reset()
2907 spin_unlock_irqrestore(link->ap->lock, flags); in ata_eh_reset()
2909 if (ap->pflags & ATA_PFLAG_FROZEN) in ata_eh_reset()
2923 if (classes[dev->devno] == ATA_DEV_UNKNOWN) { in ata_eh_reset()
2925 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2929 if (ata_class_enabled(classes[dev->devno])) in ata_eh_reset()
2932 classes[dev->devno]); in ata_eh_reset()
2933 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2934 } else if (classes[dev->devno] == ATA_DEV_UNKNOWN) { in ata_eh_reset()
2937 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2947 rc = -EAGAIN; in ata_eh_reset()
2959 ehc->last_reset = jiffies; /* update to completion time */ in ata_eh_reset()
2960 ehc->i.action |= ATA_EH_REVALIDATE; in ata_eh_reset()
2961 link->lpm_policy = ATA_LPM_UNKNOWN; /* reset LPM state */ in ata_eh_reset()
2966 ehc->i.flags &= ~ATA_EHI_HOTPLUGGED; in ata_eh_reset()
2968 sehc->i.flags &= ~ATA_EHI_HOTPLUGGED; in ata_eh_reset()
2970 spin_lock_irqsave(ap->lock, flags); in ata_eh_reset()
2971 ap->pflags &= ~ATA_PFLAG_RESETTING; in ata_eh_reset()
2972 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_reset()
2977 /* if SCR isn't accessible on a fan-out port, PMP needs to be reset */ in ata_eh_reset()
2980 rc = -ERESTART; in ata_eh_reset()
2996 unsigned long delta = deadline - now; in ata_eh_reset()
3010 * They need to be reset - as well as the PMP - before retrying. in ata_eh_reset()
3012 if (rc == -ERESTART) { in ata_eh_reset()
3018 if (try == max_tries - 1) { in ata_eh_reset()
3022 } else if (rc == -EPIPE) in ata_eh_reset()
3048 * Additionally, all write accesses to &ap->park_req_pending in ata_eh_pull_park_action()
3055 * park_req_pending.done is non-zero by the time we reach in ata_eh_pull_park_action()
3062 spin_lock_irqsave(ap->lock, flags); in ata_eh_pull_park_action()
3063 reinit_completion(&ap->park_req_pending); in ata_eh_pull_park_action()
3066 struct ata_eh_info *ehi = &link->eh_info; in ata_eh_pull_park_action()
3068 link->eh_context.i.dev_action[dev->devno] |= in ata_eh_pull_park_action()
3069 ehi->dev_action[dev->devno] & ATA_EH_PARK; in ata_eh_pull_park_action()
3073 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_pull_park_action()
3078 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_park_issue_cmd()
3084 ehc->unloaded_mask |= 1 << dev->devno; in ata_eh_park_issue_cmd()
3091 ehc->unloaded_mask &= ~(1 << dev->devno); in ata_eh_park_issue_cmd()
3100 ehc->unloaded_mask &= ~(1 << dev->devno); in ata_eh_park_issue_cmd()
3107 struct ata_port *ap = link->ap; in ata_eh_revalidate_and_attach()
3108 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_revalidate_and_attach()
3117 * be done backwards such that PDIAG- is released by the slave in ata_eh_revalidate_and_attach()
3124 if (ehc->i.flags & ATA_EHI_DID_RESET) in ata_eh_revalidate_and_attach()
3128 WARN_ON(dev->class == ATA_DEV_PMP); in ata_eh_revalidate_and_attach()
3131 rc = -EIO; in ata_eh_revalidate_and_attach()
3136 rc = ata_dev_revalidate(dev, ehc->classes[dev->devno], in ata_eh_revalidate_and_attach()
3146 ehc->i.flags |= ATA_EHI_SETMODE; in ata_eh_revalidate_and_attach()
3149 schedule_work(&(ap->scsi_rescan_task)); in ata_eh_revalidate_and_attach()
3150 } else if (dev->class == ATA_DEV_UNKNOWN && in ata_eh_revalidate_and_attach()
3151 ehc->tries[dev->devno] && in ata_eh_revalidate_and_attach()
3152 ata_class_enabled(ehc->classes[dev->devno])) { in ata_eh_revalidate_and_attach()
3153 /* Temporarily set dev->class, it will be in ata_eh_revalidate_and_attach()
3159 dev->class = ehc->classes[dev->devno]; in ata_eh_revalidate_and_attach()
3161 if (dev->class == ATA_DEV_PMP) in ata_eh_revalidate_and_attach()
3164 rc = ata_dev_read_id(dev, &dev->class, in ata_eh_revalidate_and_attach()
3165 readid_flags, dev->id); in ata_eh_revalidate_and_attach()
3168 ehc->classes[dev->devno] = dev->class; in ata_eh_revalidate_and_attach()
3169 dev->class = ATA_DEV_UNKNOWN; in ata_eh_revalidate_and_attach()
3174 ata_ering_clear(&dev->ering); in ata_eh_revalidate_and_attach()
3175 new_mask |= 1 << dev->devno; in ata_eh_revalidate_and_attach()
3177 case -ENOENT: in ata_eh_revalidate_and_attach()
3178 /* IDENTIFY was issued to non-existent in ata_eh_revalidate_and_attach()
3190 /* PDIAG- should have been released, ask cable type if post-reset */ in ata_eh_revalidate_and_attach()
3191 if ((ehc->i.flags & ATA_EHI_DID_RESET) && ata_is_host_link(link)) { in ata_eh_revalidate_and_attach()
3192 if (ap->ops->cable_detect) in ata_eh_revalidate_and_attach()
3193 ap->cbl = ap->ops->cable_detect(ap); in ata_eh_revalidate_and_attach()
3201 if (!(new_mask & (1 << dev->devno))) in ata_eh_revalidate_and_attach()
3204 dev->class = ehc->classes[dev->devno]; in ata_eh_revalidate_and_attach()
3206 if (dev->class == ATA_DEV_PMP) in ata_eh_revalidate_and_attach()
3209 ehc->i.flags |= ATA_EHI_PRINTINFO; in ata_eh_revalidate_and_attach()
3211 ehc->i.flags &= ~ATA_EHI_PRINTINFO; in ata_eh_revalidate_and_attach()
3213 dev->class = ATA_DEV_UNKNOWN; in ata_eh_revalidate_and_attach()
3217 spin_lock_irqsave(ap->lock, flags); in ata_eh_revalidate_and_attach()
3218 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG; in ata_eh_revalidate_and_attach()
3219 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_revalidate_and_attach()
3222 ehc->i.flags |= ATA_EHI_SETMODE; in ata_eh_revalidate_and_attach()
3234 * ata_set_mode - Program timings and issue SET FEATURES - XFER
3250 struct ata_port *ap = link->ap; in ata_set_mode()
3256 if (!(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) { in ata_set_mode()
3259 ent = ata_ering_top(&dev->ering); in ata_set_mode()
3261 ent->eflags &= ~ATA_EFLAG_DUBIOUS_XFER; in ata_set_mode()
3266 if (ap->ops->set_mode) in ata_set_mode()
3267 rc = ap->ops->set_mode(link, r_failed_dev); in ata_set_mode()
3273 struct ata_eh_context *ehc = &link->eh_context; in ata_set_mode()
3274 u8 saved_xfer_mode = ehc->saved_xfer_mode[dev->devno]; in ata_set_mode()
3275 u8 saved_ncq = !!(ehc->saved_ncq_enabled & (1 << dev->devno)); in ata_set_mode()
3277 if (dev->xfer_mode != saved_xfer_mode || in ata_set_mode()
3279 dev->flags |= ATA_DFLAG_DUBIOUS_XFER; in ata_set_mode()
3286 * atapi_eh_clear_ua - Clear ATAPI UNIT ATTENTION after reset
3297 * 0 on success, -errno on failure.
3304 u8 *sense_buffer = dev->link->ap->sector_buf; in atapi_eh_clear_ua()
3313 return -EIO; in atapi_eh_clear_ua()
3323 return -EIO; in atapi_eh_clear_ua()
3334 * ata_eh_maybe_retry_flush - Retry FLUSH if necessary
3348 * 0 if EH can continue, -errno if EH needs to be repeated.
3352 struct ata_link *link = dev->link; in ata_eh_maybe_retry_flush()
3353 struct ata_port *ap = link->ap; in ata_eh_maybe_retry_flush()
3360 if (!ata_tag_valid(link->active_tag)) in ata_eh_maybe_retry_flush()
3363 qc = __ata_qc_from_tag(ap, link->active_tag); in ata_eh_maybe_retry_flush()
3364 if (qc->dev != dev || (qc->tf.command != ATA_CMD_FLUSH_EXT && in ata_eh_maybe_retry_flush()
3365 qc->tf.command != ATA_CMD_FLUSH)) in ata_eh_maybe_retry_flush()
3369 if (qc->err_mask & AC_ERR_DEV) in ata_eh_maybe_retry_flush()
3375 tf.command = qc->tf.command; in ata_eh_maybe_retry_flush()
3380 tf.command, qc->err_mask); in ata_eh_maybe_retry_flush()
3388 * retrying it should do the trick - whatever was in in ata_eh_maybe_retry_flush()
3392 qc->scsicmd->allowed = max(qc->scsicmd->allowed, 1); in ata_eh_maybe_retry_flush()
3396 rc = -EIO; in ata_eh_maybe_retry_flush()
3400 qc->err_mask |= AC_ERR_DEV; in ata_eh_maybe_retry_flush()
3401 qc->result_tf = tf; in ata_eh_maybe_retry_flush()
3402 if (!(ap->pflags & ATA_PFLAG_FROZEN)) in ata_eh_maybe_retry_flush()
3410 * ata_eh_set_lpm - configure SATA interface power management
3424 * 0 on success, -errno on failure.
3429 struct ata_port *ap = ata_is_host_link(link) ? link->ap : NULL; in ata_eh_set_lpm()
3430 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_set_lpm()
3432 enum ata_lpm_policy old_policy = link->lpm_policy; in ata_eh_set_lpm()
3433 bool no_dipm = link->ap->flags & ATA_FLAG_NO_DIPM; in ata_eh_set_lpm()
3439 if ((link->flags & ATA_LFLAG_NO_LPM) || (ap && !ap->ops->set_lpm)) in ata_eh_set_lpm()
3449 bool hipm = ata_id_has_hipm(dev->id); in ata_eh_set_lpm()
3450 bool dipm = ata_id_has_dipm(dev->id) && !no_dipm; in ata_eh_set_lpm()
3471 rc = -EIO; in ata_eh_set_lpm()
3478 rc = ap->ops->set_lpm(link, policy, hints); in ata_eh_set_lpm()
3479 if (!rc && ap->slave_link) in ata_eh_set_lpm()
3480 rc = ap->ops->set_lpm(ap->slave_link, policy, hints); in ata_eh_set_lpm()
3489 if (rc == -EOPNOTSUPP) { in ata_eh_set_lpm()
3490 link->flags |= ATA_LFLAG_NO_LPM; in ata_eh_set_lpm()
3501 link->lpm_policy = policy; in ata_eh_set_lpm()
3502 if (ap && ap->slave_link) in ata_eh_set_lpm()
3503 ap->slave_link->lpm_policy = policy; in ata_eh_set_lpm()
3508 ata_id_has_dipm(dev->id)) { in ata_eh_set_lpm()
3515 rc = -EIO; in ata_eh_set_lpm()
3521 link->last_lpm_change = jiffies; in ata_eh_set_lpm()
3522 link->flags |= ATA_LFLAG_CHANGED; in ata_eh_set_lpm()
3528 link->lpm_policy = old_policy; in ata_eh_set_lpm()
3529 if (ap && ap->slave_link) in ata_eh_set_lpm()
3530 ap->slave_link->lpm_policy = old_policy; in ata_eh_set_lpm()
3533 if (!dev || ehc->tries[dev->devno] <= 2) { in ata_eh_set_lpm()
3535 link->flags |= ATA_LFLAG_NO_LPM; in ata_eh_set_lpm()
3558 if (dev->class == ATA_DEV_UNKNOWN) in ata_link_nr_vacant()
3565 struct ata_port *ap = link->ap; in ata_eh_skip_recovery()
3566 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_skip_recovery()
3570 if (link->flags & ATA_LFLAG_DISABLED) in ata_eh_skip_recovery()
3574 if (ehc->i.flags & ATA_EHI_NO_RECOVERY) in ata_eh_skip_recovery()
3578 if ((ap->pflags & ATA_PFLAG_FROZEN) || ata_link_nr_enabled(link)) in ata_eh_skip_recovery()
3582 if ((ehc->i.action & ATA_EH_RESET) && in ata_eh_skip_recovery()
3583 !(ehc->i.flags & ATA_EHI_DID_RESET)) in ata_eh_skip_recovery()
3588 if (dev->class == ATA_DEV_UNKNOWN && in ata_eh_skip_recovery()
3589 ehc->classes[dev->devno] != ATA_DEV_NONE) in ata_eh_skip_recovery()
3602 if ((ent->eflags & ATA_EFLAG_OLD_ER) || in ata_count_probe_trials_cb()
3603 (ent->timestamp < now - min(now, interval))) in ata_count_probe_trials_cb()
3604 return -1; in ata_count_probe_trials_cb()
3612 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_schedule_probe()
3616 if (!(ehc->i.probe_mask & (1 << dev->devno)) || in ata_eh_schedule_probe()
3617 (ehc->did_probe_mask & (1 << dev->devno))) in ata_eh_schedule_probe()
3622 ehc->did_probe_mask |= (1 << dev->devno); in ata_eh_schedule_probe()
3623 ehc->i.action |= ATA_EH_RESET; in ata_eh_schedule_probe()
3624 ehc->saved_xfer_mode[dev->devno] = 0; in ata_eh_schedule_probe()
3625 ehc->saved_ncq_enabled &= ~(1 << dev->devno); in ata_eh_schedule_probe()
3628 if (link->lpm_policy > ATA_LPM_MAX_POWER) { in ata_eh_schedule_probe()
3630 link->ap->ops->set_lpm(link, ATA_LPM_MAX_POWER, in ata_eh_schedule_probe()
3650 ata_ering_record(&dev->ering, 0, AC_ERR_OTHER); in ata_eh_schedule_probe()
3651 ata_ering_map(&dev->ering, ata_count_probe_trials_cb, &trials); in ata_eh_schedule_probe()
3661 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_handle_dev_fail()
3663 /* -EAGAIN from EH routine indicates retry without prejudice. in ata_eh_handle_dev_fail()
3666 if (err != -EAGAIN) in ata_eh_handle_dev_fail()
3667 ehc->tries[dev->devno]--; in ata_eh_handle_dev_fail()
3670 case -ENODEV: in ata_eh_handle_dev_fail()
3672 ehc->i.probe_mask |= (1 << dev->devno); in ata_eh_handle_dev_fail()
3674 case -EINVAL: in ata_eh_handle_dev_fail()
3676 ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1); in ata_eh_handle_dev_fail()
3678 case -EIO: in ata_eh_handle_dev_fail()
3679 if (ehc->tries[dev->devno] == 1) { in ata_eh_handle_dev_fail()
3684 if (dev->pio_mode > XFER_PIO_0) in ata_eh_handle_dev_fail()
3689 if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) { in ata_eh_handle_dev_fail()
3699 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; in ata_eh_handle_dev_fail()
3700 memset(ehc->cmd_timeout_idx[dev->devno], 0, in ata_eh_handle_dev_fail()
3701 sizeof(ehc->cmd_timeout_idx[dev->devno])); in ata_eh_handle_dev_fail()
3706 ehc->i.action |= ATA_EH_RESET; in ata_eh_handle_dev_fail()
3712 * ata_eh_recover - recover host port after error
3731 * 0 on success, -errno on failure.
3747 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3749 /* re-enable link? */ in ata_eh_recover()
3750 if (ehc->i.action & ATA_EH_ENABLE_LINK) { in ata_eh_recover()
3752 spin_lock_irqsave(ap->lock, flags); in ata_eh_recover()
3753 link->flags &= ~ATA_LFLAG_DISABLED; in ata_eh_recover()
3754 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_recover()
3759 if (link->flags & ATA_LFLAG_NO_RETRY) in ata_eh_recover()
3760 ehc->tries[dev->devno] = 1; in ata_eh_recover()
3762 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; in ata_eh_recover()
3765 ehc->i.action |= ehc->i.dev_action[dev->devno] & in ata_eh_recover()
3767 ehc->i.dev_action[dev->devno] &= ATA_EH_PERDEV_MASK; in ata_eh_recover()
3770 if (dev->flags & ATA_DFLAG_DETACH) in ata_eh_recover()
3783 if (ap->pflags & ATA_PFLAG_UNLOADING) in ata_eh_recover()
3788 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3792 ehc->i.action = 0; in ata_eh_recover()
3795 ehc->classes[dev->devno] = ATA_DEV_UNKNOWN; in ata_eh_recover()
3800 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3802 if (!(ehc->i.action & ATA_EH_RESET)) in ata_eh_recover()
3818 * ap->park_req_pending in ata_eh_recover()
3825 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3828 if (dev->class != ATA_DEV_ATA && in ata_eh_recover()
3829 dev->class != ATA_DEV_ZAC) in ata_eh_recover()
3831 if (!(ehc->i.dev_action[dev->devno] & in ata_eh_recover()
3834 tmp = dev->unpark_deadline; in ata_eh_recover()
3839 if (ehc->unloaded_mask & (1 << dev->devno)) in ata_eh_recover()
3851 deadline = wait_for_completion_timeout(&ap->park_req_pending, in ata_eh_recover()
3852 deadline - now); in ata_eh_recover()
3857 if (!(link->eh_context.unloaded_mask & in ata_eh_recover()
3858 (1 << dev->devno))) in ata_eh_recover()
3869 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3880 if (link->device->class == ATA_DEV_PMP) { in ata_eh_recover()
3881 ehc->i.action = 0; in ata_eh_recover()
3886 if (ehc->i.flags & ATA_EHI_SETMODE) { in ata_eh_recover()
3890 ehc->i.flags &= ~ATA_EHI_SETMODE; in ata_eh_recover()
3896 if (ehc->i.flags & ATA_EHI_DID_RESET) { in ata_eh_recover()
3898 if (dev->class != ATA_DEV_ATAPI) in ata_eh_recover()
3910 if (dev->class != ATA_DEV_ATA && in ata_eh_recover()
3911 dev->class != ATA_DEV_ZAC) in ata_eh_recover()
3920 if (link->lpm_policy != ap->target_lpm_policy) { in ata_eh_recover()
3921 rc = ata_eh_set_lpm(link, ap->target_lpm_policy, &dev); in ata_eh_recover()
3927 ehc->i.flags = 0; in ata_eh_recover()
3935 if (ap->pflags & ATA_PFLAG_FROZEN) { in ata_eh_recover()
3957 * ata_eh_finish - finish up EH
3973 if (!(qc->flags & ATA_QCFLAG_FAILED)) in ata_eh_finish()
3976 if (qc->err_mask) { in ata_eh_finish()
3981 if (qc->flags & ATA_QCFLAG_RETRY) in ata_eh_finish()
3986 if (qc->flags & ATA_QCFLAG_SENSE_VALID) { in ata_eh_finish()
3990 memset(&qc->result_tf, 0, sizeof(qc->result_tf)); in ata_eh_finish()
3997 WARN_ON(ap->nr_active_links); in ata_eh_finish()
3998 ap->nr_active_links = 0; in ata_eh_finish()
4002 * ata_do_eh - do standard error handling
4028 ata_for_each_dev(dev, &ap->link, ALL) in ata_do_eh()
4036 * ata_std_error_handler - standard error handler
4046 struct ata_port_operations *ops = ap->ops; in ata_std_error_handler()
4047 ata_reset_fn_t hardreset = ops->hardreset; in ata_std_error_handler()
4049 /* ignore built-in hardreset if SCR access is not available */ in ata_std_error_handler()
4050 if (hardreset == sata_std_hardreset && !sata_scr_valid(&ap->link)) in ata_std_error_handler()
4053 ata_do_eh(ap, ops->prereset, ops->softreset, hardreset, ops->postreset); in ata_std_error_handler()
4058 * ata_eh_handle_port_suspend - perform port suspend operation
4073 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_suspend()
4074 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) || in ata_eh_handle_port_suspend()
4075 ap->pm_mesg.event & PM_EVENT_RESUME) { in ata_eh_handle_port_suspend()
4076 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_suspend()
4079 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_suspend()
4081 WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED); in ata_eh_handle_port_suspend()
4088 if (PMSG_IS_AUTO(ap->pm_mesg)) { in ata_eh_handle_port_suspend()
4089 ata_for_each_dev(dev, &ap->link, ENABLED) { in ata_eh_handle_port_suspend()
4103 if (ap->ops->port_suspend) in ata_eh_handle_port_suspend()
4104 rc = ap->ops->port_suspend(ap, ap->pm_mesg); in ata_eh_handle_port_suspend()
4106 ata_acpi_set_state(ap, ap->pm_mesg); in ata_eh_handle_port_suspend()
4109 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_suspend()
4111 ap->pflags &= ~ATA_PFLAG_PM_PENDING; in ata_eh_handle_port_suspend()
4113 ap->pflags |= ATA_PFLAG_SUSPENDED; in ata_eh_handle_port_suspend()
4114 else if (ap->pflags & ATA_PFLAG_FROZEN) in ata_eh_handle_port_suspend()
4117 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_suspend()
4123 * ata_eh_handle_port_resume - perform port resume operation
4138 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_resume()
4139 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) || in ata_eh_handle_port_resume()
4140 !(ap->pm_mesg.event & PM_EVENT_RESUME)) { in ata_eh_handle_port_resume()
4141 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_resume()
4144 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_resume()
4146 WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED)); in ata_eh_handle_port_resume()
4157 ata_ering_clear(&dev->ering); in ata_eh_handle_port_resume()
4159 ata_acpi_set_state(ap, ap->pm_mesg); in ata_eh_handle_port_resume()
4161 if (ap->ops->port_resume) in ata_eh_handle_port_resume()
4162 ap->ops->port_resume(ap); in ata_eh_handle_port_resume()
4168 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_resume()
4169 ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED); in ata_eh_handle_port_resume()
4170 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_resume()