qla_nx2.c 107 KB

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