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
172 ehi->desc_len += vscnprintf(ehi->desc + ehi->desc_len, in __ata_ehi_pushv_desc()
173 ATA_EH_DESC_LEN - ehi->desc_len, in __ata_ehi_pushv_desc()
178 * __ata_ehi_push_desc - push error description without adding separator
182 * Format string according to @fmt and append it to @ehi->desc.
198 * ata_ehi_push_desc - push error description with separator
202 * Format string according to @fmt and append it to @ehi->desc.
203 * If @ehi->desc is not empty, ", " is added in-between.
212 if (ehi->desc_len) in ata_ehi_push_desc()
222 * ata_ehi_clear_desc - clean error description
225 * Clear @ehi->desc.
232 ehi->desc[0] = '\0'; in ata_ehi_clear_desc()
233 ehi->desc_len = 0; in ata_ehi_clear_desc()
238 * ata_port_desc - append port description
244 * in-between. This function is to be used while initializing
254 WARN_ON(!(ap->pflags & ATA_PFLAG_INITIALIZING)); in ata_port_desc()
256 if (ap->link.eh_info.desc_len) in ata_port_desc()
257 __ata_ehi_push_desc(&ap->link.eh_info, " "); in ata_port_desc()
260 __ata_ehi_pushv_desc(&ap->link.eh_info, fmt, args); in ata_port_desc()
267 * ata_port_pbar_desc - append PCI BAR description
284 struct pci_dev *pdev = to_pci_dev(ap->host->dev); in ata_port_pbar_desc()
317 return -1; in ata_lookup_timeout_table()
321 * ata_internal_cmd_timeout - determine timeout for an internal command
335 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_internal_cmd_timeout()
342 idx = ehc->cmd_timeout_idx[dev->devno][ent]; in ata_internal_cmd_timeout()
347 * ata_internal_cmd_timed_out - notification for internal command timeout
360 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_internal_cmd_timed_out()
367 idx = ehc->cmd_timeout_idx[dev->devno][ent]; in ata_internal_cmd_timed_out()
369 ehc->cmd_timeout_idx[dev->devno][ent]++; in ata_internal_cmd_timed_out()
379 ering->cursor++; in ata_ering_record()
380 ering->cursor %= ATA_ERING_SIZE; in ata_ering_record()
382 ent = &ering->ring[ering->cursor]; in ata_ering_record()
383 ent->eflags = eflags; in ata_ering_record()
384 ent->err_mask = err_mask; in ata_ering_record()
385 ent->timestamp = get_jiffies_64(); in ata_ering_record()
390 struct ata_ering_entry *ent = &ering->ring[ering->cursor]; in ata_ering_top()
392 if (ent->err_mask) in ata_ering_top()
404 idx = ering->cursor; in ata_ering_map()
406 ent = &ering->ring[idx]; in ata_ering_map()
407 if (!ent->err_mask) in ata_ering_map()
412 idx = (idx - 1 + ATA_ERING_SIZE) % ATA_ERING_SIZE; in ata_ering_map()
413 } while (idx != ering->cursor); in ata_ering_map()
420 ent->eflags |= ATA_EFLAG_OLD_ER; in ata_ering_clear_cb()
431 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_dev_action()
433 return ehc->i.action | ehc->i.dev_action[dev->devno]; in ata_eh_dev_action()
442 ehi->action &= ~action; in ata_eh_clear_action()
444 ehi->dev_action[tdev->devno] &= ~action; in ata_eh_clear_action()
446 /* doesn't make sense for port-wide EH actions */ in ata_eh_clear_action()
449 /* break ehi->action into ehi->dev_action */ in ata_eh_clear_action()
450 if (ehi->action & action) { in ata_eh_clear_action()
452 ehi->dev_action[tdev->devno] |= in ata_eh_clear_action()
453 ehi->action & action; in ata_eh_clear_action()
454 ehi->action &= ~action; in ata_eh_clear_action()
457 /* turn off the specified per-dev action */ in ata_eh_clear_action()
458 ehi->dev_action[dev->devno] &= ~action; in ata_eh_clear_action()
463 * ata_eh_acquire - acquire EH ownership
475 mutex_lock(&ap->host->eh_mutex); in ata_eh_acquire()
476 WARN_ON_ONCE(ap->host->eh_owner); in ata_eh_acquire()
477 ap->host->eh_owner = current; in ata_eh_acquire()
481 * ata_eh_release - release EH ownership
492 WARN_ON_ONCE(ap->host->eh_owner != current); in ata_eh_release()
493 ap->host->eh_owner = NULL; in ata_eh_release()
494 mutex_unlock(&ap->host->eh_mutex); in ata_eh_release()
519 sata_scr_write(link, SCR_CONTROL, link->saved_scontrol & 0xff0); in ata_eh_unload()
525 spin_lock_irqsave(ap->lock, flags); in ata_eh_unload()
528 ap->pflags &= ~ATA_PFLAG_EH_PENDING; /* clear pending from freeze */ in ata_eh_unload()
529 ap->pflags |= ATA_PFLAG_UNLOADED; in ata_eh_unload()
531 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_unload()
535 * ata_scsi_error - SCSI layer error handler callback
538 * Handles SCSI-layer-thrown error events.
552 spin_lock_irqsave(host->host_lock, flags); in ata_scsi_error()
553 list_splice_init(&host->eh_cmd_q, &eh_work_q); in ata_scsi_error()
554 spin_unlock_irqrestore(host->host_lock, flags); in ata_scsi_error()
568 * ata_scsi_cmd_error_handler - error callback for a list of commands
574 * ap->eh_done_q. This function is the first part of the libata error
591 * For EH, all qcs are finished in one of three ways - in ata_scsi_cmd_error_handler()
603 spin_lock_irqsave(ap->lock, flags); in ata_scsi_cmd_error_handler()
606 * This must occur under the ap->lock as we don't want in ata_scsi_cmd_error_handler()
610 * non-notified command and completes much like an IRQ handler. in ata_scsi_cmd_error_handler()
615 if (ap->ops->lost_interrupt) in ata_scsi_cmd_error_handler()
616 ap->ops->lost_interrupt(ap); in ata_scsi_cmd_error_handler()
622 * If the scmd was added to EH, via ata_qc_schedule_eh() -> in ata_scsi_cmd_error_handler()
623 * scsi_timeout() -> scsi_eh_scmd_add(), scsi_timeout() will in ata_scsi_cmd_error_handler()
630 if (qc->flags & ATA_QCFLAG_ACTIVE && in ata_scsi_cmd_error_handler()
631 qc->scsicmd == scmd) in ata_scsi_cmd_error_handler()
637 if (!(qc->flags & ATA_QCFLAG_EH)) { in ata_scsi_cmd_error_handler()
640 qc->err_mask |= AC_ERR_TIMEOUT; in ata_scsi_cmd_error_handler()
641 qc->flags |= ATA_QCFLAG_EH; in ata_scsi_cmd_error_handler()
649 scmd->retries = scmd->allowed; in ata_scsi_cmd_error_handler()
650 scsi_eh_finish_cmd(scmd, &ap->eh_done_q); in ata_scsi_cmd_error_handler()
665 ap->eh_tries = ATA_EH_MAX_TRIES; in ata_scsi_cmd_error_handler()
667 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_cmd_error_handler()
672 * ata_scsi_port_error_handler - recover the port after the commands
688 del_timer_sync(&ap->fastdrain_timer); in ata_scsi_port_error_handler()
694 spin_lock_irqsave(ap->lock, flags); in ata_scsi_port_error_handler()
697 struct ata_eh_context *ehc = &link->eh_context; in ata_scsi_port_error_handler()
700 memset(&link->eh_context, 0, sizeof(link->eh_context)); in ata_scsi_port_error_handler()
701 link->eh_context.i = link->eh_info; in ata_scsi_port_error_handler()
702 memset(&link->eh_info, 0, sizeof(link->eh_info)); in ata_scsi_port_error_handler()
705 int devno = dev->devno; in ata_scsi_port_error_handler()
707 ehc->saved_xfer_mode[devno] = dev->xfer_mode; in ata_scsi_port_error_handler()
709 ehc->saved_ncq_enabled |= 1 << devno; in ata_scsi_port_error_handler()
712 if (ap->pflags & ATA_PFLAG_RESUMING) { in ata_scsi_port_error_handler()
713 dev->flags |= ATA_DFLAG_RESUMING; in ata_scsi_port_error_handler()
714 ehc->i.dev_action[devno] |= ATA_EH_SET_ACTIVE; in ata_scsi_port_error_handler()
719 ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS; in ata_scsi_port_error_handler()
720 ap->pflags &= ~ATA_PFLAG_EH_PENDING; in ata_scsi_port_error_handler()
721 ap->excl_link = NULL; /* don't maintain exclusion over EH */ in ata_scsi_port_error_handler()
723 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
726 if (!(ap->pflags & (ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED))) in ata_scsi_port_error_handler()
727 ap->ops->error_handler(ap); in ata_scsi_port_error_handler()
730 if ((ap->pflags & ATA_PFLAG_UNLOADING) && in ata_scsi_port_error_handler()
731 !(ap->pflags & ATA_PFLAG_UNLOADED)) in ata_scsi_port_error_handler()
740 * Exception might have happened after ->error_handler recovered the in ata_scsi_port_error_handler()
743 spin_lock_irqsave(ap->lock, flags); in ata_scsi_port_error_handler()
745 if (ap->pflags & ATA_PFLAG_EH_PENDING) { in ata_scsi_port_error_handler()
746 if (--ap->eh_tries) { in ata_scsi_port_error_handler()
747 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
753 ap->pflags &= ~ATA_PFLAG_EH_PENDING; in ata_scsi_port_error_handler()
758 memset(&link->eh_info, 0, sizeof(link->eh_info)); in ata_scsi_port_error_handler()
761 * end eh (clear host_eh_scheduled) while holding ap->lock such that if in ata_scsi_port_error_handler()
763 * midlayer will re-initiate EH. in ata_scsi_port_error_handler()
765 ap->ops->end_eh(ap); in ata_scsi_port_error_handler()
767 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
770 scsi_eh_flush_done_q(&ap->eh_done_q); in ata_scsi_port_error_handler()
773 spin_lock_irqsave(ap->lock, flags); in ata_scsi_port_error_handler()
775 ap->pflags &= ~ATA_PFLAG_RESUMING; in ata_scsi_port_error_handler()
777 if (ap->pflags & ATA_PFLAG_LOADING) in ata_scsi_port_error_handler()
778 ap->pflags &= ~ATA_PFLAG_LOADING; in ata_scsi_port_error_handler()
779 else if ((ap->pflags & ATA_PFLAG_SCSI_HOTPLUG) && in ata_scsi_port_error_handler()
780 !(ap->flags & ATA_FLAG_SAS_HOST)) in ata_scsi_port_error_handler()
781 schedule_delayed_work(&ap->hotplug_task, 0); in ata_scsi_port_error_handler()
783 if (ap->pflags & ATA_PFLAG_RECOVERED) in ata_scsi_port_error_handler()
786 ap->pflags &= ~(ATA_PFLAG_SCSI_HOTPLUG | ATA_PFLAG_RECOVERED); in ata_scsi_port_error_handler()
789 ap->pflags &= ~ATA_PFLAG_EH_IN_PROGRESS; in ata_scsi_port_error_handler()
790 wake_up_all(&ap->eh_wait_q); in ata_scsi_port_error_handler()
792 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_port_error_handler()
797 * ata_port_wait_eh - Wait for the currently pending EH to complete
811 spin_lock_irqsave(ap->lock, flags); in ata_port_wait_eh()
813 while (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) { in ata_port_wait_eh()
814 prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE); in ata_port_wait_eh()
815 spin_unlock_irqrestore(ap->lock, flags); in ata_port_wait_eh()
817 spin_lock_irqsave(ap->lock, flags); in ata_port_wait_eh()
819 finish_wait(&ap->eh_wait_q, &wait); in ata_port_wait_eh()
821 spin_unlock_irqrestore(ap->lock, flags); in ata_port_wait_eh()
824 if (scsi_host_in_recovery(ap->scsi_host)) { in ata_port_wait_eh()
837 /* count only non-internal commands */ in ata_eh_nr_in_flight()
852 spin_lock_irqsave(ap->lock, flags); in ata_eh_fastdrain_timerfn()
860 if (cnt == ap->fastdrain_cnt) { in ata_eh_fastdrain_timerfn()
865 * in-flight qcs as timed out and freeze the port. in ata_eh_fastdrain_timerfn()
869 qc->err_mask |= AC_ERR_TIMEOUT; in ata_eh_fastdrain_timerfn()
875 ap->fastdrain_cnt = cnt; in ata_eh_fastdrain_timerfn()
876 ap->fastdrain_timer.expires = in ata_eh_fastdrain_timerfn()
878 add_timer(&ap->fastdrain_timer); in ata_eh_fastdrain_timerfn()
882 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_fastdrain_timerfn()
886 * ata_eh_set_pending - set ATA_PFLAG_EH_PENDING and activate fast drain
891 * is non-zero and EH wasn't pending before. Fast drain ensures
902 if (ap->pflags & ATA_PFLAG_EH_PENDING) in ata_eh_set_pending()
905 ap->pflags |= ATA_PFLAG_EH_PENDING; in ata_eh_set_pending()
910 /* do we have in-flight qcs? */ in ata_eh_set_pending()
916 ap->fastdrain_cnt = cnt; in ata_eh_set_pending()
917 ap->fastdrain_timer.expires = in ata_eh_set_pending()
919 add_timer(&ap->fastdrain_timer); in ata_eh_set_pending()
923 * ata_qc_schedule_eh - schedule qc for error handling
934 struct ata_port *ap = qc->ap; in ata_qc_schedule_eh()
936 qc->flags |= ATA_QCFLAG_EH; in ata_qc_schedule_eh()
944 blk_abort_request(scsi_cmd_to_rq(qc->scsicmd)); in ata_qc_schedule_eh()
948 * ata_std_sched_eh - non-libsas ata_ports issue eh with this common routine
956 if (ap->pflags & ATA_PFLAG_INITIALIZING) in ata_std_sched_eh()
960 scsi_schedule_eh(ap->scsi_host); in ata_std_sched_eh()
967 * ata_std_end_eh - non-libsas ata_ports complete eh with this common routine
971 * shost, so host fields can be directly manipulated under ap->lock, in
972 * the libsas case we need to hold a lock at the ha->level to coordinate
980 struct Scsi_Host *host = ap->scsi_host; in ata_std_end_eh()
982 host->host_eh_scheduled = 0; in ata_std_end_eh()
988 * ata_port_schedule_eh - schedule error handling without a qc
1000 ap->ops->sched_eh(ap); in ata_port_schedule_eh()
1014 if (qc && (!link || qc->dev->link == link)) { in ata_do_link_abort()
1015 qc->flags |= ATA_QCFLAG_EH; in ata_do_link_abort()
1028 * ata_link_abort - abort all qc's on the link
1041 return ata_do_link_abort(link->ap, link); in ata_link_abort()
1046 * ata_port_abort - abort all qc's on the port
1064 * __ata_port_freeze - freeze port
1072 * ap->ops->freeze() callback can be used for freezing the port
1073 * hardware-wise (e.g. mask interrupt and stop DMA engine). If a
1074 * port cannot be frozen hardware-wise, the interrupt handler
1083 if (ap->ops->freeze) in __ata_port_freeze()
1084 ap->ops->freeze(ap); in __ata_port_freeze()
1086 ap->pflags |= ATA_PFLAG_FROZEN; in __ata_port_freeze()
1092 * ata_port_freeze - abort & freeze port
1114 * ata_eh_freeze_port - EH helper to freeze port
1126 spin_lock_irqsave(ap->lock, flags); in ata_eh_freeze_port()
1128 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_freeze_port()
1133 * ata_eh_thaw_port - EH helper to thaw port
1145 spin_lock_irqsave(ap->lock, flags); in ata_eh_thaw_port()
1147 ap->pflags &= ~ATA_PFLAG_FROZEN; in ata_eh_thaw_port()
1149 if (ap->ops->thaw) in ata_eh_thaw_port()
1150 ap->ops->thaw(ap); in ata_eh_thaw_port()
1152 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_thaw_port()
1164 struct ata_port *ap = qc->ap; in __ata_eh_qc_complete()
1165 struct scsi_cmnd *scmd = qc->scsicmd; in __ata_eh_qc_complete()
1168 spin_lock_irqsave(ap->lock, flags); in __ata_eh_qc_complete()
1169 qc->scsidone = ata_eh_scsidone; in __ata_eh_qc_complete()
1171 WARN_ON(ata_tag_valid(qc->tag)); in __ata_eh_qc_complete()
1172 spin_unlock_irqrestore(ap->lock, flags); in __ata_eh_qc_complete()
1174 scsi_eh_finish_cmd(scmd, &ap->eh_done_q); in __ata_eh_qc_complete()
1178 * ata_eh_qc_complete - Complete an active ATA command from EH
1186 struct scsi_cmnd *scmd = qc->scsicmd; in ata_eh_qc_complete()
1187 scmd->retries = scmd->allowed; in ata_eh_qc_complete()
1192 * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
1198 * SCSI midlayer limits the number of retries to scmd->allowed.
1199 * scmd->allowed is incremented for commands which get retried
1200 * due to unrelated failures (qc->err_mask is zero).
1204 struct scsi_cmnd *scmd = qc->scsicmd; in ata_eh_qc_retry()
1205 if (!qc->err_mask) in ata_eh_qc_retry()
1206 scmd->allowed++; in ata_eh_qc_retry()
1211 * ata_dev_disable - disable ATA device
1227 dev->class++; in ata_dev_disable()
1232 ata_ering_clear(&dev->ering); in ata_dev_disable()
1237 * ata_eh_detach_dev - detach ATA device
1247 struct ata_link *link = dev->link; in ata_eh_detach_dev()
1248 struct ata_port *ap = link->ap; in ata_eh_detach_dev()
1249 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_detach_dev()
1261 spin_lock_irqsave(ap->lock, flags); in ata_eh_detach_dev()
1263 dev->flags &= ~ATA_DFLAG_DETACH; in ata_eh_detach_dev()
1266 dev->flags |= ATA_DFLAG_DETACHED; in ata_eh_detach_dev()
1267 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG; in ata_eh_detach_dev()
1270 /* clear per-dev EH info */ in ata_eh_detach_dev()
1271 ata_eh_clear_action(link, dev, &link->eh_info, ATA_EH_PERDEV_MASK); in ata_eh_detach_dev()
1272 ata_eh_clear_action(link, dev, &link->eh_context.i, ATA_EH_PERDEV_MASK); in ata_eh_detach_dev()
1273 ehc->saved_xfer_mode[dev->devno] = 0; in ata_eh_detach_dev()
1274 ehc->saved_ncq_enabled &= ~(1 << dev->devno); in ata_eh_detach_dev()
1276 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_detach_dev()
1280 * ata_eh_about_to_do - about to perform eh_action
1282 * @dev: target ATA dev for per-dev action (can be NULL)
1286 * in @link->eh_info such that eh actions are not unnecessarily
1295 struct ata_port *ap = link->ap; in ata_eh_about_to_do()
1296 struct ata_eh_info *ehi = &link->eh_info; in ata_eh_about_to_do()
1297 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_about_to_do()
1300 trace_ata_eh_about_to_do(link, dev ? dev->devno : 0, action); in ata_eh_about_to_do()
1302 spin_lock_irqsave(ap->lock, flags); in ata_eh_about_to_do()
1309 if (!(ehc->i.flags & ATA_EHI_QUIET) && link != ap->slave_link) in ata_eh_about_to_do()
1310 ap->pflags |= ATA_PFLAG_RECOVERED; in ata_eh_about_to_do()
1312 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_about_to_do()
1316 * ata_eh_done - EH action complete
1318 * @dev: target ATA dev for per-dev action (can be NULL)
1322 * in @link->eh_context.
1330 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_done()
1332 trace_ata_eh_done(link, dev ? dev->devno : 0, action); in ata_eh_done()
1334 ata_eh_clear_action(link, dev, &ehc->i, action); in ata_eh_done()
1338 * ata_err_string - convert err_mask to descriptive string
1377 * atapi_eh_tur - perform ATAPI TEST_UNIT_READY
1408 * ata_eh_request_sense - perform REQUEST_SENSE_DATA_EXT
1422 struct scsi_cmnd *cmd = qc->scsicmd; in ata_eh_request_sense()
1423 struct ata_device *dev = qc->dev; in ata_eh_request_sense()
1427 if (ata_port_is_frozen(qc->ap)) { in ata_eh_request_sense()
1432 if (!ata_id_sense_reporting_enabled(dev->id)) { in ata_eh_request_sense()
1433 ata_dev_warn(qc->dev, "sense data reporting disabled\n"); in ata_eh_request_sense()
1447 /* Set sense without also setting scsicmd->result */ in ata_eh_request_sense()
1448 scsi_build_sense_buffer(dev->flags & ATA_DFLAG_D_SENSE, in ata_eh_request_sense()
1449 cmd->sense_buffer, tf.lbah, in ata_eh_request_sense()
1451 qc->flags |= ATA_QCFLAG_SENSE_VALID; in ata_eh_request_sense()
1463 * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE
1482 struct ata_port *ap = dev->link->ap; in atapi_eh_request_sense()
1488 * for the case where they are -not- overwritten in atapi_eh_request_sense()
1507 if ((ap->flags & ATA_FLAG_PIO_DMA) && !(dev->flags & ATA_DFLAG_PIO)) { in atapi_eh_request_sense()
1521 * ata_eh_analyze_serror - analyze SError for a failed port
1532 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_analyze_serror()
1533 u32 serror = ehc->i.serror; in ata_eh_analyze_serror()
1555 if (link->lpm_policy > ATA_LPM_MAX_POWER) in ata_eh_analyze_serror()
1557 else if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link)) in ata_eh_analyze_serror()
1563 ata_ehi_hotplugged(&ehc->i); in ata_eh_analyze_serror()
1565 ehc->i.err_mask |= err_mask; in ata_eh_analyze_serror()
1566 ehc->i.action |= action; in ata_eh_analyze_serror()
1570 * ata_eh_analyze_tf - analyze taskfile of a failed qc
1585 const struct ata_taskfile *tf = &qc->result_tf; in ata_eh_analyze_tf()
1587 u8 stat = tf->status, err = tf->error; in ata_eh_analyze_tf()
1590 qc->err_mask |= AC_ERR_HSM; in ata_eh_analyze_tf()
1595 qc->err_mask |= AC_ERR_DEV; in ata_eh_analyze_tf()
1606 switch (qc->dev->class) { in ata_eh_analyze_tf()
1611 * -It was a non-NCQ command that failed, or in ata_eh_analyze_tf()
1612 * -It was a NCQ command that failed, but the sense data in ata_eh_analyze_tf()
1616 if (!(qc->flags & ATA_QCFLAG_SENSE_VALID) && in ata_eh_analyze_tf()
1618 set_status_byte(qc->scsicmd, SAM_STAT_CHECK_CONDITION); in ata_eh_analyze_tf()
1620 qc->err_mask |= AC_ERR_ATA_BUS; in ata_eh_analyze_tf()
1622 qc->err_mask |= AC_ERR_MEDIA; in ata_eh_analyze_tf()
1624 qc->err_mask |= AC_ERR_INVALID; in ata_eh_analyze_tf()
1628 if (!ata_port_is_frozen(qc->ap)) { in ata_eh_analyze_tf()
1629 tmp = atapi_eh_request_sense(qc->dev, in ata_eh_analyze_tf()
1630 qc->scsicmd->sense_buffer, in ata_eh_analyze_tf()
1631 qc->result_tf.error >> 4); in ata_eh_analyze_tf()
1633 qc->flags |= ATA_QCFLAG_SENSE_VALID; in ata_eh_analyze_tf()
1635 qc->err_mask |= tmp; in ata_eh_analyze_tf()
1639 if (qc->flags & ATA_QCFLAG_SENSE_VALID) { in ata_eh_analyze_tf()
1640 enum scsi_disposition ret = scsi_check_sense(qc->scsicmd); in ata_eh_analyze_tf()
1651 qc->flags |= ATA_QCFLAG_RETRY; in ata_eh_analyze_tf()
1652 qc->err_mask |= AC_ERR_OTHER; in ata_eh_analyze_tf()
1654 qc->err_mask |= AC_ERR_HSM; in ata_eh_analyze_tf()
1657 if (qc->err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT | AC_ERR_ATA_BUS)) in ata_eh_analyze_tf()
1702 if ((ent->eflags & ATA_EFLAG_OLD_ER) || (ent->timestamp < arg->since)) in speed_down_verdict_cb()
1703 return -1; in speed_down_verdict_cb()
1705 cat = ata_eh_categorize_error(ent->eflags, ent->err_mask, in speed_down_verdict_cb()
1706 &arg->xfer_ok); in speed_down_verdict_cb()
1707 arg->nr_errors[cat]++; in speed_down_verdict_cb()
1713 * ata_eh_speed_down_verdict - Determine speed down verdict
1740 * taken per error. An action triggered by non-DUBIOUS errors
1778 arg.since = j64 - min(j64, j5mins); in ata_eh_speed_down_verdict()
1779 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); in ata_eh_speed_down_verdict()
1797 arg.since = j64 - min(j64, j10mins); in ata_eh_speed_down_verdict()
1798 ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg); in ata_eh_speed_down_verdict()
1813 * ata_eh_speed_down - record error and speed down if necessary
1837 /* don't bother if Cat-0 error */ in ata_eh_speed_down()
1842 ata_ering_record(&dev->ering, eflags, err_mask); in ata_eh_speed_down()
1847 dev->flags |= ATA_DFLAG_NCQ_OFF; in ata_eh_speed_down()
1861 if (dev->spdn_cnt < 2) { in ata_eh_speed_down()
1868 if (dev->xfer_shift != ATA_SHIFT_PIO) in ata_eh_speed_down()
1869 sel = dma_dnxfer_sel[dev->spdn_cnt]; in ata_eh_speed_down()
1871 sel = pio_dnxfer_sel[dev->spdn_cnt]; in ata_eh_speed_down()
1873 dev->spdn_cnt++; in ata_eh_speed_down()
1885 if ((verdict & ATA_EH_SPDN_FALLBACK_TO_PIO) && (dev->spdn_cnt >= 2) && in ata_eh_speed_down()
1886 (link->ap->cbl != ATA_CBL_SATA || dev->class == ATA_DEV_ATAPI) && in ata_eh_speed_down()
1887 (dev->xfer_shift != ATA_SHIFT_PIO)) { in ata_eh_speed_down()
1889 dev->spdn_cnt = 0; in ata_eh_speed_down()
1899 ata_ering_clear(&dev->ering); in ata_eh_speed_down()
1904 * ata_eh_worth_retry - analyze error and decide whether to retry
1909 * because the drive itself has probably already taken 10-30 seconds
1914 if (qc->err_mask & AC_ERR_MEDIA) in ata_eh_worth_retry()
1916 if (qc->flags & ATA_QCFLAG_IO) in ata_eh_worth_retry()
1918 if (qc->err_mask & AC_ERR_INVALID) in ata_eh_worth_retry()
1920 return qc->err_mask != AC_ERR_DEV; /* retry if not dev error */ in ata_eh_worth_retry()
1924 * ata_eh_quiet - check if we need to be quiet about a command error
1932 if (qc->scsicmd && scsi_cmd_to_rq(qc->scsicmd)->rq_flags & RQF_QUIET) in ata_eh_quiet()
1933 qc->flags |= ATA_QCFLAG_QUIET; in ata_eh_quiet()
1934 return qc->flags & ATA_QCFLAG_QUIET; in ata_eh_quiet()
1939 struct ata_port *ap = link->ap; in ata_eh_read_sense_success_non_ncq()
1942 qc = __ata_qc_from_tag(ap, link->active_tag); in ata_eh_read_sense_success_non_ncq()
1944 return -EIO; in ata_eh_read_sense_success_non_ncq()
1946 if (!(qc->flags & ATA_QCFLAG_EH) || in ata_eh_read_sense_success_non_ncq()
1947 !(qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD) || in ata_eh_read_sense_success_non_ncq()
1948 qc->err_mask) in ata_eh_read_sense_success_non_ncq()
1949 return -EIO; in ata_eh_read_sense_success_non_ncq()
1952 return -EIO; in ata_eh_read_sense_success_non_ncq()
1959 scsi_check_sense(qc->scsicmd); in ata_eh_read_sense_success_non_ncq()
1966 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_get_success_sense()
1967 struct ata_device *dev = link->device; in ata_eh_get_success_sense()
1968 struct ata_port *ap = link->ap; in ata_eh_get_success_sense()
1972 if (!(ehc->i.dev_action[dev->devno] & ATA_EH_GET_SUCCESS_SENSE)) in ata_eh_get_success_sense()
1985 * data. Otherwise, we are dealing with a non-NCQ command and use in ata_eh_get_success_sense()
1988 if (link->sactive) in ata_eh_get_success_sense()
2009 if (!(qc->flags & ATA_QCFLAG_EH) || in ata_eh_get_success_sense()
2010 !(qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD) || in ata_eh_get_success_sense()
2011 qc->err_mask || in ata_eh_get_success_sense()
2012 ata_dev_phys_link(qc->dev) != link) in ata_eh_get_success_sense()
2016 if (qc->flags & ATA_QCFLAG_SENSE_VALID) in ata_eh_get_success_sense()
2020 if (!(qc->result_tf.status & ATA_SENSE)) in ata_eh_get_success_sense()
2024 ata_scsi_set_sense(dev, qc->scsicmd, ABORTED_COMMAND, 0, 0); in ata_eh_get_success_sense()
2025 qc->flags |= ATA_QCFLAG_SENSE_VALID; in ata_eh_get_success_sense()
2031 * ata_eh_link_autopsy - analyze error and determine recovery action
2043 struct ata_port *ap = link->ap; in ata_eh_link_autopsy()
2044 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_link_autopsy()
2052 if (ehc->i.flags & ATA_EHI_NO_AUTOPSY) in ata_eh_link_autopsy()
2058 ehc->i.serror |= serror; in ata_eh_link_autopsy()
2060 } else if (rc != -EOPNOTSUPP) { in ata_eh_link_autopsy()
2062 ehc->i.probe_mask |= ATA_ALL_DEVICES; in ata_eh_link_autopsy()
2063 ehc->i.action |= ATA_EH_RESET; in ata_eh_link_autopsy()
2064 ehc->i.err_mask |= AC_ERR_OTHER; in ata_eh_link_autopsy()
2079 if (ehc->i.err_mask & ~AC_ERR_OTHER) in ata_eh_link_autopsy()
2080 ehc->i.err_mask &= ~AC_ERR_OTHER; in ata_eh_link_autopsy()
2082 all_err_mask |= ehc->i.err_mask; in ata_eh_link_autopsy()
2085 if (!(qc->flags & ATA_QCFLAG_EH) || in ata_eh_link_autopsy()
2086 qc->flags & ATA_QCFLAG_RETRY || in ata_eh_link_autopsy()
2087 qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD || in ata_eh_link_autopsy()
2088 ata_dev_phys_link(qc->dev) != link) in ata_eh_link_autopsy()
2092 qc->err_mask |= ehc->i.err_mask; in ata_eh_link_autopsy()
2095 ehc->i.action |= ata_eh_analyze_tf(qc); in ata_eh_link_autopsy()
2098 if (qc->err_mask & AC_ERR_ATA_BUS) in ata_eh_link_autopsy()
2099 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_MEDIA | in ata_eh_link_autopsy()
2103 if (qc->err_mask & ~AC_ERR_OTHER) in ata_eh_link_autopsy()
2104 qc->err_mask &= ~AC_ERR_OTHER; in ata_eh_link_autopsy()
2113 if (qc->flags & ATA_QCFLAG_SENSE_VALID) in ata_eh_link_autopsy()
2114 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER); in ata_eh_link_autopsy()
2116 qc->flags |= ATA_QCFLAG_RETRY; in ata_eh_link_autopsy()
2119 ehc->i.dev = qc->dev; in ata_eh_link_autopsy()
2120 all_err_mask |= qc->err_mask; in ata_eh_link_autopsy()
2121 if (qc->flags & ATA_QCFLAG_IO) in ata_eh_link_autopsy()
2133 ehc->i.flags |= ATA_EHI_QUIET; in ata_eh_link_autopsy()
2138 ehc->i.action |= ATA_EH_RESET; in ata_eh_link_autopsy()
2141 ehc->i.action |= ATA_EH_REVALIDATE; in ata_eh_link_autopsy()
2144 * perform per-dev EH action only on the offending device. in ata_eh_link_autopsy()
2146 if (ehc->i.dev) { in ata_eh_link_autopsy()
2147 ehc->i.dev_action[ehc->i.dev->devno] |= in ata_eh_link_autopsy()
2148 ehc->i.action & ATA_EH_PERDEV_MASK; in ata_eh_link_autopsy()
2149 ehc->i.action &= ~ATA_EH_PERDEV_MASK; in ata_eh_link_autopsy()
2154 ap->link.eh_context.i.err_mask |= AC_ERR_TIMEOUT; in ata_eh_link_autopsy()
2157 dev = ehc->i.dev; in ata_eh_link_autopsy()
2159 ata_dev_enabled(link->device)))) in ata_eh_link_autopsy()
2160 dev = link->device; in ata_eh_link_autopsy()
2163 if (dev->flags & ATA_DFLAG_DUBIOUS_XFER) in ata_eh_link_autopsy()
2165 ehc->i.action |= ata_eh_speed_down(dev, eflags, all_err_mask); in ata_eh_link_autopsy()
2166 trace_ata_eh_link_autopsy(dev, ehc->i.action, all_err_mask); in ata_eh_link_autopsy()
2171 * ata_eh_autopsy - analyze error and determine recovery action
2191 if (ap->slave_link) { in ata_eh_autopsy()
2192 struct ata_eh_context *mehc = &ap->link.eh_context; in ata_eh_autopsy()
2193 struct ata_eh_context *sehc = &ap->slave_link->eh_context; in ata_eh_autopsy()
2196 sehc->i.flags |= mehc->i.flags & ATA_EHI_TO_SLAVE_MASK; in ata_eh_autopsy()
2199 ata_eh_link_autopsy(ap->slave_link); in ata_eh_autopsy()
2202 ata_eh_about_to_do(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS); in ata_eh_autopsy()
2203 mehc->i.action |= sehc->i.action; in ata_eh_autopsy()
2204 mehc->i.dev_action[1] |= sehc->i.dev_action[1]; in ata_eh_autopsy()
2205 mehc->i.flags |= sehc->i.flags; in ata_eh_autopsy()
2206 ata_eh_done(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS); in ata_eh_autopsy()
2213 ata_eh_link_autopsy(&ap->link); in ata_eh_autopsy()
2217 * ata_get_cmd_name - get name for ATA command
2260 { ATA_CMD_NCQ_NON_DATA, "NCQ NON-DATA" }, in ata_get_cmd_name()
2289 { ATA_CMD_TRUSTED_NONDATA, "TRUSTED NON-DATA" }, in ata_get_cmd_name()
2339 * ata_eh_link_report - report error handling to user
2349 struct ata_port *ap = link->ap; in ata_eh_link_report()
2350 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_link_report()
2356 if (ehc->i.flags & ATA_EHI_QUIET) in ata_eh_link_report()
2360 if (ehc->i.desc[0] != '\0') in ata_eh_link_report()
2361 desc = ehc->i.desc; in ata_eh_link_report()
2364 if (!(qc->flags & ATA_QCFLAG_EH) || in ata_eh_link_report()
2365 ata_dev_phys_link(qc->dev) != link || in ata_eh_link_report()
2366 ((qc->flags & ATA_QCFLAG_QUIET) && in ata_eh_link_report()
2367 qc->err_mask == AC_ERR_DEV)) in ata_eh_link_report()
2369 if (qc->flags & ATA_QCFLAG_SENSE_VALID && !qc->err_mask) in ata_eh_link_report()
2375 if (!nr_failed && !ehc->i.err_mask) in ata_eh_link_report()
2382 if (ap->eh_tries < ATA_EH_MAX_TRIES) in ata_eh_link_report()
2384 ap->eh_tries); in ata_eh_link_report()
2386 if (ehc->i.dev) { in ata_eh_link_report()
2387 ata_dev_err(ehc->i.dev, "exception Emask 0x%x " in ata_eh_link_report()
2389 ehc->i.err_mask, link->sactive, ehc->i.serror, in ata_eh_link_report()
2390 ehc->i.action, frozen, tries_buf); in ata_eh_link_report()
2392 ata_dev_err(ehc->i.dev, "%s\n", desc); in ata_eh_link_report()
2396 ehc->i.err_mask, link->sactive, ehc->i.serror, in ata_eh_link_report()
2397 ehc->i.action, frozen, tries_buf); in ata_eh_link_report()
2403 if (ehc->i.serror) in ata_eh_link_report()
2406 ehc->i.serror & SERR_DATA_RECOVERED ? "RecovData " : "", in ata_eh_link_report()
2407 ehc->i.serror & SERR_COMM_RECOVERED ? "RecovComm " : "", in ata_eh_link_report()
2408 ehc->i.serror & SERR_DATA ? "UnrecovData " : "", in ata_eh_link_report()
2409 ehc->i.serror & SERR_PERSISTENT ? "Persist " : "", in ata_eh_link_report()
2410 ehc->i.serror & SERR_PROTOCOL ? "Proto " : "", in ata_eh_link_report()
2411 ehc->i.serror & SERR_INTERNAL ? "HostInt " : "", in ata_eh_link_report()
2412 ehc->i.serror & SERR_PHYRDY_CHG ? "PHYRdyChg " : "", in ata_eh_link_report()
2413 ehc->i.serror & SERR_PHY_INT_ERR ? "PHYInt " : "", in ata_eh_link_report()
2414 ehc->i.serror & SERR_COMM_WAKE ? "CommWake " : "", in ata_eh_link_report()
2415 ehc->i.serror & SERR_10B_8B_ERR ? "10B8B " : "", in ata_eh_link_report()
2416 ehc->i.serror & SERR_DISPARITY ? "Dispar " : "", in ata_eh_link_report()
2417 ehc->i.serror & SERR_CRC ? "BadCRC " : "", in ata_eh_link_report()
2418 ehc->i.serror & SERR_HANDSHAKE ? "Handshk " : "", in ata_eh_link_report()
2419 ehc->i.serror & SERR_LINK_SEQ_ERR ? "LinkSeq " : "", in ata_eh_link_report()
2420 ehc->i.serror & SERR_TRANS_ST_ERROR ? "TrStaTrns " : "", in ata_eh_link_report()
2421 ehc->i.serror & SERR_UNRECOG_FIS ? "UnrecFIS " : "", in ata_eh_link_report()
2422 ehc->i.serror & SERR_DEV_XCHG ? "DevExch " : ""); in ata_eh_link_report()
2426 struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf; in ata_eh_link_report()
2430 if (!(qc->flags & ATA_QCFLAG_EH) || in ata_eh_link_report()
2431 ata_dev_phys_link(qc->dev) != link || !qc->err_mask) in ata_eh_link_report()
2434 if (qc->dma_dir != DMA_NONE) { in ata_eh_link_report()
2442 switch (qc->tf.protocol) { in ata_eh_link_report()
2472 prot_str, qc->nbytes, dma_str[qc->dma_dir]); in ata_eh_link_report()
2475 if (ata_is_atapi(qc->tf.protocol)) { in ata_eh_link_report()
2476 const u8 *cdb = qc->cdb; in ata_eh_link_report()
2477 size_t cdb_len = qc->dev->cdb_len; in ata_eh_link_report()
2479 if (qc->scsicmd) { in ata_eh_link_report()
2480 cdb = qc->scsicmd->cmnd; in ata_eh_link_report()
2481 cdb_len = qc->scsicmd->cmd_len; in ata_eh_link_report()
2486 ata_dev_err(qc->dev, "failed command: %s\n", in ata_eh_link_report()
2487 ata_get_cmd_name(cmd->command)); in ata_eh_link_report()
2489 ata_dev_err(qc->dev, in ata_eh_link_report()
2494 cmd->command, cmd->feature, cmd->nsect, in ata_eh_link_report()
2495 cmd->lbal, cmd->lbam, cmd->lbah, in ata_eh_link_report()
2496 cmd->hob_feature, cmd->hob_nsect, in ata_eh_link_report()
2497 cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah, in ata_eh_link_report()
2498 cmd->device, qc->tag, data_buf, cdb_buf, in ata_eh_link_report()
2499 res->status, res->error, res->nsect, in ata_eh_link_report()
2500 res->lbal, res->lbam, res->lbah, in ata_eh_link_report()
2501 res->hob_feature, res->hob_nsect, in ata_eh_link_report()
2502 res->hob_lbal, res->hob_lbam, res->hob_lbah, in ata_eh_link_report()
2503 res->device, qc->err_mask, ata_err_string(qc->err_mask), in ata_eh_link_report()
2504 qc->err_mask & AC_ERR_NCQ ? " <F>" : ""); in ata_eh_link_report()
2507 if (res->status & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | in ata_eh_link_report()
2509 if (res->status & ATA_BUSY) in ata_eh_link_report()
2510 ata_dev_err(qc->dev, "status: { Busy }\n"); in ata_eh_link_report()
2512 ata_dev_err(qc->dev, "status: { %s%s%s%s%s}\n", in ata_eh_link_report()
2513 res->status & ATA_DRDY ? "DRDY " : "", in ata_eh_link_report()
2514 res->status & ATA_DF ? "DF " : "", in ata_eh_link_report()
2515 res->status & ATA_DRQ ? "DRQ " : "", in ata_eh_link_report()
2516 res->status & ATA_SENSE ? "SENSE " : "", in ata_eh_link_report()
2517 res->status & ATA_ERR ? "ERR " : ""); in ata_eh_link_report()
2520 if (cmd->command != ATA_CMD_PACKET && in ata_eh_link_report()
2521 (res->error & (ATA_ICRC | ATA_UNC | ATA_AMNF | ATA_IDNF | in ata_eh_link_report()
2523 ata_dev_err(qc->dev, "error: { %s%s%s%s%s}\n", in ata_eh_link_report()
2524 res->error & ATA_ICRC ? "ICRC " : "", in ata_eh_link_report()
2525 res->error & ATA_UNC ? "UNC " : "", in ata_eh_link_report()
2526 res->error & ATA_AMNF ? "AMNF " : "", in ata_eh_link_report()
2527 res->error & ATA_IDNF ? "IDNF " : "", in ata_eh_link_report()
2528 res->error & ATA_ABORTED ? "ABRT " : ""); in ata_eh_link_report()
2534 * ata_eh_report - report error handling to user
2558 classes[dev->devno] = ATA_DEV_UNKNOWN; in ata_do_reset()
2565 if ((link->flags & ATA_LFLAG_NO_SRST) || ata_link_offline(link)) in ata_eh_followup_srst_needed()
2567 if (rc == -EAGAIN) in ata_eh_followup_srst_needed()
2569 if (sata_pmp_supported(link->ap) && ata_is_host_link(link)) in ata_eh_followup_srst_needed()
2578 struct ata_port *ap = link->ap; in ata_eh_reset()
2579 struct ata_link *slave = ap->slave_link; in ata_eh_reset()
2580 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_reset()
2581 struct ata_eh_context *sehc = slave ? &slave->eh_context : NULL; in ata_eh_reset()
2582 unsigned int *classes = ehc->classes; in ata_eh_reset()
2583 unsigned int lflags = link->flags; in ata_eh_reset()
2584 int verbose = !(ehc->i.flags & ATA_EHI_QUIET); in ata_eh_reset()
2599 if (link->flags & ATA_LFLAG_RST_ONCE) in ata_eh_reset()
2601 if (link->flags & ATA_LFLAG_NO_HRST) in ata_eh_reset()
2603 if (link->flags & ATA_LFLAG_NO_SRST) in ata_eh_reset()
2607 if (ehc->i.flags & ATA_EHI_DID_RESET) { in ata_eh_reset()
2609 WARN_ON(time_after(ehc->last_reset, now)); in ata_eh_reset()
2610 deadline = ata_deadline(ehc->last_reset, in ata_eh_reset()
2613 schedule_timeout_uninterruptible(deadline - now); in ata_eh_reset()
2616 spin_lock_irqsave(ap->lock, flags); in ata_eh_reset()
2617 ap->pflags |= ATA_PFLAG_RESETTING; in ata_eh_reset()
2618 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_reset()
2630 dev->pio_mode = XFER_PIO_0; in ata_eh_reset()
2631 dev->dma_mode = 0xff; in ata_eh_reset()
2638 if (ap->ops->set_piomode) in ata_eh_reset()
2639 ap->ops->set_piomode(ap, dev); in ata_eh_reset()
2644 ehc->i.action &= ~ATA_EH_RESET; in ata_eh_reset()
2647 ehc->i.action |= ATA_EH_HARDRESET; in ata_eh_reset()
2650 ehc->i.action |= ATA_EH_SOFTRESET; in ata_eh_reset()
2658 sehc->i.action &= ~ATA_EH_RESET; in ata_eh_reset()
2659 sehc->i.action |= ehc->i.action; in ata_eh_reset()
2666 * -ENOENT or clear ATA_EH_RESET. in ata_eh_reset()
2668 if (slave && (rc == 0 || rc == -ENOENT)) { in ata_eh_reset()
2672 if (tmp != -ENOENT) in ata_eh_reset()
2675 ehc->i.action |= sehc->i.action; in ata_eh_reset()
2679 if (rc == -ENOENT) { in ata_eh_reset()
2680 ata_link_dbg(link, "port disabled--ignoring\n"); in ata_eh_reset()
2681 ehc->i.action &= ~ATA_EH_RESET; in ata_eh_reset()
2684 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2697 if (reset && !(ehc->i.action & ATA_EH_RESET)) { in ata_eh_reset()
2699 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2722 ehc->last_reset = jiffies; in ata_eh_reset()
2724 ehc->i.flags |= ATA_EHI_DID_HARDRESET; in ata_eh_reset()
2727 ehc->i.flags |= ATA_EHI_DID_SOFTRESET; in ata_eh_reset()
2736 if (rc && rc != -EAGAIN) { in ata_eh_reset()
2755 case -EAGAIN: in ata_eh_reset()
2756 rc = -EAGAIN; in ata_eh_reset()
2767 /* perform follow-up SRST if necessary */ in ata_eh_reset()
2774 "follow-up softreset required but no softreset available\n"); in ata_eh_reset()
2776 rc = -EINVAL; in ata_eh_reset()
2798 * Post-reset processing in ata_eh_reset()
2805 dev->pio_mode = XFER_PIO_0; in ata_eh_reset()
2806 dev->flags &= ~ATA_DFLAG_SLEEPING; in ata_eh_reset()
2813 classes[dev->devno] = ATA_DEV_ATA; in ata_eh_reset()
2815 classes[dev->devno] = ATA_DEV_SEMB_UNSUP; in ata_eh_reset()
2820 link->sata_spd = (sstatus >> 4) & 0xf; in ata_eh_reset()
2822 slave->sata_spd = (sstatus >> 4) & 0xf; in ata_eh_reset()
2845 spin_lock_irqsave(link->ap->lock, flags); in ata_eh_reset()
2846 link->eh_info.serror = 0; in ata_eh_reset()
2848 slave->eh_info.serror = 0; in ata_eh_reset()
2849 spin_unlock_irqrestore(link->ap->lock, flags); in ata_eh_reset()
2862 if (classes[dev->devno] == ATA_DEV_UNKNOWN) { in ata_eh_reset()
2864 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2868 if (ata_class_enabled(classes[dev->devno])) in ata_eh_reset()
2871 classes[dev->devno]); in ata_eh_reset()
2872 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2873 } else if (classes[dev->devno] == ATA_DEV_UNKNOWN) { in ata_eh_reset()
2876 classes[dev->devno] = ATA_DEV_NONE; in ata_eh_reset()
2886 rc = -EAGAIN; in ata_eh_reset()
2898 ehc->last_reset = jiffies; /* update to completion time */ in ata_eh_reset()
2899 ehc->i.action |= ATA_EH_REVALIDATE; in ata_eh_reset()
2900 link->lpm_policy = ATA_LPM_UNKNOWN; /* reset LPM state */ in ata_eh_reset()
2905 ehc->i.flags &= ~ATA_EHI_HOTPLUGGED; in ata_eh_reset()
2907 sehc->i.flags &= ~ATA_EHI_HOTPLUGGED; in ata_eh_reset()
2909 spin_lock_irqsave(ap->lock, flags); in ata_eh_reset()
2910 ap->pflags &= ~ATA_PFLAG_RESETTING; in ata_eh_reset()
2911 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_reset()
2916 /* if SCR isn't accessible on a fan-out port, PMP needs to be reset */ in ata_eh_reset()
2919 rc = -ERESTART; in ata_eh_reset()
2935 unsigned long delta = deadline - now; in ata_eh_reset()
2949 * They need to be reset - as well as the PMP - before retrying. in ata_eh_reset()
2951 if (rc == -ERESTART) { in ata_eh_reset()
2957 if (try == max_tries - 1) { in ata_eh_reset()
2961 } else if (rc == -EPIPE) in ata_eh_reset()
2983 * timeout updates for the same device, we have to pull in ata_eh_pull_park_action()
2987 * Additionally, all write accesses to &ap->park_req_pending in ata_eh_pull_park_action()
2994 * park_req_pending.done is non-zero by the time we reach in ata_eh_pull_park_action()
3001 spin_lock_irqsave(ap->lock, flags); in ata_eh_pull_park_action()
3002 reinit_completion(&ap->park_req_pending); in ata_eh_pull_park_action()
3005 struct ata_eh_info *ehi = &link->eh_info; in ata_eh_pull_park_action()
3007 link->eh_context.i.dev_action[dev->devno] |= in ata_eh_pull_park_action()
3008 ehi->dev_action[dev->devno] & ATA_EH_PARK; in ata_eh_pull_park_action()
3012 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_pull_park_action()
3017 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_park_issue_cmd()
3023 ehc->unloaded_mask |= 1 << dev->devno; in ata_eh_park_issue_cmd()
3030 ehc->unloaded_mask &= ~(1 << dev->devno); in ata_eh_park_issue_cmd()
3039 ehc->unloaded_mask &= ~(1 << dev->devno); in ata_eh_park_issue_cmd()
3046 struct ata_port *ap = link->ap; in ata_eh_revalidate_and_attach()
3047 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_revalidate_and_attach()
3054 * be done backwards such that PDIAG- is released by the slave in ata_eh_revalidate_and_attach()
3061 if (ehc->i.flags & ATA_EHI_DID_RESET) in ata_eh_revalidate_and_attach()
3074 WARN_ON(dev->class == ATA_DEV_PMP); in ata_eh_revalidate_and_attach()
3084 * to ap->target_lpm_policy after revalidation is done. in ata_eh_revalidate_and_attach()
3086 if (link->lpm_policy > ATA_LPM_MAX_POWER) { in ata_eh_revalidate_and_attach()
3094 rc = -EIO; in ata_eh_revalidate_and_attach()
3099 rc = ata_dev_revalidate(dev, ehc->classes[dev->devno], in ata_eh_revalidate_and_attach()
3109 ehc->i.flags |= ATA_EHI_SETMODE; in ata_eh_revalidate_and_attach()
3112 schedule_delayed_work(&ap->scsi_rescan_task, 0); in ata_eh_revalidate_and_attach()
3113 } else if (dev->class == ATA_DEV_UNKNOWN && in ata_eh_revalidate_and_attach()
3114 ehc->tries[dev->devno] && in ata_eh_revalidate_and_attach()
3115 ata_class_enabled(ehc->classes[dev->devno])) { in ata_eh_revalidate_and_attach()
3116 /* Temporarily set dev->class, it will be in ata_eh_revalidate_and_attach()
3122 dev->class = ehc->classes[dev->devno]; in ata_eh_revalidate_and_attach()
3124 if (dev->class == ATA_DEV_PMP) in ata_eh_revalidate_and_attach()
3127 rc = ata_dev_read_id(dev, &dev->class, in ata_eh_revalidate_and_attach()
3128 readid_flags, dev->id); in ata_eh_revalidate_and_attach()
3131 ehc->classes[dev->devno] = dev->class; in ata_eh_revalidate_and_attach()
3132 dev->class = ATA_DEV_UNKNOWN; in ata_eh_revalidate_and_attach()
3137 ata_ering_clear(&dev->ering); in ata_eh_revalidate_and_attach()
3138 new_mask |= 1 << dev->devno; in ata_eh_revalidate_and_attach()
3140 case -ENOENT: in ata_eh_revalidate_and_attach()
3141 /* IDENTIFY was issued to non-existent in ata_eh_revalidate_and_attach()
3153 /* PDIAG- should have been released, ask cable type if post-reset */ in ata_eh_revalidate_and_attach()
3154 if ((ehc->i.flags & ATA_EHI_DID_RESET) && ata_is_host_link(link)) { in ata_eh_revalidate_and_attach()
3155 if (ap->ops->cable_detect) in ata_eh_revalidate_and_attach()
3156 ap->cbl = ap->ops->cable_detect(ap); in ata_eh_revalidate_and_attach()
3164 if (!(new_mask & (1 << dev->devno))) in ata_eh_revalidate_and_attach()
3167 dev->class = ehc->classes[dev->devno]; in ata_eh_revalidate_and_attach()
3169 if (dev->class == ATA_DEV_PMP) in ata_eh_revalidate_and_attach()
3172 ehc->i.flags |= ATA_EHI_PRINTINFO; in ata_eh_revalidate_and_attach()
3174 ehc->i.flags &= ~ATA_EHI_PRINTINFO; in ata_eh_revalidate_and_attach()
3176 dev->class = ATA_DEV_UNKNOWN; in ata_eh_revalidate_and_attach()
3180 spin_lock_irqsave(ap->lock, flags); in ata_eh_revalidate_and_attach()
3181 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG; in ata_eh_revalidate_and_attach()
3182 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_revalidate_and_attach()
3185 ehc->i.flags |= ATA_EHI_SETMODE; in ata_eh_revalidate_and_attach()
3191 dev->flags &= ~ATA_DFLAG_RESUMING; in ata_eh_revalidate_and_attach()
3197 * ata_set_mode - Program timings and issue SET FEATURES - XFER
3213 struct ata_port *ap = link->ap; in ata_set_mode()
3219 if (!(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) { in ata_set_mode()
3222 ent = ata_ering_top(&dev->ering); in ata_set_mode()
3224 ent->eflags &= ~ATA_EFLAG_DUBIOUS_XFER; in ata_set_mode()
3229 if (ap->ops->set_mode) in ata_set_mode()
3230 rc = ap->ops->set_mode(link, r_failed_dev); in ata_set_mode()
3236 struct ata_eh_context *ehc = &link->eh_context; in ata_set_mode()
3237 u8 saved_xfer_mode = ehc->saved_xfer_mode[dev->devno]; in ata_set_mode()
3238 u8 saved_ncq = !!(ehc->saved_ncq_enabled & (1 << dev->devno)); in ata_set_mode()
3240 if (dev->xfer_mode != saved_xfer_mode || in ata_set_mode()
3242 dev->flags |= ATA_DFLAG_DUBIOUS_XFER; in ata_set_mode()
3249 * atapi_eh_clear_ua - Clear ATAPI UNIT ATTENTION after reset
3260 * 0 on success, -errno on failure.
3267 u8 *sense_buffer = dev->link->ap->sector_buf; in atapi_eh_clear_ua()
3276 return -EIO; in atapi_eh_clear_ua()
3286 return -EIO; in atapi_eh_clear_ua()
3297 * ata_eh_maybe_retry_flush - Retry FLUSH if necessary
3311 * 0 if EH can continue, -errno if EH needs to be repeated.
3315 struct ata_link *link = dev->link; in ata_eh_maybe_retry_flush()
3316 struct ata_port *ap = link->ap; in ata_eh_maybe_retry_flush()
3323 if (!ata_tag_valid(link->active_tag)) in ata_eh_maybe_retry_flush()
3326 qc = __ata_qc_from_tag(ap, link->active_tag); in ata_eh_maybe_retry_flush()
3327 if (qc->dev != dev || (qc->tf.command != ATA_CMD_FLUSH_EXT && in ata_eh_maybe_retry_flush()
3328 qc->tf.command != ATA_CMD_FLUSH)) in ata_eh_maybe_retry_flush()
3332 if (qc->err_mask & AC_ERR_DEV) in ata_eh_maybe_retry_flush()
3338 tf.command = qc->tf.command; in ata_eh_maybe_retry_flush()
3343 tf.command, qc->err_mask); in ata_eh_maybe_retry_flush()
3351 * retrying it should do the trick - whatever was in in ata_eh_maybe_retry_flush()
3355 qc->scsicmd->allowed = max(qc->scsicmd->allowed, 1); in ata_eh_maybe_retry_flush()
3359 rc = -EIO; in ata_eh_maybe_retry_flush()
3363 qc->err_mask |= AC_ERR_DEV; in ata_eh_maybe_retry_flush()
3364 qc->result_tf = tf; in ata_eh_maybe_retry_flush()
3373 * ata_eh_set_lpm - configure SATA interface power management
3387 * 0 on success, -errno on failure.
3392 struct ata_port *ap = ata_is_host_link(link) ? link->ap : NULL; in ata_eh_set_lpm()
3393 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_set_lpm()
3395 enum ata_lpm_policy old_policy = link->lpm_policy; in ata_eh_set_lpm()
3396 bool no_dipm = link->ap->flags & ATA_FLAG_NO_DIPM; in ata_eh_set_lpm()
3403 (link->flags & ATA_LFLAG_NO_LPM) || (ap && !ap->ops->set_lpm)) in ata_eh_set_lpm()
3413 bool hipm = ata_id_has_hipm(dev->id); in ata_eh_set_lpm()
3414 bool dipm = ata_id_has_dipm(dev->id) && !no_dipm; in ata_eh_set_lpm()
3435 rc = -EIO; in ata_eh_set_lpm()
3442 rc = ap->ops->set_lpm(link, policy, hints); in ata_eh_set_lpm()
3443 if (!rc && ap->slave_link) in ata_eh_set_lpm()
3444 rc = ap->ops->set_lpm(ap->slave_link, policy, hints); in ata_eh_set_lpm()
3453 if (rc == -EOPNOTSUPP) { in ata_eh_set_lpm()
3454 link->flags |= ATA_LFLAG_NO_LPM; in ata_eh_set_lpm()
3465 link->lpm_policy = policy; in ata_eh_set_lpm()
3466 if (ap && ap->slave_link) in ata_eh_set_lpm()
3467 ap->slave_link->lpm_policy = policy; in ata_eh_set_lpm()
3472 ata_id_has_dipm(dev->id)) { in ata_eh_set_lpm()
3479 rc = -EIO; in ata_eh_set_lpm()
3485 link->last_lpm_change = jiffies; in ata_eh_set_lpm()
3486 link->flags |= ATA_LFLAG_CHANGED; in ata_eh_set_lpm()
3492 link->lpm_policy = old_policy; in ata_eh_set_lpm()
3493 if (ap && ap->slave_link) in ata_eh_set_lpm()
3494 ap->slave_link->lpm_policy = old_policy; in ata_eh_set_lpm()
3497 if (!dev || ehc->tries[dev->devno] <= 2) { in ata_eh_set_lpm()
3499 link->flags |= ATA_LFLAG_NO_LPM; in ata_eh_set_lpm()
3522 if (dev->class == ATA_DEV_UNKNOWN) in ata_link_nr_vacant()
3529 struct ata_port *ap = link->ap; in ata_eh_skip_recovery()
3530 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_skip_recovery()
3534 if (link->flags & ATA_LFLAG_DISABLED) in ata_eh_skip_recovery()
3538 if (ehc->i.flags & ATA_EHI_NO_RECOVERY) in ata_eh_skip_recovery()
3546 if ((ehc->i.action & ATA_EH_RESET) && in ata_eh_skip_recovery()
3547 !(ehc->i.flags & ATA_EHI_DID_RESET)) in ata_eh_skip_recovery()
3552 if (dev->class == ATA_DEV_UNKNOWN && in ata_eh_skip_recovery()
3553 ehc->classes[dev->devno] != ATA_DEV_NONE) in ata_eh_skip_recovery()
3566 if ((ent->eflags & ATA_EFLAG_OLD_ER) || in ata_count_probe_trials_cb()
3567 (ent->timestamp < now - min(now, interval))) in ata_count_probe_trials_cb()
3568 return -1; in ata_count_probe_trials_cb()
3576 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_schedule_probe()
3580 if (!(ehc->i.probe_mask & (1 << dev->devno)) || in ata_eh_schedule_probe()
3581 (ehc->did_probe_mask & (1 << dev->devno))) in ata_eh_schedule_probe()
3586 ehc->did_probe_mask |= (1 << dev->devno); in ata_eh_schedule_probe()
3587 ehc->i.action |= ATA_EH_RESET; in ata_eh_schedule_probe()
3588 ehc->saved_xfer_mode[dev->devno] = 0; in ata_eh_schedule_probe()
3589 ehc->saved_ncq_enabled &= ~(1 << dev->devno); in ata_eh_schedule_probe()
3592 if (link->lpm_policy > ATA_LPM_MAX_POWER) { in ata_eh_schedule_probe()
3594 link->ap->ops->set_lpm(link, ATA_LPM_MAX_POWER, in ata_eh_schedule_probe()
3614 ata_ering_record(&dev->ering, 0, AC_ERR_OTHER); in ata_eh_schedule_probe()
3615 ata_ering_map(&dev->ering, ata_count_probe_trials_cb, &trials); in ata_eh_schedule_probe()
3625 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_eh_handle_dev_fail()
3627 /* -EAGAIN from EH routine indicates retry without prejudice. in ata_eh_handle_dev_fail()
3630 if (err != -EAGAIN) in ata_eh_handle_dev_fail()
3631 ehc->tries[dev->devno]--; in ata_eh_handle_dev_fail()
3634 case -ENODEV: in ata_eh_handle_dev_fail()
3636 ehc->i.probe_mask |= (1 << dev->devno); in ata_eh_handle_dev_fail()
3638 case -EINVAL: in ata_eh_handle_dev_fail()
3640 ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1); in ata_eh_handle_dev_fail()
3642 case -EIO: in ata_eh_handle_dev_fail()
3643 if (ehc->tries[dev->devno] == 1) { in ata_eh_handle_dev_fail()
3648 if (dev->pio_mode > XFER_PIO_0) in ata_eh_handle_dev_fail()
3653 if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) { in ata_eh_handle_dev_fail()
3663 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; in ata_eh_handle_dev_fail()
3664 memset(ehc->cmd_timeout_idx[dev->devno], 0, in ata_eh_handle_dev_fail()
3665 sizeof(ehc->cmd_timeout_idx[dev->devno])); in ata_eh_handle_dev_fail()
3670 ehc->i.action |= ATA_EH_RESET; in ata_eh_handle_dev_fail()
3676 * ata_eh_recover - recover host port after error
3695 * 0 on success, -errno on failure.
3709 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3711 /* re-enable link? */ in ata_eh_recover()
3712 if (ehc->i.action & ATA_EH_ENABLE_LINK) { in ata_eh_recover()
3714 spin_lock_irqsave(ap->lock, flags); in ata_eh_recover()
3715 link->flags &= ~ATA_LFLAG_DISABLED; in ata_eh_recover()
3716 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_recover()
3721 if (link->flags & ATA_LFLAG_NO_RETRY) in ata_eh_recover()
3722 ehc->tries[dev->devno] = 1; in ata_eh_recover()
3724 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; in ata_eh_recover()
3727 ehc->i.action |= ehc->i.dev_action[dev->devno] & in ata_eh_recover()
3729 ehc->i.dev_action[dev->devno] &= ATA_EH_PERDEV_MASK; in ata_eh_recover()
3732 if (dev->flags & ATA_DFLAG_DETACH) in ata_eh_recover()
3745 if (ap->pflags & ATA_PFLAG_UNLOADING) in ata_eh_recover()
3750 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3754 ehc->i.action = 0; in ata_eh_recover()
3757 ehc->classes[dev->devno] = ATA_DEV_UNKNOWN; in ata_eh_recover()
3762 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3764 if (!(ehc->i.action & ATA_EH_RESET)) in ata_eh_recover()
3780 * ap->park_req_pending in ata_eh_recover()
3787 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3790 if (dev->class != ATA_DEV_ATA && in ata_eh_recover()
3791 dev->class != ATA_DEV_ZAC) in ata_eh_recover()
3793 if (!(ehc->i.dev_action[dev->devno] & in ata_eh_recover()
3796 tmp = dev->unpark_deadline; in ata_eh_recover()
3801 if (ehc->unloaded_mask & (1 << dev->devno)) in ata_eh_recover()
3813 deadline = wait_for_completion_timeout(&ap->park_req_pending, in ata_eh_recover()
3814 deadline - now); in ata_eh_recover()
3819 if (!(link->eh_context.unloaded_mask & in ata_eh_recover()
3820 (1 << dev->devno))) in ata_eh_recover()
3831 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_recover()
3842 if (link->device->class == ATA_DEV_PMP) { in ata_eh_recover()
3843 ehc->i.action = 0; in ata_eh_recover()
3848 if (ehc->i.flags & ATA_EHI_SETMODE) { in ata_eh_recover()
3852 ehc->i.flags &= ~ATA_EHI_SETMODE; in ata_eh_recover()
3858 if (ehc->i.flags & ATA_EHI_DID_RESET) { in ata_eh_recover()
3860 if (dev->class != ATA_DEV_ATAPI) in ata_eh_recover()
3872 if (dev->class != ATA_DEV_ATA && in ata_eh_recover()
3873 dev->class != ATA_DEV_ZAC) in ata_eh_recover()
3882 if (link->lpm_policy != ap->target_lpm_policy) { in ata_eh_recover()
3883 rc = ata_eh_set_lpm(link, ap->target_lpm_policy, &dev); in ata_eh_recover()
3889 ehc->i.flags = 0; in ata_eh_recover()
3918 * ata_eh_finish - finish up EH
3934 if (!(qc->flags & ATA_QCFLAG_EH)) in ata_eh_finish()
3937 if (qc->err_mask) { in ata_eh_finish()
3942 if (qc->flags & ATA_QCFLAG_RETRY) { in ata_eh_finish()
3944 * Since qc->err_mask is set, ata_eh_qc_retry() in ata_eh_finish()
3945 * will not increment scmd->allowed, so upper in ata_eh_finish()
3954 if (qc->flags & ATA_QCFLAG_SENSE_VALID || in ata_eh_finish()
3955 qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD) { in ata_eh_finish()
3959 memset(&qc->result_tf, 0, sizeof(qc->result_tf)); in ata_eh_finish()
3961 * Since qc->err_mask is not set, in ata_eh_finish()
3963 * scmd->allowed, so upper layer is guaranteed in ata_eh_finish()
3972 WARN_ON(ap->nr_active_links); in ata_eh_finish()
3973 ap->nr_active_links = 0; in ata_eh_finish()
3977 * ata_do_eh - do standard error handling
4003 ata_for_each_dev(dev, &ap->link, ALL) in ata_do_eh()
4011 * ata_std_error_handler - standard error handler
4021 struct ata_port_operations *ops = ap->ops; in ata_std_error_handler()
4022 ata_reset_fn_t hardreset = ops->hardreset; in ata_std_error_handler()
4024 /* ignore built-in hardreset if SCR access is not available */ in ata_std_error_handler()
4025 if (hardreset == sata_std_hardreset && !sata_scr_valid(&ap->link)) in ata_std_error_handler()
4028 ata_do_eh(ap, ops->prereset, ops->softreset, hardreset, ops->postreset); in ata_std_error_handler()
4034 * ata_eh_handle_port_suspend - perform port suspend operation
4050 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_suspend()
4051 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) || in ata_eh_handle_port_suspend()
4052 ap->pm_mesg.event & PM_EVENT_RESUME) { in ata_eh_handle_port_suspend()
4053 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_suspend()
4056 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_suspend()
4058 WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED); in ata_eh_handle_port_suspend()
4068 if (!(ap->pm_mesg.event & PM_EVENT_FREEZE)) { in ata_eh_handle_port_suspend()
4081 if (PMSG_IS_AUTO(ap->pm_mesg)) { in ata_eh_handle_port_suspend()
4082 ata_for_each_dev(dev, &ap->link, ENABLED) { in ata_eh_handle_port_suspend()
4091 if (ap->ops->port_suspend) in ata_eh_handle_port_suspend()
4092 rc = ap->ops->port_suspend(ap, ap->pm_mesg); in ata_eh_handle_port_suspend()
4094 ata_acpi_set_state(ap, ap->pm_mesg); in ata_eh_handle_port_suspend()
4097 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_suspend()
4099 ap->pflags &= ~ATA_PFLAG_PM_PENDING; in ata_eh_handle_port_suspend()
4101 ap->pflags |= ATA_PFLAG_SUSPENDED; in ata_eh_handle_port_suspend()
4105 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_suspend()
4111 * ata_eh_handle_port_resume - perform port resume operation
4126 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_resume()
4127 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) || in ata_eh_handle_port_resume()
4128 !(ap->pm_mesg.event & PM_EVENT_RESUME)) { in ata_eh_handle_port_resume()
4129 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_resume()
4132 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_resume()
4134 WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED)); in ata_eh_handle_port_resume()
4140 * downs if the machine is suspended and resumed repeatedly. in ata_eh_handle_port_resume()
4145 ata_ering_clear(&dev->ering); in ata_eh_handle_port_resume()
4147 ata_acpi_set_state(ap, ap->pm_mesg); in ata_eh_handle_port_resume()
4149 if (ap->ops->port_resume) in ata_eh_handle_port_resume()
4150 ap->ops->port_resume(ap); in ata_eh_handle_port_resume()
4156 spin_lock_irqsave(ap->lock, flags); in ata_eh_handle_port_resume()
4157 ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED); in ata_eh_handle_port_resume()
4158 ap->pflags |= ATA_PFLAG_RESUMING; in ata_eh_handle_port_resume()
4159 spin_unlock_irqrestore(ap->lock, flags); in ata_eh_handle_port_resume()