Lines Matching +full:pull +full:- +full:downs
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
97 15000, /* Some drives are slow to read log pages when waking-up */
129 * ehc->cmd_timeout_idx keeps track of which timeout to use per
168 ehi->desc_len += vscnprintf(ehi->desc + ehi->desc_len, in __ata_ehi_pushv_desc()
169 ATA_EH_DESC_LEN - ehi->desc_len, in __ata_ehi_pushv_desc()
174 * __ata_ehi_push_desc - push error description without adding separator
178 * Format string according to @fmt and append it to @ehi->desc.
194 * ata_ehi_push_desc - push error description with separator
198 * Format string according to @fmt and append it to @ehi->desc.
199 * If @ehi->desc is not empty, ", " is added in-between.
208 if (ehi->desc_len) in ata_ehi_push_desc()
218 * ata_ehi_clear_desc - clean error description
221 * Clear @ehi->desc.
228 ehi->desc[0] = '\0'; in ata_ehi_clear_desc()
229 ehi->desc_len = 0; in ata_ehi_clear_desc()
234 * ata_port_desc - append port description
240 * in-between. This function is to be used while initializing
250 WARN_ON(!(ap->pflags & ATA_PFLAG_INITIALIZING)); in ata_port_desc()
252 if (ap->link.eh_info.desc_len) in ata_port_desc()
253 __ata_ehi_push_desc(&ap->link.eh_info, " "); in ata_port_desc()
256 __ata_ehi_pushv_desc(&ap->link.eh_info, fmt, args); in ata_port_desc()
263 * ata_port_pbar_desc - append PCI BAR description
280 struct pci_dev *pdev = to_pci_dev(ap->host->dev); in ata_port_pbar_desc()
313 return -1; in ata_lookup_timeout_table()
317 * ata_internal_cmd_timeout - determine timeout for an internal command
331 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_internal_cmd_timeout()
338 idx = ehc->cmd_timeout_idx[dev->devno][ent]; in ata_internal_cmd_timeout()
343 * ata_internal_cmd_timed_out - notification for internal command timeout
356 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_internal_cmd_timed_out()
363 idx = ehc->cmd_timeout_idx[dev->devno][ent]; in ata_internal_cmd_timed_out()
365 ehc->cmd_timeout_idx[dev->devno][ent]++; in ata_internal_cmd_timed_out()
375 ering->cursor++; in ata_ering_record()
376 ering->cursor %= ATA_ERING_SIZE; in ata_ering_record()
378 ent = &ering->ring[ering->cursor]; in ata_ering_record()
379 ent->eflags = eflags; in ata_ering_record()
380 ent->err_mask = err_mask; in ata_ering_record()
381 ent->timestamp = get_jiffies_64(); in ata_ering_record()
386 struct ata_ering_entry *ent = &ering->ring[ering->cursor]; in ata_ering_top()
388 if (ent->err_mask) in ata_ering_top()
400 idx = ering->cursor; in ata_ering_map()
402 ent = &ering->ring[idx]; in ata_ering_map()
403 if (!ent->err_mask) in ata_ering_map()
408 idx = (idx - 1 + ATA_ERING_SIZE) % ATA_ERING_SIZE; in ata_ering_map()
409 } while (idx != ering->cursor); in ata_ering_map()
416 ent->eflags |= ATA_EFLAG_OLD_ER; in ata_ering_clear_cb()
427 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_dev_action()
429 return ehc->i.action | ehc->i.dev_action[dev->devno]; in ata_eh_dev_action()
438 ehi->action &= ~action; in ata_eh_clear_action()
440 ehi->dev_action[tdev->devno] &= ~action; in ata_eh_clear_action()
442 /* doesn't make sense for port-wide EH actions */ in ata_eh_clear_action()
445 /* break ehi->action into ehi->dev_action */ in ata_eh_clear_action()
446 if (ehi->action & action) { in ata_eh_clear_action()
448 ehi->dev_action[tdev->devno] |= in ata_eh_clear_action()
449 ehi->action & action; in ata_eh_clear_action()
450 ehi->action &= ~action; in ata_eh_clear_action()
453 /* turn off the specified per-dev action */ in ata_eh_clear_action()
454 ehi->dev_action[dev->devno] &= ~action; in ata_eh_clear_action()
459 * ata_eh_acquire - acquire EH ownership
471 mutex_lock(&ap->host->eh_mutex); in ata_eh_acquire()
472 WARN_ON_ONCE(ap->host->eh_owner); in ata_eh_acquire()
473 ap->host->eh_owner = current; in ata_eh_acquire()
477 * ata_eh_release - release EH ownership
488 WARN_ON_ONCE(ap->host->eh_owner != current); in ata_eh_release()
489 ap->host->eh_owner = NULL; in ata_eh_release()
490 mutex_unlock(&ap->host->eh_mutex); in ata_eh_release()
503 sata_scr_write(link, SCR_CONTROL, link->saved_scontrol & 0xff0); in ata_eh_unload()
509 spin_lock_irqsave(ap->lock, flags); in ata_eh_unload()
512 ap->pflags &= ~ATA_PFLAG_EH_PENDING; /* clear pending from freeze */ in ata_eh_unload()
513 ap->pflags |= ATA_PFLAG_UNLOADED; in ata_eh_unload()
515 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_unload()
519 * ata_scsi_error - SCSI layer error handler callback
522 * Handles SCSI-layer-thrown error events.
538 spin_lock_irqsave(host->host_lock, flags); in ata_scsi_error()
539 list_splice_init(&host->eh_cmd_q, &eh_work_q); in ata_scsi_error()
540 spin_unlock_irqrestore(host->host_lock, flags); in ata_scsi_error()
555 * ata_scsi_cmd_error_handler - error callback for a list of commands
561 * ap->eh_done_q. This function is the first part of the libata error
575 /* For new EH, all qcs are finished in one of three ways - in ata_scsi_cmd_error_handler()
587 spin_lock_irqsave(ap->lock, flags); in ata_scsi_cmd_error_handler()
588 if (ap->ops->error_handler) { in ata_scsi_cmd_error_handler()
592 /* This must occur under the ap->lock as we don't want in ata_scsi_cmd_error_handler()
596 non-notified command and completes much like an IRQ handler. in ata_scsi_cmd_error_handler()
601 if (ap->ops->lost_interrupt) in ata_scsi_cmd_error_handler()
602 ap->ops->lost_interrupt(ap); in ata_scsi_cmd_error_handler()
608 if (qc->flags & ATA_QCFLAG_ACTIVE && in ata_scsi_cmd_error_handler()
609 qc->scsicmd == scmd) in ata_scsi_cmd_error_handler()
615 if (!(qc->flags & ATA_QCFLAG_FAILED)) { in ata_scsi_cmd_error_handler()
617 qc->err_mask |= AC_ERR_TIMEOUT; in ata_scsi_cmd_error_handler()
618 qc->flags |= ATA_QCFLAG_FAILED; in ata_scsi_cmd_error_handler()
626 scmd->retries = scmd->allowed; in ata_scsi_cmd_error_handler()
627 scsi_eh_finish_cmd(scmd, &ap->eh_done_q); in ata_scsi_cmd_error_handler()
642 ap->eh_tries = ATA_EH_MAX_TRIES; in ata_scsi_cmd_error_handler()
644 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_cmd_error_handler()
650 * ata_scsi_port_error_handler - recover the port after the commands
662 if (ap->ops->error_handler) { in ata_scsi_port_error_handler()
669 del_timer_sync(&ap->fastdrain_timer); in ata_scsi_port_error_handler()
675 spin_lock_irqsave(ap->lock, flags); in ata_scsi_port_error_handler()
678 struct ata_eh_context *ehc = &link->eh_context; in ata_scsi_port_error_handler()
681 memset(&link->eh_context, 0, sizeof(link->eh_context)); in ata_scsi_port_error_handler()
682 link->eh_context.i = link->eh_info; in ata_scsi_port_error_handler()
683 memset(&link->eh_info, 0, sizeof(link->eh_info)); in ata_scsi_port_error_handler()
686 int devno = dev->devno; in ata_scsi_port_error_handler()
688 ehc->saved_xfer_mode[devno] = dev->xfer_mode; in ata_scsi_port_error_handler()
690 ehc->saved_ncq_enabled |= 1 << devno; in ata_scsi_port_error_handler()
694 ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS; in ata_scsi_port_error_handler()
695 ap->pflags &= ~ATA_PFLAG_EH_PENDING; in ata_scsi_port_error_handler()
696 ap->excl_link = NULL; /* don't maintain exclusion over EH */ in ata_scsi_port_error_handler()
698 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
701 if (!(ap->pflags & (ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED))) in ata_scsi_port_error_handler()
702 ap->ops->error_handler(ap); in ata_scsi_port_error_handler()
705 if ((ap->pflags & ATA_PFLAG_UNLOADING) && in ata_scsi_port_error_handler()
706 !(ap->pflags & ATA_PFLAG_UNLOADED)) in ata_scsi_port_error_handler()
714 /* Exception might have happened after ->error_handler in ata_scsi_port_error_handler()
718 spin_lock_irqsave(ap->lock, flags); in ata_scsi_port_error_handler()
720 if (ap->pflags & ATA_PFLAG_EH_PENDING) { in ata_scsi_port_error_handler()
721 if (--ap->eh_tries) { in ata_scsi_port_error_handler()
722 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
728 ap->pflags &= ~ATA_PFLAG_EH_PENDING; in ata_scsi_port_error_handler()
733 memset(&link->eh_info, 0, sizeof(link->eh_info)); in ata_scsi_port_error_handler()
736 * ap->lock such that if exception occurs after this in ata_scsi_port_error_handler()
738 * re-initiate EH. in ata_scsi_port_error_handler()
740 ap->ops->end_eh(ap); in ata_scsi_port_error_handler()
742 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
745 WARN_ON(ata_qc_from_tag(ap, ap->link.active_tag) == NULL); in ata_scsi_port_error_handler()
746 ap->ops->eng_timeout(ap); in ata_scsi_port_error_handler()
749 scsi_eh_flush_done_q(&ap->eh_done_q); in ata_scsi_port_error_handler()
752 spin_lock_irqsave(ap->lock, flags); in ata_scsi_port_error_handler()
754 if (ap->pflags & ATA_PFLAG_LOADING) in ata_scsi_port_error_handler()
755 ap->pflags &= ~ATA_PFLAG_LOADING; in ata_scsi_port_error_handler()
756 else if ((ap->pflags & ATA_PFLAG_SCSI_HOTPLUG) && in ata_scsi_port_error_handler()
757 !(ap->flags & ATA_FLAG_SAS_HOST)) in ata_scsi_port_error_handler()
758 schedule_delayed_work(&ap->hotplug_task, 0); in ata_scsi_port_error_handler()
760 if (ap->pflags & ATA_PFLAG_RECOVERED) in ata_scsi_port_error_handler()
763 ap->pflags &= ~(ATA_PFLAG_SCSI_HOTPLUG | ATA_PFLAG_RECOVERED); in ata_scsi_port_error_handler()
766 ap->pflags &= ~ATA_PFLAG_EH_IN_PROGRESS; in ata_scsi_port_error_handler()
767 wake_up_all(&ap->eh_wait_q); in ata_scsi_port_error_handler()
769 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
774 * ata_port_wait_eh - Wait for the currently pending EH to complete
788 spin_lock_irqsave(ap->lock, flags); in ata_port_wait_eh()
790 while (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) { in ata_port_wait_eh()
791 prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE); in ata_port_wait_eh()
792 spin_unlock_irqrestore(ap->lock, flags); in ata_port_wait_eh()
794 spin_lock_irqsave(ap->lock, flags); in ata_port_wait_eh()
796 finish_wait(&ap->eh_wait_q, &wait); in ata_port_wait_eh()
798 spin_unlock_irqrestore(ap->lock, flags); in ata_port_wait_eh()
801 if (scsi_host_in_recovery(ap->scsi_host)) { in ata_port_wait_eh()
814 /* count only non-internal commands */ in ata_eh_nr_in_flight()
829 spin_lock_irqsave(ap->lock, flags); in ata_eh_fastdrain_timerfn()
837 if (cnt == ap->fastdrain_cnt) { in ata_eh_fastdrain_timerfn()
842 * in-flight qcs as timed out and freeze the port. in ata_eh_fastdrain_timerfn()
846 qc->err_mask |= AC_ERR_TIMEOUT; in ata_eh_fastdrain_timerfn()
852 ap->fastdrain_cnt = cnt; in ata_eh_fastdrain_timerfn()
853 ap->fastdrain_timer.expires = in ata_eh_fastdrain_timerfn()
855 add_timer(&ap->fastdrain_timer); in ata_eh_fastdrain_timerfn()
859 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_fastdrain_timerfn()
863 * ata_eh_set_pending - set ATA_PFLAG_EH_PENDING and activate fast drain
868 * is non-zero and EH wasn't pending before. Fast drain ensures
879 if (ap->pflags & ATA_PFLAG_EH_PENDING) in ata_eh_set_pending()
882 ap->pflags |= ATA_PFLAG_EH_PENDING; in ata_eh_set_pending()
887 /* do we have in-flight qcs? */ in ata_eh_set_pending()
893 ap->fastdrain_cnt = cnt; in ata_eh_set_pending()
894 ap->fastdrain_timer.expires = in ata_eh_set_pending()
896 add_timer(&ap->fastdrain_timer); in ata_eh_set_pending()
900 * ata_qc_schedule_eh - schedule qc for error handling
911 struct ata_port *ap = qc->ap; in ata_qc_schedule_eh()
913 WARN_ON(!ap->ops->error_handler); in ata_qc_schedule_eh()
915 qc->flags |= ATA_QCFLAG_FAILED; in ata_qc_schedule_eh()
923 blk_abort_request(qc->scsicmd->request); in ata_qc_schedule_eh()
927 * ata_std_sched_eh - non-libsas ata_ports issue eh with this common routine
935 WARN_ON(!ap->ops->error_handler); in ata_std_sched_eh()
937 if (ap->pflags & ATA_PFLAG_INITIALIZING) in ata_std_sched_eh()
941 scsi_schedule_eh(ap->scsi_host); in ata_std_sched_eh()
948 * ata_std_end_eh - non-libsas ata_ports complete eh with this common routine
952 * shost, so host fields can be directly manipulated under ap->lock, in
953 * the libsas case we need to hold a lock at the ha->level to coordinate
961 struct Scsi_Host *host = ap->scsi_host; in ata_std_end_eh()
963 host->host_eh_scheduled = 0; in ata_std_end_eh()
969 * ata_port_schedule_eh - schedule error handling without a qc
981 ap->ops->sched_eh(ap); in ata_port_schedule_eh()
990 WARN_ON(!ap->ops->error_handler); in ata_do_link_abort()
997 if (qc && (!link || qc->dev->link == link)) { in ata_do_link_abort()
998 qc->flags |= ATA_QCFLAG_FAILED; in ata_do_link_abort()
1011 * ata_link_abort - abort all qc's on the link
1024 return ata_do_link_abort(link->ap, link); in ata_link_abort()
1029 * ata_port_abort - abort all qc's on the port
1047 * __ata_port_freeze - freeze port
1055 * ap->ops->freeze() callback can be used for freezing the port
1056 * hardware-wise (e.g. mask interrupt and stop DMA engine). If a
1057 * port cannot be frozen hardware-wise, the interrupt handler
1066 WARN_ON(!ap->ops->error_handler); in __ata_port_freeze()
1068 if (ap->ops->freeze) in __ata_port_freeze()
1069 ap->ops->freeze(ap); in __ata_port_freeze()
1071 ap->pflags |= ATA_PFLAG_FROZEN; in __ata_port_freeze()
1073 DPRINTK("ata%u port frozen\n", ap->print_id); in __ata_port_freeze()
1077 * ata_port_freeze - abort & freeze port
1094 WARN_ON(!ap->ops->error_handler); in ata_port_freeze()
1104 * ata_eh_freeze_port - EH helper to freeze port
1116 if (!ap->ops->error_handler) in ata_eh_freeze_port()
1119 spin_lock_irqsave(ap->lock, flags); in ata_eh_freeze_port()
1121 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_freeze_port()
1126 * ata_eh_thaw_port - EH helper to thaw port
1138 if (!ap->ops->error_handler) in ata_eh_thaw_port()
1141 spin_lock_irqsave(ap->lock, flags); in ata_eh_thaw_port()
1143 ap->pflags &= ~ATA_PFLAG_FROZEN; in ata_eh_thaw_port()
1145 if (ap->ops->thaw) in ata_eh_thaw_port()
1146 ap->ops->thaw(ap); in ata_eh_thaw_port()
1148 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_thaw_port()
1150 DPRINTK("ata%u port thawed\n", ap->print_id); in ata_eh_thaw_port()
1160 struct ata_port *ap = qc->ap; in __ata_eh_qc_complete()
1161 struct scsi_cmnd *scmd = qc->scsicmd; in __ata_eh_qc_complete()
1164 spin_lock_irqsave(ap->lock, flags); in __ata_eh_qc_complete()
1165 qc->scsidone = ata_eh_scsidone; in __ata_eh_qc_complete()
1167 WARN_ON(ata_tag_valid(qc->tag)); in __ata_eh_qc_complete()
1168 spin_unlock_irqrestore(ap->lock, flags); in __ata_eh_qc_complete()
1170 scsi_eh_finish_cmd(scmd, &ap->eh_done_q); in __ata_eh_qc_complete()
1174 * ata_eh_qc_complete - Complete an active ATA command from EH
1182 struct scsi_cmnd *scmd = qc->scsicmd; in ata_eh_qc_complete()
1183 scmd->retries = scmd->allowed; in ata_eh_qc_complete()
1188 * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
1194 * SCSI midlayer limits the number of retries to scmd->allowed.
1195 * scmd->allowed is incremented for commands which get retried
1196 * due to unrelated failures (qc->err_mask is zero).
1200 struct scsi_cmnd *scmd = qc->scsicmd; in ata_eh_qc_retry()
1201 if (!qc->err_mask) in ata_eh_qc_retry()
1202 scmd->allowed++; in ata_eh_qc_retry()
1207 * ata_dev_disable - disable ATA device
1220 if (ata_msg_drv(dev->link->ap)) in ata_dev_disable()
1224 dev->class++; in ata_dev_disable()
1229 ata_ering_clear(&dev->ering); in ata_dev_disable()
1234 * ata_eh_detach_dev - detach ATA device
1244 struct ata_link *link = dev->link; in ata_eh_detach_dev()
1245 struct ata_port *ap = link->ap; in ata_eh_detach_dev()
1246 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_detach_dev()
1251 spin_lock_irqsave(ap->lock, flags); in ata_eh_detach_dev()
1253 dev->flags &= ~ATA_DFLAG_DETACH; in ata_eh_detach_dev()
1256 dev->flags |= ATA_DFLAG_DETACHED; in ata_eh_detach_dev()
1257 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG; in ata_eh_detach_dev()
1260 /* clear per-dev EH info */ in ata_eh_detach_dev()
1261 ata_eh_clear_action(link, dev, &link->eh_info, ATA_EH_PERDEV_MASK); in ata_eh_detach_dev()
1262 ata_eh_clear_action(link, dev, &link->eh_context.i, ATA_EH_PERDEV_MASK); in ata_eh_detach_dev()
1263 ehc->saved_xfer_mode[dev->devno] = 0; in ata_eh_detach_dev()
1264 ehc->saved_ncq_enabled &= ~(1 << dev->devno); in ata_eh_detach_dev()
1266 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_detach_dev()
1270 * ata_eh_about_to_do - about to perform eh_action
1272 * @dev: target ATA dev for per-dev action (can be NULL)
1276 * in @link->eh_info such that eh actions are not unnecessarily
1285 struct ata_port *ap = link->ap; in ata_eh_about_to_do()
1286 struct ata_eh_info *ehi = &link->eh_info; in ata_eh_about_to_do()
1287 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_about_to_do()
1290 spin_lock_irqsave(ap->lock, flags); in ata_eh_about_to_do()
1297 if (!(ehc->i.flags & ATA_EHI_QUIET) && link != ap->slave_link) in ata_eh_about_to_do()
1298 ap->pflags |= ATA_PFLAG_RECOVERED; in ata_eh_about_to_do()
1300 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_about_to_do()
1304 * ata_eh_done - EH action complete
1306 * @dev: target ATA dev for per-dev action (can be NULL)
1310 * in @link->eh_context.
1318 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_done()
1320 ata_eh_clear_action(link, dev, &ehc->i, action); in ata_eh_done()
1324 * ata_err_string - convert err_mask to descriptive string
1363 * atapi_eh_tur - perform ATAPI TEST_UNIT_READY
1394 * ata_eh_request_sense - perform REQUEST_SENSE_DATA_EXT
1407 struct ata_device *dev = qc->dev; in ata_eh_request_sense()
1411 if (qc->ap->pflags & ATA_PFLAG_FROZEN) { in ata_eh_request_sense()
1416 if (!cmd || qc->flags & ATA_QCFLAG_SENSE_VALID) in ata_eh_request_sense()
1419 if (!ata_id_sense_reporting_enabled(dev->id)) { in ata_eh_request_sense()
1420 ata_dev_warn(qc->dev, "sense data reporting disabled\n"); in ata_eh_request_sense()
1436 qc->flags |= ATA_QCFLAG_SENSE_VALID; in ata_eh_request_sense()
1444 * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE
1463 struct ata_port *ap = dev->link->ap; in atapi_eh_request_sense()
1471 * for the case where they are -not- overwritten in atapi_eh_request_sense()
1483 if (ap->flags & ATA_FLAG_PIO_DMA) { in atapi_eh_request_sense()
1497 * ata_eh_analyze_serror - analyze SError for a failed port
1508 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_analyze_serror()
1509 u32 serror = ehc->i.serror; in ata_eh_analyze_serror()
1531 if (link->lpm_policy > ATA_LPM_MAX_POWER) in ata_eh_analyze_serror()
1533 else if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link)) in ata_eh_analyze_serror()
1539 ata_ehi_hotplugged(&ehc->i); in ata_eh_analyze_serror()
1541 ehc->i.err_mask |= err_mask; in ata_eh_analyze_serror()
1542 ehc->i.action |= action; in ata_eh_analyze_serror()
1546 * ata_eh_analyze_tf - analyze taskfile of a failed qc
1564 u8 stat = tf->command, err = tf->feature; in ata_eh_analyze_tf()
1567 qc->err_mask |= AC_ERR_HSM; in ata_eh_analyze_tf()
1572 qc->err_mask |= AC_ERR_DEV; in ata_eh_analyze_tf()
1583 switch (qc->dev->class) { in ata_eh_analyze_tf()
1586 ata_eh_request_sense(qc, qc->scsicmd); in ata_eh_analyze_tf()
1590 qc->err_mask |= AC_ERR_ATA_BUS; in ata_eh_analyze_tf()
1592 qc->err_mask |= AC_ERR_MEDIA; in ata_eh_analyze_tf()
1594 qc->err_mask |= AC_ERR_INVALID; in ata_eh_analyze_tf()
1598 if (!(qc->ap->pflags & ATA_PFLAG_FROZEN)) { in ata_eh_analyze_tf()
1599 tmp = atapi_eh_request_sense(qc->dev, in ata_eh_analyze_tf()
1600 qc->scsicmd->sense_buffer, in ata_eh_analyze_tf()
1601 qc->result_tf.feature >> 4); in ata_eh_analyze_tf()
1603 qc->flags |= ATA_QCFLAG_SENSE_VALID; in ata_eh_analyze_tf()
1605 qc->err_mask |= tmp; in ata_eh_analyze_tf()
1609 if (qc->flags & ATA_QCFLAG_SENSE_VALID) { in ata_eh_analyze_tf()
1610 enum scsi_disposition ret = scsi_check_sense(qc->scsicmd); in ata_eh_analyze_tf()
1621 qc->flags |= ATA_QCFLAG_RETRY; in ata_eh_analyze_tf()
1622 qc->err_mask |= AC_ERR_OTHER; in ata_eh_analyze_tf()
1624 qc->err_mask |= AC_ERR_HSM; in ata_eh_analyze_tf()
1627 if (qc->err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT | AC_ERR_ATA_BUS)) in ata_eh_analyze_tf()
1672 if ((ent->eflags & ATA_EFLAG_OLD_ER) || (ent->timestamp < arg->since)) in speed_down_verdict_cb()
1673 return -1; in speed_down_verdict_cb()
1675 cat = ata_eh_categorize_error(ent->eflags, ent->err_mask, in speed_down_verdict_cb()
1676 &arg->xfer_ok); in speed_down_verdict_cb()
1677 arg->nr_errors[cat]++; in speed_down_verdict_cb()
1683 * ata_eh_speed_down_verdict - Determine speed down verdict
1710 * taken per error. An action triggered by non-DUBIOUS errors
1748 arg.since = j64 - min(j64, j5mins); in ata_eh_speed_down_verdict()
1749 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); in ata_eh_speed_down_verdict()
1767 arg.since = j64 - min(j64, j10mins); in ata_eh_speed_down_verdict()
1768 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); in ata_eh_speed_down_verdict()
1783 * ata_eh_speed_down - record error and speed down if necessary
1807 /* don't bother if Cat-0 error */ in ata_eh_speed_down()
1812 ata_ering_record(&dev->ering, eflags, err_mask); in ata_eh_speed_down()
1817 (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ | in ata_eh_speed_down()
1819 dev->flags |= ATA_DFLAG_NCQ_OFF; in ata_eh_speed_down()
1833 if (dev->spdn_cnt < 2) { in ata_eh_speed_down()
1840 if (dev->xfer_shift != ATA_SHIFT_PIO) in ata_eh_speed_down()
1841 sel = dma_dnxfer_sel[dev->spdn_cnt]; in ata_eh_speed_down()
1843 sel = pio_dnxfer_sel[dev->spdn_cnt]; in ata_eh_speed_down()
1845 dev->spdn_cnt++; in ata_eh_speed_down()
1857 if ((verdict & ATA_EH_SPDN_FALLBACK_TO_PIO) && (dev->spdn_cnt >= 2) && in ata_eh_speed_down()
1858 (link->ap->cbl != ATA_CBL_SATA || dev->class == ATA_DEV_ATAPI) && in ata_eh_speed_down()
1859 (dev->xfer_shift != ATA_SHIFT_PIO)) { in ata_eh_speed_down()
1861 dev->spdn_cnt = 0; in ata_eh_speed_down()
1871 ata_ering_clear(&dev->ering); in ata_eh_speed_down()
1876 * ata_eh_worth_retry - analyze error and decide whether to retry
1881 * because the drive itself has probably already taken 10-30 seconds
1886 if (qc->err_mask & AC_ERR_MEDIA) in ata_eh_worth_retry()
1888 if (qc->flags & ATA_QCFLAG_IO) in ata_eh_worth_retry()
1890 if (qc->err_mask & AC_ERR_INVALID) in ata_eh_worth_retry()
1892 return qc->err_mask != AC_ERR_DEV; /* retry if not dev error */ in ata_eh_worth_retry()
1896 * ata_eh_quiet - check if we need to be quiet about a command error
1904 if (qc->scsicmd && in ata_eh_quiet()
1905 qc->scsicmd->request->rq_flags & RQF_QUIET) in ata_eh_quiet()
1906 qc->flags |= ATA_QCFLAG_QUIET; in ata_eh_quiet()
1907 return qc->flags & ATA_QCFLAG_QUIET; in ata_eh_quiet()
1911 * ata_eh_link_autopsy - analyze error and determine recovery action
1923 struct ata_port *ap = link->ap; in ata_eh_link_autopsy()
1924 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_link_autopsy()
1934 if (ehc->i.flags & ATA_EHI_NO_AUTOPSY) in ata_eh_link_autopsy()
1940 ehc->i.serror |= serror; in ata_eh_link_autopsy()
1942 } else if (rc != -EOPNOTSUPP) { in ata_eh_link_autopsy()
1944 ehc->i.probe_mask |= ATA_ALL_DEVICES; in ata_eh_link_autopsy()
1945 ehc->i.action |= ATA_EH_RESET; in ata_eh_link_autopsy()
1946 ehc->i.err_mask |= AC_ERR_OTHER; in ata_eh_link_autopsy()
1953 if (ehc->i.err_mask & ~AC_ERR_OTHER) in ata_eh_link_autopsy()
1954 ehc->i.err_mask &= ~AC_ERR_OTHER; in ata_eh_link_autopsy()
1956 all_err_mask |= ehc->i.err_mask; in ata_eh_link_autopsy()
1959 if (!(qc->flags & ATA_QCFLAG_FAILED) || in ata_eh_link_autopsy()
1960 ata_dev_phys_link(qc->dev) != link) in ata_eh_link_autopsy()
1964 qc->err_mask |= ehc->i.err_mask; in ata_eh_link_autopsy()
1967 ehc->i.action |= ata_eh_analyze_tf(qc, &qc->result_tf); in ata_eh_link_autopsy()
1970 if (qc->err_mask & AC_ERR_ATA_BUS) in ata_eh_link_autopsy()
1971 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_MEDIA | in ata_eh_link_autopsy()
1975 if (qc->err_mask & ~AC_ERR_OTHER) in ata_eh_link_autopsy()
1976 qc->err_mask &= ~AC_ERR_OTHER; in ata_eh_link_autopsy()
1985 if (qc->flags & ATA_QCFLAG_SENSE_VALID) in ata_eh_link_autopsy()
1986 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER); in ata_eh_link_autopsy()
1988 qc->flags |= ATA_QCFLAG_RETRY; in ata_eh_link_autopsy()
1991 ehc->i.dev = qc->dev; in ata_eh_link_autopsy()
1992 all_err_mask |= qc->err_mask; in ata_eh_link_autopsy()
1993 if (qc->flags & ATA_QCFLAG_IO) in ata_eh_link_autopsy()
2005 ehc->i.flags |= ATA_EHI_QUIET; in ata_eh_link_autopsy()
2008 if (ap->pflags & ATA_PFLAG_FROZEN || in ata_eh_link_autopsy()
2010 ehc->i.action |= ATA_EH_RESET; in ata_eh_link_autopsy()
2013 ehc->i.action |= ATA_EH_REVALIDATE; in ata_eh_link_autopsy()
2016 * perform per-dev EH action only on the offending device. in ata_eh_link_autopsy()
2018 if (ehc->i.dev) { in ata_eh_link_autopsy()
2019 ehc->i.dev_action[ehc->i.dev->devno] |= in ata_eh_link_autopsy()
2020 ehc->i.action & ATA_EH_PERDEV_MASK; in ata_eh_link_autopsy()
2021 ehc->i.action &= ~ATA_EH_PERDEV_MASK; in ata_eh_link_autopsy()
2026 ap->link.eh_context.i.err_mask |= AC_ERR_TIMEOUT; in ata_eh_link_autopsy()
2029 dev = ehc->i.dev; in ata_eh_link_autopsy()
2031 ata_dev_enabled(link->device)))) in ata_eh_link_autopsy()
2032 dev = link->device; in ata_eh_link_autopsy()
2035 if (dev->flags & ATA_DFLAG_DUBIOUS_XFER) in ata_eh_link_autopsy()
2037 ehc->i.action |= ata_eh_speed_down(dev, eflags, all_err_mask); in ata_eh_link_autopsy()
2038 trace_ata_eh_link_autopsy(dev, ehc->i.action, all_err_mask); in ata_eh_link_autopsy()
2044 * ata_eh_autopsy - analyze error and determine recovery action
2064 if (ap->slave_link) { in ata_eh_autopsy()
2065 struct ata_eh_context *mehc = &ap->link.eh_context; in ata_eh_autopsy()
2066 struct ata_eh_context *sehc = &ap->slave_link->eh_context; in ata_eh_autopsy()
2069 sehc->i.flags |= mehc->i.flags & ATA_EHI_TO_SLAVE_MASK; in ata_eh_autopsy()
2072 ata_eh_link_autopsy(ap->slave_link); in ata_eh_autopsy()
2075 ata_eh_about_to_do(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS); in ata_eh_autopsy()
2076 mehc->i.action |= sehc->i.action; in ata_eh_autopsy()
2077 mehc->i.dev_action[1] |= sehc->i.dev_action[1]; in ata_eh_autopsy()
2078 mehc->i.flags |= sehc->i.flags; in ata_eh_autopsy()
2079 ata_eh_done(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS); in ata_eh_autopsy()
2086 ata_eh_link_autopsy(&ap->link); in ata_eh_autopsy()
2090 * ata_get_cmd_descript - get description for ATA command
2134 { ATA_CMD_NCQ_NON_DATA, "NCQ NON-DATA" }, in ata_get_cmd_descript()
2163 { ATA_CMD_TRUSTED_NONDATA, "TRUSTED NON-DATA" }, in ata_get_cmd_descript()
2213 * ata_eh_link_report - report error handling to user
2223 struct ata_port *ap = link->ap; in ata_eh_link_report()
2224 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_link_report()
2230 if (ehc->i.flags & ATA_EHI_QUIET) in ata_eh_link_report()
2234 if (ehc->i.desc[0] != '\0') in ata_eh_link_report()
2235 desc = ehc->i.desc; in ata_eh_link_report()
2238 if (!(qc->flags & ATA_QCFLAG_FAILED) || in ata_eh_link_report()
2239 ata_dev_phys_link(qc->dev) != link || in ata_eh_link_report()
2240 ((qc->flags & ATA_QCFLAG_QUIET) && in ata_eh_link_report()
2241 qc->err_mask == AC_ERR_DEV)) in ata_eh_link_report()
2243 if (qc->flags & ATA_QCFLAG_SENSE_VALID && !qc->err_mask) in ata_eh_link_report()
2249 if (!nr_failed && !ehc->i.err_mask) in ata_eh_link_report()
2253 if (ap->pflags & ATA_PFLAG_FROZEN) in ata_eh_link_report()
2256 if (ap->eh_tries < ATA_EH_MAX_TRIES) in ata_eh_link_report()
2258 ap->eh_tries); in ata_eh_link_report()
2260 if (ehc->i.dev) { in ata_eh_link_report()
2261 ata_dev_err(ehc->i.dev, "exception Emask 0x%x " in ata_eh_link_report()
2263 ehc->i.err_mask, link->sactive, ehc->i.serror, in ata_eh_link_report()
2264 ehc->i.action, frozen, tries_buf); in ata_eh_link_report()
2266 ata_dev_err(ehc->i.dev, "%s\n", desc); in ata_eh_link_report()
2270 ehc->i.err_mask, link->sactive, ehc->i.serror, in ata_eh_link_report()
2271 ehc->i.action, frozen, tries_buf); in ata_eh_link_report()
2277 if (ehc->i.serror) in ata_eh_link_report()
2280 ehc->i.serror & SERR_DATA_RECOVERED ? "RecovData " : "", in ata_eh_link_report()
2281 ehc->i.serror & SERR_COMM_RECOVERED ? "RecovComm " : "", in ata_eh_link_report()
2282 ehc->i.serror & SERR_DATA ? "UnrecovData " : "", in ata_eh_link_report()
2283 ehc->i.serror & SERR_PERSISTENT ? "Persist " : "", in ata_eh_link_report()
2284 ehc->i.serror & SERR_PROTOCOL ? "Proto " : "", in ata_eh_link_report()
2285 ehc->i.serror & SERR_INTERNAL ? "HostInt " : "", in ata_eh_link_report()
2286 ehc->i.serror & SERR_PHYRDY_CHG ? "PHYRdyChg " : "", in ata_eh_link_report()
2287 ehc->i.serror & SERR_PHY_INT_ERR ? "PHYInt " : "", in ata_eh_link_report()
2288 ehc->i.serror & SERR_COMM_WAKE ? "CommWake " : "", in ata_eh_link_report()
2289 ehc->i.serror & SERR_10B_8B_ERR ? "10B8B " : "", in ata_eh_link_report()
2290 ehc->i.serror & SERR_DISPARITY ? "Dispar " : "", in ata_eh_link_report()
2291 ehc->i.serror & SERR_CRC ? "BadCRC " : "", in ata_eh_link_report()
2292 ehc->i.serror & SERR_HANDSHAKE ? "Handshk " : "", in ata_eh_link_report()
2293 ehc->i.serror & SERR_LINK_SEQ_ERR ? "LinkSeq " : "", in ata_eh_link_report()
2294 ehc->i.serror & SERR_TRANS_ST_ERROR ? "TrStaTrns " : "", in ata_eh_link_report()
2295 ehc->i.serror & SERR_UNRECOG_FIS ? "UnrecFIS " : "", in ata_eh_link_report()
2296 ehc->i.serror & SERR_DEV_XCHG ? "DevExch " : ""); in ata_eh_link_report()
2300 struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf; in ata_eh_link_report()
2304 if (!(qc->flags & ATA_QCFLAG_FAILED) || in ata_eh_link_report()
2305 ata_dev_phys_link(qc->dev) != link || !qc->err_mask) in ata_eh_link_report()
2308 if (qc->dma_dir != DMA_NONE) { in ata_eh_link_report()
2316 switch (qc->tf.protocol) { in ata_eh_link_report()
2346 prot_str, qc->nbytes, dma_str[qc->dma_dir]); in ata_eh_link_report()
2349 if (ata_is_atapi(qc->tf.protocol)) { in ata_eh_link_report()
2350 const u8 *cdb = qc->cdb; in ata_eh_link_report()
2351 size_t cdb_len = qc->dev->cdb_len; in ata_eh_link_report()
2353 if (qc->scsicmd) { in ata_eh_link_report()
2354 cdb = qc->scsicmd->cmnd; in ata_eh_link_report()
2355 cdb_len = qc->scsicmd->cmd_len; in ata_eh_link_report()
2360 const char *descr = ata_get_cmd_descript(cmd->command); in ata_eh_link_report()
2362 ata_dev_err(qc->dev, "failed command: %s\n", in ata_eh_link_report()
2366 ata_dev_err(qc->dev, in ata_eh_link_report()
2371 cmd->command, cmd->feature, cmd->nsect, in ata_eh_link_report()
2372 cmd->lbal, cmd->lbam, cmd->lbah, in ata_eh_link_report()
2373 cmd->hob_feature, cmd->hob_nsect, in ata_eh_link_report()
2374 cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah, in ata_eh_link_report()
2375 cmd->device, qc->tag, data_buf, cdb_buf, in ata_eh_link_report()
2376 res->command, res->feature, res->nsect, in ata_eh_link_report()
2377 res->lbal, res->lbam, res->lbah, in ata_eh_link_report()
2378 res->hob_feature, res->hob_nsect, in ata_eh_link_report()
2379 res->hob_lbal, res->hob_lbam, res->hob_lbah, in ata_eh_link_report()
2380 res->device, qc->err_mask, ata_err_string(qc->err_mask), in ata_eh_link_report()
2381 qc->err_mask & AC_ERR_NCQ ? " <F>" : ""); in ata_eh_link_report()
2384 if (res->command & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | in ata_eh_link_report()
2386 if (res->command & ATA_BUSY) in ata_eh_link_report()
2387 ata_dev_err(qc->dev, "status: { Busy }\n"); in ata_eh_link_report()
2389 ata_dev_err(qc->dev, "status: { %s%s%s%s%s}\n", in ata_eh_link_report()
2390 res->command & ATA_DRDY ? "DRDY " : "", in ata_eh_link_report()
2391 res->command & ATA_DF ? "DF " : "", in ata_eh_link_report()
2392 res->command & ATA_DRQ ? "DRQ " : "", in ata_eh_link_report()
2393 res->command & ATA_SENSE ? "SENSE " : "", in ata_eh_link_report()
2394 res->command & ATA_ERR ? "ERR " : ""); in ata_eh_link_report()
2397 if (cmd->command != ATA_CMD_PACKET && in ata_eh_link_report()
2398 (res->feature & (ATA_ICRC | ATA_UNC | ATA_AMNF | in ata_eh_link_report()
2400 ata_dev_err(qc->dev, "error: { %s%s%s%s%s}\n", in ata_eh_link_report()
2401 res->feature & ATA_ICRC ? "ICRC " : "", in ata_eh_link_report()
2402 res->feature & ATA_UNC ? "UNC " : "", in ata_eh_link_report()
2403 res->feature & ATA_AMNF ? "AMNF " : "", in ata_eh_link_report()
2404 res->feature & ATA_IDNF ? "IDNF " : "", in ata_eh_link_report()
2405 res->feature & ATA_ABORTED ? "ABRT " : ""); in ata_eh_link_report()
2411 * ata_eh_report - report error handling to user
2435 classes[dev->devno] = ATA_DEV_UNKNOWN; in ata_do_reset()
2442 if ((link->flags & ATA_LFLAG_NO_SRST) || ata_link_offline(link)) in ata_eh_followup_srst_needed()
2444 if (rc == -EAGAIN) in ata_eh_followup_srst_needed()
2446 if (sata_pmp_supported(link->ap) && ata_is_host_link(link)) in ata_eh_followup_srst_needed()
2455 struct ata_port *ap = link->ap; in ata_eh_reset()
2456 struct ata_link *slave = ap->slave_link; in ata_eh_reset()
2457 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_reset()
2458 struct ata_eh_context *sehc = slave ? &slave->eh_context : NULL; in ata_eh_reset()
2459 unsigned int *classes = ehc->classes; in ata_eh_reset()
2460 unsigned int lflags = link->flags; in ata_eh_reset()
2461 int verbose = !(ehc->i.flags & ATA_EHI_QUIET); in ata_eh_reset()
2476 if (link->flags & ATA_LFLAG_RST_ONCE) in ata_eh_reset()
2478 if (link->flags & ATA_LFLAG_NO_HRST) in ata_eh_reset()
2480 if (link->flags & ATA_LFLAG_NO_SRST) in ata_eh_reset()
2484 if (ehc->i.flags & ATA_EHI_DID_RESET) { in ata_eh_reset()
2486 WARN_ON(time_after(ehc->last_reset, now)); in ata_eh_reset()
2487 deadline = ata_deadline(ehc->last_reset, in ata_eh_reset()
2490 schedule_timeout_uninterruptible(deadline - now); in ata_eh_reset()
2493 spin_lock_irqsave(ap->lock, flags); in ata_eh_reset()
2494 ap->pflags |= ATA_PFLAG_RESETTING; in ata_eh_reset()
2495 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_reset()
2507 dev->pio_mode = XFER_PIO_0; in ata_eh_reset()
2508 dev->dma_mode = 0xff; in ata_eh_reset()
2515 if (ap->ops->set_piomode) in ata_eh_reset()
2516 ap->ops->set_piomode(ap, dev); in ata_eh_reset()
2521 ehc->i.action &= ~ATA_EH_RESET; in ata_eh_reset()
2524 ehc->i.action |= ATA_EH_HARDRESET; in ata_eh_reset()
2527 ehc->i.action |= ATA_EH_SOFTRESET; in ata_eh_reset()
2535 sehc->i.action &= ~ATA_EH_RESET; in ata_eh_reset()
2536 sehc->i.action |= ehc->i.action; in ata_eh_reset()
2543 * -ENOENT or clear ATA_EH_RESET. in ata_eh_reset()
2545 if (slave && (rc == 0 || rc == -ENOENT)) { in ata_eh_reset()
2549 if (tmp != -ENOENT) in ata_eh_reset()
2552 ehc->i.action |= sehc->i.action; in ata_eh_reset()
2556 if (rc == -ENOENT) { in ata_eh_reset()
2557 ata_link_dbg(link, "port disabled--ignoring\n"); in ata_eh_reset()
2558 ehc->i.action &= ~ATA_EH_RESET; in ata_eh_reset()
2561 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2574 if (reset && !(ehc->i.action & ATA_EH_RESET)) { in ata_eh_reset()
2576 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2577 if ((ap->pflags & ATA_PFLAG_FROZEN) && in ata_eh_reset()
2600 ehc->last_reset = jiffies; in ata_eh_reset()
2602 ehc->i.flags |= ATA_EHI_DID_HARDRESET; in ata_eh_reset()
2604 ehc->i.flags |= ATA_EHI_DID_SOFTRESET; in ata_eh_reset()
2607 if (rc && rc != -EAGAIN) { in ata_eh_reset()
2623 case -EAGAIN: in ata_eh_reset()
2624 rc = -EAGAIN; in ata_eh_reset()
2634 /* perform follow-up SRST if necessary */ in ata_eh_reset()
2641 "follow-up softreset required but no softreset available\n"); in ata_eh_reset()
2643 rc = -EINVAL; in ata_eh_reset()
2663 * Post-reset processing in ata_eh_reset()
2670 dev->pio_mode = XFER_PIO_0; in ata_eh_reset()
2671 dev->flags &= ~ATA_DFLAG_SLEEPING; in ata_eh_reset()
2678 classes[dev->devno] = ATA_DEV_ATA; in ata_eh_reset()
2680 classes[dev->devno] = ATA_DEV_SEMB_UNSUP; in ata_eh_reset()
2685 link->sata_spd = (sstatus >> 4) & 0xf; in ata_eh_reset()
2687 slave->sata_spd = (sstatus >> 4) & 0xf; in ata_eh_reset()
2707 spin_lock_irqsave(link->ap->lock, flags); in ata_eh_reset()
2708 link->eh_info.serror = 0; in ata_eh_reset()
2710 slave->eh_info.serror = 0; in ata_eh_reset()
2711 spin_unlock_irqrestore(link->ap->lock, flags); in ata_eh_reset()
2713 if (ap->pflags & ATA_PFLAG_FROZEN) in ata_eh_reset()
2727 if (classes[dev->devno] == ATA_DEV_UNKNOWN) { in ata_eh_reset()
2729 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2733 if (ata_class_enabled(classes[dev->devno])) in ata_eh_reset()
2736 classes[dev->devno]); in ata_eh_reset()
2737 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2738 } else if (classes[dev->devno] == ATA_DEV_UNKNOWN) { in ata_eh_reset()
2741 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2751 rc = -EAGAIN; in ata_eh_reset()
2763 ehc->last_reset = jiffies; /* update to completion time */ in ata_eh_reset()
2764 ehc->i.action |= ATA_EH_REVALIDATE; in ata_eh_reset()
2765 link->lpm_policy = ATA_LPM_UNKNOWN; /* reset LPM state */ in ata_eh_reset()
2770 ehc->i.flags &= ~ATA_EHI_HOTPLUGGED; in ata_eh_reset()
2772 sehc->i.flags &= ~ATA_EHI_HOTPLUGGED; in ata_eh_reset()
2774 spin_lock_irqsave(ap->lock, flags); in ata_eh_reset()
2775 ap->pflags &= ~ATA_PFLAG_RESETTING; in ata_eh_reset()
2776 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_reset()
2781 /* if SCR isn't accessible on a fan-out port, PMP needs to be reset */ in ata_eh_reset()
2784 rc = -ERESTART; in ata_eh_reset()
2800 unsigned long delta = deadline - now; in ata_eh_reset()
2814 * They need to be reset - as well as the PMP - before retrying. in ata_eh_reset()
2816 if (rc == -ERESTART) { in ata_eh_reset()
2822 if (try == max_tries - 1) { in ata_eh_reset()
2826 } else if (rc == -EPIPE) in ata_eh_reset()
2848 * timeout updates for the same device, we have to pull in ata_eh_pull_park_action()
2852 * Additionally, all write accesses to &ap->park_req_pending in ata_eh_pull_park_action()
2859 * park_req_pending.done is non-zero by the time we reach in ata_eh_pull_park_action()
2866 spin_lock_irqsave(ap->lock, flags); in ata_eh_pull_park_action()
2867 reinit_completion(&ap->park_req_pending); in ata_eh_pull_park_action()
2870 struct ata_eh_info *ehi = &link->eh_info; in ata_eh_pull_park_action()
2872 link->eh_context.i.dev_action[dev->devno] |= in ata_eh_pull_park_action()
2873 ehi->dev_action[dev->devno] & ATA_EH_PARK; in ata_eh_pull_park_action()
2877 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_pull_park_action()
2882 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_park_issue_cmd()
2888 ehc->unloaded_mask |= 1 << dev->devno; in ata_eh_park_issue_cmd()
2895 ehc->unloaded_mask &= ~(1 << dev->devno); in ata_eh_park_issue_cmd()
2904 ehc->unloaded_mask &= ~(1 << dev->devno); in ata_eh_park_issue_cmd()
2911 struct ata_port *ap = link->ap; in ata_eh_revalidate_and_attach()
2912 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_revalidate_and_attach()
2921 * be done backwards such that PDIAG- is released by the slave in ata_eh_revalidate_and_attach()
2928 if (ehc->i.flags & ATA_EHI_DID_RESET) in ata_eh_revalidate_and_attach()
2932 WARN_ON(dev->class == ATA_DEV_PMP); in ata_eh_revalidate_and_attach()
2935 rc = -EIO; in ata_eh_revalidate_and_attach()
2940 rc = ata_dev_revalidate(dev, ehc->classes[dev->devno], in ata_eh_revalidate_and_attach()
2950 ehc->i.flags |= ATA_EHI_SETMODE; in ata_eh_revalidate_and_attach()
2953 schedule_work(&(ap->scsi_rescan_task)); in ata_eh_revalidate_and_attach()
2954 } else if (dev->class == ATA_DEV_UNKNOWN && in ata_eh_revalidate_and_attach()
2955 ehc->tries[dev->devno] && in ata_eh_revalidate_and_attach()
2956 ata_class_enabled(ehc->classes[dev->devno])) { in ata_eh_revalidate_and_attach()
2957 /* Temporarily set dev->class, it will be in ata_eh_revalidate_and_attach()
2963 dev->class = ehc->classes[dev->devno]; in ata_eh_revalidate_and_attach()
2965 if (dev->class == ATA_DEV_PMP) in ata_eh_revalidate_and_attach()
2968 rc = ata_dev_read_id(dev, &dev->class, in ata_eh_revalidate_and_attach()
2969 readid_flags, dev->id); in ata_eh_revalidate_and_attach()
2972 ehc->classes[dev->devno] = dev->class; in ata_eh_revalidate_and_attach()
2973 dev->class = ATA_DEV_UNKNOWN; in ata_eh_revalidate_and_attach()
2978 ata_ering_clear(&dev->ering); in ata_eh_revalidate_and_attach()
2979 new_mask |= 1 << dev->devno; in ata_eh_revalidate_and_attach()
2981 case -ENOENT: in ata_eh_revalidate_and_attach()
2982 /* IDENTIFY was issued to non-existent in ata_eh_revalidate_and_attach()
2994 /* PDIAG- should have been released, ask cable type if post-reset */ in ata_eh_revalidate_and_attach()
2995 if ((ehc->i.flags & ATA_EHI_DID_RESET) && ata_is_host_link(link)) { in ata_eh_revalidate_and_attach()
2996 if (ap->ops->cable_detect) in ata_eh_revalidate_and_attach()
2997 ap->cbl = ap->ops->cable_detect(ap); in ata_eh_revalidate_and_attach()
3005 if (!(new_mask & (1 << dev->devno))) in ata_eh_revalidate_and_attach()
3008 dev->class = ehc->classes[dev->devno]; in ata_eh_revalidate_and_attach()
3010 if (dev->class == ATA_DEV_PMP) in ata_eh_revalidate_and_attach()
3013 ehc->i.flags |= ATA_EHI_PRINTINFO; in ata_eh_revalidate_and_attach()
3015 ehc->i.flags &= ~ATA_EHI_PRINTINFO; in ata_eh_revalidate_and_attach()
3017 dev->class = ATA_DEV_UNKNOWN; in ata_eh_revalidate_and_attach()
3021 spin_lock_irqsave(ap->lock, flags); in ata_eh_revalidate_and_attach()
3022 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG; in ata_eh_revalidate_and_attach()
3023 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_revalidate_and_attach()
3026 ehc->i.flags |= ATA_EHI_SETMODE; in ata_eh_revalidate_and_attach()
3038 * ata_set_mode - Program timings and issue SET FEATURES - XFER
3054 struct ata_port *ap = link->ap; in ata_set_mode()
3060 if (!(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) { in ata_set_mode()
3063 ent = ata_ering_top(&dev->ering); in ata_set_mode()
3065 ent->eflags &= ~ATA_EFLAG_DUBIOUS_XFER; in ata_set_mode()
3070 if (ap->ops->set_mode) in ata_set_mode()
3071 rc = ap->ops->set_mode(link, r_failed_dev); in ata_set_mode()
3077 struct ata_eh_context *ehc = &link->eh_context; in ata_set_mode()
3078 u8 saved_xfer_mode = ehc->saved_xfer_mode[dev->devno]; in ata_set_mode()
3079 u8 saved_ncq = !!(ehc->saved_ncq_enabled & (1 << dev->devno)); in ata_set_mode()
3081 if (dev->xfer_mode != saved_xfer_mode || in ata_set_mode()
3083 dev->flags |= ATA_DFLAG_DUBIOUS_XFER; in ata_set_mode()
3090 * atapi_eh_clear_ua - Clear ATAPI UNIT ATTENTION after reset
3101 * 0 on success, -errno on failure.
3108 u8 *sense_buffer = dev->link->ap->sector_buf; in atapi_eh_clear_ua()
3117 return -EIO; in atapi_eh_clear_ua()
3127 return -EIO; in atapi_eh_clear_ua()
3138 * ata_eh_maybe_retry_flush - Retry FLUSH if necessary
3152 * 0 if EH can continue, -errno if EH needs to be repeated.
3156 struct ata_link *link = dev->link; in ata_eh_maybe_retry_flush()
3157 struct ata_port *ap = link->ap; in ata_eh_maybe_retry_flush()
3164 if (!ata_tag_valid(link->active_tag)) in ata_eh_maybe_retry_flush()
3167 qc = __ata_qc_from_tag(ap, link->active_tag); in ata_eh_maybe_retry_flush()
3168 if (qc->dev != dev || (qc->tf.command != ATA_CMD_FLUSH_EXT && in ata_eh_maybe_retry_flush()
3169 qc->tf.command != ATA_CMD_FLUSH)) in ata_eh_maybe_retry_flush()
3173 if (qc->err_mask & AC_ERR_DEV) in ata_eh_maybe_retry_flush()
3179 tf.command = qc->tf.command; in ata_eh_maybe_retry_flush()
3184 tf.command, qc->err_mask); in ata_eh_maybe_retry_flush()
3192 * retrying it should do the trick - whatever was in in ata_eh_maybe_retry_flush()
3196 qc->scsicmd->allowed = max(qc->scsicmd->allowed, 1); in ata_eh_maybe_retry_flush()
3200 rc = -EIO; in ata_eh_maybe_retry_flush()
3204 qc->err_mask |= AC_ERR_DEV; in ata_eh_maybe_retry_flush()
3205 qc->result_tf = tf; in ata_eh_maybe_retry_flush()
3206 if (!(ap->pflags & ATA_PFLAG_FROZEN)) in ata_eh_maybe_retry_flush()
3214 * ata_eh_set_lpm - configure SATA interface power management
3228 * 0 on success, -errno on failure.
3233 struct ata_port *ap = ata_is_host_link(link) ? link->ap : NULL; in ata_eh_set_lpm()
3234 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_set_lpm()
3236 enum ata_lpm_policy old_policy = link->lpm_policy; in ata_eh_set_lpm()
3237 bool no_dipm = link->ap->flags & ATA_FLAG_NO_DIPM; in ata_eh_set_lpm()
3244 (link->flags & ATA_LFLAG_NO_LPM) || (ap && !ap->ops->set_lpm)) in ata_eh_set_lpm()
3254 bool hipm = ata_id_has_hipm(dev->id); in ata_eh_set_lpm()
3255 bool dipm = ata_id_has_dipm(dev->id) && !no_dipm; in ata_eh_set_lpm()
3276 rc = -EIO; in ata_eh_set_lpm()
3283 rc = ap->ops->set_lpm(link, policy, hints); in ata_eh_set_lpm()
3284 if (!rc && ap->slave_link) in ata_eh_set_lpm()
3285 rc = ap->ops->set_lpm(ap->slave_link, policy, hints); in ata_eh_set_lpm()
3294 if (rc == -EOPNOTSUPP) { in ata_eh_set_lpm()
3295 link->flags |= ATA_LFLAG_NO_LPM; in ata_eh_set_lpm()
3306 link->lpm_policy = policy; in ata_eh_set_lpm()
3307 if (ap && ap->slave_link) in ata_eh_set_lpm()
3308 ap->slave_link->lpm_policy = policy; in ata_eh_set_lpm()
3313 ata_id_has_dipm(dev->id)) { in ata_eh_set_lpm()
3320 rc = -EIO; in ata_eh_set_lpm()
3326 link->last_lpm_change = jiffies; in ata_eh_set_lpm()
3327 link->flags |= ATA_LFLAG_CHANGED; in ata_eh_set_lpm()
3333 link->lpm_policy = old_policy; in ata_eh_set_lpm()
3334 if (ap && ap->slave_link) in ata_eh_set_lpm()
3335 ap->slave_link->lpm_policy = old_policy; in ata_eh_set_lpm()
3338 if (!dev || ehc->tries[dev->devno] <= 2) { in ata_eh_set_lpm()
3340 link->flags |= ATA_LFLAG_NO_LPM; in ata_eh_set_lpm()
3363 if (dev->class == ATA_DEV_UNKNOWN) in ata_link_nr_vacant()
3370 struct ata_port *ap = link->ap; in ata_eh_skip_recovery()
3371 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_skip_recovery()
3375 if (link->flags & ATA_LFLAG_DISABLED) in ata_eh_skip_recovery()
3379 if (ehc->i.flags & ATA_EHI_NO_RECOVERY) in ata_eh_skip_recovery()
3383 if ((ap->pflags & ATA_PFLAG_FROZEN) || ata_link_nr_enabled(link)) in ata_eh_skip_recovery()
3387 if ((ehc->i.action & ATA_EH_RESET) && in ata_eh_skip_recovery()
3388 !(ehc->i.flags & ATA_EHI_DID_RESET)) in ata_eh_skip_recovery()
3393 if (dev->class == ATA_DEV_UNKNOWN && in ata_eh_skip_recovery()
3394 ehc->classes[dev->devno] != ATA_DEV_NONE) in ata_eh_skip_recovery()
3407 if ((ent->eflags & ATA_EFLAG_OLD_ER) || in ata_count_probe_trials_cb()
3408 (ent->timestamp < now - min(now, interval))) in ata_count_probe_trials_cb()
3409 return -1; in ata_count_probe_trials_cb()
3417 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_schedule_probe()
3421 if (!(ehc->i.probe_mask & (1 << dev->devno)) || in ata_eh_schedule_probe()
3422 (ehc->did_probe_mask & (1 << dev->devno))) in ata_eh_schedule_probe()
3427 ehc->did_probe_mask |= (1 << dev->devno); in ata_eh_schedule_probe()
3428 ehc->i.action |= ATA_EH_RESET; in ata_eh_schedule_probe()
3429 ehc->saved_xfer_mode[dev->devno] = 0; in ata_eh_schedule_probe()
3430 ehc->saved_ncq_enabled &= ~(1 << dev->devno); in ata_eh_schedule_probe()
3433 if (link->lpm_policy > ATA_LPM_MAX_POWER) { in ata_eh_schedule_probe()
3435 link->ap->ops->set_lpm(link, ATA_LPM_MAX_POWER, in ata_eh_schedule_probe()
3455 ata_ering_record(&dev->ering, 0, AC_ERR_OTHER); in ata_eh_schedule_probe()
3456 ata_ering_map(&dev->ering, ata_count_probe_trials_cb, &trials); in ata_eh_schedule_probe()
3466 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_handle_dev_fail()
3468 /* -EAGAIN from EH routine indicates retry without prejudice. in ata_eh_handle_dev_fail()
3471 if (err != -EAGAIN) in ata_eh_handle_dev_fail()
3472 ehc->tries[dev->devno]--; in ata_eh_handle_dev_fail()
3475 case -ENODEV: in ata_eh_handle_dev_fail()
3477 ehc->i.probe_mask |= (1 << dev->devno); in ata_eh_handle_dev_fail()
3479 case -EINVAL: in ata_eh_handle_dev_fail()
3481 ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1); in ata_eh_handle_dev_fail()
3483 case -EIO: in ata_eh_handle_dev_fail()
3484 if (ehc->tries[dev->devno] == 1) { in ata_eh_handle_dev_fail()
3489 if (dev->pio_mode > XFER_PIO_0) in ata_eh_handle_dev_fail()
3494 if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) { in ata_eh_handle_dev_fail()
3504 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; in ata_eh_handle_dev_fail()
3505 memset(ehc->cmd_timeout_idx[dev->devno], 0, in ata_eh_handle_dev_fail()
3506 sizeof(ehc->cmd_timeout_idx[dev->devno])); in ata_eh_handle_dev_fail()
3511 ehc->i.action |= ATA_EH_RESET; in ata_eh_handle_dev_fail()
3517 * ata_eh_recover - recover host port after error
3536 * 0 on success, -errno on failure.
3552 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3554 /* re-enable link? */ in ata_eh_recover()
3555 if (ehc->i.action & ATA_EH_ENABLE_LINK) { in ata_eh_recover()
3557 spin_lock_irqsave(ap->lock, flags); in ata_eh_recover()
3558 link->flags &= ~ATA_LFLAG_DISABLED; in ata_eh_recover()
3559 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_recover()
3564 if (link->flags & ATA_LFLAG_NO_RETRY) in ata_eh_recover()
3565 ehc->tries[dev->devno] = 1; in ata_eh_recover()
3567 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; in ata_eh_recover()
3570 ehc->i.action |= ehc->i.dev_action[dev->devno] & in ata_eh_recover()
3572 ehc->i.dev_action[dev->devno] &= ATA_EH_PERDEV_MASK; in ata_eh_recover()
3575 if (dev->flags & ATA_DFLAG_DETACH) in ata_eh_recover()
3588 if (ap->pflags & ATA_PFLAG_UNLOADING) in ata_eh_recover()
3593 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3597 ehc->i.action = 0; in ata_eh_recover()
3600 ehc->classes[dev->devno] = ATA_DEV_UNKNOWN; in ata_eh_recover()
3605 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3607 if (!(ehc->i.action & ATA_EH_RESET)) in ata_eh_recover()
3623 * ap->park_req_pending in ata_eh_recover()
3630 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3633 if (dev->class != ATA_DEV_ATA && in ata_eh_recover()
3634 dev->class != ATA_DEV_ZAC) in ata_eh_recover()
3636 if (!(ehc->i.dev_action[dev->devno] & in ata_eh_recover()
3639 tmp = dev->unpark_deadline; in ata_eh_recover()
3644 if (ehc->unloaded_mask & (1 << dev->devno)) in ata_eh_recover()
3656 deadline = wait_for_completion_timeout(&ap->park_req_pending, in ata_eh_recover()
3657 deadline - now); in ata_eh_recover()
3662 if (!(link->eh_context.unloaded_mask & in ata_eh_recover()
3663 (1 << dev->devno))) in ata_eh_recover()
3674 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3685 if (link->device->class == ATA_DEV_PMP) { in ata_eh_recover()
3686 ehc->i.action = 0; in ata_eh_recover()
3691 if (ehc->i.flags & ATA_EHI_SETMODE) { in ata_eh_recover()
3695 ehc->i.flags &= ~ATA_EHI_SETMODE; in ata_eh_recover()
3701 if (ehc->i.flags & ATA_EHI_DID_RESET) { in ata_eh_recover()
3703 if (dev->class != ATA_DEV_ATAPI) in ata_eh_recover()
3715 if (dev->class != ATA_DEV_ATA && in ata_eh_recover()
3716 dev->class != ATA_DEV_ZAC) in ata_eh_recover()
3725 if (link->lpm_policy != ap->target_lpm_policy) { in ata_eh_recover()
3726 rc = ata_eh_set_lpm(link, ap->target_lpm_policy, &dev); in ata_eh_recover()
3732 ehc->i.flags = 0; in ata_eh_recover()
3740 if (ap->pflags & ATA_PFLAG_FROZEN) { in ata_eh_recover()
3762 * ata_eh_finish - finish up EH
3778 if (!(qc->flags & ATA_QCFLAG_FAILED)) in ata_eh_finish()
3781 if (qc->err_mask) { in ata_eh_finish()
3786 if (qc->flags & ATA_QCFLAG_RETRY) in ata_eh_finish()
3791 if (qc->flags & ATA_QCFLAG_SENSE_VALID) { in ata_eh_finish()
3795 memset(&qc->result_tf, 0, sizeof(qc->result_tf)); in ata_eh_finish()
3802 WARN_ON(ap->nr_active_links); in ata_eh_finish()
3803 ap->nr_active_links = 0; in ata_eh_finish()
3807 * ata_do_eh - do standard error handling
3833 ata_for_each_dev(dev, &ap->link, ALL) in ata_do_eh()
3841 * ata_std_error_handler - standard error handler
3851 struct ata_port_operations *ops = ap->ops; in ata_std_error_handler()
3852 ata_reset_fn_t hardreset = ops->hardreset; in ata_std_error_handler()
3854 /* ignore built-in hardreset if SCR access is not available */ in ata_std_error_handler()
3855 if (hardreset == sata_std_hardreset && !sata_scr_valid(&ap->link)) in ata_std_error_handler()
3858 ata_do_eh(ap, ops->prereset, ops->softreset, hardreset, ops->postreset); in ata_std_error_handler()
3864 * ata_eh_handle_port_suspend - perform port suspend operation
3879 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_suspend()
3880 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) || in ata_eh_handle_port_suspend()
3881 ap->pm_mesg.event & PM_EVENT_RESUME) { in ata_eh_handle_port_suspend()
3882 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_suspend()
3885 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_suspend()
3887 WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED); in ata_eh_handle_port_suspend()
3894 if (PMSG_IS_AUTO(ap->pm_mesg)) { in ata_eh_handle_port_suspend()
3895 ata_for_each_dev(dev, &ap->link, ENABLED) { in ata_eh_handle_port_suspend()
3909 if (ap->ops->port_suspend) in ata_eh_handle_port_suspend()
3910 rc = ap->ops->port_suspend(ap, ap->pm_mesg); in ata_eh_handle_port_suspend()
3912 ata_acpi_set_state(ap, ap->pm_mesg); in ata_eh_handle_port_suspend()
3915 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_suspend()
3917 ap->pflags &= ~ATA_PFLAG_PM_PENDING; in ata_eh_handle_port_suspend()
3919 ap->pflags |= ATA_PFLAG_SUSPENDED; in ata_eh_handle_port_suspend()
3920 else if (ap->pflags & ATA_PFLAG_FROZEN) in ata_eh_handle_port_suspend()
3923 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_suspend()
3929 * ata_eh_handle_port_resume - perform port resume operation
3944 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_resume()
3945 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) || in ata_eh_handle_port_resume()
3946 !(ap->pm_mesg.event & PM_EVENT_RESUME)) { in ata_eh_handle_port_resume()
3947 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_resume()
3950 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_resume()
3952 WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED)); in ata_eh_handle_port_resume()
3958 * downs if the machine is suspended and resumed repeatedly. in ata_eh_handle_port_resume()
3963 ata_ering_clear(&dev->ering); in ata_eh_handle_port_resume()
3965 ata_acpi_set_state(ap, ap->pm_mesg); in ata_eh_handle_port_resume()
3967 if (ap->ops->port_resume) in ata_eh_handle_port_resume()
3968 ap->ops->port_resume(ap); in ata_eh_handle_port_resume()
3974 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_resume()
3975 ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED); in ata_eh_handle_port_resume()
3976 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_resume()