libata-eh.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969
  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/kernel.h>
  35. #include <linux/pci.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/scsi_transport_api.h"
  42. #include <linux/libata.h>
  43. #include "libata.h"
  44. enum {
  45. /* speed down verdicts */
  46. ATA_EH_SPDN_NCQ_OFF = (1 << 0),
  47. ATA_EH_SPDN_SPEED_DOWN = (1 << 1),
  48. ATA_EH_SPDN_FALLBACK_TO_PIO = (1 << 2),
  49. ATA_EH_SPDN_KEEP_ERRORS = (1 << 3),
  50. /* error flags */
  51. ATA_EFLAG_IS_IO = (1 << 0),
  52. ATA_EFLAG_DUBIOUS_XFER = (1 << 1),
  53. /* error categories */
  54. ATA_ECAT_NONE = 0,
  55. ATA_ECAT_ATA_BUS = 1,
  56. ATA_ECAT_TOUT_HSM = 2,
  57. ATA_ECAT_UNK_DEV = 3,
  58. ATA_ECAT_DUBIOUS_ATA_BUS = 4,
  59. ATA_ECAT_DUBIOUS_TOUT_HSM = 5,
  60. ATA_ECAT_DUBIOUS_UNK_DEV = 6,
  61. ATA_ECAT_NR = 7,
  62. ATA_ECAT_DUBIOUS_BASE = ATA_ECAT_DUBIOUS_ATA_BUS,
  63. };
  64. /* Waiting in ->prereset can never be reliable. It's sometimes nice
  65. * to wait there but it can't be depended upon; otherwise, we wouldn't
  66. * be resetting. Just give it enough time for most drives to spin up.
  67. */
  68. enum {
  69. ATA_EH_PRERESET_TIMEOUT = 10 * HZ,
  70. ATA_EH_FASTDRAIN_INTERVAL = 3 * HZ,
  71. };
  72. /* The following table determines how we sequence resets. Each entry
  73. * represents timeout for that try. The first try can be soft or
  74. * hardreset. All others are hardreset if available. In most cases
  75. * the first reset w/ 10sec timeout should succeed. Following entries
  76. * are mostly for error handling, hotplug and retarded devices.
  77. */
  78. static const unsigned long ata_eh_reset_timeouts[] = {
  79. 10 * HZ, /* most drives spin up by 10sec */
  80. 10 * HZ, /* > 99% working drives spin up before 20sec */
  81. 35 * HZ, /* give > 30 secs of idleness for retarded devices */
  82. 5 * HZ, /* and sweet one last chance */
  83. /* > 1 min has elapsed, give up */
  84. };
  85. static void __ata_port_freeze(struct ata_port *ap);
  86. #ifdef CONFIG_PM
  87. static void ata_eh_handle_port_suspend(struct ata_port *ap);
  88. static void ata_eh_handle_port_resume(struct ata_port *ap);
  89. #else /* CONFIG_PM */
  90. static void ata_eh_handle_port_suspend(struct ata_port *ap)
  91. { }
  92. static void ata_eh_handle_port_resume(struct ata_port *ap)
  93. { }
  94. #endif /* CONFIG_PM */
  95. static void __ata_ehi_pushv_desc(struct ata_eh_info *ehi, const char *fmt,
  96. va_list args)
  97. {
  98. ehi->desc_len += vscnprintf(ehi->desc + ehi->desc_len,
  99. ATA_EH_DESC_LEN - ehi->desc_len,
  100. fmt, args);
  101. }
  102. /**
  103. * __ata_ehi_push_desc - push error description without adding separator
  104. * @ehi: target EHI
  105. * @fmt: printf format string
  106. *
  107. * Format string according to @fmt and append it to @ehi->desc.
  108. *
  109. * LOCKING:
  110. * spin_lock_irqsave(host lock)
  111. */
  112. void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
  113. {
  114. va_list args;
  115. va_start(args, fmt);
  116. __ata_ehi_pushv_desc(ehi, fmt, args);
  117. va_end(args);
  118. }
  119. /**
  120. * ata_ehi_push_desc - push error description with separator
  121. * @ehi: target EHI
  122. * @fmt: printf format string
  123. *
  124. * Format string according to @fmt and append it to @ehi->desc.
  125. * If @ehi->desc is not empty, ", " is added in-between.
  126. *
  127. * LOCKING:
  128. * spin_lock_irqsave(host lock)
  129. */
  130. void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
  131. {
  132. va_list args;
  133. if (ehi->desc_len)
  134. __ata_ehi_push_desc(ehi, ", ");
  135. va_start(args, fmt);
  136. __ata_ehi_pushv_desc(ehi, fmt, args);
  137. va_end(args);
  138. }
  139. /**
  140. * ata_ehi_clear_desc - clean error description
  141. * @ehi: target EHI
  142. *
  143. * Clear @ehi->desc.
  144. *
  145. * LOCKING:
  146. * spin_lock_irqsave(host lock)
  147. */
  148. void ata_ehi_clear_desc(struct ata_eh_info *ehi)
  149. {
  150. ehi->desc[0] = '\0';
  151. ehi->desc_len = 0;
  152. }
  153. /**
  154. * ata_port_desc - append port description
  155. * @ap: target ATA port
  156. * @fmt: printf format string
  157. *
  158. * Format string according to @fmt and append it to port
  159. * description. If port description is not empty, " " is added
  160. * in-between. This function is to be used while initializing
  161. * ata_host. The description is printed on host registration.
  162. *
  163. * LOCKING:
  164. * None.
  165. */
  166. void ata_port_desc(struct ata_port *ap, const char *fmt, ...)
  167. {
  168. va_list args;
  169. WARN_ON(!(ap->pflags & ATA_PFLAG_INITIALIZING));
  170. if (ap->link.eh_info.desc_len)
  171. __ata_ehi_push_desc(&ap->link.eh_info, " ");
  172. va_start(args, fmt);
  173. __ata_ehi_pushv_desc(&ap->link.eh_info, fmt, args);
  174. va_end(args);
  175. }
  176. #ifdef CONFIG_PCI
  177. /**
  178. * ata_port_pbar_desc - append PCI BAR description
  179. * @ap: target ATA port
  180. * @bar: target PCI BAR
  181. * @offset: offset into PCI BAR
  182. * @name: name of the area
  183. *
  184. * If @offset is negative, this function formats a string which
  185. * contains the name, address, size and type of the BAR and
  186. * appends it to the port description. If @offset is zero or
  187. * positive, only name and offsetted address is appended.
  188. *
  189. * LOCKING:
  190. * None.
  191. */
  192. void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset,
  193. const char *name)
  194. {
  195. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  196. char *type = "";
  197. unsigned long long start, len;
  198. if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM)
  199. type = "m";
  200. else if (pci_resource_flags(pdev, bar) & IORESOURCE_IO)
  201. type = "i";
  202. start = (unsigned long long)pci_resource_start(pdev, bar);
  203. len = (unsigned long long)pci_resource_len(pdev, bar);
  204. if (offset < 0)
  205. ata_port_desc(ap, "%s %s%llu@0x%llx", name, type, len, start);
  206. else
  207. ata_port_desc(ap, "%s 0x%llx", name, start + offset);
  208. }
  209. #endif /* CONFIG_PCI */
  210. static void ata_ering_record(struct ata_ering *ering, unsigned int eflags,
  211. unsigned int err_mask)
  212. {
  213. struct ata_ering_entry *ent;
  214. WARN_ON(!err_mask);
  215. ering->cursor++;
  216. ering->cursor %= ATA_ERING_SIZE;
  217. ent = &ering->ring[ering->cursor];
  218. ent->eflags = eflags;
  219. ent->err_mask = err_mask;
  220. ent->timestamp = get_jiffies_64();
  221. }
  222. static struct ata_ering_entry *ata_ering_top(struct ata_ering *ering)
  223. {
  224. struct ata_ering_entry *ent = &ering->ring[ering->cursor];
  225. if (ent->err_mask)
  226. return ent;
  227. return NULL;
  228. }
  229. static void ata_ering_clear(struct ata_ering *ering)
  230. {
  231. memset(ering, 0, sizeof(*ering));
  232. }
  233. static int ata_ering_map(struct ata_ering *ering,
  234. int (*map_fn)(struct ata_ering_entry *, void *),
  235. void *arg)
  236. {
  237. int idx, rc = 0;
  238. struct ata_ering_entry *ent;
  239. idx = ering->cursor;
  240. do {
  241. ent = &ering->ring[idx];
  242. if (!ent->err_mask)
  243. break;
  244. rc = map_fn(ent, arg);
  245. if (rc)
  246. break;
  247. idx = (idx - 1 + ATA_ERING_SIZE) % ATA_ERING_SIZE;
  248. } while (idx != ering->cursor);
  249. return rc;
  250. }
  251. static unsigned int ata_eh_dev_action(struct ata_device *dev)
  252. {
  253. struct ata_eh_context *ehc = &dev->link->eh_context;
  254. return ehc->i.action | ehc->i.dev_action[dev->devno];
  255. }
  256. static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev,
  257. struct ata_eh_info *ehi, unsigned int action)
  258. {
  259. struct ata_device *tdev;
  260. if (!dev) {
  261. ehi->action &= ~action;
  262. ata_link_for_each_dev(tdev, link)
  263. ehi->dev_action[tdev->devno] &= ~action;
  264. } else {
  265. /* doesn't make sense for port-wide EH actions */
  266. WARN_ON(!(action & ATA_EH_PERDEV_MASK));
  267. /* break ehi->action into ehi->dev_action */
  268. if (ehi->action & action) {
  269. ata_link_for_each_dev(tdev, link)
  270. ehi->dev_action[tdev->devno] |=
  271. ehi->action & action;
  272. ehi->action &= ~action;
  273. }
  274. /* turn off the specified per-dev action */
  275. ehi->dev_action[dev->devno] &= ~action;
  276. }
  277. }
  278. /**
  279. * ata_scsi_timed_out - SCSI layer time out callback
  280. * @cmd: timed out SCSI command
  281. *
  282. * Handles SCSI layer timeout. We race with normal completion of
  283. * the qc for @cmd. If the qc is already gone, we lose and let
  284. * the scsi command finish (EH_HANDLED). Otherwise, the qc has
  285. * timed out and EH should be invoked. Prevent ata_qc_complete()
  286. * from finishing it by setting EH_SCHEDULED and return
  287. * EH_NOT_HANDLED.
  288. *
  289. * TODO: kill this function once old EH is gone.
  290. *
  291. * LOCKING:
  292. * Called from timer context
  293. *
  294. * RETURNS:
  295. * EH_HANDLED or EH_NOT_HANDLED
  296. */
  297. enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
  298. {
  299. struct Scsi_Host *host = cmd->device->host;
  300. struct ata_port *ap = ata_shost_to_port(host);
  301. unsigned long flags;
  302. struct ata_queued_cmd *qc;
  303. enum scsi_eh_timer_return ret;
  304. DPRINTK("ENTER\n");
  305. if (ap->ops->error_handler) {
  306. ret = EH_NOT_HANDLED;
  307. goto out;
  308. }
  309. ret = EH_HANDLED;
  310. spin_lock_irqsave(ap->lock, flags);
  311. qc = ata_qc_from_tag(ap, ap->link.active_tag);
  312. if (qc) {
  313. WARN_ON(qc->scsicmd != cmd);
  314. qc->flags |= ATA_QCFLAG_EH_SCHEDULED;
  315. qc->err_mask |= AC_ERR_TIMEOUT;
  316. ret = EH_NOT_HANDLED;
  317. }
  318. spin_unlock_irqrestore(ap->lock, flags);
  319. out:
  320. DPRINTK("EXIT, ret=%d\n", ret);
  321. return ret;
  322. }
  323. /**
  324. * ata_scsi_error - SCSI layer error handler callback
  325. * @host: SCSI host on which error occurred
  326. *
  327. * Handles SCSI-layer-thrown error events.
  328. *
  329. * LOCKING:
  330. * Inherited from SCSI layer (none, can sleep)
  331. *
  332. * RETURNS:
  333. * Zero.
  334. */
  335. void ata_scsi_error(struct Scsi_Host *host)
  336. {
  337. struct ata_port *ap = ata_shost_to_port(host);
  338. int i;
  339. unsigned long flags;
  340. DPRINTK("ENTER\n");
  341. /* synchronize with port task */
  342. ata_port_flush_task(ap);
  343. /* synchronize with host lock and sort out timeouts */
  344. /* For new EH, all qcs are finished in one of three ways -
  345. * normal completion, error completion, and SCSI timeout.
  346. * Both cmpletions can race against SCSI timeout. When normal
  347. * completion wins, the qc never reaches EH. When error
  348. * completion wins, the qc has ATA_QCFLAG_FAILED set.
  349. *
  350. * When SCSI timeout wins, things are a bit more complex.
  351. * Normal or error completion can occur after the timeout but
  352. * before this point. In such cases, both types of
  353. * completions are honored. A scmd is determined to have
  354. * timed out iff its associated qc is active and not failed.
  355. */
  356. if (ap->ops->error_handler) {
  357. struct scsi_cmnd *scmd, *tmp;
  358. int nr_timedout = 0;
  359. spin_lock_irqsave(ap->lock, flags);
  360. list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) {
  361. struct ata_queued_cmd *qc;
  362. for (i = 0; i < ATA_MAX_QUEUE; i++) {
  363. qc = __ata_qc_from_tag(ap, i);
  364. if (qc->flags & ATA_QCFLAG_ACTIVE &&
  365. qc->scsicmd == scmd)
  366. break;
  367. }
  368. if (i < ATA_MAX_QUEUE) {
  369. /* the scmd has an associated qc */
  370. if (!(qc->flags & ATA_QCFLAG_FAILED)) {
  371. /* which hasn't failed yet, timeout */
  372. qc->err_mask |= AC_ERR_TIMEOUT;
  373. qc->flags |= ATA_QCFLAG_FAILED;
  374. nr_timedout++;
  375. }
  376. } else {
  377. /* Normal completion occurred after
  378. * SCSI timeout but before this point.
  379. * Successfully complete it.
  380. */
  381. scmd->retries = scmd->allowed;
  382. scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
  383. }
  384. }
  385. /* If we have timed out qcs. They belong to EH from
  386. * this point but the state of the controller is
  387. * unknown. Freeze the port to make sure the IRQ
  388. * handler doesn't diddle with those qcs. This must
  389. * be done atomically w.r.t. setting QCFLAG_FAILED.
  390. */
  391. if (nr_timedout)
  392. __ata_port_freeze(ap);
  393. spin_unlock_irqrestore(ap->lock, flags);
  394. /* initialize eh_tries */
  395. ap->eh_tries = ATA_EH_MAX_TRIES;
  396. } else
  397. spin_unlock_wait(ap->lock);
  398. repeat:
  399. /* invoke error handler */
  400. if (ap->ops->error_handler) {
  401. struct ata_link *link;
  402. /* kill fast drain timer */
  403. del_timer_sync(&ap->fastdrain_timer);
  404. /* process port resume request */
  405. ata_eh_handle_port_resume(ap);
  406. /* fetch & clear EH info */
  407. spin_lock_irqsave(ap->lock, flags);
  408. __ata_port_for_each_link(link, ap) {
  409. struct ata_eh_context *ehc = &link->eh_context;
  410. struct ata_device *dev;
  411. memset(&link->eh_context, 0, sizeof(link->eh_context));
  412. link->eh_context.i = link->eh_info;
  413. memset(&link->eh_info, 0, sizeof(link->eh_info));
  414. ata_link_for_each_dev(dev, link) {
  415. int devno = dev->devno;
  416. ehc->saved_xfer_mode[devno] = dev->xfer_mode;
  417. if (ata_ncq_enabled(dev))
  418. ehc->saved_ncq_enabled |= 1 << devno;
  419. }
  420. }
  421. ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS;
  422. ap->pflags &= ~ATA_PFLAG_EH_PENDING;
  423. ap->excl_link = NULL; /* don't maintain exclusion over EH */
  424. spin_unlock_irqrestore(ap->lock, flags);
  425. /* invoke EH, skip if unloading or suspended */
  426. if (!(ap->pflags & (ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED)))
  427. ap->ops->error_handler(ap);
  428. else
  429. ata_eh_finish(ap);
  430. /* process port suspend request */
  431. ata_eh_handle_port_suspend(ap);
  432. /* Exception might have happend after ->error_handler
  433. * recovered the port but before this point. Repeat
  434. * EH in such case.
  435. */
  436. spin_lock_irqsave(ap->lock, flags);
  437. if (ap->pflags & ATA_PFLAG_EH_PENDING) {
  438. if (--ap->eh_tries) {
  439. spin_unlock_irqrestore(ap->lock, flags);
  440. goto repeat;
  441. }
  442. ata_port_printk(ap, KERN_ERR, "EH pending after %d "
  443. "tries, giving up\n", ATA_EH_MAX_TRIES);
  444. ap->pflags &= ~ATA_PFLAG_EH_PENDING;
  445. }
  446. /* this run is complete, make sure EH info is clear */
  447. __ata_port_for_each_link(link, ap)
  448. memset(&link->eh_info, 0, sizeof(link->eh_info));
  449. /* Clear host_eh_scheduled while holding ap->lock such
  450. * that if exception occurs after this point but
  451. * before EH completion, SCSI midlayer will
  452. * re-initiate EH.
  453. */
  454. host->host_eh_scheduled = 0;
  455. spin_unlock_irqrestore(ap->lock, flags);
  456. } else {
  457. WARN_ON(ata_qc_from_tag(ap, ap->link.active_tag) == NULL);
  458. ap->ops->eng_timeout(ap);
  459. }
  460. /* finish or retry handled scmd's and clean up */
  461. WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q));
  462. scsi_eh_flush_done_q(&ap->eh_done_q);
  463. /* clean up */
  464. spin_lock_irqsave(ap->lock, flags);
  465. if (ap->pflags & ATA_PFLAG_LOADING)
  466. ap->pflags &= ~ATA_PFLAG_LOADING;
  467. else if (ap->pflags & ATA_PFLAG_SCSI_HOTPLUG)
  468. queue_delayed_work(ata_aux_wq, &ap->hotplug_task, 0);
  469. if (ap->pflags & ATA_PFLAG_RECOVERED)
  470. ata_port_printk(ap, KERN_INFO, "EH complete\n");
  471. ap->pflags &= ~(ATA_PFLAG_SCSI_HOTPLUG | ATA_PFLAG_RECOVERED);
  472. /* tell wait_eh that we're done */
  473. ap->pflags &= ~ATA_PFLAG_EH_IN_PROGRESS;
  474. wake_up_all(&ap->eh_wait_q);
  475. spin_unlock_irqrestore(ap->lock, flags);
  476. DPRINTK("EXIT\n");
  477. }
  478. /**
  479. * ata_port_wait_eh - Wait for the currently pending EH to complete
  480. * @ap: Port to wait EH for
  481. *
  482. * Wait until the currently pending EH is complete.
  483. *
  484. * LOCKING:
  485. * Kernel thread context (may sleep).
  486. */
  487. void ata_port_wait_eh(struct ata_port *ap)
  488. {
  489. unsigned long flags;
  490. DEFINE_WAIT(wait);
  491. retry:
  492. spin_lock_irqsave(ap->lock, flags);
  493. while (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) {
  494. prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE);
  495. spin_unlock_irqrestore(ap->lock, flags);
  496. schedule();
  497. spin_lock_irqsave(ap->lock, flags);
  498. }
  499. finish_wait(&ap->eh_wait_q, &wait);
  500. spin_unlock_irqrestore(ap->lock, flags);
  501. /* make sure SCSI EH is complete */
  502. if (scsi_host_in_recovery(ap->scsi_host)) {
  503. msleep(10);
  504. goto retry;
  505. }
  506. }
  507. static int ata_eh_nr_in_flight(struct ata_port *ap)
  508. {
  509. unsigned int tag;
  510. int nr = 0;
  511. /* count only non-internal commands */
  512. for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++)
  513. if (ata_qc_from_tag(ap, tag))
  514. nr++;
  515. return nr;
  516. }
  517. void ata_eh_fastdrain_timerfn(unsigned long arg)
  518. {
  519. struct ata_port *ap = (void *)arg;
  520. unsigned long flags;
  521. int cnt;
  522. spin_lock_irqsave(ap->lock, flags);
  523. cnt = ata_eh_nr_in_flight(ap);
  524. /* are we done? */
  525. if (!cnt)
  526. goto out_unlock;
  527. if (cnt == ap->fastdrain_cnt) {
  528. unsigned int tag;
  529. /* No progress during the last interval, tag all
  530. * in-flight qcs as timed out and freeze the port.
  531. */
  532. for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++) {
  533. struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
  534. if (qc)
  535. qc->err_mask |= AC_ERR_TIMEOUT;
  536. }
  537. ata_port_freeze(ap);
  538. } else {
  539. /* some qcs have finished, give it another chance */
  540. ap->fastdrain_cnt = cnt;
  541. ap->fastdrain_timer.expires =
  542. jiffies + ATA_EH_FASTDRAIN_INTERVAL;
  543. add_timer(&ap->fastdrain_timer);
  544. }
  545. out_unlock:
  546. spin_unlock_irqrestore(ap->lock, flags);
  547. }
  548. /**
  549. * ata_eh_set_pending - set ATA_PFLAG_EH_PENDING and activate fast drain
  550. * @ap: target ATA port
  551. * @fastdrain: activate fast drain
  552. *
  553. * Set ATA_PFLAG_EH_PENDING and activate fast drain if @fastdrain
  554. * is non-zero and EH wasn't pending before. Fast drain ensures
  555. * that EH kicks in in timely manner.
  556. *
  557. * LOCKING:
  558. * spin_lock_irqsave(host lock)
  559. */
  560. static void ata_eh_set_pending(struct ata_port *ap, int fastdrain)
  561. {
  562. int cnt;
  563. /* already scheduled? */
  564. if (ap->pflags & ATA_PFLAG_EH_PENDING)
  565. return;
  566. ap->pflags |= ATA_PFLAG_EH_PENDING;
  567. if (!fastdrain)
  568. return;
  569. /* do we have in-flight qcs? */
  570. cnt = ata_eh_nr_in_flight(ap);
  571. if (!cnt)
  572. return;
  573. /* activate fast drain */
  574. ap->fastdrain_cnt = cnt;
  575. ap->fastdrain_timer.expires = jiffies + ATA_EH_FASTDRAIN_INTERVAL;
  576. add_timer(&ap->fastdrain_timer);
  577. }
  578. /**
  579. * ata_qc_schedule_eh - schedule qc for error handling
  580. * @qc: command to schedule error handling for
  581. *
  582. * Schedule error handling for @qc. EH will kick in as soon as
  583. * other commands are drained.
  584. *
  585. * LOCKING:
  586. * spin_lock_irqsave(host lock)
  587. */
  588. void ata_qc_schedule_eh(struct ata_queued_cmd *qc)
  589. {
  590. struct ata_port *ap = qc->ap;
  591. WARN_ON(!ap->ops->error_handler);
  592. qc->flags |= ATA_QCFLAG_FAILED;
  593. ata_eh_set_pending(ap, 1);
  594. /* The following will fail if timeout has already expired.
  595. * ata_scsi_error() takes care of such scmds on EH entry.
  596. * Note that ATA_QCFLAG_FAILED is unconditionally set after
  597. * this function completes.
  598. */
  599. scsi_req_abort_cmd(qc->scsicmd);
  600. }
  601. /**
  602. * ata_port_schedule_eh - schedule error handling without a qc
  603. * @ap: ATA port to schedule EH for
  604. *
  605. * Schedule error handling for @ap. EH will kick in as soon as
  606. * all commands are drained.
  607. *
  608. * LOCKING:
  609. * spin_lock_irqsave(host lock)
  610. */
  611. void ata_port_schedule_eh(struct ata_port *ap)
  612. {
  613. WARN_ON(!ap->ops->error_handler);
  614. if (ap->pflags & ATA_PFLAG_INITIALIZING)
  615. return;
  616. ata_eh_set_pending(ap, 1);
  617. scsi_schedule_eh(ap->scsi_host);
  618. DPRINTK("port EH scheduled\n");
  619. }
  620. static int ata_do_link_abort(struct ata_port *ap, struct ata_link *link)
  621. {
  622. int tag, nr_aborted = 0;
  623. WARN_ON(!ap->ops->error_handler);
  624. /* we're gonna abort all commands, no need for fast drain */
  625. ata_eh_set_pending(ap, 0);
  626. for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
  627. struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
  628. if (qc && (!link || qc->dev->link == link)) {
  629. qc->flags |= ATA_QCFLAG_FAILED;
  630. ata_qc_complete(qc);
  631. nr_aborted++;
  632. }
  633. }
  634. if (!nr_aborted)
  635. ata_port_schedule_eh(ap);
  636. return nr_aborted;
  637. }
  638. /**
  639. * ata_link_abort - abort all qc's on the link
  640. * @link: ATA link to abort qc's for
  641. *
  642. * Abort all active qc's active on @link and schedule EH.
  643. *
  644. * LOCKING:
  645. * spin_lock_irqsave(host lock)
  646. *
  647. * RETURNS:
  648. * Number of aborted qc's.
  649. */
  650. int ata_link_abort(struct ata_link *link)
  651. {
  652. return ata_do_link_abort(link->ap, link);
  653. }
  654. /**
  655. * ata_port_abort - abort all qc's on the port
  656. * @ap: ATA port to abort qc's for
  657. *
  658. * Abort all active qc's of @ap and schedule EH.
  659. *
  660. * LOCKING:
  661. * spin_lock_irqsave(host_set lock)
  662. *
  663. * RETURNS:
  664. * Number of aborted qc's.
  665. */
  666. int ata_port_abort(struct ata_port *ap)
  667. {
  668. return ata_do_link_abort(ap, NULL);
  669. }
  670. /**
  671. * __ata_port_freeze - freeze port
  672. * @ap: ATA port to freeze
  673. *
  674. * This function is called when HSM violation or some other
  675. * condition disrupts normal operation of the port. Frozen port
  676. * is not allowed to perform any operation until the port is
  677. * thawed, which usually follows a successful reset.
  678. *
  679. * ap->ops->freeze() callback can be used for freezing the port
  680. * hardware-wise (e.g. mask interrupt and stop DMA engine). If a
  681. * port cannot be frozen hardware-wise, the interrupt handler
  682. * must ack and clear interrupts unconditionally while the port
  683. * is frozen.
  684. *
  685. * LOCKING:
  686. * spin_lock_irqsave(host lock)
  687. */
  688. static void __ata_port_freeze(struct ata_port *ap)
  689. {
  690. WARN_ON(!ap->ops->error_handler);
  691. if (ap->ops->freeze)
  692. ap->ops->freeze(ap);
  693. ap->pflags |= ATA_PFLAG_FROZEN;
  694. DPRINTK("ata%u port frozen\n", ap->print_id);
  695. }
  696. /**
  697. * ata_port_freeze - abort & freeze port
  698. * @ap: ATA port to freeze
  699. *
  700. * Abort and freeze @ap.
  701. *
  702. * LOCKING:
  703. * spin_lock_irqsave(host lock)
  704. *
  705. * RETURNS:
  706. * Number of aborted commands.
  707. */
  708. int ata_port_freeze(struct ata_port *ap)
  709. {
  710. int nr_aborted;
  711. WARN_ON(!ap->ops->error_handler);
  712. nr_aborted = ata_port_abort(ap);
  713. __ata_port_freeze(ap);
  714. return nr_aborted;
  715. }
  716. /**
  717. * sata_async_notification - SATA async notification handler
  718. * @ap: ATA port where async notification is received
  719. *
  720. * Handler to be called when async notification via SDB FIS is
  721. * received. This function schedules EH if necessary.
  722. *
  723. * LOCKING:
  724. * spin_lock_irqsave(host lock)
  725. *
  726. * RETURNS:
  727. * 1 if EH is scheduled, 0 otherwise.
  728. */
  729. int sata_async_notification(struct ata_port *ap)
  730. {
  731. u32 sntf;
  732. int rc;
  733. if (!(ap->flags & ATA_FLAG_AN))
  734. return 0;
  735. rc = sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf);
  736. if (rc == 0)
  737. sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf);
  738. if (!ap->nr_pmp_links || rc) {
  739. /* PMP is not attached or SNTF is not available */
  740. if (!ap->nr_pmp_links) {
  741. /* PMP is not attached. Check whether ATAPI
  742. * AN is configured. If so, notify media
  743. * change.
  744. */
  745. struct ata_device *dev = ap->link.device;
  746. if ((dev->class == ATA_DEV_ATAPI) &&
  747. (dev->flags & ATA_DFLAG_AN))
  748. ata_scsi_media_change_notify(dev);
  749. return 0;
  750. } else {
  751. /* PMP is attached but SNTF is not available.
  752. * ATAPI async media change notification is
  753. * not used. The PMP must be reporting PHY
  754. * status change, schedule EH.
  755. */
  756. ata_port_schedule_eh(ap);
  757. return 1;
  758. }
  759. } else {
  760. /* PMP is attached and SNTF is available */
  761. struct ata_link *link;
  762. /* check and notify ATAPI AN */
  763. ata_port_for_each_link(link, ap) {
  764. if (!(sntf & (1 << link->pmp)))
  765. continue;
  766. if ((link->device->class == ATA_DEV_ATAPI) &&
  767. (link->device->flags & ATA_DFLAG_AN))
  768. ata_scsi_media_change_notify(link->device);
  769. }
  770. /* If PMP is reporting that PHY status of some
  771. * downstream ports has changed, schedule EH.
  772. */
  773. if (sntf & (1 << SATA_PMP_CTRL_PORT)) {
  774. ata_port_schedule_eh(ap);
  775. return 1;
  776. }
  777. return 0;
  778. }
  779. }
  780. /**
  781. * ata_eh_freeze_port - EH helper to freeze port
  782. * @ap: ATA port to freeze
  783. *
  784. * Freeze @ap.
  785. *
  786. * LOCKING:
  787. * None.
  788. */
  789. void ata_eh_freeze_port(struct ata_port *ap)
  790. {
  791. unsigned long flags;
  792. if (!ap->ops->error_handler)
  793. return;
  794. spin_lock_irqsave(ap->lock, flags);
  795. __ata_port_freeze(ap);
  796. spin_unlock_irqrestore(ap->lock, flags);
  797. }
  798. /**
  799. * ata_port_thaw_port - EH helper to thaw port
  800. * @ap: ATA port to thaw
  801. *
  802. * Thaw frozen port @ap.
  803. *
  804. * LOCKING:
  805. * None.
  806. */
  807. void ata_eh_thaw_port(struct ata_port *ap)
  808. {
  809. unsigned long flags;
  810. if (!ap->ops->error_handler)
  811. return;
  812. spin_lock_irqsave(ap->lock, flags);
  813. ap->pflags &= ~ATA_PFLAG_FROZEN;
  814. if (ap->ops->thaw)
  815. ap->ops->thaw(ap);
  816. spin_unlock_irqrestore(ap->lock, flags);
  817. DPRINTK("ata%u port thawed\n", ap->print_id);
  818. }
  819. static void ata_eh_scsidone(struct scsi_cmnd *scmd)
  820. {
  821. /* nada */
  822. }
  823. static void __ata_eh_qc_complete(struct ata_queued_cmd *qc)
  824. {
  825. struct ata_port *ap = qc->ap;
  826. struct scsi_cmnd *scmd = qc->scsicmd;
  827. unsigned long flags;
  828. spin_lock_irqsave(ap->lock, flags);
  829. qc->scsidone = ata_eh_scsidone;
  830. __ata_qc_complete(qc);
  831. WARN_ON(ata_tag_valid(qc->tag));
  832. spin_unlock_irqrestore(ap->lock, flags);
  833. scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
  834. }
  835. /**
  836. * ata_eh_qc_complete - Complete an active ATA command from EH
  837. * @qc: Command to complete
  838. *
  839. * Indicate to the mid and upper layers that an ATA command has
  840. * completed. To be used from EH.
  841. */
  842. void ata_eh_qc_complete(struct ata_queued_cmd *qc)
  843. {
  844. struct scsi_cmnd *scmd = qc->scsicmd;
  845. scmd->retries = scmd->allowed;
  846. __ata_eh_qc_complete(qc);
  847. }
  848. /**
  849. * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
  850. * @qc: Command to retry
  851. *
  852. * Indicate to the mid and upper layers that an ATA command
  853. * should be retried. To be used from EH.
  854. *
  855. * SCSI midlayer limits the number of retries to scmd->allowed.
  856. * scmd->retries is decremented for commands which get retried
  857. * due to unrelated failures (qc->err_mask is zero).
  858. */
  859. void ata_eh_qc_retry(struct ata_queued_cmd *qc)
  860. {
  861. struct scsi_cmnd *scmd = qc->scsicmd;
  862. if (!qc->err_mask && scmd->retries)
  863. scmd->retries--;
  864. __ata_eh_qc_complete(qc);
  865. }
  866. /**
  867. * ata_eh_detach_dev - detach ATA device
  868. * @dev: ATA device to detach
  869. *
  870. * Detach @dev.
  871. *
  872. * LOCKING:
  873. * None.
  874. */
  875. void ata_eh_detach_dev(struct ata_device *dev)
  876. {
  877. struct ata_link *link = dev->link;
  878. struct ata_port *ap = link->ap;
  879. unsigned long flags;
  880. ata_dev_disable(dev);
  881. spin_lock_irqsave(ap->lock, flags);
  882. dev->flags &= ~ATA_DFLAG_DETACH;
  883. if (ata_scsi_offline_dev(dev)) {
  884. dev->flags |= ATA_DFLAG_DETACHED;
  885. ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
  886. }
  887. /* clear per-dev EH actions */
  888. ata_eh_clear_action(link, dev, &link->eh_info, ATA_EH_PERDEV_MASK);
  889. ata_eh_clear_action(link, dev, &link->eh_context.i, ATA_EH_PERDEV_MASK);
  890. spin_unlock_irqrestore(ap->lock, flags);
  891. }
  892. /**
  893. * ata_eh_about_to_do - about to perform eh_action
  894. * @link: target ATA link
  895. * @dev: target ATA dev for per-dev action (can be NULL)
  896. * @action: action about to be performed
  897. *
  898. * Called just before performing EH actions to clear related bits
  899. * in @link->eh_info such that eh actions are not unnecessarily
  900. * repeated.
  901. *
  902. * LOCKING:
  903. * None.
  904. */
  905. void ata_eh_about_to_do(struct ata_link *link, struct ata_device *dev,
  906. unsigned int action)
  907. {
  908. struct ata_port *ap = link->ap;
  909. struct ata_eh_info *ehi = &link->eh_info;
  910. struct ata_eh_context *ehc = &link->eh_context;
  911. unsigned long flags;
  912. spin_lock_irqsave(ap->lock, flags);
  913. /* Reset is represented by combination of actions and EHI
  914. * flags. Suck in all related bits before clearing eh_info to
  915. * avoid losing requested action.
  916. */
  917. if (action & ATA_EH_RESET_MASK) {
  918. ehc->i.action |= ehi->action & ATA_EH_RESET_MASK;
  919. ehc->i.flags |= ehi->flags & ATA_EHI_RESET_MODIFIER_MASK;
  920. /* make sure all reset actions are cleared & clear EHI flags */
  921. action |= ATA_EH_RESET_MASK;
  922. ehi->flags &= ~ATA_EHI_RESET_MODIFIER_MASK;
  923. }
  924. ata_eh_clear_action(link, dev, ehi, action);
  925. if (!(ehc->i.flags & ATA_EHI_QUIET))
  926. ap->pflags |= ATA_PFLAG_RECOVERED;
  927. spin_unlock_irqrestore(ap->lock, flags);
  928. }
  929. /**
  930. * ata_eh_done - EH action complete
  931. * @ap: target ATA port
  932. * @dev: target ATA dev for per-dev action (can be NULL)
  933. * @action: action just completed
  934. *
  935. * Called right after performing EH actions to clear related bits
  936. * in @link->eh_context.
  937. *
  938. * LOCKING:
  939. * None.
  940. */
  941. void ata_eh_done(struct ata_link *link, struct ata_device *dev,
  942. unsigned int action)
  943. {
  944. struct ata_eh_context *ehc = &link->eh_context;
  945. /* if reset is complete, clear all reset actions & reset modifier */
  946. if (action & ATA_EH_RESET_MASK) {
  947. action |= ATA_EH_RESET_MASK;
  948. ehc->i.flags &= ~ATA_EHI_RESET_MODIFIER_MASK;
  949. }
  950. ata_eh_clear_action(link, dev, &ehc->i, action);
  951. }
  952. /**
  953. * ata_err_string - convert err_mask to descriptive string
  954. * @err_mask: error mask to convert to string
  955. *
  956. * Convert @err_mask to descriptive string. Errors are
  957. * prioritized according to severity and only the most severe
  958. * error is reported.
  959. *
  960. * LOCKING:
  961. * None.
  962. *
  963. * RETURNS:
  964. * Descriptive string for @err_mask
  965. */
  966. static const char *ata_err_string(unsigned int err_mask)
  967. {
  968. if (err_mask & AC_ERR_HOST_BUS)
  969. return "host bus error";
  970. if (err_mask & AC_ERR_ATA_BUS)
  971. return "ATA bus error";
  972. if (err_mask & AC_ERR_TIMEOUT)
  973. return "timeout";
  974. if (err_mask & AC_ERR_HSM)
  975. return "HSM violation";
  976. if (err_mask & AC_ERR_SYSTEM)
  977. return "internal error";
  978. if (err_mask & AC_ERR_MEDIA)
  979. return "media error";
  980. if (err_mask & AC_ERR_INVALID)
  981. return "invalid argument";
  982. if (err_mask & AC_ERR_DEV)
  983. return "device error";
  984. return "unknown error";
  985. }
  986. /**
  987. * ata_read_log_page - read a specific log page
  988. * @dev: target device
  989. * @page: page to read
  990. * @buf: buffer to store read page
  991. * @sectors: number of sectors to read
  992. *
  993. * Read log page using READ_LOG_EXT command.
  994. *
  995. * LOCKING:
  996. * Kernel thread context (may sleep).
  997. *
  998. * RETURNS:
  999. * 0 on success, AC_ERR_* mask otherwise.
  1000. */
  1001. static unsigned int ata_read_log_page(struct ata_device *dev,
  1002. u8 page, void *buf, unsigned int sectors)
  1003. {
  1004. struct ata_taskfile tf;
  1005. unsigned int err_mask;
  1006. DPRINTK("read log page - page %d\n", page);
  1007. ata_tf_init(dev, &tf);
  1008. tf.command = ATA_CMD_READ_LOG_EXT;
  1009. tf.lbal = page;
  1010. tf.nsect = sectors;
  1011. tf.hob_nsect = sectors >> 8;
  1012. tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_LBA48 | ATA_TFLAG_DEVICE;
  1013. tf.protocol = ATA_PROT_PIO;
  1014. err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE,
  1015. buf, sectors * ATA_SECT_SIZE, 0);
  1016. DPRINTK("EXIT, err_mask=%x\n", err_mask);
  1017. return err_mask;
  1018. }
  1019. /**
  1020. * ata_eh_read_log_10h - Read log page 10h for NCQ error details
  1021. * @dev: Device to read log page 10h from
  1022. * @tag: Resulting tag of the failed command
  1023. * @tf: Resulting taskfile registers of the failed command
  1024. *
  1025. * Read log page 10h to obtain NCQ error details and clear error
  1026. * condition.
  1027. *
  1028. * LOCKING:
  1029. * Kernel thread context (may sleep).
  1030. *
  1031. * RETURNS:
  1032. * 0 on success, -errno otherwise.
  1033. */
  1034. static int ata_eh_read_log_10h(struct ata_device *dev,
  1035. int *tag, struct ata_taskfile *tf)
  1036. {
  1037. u8 *buf = dev->link->ap->sector_buf;
  1038. unsigned int err_mask;
  1039. u8 csum;
  1040. int i;
  1041. err_mask = ata_read_log_page(dev, ATA_LOG_SATA_NCQ, buf, 1);
  1042. if (err_mask)
  1043. return -EIO;
  1044. csum = 0;
  1045. for (i = 0; i < ATA_SECT_SIZE; i++)
  1046. csum += buf[i];
  1047. if (csum)
  1048. ata_dev_printk(dev, KERN_WARNING,
  1049. "invalid checksum 0x%x on log page 10h\n", csum);
  1050. if (buf[0] & 0x80)
  1051. return -ENOENT;
  1052. *tag = buf[0] & 0x1f;
  1053. tf->command = buf[2];
  1054. tf->feature = buf[3];
  1055. tf->lbal = buf[4];
  1056. tf->lbam = buf[5];
  1057. tf->lbah = buf[6];
  1058. tf->device = buf[7];
  1059. tf->hob_lbal = buf[8];
  1060. tf->hob_lbam = buf[9];
  1061. tf->hob_lbah = buf[10];
  1062. tf->nsect = buf[12];
  1063. tf->hob_nsect = buf[13];
  1064. return 0;
  1065. }
  1066. /**
  1067. * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE
  1068. * @dev: device to perform REQUEST_SENSE to
  1069. * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long)
  1070. *
  1071. * Perform ATAPI REQUEST_SENSE after the device reported CHECK
  1072. * SENSE. This function is EH helper.
  1073. *
  1074. * LOCKING:
  1075. * Kernel thread context (may sleep).
  1076. *
  1077. * RETURNS:
  1078. * 0 on success, AC_ERR_* mask on failure
  1079. */
  1080. static unsigned int atapi_eh_request_sense(struct ata_queued_cmd *qc)
  1081. {
  1082. struct ata_device *dev = qc->dev;
  1083. unsigned char *sense_buf = qc->scsicmd->sense_buffer;
  1084. struct ata_port *ap = dev->link->ap;
  1085. struct ata_taskfile tf;
  1086. u8 cdb[ATAPI_CDB_LEN];
  1087. DPRINTK("ATAPI request sense\n");
  1088. /* FIXME: is this needed? */
  1089. memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
  1090. /* initialize sense_buf with the error register,
  1091. * for the case where they are -not- overwritten
  1092. */
  1093. sense_buf[0] = 0x70;
  1094. sense_buf[2] = qc->result_tf.feature >> 4;
  1095. /* some devices time out if garbage left in tf */
  1096. ata_tf_init(dev, &tf);
  1097. memset(cdb, 0, ATAPI_CDB_LEN);
  1098. cdb[0] = REQUEST_SENSE;
  1099. cdb[4] = SCSI_SENSE_BUFFERSIZE;
  1100. tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
  1101. tf.command = ATA_CMD_PACKET;
  1102. /* is it pointless to prefer PIO for "safety reasons"? */
  1103. if (ap->flags & ATA_FLAG_PIO_DMA) {
  1104. tf.protocol = ATA_PROT_ATAPI_DMA;
  1105. tf.feature |= ATAPI_PKT_DMA;
  1106. } else {
  1107. tf.protocol = ATA_PROT_ATAPI;
  1108. tf.lbam = SCSI_SENSE_BUFFERSIZE;
  1109. tf.lbah = 0;
  1110. }
  1111. return ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE,
  1112. sense_buf, SCSI_SENSE_BUFFERSIZE, 0);
  1113. }
  1114. /**
  1115. * ata_eh_analyze_serror - analyze SError for a failed port
  1116. * @link: ATA link to analyze SError for
  1117. *
  1118. * Analyze SError if available and further determine cause of
  1119. * failure.
  1120. *
  1121. * LOCKING:
  1122. * None.
  1123. */
  1124. static void ata_eh_analyze_serror(struct ata_link *link)
  1125. {
  1126. struct ata_eh_context *ehc = &link->eh_context;
  1127. u32 serror = ehc->i.serror;
  1128. unsigned int err_mask = 0, action = 0;
  1129. u32 hotplug_mask;
  1130. if (serror & SERR_PERSISTENT) {
  1131. err_mask |= AC_ERR_ATA_BUS;
  1132. action |= ATA_EH_HARDRESET;
  1133. }
  1134. if (serror &
  1135. (SERR_DATA_RECOVERED | SERR_COMM_RECOVERED | SERR_DATA)) {
  1136. err_mask |= AC_ERR_ATA_BUS;
  1137. action |= ATA_EH_SOFTRESET;
  1138. }
  1139. if (serror & SERR_PROTOCOL) {
  1140. err_mask |= AC_ERR_HSM;
  1141. action |= ATA_EH_SOFTRESET;
  1142. }
  1143. if (serror & SERR_INTERNAL) {
  1144. err_mask |= AC_ERR_SYSTEM;
  1145. action |= ATA_EH_HARDRESET;
  1146. }
  1147. /* Determine whether a hotplug event has occurred. Both
  1148. * SError.N/X are considered hotplug events for enabled or
  1149. * host links. For disabled PMP links, only N bit is
  1150. * considered as X bit is left at 1 for link plugging.
  1151. */
  1152. hotplug_mask = 0;
  1153. if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link))
  1154. hotplug_mask = SERR_PHYRDY_CHG | SERR_DEV_XCHG;
  1155. else
  1156. hotplug_mask = SERR_PHYRDY_CHG;
  1157. if (serror & hotplug_mask)
  1158. ata_ehi_hotplugged(&ehc->i);
  1159. ehc->i.err_mask |= err_mask;
  1160. ehc->i.action |= action;
  1161. }
  1162. /**
  1163. * ata_eh_analyze_ncq_error - analyze NCQ error
  1164. * @link: ATA link to analyze NCQ error for
  1165. *
  1166. * Read log page 10h, determine the offending qc and acquire
  1167. * error status TF. For NCQ device errors, all LLDDs have to do
  1168. * is setting AC_ERR_DEV in ehi->err_mask. This function takes
  1169. * care of the rest.
  1170. *
  1171. * LOCKING:
  1172. * Kernel thread context (may sleep).
  1173. */
  1174. static void ata_eh_analyze_ncq_error(struct ata_link *link)
  1175. {
  1176. struct ata_port *ap = link->ap;
  1177. struct ata_eh_context *ehc = &link->eh_context;
  1178. struct ata_device *dev = link->device;
  1179. struct ata_queued_cmd *qc;
  1180. struct ata_taskfile tf;
  1181. int tag, rc;
  1182. /* if frozen, we can't do much */
  1183. if (ap->pflags & ATA_PFLAG_FROZEN)
  1184. return;
  1185. /* is it NCQ device error? */
  1186. if (!link->sactive || !(ehc->i.err_mask & AC_ERR_DEV))
  1187. return;
  1188. /* has LLDD analyzed already? */
  1189. for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
  1190. qc = __ata_qc_from_tag(ap, tag);
  1191. if (!(qc->flags & ATA_QCFLAG_FAILED))
  1192. continue;
  1193. if (qc->err_mask)
  1194. return;
  1195. }
  1196. /* okay, this error is ours */
  1197. rc = ata_eh_read_log_10h(dev, &tag, &tf);
  1198. if (rc) {
  1199. ata_link_printk(link, KERN_ERR, "failed to read log page 10h "
  1200. "(errno=%d)\n", rc);
  1201. return;
  1202. }
  1203. if (!(link->sactive & (1 << tag))) {
  1204. ata_link_printk(link, KERN_ERR, "log page 10h reported "
  1205. "inactive tag %d\n", tag);
  1206. return;
  1207. }
  1208. /* we've got the perpetrator, condemn it */
  1209. qc = __ata_qc_from_tag(ap, tag);
  1210. memcpy(&qc->result_tf, &tf, sizeof(tf));
  1211. qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ;
  1212. ehc->i.err_mask &= ~AC_ERR_DEV;
  1213. }
  1214. /**
  1215. * ata_eh_analyze_tf - analyze taskfile of a failed qc
  1216. * @qc: qc to analyze
  1217. * @tf: Taskfile registers to analyze
  1218. *
  1219. * Analyze taskfile of @qc and further determine cause of
  1220. * failure. This function also requests ATAPI sense data if
  1221. * avaliable.
  1222. *
  1223. * LOCKING:
  1224. * Kernel thread context (may sleep).
  1225. *
  1226. * RETURNS:
  1227. * Determined recovery action
  1228. */
  1229. static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
  1230. const struct ata_taskfile *tf)
  1231. {
  1232. unsigned int tmp, action = 0;
  1233. u8 stat = tf->command, err = tf->feature;
  1234. if ((stat & (ATA_BUSY | ATA_DRQ | ATA_DRDY)) != ATA_DRDY) {
  1235. qc->err_mask |= AC_ERR_HSM;
  1236. return ATA_EH_SOFTRESET;
  1237. }
  1238. if (stat & (ATA_ERR | ATA_DF))
  1239. qc->err_mask |= AC_ERR_DEV;
  1240. else
  1241. return 0;
  1242. switch (qc->dev->class) {
  1243. case ATA_DEV_ATA:
  1244. if (err & ATA_ICRC)
  1245. qc->err_mask |= AC_ERR_ATA_BUS;
  1246. if (err & ATA_UNC)
  1247. qc->err_mask |= AC_ERR_MEDIA;
  1248. if (err & ATA_IDNF)
  1249. qc->err_mask |= AC_ERR_INVALID;
  1250. break;
  1251. case ATA_DEV_ATAPI:
  1252. if (!(qc->ap->pflags & ATA_PFLAG_FROZEN)) {
  1253. tmp = atapi_eh_request_sense(qc);
  1254. if (!tmp) {
  1255. /* ATA_QCFLAG_SENSE_VALID is used to
  1256. * tell atapi_qc_complete() that sense
  1257. * data is already valid.
  1258. *
  1259. * TODO: interpret sense data and set
  1260. * appropriate err_mask.
  1261. */
  1262. qc->flags |= ATA_QCFLAG_SENSE_VALID;
  1263. } else
  1264. qc->err_mask |= tmp;
  1265. }
  1266. }
  1267. if (qc->err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT | AC_ERR_ATA_BUS))
  1268. action |= ATA_EH_SOFTRESET;
  1269. return action;
  1270. }
  1271. static int ata_eh_categorize_error(unsigned int eflags, unsigned int err_mask,
  1272. int *xfer_ok)
  1273. {
  1274. int base = 0;
  1275. if (!(eflags & ATA_EFLAG_DUBIOUS_XFER))
  1276. *xfer_ok = 1;
  1277. if (!*xfer_ok)
  1278. base = ATA_ECAT_DUBIOUS_BASE;
  1279. if (err_mask & AC_ERR_ATA_BUS)
  1280. return base + ATA_ECAT_ATA_BUS;
  1281. if (err_mask & AC_ERR_TIMEOUT)
  1282. return base + ATA_ECAT_TOUT_HSM;
  1283. if (eflags & ATA_EFLAG_IS_IO) {
  1284. if (err_mask & AC_ERR_HSM)
  1285. return base + ATA_ECAT_TOUT_HSM;
  1286. if ((err_mask &
  1287. (AC_ERR_DEV|AC_ERR_MEDIA|AC_ERR_INVALID)) == AC_ERR_DEV)
  1288. return base + ATA_ECAT_UNK_DEV;
  1289. }
  1290. return 0;
  1291. }
  1292. struct speed_down_verdict_arg {
  1293. u64 since;
  1294. int xfer_ok;
  1295. int nr_errors[ATA_ECAT_NR];
  1296. };
  1297. static int speed_down_verdict_cb(struct ata_ering_entry *ent, void *void_arg)
  1298. {
  1299. struct speed_down_verdict_arg *arg = void_arg;
  1300. int cat;
  1301. if (ent->timestamp < arg->since)
  1302. return -1;
  1303. cat = ata_eh_categorize_error(ent->eflags, ent->err_mask,
  1304. &arg->xfer_ok);
  1305. arg->nr_errors[cat]++;
  1306. return 0;
  1307. }
  1308. /**
  1309. * ata_eh_speed_down_verdict - Determine speed down verdict
  1310. * @dev: Device of interest
  1311. *
  1312. * This function examines error ring of @dev and determines
  1313. * whether NCQ needs to be turned off, transfer speed should be
  1314. * stepped down, or falling back to PIO is necessary.
  1315. *
  1316. * ECAT_ATA_BUS : ATA_BUS error for any command
  1317. *
  1318. * ECAT_TOUT_HSM : TIMEOUT for any command or HSM violation for
  1319. * IO commands
  1320. *
  1321. * ECAT_UNK_DEV : Unknown DEV error for IO commands
  1322. *
  1323. * ECAT_DUBIOUS_* : Identical to above three but occurred while
  1324. * data transfer hasn't been verified.
  1325. *
  1326. * Verdicts are
  1327. *
  1328. * NCQ_OFF : Turn off NCQ.
  1329. *
  1330. * SPEED_DOWN : Speed down transfer speed but don't fall back
  1331. * to PIO.
  1332. *
  1333. * FALLBACK_TO_PIO : Fall back to PIO.
  1334. *
  1335. * Even if multiple verdicts are returned, only one action is
  1336. * taken per error. An action triggered by non-DUBIOUS errors
  1337. * clears ering, while one triggered by DUBIOUS_* errors doesn't.
  1338. * This is to expedite speed down decisions right after device is
  1339. * initially configured.
  1340. *
  1341. * The followings are speed down rules. #1 and #2 deal with
  1342. * DUBIOUS errors.
  1343. *
  1344. * 1. If more than one DUBIOUS_ATA_BUS or DUBIOUS_TOUT_HSM errors
  1345. * occurred during last 5 mins, SPEED_DOWN and FALLBACK_TO_PIO.
  1346. *
  1347. * 2. If more than one DUBIOUS_TOUT_HSM or DUBIOUS_UNK_DEV errors
  1348. * occurred during last 5 mins, NCQ_OFF.
  1349. *
  1350. * 3. If more than 8 ATA_BUS, TOUT_HSM or UNK_DEV errors
  1351. * ocurred during last 5 mins, FALLBACK_TO_PIO
  1352. *
  1353. * 4. If more than 3 TOUT_HSM or UNK_DEV errors occurred
  1354. * during last 10 mins, NCQ_OFF.
  1355. *
  1356. * 5. If more than 3 ATA_BUS or TOUT_HSM errors, or more than 6
  1357. * UNK_DEV errors occurred during last 10 mins, SPEED_DOWN.
  1358. *
  1359. * LOCKING:
  1360. * Inherited from caller.
  1361. *
  1362. * RETURNS:
  1363. * OR of ATA_EH_SPDN_* flags.
  1364. */
  1365. static unsigned int ata_eh_speed_down_verdict(struct ata_device *dev)
  1366. {
  1367. const u64 j5mins = 5LLU * 60 * HZ, j10mins = 10LLU * 60 * HZ;
  1368. u64 j64 = get_jiffies_64();
  1369. struct speed_down_verdict_arg arg;
  1370. unsigned int verdict = 0;
  1371. /* scan past 5 mins of error history */
  1372. memset(&arg, 0, sizeof(arg));
  1373. arg.since = j64 - min(j64, j5mins);
  1374. ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg);
  1375. if (arg.nr_errors[ATA_ECAT_DUBIOUS_ATA_BUS] +
  1376. arg.nr_errors[ATA_ECAT_DUBIOUS_TOUT_HSM] > 1)
  1377. verdict |= ATA_EH_SPDN_SPEED_DOWN |
  1378. ATA_EH_SPDN_FALLBACK_TO_PIO | ATA_EH_SPDN_KEEP_ERRORS;
  1379. if (arg.nr_errors[ATA_ECAT_DUBIOUS_TOUT_HSM] +
  1380. arg.nr_errors[ATA_ECAT_DUBIOUS_UNK_DEV] > 1)
  1381. verdict |= ATA_EH_SPDN_NCQ_OFF | ATA_EH_SPDN_KEEP_ERRORS;
  1382. if (arg.nr_errors[ATA_ECAT_ATA_BUS] +
  1383. arg.nr_errors[ATA_ECAT_TOUT_HSM] +
  1384. arg.nr_errors[ATA_ECAT_UNK_DEV] > 6)
  1385. verdict |= ATA_EH_SPDN_FALLBACK_TO_PIO;
  1386. /* scan past 10 mins of error history */
  1387. memset(&arg, 0, sizeof(arg));
  1388. arg.since = j64 - min(j64, j10mins);
  1389. ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg);
  1390. if (arg.nr_errors[ATA_ECAT_TOUT_HSM] +
  1391. arg.nr_errors[ATA_ECAT_UNK_DEV] > 3)
  1392. verdict |= ATA_EH_SPDN_NCQ_OFF;
  1393. if (arg.nr_errors[ATA_ECAT_ATA_BUS] +
  1394. arg.nr_errors[ATA_ECAT_TOUT_HSM] > 3 ||
  1395. arg.nr_errors[ATA_ECAT_UNK_DEV] > 6)
  1396. verdict |= ATA_EH_SPDN_SPEED_DOWN;
  1397. return verdict;
  1398. }
  1399. /**
  1400. * ata_eh_speed_down - record error and speed down if necessary
  1401. * @dev: Failed device
  1402. * @eflags: mask of ATA_EFLAG_* flags
  1403. * @err_mask: err_mask of the error
  1404. *
  1405. * Record error and examine error history to determine whether
  1406. * adjusting transmission speed is necessary. It also sets
  1407. * transmission limits appropriately if such adjustment is
  1408. * necessary.
  1409. *
  1410. * LOCKING:
  1411. * Kernel thread context (may sleep).
  1412. *
  1413. * RETURNS:
  1414. * Determined recovery action.
  1415. */
  1416. static unsigned int ata_eh_speed_down(struct ata_device *dev,
  1417. unsigned int eflags, unsigned int err_mask)
  1418. {
  1419. struct ata_link *link = dev->link;
  1420. int xfer_ok = 0;
  1421. unsigned int verdict;
  1422. unsigned int action = 0;
  1423. /* don't bother if Cat-0 error */
  1424. if (ata_eh_categorize_error(eflags, err_mask, &xfer_ok) == 0)
  1425. return 0;
  1426. /* record error and determine whether speed down is necessary */
  1427. ata_ering_record(&dev->ering, eflags, err_mask);
  1428. verdict = ata_eh_speed_down_verdict(dev);
  1429. /* turn off NCQ? */
  1430. if ((verdict & ATA_EH_SPDN_NCQ_OFF) &&
  1431. (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ |
  1432. ATA_DFLAG_NCQ_OFF)) == ATA_DFLAG_NCQ) {
  1433. dev->flags |= ATA_DFLAG_NCQ_OFF;
  1434. ata_dev_printk(dev, KERN_WARNING,
  1435. "NCQ disabled due to excessive errors\n");
  1436. goto done;
  1437. }
  1438. /* speed down? */
  1439. if (verdict & ATA_EH_SPDN_SPEED_DOWN) {
  1440. /* speed down SATA link speed if possible */
  1441. if (sata_down_spd_limit(link) == 0) {
  1442. action |= ATA_EH_HARDRESET;
  1443. goto done;
  1444. }
  1445. /* lower transfer mode */
  1446. if (dev->spdn_cnt < 2) {
  1447. static const int dma_dnxfer_sel[] =
  1448. { ATA_DNXFER_DMA, ATA_DNXFER_40C };
  1449. static const int pio_dnxfer_sel[] =
  1450. { ATA_DNXFER_PIO, ATA_DNXFER_FORCE_PIO0 };
  1451. int sel;
  1452. if (dev->xfer_shift != ATA_SHIFT_PIO)
  1453. sel = dma_dnxfer_sel[dev->spdn_cnt];
  1454. else
  1455. sel = pio_dnxfer_sel[dev->spdn_cnt];
  1456. dev->spdn_cnt++;
  1457. if (ata_down_xfermask_limit(dev, sel) == 0) {
  1458. action |= ATA_EH_SOFTRESET;
  1459. goto done;
  1460. }
  1461. }
  1462. }
  1463. /* Fall back to PIO? Slowing down to PIO is meaningless for
  1464. * SATA ATA devices. Consider it only for PATA and SATAPI.
  1465. */
  1466. if ((verdict & ATA_EH_SPDN_FALLBACK_TO_PIO) && (dev->spdn_cnt >= 2) &&
  1467. (link->ap->cbl != ATA_CBL_SATA || dev->class == ATA_DEV_ATAPI) &&
  1468. (dev->xfer_shift != ATA_SHIFT_PIO)) {
  1469. if (ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO) == 0) {
  1470. dev->spdn_cnt = 0;
  1471. action |= ATA_EH_SOFTRESET;
  1472. goto done;
  1473. }
  1474. }
  1475. return 0;
  1476. done:
  1477. /* device has been slowed down, blow error history */
  1478. if (!(verdict & ATA_EH_SPDN_KEEP_ERRORS))
  1479. ata_ering_clear(&dev->ering);
  1480. return action;
  1481. }
  1482. /**
  1483. * ata_eh_link_autopsy - analyze error and determine recovery action
  1484. * @link: host link to perform autopsy on
  1485. *
  1486. * Analyze why @link failed and determine which recovery actions
  1487. * are needed. This function also sets more detailed AC_ERR_*
  1488. * values and fills sense data for ATAPI CHECK SENSE.
  1489. *
  1490. * LOCKING:
  1491. * Kernel thread context (may sleep).
  1492. */
  1493. static void ata_eh_link_autopsy(struct ata_link *link)
  1494. {
  1495. struct ata_port *ap = link->ap;
  1496. struct ata_eh_context *ehc = &link->eh_context;
  1497. struct ata_device *dev;
  1498. unsigned int all_err_mask = 0, eflags = 0;
  1499. int tag;
  1500. u32 serror;
  1501. int rc;
  1502. DPRINTK("ENTER\n");
  1503. if (ehc->i.flags & ATA_EHI_NO_AUTOPSY)
  1504. return;
  1505. /* obtain and analyze SError */
  1506. rc = sata_scr_read(link, SCR_ERROR, &serror);
  1507. if (rc == 0) {
  1508. ehc->i.serror |= serror;
  1509. ata_eh_analyze_serror(link);
  1510. } else if (rc != -EOPNOTSUPP) {
  1511. /* SError read failed, force hardreset and probing */
  1512. ata_ehi_schedule_probe(&ehc->i);
  1513. ehc->i.action |= ATA_EH_HARDRESET;
  1514. ehc->i.err_mask |= AC_ERR_OTHER;
  1515. }
  1516. /* analyze NCQ failure */
  1517. ata_eh_analyze_ncq_error(link);
  1518. /* any real error trumps AC_ERR_OTHER */
  1519. if (ehc->i.err_mask & ~AC_ERR_OTHER)
  1520. ehc->i.err_mask &= ~AC_ERR_OTHER;
  1521. all_err_mask |= ehc->i.err_mask;
  1522. for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
  1523. struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
  1524. if (!(qc->flags & ATA_QCFLAG_FAILED) || qc->dev->link != link)
  1525. continue;
  1526. /* inherit upper level err_mask */
  1527. qc->err_mask |= ehc->i.err_mask;
  1528. /* analyze TF */
  1529. ehc->i.action |= ata_eh_analyze_tf(qc, &qc->result_tf);
  1530. /* DEV errors are probably spurious in case of ATA_BUS error */
  1531. if (qc->err_mask & AC_ERR_ATA_BUS)
  1532. qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_MEDIA |
  1533. AC_ERR_INVALID);
  1534. /* any real error trumps unknown error */
  1535. if (qc->err_mask & ~AC_ERR_OTHER)
  1536. qc->err_mask &= ~AC_ERR_OTHER;
  1537. /* SENSE_VALID trumps dev/unknown error and revalidation */
  1538. if (qc->flags & ATA_QCFLAG_SENSE_VALID)
  1539. qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER);
  1540. /* accumulate error info */
  1541. ehc->i.dev = qc->dev;
  1542. all_err_mask |= qc->err_mask;
  1543. if (qc->flags & ATA_QCFLAG_IO)
  1544. eflags |= ATA_EFLAG_IS_IO;
  1545. }
  1546. /* enforce default EH actions */
  1547. if (ap->pflags & ATA_PFLAG_FROZEN ||
  1548. all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT))
  1549. ehc->i.action |= ATA_EH_SOFTRESET;
  1550. else if (((eflags & ATA_EFLAG_IS_IO) && all_err_mask) ||
  1551. (!(eflags & ATA_EFLAG_IS_IO) && (all_err_mask & ~AC_ERR_DEV)))
  1552. ehc->i.action |= ATA_EH_REVALIDATE;
  1553. /* If we have offending qcs and the associated failed device,
  1554. * perform per-dev EH action only on the offending device.
  1555. */
  1556. if (ehc->i.dev) {
  1557. ehc->i.dev_action[ehc->i.dev->devno] |=
  1558. ehc->i.action & ATA_EH_PERDEV_MASK;
  1559. ehc->i.action &= ~ATA_EH_PERDEV_MASK;
  1560. }
  1561. /* propagate timeout to host link */
  1562. if ((all_err_mask & AC_ERR_TIMEOUT) && !ata_is_host_link(link))
  1563. ap->link.eh_context.i.err_mask |= AC_ERR_TIMEOUT;
  1564. /* record error and consider speeding down */
  1565. dev = ehc->i.dev;
  1566. if (!dev && ((ata_link_max_devices(link) == 1 &&
  1567. ata_dev_enabled(link->device))))
  1568. dev = link->device;
  1569. if (dev) {
  1570. if (dev->flags & ATA_DFLAG_DUBIOUS_XFER)
  1571. eflags |= ATA_EFLAG_DUBIOUS_XFER;
  1572. ehc->i.action |= ata_eh_speed_down(dev, eflags, all_err_mask);
  1573. }
  1574. DPRINTK("EXIT\n");
  1575. }
  1576. /**
  1577. * ata_eh_autopsy - analyze error and determine recovery action
  1578. * @ap: host port to perform autopsy on
  1579. *
  1580. * Analyze all links of @ap and determine why they failed and
  1581. * which recovery actions are needed.
  1582. *
  1583. * LOCKING:
  1584. * Kernel thread context (may sleep).
  1585. */
  1586. void ata_eh_autopsy(struct ata_port *ap)
  1587. {
  1588. struct ata_link *link;
  1589. ata_port_for_each_link(link, ap)
  1590. ata_eh_link_autopsy(link);
  1591. /* Autopsy of fanout ports can affect host link autopsy.
  1592. * Perform host link autopsy last.
  1593. */
  1594. if (ap->nr_pmp_links)
  1595. ata_eh_link_autopsy(&ap->link);
  1596. }
  1597. /**
  1598. * ata_eh_link_report - report error handling to user
  1599. * @link: ATA link EH is going on
  1600. *
  1601. * Report EH to user.
  1602. *
  1603. * LOCKING:
  1604. * None.
  1605. */
  1606. static void ata_eh_link_report(struct ata_link *link)
  1607. {
  1608. struct ata_port *ap = link->ap;
  1609. struct ata_eh_context *ehc = &link->eh_context;
  1610. const char *frozen, *desc;
  1611. char tries_buf[6];
  1612. int tag, nr_failed = 0;
  1613. if (ehc->i.flags & ATA_EHI_QUIET)
  1614. return;
  1615. desc = NULL;
  1616. if (ehc->i.desc[0] != '\0')
  1617. desc = ehc->i.desc;
  1618. for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
  1619. struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
  1620. if (!(qc->flags & ATA_QCFLAG_FAILED) || qc->dev->link != link ||
  1621. ((qc->flags & ATA_QCFLAG_QUIET) &&
  1622. qc->err_mask == AC_ERR_DEV))
  1623. continue;
  1624. if (qc->flags & ATA_QCFLAG_SENSE_VALID && !qc->err_mask)
  1625. continue;
  1626. nr_failed++;
  1627. }
  1628. if (!nr_failed && !ehc->i.err_mask)
  1629. return;
  1630. frozen = "";
  1631. if (ap->pflags & ATA_PFLAG_FROZEN)
  1632. frozen = " frozen";
  1633. memset(tries_buf, 0, sizeof(tries_buf));
  1634. if (ap->eh_tries < ATA_EH_MAX_TRIES)
  1635. snprintf(tries_buf, sizeof(tries_buf) - 1, " t%d",
  1636. ap->eh_tries);
  1637. if (ehc->i.dev) {
  1638. ata_dev_printk(ehc->i.dev, KERN_ERR, "exception Emask 0x%x "
  1639. "SAct 0x%x SErr 0x%x action 0x%x%s%s\n",
  1640. ehc->i.err_mask, link->sactive, ehc->i.serror,
  1641. ehc->i.action, frozen, tries_buf);
  1642. if (desc)
  1643. ata_dev_printk(ehc->i.dev, KERN_ERR, "%s\n", desc);
  1644. } else {
  1645. ata_link_printk(link, KERN_ERR, "exception Emask 0x%x "
  1646. "SAct 0x%x SErr 0x%x action 0x%x%s%s\n",
  1647. ehc->i.err_mask, link->sactive, ehc->i.serror,
  1648. ehc->i.action, frozen, tries_buf);
  1649. if (desc)
  1650. ata_link_printk(link, KERN_ERR, "%s\n", desc);
  1651. }
  1652. if (ehc->i.serror)
  1653. ata_port_printk(ap, KERN_ERR,
  1654. "SError: { %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s}\n",
  1655. ehc->i.serror & SERR_DATA_RECOVERED ? "RecovData " : "",
  1656. ehc->i.serror & SERR_COMM_RECOVERED ? "RecovComm " : "",
  1657. ehc->i.serror & SERR_DATA ? "UnrecovData " : "",
  1658. ehc->i.serror & SERR_PERSISTENT ? "Persist " : "",
  1659. ehc->i.serror & SERR_PROTOCOL ? "Proto " : "",
  1660. ehc->i.serror & SERR_INTERNAL ? "HostInt " : "",
  1661. ehc->i.serror & SERR_PHYRDY_CHG ? "PHYRdyChg " : "",
  1662. ehc->i.serror & SERR_PHY_INT_ERR ? "PHYInt " : "",
  1663. ehc->i.serror & SERR_COMM_WAKE ? "CommWake " : "",
  1664. ehc->i.serror & SERR_10B_8B_ERR ? "10B8B " : "",
  1665. ehc->i.serror & SERR_DISPARITY ? "Dispar " : "",
  1666. ehc->i.serror & SERR_CRC ? "BadCRC " : "",
  1667. ehc->i.serror & SERR_HANDSHAKE ? "Handshk " : "",
  1668. ehc->i.serror & SERR_LINK_SEQ_ERR ? "LinkSeq " : "",
  1669. ehc->i.serror & SERR_TRANS_ST_ERROR ? "TrStaTrns " : "",
  1670. ehc->i.serror & SERR_UNRECOG_FIS ? "UnrecFIS " : "",
  1671. ehc->i.serror & SERR_DEV_XCHG ? "DevExch " : "");
  1672. for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
  1673. struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
  1674. struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf;
  1675. const u8 *cdb = qc->cdb;
  1676. char data_buf[20] = "";
  1677. char cdb_buf[70] = "";
  1678. if (!(qc->flags & ATA_QCFLAG_FAILED) ||
  1679. qc->dev->link != link || !qc->err_mask)
  1680. continue;
  1681. if (qc->dma_dir != DMA_NONE) {
  1682. static const char *dma_str[] = {
  1683. [DMA_BIDIRECTIONAL] = "bidi",
  1684. [DMA_TO_DEVICE] = "out",
  1685. [DMA_FROM_DEVICE] = "in",
  1686. };
  1687. static const char *prot_str[] = {
  1688. [ATA_PROT_PIO] = "pio",
  1689. [ATA_PROT_DMA] = "dma",
  1690. [ATA_PROT_NCQ] = "ncq",
  1691. [ATA_PROT_ATAPI] = "pio",
  1692. [ATA_PROT_ATAPI_DMA] = "dma",
  1693. };
  1694. snprintf(data_buf, sizeof(data_buf), " %s %u %s",
  1695. prot_str[qc->tf.protocol], qc->nbytes,
  1696. dma_str[qc->dma_dir]);
  1697. }
  1698. if (ata_is_atapi(qc->tf.protocol))
  1699. snprintf(cdb_buf, sizeof(cdb_buf),
  1700. "cdb %02x %02x %02x %02x %02x %02x %02x %02x "
  1701. "%02x %02x %02x %02x %02x %02x %02x %02x\n ",
  1702. cdb[0], cdb[1], cdb[2], cdb[3],
  1703. cdb[4], cdb[5], cdb[6], cdb[7],
  1704. cdb[8], cdb[9], cdb[10], cdb[11],
  1705. cdb[12], cdb[13], cdb[14], cdb[15]);
  1706. ata_dev_printk(qc->dev, KERN_ERR,
  1707. "cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x "
  1708. "tag %d%s\n %s"
  1709. "res %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x "
  1710. "Emask 0x%x (%s)%s\n",
  1711. cmd->command, cmd->feature, cmd->nsect,
  1712. cmd->lbal, cmd->lbam, cmd->lbah,
  1713. cmd->hob_feature, cmd->hob_nsect,
  1714. cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah,
  1715. cmd->device, qc->tag, data_buf, cdb_buf,
  1716. res->command, res->feature, res->nsect,
  1717. res->lbal, res->lbam, res->lbah,
  1718. res->hob_feature, res->hob_nsect,
  1719. res->hob_lbal, res->hob_lbam, res->hob_lbah,
  1720. res->device, qc->err_mask, ata_err_string(qc->err_mask),
  1721. qc->err_mask & AC_ERR_NCQ ? " <F>" : "");
  1722. if (res->command & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ |
  1723. ATA_ERR)) {
  1724. if (res->command & ATA_BUSY)
  1725. ata_dev_printk(qc->dev, KERN_ERR,
  1726. "status: { Busy }\n");
  1727. else
  1728. ata_dev_printk(qc->dev, KERN_ERR,
  1729. "status: { %s%s%s%s}\n",
  1730. res->command & ATA_DRDY ? "DRDY " : "",
  1731. res->command & ATA_DF ? "DF " : "",
  1732. res->command & ATA_DRQ ? "DRQ " : "",
  1733. res->command & ATA_ERR ? "ERR " : "");
  1734. }
  1735. if (cmd->command != ATA_CMD_PACKET &&
  1736. (res->feature & (ATA_ICRC | ATA_UNC | ATA_IDNF |
  1737. ATA_ABORTED)))
  1738. ata_dev_printk(qc->dev, KERN_ERR,
  1739. "error: { %s%s%s%s}\n",
  1740. res->feature & ATA_ICRC ? "ICRC " : "",
  1741. res->feature & ATA_UNC ? "UNC " : "",
  1742. res->feature & ATA_IDNF ? "IDNF " : "",
  1743. res->feature & ATA_ABORTED ? "ABRT " : "");
  1744. }
  1745. }
  1746. /**
  1747. * ata_eh_report - report error handling to user
  1748. * @ap: ATA port to report EH about
  1749. *
  1750. * Report EH to user.
  1751. *
  1752. * LOCKING:
  1753. * None.
  1754. */
  1755. void ata_eh_report(struct ata_port *ap)
  1756. {
  1757. struct ata_link *link;
  1758. __ata_port_for_each_link(link, ap)
  1759. ata_eh_link_report(link);
  1760. }
  1761. static int ata_do_reset(struct ata_link *link, ata_reset_fn_t reset,
  1762. unsigned int *classes, unsigned long deadline)
  1763. {
  1764. struct ata_device *dev;
  1765. int rc;
  1766. ata_link_for_each_dev(dev, link)
  1767. classes[dev->devno] = ATA_DEV_UNKNOWN;
  1768. rc = reset(link, classes, deadline);
  1769. if (rc)
  1770. return rc;
  1771. /* If any class isn't ATA_DEV_UNKNOWN, consider classification
  1772. * is complete and convert all ATA_DEV_UNKNOWN to
  1773. * ATA_DEV_NONE.
  1774. */
  1775. ata_link_for_each_dev(dev, link)
  1776. if (classes[dev->devno] != ATA_DEV_UNKNOWN)
  1777. break;
  1778. if (dev) {
  1779. ata_link_for_each_dev(dev, link) {
  1780. if (classes[dev->devno] == ATA_DEV_UNKNOWN)
  1781. classes[dev->devno] = ATA_DEV_NONE;
  1782. }
  1783. }
  1784. return 0;
  1785. }
  1786. static int ata_eh_followup_srst_needed(struct ata_link *link,
  1787. int rc, int classify,
  1788. const unsigned int *classes)
  1789. {
  1790. if (link->flags & ATA_LFLAG_NO_SRST)
  1791. return 0;
  1792. if (rc == -EAGAIN)
  1793. return 1;
  1794. if (rc != 0)
  1795. return 0;
  1796. if ((link->ap->flags & ATA_FLAG_PMP) && ata_is_host_link(link))
  1797. return 1;
  1798. if (classify && !(link->flags & ATA_LFLAG_ASSUME_CLASS) &&
  1799. classes[0] == ATA_DEV_UNKNOWN)
  1800. return 1;
  1801. return 0;
  1802. }
  1803. int ata_eh_reset(struct ata_link *link, int classify,
  1804. ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
  1805. ata_reset_fn_t hardreset, ata_postreset_fn_t postreset)
  1806. {
  1807. const int max_tries = ARRAY_SIZE(ata_eh_reset_timeouts);
  1808. struct ata_port *ap = link->ap;
  1809. struct ata_eh_context *ehc = &link->eh_context;
  1810. unsigned int *classes = ehc->classes;
  1811. unsigned int lflags = link->flags;
  1812. int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
  1813. int try = 0;
  1814. struct ata_device *dev;
  1815. unsigned long deadline, now;
  1816. unsigned int tmp_action;
  1817. ata_reset_fn_t reset;
  1818. unsigned long flags;
  1819. u32 sstatus;
  1820. int rc;
  1821. /* about to reset */
  1822. spin_lock_irqsave(ap->lock, flags);
  1823. ap->pflags |= ATA_PFLAG_RESETTING;
  1824. spin_unlock_irqrestore(ap->lock, flags);
  1825. ata_eh_about_to_do(link, NULL, ehc->i.action & ATA_EH_RESET_MASK);
  1826. ata_link_for_each_dev(dev, link) {
  1827. /* If we issue an SRST then an ATA drive (not ATAPI)
  1828. * may change configuration and be in PIO0 timing. If
  1829. * we do a hard reset (or are coming from power on)
  1830. * this is true for ATA or ATAPI. Until we've set a
  1831. * suitable controller mode we should not touch the
  1832. * bus as we may be talking too fast.
  1833. */
  1834. dev->pio_mode = XFER_PIO_0;
  1835. /* If the controller has a pio mode setup function
  1836. * then use it to set the chipset to rights. Don't
  1837. * touch the DMA setup as that will be dealt with when
  1838. * configuring devices.
  1839. */
  1840. if (ap->ops->set_piomode)
  1841. ap->ops->set_piomode(ap, dev);
  1842. }
  1843. /* Determine which reset to use and record in ehc->i.action.
  1844. * prereset() may examine and modify it.
  1845. */
  1846. if (softreset && (!hardreset || (!(lflags & ATA_LFLAG_NO_SRST) &&
  1847. !sata_set_spd_needed(link) &&
  1848. !(ehc->i.action & ATA_EH_HARDRESET))))
  1849. tmp_action = ATA_EH_SOFTRESET;
  1850. else
  1851. tmp_action = ATA_EH_HARDRESET;
  1852. ehc->i.action = (ehc->i.action & ~ATA_EH_RESET_MASK) | tmp_action;
  1853. if (prereset) {
  1854. rc = prereset(link, jiffies + ATA_EH_PRERESET_TIMEOUT);
  1855. if (rc) {
  1856. if (rc == -ENOENT) {
  1857. ata_link_printk(link, KERN_DEBUG,
  1858. "port disabled. ignoring.\n");
  1859. ehc->i.action &= ~ATA_EH_RESET_MASK;
  1860. ata_link_for_each_dev(dev, link)
  1861. classes[dev->devno] = ATA_DEV_NONE;
  1862. rc = 0;
  1863. } else
  1864. ata_link_printk(link, KERN_ERR,
  1865. "prereset failed (errno=%d)\n", rc);
  1866. goto out;
  1867. }
  1868. }
  1869. /* prereset() might have modified ehc->i.action */
  1870. if (ehc->i.action & ATA_EH_HARDRESET)
  1871. reset = hardreset;
  1872. else if (ehc->i.action & ATA_EH_SOFTRESET)
  1873. reset = softreset;
  1874. else {
  1875. /* prereset told us not to reset, bang classes and return */
  1876. ata_link_for_each_dev(dev, link)
  1877. classes[dev->devno] = ATA_DEV_NONE;
  1878. rc = 0;
  1879. goto out;
  1880. }
  1881. /* did prereset() screw up? if so, fix up to avoid oopsing */
  1882. if (!reset) {
  1883. if (softreset)
  1884. reset = softreset;
  1885. else
  1886. reset = hardreset;
  1887. }
  1888. retry:
  1889. deadline = jiffies + ata_eh_reset_timeouts[try++];
  1890. /* shut up during boot probing */
  1891. if (verbose)
  1892. ata_link_printk(link, KERN_INFO, "%s resetting link\n",
  1893. reset == softreset ? "soft" : "hard");
  1894. /* mark that this EH session started with reset */
  1895. if (reset == hardreset)
  1896. ehc->i.flags |= ATA_EHI_DID_HARDRESET;
  1897. else
  1898. ehc->i.flags |= ATA_EHI_DID_SOFTRESET;
  1899. rc = ata_do_reset(link, reset, classes, deadline);
  1900. if (reset == hardreset &&
  1901. ata_eh_followup_srst_needed(link, rc, classify, classes)) {
  1902. /* okay, let's do follow-up softreset */
  1903. reset = softreset;
  1904. if (!reset) {
  1905. ata_link_printk(link, KERN_ERR,
  1906. "follow-up softreset required "
  1907. "but no softreset avaliable\n");
  1908. rc = -EINVAL;
  1909. goto fail;
  1910. }
  1911. ata_eh_about_to_do(link, NULL, ATA_EH_RESET_MASK);
  1912. rc = ata_do_reset(link, reset, classes, deadline);
  1913. }
  1914. /* -EAGAIN can happen if we skipped followup SRST */
  1915. if (rc && rc != -EAGAIN)
  1916. goto fail;
  1917. /* was classification successful? */
  1918. if (classify && classes[0] == ATA_DEV_UNKNOWN &&
  1919. !(lflags & ATA_LFLAG_ASSUME_CLASS)) {
  1920. if (try < max_tries) {
  1921. ata_link_printk(link, KERN_WARNING,
  1922. "classification failed\n");
  1923. rc = -EINVAL;
  1924. goto fail;
  1925. }
  1926. ata_link_printk(link, KERN_WARNING,
  1927. "classfication failed, assuming ATA\n");
  1928. lflags |= ATA_LFLAG_ASSUME_ATA;
  1929. }
  1930. ata_link_for_each_dev(dev, link) {
  1931. /* After the reset, the device state is PIO 0 and the
  1932. * controller state is undefined. Reset also wakes up
  1933. * drives from sleeping mode.
  1934. */
  1935. dev->pio_mode = XFER_PIO_0;
  1936. dev->flags &= ~ATA_DFLAG_SLEEPING;
  1937. if (ata_link_offline(link))
  1938. continue;
  1939. /* apply class override */
  1940. if (lflags & ATA_LFLAG_ASSUME_ATA)
  1941. classes[dev->devno] = ATA_DEV_ATA;
  1942. else if (lflags & ATA_LFLAG_ASSUME_SEMB)
  1943. classes[dev->devno] = ATA_DEV_SEMB_UNSUP; /* not yet */
  1944. }
  1945. /* record current link speed */
  1946. if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0)
  1947. link->sata_spd = (sstatus >> 4) & 0xf;
  1948. if (postreset)
  1949. postreset(link, classes);
  1950. /* reset successful, schedule revalidation */
  1951. ata_eh_done(link, NULL, ehc->i.action & ATA_EH_RESET_MASK);
  1952. ehc->i.action |= ATA_EH_REVALIDATE;
  1953. rc = 0;
  1954. out:
  1955. /* clear hotplug flag */
  1956. ehc->i.flags &= ~ATA_EHI_HOTPLUGGED;
  1957. spin_lock_irqsave(ap->lock, flags);
  1958. ap->pflags &= ~ATA_PFLAG_RESETTING;
  1959. spin_unlock_irqrestore(ap->lock, flags);
  1960. return rc;
  1961. fail:
  1962. if (rc == -ERESTART || try >= max_tries)
  1963. goto out;
  1964. now = jiffies;
  1965. if (time_before(now, deadline)) {
  1966. unsigned long delta = deadline - now;
  1967. ata_link_printk(link, KERN_WARNING, "reset failed "
  1968. "(errno=%d), retrying in %u secs\n",
  1969. rc, (jiffies_to_msecs(delta) + 999) / 1000);
  1970. while (delta)
  1971. delta = schedule_timeout_uninterruptible(delta);
  1972. }
  1973. if (rc == -EPIPE || try == max_tries - 1)
  1974. sata_down_spd_limit(link);
  1975. if (hardreset)
  1976. reset = hardreset;
  1977. goto retry;
  1978. }
  1979. static int ata_eh_revalidate_and_attach(struct ata_link *link,
  1980. struct ata_device **r_failed_dev)
  1981. {
  1982. struct ata_port *ap = link->ap;
  1983. struct ata_eh_context *ehc = &link->eh_context;
  1984. struct ata_device *dev;
  1985. unsigned int new_mask = 0;
  1986. unsigned long flags;
  1987. int rc = 0;
  1988. DPRINTK("ENTER\n");
  1989. /* For PATA drive side cable detection to work, IDENTIFY must
  1990. * be done backwards such that PDIAG- is released by the slave
  1991. * device before the master device is identified.
  1992. */
  1993. ata_link_for_each_dev_reverse(dev, link) {
  1994. unsigned int action = ata_eh_dev_action(dev);
  1995. unsigned int readid_flags = 0;
  1996. if (ehc->i.flags & ATA_EHI_DID_RESET)
  1997. readid_flags |= ATA_READID_POSTRESET;
  1998. if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) {
  1999. WARN_ON(dev->class == ATA_DEV_PMP);
  2000. if (ata_link_offline(link)) {
  2001. rc = -EIO;
  2002. goto err;
  2003. }
  2004. ata_eh_about_to_do(link, dev, ATA_EH_REVALIDATE);
  2005. rc = ata_dev_revalidate(dev, ehc->classes[dev->devno],
  2006. readid_flags);
  2007. if (rc)
  2008. goto err;
  2009. ata_eh_done(link, dev, ATA_EH_REVALIDATE);
  2010. /* Configuration may have changed, reconfigure
  2011. * transfer mode.
  2012. */
  2013. ehc->i.flags |= ATA_EHI_SETMODE;
  2014. /* schedule the scsi_rescan_device() here */
  2015. queue_work(ata_aux_wq, &(ap->scsi_rescan_task));
  2016. } else if (dev->class == ATA_DEV_UNKNOWN &&
  2017. ehc->tries[dev->devno] &&
  2018. ata_class_enabled(ehc->classes[dev->devno])) {
  2019. dev->class = ehc->classes[dev->devno];
  2020. if (dev->class == ATA_DEV_PMP)
  2021. rc = sata_pmp_attach(dev);
  2022. else
  2023. rc = ata_dev_read_id(dev, &dev->class,
  2024. readid_flags, dev->id);
  2025. switch (rc) {
  2026. case 0:
  2027. new_mask |= 1 << dev->devno;
  2028. break;
  2029. case -ENOENT:
  2030. /* IDENTIFY was issued to non-existent
  2031. * device. No need to reset. Just
  2032. * thaw and kill the device.
  2033. */
  2034. ata_eh_thaw_port(ap);
  2035. dev->class = ATA_DEV_UNKNOWN;
  2036. break;
  2037. default:
  2038. dev->class = ATA_DEV_UNKNOWN;
  2039. goto err;
  2040. }
  2041. }
  2042. }
  2043. /* PDIAG- should have been released, ask cable type if post-reset */
  2044. if (ata_is_host_link(link) && ap->ops->cable_detect &&
  2045. (ehc->i.flags & ATA_EHI_DID_RESET))
  2046. ap->cbl = ap->ops->cable_detect(ap);
  2047. /* Configure new devices forward such that user doesn't see
  2048. * device detection messages backwards.
  2049. */
  2050. ata_link_for_each_dev(dev, link) {
  2051. if (!(new_mask & (1 << dev->devno)) ||
  2052. dev->class == ATA_DEV_PMP)
  2053. continue;
  2054. ehc->i.flags |= ATA_EHI_PRINTINFO;
  2055. rc = ata_dev_configure(dev);
  2056. ehc->i.flags &= ~ATA_EHI_PRINTINFO;
  2057. if (rc)
  2058. goto err;
  2059. spin_lock_irqsave(ap->lock, flags);
  2060. ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
  2061. spin_unlock_irqrestore(ap->lock, flags);
  2062. /* new device discovered, configure xfermode */
  2063. ehc->i.flags |= ATA_EHI_SETMODE;
  2064. }
  2065. return 0;
  2066. err:
  2067. *r_failed_dev = dev;
  2068. DPRINTK("EXIT rc=%d\n", rc);
  2069. return rc;
  2070. }
  2071. /**
  2072. * ata_set_mode - Program timings and issue SET FEATURES - XFER
  2073. * @link: link on which timings will be programmed
  2074. * @r_failed_dev: out paramter for failed device
  2075. *
  2076. * Set ATA device disk transfer mode (PIO3, UDMA6, etc.). If
  2077. * ata_set_mode() fails, pointer to the failing device is
  2078. * returned in @r_failed_dev.
  2079. *
  2080. * LOCKING:
  2081. * PCI/etc. bus probe sem.
  2082. *
  2083. * RETURNS:
  2084. * 0 on success, negative errno otherwise
  2085. */
  2086. int ata_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
  2087. {
  2088. struct ata_port *ap = link->ap;
  2089. struct ata_device *dev;
  2090. int rc;
  2091. /* if data transfer is verified, clear DUBIOUS_XFER on ering top */
  2092. ata_link_for_each_dev(dev, link) {
  2093. if (!(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) {
  2094. struct ata_ering_entry *ent;
  2095. ent = ata_ering_top(&dev->ering);
  2096. if (ent)
  2097. ent->eflags &= ~ATA_EFLAG_DUBIOUS_XFER;
  2098. }
  2099. }
  2100. /* has private set_mode? */
  2101. if (ap->ops->set_mode)
  2102. rc = ap->ops->set_mode(link, r_failed_dev);
  2103. else
  2104. rc = ata_do_set_mode(link, r_failed_dev);
  2105. /* if transfer mode has changed, set DUBIOUS_XFER on device */
  2106. ata_link_for_each_dev(dev, link) {
  2107. struct ata_eh_context *ehc = &link->eh_context;
  2108. u8 saved_xfer_mode = ehc->saved_xfer_mode[dev->devno];
  2109. u8 saved_ncq = !!(ehc->saved_ncq_enabled & (1 << dev->devno));
  2110. if (dev->xfer_mode != saved_xfer_mode ||
  2111. ata_ncq_enabled(dev) != saved_ncq)
  2112. dev->flags |= ATA_DFLAG_DUBIOUS_XFER;
  2113. }
  2114. return rc;
  2115. }
  2116. static int ata_link_nr_enabled(struct ata_link *link)
  2117. {
  2118. struct ata_device *dev;
  2119. int cnt = 0;
  2120. ata_link_for_each_dev(dev, link)
  2121. if (ata_dev_enabled(dev))
  2122. cnt++;
  2123. return cnt;
  2124. }
  2125. static int ata_link_nr_vacant(struct ata_link *link)
  2126. {
  2127. struct ata_device *dev;
  2128. int cnt = 0;
  2129. ata_link_for_each_dev(dev, link)
  2130. if (dev->class == ATA_DEV_UNKNOWN)
  2131. cnt++;
  2132. return cnt;
  2133. }
  2134. static int ata_eh_skip_recovery(struct ata_link *link)
  2135. {
  2136. struct ata_eh_context *ehc = &link->eh_context;
  2137. struct ata_device *dev;
  2138. /* skip disabled links */
  2139. if (link->flags & ATA_LFLAG_DISABLED)
  2140. return 1;
  2141. /* thaw frozen port, resume link and recover failed devices */
  2142. if ((link->ap->pflags & ATA_PFLAG_FROZEN) ||
  2143. (ehc->i.flags & ATA_EHI_RESUME_LINK) || ata_link_nr_enabled(link))
  2144. return 0;
  2145. /* skip if class codes for all vacant slots are ATA_DEV_NONE */
  2146. ata_link_for_each_dev(dev, link) {
  2147. if (dev->class == ATA_DEV_UNKNOWN &&
  2148. ehc->classes[dev->devno] != ATA_DEV_NONE)
  2149. return 0;
  2150. }
  2151. return 1;
  2152. }
  2153. static int ata_eh_schedule_probe(struct ata_device *dev)
  2154. {
  2155. struct ata_eh_context *ehc = &dev->link->eh_context;
  2156. if (!(ehc->i.probe_mask & (1 << dev->devno)) ||
  2157. (ehc->did_probe_mask & (1 << dev->devno)))
  2158. return 0;
  2159. ata_eh_detach_dev(dev);
  2160. ata_dev_init(dev);
  2161. ehc->did_probe_mask |= (1 << dev->devno);
  2162. ehc->i.action |= ATA_EH_SOFTRESET;
  2163. ehc->saved_xfer_mode[dev->devno] = 0;
  2164. ehc->saved_ncq_enabled &= ~(1 << dev->devno);
  2165. return 1;
  2166. }
  2167. static int ata_eh_handle_dev_fail(struct ata_device *dev, int err)
  2168. {
  2169. struct ata_eh_context *ehc = &dev->link->eh_context;
  2170. ehc->tries[dev->devno]--;
  2171. switch (err) {
  2172. case -ENODEV:
  2173. /* device missing or wrong IDENTIFY data, schedule probing */
  2174. ehc->i.probe_mask |= (1 << dev->devno);
  2175. case -EINVAL:
  2176. /* give it just one more chance */
  2177. ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1);
  2178. case -EIO:
  2179. if (ehc->tries[dev->devno] == 1 && dev->pio_mode > XFER_PIO_0) {
  2180. /* This is the last chance, better to slow
  2181. * down than lose it.
  2182. */
  2183. sata_down_spd_limit(dev->link);
  2184. ata_down_xfermask_limit(dev, ATA_DNXFER_PIO);
  2185. }
  2186. }
  2187. if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) {
  2188. /* disable device if it has used up all its chances */
  2189. ata_dev_disable(dev);
  2190. /* detach if offline */
  2191. if (ata_link_offline(dev->link))
  2192. ata_eh_detach_dev(dev);
  2193. /* schedule probe if necessary */
  2194. if (ata_eh_schedule_probe(dev))
  2195. ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
  2196. return 1;
  2197. } else {
  2198. /* soft didn't work? be haaaaard */
  2199. if (ehc->i.flags & ATA_EHI_DID_RESET)
  2200. ehc->i.action |= ATA_EH_HARDRESET;
  2201. else
  2202. ehc->i.action |= ATA_EH_SOFTRESET;
  2203. return 0;
  2204. }
  2205. }
  2206. /**
  2207. * ata_eh_recover - recover host port after error
  2208. * @ap: host port to recover
  2209. * @prereset: prereset method (can be NULL)
  2210. * @softreset: softreset method (can be NULL)
  2211. * @hardreset: hardreset method (can be NULL)
  2212. * @postreset: postreset method (can be NULL)
  2213. * @r_failed_link: out parameter for failed link
  2214. *
  2215. * This is the alpha and omega, eum and yang, heart and soul of
  2216. * libata exception handling. On entry, actions required to
  2217. * recover each link and hotplug requests are recorded in the
  2218. * link's eh_context. This function executes all the operations
  2219. * with appropriate retrials and fallbacks to resurrect failed
  2220. * devices, detach goners and greet newcomers.
  2221. *
  2222. * LOCKING:
  2223. * Kernel thread context (may sleep).
  2224. *
  2225. * RETURNS:
  2226. * 0 on success, -errno on failure.
  2227. */
  2228. int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
  2229. ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
  2230. ata_postreset_fn_t postreset,
  2231. struct ata_link **r_failed_link)
  2232. {
  2233. struct ata_link *link;
  2234. struct ata_device *dev;
  2235. int nr_failed_devs, nr_disabled_devs;
  2236. int reset, rc;
  2237. unsigned long flags;
  2238. DPRINTK("ENTER\n");
  2239. /* prep for recovery */
  2240. ata_port_for_each_link(link, ap) {
  2241. struct ata_eh_context *ehc = &link->eh_context;
  2242. /* re-enable link? */
  2243. if (ehc->i.action & ATA_EH_ENABLE_LINK) {
  2244. ata_eh_about_to_do(link, NULL, ATA_EH_ENABLE_LINK);
  2245. spin_lock_irqsave(ap->lock, flags);
  2246. link->flags &= ~ATA_LFLAG_DISABLED;
  2247. spin_unlock_irqrestore(ap->lock, flags);
  2248. ata_eh_done(link, NULL, ATA_EH_ENABLE_LINK);
  2249. }
  2250. ata_link_for_each_dev(dev, link) {
  2251. if (link->flags & ATA_LFLAG_NO_RETRY)
  2252. ehc->tries[dev->devno] = 1;
  2253. else
  2254. ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
  2255. /* collect port action mask recorded in dev actions */
  2256. ehc->i.action |= ehc->i.dev_action[dev->devno] &
  2257. ~ATA_EH_PERDEV_MASK;
  2258. ehc->i.dev_action[dev->devno] &= ATA_EH_PERDEV_MASK;
  2259. /* process hotplug request */
  2260. if (dev->flags & ATA_DFLAG_DETACH)
  2261. ata_eh_detach_dev(dev);
  2262. /* schedule probe if necessary */
  2263. if (!ata_dev_enabled(dev))
  2264. ata_eh_schedule_probe(dev);
  2265. }
  2266. }
  2267. retry:
  2268. rc = 0;
  2269. nr_failed_devs = 0;
  2270. nr_disabled_devs = 0;
  2271. reset = 0;
  2272. /* if UNLOADING, finish immediately */
  2273. if (ap->pflags & ATA_PFLAG_UNLOADING)
  2274. goto out;
  2275. /* prep for EH */
  2276. ata_port_for_each_link(link, ap) {
  2277. struct ata_eh_context *ehc = &link->eh_context;
  2278. /* skip EH if possible. */
  2279. if (ata_eh_skip_recovery(link))
  2280. ehc->i.action = 0;
  2281. /* do we need to reset? */
  2282. if (ehc->i.action & ATA_EH_RESET_MASK)
  2283. reset = 1;
  2284. ata_link_for_each_dev(dev, link)
  2285. ehc->classes[dev->devno] = ATA_DEV_UNKNOWN;
  2286. }
  2287. /* reset */
  2288. if (reset) {
  2289. /* if PMP is attached, this function only deals with
  2290. * downstream links, port should stay thawed.
  2291. */
  2292. if (!ap->nr_pmp_links)
  2293. ata_eh_freeze_port(ap);
  2294. ata_port_for_each_link(link, ap) {
  2295. struct ata_eh_context *ehc = &link->eh_context;
  2296. if (!(ehc->i.action & ATA_EH_RESET_MASK))
  2297. continue;
  2298. rc = ata_eh_reset(link, ata_link_nr_vacant(link),
  2299. prereset, softreset, hardreset,
  2300. postreset);
  2301. if (rc) {
  2302. ata_link_printk(link, KERN_ERR,
  2303. "reset failed, giving up\n");
  2304. goto out;
  2305. }
  2306. }
  2307. if (!ap->nr_pmp_links)
  2308. ata_eh_thaw_port(ap);
  2309. }
  2310. /* the rest */
  2311. ata_port_for_each_link(link, ap) {
  2312. struct ata_eh_context *ehc = &link->eh_context;
  2313. /* revalidate existing devices and attach new ones */
  2314. rc = ata_eh_revalidate_and_attach(link, &dev);
  2315. if (rc)
  2316. goto dev_fail;
  2317. /* if PMP got attached, return, pmp EH will take care of it */
  2318. if (link->device->class == ATA_DEV_PMP) {
  2319. ehc->i.action = 0;
  2320. return 0;
  2321. }
  2322. /* configure transfer mode if necessary */
  2323. if (ehc->i.flags & ATA_EHI_SETMODE) {
  2324. rc = ata_set_mode(link, &dev);
  2325. if (rc)
  2326. goto dev_fail;
  2327. ehc->i.flags &= ~ATA_EHI_SETMODE;
  2328. }
  2329. if (ehc->i.action & ATA_EHI_LPM)
  2330. ata_link_for_each_dev(dev, link)
  2331. ata_dev_enable_pm(dev, ap->pm_policy);
  2332. /* this link is okay now */
  2333. ehc->i.flags = 0;
  2334. continue;
  2335. dev_fail:
  2336. nr_failed_devs++;
  2337. if (ata_eh_handle_dev_fail(dev, rc))
  2338. nr_disabled_devs++;
  2339. if (ap->pflags & ATA_PFLAG_FROZEN) {
  2340. /* PMP reset requires working host port.
  2341. * Can't retry if it's frozen.
  2342. */
  2343. if (ap->nr_pmp_links)
  2344. goto out;
  2345. break;
  2346. }
  2347. }
  2348. if (nr_failed_devs) {
  2349. if (nr_failed_devs != nr_disabled_devs) {
  2350. ata_port_printk(ap, KERN_WARNING, "failed to recover "
  2351. "some devices, retrying in 5 secs\n");
  2352. ssleep(5);
  2353. } else {
  2354. /* no device left to recover, repeat fast */
  2355. msleep(500);
  2356. }
  2357. goto retry;
  2358. }
  2359. out:
  2360. if (rc && r_failed_link)
  2361. *r_failed_link = link;
  2362. DPRINTK("EXIT, rc=%d\n", rc);
  2363. return rc;
  2364. }
  2365. /**
  2366. * ata_eh_finish - finish up EH
  2367. * @ap: host port to finish EH for
  2368. *
  2369. * Recovery is complete. Clean up EH states and retry or finish
  2370. * failed qcs.
  2371. *
  2372. * LOCKING:
  2373. * None.
  2374. */
  2375. void ata_eh_finish(struct ata_port *ap)
  2376. {
  2377. int tag;
  2378. /* retry or finish qcs */
  2379. for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
  2380. struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
  2381. if (!(qc->flags & ATA_QCFLAG_FAILED))
  2382. continue;
  2383. if (qc->err_mask) {
  2384. /* FIXME: Once EH migration is complete,
  2385. * generate sense data in this function,
  2386. * considering both err_mask and tf.
  2387. *
  2388. * There's no point in retrying invalid
  2389. * (detected by libata) and non-IO device
  2390. * errors (rejected by device). Finish them
  2391. * immediately.
  2392. */
  2393. if ((qc->err_mask & AC_ERR_INVALID) ||
  2394. (!(qc->flags & ATA_QCFLAG_IO) &&
  2395. qc->err_mask == AC_ERR_DEV))
  2396. ata_eh_qc_complete(qc);
  2397. else
  2398. ata_eh_qc_retry(qc);
  2399. } else {
  2400. if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
  2401. ata_eh_qc_complete(qc);
  2402. } else {
  2403. /* feed zero TF to sense generation */
  2404. memset(&qc->result_tf, 0, sizeof(qc->result_tf));
  2405. ata_eh_qc_retry(qc);
  2406. }
  2407. }
  2408. }
  2409. /* make sure nr_active_links is zero after EH */
  2410. WARN_ON(ap->nr_active_links);
  2411. ap->nr_active_links = 0;
  2412. }
  2413. /**
  2414. * ata_do_eh - do standard error handling
  2415. * @ap: host port to handle error for
  2416. * @prereset: prereset method (can be NULL)
  2417. * @softreset: softreset method (can be NULL)
  2418. * @hardreset: hardreset method (can be NULL)
  2419. * @postreset: postreset method (can be NULL)
  2420. *
  2421. * Perform standard error handling sequence.
  2422. *
  2423. * LOCKING:
  2424. * Kernel thread context (may sleep).
  2425. */
  2426. void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
  2427. ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
  2428. ata_postreset_fn_t postreset)
  2429. {
  2430. struct ata_device *dev;
  2431. int rc;
  2432. ata_eh_autopsy(ap);
  2433. ata_eh_report(ap);
  2434. rc = ata_eh_recover(ap, prereset, softreset, hardreset, postreset,
  2435. NULL);
  2436. if (rc) {
  2437. ata_link_for_each_dev(dev, &ap->link)
  2438. ata_dev_disable(dev);
  2439. }
  2440. ata_eh_finish(ap);
  2441. }
  2442. #ifdef CONFIG_PM
  2443. /**
  2444. * ata_eh_handle_port_suspend - perform port suspend operation
  2445. * @ap: port to suspend
  2446. *
  2447. * Suspend @ap.
  2448. *
  2449. * LOCKING:
  2450. * Kernel thread context (may sleep).
  2451. */
  2452. static void ata_eh_handle_port_suspend(struct ata_port *ap)
  2453. {
  2454. unsigned long flags;
  2455. int rc = 0;
  2456. /* are we suspending? */
  2457. spin_lock_irqsave(ap->lock, flags);
  2458. if (!(ap->pflags & ATA_PFLAG_PM_PENDING) ||
  2459. ap->pm_mesg.event == PM_EVENT_ON) {
  2460. spin_unlock_irqrestore(ap->lock, flags);
  2461. return;
  2462. }
  2463. spin_unlock_irqrestore(ap->lock, flags);
  2464. WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED);
  2465. /* tell ACPI we're suspending */
  2466. rc = ata_acpi_on_suspend(ap);
  2467. if (rc)
  2468. goto out;
  2469. /* suspend */
  2470. ata_eh_freeze_port(ap);
  2471. if (ap->ops->port_suspend)
  2472. rc = ap->ops->port_suspend(ap, ap->pm_mesg);
  2473. ata_acpi_set_state(ap, PMSG_SUSPEND);
  2474. out:
  2475. /* report result */
  2476. spin_lock_irqsave(ap->lock, flags);
  2477. ap->pflags &= ~ATA_PFLAG_PM_PENDING;
  2478. if (rc == 0)
  2479. ap->pflags |= ATA_PFLAG_SUSPENDED;
  2480. else if (ap->pflags & ATA_PFLAG_FROZEN)
  2481. ata_port_schedule_eh(ap);
  2482. if (ap->pm_result) {
  2483. *ap->pm_result = rc;
  2484. ap->pm_result = NULL;
  2485. }
  2486. spin_unlock_irqrestore(ap->lock, flags);
  2487. return;
  2488. }
  2489. /**
  2490. * ata_eh_handle_port_resume - perform port resume operation
  2491. * @ap: port to resume
  2492. *
  2493. * Resume @ap.
  2494. *
  2495. * LOCKING:
  2496. * Kernel thread context (may sleep).
  2497. */
  2498. static void ata_eh_handle_port_resume(struct ata_port *ap)
  2499. {
  2500. unsigned long flags;
  2501. int rc = 0;
  2502. /* are we resuming? */
  2503. spin_lock_irqsave(ap->lock, flags);
  2504. if (!(ap->pflags & ATA_PFLAG_PM_PENDING) ||
  2505. ap->pm_mesg.event != PM_EVENT_ON) {
  2506. spin_unlock_irqrestore(ap->lock, flags);
  2507. return;
  2508. }
  2509. spin_unlock_irqrestore(ap->lock, flags);
  2510. WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
  2511. ata_acpi_set_state(ap, PMSG_ON);
  2512. if (ap->ops->port_resume)
  2513. rc = ap->ops->port_resume(ap);
  2514. /* tell ACPI that we're resuming */
  2515. ata_acpi_on_resume(ap);
  2516. /* report result */
  2517. spin_lock_irqsave(ap->lock, flags);
  2518. ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED);
  2519. if (ap->pm_result) {
  2520. *ap->pm_result = rc;
  2521. ap->pm_result = NULL;
  2522. }
  2523. spin_unlock_irqrestore(ap->lock, flags);
  2524. }
  2525. #endif /* CONFIG_PM */