/drivers/ata/libata-eh.c

http://github.com/mirrors/linux · C · 3976 lines · 2313 code · 532 blank · 1131 comment · 500 complexity · a860a0d0ecf0a8a4d070f5c92e87c4d4 MD5 · raw file

Large files are truncated click here to view the full file

  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * libata-eh.c - libata error handling
  4. *
  5. * Copyright 2006 Tejun Heo <htejun@gmail.com>
  6. *
  7. * libata documentation is available via 'make {ps|pdf}docs',
  8. * as Documentation/driver-api/libata.rst
  9. *
  10. * Hardware documentation available from http://www.t13.org/ and
  11. * http://www.sata-io.org/
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/blkdev.h>
  15. #include <linux/export.h>
  16. #include <linux/pci.h>
  17. #include <scsi/scsi.h>
  18. #include <scsi/scsi_host.h>
  19. #include <scsi/scsi_eh.h>
  20. #include <scsi/scsi_device.h>
  21. #include <scsi/scsi_cmnd.h>
  22. #include <scsi/scsi_dbg.h>
  23. #include "../scsi/scsi_transport_api.h"
  24. #include <linux/libata.h>
  25. #include <trace/events/libata.h>
  26. #include "libata.h"
  27. enum {
  28. /* speed down verdicts */
  29. ATA_EH_SPDN_NCQ_OFF = (1 << 0),
  30. ATA_EH_SPDN_SPEED_DOWN = (1 << 1),
  31. ATA_EH_SPDN_FALLBACK_TO_PIO = (1 << 2),
  32. ATA_EH_SPDN_KEEP_ERRORS = (1 << 3),
  33. /* error flags */
  34. ATA_EFLAG_IS_IO = (1 << 0),
  35. ATA_EFLAG_DUBIOUS_XFER = (1 << 1),
  36. ATA_EFLAG_OLD_ER = (1 << 31),
  37. /* error categories */
  38. ATA_ECAT_NONE = 0,
  39. ATA_ECAT_ATA_BUS = 1,
  40. ATA_ECAT_TOUT_HSM = 2,
  41. ATA_ECAT_UNK_DEV = 3,
  42. ATA_ECAT_DUBIOUS_NONE = 4,
  43. ATA_ECAT_DUBIOUS_ATA_BUS = 5,
  44. ATA_ECAT_DUBIOUS_TOUT_HSM = 6,
  45. ATA_ECAT_DUBIOUS_UNK_DEV = 7,
  46. ATA_ECAT_NR = 8,
  47. ATA_EH_CMD_DFL_TIMEOUT = 5000,
  48. /* always put at least this amount of time between resets */
  49. ATA_EH_RESET_COOL_DOWN = 5000,
  50. /* Waiting in ->prereset can never be reliable. It's
  51. * sometimes nice to wait there but it can't be depended upon;
  52. * otherwise, we wouldn't be resetting. Just give it enough
  53. * time for most drives to spin up.
  54. */
  55. ATA_EH_PRERESET_TIMEOUT = 10000,
  56. ATA_EH_FASTDRAIN_INTERVAL = 3000,
  57. ATA_EH_UA_TRIES = 5,
  58. /* probe speed down parameters, see ata_eh_schedule_probe() */
  59. ATA_EH_PROBE_TRIAL_INTERVAL = 60000, /* 1 min */
  60. ATA_EH_PROBE_TRIALS = 2,
  61. };
  62. /* The following table determines how we sequence resets. Each entry
  63. * represents timeout for that try. The first try can be soft or
  64. * hardreset. All others are hardreset if available. In most cases
  65. * the first reset w/ 10sec timeout should succeed. Following entries
  66. * are mostly for error handling, hotplug and those outlier devices that
  67. * take an exceptionally long time to recover from reset.
  68. */
  69. static const unsigned long ata_eh_reset_timeouts[] = {
  70. 10000, /* most drives spin up by 10sec */
  71. 10000, /* > 99% working drives spin up before 20sec */
  72. 35000, /* give > 30 secs of idleness for outlier devices */
  73. 5000, /* and sweet one last chance */
  74. ULONG_MAX, /* > 1 min has elapsed, give up */
  75. };
  76. static const unsigned long ata_eh_identify_timeouts[] = {
  77. 5000, /* covers > 99% of successes and not too boring on failures */
  78. 10000, /* combined time till here is enough even for media access */
  79. 30000, /* for true idiots */
  80. ULONG_MAX,
  81. };
  82. static const unsigned long ata_eh_flush_timeouts[] = {
  83. 15000, /* be generous with flush */
  84. 15000, /* ditto */
  85. 30000, /* and even more generous */
  86. ULONG_MAX,
  87. };
  88. static const unsigned long ata_eh_other_timeouts[] = {
  89. 5000, /* same rationale as identify timeout */
  90. 10000, /* ditto */
  91. /* but no merciful 30sec for other commands, it just isn't worth it */
  92. ULONG_MAX,
  93. };
  94. struct ata_eh_cmd_timeout_ent {
  95. const u8 *commands;
  96. const unsigned long *timeouts;
  97. };
  98. /* The following table determines timeouts to use for EH internal
  99. * commands. Each table entry is a command class and matches the
  100. * commands the entry applies to and the timeout table to use.
  101. *
  102. * On the retry after a command timed out, the next timeout value from
  103. * the table is used. If the table doesn't contain further entries,
  104. * the last value is used.
  105. *
  106. * ehc->cmd_timeout_idx keeps track of which timeout to use per
  107. * command class, so if SET_FEATURES times out on the first try, the
  108. * next try will use the second timeout value only for that class.
  109. */
  110. #define CMDS(cmds...) (const u8 []){ cmds, 0 }
  111. static const struct ata_eh_cmd_timeout_ent
  112. ata_eh_cmd_timeout_table[ATA_EH_CMD_TIMEOUT_TABLE_SIZE] = {
  113. { .commands = CMDS(ATA_CMD_ID_ATA, ATA_CMD_ID_ATAPI),
  114. .timeouts = ata_eh_identify_timeouts, },
  115. { .commands = CMDS(ATA_CMD_READ_NATIVE_MAX, ATA_CMD_READ_NATIVE_MAX_EXT),
  116. .timeouts = ata_eh_other_timeouts, },
  117. { .commands = CMDS(ATA_CMD_SET_MAX, ATA_CMD_SET_MAX_EXT),
  118. .timeouts = ata_eh_other_timeouts, },
  119. { .commands = CMDS(ATA_CMD_SET_FEATURES),
  120. .timeouts = ata_eh_other_timeouts, },
  121. { .commands = CMDS(ATA_CMD_INIT_DEV_PARAMS),
  122. .timeouts = ata_eh_other_timeouts, },
  123. { .commands = CMDS(ATA_CMD_FLUSH, ATA_CMD_FLUSH_EXT),
  124. .timeouts = ata_eh_flush_timeouts },
  125. };
  126. #undef CMDS
  127. static void __ata_port_freeze(struct ata_port *ap);
  128. #ifdef CONFIG_PM
  129. static void ata_eh_handle_port_suspend(struct ata_port *ap);
  130. static void ata_eh_handle_port_resume(struct ata_port *ap);
  131. #else /* CONFIG_PM */
  132. static void ata_eh_handle_port_suspend(struct ata_port *ap)
  133. { }
  134. static void ata_eh_handle_port_resume(struct ata_port *ap)
  135. { }
  136. #endif /* CONFIG_PM */
  137. static __printf(2, 0) void __ata_ehi_pushv_desc(struct ata_eh_info *ehi,
  138. const char *fmt, va_list args)
  139. {
  140. ehi->desc_len += vscnprintf(ehi->desc + ehi->desc_len,
  141. ATA_EH_DESC_LEN - ehi->desc_len,
  142. fmt, args);
  143. }
  144. /**
  145. * __ata_ehi_push_desc - push error description without adding separator
  146. * @ehi: target EHI
  147. * @fmt: printf format string
  148. *
  149. * Format string according to @fmt and append it to @ehi->desc.
  150. *
  151. * LOCKING:
  152. * spin_lock_irqsave(host lock)
  153. */
  154. void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
  155. {
  156. va_list args;
  157. va_start(args, fmt);
  158. __ata_ehi_pushv_desc(ehi, fmt, args);
  159. va_end(args);
  160. }
  161. EXPORT_SYMBOL_GPL(__ata_ehi_push_desc);
  162. /**
  163. * ata_ehi_push_desc - push error description with separator
  164. * @ehi: target EHI
  165. * @fmt: printf format string
  166. *
  167. * Format string according to @fmt and append it to @ehi->desc.
  168. * If @ehi->desc is not empty, ", " is added in-between.
  169. *
  170. * LOCKING:
  171. * spin_lock_irqsave(host lock)
  172. */
  173. void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
  174. {
  175. va_list args;
  176. if (ehi->desc_len)
  177. __ata_ehi_push_desc(ehi, ", ");
  178. va_start(args, fmt);
  179. __ata_ehi_pushv_desc(ehi, fmt, args);
  180. va_end(args);
  181. }
  182. EXPORT_SYMBOL_GPL(ata_ehi_push_desc);
  183. /**
  184. * ata_ehi_clear_desc - clean error description
  185. * @ehi: target EHI
  186. *
  187. * Clear @ehi->desc.
  188. *
  189. * LOCKING:
  190. * spin_lock_irqsave(host lock)
  191. */
  192. void ata_ehi_clear_desc(struct ata_eh_info *ehi)
  193. {
  194. ehi->desc[0] = '\0';
  195. ehi->desc_len = 0;
  196. }
  197. EXPORT_SYMBOL_GPL(ata_ehi_clear_desc);
  198. /**
  199. * ata_port_desc - append port description
  200. * @ap: target ATA port
  201. * @fmt: printf format string
  202. *
  203. * Format string according to @fmt and append it to port
  204. * description. If port description is not empty, " " is added
  205. * in-between. This function is to be used while initializing
  206. * ata_host. The description is printed on host registration.
  207. *
  208. * LOCKING:
  209. * None.
  210. */
  211. void ata_port_desc(struct ata_port *ap, const char *fmt, ...)
  212. {
  213. va_list args;
  214. WARN_ON(!(ap->pflags & ATA_PFLAG_INITIALIZING));
  215. if (ap->link.eh_info.desc_len)
  216. __ata_ehi_push_desc(&ap->link.eh_info, " ");
  217. va_start(args, fmt);
  218. __ata_ehi_pushv_desc(&ap->link.eh_info, fmt, args);
  219. va_end(args);
  220. }
  221. EXPORT_SYMBOL_GPL(ata_port_desc);
  222. #ifdef CONFIG_PCI
  223. /**
  224. * ata_port_pbar_desc - append PCI BAR description
  225. * @ap: target ATA port
  226. * @bar: target PCI BAR
  227. * @offset: offset into PCI BAR
  228. * @name: name of the area
  229. *
  230. * If @offset is negative, this function formats a string which
  231. * contains the name, address, size and type of the BAR and
  232. * appends it to the port description. If @offset is zero or
  233. * positive, only name and offsetted address is appended.
  234. *
  235. * LOCKING:
  236. * None.
  237. */
  238. void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset,
  239. const char *name)
  240. {
  241. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  242. char *type = "";
  243. unsigned long long start, len;
  244. if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM)
  245. type = "m";
  246. else if (pci_resource_flags(pdev, bar) & IORESOURCE_IO)
  247. type = "i";
  248. start = (unsigned long long)pci_resource_start(pdev, bar);
  249. len = (unsigned long long)pci_resource_len(pdev, bar);
  250. if (offset < 0)
  251. ata_port_desc(ap, "%s %s%llu@0x%llx", name, type, len, start);
  252. else
  253. ata_port_desc(ap, "%s 0x%llx", name,
  254. start + (unsigned long long)offset);
  255. }
  256. EXPORT_SYMBOL_GPL(ata_port_pbar_desc);
  257. #endif /* CONFIG_PCI */
  258. static int ata_lookup_timeout_table(u8 cmd)
  259. {
  260. int i;
  261. for (i = 0; i < ATA_EH_CMD_TIMEOUT_TABLE_SIZE; i++) {
  262. const u8 *cur;
  263. for (cur = ata_eh_cmd_timeout_table[i].commands; *cur; cur++)
  264. if (*cur == cmd)
  265. return i;
  266. }
  267. return -1;
  268. }
  269. /**
  270. * ata_internal_cmd_timeout - determine timeout for an internal command
  271. * @dev: target device
  272. * @cmd: internal command to be issued
  273. *
  274. * Determine timeout for internal command @cmd for @dev.
  275. *
  276. * LOCKING:
  277. * EH context.
  278. *
  279. * RETURNS:
  280. * Determined timeout.
  281. */
  282. unsigned long ata_internal_cmd_timeout(struct ata_device *dev, u8 cmd)
  283. {
  284. struct ata_eh_context *ehc = &dev->link->eh_context;
  285. int ent = ata_lookup_timeout_table(cmd);
  286. int idx;
  287. if (ent < 0)
  288. return ATA_EH_CMD_DFL_TIMEOUT;
  289. idx = ehc->cmd_timeout_idx[dev->devno][ent];
  290. return ata_eh_cmd_timeout_table[ent].timeouts[idx];
  291. }
  292. /**
  293. * ata_internal_cmd_timed_out - notification for internal command timeout
  294. * @dev: target device
  295. * @cmd: internal command which timed out
  296. *
  297. * Notify EH that internal command @cmd for @dev timed out. This
  298. * function should be called only for commands whose timeouts are
  299. * determined using ata_internal_cmd_timeout().
  300. *
  301. * LOCKING:
  302. * EH context.
  303. */
  304. void ata_internal_cmd_timed_out(struct ata_device *dev, u8 cmd)
  305. {
  306. struct ata_eh_context *ehc = &dev->link->eh_context;
  307. int ent = ata_lookup_timeout_table(cmd);
  308. int idx;
  309. if (ent < 0)
  310. return;
  311. idx = ehc->cmd_timeout_idx[dev->devno][ent];
  312. if (ata_eh_cmd_timeout_table[ent].timeouts[idx + 1] != ULONG_MAX)
  313. ehc->cmd_timeout_idx[dev->devno][ent]++;
  314. }
  315. static void ata_ering_record(struct ata_ering *ering, unsigned int eflags,
  316. unsigned int err_mask)
  317. {
  318. struct ata_ering_entry *ent;
  319. WARN_ON(!err_mask);
  320. ering->cursor++;
  321. ering->cursor %= ATA_ERING_SIZE;
  322. ent = &ering->ring[ering->cursor];
  323. ent->eflags = eflags;
  324. ent->err_mask = err_mask;
  325. ent->timestamp = get_jiffies_64();
  326. }
  327. static struct ata_ering_entry *ata_ering_top(struct ata_ering *ering)
  328. {
  329. struct ata_ering_entry *ent = &ering->ring[ering->cursor];
  330. if (ent->err_mask)
  331. return ent;
  332. return NULL;
  333. }
  334. int ata_ering_map(struct ata_ering *ering,
  335. int (*map_fn)(struct ata_ering_entry *, void *),
  336. void *arg)
  337. {
  338. int idx, rc = 0;
  339. struct ata_ering_entry *ent;
  340. idx = ering->cursor;
  341. do {
  342. ent = &ering->ring[idx];
  343. if (!ent->err_mask)
  344. break;
  345. rc = map_fn(ent, arg);
  346. if (rc)
  347. break;
  348. idx = (idx - 1 + ATA_ERING_SIZE) % ATA_ERING_SIZE;
  349. } while (idx != ering->cursor);
  350. return rc;
  351. }
  352. static int ata_ering_clear_cb(struct ata_ering_entry *ent, void *void_arg)
  353. {
  354. ent->eflags |= ATA_EFLAG_OLD_ER;
  355. return 0;
  356. }
  357. static void ata_ering_clear(struct ata_ering *ering)
  358. {
  359. ata_ering_map(ering, ata_ering_clear_cb, NULL);
  360. }
  361. static unsigned int ata_eh_dev_action(struct ata_device *dev)
  362. {
  363. struct ata_eh_context *ehc = &dev->link->eh_context;
  364. return ehc->i.action | ehc->i.dev_action[dev->devno];
  365. }
  366. static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev,
  367. struct ata_eh_info *ehi, unsigned int action)
  368. {
  369. struct ata_device *tdev;
  370. if (!dev) {
  371. ehi->action &= ~action;
  372. ata_for_each_dev(tdev, link, ALL)
  373. ehi->dev_action[tdev->devno] &= ~action;
  374. } else {
  375. /* doesn't make sense for port-wide EH actions */
  376. WARN_ON(!(action & ATA_EH_PERDEV_MASK));
  377. /* break ehi->action into ehi->dev_action */
  378. if (ehi->action & action) {
  379. ata_for_each_dev(tdev, link, ALL)
  380. ehi->dev_action[tdev->devno] |=
  381. ehi->action & action;
  382. ehi->action &= ~action;
  383. }
  384. /* turn off the specified per-dev action */
  385. ehi->dev_action[dev->devno] &= ~action;
  386. }
  387. }
  388. /**
  389. * ata_eh_acquire - acquire EH ownership
  390. * @ap: ATA port to acquire EH ownership for
  391. *
  392. * Acquire EH ownership for @ap. This is the basic exclusion
  393. * mechanism for ports sharing a host. Only one port hanging off
  394. * the same host can claim the ownership of EH.
  395. *
  396. * LOCKING:
  397. * EH context.
  398. */
  399. void ata_eh_acquire(struct ata_port *ap)
  400. {
  401. mutex_lock(&ap->host->eh_mutex);
  402. WARN_ON_ONCE(ap->host->eh_owner);
  403. ap->host->eh_owner = current;
  404. }
  405. /**
  406. * ata_eh_release - release EH ownership
  407. * @ap: ATA port to release EH ownership for
  408. *
  409. * Release EH ownership for @ap if the caller. The caller must
  410. * have acquired EH ownership using ata_eh_acquire() previously.
  411. *
  412. * LOCKING:
  413. * EH context.
  414. */
  415. void ata_eh_release(struct ata_port *ap)
  416. {
  417. WARN_ON_ONCE(ap->host->eh_owner != current);
  418. ap->host->eh_owner = NULL;
  419. mutex_unlock(&ap->host->eh_mutex);
  420. }
  421. static void ata_eh_unload(struct ata_port *ap)
  422. {
  423. struct ata_link *link;
  424. struct ata_device *dev;
  425. unsigned long flags;
  426. /* Restore SControl IPM and SPD for the next driver and
  427. * disable attached devices.
  428. */
  429. ata_for_each_link(link, ap, PMP_FIRST) {
  430. sata_scr_write(link, SCR_CONTROL, link->saved_scontrol & 0xff0);
  431. ata_for_each_dev(dev, link, ALL)
  432. ata_dev_disable(dev);
  433. }
  434. /* freeze and set UNLOADED */
  435. spin_lock_irqsave(ap->lock, flags);
  436. ata_port_freeze(ap); /* won't be thawed */
  437. ap->pflags &= ~ATA_PFLAG_EH_PENDING; /* clear pending from freeze */
  438. ap->pflags |= ATA_PFLAG_UNLOADED;
  439. spin_unlock_irqrestore(ap->lock, flags);
  440. }
  441. /**
  442. * ata_scsi_error - SCSI layer error handler callback
  443. * @host: SCSI host on which error occurred
  444. *
  445. * Handles SCSI-layer-thrown error events.
  446. *
  447. * LOCKING:
  448. * Inherited from SCSI layer (none, can sleep)
  449. *
  450. * RETURNS:
  451. * Zero.
  452. */
  453. void ata_scsi_error(struct Scsi_Host *host)
  454. {
  455. struct ata_port *ap = ata_shost_to_port(host);
  456. unsigned long flags;
  457. LIST_HEAD(eh_work_q);
  458. DPRINTK("ENTER\n");
  459. spin_lock_irqsave(host->host_lock, flags);
  460. list_splice_init(&host->eh_cmd_q, &eh_work_q);
  461. spin_unlock_irqrestore(host->host_lock, flags);
  462. ata_scsi_cmd_error_handler(host, ap, &eh_work_q);
  463. /* If we timed raced normal completion and there is nothing to
  464. recover nr_timedout == 0 why exactly are we doing error recovery ? */
  465. ata_scsi_port_error_handler(host, ap);
  466. /* finish or retry handled scmd's and clean up */
  467. WARN_ON(!list_empty(&eh_work_q));
  468. DPRINTK("EXIT\n");
  469. }
  470. /**
  471. * ata_scsi_cmd_error_handler - error callback for a list of commands
  472. * @host: scsi host containing the port
  473. * @ap: ATA port within the host
  474. * @eh_work_q: list of commands to process
  475. *
  476. * process the given list of commands and return those finished to the
  477. * ap->eh_done_q. This function is the first part of the libata error
  478. * handler which processes a given list of failed commands.
  479. */
  480. void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap,
  481. struct list_head *eh_work_q)
  482. {
  483. int i;
  484. unsigned long flags;
  485. /* make sure sff pio task is not running */
  486. ata_sff_flush_pio_task(ap);
  487. /* synchronize with host lock and sort out timeouts */
  488. /* For new EH, all qcs are finished in one of three ways -
  489. * normal completion, error completion, and SCSI timeout.
  490. * Both completions can race against SCSI timeout. When normal
  491. * completion wins, the qc never reaches EH. When error
  492. * completion wins, the qc has ATA_QCFLAG_FAILED set.
  493. *
  494. * When SCSI timeout wins, things are a bit more complex.
  495. * Normal or error completion can occur after the timeout but
  496. * before this point. In such cases, both types of
  497. * completions are honored. A scmd is determined to have
  498. * timed out iff its associated qc is active and not failed.
  499. */
  500. spin_lock_irqsave(ap->lock, flags);
  501. if (ap->ops->error_handler) {
  502. struct scsi_cmnd *scmd, *tmp;
  503. int nr_timedout = 0;
  504. /* This must occur under the ap->lock as we don't want
  505. a polled recovery to race the real interrupt handler
  506. The lost_interrupt handler checks for any completed but
  507. non-notified command and completes much like an IRQ handler.
  508. We then fall into the error recovery code which will treat
  509. this as if normal completion won the race */
  510. if (ap->ops->lost_interrupt)
  511. ap->ops->lost_interrupt(ap);
  512. list_for_each_entry_safe(scmd, tmp, eh_work_q, eh_entry) {
  513. struct ata_queued_cmd *qc;
  514. ata_qc_for_each_raw(ap, qc, i) {
  515. if (qc->flags & ATA_QCFLAG_ACTIVE &&
  516. qc->scsicmd == scmd)
  517. break;
  518. }
  519. if (i < ATA_MAX_QUEUE) {
  520. /* the scmd has an associated qc */
  521. if (!(qc->flags & ATA_QCFLAG_FAILED)) {
  522. /* which hasn't failed yet, timeout */
  523. qc->err_mask |= AC_ERR_TIMEOUT;
  524. qc->flags |= ATA_QCFLAG_FAILED;
  525. nr_timedout++;
  526. }
  527. } else {
  528. /* Normal completion occurred after
  529. * SCSI timeout but before this point.
  530. * Successfully complete it.
  531. */
  532. scmd->retries = scmd->allowed;
  533. scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
  534. }
  535. }
  536. /* If we have timed out qcs. They belong to EH from
  537. * this point but the state of the controller is
  538. * unknown. Freeze the port to make sure the IRQ
  539. * handler doesn't diddle with those qcs. This must
  540. * be done atomically w.r.t. setting QCFLAG_FAILED.
  541. */
  542. if (nr_timedout)
  543. __ata_port_freeze(ap);
  544. /* initialize eh_tries */
  545. ap->eh_tries = ATA_EH_MAX_TRIES;
  546. }
  547. spin_unlock_irqrestore(ap->lock, flags);
  548. }
  549. EXPORT_SYMBOL(ata_scsi_cmd_error_handler);
  550. /**
  551. * ata_scsi_port_error_handler - recover the port after the commands
  552. * @host: SCSI host containing the port
  553. * @ap: the ATA port
  554. *
  555. * Handle the recovery of the port @ap after all the commands
  556. * have been recovered.
  557. */
  558. void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap)
  559. {
  560. unsigned long flags;
  561. /* invoke error handler */
  562. if (ap->ops->error_handler) {
  563. struct ata_link *link;
  564. /* acquire EH ownership */
  565. ata_eh_acquire(ap);
  566. repeat:
  567. /* kill fast drain timer */
  568. del_timer_sync(&ap->fastdrain_timer);
  569. /* process port resume request */
  570. ata_eh_handle_port_resume(ap);
  571. /* fetch & clear EH info */
  572. spin_lock_irqsave(ap->lock, flags);
  573. ata_for_each_link(link, ap, HOST_FIRST) {
  574. struct ata_eh_context *ehc = &link->eh_context;
  575. struct ata_device *dev;
  576. memset(&link->eh_context, 0, sizeof(link->eh_context));
  577. link->eh_context.i = link->eh_info;
  578. memset(&link->eh_info, 0, sizeof(link->eh_info));
  579. ata_for_each_dev(dev, link, ENABLED) {
  580. int devno = dev->devno;
  581. ehc->saved_xfer_mode[devno] = dev->xfer_mode;
  582. if (ata_ncq_enabled(dev))
  583. ehc->saved_ncq_enabled |= 1 << devno;
  584. }
  585. }
  586. ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS;
  587. ap->pflags &= ~ATA_PFLAG_EH_PENDING;
  588. ap->excl_link = NULL; /* don't maintain exclusion over EH */
  589. spin_unlock_irqrestore(ap->lock, flags);
  590. /* invoke EH, skip if unloading or suspended */
  591. if (!(ap->pflags & (ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED)))
  592. ap->ops->error_handler(ap);
  593. else {
  594. /* if unloading, commence suicide */
  595. if ((ap->pflags & ATA_PFLAG_UNLOADING) &&
  596. !(ap->pflags & ATA_PFLAG_UNLOADED))
  597. ata_eh_unload(ap);
  598. ata_eh_finish(ap);
  599. }
  600. /* process port suspend request */
  601. ata_eh_handle_port_suspend(ap);
  602. /* Exception might have happened after ->error_handler
  603. * recovered the port but before this point. Repeat
  604. * EH in such case.
  605. */
  606. spin_lock_irqsave(ap->lock, flags);
  607. if (ap->pflags & ATA_PFLAG_EH_PENDING) {
  608. if (--ap->eh_tries) {
  609. spin_unlock_irqrestore(ap->lock, flags);
  610. goto repeat;
  611. }
  612. ata_port_err(ap,
  613. "EH pending after %d tries, giving up\n",
  614. ATA_EH_MAX_TRIES);
  615. ap->pflags &= ~ATA_PFLAG_EH_PENDING;
  616. }
  617. /* this run is complete, make sure EH info is clear */
  618. ata_for_each_link(link, ap, HOST_FIRST)
  619. memset(&link->eh_info, 0, sizeof(link->eh_info));
  620. /* end eh (clear host_eh_scheduled) while holding
  621. * ap->lock such that if exception occurs after this
  622. * point but before EH completion, SCSI midlayer will
  623. * re-initiate EH.
  624. */
  625. ap->ops->end_eh(ap);
  626. spin_unlock_irqrestore(ap->lock, flags);
  627. ata_eh_release(ap);
  628. } else {
  629. WARN_ON(ata_qc_from_tag(ap, ap->link.active_tag) == NULL);
  630. ap->ops->eng_timeout(ap);
  631. }
  632. scsi_eh_flush_done_q(&ap->eh_done_q);
  633. /* clean up */
  634. spin_lock_irqsave(ap->lock, flags);
  635. if (ap->pflags & ATA_PFLAG_LOADING)
  636. ap->pflags &= ~ATA_PFLAG_LOADING;
  637. else if ((ap->pflags & ATA_PFLAG_SCSI_HOTPLUG) &&
  638. !(ap->flags & ATA_FLAG_SAS_HOST))
  639. schedule_delayed_work(&ap->hotplug_task, 0);
  640. if (ap->pflags & ATA_PFLAG_RECOVERED)
  641. ata_port_info(ap, "EH complete\n");
  642. ap->pflags &= ~(ATA_PFLAG_SCSI_HOTPLUG | ATA_PFLAG_RECOVERED);
  643. /* tell wait_eh that we're done */
  644. ap->pflags &= ~ATA_PFLAG_EH_IN_PROGRESS;
  645. wake_up_all(&ap->eh_wait_q);
  646. spin_unlock_irqrestore(ap->lock, flags);
  647. }
  648. EXPORT_SYMBOL_GPL(ata_scsi_port_error_handler);
  649. /**
  650. * ata_port_wait_eh - Wait for the currently pending EH to complete
  651. * @ap: Port to wait EH for
  652. *
  653. * Wait until the currently pending EH is complete.
  654. *
  655. * LOCKING:
  656. * Kernel thread context (may sleep).
  657. */
  658. void ata_port_wait_eh(struct ata_port *ap)
  659. {
  660. unsigned long flags;
  661. DEFINE_WAIT(wait);
  662. retry:
  663. spin_lock_irqsave(ap->lock, flags);
  664. while (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) {
  665. prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE);
  666. spin_unlock_irqrestore(ap->lock, flags);
  667. schedule();
  668. spin_lock_irqsave(ap->lock, flags);
  669. }
  670. finish_wait(&ap->eh_wait_q, &wait);
  671. spin_unlock_irqrestore(ap->lock, flags);
  672. /* make sure SCSI EH is complete */
  673. if (scsi_host_in_recovery(ap->scsi_host)) {
  674. ata_msleep(ap, 10);
  675. goto retry;
  676. }
  677. }
  678. EXPORT_SYMBOL_GPL(ata_port_wait_eh);
  679. static int ata_eh_nr_in_flight(struct ata_port *ap)
  680. {
  681. struct ata_queued_cmd *qc;
  682. unsigned int tag;
  683. int nr = 0;
  684. /* count only non-internal commands */
  685. ata_qc_for_each(ap, qc, tag) {
  686. if (qc)
  687. nr++;
  688. }
  689. return nr;
  690. }
  691. void ata_eh_fastdrain_timerfn(struct timer_list *t)
  692. {
  693. struct ata_port *ap = from_timer(ap, t, fastdrain_timer);
  694. unsigned long flags;
  695. int cnt;
  696. spin_lock_irqsave(ap->lock, flags);
  697. cnt = ata_eh_nr_in_flight(ap);
  698. /* are we done? */
  699. if (!cnt)
  700. goto out_unlock;
  701. if (cnt == ap->fastdrain_cnt) {
  702. struct ata_queued_cmd *qc;
  703. unsigned int tag;
  704. /* No progress during the last interval, tag all
  705. * in-flight qcs as timed out and freeze the port.
  706. */
  707. ata_qc_for_each(ap, qc, tag) {
  708. if (qc)
  709. qc->err_mask |= AC_ERR_TIMEOUT;
  710. }
  711. ata_port_freeze(ap);
  712. } else {
  713. /* some qcs have finished, give it another chance */
  714. ap->fastdrain_cnt = cnt;
  715. ap->fastdrain_timer.expires =
  716. ata_deadline(jiffies, ATA_EH_FASTDRAIN_INTERVAL);
  717. add_timer(&ap->fastdrain_timer);
  718. }
  719. out_unlock:
  720. spin_unlock_irqrestore(ap->lock, flags);
  721. }
  722. /**
  723. * ata_eh_set_pending - set ATA_PFLAG_EH_PENDING and activate fast drain
  724. * @ap: target ATA port
  725. * @fastdrain: activate fast drain
  726. *
  727. * Set ATA_PFLAG_EH_PENDING and activate fast drain if @fastdrain
  728. * is non-zero and EH wasn't pending before. Fast drain ensures
  729. * that EH kicks in in timely manner.
  730. *
  731. * LOCKING:
  732. * spin_lock_irqsave(host lock)
  733. */
  734. static void ata_eh_set_pending(struct ata_port *ap, int fastdrain)
  735. {
  736. int cnt;
  737. /* already scheduled? */
  738. if (ap->pflags & ATA_PFLAG_EH_PENDING)
  739. return;
  740. ap->pflags |= ATA_PFLAG_EH_PENDING;
  741. if (!fastdrain)
  742. return;
  743. /* do we have in-flight qcs? */
  744. cnt = ata_eh_nr_in_flight(ap);
  745. if (!cnt)
  746. return;
  747. /* activate fast drain */
  748. ap->fastdrain_cnt = cnt;
  749. ap->fastdrain_timer.expires =
  750. ata_deadline(jiffies, ATA_EH_FASTDRAIN_INTERVAL);
  751. add_timer(&ap->fastdrain_timer);
  752. }
  753. /**
  754. * ata_qc_schedule_eh - schedule qc for error handling
  755. * @qc: command to schedule error handling for
  756. *
  757. * Schedule error handling for @qc. EH will kick in as soon as
  758. * other commands are drained.
  759. *
  760. * LOCKING:
  761. * spin_lock_irqsave(host lock)
  762. */
  763. void ata_qc_schedule_eh(struct ata_queued_cmd *qc)
  764. {
  765. struct ata_port *ap = qc->ap;
  766. WARN_ON(!ap->ops->error_handler);
  767. qc->flags |= ATA_QCFLAG_FAILED;
  768. ata_eh_set_pending(ap, 1);
  769. /* The following will fail if timeout has already expired.
  770. * ata_scsi_error() takes care of such scmds on EH entry.
  771. * Note that ATA_QCFLAG_FAILED is unconditionally set after
  772. * this function completes.
  773. */
  774. blk_abort_request(qc->scsicmd->request);
  775. }
  776. /**
  777. * ata_std_sched_eh - non-libsas ata_ports issue eh with this common routine
  778. * @ap: ATA port to schedule EH for
  779. *
  780. * LOCKING: inherited from ata_port_schedule_eh
  781. * spin_lock_irqsave(host lock)
  782. */
  783. void ata_std_sched_eh(struct ata_port *ap)
  784. {
  785. WARN_ON(!ap->ops->error_handler);
  786. if (ap->pflags & ATA_PFLAG_INITIALIZING)
  787. return;
  788. ata_eh_set_pending(ap, 1);
  789. scsi_schedule_eh(ap->scsi_host);
  790. DPRINTK("port EH scheduled\n");
  791. }
  792. EXPORT_SYMBOL_GPL(ata_std_sched_eh);
  793. /**
  794. * ata_std_end_eh - non-libsas ata_ports complete eh with this common routine
  795. * @ap: ATA port to end EH for
  796. *
  797. * In the libata object model there is a 1:1 mapping of ata_port to
  798. * shost, so host fields can be directly manipulated under ap->lock, in
  799. * the libsas case we need to hold a lock at the ha->level to coordinate
  800. * these events.
  801. *
  802. * LOCKING:
  803. * spin_lock_irqsave(host lock)
  804. */
  805. void ata_std_end_eh(struct ata_port *ap)
  806. {
  807. struct Scsi_Host *host = ap->scsi_host;
  808. host->host_eh_scheduled = 0;
  809. }
  810. EXPORT_SYMBOL(ata_std_end_eh);
  811. /**
  812. * ata_port_schedule_eh - schedule error handling without a qc
  813. * @ap: ATA port to schedule EH for
  814. *
  815. * Schedule error handling for @ap. EH will kick in as soon as
  816. * all commands are drained.
  817. *
  818. * LOCKING:
  819. * spin_lock_irqsave(host lock)
  820. */
  821. void ata_port_schedule_eh(struct ata_port *ap)
  822. {
  823. /* see: ata_std_sched_eh, unless you know better */
  824. ap->ops->sched_eh(ap);
  825. }
  826. EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
  827. static int ata_do_link_abort(struct ata_port *ap, struct ata_link *link)
  828. {
  829. struct ata_queued_cmd *qc;
  830. int tag, nr_aborted = 0;
  831. WARN_ON(!ap->ops->error_handler);
  832. /* we're gonna abort all commands, no need for fast drain */
  833. ata_eh_set_pending(ap, 0);
  834. /* include internal tag in iteration */
  835. ata_qc_for_each_with_internal(ap, qc, tag) {
  836. if (qc && (!link || qc->dev->link == link)) {
  837. qc->flags |= ATA_QCFLAG_FAILED;
  838. ata_qc_complete(qc);
  839. nr_aborted++;
  840. }
  841. }
  842. if (!nr_aborted)
  843. ata_port_schedule_eh(ap);
  844. return nr_aborted;
  845. }
  846. /**
  847. * ata_link_abort - abort all qc's on the link
  848. * @link: ATA link to abort qc's for
  849. *
  850. * Abort all active qc's active on @link and schedule EH.
  851. *
  852. * LOCKING:
  853. * spin_lock_irqsave(host lock)
  854. *
  855. * RETURNS:
  856. * Number of aborted qc's.
  857. */
  858. int ata_link_abort(struct ata_link *link)
  859. {
  860. return ata_do_link_abort(link->ap, link);
  861. }
  862. EXPORT_SYMBOL_GPL(ata_link_abort);
  863. /**
  864. * ata_port_abort - abort all qc's on the port
  865. * @ap: ATA port to abort qc's for
  866. *
  867. * Abort all active qc's of @ap and schedule EH.
  868. *
  869. * LOCKING:
  870. * spin_lock_irqsave(host_set lock)
  871. *
  872. * RETURNS:
  873. * Number of aborted qc's.
  874. */
  875. int ata_port_abort(struct ata_port *ap)
  876. {
  877. return ata_do_link_abort(ap, NULL);
  878. }
  879. EXPORT_SYMBOL_GPL(ata_port_abort);
  880. /**
  881. * __ata_port_freeze - freeze port
  882. * @ap: ATA port to freeze
  883. *
  884. * This function is called when HSM violation or some other
  885. * condition disrupts normal operation of the port. Frozen port
  886. * is not allowed to perform any operation until the port is
  887. * thawed, which usually follows a successful reset.
  888. *
  889. * ap->ops->freeze() callback can be used for freezing the port
  890. * hardware-wise (e.g. mask interrupt and stop DMA engine). If a
  891. * port cannot be frozen hardware-wise, the interrupt handler
  892. * must ack and clear interrupts unconditionally while the port
  893. * is frozen.
  894. *
  895. * LOCKING:
  896. * spin_lock_irqsave(host lock)
  897. */
  898. static void __ata_port_freeze(struct ata_port *ap)
  899. {
  900. WARN_ON(!ap->ops->error_handler);
  901. if (ap->ops->freeze)
  902. ap->ops->freeze(ap);
  903. ap->pflags |= ATA_PFLAG_FROZEN;
  904. DPRINTK("ata%u port frozen\n", ap->print_id);
  905. }
  906. /**
  907. * ata_port_freeze - abort & freeze port
  908. * @ap: ATA port to freeze
  909. *
  910. * Abort and freeze @ap. The freeze operation must be called
  911. * first, because some hardware requires special operations
  912. * before the taskfile registers are accessible.
  913. *
  914. * LOCKING:
  915. * spin_lock_irqsave(host lock)
  916. *
  917. * RETURNS:
  918. * Number of aborted commands.
  919. */
  920. int ata_port_freeze(struct ata_port *ap)
  921. {
  922. int nr_aborted;
  923. WARN_ON(!ap->ops->error_handler);
  924. __ata_port_freeze(ap);
  925. nr_aborted = ata_port_abort(ap);
  926. return nr_aborted;
  927. }
  928. EXPORT_SYMBOL_GPL(ata_port_freeze);
  929. /**
  930. * ata_eh_freeze_port - EH helper to freeze port
  931. * @ap: ATA port to freeze
  932. *
  933. * Freeze @ap.
  934. *
  935. * LOCKING:
  936. * None.
  937. */
  938. void ata_eh_freeze_port(struct ata_port *ap)
  939. {
  940. unsigned long flags;
  941. if (!ap->ops->error_handler)
  942. return;
  943. spin_lock_irqsave(ap->lock, flags);
  944. __ata_port_freeze(ap);
  945. spin_unlock_irqrestore(ap->lock, flags);
  946. }
  947. EXPORT_SYMBOL_GPL(ata_eh_freeze_port);
  948. /**
  949. * ata_port_thaw_port - EH helper to thaw port
  950. * @ap: ATA port to thaw
  951. *
  952. * Thaw frozen port @ap.
  953. *
  954. * LOCKING:
  955. * None.
  956. */
  957. void ata_eh_thaw_port(struct ata_port *ap)
  958. {
  959. unsigned long flags;
  960. if (!ap->ops->error_handler)
  961. return;
  962. spin_lock_irqsave(ap->lock, flags);
  963. ap->pflags &= ~ATA_PFLAG_FROZEN;
  964. if (ap->ops->thaw)
  965. ap->ops->thaw(ap);
  966. spin_unlock_irqrestore(ap->lock, flags);
  967. DPRINTK("ata%u port thawed\n", ap->print_id);
  968. }
  969. static void ata_eh_scsidone(struct scsi_cmnd *scmd)
  970. {
  971. /* nada */
  972. }
  973. static void __ata_eh_qc_complete(struct ata_queued_cmd *qc)
  974. {
  975. struct ata_port *ap = qc->ap;
  976. struct scsi_cmnd *scmd = qc->scsicmd;
  977. unsigned long flags;
  978. spin_lock_irqsave(ap->lock, flags);
  979. qc->scsidone = ata_eh_scsidone;
  980. __ata_qc_complete(qc);
  981. WARN_ON(ata_tag_valid(qc->tag));
  982. spin_unlock_irqrestore(ap->lock, flags);
  983. scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
  984. }
  985. /**
  986. * ata_eh_qc_complete - Complete an active ATA command from EH
  987. * @qc: Command to complete
  988. *
  989. * Indicate to the mid and upper layers that an ATA command has
  990. * completed. To be used from EH.
  991. */
  992. void ata_eh_qc_complete(struct ata_queued_cmd *qc)
  993. {
  994. struct scsi_cmnd *scmd = qc->scsicmd;
  995. scmd->retries = scmd->allowed;
  996. __ata_eh_qc_complete(qc);
  997. }
  998. /**
  999. * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
  1000. * @qc: Command to retry
  1001. *
  1002. * Indicate to the mid and upper layers that an ATA command
  1003. * should be retried. To be used from EH.
  1004. *
  1005. * SCSI midlayer limits the number of retries to scmd->allowed.
  1006. * scmd->allowed is incremented for commands which get retried
  1007. * due to unrelated failures (qc->err_mask is zero).
  1008. */
  1009. void ata_eh_qc_retry(struct ata_queued_cmd *qc)
  1010. {
  1011. struct scsi_cmnd *scmd = qc->scsicmd;
  1012. if (!qc->err_mask)
  1013. scmd->allowed++;
  1014. __ata_eh_qc_complete(qc);
  1015. }
  1016. /**
  1017. * ata_dev_disable - disable ATA device
  1018. * @dev: ATA device to disable
  1019. *
  1020. * Disable @dev.
  1021. *
  1022. * Locking:
  1023. * EH context.
  1024. */
  1025. void ata_dev_disable(struct ata_device *dev)
  1026. {
  1027. if (!ata_dev_enabled(dev))
  1028. return;
  1029. if (ata_msg_drv(dev->link->ap))
  1030. ata_dev_warn(dev, "disabled\n");
  1031. ata_acpi_on_disable(dev);
  1032. ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 | ATA_DNXFER_QUIET);
  1033. dev->class++;
  1034. /* From now till the next successful probe, ering is used to
  1035. * track probe failures. Clear accumulated device error info.
  1036. */
  1037. ata_ering_clear(&dev->ering);
  1038. }
  1039. EXPORT_SYMBOL_GPL(ata_dev_disable);
  1040. /**
  1041. * ata_eh_detach_dev - detach ATA device
  1042. * @dev: ATA device to detach
  1043. *
  1044. * Detach @dev.
  1045. *
  1046. * LOCKING:
  1047. * None.
  1048. */
  1049. void ata_eh_detach_dev(struct ata_device *dev)
  1050. {
  1051. struct ata_link *link = dev->link;
  1052. struct ata_port *ap = link->ap;
  1053. struct ata_eh_context *ehc = &link->eh_context;
  1054. unsigned long flags;
  1055. ata_dev_disable(dev);
  1056. spin_lock_irqsave(ap->lock, flags);
  1057. dev->flags &= ~ATA_DFLAG_DETACH;
  1058. if (ata_scsi_offline_dev(dev)) {
  1059. dev->flags |= ATA_DFLAG_DETACHED;
  1060. ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
  1061. }
  1062. /* clear per-dev EH info */
  1063. ata_eh_clear_action(link, dev, &link->eh_info, ATA_EH_PERDEV_MASK);
  1064. ata_eh_clear_action(link, dev, &link->eh_context.i, ATA_EH_PERDEV_MASK);
  1065. ehc->saved_xfer_mode[dev->devno] = 0;
  1066. ehc->saved_ncq_enabled &= ~(1 << dev->devno);
  1067. spin_unlock_irqrestore(ap->lock, flags);
  1068. }
  1069. /**
  1070. * ata_eh_about_to_do - about to perform eh_action
  1071. * @link: target ATA link
  1072. * @dev: target ATA dev for per-dev action (can be NULL)
  1073. * @action: action about to be performed
  1074. *
  1075. * Called just before performing EH actions to clear related bits
  1076. * in @link->eh_info such that eh actions are not unnecessarily
  1077. * repeated.
  1078. *
  1079. * LOCKING:
  1080. * None.
  1081. */
  1082. void ata_eh_about_to_do(struct ata_link *link, struct ata_device *dev,
  1083. unsigned int action)
  1084. {
  1085. struct ata_port *ap = link->ap;
  1086. struct ata_eh_info *ehi = &link->eh_info;
  1087. struct ata_eh_context *ehc = &link->eh_context;
  1088. unsigned long flags;
  1089. spin_lock_irqsave(ap->lock, flags);
  1090. ata_eh_clear_action(link, dev, ehi, action);
  1091. /* About to take EH action, set RECOVERED. Ignore actions on
  1092. * slave links as master will do them again.
  1093. */
  1094. if (!(ehc->i.flags & ATA_EHI_QUIET) && link != ap->slave_link)
  1095. ap->pflags |= ATA_PFLAG_RECOVERED;
  1096. spin_unlock_irqrestore(ap->lock, flags);
  1097. }
  1098. /**
  1099. * ata_eh_done - EH action complete
  1100. * @link: ATA link for which EH actions are complete
  1101. * @dev: target ATA dev for per-dev action (can be NULL)
  1102. * @action: action just completed
  1103. *
  1104. * Called right after performing EH actions to clear related bits
  1105. * in @link->eh_context.
  1106. *
  1107. * LOCKING:
  1108. * None.
  1109. */
  1110. void ata_eh_done(struct ata_link *link, struct ata_device *dev,
  1111. unsigned int action)
  1112. {
  1113. struct ata_eh_context *ehc = &link->eh_context;
  1114. ata_eh_clear_action(link, dev, &ehc->i, action);
  1115. }
  1116. /**
  1117. * ata_err_string - convert err_mask to descriptive string
  1118. * @err_mask: error mask to convert to string
  1119. *
  1120. * Convert @err_mask to descriptive string. Errors are
  1121. * prioritized according to severity and only the most severe
  1122. * error is reported.
  1123. *
  1124. * LOCKING:
  1125. * None.
  1126. *
  1127. * RETURNS:
  1128. * Descriptive string for @err_mask
  1129. */
  1130. static const char *ata_err_string(unsigned int err_mask)
  1131. {
  1132. if (err_mask & AC_ERR_HOST_BUS)
  1133. return "host bus error";
  1134. if (err_mask & AC_ERR_ATA_BUS)
  1135. return "ATA bus error";
  1136. if (err_mask & AC_ERR_TIMEOUT)
  1137. return "timeout";
  1138. if (err_mask & AC_ERR_HSM)
  1139. return "HSM violation";
  1140. if (err_mask & AC_ERR_SYSTEM)
  1141. return "internal error";
  1142. if (err_mask & AC_ERR_MEDIA)
  1143. return "media error";
  1144. if (err_mask & AC_ERR_INVALID)
  1145. return "invalid argument";
  1146. if (err_mask & AC_ERR_DEV)
  1147. return "device error";
  1148. if (err_mask & AC_ERR_NCQ)
  1149. return "NCQ error";
  1150. if (err_mask & AC_ERR_NODEV_HINT)
  1151. return "Polling detection error";
  1152. return "unknown error";
  1153. }
  1154. /**
  1155. * atapi_eh_tur - perform ATAPI TEST_UNIT_READY
  1156. * @dev: target ATAPI device
  1157. * @r_sense_key: out parameter for sense_key
  1158. *
  1159. * Perform ATAPI TEST_UNIT_READY.
  1160. *
  1161. * LOCKING:
  1162. * EH context (may sleep).
  1163. *
  1164. * RETURNS:
  1165. * 0 on success, AC_ERR_* mask on failure.
  1166. */
  1167. unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key)
  1168. {
  1169. u8 cdb[ATAPI_CDB_LEN] = { TEST_UNIT_READY, 0, 0, 0, 0, 0 };
  1170. struct ata_taskfile tf;
  1171. unsigned int err_mask;
  1172. ata_tf_init(dev, &tf);
  1173. tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
  1174. tf.command = ATA_CMD_PACKET;
  1175. tf.protocol = ATAPI_PROT_NODATA;
  1176. err_mask = ata_exec_internal(dev, &tf, cdb, DMA_NONE, NULL, 0, 0);
  1177. if (err_mask == AC_ERR_DEV)
  1178. *r_sense_key = tf.feature >> 4;
  1179. return err_mask;
  1180. }
  1181. /**
  1182. * ata_eh_request_sense - perform REQUEST_SENSE_DATA_EXT
  1183. * @qc: qc to perform REQUEST_SENSE_SENSE_DATA_EXT to
  1184. * @cmd: scsi command for which the sense code should be set
  1185. *
  1186. * Perform REQUEST_SENSE_DATA_EXT after the device reported CHECK
  1187. * SENSE. This function is an EH helper.
  1188. *
  1189. * LOCKING:
  1190. * Kernel thread context (may sleep).
  1191. */
  1192. static void ata_eh_request_sense(struct ata_queued_cmd *qc,
  1193. struct scsi_cmnd *cmd)
  1194. {
  1195. struct ata_device *dev = qc->dev;
  1196. struct ata_taskfile tf;
  1197. unsigned int err_mask;
  1198. if (qc->ap->pflags & ATA_PFLAG_FROZEN) {
  1199. ata_dev_warn(dev, "sense data available but port frozen\n");
  1200. return;
  1201. }
  1202. if (!cmd || qc->flags & ATA_QCFLAG_SENSE_VALID)
  1203. return;
  1204. if (!ata_id_sense_reporting_enabled(dev->id)) {
  1205. ata_dev_warn(qc->dev, "sense data reporting disabled\n");
  1206. return;
  1207. }
  1208. DPRINTK("ATA request sense\n");
  1209. ata_tf_init(dev, &tf);
  1210. tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
  1211. tf.flags |= ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
  1212. tf.command = ATA_CMD_REQ_SENSE_DATA;
  1213. tf.protocol = ATA_PROT_NODATA;
  1214. err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0);
  1215. /* Ignore err_mask; ATA_ERR might be set */
  1216. if (tf.command & ATA_SENSE) {
  1217. ata_scsi_set_sense(dev, cmd, tf.lbah, tf.lbam, tf.lbal);
  1218. qc->flags |= ATA_QCFLAG_SENSE_VALID;
  1219. } else {
  1220. ata_dev_warn(dev, "request sense failed stat %02x emask %x\n",
  1221. tf.command, err_mask);
  1222. }
  1223. }
  1224. /**
  1225. * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE
  1226. * @dev: device to perform REQUEST_SENSE to
  1227. * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long)
  1228. * @dfl_sense_key: default sense key to use
  1229. *
  1230. * Perform ATAPI REQUEST_SENSE after the device reported CHECK
  1231. * SENSE. This function is EH helper.
  1232. *
  1233. * LOCKING:
  1234. * Kernel thread context (may sleep).
  1235. *
  1236. * RETURNS:
  1237. * 0 on success, AC_ERR_* mask on failure
  1238. */
  1239. unsigned int atapi_eh_request_sense(struct ata_device *dev,
  1240. u8 *sense_buf, u8 dfl_sense_key)
  1241. {
  1242. u8 cdb[ATAPI_CDB_LEN] =
  1243. { REQUEST_SENSE, 0, 0, 0, SCSI_SENSE_BUFFERSIZE, 0 };
  1244. struct ata_port *ap = dev->link->ap;
  1245. struct ata_taskfile tf;
  1246. DPRINTK("ATAPI request sense\n");
  1247. memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
  1248. /* initialize sense_buf with the error register,
  1249. * for the case where they are -not- overwritten
  1250. */
  1251. sense_buf[0] = 0x70;
  1252. sense_buf[2] = dfl_sense_key;
  1253. /* some devices time out if garbage left in tf */
  1254. ata_tf_init(dev, &tf);
  1255. tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
  1256. tf.command = ATA_CMD_PACKET;
  1257. /* is it pointless to prefer PIO for "safety reasons"? */
  1258. if (ap->flags & ATA_FLAG_PIO_DMA) {
  1259. tf.protocol = ATAPI_PROT_DMA;
  1260. tf.feature |= ATAPI_PKT_DMA;
  1261. } else {
  1262. tf.protocol = ATAPI_PROT_PIO;
  1263. tf.lbam = SCSI_SENSE_BUFFERSIZE;
  1264. tf.lbah = 0;
  1265. }
  1266. return ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE,
  1267. sense_buf, SCSI_SENSE_BUFFERSIZE, 0);
  1268. }
  1269. /**
  1270. * ata_eh_analyze_serror - analyze SError for a failed port
  1271. * @link: ATA link to analyze SError for
  1272. *
  1273. * Analyze SError if available and further determine cause of
  1274. * failure.
  1275. *
  1276. * LOCKING:
  1277. * None.
  1278. */
  1279. static void ata_eh_analyze_serror(struct ata_link *link)
  1280. {
  1281. struct ata_eh_context *ehc = &link->eh_context;
  1282. u32 serror = ehc->i.serror;
  1283. unsigned int err_mask = 0, action = 0;
  1284. u32 hotplug_mask;
  1285. if (serror & (SERR_PERSISTENT | SERR_DATA)) {
  1286. err_mask |= AC_ERR_ATA_BUS;
  1287. action |= ATA_EH_RESET;
  1288. }
  1289. if (serror & SERR_PROTOCOL) {
  1290. err_mask |= AC_ERR_HSM;
  1291. action |= ATA_EH_RESET;
  1292. }
  1293. if (serror & SERR_INTERNAL) {
  1294. err_mask |= AC_ERR_SYSTEM;
  1295. action |= ATA_EH_RESET;
  1296. }
  1297. /* Determine whether a hotplug event has occurred. Both
  1298. * SError.N/X are considered hotplug events for enabled or
  1299. * host links. For disabled PMP links, only N bit is
  1300. * considered as X bit is left at 1 for link plugging.
  1301. */
  1302. if (link->lpm_policy > ATA_LPM_MAX_POWER)
  1303. hotplug_mask = 0; /* hotplug doesn't work w/ LPM */
  1304. else if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link))
  1305. hotplug_mask = SERR_PHYRDY_CHG | SERR_DEV_XCHG;
  1306. else
  1307. hotplug_mask = SERR_PHYRDY_CHG;
  1308. if (serror & hotplug_mask)
  1309. ata_ehi_hotplugged(&ehc->i);
  1310. ehc->i.err_mask |= err_mask;
  1311. ehc->i.action |= action;
  1312. }
  1313. /**
  1314. * ata_eh_analyze_tf - analyze taskfile of a failed qc
  1315. * @qc: qc to analyze
  1316. * @tf: Taskfile registers to analyze
  1317. *
  1318. * Analyze taskfile of @qc and further determine cause of
  1319. * failure. This function also requests ATAPI sense data if
  1320. * available.
  1321. *
  1322. * LOCKING:
  1323. * Kernel thread context (may sleep).
  1324. *
  1325. * RETURNS:
  1326. * Determined recovery action
  1327. */
  1328. static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
  1329. const struct ata_taskfile *tf)
  1330. {
  1331. unsigned int tmp, action = 0;
  1332. u8 stat = tf->command, err = tf->feature;
  1333. if ((stat & (ATA_BUSY | ATA_DRQ | ATA_DRDY)) != ATA_DRDY) {
  1334. qc->err_mask |= AC_ERR_HSM;
  1335. return ATA_EH_RESET;
  1336. }
  1337. if (stat & (ATA_ERR | ATA_DF)) {
  1338. qc->err_mask |= AC_ERR_DEV;
  1339. /*
  1340. * Sense data reporting does not work if the
  1341. * device fault bit is set.
  1342. */
  1343. if (stat & ATA_DF)
  1344. stat &= ~ATA_SENSE;
  1345. } else {
  1346. return 0;
  1347. }
  1348. switch (qc->dev->class) {
  1349. case ATA_DEV_ZAC:
  1350. if (stat & ATA_SENSE)
  1351. ata_eh_request_sense(qc, qc->scsicmd);
  1352. /* fall through */
  1353. case ATA_DEV_ATA:
  1354. if (err & ATA_ICRC)
  1355. qc->err_mask |= AC_ERR_ATA_BUS;
  1356. if (err & (ATA_UNC | ATA_AMNF))
  1357. qc->err_mask |= AC_ERR_MEDIA;
  1358. if (err & ATA_IDNF)
  1359. qc->err_mask |= AC_ERR_INVALID;
  1360. break;
  1361. case ATA_DEV_ATAPI:
  1362. if (!(qc->ap->pflags & ATA_PFLAG_FROZEN)) {
  1363. tmp = atapi_eh_request_sense(qc->dev,
  1364. qc->scsicmd->sense_buffer,
  1365. qc->result_tf.feature >> 4);
  1366. if (!tmp)
  1367. qc->flags |= ATA_QCFLAG_SENSE_VALID;
  1368. else
  1369. qc->err_mask |= tmp;
  1370. }
  1371. }
  1372. if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
  1373. int ret = scsi_check_sense(qc->scsicmd);
  1374. /*
  1375. * SUCCESS here means that the sense code could be
  1376. * evaluated and should be passed to the upper layers
  1377. * for correct evaluation.
  1378. * FAILED means the sense code could not be interpreted
  1379. * and the device would need to be reset.
  1380. * NEEDS_RETRY and ADD_TO_MLQUEUE means that the
  1381. * command would need to be retried.
  1382. */
  1383. if (ret == NEEDS_RETRY || ret == ADD_TO_MLQUEUE) {
  1384. qc->flags |= ATA_QCFLAG_RETRY;
  1385. qc->err_mask |= AC_ERR_OTHER;
  1386. } else if (ret != SUCCESS) {
  1387. qc->err_mask |= AC_ERR_HSM;
  1388. }
  1389. }
  1390. if (qc->err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT | AC_ERR_ATA_BUS))
  1391. action |= ATA_EH_RESET;
  1392. return action;
  1393. }
  1394. static int ata_eh_categorize_error(unsigned int eflags, unsigned int err_mask,
  1395. int *xfer_ok)
  1396. {
  1397. int base = 0;
  1398. if (!(eflags & ATA_EFLAG_DUBIOUS_XFER))
  1399. *xfer_ok = 1;
  1400. if (!*xfer_ok)
  1401. base = ATA_ECAT_DUBIOUS_NONE;
  1402. if (err_mask & AC_ERR_ATA_BUS)
  1403. return base + ATA_ECAT_ATA_BUS;
  1404. if (err_mask & AC_ERR_TIMEOUT)
  1405. return base + ATA_ECAT_TOUT_HSM;
  1406. if (eflags & ATA_EFLAG_IS_IO) {
  1407. if (err_mask & AC_ERR_HSM)
  1408. return base + ATA_ECAT_TOUT_HSM;
  1409. if ((err_mask &
  1410. (AC_ERR_DEV|AC_ERR_MEDIA|AC_ERR_INVALID)) == AC_ERR_DEV)
  1411. return base + ATA_ECAT_UNK_DEV;
  1412. }
  1413. return 0;
  1414. }
  1415. struct speed_down_verdict_arg {
  1416. u64 since;
  1417. int xfer_ok;
  1418. int nr_errors[ATA_ECAT_NR];
  1419. };
  1420. static int speed_down_verdict_cb(struct ata_ering_entry *ent, void *void_arg)
  1421. {
  1422. struct speed_down_verdict_arg *arg = void_arg;
  1423. int cat;
  1424. if ((ent->eflags & ATA_EFLAG_OLD_ER) || (ent->timestamp < arg->since))
  1425. return -1;
  1426. cat = ata_eh_categorize_error(ent->eflags, ent->err_mask,
  1427. &arg->xfer_ok);
  1428. arg->nr_errors[cat]++;
  1429. return 0;
  1430. }
  1431. /**
  1432. * ata_eh_speed_down_verdict - Determine speed down verdict
  1433. * @dev: Device of interest
  1434. *
  1435. * This function examines error ring of @dev and determines
  1436. * whether NCQ needs to be turned off, transfer speed should be
  1437. * stepped down, or falling back to PIO is necessary.
  1438. *
  1439. * ECAT_ATA_BUS : ATA_BUS error for any command
  1440. *
  1441. * ECAT_TOUT_HSM : TIMEOUT for any command or HSM violation for
  1442. * IO commands
  1443. *
  1444. * ECAT_UNK_DEV : Unknown DEV error for IO commands
  1445. *
  1446. * ECAT_DUBIOUS_* : Identical to above three but occurred while
  1447. * data transfer hasn't been verified.
  1448. *
  1449. * Verdicts are
  1450. *
  1451. * NCQ_OFF : Turn off NCQ.
  1452. *
  1453. * SPEED_DOWN : Speed down transfer speed but don't fall back
  1454. * to PIO.
  1455. *
  1456. * FALLBACK_TO_PIO : Fall back to PIO.
  1457. *
  1458. * Even if multiple verdicts are returned, only one action is
  1459. * taken per error. An action triggered by non-DUBIOUS errors
  1460. * clears ering, while one triggered by DUBIOUS_* errors doesn't.
  1461. * This is to expedite speed down decisions right after device is
  1462. * initially configured.
  1463. *
  1464. * The following are speed down rules. #1 and #2 deal with
  1465. * DUBIOUS errors.
  1466. *
  1467. * 1. If more than one DUBIOUS_ATA_BUS or DUBIOUS_TOUT_HSM errors
  1468. * occurred during last 5 mins, SPEED_DOWN and FALLBACK_TO_PIO.
  1469. *
  1470. * 2. If more than one DUBIOUS_TOUT_HSM or DUBIOUS_UNK_DEV errors
  1471. * occurred during last 5 mins, NCQ_OFF.
  1472. *
  1473. * 3. If more than 8 ATA_BUS, TOUT_HSM or UNK_DEV errors
  1474. * occurred during last 5 mins, FALLBACK_TO_PIO
  1475. *
  1476. * 4. If more than 3 TOUT_HSM or UNK_DEV errors occurred
  1477. * during last 10 mins, NCQ_OFF.
  1478. *
  1479. * 5. If more than 3 ATA_BUS or TOUT_HSM errors, or more than 6
  1480. * UNK_DEV errors occurred during last 10 mins, SPEED_DOWN.
  1481. *
  1482. * LOCKING:
  1483. * Inherited from caller.
  1484. *
  1485. * RETURNS:
  1486. * OR of ATA_EH_SPDN_* flags.
  1487. */
  1488. static unsigned int ata_eh_speed_down_verdict(struct ata_device *dev)
  1489. {
  1490. const u64 j5mins = 5LLU * 60 * HZ, j10mins = 10LLU * 60 * HZ;
  1491. u64 j64 = get_jiffies_64();
  1492. struct speed_down_verdict_arg arg;
  1493. unsigned int verdict = 0;
  1494. /* scan past 5 mins of error history */
  1495. memset(&arg, 0, sizeof(arg));
  1496. arg.since = j64 - min(j64, j5mins);
  1497. ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg);
  1498. if (arg.nr_errors[ATA_ECAT_DUBIOUS_ATA_BUS] +
  1499. arg.nr_errors[ATA_ECAT_DUBIOUS_TOUT_HSM] > 1)
  1500. verdict |= ATA_EH_SPDN_SPEED_DOWN |
  1501. ATA_EH_SPDN_FALLBACK_TO_PIO | ATA_EH_SPDN_KEEP_ERRORS;
  1502. if (arg.nr_errors[ATA_ECAT_DUBIOUS_TOUT_HSM] +
  1503. arg.nr_errors[ATA_ECAT_DUBIOUS_UNK_DEV] > 1)
  1504. verdict |= ATA_EH_SPDN_NCQ_OFF | ATA_EH_SPDN_KEEP_ERRORS;
  1505. if (arg.nr_errors[ATA_ECAT_ATA_BUS] +
  1506. arg.nr_errors[ATA_ECAT_TOUT_HSM] +
  1507. arg.nr_errors[ATA_ECAT_UNK_DEV] > 6)
  1508. verdict |= ATA_EH_SPDN_FALLBACK_TO_PIO;
  1509. /* scan past 10 mins of error history */
  1510. memset(&arg, 0, sizeof(arg));
  1511. arg.since = j64 - min(j64, j10mins);
  1512. ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg);
  1513. if (arg.nr_errors[ATA_ECAT_TOUT_HSM] +
  1514. arg.nr_errors[ATA_ECAT_UNK_DEV] > 3)
  1515. verdict |= ATA_EH_SPDN_NCQ_OFF;
  1516. if (arg.nr_errors[ATA_ECAT_ATA_BUS] +
  1517. arg.nr_errors[ATA_ECAT_TOUT_HSM] > 3 ||
  1518. arg.nr_errors[ATA_ECAT_UNK_DEV] > 6)
  1519. verdict |= ATA_EH_SPDN_SPEED_DOWN;
  1520. return verdict;
  1521. }
  1522. /**
  1523. * ata_eh_speed_down - record error and speed down if necessary
  1524. * @dev: Failed device
  1525. * @eflags: mask of ATA_EFLAG_* flags
  1526. * @err_mask: err_mask of the error
  1527. *
  1528. * Record error and examine error history to determine whether
  1529. * adjusting transmission speed is necessary. It also sets
  1530. * transmission limits appropriately if such adjustment is
  1531. * necessary.
  1532. *
  1533. * LOCKING:
  1534. * Kernel thread context (may sleep).
  1535. *
  1536. * RETURNS:
  1537. * Determined recovery action.
  1538. */
  1539. static unsigned int ata_eh_speed_down(struct ata_device *dev,
  1540. unsigned int eflags, unsigned int err_mask)
  1541. {
  1542. struct ata_link *link = ata_dev_phys_link(dev);
  1543. int xfer_ok = 0;
  1544. unsigned int verdict;
  1545. unsigned int action = 0;
  1546. /* don't bother if Cat-0 error */
  1547. if (ata_eh_categorize_error(eflags, err_mask, &xfer_ok) == 0)
  1548. return 0;
  1549. /* record error and determine whether speed down is necessary */
  1550. ata_ering_record(&dev->ering, eflags, err_mask);
  1551. verdict = ata_eh_speed_down_verdict(dev);
  1552. /* turn off NCQ? */
  1553. if ((verdict & ATA_EH_SPDN_NCQ_OFF) &&
  1554. (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ |
  1555. ATA_DFLAG_NCQ_OFF)) == ATA_DFLAG_NCQ) {
  1556. dev->flags |= ATA_DFLAG_NCQ_OFF;
  1557. ata_dev_warn(dev, "NCQ disabled due to excessive errors\n");
  1558. goto done;
  1559. }
  1560. /* speed down? */
  1561. if (verdict & ATA_EH_SPDN_SPEED_DOWN) {
  1562. /* speed down SATA link speed if possible */
  1563. if (sata_down_spd_limit(link, 0) == 0) {
  1564. action |= ATA_EH_RESET;
  1565. goto done;
  1566. }
  1567. /* lower transfer mode */
  1568. if (dev->spdn_cnt < 2) {
  1569. static const int dma_dnxfer_sel[] =
  1570. { ATA_DNXFER_DMA, ATA_DNXFER_40C };
  1571. static const int pio_dnxfer_sel[] =
  1572. { ATA_DNXFER_PIO, ATA_DNXFER_FORCE_PIO0 };
  1573. int sel;
  1574. if (dev->xfer_shift != ATA_SHIFT_PIO)
  1575. sel = dma_dnxfer_sel[dev->spdn_cnt];
  1576. else
  1577. sel = pio_dnxfer_sel[dev->spdn_cnt];
  1578. dev->spdn_cnt++;
  1579. if (ata_down_xfermask_limit(dev, sel) == 0) {
  1580. action |= ATA_EH_RESET;
  1581. goto done;
  1582. }
  1583. }
  1584. }
  1585. /* Fall back to PIO? Slowing down to PIO is meaningless for
  1586. * SATA ATA devices. Consider it only for PATA and SATAPI.
  1587. */
  1588. if ((verdict & ATA_EH_SPDN_FALLBACK_TO_PIO) && (dev->spdn_cnt >= 2) &&
  1589. (link->ap->cbl != ATA_CBL_SATA || dev->class == ATA_DEV_ATAPI) &&
  1590. (dev->xfer_shift != ATA_SHIFT_PIO)) {
  1591. if (ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO) == 0) {
  1592. dev->spdn_cnt = 0;
  1593. action |= ATA_EH_RESET;
  1594. goto done;
  1595. }
  1596. }
  1597. return 0;
  1598. done:
  1599. /* device has been slowed down, blow error history */
  1600. if (!(verdict & ATA_EH_SPDN_KEEP_ERRORS))
  1601. ata_ering_clear(&dev->ering);
  1602. return action;
  1603. }
  1604. /**
  1605. * ata_eh_worth_retry - analyze error and decide whether to retry
  1606. * @qc: qc to possibly retry
  1607. *
  1608. * Look at the cause of the error and decide if a retry
  1609. * might be useful or not. We don't want to retry media errors
  1610. * because the drive itself has probably already taken 10-30 seconds
  1611. * doing its own internal retries before reporting the failure.
  1612. */
  1613. static inline int ata_eh_worth_retry(struct ata_queued_cmd *qc)
  1614. {
  1615. if (qc->err_mask & AC_ERR_MEDIA)
  1616. return 0; /* don't retry media errors */
  1617. if (qc->flags & ATA_QCFLAG_IO)
  1618. return 1; /* otherwise retry anything from fs stack */
  1619. if (qc->err_mask & AC_ERR_INVALID)
  1620. return 0; /* don't retry these */
  1621. return qc->err_mask != AC_ERR_DEV; /* retry if not dev error */
  1622. }
  1623. /**
  1624. * ata_eh_quiet - check if we need to be quiet about a command error
  1625. * @qc: qc to check
  1626. *
  1627. * Look at the qc flags anbd its scsi command request flags to determine
  1628. * if we need to be quiet about the command failure.
  1629. */
  1630. static inline bool ata_eh_quiet(struct ata_queued_cmd *qc)
  1631. {
  1632. if (qc->scsicmd &&
  1633. qc->scsicmd->request->rq_flags & RQF_QUIET)
  1634. qc->flags |= ATA_QCFLAG_QUIET;
  1635. return qc->flags & ATA_QCFLAG_QUIET;
  1636. }
  1637. /**
  1638. * ata_eh_link_autopsy - analyze error and determine recovery action
  1639. * @link: host link to perform autopsy on
  1640. *
  1641. * Analyze why @link failed and determine which recovery actions
  1642. * are needed. This function also sets more detailed AC_ERR_*
  1643. * values and fills sense data for ATAPI CHECK SENSE.
  1644. *
  1645. * LOCKING:
  1646. * Kernel thread context (may sleep).
  1647. */
  1648. static void ata_eh_link_autopsy(struct ata_link *link)
  1649. {
  1650. struct ata_port *ap = link->ap;
  1651. struct ata_eh_context *ehc = &link->eh_context;
  1652. struct ata_queued_cmd *qc;
  1653. struct ata_device *dev;
  1654. unsigned int all_err_mask = 0, eflags = 0;