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. /**
  84. * ata_scsi_timed_out - SCSI layer time out callback
  85. * @cmd: timed out SCSI command
  86. *
  87. * Handles SCSI layer timeout. We race with normal completion of
  88. * the qc for @cmd. If the qc is already gone, we lose and let
  89. * the scsi command finish (EH_HANDLED). Otherwise, the qc has
  90. * timed out and EH should be invoked. Prevent ata_qc_complete()
  91. * from finishing it by setting EH_SCHEDULED and return
  92. * EH_NOT_HANDLED.
  93. *
  94. * TODO: kill this function once old EH is gone.
  95. *
  96. * LOCKING:
  97. * Called from timer context
  98. *
  99. * RETURNS:
  100. * EH_HANDLED or EH_NOT_HANDLED
  101. */
  102. enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
  103. {
  104. struct Scsi_Host *host = cmd->device->host;
  105. struct ata_port *ap = ata_shost_to_port(host);
  106. unsigned long flags;
  107. struct ata_queued_cmd *qc;
  108. enum scsi_eh_timer_return ret;
  109. DPRINTK("ENTER\n");
  110. if (ap->ops->error_handler) {
  111. ret = EH_NOT_HANDLED;
  112. goto out;
  113. }
  114. ret = EH_HANDLED;
  115. spin_lock_irqsave(ap->lock, flags);
  116. qc = ata_qc_from_tag(ap, ap->active_tag);
  117. if (qc) {
  118. WARN_ON(qc->scsicmd != cmd);
  119. qc->flags |= ATA_QCFLAG_EH_SCHEDULED;
  120. qc->err_mask |= AC_ERR_TIMEOUT;
  121. ret = EH_NOT_HANDLED;
  122. }
  123. spin_unlock_irqrestore(ap->lock, flags);
  124. out:
  125. DPRINTK("EXIT, ret=%d\n", ret);
  126. return ret;
  127. }
  128. /**
  129. * ata_scsi_error - SCSI layer error handler callback
  130. * @host: SCSI host on which error occurred
  131. *
  132. * Handles SCSI-layer-thrown error events.
  133. *
  134. * LOCKING:
  135. * Inherited from SCSI layer (none, can sleep)
  136. *
  137. * RETURNS:
  138. * Zero.
  139. */
  140. void ata_scsi_error(struct Scsi_Host *host)
  141. {
  142. struct ata_port *ap = ata_shost_to_port(host);
  143. spinlock_t *ap_lock = ap->lock;
  144. int i, repeat_cnt = ATA_EH_MAX_REPEAT;
  145. unsigned long flags;
  146. DPRINTK("ENTER\n");
  147. /* synchronize with port task */
  148. ata_port_flush_task(ap);
  149. /* synchronize with host_set lock and sort out timeouts */
  150. /* For new EH, all qcs are finished in one of three ways -
  151. * normal completion, error completion, and SCSI timeout.
  152. * Both cmpletions can race against SCSI timeout. When normal
  153. * completion wins, the qc never reaches EH. When error
  154. * completion wins, the qc has ATA_QCFLAG_FAILED set.
  155. *
  156. * When SCSI timeout wins, things are a bit more complex.
  157. * Normal or error completion can occur after the timeout but
  158. * before this point. In such cases, both types of
  159. * completions are honored. A scmd is determined to have
  160. * timed out iff its associated qc is active and not failed.
  161. */
  162. if (ap->ops->error_handler) {
  163. struct scsi_cmnd *scmd, *tmp;
  164. int nr_timedout = 0;
  165. spin_lock_irqsave(ap_lock, flags);
  166. list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) {
  167. struct ata_queued_cmd *qc;
  168. for (i = 0; i < ATA_MAX_QUEUE; i++) {
  169. qc = __ata_qc_from_tag(ap, i);
  170. if (qc->flags & ATA_QCFLAG_ACTIVE &&
  171. qc->scsicmd == scmd)
  172. break;
  173. }
  174. if (i < ATA_MAX_QUEUE) {
  175. /* the scmd has an associated qc */
  176. if (!(qc->flags & ATA_QCFLAG_FAILED)) {
  177. /* which hasn't failed yet, timeout */
  178. qc->err_mask |= AC_ERR_TIMEOUT;
  179. qc->flags |= ATA_QCFLAG_FAILED;
  180. nr_timedout++;
  181. }
  182. } else {
  183. /* Normal completion occurred after
  184. * SCSI timeout but before this point.
  185. * Successfully complete it.
  186. */
  187. scmd->retries = scmd->allowed;
  188. scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
  189. }
  190. }
  191. /* If we have timed out qcs. They belong to EH from
  192. * this point but the state of the controller is
  193. * unknown. Freeze the port to make sure the IRQ
  194. * handler doesn't diddle with those qcs. This must
  195. * be done atomically w.r.t. setting QCFLAG_FAILED.
  196. */
  197. if (nr_timedout)
  198. __ata_port_freeze(ap);
  199. spin_unlock_irqrestore(ap_lock, flags);
  200. } else
  201. spin_unlock_wait(ap_lock);
  202. repeat:
  203. /* invoke error handler */
  204. if (ap->ops->error_handler) {
  205. /* fetch & clear EH info */
  206. spin_lock_irqsave(ap_lock, flags);
  207. memset(&ap->eh_context, 0, sizeof(ap->eh_context));
  208. ap->eh_context.i = ap->eh_info;
  209. memset(&ap->eh_info, 0, sizeof(ap->eh_info));
  210. ap->flags |= ATA_FLAG_EH_IN_PROGRESS;
  211. ap->flags &= ~ATA_FLAG_EH_PENDING;
  212. spin_unlock_irqrestore(ap_lock, flags);
  213. /* invoke EH. if unloading, just finish failed qcs */
  214. if (!(ap->flags & ATA_FLAG_UNLOADING))
  215. ap->ops->error_handler(ap);
  216. else
  217. ata_eh_finish(ap);
  218. /* Exception might have happend after ->error_handler
  219. * recovered the port but before this point. Repeat
  220. * EH in such case.
  221. */
  222. spin_lock_irqsave(ap_lock, flags);
  223. if (ap->flags & ATA_FLAG_EH_PENDING) {
  224. if (--repeat_cnt) {
  225. ata_port_printk(ap, KERN_INFO,
  226. "EH pending after completion, "
  227. "repeating EH (cnt=%d)\n", repeat_cnt);
  228. spin_unlock_irqrestore(ap_lock, flags);
  229. goto repeat;
  230. }
  231. ata_port_printk(ap, KERN_ERR, "EH pending after %d "
  232. "tries, giving up\n", ATA_EH_MAX_REPEAT);
  233. }
  234. /* this run is complete, make sure EH info is clear */
  235. memset(&ap->eh_info, 0, sizeof(ap->eh_info));
  236. /* Clear host_eh_scheduled while holding ap_lock such
  237. * that if exception occurs after this point but
  238. * before EH completion, SCSI midlayer will
  239. * re-initiate EH.
  240. */
  241. host->host_eh_scheduled = 0;
  242. spin_unlock_irqrestore(ap_lock, flags);
  243. } else {
  244. WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL);
  245. ap->ops->eng_timeout(ap);
  246. }
  247. /* finish or retry handled scmd's and clean up */
  248. WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q));
  249. scsi_eh_flush_done_q(&ap->eh_done_q);
  250. /* clean up */
  251. spin_lock_irqsave(ap_lock, flags);
  252. if (ap->flags & ATA_FLAG_LOADING) {
  253. ap->flags &= ~ATA_FLAG_LOADING;
  254. } else {
  255. if (ap->flags & ATA_FLAG_SCSI_HOTPLUG)
  256. queue_work(ata_aux_wq, &ap->hotplug_task);
  257. if (ap->flags & ATA_FLAG_RECOVERED)
  258. ata_port_printk(ap, KERN_INFO, "EH complete\n");
  259. }
  260. ap->flags &= ~(ATA_FLAG_SCSI_HOTPLUG | ATA_FLAG_RECOVERED);
  261. /* tell wait_eh that we're done */
  262. ap->flags &= ~ATA_FLAG_EH_IN_PROGRESS;
  263. wake_up_all(&ap->eh_wait_q);
  264. spin_unlock_irqrestore(ap_lock, flags);
  265. DPRINTK("EXIT\n");
  266. }
  267. /**
  268. * ata_port_wait_eh - Wait for the currently pending EH to complete
  269. * @ap: Port to wait EH for
  270. *
  271. * Wait until the currently pending EH is complete.
  272. *
  273. * LOCKING:
  274. * Kernel thread context (may sleep).
  275. */
  276. void ata_port_wait_eh(struct ata_port *ap)
  277. {
  278. unsigned long flags;
  279. DEFINE_WAIT(wait);
  280. retry:
  281. spin_lock_irqsave(ap->lock, flags);
  282. while (ap->flags & (ATA_FLAG_EH_PENDING | ATA_FLAG_EH_IN_PROGRESS)) {
  283. prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE);
  284. spin_unlock_irqrestore(ap->lock, flags);
  285. schedule();
  286. spin_lock_irqsave(ap->lock, flags);
  287. }
  288. finish_wait(&ap->eh_wait_q, &wait);
  289. spin_unlock_irqrestore(ap->lock, flags);
  290. /* make sure SCSI EH is complete */
  291. if (scsi_host_in_recovery(ap->host)) {
  292. msleep(10);
  293. goto retry;
  294. }
  295. }
  296. /**
  297. * ata_qc_timeout - Handle timeout of queued command
  298. * @qc: Command that timed out
  299. *
  300. * Some part of the kernel (currently, only the SCSI layer)
  301. * has noticed that the active command on port @ap has not
  302. * completed after a specified length of time. Handle this
  303. * condition by disabling DMA (if necessary) and completing
  304. * transactions, with error if necessary.
  305. *
  306. * This also handles the case of the "lost interrupt", where
  307. * for some reason (possibly hardware bug, possibly driver bug)
  308. * an interrupt was not delivered to the driver, even though the
  309. * transaction completed successfully.
  310. *
  311. * TODO: kill this function once old EH is gone.
  312. *
  313. * LOCKING:
  314. * Inherited from SCSI layer (none, can sleep)
  315. */
  316. static void ata_qc_timeout(struct ata_queued_cmd *qc)
  317. {
  318. struct ata_port *ap = qc->ap;
  319. u8 host_stat = 0, drv_stat;
  320. unsigned long flags;
  321. DPRINTK("ENTER\n");
  322. ap->hsm_task_state = HSM_ST_IDLE;
  323. spin_lock_irqsave(ap->lock, flags);
  324. switch (qc->tf.protocol) {
  325. case ATA_PROT_DMA:
  326. case ATA_PROT_ATAPI_DMA:
  327. host_stat = ap->ops->bmdma_status(ap);
  328. /* before we do anything else, clear DMA-Start bit */
  329. ap->ops->bmdma_stop(qc);
  330. /* fall through */
  331. default:
  332. ata_altstatus(ap);
  333. drv_stat = ata_chk_status(ap);
  334. /* ack bmdma irq events */
  335. ap->ops->irq_clear(ap);
  336. ata_dev_printk(qc->dev, KERN_ERR, "command 0x%x timeout, "
  337. "stat 0x%x host_stat 0x%x\n",
  338. qc->tf.command, drv_stat, host_stat);
  339. /* complete taskfile transaction */
  340. qc->err_mask |= AC_ERR_TIMEOUT;
  341. break;
  342. }
  343. spin_unlock_irqrestore(ap->lock, flags);
  344. ata_eh_qc_complete(qc);
  345. DPRINTK("EXIT\n");
  346. }
  347. /**
  348. * ata_eng_timeout - Handle timeout of queued command
  349. * @ap: Port on which timed-out command is active
  350. *
  351. * Some part of the kernel (currently, only the SCSI layer)
  352. * has noticed that the active command on port @ap has not
  353. * completed after a specified length of time. Handle this
  354. * condition by disabling DMA (if necessary) and completing
  355. * transactions, with error if necessary.
  356. *
  357. * This also handles the case of the "lost interrupt", where
  358. * for some reason (possibly hardware bug, possibly driver bug)
  359. * an interrupt was not delivered to the driver, even though the
  360. * transaction completed successfully.
  361. *
  362. * TODO: kill this function once old EH is gone.
  363. *
  364. * LOCKING:
  365. * Inherited from SCSI layer (none, can sleep)
  366. */
  367. void ata_eng_timeout(struct ata_port *ap)
  368. {
  369. DPRINTK("ENTER\n");
  370. ata_qc_timeout(ata_qc_from_tag(ap, ap->active_tag));
  371. DPRINTK("EXIT\n");
  372. }
  373. /**
  374. * ata_qc_schedule_eh - schedule qc for error handling
  375. * @qc: command to schedule error handling for
  376. *
  377. * Schedule error handling for @qc. EH will kick in as soon as
  378. * other commands are drained.
  379. *
  380. * LOCKING:
  381. * spin_lock_irqsave(host_set lock)
  382. */
  383. void ata_qc_schedule_eh(struct ata_queued_cmd *qc)
  384. {
  385. struct ata_port *ap = qc->ap;
  386. WARN_ON(!ap->ops->error_handler);
  387. qc->flags |= ATA_QCFLAG_FAILED;
  388. qc->ap->flags |= ATA_FLAG_EH_PENDING;
  389. /* The following will fail if timeout has already expired.
  390. * ata_scsi_error() takes care of such scmds on EH entry.
  391. * Note that ATA_QCFLAG_FAILED is unconditionally set after
  392. * this function completes.
  393. */
  394. scsi_req_abort_cmd(qc->scsicmd);
  395. }
  396. /**
  397. * ata_port_schedule_eh - schedule error handling without a qc
  398. * @ap: ATA port to schedule EH for
  399. *
  400. * Schedule error handling for @ap. EH will kick in as soon as
  401. * all commands are drained.
  402. *
  403. * LOCKING:
  404. * spin_lock_irqsave(host_set lock)
  405. */
  406. void ata_port_schedule_eh(struct ata_port *ap)
  407. {
  408. WARN_ON(!ap->ops->error_handler);
  409. ap->flags |= ATA_FLAG_EH_PENDING;
  410. scsi_schedule_eh(ap->host);
  411. DPRINTK("port EH scheduled\n");
  412. }
  413. /**
  414. * ata_port_abort - abort all qc's on the port
  415. * @ap: ATA port to abort qc's for
  416. *
  417. * Abort all active qc's of @ap and schedule EH.
  418. *
  419. * LOCKING:
  420. * spin_lock_irqsave(host_set lock)
  421. *
  422. * RETURNS:
  423. * Number of aborted qc's.
  424. */
  425. int ata_port_abort(struct ata_port *ap)
  426. {
  427. int tag, nr_aborted = 0;
  428. WARN_ON(!ap->ops->error_handler);
  429. for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
  430. struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
  431. if (qc) {
  432. qc->flags |= ATA_QCFLAG_FAILED;
  433. ata_qc_complete(qc);
  434. nr_aborted++;
  435. }
  436. }
  437. if (!nr_aborted)
  438. ata_port_schedule_eh(ap);
  439. return nr_aborted;
  440. }
  441. /**
  442. * __ata_port_freeze - freeze port
  443. * @ap: ATA port to freeze
  444. *
  445. * This function is called when HSM violation or some other
  446. * condition disrupts normal operation of the port. Frozen port
  447. * is not allowed to perform any operation until the port is
  448. * thawed, which usually follows a successful reset.
  449. *
  450. * ap->ops->freeze() callback can be used for freezing the port
  451. * hardware-wise (e.g. mask interrupt and stop DMA engine). If a
  452. * port cannot be frozen hardware-wise, the interrupt handler
  453. * must ack and clear interrupts unconditionally while the port
  454. * is frozen.
  455. *
  456. * LOCKING:
  457. * spin_lock_irqsave(host_set lock)
  458. */
  459. static void __ata_port_freeze(struct ata_port *ap)
  460. {
  461. WARN_ON(!ap->ops->error_handler);
  462. if (ap->ops->freeze)
  463. ap->ops->freeze(ap);
  464. ap->flags |= ATA_FLAG_FROZEN;
  465. DPRINTK("ata%u port frozen\n", ap->id);
  466. }
  467. /**
  468. * ata_port_freeze - abort & freeze port
  469. * @ap: ATA port to freeze
  470. *
  471. * Abort and freeze @ap.
  472. *
  473. * LOCKING:
  474. * spin_lock_irqsave(host_set lock)
  475. *
  476. * RETURNS:
  477. * Number of aborted commands.
  478. */
  479. int ata_port_freeze(struct ata_port *ap)
  480. {
  481. int nr_aborted;
  482. WARN_ON(!ap->ops->error_handler);
  483. nr_aborted = ata_port_abort(ap);
  484. __ata_port_freeze(ap);
  485. return nr_aborted;
  486. }
  487. /**
  488. * ata_eh_freeze_port - EH helper to freeze port
  489. * @ap: ATA port to freeze
  490. *
  491. * Freeze @ap.
  492. *
  493. * LOCKING:
  494. * None.
  495. */
  496. void ata_eh_freeze_port(struct ata_port *ap)
  497. {
  498. unsigned long flags;
  499. if (!ap->ops->error_handler)
  500. return;
  501. spin_lock_irqsave(ap->lock, flags);
  502. __ata_port_freeze(ap);
  503. spin_unlock_irqrestore(ap->lock, flags);
  504. }
  505. /**
  506. * ata_port_thaw_port - EH helper to thaw port
  507. * @ap: ATA port to thaw
  508. *
  509. * Thaw frozen port @ap.
  510. *
  511. * LOCKING:
  512. * None.
  513. */
  514. void ata_eh_thaw_port(struct ata_port *ap)
  515. {
  516. unsigned long flags;
  517. if (!ap->ops->error_handler)
  518. return;
  519. spin_lock_irqsave(ap->lock, flags);
  520. ap->flags &= ~ATA_FLAG_FROZEN;
  521. if (ap->ops->thaw)
  522. ap->ops->thaw(ap);
  523. spin_unlock_irqrestore(ap->lock, flags);
  524. DPRINTK("ata%u port thawed\n", ap->id);
  525. }
  526. static void ata_eh_scsidone(struct scsi_cmnd *scmd)
  527. {
  528. /* nada */
  529. }
  530. static void __ata_eh_qc_complete(struct ata_queued_cmd *qc)
  531. {
  532. struct ata_port *ap = qc->ap;
  533. struct scsi_cmnd *scmd = qc->scsicmd;
  534. unsigned long flags;
  535. spin_lock_irqsave(ap->lock, flags);
  536. qc->scsidone = ata_eh_scsidone;
  537. __ata_qc_complete(qc);
  538. WARN_ON(ata_tag_valid(qc->tag));
  539. spin_unlock_irqrestore(ap->lock, flags);
  540. scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
  541. }
  542. /**
  543. * ata_eh_qc_complete - Complete an active ATA command from EH
  544. * @qc: Command to complete
  545. *
  546. * Indicate to the mid and upper layers that an ATA command has
  547. * completed. To be used from EH.
  548. */
  549. void ata_eh_qc_complete(struct ata_queued_cmd *qc)
  550. {
  551. struct scsi_cmnd *scmd = qc->scsicmd;
  552. scmd->retries = scmd->allowed;
  553. __ata_eh_qc_complete(qc);
  554. }
  555. /**
  556. * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
  557. * @qc: Command to retry
  558. *
  559. * Indicate to the mid and upper layers that an ATA command
  560. * should be retried. To be used from EH.
  561. *
  562. * SCSI midlayer limits the number of retries to scmd->allowed.
  563. * scmd->retries is decremented for commands which get retried
  564. * due to unrelated failures (qc->err_mask is zero).
  565. */
  566. void ata_eh_qc_retry(struct ata_queued_cmd *qc)
  567. {
  568. struct scsi_cmnd *scmd = qc->scsicmd;
  569. if (!qc->err_mask && scmd->retries)
  570. scmd->retries--;
  571. __ata_eh_qc_complete(qc);
  572. }
  573. /**
  574. * ata_eh_detach_dev - detach ATA device
  575. * @dev: ATA device to detach
  576. *
  577. * Detach @dev.
  578. *
  579. * LOCKING:
  580. * None.
  581. */
  582. static void ata_eh_detach_dev(struct ata_device *dev)
  583. {
  584. struct ata_port *ap = dev->ap;
  585. unsigned long flags;
  586. ata_dev_disable(dev);
  587. spin_lock_irqsave(ap->lock, flags);
  588. dev->flags &= ~ATA_DFLAG_DETACH;
  589. if (ata_scsi_offline_dev(dev)) {
  590. dev->flags |= ATA_DFLAG_DETACHED;
  591. ap->flags |= ATA_FLAG_SCSI_HOTPLUG;
  592. }
  593. spin_unlock_irqrestore(ap->lock, flags);
  594. }
  595. static void ata_eh_clear_action(struct ata_device *dev,
  596. struct ata_eh_info *ehi, unsigned int action)
  597. {
  598. int i;
  599. if (!dev) {
  600. ehi->action &= ~action;
  601. for (i = 0; i < ATA_MAX_DEVICES; i++)
  602. ehi->dev_action[i] &= ~action;
  603. } else {
  604. /* doesn't make sense for port-wide EH actions */
  605. WARN_ON(!(action & ATA_EH_PERDEV_MASK));
  606. /* break ehi->action into ehi->dev_action */
  607. if (ehi->action & action) {
  608. for (i = 0; i < ATA_MAX_DEVICES; i++)
  609. ehi->dev_action[i] |= ehi->action & action;
  610. ehi->action &= ~action;
  611. }
  612. /* turn off the specified per-dev action */
  613. ehi->dev_action[dev->devno] &= ~action;
  614. }
  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. }