Lines Matching +full:deep +full:- +full:touch
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * libata-eh.c - libata error handling
8 * as Documentation/driver-api/libata.rst
11 * http://www.sata-io.org/
59 /* Waiting in ->prereset can never be reliable. It's
123 * ehc->cmd_timeout_idx keeps track of which timeout to use per
160 ehi->desc_len += vscnprintf(ehi->desc + ehi->desc_len, in __ata_ehi_pushv_desc()
161 ATA_EH_DESC_LEN - ehi->desc_len, in __ata_ehi_pushv_desc()
166 * __ata_ehi_push_desc - push error description without adding separator
170 * Format string according to @fmt and append it to @ehi->desc.
186 * ata_ehi_push_desc - push error description with separator
190 * Format string according to @fmt and append it to @ehi->desc.
191 * If @ehi->desc is not empty, ", " is added in-between.
200 if (ehi->desc_len) in ata_ehi_push_desc()
210 * ata_ehi_clear_desc - clean error description
213 * Clear @ehi->desc.
220 ehi->desc[0] = '\0'; in ata_ehi_clear_desc()
221 ehi->desc_len = 0; in ata_ehi_clear_desc()
226 * ata_port_desc - append port description
232 * in-between. This function is to be used while initializing
242 WARN_ON(!(ap->pflags & ATA_PFLAG_INITIALIZING)); in ata_port_desc()
244 if (ap->link.eh_info.desc_len) in ata_port_desc()
245 __ata_ehi_push_desc(&ap->link.eh_info, " "); in ata_port_desc()
248 __ata_ehi_pushv_desc(&ap->link.eh_info, fmt, args); in ata_port_desc()
255 * ata_port_pbar_desc - append PCI BAR description
272 struct pci_dev *pdev = to_pci_dev(ap->host->dev); in ata_port_pbar_desc()
305 return -1; in ata_lookup_timeout_table()
309 * ata_internal_cmd_timeout - determine timeout for an internal command
323 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_internal_cmd_timeout()
330 idx = ehc->cmd_timeout_idx[dev->devno][ent]; in ata_internal_cmd_timeout()
335 * ata_internal_cmd_timed_out - notification for internal command timeout
348 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_internal_cmd_timed_out()
355 idx = ehc->cmd_timeout_idx[dev->devno][ent]; in ata_internal_cmd_timed_out()
357 ehc->cmd_timeout_idx[dev->devno][ent]++; in ata_internal_cmd_timed_out()
367 ering->cursor++; in ata_ering_record()
368 ering->cursor %= ATA_ERING_SIZE; in ata_ering_record()
370 ent = &ering->ring[ering->cursor]; in ata_ering_record()
371 ent->eflags = eflags; in ata_ering_record()
372 ent->err_mask = err_mask; in ata_ering_record()
373 ent->timestamp = get_jiffies_64(); in ata_ering_record()
378 struct ata_ering_entry *ent = &ering->ring[ering->cursor]; in ata_ering_top()
380 if (ent->err_mask) in ata_ering_top()
392 idx = ering->cursor; in ata_ering_map()
394 ent = &ering->ring[idx]; in ata_ering_map()
395 if (!ent->err_mask) in ata_ering_map()
400 idx = (idx - 1 + ATA_ERING_SIZE) % ATA_ERING_SIZE; in ata_ering_map()
401 } while (idx != ering->cursor); in ata_ering_map()
408 ent->eflags |= ATA_EFLAG_OLD_ER; in ata_ering_clear_cb()
419 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_dev_action()
421 return ehc->i.action | ehc->i.dev_action[dev->devno]; in ata_eh_dev_action()
430 ehi->action &= ~action; in ata_eh_clear_action()
432 ehi->dev_action[tdev->devno] &= ~action; in ata_eh_clear_action()
434 /* doesn't make sense for port-wide EH actions */ in ata_eh_clear_action()
437 /* break ehi->action into ehi->dev_action */ in ata_eh_clear_action()
438 if (ehi->action & action) { in ata_eh_clear_action()
440 ehi->dev_action[tdev->devno] |= in ata_eh_clear_action()
441 ehi->action & action; in ata_eh_clear_action()
442 ehi->action &= ~action; in ata_eh_clear_action()
445 /* turn off the specified per-dev action */ in ata_eh_clear_action()
446 ehi->dev_action[dev->devno] &= ~action; in ata_eh_clear_action()
451 * ata_eh_acquire - acquire EH ownership
463 mutex_lock(&ap->host->eh_mutex); in ata_eh_acquire()
464 WARN_ON_ONCE(ap->host->eh_owner); in ata_eh_acquire()
465 ap->host->eh_owner = current; in ata_eh_acquire()
469 * ata_eh_release - release EH ownership
480 WARN_ON_ONCE(ap->host->eh_owner != current); in ata_eh_release()
481 ap->host->eh_owner = NULL; in ata_eh_release()
482 mutex_unlock(&ap->host->eh_mutex); in ata_eh_release()
495 sata_scr_write(link, SCR_CONTROL, link->saved_scontrol & 0xff0); in ata_eh_unload()
501 spin_lock_irqsave(ap->lock, flags); in ata_eh_unload()
504 ap->pflags &= ~ATA_PFLAG_EH_PENDING; /* clear pending from freeze */ in ata_eh_unload()
505 ap->pflags |= ATA_PFLAG_UNLOADED; in ata_eh_unload()
507 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_unload()
511 * ata_scsi_error - SCSI layer error handler callback
514 * Handles SCSI-layer-thrown error events.
530 spin_lock_irqsave(host->host_lock, flags); in ata_scsi_error()
531 list_splice_init(&host->eh_cmd_q, &eh_work_q); in ata_scsi_error()
532 spin_unlock_irqrestore(host->host_lock, flags); in ata_scsi_error()
547 * ata_scsi_cmd_error_handler - error callback for a list of commands
553 * ap->eh_done_q. This function is the first part of the libata error
567 /* For new EH, all qcs are finished in one of three ways - in ata_scsi_cmd_error_handler()
579 spin_lock_irqsave(ap->lock, flags); in ata_scsi_cmd_error_handler()
580 if (ap->ops->error_handler) { in ata_scsi_cmd_error_handler()
584 /* This must occur under the ap->lock as we don't want in ata_scsi_cmd_error_handler()
588 non-notified command and completes much like an IRQ handler. in ata_scsi_cmd_error_handler()
593 if (ap->ops->lost_interrupt) in ata_scsi_cmd_error_handler()
594 ap->ops->lost_interrupt(ap); in ata_scsi_cmd_error_handler()
600 if (qc->flags & ATA_QCFLAG_ACTIVE && in ata_scsi_cmd_error_handler()
601 qc->scsicmd == scmd) in ata_scsi_cmd_error_handler()
607 if (!(qc->flags & ATA_QCFLAG_FAILED)) { in ata_scsi_cmd_error_handler()
609 qc->err_mask |= AC_ERR_TIMEOUT; in ata_scsi_cmd_error_handler()
610 qc->flags |= ATA_QCFLAG_FAILED; in ata_scsi_cmd_error_handler()
618 scmd->retries = scmd->allowed; in ata_scsi_cmd_error_handler()
619 scsi_eh_finish_cmd(scmd, &ap->eh_done_q); in ata_scsi_cmd_error_handler()
634 ap->eh_tries = ATA_EH_MAX_TRIES; in ata_scsi_cmd_error_handler()
636 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_cmd_error_handler()
642 * ata_scsi_port_error_handler - recover the port after the commands
654 if (ap->ops->error_handler) { in ata_scsi_port_error_handler()
661 del_timer_sync(&ap->fastdrain_timer); in ata_scsi_port_error_handler()
667 spin_lock_irqsave(ap->lock, flags); in ata_scsi_port_error_handler()
670 struct ata_eh_context *ehc = &link->eh_context; in ata_scsi_port_error_handler()
673 memset(&link->eh_context, 0, sizeof(link->eh_context)); in ata_scsi_port_error_handler()
674 link->eh_context.i = link->eh_info; in ata_scsi_port_error_handler()
675 memset(&link->eh_info, 0, sizeof(link->eh_info)); in ata_scsi_port_error_handler()
678 int devno = dev->devno; in ata_scsi_port_error_handler()
680 ehc->saved_xfer_mode[devno] = dev->xfer_mode; in ata_scsi_port_error_handler()
682 ehc->saved_ncq_enabled |= 1 << devno; in ata_scsi_port_error_handler()
686 ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS; in ata_scsi_port_error_handler()
687 ap->pflags &= ~ATA_PFLAG_EH_PENDING; in ata_scsi_port_error_handler()
688 ap->excl_link = NULL; /* don't maintain exclusion over EH */ in ata_scsi_port_error_handler()
690 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
693 if (!(ap->pflags & (ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED))) in ata_scsi_port_error_handler()
694 ap->ops->error_handler(ap); in ata_scsi_port_error_handler()
697 if ((ap->pflags & ATA_PFLAG_UNLOADING) && in ata_scsi_port_error_handler()
698 !(ap->pflags & ATA_PFLAG_UNLOADED)) in ata_scsi_port_error_handler()
706 /* Exception might have happened after ->error_handler in ata_scsi_port_error_handler()
710 spin_lock_irqsave(ap->lock, flags); in ata_scsi_port_error_handler()
712 if (ap->pflags & ATA_PFLAG_EH_PENDING) { in ata_scsi_port_error_handler()
713 if (--ap->eh_tries) { in ata_scsi_port_error_handler()
714 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
720 ap->pflags &= ~ATA_PFLAG_EH_PENDING; in ata_scsi_port_error_handler()
725 memset(&link->eh_info, 0, sizeof(link->eh_info)); in ata_scsi_port_error_handler()
728 * ap->lock such that if exception occurs after this in ata_scsi_port_error_handler()
730 * re-initiate EH. in ata_scsi_port_error_handler()
732 ap->ops->end_eh(ap); in ata_scsi_port_error_handler()
734 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
737 WARN_ON(ata_qc_from_tag(ap, ap->link.active_tag) == NULL); in ata_scsi_port_error_handler()
738 ap->ops->eng_timeout(ap); in ata_scsi_port_error_handler()
741 scsi_eh_flush_done_q(&ap->eh_done_q); in ata_scsi_port_error_handler()
744 spin_lock_irqsave(ap->lock, flags); in ata_scsi_port_error_handler()
746 if (ap->pflags & ATA_PFLAG_LOADING) in ata_scsi_port_error_handler()
747 ap->pflags &= ~ATA_PFLAG_LOADING; in ata_scsi_port_error_handler()
748 else if ((ap->pflags & ATA_PFLAG_SCSI_HOTPLUG) && in ata_scsi_port_error_handler()
749 !(ap->flags & ATA_FLAG_SAS_HOST)) in ata_scsi_port_error_handler()
750 schedule_delayed_work(&ap->hotplug_task, 0); in ata_scsi_port_error_handler()
752 if (ap->pflags & ATA_PFLAG_RECOVERED) in ata_scsi_port_error_handler()
755 ap->pflags &= ~(ATA_PFLAG_SCSI_HOTPLUG | ATA_PFLAG_RECOVERED); in ata_scsi_port_error_handler()
758 ap->pflags &= ~ATA_PFLAG_EH_IN_PROGRESS; in ata_scsi_port_error_handler()
759 wake_up_all(&ap->eh_wait_q); in ata_scsi_port_error_handler()
761 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
766 * ata_port_wait_eh - Wait for the currently pending EH to complete
780 spin_lock_irqsave(ap->lock, flags); in ata_port_wait_eh()
782 while (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) { in ata_port_wait_eh()
783 prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE); in ata_port_wait_eh()
784 spin_unlock_irqrestore(ap->lock, flags); in ata_port_wait_eh()
786 spin_lock_irqsave(ap->lock, flags); in ata_port_wait_eh()
788 finish_wait(&ap->eh_wait_q, &wait); in ata_port_wait_eh()
790 spin_unlock_irqrestore(ap->lock, flags); in ata_port_wait_eh()
793 if (scsi_host_in_recovery(ap->scsi_host)) { in ata_port_wait_eh()
806 /* count only non-internal commands */ in ata_eh_nr_in_flight()
821 spin_lock_irqsave(ap->lock, flags); in ata_eh_fastdrain_timerfn()
829 if (cnt == ap->fastdrain_cnt) { in ata_eh_fastdrain_timerfn()
834 * in-flight qcs as timed out and freeze the port. in ata_eh_fastdrain_timerfn()
838 qc->err_mask |= AC_ERR_TIMEOUT; in ata_eh_fastdrain_timerfn()
844 ap->fastdrain_cnt = cnt; in ata_eh_fastdrain_timerfn()
845 ap->fastdrain_timer.expires = in ata_eh_fastdrain_timerfn()
847 add_timer(&ap->fastdrain_timer); in ata_eh_fastdrain_timerfn()
851 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_fastdrain_timerfn()
855 * ata_eh_set_pending - set ATA_PFLAG_EH_PENDING and activate fast drain
860 * is non-zero and EH wasn't pending before. Fast drain ensures
871 if (ap->pflags & ATA_PFLAG_EH_PENDING) in ata_eh_set_pending()
874 ap->pflags |= ATA_PFLAG_EH_PENDING; in ata_eh_set_pending()
879 /* do we have in-flight qcs? */ in ata_eh_set_pending()
885 ap->fastdrain_cnt = cnt; in ata_eh_set_pending()
886 ap->fastdrain_timer.expires = in ata_eh_set_pending()
888 add_timer(&ap->fastdrain_timer); in ata_eh_set_pending()
892 * ata_qc_schedule_eh - schedule qc for error handling
903 struct ata_port *ap = qc->ap; in ata_qc_schedule_eh()
905 WARN_ON(!ap->ops->error_handler); in ata_qc_schedule_eh()
907 qc->flags |= ATA_QCFLAG_FAILED; in ata_qc_schedule_eh()
915 blk_abort_request(qc->scsicmd->request); in ata_qc_schedule_eh()
919 * ata_std_sched_eh - non-libsas ata_ports issue eh with this common routine
927 WARN_ON(!ap->ops->error_handler); in ata_std_sched_eh()
929 if (ap->pflags & ATA_PFLAG_INITIALIZING) in ata_std_sched_eh()
933 scsi_schedule_eh(ap->scsi_host); in ata_std_sched_eh()
940 * ata_std_end_eh - non-libsas ata_ports complete eh with this common routine
944 * shost, so host fields can be directly manipulated under ap->lock, in
945 * the libsas case we need to hold a lock at the ha->level to coordinate
953 struct Scsi_Host *host = ap->scsi_host; in ata_std_end_eh()
955 host->host_eh_scheduled = 0; in ata_std_end_eh()
961 * ata_port_schedule_eh - schedule error handling without a qc
973 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()
1021 * ata_port_abort - abort all qc's on the port
1039 * __ata_port_freeze - freeze port
1047 * ap->ops->freeze() callback can be used for freezing the port
1048 * hardware-wise (e.g. mask interrupt and stop DMA engine). If a
1049 * port cannot be frozen hardware-wise, the interrupt handler
1058 WARN_ON(!ap->ops->error_handler); in __ata_port_freeze()
1060 if (ap->ops->freeze) in __ata_port_freeze()
1061 ap->ops->freeze(ap); in __ata_port_freeze()
1063 ap->pflags |= ATA_PFLAG_FROZEN; in __ata_port_freeze()
1065 DPRINTK("ata%u port frozen\n", ap->print_id); in __ata_port_freeze()
1069 * ata_port_freeze - abort & freeze port
1086 WARN_ON(!ap->ops->error_handler); in ata_port_freeze()
1096 * ata_eh_freeze_port - EH helper to freeze port
1108 if (!ap->ops->error_handler) in ata_eh_freeze_port()
1111 spin_lock_irqsave(ap->lock, flags); in ata_eh_freeze_port()
1113 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_freeze_port()
1118 * ata_eh_thaw_port - EH helper to thaw port
1130 if (!ap->ops->error_handler) in ata_eh_thaw_port()
1133 spin_lock_irqsave(ap->lock, flags); in ata_eh_thaw_port()
1135 ap->pflags &= ~ATA_PFLAG_FROZEN; in ata_eh_thaw_port()
1137 if (ap->ops->thaw) in ata_eh_thaw_port()
1138 ap->ops->thaw(ap); in ata_eh_thaw_port()
1140 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_thaw_port()
1142 DPRINTK("ata%u port thawed\n", ap->print_id); in ata_eh_thaw_port()
1152 struct ata_port *ap = qc->ap; in __ata_eh_qc_complete()
1153 struct scsi_cmnd *scmd = qc->scsicmd; in __ata_eh_qc_complete()
1156 spin_lock_irqsave(ap->lock, flags); in __ata_eh_qc_complete()
1157 qc->scsidone = ata_eh_scsidone; in __ata_eh_qc_complete()
1159 WARN_ON(ata_tag_valid(qc->tag)); in __ata_eh_qc_complete()
1160 spin_unlock_irqrestore(ap->lock, flags); in __ata_eh_qc_complete()
1162 scsi_eh_finish_cmd(scmd, &ap->eh_done_q); in __ata_eh_qc_complete()
1166 * ata_eh_qc_complete - Complete an active ATA command from EH
1174 struct scsi_cmnd *scmd = qc->scsicmd; in ata_eh_qc_complete()
1175 scmd->retries = scmd->allowed; in ata_eh_qc_complete()
1180 * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
1186 * SCSI midlayer limits the number of retries to scmd->allowed.
1187 * scmd->allowed is incremented for commands which get retried
1188 * due to unrelated failures (qc->err_mask is zero).
1192 struct scsi_cmnd *scmd = qc->scsicmd; in ata_eh_qc_retry()
1193 if (!qc->err_mask) in ata_eh_qc_retry()
1194 scmd->allowed++; in ata_eh_qc_retry()
1199 * ata_dev_disable - disable ATA device
1212 if (ata_msg_drv(dev->link->ap)) in ata_dev_disable()
1216 dev->class++; in ata_dev_disable()
1221 ata_ering_clear(&dev->ering); in ata_dev_disable()
1226 * ata_eh_detach_dev - detach ATA device
1236 struct ata_link *link = dev->link; in ata_eh_detach_dev()
1237 struct ata_port *ap = link->ap; in ata_eh_detach_dev()
1238 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_detach_dev()
1243 spin_lock_irqsave(ap->lock, flags); in ata_eh_detach_dev()
1245 dev->flags &= ~ATA_DFLAG_DETACH; in ata_eh_detach_dev()
1248 dev->flags |= ATA_DFLAG_DETACHED; in ata_eh_detach_dev()
1249 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG; in ata_eh_detach_dev()
1252 /* clear per-dev EH info */ in ata_eh_detach_dev()
1253 ata_eh_clear_action(link, dev, &link->eh_info, ATA_EH_PERDEV_MASK); in ata_eh_detach_dev()
1254 ata_eh_clear_action(link, dev, &link->eh_context.i, ATA_EH_PERDEV_MASK); in ata_eh_detach_dev()
1255 ehc->saved_xfer_mode[dev->devno] = 0; in ata_eh_detach_dev()
1256 ehc->saved_ncq_enabled &= ~(1 << dev->devno); in ata_eh_detach_dev()
1258 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_detach_dev()
1262 * ata_eh_about_to_do - about to perform eh_action
1264 * @dev: target ATA dev for per-dev action (can be NULL)
1268 * in @link->eh_info such that eh actions are not unnecessarily
1277 struct ata_port *ap = link->ap; in ata_eh_about_to_do()
1278 struct ata_eh_info *ehi = &link->eh_info; in ata_eh_about_to_do()
1279 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_about_to_do()
1282 spin_lock_irqsave(ap->lock, flags); in ata_eh_about_to_do()
1289 if (!(ehc->i.flags & ATA_EHI_QUIET) && link != ap->slave_link) in ata_eh_about_to_do()
1290 ap->pflags |= ATA_PFLAG_RECOVERED; in ata_eh_about_to_do()
1292 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_about_to_do()
1296 * ata_eh_done - EH action complete
1298 * @dev: target ATA dev for per-dev action (can be NULL)
1302 * in @link->eh_context.
1310 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_done()
1312 ata_eh_clear_action(link, dev, &ehc->i, action); in ata_eh_done()
1316 * ata_err_string - convert err_mask to descriptive string
1355 * atapi_eh_tur - perform ATAPI TEST_UNIT_READY
1386 * ata_eh_request_sense - perform REQUEST_SENSE_DATA_EXT
1399 struct ata_device *dev = qc->dev; in ata_eh_request_sense()
1403 if (qc->ap->pflags & ATA_PFLAG_FROZEN) { in ata_eh_request_sense()
1408 if (!cmd || qc->flags & ATA_QCFLAG_SENSE_VALID) in ata_eh_request_sense()
1411 if (!ata_id_sense_reporting_enabled(dev->id)) { in ata_eh_request_sense()
1412 ata_dev_warn(qc->dev, "sense data reporting disabled\n"); in ata_eh_request_sense()
1428 qc->flags |= ATA_QCFLAG_SENSE_VALID; in ata_eh_request_sense()
1436 * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE
1455 struct ata_port *ap = dev->link->ap; in atapi_eh_request_sense()
1463 * for the case where they are -not- overwritten in atapi_eh_request_sense()
1475 if (ap->flags & ATA_FLAG_PIO_DMA) { in atapi_eh_request_sense()
1489 * ata_eh_analyze_serror - analyze SError for a failed port
1500 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_analyze_serror()
1501 u32 serror = ehc->i.serror; in ata_eh_analyze_serror()
1523 if (link->lpm_policy > ATA_LPM_MAX_POWER) in ata_eh_analyze_serror()
1525 else if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link)) in ata_eh_analyze_serror()
1531 ata_ehi_hotplugged(&ehc->i); in ata_eh_analyze_serror()
1533 ehc->i.err_mask |= err_mask; in ata_eh_analyze_serror()
1534 ehc->i.action |= action; in ata_eh_analyze_serror()
1538 * ata_eh_analyze_tf - analyze taskfile of a failed qc
1556 u8 stat = tf->command, err = tf->feature; in ata_eh_analyze_tf()
1559 qc->err_mask |= AC_ERR_HSM; in ata_eh_analyze_tf()
1564 qc->err_mask |= AC_ERR_DEV; in ata_eh_analyze_tf()
1575 switch (qc->dev->class) { in ata_eh_analyze_tf()
1578 ata_eh_request_sense(qc, qc->scsicmd); in ata_eh_analyze_tf()
1582 qc->err_mask |= AC_ERR_ATA_BUS; in ata_eh_analyze_tf()
1584 qc->err_mask |= AC_ERR_MEDIA; in ata_eh_analyze_tf()
1586 qc->err_mask |= AC_ERR_INVALID; in ata_eh_analyze_tf()
1590 if (!(qc->ap->pflags & ATA_PFLAG_FROZEN)) { in ata_eh_analyze_tf()
1591 tmp = atapi_eh_request_sense(qc->dev, in ata_eh_analyze_tf()
1592 qc->scsicmd->sense_buffer, in ata_eh_analyze_tf()
1593 qc->result_tf.feature >> 4); in ata_eh_analyze_tf()
1595 qc->flags |= ATA_QCFLAG_SENSE_VALID; in ata_eh_analyze_tf()
1597 qc->err_mask |= tmp; in ata_eh_analyze_tf()
1601 if (qc->flags & ATA_QCFLAG_SENSE_VALID) { in ata_eh_analyze_tf()
1602 int ret = scsi_check_sense(qc->scsicmd); in ata_eh_analyze_tf()
1613 qc->flags |= ATA_QCFLAG_RETRY; in ata_eh_analyze_tf()
1614 qc->err_mask |= AC_ERR_OTHER; in ata_eh_analyze_tf()
1616 qc->err_mask |= AC_ERR_HSM; in ata_eh_analyze_tf()
1619 if (qc->err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT | AC_ERR_ATA_BUS)) in ata_eh_analyze_tf()
1664 if ((ent->eflags & ATA_EFLAG_OLD_ER) || (ent->timestamp < arg->since)) in speed_down_verdict_cb()
1665 return -1; in speed_down_verdict_cb()
1667 cat = ata_eh_categorize_error(ent->eflags, ent->err_mask, in speed_down_verdict_cb()
1668 &arg->xfer_ok); in speed_down_verdict_cb()
1669 arg->nr_errors[cat]++; in speed_down_verdict_cb()
1675 * ata_eh_speed_down_verdict - Determine speed down verdict
1702 * taken per error. An action triggered by non-DUBIOUS errors
1740 arg.since = j64 - min(j64, j5mins); in ata_eh_speed_down_verdict()
1741 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); in ata_eh_speed_down_verdict()
1759 arg.since = j64 - min(j64, j10mins); in ata_eh_speed_down_verdict()
1760 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); in ata_eh_speed_down_verdict()
1775 * ata_eh_speed_down - record error and speed down if necessary
1799 /* don't bother if Cat-0 error */ in ata_eh_speed_down()
1804 ata_ering_record(&dev->ering, eflags, err_mask); in ata_eh_speed_down()
1809 (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ | in ata_eh_speed_down()
1811 dev->flags |= ATA_DFLAG_NCQ_OFF; in ata_eh_speed_down()
1825 if (dev->spdn_cnt < 2) { in ata_eh_speed_down()
1832 if (dev->xfer_shift != ATA_SHIFT_PIO) in ata_eh_speed_down()
1833 sel = dma_dnxfer_sel[dev->spdn_cnt]; in ata_eh_speed_down()
1835 sel = pio_dnxfer_sel[dev->spdn_cnt]; in ata_eh_speed_down()
1837 dev->spdn_cnt++; in ata_eh_speed_down()
1849 if ((verdict & ATA_EH_SPDN_FALLBACK_TO_PIO) && (dev->spdn_cnt >= 2) && in ata_eh_speed_down()
1850 (link->ap->cbl != ATA_CBL_SATA || dev->class == ATA_DEV_ATAPI) && in ata_eh_speed_down()
1851 (dev->xfer_shift != ATA_SHIFT_PIO)) { in ata_eh_speed_down()
1853 dev->spdn_cnt = 0; in ata_eh_speed_down()
1863 ata_ering_clear(&dev->ering); in ata_eh_speed_down()
1868 * ata_eh_worth_retry - analyze error and decide whether to retry
1873 * because the drive itself has probably already taken 10-30 seconds
1878 if (qc->err_mask & AC_ERR_MEDIA) in ata_eh_worth_retry()
1880 if (qc->flags & ATA_QCFLAG_IO) in ata_eh_worth_retry()
1882 if (qc->err_mask & AC_ERR_INVALID) in ata_eh_worth_retry()
1884 return qc->err_mask != AC_ERR_DEV; /* retry if not dev error */ in ata_eh_worth_retry()
1888 * ata_eh_quiet - check if we need to be quiet about a command error
1896 if (qc->scsicmd && in ata_eh_quiet()
1897 qc->scsicmd->request->rq_flags & RQF_QUIET) in ata_eh_quiet()
1898 qc->flags |= ATA_QCFLAG_QUIET; in ata_eh_quiet()
1899 return qc->flags & ATA_QCFLAG_QUIET; in ata_eh_quiet()
1903 * ata_eh_link_autopsy - analyze error and determine recovery action
1915 struct ata_port *ap = link->ap; in ata_eh_link_autopsy()
1916 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_link_autopsy()
1926 if (ehc->i.flags & ATA_EHI_NO_AUTOPSY) in ata_eh_link_autopsy()
1932 ehc->i.serror |= serror; in ata_eh_link_autopsy()
1934 } else if (rc != -EOPNOTSUPP) { in ata_eh_link_autopsy()
1936 ehc->i.probe_mask |= ATA_ALL_DEVICES; in ata_eh_link_autopsy()
1937 ehc->i.action |= ATA_EH_RESET; in ata_eh_link_autopsy()
1938 ehc->i.err_mask |= AC_ERR_OTHER; in ata_eh_link_autopsy()
1945 if (ehc->i.err_mask & ~AC_ERR_OTHER) in ata_eh_link_autopsy()
1946 ehc->i.err_mask &= ~AC_ERR_OTHER; in ata_eh_link_autopsy()
1948 all_err_mask |= ehc->i.err_mask; in ata_eh_link_autopsy()
1951 if (!(qc->flags & ATA_QCFLAG_FAILED) || in ata_eh_link_autopsy()
1952 ata_dev_phys_link(qc->dev) != link) in ata_eh_link_autopsy()
1956 qc->err_mask |= ehc->i.err_mask; in ata_eh_link_autopsy()
1959 ehc->i.action |= ata_eh_analyze_tf(qc, &qc->result_tf); in ata_eh_link_autopsy()
1962 if (qc->err_mask & AC_ERR_ATA_BUS) in ata_eh_link_autopsy()
1963 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_MEDIA | in ata_eh_link_autopsy()
1967 if (qc->err_mask & ~AC_ERR_OTHER) in ata_eh_link_autopsy()
1968 qc->err_mask &= ~AC_ERR_OTHER; in ata_eh_link_autopsy()
1977 if (qc->flags & ATA_QCFLAG_SENSE_VALID) in ata_eh_link_autopsy()
1978 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER); in ata_eh_link_autopsy()
1980 qc->flags |= ATA_QCFLAG_RETRY; in ata_eh_link_autopsy()
1983 ehc->i.dev = qc->dev; in ata_eh_link_autopsy()
1984 all_err_mask |= qc->err_mask; in ata_eh_link_autopsy()
1985 if (qc->flags & ATA_QCFLAG_IO) in ata_eh_link_autopsy()
1997 ehc->i.flags |= ATA_EHI_QUIET; in ata_eh_link_autopsy()
2000 if (ap->pflags & ATA_PFLAG_FROZEN || in ata_eh_link_autopsy()
2002 ehc->i.action |= ATA_EH_RESET; in ata_eh_link_autopsy()
2005 ehc->i.action |= ATA_EH_REVALIDATE; in ata_eh_link_autopsy()
2008 * perform per-dev EH action only on the offending device. in ata_eh_link_autopsy()
2010 if (ehc->i.dev) { in ata_eh_link_autopsy()
2011 ehc->i.dev_action[ehc->i.dev->devno] |= in ata_eh_link_autopsy()
2012 ehc->i.action & ATA_EH_PERDEV_MASK; in ata_eh_link_autopsy()
2013 ehc->i.action &= ~ATA_EH_PERDEV_MASK; in ata_eh_link_autopsy()
2018 ap->link.eh_context.i.err_mask |= AC_ERR_TIMEOUT; in ata_eh_link_autopsy()
2021 dev = ehc->i.dev; in ata_eh_link_autopsy()
2023 ata_dev_enabled(link->device)))) in ata_eh_link_autopsy()
2024 dev = link->device; in ata_eh_link_autopsy()
2027 if (dev->flags & ATA_DFLAG_DUBIOUS_XFER) in ata_eh_link_autopsy()
2029 ehc->i.action |= ata_eh_speed_down(dev, eflags, all_err_mask); in ata_eh_link_autopsy()
2030 trace_ata_eh_link_autopsy(dev, ehc->i.action, all_err_mask); in ata_eh_link_autopsy()
2036 * ata_eh_autopsy - analyze error and determine recovery action
2056 if (ap->slave_link) { in ata_eh_autopsy()
2057 struct ata_eh_context *mehc = &ap->link.eh_context; in ata_eh_autopsy()
2058 struct ata_eh_context *sehc = &ap->slave_link->eh_context; in ata_eh_autopsy()
2061 sehc->i.flags |= mehc->i.flags & ATA_EHI_TO_SLAVE_MASK; in ata_eh_autopsy()
2064 ata_eh_link_autopsy(ap->slave_link); in ata_eh_autopsy()
2067 ata_eh_about_to_do(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS); in ata_eh_autopsy()
2068 mehc->i.action |= sehc->i.action; in ata_eh_autopsy()
2069 mehc->i.dev_action[1] |= sehc->i.dev_action[1]; in ata_eh_autopsy()
2070 mehc->i.flags |= sehc->i.flags; in ata_eh_autopsy()
2071 ata_eh_done(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS); in ata_eh_autopsy()
2078 ata_eh_link_autopsy(&ap->link); in ata_eh_autopsy()
2082 * ata_get_cmd_descript - get description for ATA command
2154 { ATA_CMD_TRUSTED_NONDATA, "TRUSTED NON-DATA" }, in ata_get_cmd_descript()
2204 * ata_eh_link_report - report error handling to user
2214 struct ata_port *ap = link->ap; in ata_eh_link_report()
2215 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_link_report()
2221 if (ehc->i.flags & ATA_EHI_QUIET) in ata_eh_link_report()
2225 if (ehc->i.desc[0] != '\0') in ata_eh_link_report()
2226 desc = ehc->i.desc; in ata_eh_link_report()
2229 if (!(qc->flags & ATA_QCFLAG_FAILED) || in ata_eh_link_report()
2230 ata_dev_phys_link(qc->dev) != link || in ata_eh_link_report()
2231 ((qc->flags & ATA_QCFLAG_QUIET) && in ata_eh_link_report()
2232 qc->err_mask == AC_ERR_DEV)) in ata_eh_link_report()
2234 if (qc->flags & ATA_QCFLAG_SENSE_VALID && !qc->err_mask) in ata_eh_link_report()
2240 if (!nr_failed && !ehc->i.err_mask) in ata_eh_link_report()
2244 if (ap->pflags & ATA_PFLAG_FROZEN) in ata_eh_link_report()
2247 if (ap->eh_tries < ATA_EH_MAX_TRIES) in ata_eh_link_report()
2249 ap->eh_tries); in ata_eh_link_report()
2251 if (ehc->i.dev) { in ata_eh_link_report()
2252 ata_dev_err(ehc->i.dev, "exception Emask 0x%x " in ata_eh_link_report()
2254 ehc->i.err_mask, link->sactive, ehc->i.serror, in ata_eh_link_report()
2255 ehc->i.action, frozen, tries_buf); in ata_eh_link_report()
2257 ata_dev_err(ehc->i.dev, "%s\n", desc); in ata_eh_link_report()
2261 ehc->i.err_mask, link->sactive, ehc->i.serror, in ata_eh_link_report()
2262 ehc->i.action, frozen, tries_buf); in ata_eh_link_report()
2268 if (ehc->i.serror) in ata_eh_link_report()
2271 ehc->i.serror & SERR_DATA_RECOVERED ? "RecovData " : "", in ata_eh_link_report()
2272 ehc->i.serror & SERR_COMM_RECOVERED ? "RecovComm " : "", in ata_eh_link_report()
2273 ehc->i.serror & SERR_DATA ? "UnrecovData " : "", in ata_eh_link_report()
2274 ehc->i.serror & SERR_PERSISTENT ? "Persist " : "", in ata_eh_link_report()
2275 ehc->i.serror & SERR_PROTOCOL ? "Proto " : "", in ata_eh_link_report()
2276 ehc->i.serror & SERR_INTERNAL ? "HostInt " : "", in ata_eh_link_report()
2277 ehc->i.serror & SERR_PHYRDY_CHG ? "PHYRdyChg " : "", in ata_eh_link_report()
2278 ehc->i.serror & SERR_PHY_INT_ERR ? "PHYInt " : "", in ata_eh_link_report()
2279 ehc->i.serror & SERR_COMM_WAKE ? "CommWake " : "", in ata_eh_link_report()
2280 ehc->i.serror & SERR_10B_8B_ERR ? "10B8B " : "", in ata_eh_link_report()
2281 ehc->i.serror & SERR_DISPARITY ? "Dispar " : "", in ata_eh_link_report()
2282 ehc->i.serror & SERR_CRC ? "BadCRC " : "", in ata_eh_link_report()
2283 ehc->i.serror & SERR_HANDSHAKE ? "Handshk " : "", in ata_eh_link_report()
2284 ehc->i.serror & SERR_LINK_SEQ_ERR ? "LinkSeq " : "", in ata_eh_link_report()
2285 ehc->i.serror & SERR_TRANS_ST_ERROR ? "TrStaTrns " : "", in ata_eh_link_report()
2286 ehc->i.serror & SERR_UNRECOG_FIS ? "UnrecFIS " : "", in ata_eh_link_report()
2287 ehc->i.serror & SERR_DEV_XCHG ? "DevExch " : ""); in ata_eh_link_report()
2291 struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf; in ata_eh_link_report()
2295 if (!(qc->flags & ATA_QCFLAG_FAILED) || in ata_eh_link_report()
2296 ata_dev_phys_link(qc->dev) != link || !qc->err_mask) in ata_eh_link_report()
2299 if (qc->dma_dir != DMA_NONE) { in ata_eh_link_report()
2307 switch (qc->tf.protocol) { in ata_eh_link_report()
2337 prot_str, qc->nbytes, dma_str[qc->dma_dir]); in ata_eh_link_report()
2340 if (ata_is_atapi(qc->tf.protocol)) { in ata_eh_link_report()
2341 const u8 *cdb = qc->cdb; in ata_eh_link_report()
2342 size_t cdb_len = qc->dev->cdb_len; in ata_eh_link_report()
2344 if (qc->scsicmd) { in ata_eh_link_report()
2345 cdb = qc->scsicmd->cmnd; in ata_eh_link_report()
2346 cdb_len = qc->scsicmd->cmd_len; in ata_eh_link_report()
2351 const char *descr = ata_get_cmd_descript(cmd->command); in ata_eh_link_report()
2353 ata_dev_err(qc->dev, "failed command: %s\n", in ata_eh_link_report()
2357 ata_dev_err(qc->dev, in ata_eh_link_report()
2362 cmd->command, cmd->feature, cmd->nsect, in ata_eh_link_report()
2363 cmd->lbal, cmd->lbam, cmd->lbah, in ata_eh_link_report()
2364 cmd->hob_feature, cmd->hob_nsect, in ata_eh_link_report()
2365 cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah, in ata_eh_link_report()
2366 cmd->device, qc->tag, data_buf, cdb_buf, in ata_eh_link_report()
2367 res->command, res->feature, res->nsect, in ata_eh_link_report()
2368 res->lbal, res->lbam, res->lbah, in ata_eh_link_report()
2369 res->hob_feature, res->hob_nsect, in ata_eh_link_report()
2370 res->hob_lbal, res->hob_lbam, res->hob_lbah, in ata_eh_link_report()
2371 res->device, qc->err_mask, ata_err_string(qc->err_mask), in ata_eh_link_report()
2372 qc->err_mask & AC_ERR_NCQ ? " <F>" : ""); in ata_eh_link_report()
2375 if (res->command & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | in ata_eh_link_report()
2377 if (res->command & ATA_BUSY) in ata_eh_link_report()
2378 ata_dev_err(qc->dev, "status: { Busy }\n"); in ata_eh_link_report()
2380 ata_dev_err(qc->dev, "status: { %s%s%s%s%s}\n", in ata_eh_link_report()
2381 res->command & ATA_DRDY ? "DRDY " : "", in ata_eh_link_report()
2382 res->command & ATA_DF ? "DF " : "", in ata_eh_link_report()
2383 res->command & ATA_DRQ ? "DRQ " : "", in ata_eh_link_report()
2384 res->command & ATA_SENSE ? "SENSE " : "", in ata_eh_link_report()
2385 res->command & ATA_ERR ? "ERR " : ""); in ata_eh_link_report()
2388 if (cmd->command != ATA_CMD_PACKET && in ata_eh_link_report()
2389 (res->feature & (ATA_ICRC | ATA_UNC | ATA_AMNF | in ata_eh_link_report()
2391 ata_dev_err(qc->dev, "error: { %s%s%s%s%s}\n", in ata_eh_link_report()
2392 res->feature & ATA_ICRC ? "ICRC " : "", in ata_eh_link_report()
2393 res->feature & ATA_UNC ? "UNC " : "", in ata_eh_link_report()
2394 res->feature & ATA_AMNF ? "AMNF " : "", in ata_eh_link_report()
2395 res->feature & ATA_IDNF ? "IDNF " : "", in ata_eh_link_report()
2396 res->feature & ATA_ABORTED ? "ABRT " : ""); in ata_eh_link_report()
2402 * ata_eh_report - report error handling to user
2426 classes[dev->devno] = ATA_DEV_UNKNOWN; in ata_do_reset()
2433 if ((link->flags & ATA_LFLAG_NO_SRST) || ata_link_offline(link)) in ata_eh_followup_srst_needed()
2435 if (rc == -EAGAIN) in ata_eh_followup_srst_needed()
2437 if (sata_pmp_supported(link->ap) && ata_is_host_link(link)) in ata_eh_followup_srst_needed()
2446 struct ata_port *ap = link->ap; in ata_eh_reset()
2447 struct ata_link *slave = ap->slave_link; in ata_eh_reset()
2448 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_reset()
2449 struct ata_eh_context *sehc = slave ? &slave->eh_context : NULL; in ata_eh_reset()
2450 unsigned int *classes = ehc->classes; in ata_eh_reset()
2451 unsigned int lflags = link->flags; in ata_eh_reset()
2452 int verbose = !(ehc->i.flags & ATA_EHI_QUIET); in ata_eh_reset()
2467 if (link->flags & ATA_LFLAG_RST_ONCE) in ata_eh_reset()
2469 if (link->flags & ATA_LFLAG_NO_HRST) in ata_eh_reset()
2471 if (link->flags & ATA_LFLAG_NO_SRST) in ata_eh_reset()
2475 if (ehc->i.flags & ATA_EHI_DID_RESET) { in ata_eh_reset()
2477 WARN_ON(time_after(ehc->last_reset, now)); in ata_eh_reset()
2478 deadline = ata_deadline(ehc->last_reset, in ata_eh_reset()
2481 schedule_timeout_uninterruptible(deadline - now); in ata_eh_reset()
2484 spin_lock_irqsave(ap->lock, flags); in ata_eh_reset()
2485 ap->pflags |= ATA_PFLAG_RESETTING; in ata_eh_reset()
2486 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_reset()
2495 * suitable controller mode we should not touch the in ata_eh_reset()
2498 dev->pio_mode = XFER_PIO_0; in ata_eh_reset()
2499 dev->dma_mode = 0xff; in ata_eh_reset()
2503 * touch the DMA setup as that will be dealt with when in ata_eh_reset()
2506 if (ap->ops->set_piomode) in ata_eh_reset()
2507 ap->ops->set_piomode(ap, dev); in ata_eh_reset()
2512 ehc->i.action &= ~ATA_EH_RESET; in ata_eh_reset()
2515 ehc->i.action |= ATA_EH_HARDRESET; in ata_eh_reset()
2518 ehc->i.action |= ATA_EH_SOFTRESET; in ata_eh_reset()
2526 sehc->i.action &= ~ATA_EH_RESET; in ata_eh_reset()
2527 sehc->i.action |= ehc->i.action; in ata_eh_reset()
2534 * -ENOENT or clear ATA_EH_RESET. in ata_eh_reset()
2536 if (slave && (rc == 0 || rc == -ENOENT)) { in ata_eh_reset()
2540 if (tmp != -ENOENT) in ata_eh_reset()
2543 ehc->i.action |= sehc->i.action; in ata_eh_reset()
2547 if (rc == -ENOENT) { in ata_eh_reset()
2548 ata_link_dbg(link, "port disabled--ignoring\n"); in ata_eh_reset()
2549 ehc->i.action &= ~ATA_EH_RESET; in ata_eh_reset()
2552 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2565 if (reset && !(ehc->i.action & ATA_EH_RESET)) { in ata_eh_reset()
2567 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2568 if ((ap->pflags & ATA_PFLAG_FROZEN) && in ata_eh_reset()
2591 ehc->last_reset = jiffies; in ata_eh_reset()
2593 ehc->i.flags |= ATA_EHI_DID_HARDRESET; in ata_eh_reset()
2595 ehc->i.flags |= ATA_EHI_DID_SOFTRESET; in ata_eh_reset()
2598 if (rc && rc != -EAGAIN) { in ata_eh_reset()
2614 case -EAGAIN: in ata_eh_reset()
2615 rc = -EAGAIN; in ata_eh_reset()
2625 /* perform follow-up SRST if necessary */ in ata_eh_reset()
2632 "follow-up softreset required but no softreset available\n"); in ata_eh_reset()
2634 rc = -EINVAL; in ata_eh_reset()
2654 * Post-reset processing in ata_eh_reset()
2661 dev->pio_mode = XFER_PIO_0; in ata_eh_reset()
2662 dev->flags &= ~ATA_DFLAG_SLEEPING; in ata_eh_reset()
2669 classes[dev->devno] = ATA_DEV_ATA; in ata_eh_reset()
2671 classes[dev->devno] = ATA_DEV_SEMB_UNSUP; in ata_eh_reset()
2676 link->sata_spd = (sstatus >> 4) & 0xf; in ata_eh_reset()
2678 slave->sata_spd = (sstatus >> 4) & 0xf; in ata_eh_reset()
2700 * information and re-thaw the port if frozen. As reset is the in ata_eh_reset()
2704 spin_lock_irqsave(link->ap->lock, flags); in ata_eh_reset()
2705 memset(&link->eh_info, 0, sizeof(link->eh_info)); in ata_eh_reset()
2707 memset(&slave->eh_info, 0, sizeof(link->eh_info)); in ata_eh_reset()
2708 ap->pflags &= ~ATA_PFLAG_EH_PENDING; in ata_eh_reset()
2709 spin_unlock_irqrestore(link->ap->lock, flags); in ata_eh_reset()
2711 if (ap->pflags & ATA_PFLAG_FROZEN) in ata_eh_reset()
2725 if (classes[dev->devno] == ATA_DEV_UNKNOWN) { in ata_eh_reset()
2727 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2731 if (ata_class_enabled(classes[dev->devno])) in ata_eh_reset()
2734 classes[dev->devno]); in ata_eh_reset()
2735 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2736 } else if (classes[dev->devno] == ATA_DEV_UNKNOWN) { in ata_eh_reset()
2739 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2749 rc = -EAGAIN; in ata_eh_reset()
2761 ehc->last_reset = jiffies; /* update to completion time */ in ata_eh_reset()
2762 ehc->i.action |= ATA_EH_REVALIDATE; in ata_eh_reset()
2763 link->lpm_policy = ATA_LPM_UNKNOWN; /* reset LPM state */ in ata_eh_reset()
2768 ehc->i.flags &= ~ATA_EHI_HOTPLUGGED; in ata_eh_reset()
2770 sehc->i.flags &= ~ATA_EHI_HOTPLUGGED; in ata_eh_reset()
2772 spin_lock_irqsave(ap->lock, flags); in ata_eh_reset()
2773 ap->pflags &= ~ATA_PFLAG_RESETTING; in ata_eh_reset()
2774 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_reset()
2779 /* if SCR isn't accessible on a fan-out port, PMP needs to be reset */ in ata_eh_reset()
2782 rc = -ERESTART; in ata_eh_reset()
2798 unsigned long delta = deadline - now; in ata_eh_reset()
2812 * They need to be reset - as well as the PMP - before retrying. in ata_eh_reset()
2814 if (rc == -ERESTART) { in ata_eh_reset()
2820 if (try == max_tries - 1) { in ata_eh_reset()
2824 } else if (rc == -EPIPE) in ata_eh_reset()
2850 * Additionally, all write accesses to &ap->park_req_pending in ata_eh_pull_park_action()
2857 * park_req_pending.done is non-zero by the time we reach in ata_eh_pull_park_action()
2864 spin_lock_irqsave(ap->lock, flags); in ata_eh_pull_park_action()
2865 reinit_completion(&ap->park_req_pending); in ata_eh_pull_park_action()
2868 struct ata_eh_info *ehi = &link->eh_info; in ata_eh_pull_park_action()
2870 link->eh_context.i.dev_action[dev->devno] |= in ata_eh_pull_park_action()
2871 ehi->dev_action[dev->devno] & ATA_EH_PARK; in ata_eh_pull_park_action()
2875 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_pull_park_action()
2880 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_park_issue_cmd()
2886 ehc->unloaded_mask |= 1 << dev->devno; in ata_eh_park_issue_cmd()
2893 ehc->unloaded_mask &= ~(1 << dev->devno); in ata_eh_park_issue_cmd()
2902 ehc->unloaded_mask &= ~(1 << dev->devno); in ata_eh_park_issue_cmd()
2909 struct ata_port *ap = link->ap; in ata_eh_revalidate_and_attach()
2910 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_revalidate_and_attach()
2919 * be done backwards such that PDIAG- is released by the slave in ata_eh_revalidate_and_attach()
2926 if (ehc->i.flags & ATA_EHI_DID_RESET) in ata_eh_revalidate_and_attach()
2930 WARN_ON(dev->class == ATA_DEV_PMP); in ata_eh_revalidate_and_attach()
2933 rc = -EIO; in ata_eh_revalidate_and_attach()
2938 rc = ata_dev_revalidate(dev, ehc->classes[dev->devno], in ata_eh_revalidate_and_attach()
2948 ehc->i.flags |= ATA_EHI_SETMODE; in ata_eh_revalidate_and_attach()
2951 schedule_work(&(ap->scsi_rescan_task)); in ata_eh_revalidate_and_attach()
2952 } else if (dev->class == ATA_DEV_UNKNOWN && in ata_eh_revalidate_and_attach()
2953 ehc->tries[dev->devno] && in ata_eh_revalidate_and_attach()
2954 ata_class_enabled(ehc->classes[dev->devno])) { in ata_eh_revalidate_and_attach()
2955 /* Temporarily set dev->class, it will be in ata_eh_revalidate_and_attach()
2961 dev->class = ehc->classes[dev->devno]; in ata_eh_revalidate_and_attach()
2963 if (dev->class == ATA_DEV_PMP) in ata_eh_revalidate_and_attach()
2966 rc = ata_dev_read_id(dev, &dev->class, in ata_eh_revalidate_and_attach()
2967 readid_flags, dev->id); in ata_eh_revalidate_and_attach()
2970 ehc->classes[dev->devno] = dev->class; in ata_eh_revalidate_and_attach()
2971 dev->class = ATA_DEV_UNKNOWN; in ata_eh_revalidate_and_attach()
2976 ata_ering_clear(&dev->ering); in ata_eh_revalidate_and_attach()
2977 new_mask |= 1 << dev->devno; in ata_eh_revalidate_and_attach()
2979 case -ENOENT: in ata_eh_revalidate_and_attach()
2980 /* IDENTIFY was issued to non-existent in ata_eh_revalidate_and_attach()
2992 /* PDIAG- should have been released, ask cable type if post-reset */ in ata_eh_revalidate_and_attach()
2993 if ((ehc->i.flags & ATA_EHI_DID_RESET) && ata_is_host_link(link)) { in ata_eh_revalidate_and_attach()
2994 if (ap->ops->cable_detect) in ata_eh_revalidate_and_attach()
2995 ap->cbl = ap->ops->cable_detect(ap); in ata_eh_revalidate_and_attach()
3003 if (!(new_mask & (1 << dev->devno))) in ata_eh_revalidate_and_attach()
3006 dev->class = ehc->classes[dev->devno]; in ata_eh_revalidate_and_attach()
3008 if (dev->class == ATA_DEV_PMP) in ata_eh_revalidate_and_attach()
3011 ehc->i.flags |= ATA_EHI_PRINTINFO; in ata_eh_revalidate_and_attach()
3013 ehc->i.flags &= ~ATA_EHI_PRINTINFO; in ata_eh_revalidate_and_attach()
3015 dev->class = ATA_DEV_UNKNOWN; in ata_eh_revalidate_and_attach()
3019 spin_lock_irqsave(ap->lock, flags); in ata_eh_revalidate_and_attach()
3020 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG; in ata_eh_revalidate_and_attach()
3021 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_revalidate_and_attach()
3024 ehc->i.flags |= ATA_EHI_SETMODE; in ata_eh_revalidate_and_attach()
3036 * ata_set_mode - Program timings and issue SET FEATURES - XFER
3052 struct ata_port *ap = link->ap; in ata_set_mode()
3058 if (!(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) { in ata_set_mode()
3061 ent = ata_ering_top(&dev->ering); in ata_set_mode()
3063 ent->eflags &= ~ATA_EFLAG_DUBIOUS_XFER; in ata_set_mode()
3068 if (ap->ops->set_mode) in ata_set_mode()
3069 rc = ap->ops->set_mode(link, r_failed_dev); in ata_set_mode()
3075 struct ata_eh_context *ehc = &link->eh_context; in ata_set_mode()
3076 u8 saved_xfer_mode = ehc->saved_xfer_mode[dev->devno]; in ata_set_mode()
3077 u8 saved_ncq = !!(ehc->saved_ncq_enabled & (1 << dev->devno)); in ata_set_mode()
3079 if (dev->xfer_mode != saved_xfer_mode || in ata_set_mode()
3081 dev->flags |= ATA_DFLAG_DUBIOUS_XFER; in ata_set_mode()
3088 * atapi_eh_clear_ua - Clear ATAPI UNIT ATTENTION after reset
3099 * 0 on success, -errno on failure.
3106 u8 *sense_buffer = dev->link->ap->sector_buf; in atapi_eh_clear_ua()
3115 return -EIO; in atapi_eh_clear_ua()
3125 return -EIO; in atapi_eh_clear_ua()
3136 * ata_eh_maybe_retry_flush - Retry FLUSH if necessary
3150 * 0 if EH can continue, -errno if EH needs to be repeated.
3154 struct ata_link *link = dev->link; in ata_eh_maybe_retry_flush()
3155 struct ata_port *ap = link->ap; in ata_eh_maybe_retry_flush()
3162 if (!ata_tag_valid(link->active_tag)) in ata_eh_maybe_retry_flush()
3165 qc = __ata_qc_from_tag(ap, link->active_tag); in ata_eh_maybe_retry_flush()
3166 if (qc->dev != dev || (qc->tf.command != ATA_CMD_FLUSH_EXT && in ata_eh_maybe_retry_flush()
3167 qc->tf.command != ATA_CMD_FLUSH)) in ata_eh_maybe_retry_flush()
3171 if (qc->err_mask & AC_ERR_DEV) in ata_eh_maybe_retry_flush()
3177 tf.command = qc->tf.command; in ata_eh_maybe_retry_flush()
3182 tf.command, qc->err_mask); in ata_eh_maybe_retry_flush()
3190 * retrying it should do the trick - whatever was in in ata_eh_maybe_retry_flush()
3194 qc->scsicmd->allowed = max(qc->scsicmd->allowed, 1); in ata_eh_maybe_retry_flush()
3198 rc = -EIO; in ata_eh_maybe_retry_flush()
3202 qc->err_mask |= AC_ERR_DEV; in ata_eh_maybe_retry_flush()
3203 qc->result_tf = tf; in ata_eh_maybe_retry_flush()
3204 if (!(ap->pflags & ATA_PFLAG_FROZEN)) in ata_eh_maybe_retry_flush()
3212 * ata_eh_set_lpm - configure SATA interface power management
3226 * 0 on success, -errno on failure.
3231 struct ata_port *ap = ata_is_host_link(link) ? link->ap : NULL; in ata_eh_set_lpm()
3232 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_set_lpm()
3234 enum ata_lpm_policy old_policy = link->lpm_policy; in ata_eh_set_lpm()
3235 bool no_dipm = link->ap->flags & ATA_FLAG_NO_DIPM; in ata_eh_set_lpm()
3242 (link->flags & ATA_LFLAG_NO_LPM) || (ap && !ap->ops->set_lpm)) in ata_eh_set_lpm()
3252 bool hipm = ata_id_has_hipm(dev->id); in ata_eh_set_lpm()
3253 bool dipm = ata_id_has_dipm(dev->id) && !no_dipm; in ata_eh_set_lpm()
3274 rc = -EIO; in ata_eh_set_lpm()
3281 rc = ap->ops->set_lpm(link, policy, hints); in ata_eh_set_lpm()
3282 if (!rc && ap->slave_link) in ata_eh_set_lpm()
3283 rc = ap->ops->set_lpm(ap->slave_link, policy, hints); in ata_eh_set_lpm()
3292 if (rc == -EOPNOTSUPP) { in ata_eh_set_lpm()
3293 link->flags |= ATA_LFLAG_NO_LPM; in ata_eh_set_lpm()
3304 link->lpm_policy = policy; in ata_eh_set_lpm()
3305 if (ap && ap->slave_link) in ata_eh_set_lpm()
3306 ap->slave_link->lpm_policy = policy; in ata_eh_set_lpm()
3311 ata_id_has_dipm(dev->id)) { in ata_eh_set_lpm()
3318 rc = -EIO; in ata_eh_set_lpm()
3324 link->last_lpm_change = jiffies; in ata_eh_set_lpm()
3325 link->flags |= ATA_LFLAG_CHANGED; in ata_eh_set_lpm()
3331 link->lpm_policy = old_policy; in ata_eh_set_lpm()
3332 if (ap && ap->slave_link) in ata_eh_set_lpm()
3333 ap->slave_link->lpm_policy = old_policy; in ata_eh_set_lpm()
3336 if (!dev || ehc->tries[dev->devno] <= 2) { in ata_eh_set_lpm()
3338 link->flags |= ATA_LFLAG_NO_LPM; in ata_eh_set_lpm()
3361 if (dev->class == ATA_DEV_UNKNOWN) in ata_link_nr_vacant()
3368 struct ata_port *ap = link->ap; in ata_eh_skip_recovery()
3369 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_skip_recovery()
3373 if (link->flags & ATA_LFLAG_DISABLED) in ata_eh_skip_recovery()
3377 if (ehc->i.flags & ATA_EHI_NO_RECOVERY) in ata_eh_skip_recovery()
3381 if ((ap->pflags & ATA_PFLAG_FROZEN) || ata_link_nr_enabled(link)) in ata_eh_skip_recovery()
3385 if ((ehc->i.action & ATA_EH_RESET) && in ata_eh_skip_recovery()
3386 !(ehc->i.flags & ATA_EHI_DID_RESET)) in ata_eh_skip_recovery()
3391 if (dev->class == ATA_DEV_UNKNOWN && in ata_eh_skip_recovery()
3392 ehc->classes[dev->devno] != ATA_DEV_NONE) in ata_eh_skip_recovery()
3405 if ((ent->eflags & ATA_EFLAG_OLD_ER) || in ata_count_probe_trials_cb()
3406 (ent->timestamp < now - min(now, interval))) in ata_count_probe_trials_cb()
3407 return -1; in ata_count_probe_trials_cb()
3415 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_schedule_probe()
3419 if (!(ehc->i.probe_mask & (1 << dev->devno)) || in ata_eh_schedule_probe()
3420 (ehc->did_probe_mask & (1 << dev->devno))) in ata_eh_schedule_probe()
3425 ehc->did_probe_mask |= (1 << dev->devno); in ata_eh_schedule_probe()
3426 ehc->i.action |= ATA_EH_RESET; in ata_eh_schedule_probe()
3427 ehc->saved_xfer_mode[dev->devno] = 0; in ata_eh_schedule_probe()
3428 ehc->saved_ncq_enabled &= ~(1 << dev->devno); in ata_eh_schedule_probe()
3430 /* the link maybe in a deep sleep, wake it up */ in ata_eh_schedule_probe()
3431 if (link->lpm_policy > ATA_LPM_MAX_POWER) { in ata_eh_schedule_probe()
3433 link->ap->ops->set_lpm(link, ATA_LPM_MAX_POWER, in ata_eh_schedule_probe()
3453 ata_ering_record(&dev->ering, 0, AC_ERR_OTHER); in ata_eh_schedule_probe()
3454 ata_ering_map(&dev->ering, ata_count_probe_trials_cb, &trials); in ata_eh_schedule_probe()
3464 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_handle_dev_fail()
3466 /* -EAGAIN from EH routine indicates retry without prejudice. in ata_eh_handle_dev_fail()
3469 if (err != -EAGAIN) in ata_eh_handle_dev_fail()
3470 ehc->tries[dev->devno]--; in ata_eh_handle_dev_fail()
3473 case -ENODEV: in ata_eh_handle_dev_fail()
3475 ehc->i.probe_mask |= (1 << dev->devno); in ata_eh_handle_dev_fail()
3477 case -EINVAL: in ata_eh_handle_dev_fail()
3479 ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1); in ata_eh_handle_dev_fail()
3481 case -EIO: in ata_eh_handle_dev_fail()
3482 if (ehc->tries[dev->devno] == 1) { in ata_eh_handle_dev_fail()
3487 if (dev->pio_mode > XFER_PIO_0) in ata_eh_handle_dev_fail()
3492 if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) { in ata_eh_handle_dev_fail()
3502 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; in ata_eh_handle_dev_fail()
3503 memset(ehc->cmd_timeout_idx[dev->devno], 0, in ata_eh_handle_dev_fail()
3504 sizeof(ehc->cmd_timeout_idx[dev->devno])); in ata_eh_handle_dev_fail()
3509 ehc->i.action |= ATA_EH_RESET; in ata_eh_handle_dev_fail()
3515 * ata_eh_recover - recover host port after error
3534 * 0 on success, -errno on failure.
3550 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3552 /* re-enable link? */ in ata_eh_recover()
3553 if (ehc->i.action & ATA_EH_ENABLE_LINK) { in ata_eh_recover()
3555 spin_lock_irqsave(ap->lock, flags); in ata_eh_recover()
3556 link->flags &= ~ATA_LFLAG_DISABLED; in ata_eh_recover()
3557 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_recover()
3562 if (link->flags & ATA_LFLAG_NO_RETRY) in ata_eh_recover()
3563 ehc->tries[dev->devno] = 1; in ata_eh_recover()
3565 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; in ata_eh_recover()
3568 ehc->i.action |= ehc->i.dev_action[dev->devno] & in ata_eh_recover()
3570 ehc->i.dev_action[dev->devno] &= ATA_EH_PERDEV_MASK; in ata_eh_recover()
3573 if (dev->flags & ATA_DFLAG_DETACH) in ata_eh_recover()
3586 if (ap->pflags & ATA_PFLAG_UNLOADING) in ata_eh_recover()
3591 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3595 ehc->i.action = 0; in ata_eh_recover()
3598 ehc->classes[dev->devno] = ATA_DEV_UNKNOWN; in ata_eh_recover()
3603 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3605 if (!(ehc->i.action & ATA_EH_RESET)) in ata_eh_recover()
3621 * ap->park_req_pending in ata_eh_recover()
3628 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3631 if (dev->class != ATA_DEV_ATA && in ata_eh_recover()
3632 dev->class != ATA_DEV_ZAC) in ata_eh_recover()
3634 if (!(ehc->i.dev_action[dev->devno] & in ata_eh_recover()
3637 tmp = dev->unpark_deadline; in ata_eh_recover()
3642 if (ehc->unloaded_mask & (1 << dev->devno)) in ata_eh_recover()
3654 deadline = wait_for_completion_timeout(&ap->park_req_pending, in ata_eh_recover()
3655 deadline - now); in ata_eh_recover()
3660 if (!(link->eh_context.unloaded_mask & in ata_eh_recover()
3661 (1 << dev->devno))) in ata_eh_recover()
3672 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3683 if (link->device->class == ATA_DEV_PMP) { in ata_eh_recover()
3684 ehc->i.action = 0; in ata_eh_recover()
3689 if (ehc->i.flags & ATA_EHI_SETMODE) { in ata_eh_recover()
3693 ehc->i.flags &= ~ATA_EHI_SETMODE; in ata_eh_recover()
3699 if (ehc->i.flags & ATA_EHI_DID_RESET) { in ata_eh_recover()
3701 if (dev->class != ATA_DEV_ATAPI) in ata_eh_recover()
3713 if (dev->class != ATA_DEV_ATA && in ata_eh_recover()
3714 dev->class != ATA_DEV_ZAC) in ata_eh_recover()
3723 if (link->lpm_policy != ap->target_lpm_policy) { in ata_eh_recover()
3724 rc = ata_eh_set_lpm(link, ap->target_lpm_policy, &dev); in ata_eh_recover()
3730 ehc->i.flags = 0; in ata_eh_recover()
3738 if (ap->pflags & ATA_PFLAG_FROZEN) { in ata_eh_recover()
3760 * ata_eh_finish - finish up EH
3776 if (!(qc->flags & ATA_QCFLAG_FAILED)) in ata_eh_finish()
3779 if (qc->err_mask) { in ata_eh_finish()
3784 if (qc->flags & ATA_QCFLAG_RETRY) in ata_eh_finish()
3789 if (qc->flags & ATA_QCFLAG_SENSE_VALID) { in ata_eh_finish()
3793 memset(&qc->result_tf, 0, sizeof(qc->result_tf)); in ata_eh_finish()
3800 WARN_ON(ap->nr_active_links); in ata_eh_finish()
3801 ap->nr_active_links = 0; in ata_eh_finish()
3805 * ata_do_eh - do standard error handling
3831 ata_for_each_dev(dev, &ap->link, ALL) in ata_do_eh()
3839 * ata_std_error_handler - standard error handler
3849 struct ata_port_operations *ops = ap->ops; in ata_std_error_handler()
3850 ata_reset_fn_t hardreset = ops->hardreset; in ata_std_error_handler()
3852 /* ignore built-in hardreset if SCR access is not available */ in ata_std_error_handler()
3853 if (hardreset == sata_std_hardreset && !sata_scr_valid(&ap->link)) in ata_std_error_handler()
3856 ata_do_eh(ap, ops->prereset, ops->softreset, hardreset, ops->postreset); in ata_std_error_handler()
3862 * ata_eh_handle_port_suspend - perform port suspend operation
3877 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_suspend()
3878 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) || in ata_eh_handle_port_suspend()
3879 ap->pm_mesg.event & PM_EVENT_RESUME) { in ata_eh_handle_port_suspend()
3880 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_suspend()
3883 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_suspend()
3885 WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED); in ata_eh_handle_port_suspend()
3892 if (PMSG_IS_AUTO(ap->pm_mesg)) { in ata_eh_handle_port_suspend()
3893 ata_for_each_dev(dev, &ap->link, ENABLED) { in ata_eh_handle_port_suspend()
3907 if (ap->ops->port_suspend) in ata_eh_handle_port_suspend()
3908 rc = ap->ops->port_suspend(ap, ap->pm_mesg); in ata_eh_handle_port_suspend()
3910 ata_acpi_set_state(ap, ap->pm_mesg); in ata_eh_handle_port_suspend()
3913 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_suspend()
3915 ap->pflags &= ~ATA_PFLAG_PM_PENDING; in ata_eh_handle_port_suspend()
3917 ap->pflags |= ATA_PFLAG_SUSPENDED; in ata_eh_handle_port_suspend()
3918 else if (ap->pflags & ATA_PFLAG_FROZEN) in ata_eh_handle_port_suspend()
3921 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_suspend()
3927 * ata_eh_handle_port_resume - perform port resume operation
3942 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_resume()
3943 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) || in ata_eh_handle_port_resume()
3944 !(ap->pm_mesg.event & PM_EVENT_RESUME)) { in ata_eh_handle_port_resume()
3945 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_resume()
3948 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_resume()
3950 WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED)); in ata_eh_handle_port_resume()
3961 ata_ering_clear(&dev->ering); in ata_eh_handle_port_resume()
3963 ata_acpi_set_state(ap, ap->pm_mesg); in ata_eh_handle_port_resume()
3965 if (ap->ops->port_resume) in ata_eh_handle_port_resume()
3966 ap->ops->port_resume(ap); in ata_eh_handle_port_resume()
3972 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_resume()
3973 ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED); in ata_eh_handle_port_resume()
3974 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_resume()