libata-eh.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907
  1. /*
  2. * libata-eh.c - libata error handling
  3. *
  4. * Maintained by: Jeff Garzik <jgarzik@pobox.com>
  5. * Please ALWAYS copy linux-ide@vger.kernel.org
  6. * on emails.
  7. *
  8. * Copyright 2006 Tejun Heo <htejun@gmail.com>
  9. *
  10. *
  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.
  15. *
  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.
  20. *
  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,
  24. * USA.
  25. *
  26. *
  27. * libata documentation is available via 'make {ps|pdf}docs',
  28. * as Documentation/DocBook/libata.*
  29. *
  30. * Hardware documentation available from http://www.t13.org/ and
  31. * http://www.sata-io.org/
  32. *
  33. */
  34. #include <linux/config.h>
  35. #include <linux/kernel.h>
  36. #include <scsi/scsi.h>
  37. #include <scsi/scsi_host.h>
  38. #include <scsi/scsi_eh.h>
  39. #include <scsi/scsi_device.h>
  40. #include <scsi/scsi_cmnd.h>
  41. #include "scsi_transport_api.h"
  42. #include <linux/libata.h>
  43. #include "libata.h"
  44. static void __ata_port_freeze(struct ata_port *ap);
  45. static void ata_eh_finish(struct ata_port *ap);
  46. static void ata_ering_record(struct ata_ering *ering, int is_io,
  47. unsigned int err_mask)
  48. {
  49. struct ata_ering_entry *ent;
  50. WARN_ON(!err_mask);
  51. ering->cursor++;
  52. ering->cursor %= ATA_ERING_SIZE;
  53. ent = &ering->ring[ering->cursor];
  54. ent->is_io = is_io;
  55. ent->err_mask = err_mask;
  56. ent->timestamp = get_jiffies_64();
  57. }
  58. static struct ata_ering_entry * ata_ering_top(struct ata_ering *ering)
  59. {
  60. struct ata_ering_entry *ent = &ering->ring[ering->cursor];
  61. if (!ent->err_mask)
  62. return NULL;
  63. return ent;
  64. }
  65. static int ata_ering_map(struct ata_ering *ering,
  66. int (*map_fn)(struct ata_ering_entry *, void *),
  67. void *arg)
  68. {
  69. int idx, rc = 0;
  70. struct ata_ering_entry *ent;
  71. idx = ering->cursor;
  72. do {
  73. ent = &ering->ring[idx];
  74. if (!ent->err_mask)
  75. break;
  76. rc = map_fn(ent, arg);
  77. if (rc)
  78. break;
  79. idx = (idx - 1 + ATA_ERING_SIZE) % ATA_ERING_SIZE;
  80. } while (idx != ering->cursor);
  81. return rc;
  82. }
  83. static void ata_eh_clear_action(struct ata_device *dev,
  84. struct ata_eh_info *ehi, unsigned int action)
  85. {
  86. int i;
  87. if (!dev) {
  88. ehi->action &= ~action;
  89. for (i = 0; i < ATA_MAX_DEVICES; i++)
  90. ehi->dev_action[i] &= ~action;
  91. } else {
  92. /* doesn't make sense for port-wide EH actions */
  93. WARN_ON(!(action & ATA_EH_PERDEV_MASK));
  94. /* break ehi->action into ehi->dev_action */
  95. if (ehi->action & action) {
  96. for (i = 0; i < ATA_MAX_DEVICES; i++)
  97. ehi->dev_action[i] |= ehi->action & action;
  98. ehi->action &= ~action;
  99. }
  100. /* turn off the specified per-dev action */
  101. ehi->dev_action[dev->devno] &= ~action;
  102. }
  103. }
  104. /**
  105. * ata_scsi_timed_out - SCSI layer time out callback
  106. * @cmd: timed out SCSI command
  107. *
  108. * Handles SCSI layer timeout. We race with normal completion of
  109. * the qc for @cmd. If the qc is already gone, we lose and let
  110. * the scsi command finish (EH_HANDLED). Otherwise, the qc has
  111. * timed out and EH should be invoked. Prevent ata_qc_complete()
  112. * from finishing it by setting EH_SCHEDULED and return
  113. * EH_NOT_HANDLED.
  114. *
  115. * TODO: kill this function once old EH is gone.
  116. *
  117. * LOCKING:
  118. * Called from timer context
  119. *
  120. * RETURNS:
  121. * EH_HANDLED or EH_NOT_HANDLED
  122. */
  123. enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
  124. {
  125. struct Scsi_Host *host = cmd->device->host;
  126. struct ata_port *ap = ata_shost_to_port(host);
  127. unsigned long flags;
  128. struct ata_queued_cmd *qc;
  129. enum scsi_eh_timer_return ret;
  130. DPRINTK("ENTER\n");
  131. if (ap->ops->error_handler) {
  132. ret = EH_NOT_HANDLED;
  133. goto out;
  134. }
  135. ret = EH_HANDLED;
  136. spin_lock_irqsave(ap->lock, flags);
  137. qc = ata_qc_from_tag(ap, ap->active_tag);
  138. if (qc) {
  139. WARN_ON(qc->scsicmd != cmd);
  140. qc->flags |= ATA_QCFLAG_EH_SCHEDULED;
  141. qc->err_mask |= AC_ERR_TIMEOUT;
  142. ret = EH_NOT_HANDLED;
  143. }
  144. spin_unlock_irqrestore(ap->lock, flags);
  145. out:
  146. DPRINTK("EXIT, ret=%d\n", ret);
  147. return ret;
  148. }
  149. /**
  150. * ata_scsi_error - SCSI layer error handler callback
  151. * @host: SCSI host on which error occurred
  152. *
  153. * Handles SCSI-layer-thrown error events.
  154. *
  155. * LOCKING:
  156. * Inherited from SCSI layer (none, can sleep)
  157. *
  158. * RETURNS:
  159. * Zero.
  160. */
  161. void ata_scsi_error(struct Scsi_Host *host)
  162. {
  163. struct ata_port *ap = ata_shost_to_port(host);
  164. spinlock_t *ap_lock = ap->lock;
  165. int i, repeat_cnt = ATA_EH_MAX_REPEAT;
  166. unsigned long flags;
  167. DPRINTK("ENTER\n");
  168. /* synchronize with port task */
  169. ata_port_flush_task(ap);
  170. /* 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.
  176. *
  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.
  182. */
  183. if (ap->ops->error_handler) {
  184. struct scsi_cmnd *scmd, *tmp;
  185. int nr_timedout = 0;
  186. spin_lock_irqsave(ap_lock, flags);
  187. list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) {
  188. struct ata_queued_cmd *qc;
  189. for (i = 0; i < ATA_MAX_QUEUE; i++) {
  190. qc = __ata_qc_from_tag(ap, i);
  191. if (qc->flags & ATA_QCFLAG_ACTIVE &&
  192. qc->scsicmd == scmd)
  193. break;
  194. }
  195. if (i < ATA_MAX_QUEUE) {
  196. /* the scmd has an associated qc */
  197. if (!(qc->flags & ATA_QCFLAG_FAILED)) {
  198. /* which hasn't failed yet, timeout */
  199. qc->err_mask |= AC_ERR_TIMEOUT;
  200. qc->flags |= ATA_QCFLAG_FAILED;
  201. nr_timedout++;
  202. }
  203. } else {
  204. /* Normal completion occurred after
  205. * SCSI timeout but before this point.
  206. * Successfully complete it.
  207. */
  208. scmd->retries = scmd->allowed;
  209. scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
  210. }
  211. }
  212. /* If we have timed out qcs. They belong to EH from
  213. * this point but the state of the controller is
  214. * unknown. Freeze the port to make sure the IRQ
  215. * handler doesn't diddle with those qcs. This must
  216. * be done atomically w.r.t. setting QCFLAG_FAILED.
  217. */
  218. if (nr_timedout)
  219. __ata_port_freeze(ap);
  220. spin_unlock_irqrestore(ap_lock, flags);
  221. } else
  222. spin_unlock_wait(ap_lock);
  223. repeat:
  224. /* invoke error handler */
  225. if (ap->ops->error_handler) {
  226. /* fetch & clear EH info */
  227. spin_lock_irqsave(ap_lock, flags);
  228. memset(&ap->eh_context, 0, sizeof(ap->eh_context));
  229. ap->eh_context.i = ap->eh_info;
  230. memset(&ap->eh_info, 0, sizeof(ap->eh_info));
  231. ap->flags |= ATA_FLAG_EH_IN_PROGRESS;
  232. ap->flags &= ~ATA_FLAG_EH_PENDING;
  233. spin_unlock_irqrestore(ap_lock, flags);
  234. /* invoke EH. if unloading, just finish failed qcs */
  235. if (!(ap->flags & ATA_FLAG_UNLOADING))
  236. ap->ops->error_handler(ap);
  237. else
  238. ata_eh_finish(ap);
  239. /* Exception might have happend after ->error_handler
  240. * recovered the port but before this point. Repeat
  241. * EH in such case.
  242. */
  243. spin_lock_irqsave(ap_lock, flags);
  244. if (ap->flags & ATA_FLAG_EH_PENDING) {
  245. if (--repeat_cnt) {
  246. ata_port_printk(ap, KERN_INFO,
  247. "EH pending after completion, "
  248. "repeating EH (cnt=%d)\n", repeat_cnt);
  249. spin_unlock_irqrestore(ap_lock, flags);
  250. goto repeat;
  251. }
  252. ata_port_printk(ap, KERN_ERR, "EH pending after %d "
  253. "tries, giving up\n", ATA_EH_MAX_REPEAT);
  254. }
  255. /* this run is complete, make sure EH info is clear */
  256. memset(&ap->eh_info, 0, sizeof(ap->eh_info));
  257. /* Clear host_eh_scheduled while holding ap_lock such
  258. * that if exception occurs after this point but
  259. * before EH completion, SCSI midlayer will
  260. * re-initiate EH.
  261. */
  262. host->host_eh_scheduled = 0;
  263. spin_unlock_irqrestore(ap_lock, flags);
  264. } else {
  265. WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL);
  266. ap->ops->eng_timeout(ap);
  267. }
  268. /* finish or retry handled scmd's and clean up */
  269. WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q));
  270. scsi_eh_flush_done_q(&ap->eh_done_q);
  271. /* clean up */
  272. spin_lock_irqsave(ap_lock, flags);
  273. if (ap->flags & ATA_FLAG_LOADING) {
  274. ap->flags &= ~ATA_FLAG_LOADING;
  275. } else {
  276. if (ap->flags & ATA_FLAG_SCSI_HOTPLUG)
  277. queue_work(ata_aux_wq, &ap->hotplug_task);
  278. if (ap->flags & ATA_FLAG_RECOVERED)
  279. ata_port_printk(ap, KERN_INFO, "EH complete\n");
  280. }
  281. ap->flags &= ~(ATA_FLAG_SCSI_HOTPLUG | ATA_FLAG_RECOVERED);
  282. /* tell wait_eh that we're done */
  283. ap->flags &= ~ATA_FLAG_EH_IN_PROGRESS;
  284. wake_up_all(&ap->eh_wait_q);
  285. spin_unlock_irqrestore(ap_lock, flags);
  286. DPRINTK("EXIT\n");
  287. }
  288. /**
  289. * ata_port_wait_eh - Wait for the currently pending EH to complete
  290. * @ap: Port to wait EH for
  291. *
  292. * Wait until the currently pending EH is complete.
  293. *
  294. * LOCKING:
  295. * Kernel thread context (may sleep).
  296. */
  297. void ata_port_wait_eh(struct ata_port *ap)
  298. {
  299. unsigned long flags;
  300. DEFINE_WAIT(wait);
  301. retry:
  302. spin_lock_irqsave(ap->lock, flags);
  303. while (ap->flags & (ATA_FLAG_EH_PENDING | ATA_FLAG_EH_IN_PROGRESS)) {
  304. prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE);
  305. spin_unlock_irqrestore(ap->lock, flags);
  306. schedule();
  307. spin_lock_irqsave(ap->lock, flags);
  308. }
  309. finish_wait(&ap->eh_wait_q, &wait);
  310. spin_unlock_irqrestore(ap->lock, flags);
  311. /* make sure SCSI EH is complete */
  312. if (scsi_host_in_recovery(ap->host)) {
  313. msleep(10);
  314. goto retry;
  315. }
  316. }
  317. /**
  318. * ata_qc_timeout - Handle timeout of queued command
  319. * @qc: Command that timed out
  320. *
  321. * Some part of the kernel (currently, only the SCSI layer)
  322. * has noticed that the active command on port @ap has not
  323. * completed after a specified length of time. Handle this
  324. * condition by disabling DMA (if necessary) and completing
  325. * transactions, with error if necessary.
  326. *
  327. * This also handles the case of the "lost interrupt", where
  328. * for some reason (possibly hardware bug, possibly driver bug)
  329. * an interrupt was not delivered to the driver, even though the
  330. * transaction completed successfully.
  331. *
  332. * TODO: kill this function once old EH is gone.
  333. *
  334. * LOCKING:
  335. * Inherited from SCSI layer (none, can sleep)
  336. */
  337. static void ata_qc_timeout(struct ata_queued_cmd *qc)
  338. {
  339. struct ata_port *ap = qc->ap;
  340. u8 host_stat = 0, drv_stat;
  341. unsigned long flags;
  342. DPRINTK("ENTER\n");
  343. ap->hsm_task_state = HSM_ST_IDLE;
  344. spin_lock_irqsave(ap->lock, flags);
  345. switch (qc->tf.protocol) {
  346. case ATA_PROT_DMA:
  347. case ATA_PROT_ATAPI_DMA:
  348. host_stat = ap->ops->bmdma_status(ap);
  349. /* before we do anything else, clear DMA-Start bit */
  350. ap->ops->bmdma_stop(qc);
  351. /* fall through */
  352. default:
  353. ata_altstatus(ap);
  354. drv_stat = ata_chk_status(ap);
  355. /* ack bmdma irq events */
  356. ap->ops->irq_clear(ap);
  357. ata_dev_printk(qc->dev, KERN_ERR, "command 0x%x timeout, "
  358. "stat 0x%x host_stat 0x%x\n",
  359. qc->tf.command, drv_stat, host_stat);
  360. /* complete taskfile transaction */
  361. qc->err_mask |= AC_ERR_TIMEOUT;
  362. break;
  363. }
  364. spin_unlock_irqrestore(ap->lock, flags);
  365. ata_eh_qc_complete(qc);
  366. DPRINTK("EXIT\n");
  367. }
  368. /**
  369. * ata_eng_timeout - Handle timeout of queued command
  370. * @ap: Port on which timed-out command is active
  371. *
  372. * Some part of the kernel (currently, only the SCSI layer)
  373. * has noticed that the active command on port @ap has not
  374. * completed after a specified length of time. Handle this
  375. * condition by disabling DMA (if necessary) and completing
  376. * transactions, with error if necessary.
  377. *
  378. * This also handles the case of the "lost interrupt", where
  379. * for some reason (possibly hardware bug, possibly driver bug)
  380. * an interrupt was not delivered to the driver, even though the
  381. * transaction completed successfully.
  382. *
  383. * TODO: kill this function once old EH is gone.
  384. *
  385. * LOCKING:
  386. * Inherited from SCSI layer (none, can sleep)
  387. */
  388. void ata_eng_timeout(struct ata_port *ap)
  389. {
  390. DPRINTK("ENTER\n");
  391. ata_qc_timeout(ata_qc_from_tag(ap, ap->active_tag));
  392. DPRINTK("EXIT\n");
  393. }
  394. /**
  395. * ata_qc_schedule_eh - schedule qc for error handling
  396. * @qc: command to schedule error handling for
  397. *
  398. * Schedule error handling for @qc. EH will kick in as soon as
  399. * other commands are drained.
  400. *
  401. * LOCKING:
  402. * spin_lock_irqsave(host_set lock)
  403. */
  404. void ata_qc_schedule_eh(struct ata_queued_cmd *qc)
  405. {
  406. struct ata_port *ap = qc->ap;
  407. WARN_ON(!ap->ops->error_handler);
  408. qc->flags |= ATA_QCFLAG_FAILED;
  409. qc->ap->flags |= ATA_FLAG_EH_PENDING;
  410. /* The following will fail if timeout has already expired.
  411. * ata_scsi_error() takes care of such scmds on EH entry.
  412. * Note that ATA_QCFLAG_FAILED is unconditionally set after
  413. * this function completes.
  414. */
  415. scsi_req_abort_cmd(qc->scsicmd);
  416. }
  417. /**
  418. * ata_port_schedule_eh - schedule error handling without a qc
  419. * @ap: ATA port to schedule EH for
  420. *
  421. * Schedule error handling for @ap. EH will kick in as soon as
  422. * all commands are drained.
  423. *
  424. * LOCKING:
  425. * spin_lock_irqsave(host_set lock)
  426. */
  427. void ata_port_schedule_eh(struct ata_port *ap)
  428. {
  429. WARN_ON(!ap->ops->error_handler);
  430. ap->flags |= ATA_FLAG_EH_PENDING;
  431. scsi_schedule_eh(ap->host);
  432. DPRINTK("port EH scheduled\n");
  433. }
  434. /**
  435. * ata_port_abort - abort all qc's on the port
  436. * @ap: ATA port to abort qc's for
  437. *
  438. * Abort all active qc's of @ap and schedule EH.
  439. *
  440. * LOCKING:
  441. * spin_lock_irqsave(host_set lock)
  442. *
  443. * RETURNS:
  444. * Number of aborted qc's.
  445. */
  446. int ata_port_abort(struct ata_port *ap)
  447. {
  448. int tag, nr_aborted = 0;
  449. WARN_ON(!ap->ops->error_handler);
  450. for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
  451. struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
  452. if (qc) {
  453. qc->flags |= ATA_QCFLAG_FAILED;
  454. ata_qc_complete(qc);
  455. nr_aborted++;
  456. }
  457. }
  458. if (!nr_aborted)
  459. ata_port_schedule_eh(ap);
  460. return nr_aborted;
  461. }
  462. /**
  463. * __ata_port_freeze - freeze port
  464. * @ap: ATA port to freeze
  465. *
  466. * This function is called when HSM violation or some other
  467. * condition disrupts normal operation of the port. Frozen port
  468. * is not allowed to perform any operation until the port is
  469. * thawed, which usually follows a successful reset.
  470. *
  471. * ap->ops->freeze() callback can be used for freezing the port
  472. * hardware-wise (e.g. mask interrupt and stop DMA engine). If a
  473. * port cannot be frozen hardware-wise, the interrupt handler
  474. * must ack and clear interrupts unconditionally while the port
  475. * is frozen.
  476. *
  477. * LOCKING:
  478. * spin_lock_irqsave(host_set lock)
  479. */
  480. static void __ata_port_freeze(struct ata_port *ap)
  481. {
  482. WARN_ON(!ap->ops->error_handler);
  483. if (ap->ops->freeze)
  484. ap->ops->freeze(ap);
  485. ap->flags |= ATA_FLAG_FROZEN;
  486. DPRINTK("ata%u port frozen\n", ap->id);
  487. }
  488. /**
  489. * ata_port_freeze - abort & freeze port
  490. * @ap: ATA port to freeze
  491. *
  492. * Abort and freeze @ap.
  493. *
  494. * LOCKING:
  495. * spin_lock_irqsave(host_set lock)
  496. *
  497. * RETURNS:
  498. * Number of aborted commands.
  499. */
  500. int ata_port_freeze(struct ata_port *ap)
  501. {
  502. int nr_aborted;
  503. WARN_ON(!ap->ops->error_handler);
  504. nr_aborted = ata_port_abort(ap);
  505. __ata_port_freeze(ap);
  506. return nr_aborted;
  507. }
  508. /**
  509. * ata_eh_freeze_port - EH helper to freeze port
  510. * @ap: ATA port to freeze
  511. *
  512. * Freeze @ap.
  513. *
  514. * LOCKING:
  515. * None.
  516. */
  517. void ata_eh_freeze_port(struct ata_port *ap)
  518. {
  519. unsigned long flags;
  520. if (!ap->ops->error_handler)
  521. return;
  522. spin_lock_irqsave(ap->lock, flags);
  523. __ata_port_freeze(ap);
  524. spin_unlock_irqrestore(ap->lock, flags);
  525. }
  526. /**
  527. * ata_port_thaw_port - EH helper to thaw port
  528. * @ap: ATA port to thaw
  529. *
  530. * Thaw frozen port @ap.
  531. *
  532. * LOCKING:
  533. * None.
  534. */
  535. void ata_eh_thaw_port(struct ata_port *ap)
  536. {
  537. unsigned long flags;
  538. if (!ap->ops->error_handler)
  539. return;
  540. spin_lock_irqsave(ap->lock, flags);
  541. ap->flags &= ~ATA_FLAG_FROZEN;
  542. if (ap->ops->thaw)
  543. ap->ops->thaw(ap);
  544. spin_unlock_irqrestore(ap->lock, flags);
  545. DPRINTK("ata%u port thawed\n", ap->id);
  546. }
  547. static void ata_eh_scsidone(struct scsi_cmnd *scmd)
  548. {
  549. /* nada */
  550. }
  551. static void __ata_eh_qc_complete(struct ata_queued_cmd *qc)
  552. {
  553. struct ata_port *ap = qc->ap;
  554. struct scsi_cmnd *scmd = qc->scsicmd;
  555. unsigned long flags;
  556. spin_lock_irqsave(ap->lock, flags);
  557. qc->scsidone = ata_eh_scsidone;
  558. __ata_qc_complete(qc);
  559. WARN_ON(ata_tag_valid(qc->tag));
  560. spin_unlock_irqrestore(ap->lock, flags);
  561. scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
  562. }
  563. /**
  564. * ata_eh_qc_complete - Complete an active ATA command from EH
  565. * @qc: Command to complete
  566. *
  567. * Indicate to the mid and upper layers that an ATA command has
  568. * completed. To be used from EH.
  569. */
  570. void ata_eh_qc_complete(struct ata_queued_cmd *qc)
  571. {
  572. struct scsi_cmnd *scmd = qc->scsicmd;
  573. scmd->retries = scmd->allowed;
  574. __ata_eh_qc_complete(qc);
  575. }
  576. /**
  577. * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
  578. * @qc: Command to retry
  579. *
  580. * Indicate to the mid and upper layers that an ATA command
  581. * should be retried. To be used from EH.
  582. *
  583. * SCSI midlayer limits the number of retries to scmd->allowed.
  584. * scmd->retries is decremented for commands which get retried
  585. * due to unrelated failures (qc->err_mask is zero).
  586. */
  587. void ata_eh_qc_retry(struct ata_queued_cmd *qc)
  588. {
  589. struct scsi_cmnd *scmd = qc->scsicmd;
  590. if (!qc->err_mask && scmd->retries)
  591. scmd->retries--;
  592. __ata_eh_qc_complete(qc);
  593. }
  594. /**
  595. * ata_eh_detach_dev - detach ATA device
  596. * @dev: ATA device to detach
  597. *
  598. * Detach @dev.
  599. *
  600. * LOCKING:
  601. * None.
  602. */
  603. static void ata_eh_detach_dev(struct ata_device *dev)
  604. {
  605. struct ata_port *ap = dev->ap;
  606. unsigned long flags;
  607. ata_dev_disable(dev);
  608. spin_lock_irqsave(ap->lock, flags);
  609. dev->flags &= ~ATA_DFLAG_DETACH;
  610. if (ata_scsi_offline_dev(dev)) {
  611. dev->flags |= ATA_DFLAG_DETACHED;
  612. ap->flags |= ATA_FLAG_SCSI_HOTPLUG;
  613. }
  614. spin_unlock_irqrestore(ap->lock, flags);
  615. }
  616. /**
  617. * ata_eh_about_to_do - about to perform eh_action
  618. * @ap: target ATA port
  619. * @dev: target ATA dev for per-dev action (can be NULL)
  620. * @action: action about to be performed
  621. *
  622. * Called just before performing EH actions to clear related bits
  623. * in @ap->eh_info such that eh actions are not unnecessarily
  624. * repeated.
  625. *
  626. * LOCKING:
  627. * None.
  628. */
  629. static void ata_eh_about_to_do(struct ata_port *ap, struct ata_device *dev,
  630. unsigned int action)
  631. {
  632. unsigned long flags;
  633. spin_lock_irqsave(ap->lock, flags);
  634. ata_eh_clear_action(dev, &ap->eh_info, action);
  635. ap->flags |= ATA_FLAG_RECOVERED;
  636. spin_unlock_irqrestore(ap->lock, flags);
  637. }
  638. /**
  639. * ata_eh_done - EH action complete
  640. * @ap: target ATA port
  641. * @dev: target ATA dev for per-dev action (can be NULL)
  642. * @action: action just completed
  643. *
  644. * Called right after performing EH actions to clear related bits
  645. * in @ap->eh_context.
  646. *
  647. * LOCKING:
  648. * None.
  649. */
  650. static void ata_eh_done(struct ata_port *ap, struct ata_device *dev,
  651. unsigned int action)
  652. {
  653. ata_eh_clear_action(dev, &ap->eh_context.i, action);
  654. }
  655. /**
  656. * ata_err_string - convert err_mask to descriptive string
  657. * @err_mask: error mask to convert to string
  658. *
  659. * Convert @err_mask to descriptive string. Errors are
  660. * prioritized according to severity and only the most severe
  661. * error is reported.
  662. *
  663. * LOCKING:
  664. * None.
  665. *
  666. * RETURNS:
  667. * Descriptive string for @err_mask
  668. */
  669. static const char * ata_err_string(unsigned int err_mask)
  670. {
  671. if (err_mask & AC_ERR_HOST_BUS)
  672. return "host bus error";
  673. if (err_mask & AC_ERR_ATA_BUS)
  674. return "ATA bus error";
  675. if (err_mask & AC_ERR_TIMEOUT)
  676. return "timeout";
  677. if (err_mask & AC_ERR_HSM)
  678. return "HSM violation";
  679. if (err_mask & AC_ERR_SYSTEM)
  680. return "internal error";
  681. if (err_mask & AC_ERR_MEDIA)
  682. return "media error";
  683. if (err_mask & AC_ERR_INVALID)
  684. return "invalid argument";
  685. if (err_mask & AC_ERR_DEV)
  686. return "device error";
  687. return "unknown error";
  688. }
  689. /**
  690. * ata_read_log_page - read a specific log page
  691. * @dev: target device
  692. * @page: page to read
  693. * @buf: buffer to store read page
  694. * @sectors: number of sectors to read
  695. *
  696. * Read log page using READ_LOG_EXT command.
  697. *
  698. * LOCKING:
  699. * Kernel thread context (may sleep).
  700. *
  701. * RETURNS:
  702. * 0 on success, AC_ERR_* mask otherwise.
  703. */
  704. static unsigned int ata_read_log_page(struct ata_device *dev,
  705. u8 page, void *buf, unsigned int sectors)
  706. {
  707. struct ata_taskfile tf;
  708. unsigned int err_mask;
  709. DPRINTK("read log page - page %d\n", page);
  710. ata_tf_init(dev, &tf);
  711. tf.command = ATA_CMD_READ_LOG_EXT;
  712. tf.lbal = page;
  713. tf.nsect = sectors;
  714. tf.hob_nsect = sectors >> 8;
  715. tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_LBA48 | ATA_TFLAG_DEVICE;
  716. tf.protocol = ATA_PROT_PIO;
  717. err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE,
  718. buf, sectors * ATA_SECT_SIZE);
  719. DPRINTK("EXIT, err_mask=%x\n", err_mask);
  720. return err_mask;
  721. }
  722. /**
  723. * ata_eh_read_log_10h - Read log page 10h for NCQ error details
  724. * @dev: Device to read log page 10h from
  725. * @tag: Resulting tag of the failed command
  726. * @tf: Resulting taskfile registers of the failed command
  727. *
  728. * Read log page 10h to obtain NCQ error details and clear error
  729. * condition.
  730. *
  731. * LOCKING:
  732. * Kernel thread context (may sleep).
  733. *
  734. * RETURNS:
  735. * 0 on success, -errno otherwise.
  736. */
  737. static int ata_eh_read_log_10h(struct ata_device *dev,
  738. int *tag, struct ata_taskfile *tf)
  739. {
  740. u8 *buf = dev->ap->sector_buf;
  741. unsigned int err_mask;
  742. u8 csum;
  743. int i;
  744. err_mask = ata_read_log_page(dev, ATA_LOG_SATA_NCQ, buf, 1);
  745. if (err_mask)
  746. return -EIO;
  747. csum = 0;
  748. for (i = 0; i < ATA_SECT_SIZE; i++)
  749. csum += buf[i];
  750. if (csum)
  751. ata_dev_printk(dev, KERN_WARNING,
  752. "invalid checksum 0x%x on log page 10h\n", csum);
  753. if (buf[0] & 0x80)
  754. return -ENOENT;
  755. *tag = buf[0] & 0x1f;
  756. tf->command = buf[2];
  757. tf->feature = buf[3];
  758. tf->lbal = buf[4];
  759. tf->lbam = buf[5];
  760. tf->lbah = buf[6];
  761. tf->device = buf[7];
  762. tf->hob_lbal = buf[8];
  763. tf->hob_lbam = buf[9];
  764. tf->hob_lbah = buf[10];
  765. tf->nsect = buf[12];
  766. tf->hob_nsect = buf[13];
  767. return 0;
  768. }
  769. /**
  770. * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE
  771. * @dev: device to perform REQUEST_SENSE to
  772. * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long)
  773. *
  774. * Perform ATAPI REQUEST_SENSE after the device reported CHECK
  775. * SENSE. This function is EH helper.
  776. *
  777. * LOCKING:
  778. * Kernel thread context (may sleep).
  779. *
  780. * RETURNS:
  781. * 0 on success, AC_ERR_* mask on failure
  782. */
  783. static unsigned int atapi_eh_request_sense(struct ata_device *dev,
  784. unsigned char *sense_buf)
  785. {
  786. struct ata_port *ap = dev->ap;
  787. struct ata_taskfile tf;
  788. u8 cdb[ATAPI_CDB_LEN];
  789. DPRINTK("ATAPI request sense\n");
  790. ata_tf_init(dev, &tf);
  791. /* FIXME: is this needed? */
  792. memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
  793. /* XXX: why tf_read here? */
  794. ap->ops->tf_read(ap, &tf);
  795. /* fill these in, for the case where they are -not- overwritten */
  796. sense_buf[0] = 0x70;
  797. sense_buf[2] = tf.feature >> 4;
  798. memset(cdb, 0, ATAPI_CDB_LEN);
  799. cdb[0] = REQUEST_SENSE;
  800. cdb[4] = SCSI_SENSE_BUFFERSIZE;
  801. tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
  802. tf.command = ATA_CMD_PACKET;
  803. /* is it pointless to prefer PIO for "safety reasons"? */
  804. if (ap->flags & ATA_FLAG_PIO_DMA) {
  805. tf.protocol = ATA_PROT_ATAPI_DMA;
  806. tf.feature |= ATAPI_PKT_DMA;
  807. } else {
  808. tf.protocol = ATA_PROT_ATAPI;
  809. tf.lbam = (8 * 1024) & 0xff;
  810. tf.lbah = (8 * 1024) >> 8;
  811. }
  812. return ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE,
  813. sense_buf, SCSI_SENSE_BUFFERSIZE);
  814. }
  815. /**
  816. * ata_eh_analyze_serror - analyze SError for a failed port
  817. * @ap: ATA port to analyze SError for
  818. *
  819. * Analyze SError if available and further determine cause of
  820. * failure.
  821. *
  822. * LOCKING:
  823. * None.
  824. */
  825. static void ata_eh_analyze_serror(struct ata_port *ap)
  826. {
  827. struct ata_eh_context *ehc = &ap->eh_context;
  828. u32 serror = ehc->i.serror;
  829. unsigned int err_mask = 0, action = 0;
  830. if (serror & SERR_PERSISTENT) {
  831. err_mask |= AC_ERR_ATA_BUS;
  832. action |= ATA_EH_HARDRESET;
  833. }
  834. if (serror &
  835. (SERR_DATA_RECOVERED | SERR_COMM_RECOVERED | SERR_DATA)) {
  836. err_mask |= AC_ERR_ATA_BUS;
  837. action |= ATA_EH_SOFTRESET;
  838. }
  839. if (serror & SERR_PROTOCOL) {
  840. err_mask |= AC_ERR_HSM;
  841. action |= ATA_EH_SOFTRESET;
  842. }
  843. if (serror & SERR_INTERNAL) {
  844. err_mask |= AC_ERR_SYSTEM;
  845. action |= ATA_EH_SOFTRESET;
  846. }
  847. if (serror & (SERR_PHYRDY_CHG | SERR_DEV_XCHG))
  848. ata_ehi_hotplugged(&ehc->i);
  849. ehc->i.err_mask |= err_mask;
  850. ehc->i.action |= action;
  851. }
  852. /**
  853. * ata_eh_analyze_ncq_error - analyze NCQ error
  854. * @ap: ATA port to analyze NCQ error for
  855. *
  856. * Read log page 10h, determine the offending qc and acquire
  857. * error status TF. For NCQ device errors, all LLDDs have to do
  858. * is setting AC_ERR_DEV in ehi->err_mask. This function takes
  859. * care of the rest.
  860. *
  861. * LOCKING:
  862. * Kernel thread context (may sleep).
  863. */
  864. static void ata_eh_analyze_ncq_error(struct ata_port *ap)
  865. {
  866. struct ata_eh_context *ehc = &ap->eh_context;
  867. struct ata_device *dev = ap->device;
  868. struct ata_queued_cmd *qc;
  869. struct ata_taskfile tf;
  870. int tag, rc;
  871. /* if frozen, we can't do much */
  872. if (ap->flags & ATA_FLAG_FROZEN)
  873. return;
  874. /* is it NCQ device error? */
  875. if (!ap->sactive || !(ehc->i.err_mask & AC_ERR_DEV))
  876. return;
  877. /* has LLDD analyzed already? */
  878. for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
  879. qc = __ata_qc_from_tag(ap, tag);
  880. if (!(qc->flags & ATA_QCFLAG_FAILED))
  881. continue;
  882. if (qc->err_mask)
  883. return;
  884. }
  885. /* okay, this error is ours */
  886. rc = ata_eh_read_log_10h(dev, &tag, &tf);
  887. if (rc) {
  888. ata_port_printk(ap, KERN_ERR, "failed to read log page 10h "
  889. "(errno=%d)\n", rc);
  890. return;
  891. }
  892. if (!(ap->sactive & (1 << tag))) {
  893. ata_port_printk(ap, KERN_ERR, "log page 10h reported "
  894. "inactive tag %d\n", tag);
  895. return;
  896. }
  897. /* we've got the perpetrator, condemn it */
  898. qc = __ata_qc_from_tag(ap, tag);
  899. memcpy(&qc->result_tf, &tf, sizeof(tf));
  900. qc->err_mask |= AC_ERR_DEV;
  901. ehc->i.err_mask &= ~AC_ERR_DEV;
  902. }
  903. /**
  904. * ata_eh_analyze_tf - analyze taskfile of a failed qc
  905. * @qc: qc to analyze
  906. * @tf: Taskfile registers to analyze
  907. *
  908. * Analyze taskfile of @qc and further determine cause of
  909. * failure. This function also requests ATAPI sense data if
  910. * avaliable.
  911. *
  912. * LOCKING:
  913. * Kernel thread context (may sleep).
  914. *
  915. * RETURNS:
  916. * Determined recovery action
  917. */
  918. static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
  919. const struct ata_taskfile *tf)
  920. {
  921. unsigned int tmp, action = 0;
  922. u8 stat = tf->command, err = tf->feature;
  923. if ((stat & (ATA_BUSY | ATA_DRQ | ATA_DRDY)) != ATA_DRDY) {
  924. qc->err_mask |= AC_ERR_HSM;
  925. return ATA_EH_SOFTRESET;
  926. }
  927. if (!(qc->err_mask & AC_ERR_DEV))
  928. return 0;
  929. switch (qc->dev->class) {
  930. case ATA_DEV_ATA:
  931. if (err & ATA_ICRC)
  932. qc->err_mask |= AC_ERR_ATA_BUS;
  933. if (err & ATA_UNC)
  934. qc->err_mask |= AC_ERR_MEDIA;
  935. if (err & ATA_IDNF)
  936. qc->err_mask |= AC_ERR_INVALID;
  937. break;
  938. case ATA_DEV_ATAPI:
  939. tmp = atapi_eh_request_sense(qc->dev,
  940. qc->scsicmd->sense_buffer);
  941. if (!tmp) {
  942. /* ATA_QCFLAG_SENSE_VALID is used to tell
  943. * atapi_qc_complete() that sense data is
  944. * already valid.
  945. *
  946. * TODO: interpret sense data and set
  947. * appropriate err_mask.
  948. */
  949. qc->flags |= ATA_QCFLAG_SENSE_VALID;
  950. } else
  951. qc->err_mask |= tmp;
  952. }
  953. if (qc->err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT | AC_ERR_ATA_BUS))
  954. action |= ATA_EH_SOFTRESET;
  955. return action;
  956. }
  957. static int ata_eh_categorize_ering_entry(struct ata_ering_entry *ent)
  958. {
  959. if (ent->err_mask & (AC_ERR_ATA_BUS | AC_ERR_TIMEOUT))
  960. return 1;
  961. if (ent->is_io) {
  962. if (ent->err_mask & AC_ERR_HSM)
  963. return 1;
  964. if ((ent->err_mask &
  965. (AC_ERR_DEV|AC_ERR_MEDIA|AC_ERR_INVALID)) == AC_ERR_DEV)
  966. return 2;
  967. }
  968. return 0;
  969. }
  970. struct speed_down_needed_arg {
  971. u64 since;
  972. int nr_errors[3];
  973. };
  974. static int speed_down_needed_cb(struct ata_ering_entry *ent, void *void_arg)
  975. {
  976. struct speed_down_needed_arg *arg = void_arg;
  977. if (ent->timestamp < arg->since)
  978. return -1;
  979. arg->nr_errors[ata_eh_categorize_ering_entry(ent)]++;
  980. return 0;
  981. }
  982. /**
  983. * ata_eh_speed_down_needed - Determine wheter speed down is necessary
  984. * @dev: Device of interest
  985. *
  986. * This function examines error ring of @dev and determines
  987. * whether speed down is necessary. Speed down is necessary if
  988. * there have been more than 3 of Cat-1 errors or 10 of Cat-2
  989. * errors during last 15 minutes.
  990. *
  991. * Cat-1 errors are ATA_BUS, TIMEOUT for any command and HSM
  992. * violation for known supported commands.
  993. *
  994. * Cat-2 errors are unclassified DEV error for known supported
  995. * command.
  996. *
  997. * LOCKING:
  998. * Inherited from caller.
  999. *
  1000. * RETURNS:
  1001. * 1 if speed down is necessary, 0 otherwise
  1002. */
  1003. static int ata_eh_speed_down_needed(struct ata_device *dev)
  1004. {
  1005. const u64 interval = 15LLU * 60 * HZ;
  1006. static const int err_limits[3] = { -1, 3, 10 };
  1007. struct speed_down_needed_arg arg;
  1008. struct ata_ering_entry *ent;
  1009. int err_cat;
  1010. u64 j64;
  1011. ent = ata_ering_top(&dev->ering);
  1012. if (!ent)
  1013. return 0;
  1014. err_cat = ata_eh_categorize_ering_entry(ent);
  1015. if (err_cat == 0)
  1016. return 0;
  1017. memset(&arg, 0, sizeof(arg));
  1018. j64 = get_jiffies_64();
  1019. if (j64 >= interval)
  1020. arg.since = j64 - interval;
  1021. else
  1022. arg.since = 0;
  1023. ata_ering_map(&dev->ering, speed_down_needed_cb, &arg);
  1024. return arg.nr_errors[err_cat] > err_limits[err_cat];
  1025. }
  1026. /**
  1027. * ata_eh_speed_down - record error and speed down if necessary
  1028. * @dev: Failed device
  1029. * @is_io: Did the device fail during normal IO?
  1030. * @err_mask: err_mask of the error
  1031. *
  1032. * Record error and examine error history to determine whether
  1033. * adjusting transmission speed is necessary. It also sets
  1034. * transmission limits appropriately if such adjustment is
  1035. * necessary.
  1036. *
  1037. * LOCKING:
  1038. * Kernel thread context (may sleep).
  1039. *
  1040. * RETURNS:
  1041. * 0 on success, -errno otherwise
  1042. */
  1043. static int ata_eh_speed_down(struct ata_device *dev, int is_io,
  1044. unsigned int err_mask)
  1045. {
  1046. if (!err_mask)
  1047. return 0;
  1048. /* record error and determine whether speed down is necessary */
  1049. ata_ering_record(&dev->ering, is_io, err_mask);
  1050. if (!ata_eh_speed_down_needed(dev))
  1051. return 0;
  1052. /* speed down SATA link speed if possible */
  1053. if (sata_down_spd_limit(dev->ap) == 0)
  1054. return ATA_EH_HARDRESET;
  1055. /* lower transfer mode */
  1056. if (ata_down_xfermask_limit(dev, 0) == 0)
  1057. return ATA_EH_SOFTRESET;
  1058. ata_dev_printk(dev, KERN_ERR,
  1059. "speed down requested but no transfer mode left\n");
  1060. return 0;
  1061. }
  1062. /**
  1063. * ata_eh_autopsy - analyze error and determine recovery action
  1064. * @ap: ATA port to perform autopsy on
  1065. *
  1066. * Analyze why @ap failed and determine which recovery action is
  1067. * needed. This function also sets more detailed AC_ERR_* values
  1068. * and fills sense data for ATAPI CHECK SENSE.
  1069. *
  1070. * LOCKING:
  1071. * Kernel thread context (may sleep).
  1072. */
  1073. static void ata_eh_autopsy(struct ata_port *ap)
  1074. {
  1075. struct ata_eh_context *ehc = &ap->eh_context;
  1076. unsigned int action = ehc->i.action;
  1077. struct ata_device *failed_dev = NULL;
  1078. unsigned int all_err_mask = 0;
  1079. int tag, is_io = 0;
  1080. u32 serror;
  1081. int rc;
  1082. DPRINTK("ENTER\n");
  1083. /* obtain and analyze SError */
  1084. rc = sata_scr_read(ap, SCR_ERROR, &serror);
  1085. if (rc == 0) {
  1086. ehc->i.serror |= serror;
  1087. ata_eh_analyze_serror(ap);
  1088. } else if (rc != -EOPNOTSUPP)
  1089. action |= ATA_EH_HARDRESET;
  1090. /* analyze NCQ failure */
  1091. ata_eh_analyze_ncq_error(ap);
  1092. /* any real error trumps AC_ERR_OTHER */
  1093. if (ehc->i.err_mask & ~AC_ERR_OTHER)
  1094. ehc->i.err_mask &= ~AC_ERR_OTHER;
  1095. all_err_mask |= ehc->i.err_mask;
  1096. for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
  1097. struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
  1098. if (!(qc->flags & ATA_QCFLAG_FAILED))
  1099. continue;
  1100. /* inherit upper level err_mask */
  1101. qc->err_mask |= ehc->i.err_mask;
  1102. /* analyze TF */
  1103. action |= ata_eh_analyze_tf(qc, &qc->result_tf);
  1104. /* DEV errors are probably spurious in case of ATA_BUS error */
  1105. if (qc->err_mask & AC_ERR_ATA_BUS)
  1106. qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_MEDIA |
  1107. AC_ERR_INVALID);
  1108. /* any real error trumps unknown error */
  1109. if (qc->err_mask & ~AC_ERR_OTHER)
  1110. qc->err_mask &= ~AC_ERR_OTHER;
  1111. /* SENSE_VALID trumps dev/unknown error and revalidation */
  1112. if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
  1113. qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER);
  1114. action &= ~ATA_EH_REVALIDATE;
  1115. }
  1116. /* accumulate error info */
  1117. failed_dev = qc->dev;
  1118. all_err_mask |= qc->err_mask;
  1119. if (qc->flags & ATA_QCFLAG_IO)
  1120. is_io = 1;
  1121. }
  1122. /* enforce default EH actions */
  1123. if (ap->flags & ATA_FLAG_FROZEN ||
  1124. all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT))
  1125. action |= ATA_EH_SOFTRESET;
  1126. else if (all_err_mask)
  1127. action |= ATA_EH_REVALIDATE;
  1128. /* if we have offending qcs and the associated failed device */
  1129. if (failed_dev) {
  1130. /* speed down */
  1131. action |= ata_eh_speed_down(failed_dev, is_io, all_err_mask);
  1132. /* perform per-dev EH action only on the offending device */
  1133. ehc->i.dev_action[failed_dev->devno] |=
  1134. action & ATA_EH_PERDEV_MASK;
  1135. action &= ~ATA_EH_PERDEV_MASK;
  1136. }
  1137. /* record autopsy result */
  1138. ehc->i.dev = failed_dev;
  1139. ehc->i.action = action;
  1140. DPRINTK("EXIT\n");
  1141. }
  1142. /**
  1143. * ata_eh_report - report error handling to user
  1144. * @ap: ATA port EH is going on
  1145. *
  1146. * Report EH to user.
  1147. *
  1148. * LOCKING:
  1149. * None.
  1150. */
  1151. static void ata_eh_report(struct ata_port *ap)
  1152. {
  1153. struct ata_eh_context *ehc = &ap->eh_context;
  1154. const char *frozen, *desc;
  1155. int tag, nr_failed = 0;
  1156. desc = NULL;
  1157. if (ehc->i.desc[0] != '\0')
  1158. desc = ehc->i.desc;
  1159. for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
  1160. struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
  1161. if (!(qc->flags & ATA_QCFLAG_FAILED))
  1162. continue;
  1163. if (qc->flags & ATA_QCFLAG_SENSE_VALID && !qc->err_mask)
  1164. continue;
  1165. nr_failed++;
  1166. }
  1167. if (!nr_failed && !ehc->i.err_mask)
  1168. return;
  1169. frozen = "";
  1170. if (ap->flags & ATA_FLAG_FROZEN)
  1171. frozen = " frozen";
  1172. if (ehc->i.dev) {
  1173. ata_dev_printk(ehc->i.dev, KERN_ERR, "exception Emask 0x%x "
  1174. "SAct 0x%x SErr 0x%x action 0x%x%s\n",
  1175. ehc->i.err_mask, ap->sactive, ehc->i.serror,
  1176. ehc->i.action, frozen);
  1177. if (desc)
  1178. ata_dev_printk(ehc->i.dev, KERN_ERR, "(%s)\n", desc);
  1179. } else {
  1180. ata_port_printk(ap, KERN_ERR, "exception Emask 0x%x "
  1181. "SAct 0x%x SErr 0x%x action 0x%x%s\n",
  1182. ehc->i.err_mask, ap->sactive, ehc->i.serror,
  1183. ehc->i.action, frozen);
  1184. if (desc)
  1185. ata_port_printk(ap, KERN_ERR, "(%s)\n", desc);
  1186. }
  1187. for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
  1188. struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
  1189. if (!(qc->flags & ATA_QCFLAG_FAILED) || !qc->err_mask)
  1190. continue;
  1191. ata_dev_printk(qc->dev, KERN_ERR, "tag %d cmd 0x%x "
  1192. "Emask 0x%x stat 0x%x err 0x%x (%s)\n",
  1193. qc->tag, qc->tf.command, qc->err_mask,
  1194. qc->result_tf.command, qc->result_tf.feature,
  1195. ata_err_string(qc->err_mask));
  1196. }
  1197. }
  1198. static int ata_do_reset(struct ata_port *ap, ata_reset_fn_t reset,
  1199. unsigned int *classes)
  1200. {
  1201. int i, rc;
  1202. for (i = 0; i < ATA_MAX_DEVICES; i++)
  1203. classes[i] = ATA_DEV_UNKNOWN;
  1204. rc = reset(ap, classes);
  1205. if (rc)
  1206. return rc;
  1207. /* If any class isn't ATA_DEV_UNKNOWN, consider classification
  1208. * is complete and convert all ATA_DEV_UNKNOWN to
  1209. * ATA_DEV_NONE.
  1210. */
  1211. for (i = 0; i < ATA_MAX_DEVICES; i++)
  1212. if (classes[i] != ATA_DEV_UNKNOWN)
  1213. break;
  1214. if (i < ATA_MAX_DEVICES)
  1215. for (i = 0; i < ATA_MAX_DEVICES; i++)
  1216. if (classes[i] == ATA_DEV_UNKNOWN)
  1217. classes[i] = ATA_DEV_NONE;
  1218. return 0;
  1219. }
  1220. static int ata_eh_followup_srst_needed(int rc, int classify,
  1221. const unsigned int *classes)
  1222. {
  1223. if (rc == -EAGAIN)
  1224. return 1;
  1225. if (rc != 0)
  1226. return 0;
  1227. if (classify && classes[0] == ATA_DEV_UNKNOWN)
  1228. return 1;
  1229. return 0;
  1230. }
  1231. static int ata_eh_reset(struct ata_port *ap, int classify,
  1232. ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
  1233. ata_reset_fn_t hardreset, ata_postreset_fn_t postreset)
  1234. {
  1235. struct ata_eh_context *ehc = &ap->eh_context;
  1236. unsigned int *classes = ehc->classes;
  1237. int tries = ATA_EH_RESET_TRIES;
  1238. int verbose = !(ap->flags & ATA_FLAG_LOADING);
  1239. unsigned int action;
  1240. ata_reset_fn_t reset;
  1241. int i, did_followup_srst, rc;
  1242. /* Determine which reset to use and record in ehc->i.action.
  1243. * prereset() may examine and modify it.
  1244. */
  1245. action = ehc->i.action;
  1246. ehc->i.action &= ~ATA_EH_RESET_MASK;
  1247. if (softreset && (!hardreset || (!sata_set_spd_needed(ap) &&
  1248. !(action & ATA_EH_HARDRESET))))
  1249. ehc->i.action |= ATA_EH_SOFTRESET;
  1250. else
  1251. ehc->i.action |= ATA_EH_HARDRESET;
  1252. if (prereset) {
  1253. rc = prereset(ap);
  1254. if (rc) {
  1255. ata_port_printk(ap, KERN_ERR,
  1256. "prereset failed (errno=%d)\n", rc);
  1257. return rc;
  1258. }
  1259. }
  1260. /* prereset() might have modified ehc->i.action */
  1261. if (ehc->i.action & ATA_EH_HARDRESET)
  1262. reset = hardreset;
  1263. else if (ehc->i.action & ATA_EH_SOFTRESET)
  1264. reset = softreset;
  1265. else {
  1266. /* prereset told us not to reset, bang classes and return */
  1267. for (i = 0; i < ATA_MAX_DEVICES; i++)
  1268. classes[i] = ATA_DEV_NONE;
  1269. return 0;
  1270. }
  1271. /* did prereset() screw up? if so, fix up to avoid oopsing */
  1272. if (!reset) {
  1273. ata_port_printk(ap, KERN_ERR, "BUG: prereset() requested "
  1274. "invalid reset type\n");
  1275. if (softreset)
  1276. reset = softreset;
  1277. else
  1278. reset = hardreset;
  1279. }
  1280. retry:
  1281. /* shut up during boot probing */
  1282. if (verbose)
  1283. ata_port_printk(ap, KERN_INFO, "%s resetting port\n",
  1284. reset == softreset ? "soft" : "hard");
  1285. /* reset */
  1286. ata_eh_about_to_do(ap, NULL, ATA_EH_RESET_MASK);
  1287. ehc->i.flags |= ATA_EHI_DID_RESET;
  1288. rc = ata_do_reset(ap, reset, classes);
  1289. did_followup_srst = 0;
  1290. if (reset == hardreset &&
  1291. ata_eh_followup_srst_needed(rc, classify, classes)) {
  1292. /* okay, let's do follow-up softreset */
  1293. did_followup_srst = 1;
  1294. reset = softreset;
  1295. if (!reset) {
  1296. ata_port_printk(ap, KERN_ERR,
  1297. "follow-up softreset required "
  1298. "but no softreset avaliable\n");
  1299. return -EINVAL;
  1300. }
  1301. ata_eh_about_to_do(ap, NULL, ATA_EH_RESET_MASK);
  1302. rc = ata_do_reset(ap, reset, classes);
  1303. if (rc == 0 && classify &&
  1304. classes[0] == ATA_DEV_UNKNOWN) {
  1305. ata_port_printk(ap, KERN_ERR,
  1306. "classification failed\n");
  1307. return -EINVAL;
  1308. }
  1309. }
  1310. if (rc && --tries) {
  1311. const char *type;
  1312. if (reset == softreset) {
  1313. if (did_followup_srst)
  1314. type = "follow-up soft";
  1315. else
  1316. type = "soft";
  1317. } else
  1318. type = "hard";
  1319. ata_port_printk(ap, KERN_WARNING,
  1320. "%sreset failed, retrying in 5 secs\n", type);
  1321. ssleep(5);
  1322. if (reset == hardreset)
  1323. sata_down_spd_limit(ap);
  1324. if (hardreset)
  1325. reset = hardreset;
  1326. goto retry;
  1327. }
  1328. if (rc == 0) {
  1329. /* After the reset, the device state is PIO 0 and the
  1330. * controller state is undefined. Record the mode.
  1331. */
  1332. for (i = 0; i < ATA_MAX_DEVICES; i++)
  1333. ap->device[i].pio_mode = XFER_PIO_0;
  1334. if (postreset)
  1335. postreset(ap, classes);
  1336. /* reset successful, schedule revalidation */
  1337. ata_eh_done(ap, NULL, ATA_EH_RESET_MASK);
  1338. ehc->i.action |= ATA_EH_REVALIDATE;
  1339. }
  1340. return rc;
  1341. }
  1342. static int ata_eh_revalidate_and_attach(struct ata_port *ap,
  1343. struct ata_device **r_failed_dev)
  1344. {
  1345. struct ata_eh_context *ehc = &ap->eh_context;
  1346. struct ata_device *dev;
  1347. unsigned long flags;
  1348. int i, rc = 0;
  1349. DPRINTK("ENTER\n");
  1350. for (i = 0; i < ATA_MAX_DEVICES; i++) {
  1351. unsigned int action;
  1352. dev = &ap->device[i];
  1353. action = ehc->i.action | ehc->i.dev_action[dev->devno];
  1354. if (action & ATA_EH_REVALIDATE && ata_dev_enabled(dev)) {
  1355. if (ata_port_offline(ap)) {
  1356. rc = -EIO;
  1357. break;
  1358. }
  1359. ata_eh_about_to_do(ap, dev, ATA_EH_REVALIDATE);
  1360. rc = ata_dev_revalidate(dev,
  1361. ehc->i.flags & ATA_EHI_DID_RESET);
  1362. if (rc)
  1363. break;
  1364. ata_eh_done(ap, dev, ATA_EH_REVALIDATE);
  1365. /* schedule the scsi_rescan_device() here */
  1366. queue_work(ata_aux_wq, &(ap->scsi_rescan_task));
  1367. } else if (dev->class == ATA_DEV_UNKNOWN &&
  1368. ehc->tries[dev->devno] &&
  1369. ata_class_enabled(ehc->classes[dev->devno])) {
  1370. dev->class = ehc->classes[dev->devno];
  1371. rc = ata_dev_read_id(dev, &dev->class, 1, dev->id);
  1372. if (rc == 0)
  1373. rc = ata_dev_configure(dev, 1);
  1374. if (rc) {
  1375. dev->class = ATA_DEV_UNKNOWN;
  1376. break;
  1377. }
  1378. spin_lock_irqsave(ap->lock, flags);
  1379. ap->flags |= ATA_FLAG_SCSI_HOTPLUG;
  1380. spin_unlock_irqrestore(ap->lock, flags);
  1381. }
  1382. }
  1383. if (rc)
  1384. *r_failed_dev = dev;
  1385. DPRINTK("EXIT\n");
  1386. return rc;
  1387. }
  1388. static int ata_port_nr_enabled(struct ata_port *ap)
  1389. {
  1390. int i, cnt = 0;
  1391. for (i = 0; i < ATA_MAX_DEVICES; i++)
  1392. if (ata_dev_enabled(&ap->device[i]))
  1393. cnt++;
  1394. return cnt;
  1395. }
  1396. static int ata_port_nr_vacant(struct ata_port *ap)
  1397. {
  1398. int i, cnt = 0;
  1399. for (i = 0; i < ATA_MAX_DEVICES; i++)
  1400. if (ap->device[i].class == ATA_DEV_UNKNOWN)
  1401. cnt++;
  1402. return cnt;
  1403. }
  1404. static int ata_eh_skip_recovery(struct ata_port *ap)
  1405. {
  1406. struct ata_eh_context *ehc = &ap->eh_context;
  1407. int i;
  1408. if (ap->flags & ATA_FLAG_FROZEN || ata_port_nr_enabled(ap))
  1409. return 0;
  1410. /* skip if class codes for all vacant slots are ATA_DEV_NONE */
  1411. for (i = 0; i < ATA_MAX_DEVICES; i++) {
  1412. struct ata_device *dev = &ap->device[i];
  1413. if (dev->class == ATA_DEV_UNKNOWN &&
  1414. ehc->classes[dev->devno] != ATA_DEV_NONE)
  1415. return 0;
  1416. }
  1417. return 1;
  1418. }
  1419. /**
  1420. * ata_eh_recover - recover host port after error
  1421. * @ap: host port to recover
  1422. * @prereset: prereset method (can be NULL)
  1423. * @softreset: softreset method (can be NULL)
  1424. * @hardreset: hardreset method (can be NULL)
  1425. * @postreset: postreset method (can be NULL)
  1426. *
  1427. * This is the alpha and omega, eum and yang, heart and soul of
  1428. * libata exception handling. On entry, actions required to
  1429. * recover the port and hotplug requests are recorded in
  1430. * eh_context. This function executes all the operations with
  1431. * appropriate retrials and fallbacks to resurrect failed
  1432. * devices, detach goners and greet newcomers.
  1433. *
  1434. * LOCKING:
  1435. * Kernel thread context (may sleep).
  1436. *
  1437. * RETURNS:
  1438. * 0 on success, -errno on failure.
  1439. */
  1440. static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
  1441. ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
  1442. ata_postreset_fn_t postreset)
  1443. {
  1444. struct ata_eh_context *ehc = &ap->eh_context;
  1445. struct ata_device *dev;
  1446. int down_xfermask, i, rc;
  1447. DPRINTK("ENTER\n");
  1448. /* prep for recovery */
  1449. for (i = 0; i < ATA_MAX_DEVICES; i++) {
  1450. dev = &ap->device[i];
  1451. ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
  1452. /* process hotplug request */
  1453. if (dev->flags & ATA_DFLAG_DETACH)
  1454. ata_eh_detach_dev(dev);
  1455. if (!ata_dev_enabled(dev) &&
  1456. ((ehc->i.probe_mask & (1 << dev->devno)) &&
  1457. !(ehc->did_probe_mask & (1 << dev->devno)))) {
  1458. ata_eh_detach_dev(dev);
  1459. ata_dev_init(dev);
  1460. ehc->did_probe_mask |= (1 << dev->devno);
  1461. ehc->i.action |= ATA_EH_SOFTRESET;
  1462. }
  1463. }
  1464. retry:
  1465. down_xfermask = 0;
  1466. rc = 0;
  1467. /* if UNLOADING, finish immediately */
  1468. if (ap->flags & ATA_FLAG_UNLOADING)
  1469. goto out;
  1470. /* skip EH if possible. */
  1471. if (ata_eh_skip_recovery(ap))
  1472. ehc->i.action = 0;
  1473. for (i = 0; i < ATA_MAX_DEVICES; i++)
  1474. ehc->classes[i] = ATA_DEV_UNKNOWN;
  1475. /* reset */
  1476. if (ehc->i.action & ATA_EH_RESET_MASK) {
  1477. ata_eh_freeze_port(ap);
  1478. rc = ata_eh_reset(ap, ata_port_nr_vacant(ap), prereset,
  1479. softreset, hardreset, postreset);
  1480. if (rc) {
  1481. ata_port_printk(ap, KERN_ERR,
  1482. "reset failed, giving up\n");
  1483. goto out;
  1484. }
  1485. ata_eh_thaw_port(ap);
  1486. }
  1487. /* revalidate existing devices and attach new ones */
  1488. rc = ata_eh_revalidate_and_attach(ap, &dev);
  1489. if (rc)
  1490. goto dev_fail;
  1491. /* configure transfer mode if the port has been reset */
  1492. if (ehc->i.flags & ATA_EHI_DID_RESET) {
  1493. rc = ata_set_mode(ap, &dev);
  1494. if (rc) {
  1495. down_xfermask = 1;
  1496. goto dev_fail;
  1497. }
  1498. }
  1499. goto out;
  1500. dev_fail:
  1501. switch (rc) {
  1502. case -ENODEV:
  1503. /* device missing, schedule probing */
  1504. ehc->i.probe_mask |= (1 << dev->devno);
  1505. case -EINVAL:
  1506. ehc->tries[dev->devno] = 0;
  1507. break;
  1508. case -EIO:
  1509. sata_down_spd_limit(ap);
  1510. default:
  1511. ehc->tries[dev->devno]--;
  1512. if (down_xfermask &&
  1513. ata_down_xfermask_limit(dev, ehc->tries[dev->devno] == 1))
  1514. ehc->tries[dev->devno] = 0;
  1515. }
  1516. if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) {
  1517. /* disable device if it has used up all its chances */
  1518. ata_dev_disable(dev);
  1519. /* detach if offline */
  1520. if (ata_port_offline(ap))
  1521. ata_eh_detach_dev(dev);
  1522. /* probe if requested */
  1523. if ((ehc->i.probe_mask & (1 << dev->devno)) &&
  1524. !(ehc->did_probe_mask & (1 << dev->devno))) {
  1525. ata_eh_detach_dev(dev);
  1526. ata_dev_init(dev);
  1527. ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
  1528. ehc->did_probe_mask |= (1 << dev->devno);
  1529. ehc->i.action |= ATA_EH_SOFTRESET;
  1530. }
  1531. } else {
  1532. /* soft didn't work? be haaaaard */
  1533. if (ehc->i.flags & ATA_EHI_DID_RESET)
  1534. ehc->i.action |= ATA_EH_HARDRESET;
  1535. else
  1536. ehc->i.action |= ATA_EH_SOFTRESET;
  1537. }
  1538. if (ata_port_nr_enabled(ap)) {
  1539. ata_port_printk(ap, KERN_WARNING, "failed to recover some "
  1540. "devices, retrying in 5 secs\n");
  1541. ssleep(5);
  1542. } else {
  1543. /* no device left, repeat fast */
  1544. msleep(500);
  1545. }
  1546. goto retry;
  1547. out:
  1548. if (rc) {
  1549. for (i = 0; i < ATA_MAX_DEVICES; i++)
  1550. ata_dev_disable(&ap->device[i]);
  1551. }
  1552. DPRINTK("EXIT, rc=%d\n", rc);
  1553. return rc;
  1554. }
  1555. /**
  1556. * ata_eh_finish - finish up EH
  1557. * @ap: host port to finish EH for
  1558. *
  1559. * Recovery is complete. Clean up EH states and retry or finish
  1560. * failed qcs.
  1561. *
  1562. * LOCKING:
  1563. * None.
  1564. */
  1565. static void ata_eh_finish(struct ata_port *ap)
  1566. {
  1567. int tag;
  1568. /* retry or finish qcs */
  1569. for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
  1570. struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
  1571. if (!(qc->flags & ATA_QCFLAG_FAILED))
  1572. continue;
  1573. if (qc->err_mask) {
  1574. /* FIXME: Once EH migration is complete,
  1575. * generate sense data in this function,
  1576. * considering both err_mask and tf.
  1577. */
  1578. if (qc->err_mask & AC_ERR_INVALID)
  1579. ata_eh_qc_complete(qc);
  1580. else
  1581. ata_eh_qc_retry(qc);
  1582. } else {
  1583. if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
  1584. ata_eh_qc_complete(qc);
  1585. } else {
  1586. /* feed zero TF to sense generation */
  1587. memset(&qc->result_tf, 0, sizeof(qc->result_tf));
  1588. ata_eh_qc_retry(qc);
  1589. }
  1590. }
  1591. }
  1592. }
  1593. /**
  1594. * ata_do_eh - do standard error handling
  1595. * @ap: host port to handle error for
  1596. * @prereset: prereset method (can be NULL)
  1597. * @softreset: softreset method (can be NULL)
  1598. * @hardreset: hardreset method (can be NULL)
  1599. * @postreset: postreset method (can be NULL)
  1600. *
  1601. * Perform standard error handling sequence.
  1602. *
  1603. * LOCKING:
  1604. * Kernel thread context (may sleep).
  1605. */
  1606. void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
  1607. ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
  1608. ata_postreset_fn_t postreset)
  1609. {
  1610. if (!(ap->flags & ATA_FLAG_LOADING)) {
  1611. ata_eh_autopsy(ap);
  1612. ata_eh_report(ap);
  1613. }
  1614. ata_eh_recover(ap, prereset, softreset, hardreset, postreset);
  1615. ata_eh_finish(ap);
  1616. }