qla_nx2.c 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2014 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include <linux/vmalloc.h>
  8. #include <linux/delay.h>
  9. #include "qla_def.h"
  10. #include "qla_gbl.h"
  11. #include <linux/delay.h>
  12. #define TIMEOUT_100_MS 100
  13. /* 8044 Flash Read/Write functions */
  14. uint32_t
  15. qla8044_rd_reg(struct qla_hw_data *ha, ulong addr)
  16. {
  17. return readl((void __iomem *) (ha->nx_pcibase + addr));
  18. }
  19. void
  20. qla8044_wr_reg(struct qla_hw_data *ha, ulong addr, uint32_t val)
  21. {
  22. writel(val, (void __iomem *)((ha)->nx_pcibase + addr));
  23. }
  24. int
  25. qla8044_rd_direct(struct scsi_qla_host *vha,
  26. const uint32_t crb_reg)
  27. {
  28. struct qla_hw_data *ha = vha->hw;
  29. if (crb_reg < CRB_REG_INDEX_MAX)
  30. return qla8044_rd_reg(ha, qla8044_reg_tbl[crb_reg]);
  31. else
  32. return QLA_FUNCTION_FAILED;
  33. }
  34. void
  35. qla8044_wr_direct(struct scsi_qla_host *vha,
  36. const uint32_t crb_reg,
  37. const uint32_t value)
  38. {
  39. struct qla_hw_data *ha = vha->hw;
  40. if (crb_reg < CRB_REG_INDEX_MAX)
  41. qla8044_wr_reg(ha, qla8044_reg_tbl[crb_reg], value);
  42. }
  43. static int
  44. qla8044_set_win_base(scsi_qla_host_t *vha, uint32_t addr)
  45. {
  46. uint32_t val;
  47. int ret_val = QLA_SUCCESS;
  48. struct qla_hw_data *ha = vha->hw;
  49. qla8044_wr_reg(ha, QLA8044_CRB_WIN_FUNC(ha->portnum), addr);
  50. val = qla8044_rd_reg(ha, QLA8044_CRB_WIN_FUNC(ha->portnum));
  51. if (val != addr) {
  52. ql_log(ql_log_warn, vha, 0xb087,
  53. "%s: Failed to set register window : "
  54. "addr written 0x%x, read 0x%x!\n",
  55. __func__, addr, val);
  56. ret_val = QLA_FUNCTION_FAILED;
  57. }
  58. return ret_val;
  59. }
  60. static int
  61. qla8044_rd_reg_indirect(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
  62. {
  63. int ret_val = QLA_SUCCESS;
  64. struct qla_hw_data *ha = vha->hw;
  65. ret_val = qla8044_set_win_base(vha, addr);
  66. if (!ret_val)
  67. *data = qla8044_rd_reg(ha, QLA8044_WILDCARD);
  68. else
  69. ql_log(ql_log_warn, vha, 0xb088,
  70. "%s: failed read of addr 0x%x!\n", __func__, addr);
  71. return ret_val;
  72. }
  73. static int
  74. qla8044_wr_reg_indirect(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
  75. {
  76. int ret_val = QLA_SUCCESS;
  77. struct qla_hw_data *ha = vha->hw;
  78. ret_val = qla8044_set_win_base(vha, addr);
  79. if (!ret_val)
  80. qla8044_wr_reg(ha, QLA8044_WILDCARD, data);
  81. else
  82. ql_log(ql_log_warn, vha, 0xb089,
  83. "%s: failed wrt to addr 0x%x, data 0x%x\n",
  84. __func__, addr, data);
  85. return ret_val;
  86. }
  87. /*
  88. * qla8044_read_write_crb_reg - Read from raddr and write value to waddr.
  89. *
  90. * @ha : Pointer to adapter structure
  91. * @raddr : CRB address to read from
  92. * @waddr : CRB address to write to
  93. *
  94. */
  95. static void
  96. qla8044_read_write_crb_reg(struct scsi_qla_host *vha,
  97. uint32_t raddr, uint32_t waddr)
  98. {
  99. uint32_t value;
  100. qla8044_rd_reg_indirect(vha, raddr, &value);
  101. qla8044_wr_reg_indirect(vha, waddr, value);
  102. }
  103. static int
  104. qla8044_poll_wait_for_ready(struct scsi_qla_host *vha, uint32_t addr1,
  105. uint32_t mask)
  106. {
  107. unsigned long timeout;
  108. uint32_t temp;
  109. /* jiffies after 100ms */
  110. timeout = jiffies + msecs_to_jiffies(TIMEOUT_100_MS);
  111. do {
  112. qla8044_rd_reg_indirect(vha, addr1, &temp);
  113. if ((temp & mask) != 0)
  114. break;
  115. if (time_after_eq(jiffies, timeout)) {
  116. ql_log(ql_log_warn, vha, 0xb151,
  117. "Error in processing rdmdio entry\n");
  118. return -1;
  119. }
  120. } while (1);
  121. return 0;
  122. }
  123. static uint32_t
  124. qla8044_ipmdio_rd_reg(struct scsi_qla_host *vha,
  125. uint32_t addr1, uint32_t addr3, uint32_t mask, uint32_t addr)
  126. {
  127. uint32_t temp;
  128. int ret = 0;
  129. ret = qla8044_poll_wait_for_ready(vha, addr1, mask);
  130. if (ret == -1)
  131. return -1;
  132. temp = (0x40000000 | addr);
  133. qla8044_wr_reg_indirect(vha, addr1, temp);
  134. ret = qla8044_poll_wait_for_ready(vha, addr1, mask);
  135. if (ret == -1)
  136. return 0;
  137. qla8044_rd_reg_indirect(vha, addr3, &ret);
  138. return ret;
  139. }
  140. static int
  141. qla8044_poll_wait_ipmdio_bus_idle(struct scsi_qla_host *vha,
  142. uint32_t addr1, uint32_t addr2, uint32_t addr3, uint32_t mask)
  143. {
  144. unsigned long timeout;
  145. uint32_t temp;
  146. /* jiffies after 100 msecs */
  147. timeout = jiffies + msecs_to_jiffies(TIMEOUT_100_MS);
  148. do {
  149. temp = qla8044_ipmdio_rd_reg(vha, addr1, addr3, mask, addr2);
  150. if ((temp & 0x1) != 1)
  151. break;
  152. if (time_after_eq(jiffies, timeout)) {
  153. ql_log(ql_log_warn, vha, 0xb152,
  154. "Error in processing mdiobus idle\n");
  155. return -1;
  156. }
  157. } while (1);
  158. return 0;
  159. }
  160. static int
  161. qla8044_ipmdio_wr_reg(struct scsi_qla_host *vha, uint32_t addr1,
  162. uint32_t addr3, uint32_t mask, uint32_t addr, uint32_t value)
  163. {
  164. int ret = 0;
  165. ret = qla8044_poll_wait_for_ready(vha, addr1, mask);
  166. if (ret == -1)
  167. return -1;
  168. qla8044_wr_reg_indirect(vha, addr3, value);
  169. qla8044_wr_reg_indirect(vha, addr1, addr);
  170. ret = qla8044_poll_wait_for_ready(vha, addr1, mask);
  171. if (ret == -1)
  172. return -1;
  173. return 0;
  174. }
  175. /*
  176. * qla8044_rmw_crb_reg - Read value from raddr, AND with test_mask,
  177. * Shift Left,Right/OR/XOR with values RMW header and write value to waddr.
  178. *
  179. * @vha : Pointer to adapter structure
  180. * @raddr : CRB address to read from
  181. * @waddr : CRB address to write to
  182. * @p_rmw_hdr : header with shift/or/xor values.
  183. *
  184. */
  185. static void
  186. qla8044_rmw_crb_reg(struct scsi_qla_host *vha,
  187. uint32_t raddr, uint32_t waddr, struct qla8044_rmw *p_rmw_hdr)
  188. {
  189. uint32_t value;
  190. if (p_rmw_hdr->index_a)
  191. value = vha->reset_tmplt.array[p_rmw_hdr->index_a];
  192. else
  193. qla8044_rd_reg_indirect(vha, raddr, &value);
  194. value &= p_rmw_hdr->test_mask;
  195. value <<= p_rmw_hdr->shl;
  196. value >>= p_rmw_hdr->shr;
  197. value |= p_rmw_hdr->or_value;
  198. value ^= p_rmw_hdr->xor_value;
  199. qla8044_wr_reg_indirect(vha, waddr, value);
  200. return;
  201. }
  202. static inline void
  203. qla8044_set_qsnt_ready(struct scsi_qla_host *vha)
  204. {
  205. uint32_t qsnt_state;
  206. struct qla_hw_data *ha = vha->hw;
  207. qsnt_state = qla8044_rd_direct(vha, QLA8044_CRB_DRV_STATE_INDEX);
  208. qsnt_state |= (1 << ha->portnum);
  209. qla8044_wr_direct(vha, QLA8044_CRB_DRV_STATE_INDEX, qsnt_state);
  210. ql_log(ql_log_info, vha, 0xb08e, "%s(%ld): qsnt_state: 0x%08x\n",
  211. __func__, vha->host_no, qsnt_state);
  212. }
  213. void
  214. qla8044_clear_qsnt_ready(struct scsi_qla_host *vha)
  215. {
  216. uint32_t qsnt_state;
  217. struct qla_hw_data *ha = vha->hw;
  218. qsnt_state = qla8044_rd_direct(vha, QLA8044_CRB_DRV_STATE_INDEX);
  219. qsnt_state &= ~(1 << ha->portnum);
  220. qla8044_wr_direct(vha, QLA8044_CRB_DRV_STATE_INDEX, qsnt_state);
  221. ql_log(ql_log_info, vha, 0xb08f, "%s(%ld): qsnt_state: 0x%08x\n",
  222. __func__, vha->host_no, qsnt_state);
  223. }
  224. /**
  225. *
  226. * qla8044_lock_recovery - Recovers the idc_lock.
  227. * @ha : Pointer to adapter structure
  228. *
  229. * Lock Recovery Register
  230. * 5-2 Lock recovery owner: Function ID of driver doing lock recovery,
  231. * valid if bits 1..0 are set by driver doing lock recovery.
  232. * 1-0 1 - Driver intends to force unlock the IDC lock.
  233. * 2 - Driver is moving forward to unlock the IDC lock. Driver clears
  234. * this field after force unlocking the IDC lock.
  235. *
  236. * Lock Recovery process
  237. * a. Read the IDC_LOCK_RECOVERY register. If the value in bits 1..0 is
  238. * greater than 0, then wait for the other driver to unlock otherwise
  239. * move to the next step.
  240. * b. Indicate intent to force-unlock by writing 1h to the IDC_LOCK_RECOVERY
  241. * register bits 1..0 and also set the function# in bits 5..2.
  242. * c. Read the IDC_LOCK_RECOVERY register again after a delay of 200ms.
  243. * Wait for the other driver to perform lock recovery if the function
  244. * number in bits 5..2 has changed, otherwise move to the next step.
  245. * d. Write a value of 2h to the IDC_LOCK_RECOVERY register bits 1..0
  246. * leaving your function# in bits 5..2.
  247. * e. Force unlock using the DRIVER_UNLOCK register and immediately clear
  248. * the IDC_LOCK_RECOVERY bits 5..0 by writing 0.
  249. **/
  250. static int
  251. qla8044_lock_recovery(struct scsi_qla_host *vha)
  252. {
  253. uint32_t lock = 0, lockid;
  254. struct qla_hw_data *ha = vha->hw;
  255. lockid = qla8044_rd_reg(ha, QLA8044_DRV_LOCKRECOVERY);
  256. /* Check for other Recovery in progress, go wait */
  257. if ((lockid & IDC_LOCK_RECOVERY_STATE_MASK) != 0)
  258. return QLA_FUNCTION_FAILED;
  259. /* Intent to Recover */
  260. qla8044_wr_reg(ha, QLA8044_DRV_LOCKRECOVERY,
  261. (ha->portnum <<
  262. IDC_LOCK_RECOVERY_STATE_SHIFT_BITS) | INTENT_TO_RECOVER);
  263. msleep(200);
  264. /* Check Intent to Recover is advertised */
  265. lockid = qla8044_rd_reg(ha, QLA8044_DRV_LOCKRECOVERY);
  266. if ((lockid & IDC_LOCK_RECOVERY_OWNER_MASK) != (ha->portnum <<
  267. IDC_LOCK_RECOVERY_STATE_SHIFT_BITS))
  268. return QLA_FUNCTION_FAILED;
  269. ql_dbg(ql_dbg_p3p, vha, 0xb08B, "%s:%d: IDC Lock recovery initiated\n"
  270. , __func__, ha->portnum);
  271. /* Proceed to Recover */
  272. qla8044_wr_reg(ha, QLA8044_DRV_LOCKRECOVERY,
  273. (ha->portnum << IDC_LOCK_RECOVERY_STATE_SHIFT_BITS) |
  274. PROCEED_TO_RECOVER);
  275. /* Force Unlock() */
  276. qla8044_wr_reg(ha, QLA8044_DRV_LOCK_ID, 0xFF);
  277. qla8044_rd_reg(ha, QLA8044_DRV_UNLOCK);
  278. /* Clear bits 0-5 in IDC_RECOVERY register*/
  279. qla8044_wr_reg(ha, QLA8044_DRV_LOCKRECOVERY, 0);
  280. /* Get lock() */
  281. lock = qla8044_rd_reg(ha, QLA8044_DRV_LOCK);
  282. if (lock) {
  283. lockid = qla8044_rd_reg(ha, QLA8044_DRV_LOCK_ID);
  284. lockid = ((lockid + (1 << 8)) & ~0xFF) | ha->portnum;
  285. qla8044_wr_reg(ha, QLA8044_DRV_LOCK_ID, lockid);
  286. return QLA_SUCCESS;
  287. } else
  288. return QLA_FUNCTION_FAILED;
  289. }
  290. int
  291. qla8044_idc_lock(struct qla_hw_data *ha)
  292. {
  293. uint32_t ret_val = QLA_SUCCESS, timeout = 0, status = 0;
  294. uint32_t lock_id, lock_cnt, func_num, tmo_owner = 0, first_owner = 0;
  295. scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
  296. while (status == 0) {
  297. /* acquire semaphore5 from PCI HW block */
  298. status = qla8044_rd_reg(ha, QLA8044_DRV_LOCK);
  299. if (status) {
  300. /* Increment Counter (8-31) and update func_num (0-7) on
  301. * getting a successful lock */
  302. lock_id = qla8044_rd_reg(ha, QLA8044_DRV_LOCK_ID);
  303. lock_id = ((lock_id + (1 << 8)) & ~0xFF) | ha->portnum;
  304. qla8044_wr_reg(ha, QLA8044_DRV_LOCK_ID, lock_id);
  305. break;
  306. }
  307. if (timeout == 0)
  308. first_owner = qla8044_rd_reg(ha, QLA8044_DRV_LOCK_ID);
  309. if (++timeout >=
  310. (QLA8044_DRV_LOCK_TIMEOUT / QLA8044_DRV_LOCK_MSLEEP)) {
  311. tmo_owner = qla8044_rd_reg(ha, QLA8044_DRV_LOCK_ID);
  312. func_num = tmo_owner & 0xFF;
  313. lock_cnt = tmo_owner >> 8;
  314. ql_log(ql_log_warn, vha, 0xb114,
  315. "%s: Lock by func %d failed after 2s, lock held "
  316. "by func %d, lock count %d, first_owner %d\n",
  317. __func__, ha->portnum, func_num, lock_cnt,
  318. (first_owner & 0xFF));
  319. if (first_owner != tmo_owner) {
  320. /* Some other driver got lock,
  321. * OR same driver got lock again (counter
  322. * value changed), when we were waiting for
  323. * lock. Retry for another 2 sec */
  324. ql_dbg(ql_dbg_p3p, vha, 0xb115,
  325. "%s: %d: IDC lock failed\n",
  326. __func__, ha->portnum);
  327. timeout = 0;
  328. } else {
  329. /* Same driver holding lock > 2sec.
  330. * Force Recovery */
  331. if (qla8044_lock_recovery(vha) == QLA_SUCCESS) {
  332. /* Recovered and got lock */
  333. ret_val = QLA_SUCCESS;
  334. ql_dbg(ql_dbg_p3p, vha, 0xb116,
  335. "%s:IDC lock Recovery by %d"
  336. "successful...\n", __func__,
  337. ha->portnum);
  338. }
  339. /* Recovery Failed, some other function
  340. * has the lock, wait for 2secs
  341. * and retry
  342. */
  343. ql_dbg(ql_dbg_p3p, vha, 0xb08a,
  344. "%s: IDC lock Recovery by %d "
  345. "failed, Retrying timeout\n", __func__,
  346. ha->portnum);
  347. timeout = 0;
  348. }
  349. }
  350. msleep(QLA8044_DRV_LOCK_MSLEEP);
  351. }
  352. return ret_val;
  353. }
  354. void
  355. qla8044_idc_unlock(struct qla_hw_data *ha)
  356. {
  357. int id;
  358. scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
  359. id = qla8044_rd_reg(ha, QLA8044_DRV_LOCK_ID);
  360. if ((id & 0xFF) != ha->portnum) {
  361. ql_log(ql_log_warn, vha, 0xb118,
  362. "%s: IDC Unlock by %d failed, lock owner is %d!\n",
  363. __func__, ha->portnum, (id & 0xFF));
  364. return;
  365. }
  366. /* Keep lock counter value, update the ha->func_num to 0xFF */
  367. qla8044_wr_reg(ha, QLA8044_DRV_LOCK_ID, (id | 0xFF));
  368. qla8044_rd_reg(ha, QLA8044_DRV_UNLOCK);
  369. }
  370. /* 8044 Flash Lock/Unlock functions */
  371. static int
  372. qla8044_flash_lock(scsi_qla_host_t *vha)
  373. {
  374. int lock_owner;
  375. int timeout = 0;
  376. uint32_t lock_status = 0;
  377. int ret_val = QLA_SUCCESS;
  378. struct qla_hw_data *ha = vha->hw;
  379. while (lock_status == 0) {
  380. lock_status = qla8044_rd_reg(ha, QLA8044_FLASH_LOCK);
  381. if (lock_status)
  382. break;
  383. if (++timeout >= QLA8044_FLASH_LOCK_TIMEOUT / 20) {
  384. lock_owner = qla8044_rd_reg(ha,
  385. QLA8044_FLASH_LOCK_ID);
  386. ql_log(ql_log_warn, vha, 0xb113,
  387. "%s: Simultaneous flash access by following ports, active port = %d: accessing port = %d",
  388. __func__, ha->portnum, lock_owner);
  389. ret_val = QLA_FUNCTION_FAILED;
  390. break;
  391. }
  392. msleep(20);
  393. }
  394. qla8044_wr_reg(ha, QLA8044_FLASH_LOCK_ID, ha->portnum);
  395. return ret_val;
  396. }
  397. static void
  398. qla8044_flash_unlock(scsi_qla_host_t *vha)
  399. {
  400. int ret_val;
  401. struct qla_hw_data *ha = vha->hw;
  402. /* Reading FLASH_UNLOCK register unlocks the Flash */
  403. qla8044_wr_reg(ha, QLA8044_FLASH_LOCK_ID, 0xFF);
  404. ret_val = qla8044_rd_reg(ha, QLA8044_FLASH_UNLOCK);
  405. }
  406. static
  407. void qla8044_flash_lock_recovery(struct scsi_qla_host *vha)
  408. {
  409. if (qla8044_flash_lock(vha)) {
  410. /* Someone else is holding the lock. */
  411. ql_log(ql_log_warn, vha, 0xb120, "Resetting flash_lock\n");
  412. }
  413. /*
  414. * Either we got the lock, or someone
  415. * else died while holding it.
  416. * In either case, unlock.
  417. */
  418. qla8044_flash_unlock(vha);
  419. }
  420. /*
  421. * Address and length are byte address
  422. */
  423. static int
  424. qla8044_read_flash_data(scsi_qla_host_t *vha, uint8_t *p_data,
  425. uint32_t flash_addr, int u32_word_count)
  426. {
  427. int i, ret_val = QLA_SUCCESS;
  428. uint32_t u32_word;
  429. if (qla8044_flash_lock(vha) != QLA_SUCCESS) {
  430. ret_val = QLA_FUNCTION_FAILED;
  431. goto exit_lock_error;
  432. }
  433. if (flash_addr & 0x03) {
  434. ql_log(ql_log_warn, vha, 0xb117,
  435. "%s: Illegal addr = 0x%x\n", __func__, flash_addr);
  436. ret_val = QLA_FUNCTION_FAILED;
  437. goto exit_flash_read;
  438. }
  439. for (i = 0; i < u32_word_count; i++) {
  440. if (qla8044_wr_reg_indirect(vha, QLA8044_FLASH_DIRECT_WINDOW,
  441. (flash_addr & 0xFFFF0000))) {
  442. ql_log(ql_log_warn, vha, 0xb119,
  443. "%s: failed to write addr 0x%x to "
  444. "FLASH_DIRECT_WINDOW\n! ",
  445. __func__, flash_addr);
  446. ret_val = QLA_FUNCTION_FAILED;
  447. goto exit_flash_read;
  448. }
  449. ret_val = qla8044_rd_reg_indirect(vha,
  450. QLA8044_FLASH_DIRECT_DATA(flash_addr),
  451. &u32_word);
  452. if (ret_val != QLA_SUCCESS) {
  453. ql_log(ql_log_warn, vha, 0xb08c,
  454. "%s: failed to read addr 0x%x!\n",
  455. __func__, flash_addr);
  456. goto exit_flash_read;
  457. }
  458. *(uint32_t *)p_data = u32_word;
  459. p_data = p_data + 4;
  460. flash_addr = flash_addr + 4;
  461. }
  462. exit_flash_read:
  463. qla8044_flash_unlock(vha);
  464. exit_lock_error:
  465. return ret_val;
  466. }
  467. /*
  468. * Address and length are byte address
  469. */
  470. uint8_t *
  471. qla8044_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
  472. uint32_t offset, uint32_t length)
  473. {
  474. scsi_block_requests(vha->host);
  475. if (qla8044_read_flash_data(vha, (uint8_t *)buf, offset, length / 4)
  476. != QLA_SUCCESS) {
  477. ql_log(ql_log_warn, vha, 0xb08d,
  478. "%s: Failed to read from flash\n",
  479. __func__);
  480. }
  481. scsi_unblock_requests(vha->host);
  482. return buf;
  483. }
  484. inline int
  485. qla8044_need_reset(struct scsi_qla_host *vha)
  486. {
  487. uint32_t drv_state, drv_active;
  488. int rval;
  489. struct qla_hw_data *ha = vha->hw;
  490. drv_active = qla8044_rd_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX);
  491. drv_state = qla8044_rd_direct(vha, QLA8044_CRB_DRV_STATE_INDEX);
  492. rval = drv_state & (1 << ha->portnum);
  493. if (ha->flags.eeh_busy && drv_active)
  494. rval = 1;
  495. return rval;
  496. }
  497. /*
  498. * qla8044_write_list - Write the value (p_entry->arg2) to address specified
  499. * by p_entry->arg1 for all entries in header with delay of p_hdr->delay between
  500. * entries.
  501. *
  502. * @vha : Pointer to adapter structure
  503. * @p_hdr : reset_entry header for WRITE_LIST opcode.
  504. *
  505. */
  506. static void
  507. qla8044_write_list(struct scsi_qla_host *vha,
  508. struct qla8044_reset_entry_hdr *p_hdr)
  509. {
  510. struct qla8044_entry *p_entry;
  511. uint32_t i;
  512. p_entry = (struct qla8044_entry *)((char *)p_hdr +
  513. sizeof(struct qla8044_reset_entry_hdr));
  514. for (i = 0; i < p_hdr->count; i++, p_entry++) {
  515. qla8044_wr_reg_indirect(vha, p_entry->arg1, p_entry->arg2);
  516. if (p_hdr->delay)
  517. udelay((uint32_t)(p_hdr->delay));
  518. }
  519. }
  520. /*
  521. * qla8044_read_write_list - Read from address specified by p_entry->arg1,
  522. * write value read to address specified by p_entry->arg2, for all entries in
  523. * header with delay of p_hdr->delay between entries.
  524. *
  525. * @vha : Pointer to adapter structure
  526. * @p_hdr : reset_entry header for READ_WRITE_LIST opcode.
  527. *
  528. */
  529. static void
  530. qla8044_read_write_list(struct scsi_qla_host *vha,
  531. struct qla8044_reset_entry_hdr *p_hdr)
  532. {
  533. struct qla8044_entry *p_entry;
  534. uint32_t i;
  535. p_entry = (struct qla8044_entry *)((char *)p_hdr +
  536. sizeof(struct qla8044_reset_entry_hdr));
  537. for (i = 0; i < p_hdr->count; i++, p_entry++) {
  538. qla8044_read_write_crb_reg(vha, p_entry->arg1,
  539. p_entry->arg2);
  540. if (p_hdr->delay)
  541. udelay((uint32_t)(p_hdr->delay));
  542. }
  543. }
  544. /*
  545. * qla8044_poll_reg - Poll the given CRB addr for duration msecs till
  546. * value read ANDed with test_mask is equal to test_result.
  547. *
  548. * @ha : Pointer to adapter structure
  549. * @addr : CRB register address
  550. * @duration : Poll for total of "duration" msecs
  551. * @test_mask : Mask value read with "test_mask"
  552. * @test_result : Compare (value&test_mask) with test_result.
  553. *
  554. * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
  555. */
  556. static int
  557. qla8044_poll_reg(struct scsi_qla_host *vha, uint32_t addr,
  558. int duration, uint32_t test_mask, uint32_t test_result)
  559. {
  560. uint32_t value;
  561. int timeout_error;
  562. uint8_t retries;
  563. int ret_val = QLA_SUCCESS;
  564. ret_val = qla8044_rd_reg_indirect(vha, addr, &value);
  565. if (ret_val == QLA_FUNCTION_FAILED) {
  566. timeout_error = 1;
  567. goto exit_poll_reg;
  568. }
  569. /* poll every 1/10 of the total duration */
  570. retries = duration/10;
  571. do {
  572. if ((value & test_mask) != test_result) {
  573. timeout_error = 1;
  574. msleep(duration/10);
  575. ret_val = qla8044_rd_reg_indirect(vha, addr, &value);
  576. if (ret_val == QLA_FUNCTION_FAILED) {
  577. timeout_error = 1;
  578. goto exit_poll_reg;
  579. }
  580. } else {
  581. timeout_error = 0;
  582. break;
  583. }
  584. } while (retries--);
  585. exit_poll_reg:
  586. if (timeout_error) {
  587. vha->reset_tmplt.seq_error++;
  588. ql_log(ql_log_fatal, vha, 0xb090,
  589. "%s: Poll Failed: 0x%08x 0x%08x 0x%08x\n",
  590. __func__, value, test_mask, test_result);
  591. }
  592. return timeout_error;
  593. }
  594. /*
  595. * qla8044_poll_list - For all entries in the POLL_LIST header, poll read CRB
  596. * register specified by p_entry->arg1 and compare (value AND test_mask) with
  597. * test_result to validate it. Wait for p_hdr->delay between processing entries.
  598. *
  599. * @ha : Pointer to adapter structure
  600. * @p_hdr : reset_entry header for POLL_LIST opcode.
  601. *
  602. */
  603. static void
  604. qla8044_poll_list(struct scsi_qla_host *vha,
  605. struct qla8044_reset_entry_hdr *p_hdr)
  606. {
  607. long delay;
  608. struct qla8044_entry *p_entry;
  609. struct qla8044_poll *p_poll;
  610. uint32_t i;
  611. uint32_t value;
  612. p_poll = (struct qla8044_poll *)
  613. ((char *)p_hdr + sizeof(struct qla8044_reset_entry_hdr));
  614. /* Entries start after 8 byte qla8044_poll, poll header contains
  615. * the test_mask, test_value.
  616. */
  617. p_entry = (struct qla8044_entry *)((char *)p_poll +
  618. sizeof(struct qla8044_poll));
  619. delay = (long)p_hdr->delay;
  620. if (!delay) {
  621. for (i = 0; i < p_hdr->count; i++, p_entry++)
  622. qla8044_poll_reg(vha, p_entry->arg1,
  623. delay, p_poll->test_mask, p_poll->test_value);
  624. } else {
  625. for (i = 0; i < p_hdr->count; i++, p_entry++) {
  626. if (delay) {
  627. if (qla8044_poll_reg(vha,
  628. p_entry->arg1, delay,
  629. p_poll->test_mask,
  630. p_poll->test_value)) {
  631. /*If
  632. * (data_read&test_mask != test_value)
  633. * read TIMEOUT_ADDR (arg1) and
  634. * ADDR (arg2) registers
  635. */
  636. qla8044_rd_reg_indirect(vha,
  637. p_entry->arg1, &value);
  638. qla8044_rd_reg_indirect(vha,
  639. p_entry->arg2, &value);
  640. }
  641. }
  642. }
  643. }
  644. }
  645. /*
  646. * qla8044_poll_write_list - Write dr_value, ar_value to dr_addr/ar_addr,
  647. * read ar_addr, if (value& test_mask != test_mask) re-read till timeout
  648. * expires.
  649. *
  650. * @vha : Pointer to adapter structure
  651. * @p_hdr : reset entry header for POLL_WRITE_LIST opcode.
  652. *
  653. */
  654. static void
  655. qla8044_poll_write_list(struct scsi_qla_host *vha,
  656. struct qla8044_reset_entry_hdr *p_hdr)
  657. {
  658. long delay;
  659. struct qla8044_quad_entry *p_entry;
  660. struct qla8044_poll *p_poll;
  661. uint32_t i;
  662. p_poll = (struct qla8044_poll *)((char *)p_hdr +
  663. sizeof(struct qla8044_reset_entry_hdr));
  664. p_entry = (struct qla8044_quad_entry *)((char *)p_poll +
  665. sizeof(struct qla8044_poll));
  666. delay = (long)p_hdr->delay;
  667. for (i = 0; i < p_hdr->count; i++, p_entry++) {
  668. qla8044_wr_reg_indirect(vha,
  669. p_entry->dr_addr, p_entry->dr_value);
  670. qla8044_wr_reg_indirect(vha,
  671. p_entry->ar_addr, p_entry->ar_value);
  672. if (delay) {
  673. if (qla8044_poll_reg(vha,
  674. p_entry->ar_addr, delay,
  675. p_poll->test_mask,
  676. p_poll->test_value)) {
  677. ql_dbg(ql_dbg_p3p, vha, 0xb091,
  678. "%s: Timeout Error: poll list, ",
  679. __func__);
  680. ql_dbg(ql_dbg_p3p, vha, 0xb092,
  681. "item_num %d, entry_num %d\n", i,
  682. vha->reset_tmplt.seq_index);
  683. }
  684. }
  685. }
  686. }
  687. /*
  688. * qla8044_read_modify_write - Read value from p_entry->arg1, modify the
  689. * value, write value to p_entry->arg2. Process entries with p_hdr->delay
  690. * between entries.
  691. *
  692. * @vha : Pointer to adapter structure
  693. * @p_hdr : header with shift/or/xor values.
  694. *
  695. */
  696. static void
  697. qla8044_read_modify_write(struct scsi_qla_host *vha,
  698. struct qla8044_reset_entry_hdr *p_hdr)
  699. {
  700. struct qla8044_entry *p_entry;
  701. struct qla8044_rmw *p_rmw_hdr;
  702. uint32_t i;
  703. p_rmw_hdr = (struct qla8044_rmw *)((char *)p_hdr +
  704. sizeof(struct qla8044_reset_entry_hdr));
  705. p_entry = (struct qla8044_entry *)((char *)p_rmw_hdr +
  706. sizeof(struct qla8044_rmw));
  707. for (i = 0; i < p_hdr->count; i++, p_entry++) {
  708. qla8044_rmw_crb_reg(vha, p_entry->arg1,
  709. p_entry->arg2, p_rmw_hdr);
  710. if (p_hdr->delay)
  711. udelay((uint32_t)(p_hdr->delay));
  712. }
  713. }
  714. /*
  715. * qla8044_pause - Wait for p_hdr->delay msecs, called between processing
  716. * two entries of a sequence.
  717. *
  718. * @vha : Pointer to adapter structure
  719. * @p_hdr : Common reset entry header.
  720. *
  721. */
  722. static
  723. void qla8044_pause(struct scsi_qla_host *vha,
  724. struct qla8044_reset_entry_hdr *p_hdr)
  725. {
  726. if (p_hdr->delay)
  727. mdelay((uint32_t)((long)p_hdr->delay));
  728. }
  729. /*
  730. * qla8044_template_end - Indicates end of reset sequence processing.
  731. *
  732. * @vha : Pointer to adapter structure
  733. * @p_hdr : Common reset entry header.
  734. *
  735. */
  736. static void
  737. qla8044_template_end(struct scsi_qla_host *vha,
  738. struct qla8044_reset_entry_hdr *p_hdr)
  739. {
  740. vha->reset_tmplt.template_end = 1;
  741. if (vha->reset_tmplt.seq_error == 0) {
  742. ql_dbg(ql_dbg_p3p, vha, 0xb093,
  743. "%s: Reset sequence completed SUCCESSFULLY.\n", __func__);
  744. } else {
  745. ql_log(ql_log_fatal, vha, 0xb094,
  746. "%s: Reset sequence completed with some timeout "
  747. "errors.\n", __func__);
  748. }
  749. }
  750. /*
  751. * qla8044_poll_read_list - Write ar_value to ar_addr register, read ar_addr,
  752. * if (value & test_mask != test_value) re-read till timeout value expires,
  753. * read dr_addr register and assign to reset_tmplt.array.
  754. *
  755. * @vha : Pointer to adapter structure
  756. * @p_hdr : Common reset entry header.
  757. *
  758. */
  759. static void
  760. qla8044_poll_read_list(struct scsi_qla_host *vha,
  761. struct qla8044_reset_entry_hdr *p_hdr)
  762. {
  763. long delay;
  764. int index;
  765. struct qla8044_quad_entry *p_entry;
  766. struct qla8044_poll *p_poll;
  767. uint32_t i;
  768. uint32_t value;
  769. p_poll = (struct qla8044_poll *)
  770. ((char *)p_hdr + sizeof(struct qla8044_reset_entry_hdr));
  771. p_entry = (struct qla8044_quad_entry *)
  772. ((char *)p_poll + sizeof(struct qla8044_poll));
  773. delay = (long)p_hdr->delay;
  774. for (i = 0; i < p_hdr->count; i++, p_entry++) {
  775. qla8044_wr_reg_indirect(vha, p_entry->ar_addr,
  776. p_entry->ar_value);
  777. if (delay) {
  778. if (qla8044_poll_reg(vha, p_entry->ar_addr, delay,
  779. p_poll->test_mask, p_poll->test_value)) {
  780. ql_dbg(ql_dbg_p3p, vha, 0xb095,
  781. "%s: Timeout Error: poll "
  782. "list, ", __func__);
  783. ql_dbg(ql_dbg_p3p, vha, 0xb096,
  784. "Item_num %d, "
  785. "entry_num %d\n", i,
  786. vha->reset_tmplt.seq_index);
  787. } else {
  788. index = vha->reset_tmplt.array_index;
  789. qla8044_rd_reg_indirect(vha,
  790. p_entry->dr_addr, &value);
  791. vha->reset_tmplt.array[index++] = value;
  792. if (index == QLA8044_MAX_RESET_SEQ_ENTRIES)
  793. vha->reset_tmplt.array_index = 1;
  794. }
  795. }
  796. }
  797. }
  798. /*
  799. * qla8031_process_reset_template - Process all entries in reset template
  800. * till entry with SEQ_END opcode, which indicates end of the reset template
  801. * processing. Each entry has a Reset Entry header, entry opcode/command, with
  802. * size of the entry, number of entries in sub-sequence and delay in microsecs
  803. * or timeout in millisecs.
  804. *
  805. * @ha : Pointer to adapter structure
  806. * @p_buff : Common reset entry header.
  807. *
  808. */
  809. static void
  810. qla8044_process_reset_template(struct scsi_qla_host *vha,
  811. char *p_buff)
  812. {
  813. int index, entries;
  814. struct qla8044_reset_entry_hdr *p_hdr;
  815. char *p_entry = p_buff;
  816. vha->reset_tmplt.seq_end = 0;
  817. vha->reset_tmplt.template_end = 0;
  818. entries = vha->reset_tmplt.hdr->entries;
  819. index = vha->reset_tmplt.seq_index;
  820. for (; (!vha->reset_tmplt.seq_end) && (index < entries); index++) {
  821. p_hdr = (struct qla8044_reset_entry_hdr *)p_entry;
  822. switch (p_hdr->cmd) {
  823. case OPCODE_NOP:
  824. break;
  825. case OPCODE_WRITE_LIST:
  826. qla8044_write_list(vha, p_hdr);
  827. break;
  828. case OPCODE_READ_WRITE_LIST:
  829. qla8044_read_write_list(vha, p_hdr);
  830. break;
  831. case OPCODE_POLL_LIST:
  832. qla8044_poll_list(vha, p_hdr);
  833. break;
  834. case OPCODE_POLL_WRITE_LIST:
  835. qla8044_poll_write_list(vha, p_hdr);
  836. break;
  837. case OPCODE_READ_MODIFY_WRITE:
  838. qla8044_read_modify_write(vha, p_hdr);
  839. break;
  840. case OPCODE_SEQ_PAUSE:
  841. qla8044_pause(vha, p_hdr);
  842. break;
  843. case OPCODE_SEQ_END:
  844. vha->reset_tmplt.seq_end = 1;
  845. break;
  846. case OPCODE_TMPL_END:
  847. qla8044_template_end(vha, p_hdr);
  848. break;
  849. case OPCODE_POLL_READ_LIST:
  850. qla8044_poll_read_list(vha, p_hdr);
  851. break;
  852. default:
  853. ql_log(ql_log_fatal, vha, 0xb097,
  854. "%s: Unknown command ==> 0x%04x on "
  855. "entry = %d\n", __func__, p_hdr->cmd, index);
  856. break;
  857. }
  858. /*
  859. *Set pointer to next entry in the sequence.
  860. */
  861. p_entry += p_hdr->size;
  862. }
  863. vha->reset_tmplt.seq_index = index;
  864. }
  865. static void
  866. qla8044_process_init_seq(struct scsi_qla_host *vha)
  867. {
  868. qla8044_process_reset_template(vha,
  869. vha->reset_tmplt.init_offset);
  870. if (vha->reset_tmplt.seq_end != 1)
  871. ql_log(ql_log_fatal, vha, 0xb098,
  872. "%s: Abrupt INIT Sub-Sequence end.\n",
  873. __func__);
  874. }
  875. static void
  876. qla8044_process_stop_seq(struct scsi_qla_host *vha)
  877. {
  878. vha->reset_tmplt.seq_index = 0;
  879. qla8044_process_reset_template(vha, vha->reset_tmplt.stop_offset);
  880. if (vha->reset_tmplt.seq_end != 1)
  881. ql_log(ql_log_fatal, vha, 0xb099,
  882. "%s: Abrupt STOP Sub-Sequence end.\n", __func__);
  883. }
  884. static void
  885. qla8044_process_start_seq(struct scsi_qla_host *vha)
  886. {
  887. qla8044_process_reset_template(vha, vha->reset_tmplt.start_offset);
  888. if (vha->reset_tmplt.template_end != 1)
  889. ql_log(ql_log_fatal, vha, 0xb09a,
  890. "%s: Abrupt START Sub-Sequence end.\n",
  891. __func__);
  892. }
  893. static int
  894. qla8044_lockless_flash_read_u32(struct scsi_qla_host *vha,
  895. uint32_t flash_addr, uint8_t *p_data, int u32_word_count)
  896. {
  897. uint32_t i;
  898. uint32_t u32_word;
  899. uint32_t flash_offset;
  900. uint32_t addr = flash_addr;
  901. int ret_val = QLA_SUCCESS;
  902. flash_offset = addr & (QLA8044_FLASH_SECTOR_SIZE - 1);
  903. if (addr & 0x3) {
  904. ql_log(ql_log_fatal, vha, 0xb09b, "%s: Illegal addr = 0x%x\n",
  905. __func__, addr);
  906. ret_val = QLA_FUNCTION_FAILED;
  907. goto exit_lockless_read;
  908. }
  909. ret_val = qla8044_wr_reg_indirect(vha,
  910. QLA8044_FLASH_DIRECT_WINDOW, (addr));
  911. if (ret_val != QLA_SUCCESS) {
  912. ql_log(ql_log_fatal, vha, 0xb09c,
  913. "%s: failed to write addr 0x%x to FLASH_DIRECT_WINDOW!\n",
  914. __func__, addr);
  915. goto exit_lockless_read;
  916. }
  917. /* Check if data is spread across multiple sectors */
  918. if ((flash_offset + (u32_word_count * sizeof(uint32_t))) >
  919. (QLA8044_FLASH_SECTOR_SIZE - 1)) {
  920. /* Multi sector read */
  921. for (i = 0; i < u32_word_count; i++) {
  922. ret_val = qla8044_rd_reg_indirect(vha,
  923. QLA8044_FLASH_DIRECT_DATA(addr), &u32_word);
  924. if (ret_val != QLA_SUCCESS) {
  925. ql_log(ql_log_fatal, vha, 0xb09d,
  926. "%s: failed to read addr 0x%x!\n",
  927. __func__, addr);
  928. goto exit_lockless_read;
  929. }
  930. *(uint32_t *)p_data = u32_word;
  931. p_data = p_data + 4;
  932. addr = addr + 4;
  933. flash_offset = flash_offset + 4;
  934. if (flash_offset > (QLA8044_FLASH_SECTOR_SIZE - 1)) {
  935. /* This write is needed once for each sector */
  936. ret_val = qla8044_wr_reg_indirect(vha,
  937. QLA8044_FLASH_DIRECT_WINDOW, (addr));
  938. if (ret_val != QLA_SUCCESS) {
  939. ql_log(ql_log_fatal, vha, 0xb09f,
  940. "%s: failed to write addr "
  941. "0x%x to FLASH_DIRECT_WINDOW!\n",
  942. __func__, addr);
  943. goto exit_lockless_read;
  944. }
  945. flash_offset = 0;
  946. }
  947. }
  948. } else {
  949. /* Single sector read */
  950. for (i = 0; i < u32_word_count; i++) {
  951. ret_val = qla8044_rd_reg_indirect(vha,
  952. QLA8044_FLASH_DIRECT_DATA(addr), &u32_word);
  953. if (ret_val != QLA_SUCCESS) {
  954. ql_log(ql_log_fatal, vha, 0xb0a0,
  955. "%s: failed to read addr 0x%x!\n",
  956. __func__, addr);
  957. goto exit_lockless_read;
  958. }
  959. *(uint32_t *)p_data = u32_word;
  960. p_data = p_data + 4;
  961. addr = addr + 4;
  962. }
  963. }
  964. exit_lockless_read:
  965. return ret_val;
  966. }
  967. /*
  968. * qla8044_ms_mem_write_128b - Writes data to MS/off-chip memory
  969. *
  970. * @vha : Pointer to adapter structure
  971. * addr : Flash address to write to
  972. * data : Data to be written
  973. * count : word_count to be written
  974. *
  975. * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
  976. */
  977. static int
  978. qla8044_ms_mem_write_128b(struct scsi_qla_host *vha,
  979. uint64_t addr, uint32_t *data, uint32_t count)
  980. {
  981. int i, j, ret_val = QLA_SUCCESS;
  982. uint32_t agt_ctrl;
  983. unsigned long flags;
  984. struct qla_hw_data *ha = vha->hw;
  985. /* Only 128-bit aligned access */
  986. if (addr & 0xF) {
  987. ret_val = QLA_FUNCTION_FAILED;
  988. goto exit_ms_mem_write;
  989. }
  990. write_lock_irqsave(&ha->hw_lock, flags);
  991. /* Write address */
  992. ret_val = qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_ADDR_HI, 0);
  993. if (ret_val == QLA_FUNCTION_FAILED) {
  994. ql_log(ql_log_fatal, vha, 0xb0a1,
  995. "%s: write to AGT_ADDR_HI failed!\n", __func__);
  996. goto exit_ms_mem_write_unlock;
  997. }
  998. for (i = 0; i < count; i++, addr += 16) {
  999. if (!((QLA8044_ADDR_IN_RANGE(addr, QLA8044_ADDR_QDR_NET,
  1000. QLA8044_ADDR_QDR_NET_MAX)) ||
  1001. (QLA8044_ADDR_IN_RANGE(addr, QLA8044_ADDR_DDR_NET,
  1002. QLA8044_ADDR_DDR_NET_MAX)))) {
  1003. ret_val = QLA_FUNCTION_FAILED;
  1004. goto exit_ms_mem_write_unlock;
  1005. }
  1006. ret_val = qla8044_wr_reg_indirect(vha,
  1007. MD_MIU_TEST_AGT_ADDR_LO, addr);
  1008. /* Write data */
  1009. ret_val += qla8044_wr_reg_indirect(vha,
  1010. MD_MIU_TEST_AGT_WRDATA_LO, *data++);
  1011. ret_val += qla8044_wr_reg_indirect(vha,
  1012. MD_MIU_TEST_AGT_WRDATA_HI, *data++);
  1013. ret_val += qla8044_wr_reg_indirect(vha,
  1014. MD_MIU_TEST_AGT_WRDATA_ULO, *data++);
  1015. ret_val += qla8044_wr_reg_indirect(vha,
  1016. MD_MIU_TEST_AGT_WRDATA_UHI, *data++);
  1017. if (ret_val == QLA_FUNCTION_FAILED) {
  1018. ql_log(ql_log_fatal, vha, 0xb0a2,
  1019. "%s: write to AGT_WRDATA failed!\n",
  1020. __func__);
  1021. goto exit_ms_mem_write_unlock;
  1022. }
  1023. /* Check write status */
  1024. ret_val = qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_CTRL,
  1025. MIU_TA_CTL_WRITE_ENABLE);
  1026. ret_val += qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_CTRL,
  1027. MIU_TA_CTL_WRITE_START);
  1028. if (ret_val == QLA_FUNCTION_FAILED) {
  1029. ql_log(ql_log_fatal, vha, 0xb0a3,
  1030. "%s: write to AGT_CTRL failed!\n", __func__);
  1031. goto exit_ms_mem_write_unlock;
  1032. }
  1033. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1034. ret_val = qla8044_rd_reg_indirect(vha,
  1035. MD_MIU_TEST_AGT_CTRL, &agt_ctrl);
  1036. if (ret_val == QLA_FUNCTION_FAILED) {
  1037. ql_log(ql_log_fatal, vha, 0xb0a4,
  1038. "%s: failed to read "
  1039. "MD_MIU_TEST_AGT_CTRL!\n", __func__);
  1040. goto exit_ms_mem_write_unlock;
  1041. }
  1042. if ((agt_ctrl & MIU_TA_CTL_BUSY) == 0)
  1043. break;
  1044. }
  1045. /* Status check failed */
  1046. if (j >= MAX_CTL_CHECK) {
  1047. ql_log(ql_log_fatal, vha, 0xb0a5,
  1048. "%s: MS memory write failed!\n",
  1049. __func__);
  1050. ret_val = QLA_FUNCTION_FAILED;
  1051. goto exit_ms_mem_write_unlock;
  1052. }
  1053. }
  1054. exit_ms_mem_write_unlock:
  1055. write_unlock_irqrestore(&ha->hw_lock, flags);
  1056. exit_ms_mem_write:
  1057. return ret_val;
  1058. }
  1059. static int
  1060. qla8044_copy_bootloader(struct scsi_qla_host *vha)
  1061. {
  1062. uint8_t *p_cache;
  1063. uint32_t src, count, size;
  1064. uint64_t dest;
  1065. int ret_val = QLA_SUCCESS;
  1066. struct qla_hw_data *ha = vha->hw;
  1067. src = QLA8044_BOOTLOADER_FLASH_ADDR;
  1068. dest = qla8044_rd_reg(ha, QLA8044_BOOTLOADER_ADDR);
  1069. size = qla8044_rd_reg(ha, QLA8044_BOOTLOADER_SIZE);
  1070. /* 128 bit alignment check */
  1071. if (size & 0xF)
  1072. size = (size + 16) & ~0xF;
  1073. /* 16 byte count */
  1074. count = size/16;
  1075. p_cache = vmalloc(size);
  1076. if (p_cache == NULL) {
  1077. ql_log(ql_log_fatal, vha, 0xb0a6,
  1078. "%s: Failed to allocate memory for "
  1079. "boot loader cache\n", __func__);
  1080. ret_val = QLA_FUNCTION_FAILED;
  1081. goto exit_copy_bootloader;
  1082. }
  1083. ret_val = qla8044_lockless_flash_read_u32(vha, src,
  1084. p_cache, size/sizeof(uint32_t));
  1085. if (ret_val == QLA_FUNCTION_FAILED) {
  1086. ql_log(ql_log_fatal, vha, 0xb0a7,
  1087. "%s: Error reading F/W from flash!!!\n", __func__);
  1088. goto exit_copy_error;
  1089. }
  1090. ql_dbg(ql_dbg_p3p, vha, 0xb0a8, "%s: Read F/W from flash!\n",
  1091. __func__);
  1092. /* 128 bit/16 byte write to MS memory */
  1093. ret_val = qla8044_ms_mem_write_128b(vha, dest,
  1094. (uint32_t *)p_cache, count);
  1095. if (ret_val == QLA_FUNCTION_FAILED) {
  1096. ql_log(ql_log_fatal, vha, 0xb0a9,
  1097. "%s: Error writing F/W to MS !!!\n", __func__);
  1098. goto exit_copy_error;
  1099. }
  1100. ql_dbg(ql_dbg_p3p, vha, 0xb0aa,
  1101. "%s: Wrote F/W (size %d) to MS !!!\n",
  1102. __func__, size);
  1103. exit_copy_error:
  1104. vfree(p_cache);
  1105. exit_copy_bootloader:
  1106. return ret_val;
  1107. }
  1108. static int
  1109. qla8044_restart(struct scsi_qla_host *vha)
  1110. {
  1111. int ret_val = QLA_SUCCESS;
  1112. struct qla_hw_data *ha = vha->hw;
  1113. qla8044_process_stop_seq(vha);
  1114. /* Collect minidump */
  1115. if (ql2xmdenable)
  1116. qla8044_get_minidump(vha);
  1117. else
  1118. ql_log(ql_log_fatal, vha, 0xb14c,
  1119. "Minidump disabled.\n");
  1120. qla8044_process_init_seq(vha);
  1121. if (qla8044_copy_bootloader(vha)) {
  1122. ql_log(ql_log_fatal, vha, 0xb0ab,
  1123. "%s: Copy bootloader, firmware restart failed!\n",
  1124. __func__);
  1125. ret_val = QLA_FUNCTION_FAILED;
  1126. goto exit_restart;
  1127. }
  1128. /*
  1129. * Loads F/W from flash
  1130. */
  1131. qla8044_wr_reg(ha, QLA8044_FW_IMAGE_VALID, QLA8044_BOOT_FROM_FLASH);
  1132. qla8044_process_start_seq(vha);
  1133. exit_restart:
  1134. return ret_val;
  1135. }
  1136. /*
  1137. * qla8044_check_cmd_peg_status - Check peg status to see if Peg is
  1138. * initialized.
  1139. *
  1140. * @ha : Pointer to adapter structure
  1141. *
  1142. * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
  1143. */
  1144. static int
  1145. qla8044_check_cmd_peg_status(struct scsi_qla_host *vha)
  1146. {
  1147. uint32_t val, ret_val = QLA_FUNCTION_FAILED;
  1148. int retries = CRB_CMDPEG_CHECK_RETRY_COUNT;
  1149. struct qla_hw_data *ha = vha->hw;
  1150. do {
  1151. val = qla8044_rd_reg(ha, QLA8044_CMDPEG_STATE);
  1152. if (val == PHAN_INITIALIZE_COMPLETE) {
  1153. ql_dbg(ql_dbg_p3p, vha, 0xb0ac,
  1154. "%s: Command Peg initialization "
  1155. "complete! state=0x%x\n", __func__, val);
  1156. ret_val = QLA_SUCCESS;
  1157. break;
  1158. }
  1159. msleep(CRB_CMDPEG_CHECK_DELAY);
  1160. } while (--retries);
  1161. return ret_val;
  1162. }
  1163. static int
  1164. qla8044_start_firmware(struct scsi_qla_host *vha)
  1165. {
  1166. int ret_val = QLA_SUCCESS;
  1167. if (qla8044_restart(vha)) {
  1168. ql_log(ql_log_fatal, vha, 0xb0ad,
  1169. "%s: Restart Error!!!, Need Reset!!!\n",
  1170. __func__);
  1171. ret_val = QLA_FUNCTION_FAILED;
  1172. goto exit_start_fw;
  1173. } else
  1174. ql_dbg(ql_dbg_p3p, vha, 0xb0af,
  1175. "%s: Restart done!\n", __func__);
  1176. ret_val = qla8044_check_cmd_peg_status(vha);
  1177. if (ret_val) {
  1178. ql_log(ql_log_fatal, vha, 0xb0b0,
  1179. "%s: Peg not initialized!\n", __func__);
  1180. ret_val = QLA_FUNCTION_FAILED;
  1181. }
  1182. exit_start_fw:
  1183. return ret_val;
  1184. }
  1185. void
  1186. qla8044_clear_drv_active(struct qla_hw_data *ha)
  1187. {
  1188. uint32_t drv_active;
  1189. struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
  1190. drv_active = qla8044_rd_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX);
  1191. drv_active &= ~(1 << (ha->portnum));
  1192. ql_log(ql_log_info, vha, 0xb0b1,
  1193. "%s(%ld): drv_active: 0x%08x\n",
  1194. __func__, vha->host_no, drv_active);
  1195. qla8044_wr_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX, drv_active);
  1196. }
  1197. /*
  1198. * qla8044_device_bootstrap - Initialize device, set DEV_READY, start fw
  1199. * @ha: pointer to adapter structure
  1200. *
  1201. * Note: IDC lock must be held upon entry
  1202. **/
  1203. static int
  1204. qla8044_device_bootstrap(struct scsi_qla_host *vha)
  1205. {
  1206. int rval = QLA_FUNCTION_FAILED;
  1207. int i;
  1208. uint32_t old_count = 0, count = 0;
  1209. int need_reset = 0;
  1210. uint32_t idc_ctrl;
  1211. struct qla_hw_data *ha = vha->hw;
  1212. need_reset = qla8044_need_reset(vha);
  1213. if (!need_reset) {
  1214. old_count = qla8044_rd_direct(vha,
  1215. QLA8044_PEG_ALIVE_COUNTER_INDEX);
  1216. for (i = 0; i < 10; i++) {
  1217. msleep(200);
  1218. count = qla8044_rd_direct(vha,
  1219. QLA8044_PEG_ALIVE_COUNTER_INDEX);
  1220. if (count != old_count) {
  1221. rval = QLA_SUCCESS;
  1222. goto dev_ready;
  1223. }
  1224. }
  1225. qla8044_flash_lock_recovery(vha);
  1226. } else {
  1227. /* We are trying to perform a recovery here. */
  1228. if (ha->flags.isp82xx_fw_hung)
  1229. qla8044_flash_lock_recovery(vha);
  1230. }
  1231. /* set to DEV_INITIALIZING */
  1232. ql_log(ql_log_info, vha, 0xb0b2,
  1233. "%s: HW State: INITIALIZING\n", __func__);
  1234. qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX,
  1235. QLA8XXX_DEV_INITIALIZING);
  1236. qla8044_idc_unlock(ha);
  1237. rval = qla8044_start_firmware(vha);
  1238. qla8044_idc_lock(ha);
  1239. if (rval != QLA_SUCCESS) {
  1240. ql_log(ql_log_info, vha, 0xb0b3,
  1241. "%s: HW State: FAILED\n", __func__);
  1242. qla8044_clear_drv_active(ha);
  1243. qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX,
  1244. QLA8XXX_DEV_FAILED);
  1245. return rval;
  1246. }
  1247. /* For ISP8044, If IDC_CTRL GRACEFUL_RESET_BIT1 is set , reset it after
  1248. * device goes to INIT state. */
  1249. idc_ctrl = qla8044_rd_reg(ha, QLA8044_IDC_DRV_CTRL);
  1250. if (idc_ctrl & GRACEFUL_RESET_BIT1) {
  1251. qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
  1252. (idc_ctrl & ~GRACEFUL_RESET_BIT1));
  1253. ha->fw_dumped = 0;
  1254. }
  1255. dev_ready:
  1256. ql_log(ql_log_info, vha, 0xb0b4,
  1257. "%s: HW State: READY\n", __func__);
  1258. qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX, QLA8XXX_DEV_READY);
  1259. return rval;
  1260. }
  1261. /*-------------------------Reset Sequence Functions-----------------------*/
  1262. static void
  1263. qla8044_dump_reset_seq_hdr(struct scsi_qla_host *vha)
  1264. {
  1265. u8 *phdr;
  1266. if (!vha->reset_tmplt.buff) {
  1267. ql_log(ql_log_fatal, vha, 0xb0b5,
  1268. "%s: Error Invalid reset_seq_template\n", __func__);
  1269. return;
  1270. }
  1271. phdr = vha->reset_tmplt.buff;
  1272. ql_dbg(ql_dbg_p3p, vha, 0xb0b6,
  1273. "Reset Template :\n\t0x%X 0x%X 0x%X 0x%X"
  1274. "0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n"
  1275. "\t0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n\n",
  1276. *phdr, *(phdr+1), *(phdr+2), *(phdr+3), *(phdr+4),
  1277. *(phdr+5), *(phdr+6), *(phdr+7), *(phdr + 8),
  1278. *(phdr+9), *(phdr+10), *(phdr+11), *(phdr+12),
  1279. *(phdr+13), *(phdr+14), *(phdr+15));
  1280. }
  1281. /*
  1282. * qla8044_reset_seq_checksum_test - Validate Reset Sequence template.
  1283. *
  1284. * @ha : Pointer to adapter structure
  1285. *
  1286. * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
  1287. */
  1288. static int
  1289. qla8044_reset_seq_checksum_test(struct scsi_qla_host *vha)
  1290. {
  1291. uint32_t sum = 0;
  1292. uint16_t *buff = (uint16_t *)vha->reset_tmplt.buff;
  1293. int u16_count = vha->reset_tmplt.hdr->size / sizeof(uint16_t);
  1294. while (u16_count-- > 0)
  1295. sum += *buff++;
  1296. while (sum >> 16)
  1297. sum = (sum & 0xFFFF) + (sum >> 16);
  1298. /* checksum of 0 indicates a valid template */
  1299. if (~sum) {
  1300. return QLA_SUCCESS;
  1301. } else {
  1302. ql_log(ql_log_fatal, vha, 0xb0b7,
  1303. "%s: Reset seq checksum failed\n", __func__);
  1304. return QLA_FUNCTION_FAILED;
  1305. }
  1306. }
  1307. /*
  1308. * qla8044_read_reset_template - Read Reset Template from Flash, validate
  1309. * the template and store offsets of stop/start/init offsets in ha->reset_tmplt.
  1310. *
  1311. * @ha : Pointer to adapter structure
  1312. */
  1313. void
  1314. qla8044_read_reset_template(struct scsi_qla_host *vha)
  1315. {
  1316. uint8_t *p_buff;
  1317. uint32_t addr, tmplt_hdr_def_size, tmplt_hdr_size;
  1318. vha->reset_tmplt.seq_error = 0;
  1319. vha->reset_tmplt.buff = vmalloc(QLA8044_RESTART_TEMPLATE_SIZE);
  1320. if (vha->reset_tmplt.buff == NULL) {
  1321. ql_log(ql_log_fatal, vha, 0xb0b8,
  1322. "%s: Failed to allocate reset template resources\n",
  1323. __func__);
  1324. goto exit_read_reset_template;
  1325. }
  1326. p_buff = vha->reset_tmplt.buff;
  1327. addr = QLA8044_RESET_TEMPLATE_ADDR;
  1328. tmplt_hdr_def_size =
  1329. sizeof(struct qla8044_reset_template_hdr) / sizeof(uint32_t);
  1330. ql_dbg(ql_dbg_p3p, vha, 0xb0b9,
  1331. "%s: Read template hdr size %d from Flash\n",
  1332. __func__, tmplt_hdr_def_size);
  1333. /* Copy template header from flash */
  1334. if (qla8044_read_flash_data(vha, p_buff, addr, tmplt_hdr_def_size)) {
  1335. ql_log(ql_log_fatal, vha, 0xb0ba,
  1336. "%s: Failed to read reset template\n", __func__);
  1337. goto exit_read_template_error;
  1338. }
  1339. vha->reset_tmplt.hdr =
  1340. (struct qla8044_reset_template_hdr *) vha->reset_tmplt.buff;
  1341. /* Validate the template header size and signature */
  1342. tmplt_hdr_size = vha->reset_tmplt.hdr->hdr_size/sizeof(uint32_t);
  1343. if ((tmplt_hdr_size != tmplt_hdr_def_size) ||
  1344. (vha->reset_tmplt.hdr->signature != RESET_TMPLT_HDR_SIGNATURE)) {
  1345. ql_log(ql_log_fatal, vha, 0xb0bb,
  1346. "%s: Template Header size invalid %d "
  1347. "tmplt_hdr_def_size %d!!!\n", __func__,
  1348. tmplt_hdr_size, tmplt_hdr_def_size);
  1349. goto exit_read_template_error;
  1350. }
  1351. addr = QLA8044_RESET_TEMPLATE_ADDR + vha->reset_tmplt.hdr->hdr_size;
  1352. p_buff = vha->reset_tmplt.buff + vha->reset_tmplt.hdr->hdr_size;
  1353. tmplt_hdr_def_size = (vha->reset_tmplt.hdr->size -
  1354. vha->reset_tmplt.hdr->hdr_size)/sizeof(uint32_t);
  1355. ql_dbg(ql_dbg_p3p, vha, 0xb0bc,
  1356. "%s: Read rest of the template size %d\n",
  1357. __func__, vha->reset_tmplt.hdr->size);
  1358. /* Copy rest of the template */
  1359. if (qla8044_read_flash_data(vha, p_buff, addr, tmplt_hdr_def_size)) {
  1360. ql_log(ql_log_fatal, vha, 0xb0bd,
  1361. "%s: Failed to read reset tempelate\n", __func__);
  1362. goto exit_read_template_error;
  1363. }
  1364. /* Integrity check */
  1365. if (qla8044_reset_seq_checksum_test(vha)) {
  1366. ql_log(ql_log_fatal, vha, 0xb0be,
  1367. "%s: Reset Seq checksum failed!\n", __func__);
  1368. goto exit_read_template_error;
  1369. }
  1370. ql_dbg(ql_dbg_p3p, vha, 0xb0bf,
  1371. "%s: Reset Seq checksum passed! Get stop, "
  1372. "start and init seq offsets\n", __func__);
  1373. /* Get STOP, START, INIT sequence offsets */
  1374. vha->reset_tmplt.init_offset = vha->reset_tmplt.buff +
  1375. vha->reset_tmplt.hdr->init_seq_offset;
  1376. vha->reset_tmplt.start_offset = vha->reset_tmplt.buff +
  1377. vha->reset_tmplt.hdr->start_seq_offset;
  1378. vha->reset_tmplt.stop_offset = vha->reset_tmplt.buff +
  1379. vha->reset_tmplt.hdr->hdr_size;
  1380. qla8044_dump_reset_seq_hdr(vha);
  1381. goto exit_read_reset_template;
  1382. exit_read_template_error:
  1383. vfree(vha->reset_tmplt.buff);
  1384. exit_read_reset_template:
  1385. return;
  1386. }
  1387. void
  1388. qla8044_set_idc_dontreset(struct scsi_qla_host *vha)
  1389. {
  1390. uint32_t idc_ctrl;
  1391. struct qla_hw_data *ha = vha->hw;
  1392. idc_ctrl = qla8044_rd_reg(ha, QLA8044_IDC_DRV_CTRL);
  1393. idc_ctrl |= DONTRESET_BIT0;
  1394. ql_dbg(ql_dbg_p3p, vha, 0xb0c0,
  1395. "%s: idc_ctrl = %d\n", __func__, idc_ctrl);
  1396. qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL, idc_ctrl);
  1397. }
  1398. inline void
  1399. qla8044_set_rst_ready(struct scsi_qla_host *vha)
  1400. {
  1401. uint32_t drv_state;
  1402. struct qla_hw_data *ha = vha->hw;
  1403. drv_state = qla8044_rd_direct(vha, QLA8044_CRB_DRV_STATE_INDEX);
  1404. /* For ISP8044, drv_active register has 1 bit per function,
  1405. * shift 1 by func_num to set a bit for the function.*/
  1406. drv_state |= (1 << ha->portnum);
  1407. ql_log(ql_log_info, vha, 0xb0c1,
  1408. "%s(%ld): drv_state: 0x%08x\n",
  1409. __func__, vha->host_no, drv_state);
  1410. qla8044_wr_direct(vha, QLA8044_CRB_DRV_STATE_INDEX, drv_state);
  1411. }
  1412. /**
  1413. * qla8044_need_reset_handler - Code to start reset sequence
  1414. * @ha: pointer to adapter structure
  1415. *
  1416. * Note: IDC lock must be held upon entry
  1417. **/
  1418. static void
  1419. qla8044_need_reset_handler(struct scsi_qla_host *vha)
  1420. {
  1421. uint32_t dev_state = 0, drv_state, drv_active;
  1422. unsigned long reset_timeout;
  1423. struct qla_hw_data *ha = vha->hw;
  1424. ql_log(ql_log_fatal, vha, 0xb0c2,
  1425. "%s: Performing ISP error recovery\n", __func__);
  1426. if (vha->flags.online) {
  1427. qla8044_idc_unlock(ha);
  1428. qla2x00_abort_isp_cleanup(vha);
  1429. ha->isp_ops->get_flash_version(vha, vha->req->ring);
  1430. ha->isp_ops->nvram_config(vha);
  1431. qla8044_idc_lock(ha);
  1432. }
  1433. dev_state = qla8044_rd_direct(vha,
  1434. QLA8044_CRB_DEV_STATE_INDEX);
  1435. drv_state = qla8044_rd_direct(vha,
  1436. QLA8044_CRB_DRV_STATE_INDEX);
  1437. drv_active = qla8044_rd_direct(vha,
  1438. QLA8044_CRB_DRV_ACTIVE_INDEX);
  1439. ql_log(ql_log_info, vha, 0xb0c5,
  1440. "%s(%ld): drv_state = 0x%x, drv_active = 0x%x dev_state = 0x%x\n",
  1441. __func__, vha->host_no, drv_state, drv_active, dev_state);
  1442. qla8044_set_rst_ready(vha);
  1443. /* wait for 10 seconds for reset ack from all functions */
  1444. reset_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
  1445. do {
  1446. if (time_after_eq(jiffies, reset_timeout)) {
  1447. ql_log(ql_log_info, vha, 0xb0c4,
  1448. "%s: Function %d: Reset Ack Timeout!, drv_state: 0x%08x, drv_active: 0x%08x\n",
  1449. __func__, ha->portnum, drv_state, drv_active);
  1450. break;
  1451. }
  1452. qla8044_idc_unlock(ha);
  1453. msleep(1000);
  1454. qla8044_idc_lock(ha);
  1455. dev_state = qla8044_rd_direct(vha,
  1456. QLA8044_CRB_DEV_STATE_INDEX);
  1457. drv_state = qla8044_rd_direct(vha,
  1458. QLA8044_CRB_DRV_STATE_INDEX);
  1459. drv_active = qla8044_rd_direct(vha,
  1460. QLA8044_CRB_DRV_ACTIVE_INDEX);
  1461. } while (((drv_state & drv_active) != drv_active) &&
  1462. (dev_state == QLA8XXX_DEV_NEED_RESET));
  1463. /* Remove IDC participation of functions not acknowledging */
  1464. if (drv_state != drv_active) {
  1465. ql_log(ql_log_info, vha, 0xb0c7,
  1466. "%s(%ld): Function %d turning off drv_active of non-acking function 0x%x\n",
  1467. __func__, vha->host_no, ha->portnum,
  1468. (drv_active ^ drv_state));
  1469. drv_active = drv_active & drv_state;
  1470. qla8044_wr_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX,
  1471. drv_active);
  1472. } else {
  1473. /*
  1474. * Reset owner should execute reset recovery,
  1475. * if all functions acknowledged
  1476. */
  1477. if ((ha->flags.nic_core_reset_owner) &&
  1478. (dev_state == QLA8XXX_DEV_NEED_RESET)) {
  1479. ha->flags.nic_core_reset_owner = 0;
  1480. qla8044_device_bootstrap(vha);
  1481. return;
  1482. }
  1483. }
  1484. /* Exit if non active function */
  1485. if (!(drv_active & (1 << ha->portnum))) {
  1486. ha->flags.nic_core_reset_owner = 0;
  1487. return;
  1488. }
  1489. /*
  1490. * Execute Reset Recovery if Reset Owner or Function 7
  1491. * is the only active function
  1492. */
  1493. if (ha->flags.nic_core_reset_owner ||
  1494. ((drv_state & drv_active) == QLA8044_FUN7_ACTIVE_INDEX)) {
  1495. ha->flags.nic_core_reset_owner = 0;
  1496. qla8044_device_bootstrap(vha);
  1497. }
  1498. }
  1499. static void
  1500. qla8044_set_drv_active(struct scsi_qla_host *vha)
  1501. {
  1502. uint32_t drv_active;
  1503. struct qla_hw_data *ha = vha->hw;
  1504. drv_active = qla8044_rd_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX);
  1505. /* For ISP8044, drv_active register has 1 bit per function,
  1506. * shift 1 by func_num to set a bit for the function.*/
  1507. drv_active |= (1 << ha->portnum);
  1508. ql_log(ql_log_info, vha, 0xb0c8,
  1509. "%s(%ld): drv_active: 0x%08x\n",
  1510. __func__, vha->host_no, drv_active);
  1511. qla8044_wr_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX, drv_active);
  1512. }
  1513. static int
  1514. qla8044_check_drv_active(struct scsi_qla_host *vha)
  1515. {
  1516. uint32_t drv_active;
  1517. struct qla_hw_data *ha = vha->hw;
  1518. drv_active = qla8044_rd_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX);
  1519. if (drv_active & (1 << ha->portnum))
  1520. return QLA_SUCCESS;
  1521. else
  1522. return QLA_TEST_FAILED;
  1523. }
  1524. static void
  1525. qla8044_clear_idc_dontreset(struct scsi_qla_host *vha)
  1526. {
  1527. uint32_t idc_ctrl;
  1528. struct qla_hw_data *ha = vha->hw;
  1529. idc_ctrl = qla8044_rd_reg(ha, QLA8044_IDC_DRV_CTRL);
  1530. idc_ctrl &= ~DONTRESET_BIT0;
  1531. ql_log(ql_log_info, vha, 0xb0c9,
  1532. "%s: idc_ctrl = %d\n", __func__,
  1533. idc_ctrl);
  1534. qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL, idc_ctrl);
  1535. }
  1536. static int
  1537. qla8044_set_idc_ver(struct scsi_qla_host *vha)
  1538. {
  1539. int idc_ver;
  1540. uint32_t drv_active;
  1541. int rval = QLA_SUCCESS;
  1542. struct qla_hw_data *ha = vha->hw;
  1543. drv_active = qla8044_rd_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX);
  1544. if (drv_active == (1 << ha->portnum)) {
  1545. idc_ver = qla8044_rd_direct(vha,
  1546. QLA8044_CRB_DRV_IDC_VERSION_INDEX);
  1547. idc_ver &= (~0xFF);
  1548. idc_ver |= QLA8044_IDC_VER_MAJ_VALUE;
  1549. qla8044_wr_direct(vha, QLA8044_CRB_DRV_IDC_VERSION_INDEX,
  1550. idc_ver);
  1551. ql_log(ql_log_info, vha, 0xb0ca,
  1552. "%s: IDC version updated to %d\n",
  1553. __func__, idc_ver);
  1554. } else {
  1555. idc_ver = qla8044_rd_direct(vha,
  1556. QLA8044_CRB_DRV_IDC_VERSION_INDEX);
  1557. idc_ver &= 0xFF;
  1558. if (QLA8044_IDC_VER_MAJ_VALUE != idc_ver) {
  1559. ql_log(ql_log_info, vha, 0xb0cb,
  1560. "%s: qla4xxx driver IDC version %d "
  1561. "is not compatible with IDC version %d "
  1562. "of other drivers!\n",
  1563. __func__, QLA8044_IDC_VER_MAJ_VALUE,
  1564. idc_ver);
  1565. rval = QLA_FUNCTION_FAILED;
  1566. goto exit_set_idc_ver;
  1567. }
  1568. }
  1569. /* Update IDC_MINOR_VERSION */
  1570. idc_ver = qla8044_rd_reg(ha, QLA8044_CRB_IDC_VER_MINOR);
  1571. idc_ver &= ~(0x03 << (ha->portnum * 2));
  1572. idc_ver |= (QLA8044_IDC_VER_MIN_VALUE << (ha->portnum * 2));
  1573. qla8044_wr_reg(ha, QLA8044_CRB_IDC_VER_MINOR, idc_ver);
  1574. exit_set_idc_ver:
  1575. return rval;
  1576. }
  1577. static int
  1578. qla8044_update_idc_reg(struct scsi_qla_host *vha)
  1579. {
  1580. uint32_t drv_active;
  1581. int rval = QLA_SUCCESS;
  1582. struct qla_hw_data *ha = vha->hw;
  1583. if (vha->flags.init_done)
  1584. goto exit_update_idc_reg;
  1585. qla8044_idc_lock(ha);
  1586. qla8044_set_drv_active(vha);
  1587. drv_active = qla8044_rd_direct(vha,
  1588. QLA8044_CRB_DRV_ACTIVE_INDEX);
  1589. /* If we are the first driver to load and
  1590. * ql2xdontresethba is not set, clear IDC_CTRL BIT0. */
  1591. if ((drv_active == (1 << ha->portnum)) && !ql2xdontresethba)
  1592. qla8044_clear_idc_dontreset(vha);
  1593. rval = qla8044_set_idc_ver(vha);
  1594. if (rval == QLA_FUNCTION_FAILED)
  1595. qla8044_clear_drv_active(ha);
  1596. qla8044_idc_unlock(ha);
  1597. exit_update_idc_reg:
  1598. return rval;
  1599. }
  1600. /**
  1601. * qla8044_need_qsnt_handler - Code to start qsnt
  1602. * @ha: pointer to adapter structure
  1603. **/
  1604. static void
  1605. qla8044_need_qsnt_handler(struct scsi_qla_host *vha)
  1606. {
  1607. unsigned long qsnt_timeout;
  1608. uint32_t drv_state, drv_active, dev_state;
  1609. struct qla_hw_data *ha = vha->hw;
  1610. if (vha->flags.online)
  1611. qla2x00_quiesce_io(vha);
  1612. else
  1613. return;
  1614. qla8044_set_qsnt_ready(vha);
  1615. /* Wait for 30 secs for all functions to ack qsnt mode */
  1616. qsnt_timeout = jiffies + (QSNT_ACK_TOV * HZ);
  1617. drv_state = qla8044_rd_direct(vha, QLA8044_CRB_DRV_STATE_INDEX);
  1618. drv_active = qla8044_rd_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX);
  1619. /* Shift drv_active by 1 to match drv_state. As quiescent ready bit
  1620. position is at bit 1 and drv active is at bit 0 */
  1621. drv_active = drv_active << 1;
  1622. while (drv_state != drv_active) {
  1623. if (time_after_eq(jiffies, qsnt_timeout)) {
  1624. /* Other functions did not ack, changing state to
  1625. * DEV_READY
  1626. */
  1627. clear_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
  1628. qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX,
  1629. QLA8XXX_DEV_READY);
  1630. qla8044_clear_qsnt_ready(vha);
  1631. ql_log(ql_log_info, vha, 0xb0cc,
  1632. "Timeout waiting for quiescent ack!!!\n");
  1633. return;
  1634. }
  1635. qla8044_idc_unlock(ha);
  1636. msleep(1000);
  1637. qla8044_idc_lock(ha);
  1638. drv_state = qla8044_rd_direct(vha,
  1639. QLA8044_CRB_DRV_STATE_INDEX);
  1640. drv_active = qla8044_rd_direct(vha,
  1641. QLA8044_CRB_DRV_ACTIVE_INDEX);
  1642. drv_active = drv_active << 1;
  1643. }
  1644. /* All functions have Acked. Set quiescent state */
  1645. dev_state = qla8044_rd_direct(vha, QLA8044_CRB_DEV_STATE_INDEX);
  1646. if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
  1647. qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX,
  1648. QLA8XXX_DEV_QUIESCENT);
  1649. ql_log(ql_log_info, vha, 0xb0cd,
  1650. "%s: HW State: QUIESCENT\n", __func__);
  1651. }
  1652. }
  1653. /*
  1654. * qla8044_device_state_handler - Adapter state machine
  1655. * @ha: pointer to host adapter structure.
  1656. *
  1657. * Note: IDC lock must be UNLOCKED upon entry
  1658. **/
  1659. int
  1660. qla8044_device_state_handler(struct scsi_qla_host *vha)
  1661. {
  1662. uint32_t dev_state;
  1663. int rval = QLA_SUCCESS;
  1664. unsigned long dev_init_timeout;
  1665. struct qla_hw_data *ha = vha->hw;
  1666. rval = qla8044_update_idc_reg(vha);
  1667. if (rval == QLA_FUNCTION_FAILED)
  1668. goto exit_error;
  1669. dev_state = qla8044_rd_direct(vha, QLA8044_CRB_DEV_STATE_INDEX);
  1670. ql_dbg(ql_dbg_p3p, vha, 0xb0ce,
  1671. "Device state is 0x%x = %s\n",
  1672. dev_state, dev_state < MAX_STATES ?
  1673. qdev_state(dev_state) : "Unknown");
  1674. /* wait for 30 seconds for device to go ready */
  1675. dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
  1676. qla8044_idc_lock(ha);
  1677. while (1) {
  1678. if (time_after_eq(jiffies, dev_init_timeout)) {
  1679. if (qla8044_check_drv_active(vha) == QLA_SUCCESS) {
  1680. ql_log(ql_log_warn, vha, 0xb0cf,
  1681. "%s: Device Init Failed 0x%x = %s\n",
  1682. QLA2XXX_DRIVER_NAME, dev_state,
  1683. dev_state < MAX_STATES ?
  1684. qdev_state(dev_state) : "Unknown");
  1685. qla8044_wr_direct(vha,
  1686. QLA8044_CRB_DEV_STATE_INDEX,
  1687. QLA8XXX_DEV_FAILED);
  1688. }
  1689. }
  1690. dev_state = qla8044_rd_direct(vha, QLA8044_CRB_DEV_STATE_INDEX);
  1691. ql_log(ql_log_info, vha, 0xb0d0,
  1692. "Device state is 0x%x = %s\n",
  1693. dev_state, dev_state < MAX_STATES ?
  1694. qdev_state(dev_state) : "Unknown");
  1695. /* NOTE: Make sure idc unlocked upon exit of switch statement */
  1696. switch (dev_state) {
  1697. case QLA8XXX_DEV_READY:
  1698. ha->flags.nic_core_reset_owner = 0;
  1699. goto exit;
  1700. case QLA8XXX_DEV_COLD:
  1701. rval = qla8044_device_bootstrap(vha);
  1702. break;
  1703. case QLA8XXX_DEV_INITIALIZING:
  1704. qla8044_idc_unlock(ha);
  1705. msleep(1000);
  1706. qla8044_idc_lock(ha);
  1707. break;
  1708. case QLA8XXX_DEV_NEED_RESET:
  1709. /* For ISP8044, if NEED_RESET is set by any driver,
  1710. * it should be honored, irrespective of IDC_CTRL
  1711. * DONTRESET_BIT0 */
  1712. qla8044_need_reset_handler(vha);
  1713. break;
  1714. case QLA8XXX_DEV_NEED_QUIESCENT:
  1715. /* idc locked/unlocked in handler */
  1716. qla8044_need_qsnt_handler(vha);
  1717. /* Reset the init timeout after qsnt handler */
  1718. dev_init_timeout = jiffies +
  1719. (ha->fcoe_reset_timeout * HZ);
  1720. break;
  1721. case QLA8XXX_DEV_QUIESCENT:
  1722. ql_log(ql_log_info, vha, 0xb0d1,
  1723. "HW State: QUIESCENT\n");
  1724. qla8044_idc_unlock(ha);
  1725. msleep(1000);
  1726. qla8044_idc_lock(ha);
  1727. /* Reset the init timeout after qsnt handler */
  1728. dev_init_timeout = jiffies +
  1729. (ha->fcoe_reset_timeout * HZ);
  1730. break;
  1731. case QLA8XXX_DEV_FAILED:
  1732. ha->flags.nic_core_reset_owner = 0;
  1733. qla8044_idc_unlock(ha);
  1734. qla8xxx_dev_failed_handler(vha);
  1735. rval = QLA_FUNCTION_FAILED;
  1736. qla8044_idc_lock(ha);
  1737. goto exit;
  1738. default:
  1739. qla8044_idc_unlock(ha);
  1740. qla8xxx_dev_failed_handler(vha);
  1741. rval = QLA_FUNCTION_FAILED;
  1742. qla8044_idc_lock(ha);
  1743. goto exit;
  1744. }
  1745. }
  1746. exit:
  1747. qla8044_idc_unlock(ha);
  1748. exit_error:
  1749. return rval;
  1750. }
  1751. /**
  1752. * qla4_8xxx_check_temp - Check the ISP82XX temperature.
  1753. * @ha: adapter block pointer.
  1754. *
  1755. * Note: The caller should not hold the idc lock.
  1756. **/
  1757. static int
  1758. qla8044_check_temp(struct scsi_qla_host *vha)
  1759. {
  1760. uint32_t temp, temp_state, temp_val;
  1761. int status = QLA_SUCCESS;
  1762. temp = qla8044_rd_direct(vha, QLA8044_CRB_TEMP_STATE_INDEX);
  1763. temp_state = qla82xx_get_temp_state(temp);
  1764. temp_val = qla82xx_get_temp_val(temp);
  1765. if (temp_state == QLA82XX_TEMP_PANIC) {
  1766. ql_log(ql_log_warn, vha, 0xb0d2,
  1767. "Device temperature %d degrees C"
  1768. " exceeds maximum allowed. Hardware has been shut"
  1769. " down\n", temp_val);
  1770. status = QLA_FUNCTION_FAILED;
  1771. return status;
  1772. } else if (temp_state == QLA82XX_TEMP_WARN) {
  1773. ql_log(ql_log_warn, vha, 0xb0d3,
  1774. "Device temperature %d"
  1775. " degrees C exceeds operating range."
  1776. " Immediate action needed.\n", temp_val);
  1777. }
  1778. return 0;
  1779. }
  1780. int qla8044_read_temperature(scsi_qla_host_t *vha)
  1781. {
  1782. uint32_t temp;
  1783. temp = qla8044_rd_direct(vha, QLA8044_CRB_TEMP_STATE_INDEX);
  1784. return qla82xx_get_temp_val(temp);
  1785. }
  1786. /**
  1787. * qla8044_check_fw_alive - Check firmware health
  1788. * @ha: Pointer to host adapter structure.
  1789. *
  1790. * Context: Interrupt
  1791. **/
  1792. int
  1793. qla8044_check_fw_alive(struct scsi_qla_host *vha)
  1794. {
  1795. uint32_t fw_heartbeat_counter;
  1796. uint32_t halt_status1, halt_status2;
  1797. int status = QLA_SUCCESS;
  1798. fw_heartbeat_counter = qla8044_rd_direct(vha,
  1799. QLA8044_PEG_ALIVE_COUNTER_INDEX);
  1800. /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
  1801. if (fw_heartbeat_counter == 0xffffffff) {
  1802. ql_dbg(ql_dbg_p3p, vha, 0xb0d4,
  1803. "scsi%ld: %s: Device in frozen "
  1804. "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
  1805. vha->host_no, __func__);
  1806. return status;
  1807. }
  1808. if (vha->fw_heartbeat_counter == fw_heartbeat_counter) {
  1809. vha->seconds_since_last_heartbeat++;
  1810. /* FW not alive after 2 seconds */
  1811. if (vha->seconds_since_last_heartbeat == 2) {
  1812. vha->seconds_since_last_heartbeat = 0;
  1813. halt_status1 = qla8044_rd_direct(vha,
  1814. QLA8044_PEG_HALT_STATUS1_INDEX);
  1815. halt_status2 = qla8044_rd_direct(vha,
  1816. QLA8044_PEG_HALT_STATUS2_INDEX);
  1817. ql_log(ql_log_info, vha, 0xb0d5,
  1818. "scsi(%ld): %s, ISP8044 "
  1819. "Dumping hw/fw registers:\n"
  1820. " PEG_HALT_STATUS1: 0x%x, "
  1821. "PEG_HALT_STATUS2: 0x%x,\n",
  1822. vha->host_no, __func__, halt_status1,
  1823. halt_status2);
  1824. status = QLA_FUNCTION_FAILED;
  1825. }
  1826. } else
  1827. vha->seconds_since_last_heartbeat = 0;
  1828. vha->fw_heartbeat_counter = fw_heartbeat_counter;
  1829. return status;
  1830. }
  1831. void
  1832. qla8044_watchdog(struct scsi_qla_host *vha)
  1833. {
  1834. uint32_t dev_state, halt_status;
  1835. int halt_status_unrecoverable = 0;
  1836. struct qla_hw_data *ha = vha->hw;
  1837. /* don't poll if reset is going on or FW hang in quiescent state */
  1838. if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1839. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))) {
  1840. dev_state = qla8044_rd_direct(vha, QLA8044_CRB_DEV_STATE_INDEX);
  1841. if (qla8044_check_fw_alive(vha)) {
  1842. ha->flags.isp82xx_fw_hung = 1;
  1843. ql_log(ql_log_warn, vha, 0xb10a,
  1844. "Firmware hung.\n");
  1845. qla82xx_clear_pending_mbx(vha);
  1846. }
  1847. if (qla8044_check_temp(vha)) {
  1848. set_bit(ISP_UNRECOVERABLE, &vha->dpc_flags);
  1849. ha->flags.isp82xx_fw_hung = 1;
  1850. qla2xxx_wake_dpc(vha);
  1851. } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
  1852. !test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) {
  1853. ql_log(ql_log_info, vha, 0xb0d6,
  1854. "%s: HW State: NEED RESET!\n",
  1855. __func__);
  1856. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1857. qla2xxx_wake_dpc(vha);
  1858. } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
  1859. !test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags)) {
  1860. ql_log(ql_log_info, vha, 0xb0d7,
  1861. "%s: HW State: NEED QUIES detected!\n",
  1862. __func__);
  1863. set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
  1864. qla2xxx_wake_dpc(vha);
  1865. } else {
  1866. /* Check firmware health */
  1867. if (ha->flags.isp82xx_fw_hung) {
  1868. halt_status = qla8044_rd_direct(vha,
  1869. QLA8044_PEG_HALT_STATUS1_INDEX);
  1870. if (halt_status &
  1871. QLA8044_HALT_STATUS_FW_RESET) {
  1872. ql_log(ql_log_fatal, vha,
  1873. 0xb0d8, "%s: Firmware "
  1874. "error detected device "
  1875. "is being reset\n",
  1876. __func__);
  1877. } else if (halt_status &
  1878. QLA8044_HALT_STATUS_UNRECOVERABLE) {
  1879. halt_status_unrecoverable = 1;
  1880. }
  1881. /* Since we cannot change dev_state in interrupt
  1882. * context, set appropriate DPC flag then wakeup
  1883. * DPC */
  1884. if (halt_status_unrecoverable) {
  1885. set_bit(ISP_UNRECOVERABLE,
  1886. &vha->dpc_flags);
  1887. } else {
  1888. if (dev_state ==
  1889. QLA8XXX_DEV_QUIESCENT) {
  1890. set_bit(FCOE_CTX_RESET_NEEDED,
  1891. &vha->dpc_flags);
  1892. ql_log(ql_log_info, vha, 0xb0d9,
  1893. "%s: FW CONTEXT Reset "
  1894. "needed!\n", __func__);
  1895. } else {
  1896. ql_log(ql_log_info, vha,
  1897. 0xb0da, "%s: "
  1898. "detect abort needed\n",
  1899. __func__);
  1900. set_bit(ISP_ABORT_NEEDED,
  1901. &vha->dpc_flags);
  1902. }
  1903. }
  1904. qla2xxx_wake_dpc(vha);
  1905. }
  1906. }
  1907. }
  1908. }
  1909. static int
  1910. qla8044_minidump_process_control(struct scsi_qla_host *vha,
  1911. struct qla8044_minidump_entry_hdr *entry_hdr)
  1912. {
  1913. struct qla8044_minidump_entry_crb *crb_entry;
  1914. uint32_t read_value, opcode, poll_time, addr, index;
  1915. uint32_t crb_addr, rval = QLA_SUCCESS;
  1916. unsigned long wtime;
  1917. struct qla8044_minidump_template_hdr *tmplt_hdr;
  1918. int i;
  1919. struct qla_hw_data *ha = vha->hw;
  1920. ql_dbg(ql_dbg_p3p, vha, 0xb0dd, "Entering fn: %s\n", __func__);
  1921. tmplt_hdr = (struct qla8044_minidump_template_hdr *)
  1922. ha->md_tmplt_hdr;
  1923. crb_entry = (struct qla8044_minidump_entry_crb *)entry_hdr;
  1924. crb_addr = crb_entry->addr;
  1925. for (i = 0; i < crb_entry->op_count; i++) {
  1926. opcode = crb_entry->crb_ctrl.opcode;
  1927. if (opcode & QLA82XX_DBG_OPCODE_WR) {
  1928. qla8044_wr_reg_indirect(vha, crb_addr,
  1929. crb_entry->value_1);
  1930. opcode &= ~QLA82XX_DBG_OPCODE_WR;
  1931. }
  1932. if (opcode & QLA82XX_DBG_OPCODE_RW) {
  1933. qla8044_rd_reg_indirect(vha, crb_addr, &read_value);
  1934. qla8044_wr_reg_indirect(vha, crb_addr, read_value);
  1935. opcode &= ~QLA82XX_DBG_OPCODE_RW;
  1936. }
  1937. if (opcode & QLA82XX_DBG_OPCODE_AND) {
  1938. qla8044_rd_reg_indirect(vha, crb_addr, &read_value);
  1939. read_value &= crb_entry->value_2;
  1940. opcode &= ~QLA82XX_DBG_OPCODE_AND;
  1941. if (opcode & QLA82XX_DBG_OPCODE_OR) {
  1942. read_value |= crb_entry->value_3;
  1943. opcode &= ~QLA82XX_DBG_OPCODE_OR;
  1944. }
  1945. qla8044_wr_reg_indirect(vha, crb_addr, read_value);
  1946. }
  1947. if (opcode & QLA82XX_DBG_OPCODE_OR) {
  1948. qla8044_rd_reg_indirect(vha, crb_addr, &read_value);
  1949. read_value |= crb_entry->value_3;
  1950. qla8044_wr_reg_indirect(vha, crb_addr, read_value);
  1951. opcode &= ~QLA82XX_DBG_OPCODE_OR;
  1952. }
  1953. if (opcode & QLA82XX_DBG_OPCODE_POLL) {
  1954. poll_time = crb_entry->crb_strd.poll_timeout;
  1955. wtime = jiffies + poll_time;
  1956. qla8044_rd_reg_indirect(vha, crb_addr, &read_value);
  1957. do {
  1958. if ((read_value & crb_entry->value_2) ==
  1959. crb_entry->value_1) {
  1960. break;
  1961. } else if (time_after_eq(jiffies, wtime)) {
  1962. /* capturing dump failed */
  1963. rval = QLA_FUNCTION_FAILED;
  1964. break;
  1965. } else {
  1966. qla8044_rd_reg_indirect(vha,
  1967. crb_addr, &read_value);
  1968. }
  1969. } while (1);
  1970. opcode &= ~QLA82XX_DBG_OPCODE_POLL;
  1971. }
  1972. if (opcode & QLA82XX_DBG_OPCODE_RDSTATE) {
  1973. if (crb_entry->crb_strd.state_index_a) {
  1974. index = crb_entry->crb_strd.state_index_a;
  1975. addr = tmplt_hdr->saved_state_array[index];
  1976. } else {
  1977. addr = crb_addr;
  1978. }
  1979. qla8044_rd_reg_indirect(vha, addr, &read_value);
  1980. index = crb_entry->crb_ctrl.state_index_v;
  1981. tmplt_hdr->saved_state_array[index] = read_value;
  1982. opcode &= ~QLA82XX_DBG_OPCODE_RDSTATE;
  1983. }
  1984. if (opcode & QLA82XX_DBG_OPCODE_WRSTATE) {
  1985. if (crb_entry->crb_strd.state_index_a) {
  1986. index = crb_entry->crb_strd.state_index_a;
  1987. addr = tmplt_hdr->saved_state_array[index];
  1988. } else {
  1989. addr = crb_addr;
  1990. }
  1991. if (crb_entry->crb_ctrl.state_index_v) {
  1992. index = crb_entry->crb_ctrl.state_index_v;
  1993. read_value =
  1994. tmplt_hdr->saved_state_array[index];
  1995. } else {
  1996. read_value = crb_entry->value_1;
  1997. }
  1998. qla8044_wr_reg_indirect(vha, addr, read_value);
  1999. opcode &= ~QLA82XX_DBG_OPCODE_WRSTATE;
  2000. }
  2001. if (opcode & QLA82XX_DBG_OPCODE_MDSTATE) {
  2002. index = crb_entry->crb_ctrl.state_index_v;
  2003. read_value = tmplt_hdr->saved_state_array[index];
  2004. read_value <<= crb_entry->crb_ctrl.shl;
  2005. read_value >>= crb_entry->crb_ctrl.shr;
  2006. if (crb_entry->value_2)
  2007. read_value &= crb_entry->value_2;
  2008. read_value |= crb_entry->value_3;
  2009. read_value += crb_entry->value_1;
  2010. tmplt_hdr->saved_state_array[index] = read_value;
  2011. opcode &= ~QLA82XX_DBG_OPCODE_MDSTATE;
  2012. }
  2013. crb_addr += crb_entry->crb_strd.addr_stride;
  2014. }
  2015. return rval;
  2016. }
  2017. static void
  2018. qla8044_minidump_process_rdcrb(struct scsi_qla_host *vha,
  2019. struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
  2020. {
  2021. uint32_t r_addr, r_stride, loop_cnt, i, r_value;
  2022. struct qla8044_minidump_entry_crb *crb_hdr;
  2023. uint32_t *data_ptr = *d_ptr;
  2024. ql_dbg(ql_dbg_p3p, vha, 0xb0de, "Entering fn: %s\n", __func__);
  2025. crb_hdr = (struct qla8044_minidump_entry_crb *)entry_hdr;
  2026. r_addr = crb_hdr->addr;
  2027. r_stride = crb_hdr->crb_strd.addr_stride;
  2028. loop_cnt = crb_hdr->op_count;
  2029. for (i = 0; i < loop_cnt; i++) {
  2030. qla8044_rd_reg_indirect(vha, r_addr, &r_value);
  2031. *data_ptr++ = r_addr;
  2032. *data_ptr++ = r_value;
  2033. r_addr += r_stride;
  2034. }
  2035. *d_ptr = data_ptr;
  2036. }
  2037. static int
  2038. qla8044_minidump_process_rdmem(struct scsi_qla_host *vha,
  2039. struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
  2040. {
  2041. uint32_t r_addr, r_value, r_data;
  2042. uint32_t i, j, loop_cnt;
  2043. struct qla8044_minidump_entry_rdmem *m_hdr;
  2044. unsigned long flags;
  2045. uint32_t *data_ptr = *d_ptr;
  2046. struct qla_hw_data *ha = vha->hw;
  2047. ql_dbg(ql_dbg_p3p, vha, 0xb0df, "Entering fn: %s\n", __func__);
  2048. m_hdr = (struct qla8044_minidump_entry_rdmem *)entry_hdr;
  2049. r_addr = m_hdr->read_addr;
  2050. loop_cnt = m_hdr->read_data_size/16;
  2051. ql_dbg(ql_dbg_p3p, vha, 0xb0f0,
  2052. "[%s]: Read addr: 0x%x, read_data_size: 0x%x\n",
  2053. __func__, r_addr, m_hdr->read_data_size);
  2054. if (r_addr & 0xf) {
  2055. ql_dbg(ql_dbg_p3p, vha, 0xb0f1,
  2056. "[%s]: Read addr 0x%x not 16 bytes aligned\n",
  2057. __func__, r_addr);
  2058. return QLA_FUNCTION_FAILED;
  2059. }
  2060. if (m_hdr->read_data_size % 16) {
  2061. ql_dbg(ql_dbg_p3p, vha, 0xb0f2,
  2062. "[%s]: Read data[0x%x] not multiple of 16 bytes\n",
  2063. __func__, m_hdr->read_data_size);
  2064. return QLA_FUNCTION_FAILED;
  2065. }
  2066. ql_dbg(ql_dbg_p3p, vha, 0xb0f3,
  2067. "[%s]: rdmem_addr: 0x%x, read_data_size: 0x%x, loop_cnt: 0x%x\n",
  2068. __func__, r_addr, m_hdr->read_data_size, loop_cnt);
  2069. write_lock_irqsave(&ha->hw_lock, flags);
  2070. for (i = 0; i < loop_cnt; i++) {
  2071. qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_ADDR_LO, r_addr);
  2072. r_value = 0;
  2073. qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_ADDR_HI, r_value);
  2074. r_value = MIU_TA_CTL_ENABLE;
  2075. qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_CTRL, r_value);
  2076. r_value = MIU_TA_CTL_START_ENABLE;
  2077. qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_CTRL, r_value);
  2078. for (j = 0; j < MAX_CTL_CHECK; j++) {
  2079. qla8044_rd_reg_indirect(vha, MD_MIU_TEST_AGT_CTRL,
  2080. &r_value);
  2081. if ((r_value & MIU_TA_CTL_BUSY) == 0)
  2082. break;
  2083. }
  2084. if (j >= MAX_CTL_CHECK) {
  2085. write_unlock_irqrestore(&ha->hw_lock, flags);
  2086. return QLA_SUCCESS;
  2087. }
  2088. for (j = 0; j < 4; j++) {
  2089. qla8044_rd_reg_indirect(vha, MD_MIU_TEST_AGT_RDDATA[j],
  2090. &r_data);
  2091. *data_ptr++ = r_data;
  2092. }
  2093. r_addr += 16;
  2094. }
  2095. write_unlock_irqrestore(&ha->hw_lock, flags);
  2096. ql_dbg(ql_dbg_p3p, vha, 0xb0f4,
  2097. "Leaving fn: %s datacount: 0x%x\n",
  2098. __func__, (loop_cnt * 16));
  2099. *d_ptr = data_ptr;
  2100. return QLA_SUCCESS;
  2101. }
  2102. /* ISP83xx flash read for _RDROM _BOARD */
  2103. static uint32_t
  2104. qla8044_minidump_process_rdrom(struct scsi_qla_host *vha,
  2105. struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
  2106. {
  2107. uint32_t fl_addr, u32_count, rval;
  2108. struct qla8044_minidump_entry_rdrom *rom_hdr;
  2109. uint32_t *data_ptr = *d_ptr;
  2110. rom_hdr = (struct qla8044_minidump_entry_rdrom *)entry_hdr;
  2111. fl_addr = rom_hdr->read_addr;
  2112. u32_count = (rom_hdr->read_data_size)/sizeof(uint32_t);
  2113. ql_dbg(ql_dbg_p3p, vha, 0xb0f5, "[%s]: fl_addr: 0x%x, count: 0x%x\n",
  2114. __func__, fl_addr, u32_count);
  2115. rval = qla8044_lockless_flash_read_u32(vha, fl_addr,
  2116. (u8 *)(data_ptr), u32_count);
  2117. if (rval != QLA_SUCCESS) {
  2118. ql_log(ql_log_fatal, vha, 0xb0f6,
  2119. "%s: Flash Read Error,Count=%d\n", __func__, u32_count);
  2120. return QLA_FUNCTION_FAILED;
  2121. } else {
  2122. data_ptr += u32_count;
  2123. *d_ptr = data_ptr;
  2124. return QLA_SUCCESS;
  2125. }
  2126. }
  2127. static void
  2128. qla8044_mark_entry_skipped(struct scsi_qla_host *vha,
  2129. struct qla8044_minidump_entry_hdr *entry_hdr, int index)
  2130. {
  2131. entry_hdr->d_ctrl.driver_flags |= QLA82XX_DBG_SKIPPED_FLAG;
  2132. ql_log(ql_log_info, vha, 0xb0f7,
  2133. "scsi(%ld): Skipping entry[%d]: ETYPE[0x%x]-ELEVEL[0x%x]\n",
  2134. vha->host_no, index, entry_hdr->entry_type,
  2135. entry_hdr->d_ctrl.entry_capture_mask);
  2136. }
  2137. static int
  2138. qla8044_minidump_process_l2tag(struct scsi_qla_host *vha,
  2139. struct qla8044_minidump_entry_hdr *entry_hdr,
  2140. uint32_t **d_ptr)
  2141. {
  2142. uint32_t addr, r_addr, c_addr, t_r_addr;
  2143. uint32_t i, k, loop_count, t_value, r_cnt, r_value;
  2144. unsigned long p_wait, w_time, p_mask;
  2145. uint32_t c_value_w, c_value_r;
  2146. struct qla8044_minidump_entry_cache *cache_hdr;
  2147. int rval = QLA_FUNCTION_FAILED;
  2148. uint32_t *data_ptr = *d_ptr;
  2149. ql_dbg(ql_dbg_p3p, vha, 0xb0f8, "Entering fn: %s\n", __func__);
  2150. cache_hdr = (struct qla8044_minidump_entry_cache *)entry_hdr;
  2151. loop_count = cache_hdr->op_count;
  2152. r_addr = cache_hdr->read_addr;
  2153. c_addr = cache_hdr->control_addr;
  2154. c_value_w = cache_hdr->cache_ctrl.write_value;
  2155. t_r_addr = cache_hdr->tag_reg_addr;
  2156. t_value = cache_hdr->addr_ctrl.init_tag_value;
  2157. r_cnt = cache_hdr->read_ctrl.read_addr_cnt;
  2158. p_wait = cache_hdr->cache_ctrl.poll_wait;
  2159. p_mask = cache_hdr->cache_ctrl.poll_mask;
  2160. for (i = 0; i < loop_count; i++) {
  2161. qla8044_wr_reg_indirect(vha, t_r_addr, t_value);
  2162. if (c_value_w)
  2163. qla8044_wr_reg_indirect(vha, c_addr, c_value_w);
  2164. if (p_mask) {
  2165. w_time = jiffies + p_wait;
  2166. do {
  2167. qla8044_rd_reg_indirect(vha, c_addr,
  2168. &c_value_r);
  2169. if ((c_value_r & p_mask) == 0) {
  2170. break;
  2171. } else if (time_after_eq(jiffies, w_time)) {
  2172. /* capturing dump failed */
  2173. return rval;
  2174. }
  2175. } while (1);
  2176. }
  2177. addr = r_addr;
  2178. for (k = 0; k < r_cnt; k++) {
  2179. qla8044_rd_reg_indirect(vha, addr, &r_value);
  2180. *data_ptr++ = r_value;
  2181. addr += cache_hdr->read_ctrl.read_addr_stride;
  2182. }
  2183. t_value += cache_hdr->addr_ctrl.tag_value_stride;
  2184. }
  2185. *d_ptr = data_ptr;
  2186. return QLA_SUCCESS;
  2187. }
  2188. static void
  2189. qla8044_minidump_process_l1cache(struct scsi_qla_host *vha,
  2190. struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
  2191. {
  2192. uint32_t addr, r_addr, c_addr, t_r_addr;
  2193. uint32_t i, k, loop_count, t_value, r_cnt, r_value;
  2194. uint32_t c_value_w;
  2195. struct qla8044_minidump_entry_cache *cache_hdr;
  2196. uint32_t *data_ptr = *d_ptr;
  2197. cache_hdr = (struct qla8044_minidump_entry_cache *)entry_hdr;
  2198. loop_count = cache_hdr->op_count;
  2199. r_addr = cache_hdr->read_addr;
  2200. c_addr = cache_hdr->control_addr;
  2201. c_value_w = cache_hdr->cache_ctrl.write_value;
  2202. t_r_addr = cache_hdr->tag_reg_addr;
  2203. t_value = cache_hdr->addr_ctrl.init_tag_value;
  2204. r_cnt = cache_hdr->read_ctrl.read_addr_cnt;
  2205. for (i = 0; i < loop_count; i++) {
  2206. qla8044_wr_reg_indirect(vha, t_r_addr, t_value);
  2207. qla8044_wr_reg_indirect(vha, c_addr, c_value_w);
  2208. addr = r_addr;
  2209. for (k = 0; k < r_cnt; k++) {
  2210. qla8044_rd_reg_indirect(vha, addr, &r_value);
  2211. *data_ptr++ = r_value;
  2212. addr += cache_hdr->read_ctrl.read_addr_stride;
  2213. }
  2214. t_value += cache_hdr->addr_ctrl.tag_value_stride;
  2215. }
  2216. *d_ptr = data_ptr;
  2217. }
  2218. static void
  2219. qla8044_minidump_process_rdocm(struct scsi_qla_host *vha,
  2220. struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
  2221. {
  2222. uint32_t r_addr, r_stride, loop_cnt, i, r_value;
  2223. struct qla8044_minidump_entry_rdocm *ocm_hdr;
  2224. uint32_t *data_ptr = *d_ptr;
  2225. struct qla_hw_data *ha = vha->hw;
  2226. ql_dbg(ql_dbg_p3p, vha, 0xb0f9, "Entering fn: %s\n", __func__);
  2227. ocm_hdr = (struct qla8044_minidump_entry_rdocm *)entry_hdr;
  2228. r_addr = ocm_hdr->read_addr;
  2229. r_stride = ocm_hdr->read_addr_stride;
  2230. loop_cnt = ocm_hdr->op_count;
  2231. ql_dbg(ql_dbg_p3p, vha, 0xb0fa,
  2232. "[%s]: r_addr: 0x%x, r_stride: 0x%x, loop_cnt: 0x%x\n",
  2233. __func__, r_addr, r_stride, loop_cnt);
  2234. for (i = 0; i < loop_cnt; i++) {
  2235. r_value = readl((void __iomem *)(r_addr + ha->nx_pcibase));
  2236. *data_ptr++ = r_value;
  2237. r_addr += r_stride;
  2238. }
  2239. ql_dbg(ql_dbg_p3p, vha, 0xb0fb, "Leaving fn: %s datacount: 0x%lx\n",
  2240. __func__, (long unsigned int) (loop_cnt * sizeof(uint32_t)));
  2241. *d_ptr = data_ptr;
  2242. }
  2243. static void
  2244. qla8044_minidump_process_rdmux(struct scsi_qla_host *vha,
  2245. struct qla8044_minidump_entry_hdr *entry_hdr,
  2246. uint32_t **d_ptr)
  2247. {
  2248. uint32_t r_addr, s_stride, s_addr, s_value, loop_cnt, i, r_value;
  2249. struct qla8044_minidump_entry_mux *mux_hdr;
  2250. uint32_t *data_ptr = *d_ptr;
  2251. ql_dbg(ql_dbg_p3p, vha, 0xb0fc, "Entering fn: %s\n", __func__);
  2252. mux_hdr = (struct qla8044_minidump_entry_mux *)entry_hdr;
  2253. r_addr = mux_hdr->read_addr;
  2254. s_addr = mux_hdr->select_addr;
  2255. s_stride = mux_hdr->select_value_stride;
  2256. s_value = mux_hdr->select_value;
  2257. loop_cnt = mux_hdr->op_count;
  2258. for (i = 0; i < loop_cnt; i++) {
  2259. qla8044_wr_reg_indirect(vha, s_addr, s_value);
  2260. qla8044_rd_reg_indirect(vha, r_addr, &r_value);
  2261. *data_ptr++ = s_value;
  2262. *data_ptr++ = r_value;
  2263. s_value += s_stride;
  2264. }
  2265. *d_ptr = data_ptr;
  2266. }
  2267. static void
  2268. qla8044_minidump_process_queue(struct scsi_qla_host *vha,
  2269. struct qla8044_minidump_entry_hdr *entry_hdr,
  2270. uint32_t **d_ptr)
  2271. {
  2272. uint32_t s_addr, r_addr;
  2273. uint32_t r_stride, r_value, r_cnt, qid = 0;
  2274. uint32_t i, k, loop_cnt;
  2275. struct qla8044_minidump_entry_queue *q_hdr;
  2276. uint32_t *data_ptr = *d_ptr;
  2277. ql_dbg(ql_dbg_p3p, vha, 0xb0fd, "Entering fn: %s\n", __func__);
  2278. q_hdr = (struct qla8044_minidump_entry_queue *)entry_hdr;
  2279. s_addr = q_hdr->select_addr;
  2280. r_cnt = q_hdr->rd_strd.read_addr_cnt;
  2281. r_stride = q_hdr->rd_strd.read_addr_stride;
  2282. loop_cnt = q_hdr->op_count;
  2283. for (i = 0; i < loop_cnt; i++) {
  2284. qla8044_wr_reg_indirect(vha, s_addr, qid);
  2285. r_addr = q_hdr->read_addr;
  2286. for (k = 0; k < r_cnt; k++) {
  2287. qla8044_rd_reg_indirect(vha, r_addr, &r_value);
  2288. *data_ptr++ = r_value;
  2289. r_addr += r_stride;
  2290. }
  2291. qid += q_hdr->q_strd.queue_id_stride;
  2292. }
  2293. *d_ptr = data_ptr;
  2294. }
  2295. /* ISP83xx functions to process new minidump entries... */
  2296. static uint32_t
  2297. qla8044_minidump_process_pollrd(struct scsi_qla_host *vha,
  2298. struct qla8044_minidump_entry_hdr *entry_hdr,
  2299. uint32_t **d_ptr)
  2300. {
  2301. uint32_t r_addr, s_addr, s_value, r_value, poll_wait, poll_mask;
  2302. uint16_t s_stride, i;
  2303. struct qla8044_minidump_entry_pollrd *pollrd_hdr;
  2304. uint32_t *data_ptr = *d_ptr;
  2305. pollrd_hdr = (struct qla8044_minidump_entry_pollrd *) entry_hdr;
  2306. s_addr = pollrd_hdr->select_addr;
  2307. r_addr = pollrd_hdr->read_addr;
  2308. s_value = pollrd_hdr->select_value;
  2309. s_stride = pollrd_hdr->select_value_stride;
  2310. poll_wait = pollrd_hdr->poll_wait;
  2311. poll_mask = pollrd_hdr->poll_mask;
  2312. for (i = 0; i < pollrd_hdr->op_count; i++) {
  2313. qla8044_wr_reg_indirect(vha, s_addr, s_value);
  2314. poll_wait = pollrd_hdr->poll_wait;
  2315. while (1) {
  2316. qla8044_rd_reg_indirect(vha, s_addr, &r_value);
  2317. if ((r_value & poll_mask) != 0) {
  2318. break;
  2319. } else {
  2320. usleep_range(1000, 1100);
  2321. if (--poll_wait == 0) {
  2322. ql_log(ql_log_fatal, vha, 0xb0fe,
  2323. "%s: TIMEOUT\n", __func__);
  2324. goto error;
  2325. }
  2326. }
  2327. }
  2328. qla8044_rd_reg_indirect(vha, r_addr, &r_value);
  2329. *data_ptr++ = s_value;
  2330. *data_ptr++ = r_value;
  2331. s_value += s_stride;
  2332. }
  2333. *d_ptr = data_ptr;
  2334. return QLA_SUCCESS;
  2335. error:
  2336. return QLA_FUNCTION_FAILED;
  2337. }
  2338. static void
  2339. qla8044_minidump_process_rdmux2(struct scsi_qla_host *vha,
  2340. struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
  2341. {
  2342. uint32_t sel_val1, sel_val2, t_sel_val, data, i;
  2343. uint32_t sel_addr1, sel_addr2, sel_val_mask, read_addr;
  2344. struct qla8044_minidump_entry_rdmux2 *rdmux2_hdr;
  2345. uint32_t *data_ptr = *d_ptr;
  2346. rdmux2_hdr = (struct qla8044_minidump_entry_rdmux2 *) entry_hdr;
  2347. sel_val1 = rdmux2_hdr->select_value_1;
  2348. sel_val2 = rdmux2_hdr->select_value_2;
  2349. sel_addr1 = rdmux2_hdr->select_addr_1;
  2350. sel_addr2 = rdmux2_hdr->select_addr_2;
  2351. sel_val_mask = rdmux2_hdr->select_value_mask;
  2352. read_addr = rdmux2_hdr->read_addr;
  2353. for (i = 0; i < rdmux2_hdr->op_count; i++) {
  2354. qla8044_wr_reg_indirect(vha, sel_addr1, sel_val1);
  2355. t_sel_val = sel_val1 & sel_val_mask;
  2356. *data_ptr++ = t_sel_val;
  2357. qla8044_wr_reg_indirect(vha, sel_addr2, t_sel_val);
  2358. qla8044_rd_reg_indirect(vha, read_addr, &data);
  2359. *data_ptr++ = data;
  2360. qla8044_wr_reg_indirect(vha, sel_addr1, sel_val2);
  2361. t_sel_val = sel_val2 & sel_val_mask;
  2362. *data_ptr++ = t_sel_val;
  2363. qla8044_wr_reg_indirect(vha, sel_addr2, t_sel_val);
  2364. qla8044_rd_reg_indirect(vha, read_addr, &data);
  2365. *data_ptr++ = data;
  2366. sel_val1 += rdmux2_hdr->select_value_stride;
  2367. sel_val2 += rdmux2_hdr->select_value_stride;
  2368. }
  2369. *d_ptr = data_ptr;
  2370. }
  2371. static uint32_t
  2372. qla8044_minidump_process_pollrdmwr(struct scsi_qla_host *vha,
  2373. struct qla8044_minidump_entry_hdr *entry_hdr,
  2374. uint32_t **d_ptr)
  2375. {
  2376. uint32_t poll_wait, poll_mask, r_value, data;
  2377. uint32_t addr_1, addr_2, value_1, value_2;
  2378. struct qla8044_minidump_entry_pollrdmwr *poll_hdr;
  2379. uint32_t *data_ptr = *d_ptr;
  2380. poll_hdr = (struct qla8044_minidump_entry_pollrdmwr *) entry_hdr;
  2381. addr_1 = poll_hdr->addr_1;
  2382. addr_2 = poll_hdr->addr_2;
  2383. value_1 = poll_hdr->value_1;
  2384. value_2 = poll_hdr->value_2;
  2385. poll_mask = poll_hdr->poll_mask;
  2386. qla8044_wr_reg_indirect(vha, addr_1, value_1);
  2387. poll_wait = poll_hdr->poll_wait;
  2388. while (1) {
  2389. qla8044_rd_reg_indirect(vha, addr_1, &r_value);
  2390. if ((r_value & poll_mask) != 0) {
  2391. break;
  2392. } else {
  2393. usleep_range(1000, 1100);
  2394. if (--poll_wait == 0) {
  2395. ql_log(ql_log_fatal, vha, 0xb0ff,
  2396. "%s: TIMEOUT\n", __func__);
  2397. goto error;
  2398. }
  2399. }
  2400. }
  2401. qla8044_rd_reg_indirect(vha, addr_2, &data);
  2402. data &= poll_hdr->modify_mask;
  2403. qla8044_wr_reg_indirect(vha, addr_2, data);
  2404. qla8044_wr_reg_indirect(vha, addr_1, value_2);
  2405. poll_wait = poll_hdr->poll_wait;
  2406. while (1) {
  2407. qla8044_rd_reg_indirect(vha, addr_1, &r_value);
  2408. if ((r_value & poll_mask) != 0) {
  2409. break;
  2410. } else {
  2411. usleep_range(1000, 1100);
  2412. if (--poll_wait == 0) {
  2413. ql_log(ql_log_fatal, vha, 0xb100,
  2414. "%s: TIMEOUT2\n", __func__);
  2415. goto error;
  2416. }
  2417. }
  2418. }
  2419. *data_ptr++ = addr_2;
  2420. *data_ptr++ = data;
  2421. *d_ptr = data_ptr;
  2422. return QLA_SUCCESS;
  2423. error:
  2424. return QLA_FUNCTION_FAILED;
  2425. }
  2426. #define ISP8044_PEX_DMA_ENGINE_INDEX 8
  2427. #define ISP8044_PEX_DMA_BASE_ADDRESS 0x77320000
  2428. #define ISP8044_PEX_DMA_NUM_OFFSET 0x10000
  2429. #define ISP8044_PEX_DMA_CMD_ADDR_LOW 0x0
  2430. #define ISP8044_PEX_DMA_CMD_ADDR_HIGH 0x04
  2431. #define ISP8044_PEX_DMA_CMD_STS_AND_CNTRL 0x08
  2432. #define ISP8044_PEX_DMA_READ_SIZE (16 * 1024)
  2433. #define ISP8044_PEX_DMA_MAX_WAIT (100 * 100) /* Max wait of 100 msecs */
  2434. static int
  2435. qla8044_check_dma_engine_state(struct scsi_qla_host *vha)
  2436. {
  2437. struct qla_hw_data *ha = vha->hw;
  2438. int rval = QLA_SUCCESS;
  2439. uint32_t dma_eng_num = 0, cmd_sts_and_cntrl = 0;
  2440. uint64_t dma_base_addr = 0;
  2441. struct qla8044_minidump_template_hdr *tmplt_hdr = NULL;
  2442. tmplt_hdr = ha->md_tmplt_hdr;
  2443. dma_eng_num =
  2444. tmplt_hdr->saved_state_array[ISP8044_PEX_DMA_ENGINE_INDEX];
  2445. dma_base_addr = ISP8044_PEX_DMA_BASE_ADDRESS +
  2446. (dma_eng_num * ISP8044_PEX_DMA_NUM_OFFSET);
  2447. /* Read the pex-dma's command-status-and-control register. */
  2448. rval = qla8044_rd_reg_indirect(vha,
  2449. (dma_base_addr + ISP8044_PEX_DMA_CMD_STS_AND_CNTRL),
  2450. &cmd_sts_and_cntrl);
  2451. if (rval)
  2452. return QLA_FUNCTION_FAILED;
  2453. /* Check if requested pex-dma engine is available. */
  2454. if (cmd_sts_and_cntrl & BIT_31)
  2455. return QLA_SUCCESS;
  2456. return QLA_FUNCTION_FAILED;
  2457. }
  2458. static int
  2459. qla8044_start_pex_dma(struct scsi_qla_host *vha,
  2460. struct qla8044_minidump_entry_rdmem_pex_dma *m_hdr)
  2461. {
  2462. struct qla_hw_data *ha = vha->hw;
  2463. int rval = QLA_SUCCESS, wait = 0;
  2464. uint32_t dma_eng_num = 0, cmd_sts_and_cntrl = 0;
  2465. uint64_t dma_base_addr = 0;
  2466. struct qla8044_minidump_template_hdr *tmplt_hdr = NULL;
  2467. tmplt_hdr = ha->md_tmplt_hdr;
  2468. dma_eng_num =
  2469. tmplt_hdr->saved_state_array[ISP8044_PEX_DMA_ENGINE_INDEX];
  2470. dma_base_addr = ISP8044_PEX_DMA_BASE_ADDRESS +
  2471. (dma_eng_num * ISP8044_PEX_DMA_NUM_OFFSET);
  2472. rval = qla8044_wr_reg_indirect(vha,
  2473. dma_base_addr + ISP8044_PEX_DMA_CMD_ADDR_LOW,
  2474. m_hdr->desc_card_addr);
  2475. if (rval)
  2476. goto error_exit;
  2477. rval = qla8044_wr_reg_indirect(vha,
  2478. dma_base_addr + ISP8044_PEX_DMA_CMD_ADDR_HIGH, 0);
  2479. if (rval)
  2480. goto error_exit;
  2481. rval = qla8044_wr_reg_indirect(vha,
  2482. dma_base_addr + ISP8044_PEX_DMA_CMD_STS_AND_CNTRL,
  2483. m_hdr->start_dma_cmd);
  2484. if (rval)
  2485. goto error_exit;
  2486. /* Wait for dma operation to complete. */
  2487. for (wait = 0; wait < ISP8044_PEX_DMA_MAX_WAIT; wait++) {
  2488. rval = qla8044_rd_reg_indirect(vha,
  2489. (dma_base_addr + ISP8044_PEX_DMA_CMD_STS_AND_CNTRL),
  2490. &cmd_sts_and_cntrl);
  2491. if (rval)
  2492. goto error_exit;
  2493. if ((cmd_sts_and_cntrl & BIT_1) == 0)
  2494. break;
  2495. udelay(10);
  2496. }
  2497. /* Wait a max of 100 ms, otherwise fallback to rdmem entry read */
  2498. if (wait >= ISP8044_PEX_DMA_MAX_WAIT) {
  2499. rval = QLA_FUNCTION_FAILED;
  2500. goto error_exit;
  2501. }
  2502. error_exit:
  2503. return rval;
  2504. }
  2505. static int
  2506. qla8044_minidump_pex_dma_read(struct scsi_qla_host *vha,
  2507. struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
  2508. {
  2509. struct qla_hw_data *ha = vha->hw;
  2510. int rval = QLA_SUCCESS;
  2511. struct qla8044_minidump_entry_rdmem_pex_dma *m_hdr = NULL;
  2512. uint32_t chunk_size, read_size;
  2513. uint8_t *data_ptr = (uint8_t *)*d_ptr;
  2514. void *rdmem_buffer = NULL;
  2515. dma_addr_t rdmem_dma;
  2516. struct qla8044_pex_dma_descriptor dma_desc;
  2517. rval = qla8044_check_dma_engine_state(vha);
  2518. if (rval != QLA_SUCCESS) {
  2519. ql_dbg(ql_dbg_p3p, vha, 0xb147,
  2520. "DMA engine not available. Fallback to rdmem-read.\n");
  2521. return QLA_FUNCTION_FAILED;
  2522. }
  2523. m_hdr = (void *)entry_hdr;
  2524. rdmem_buffer = dma_alloc_coherent(&ha->pdev->dev,
  2525. ISP8044_PEX_DMA_READ_SIZE, &rdmem_dma, GFP_KERNEL);
  2526. if (!rdmem_buffer) {
  2527. ql_dbg(ql_dbg_p3p, vha, 0xb148,
  2528. "Unable to allocate rdmem dma buffer\n");
  2529. return QLA_FUNCTION_FAILED;
  2530. }
  2531. /* Prepare pex-dma descriptor to be written to MS memory. */
  2532. /* dma-desc-cmd layout:
  2533. * 0-3: dma-desc-cmd 0-3
  2534. * 4-7: pcid function number
  2535. * 8-15: dma-desc-cmd 8-15
  2536. * dma_bus_addr: dma buffer address
  2537. * cmd.read_data_size: amount of data-chunk to be read.
  2538. */
  2539. dma_desc.cmd.dma_desc_cmd = (m_hdr->dma_desc_cmd & 0xff0f);
  2540. dma_desc.cmd.dma_desc_cmd |=
  2541. ((PCI_FUNC(ha->pdev->devfn) & 0xf) << 0x4);
  2542. dma_desc.dma_bus_addr = rdmem_dma;
  2543. dma_desc.cmd.read_data_size = chunk_size = ISP8044_PEX_DMA_READ_SIZE;
  2544. read_size = 0;
  2545. /*
  2546. * Perform rdmem operation using pex-dma.
  2547. * Prepare dma in chunks of ISP8044_PEX_DMA_READ_SIZE.
  2548. */
  2549. while (read_size < m_hdr->read_data_size) {
  2550. if (m_hdr->read_data_size - read_size <
  2551. ISP8044_PEX_DMA_READ_SIZE) {
  2552. chunk_size = (m_hdr->read_data_size - read_size);
  2553. dma_desc.cmd.read_data_size = chunk_size;
  2554. }
  2555. dma_desc.src_addr = m_hdr->read_addr + read_size;
  2556. /* Prepare: Write pex-dma descriptor to MS memory. */
  2557. rval = qla8044_ms_mem_write_128b(vha,
  2558. m_hdr->desc_card_addr, (void *)&dma_desc,
  2559. (sizeof(struct qla8044_pex_dma_descriptor)/16));
  2560. if (rval) {
  2561. ql_log(ql_log_warn, vha, 0xb14a,
  2562. "%s: Error writing rdmem-dma-init to MS !!!\n",
  2563. __func__);
  2564. goto error_exit;
  2565. }
  2566. ql_dbg(ql_dbg_p3p, vha, 0xb14b,
  2567. "%s: Dma-descriptor: Instruct for rdmem dma "
  2568. "(chunk_size 0x%x).\n", __func__, chunk_size);
  2569. /* Execute: Start pex-dma operation. */
  2570. rval = qla8044_start_pex_dma(vha, m_hdr);
  2571. if (rval)
  2572. goto error_exit;
  2573. memcpy(data_ptr, rdmem_buffer, chunk_size);
  2574. data_ptr += chunk_size;
  2575. read_size += chunk_size;
  2576. }
  2577. *d_ptr = (void *)data_ptr;
  2578. error_exit:
  2579. if (rdmem_buffer)
  2580. dma_free_coherent(&ha->pdev->dev, ISP8044_PEX_DMA_READ_SIZE,
  2581. rdmem_buffer, rdmem_dma);
  2582. return rval;
  2583. }
  2584. static uint32_t
  2585. qla8044_minidump_process_rddfe(struct scsi_qla_host *vha,
  2586. struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
  2587. {
  2588. int loop_cnt;
  2589. uint32_t addr1, addr2, value, data, temp, wrVal;
  2590. uint8_t stride, stride2;
  2591. uint16_t count;
  2592. uint32_t poll, mask, data_size, modify_mask;
  2593. uint32_t wait_count = 0;
  2594. uint32_t *data_ptr = *d_ptr;
  2595. struct qla8044_minidump_entry_rddfe *rddfe;
  2596. rddfe = (struct qla8044_minidump_entry_rddfe *) entry_hdr;
  2597. addr1 = rddfe->addr_1;
  2598. value = rddfe->value;
  2599. stride = rddfe->stride;
  2600. stride2 = rddfe->stride2;
  2601. count = rddfe->count;
  2602. poll = rddfe->poll;
  2603. mask = rddfe->mask;
  2604. modify_mask = rddfe->modify_mask;
  2605. data_size = rddfe->data_size;
  2606. addr2 = addr1 + stride;
  2607. for (loop_cnt = 0x0; loop_cnt < count; loop_cnt++) {
  2608. qla8044_wr_reg_indirect(vha, addr1, (0x40000000 | value));
  2609. wait_count = 0;
  2610. while (wait_count < poll) {
  2611. qla8044_rd_reg_indirect(vha, addr1, &temp);
  2612. if ((temp & mask) != 0)
  2613. break;
  2614. wait_count++;
  2615. }
  2616. if (wait_count == poll) {
  2617. ql_log(ql_log_warn, vha, 0xb153,
  2618. "%s: TIMEOUT\n", __func__);
  2619. goto error;
  2620. } else {
  2621. qla8044_rd_reg_indirect(vha, addr2, &temp);
  2622. temp = temp & modify_mask;
  2623. temp = (temp | ((loop_cnt << 16) | loop_cnt));
  2624. wrVal = ((temp << 16) | temp);
  2625. qla8044_wr_reg_indirect(vha, addr2, wrVal);
  2626. qla8044_wr_reg_indirect(vha, addr1, value);
  2627. wait_count = 0;
  2628. while (wait_count < poll) {
  2629. qla8044_rd_reg_indirect(vha, addr1, &temp);
  2630. if ((temp & mask) != 0)
  2631. break;
  2632. wait_count++;
  2633. }
  2634. if (wait_count == poll) {
  2635. ql_log(ql_log_warn, vha, 0xb154,
  2636. "%s: TIMEOUT\n", __func__);
  2637. goto error;
  2638. }
  2639. qla8044_wr_reg_indirect(vha, addr1,
  2640. ((0x40000000 | value) + stride2));
  2641. wait_count = 0;
  2642. while (wait_count < poll) {
  2643. qla8044_rd_reg_indirect(vha, addr1, &temp);
  2644. if ((temp & mask) != 0)
  2645. break;
  2646. wait_count++;
  2647. }
  2648. if (wait_count == poll) {
  2649. ql_log(ql_log_warn, vha, 0xb155,
  2650. "%s: TIMEOUT\n", __func__);
  2651. goto error;
  2652. }
  2653. qla8044_rd_reg_indirect(vha, addr2, &data);
  2654. *data_ptr++ = wrVal;
  2655. *data_ptr++ = data;
  2656. }
  2657. }
  2658. *d_ptr = data_ptr;
  2659. return QLA_SUCCESS;
  2660. error:
  2661. return -1;
  2662. }
  2663. static uint32_t
  2664. qla8044_minidump_process_rdmdio(struct scsi_qla_host *vha,
  2665. struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
  2666. {
  2667. int ret = 0;
  2668. uint32_t addr1, addr2, value1, value2, data, selVal;
  2669. uint8_t stride1, stride2;
  2670. uint32_t addr3, addr4, addr5, addr6, addr7;
  2671. uint16_t count, loop_cnt;
  2672. uint32_t poll, mask;
  2673. uint32_t *data_ptr = *d_ptr;
  2674. struct qla8044_minidump_entry_rdmdio *rdmdio;
  2675. rdmdio = (struct qla8044_minidump_entry_rdmdio *) entry_hdr;
  2676. addr1 = rdmdio->addr_1;
  2677. addr2 = rdmdio->addr_2;
  2678. value1 = rdmdio->value_1;
  2679. stride1 = rdmdio->stride_1;
  2680. stride2 = rdmdio->stride_2;
  2681. count = rdmdio->count;
  2682. poll = rdmdio->poll;
  2683. mask = rdmdio->mask;
  2684. value2 = rdmdio->value_2;
  2685. addr3 = addr1 + stride1;
  2686. for (loop_cnt = 0; loop_cnt < count; loop_cnt++) {
  2687. ret = qla8044_poll_wait_ipmdio_bus_idle(vha, addr1, addr2,
  2688. addr3, mask);
  2689. if (ret == -1)
  2690. goto error;
  2691. addr4 = addr2 - stride1;
  2692. ret = qla8044_ipmdio_wr_reg(vha, addr1, addr3, mask, addr4,
  2693. value2);
  2694. if (ret == -1)
  2695. goto error;
  2696. addr5 = addr2 - (2 * stride1);
  2697. ret = qla8044_ipmdio_wr_reg(vha, addr1, addr3, mask, addr5,
  2698. value1);
  2699. if (ret == -1)
  2700. goto error;
  2701. addr6 = addr2 - (3 * stride1);
  2702. ret = qla8044_ipmdio_wr_reg(vha, addr1, addr3, mask,
  2703. addr6, 0x2);
  2704. if (ret == -1)
  2705. goto error;
  2706. ret = qla8044_poll_wait_ipmdio_bus_idle(vha, addr1, addr2,
  2707. addr3, mask);
  2708. if (ret == -1)
  2709. goto error;
  2710. addr7 = addr2 - (4 * stride1);
  2711. data = qla8044_ipmdio_rd_reg(vha, addr1, addr3, mask, addr7);
  2712. if (data == -1)
  2713. goto error;
  2714. selVal = (value2 << 18) | (value1 << 2) | 2;
  2715. stride2 = rdmdio->stride_2;
  2716. *data_ptr++ = selVal;
  2717. *data_ptr++ = data;
  2718. value1 = value1 + stride2;
  2719. *d_ptr = data_ptr;
  2720. }
  2721. return 0;
  2722. error:
  2723. return -1;
  2724. }
  2725. static uint32_t qla8044_minidump_process_pollwr(struct scsi_qla_host *vha,
  2726. struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
  2727. {
  2728. uint32_t addr1, addr2, value1, value2, poll, mask, r_value;
  2729. uint32_t wait_count = 0;
  2730. struct qla8044_minidump_entry_pollwr *pollwr_hdr;
  2731. pollwr_hdr = (struct qla8044_minidump_entry_pollwr *)entry_hdr;
  2732. addr1 = pollwr_hdr->addr_1;
  2733. addr2 = pollwr_hdr->addr_2;
  2734. value1 = pollwr_hdr->value_1;
  2735. value2 = pollwr_hdr->value_2;
  2736. poll = pollwr_hdr->poll;
  2737. mask = pollwr_hdr->mask;
  2738. while (wait_count < poll) {
  2739. qla8044_rd_reg_indirect(vha, addr1, &r_value);
  2740. if ((r_value & poll) != 0)
  2741. break;
  2742. wait_count++;
  2743. }
  2744. if (wait_count == poll) {
  2745. ql_log(ql_log_warn, vha, 0xb156, "%s: TIMEOUT\n", __func__);
  2746. goto error;
  2747. }
  2748. qla8044_wr_reg_indirect(vha, addr2, value2);
  2749. qla8044_wr_reg_indirect(vha, addr1, value1);
  2750. wait_count = 0;
  2751. while (wait_count < poll) {
  2752. qla8044_rd_reg_indirect(vha, addr1, &r_value);
  2753. if ((r_value & poll) != 0)
  2754. break;
  2755. wait_count++;
  2756. }
  2757. return QLA_SUCCESS;
  2758. error:
  2759. return -1;
  2760. }
  2761. /*
  2762. *
  2763. * qla8044_collect_md_data - Retrieve firmware minidump data.
  2764. * @ha: pointer to adapter structure
  2765. **/
  2766. int
  2767. qla8044_collect_md_data(struct scsi_qla_host *vha)
  2768. {
  2769. int num_entry_hdr = 0;
  2770. struct qla8044_minidump_entry_hdr *entry_hdr;
  2771. struct qla8044_minidump_template_hdr *tmplt_hdr;
  2772. uint32_t *data_ptr;
  2773. uint32_t data_collected = 0, f_capture_mask;
  2774. int i, rval = QLA_FUNCTION_FAILED;
  2775. uint64_t now;
  2776. uint32_t timestamp, idc_control;
  2777. struct qla_hw_data *ha = vha->hw;
  2778. if (!ha->md_dump) {
  2779. ql_log(ql_log_info, vha, 0xb101,
  2780. "%s(%ld) No buffer to dump\n",
  2781. __func__, vha->host_no);
  2782. return rval;
  2783. }
  2784. if (ha->fw_dumped) {
  2785. ql_log(ql_log_warn, vha, 0xb10d,
  2786. "Firmware has been previously dumped (%p) "
  2787. "-- ignoring request.\n", ha->fw_dump);
  2788. goto md_failed;
  2789. }
  2790. ha->fw_dumped = 0;
  2791. if (!ha->md_tmplt_hdr || !ha->md_dump) {
  2792. ql_log(ql_log_warn, vha, 0xb10e,
  2793. "Memory not allocated for minidump capture\n");
  2794. goto md_failed;
  2795. }
  2796. qla8044_idc_lock(ha);
  2797. idc_control = qla8044_rd_reg(ha, QLA8044_IDC_DRV_CTRL);
  2798. if (idc_control & GRACEFUL_RESET_BIT1) {
  2799. ql_log(ql_log_warn, vha, 0xb112,
  2800. "Forced reset from application, "
  2801. "ignore minidump capture\n");
  2802. qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
  2803. (idc_control & ~GRACEFUL_RESET_BIT1));
  2804. qla8044_idc_unlock(ha);
  2805. goto md_failed;
  2806. }
  2807. qla8044_idc_unlock(ha);
  2808. if (qla82xx_validate_template_chksum(vha)) {
  2809. ql_log(ql_log_info, vha, 0xb109,
  2810. "Template checksum validation error\n");
  2811. goto md_failed;
  2812. }
  2813. tmplt_hdr = (struct qla8044_minidump_template_hdr *)
  2814. ha->md_tmplt_hdr;
  2815. data_ptr = (uint32_t *)((uint8_t *)ha->md_dump);
  2816. num_entry_hdr = tmplt_hdr->num_of_entries;
  2817. ql_dbg(ql_dbg_p3p, vha, 0xb11a,
  2818. "Capture Mask obtained: 0x%x\n", tmplt_hdr->capture_debug_level);
  2819. f_capture_mask = tmplt_hdr->capture_debug_level & 0xFF;
  2820. /* Validate whether required debug level is set */
  2821. if ((f_capture_mask & 0x3) != 0x3) {
  2822. ql_log(ql_log_warn, vha, 0xb10f,
  2823. "Minimum required capture mask[0x%x] level not set\n",
  2824. f_capture_mask);
  2825. }
  2826. tmplt_hdr->driver_capture_mask = ql2xmdcapmask;
  2827. ql_log(ql_log_info, vha, 0xb102,
  2828. "[%s]: starting data ptr: %p\n",
  2829. __func__, data_ptr);
  2830. ql_log(ql_log_info, vha, 0xb10b,
  2831. "[%s]: no of entry headers in Template: 0x%x\n",
  2832. __func__, num_entry_hdr);
  2833. ql_log(ql_log_info, vha, 0xb10c,
  2834. "[%s]: Total_data_size 0x%x, %d obtained\n",
  2835. __func__, ha->md_dump_size, ha->md_dump_size);
  2836. /* Update current timestamp before taking dump */
  2837. now = get_jiffies_64();
  2838. timestamp = (u32)(jiffies_to_msecs(now) / 1000);
  2839. tmplt_hdr->driver_timestamp = timestamp;
  2840. entry_hdr = (struct qla8044_minidump_entry_hdr *)
  2841. (((uint8_t *)ha->md_tmplt_hdr) + tmplt_hdr->first_entry_offset);
  2842. tmplt_hdr->saved_state_array[QLA8044_SS_OCM_WNDREG_INDEX] =
  2843. tmplt_hdr->ocm_window_reg[ha->portnum];
  2844. /* Walk through the entry headers - validate/perform required action */
  2845. for (i = 0; i < num_entry_hdr; i++) {
  2846. if (data_collected > ha->md_dump_size) {
  2847. ql_log(ql_log_info, vha, 0xb103,
  2848. "Data collected: [0x%x], "
  2849. "Total Dump size: [0x%x]\n",
  2850. data_collected, ha->md_dump_size);
  2851. return rval;
  2852. }
  2853. if (!(entry_hdr->d_ctrl.entry_capture_mask &
  2854. ql2xmdcapmask)) {
  2855. entry_hdr->d_ctrl.driver_flags |=
  2856. QLA82XX_DBG_SKIPPED_FLAG;
  2857. goto skip_nxt_entry;
  2858. }
  2859. ql_dbg(ql_dbg_p3p, vha, 0xb104,
  2860. "Data collected: [0x%x], Dump size left:[0x%x]\n",
  2861. data_collected,
  2862. (ha->md_dump_size - data_collected));
  2863. /* Decode the entry type and take required action to capture
  2864. * debug data
  2865. */
  2866. switch (entry_hdr->entry_type) {
  2867. case QLA82XX_RDEND:
  2868. qla8044_mark_entry_skipped(vha, entry_hdr, i);
  2869. break;
  2870. case QLA82XX_CNTRL:
  2871. rval = qla8044_minidump_process_control(vha,
  2872. entry_hdr);
  2873. if (rval != QLA_SUCCESS) {
  2874. qla8044_mark_entry_skipped(vha, entry_hdr, i);
  2875. goto md_failed;
  2876. }
  2877. break;
  2878. case QLA82XX_RDCRB:
  2879. qla8044_minidump_process_rdcrb(vha,
  2880. entry_hdr, &data_ptr);
  2881. break;
  2882. case QLA82XX_RDMEM:
  2883. rval = qla8044_minidump_pex_dma_read(vha,
  2884. entry_hdr, &data_ptr);
  2885. if (rval != QLA_SUCCESS) {
  2886. rval = qla8044_minidump_process_rdmem(vha,
  2887. entry_hdr, &data_ptr);
  2888. if (rval != QLA_SUCCESS) {
  2889. qla8044_mark_entry_skipped(vha,
  2890. entry_hdr, i);
  2891. goto md_failed;
  2892. }
  2893. }
  2894. break;
  2895. case QLA82XX_BOARD:
  2896. case QLA82XX_RDROM:
  2897. rval = qla8044_minidump_process_rdrom(vha,
  2898. entry_hdr, &data_ptr);
  2899. if (rval != QLA_SUCCESS) {
  2900. qla8044_mark_entry_skipped(vha,
  2901. entry_hdr, i);
  2902. }
  2903. break;
  2904. case QLA82XX_L2DTG:
  2905. case QLA82XX_L2ITG:
  2906. case QLA82XX_L2DAT:
  2907. case QLA82XX_L2INS:
  2908. rval = qla8044_minidump_process_l2tag(vha,
  2909. entry_hdr, &data_ptr);
  2910. if (rval != QLA_SUCCESS) {
  2911. qla8044_mark_entry_skipped(vha, entry_hdr, i);
  2912. goto md_failed;
  2913. }
  2914. break;
  2915. case QLA8044_L1DTG:
  2916. case QLA8044_L1ITG:
  2917. case QLA82XX_L1DAT:
  2918. case QLA82XX_L1INS:
  2919. qla8044_minidump_process_l1cache(vha,
  2920. entry_hdr, &data_ptr);
  2921. break;
  2922. case QLA82XX_RDOCM:
  2923. qla8044_minidump_process_rdocm(vha,
  2924. entry_hdr, &data_ptr);
  2925. break;
  2926. case QLA82XX_RDMUX:
  2927. qla8044_minidump_process_rdmux(vha,
  2928. entry_hdr, &data_ptr);
  2929. break;
  2930. case QLA82XX_QUEUE:
  2931. qla8044_minidump_process_queue(vha,
  2932. entry_hdr, &data_ptr);
  2933. break;
  2934. case QLA8044_POLLRD:
  2935. rval = qla8044_minidump_process_pollrd(vha,
  2936. entry_hdr, &data_ptr);
  2937. if (rval != QLA_SUCCESS)
  2938. qla8044_mark_entry_skipped(vha, entry_hdr, i);
  2939. break;
  2940. case QLA8044_RDMUX2:
  2941. qla8044_minidump_process_rdmux2(vha,
  2942. entry_hdr, &data_ptr);
  2943. break;
  2944. case QLA8044_POLLRDMWR:
  2945. rval = qla8044_minidump_process_pollrdmwr(vha,
  2946. entry_hdr, &data_ptr);
  2947. if (rval != QLA_SUCCESS)
  2948. qla8044_mark_entry_skipped(vha, entry_hdr, i);
  2949. break;
  2950. case QLA8044_RDDFE:
  2951. rval = qla8044_minidump_process_rddfe(vha, entry_hdr,
  2952. &data_ptr);
  2953. if (rval != QLA_SUCCESS)
  2954. qla8044_mark_entry_skipped(vha, entry_hdr, i);
  2955. break;
  2956. case QLA8044_RDMDIO:
  2957. rval = qla8044_minidump_process_rdmdio(vha, entry_hdr,
  2958. &data_ptr);
  2959. if (rval != QLA_SUCCESS)
  2960. qla8044_mark_entry_skipped(vha, entry_hdr, i);
  2961. break;
  2962. case QLA8044_POLLWR:
  2963. rval = qla8044_minidump_process_pollwr(vha, entry_hdr,
  2964. &data_ptr);
  2965. if (rval != QLA_SUCCESS)
  2966. qla8044_mark_entry_skipped(vha, entry_hdr, i);
  2967. break;
  2968. case QLA82XX_RDNOP:
  2969. default:
  2970. qla8044_mark_entry_skipped(vha, entry_hdr, i);
  2971. break;
  2972. }
  2973. data_collected = (uint8_t *)data_ptr -
  2974. (uint8_t *)((uint8_t *)ha->md_dump);
  2975. skip_nxt_entry:
  2976. /*
  2977. * next entry in the template
  2978. */
  2979. entry_hdr = (struct qla8044_minidump_entry_hdr *)
  2980. (((uint8_t *)entry_hdr) + entry_hdr->entry_size);
  2981. }
  2982. if (data_collected != ha->md_dump_size) {
  2983. ql_log(ql_log_info, vha, 0xb105,
  2984. "Dump data mismatch: Data collected: "
  2985. "[0x%x], total_data_size:[0x%x]\n",
  2986. data_collected, ha->md_dump_size);
  2987. rval = QLA_FUNCTION_FAILED;
  2988. goto md_failed;
  2989. }
  2990. ql_log(ql_log_info, vha, 0xb110,
  2991. "Firmware dump saved to temp buffer (%ld/%p %ld/%p).\n",
  2992. vha->host_no, ha->md_tmplt_hdr, vha->host_no, ha->md_dump);
  2993. ha->fw_dumped = 1;
  2994. qla2x00_post_uevent_work(vha, QLA_UEVENT_CODE_FW_DUMP);
  2995. ql_log(ql_log_info, vha, 0xb106,
  2996. "Leaving fn: %s Last entry: 0x%x\n",
  2997. __func__, i);
  2998. md_failed:
  2999. return rval;
  3000. }
  3001. void
  3002. qla8044_get_minidump(struct scsi_qla_host *vha)
  3003. {
  3004. struct qla_hw_data *ha = vha->hw;
  3005. if (!qla8044_collect_md_data(vha)) {
  3006. ha->fw_dumped = 1;
  3007. ha->prev_minidump_failed = 0;
  3008. } else {
  3009. ql_log(ql_log_fatal, vha, 0xb0db,
  3010. "%s: Unable to collect minidump\n",
  3011. __func__);
  3012. ha->prev_minidump_failed = 1;
  3013. }
  3014. }
  3015. static int
  3016. qla8044_poll_flash_status_reg(struct scsi_qla_host *vha)
  3017. {
  3018. uint32_t flash_status;
  3019. int retries = QLA8044_FLASH_READ_RETRY_COUNT;
  3020. int ret_val = QLA_SUCCESS;
  3021. while (retries--) {
  3022. ret_val = qla8044_rd_reg_indirect(vha, QLA8044_FLASH_STATUS,
  3023. &flash_status);
  3024. if (ret_val) {
  3025. ql_log(ql_log_warn, vha, 0xb13c,
  3026. "%s: Failed to read FLASH_STATUS reg.\n",
  3027. __func__);
  3028. break;
  3029. }
  3030. if ((flash_status & QLA8044_FLASH_STATUS_READY) ==
  3031. QLA8044_FLASH_STATUS_READY)
  3032. break;
  3033. msleep(QLA8044_FLASH_STATUS_REG_POLL_DELAY);
  3034. }
  3035. if (!retries)
  3036. ret_val = QLA_FUNCTION_FAILED;
  3037. return ret_val;
  3038. }
  3039. static int
  3040. qla8044_write_flash_status_reg(struct scsi_qla_host *vha,
  3041. uint32_t data)
  3042. {
  3043. int ret_val = QLA_SUCCESS;
  3044. uint32_t cmd;
  3045. cmd = vha->hw->fdt_wrt_sts_reg_cmd;
  3046. ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_ADDR,
  3047. QLA8044_FLASH_STATUS_WRITE_DEF_SIG | cmd);
  3048. if (ret_val) {
  3049. ql_log(ql_log_warn, vha, 0xb125,
  3050. "%s: Failed to write to FLASH_ADDR.\n", __func__);
  3051. goto exit_func;
  3052. }
  3053. ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_WRDATA, data);
  3054. if (ret_val) {
  3055. ql_log(ql_log_warn, vha, 0xb126,
  3056. "%s: Failed to write to FLASH_WRDATA.\n", __func__);
  3057. goto exit_func;
  3058. }
  3059. ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_CONTROL,
  3060. QLA8044_FLASH_SECOND_ERASE_MS_VAL);
  3061. if (ret_val) {
  3062. ql_log(ql_log_warn, vha, 0xb127,
  3063. "%s: Failed to write to FLASH_CONTROL.\n", __func__);
  3064. goto exit_func;
  3065. }
  3066. ret_val = qla8044_poll_flash_status_reg(vha);
  3067. if (ret_val)
  3068. ql_log(ql_log_warn, vha, 0xb128,
  3069. "%s: Error polling flash status reg.\n", __func__);
  3070. exit_func:
  3071. return ret_val;
  3072. }
  3073. /*
  3074. * This function assumes that the flash lock is held.
  3075. */
  3076. static int
  3077. qla8044_unprotect_flash(scsi_qla_host_t *vha)
  3078. {
  3079. int ret_val;
  3080. struct qla_hw_data *ha = vha->hw;
  3081. ret_val = qla8044_write_flash_status_reg(vha, ha->fdt_wrt_enable);
  3082. if (ret_val)
  3083. ql_log(ql_log_warn, vha, 0xb139,
  3084. "%s: Write flash status failed.\n", __func__);
  3085. return ret_val;
  3086. }
  3087. /*
  3088. * This function assumes that the flash lock is held.
  3089. */
  3090. static int
  3091. qla8044_protect_flash(scsi_qla_host_t *vha)
  3092. {
  3093. int ret_val;
  3094. struct qla_hw_data *ha = vha->hw;
  3095. ret_val = qla8044_write_flash_status_reg(vha, ha->fdt_wrt_disable);
  3096. if (ret_val)
  3097. ql_log(ql_log_warn, vha, 0xb13b,
  3098. "%s: Write flash status failed.\n", __func__);
  3099. return ret_val;
  3100. }
  3101. static int
  3102. qla8044_erase_flash_sector(struct scsi_qla_host *vha,
  3103. uint32_t sector_start_addr)
  3104. {
  3105. uint32_t reversed_addr;
  3106. int ret_val = QLA_SUCCESS;
  3107. ret_val = qla8044_poll_flash_status_reg(vha);
  3108. if (ret_val) {
  3109. ql_log(ql_log_warn, vha, 0xb12e,
  3110. "%s: Poll flash status after erase failed..\n", __func__);
  3111. }
  3112. reversed_addr = (((sector_start_addr & 0xFF) << 16) |
  3113. (sector_start_addr & 0xFF00) |
  3114. ((sector_start_addr & 0xFF0000) >> 16));
  3115. ret_val = qla8044_wr_reg_indirect(vha,
  3116. QLA8044_FLASH_WRDATA, reversed_addr);
  3117. if (ret_val) {
  3118. ql_log(ql_log_warn, vha, 0xb12f,
  3119. "%s: Failed to write to FLASH_WRDATA.\n", __func__);
  3120. }
  3121. ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_ADDR,
  3122. QLA8044_FLASH_ERASE_SIG | vha->hw->fdt_erase_cmd);
  3123. if (ret_val) {
  3124. ql_log(ql_log_warn, vha, 0xb130,
  3125. "%s: Failed to write to FLASH_ADDR.\n", __func__);
  3126. }
  3127. ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_CONTROL,
  3128. QLA8044_FLASH_LAST_ERASE_MS_VAL);
  3129. if (ret_val) {
  3130. ql_log(ql_log_warn, vha, 0xb131,
  3131. "%s: Failed write to FLASH_CONTROL.\n", __func__);
  3132. }
  3133. ret_val = qla8044_poll_flash_status_reg(vha);
  3134. if (ret_val) {
  3135. ql_log(ql_log_warn, vha, 0xb132,
  3136. "%s: Poll flash status failed.\n", __func__);
  3137. }
  3138. return ret_val;
  3139. }
  3140. /*
  3141. * qla8044_flash_write_u32 - Write data to flash
  3142. *
  3143. * @ha : Pointer to adapter structure
  3144. * addr : Flash address to write to
  3145. * p_data : Data to be written
  3146. *
  3147. * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
  3148. *
  3149. * NOTE: Lock should be held on entry
  3150. */
  3151. static int
  3152. qla8044_flash_write_u32(struct scsi_qla_host *vha, uint32_t addr,
  3153. uint32_t *p_data)
  3154. {
  3155. int ret_val = QLA_SUCCESS;
  3156. ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_ADDR,
  3157. 0x00800000 | (addr >> 2));
  3158. if (ret_val) {
  3159. ql_log(ql_log_warn, vha, 0xb134,
  3160. "%s: Failed write to FLASH_ADDR.\n", __func__);
  3161. goto exit_func;
  3162. }
  3163. ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_WRDATA, *p_data);
  3164. if (ret_val) {
  3165. ql_log(ql_log_warn, vha, 0xb135,
  3166. "%s: Failed write to FLASH_WRDATA.\n", __func__);
  3167. goto exit_func;
  3168. }
  3169. ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_CONTROL, 0x3D);
  3170. if (ret_val) {
  3171. ql_log(ql_log_warn, vha, 0xb136,
  3172. "%s: Failed write to FLASH_CONTROL.\n", __func__);
  3173. goto exit_func;
  3174. }
  3175. ret_val = qla8044_poll_flash_status_reg(vha);
  3176. if (ret_val) {
  3177. ql_log(ql_log_warn, vha, 0xb137,
  3178. "%s: Poll flash status failed.\n", __func__);
  3179. }
  3180. exit_func:
  3181. return ret_val;
  3182. }
  3183. static int
  3184. qla8044_write_flash_buffer_mode(scsi_qla_host_t *vha, uint32_t *dwptr,
  3185. uint32_t faddr, uint32_t dwords)
  3186. {
  3187. int ret = QLA_FUNCTION_FAILED;
  3188. uint32_t spi_val;
  3189. if (dwords < QLA8044_MIN_OPTROM_BURST_DWORDS ||
  3190. dwords > QLA8044_MAX_OPTROM_BURST_DWORDS) {
  3191. ql_dbg(ql_dbg_user, vha, 0xb123,
  3192. "Got unsupported dwords = 0x%x.\n",
  3193. dwords);
  3194. return QLA_FUNCTION_FAILED;
  3195. }
  3196. qla8044_rd_reg_indirect(vha, QLA8044_FLASH_SPI_CONTROL, &spi_val);
  3197. qla8044_wr_reg_indirect(vha, QLA8044_FLASH_SPI_CONTROL,
  3198. spi_val | QLA8044_FLASH_SPI_CTL);
  3199. qla8044_wr_reg_indirect(vha, QLA8044_FLASH_ADDR,
  3200. QLA8044_FLASH_FIRST_TEMP_VAL);
  3201. /* First DWORD write to FLASH_WRDATA */
  3202. ret = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_WRDATA,
  3203. *dwptr++);
  3204. qla8044_wr_reg_indirect(vha, QLA8044_FLASH_CONTROL,
  3205. QLA8044_FLASH_FIRST_MS_PATTERN);
  3206. ret = qla8044_poll_flash_status_reg(vha);
  3207. if (ret) {
  3208. ql_log(ql_log_warn, vha, 0xb124,
  3209. "%s: Failed.\n", __func__);
  3210. goto exit_func;
  3211. }
  3212. dwords--;
  3213. qla8044_wr_reg_indirect(vha, QLA8044_FLASH_ADDR,
  3214. QLA8044_FLASH_SECOND_TEMP_VAL);
  3215. /* Second to N-1 DWORDS writes */
  3216. while (dwords != 1) {
  3217. qla8044_wr_reg_indirect(vha, QLA8044_FLASH_WRDATA, *dwptr++);
  3218. qla8044_wr_reg_indirect(vha, QLA8044_FLASH_CONTROL,
  3219. QLA8044_FLASH_SECOND_MS_PATTERN);
  3220. ret = qla8044_poll_flash_status_reg(vha);
  3221. if (ret) {
  3222. ql_log(ql_log_warn, vha, 0xb129,
  3223. "%s: Failed.\n", __func__);
  3224. goto exit_func;
  3225. }
  3226. dwords--;
  3227. }
  3228. qla8044_wr_reg_indirect(vha, QLA8044_FLASH_ADDR,
  3229. QLA8044_FLASH_FIRST_TEMP_VAL | (faddr >> 2));
  3230. /* Last DWORD write */
  3231. qla8044_wr_reg_indirect(vha, QLA8044_FLASH_WRDATA, *dwptr++);
  3232. qla8044_wr_reg_indirect(vha, QLA8044_FLASH_CONTROL,
  3233. QLA8044_FLASH_LAST_MS_PATTERN);
  3234. ret = qla8044_poll_flash_status_reg(vha);
  3235. if (ret) {
  3236. ql_log(ql_log_warn, vha, 0xb12a,
  3237. "%s: Failed.\n", __func__);
  3238. goto exit_func;
  3239. }
  3240. qla8044_rd_reg_indirect(vha, QLA8044_FLASH_SPI_STATUS, &spi_val);
  3241. if ((spi_val & QLA8044_FLASH_SPI_CTL) == QLA8044_FLASH_SPI_CTL) {
  3242. ql_log(ql_log_warn, vha, 0xb12b,
  3243. "%s: Failed.\n", __func__);
  3244. spi_val = 0;
  3245. /* Operation failed, clear error bit. */
  3246. qla8044_rd_reg_indirect(vha, QLA8044_FLASH_SPI_CONTROL,
  3247. &spi_val);
  3248. qla8044_wr_reg_indirect(vha, QLA8044_FLASH_SPI_CONTROL,
  3249. spi_val | QLA8044_FLASH_SPI_CTL);
  3250. }
  3251. exit_func:
  3252. return ret;
  3253. }
  3254. static int
  3255. qla8044_write_flash_dword_mode(scsi_qla_host_t *vha, uint32_t *dwptr,
  3256. uint32_t faddr, uint32_t dwords)
  3257. {
  3258. int ret = QLA_FUNCTION_FAILED;
  3259. uint32_t liter;
  3260. for (liter = 0; liter < dwords; liter++, faddr += 4, dwptr++) {
  3261. ret = qla8044_flash_write_u32(vha, faddr, dwptr);
  3262. if (ret) {
  3263. ql_dbg(ql_dbg_p3p, vha, 0xb141,
  3264. "%s: flash address=%x data=%x.\n", __func__,
  3265. faddr, *dwptr);
  3266. break;
  3267. }
  3268. }
  3269. return ret;
  3270. }
  3271. int
  3272. qla8044_write_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
  3273. uint32_t offset, uint32_t length)
  3274. {
  3275. int rval = QLA_FUNCTION_FAILED, i, burst_iter_count;
  3276. int dword_count, erase_sec_count;
  3277. uint32_t erase_offset;
  3278. uint8_t *p_cache, *p_src;
  3279. erase_offset = offset;
  3280. p_cache = kcalloc(length, sizeof(uint8_t), GFP_KERNEL);
  3281. if (!p_cache)
  3282. return QLA_FUNCTION_FAILED;
  3283. memcpy(p_cache, buf, length);
  3284. p_src = p_cache;
  3285. dword_count = length / sizeof(uint32_t);
  3286. /* Since the offset and legth are sector aligned, it will be always
  3287. * multiple of burst_iter_count (64)
  3288. */
  3289. burst_iter_count = dword_count / QLA8044_MAX_OPTROM_BURST_DWORDS;
  3290. erase_sec_count = length / QLA8044_SECTOR_SIZE;
  3291. /* Suspend HBA. */
  3292. scsi_block_requests(vha->host);
  3293. /* Lock and enable write for whole operation. */
  3294. qla8044_flash_lock(vha);
  3295. qla8044_unprotect_flash(vha);
  3296. /* Erasing the sectors */
  3297. for (i = 0; i < erase_sec_count; i++) {
  3298. rval = qla8044_erase_flash_sector(vha, erase_offset);
  3299. ql_dbg(ql_dbg_user, vha, 0xb138,
  3300. "Done erase of sector=0x%x.\n",
  3301. erase_offset);
  3302. if (rval) {
  3303. ql_log(ql_log_warn, vha, 0xb121,
  3304. "Failed to erase the sector having address: "
  3305. "0x%x.\n", erase_offset);
  3306. goto out;
  3307. }
  3308. erase_offset += QLA8044_SECTOR_SIZE;
  3309. }
  3310. ql_dbg(ql_dbg_user, vha, 0xb13f,
  3311. "Got write for addr = 0x%x length=0x%x.\n",
  3312. offset, length);
  3313. for (i = 0; i < burst_iter_count; i++) {
  3314. /* Go with write. */
  3315. rval = qla8044_write_flash_buffer_mode(vha, (uint32_t *)p_src,
  3316. offset, QLA8044_MAX_OPTROM_BURST_DWORDS);
  3317. if (rval) {
  3318. /* Buffer Mode failed skip to dword mode */
  3319. ql_log(ql_log_warn, vha, 0xb122,
  3320. "Failed to write flash in buffer mode, "
  3321. "Reverting to slow-write.\n");
  3322. rval = qla8044_write_flash_dword_mode(vha,
  3323. (uint32_t *)p_src, offset,
  3324. QLA8044_MAX_OPTROM_BURST_DWORDS);
  3325. }
  3326. p_src += sizeof(uint32_t) * QLA8044_MAX_OPTROM_BURST_DWORDS;
  3327. offset += sizeof(uint32_t) * QLA8044_MAX_OPTROM_BURST_DWORDS;
  3328. }
  3329. ql_dbg(ql_dbg_user, vha, 0xb133,
  3330. "Done writing.\n");
  3331. out:
  3332. qla8044_protect_flash(vha);
  3333. qla8044_flash_unlock(vha);
  3334. scsi_unblock_requests(vha->host);
  3335. kfree(p_cache);
  3336. return rval;
  3337. }
  3338. #define LEG_INT_PTR_B31 (1 << 31)
  3339. #define LEG_INT_PTR_B30 (1 << 30)
  3340. #define PF_BITS_MASK (0xF << 16)
  3341. /**
  3342. * qla8044_intr_handler() - Process interrupts for the ISP8044
  3343. * @irq:
  3344. * @dev_id: SCSI driver HA context
  3345. *
  3346. * Called by system whenever the host adapter generates an interrupt.
  3347. *
  3348. * Returns handled flag.
  3349. */
  3350. irqreturn_t
  3351. qla8044_intr_handler(int irq, void *dev_id)
  3352. {
  3353. scsi_qla_host_t *vha;
  3354. struct qla_hw_data *ha;
  3355. struct rsp_que *rsp;
  3356. struct device_reg_82xx __iomem *reg;
  3357. int status = 0;
  3358. unsigned long flags;
  3359. unsigned long iter;
  3360. uint32_t stat;
  3361. uint16_t mb[4];
  3362. uint32_t leg_int_ptr = 0, pf_bit;
  3363. rsp = (struct rsp_que *) dev_id;
  3364. if (!rsp) {
  3365. ql_log(ql_log_info, NULL, 0xb143,
  3366. "%s(): NULL response queue pointer\n", __func__);
  3367. return IRQ_NONE;
  3368. }
  3369. ha = rsp->hw;
  3370. vha = pci_get_drvdata(ha->pdev);
  3371. if (unlikely(pci_channel_offline(ha->pdev)))
  3372. return IRQ_HANDLED;
  3373. leg_int_ptr = qla8044_rd_reg(ha, LEG_INTR_PTR_OFFSET);
  3374. /* Legacy interrupt is valid if bit31 of leg_int_ptr is set */
  3375. if (!(leg_int_ptr & (LEG_INT_PTR_B31))) {
  3376. ql_dbg(ql_dbg_p3p, vha, 0xb144,
  3377. "%s: Legacy Interrupt Bit 31 not set, "
  3378. "spurious interrupt!\n", __func__);
  3379. return IRQ_NONE;
  3380. }
  3381. pf_bit = ha->portnum << 16;
  3382. /* Validate the PCIE function ID set in leg_int_ptr bits [19..16] */
  3383. if ((leg_int_ptr & (PF_BITS_MASK)) != pf_bit) {
  3384. ql_dbg(ql_dbg_p3p, vha, 0xb145,
  3385. "%s: Incorrect function ID 0x%x in "
  3386. "legacy interrupt register, "
  3387. "ha->pf_bit = 0x%x\n", __func__,
  3388. (leg_int_ptr & (PF_BITS_MASK)), pf_bit);
  3389. return IRQ_NONE;
  3390. }
  3391. /* To de-assert legacy interrupt, write 0 to Legacy Interrupt Trigger
  3392. * Control register and poll till Legacy Interrupt Pointer register
  3393. * bit32 is 0.
  3394. */
  3395. qla8044_wr_reg(ha, LEG_INTR_TRIG_OFFSET, 0);
  3396. do {
  3397. leg_int_ptr = qla8044_rd_reg(ha, LEG_INTR_PTR_OFFSET);
  3398. if ((leg_int_ptr & (PF_BITS_MASK)) != pf_bit)
  3399. break;
  3400. } while (leg_int_ptr & (LEG_INT_PTR_B30));
  3401. reg = &ha->iobase->isp82;
  3402. spin_lock_irqsave(&ha->hardware_lock, flags);
  3403. for (iter = 1; iter--; ) {
  3404. if (RD_REG_DWORD(&reg->host_int)) {
  3405. stat = RD_REG_DWORD(&reg->host_status);
  3406. if ((stat & HSRX_RISC_INT) == 0)
  3407. break;
  3408. switch (stat & 0xff) {
  3409. case 0x1:
  3410. case 0x2:
  3411. case 0x10:
  3412. case 0x11:
  3413. qla82xx_mbx_completion(vha, MSW(stat));
  3414. status |= MBX_INTERRUPT;
  3415. break;
  3416. case 0x12:
  3417. mb[0] = MSW(stat);
  3418. mb[1] = RD_REG_WORD(&reg->mailbox_out[1]);
  3419. mb[2] = RD_REG_WORD(&reg->mailbox_out[2]);
  3420. mb[3] = RD_REG_WORD(&reg->mailbox_out[3]);
  3421. qla2x00_async_event(vha, rsp, mb);
  3422. break;
  3423. case 0x13:
  3424. qla24xx_process_response_queue(vha, rsp);
  3425. break;
  3426. default:
  3427. ql_dbg(ql_dbg_p3p, vha, 0xb146,
  3428. "Unrecognized interrupt type "
  3429. "(%d).\n", stat & 0xff);
  3430. break;
  3431. }
  3432. }
  3433. WRT_REG_DWORD(&reg->host_int, 0);
  3434. }
  3435. qla2x00_handle_mbx_completion(ha, status);
  3436. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3437. return IRQ_HANDLED;
  3438. }
  3439. static int
  3440. qla8044_idc_dontreset(struct qla_hw_data *ha)
  3441. {
  3442. uint32_t idc_ctrl;
  3443. idc_ctrl = qla8044_rd_reg(ha, QLA8044_IDC_DRV_CTRL);
  3444. return idc_ctrl & DONTRESET_BIT0;
  3445. }
  3446. static void
  3447. qla8044_clear_rst_ready(scsi_qla_host_t *vha)
  3448. {
  3449. uint32_t drv_state;
  3450. drv_state = qla8044_rd_direct(vha, QLA8044_CRB_DRV_STATE_INDEX);
  3451. /*
  3452. * For ISP8044, drv_active register has 1 bit per function,
  3453. * shift 1 by func_num to set a bit for the function.
  3454. * For ISP82xx, drv_active has 4 bits per function
  3455. */
  3456. drv_state &= ~(1 << vha->hw->portnum);
  3457. ql_dbg(ql_dbg_p3p, vha, 0xb13d,
  3458. "drv_state: 0x%08x\n", drv_state);
  3459. qla8044_wr_direct(vha, QLA8044_CRB_DRV_STATE_INDEX, drv_state);
  3460. }
  3461. int
  3462. qla8044_abort_isp(scsi_qla_host_t *vha)
  3463. {
  3464. int rval;
  3465. uint32_t dev_state;
  3466. struct qla_hw_data *ha = vha->hw;
  3467. qla8044_idc_lock(ha);
  3468. dev_state = qla8044_rd_direct(vha, QLA8044_CRB_DEV_STATE_INDEX);
  3469. if (ql2xdontresethba)
  3470. qla8044_set_idc_dontreset(vha);
  3471. /* If device_state is NEED_RESET, go ahead with
  3472. * Reset,irrespective of ql2xdontresethba. This is to allow a
  3473. * non-reset-owner to force a reset. Non-reset-owner sets
  3474. * the IDC_CTRL BIT0 to prevent Reset-owner from doing a Reset
  3475. * and then forces a Reset by setting device_state to
  3476. * NEED_RESET. */
  3477. if (dev_state == QLA8XXX_DEV_READY) {
  3478. /* If IDC_CTRL DONTRESETHBA_BIT0 is set don't do reset
  3479. * recovery */
  3480. if (qla8044_idc_dontreset(ha) == DONTRESET_BIT0) {
  3481. ql_dbg(ql_dbg_p3p, vha, 0xb13e,
  3482. "Reset recovery disabled\n");
  3483. rval = QLA_FUNCTION_FAILED;
  3484. goto exit_isp_reset;
  3485. }
  3486. ql_dbg(ql_dbg_p3p, vha, 0xb140,
  3487. "HW State: NEED RESET\n");
  3488. qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX,
  3489. QLA8XXX_DEV_NEED_RESET);
  3490. }
  3491. /* For ISP8044, Reset owner is NIC, iSCSI or FCOE based on priority
  3492. * and which drivers are present. Unlike ISP82XX, the function setting
  3493. * NEED_RESET, may not be the Reset owner. */
  3494. qla83xx_reset_ownership(vha);
  3495. qla8044_idc_unlock(ha);
  3496. rval = qla8044_device_state_handler(vha);
  3497. qla8044_idc_lock(ha);
  3498. qla8044_clear_rst_ready(vha);
  3499. exit_isp_reset:
  3500. qla8044_idc_unlock(ha);
  3501. if (rval == QLA_SUCCESS) {
  3502. ha->flags.isp82xx_fw_hung = 0;
  3503. ha->flags.nic_core_reset_hdlr_active = 0;
  3504. rval = qla82xx_restart_isp(vha);
  3505. }
  3506. return rval;
  3507. }
  3508. void
  3509. qla8044_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
  3510. {
  3511. struct qla_hw_data *ha = vha->hw;
  3512. if (!ha->allow_cna_fw_dump)
  3513. return;
  3514. scsi_block_requests(vha->host);
  3515. ha->flags.isp82xx_no_md_cap = 1;
  3516. qla8044_idc_lock(ha);
  3517. qla82xx_set_reset_owner(vha);
  3518. qla8044_idc_unlock(ha);
  3519. qla2x00_wait_for_chip_reset(vha);
  3520. scsi_unblock_requests(vha->host);
  3521. }