2 * libata-eh.c - libata error handling
4 * Maintained by: Jeff Garzik <jgarzik@pobox.com>
5 * Please ALWAYS copy linux-ide@vger.kernel.org
8 * Copyright 2006 Tejun Heo <htejun@gmail.com>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
27 * libata documentation is available via 'make {ps|pdf}docs',
28 * as Documentation/DocBook/libata.*
30 * Hardware documentation available from http://www.t13.org/ and
31 * http://www.sata-io.org/
35 #include <linux/config.h>
36 #include <linux/kernel.h>
37 #include <scsi/scsi.h>
38 #include <scsi/scsi_host.h>
39 #include <scsi/scsi_eh.h>
40 #include <scsi/scsi_device.h>
41 #include <scsi/scsi_cmnd.h>
42 #include "scsi_transport_api.h"
44 #include <linux/libata.h>
48 static void __ata_port_freeze(struct ata_port *ap);
50 static void ata_ering_record(struct ata_ering *ering, int is_io,
51 unsigned int err_mask)
53 struct ata_ering_entry *ent;
58 ering->cursor %= ATA_ERING_SIZE;
60 ent = &ering->ring[ering->cursor];
62 ent->err_mask = err_mask;
63 ent->timestamp = get_jiffies_64();
66 static struct ata_ering_entry * ata_ering_top(struct ata_ering *ering)
68 struct ata_ering_entry *ent = &ering->ring[ering->cursor];
74 static int ata_ering_map(struct ata_ering *ering,
75 int (*map_fn)(struct ata_ering_entry *, void *),
79 struct ata_ering_entry *ent;
83 ent = &ering->ring[idx];
86 rc = map_fn(ent, arg);
89 idx = (idx - 1 + ATA_ERING_SIZE) % ATA_ERING_SIZE;
90 } while (idx != ering->cursor);
96 * ata_scsi_timed_out - SCSI layer time out callback
97 * @cmd: timed out SCSI command
99 * Handles SCSI layer timeout. We race with normal completion of
100 * the qc for @cmd. If the qc is already gone, we lose and let
101 * the scsi command finish (EH_HANDLED). Otherwise, the qc has
102 * timed out and EH should be invoked. Prevent ata_qc_complete()
103 * from finishing it by setting EH_SCHEDULED and return
106 * TODO: kill this function once old EH is gone.
109 * Called from timer context
112 * EH_HANDLED or EH_NOT_HANDLED
114 enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
116 struct Scsi_Host *host = cmd->device->host;
117 struct ata_port *ap = ata_shost_to_port(host);
119 struct ata_queued_cmd *qc;
120 enum scsi_eh_timer_return ret;
124 if (ap->ops->error_handler) {
125 ret = EH_NOT_HANDLED;
130 spin_lock_irqsave(&ap->host_set->lock, flags);
131 qc = ata_qc_from_tag(ap, ap->active_tag);
133 WARN_ON(qc->scsicmd != cmd);
134 qc->flags |= ATA_QCFLAG_EH_SCHEDULED;
135 qc->err_mask |= AC_ERR_TIMEOUT;
136 ret = EH_NOT_HANDLED;
138 spin_unlock_irqrestore(&ap->host_set->lock, flags);
141 DPRINTK("EXIT, ret=%d\n", ret);
146 * ata_scsi_error - SCSI layer error handler callback
147 * @host: SCSI host on which error occurred
149 * Handles SCSI-layer-thrown error events.
152 * Inherited from SCSI layer (none, can sleep)
157 void ata_scsi_error(struct Scsi_Host *host)
159 struct ata_port *ap = ata_shost_to_port(host);
160 spinlock_t *hs_lock = &ap->host_set->lock;
161 int i, repeat_cnt = ATA_EH_MAX_REPEAT;
166 /* synchronize with port task */
167 ata_port_flush_task(ap);
169 /* synchronize with host_set lock and sort out timeouts */
171 /* For new EH, all qcs are finished in one of three ways -
172 * normal completion, error completion, and SCSI timeout.
173 * Both cmpletions can race against SCSI timeout. When normal
174 * completion wins, the qc never reaches EH. When error
175 * completion wins, the qc has ATA_QCFLAG_FAILED set.
177 * When SCSI timeout wins, things are a bit more complex.
178 * Normal or error completion can occur after the timeout but
179 * before this point. In such cases, both types of
180 * completions are honored. A scmd is determined to have
181 * timed out iff its associated qc is active and not failed.
183 if (ap->ops->error_handler) {
184 struct scsi_cmnd *scmd, *tmp;
187 spin_lock_irqsave(hs_lock, flags);
189 list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) {
190 struct ata_queued_cmd *qc;
192 for (i = 0; i < ATA_MAX_QUEUE; i++) {
193 qc = __ata_qc_from_tag(ap, i);
194 if (qc->flags & ATA_QCFLAG_ACTIVE &&
199 if (i < ATA_MAX_QUEUE) {
200 /* the scmd has an associated qc */
201 if (!(qc->flags & ATA_QCFLAG_FAILED)) {
202 /* which hasn't failed yet, timeout */
203 qc->err_mask |= AC_ERR_TIMEOUT;
204 qc->flags |= ATA_QCFLAG_FAILED;
208 /* Normal completion occurred after
209 * SCSI timeout but before this point.
210 * Successfully complete it.
212 scmd->retries = scmd->allowed;
213 scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
217 /* If we have timed out qcs. They belong to EH from
218 * this point but the state of the controller is
219 * unknown. Freeze the port to make sure the IRQ
220 * handler doesn't diddle with those qcs. This must
221 * be done atomically w.r.t. setting QCFLAG_FAILED.
224 __ata_port_freeze(ap);
226 spin_unlock_irqrestore(hs_lock, flags);
228 spin_unlock_wait(hs_lock);
231 /* invoke error handler */
232 if (ap->ops->error_handler) {
233 /* fetch & clear EH info */
234 spin_lock_irqsave(hs_lock, flags);
236 memset(&ap->eh_context, 0, sizeof(ap->eh_context));
237 ap->eh_context.i = ap->eh_info;
238 memset(&ap->eh_info, 0, sizeof(ap->eh_info));
240 ap->flags |= ATA_FLAG_EH_IN_PROGRESS;
241 ap->flags &= ~ATA_FLAG_EH_PENDING;
243 spin_unlock_irqrestore(hs_lock, flags);
246 ap->ops->error_handler(ap);
248 /* Exception might have happend after ->error_handler
249 * recovered the port but before this point. Repeat
252 spin_lock_irqsave(hs_lock, flags);
254 if (ap->flags & ATA_FLAG_EH_PENDING) {
256 ata_port_printk(ap, KERN_INFO,
257 "EH pending after completion, "
258 "repeating EH (cnt=%d)\n", repeat_cnt);
259 spin_unlock_irqrestore(hs_lock, flags);
262 ata_port_printk(ap, KERN_ERR, "EH pending after %d "
263 "tries, giving up\n", ATA_EH_MAX_REPEAT);
266 /* this run is complete, make sure EH info is clear */
267 memset(&ap->eh_info, 0, sizeof(ap->eh_info));
269 /* Clear host_eh_scheduled while holding hs_lock such
270 * that if exception occurs after this point but
271 * before EH completion, SCSI midlayer will
274 host->host_eh_scheduled = 0;
276 spin_unlock_irqrestore(hs_lock, flags);
278 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL);
279 ap->ops->eng_timeout(ap);
282 /* finish or retry handled scmd's and clean up */
283 WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q));
285 scsi_eh_flush_done_q(&ap->eh_done_q);
288 spin_lock_irqsave(hs_lock, flags);
290 if (ap->flags & ATA_FLAG_SCSI_HOTPLUG)
291 queue_work(ata_aux_wq, &ap->hotplug_task);
293 if (ap->flags & ATA_FLAG_RECOVERED)
294 ata_port_printk(ap, KERN_INFO, "EH complete\n");
296 ap->flags &= ~(ATA_FLAG_SCSI_HOTPLUG | ATA_FLAG_RECOVERED);
298 /* tell wait_eh that we're done */
299 ap->flags &= ~ATA_FLAG_EH_IN_PROGRESS;
300 wake_up_all(&ap->eh_wait_q);
302 spin_unlock_irqrestore(hs_lock, flags);
308 * ata_port_wait_eh - Wait for the currently pending EH to complete
309 * @ap: Port to wait EH for
311 * Wait until the currently pending EH is complete.
314 * Kernel thread context (may sleep).
316 void ata_port_wait_eh(struct ata_port *ap)
322 spin_lock_irqsave(&ap->host_set->lock, flags);
324 while (ap->flags & (ATA_FLAG_EH_PENDING | ATA_FLAG_EH_IN_PROGRESS)) {
325 prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE);
326 spin_unlock_irqrestore(&ap->host_set->lock, flags);
328 spin_lock_irqsave(&ap->host_set->lock, flags);
331 spin_unlock_irqrestore(&ap->host_set->lock, flags);
333 /* make sure SCSI EH is complete */
334 if (scsi_host_in_recovery(ap->host)) {
341 * ata_qc_timeout - Handle timeout of queued command
342 * @qc: Command that timed out
344 * Some part of the kernel (currently, only the SCSI layer)
345 * has noticed that the active command on port @ap has not
346 * completed after a specified length of time. Handle this
347 * condition by disabling DMA (if necessary) and completing
348 * transactions, with error if necessary.
350 * This also handles the case of the "lost interrupt", where
351 * for some reason (possibly hardware bug, possibly driver bug)
352 * an interrupt was not delivered to the driver, even though the
353 * transaction completed successfully.
355 * TODO: kill this function once old EH is gone.
358 * Inherited from SCSI layer (none, can sleep)
360 static void ata_qc_timeout(struct ata_queued_cmd *qc)
362 struct ata_port *ap = qc->ap;
363 struct ata_host_set *host_set = ap->host_set;
364 u8 host_stat = 0, drv_stat;
369 ap->hsm_task_state = HSM_ST_IDLE;
371 spin_lock_irqsave(&host_set->lock, flags);
373 switch (qc->tf.protocol) {
376 case ATA_PROT_ATAPI_DMA:
377 host_stat = ap->ops->bmdma_status(ap);
379 /* before we do anything else, clear DMA-Start bit */
380 ap->ops->bmdma_stop(qc);
386 drv_stat = ata_chk_status(ap);
388 /* ack bmdma irq events */
389 ap->ops->irq_clear(ap);
391 ata_dev_printk(qc->dev, KERN_ERR, "command 0x%x timeout, "
392 "stat 0x%x host_stat 0x%x\n",
393 qc->tf.command, drv_stat, host_stat);
395 /* complete taskfile transaction */
396 qc->err_mask |= AC_ERR_TIMEOUT;
400 spin_unlock_irqrestore(&host_set->lock, flags);
402 ata_eh_qc_complete(qc);
408 * ata_eng_timeout - Handle timeout of queued command
409 * @ap: Port on which timed-out command is active
411 * Some part of the kernel (currently, only the SCSI layer)
412 * has noticed that the active command on port @ap has not
413 * completed after a specified length of time. Handle this
414 * condition by disabling DMA (if necessary) and completing
415 * transactions, with error if necessary.
417 * This also handles the case of the "lost interrupt", where
418 * for some reason (possibly hardware bug, possibly driver bug)
419 * an interrupt was not delivered to the driver, even though the
420 * transaction completed successfully.
422 * TODO: kill this function once old EH is gone.
425 * Inherited from SCSI layer (none, can sleep)
427 void ata_eng_timeout(struct ata_port *ap)
431 ata_qc_timeout(ata_qc_from_tag(ap, ap->active_tag));
437 * ata_qc_schedule_eh - schedule qc for error handling
438 * @qc: command to schedule error handling for
440 * Schedule error handling for @qc. EH will kick in as soon as
441 * other commands are drained.
444 * spin_lock_irqsave(host_set lock)
446 void ata_qc_schedule_eh(struct ata_queued_cmd *qc)
448 struct ata_port *ap = qc->ap;
450 WARN_ON(!ap->ops->error_handler);
452 qc->flags |= ATA_QCFLAG_FAILED;
453 qc->ap->flags |= ATA_FLAG_EH_PENDING;
455 /* The following will fail if timeout has already expired.
456 * ata_scsi_error() takes care of such scmds on EH entry.
457 * Note that ATA_QCFLAG_FAILED is unconditionally set after
458 * this function completes.
460 scsi_req_abort_cmd(qc->scsicmd);
464 * ata_port_schedule_eh - schedule error handling without a qc
465 * @ap: ATA port to schedule EH for
467 * Schedule error handling for @ap. EH will kick in as soon as
468 * all commands are drained.
471 * spin_lock_irqsave(host_set lock)
473 void ata_port_schedule_eh(struct ata_port *ap)
475 WARN_ON(!ap->ops->error_handler);
477 ap->flags |= ATA_FLAG_EH_PENDING;
478 scsi_schedule_eh(ap->host);
480 DPRINTK("port EH scheduled\n");
484 * ata_port_abort - abort all qc's on the port
485 * @ap: ATA port to abort qc's for
487 * Abort all active qc's of @ap and schedule EH.
490 * spin_lock_irqsave(host_set lock)
493 * Number of aborted qc's.
495 int ata_port_abort(struct ata_port *ap)
497 int tag, nr_aborted = 0;
499 WARN_ON(!ap->ops->error_handler);
501 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
502 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
505 qc->flags |= ATA_QCFLAG_FAILED;
512 ata_port_schedule_eh(ap);
518 * __ata_port_freeze - freeze port
519 * @ap: ATA port to freeze
521 * This function is called when HSM violation or some other
522 * condition disrupts normal operation of the port. Frozen port
523 * is not allowed to perform any operation until the port is
524 * thawed, which usually follows a successful reset.
526 * ap->ops->freeze() callback can be used for freezing the port
527 * hardware-wise (e.g. mask interrupt and stop DMA engine). If a
528 * port cannot be frozen hardware-wise, the interrupt handler
529 * must ack and clear interrupts unconditionally while the port
533 * spin_lock_irqsave(host_set lock)
535 static void __ata_port_freeze(struct ata_port *ap)
537 WARN_ON(!ap->ops->error_handler);
542 ap->flags |= ATA_FLAG_FROZEN;
544 DPRINTK("ata%u port frozen\n", ap->id);
548 * ata_port_freeze - abort & freeze port
549 * @ap: ATA port to freeze
551 * Abort and freeze @ap.
554 * spin_lock_irqsave(host_set lock)
557 * Number of aborted commands.
559 int ata_port_freeze(struct ata_port *ap)
563 WARN_ON(!ap->ops->error_handler);
565 nr_aborted = ata_port_abort(ap);
566 __ata_port_freeze(ap);
572 * ata_eh_freeze_port - EH helper to freeze port
573 * @ap: ATA port to freeze
580 void ata_eh_freeze_port(struct ata_port *ap)
584 if (!ap->ops->error_handler)
587 spin_lock_irqsave(&ap->host_set->lock, flags);
588 __ata_port_freeze(ap);
589 spin_unlock_irqrestore(&ap->host_set->lock, flags);
593 * ata_port_thaw_port - EH helper to thaw port
594 * @ap: ATA port to thaw
596 * Thaw frozen port @ap.
601 void ata_eh_thaw_port(struct ata_port *ap)
605 if (!ap->ops->error_handler)
608 spin_lock_irqsave(&ap->host_set->lock, flags);
610 ap->flags &= ~ATA_FLAG_FROZEN;
615 spin_unlock_irqrestore(&ap->host_set->lock, flags);
617 DPRINTK("ata%u port thawed\n", ap->id);
620 static void ata_eh_scsidone(struct scsi_cmnd *scmd)
625 static void __ata_eh_qc_complete(struct ata_queued_cmd *qc)
627 struct ata_port *ap = qc->ap;
628 struct scsi_cmnd *scmd = qc->scsicmd;
631 spin_lock_irqsave(&ap->host_set->lock, flags);
632 qc->scsidone = ata_eh_scsidone;
633 __ata_qc_complete(qc);
634 WARN_ON(ata_tag_valid(qc->tag));
635 spin_unlock_irqrestore(&ap->host_set->lock, flags);
637 scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
641 * ata_eh_qc_complete - Complete an active ATA command from EH
642 * @qc: Command to complete
644 * Indicate to the mid and upper layers that an ATA command has
645 * completed. To be used from EH.
647 void ata_eh_qc_complete(struct ata_queued_cmd *qc)
649 struct scsi_cmnd *scmd = qc->scsicmd;
650 scmd->retries = scmd->allowed;
651 __ata_eh_qc_complete(qc);
655 * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
656 * @qc: Command to retry
658 * Indicate to the mid and upper layers that an ATA command
659 * should be retried. To be used from EH.
661 * SCSI midlayer limits the number of retries to scmd->allowed.
662 * scmd->retries is decremented for commands which get retried
663 * due to unrelated failures (qc->err_mask is zero).
665 void ata_eh_qc_retry(struct ata_queued_cmd *qc)
667 struct scsi_cmnd *scmd = qc->scsicmd;
668 if (!qc->err_mask && scmd->retries)
670 __ata_eh_qc_complete(qc);
674 * ata_eh_detach_dev - detach ATA device
675 * @dev: ATA device to detach
682 static void ata_eh_detach_dev(struct ata_device *dev)
684 struct ata_port *ap = dev->ap;
687 ata_dev_disable(dev);
689 spin_lock_irqsave(&ap->host_set->lock, flags);
691 dev->flags &= ~ATA_DFLAG_DETACH;
693 if (ata_scsi_offline_dev(dev)) {
694 dev->flags |= ATA_DFLAG_DETACHED;
695 ap->flags |= ATA_FLAG_SCSI_HOTPLUG;
698 spin_unlock_irqrestore(&ap->host_set->lock, flags);
702 * ata_eh_about_to_do - about to perform eh_action
703 * @ap: target ATA port
704 * @action: action about to be performed
706 * Called just before performing EH actions to clear related bits
707 * in @ap->eh_info such that eh actions are not unnecessarily
713 static void ata_eh_about_to_do(struct ata_port *ap, unsigned int action)
717 spin_lock_irqsave(&ap->host_set->lock, flags);
718 ap->eh_info.action &= ~action;
719 ap->flags |= ATA_FLAG_RECOVERED;
720 spin_unlock_irqrestore(&ap->host_set->lock, flags);
724 * ata_err_string - convert err_mask to descriptive string
725 * @err_mask: error mask to convert to string
727 * Convert @err_mask to descriptive string. Errors are
728 * prioritized according to severity and only the most severe
735 * Descriptive string for @err_mask
737 static const char * ata_err_string(unsigned int err_mask)
739 if (err_mask & AC_ERR_HOST_BUS)
740 return "host bus error";
741 if (err_mask & AC_ERR_ATA_BUS)
742 return "ATA bus error";
743 if (err_mask & AC_ERR_TIMEOUT)
745 if (err_mask & AC_ERR_HSM)
746 return "HSM violation";
747 if (err_mask & AC_ERR_SYSTEM)
748 return "internal error";
749 if (err_mask & AC_ERR_MEDIA)
750 return "media error";
751 if (err_mask & AC_ERR_INVALID)
752 return "invalid argument";
753 if (err_mask & AC_ERR_DEV)
754 return "device error";
755 return "unknown error";
759 * ata_read_log_page - read a specific log page
760 * @dev: target device
761 * @page: page to read
762 * @buf: buffer to store read page
763 * @sectors: number of sectors to read
765 * Read log page using READ_LOG_EXT command.
768 * Kernel thread context (may sleep).
771 * 0 on success, AC_ERR_* mask otherwise.
773 static unsigned int ata_read_log_page(struct ata_device *dev,
774 u8 page, void *buf, unsigned int sectors)
776 struct ata_taskfile tf;
777 unsigned int err_mask;
779 DPRINTK("read log page - page %d\n", page);
781 ata_tf_init(dev, &tf);
782 tf.command = ATA_CMD_READ_LOG_EXT;
785 tf.hob_nsect = sectors >> 8;
786 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_LBA48 | ATA_TFLAG_DEVICE;
787 tf.protocol = ATA_PROT_PIO;
789 err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE,
790 buf, sectors * ATA_SECT_SIZE);
792 DPRINTK("EXIT, err_mask=%x\n", err_mask);
797 * ata_eh_read_log_10h - Read log page 10h for NCQ error details
798 * @dev: Device to read log page 10h from
799 * @tag: Resulting tag of the failed command
800 * @tf: Resulting taskfile registers of the failed command
802 * Read log page 10h to obtain NCQ error details and clear error
806 * Kernel thread context (may sleep).
809 * 0 on success, -errno otherwise.
811 static int ata_eh_read_log_10h(struct ata_device *dev,
812 int *tag, struct ata_taskfile *tf)
814 u8 *buf = dev->ap->sector_buf;
815 unsigned int err_mask;
819 err_mask = ata_read_log_page(dev, ATA_LOG_SATA_NCQ, buf, 1);
824 for (i = 0; i < ATA_SECT_SIZE; i++)
827 ata_dev_printk(dev, KERN_WARNING,
828 "invalid checksum 0x%x on log page 10h\n", csum);
833 *tag = buf[0] & 0x1f;
835 tf->command = buf[2];
836 tf->feature = buf[3];
841 tf->hob_lbal = buf[8];
842 tf->hob_lbam = buf[9];
843 tf->hob_lbah = buf[10];
845 tf->hob_nsect = buf[13];
851 * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE
852 * @dev: device to perform REQUEST_SENSE to
853 * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long)
855 * Perform ATAPI REQUEST_SENSE after the device reported CHECK
856 * SENSE. This function is EH helper.
859 * Kernel thread context (may sleep).
862 * 0 on success, AC_ERR_* mask on failure
864 static unsigned int atapi_eh_request_sense(struct ata_device *dev,
865 unsigned char *sense_buf)
867 struct ata_port *ap = dev->ap;
868 struct ata_taskfile tf;
869 u8 cdb[ATAPI_CDB_LEN];
871 DPRINTK("ATAPI request sense\n");
873 ata_tf_init(dev, &tf);
875 /* FIXME: is this needed? */
876 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
878 /* XXX: why tf_read here? */
879 ap->ops->tf_read(ap, &tf);
881 /* fill these in, for the case where they are -not- overwritten */
883 sense_buf[2] = tf.feature >> 4;
885 memset(cdb, 0, ATAPI_CDB_LEN);
886 cdb[0] = REQUEST_SENSE;
887 cdb[4] = SCSI_SENSE_BUFFERSIZE;
889 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
890 tf.command = ATA_CMD_PACKET;
892 /* is it pointless to prefer PIO for "safety reasons"? */
893 if (ap->flags & ATA_FLAG_PIO_DMA) {
894 tf.protocol = ATA_PROT_ATAPI_DMA;
895 tf.feature |= ATAPI_PKT_DMA;
897 tf.protocol = ATA_PROT_ATAPI;
898 tf.lbam = (8 * 1024) & 0xff;
899 tf.lbah = (8 * 1024) >> 8;
902 return ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE,
903 sense_buf, SCSI_SENSE_BUFFERSIZE);
907 * ata_eh_analyze_serror - analyze SError for a failed port
908 * @ap: ATA port to analyze SError for
910 * Analyze SError if available and further determine cause of
916 static void ata_eh_analyze_serror(struct ata_port *ap)
918 struct ata_eh_context *ehc = &ap->eh_context;
919 u32 serror = ehc->i.serror;
920 unsigned int err_mask = 0, action = 0;
922 if (serror & SERR_PERSISTENT) {
923 err_mask |= AC_ERR_ATA_BUS;
924 action |= ATA_EH_HARDRESET;
927 (SERR_DATA_RECOVERED | SERR_COMM_RECOVERED | SERR_DATA)) {
928 err_mask |= AC_ERR_ATA_BUS;
929 action |= ATA_EH_SOFTRESET;
931 if (serror & SERR_PROTOCOL) {
932 err_mask |= AC_ERR_HSM;
933 action |= ATA_EH_SOFTRESET;
935 if (serror & SERR_INTERNAL) {
936 err_mask |= AC_ERR_SYSTEM;
937 action |= ATA_EH_SOFTRESET;
939 if (serror & (SERR_PHYRDY_CHG | SERR_DEV_XCHG))
940 ata_ehi_hotplugged(&ehc->i);
942 ehc->i.err_mask |= err_mask;
943 ehc->i.action |= action;
947 * ata_eh_analyze_ncq_error - analyze NCQ error
948 * @ap: ATA port to analyze NCQ error for
950 * Read log page 10h, determine the offending qc and acquire
951 * error status TF. For NCQ device errors, all LLDDs have to do
952 * is setting AC_ERR_DEV in ehi->err_mask. This function takes
956 * Kernel thread context (may sleep).
958 static void ata_eh_analyze_ncq_error(struct ata_port *ap)
960 struct ata_eh_context *ehc = &ap->eh_context;
961 struct ata_device *dev = ap->device;
962 struct ata_queued_cmd *qc;
963 struct ata_taskfile tf;
966 /* if frozen, we can't do much */
967 if (ap->flags & ATA_FLAG_FROZEN)
970 /* is it NCQ device error? */
971 if (!ap->sactive || !(ehc->i.err_mask & AC_ERR_DEV))
974 /* has LLDD analyzed already? */
975 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
976 qc = __ata_qc_from_tag(ap, tag);
978 if (!(qc->flags & ATA_QCFLAG_FAILED))
985 /* okay, this error is ours */
986 rc = ata_eh_read_log_10h(dev, &tag, &tf);
988 ata_port_printk(ap, KERN_ERR, "failed to read log page 10h "
993 if (!(ap->sactive & (1 << tag))) {
994 ata_port_printk(ap, KERN_ERR, "log page 10h reported "
995 "inactive tag %d\n", tag);
999 /* we've got the perpetrator, condemn it */
1000 qc = __ata_qc_from_tag(ap, tag);
1001 memcpy(&qc->result_tf, &tf, sizeof(tf));
1002 qc->err_mask |= AC_ERR_DEV;
1003 ehc->i.err_mask &= ~AC_ERR_DEV;
1007 * ata_eh_analyze_tf - analyze taskfile of a failed qc
1008 * @qc: qc to analyze
1009 * @tf: Taskfile registers to analyze
1011 * Analyze taskfile of @qc and further determine cause of
1012 * failure. This function also requests ATAPI sense data if
1016 * Kernel thread context (may sleep).
1019 * Determined recovery action
1021 static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
1022 const struct ata_taskfile *tf)
1024 unsigned int tmp, action = 0;
1025 u8 stat = tf->command, err = tf->feature;
1027 if ((stat & (ATA_BUSY | ATA_DRQ | ATA_DRDY)) != ATA_DRDY) {
1028 qc->err_mask |= AC_ERR_HSM;
1029 return ATA_EH_SOFTRESET;
1032 if (!(qc->err_mask & AC_ERR_DEV))
1035 switch (qc->dev->class) {
1038 qc->err_mask |= AC_ERR_ATA_BUS;
1040 qc->err_mask |= AC_ERR_MEDIA;
1042 qc->err_mask |= AC_ERR_INVALID;
1046 tmp = atapi_eh_request_sense(qc->dev,
1047 qc->scsicmd->sense_buffer);
1049 /* ATA_QCFLAG_SENSE_VALID is used to tell
1050 * atapi_qc_complete() that sense data is
1053 * TODO: interpret sense data and set
1054 * appropriate err_mask.
1056 qc->flags |= ATA_QCFLAG_SENSE_VALID;
1058 qc->err_mask |= tmp;
1061 if (qc->err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT | AC_ERR_ATA_BUS))
1062 action |= ATA_EH_SOFTRESET;
1067 static int ata_eh_categorize_ering_entry(struct ata_ering_entry *ent)
1069 if (ent->err_mask & (AC_ERR_ATA_BUS | AC_ERR_TIMEOUT))
1073 if (ent->err_mask & AC_ERR_HSM)
1075 if ((ent->err_mask &
1076 (AC_ERR_DEV|AC_ERR_MEDIA|AC_ERR_INVALID)) == AC_ERR_DEV)
1083 struct speed_down_needed_arg {
1088 static int speed_down_needed_cb(struct ata_ering_entry *ent, void *void_arg)
1090 struct speed_down_needed_arg *arg = void_arg;
1092 if (ent->timestamp < arg->since)
1095 arg->nr_errors[ata_eh_categorize_ering_entry(ent)]++;
1100 * ata_eh_speed_down_needed - Determine wheter speed down is necessary
1101 * @dev: Device of interest
1103 * This function examines error ring of @dev and determines
1104 * whether speed down is necessary. Speed down is necessary if
1105 * there have been more than 3 of Cat-1 errors or 10 of Cat-2
1106 * errors during last 15 minutes.
1108 * Cat-1 errors are ATA_BUS, TIMEOUT for any command and HSM
1109 * violation for known supported commands.
1111 * Cat-2 errors are unclassified DEV error for known supported
1115 * Inherited from caller.
1118 * 1 if speed down is necessary, 0 otherwise
1120 static int ata_eh_speed_down_needed(struct ata_device *dev)
1122 const u64 interval = 15LLU * 60 * HZ;
1123 static const int err_limits[3] = { -1, 3, 10 };
1124 struct speed_down_needed_arg arg;
1125 struct ata_ering_entry *ent;
1129 ent = ata_ering_top(&dev->ering);
1133 err_cat = ata_eh_categorize_ering_entry(ent);
1137 memset(&arg, 0, sizeof(arg));
1139 j64 = get_jiffies_64();
1140 if (j64 >= interval)
1141 arg.since = j64 - interval;
1145 ata_ering_map(&dev->ering, speed_down_needed_cb, &arg);
1147 return arg.nr_errors[err_cat] > err_limits[err_cat];
1151 * ata_eh_speed_down - record error and speed down if necessary
1152 * @dev: Failed device
1153 * @is_io: Did the device fail during normal IO?
1154 * @err_mask: err_mask of the error
1156 * Record error and examine error history to determine whether
1157 * adjusting transmission speed is necessary. It also sets
1158 * transmission limits appropriately if such adjustment is
1162 * Kernel thread context (may sleep).
1165 * 0 on success, -errno otherwise
1167 static int ata_eh_speed_down(struct ata_device *dev, int is_io,
1168 unsigned int err_mask)
1173 /* record error and determine whether speed down is necessary */
1174 ata_ering_record(&dev->ering, is_io, err_mask);
1176 if (!ata_eh_speed_down_needed(dev))
1179 /* speed down SATA link speed if possible */
1180 if (sata_down_spd_limit(dev->ap) == 0)
1181 return ATA_EH_HARDRESET;
1183 /* lower transfer mode */
1184 if (ata_down_xfermask_limit(dev, 0) == 0)
1185 return ATA_EH_SOFTRESET;
1187 ata_dev_printk(dev, KERN_ERR,
1188 "speed down requested but no transfer mode left\n");
1193 * ata_eh_autopsy - analyze error and determine recovery action
1194 * @ap: ATA port to perform autopsy on
1196 * Analyze why @ap failed and determine which recovery action is
1197 * needed. This function also sets more detailed AC_ERR_* values
1198 * and fills sense data for ATAPI CHECK SENSE.
1201 * Kernel thread context (may sleep).
1203 static void ata_eh_autopsy(struct ata_port *ap)
1205 struct ata_eh_context *ehc = &ap->eh_context;
1206 unsigned int action = ehc->i.action;
1207 struct ata_device *failed_dev = NULL;
1208 unsigned int all_err_mask = 0;
1215 /* obtain and analyze SError */
1216 rc = sata_scr_read(ap, SCR_ERROR, &serror);
1218 ehc->i.serror |= serror;
1219 ata_eh_analyze_serror(ap);
1220 } else if (rc != -EOPNOTSUPP)
1221 action |= ATA_EH_HARDRESET;
1223 /* analyze NCQ failure */
1224 ata_eh_analyze_ncq_error(ap);
1226 /* any real error trumps AC_ERR_OTHER */
1227 if (ehc->i.err_mask & ~AC_ERR_OTHER)
1228 ehc->i.err_mask &= ~AC_ERR_OTHER;
1230 all_err_mask |= ehc->i.err_mask;
1232 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
1233 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
1235 if (!(qc->flags & ATA_QCFLAG_FAILED))
1238 /* inherit upper level err_mask */
1239 qc->err_mask |= ehc->i.err_mask;
1242 action |= ata_eh_analyze_tf(qc, &qc->result_tf);
1244 /* DEV errors are probably spurious in case of ATA_BUS error */
1245 if (qc->err_mask & AC_ERR_ATA_BUS)
1246 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_MEDIA |
1249 /* any real error trumps unknown error */
1250 if (qc->err_mask & ~AC_ERR_OTHER)
1251 qc->err_mask &= ~AC_ERR_OTHER;
1253 /* SENSE_VALID trumps dev/unknown error and revalidation */
1254 if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
1255 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER);
1256 action &= ~ATA_EH_REVALIDATE;
1259 /* accumulate error info */
1260 failed_dev = qc->dev;
1261 all_err_mask |= qc->err_mask;
1262 if (qc->flags & ATA_QCFLAG_IO)
1266 /* speed down iff command was in progress */
1268 action |= ata_eh_speed_down(failed_dev, is_io, all_err_mask);
1270 /* enforce default EH actions */
1271 if (ap->flags & ATA_FLAG_FROZEN ||
1272 all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT))
1273 action |= ATA_EH_SOFTRESET;
1274 else if (all_err_mask)
1275 action |= ATA_EH_REVALIDATE;
1277 /* record autopsy result */
1278 ehc->i.dev = failed_dev;
1279 ehc->i.action = action;
1285 * ata_eh_report - report error handling to user
1286 * @ap: ATA port EH is going on
1288 * Report EH to user.
1293 static void ata_eh_report(struct ata_port *ap)
1295 struct ata_eh_context *ehc = &ap->eh_context;
1296 const char *frozen, *desc;
1297 int tag, nr_failed = 0;
1300 if (ehc->i.desc[0] != '\0')
1303 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
1304 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
1306 if (!(qc->flags & ATA_QCFLAG_FAILED))
1308 if (qc->flags & ATA_QCFLAG_SENSE_VALID && !qc->err_mask)
1314 if (!nr_failed && !ehc->i.err_mask)
1318 if (ap->flags & ATA_FLAG_FROZEN)
1322 ata_dev_printk(ehc->i.dev, KERN_ERR, "exception Emask 0x%x "
1323 "SAct 0x%x SErr 0x%x action 0x%x%s\n",
1324 ehc->i.err_mask, ap->sactive, ehc->i.serror,
1325 ehc->i.action, frozen);
1327 ata_dev_printk(ehc->i.dev, KERN_ERR, "(%s)\n", desc);
1329 ata_port_printk(ap, KERN_ERR, "exception Emask 0x%x "
1330 "SAct 0x%x SErr 0x%x action 0x%x%s\n",
1331 ehc->i.err_mask, ap->sactive, ehc->i.serror,
1332 ehc->i.action, frozen);
1334 ata_port_printk(ap, KERN_ERR, "(%s)\n", desc);
1337 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
1338 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
1340 if (!(qc->flags & ATA_QCFLAG_FAILED) || !qc->err_mask)
1343 ata_dev_printk(qc->dev, KERN_ERR, "tag %d cmd 0x%x "
1344 "Emask 0x%x stat 0x%x err 0x%x (%s)\n",
1345 qc->tag, qc->tf.command, qc->err_mask,
1346 qc->result_tf.command, qc->result_tf.feature,
1347 ata_err_string(qc->err_mask));
1351 static int ata_eh_followup_srst_needed(int rc, int classify,
1352 const unsigned int *classes)
1358 if (classify && classes[0] == ATA_DEV_UNKNOWN)
1363 static int ata_eh_reset(struct ata_port *ap, int classify,
1364 ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
1365 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset)
1367 struct ata_eh_context *ehc = &ap->eh_context;
1368 unsigned int *classes = ehc->classes;
1369 int tries = ATA_EH_RESET_TRIES;
1370 unsigned int action;
1371 ata_reset_fn_t reset;
1372 int i, did_followup_srst, rc;
1374 /* Determine which reset to use and record in ehc->i.action.
1375 * prereset() may examine and modify it.
1377 action = ehc->i.action;
1378 ehc->i.action &= ~ATA_EH_RESET_MASK;
1379 if (softreset && (!hardreset || (!sata_set_spd_needed(ap) &&
1380 !(action & ATA_EH_HARDRESET))))
1381 ehc->i.action |= ATA_EH_SOFTRESET;
1383 ehc->i.action |= ATA_EH_HARDRESET;
1388 ata_port_printk(ap, KERN_ERR,
1389 "prereset failed (errno=%d)\n", rc);
1394 /* prereset() might have modified ehc->i.action */
1395 if (ehc->i.action & ATA_EH_HARDRESET)
1397 else if (ehc->i.action & ATA_EH_SOFTRESET)
1400 /* prereset told us not to reset, bang classes and return */
1401 for (i = 0; i < ATA_MAX_DEVICES; i++)
1402 classes[i] = ATA_DEV_NONE;
1406 /* did prereset() screw up? if so, fix up to avoid oopsing */
1408 ata_port_printk(ap, KERN_ERR, "BUG: prereset() requested "
1409 "invalid reset type\n");
1417 ata_port_printk(ap, KERN_INFO, "%s resetting port\n",
1418 reset == softreset ? "soft" : "hard");
1421 ata_eh_about_to_do(ap, ATA_EH_RESET_MASK);
1422 ehc->i.flags |= ATA_EHI_DID_RESET;
1424 rc = ata_do_reset(ap, reset, classes);
1426 did_followup_srst = 0;
1427 if (reset == hardreset &&
1428 ata_eh_followup_srst_needed(rc, classify, classes)) {
1429 /* okay, let's do follow-up softreset */
1430 did_followup_srst = 1;
1434 ata_port_printk(ap, KERN_ERR,
1435 "follow-up softreset required "
1436 "but no softreset avaliable\n");
1440 ata_eh_about_to_do(ap, ATA_EH_RESET_MASK);
1441 rc = ata_do_reset(ap, reset, classes);
1443 if (rc == 0 && classify &&
1444 classes[0] == ATA_DEV_UNKNOWN) {
1445 ata_port_printk(ap, KERN_ERR,
1446 "classification failed\n");
1451 if (rc && --tries) {
1454 if (reset == softreset) {
1455 if (did_followup_srst)
1456 type = "follow-up soft";
1462 ata_port_printk(ap, KERN_WARNING,
1463 "%sreset failed, retrying in 5 secs\n", type);
1466 if (reset == hardreset)
1467 sata_down_spd_limit(ap);
1474 /* After the reset, the device state is PIO 0 and the
1475 * controller state is undefined. Record the mode.
1477 for (i = 0; i < ATA_MAX_DEVICES; i++)
1478 ap->device[i].pio_mode = XFER_PIO_0;
1481 postreset(ap, classes);
1483 /* reset successful, schedule revalidation */
1485 ehc->i.action &= ~ATA_EH_RESET_MASK;
1486 ehc->i.action |= ATA_EH_REVALIDATE;
1492 static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1493 struct ata_device **r_failed_dev)
1495 struct ata_eh_context *ehc = &ap->eh_context;
1496 struct ata_device *dev;
1497 unsigned long flags;
1502 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1503 dev = &ap->device[i];
1505 if (ehc->i.action & ATA_EH_REVALIDATE && ata_dev_enabled(dev) &&
1506 (!ehc->i.dev || ehc->i.dev == dev)) {
1507 if (ata_port_offline(ap)) {
1512 ata_eh_about_to_do(ap, ATA_EH_REVALIDATE);
1513 rc = ata_dev_revalidate(dev,
1514 ehc->i.flags & ATA_EHI_DID_RESET);
1518 ehc->i.action &= ~ATA_EH_REVALIDATE;
1519 } else if (dev->class == ATA_DEV_UNKNOWN &&
1520 ehc->tries[dev->devno] &&
1521 ata_class_enabled(ehc->classes[dev->devno])) {
1522 dev->class = ehc->classes[dev->devno];
1524 rc = ata_dev_read_id(dev, &dev->class, 1, dev->id);
1526 rc = ata_dev_configure(dev, 1);
1529 dev->class = ATA_DEV_UNKNOWN;
1533 spin_lock_irqsave(&ap->host_set->lock, flags);
1534 ap->flags |= ATA_FLAG_SCSI_HOTPLUG;
1535 spin_unlock_irqrestore(&ap->host_set->lock, flags);
1540 *r_failed_dev = dev;
1546 static int ata_port_nr_enabled(struct ata_port *ap)
1550 for (i = 0; i < ATA_MAX_DEVICES; i++)
1551 if (ata_dev_enabled(&ap->device[i]))
1556 static int ata_port_nr_vacant(struct ata_port *ap)
1560 for (i = 0; i < ATA_MAX_DEVICES; i++)
1561 if (ap->device[i].class == ATA_DEV_UNKNOWN)
1566 static int ata_eh_skip_recovery(struct ata_port *ap)
1568 struct ata_eh_context *ehc = &ap->eh_context;
1571 if (ap->flags & ATA_FLAG_FROZEN || ata_port_nr_enabled(ap))
1574 /* skip if class codes for all vacant slots are ATA_DEV_NONE */
1575 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1576 struct ata_device *dev = &ap->device[i];
1578 if (dev->class == ATA_DEV_UNKNOWN &&
1579 ehc->classes[dev->devno] != ATA_DEV_NONE)
1587 * ata_eh_recover - recover host port after error
1588 * @ap: host port to recover
1589 * @prereset: prereset method (can be NULL)
1590 * @softreset: softreset method (can be NULL)
1591 * @hardreset: hardreset method (can be NULL)
1592 * @postreset: postreset method (can be NULL)
1594 * This is the alpha and omega, eum and yang, heart and soul of
1595 * libata exception handling. On entry, actions required to
1596 * recover the port and hotplug requests are recorded in
1597 * eh_context. This function executes all the operations with
1598 * appropriate retrials and fallbacks to resurrect failed
1599 * devices, detach goners and greet newcomers.
1602 * Kernel thread context (may sleep).
1605 * 0 on success, -errno on failure.
1607 static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1608 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
1609 ata_postreset_fn_t postreset)
1611 struct ata_eh_context *ehc = &ap->eh_context;
1612 struct ata_device *dev;
1613 int down_xfermask, i, rc;
1617 /* prep for recovery */
1618 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1619 dev = &ap->device[i];
1621 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
1623 /* process hotplug request */
1624 if (dev->flags & ATA_DFLAG_DETACH)
1625 ata_eh_detach_dev(dev);
1627 if (!ata_dev_enabled(dev) &&
1628 ((ehc->i.probe_mask & (1 << dev->devno)) &&
1629 !(ehc->did_probe_mask & (1 << dev->devno)))) {
1630 ata_eh_detach_dev(dev);
1632 ehc->did_probe_mask |= (1 << dev->devno);
1633 ehc->i.action |= ATA_EH_SOFTRESET;
1641 /* skip EH if possible. */
1642 if (ata_eh_skip_recovery(ap))
1645 for (i = 0; i < ATA_MAX_DEVICES; i++)
1646 ehc->classes[i] = ATA_DEV_UNKNOWN;
1649 if (ehc->i.action & ATA_EH_RESET_MASK) {
1650 ata_eh_freeze_port(ap);
1652 rc = ata_eh_reset(ap, ata_port_nr_vacant(ap), prereset,
1653 softreset, hardreset, postreset);
1655 ata_port_printk(ap, KERN_ERR,
1656 "reset failed, giving up\n");
1660 ata_eh_thaw_port(ap);
1663 /* revalidate existing devices and attach new ones */
1664 rc = ata_eh_revalidate_and_attach(ap, &dev);
1668 /* configure transfer mode if the port has been reset */
1669 if (ehc->i.flags & ATA_EHI_DID_RESET) {
1670 rc = ata_set_mode(ap, &dev);
1682 /* device missing, schedule probing */
1683 ehc->i.probe_mask |= (1 << dev->devno);
1685 ehc->tries[dev->devno] = 0;
1688 sata_down_spd_limit(ap);
1690 ehc->tries[dev->devno]--;
1691 if (down_xfermask &&
1692 ata_down_xfermask_limit(dev, ehc->tries[dev->devno] == 1))
1693 ehc->tries[dev->devno] = 0;
1696 if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) {
1697 /* disable device if it has used up all its chances */
1698 ata_dev_disable(dev);
1700 /* detach if offline */
1701 if (ata_port_offline(ap))
1702 ata_eh_detach_dev(dev);
1704 /* probe if requested */
1705 if ((ehc->i.probe_mask & (1 << dev->devno)) &&
1706 !(ehc->did_probe_mask & (1 << dev->devno))) {
1707 ata_eh_detach_dev(dev);
1710 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
1711 ehc->did_probe_mask |= (1 << dev->devno);
1712 ehc->i.action |= ATA_EH_SOFTRESET;
1715 /* soft didn't work? be haaaaard */
1716 if (ehc->i.flags & ATA_EHI_DID_RESET)
1717 ehc->i.action |= ATA_EH_HARDRESET;
1719 ehc->i.action |= ATA_EH_SOFTRESET;
1722 if (ata_port_nr_enabled(ap)) {
1723 ata_port_printk(ap, KERN_WARNING, "failed to recover some "
1724 "devices, retrying in 5 secs\n");
1727 /* no device left, repeat fast */
1735 for (i = 0; i < ATA_MAX_DEVICES; i++)
1736 ata_dev_disable(&ap->device[i]);
1739 DPRINTK("EXIT, rc=%d\n", rc);
1744 * ata_eh_finish - finish up EH
1745 * @ap: host port to finish EH for
1747 * Recovery is complete. Clean up EH states and retry or finish
1753 static void ata_eh_finish(struct ata_port *ap)
1757 /* retry or finish qcs */
1758 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
1759 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
1761 if (!(qc->flags & ATA_QCFLAG_FAILED))
1765 /* FIXME: Once EH migration is complete,
1766 * generate sense data in this function,
1767 * considering both err_mask and tf.
1769 if (qc->err_mask & AC_ERR_INVALID)
1770 ata_eh_qc_complete(qc);
1772 ata_eh_qc_retry(qc);
1774 if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
1775 ata_eh_qc_complete(qc);
1777 /* feed zero TF to sense generation */
1778 memset(&qc->result_tf, 0, sizeof(qc->result_tf));
1779 ata_eh_qc_retry(qc);
1786 * ata_do_eh - do standard error handling
1787 * @ap: host port to handle error for
1788 * @prereset: prereset method (can be NULL)
1789 * @softreset: softreset method (can be NULL)
1790 * @hardreset: hardreset method (can be NULL)
1791 * @postreset: postreset method (can be NULL)
1793 * Perform standard error handling sequence.
1796 * Kernel thread context (may sleep).
1798 void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
1799 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
1800 ata_postreset_fn_t postreset)
1804 ata_eh_recover(ap, prereset, softreset, hardreset, postreset);