libata-eh.c 45 KB

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