lpfc_sli.c 112 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2008 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_cmnd.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_host.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include "lpfc_hw.h"
  31. #include "lpfc_sli.h"
  32. #include "lpfc_disc.h"
  33. #include "lpfc_scsi.h"
  34. #include "lpfc.h"
  35. #include "lpfc_crtn.h"
  36. #include "lpfc_logmsg.h"
  37. #include "lpfc_compat.h"
  38. #include "lpfc_debugfs.h"
  39. /*
  40. * Define macro to log: Mailbox command x%x cannot issue Data
  41. * This allows multiple uses of lpfc_msgBlk0311
  42. * w/o perturbing log msg utility.
  43. */
  44. #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \
  45. lpfc_printf_log(phba, \
  46. KERN_INFO, \
  47. LOG_MBOX | LOG_SLI, \
  48. "(%d):0311 Mailbox command x%x cannot " \
  49. "issue Data: x%x x%x x%x\n", \
  50. pmbox->vport ? pmbox->vport->vpi : 0, \
  51. pmbox->mb.mbxCommand, \
  52. phba->pport->port_state, \
  53. psli->sli_flag, \
  54. flag)
  55. /* There are only four IOCB completion types. */
  56. typedef enum _lpfc_iocb_type {
  57. LPFC_UNKNOWN_IOCB,
  58. LPFC_UNSOL_IOCB,
  59. LPFC_SOL_IOCB,
  60. LPFC_ABORT_IOCB
  61. } lpfc_iocb_type;
  62. /* SLI-2/SLI-3 provide different sized iocbs. Given a pointer
  63. * to the start of the ring, and the slot number of the
  64. * desired iocb entry, calc a pointer to that entry.
  65. */
  66. static inline IOCB_t *
  67. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  68. {
  69. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  70. pring->cmdidx * phba->iocb_cmd_size);
  71. }
  72. static inline IOCB_t *
  73. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  74. {
  75. return (IOCB_t *) (((char *) pring->rspringaddr) +
  76. pring->rspidx * phba->iocb_rsp_size);
  77. }
  78. static struct lpfc_iocbq *
  79. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  80. {
  81. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  82. struct lpfc_iocbq * iocbq = NULL;
  83. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  84. return iocbq;
  85. }
  86. struct lpfc_iocbq *
  87. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  88. {
  89. struct lpfc_iocbq * iocbq = NULL;
  90. unsigned long iflags;
  91. spin_lock_irqsave(&phba->hbalock, iflags);
  92. iocbq = __lpfc_sli_get_iocbq(phba);
  93. spin_unlock_irqrestore(&phba->hbalock, iflags);
  94. return iocbq;
  95. }
  96. static void
  97. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  98. {
  99. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  100. /*
  101. * Clean all volatile data fields, preserve iotag and node struct.
  102. */
  103. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  104. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  105. }
  106. void
  107. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  108. {
  109. unsigned long iflags;
  110. /*
  111. * Clean all volatile data fields, preserve iotag and node struct.
  112. */
  113. spin_lock_irqsave(&phba->hbalock, iflags);
  114. __lpfc_sli_release_iocbq(phba, iocbq);
  115. spin_unlock_irqrestore(&phba->hbalock, iflags);
  116. }
  117. /*
  118. * Translate the iocb command to an iocb command type used to decide the final
  119. * disposition of each completed IOCB.
  120. */
  121. static lpfc_iocb_type
  122. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  123. {
  124. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  125. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  126. return 0;
  127. switch (iocb_cmnd) {
  128. case CMD_XMIT_SEQUENCE_CR:
  129. case CMD_XMIT_SEQUENCE_CX:
  130. case CMD_XMIT_BCAST_CN:
  131. case CMD_XMIT_BCAST_CX:
  132. case CMD_ELS_REQUEST_CR:
  133. case CMD_ELS_REQUEST_CX:
  134. case CMD_CREATE_XRI_CR:
  135. case CMD_CREATE_XRI_CX:
  136. case CMD_GET_RPI_CN:
  137. case CMD_XMIT_ELS_RSP_CX:
  138. case CMD_GET_RPI_CR:
  139. case CMD_FCP_IWRITE_CR:
  140. case CMD_FCP_IWRITE_CX:
  141. case CMD_FCP_IREAD_CR:
  142. case CMD_FCP_IREAD_CX:
  143. case CMD_FCP_ICMND_CR:
  144. case CMD_FCP_ICMND_CX:
  145. case CMD_FCP_TSEND_CX:
  146. case CMD_FCP_TRSP_CX:
  147. case CMD_FCP_TRECEIVE_CX:
  148. case CMD_FCP_AUTO_TRSP_CX:
  149. case CMD_ADAPTER_MSG:
  150. case CMD_ADAPTER_DUMP:
  151. case CMD_XMIT_SEQUENCE64_CR:
  152. case CMD_XMIT_SEQUENCE64_CX:
  153. case CMD_XMIT_BCAST64_CN:
  154. case CMD_XMIT_BCAST64_CX:
  155. case CMD_ELS_REQUEST64_CR:
  156. case CMD_ELS_REQUEST64_CX:
  157. case CMD_FCP_IWRITE64_CR:
  158. case CMD_FCP_IWRITE64_CX:
  159. case CMD_FCP_IREAD64_CR:
  160. case CMD_FCP_IREAD64_CX:
  161. case CMD_FCP_ICMND64_CR:
  162. case CMD_FCP_ICMND64_CX:
  163. case CMD_FCP_TSEND64_CX:
  164. case CMD_FCP_TRSP64_CX:
  165. case CMD_FCP_TRECEIVE64_CX:
  166. case CMD_GEN_REQUEST64_CR:
  167. case CMD_GEN_REQUEST64_CX:
  168. case CMD_XMIT_ELS_RSP64_CX:
  169. type = LPFC_SOL_IOCB;
  170. break;
  171. case CMD_ABORT_XRI_CN:
  172. case CMD_ABORT_XRI_CX:
  173. case CMD_CLOSE_XRI_CN:
  174. case CMD_CLOSE_XRI_CX:
  175. case CMD_XRI_ABORTED_CX:
  176. case CMD_ABORT_MXRI64_CN:
  177. type = LPFC_ABORT_IOCB;
  178. break;
  179. case CMD_RCV_SEQUENCE_CX:
  180. case CMD_RCV_ELS_REQ_CX:
  181. case CMD_RCV_SEQUENCE64_CX:
  182. case CMD_RCV_ELS_REQ64_CX:
  183. case CMD_ASYNC_STATUS:
  184. case CMD_IOCB_RCV_SEQ64_CX:
  185. case CMD_IOCB_RCV_ELS64_CX:
  186. case CMD_IOCB_RCV_CONT64_CX:
  187. case CMD_IOCB_RET_XRI64_CX:
  188. type = LPFC_UNSOL_IOCB;
  189. break;
  190. case CMD_IOCB_XMIT_MSEQ64_CR:
  191. case CMD_IOCB_XMIT_MSEQ64_CX:
  192. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  193. case CMD_IOCB_RCV_ELS_LIST64_CX:
  194. case CMD_IOCB_CLOSE_EXTENDED_CN:
  195. case CMD_IOCB_ABORT_EXTENDED_CN:
  196. case CMD_IOCB_RET_HBQE64_CN:
  197. case CMD_IOCB_FCP_IBIDIR64_CR:
  198. case CMD_IOCB_FCP_IBIDIR64_CX:
  199. case CMD_IOCB_FCP_ITASKMGT64_CX:
  200. case CMD_IOCB_LOGENTRY_CN:
  201. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  202. printk("%s - Unhandled SLI-3 Command x%x\n",
  203. __FUNCTION__, iocb_cmnd);
  204. type = LPFC_UNKNOWN_IOCB;
  205. break;
  206. default:
  207. type = LPFC_UNKNOWN_IOCB;
  208. break;
  209. }
  210. return type;
  211. }
  212. static int
  213. lpfc_sli_ring_map(struct lpfc_hba *phba)
  214. {
  215. struct lpfc_sli *psli = &phba->sli;
  216. LPFC_MBOXQ_t *pmb;
  217. MAILBOX_t *pmbox;
  218. int i, rc, ret = 0;
  219. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  220. if (!pmb)
  221. return -ENOMEM;
  222. pmbox = &pmb->mb;
  223. phba->link_state = LPFC_INIT_MBX_CMDS;
  224. for (i = 0; i < psli->num_rings; i++) {
  225. lpfc_config_ring(phba, i, pmb);
  226. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  227. if (rc != MBX_SUCCESS) {
  228. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  229. "0446 Adapter failed to init (%d), "
  230. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  231. "ring %d\n",
  232. rc, pmbox->mbxCommand,
  233. pmbox->mbxStatus, i);
  234. phba->link_state = LPFC_HBA_ERROR;
  235. ret = -ENXIO;
  236. break;
  237. }
  238. }
  239. mempool_free(pmb, phba->mbox_mem_pool);
  240. return ret;
  241. }
  242. static int
  243. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  244. struct lpfc_iocbq *piocb)
  245. {
  246. list_add_tail(&piocb->list, &pring->txcmplq);
  247. pring->txcmplq_cnt++;
  248. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  249. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  250. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  251. if (!piocb->vport)
  252. BUG();
  253. else
  254. mod_timer(&piocb->vport->els_tmofunc,
  255. jiffies + HZ * (phba->fc_ratov << 1));
  256. }
  257. return 0;
  258. }
  259. static struct lpfc_iocbq *
  260. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  261. {
  262. struct lpfc_iocbq *cmd_iocb;
  263. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  264. if (cmd_iocb != NULL)
  265. pring->txq_cnt--;
  266. return cmd_iocb;
  267. }
  268. static IOCB_t *
  269. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  270. {
  271. struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
  272. &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
  273. &phba->slim2p->mbx.us.s2.port[pring->ringno];
  274. uint32_t max_cmd_idx = pring->numCiocb;
  275. if ((pring->next_cmdidx == pring->cmdidx) &&
  276. (++pring->next_cmdidx >= max_cmd_idx))
  277. pring->next_cmdidx = 0;
  278. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  279. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  280. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  281. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  282. "0315 Ring %d issue: portCmdGet %d "
  283. "is bigger then cmd ring %d\n",
  284. pring->ringno,
  285. pring->local_getidx, max_cmd_idx);
  286. phba->link_state = LPFC_HBA_ERROR;
  287. /*
  288. * All error attention handlers are posted to
  289. * worker thread
  290. */
  291. phba->work_ha |= HA_ERATT;
  292. phba->work_hs = HS_FFER3;
  293. /* hbalock should already be held */
  294. if (phba->work_wait)
  295. lpfc_worker_wake_up(phba);
  296. return NULL;
  297. }
  298. if (pring->local_getidx == pring->next_cmdidx)
  299. return NULL;
  300. }
  301. return lpfc_cmd_iocb(phba, pring);
  302. }
  303. uint16_t
  304. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  305. {
  306. struct lpfc_iocbq **new_arr;
  307. struct lpfc_iocbq **old_arr;
  308. size_t new_len;
  309. struct lpfc_sli *psli = &phba->sli;
  310. uint16_t iotag;
  311. spin_lock_irq(&phba->hbalock);
  312. iotag = psli->last_iotag;
  313. if(++iotag < psli->iocbq_lookup_len) {
  314. psli->last_iotag = iotag;
  315. psli->iocbq_lookup[iotag] = iocbq;
  316. spin_unlock_irq(&phba->hbalock);
  317. iocbq->iotag = iotag;
  318. return iotag;
  319. } else if (psli->iocbq_lookup_len < (0xffff
  320. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  321. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  322. spin_unlock_irq(&phba->hbalock);
  323. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  324. GFP_KERNEL);
  325. if (new_arr) {
  326. spin_lock_irq(&phba->hbalock);
  327. old_arr = psli->iocbq_lookup;
  328. if (new_len <= psli->iocbq_lookup_len) {
  329. /* highly unprobable case */
  330. kfree(new_arr);
  331. iotag = psli->last_iotag;
  332. if(++iotag < psli->iocbq_lookup_len) {
  333. psli->last_iotag = iotag;
  334. psli->iocbq_lookup[iotag] = iocbq;
  335. spin_unlock_irq(&phba->hbalock);
  336. iocbq->iotag = iotag;
  337. return iotag;
  338. }
  339. spin_unlock_irq(&phba->hbalock);
  340. return 0;
  341. }
  342. if (psli->iocbq_lookup)
  343. memcpy(new_arr, old_arr,
  344. ((psli->last_iotag + 1) *
  345. sizeof (struct lpfc_iocbq *)));
  346. psli->iocbq_lookup = new_arr;
  347. psli->iocbq_lookup_len = new_len;
  348. psli->last_iotag = iotag;
  349. psli->iocbq_lookup[iotag] = iocbq;
  350. spin_unlock_irq(&phba->hbalock);
  351. iocbq->iotag = iotag;
  352. kfree(old_arr);
  353. return iotag;
  354. }
  355. } else
  356. spin_unlock_irq(&phba->hbalock);
  357. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  358. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  359. psli->last_iotag);
  360. return 0;
  361. }
  362. static void
  363. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  364. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  365. {
  366. /*
  367. * Set up an iotag
  368. */
  369. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  370. if (pring->ringno == LPFC_ELS_RING) {
  371. lpfc_debugfs_slow_ring_trc(phba,
  372. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  373. *(((uint32_t *) &nextiocb->iocb) + 4),
  374. *(((uint32_t *) &nextiocb->iocb) + 6),
  375. *(((uint32_t *) &nextiocb->iocb) + 7));
  376. }
  377. /*
  378. * Issue iocb command to adapter
  379. */
  380. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  381. wmb();
  382. pring->stats.iocb_cmd++;
  383. /*
  384. * If there is no completion routine to call, we can release the
  385. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  386. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  387. */
  388. if (nextiocb->iocb_cmpl)
  389. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  390. else
  391. __lpfc_sli_release_iocbq(phba, nextiocb);
  392. /*
  393. * Let the HBA know what IOCB slot will be the next one the
  394. * driver will put a command into.
  395. */
  396. pring->cmdidx = pring->next_cmdidx;
  397. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  398. }
  399. static void
  400. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  401. {
  402. int ringno = pring->ringno;
  403. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  404. wmb();
  405. /*
  406. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  407. * The HBA will tell us when an IOCB entry is available.
  408. */
  409. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  410. readl(phba->CAregaddr); /* flush */
  411. pring->stats.iocb_cmd_full++;
  412. }
  413. static void
  414. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  415. {
  416. int ringno = pring->ringno;
  417. /*
  418. * Tell the HBA that there is work to do in this ring.
  419. */
  420. wmb();
  421. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  422. readl(phba->CAregaddr); /* flush */
  423. }
  424. static void
  425. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  426. {
  427. IOCB_t *iocb;
  428. struct lpfc_iocbq *nextiocb;
  429. /*
  430. * Check to see if:
  431. * (a) there is anything on the txq to send
  432. * (b) link is up
  433. * (c) link attention events can be processed (fcp ring only)
  434. * (d) IOCB processing is not blocked by the outstanding mbox command.
  435. */
  436. if (pring->txq_cnt &&
  437. lpfc_is_link_up(phba) &&
  438. (pring->ringno != phba->sli.fcp_ring ||
  439. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  440. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  441. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  442. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  443. if (iocb)
  444. lpfc_sli_update_ring(phba, pring);
  445. else
  446. lpfc_sli_update_full_ring(phba, pring);
  447. }
  448. return;
  449. }
  450. static struct lpfc_hbq_entry *
  451. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  452. {
  453. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  454. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  455. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  456. hbqp->next_hbqPutIdx = 0;
  457. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  458. uint32_t raw_index = phba->hbq_get[hbqno];
  459. uint32_t getidx = le32_to_cpu(raw_index);
  460. hbqp->local_hbqGetIdx = getidx;
  461. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  462. lpfc_printf_log(phba, KERN_ERR,
  463. LOG_SLI | LOG_VPORT,
  464. "1802 HBQ %d: local_hbqGetIdx "
  465. "%u is > than hbqp->entry_count %u\n",
  466. hbqno, hbqp->local_hbqGetIdx,
  467. hbqp->entry_count);
  468. phba->link_state = LPFC_HBA_ERROR;
  469. return NULL;
  470. }
  471. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  472. return NULL;
  473. }
  474. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  475. hbqp->hbqPutIdx;
  476. }
  477. void
  478. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  479. {
  480. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  481. struct hbq_dmabuf *hbq_buf;
  482. unsigned long flags;
  483. int i, hbq_count;
  484. uint32_t hbqno;
  485. hbq_count = lpfc_sli_hbq_count();
  486. /* Return all memory used by all HBQs */
  487. spin_lock_irqsave(&phba->hbalock, flags);
  488. for (i = 0; i < hbq_count; ++i) {
  489. list_for_each_entry_safe(dmabuf, next_dmabuf,
  490. &phba->hbqs[i].hbq_buffer_list, list) {
  491. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  492. list_del(&hbq_buf->dbuf.list);
  493. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  494. }
  495. phba->hbqs[i].buffer_count = 0;
  496. }
  497. /* Return all HBQ buffer that are in-fly */
  498. list_for_each_entry_safe(dmabuf, next_dmabuf,
  499. &phba->hbqbuf_in_list, list) {
  500. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  501. list_del(&hbq_buf->dbuf.list);
  502. if (hbq_buf->tag == -1) {
  503. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  504. (phba, hbq_buf);
  505. } else {
  506. hbqno = hbq_buf->tag >> 16;
  507. if (hbqno >= LPFC_MAX_HBQS)
  508. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  509. (phba, hbq_buf);
  510. else
  511. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  512. hbq_buf);
  513. }
  514. }
  515. /* Mark the HBQs not in use */
  516. phba->hbq_in_use = 0;
  517. spin_unlock_irqrestore(&phba->hbalock, flags);
  518. }
  519. static struct lpfc_hbq_entry *
  520. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  521. struct hbq_dmabuf *hbq_buf)
  522. {
  523. struct lpfc_hbq_entry *hbqe;
  524. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  525. /* Get next HBQ entry slot to use */
  526. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  527. if (hbqe) {
  528. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  529. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  530. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  531. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  532. hbqe->bde.tus.f.bdeFlags = 0;
  533. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  534. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  535. /* Sync SLIM */
  536. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  537. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  538. /* flush */
  539. readl(phba->hbq_put + hbqno);
  540. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  541. }
  542. return hbqe;
  543. }
  544. static struct lpfc_hbq_init lpfc_els_hbq = {
  545. .rn = 1,
  546. .entry_count = 200,
  547. .mask_count = 0,
  548. .profile = 0,
  549. .ring_mask = (1 << LPFC_ELS_RING),
  550. .buffer_count = 0,
  551. .init_count = 20,
  552. .add_count = 5,
  553. };
  554. static struct lpfc_hbq_init lpfc_extra_hbq = {
  555. .rn = 1,
  556. .entry_count = 200,
  557. .mask_count = 0,
  558. .profile = 0,
  559. .ring_mask = (1 << LPFC_EXTRA_RING),
  560. .buffer_count = 0,
  561. .init_count = 0,
  562. .add_count = 5,
  563. };
  564. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  565. &lpfc_els_hbq,
  566. &lpfc_extra_hbq,
  567. };
  568. static int
  569. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  570. {
  571. uint32_t i, start, end;
  572. unsigned long flags;
  573. struct hbq_dmabuf *hbq_buffer;
  574. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  575. return 0;
  576. start = phba->hbqs[hbqno].buffer_count;
  577. end = count + start;
  578. if (end > lpfc_hbq_defs[hbqno]->entry_count)
  579. end = lpfc_hbq_defs[hbqno]->entry_count;
  580. /* Check whether HBQ is still in use */
  581. spin_lock_irqsave(&phba->hbalock, flags);
  582. if (!phba->hbq_in_use)
  583. goto out;
  584. /* Populate HBQ entries */
  585. for (i = start; i < end; i++) {
  586. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  587. if (!hbq_buffer)
  588. goto err;
  589. hbq_buffer->tag = (i | (hbqno << 16));
  590. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  591. phba->hbqs[hbqno].buffer_count++;
  592. else
  593. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  594. }
  595. out:
  596. spin_unlock_irqrestore(&phba->hbalock, flags);
  597. return 0;
  598. err:
  599. spin_unlock_irqrestore(&phba->hbalock, flags);
  600. return 1;
  601. }
  602. int
  603. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  604. {
  605. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  606. lpfc_hbq_defs[qno]->add_count));
  607. }
  608. static int
  609. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  610. {
  611. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  612. lpfc_hbq_defs[qno]->init_count));
  613. }
  614. static struct hbq_dmabuf *
  615. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  616. {
  617. struct lpfc_dmabuf *d_buf;
  618. struct hbq_dmabuf *hbq_buf;
  619. uint32_t hbqno;
  620. hbqno = tag >> 16;
  621. if (hbqno >= LPFC_MAX_HBQS)
  622. return NULL;
  623. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  624. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  625. if (hbq_buf->tag == tag) {
  626. return hbq_buf;
  627. }
  628. }
  629. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  630. "1803 Bad hbq tag. Data: x%x x%x\n",
  631. tag, phba->hbqs[tag >> 16].buffer_count);
  632. return NULL;
  633. }
  634. void
  635. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  636. {
  637. uint32_t hbqno;
  638. if (hbq_buffer) {
  639. hbqno = hbq_buffer->tag >> 16;
  640. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  641. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  642. }
  643. }
  644. }
  645. static int
  646. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  647. {
  648. uint8_t ret;
  649. switch (mbxCommand) {
  650. case MBX_LOAD_SM:
  651. case MBX_READ_NV:
  652. case MBX_WRITE_NV:
  653. case MBX_WRITE_VPARMS:
  654. case MBX_RUN_BIU_DIAG:
  655. case MBX_INIT_LINK:
  656. case MBX_DOWN_LINK:
  657. case MBX_CONFIG_LINK:
  658. case MBX_CONFIG_RING:
  659. case MBX_RESET_RING:
  660. case MBX_READ_CONFIG:
  661. case MBX_READ_RCONFIG:
  662. case MBX_READ_SPARM:
  663. case MBX_READ_STATUS:
  664. case MBX_READ_RPI:
  665. case MBX_READ_XRI:
  666. case MBX_READ_REV:
  667. case MBX_READ_LNK_STAT:
  668. case MBX_REG_LOGIN:
  669. case MBX_UNREG_LOGIN:
  670. case MBX_READ_LA:
  671. case MBX_CLEAR_LA:
  672. case MBX_DUMP_MEMORY:
  673. case MBX_DUMP_CONTEXT:
  674. case MBX_RUN_DIAGS:
  675. case MBX_RESTART:
  676. case MBX_UPDATE_CFG:
  677. case MBX_DOWN_LOAD:
  678. case MBX_DEL_LD_ENTRY:
  679. case MBX_RUN_PROGRAM:
  680. case MBX_SET_MASK:
  681. case MBX_SET_VARIABLE:
  682. case MBX_UNREG_D_ID:
  683. case MBX_KILL_BOARD:
  684. case MBX_CONFIG_FARP:
  685. case MBX_BEACON:
  686. case MBX_LOAD_AREA:
  687. case MBX_RUN_BIU_DIAG64:
  688. case MBX_CONFIG_PORT:
  689. case MBX_READ_SPARM64:
  690. case MBX_READ_RPI64:
  691. case MBX_REG_LOGIN64:
  692. case MBX_READ_LA64:
  693. case MBX_WRITE_WWN:
  694. case MBX_SET_DEBUG:
  695. case MBX_LOAD_EXP_ROM:
  696. case MBX_ASYNCEVT_ENABLE:
  697. case MBX_REG_VPI:
  698. case MBX_UNREG_VPI:
  699. case MBX_HEARTBEAT:
  700. ret = mbxCommand;
  701. break;
  702. default:
  703. ret = MBX_SHUTDOWN;
  704. break;
  705. }
  706. return ret;
  707. }
  708. static void
  709. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  710. {
  711. wait_queue_head_t *pdone_q;
  712. unsigned long drvr_flag;
  713. /*
  714. * If pdone_q is empty, the driver thread gave up waiting and
  715. * continued running.
  716. */
  717. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  718. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  719. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  720. if (pdone_q)
  721. wake_up_interruptible(pdone_q);
  722. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  723. return;
  724. }
  725. void
  726. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  727. {
  728. struct lpfc_dmabuf *mp;
  729. uint16_t rpi;
  730. int rc;
  731. mp = (struct lpfc_dmabuf *) (pmb->context1);
  732. if (mp) {
  733. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  734. kfree(mp);
  735. }
  736. /*
  737. * If a REG_LOGIN succeeded after node is destroyed or node
  738. * is in re-discovery driver need to cleanup the RPI.
  739. */
  740. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  741. pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
  742. !pmb->mb.mbxStatus) {
  743. rpi = pmb->mb.un.varWords[0];
  744. lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb);
  745. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  746. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  747. if (rc != MBX_NOT_FINISHED)
  748. return;
  749. }
  750. mempool_free(pmb, phba->mbox_mem_pool);
  751. return;
  752. }
  753. int
  754. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  755. {
  756. MAILBOX_t *pmbox;
  757. LPFC_MBOXQ_t *pmb;
  758. int rc;
  759. LIST_HEAD(cmplq);
  760. phba->sli.slistat.mbox_event++;
  761. /* Get all completed mailboxe buffers into the cmplq */
  762. spin_lock_irq(&phba->hbalock);
  763. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  764. spin_unlock_irq(&phba->hbalock);
  765. /* Get a Mailbox buffer to setup mailbox commands for callback */
  766. do {
  767. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  768. if (pmb == NULL)
  769. break;
  770. pmbox = &pmb->mb;
  771. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  772. if (pmb->vport) {
  773. lpfc_debugfs_disc_trc(pmb->vport,
  774. LPFC_DISC_TRC_MBOX_VPORT,
  775. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  776. (uint32_t)pmbox->mbxCommand,
  777. pmbox->un.varWords[0],
  778. pmbox->un.varWords[1]);
  779. }
  780. else {
  781. lpfc_debugfs_disc_trc(phba->pport,
  782. LPFC_DISC_TRC_MBOX,
  783. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  784. (uint32_t)pmbox->mbxCommand,
  785. pmbox->un.varWords[0],
  786. pmbox->un.varWords[1]);
  787. }
  788. }
  789. /*
  790. * It is a fatal error if unknown mbox command completion.
  791. */
  792. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  793. MBX_SHUTDOWN) {
  794. /* Unknow mailbox command compl */
  795. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  796. "(%d):0323 Unknown Mailbox command "
  797. "%x Cmpl\n",
  798. pmb->vport ? pmb->vport->vpi : 0,
  799. pmbox->mbxCommand);
  800. phba->link_state = LPFC_HBA_ERROR;
  801. phba->work_hs = HS_FFER3;
  802. lpfc_handle_eratt(phba);
  803. continue;
  804. }
  805. if (pmbox->mbxStatus) {
  806. phba->sli.slistat.mbox_stat_err++;
  807. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  808. /* Mbox cmd cmpl error - RETRYing */
  809. lpfc_printf_log(phba, KERN_INFO,
  810. LOG_MBOX | LOG_SLI,
  811. "(%d):0305 Mbox cmd cmpl "
  812. "error - RETRYing Data: x%x "
  813. "x%x x%x x%x\n",
  814. pmb->vport ? pmb->vport->vpi :0,
  815. pmbox->mbxCommand,
  816. pmbox->mbxStatus,
  817. pmbox->un.varWords[0],
  818. pmb->vport->port_state);
  819. pmbox->mbxStatus = 0;
  820. pmbox->mbxOwner = OWN_HOST;
  821. spin_lock_irq(&phba->hbalock);
  822. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  823. spin_unlock_irq(&phba->hbalock);
  824. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  825. if (rc == MBX_SUCCESS)
  826. continue;
  827. }
  828. }
  829. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  830. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  831. "(%d):0307 Mailbox cmd x%x Cmpl x%p "
  832. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  833. pmb->vport ? pmb->vport->vpi : 0,
  834. pmbox->mbxCommand,
  835. pmb->mbox_cmpl,
  836. *((uint32_t *) pmbox),
  837. pmbox->un.varWords[0],
  838. pmbox->un.varWords[1],
  839. pmbox->un.varWords[2],
  840. pmbox->un.varWords[3],
  841. pmbox->un.varWords[4],
  842. pmbox->un.varWords[5],
  843. pmbox->un.varWords[6],
  844. pmbox->un.varWords[7]);
  845. if (pmb->mbox_cmpl)
  846. pmb->mbox_cmpl(phba,pmb);
  847. } while (1);
  848. return 0;
  849. }
  850. static struct lpfc_dmabuf *
  851. lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
  852. {
  853. struct hbq_dmabuf *hbq_entry, *new_hbq_entry;
  854. uint32_t hbqno;
  855. void *virt; /* virtual address ptr */
  856. dma_addr_t phys; /* mapped address */
  857. unsigned long flags;
  858. /* Check whether HBQ is still in use */
  859. spin_lock_irqsave(&phba->hbalock, flags);
  860. if (!phba->hbq_in_use) {
  861. spin_unlock_irqrestore(&phba->hbalock, flags);
  862. return NULL;
  863. }
  864. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  865. if (hbq_entry == NULL) {
  866. spin_unlock_irqrestore(&phba->hbalock, flags);
  867. return NULL;
  868. }
  869. list_del(&hbq_entry->dbuf.list);
  870. hbqno = tag >> 16;
  871. new_hbq_entry = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  872. if (new_hbq_entry == NULL) {
  873. list_add_tail(&hbq_entry->dbuf.list, &phba->hbqbuf_in_list);
  874. spin_unlock_irqrestore(&phba->hbalock, flags);
  875. return &hbq_entry->dbuf;
  876. }
  877. new_hbq_entry->tag = -1;
  878. phys = new_hbq_entry->dbuf.phys;
  879. virt = new_hbq_entry->dbuf.virt;
  880. new_hbq_entry->dbuf.phys = hbq_entry->dbuf.phys;
  881. new_hbq_entry->dbuf.virt = hbq_entry->dbuf.virt;
  882. hbq_entry->dbuf.phys = phys;
  883. hbq_entry->dbuf.virt = virt;
  884. lpfc_sli_free_hbq(phba, hbq_entry);
  885. list_add_tail(&new_hbq_entry->dbuf.list, &phba->hbqbuf_in_list);
  886. spin_unlock_irqrestore(&phba->hbalock, flags);
  887. return &new_hbq_entry->dbuf;
  888. }
  889. static struct lpfc_dmabuf *
  890. lpfc_sli_get_buff(struct lpfc_hba *phba,
  891. struct lpfc_sli_ring *pring,
  892. uint32_t tag)
  893. {
  894. if (tag & QUE_BUFTAG_BIT)
  895. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  896. else
  897. return lpfc_sli_replace_hbqbuff(phba, tag);
  898. }
  899. static int
  900. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  901. struct lpfc_iocbq *saveq)
  902. {
  903. IOCB_t * irsp;
  904. WORD5 * w5p;
  905. uint32_t Rctl, Type;
  906. uint32_t match, i;
  907. struct lpfc_iocbq *iocbq;
  908. struct lpfc_dmabuf *dmzbuf;
  909. match = 0;
  910. irsp = &(saveq->iocb);
  911. if (irsp->ulpStatus == IOSTAT_NEED_BUFFER)
  912. return 1;
  913. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  914. if (pring->lpfc_sli_rcv_async_status)
  915. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  916. else
  917. lpfc_printf_log(phba,
  918. KERN_WARNING,
  919. LOG_SLI,
  920. "0316 Ring %d handler: unexpected "
  921. "ASYNC_STATUS iocb received evt_code "
  922. "0x%x\n",
  923. pring->ringno,
  924. irsp->un.asyncstat.evt_code);
  925. return 1;
  926. }
  927. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  928. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  929. if (irsp->ulpBdeCount > 0) {
  930. dmzbuf = lpfc_sli_get_buff(phba, pring,
  931. irsp->un.ulpWord[3]);
  932. lpfc_in_buf_free(phba, dmzbuf);
  933. }
  934. if (irsp->ulpBdeCount > 1) {
  935. dmzbuf = lpfc_sli_get_buff(phba, pring,
  936. irsp->unsli3.sli3Words[3]);
  937. lpfc_in_buf_free(phba, dmzbuf);
  938. }
  939. if (irsp->ulpBdeCount > 2) {
  940. dmzbuf = lpfc_sli_get_buff(phba, pring,
  941. irsp->unsli3.sli3Words[7]);
  942. lpfc_in_buf_free(phba, dmzbuf);
  943. }
  944. return 1;
  945. }
  946. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  947. if (irsp->ulpBdeCount != 0) {
  948. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  949. irsp->un.ulpWord[3]);
  950. if (!saveq->context2)
  951. lpfc_printf_log(phba,
  952. KERN_ERR,
  953. LOG_SLI,
  954. "0341 Ring %d Cannot find buffer for "
  955. "an unsolicited iocb. tag 0x%x\n",
  956. pring->ringno,
  957. irsp->un.ulpWord[3]);
  958. }
  959. if (irsp->ulpBdeCount == 2) {
  960. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  961. irsp->unsli3.sli3Words[7]);
  962. if (!saveq->context3)
  963. lpfc_printf_log(phba,
  964. KERN_ERR,
  965. LOG_SLI,
  966. "0342 Ring %d Cannot find buffer for an"
  967. " unsolicited iocb. tag 0x%x\n",
  968. pring->ringno,
  969. irsp->unsli3.sli3Words[7]);
  970. }
  971. list_for_each_entry(iocbq, &saveq->list, list) {
  972. irsp = &(iocbq->iocb);
  973. if (irsp->ulpBdeCount != 0) {
  974. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  975. irsp->un.ulpWord[3]);
  976. if (!iocbq->context2)
  977. lpfc_printf_log(phba,
  978. KERN_ERR,
  979. LOG_SLI,
  980. "0343 Ring %d Cannot find "
  981. "buffer for an unsolicited iocb"
  982. ". tag 0x%x\n", pring->ringno,
  983. irsp->un.ulpWord[3]);
  984. }
  985. if (irsp->ulpBdeCount == 2) {
  986. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  987. irsp->unsli3.sli3Words[7]);
  988. if (!iocbq->context3)
  989. lpfc_printf_log(phba,
  990. KERN_ERR,
  991. LOG_SLI,
  992. "0344 Ring %d Cannot find "
  993. "buffer for an unsolicited "
  994. "iocb. tag 0x%x\n",
  995. pring->ringno,
  996. irsp->unsli3.sli3Words[7]);
  997. }
  998. }
  999. }
  1000. if (irsp->ulpBdeCount != 0 &&
  1001. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1002. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1003. int found = 0;
  1004. /* search continue save q for same XRI */
  1005. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1006. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1007. list_add_tail(&saveq->list, &iocbq->list);
  1008. found = 1;
  1009. break;
  1010. }
  1011. }
  1012. if (!found)
  1013. list_add_tail(&saveq->clist,
  1014. &pring->iocb_continue_saveq);
  1015. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1016. list_del_init(&iocbq->clist);
  1017. saveq = iocbq;
  1018. irsp = &(saveq->iocb);
  1019. } else
  1020. return 0;
  1021. }
  1022. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1023. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1024. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1025. Rctl = FC_ELS_REQ;
  1026. Type = FC_ELS_DATA;
  1027. } else {
  1028. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1029. Rctl = w5p->hcsw.Rctl;
  1030. Type = w5p->hcsw.Type;
  1031. /* Firmware Workaround */
  1032. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1033. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1034. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1035. Rctl = FC_ELS_REQ;
  1036. Type = FC_ELS_DATA;
  1037. w5p->hcsw.Rctl = Rctl;
  1038. w5p->hcsw.Type = Type;
  1039. }
  1040. }
  1041. /* unSolicited Responses */
  1042. if (pring->prt[0].profile) {
  1043. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1044. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1045. saveq);
  1046. match = 1;
  1047. } else {
  1048. /* We must search, based on rctl / type
  1049. for the right routine */
  1050. for (i = 0; i < pring->num_mask; i++) {
  1051. if ((pring->prt[i].rctl == Rctl)
  1052. && (pring->prt[i].type == Type)) {
  1053. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1054. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1055. (phba, pring, saveq);
  1056. match = 1;
  1057. break;
  1058. }
  1059. }
  1060. }
  1061. if (match == 0) {
  1062. /* Unexpected Rctl / Type received */
  1063. /* Ring <ringno> handler: unexpected
  1064. Rctl <Rctl> Type <Type> received */
  1065. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1066. "0313 Ring %d handler: unexpected Rctl x%x "
  1067. "Type x%x received\n",
  1068. pring->ringno, Rctl, Type);
  1069. }
  1070. return 1;
  1071. }
  1072. static struct lpfc_iocbq *
  1073. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1074. struct lpfc_sli_ring *pring,
  1075. struct lpfc_iocbq *prspiocb)
  1076. {
  1077. struct lpfc_iocbq *cmd_iocb = NULL;
  1078. uint16_t iotag;
  1079. iotag = prspiocb->iocb.ulpIoTag;
  1080. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1081. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1082. list_del_init(&cmd_iocb->list);
  1083. pring->txcmplq_cnt--;
  1084. return cmd_iocb;
  1085. }
  1086. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1087. "0317 iotag x%x is out off "
  1088. "range: max iotag x%x wd0 x%x\n",
  1089. iotag, phba->sli.last_iotag,
  1090. *(((uint32_t *) &prspiocb->iocb) + 7));
  1091. return NULL;
  1092. }
  1093. static int
  1094. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1095. struct lpfc_iocbq *saveq)
  1096. {
  1097. struct lpfc_iocbq *cmdiocbp;
  1098. int rc = 1;
  1099. unsigned long iflag;
  1100. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  1101. spin_lock_irqsave(&phba->hbalock, iflag);
  1102. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  1103. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1104. if (cmdiocbp) {
  1105. if (cmdiocbp->iocb_cmpl) {
  1106. /*
  1107. * Post all ELS completions to the worker thread.
  1108. * All other are passed to the completion callback.
  1109. */
  1110. if (pring->ringno == LPFC_ELS_RING) {
  1111. if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
  1112. cmdiocbp->iocb_flag &=
  1113. ~LPFC_DRIVER_ABORTED;
  1114. saveq->iocb.ulpStatus =
  1115. IOSTAT_LOCAL_REJECT;
  1116. saveq->iocb.un.ulpWord[4] =
  1117. IOERR_SLI_ABORTED;
  1118. /* Firmware could still be in progress
  1119. * of DMAing payload, so don't free data
  1120. * buffer till after a hbeat.
  1121. */
  1122. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  1123. }
  1124. }
  1125. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  1126. } else
  1127. lpfc_sli_release_iocbq(phba, cmdiocbp);
  1128. } else {
  1129. /*
  1130. * Unknown initiating command based on the response iotag.
  1131. * This could be the case on the ELS ring because of
  1132. * lpfc_els_abort().
  1133. */
  1134. if (pring->ringno != LPFC_ELS_RING) {
  1135. /*
  1136. * Ring <ringno> handler: unexpected completion IoTag
  1137. * <IoTag>
  1138. */
  1139. lpfc_printf_vlog(cmdiocbp->vport, KERN_WARNING, LOG_SLI,
  1140. "0322 Ring %d handler: "
  1141. "unexpected completion IoTag x%x "
  1142. "Data: x%x x%x x%x x%x\n",
  1143. pring->ringno,
  1144. saveq->iocb.ulpIoTag,
  1145. saveq->iocb.ulpStatus,
  1146. saveq->iocb.un.ulpWord[4],
  1147. saveq->iocb.ulpCommand,
  1148. saveq->iocb.ulpContext);
  1149. }
  1150. }
  1151. return rc;
  1152. }
  1153. static void
  1154. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1155. {
  1156. struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
  1157. &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
  1158. &phba->slim2p->mbx.us.s2.port[pring->ringno];
  1159. /*
  1160. * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
  1161. * rsp ring <portRspMax>
  1162. */
  1163. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1164. "0312 Ring %d handler: portRspPut %d "
  1165. "is bigger then rsp ring %d\n",
  1166. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  1167. pring->numRiocb);
  1168. phba->link_state = LPFC_HBA_ERROR;
  1169. /*
  1170. * All error attention handlers are posted to
  1171. * worker thread
  1172. */
  1173. phba->work_ha |= HA_ERATT;
  1174. phba->work_hs = HS_FFER3;
  1175. /* hbalock should already be held */
  1176. if (phba->work_wait)
  1177. lpfc_worker_wake_up(phba);
  1178. return;
  1179. }
  1180. void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
  1181. {
  1182. struct lpfc_sli *psli = &phba->sli;
  1183. struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
  1184. IOCB_t *irsp = NULL;
  1185. IOCB_t *entry = NULL;
  1186. struct lpfc_iocbq *cmdiocbq = NULL;
  1187. struct lpfc_iocbq rspiocbq;
  1188. struct lpfc_pgp *pgp;
  1189. uint32_t status;
  1190. uint32_t portRspPut, portRspMax;
  1191. int type;
  1192. uint32_t rsp_cmpl = 0;
  1193. uint32_t ha_copy;
  1194. unsigned long iflags;
  1195. pring->stats.iocb_event++;
  1196. pgp = (phba->sli_rev == 3) ?
  1197. &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
  1198. &phba->slim2p->mbx.us.s2.port[pring->ringno];
  1199. /*
  1200. * The next available response entry should never exceed the maximum
  1201. * entries. If it does, treat it as an adapter hardware error.
  1202. */
  1203. portRspMax = pring->numRiocb;
  1204. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1205. if (unlikely(portRspPut >= portRspMax)) {
  1206. lpfc_sli_rsp_pointers_error(phba, pring);
  1207. return;
  1208. }
  1209. rmb();
  1210. while (pring->rspidx != portRspPut) {
  1211. entry = lpfc_resp_iocb(phba, pring);
  1212. if (++pring->rspidx >= portRspMax)
  1213. pring->rspidx = 0;
  1214. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  1215. (uint32_t *) &rspiocbq.iocb,
  1216. phba->iocb_rsp_size);
  1217. irsp = &rspiocbq.iocb;
  1218. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  1219. pring->stats.iocb_rsp++;
  1220. rsp_cmpl++;
  1221. if (unlikely(irsp->ulpStatus)) {
  1222. /* Rsp ring <ringno> error: IOCB */
  1223. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1224. "0326 Rsp Ring %d error: IOCB Data: "
  1225. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1226. pring->ringno,
  1227. irsp->un.ulpWord[0],
  1228. irsp->un.ulpWord[1],
  1229. irsp->un.ulpWord[2],
  1230. irsp->un.ulpWord[3],
  1231. irsp->un.ulpWord[4],
  1232. irsp->un.ulpWord[5],
  1233. *(((uint32_t *) irsp) + 6),
  1234. *(((uint32_t *) irsp) + 7));
  1235. }
  1236. switch (type) {
  1237. case LPFC_ABORT_IOCB:
  1238. case LPFC_SOL_IOCB:
  1239. /*
  1240. * Idle exchange closed via ABTS from port. No iocb
  1241. * resources need to be recovered.
  1242. */
  1243. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  1244. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1245. "0314 IOCB cmd 0x%x "
  1246. "processed. Skipping "
  1247. "completion",
  1248. irsp->ulpCommand);
  1249. break;
  1250. }
  1251. spin_lock_irqsave(&phba->hbalock, iflags);
  1252. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  1253. &rspiocbq);
  1254. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1255. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  1256. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  1257. &rspiocbq);
  1258. }
  1259. break;
  1260. default:
  1261. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  1262. char adaptermsg[LPFC_MAX_ADPTMSG];
  1263. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  1264. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  1265. MAX_MSG_DATA);
  1266. dev_warn(&((phba->pcidev)->dev),
  1267. "lpfc%d: %s\n",
  1268. phba->brd_no, adaptermsg);
  1269. } else {
  1270. /* Unknown IOCB command */
  1271. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1272. "0321 Unknown IOCB command "
  1273. "Data: x%x, x%x x%x x%x x%x\n",
  1274. type, irsp->ulpCommand,
  1275. irsp->ulpStatus,
  1276. irsp->ulpIoTag,
  1277. irsp->ulpContext);
  1278. }
  1279. break;
  1280. }
  1281. /*
  1282. * The response IOCB has been processed. Update the ring
  1283. * pointer in SLIM. If the port response put pointer has not
  1284. * been updated, sync the pgp->rspPutInx and fetch the new port
  1285. * response put pointer.
  1286. */
  1287. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  1288. if (pring->rspidx == portRspPut)
  1289. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1290. }
  1291. ha_copy = readl(phba->HAregaddr);
  1292. ha_copy >>= (LPFC_FCP_RING * 4);
  1293. if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
  1294. spin_lock_irqsave(&phba->hbalock, iflags);
  1295. pring->stats.iocb_rsp_full++;
  1296. status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
  1297. writel(status, phba->CAregaddr);
  1298. readl(phba->CAregaddr);
  1299. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1300. }
  1301. if ((ha_copy & HA_R0CE_RSP) &&
  1302. (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  1303. spin_lock_irqsave(&phba->hbalock, iflags);
  1304. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  1305. pring->stats.iocb_cmd_empty++;
  1306. /* Force update of the local copy of cmdGetInx */
  1307. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1308. lpfc_sli_resume_iocb(phba, pring);
  1309. if ((pring->lpfc_sli_cmd_available))
  1310. (pring->lpfc_sli_cmd_available) (phba, pring);
  1311. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1312. }
  1313. return;
  1314. }
  1315. /*
  1316. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  1317. * to check it explicitly.
  1318. */
  1319. static int
  1320. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  1321. struct lpfc_sli_ring *pring, uint32_t mask)
  1322. {
  1323. struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
  1324. &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
  1325. &phba->slim2p->mbx.us.s2.port[pring->ringno];
  1326. IOCB_t *irsp = NULL;
  1327. IOCB_t *entry = NULL;
  1328. struct lpfc_iocbq *cmdiocbq = NULL;
  1329. struct lpfc_iocbq rspiocbq;
  1330. uint32_t status;
  1331. uint32_t portRspPut, portRspMax;
  1332. int rc = 1;
  1333. lpfc_iocb_type type;
  1334. unsigned long iflag;
  1335. uint32_t rsp_cmpl = 0;
  1336. spin_lock_irqsave(&phba->hbalock, iflag);
  1337. pring->stats.iocb_event++;
  1338. /*
  1339. * The next available response entry should never exceed the maximum
  1340. * entries. If it does, treat it as an adapter hardware error.
  1341. */
  1342. portRspMax = pring->numRiocb;
  1343. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1344. if (unlikely(portRspPut >= portRspMax)) {
  1345. lpfc_sli_rsp_pointers_error(phba, pring);
  1346. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1347. return 1;
  1348. }
  1349. rmb();
  1350. while (pring->rspidx != portRspPut) {
  1351. /*
  1352. * Fetch an entry off the ring and copy it into a local data
  1353. * structure. The copy involves a byte-swap since the
  1354. * network byte order and pci byte orders are different.
  1355. */
  1356. entry = lpfc_resp_iocb(phba, pring);
  1357. phba->last_completion_time = jiffies;
  1358. if (++pring->rspidx >= portRspMax)
  1359. pring->rspidx = 0;
  1360. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  1361. (uint32_t *) &rspiocbq.iocb,
  1362. phba->iocb_rsp_size);
  1363. INIT_LIST_HEAD(&(rspiocbq.list));
  1364. irsp = &rspiocbq.iocb;
  1365. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  1366. pring->stats.iocb_rsp++;
  1367. rsp_cmpl++;
  1368. if (unlikely(irsp->ulpStatus)) {
  1369. /*
  1370. * If resource errors reported from HBA, reduce
  1371. * queuedepths of the SCSI device.
  1372. */
  1373. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  1374. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  1375. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1376. lpfc_adjust_queue_depth(phba);
  1377. spin_lock_irqsave(&phba->hbalock, iflag);
  1378. }
  1379. /* Rsp ring <ringno> error: IOCB */
  1380. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1381. "0336 Rsp Ring %d error: IOCB Data: "
  1382. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1383. pring->ringno,
  1384. irsp->un.ulpWord[0],
  1385. irsp->un.ulpWord[1],
  1386. irsp->un.ulpWord[2],
  1387. irsp->un.ulpWord[3],
  1388. irsp->un.ulpWord[4],
  1389. irsp->un.ulpWord[5],
  1390. *(((uint32_t *) irsp) + 6),
  1391. *(((uint32_t *) irsp) + 7));
  1392. }
  1393. switch (type) {
  1394. case LPFC_ABORT_IOCB:
  1395. case LPFC_SOL_IOCB:
  1396. /*
  1397. * Idle exchange closed via ABTS from port. No iocb
  1398. * resources need to be recovered.
  1399. */
  1400. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  1401. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1402. "0333 IOCB cmd 0x%x"
  1403. " processed. Skipping"
  1404. " completion\n",
  1405. irsp->ulpCommand);
  1406. break;
  1407. }
  1408. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  1409. &rspiocbq);
  1410. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  1411. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  1412. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  1413. &rspiocbq);
  1414. } else {
  1415. spin_unlock_irqrestore(&phba->hbalock,
  1416. iflag);
  1417. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  1418. &rspiocbq);
  1419. spin_lock_irqsave(&phba->hbalock,
  1420. iflag);
  1421. }
  1422. }
  1423. break;
  1424. case LPFC_UNSOL_IOCB:
  1425. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1426. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  1427. spin_lock_irqsave(&phba->hbalock, iflag);
  1428. break;
  1429. default:
  1430. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  1431. char adaptermsg[LPFC_MAX_ADPTMSG];
  1432. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  1433. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  1434. MAX_MSG_DATA);
  1435. dev_warn(&((phba->pcidev)->dev),
  1436. "lpfc%d: %s\n",
  1437. phba->brd_no, adaptermsg);
  1438. } else {
  1439. /* Unknown IOCB command */
  1440. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1441. "0334 Unknown IOCB command "
  1442. "Data: x%x, x%x x%x x%x x%x\n",
  1443. type, irsp->ulpCommand,
  1444. irsp->ulpStatus,
  1445. irsp->ulpIoTag,
  1446. irsp->ulpContext);
  1447. }
  1448. break;
  1449. }
  1450. /*
  1451. * The response IOCB has been processed. Update the ring
  1452. * pointer in SLIM. If the port response put pointer has not
  1453. * been updated, sync the pgp->rspPutInx and fetch the new port
  1454. * response put pointer.
  1455. */
  1456. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  1457. if (pring->rspidx == portRspPut)
  1458. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1459. }
  1460. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  1461. pring->stats.iocb_rsp_full++;
  1462. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  1463. writel(status, phba->CAregaddr);
  1464. readl(phba->CAregaddr);
  1465. }
  1466. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  1467. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  1468. pring->stats.iocb_cmd_empty++;
  1469. /* Force update of the local copy of cmdGetInx */
  1470. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1471. lpfc_sli_resume_iocb(phba, pring);
  1472. if ((pring->lpfc_sli_cmd_available))
  1473. (pring->lpfc_sli_cmd_available) (phba, pring);
  1474. }
  1475. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1476. return rc;
  1477. }
  1478. int
  1479. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  1480. struct lpfc_sli_ring *pring, uint32_t mask)
  1481. {
  1482. struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
  1483. &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
  1484. &phba->slim2p->mbx.us.s2.port[pring->ringno];
  1485. IOCB_t *entry;
  1486. IOCB_t *irsp = NULL;
  1487. struct lpfc_iocbq *rspiocbp = NULL;
  1488. struct lpfc_iocbq *next_iocb;
  1489. struct lpfc_iocbq *cmdiocbp;
  1490. struct lpfc_iocbq *saveq;
  1491. uint8_t iocb_cmd_type;
  1492. lpfc_iocb_type type;
  1493. uint32_t status, free_saveq;
  1494. uint32_t portRspPut, portRspMax;
  1495. int rc = 1;
  1496. unsigned long iflag;
  1497. spin_lock_irqsave(&phba->hbalock, iflag);
  1498. pring->stats.iocb_event++;
  1499. /*
  1500. * The next available response entry should never exceed the maximum
  1501. * entries. If it does, treat it as an adapter hardware error.
  1502. */
  1503. portRspMax = pring->numRiocb;
  1504. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1505. if (portRspPut >= portRspMax) {
  1506. /*
  1507. * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
  1508. * rsp ring <portRspMax>
  1509. */
  1510. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1511. "0303 Ring %d handler: portRspPut %d "
  1512. "is bigger then rsp ring %d\n",
  1513. pring->ringno, portRspPut, portRspMax);
  1514. phba->link_state = LPFC_HBA_ERROR;
  1515. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1516. phba->work_hs = HS_FFER3;
  1517. lpfc_handle_eratt(phba);
  1518. return 1;
  1519. }
  1520. rmb();
  1521. while (pring->rspidx != portRspPut) {
  1522. /*
  1523. * Build a completion list and call the appropriate handler.
  1524. * The process is to get the next available response iocb, get
  1525. * a free iocb from the list, copy the response data into the
  1526. * free iocb, insert to the continuation list, and update the
  1527. * next response index to slim. This process makes response
  1528. * iocb's in the ring available to DMA as fast as possible but
  1529. * pays a penalty for a copy operation. Since the iocb is
  1530. * only 32 bytes, this penalty is considered small relative to
  1531. * the PCI reads for register values and a slim write. When
  1532. * the ulpLe field is set, the entire Command has been
  1533. * received.
  1534. */
  1535. entry = lpfc_resp_iocb(phba, pring);
  1536. phba->last_completion_time = jiffies;
  1537. rspiocbp = __lpfc_sli_get_iocbq(phba);
  1538. if (rspiocbp == NULL) {
  1539. printk(KERN_ERR "%s: out of buffers! Failing "
  1540. "completion.\n", __FUNCTION__);
  1541. break;
  1542. }
  1543. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  1544. phba->iocb_rsp_size);
  1545. irsp = &rspiocbp->iocb;
  1546. if (++pring->rspidx >= portRspMax)
  1547. pring->rspidx = 0;
  1548. if (pring->ringno == LPFC_ELS_RING) {
  1549. lpfc_debugfs_slow_ring_trc(phba,
  1550. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1551. *(((uint32_t *) irsp) + 4),
  1552. *(((uint32_t *) irsp) + 6),
  1553. *(((uint32_t *) irsp) + 7));
  1554. }
  1555. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  1556. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  1557. pring->iocb_continueq_cnt++;
  1558. if (irsp->ulpLe) {
  1559. /*
  1560. * By default, the driver expects to free all resources
  1561. * associated with this iocb completion.
  1562. */
  1563. free_saveq = 1;
  1564. saveq = list_get_first(&pring->iocb_continueq,
  1565. struct lpfc_iocbq, list);
  1566. irsp = &(saveq->iocb);
  1567. list_del_init(&pring->iocb_continueq);
  1568. pring->iocb_continueq_cnt = 0;
  1569. pring->stats.iocb_rsp++;
  1570. /*
  1571. * If resource errors reported from HBA, reduce
  1572. * queuedepths of the SCSI device.
  1573. */
  1574. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  1575. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  1576. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1577. lpfc_adjust_queue_depth(phba);
  1578. spin_lock_irqsave(&phba->hbalock, iflag);
  1579. }
  1580. if (irsp->ulpStatus) {
  1581. /* Rsp ring <ringno> error: IOCB */
  1582. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1583. "0328 Rsp Ring %d error: "
  1584. "IOCB Data: "
  1585. "x%x x%x x%x x%x "
  1586. "x%x x%x x%x x%x "
  1587. "x%x x%x x%x x%x "
  1588. "x%x x%x x%x x%x\n",
  1589. pring->ringno,
  1590. irsp->un.ulpWord[0],
  1591. irsp->un.ulpWord[1],
  1592. irsp->un.ulpWord[2],
  1593. irsp->un.ulpWord[3],
  1594. irsp->un.ulpWord[4],
  1595. irsp->un.ulpWord[5],
  1596. *(((uint32_t *) irsp) + 6),
  1597. *(((uint32_t *) irsp) + 7),
  1598. *(((uint32_t *) irsp) + 8),
  1599. *(((uint32_t *) irsp) + 9),
  1600. *(((uint32_t *) irsp) + 10),
  1601. *(((uint32_t *) irsp) + 11),
  1602. *(((uint32_t *) irsp) + 12),
  1603. *(((uint32_t *) irsp) + 13),
  1604. *(((uint32_t *) irsp) + 14),
  1605. *(((uint32_t *) irsp) + 15));
  1606. }
  1607. /*
  1608. * Fetch the IOCB command type and call the correct
  1609. * completion routine. Solicited and Unsolicited
  1610. * IOCBs on the ELS ring get freed back to the
  1611. * lpfc_iocb_list by the discovery kernel thread.
  1612. */
  1613. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  1614. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  1615. if (type == LPFC_SOL_IOCB) {
  1616. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1617. rc = lpfc_sli_process_sol_iocb(phba, pring,
  1618. saveq);
  1619. spin_lock_irqsave(&phba->hbalock, iflag);
  1620. } else if (type == LPFC_UNSOL_IOCB) {
  1621. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1622. rc = lpfc_sli_process_unsol_iocb(phba, pring,
  1623. saveq);
  1624. spin_lock_irqsave(&phba->hbalock, iflag);
  1625. if (!rc)
  1626. free_saveq = 0;
  1627. } else if (type == LPFC_ABORT_IOCB) {
  1628. if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
  1629. ((cmdiocbp =
  1630. lpfc_sli_iocbq_lookup(phba, pring,
  1631. saveq)))) {
  1632. /* Call the specified completion
  1633. routine */
  1634. if (cmdiocbp->iocb_cmpl) {
  1635. spin_unlock_irqrestore(
  1636. &phba->hbalock,
  1637. iflag);
  1638. (cmdiocbp->iocb_cmpl) (phba,
  1639. cmdiocbp, saveq);
  1640. spin_lock_irqsave(
  1641. &phba->hbalock,
  1642. iflag);
  1643. } else
  1644. __lpfc_sli_release_iocbq(phba,
  1645. cmdiocbp);
  1646. }
  1647. } else if (type == LPFC_UNKNOWN_IOCB) {
  1648. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  1649. char adaptermsg[LPFC_MAX_ADPTMSG];
  1650. memset(adaptermsg, 0,
  1651. LPFC_MAX_ADPTMSG);
  1652. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  1653. MAX_MSG_DATA);
  1654. dev_warn(&((phba->pcidev)->dev),
  1655. "lpfc%d: %s\n",
  1656. phba->brd_no, adaptermsg);
  1657. } else {
  1658. /* Unknown IOCB command */
  1659. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1660. "0335 Unknown IOCB "
  1661. "command Data: x%x "
  1662. "x%x x%x x%x\n",
  1663. irsp->ulpCommand,
  1664. irsp->ulpStatus,
  1665. irsp->ulpIoTag,
  1666. irsp->ulpContext);
  1667. }
  1668. }
  1669. if (free_saveq) {
  1670. list_for_each_entry_safe(rspiocbp, next_iocb,
  1671. &saveq->list, list) {
  1672. list_del(&rspiocbp->list);
  1673. __lpfc_sli_release_iocbq(phba,
  1674. rspiocbp);
  1675. }
  1676. __lpfc_sli_release_iocbq(phba, saveq);
  1677. }
  1678. rspiocbp = NULL;
  1679. }
  1680. /*
  1681. * If the port response put pointer has not been updated, sync
  1682. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  1683. * response put pointer.
  1684. */
  1685. if (pring->rspidx == portRspPut) {
  1686. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1687. }
  1688. } /* while (pring->rspidx != portRspPut) */
  1689. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  1690. /* At least one response entry has been freed */
  1691. pring->stats.iocb_rsp_full++;
  1692. /* SET RxRE_RSP in Chip Att register */
  1693. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  1694. writel(status, phba->CAregaddr);
  1695. readl(phba->CAregaddr); /* flush */
  1696. }
  1697. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  1698. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  1699. pring->stats.iocb_cmd_empty++;
  1700. /* Force update of the local copy of cmdGetInx */
  1701. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1702. lpfc_sli_resume_iocb(phba, pring);
  1703. if ((pring->lpfc_sli_cmd_available))
  1704. (pring->lpfc_sli_cmd_available) (phba, pring);
  1705. }
  1706. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1707. return rc;
  1708. }
  1709. void
  1710. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1711. {
  1712. LIST_HEAD(completions);
  1713. struct lpfc_iocbq *iocb, *next_iocb;
  1714. IOCB_t *cmd = NULL;
  1715. if (pring->ringno == LPFC_ELS_RING) {
  1716. lpfc_fabric_abort_hba(phba);
  1717. }
  1718. /* Error everything on txq and txcmplq
  1719. * First do the txq.
  1720. */
  1721. spin_lock_irq(&phba->hbalock);
  1722. list_splice_init(&pring->txq, &completions);
  1723. pring->txq_cnt = 0;
  1724. /* Next issue ABTS for everything on the txcmplq */
  1725. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  1726. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  1727. spin_unlock_irq(&phba->hbalock);
  1728. while (!list_empty(&completions)) {
  1729. iocb = list_get_first(&completions, struct lpfc_iocbq, list);
  1730. cmd = &iocb->iocb;
  1731. list_del_init(&iocb->list);
  1732. if (!iocb->iocb_cmpl)
  1733. lpfc_sli_release_iocbq(phba, iocb);
  1734. else {
  1735. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  1736. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  1737. (iocb->iocb_cmpl) (phba, iocb, iocb);
  1738. }
  1739. }
  1740. }
  1741. int
  1742. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  1743. {
  1744. uint32_t status;
  1745. int i = 0;
  1746. int retval = 0;
  1747. /* Read the HBA Host Status Register */
  1748. status = readl(phba->HSregaddr);
  1749. /*
  1750. * Check status register every 100ms for 5 retries, then every
  1751. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  1752. * every 2.5 sec for 4.
  1753. * Break our of the loop if errors occurred during init.
  1754. */
  1755. while (((status & mask) != mask) &&
  1756. !(status & HS_FFERM) &&
  1757. i++ < 20) {
  1758. if (i <= 5)
  1759. msleep(10);
  1760. else if (i <= 10)
  1761. msleep(500);
  1762. else
  1763. msleep(2500);
  1764. if (i == 15) {
  1765. /* Do post */
  1766. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  1767. lpfc_sli_brdrestart(phba);
  1768. }
  1769. /* Read the HBA Host Status Register */
  1770. status = readl(phba->HSregaddr);
  1771. }
  1772. /* Check to see if any errors occurred during init */
  1773. if ((status & HS_FFERM) || (i >= 20)) {
  1774. phba->link_state = LPFC_HBA_ERROR;
  1775. retval = 1;
  1776. }
  1777. return retval;
  1778. }
  1779. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  1780. void lpfc_reset_barrier(struct lpfc_hba *phba)
  1781. {
  1782. uint32_t __iomem *resp_buf;
  1783. uint32_t __iomem *mbox_buf;
  1784. volatile uint32_t mbox;
  1785. uint32_t hc_copy;
  1786. int i;
  1787. uint8_t hdrtype;
  1788. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  1789. if (hdrtype != 0x80 ||
  1790. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  1791. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  1792. return;
  1793. /*
  1794. * Tell the other part of the chip to suspend temporarily all
  1795. * its DMA activity.
  1796. */
  1797. resp_buf = phba->MBslimaddr;
  1798. /* Disable the error attention */
  1799. hc_copy = readl(phba->HCregaddr);
  1800. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  1801. readl(phba->HCregaddr); /* flush */
  1802. phba->link_flag |= LS_IGNORE_ERATT;
  1803. if (readl(phba->HAregaddr) & HA_ERATT) {
  1804. /* Clear Chip error bit */
  1805. writel(HA_ERATT, phba->HAregaddr);
  1806. phba->pport->stopped = 1;
  1807. }
  1808. mbox = 0;
  1809. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  1810. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  1811. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  1812. mbox_buf = phba->MBslimaddr;
  1813. writel(mbox, mbox_buf);
  1814. for (i = 0;
  1815. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  1816. mdelay(1);
  1817. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  1818. if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
  1819. phba->pport->stopped)
  1820. goto restore_hc;
  1821. else
  1822. goto clear_errat;
  1823. }
  1824. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  1825. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  1826. mdelay(1);
  1827. clear_errat:
  1828. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  1829. mdelay(1);
  1830. if (readl(phba->HAregaddr) & HA_ERATT) {
  1831. writel(HA_ERATT, phba->HAregaddr);
  1832. phba->pport->stopped = 1;
  1833. }
  1834. restore_hc:
  1835. phba->link_flag &= ~LS_IGNORE_ERATT;
  1836. writel(hc_copy, phba->HCregaddr);
  1837. readl(phba->HCregaddr); /* flush */
  1838. }
  1839. int
  1840. lpfc_sli_brdkill(struct lpfc_hba *phba)
  1841. {
  1842. struct lpfc_sli *psli;
  1843. LPFC_MBOXQ_t *pmb;
  1844. uint32_t status;
  1845. uint32_t ha_copy;
  1846. int retval;
  1847. int i = 0;
  1848. psli = &phba->sli;
  1849. /* Kill HBA */
  1850. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1851. "0329 Kill HBA Data: x%x x%x\n",
  1852. phba->pport->port_state, psli->sli_flag);
  1853. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1854. if (!pmb)
  1855. return 1;
  1856. /* Disable the error attention */
  1857. spin_lock_irq(&phba->hbalock);
  1858. status = readl(phba->HCregaddr);
  1859. status &= ~HC_ERINT_ENA;
  1860. writel(status, phba->HCregaddr);
  1861. readl(phba->HCregaddr); /* flush */
  1862. phba->link_flag |= LS_IGNORE_ERATT;
  1863. spin_unlock_irq(&phba->hbalock);
  1864. lpfc_kill_board(phba, pmb);
  1865. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1866. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1867. if (retval != MBX_SUCCESS) {
  1868. if (retval != MBX_BUSY)
  1869. mempool_free(pmb, phba->mbox_mem_pool);
  1870. spin_lock_irq(&phba->hbalock);
  1871. phba->link_flag &= ~LS_IGNORE_ERATT;
  1872. spin_unlock_irq(&phba->hbalock);
  1873. return 1;
  1874. }
  1875. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  1876. mempool_free(pmb, phba->mbox_mem_pool);
  1877. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  1878. * attention every 100ms for 3 seconds. If we don't get ERATT after
  1879. * 3 seconds we still set HBA_ERROR state because the status of the
  1880. * board is now undefined.
  1881. */
  1882. ha_copy = readl(phba->HAregaddr);
  1883. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  1884. mdelay(100);
  1885. ha_copy = readl(phba->HAregaddr);
  1886. }
  1887. del_timer_sync(&psli->mbox_tmo);
  1888. if (ha_copy & HA_ERATT) {
  1889. writel(HA_ERATT, phba->HAregaddr);
  1890. phba->pport->stopped = 1;
  1891. }
  1892. spin_lock_irq(&phba->hbalock);
  1893. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  1894. phba->link_flag &= ~LS_IGNORE_ERATT;
  1895. spin_unlock_irq(&phba->hbalock);
  1896. psli->mbox_active = NULL;
  1897. lpfc_hba_down_post(phba);
  1898. phba->link_state = LPFC_HBA_ERROR;
  1899. return ha_copy & HA_ERATT ? 0 : 1;
  1900. }
  1901. int
  1902. lpfc_sli_brdreset(struct lpfc_hba *phba)
  1903. {
  1904. struct lpfc_sli *psli;
  1905. struct lpfc_sli_ring *pring;
  1906. uint16_t cfg_value;
  1907. int i;
  1908. psli = &phba->sli;
  1909. /* Reset HBA */
  1910. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1911. "0325 Reset HBA Data: x%x x%x\n",
  1912. phba->pport->port_state, psli->sli_flag);
  1913. /* perform board reset */
  1914. phba->fc_eventTag = 0;
  1915. phba->pport->fc_myDID = 0;
  1916. phba->pport->fc_prevDID = 0;
  1917. /* Turn off parity checking and serr during the physical reset */
  1918. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  1919. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  1920. (cfg_value &
  1921. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  1922. psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
  1923. /* Now toggle INITFF bit in the Host Control Register */
  1924. writel(HC_INITFF, phba->HCregaddr);
  1925. mdelay(1);
  1926. readl(phba->HCregaddr); /* flush */
  1927. writel(0, phba->HCregaddr);
  1928. readl(phba->HCregaddr); /* flush */
  1929. /* Restore PCI cmd register */
  1930. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  1931. /* Initialize relevant SLI info */
  1932. for (i = 0; i < psli->num_rings; i++) {
  1933. pring = &psli->ring[i];
  1934. pring->flag = 0;
  1935. pring->rspidx = 0;
  1936. pring->next_cmdidx = 0;
  1937. pring->local_getidx = 0;
  1938. pring->cmdidx = 0;
  1939. pring->missbufcnt = 0;
  1940. }
  1941. phba->link_state = LPFC_WARM_START;
  1942. return 0;
  1943. }
  1944. int
  1945. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  1946. {
  1947. MAILBOX_t *mb;
  1948. struct lpfc_sli *psli;
  1949. uint16_t skip_post;
  1950. volatile uint32_t word0;
  1951. void __iomem *to_slim;
  1952. spin_lock_irq(&phba->hbalock);
  1953. psli = &phba->sli;
  1954. /* Restart HBA */
  1955. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1956. "0337 Restart HBA Data: x%x x%x\n",
  1957. phba->pport->port_state, psli->sli_flag);
  1958. word0 = 0;
  1959. mb = (MAILBOX_t *) &word0;
  1960. mb->mbxCommand = MBX_RESTART;
  1961. mb->mbxHc = 1;
  1962. lpfc_reset_barrier(phba);
  1963. to_slim = phba->MBslimaddr;
  1964. writel(*(uint32_t *) mb, to_slim);
  1965. readl(to_slim); /* flush */
  1966. /* Only skip post after fc_ffinit is completed */
  1967. if (phba->pport->port_state) {
  1968. skip_post = 1;
  1969. word0 = 1; /* This is really setting up word1 */
  1970. } else {
  1971. skip_post = 0;
  1972. word0 = 0; /* This is really setting up word1 */
  1973. }
  1974. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  1975. writel(*(uint32_t *) mb, to_slim);
  1976. readl(to_slim); /* flush */
  1977. lpfc_sli_brdreset(phba);
  1978. phba->pport->stopped = 0;
  1979. phba->link_state = LPFC_INIT_START;
  1980. spin_unlock_irq(&phba->hbalock);
  1981. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  1982. psli->stats_start = get_seconds();
  1983. if (skip_post)
  1984. mdelay(100);
  1985. else
  1986. mdelay(2000);
  1987. lpfc_hba_down_post(phba);
  1988. return 0;
  1989. }
  1990. static int
  1991. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  1992. {
  1993. uint32_t status, i = 0;
  1994. /* Read the HBA Host Status Register */
  1995. status = readl(phba->HSregaddr);
  1996. /* Check status register to see what current state is */
  1997. i = 0;
  1998. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  1999. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  2000. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  2001. * 4.
  2002. */
  2003. if (i++ >= 20) {
  2004. /* Adapter failed to init, timeout, status reg
  2005. <status> */
  2006. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2007. "0436 Adapter failed to init, "
  2008. "timeout, status reg x%x, "
  2009. "FW Data: A8 x%x AC x%x\n", status,
  2010. readl(phba->MBslimaddr + 0xa8),
  2011. readl(phba->MBslimaddr + 0xac));
  2012. phba->link_state = LPFC_HBA_ERROR;
  2013. return -ETIMEDOUT;
  2014. }
  2015. /* Check to see if any errors occurred during init */
  2016. if (status & HS_FFERM) {
  2017. /* ERROR: During chipset initialization */
  2018. /* Adapter failed to init, chipset, status reg
  2019. <status> */
  2020. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2021. "0437 Adapter failed to init, "
  2022. "chipset, status reg x%x, "
  2023. "FW Data: A8 x%x AC x%x\n", status,
  2024. readl(phba->MBslimaddr + 0xa8),
  2025. readl(phba->MBslimaddr + 0xac));
  2026. phba->link_state = LPFC_HBA_ERROR;
  2027. return -EIO;
  2028. }
  2029. if (i <= 5) {
  2030. msleep(10);
  2031. } else if (i <= 10) {
  2032. msleep(500);
  2033. } else {
  2034. msleep(2500);
  2035. }
  2036. if (i == 15) {
  2037. /* Do post */
  2038. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2039. lpfc_sli_brdrestart(phba);
  2040. }
  2041. /* Read the HBA Host Status Register */
  2042. status = readl(phba->HSregaddr);
  2043. }
  2044. /* Check to see if any errors occurred during init */
  2045. if (status & HS_FFERM) {
  2046. /* ERROR: During chipset initialization */
  2047. /* Adapter failed to init, chipset, status reg <status> */
  2048. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2049. "0438 Adapter failed to init, chipset, "
  2050. "status reg x%x, "
  2051. "FW Data: A8 x%x AC x%x\n", status,
  2052. readl(phba->MBslimaddr + 0xa8),
  2053. readl(phba->MBslimaddr + 0xac));
  2054. phba->link_state = LPFC_HBA_ERROR;
  2055. return -EIO;
  2056. }
  2057. /* Clear all interrupt enable conditions */
  2058. writel(0, phba->HCregaddr);
  2059. readl(phba->HCregaddr); /* flush */
  2060. /* setup host attn register */
  2061. writel(0xffffffff, phba->HAregaddr);
  2062. readl(phba->HAregaddr); /* flush */
  2063. return 0;
  2064. }
  2065. int
  2066. lpfc_sli_hbq_count(void)
  2067. {
  2068. return ARRAY_SIZE(lpfc_hbq_defs);
  2069. }
  2070. static int
  2071. lpfc_sli_hbq_entry_count(void)
  2072. {
  2073. int hbq_count = lpfc_sli_hbq_count();
  2074. int count = 0;
  2075. int i;
  2076. for (i = 0; i < hbq_count; ++i)
  2077. count += lpfc_hbq_defs[i]->entry_count;
  2078. return count;
  2079. }
  2080. int
  2081. lpfc_sli_hbq_size(void)
  2082. {
  2083. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  2084. }
  2085. static int
  2086. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  2087. {
  2088. int hbq_count = lpfc_sli_hbq_count();
  2089. LPFC_MBOXQ_t *pmb;
  2090. MAILBOX_t *pmbox;
  2091. uint32_t hbqno;
  2092. uint32_t hbq_entry_index;
  2093. /* Get a Mailbox buffer to setup mailbox
  2094. * commands for HBA initialization
  2095. */
  2096. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2097. if (!pmb)
  2098. return -ENOMEM;
  2099. pmbox = &pmb->mb;
  2100. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  2101. phba->link_state = LPFC_INIT_MBX_CMDS;
  2102. phba->hbq_in_use = 1;
  2103. hbq_entry_index = 0;
  2104. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  2105. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  2106. phba->hbqs[hbqno].hbqPutIdx = 0;
  2107. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  2108. phba->hbqs[hbqno].entry_count =
  2109. lpfc_hbq_defs[hbqno]->entry_count;
  2110. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  2111. hbq_entry_index, pmb);
  2112. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  2113. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  2114. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  2115. mbxStatus <status>, ring <num> */
  2116. lpfc_printf_log(phba, KERN_ERR,
  2117. LOG_SLI | LOG_VPORT,
  2118. "1805 Adapter failed to init. "
  2119. "Data: x%x x%x x%x\n",
  2120. pmbox->mbxCommand,
  2121. pmbox->mbxStatus, hbqno);
  2122. phba->link_state = LPFC_HBA_ERROR;
  2123. mempool_free(pmb, phba->mbox_mem_pool);
  2124. return ENXIO;
  2125. }
  2126. }
  2127. phba->hbq_count = hbq_count;
  2128. mempool_free(pmb, phba->mbox_mem_pool);
  2129. /* Initially populate or replenish the HBQs */
  2130. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  2131. if (lpfc_sli_hbqbuf_init_hbqs(phba, hbqno))
  2132. return -ENOMEM;
  2133. }
  2134. return 0;
  2135. }
  2136. static int
  2137. lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
  2138. {
  2139. LPFC_MBOXQ_t *pmb;
  2140. uint32_t resetcount = 0, rc = 0, done = 0;
  2141. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2142. if (!pmb) {
  2143. phba->link_state = LPFC_HBA_ERROR;
  2144. return -ENOMEM;
  2145. }
  2146. phba->sli_rev = sli_mode;
  2147. while (resetcount < 2 && !done) {
  2148. spin_lock_irq(&phba->hbalock);
  2149. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  2150. spin_unlock_irq(&phba->hbalock);
  2151. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2152. lpfc_sli_brdrestart(phba);
  2153. msleep(2500);
  2154. rc = lpfc_sli_chipset_init(phba);
  2155. if (rc)
  2156. break;
  2157. spin_lock_irq(&phba->hbalock);
  2158. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2159. spin_unlock_irq(&phba->hbalock);
  2160. resetcount++;
  2161. /* Call pre CONFIG_PORT mailbox command initialization. A
  2162. * value of 0 means the call was successful. Any other
  2163. * nonzero value is a failure, but if ERESTART is returned,
  2164. * the driver may reset the HBA and try again.
  2165. */
  2166. rc = lpfc_config_port_prep(phba);
  2167. if (rc == -ERESTART) {
  2168. phba->link_state = LPFC_LINK_UNKNOWN;
  2169. continue;
  2170. } else if (rc) {
  2171. break;
  2172. }
  2173. phba->link_state = LPFC_INIT_MBX_CMDS;
  2174. lpfc_config_port(phba, pmb);
  2175. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  2176. if (rc != MBX_SUCCESS) {
  2177. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2178. "0442 Adapter failed to init, mbxCmd x%x "
  2179. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  2180. pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0);
  2181. spin_lock_irq(&phba->hbalock);
  2182. phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
  2183. spin_unlock_irq(&phba->hbalock);
  2184. rc = -ENXIO;
  2185. } else {
  2186. done = 1;
  2187. phba->max_vpi = (phba->max_vpi &&
  2188. pmb->mb.un.varCfgPort.gmv) != 0
  2189. ? pmb->mb.un.varCfgPort.max_vpi
  2190. : 0;
  2191. }
  2192. }
  2193. if (!done) {
  2194. rc = -EINVAL;
  2195. goto do_prep_failed;
  2196. }
  2197. if ((pmb->mb.un.varCfgPort.sli_mode == 3) &&
  2198. (!pmb->mb.un.varCfgPort.cMA)) {
  2199. rc = -ENXIO;
  2200. }
  2201. do_prep_failed:
  2202. mempool_free(pmb, phba->mbox_mem_pool);
  2203. return rc;
  2204. }
  2205. int
  2206. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  2207. {
  2208. uint32_t rc;
  2209. int mode = 3;
  2210. switch (lpfc_sli_mode) {
  2211. case 2:
  2212. if (phba->cfg_enable_npiv) {
  2213. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  2214. "1824 NPIV enabled: Override lpfc_sli_mode "
  2215. "parameter (%d) to auto (0).\n",
  2216. lpfc_sli_mode);
  2217. break;
  2218. }
  2219. mode = 2;
  2220. break;
  2221. case 0:
  2222. case 3:
  2223. break;
  2224. default:
  2225. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  2226. "1819 Unrecognized lpfc_sli_mode "
  2227. "parameter: %d.\n", lpfc_sli_mode);
  2228. break;
  2229. }
  2230. rc = lpfc_do_config_port(phba, mode);
  2231. if (rc && lpfc_sli_mode == 3)
  2232. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  2233. "1820 Unable to select SLI-3. "
  2234. "Not supported by adapter.\n");
  2235. if (rc && mode != 2)
  2236. rc = lpfc_do_config_port(phba, 2);
  2237. if (rc)
  2238. goto lpfc_sli_hba_setup_error;
  2239. if (phba->sli_rev == 3) {
  2240. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  2241. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  2242. phba->sli3_options |= LPFC_SLI3_ENABLED;
  2243. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  2244. } else {
  2245. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  2246. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  2247. phba->sli3_options = 0;
  2248. }
  2249. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2250. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  2251. phba->sli_rev, phba->max_vpi);
  2252. rc = lpfc_sli_ring_map(phba);
  2253. if (rc)
  2254. goto lpfc_sli_hba_setup_error;
  2255. /* Init HBQs */
  2256. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2257. rc = lpfc_sli_hbq_setup(phba);
  2258. if (rc)
  2259. goto lpfc_sli_hba_setup_error;
  2260. }
  2261. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  2262. rc = lpfc_config_port_post(phba);
  2263. if (rc)
  2264. goto lpfc_sli_hba_setup_error;
  2265. return rc;
  2266. lpfc_sli_hba_setup_error:
  2267. phba->link_state = LPFC_HBA_ERROR;
  2268. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2269. "0445 Firmware initialization failed\n");
  2270. return rc;
  2271. }
  2272. /*! lpfc_mbox_timeout
  2273. *
  2274. * \pre
  2275. * \post
  2276. * \param hba Pointer to per struct lpfc_hba structure
  2277. * \param l1 Pointer to the driver's mailbox queue.
  2278. * \return
  2279. * void
  2280. *
  2281. * \b Description:
  2282. *
  2283. * This routine handles mailbox timeout events at timer interrupt context.
  2284. */
  2285. void
  2286. lpfc_mbox_timeout(unsigned long ptr)
  2287. {
  2288. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  2289. unsigned long iflag;
  2290. uint32_t tmo_posted;
  2291. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  2292. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  2293. if (!tmo_posted)
  2294. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  2295. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  2296. if (!tmo_posted) {
  2297. spin_lock_irqsave(&phba->hbalock, iflag);
  2298. if (phba->work_wait)
  2299. lpfc_worker_wake_up(phba);
  2300. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2301. }
  2302. }
  2303. void
  2304. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  2305. {
  2306. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  2307. MAILBOX_t *mb = &pmbox->mb;
  2308. struct lpfc_sli *psli = &phba->sli;
  2309. struct lpfc_sli_ring *pring;
  2310. if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) {
  2311. return;
  2312. }
  2313. /* Mbox cmd <mbxCommand> timeout */
  2314. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2315. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  2316. mb->mbxCommand,
  2317. phba->pport->port_state,
  2318. phba->sli.sli_flag,
  2319. phba->sli.mbox_active);
  2320. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  2321. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  2322. * it to fail all oustanding SCSI IO.
  2323. */
  2324. spin_lock_irq(&phba->pport->work_port_lock);
  2325. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  2326. spin_unlock_irq(&phba->pport->work_port_lock);
  2327. spin_lock_irq(&phba->hbalock);
  2328. phba->link_state = LPFC_LINK_UNKNOWN;
  2329. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  2330. spin_unlock_irq(&phba->hbalock);
  2331. pring = &psli->ring[psli->fcp_ring];
  2332. lpfc_sli_abort_iocb_ring(phba, pring);
  2333. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2334. "0345 Resetting board due to mailbox timeout\n");
  2335. /*
  2336. * lpfc_offline calls lpfc_sli_hba_down which will clean up
  2337. * on oustanding mailbox commands.
  2338. */
  2339. /* If resets are disabled then set error state and return. */
  2340. if (!phba->cfg_enable_hba_reset) {
  2341. phba->link_state = LPFC_HBA_ERROR;
  2342. return;
  2343. }
  2344. lpfc_offline_prep(phba);
  2345. lpfc_offline(phba);
  2346. lpfc_sli_brdrestart(phba);
  2347. lpfc_online(phba);
  2348. lpfc_unblock_mgmt_io(phba);
  2349. return;
  2350. }
  2351. int
  2352. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  2353. {
  2354. MAILBOX_t *mb;
  2355. struct lpfc_sli *psli = &phba->sli;
  2356. uint32_t status, evtctr;
  2357. uint32_t ha_copy;
  2358. int i;
  2359. unsigned long timeout;
  2360. unsigned long drvr_flag = 0;
  2361. volatile uint32_t word0, ldata;
  2362. void __iomem *to_slim;
  2363. int processing_queue = 0;
  2364. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  2365. if (!pmbox) {
  2366. /* processing mbox queue from intr_handler */
  2367. processing_queue = 1;
  2368. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2369. pmbox = lpfc_mbox_get(phba);
  2370. if (!pmbox) {
  2371. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2372. return MBX_SUCCESS;
  2373. }
  2374. }
  2375. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  2376. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  2377. if(!pmbox->vport) {
  2378. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2379. lpfc_printf_log(phba, KERN_ERR,
  2380. LOG_MBOX | LOG_VPORT,
  2381. "1806 Mbox x%x failed. No vport\n",
  2382. pmbox->mb.mbxCommand);
  2383. dump_stack();
  2384. goto out_not_finished;
  2385. }
  2386. }
  2387. /* If the PCI channel is in offline state, do not post mbox. */
  2388. if (unlikely(pci_channel_offline(phba->pcidev))) {
  2389. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2390. goto out_not_finished;
  2391. }
  2392. psli = &phba->sli;
  2393. mb = &pmbox->mb;
  2394. status = MBX_SUCCESS;
  2395. if (phba->link_state == LPFC_HBA_ERROR) {
  2396. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2397. /* Mbox command <mbxCommand> cannot issue */
  2398. LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
  2399. goto out_not_finished;
  2400. }
  2401. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  2402. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  2403. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2404. LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
  2405. goto out_not_finished;
  2406. }
  2407. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  2408. /* Polling for a mbox command when another one is already active
  2409. * is not allowed in SLI. Also, the driver must have established
  2410. * SLI2 mode to queue and process multiple mbox commands.
  2411. */
  2412. if (flag & MBX_POLL) {
  2413. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2414. /* Mbox command <mbxCommand> cannot issue */
  2415. LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
  2416. goto out_not_finished;
  2417. }
  2418. if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
  2419. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2420. /* Mbox command <mbxCommand> cannot issue */
  2421. LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
  2422. goto out_not_finished;
  2423. }
  2424. /* Another mailbox command is still being processed, queue this
  2425. * command to be processed later.
  2426. */
  2427. lpfc_mbox_put(phba, pmbox);
  2428. /* Mbox cmd issue - BUSY */
  2429. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2430. "(%d):0308 Mbox cmd issue - BUSY Data: "
  2431. "x%x x%x x%x x%x\n",
  2432. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  2433. mb->mbxCommand, phba->pport->port_state,
  2434. psli->sli_flag, flag);
  2435. psli->slistat.mbox_busy++;
  2436. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2437. if (pmbox->vport) {
  2438. lpfc_debugfs_disc_trc(pmbox->vport,
  2439. LPFC_DISC_TRC_MBOX_VPORT,
  2440. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  2441. (uint32_t)mb->mbxCommand,
  2442. mb->un.varWords[0], mb->un.varWords[1]);
  2443. }
  2444. else {
  2445. lpfc_debugfs_disc_trc(phba->pport,
  2446. LPFC_DISC_TRC_MBOX,
  2447. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  2448. (uint32_t)mb->mbxCommand,
  2449. mb->un.varWords[0], mb->un.varWords[1]);
  2450. }
  2451. return MBX_BUSY;
  2452. }
  2453. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  2454. /* If we are not polling, we MUST be in SLI2 mode */
  2455. if (flag != MBX_POLL) {
  2456. if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
  2457. (mb->mbxCommand != MBX_KILL_BOARD)) {
  2458. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2459. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2460. /* Mbox command <mbxCommand> cannot issue */
  2461. LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
  2462. goto out_not_finished;
  2463. }
  2464. /* timeout active mbox command */
  2465. mod_timer(&psli->mbox_tmo, (jiffies +
  2466. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  2467. }
  2468. /* Mailbox cmd <cmd> issue */
  2469. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2470. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  2471. "x%x\n",
  2472. pmbox->vport ? pmbox->vport->vpi : 0,
  2473. mb->mbxCommand, phba->pport->port_state,
  2474. psli->sli_flag, flag);
  2475. if (mb->mbxCommand != MBX_HEARTBEAT) {
  2476. if (pmbox->vport) {
  2477. lpfc_debugfs_disc_trc(pmbox->vport,
  2478. LPFC_DISC_TRC_MBOX_VPORT,
  2479. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  2480. (uint32_t)mb->mbxCommand,
  2481. mb->un.varWords[0], mb->un.varWords[1]);
  2482. }
  2483. else {
  2484. lpfc_debugfs_disc_trc(phba->pport,
  2485. LPFC_DISC_TRC_MBOX,
  2486. "MBOX Send: cmd:x%x mb:x%x x%x",
  2487. (uint32_t)mb->mbxCommand,
  2488. mb->un.varWords[0], mb->un.varWords[1]);
  2489. }
  2490. }
  2491. psli->slistat.mbox_cmd++;
  2492. evtctr = psli->slistat.mbox_event;
  2493. /* next set own bit for the adapter and copy over command word */
  2494. mb->mbxOwner = OWN_CHIP;
  2495. if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
  2496. /* First copy command data to host SLIM area */
  2497. lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
  2498. } else {
  2499. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  2500. /* copy command data into host mbox for cmpl */
  2501. lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
  2502. MAILBOX_CMD_SIZE);
  2503. }
  2504. /* First copy mbox command data to HBA SLIM, skip past first
  2505. word */
  2506. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  2507. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  2508. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  2509. /* Next copy over first word, with mbxOwner set */
  2510. ldata = *((volatile uint32_t *)mb);
  2511. to_slim = phba->MBslimaddr;
  2512. writel(ldata, to_slim);
  2513. readl(to_slim); /* flush */
  2514. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  2515. /* switch over to host mailbox */
  2516. psli->sli_flag |= LPFC_SLI2_ACTIVE;
  2517. }
  2518. }
  2519. wmb();
  2520. switch (flag) {
  2521. case MBX_NOWAIT:
  2522. /* Set up reference to mailbox command */
  2523. psli->mbox_active = pmbox;
  2524. /* Interrupt board to do it */
  2525. writel(CA_MBATT, phba->CAregaddr);
  2526. readl(phba->CAregaddr); /* flush */
  2527. /* Don't wait for it to finish, just return */
  2528. break;
  2529. case MBX_POLL:
  2530. /* Set up null reference to mailbox command */
  2531. psli->mbox_active = NULL;
  2532. /* Interrupt board to do it */
  2533. writel(CA_MBATT, phba->CAregaddr);
  2534. readl(phba->CAregaddr); /* flush */
  2535. if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
  2536. /* First read mbox status word */
  2537. word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
  2538. word0 = le32_to_cpu(word0);
  2539. } else {
  2540. /* First read mbox status word */
  2541. word0 = readl(phba->MBslimaddr);
  2542. }
  2543. /* Read the HBA Host Attention Register */
  2544. ha_copy = readl(phba->HAregaddr);
  2545. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  2546. mb->mbxCommand) *
  2547. 1000) + jiffies;
  2548. i = 0;
  2549. /* Wait for command to complete */
  2550. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  2551. (!(ha_copy & HA_MBATT) &&
  2552. (phba->link_state > LPFC_WARM_START))) {
  2553. if (time_after(jiffies, timeout)) {
  2554. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2555. spin_unlock_irqrestore(&phba->hbalock,
  2556. drvr_flag);
  2557. goto out_not_finished;
  2558. }
  2559. /* Check if we took a mbox interrupt while we were
  2560. polling */
  2561. if (((word0 & OWN_CHIP) != OWN_CHIP)
  2562. && (evtctr != psli->slistat.mbox_event))
  2563. break;
  2564. if (i++ > 10) {
  2565. spin_unlock_irqrestore(&phba->hbalock,
  2566. drvr_flag);
  2567. msleep(1);
  2568. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  2569. }
  2570. if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
  2571. /* First copy command data */
  2572. word0 = *((volatile uint32_t *)
  2573. &phba->slim2p->mbx);
  2574. word0 = le32_to_cpu(word0);
  2575. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  2576. MAILBOX_t *slimmb;
  2577. volatile uint32_t slimword0;
  2578. /* Check real SLIM for any errors */
  2579. slimword0 = readl(phba->MBslimaddr);
  2580. slimmb = (MAILBOX_t *) & slimword0;
  2581. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  2582. && slimmb->mbxStatus) {
  2583. psli->sli_flag &=
  2584. ~LPFC_SLI2_ACTIVE;
  2585. word0 = slimword0;
  2586. }
  2587. }
  2588. } else {
  2589. /* First copy command data */
  2590. word0 = readl(phba->MBslimaddr);
  2591. }
  2592. /* Read the HBA Host Attention Register */
  2593. ha_copy = readl(phba->HAregaddr);
  2594. }
  2595. if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
  2596. /* copy results back to user */
  2597. lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
  2598. MAILBOX_CMD_SIZE);
  2599. } else {
  2600. /* First copy command data */
  2601. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  2602. MAILBOX_CMD_SIZE);
  2603. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  2604. pmbox->context2) {
  2605. lpfc_memcpy_from_slim((void *)pmbox->context2,
  2606. phba->MBslimaddr + DMP_RSP_OFFSET,
  2607. mb->un.varDmp.word_cnt);
  2608. }
  2609. }
  2610. writel(HA_MBATT, phba->HAregaddr);
  2611. readl(phba->HAregaddr); /* flush */
  2612. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2613. status = mb->mbxStatus;
  2614. }
  2615. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2616. return status;
  2617. out_not_finished:
  2618. if (processing_queue) {
  2619. pmbox->mb.mbxStatus = MBX_NOT_FINISHED;
  2620. lpfc_mbox_cmpl_put(phba, pmbox);
  2621. }
  2622. return MBX_NOT_FINISHED;
  2623. }
  2624. /*
  2625. * Caller needs to hold lock.
  2626. */
  2627. static void
  2628. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2629. struct lpfc_iocbq *piocb)
  2630. {
  2631. /* Insert the caller's iocb in the txq tail for later processing. */
  2632. list_add_tail(&piocb->list, &pring->txq);
  2633. pring->txq_cnt++;
  2634. }
  2635. static struct lpfc_iocbq *
  2636. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2637. struct lpfc_iocbq **piocb)
  2638. {
  2639. struct lpfc_iocbq * nextiocb;
  2640. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  2641. if (!nextiocb) {
  2642. nextiocb = *piocb;
  2643. *piocb = NULL;
  2644. }
  2645. return nextiocb;
  2646. }
  2647. /*
  2648. * Lockless version of lpfc_sli_issue_iocb.
  2649. */
  2650. static int
  2651. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2652. struct lpfc_iocbq *piocb, uint32_t flag)
  2653. {
  2654. struct lpfc_iocbq *nextiocb;
  2655. IOCB_t *iocb;
  2656. if (piocb->iocb_cmpl && (!piocb->vport) &&
  2657. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  2658. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  2659. lpfc_printf_log(phba, KERN_ERR,
  2660. LOG_SLI | LOG_VPORT,
  2661. "1807 IOCB x%x failed. No vport\n",
  2662. piocb->iocb.ulpCommand);
  2663. dump_stack();
  2664. return IOCB_ERROR;
  2665. }
  2666. /* If the PCI channel is in offline state, do not post iocbs. */
  2667. if (unlikely(pci_channel_offline(phba->pcidev)))
  2668. return IOCB_ERROR;
  2669. /*
  2670. * We should never get an IOCB if we are in a < LINK_DOWN state
  2671. */
  2672. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  2673. return IOCB_ERROR;
  2674. /*
  2675. * Check to see if we are blocking IOCB processing because of a
  2676. * outstanding event.
  2677. */
  2678. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  2679. goto iocb_busy;
  2680. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  2681. /*
  2682. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  2683. * can be issued if the link is not up.
  2684. */
  2685. switch (piocb->iocb.ulpCommand) {
  2686. case CMD_QUE_RING_BUF_CN:
  2687. case CMD_QUE_RING_BUF64_CN:
  2688. /*
  2689. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  2690. * completion, iocb_cmpl MUST be 0.
  2691. */
  2692. if (piocb->iocb_cmpl)
  2693. piocb->iocb_cmpl = NULL;
  2694. /*FALLTHROUGH*/
  2695. case CMD_CREATE_XRI_CR:
  2696. case CMD_CLOSE_XRI_CN:
  2697. case CMD_CLOSE_XRI_CX:
  2698. break;
  2699. default:
  2700. goto iocb_busy;
  2701. }
  2702. /*
  2703. * For FCP commands, we must be in a state where we can process link
  2704. * attention events.
  2705. */
  2706. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  2707. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  2708. goto iocb_busy;
  2709. }
  2710. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  2711. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  2712. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  2713. if (iocb)
  2714. lpfc_sli_update_ring(phba, pring);
  2715. else
  2716. lpfc_sli_update_full_ring(phba, pring);
  2717. if (!piocb)
  2718. return IOCB_SUCCESS;
  2719. goto out_busy;
  2720. iocb_busy:
  2721. pring->stats.iocb_cmd_delay++;
  2722. out_busy:
  2723. if (!(flag & SLI_IOCB_RET_IOCB)) {
  2724. __lpfc_sli_ringtx_put(phba, pring, piocb);
  2725. return IOCB_SUCCESS;
  2726. }
  2727. return IOCB_BUSY;
  2728. }
  2729. int
  2730. lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2731. struct lpfc_iocbq *piocb, uint32_t flag)
  2732. {
  2733. unsigned long iflags;
  2734. int rc;
  2735. spin_lock_irqsave(&phba->hbalock, iflags);
  2736. rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag);
  2737. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2738. return rc;
  2739. }
  2740. static int
  2741. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  2742. {
  2743. struct lpfc_sli *psli;
  2744. struct lpfc_sli_ring *pring;
  2745. psli = &phba->sli;
  2746. /* Adjust cmd/rsp ring iocb entries more evenly */
  2747. /* Take some away from the FCP ring */
  2748. pring = &psli->ring[psli->fcp_ring];
  2749. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  2750. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  2751. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  2752. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  2753. /* and give them to the extra ring */
  2754. pring = &psli->ring[psli->extra_ring];
  2755. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  2756. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  2757. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  2758. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  2759. /* Setup default profile for this ring */
  2760. pring->iotag_max = 4096;
  2761. pring->num_mask = 1;
  2762. pring->prt[0].profile = 0; /* Mask 0 */
  2763. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  2764. pring->prt[0].type = phba->cfg_multi_ring_type;
  2765. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  2766. return 0;
  2767. }
  2768. static void
  2769. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  2770. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  2771. {
  2772. IOCB_t *icmd;
  2773. uint16_t evt_code;
  2774. uint16_t temp;
  2775. struct temp_event temp_event_data;
  2776. struct Scsi_Host *shost;
  2777. icmd = &iocbq->iocb;
  2778. evt_code = icmd->un.asyncstat.evt_code;
  2779. temp = icmd->ulpContext;
  2780. if ((evt_code != ASYNC_TEMP_WARN) &&
  2781. (evt_code != ASYNC_TEMP_SAFE)) {
  2782. lpfc_printf_log(phba,
  2783. KERN_ERR,
  2784. LOG_SLI,
  2785. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  2786. " evt_code 0x%x\n",
  2787. pring->ringno,
  2788. icmd->un.asyncstat.evt_code);
  2789. return;
  2790. }
  2791. temp_event_data.data = (uint32_t)temp;
  2792. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  2793. if (evt_code == ASYNC_TEMP_WARN) {
  2794. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  2795. lpfc_printf_log(phba,
  2796. KERN_ERR,
  2797. LOG_TEMP,
  2798. "0347 Adapter is very hot, please take "
  2799. "corrective action. temperature : %d Celsius\n",
  2800. temp);
  2801. }
  2802. if (evt_code == ASYNC_TEMP_SAFE) {
  2803. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  2804. lpfc_printf_log(phba,
  2805. KERN_ERR,
  2806. LOG_TEMP,
  2807. "0340 Adapter temperature is OK now. "
  2808. "temperature : %d Celsius\n",
  2809. temp);
  2810. }
  2811. /* Send temperature change event to applications */
  2812. shost = lpfc_shost_from_vport(phba->pport);
  2813. fc_host_post_vendor_event(shost, fc_get_event_number(),
  2814. sizeof(temp_event_data), (char *) &temp_event_data,
  2815. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  2816. }
  2817. int
  2818. lpfc_sli_setup(struct lpfc_hba *phba)
  2819. {
  2820. int i, totiocbsize = 0;
  2821. struct lpfc_sli *psli = &phba->sli;
  2822. struct lpfc_sli_ring *pring;
  2823. psli->num_rings = MAX_CONFIGURED_RINGS;
  2824. psli->sli_flag = 0;
  2825. psli->fcp_ring = LPFC_FCP_RING;
  2826. psli->next_ring = LPFC_FCP_NEXT_RING;
  2827. psli->extra_ring = LPFC_EXTRA_RING;
  2828. psli->iocbq_lookup = NULL;
  2829. psli->iocbq_lookup_len = 0;
  2830. psli->last_iotag = 0;
  2831. for (i = 0; i < psli->num_rings; i++) {
  2832. pring = &psli->ring[i];
  2833. switch (i) {
  2834. case LPFC_FCP_RING: /* ring 0 - FCP */
  2835. /* numCiocb and numRiocb are used in config_port */
  2836. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  2837. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  2838. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  2839. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  2840. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  2841. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  2842. pring->sizeCiocb = (phba->sli_rev == 3) ?
  2843. SLI3_IOCB_CMD_SIZE :
  2844. SLI2_IOCB_CMD_SIZE;
  2845. pring->sizeRiocb = (phba->sli_rev == 3) ?
  2846. SLI3_IOCB_RSP_SIZE :
  2847. SLI2_IOCB_RSP_SIZE;
  2848. pring->iotag_ctr = 0;
  2849. pring->iotag_max =
  2850. (phba->cfg_hba_queue_depth * 2);
  2851. pring->fast_iotag = pring->iotag_max;
  2852. pring->num_mask = 0;
  2853. break;
  2854. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  2855. /* numCiocb and numRiocb are used in config_port */
  2856. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  2857. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  2858. pring->sizeCiocb = (phba->sli_rev == 3) ?
  2859. SLI3_IOCB_CMD_SIZE :
  2860. SLI2_IOCB_CMD_SIZE;
  2861. pring->sizeRiocb = (phba->sli_rev == 3) ?
  2862. SLI3_IOCB_RSP_SIZE :
  2863. SLI2_IOCB_RSP_SIZE;
  2864. pring->iotag_max = phba->cfg_hba_queue_depth;
  2865. pring->num_mask = 0;
  2866. break;
  2867. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  2868. /* numCiocb and numRiocb are used in config_port */
  2869. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  2870. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  2871. pring->sizeCiocb = (phba->sli_rev == 3) ?
  2872. SLI3_IOCB_CMD_SIZE :
  2873. SLI2_IOCB_CMD_SIZE;
  2874. pring->sizeRiocb = (phba->sli_rev == 3) ?
  2875. SLI3_IOCB_RSP_SIZE :
  2876. SLI2_IOCB_RSP_SIZE;
  2877. pring->fast_iotag = 0;
  2878. pring->iotag_ctr = 0;
  2879. pring->iotag_max = 4096;
  2880. pring->lpfc_sli_rcv_async_status =
  2881. lpfc_sli_async_event_handler;
  2882. pring->num_mask = 4;
  2883. pring->prt[0].profile = 0; /* Mask 0 */
  2884. pring->prt[0].rctl = FC_ELS_REQ;
  2885. pring->prt[0].type = FC_ELS_DATA;
  2886. pring->prt[0].lpfc_sli_rcv_unsol_event =
  2887. lpfc_els_unsol_event;
  2888. pring->prt[1].profile = 0; /* Mask 1 */
  2889. pring->prt[1].rctl = FC_ELS_RSP;
  2890. pring->prt[1].type = FC_ELS_DATA;
  2891. pring->prt[1].lpfc_sli_rcv_unsol_event =
  2892. lpfc_els_unsol_event;
  2893. pring->prt[2].profile = 0; /* Mask 2 */
  2894. /* NameServer Inquiry */
  2895. pring->prt[2].rctl = FC_UNSOL_CTL;
  2896. /* NameServer */
  2897. pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
  2898. pring->prt[2].lpfc_sli_rcv_unsol_event =
  2899. lpfc_ct_unsol_event;
  2900. pring->prt[3].profile = 0; /* Mask 3 */
  2901. /* NameServer response */
  2902. pring->prt[3].rctl = FC_SOL_CTL;
  2903. /* NameServer */
  2904. pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
  2905. pring->prt[3].lpfc_sli_rcv_unsol_event =
  2906. lpfc_ct_unsol_event;
  2907. break;
  2908. }
  2909. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  2910. (pring->numRiocb * pring->sizeRiocb);
  2911. }
  2912. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  2913. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  2914. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  2915. "SLI2 SLIM Data: x%x x%lx\n",
  2916. phba->brd_no, totiocbsize,
  2917. (unsigned long) MAX_SLIM_IOCB_SIZE);
  2918. }
  2919. if (phba->cfg_multi_ring_support == 2)
  2920. lpfc_extra_ring_setup(phba);
  2921. return 0;
  2922. }
  2923. int
  2924. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  2925. {
  2926. struct lpfc_sli *psli;
  2927. struct lpfc_sli_ring *pring;
  2928. int i;
  2929. psli = &phba->sli;
  2930. spin_lock_irq(&phba->hbalock);
  2931. INIT_LIST_HEAD(&psli->mboxq);
  2932. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  2933. /* Initialize list headers for txq and txcmplq as double linked lists */
  2934. for (i = 0; i < psli->num_rings; i++) {
  2935. pring = &psli->ring[i];
  2936. pring->ringno = i;
  2937. pring->next_cmdidx = 0;
  2938. pring->local_getidx = 0;
  2939. pring->cmdidx = 0;
  2940. INIT_LIST_HEAD(&pring->txq);
  2941. INIT_LIST_HEAD(&pring->txcmplq);
  2942. INIT_LIST_HEAD(&pring->iocb_continueq);
  2943. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  2944. INIT_LIST_HEAD(&pring->postbufq);
  2945. }
  2946. spin_unlock_irq(&phba->hbalock);
  2947. return 1;
  2948. }
  2949. int
  2950. lpfc_sli_host_down(struct lpfc_vport *vport)
  2951. {
  2952. LIST_HEAD(completions);
  2953. struct lpfc_hba *phba = vport->phba;
  2954. struct lpfc_sli *psli = &phba->sli;
  2955. struct lpfc_sli_ring *pring;
  2956. struct lpfc_iocbq *iocb, *next_iocb;
  2957. int i;
  2958. unsigned long flags = 0;
  2959. uint16_t prev_pring_flag;
  2960. lpfc_cleanup_discovery_resources(vport);
  2961. spin_lock_irqsave(&phba->hbalock, flags);
  2962. for (i = 0; i < psli->num_rings; i++) {
  2963. pring = &psli->ring[i];
  2964. prev_pring_flag = pring->flag;
  2965. if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
  2966. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  2967. /*
  2968. * Error everything on the txq since these iocbs have not been
  2969. * given to the FW yet.
  2970. */
  2971. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  2972. if (iocb->vport != vport)
  2973. continue;
  2974. list_move_tail(&iocb->list, &completions);
  2975. pring->txq_cnt--;
  2976. }
  2977. /* Next issue ABTS for everything on the txcmplq */
  2978. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  2979. list) {
  2980. if (iocb->vport != vport)
  2981. continue;
  2982. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2983. }
  2984. pring->flag = prev_pring_flag;
  2985. }
  2986. spin_unlock_irqrestore(&phba->hbalock, flags);
  2987. while (!list_empty(&completions)) {
  2988. list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
  2989. if (!iocb->iocb_cmpl)
  2990. lpfc_sli_release_iocbq(phba, iocb);
  2991. else {
  2992. iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  2993. iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN;
  2994. (iocb->iocb_cmpl) (phba, iocb, iocb);
  2995. }
  2996. }
  2997. return 1;
  2998. }
  2999. int
  3000. lpfc_sli_hba_down(struct lpfc_hba *phba)
  3001. {
  3002. LIST_HEAD(completions);
  3003. struct lpfc_sli *psli = &phba->sli;
  3004. struct lpfc_sli_ring *pring;
  3005. struct lpfc_dmabuf *buf_ptr;
  3006. LPFC_MBOXQ_t *pmb;
  3007. struct lpfc_iocbq *iocb;
  3008. IOCB_t *cmd = NULL;
  3009. int i;
  3010. unsigned long flags = 0;
  3011. lpfc_hba_down_prep(phba);
  3012. lpfc_fabric_abort_hba(phba);
  3013. spin_lock_irqsave(&phba->hbalock, flags);
  3014. for (i = 0; i < psli->num_rings; i++) {
  3015. pring = &psli->ring[i];
  3016. if (pring->ringno == LPFC_ELS_RING) /* Only slow rings */
  3017. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  3018. /*
  3019. * Error everything on the txq since these iocbs have not been
  3020. * given to the FW yet.
  3021. */
  3022. list_splice_init(&pring->txq, &completions);
  3023. pring->txq_cnt = 0;
  3024. }
  3025. spin_unlock_irqrestore(&phba->hbalock, flags);
  3026. while (!list_empty(&completions)) {
  3027. list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
  3028. cmd = &iocb->iocb;
  3029. if (!iocb->iocb_cmpl)
  3030. lpfc_sli_release_iocbq(phba, iocb);
  3031. else {
  3032. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3033. cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
  3034. (iocb->iocb_cmpl) (phba, iocb, iocb);
  3035. }
  3036. }
  3037. spin_lock_irqsave(&phba->hbalock, flags);
  3038. list_splice_init(&phba->elsbuf, &completions);
  3039. phba->elsbuf_cnt = 0;
  3040. phba->elsbuf_prev_cnt = 0;
  3041. spin_unlock_irqrestore(&phba->hbalock, flags);
  3042. while (!list_empty(&completions)) {
  3043. list_remove_head(&completions, buf_ptr,
  3044. struct lpfc_dmabuf, list);
  3045. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  3046. kfree(buf_ptr);
  3047. }
  3048. /* Return any active mbox cmds */
  3049. del_timer_sync(&psli->mbox_tmo);
  3050. spin_lock_irqsave(&phba->hbalock, flags);
  3051. spin_lock(&phba->pport->work_port_lock);
  3052. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  3053. spin_unlock(&phba->pport->work_port_lock);
  3054. /* Return any pending or completed mbox cmds */
  3055. list_splice_init(&phba->sli.mboxq, &completions);
  3056. if (psli->mbox_active) {
  3057. list_add_tail(&psli->mbox_active->list, &completions);
  3058. psli->mbox_active = NULL;
  3059. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3060. }
  3061. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  3062. spin_unlock_irqrestore(&phba->hbalock, flags);
  3063. while (!list_empty(&completions)) {
  3064. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  3065. pmb->mb.mbxStatus = MBX_NOT_FINISHED;
  3066. if (pmb->mbox_cmpl)
  3067. pmb->mbox_cmpl(phba,pmb);
  3068. }
  3069. return 1;
  3070. }
  3071. void
  3072. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  3073. {
  3074. uint32_t *src = srcp;
  3075. uint32_t *dest = destp;
  3076. uint32_t ldata;
  3077. int i;
  3078. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  3079. ldata = *src;
  3080. ldata = le32_to_cpu(ldata);
  3081. *dest = ldata;
  3082. src++;
  3083. dest++;
  3084. }
  3085. }
  3086. int
  3087. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3088. struct lpfc_dmabuf *mp)
  3089. {
  3090. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  3091. later */
  3092. spin_lock_irq(&phba->hbalock);
  3093. list_add_tail(&mp->list, &pring->postbufq);
  3094. pring->postbufq_cnt++;
  3095. spin_unlock_irq(&phba->hbalock);
  3096. return 0;
  3097. }
  3098. uint32_t
  3099. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  3100. {
  3101. spin_lock_irq(&phba->hbalock);
  3102. phba->buffer_tag_count++;
  3103. /*
  3104. * Always set the QUE_BUFTAG_BIT to distiguish between
  3105. * a tag assigned by HBQ.
  3106. */
  3107. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  3108. spin_unlock_irq(&phba->hbalock);
  3109. return phba->buffer_tag_count;
  3110. }
  3111. struct lpfc_dmabuf *
  3112. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3113. uint32_t tag)
  3114. {
  3115. struct lpfc_dmabuf *mp, *next_mp;
  3116. struct list_head *slp = &pring->postbufq;
  3117. /* Search postbufq, from the begining, looking for a match on tag */
  3118. spin_lock_irq(&phba->hbalock);
  3119. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  3120. if (mp->buffer_tag == tag) {
  3121. list_del_init(&mp->list);
  3122. pring->postbufq_cnt--;
  3123. spin_unlock_irq(&phba->hbalock);
  3124. return mp;
  3125. }
  3126. }
  3127. spin_unlock_irq(&phba->hbalock);
  3128. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3129. "0410 Cannot find virtual addr for buffer tag on "
  3130. "ring %d Data x%lx x%p x%p x%x\n",
  3131. pring->ringno, (unsigned long) tag,
  3132. slp->next, slp->prev, pring->postbufq_cnt);
  3133. return NULL;
  3134. }
  3135. struct lpfc_dmabuf *
  3136. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3137. dma_addr_t phys)
  3138. {
  3139. struct lpfc_dmabuf *mp, *next_mp;
  3140. struct list_head *slp = &pring->postbufq;
  3141. /* Search postbufq, from the begining, looking for a match on phys */
  3142. spin_lock_irq(&phba->hbalock);
  3143. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  3144. if (mp->phys == phys) {
  3145. list_del_init(&mp->list);
  3146. pring->postbufq_cnt--;
  3147. spin_unlock_irq(&phba->hbalock);
  3148. return mp;
  3149. }
  3150. }
  3151. spin_unlock_irq(&phba->hbalock);
  3152. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3153. "0410 Cannot find virtual addr for mapped buf on "
  3154. "ring %d Data x%llx x%p x%p x%x\n",
  3155. pring->ringno, (unsigned long long)phys,
  3156. slp->next, slp->prev, pring->postbufq_cnt);
  3157. return NULL;
  3158. }
  3159. static void
  3160. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3161. struct lpfc_iocbq *rspiocb)
  3162. {
  3163. IOCB_t *irsp = &rspiocb->iocb;
  3164. uint16_t abort_iotag, abort_context;
  3165. struct lpfc_iocbq *abort_iocb;
  3166. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3167. abort_iocb = NULL;
  3168. if (irsp->ulpStatus) {
  3169. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  3170. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  3171. spin_lock_irq(&phba->hbalock);
  3172. if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
  3173. abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
  3174. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  3175. "0327 Cannot abort els iocb %p "
  3176. "with tag %x context %x, abort status %x, "
  3177. "abort code %x\n",
  3178. abort_iocb, abort_iotag, abort_context,
  3179. irsp->ulpStatus, irsp->un.ulpWord[4]);
  3180. /*
  3181. * If the iocb is not found in Firmware queue the iocb
  3182. * might have completed already. Do not free it again.
  3183. */
  3184. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  3185. spin_unlock_irq(&phba->hbalock);
  3186. lpfc_sli_release_iocbq(phba, cmdiocb);
  3187. return;
  3188. }
  3189. /*
  3190. * make sure we have the right iocbq before taking it
  3191. * off the txcmplq and try to call completion routine.
  3192. */
  3193. if (!abort_iocb ||
  3194. abort_iocb->iocb.ulpContext != abort_context ||
  3195. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  3196. spin_unlock_irq(&phba->hbalock);
  3197. else {
  3198. list_del_init(&abort_iocb->list);
  3199. pring->txcmplq_cnt--;
  3200. spin_unlock_irq(&phba->hbalock);
  3201. /* Firmware could still be in progress of DMAing
  3202. * payload, so don't free data buffer till after
  3203. * a hbeat.
  3204. */
  3205. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  3206. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  3207. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  3208. abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
  3209. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  3210. }
  3211. }
  3212. lpfc_sli_release_iocbq(phba, cmdiocb);
  3213. return;
  3214. }
  3215. static void
  3216. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3217. struct lpfc_iocbq *rspiocb)
  3218. {
  3219. IOCB_t *irsp = &rspiocb->iocb;
  3220. /* ELS cmd tag <ulpIoTag> completes */
  3221. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  3222. "0133 Ignoring ELS cmd tag x%x completion Data: "
  3223. "x%x x%x x%x\n",
  3224. irsp->ulpIoTag, irsp->ulpStatus,
  3225. irsp->un.ulpWord[4], irsp->ulpTimeout);
  3226. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  3227. lpfc_ct_free_iocb(phba, cmdiocb);
  3228. else
  3229. lpfc_els_free_iocb(phba, cmdiocb);
  3230. return;
  3231. }
  3232. int
  3233. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3234. struct lpfc_iocbq *cmdiocb)
  3235. {
  3236. struct lpfc_vport *vport = cmdiocb->vport;
  3237. struct lpfc_iocbq *abtsiocbp;
  3238. IOCB_t *icmd = NULL;
  3239. IOCB_t *iabt = NULL;
  3240. int retval = IOCB_ERROR;
  3241. /*
  3242. * There are certain command types we don't want to abort. And we
  3243. * don't want to abort commands that are already in the process of
  3244. * being aborted.
  3245. */
  3246. icmd = &cmdiocb->iocb;
  3247. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  3248. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  3249. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  3250. return 0;
  3251. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  3252. * callback so that nothing happens when it finishes.
  3253. */
  3254. if ((vport->load_flag & FC_UNLOADING) &&
  3255. (pring->ringno == LPFC_ELS_RING)) {
  3256. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  3257. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  3258. else
  3259. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  3260. goto abort_iotag_exit;
  3261. }
  3262. /* issue ABTS for this IOCB based on iotag */
  3263. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  3264. if (abtsiocbp == NULL)
  3265. return 0;
  3266. /* This signals the response to set the correct status
  3267. * before calling the completion handler.
  3268. */
  3269. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  3270. iabt = &abtsiocbp->iocb;
  3271. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  3272. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  3273. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  3274. iabt->ulpLe = 1;
  3275. iabt->ulpClass = icmd->ulpClass;
  3276. if (phba->link_state >= LPFC_LINK_UP)
  3277. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  3278. else
  3279. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  3280. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  3281. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  3282. "0339 Abort xri x%x, original iotag x%x, "
  3283. "abort cmd iotag x%x\n",
  3284. iabt->un.acxri.abortContextTag,
  3285. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  3286. retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
  3287. abort_iotag_exit:
  3288. /*
  3289. * Caller to this routine should check for IOCB_ERROR
  3290. * and handle it properly. This routine no longer removes
  3291. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  3292. */
  3293. return retval;
  3294. }
  3295. static int
  3296. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  3297. uint16_t tgt_id, uint64_t lun_id,
  3298. lpfc_ctx_cmd ctx_cmd)
  3299. {
  3300. struct lpfc_scsi_buf *lpfc_cmd;
  3301. struct scsi_cmnd *cmnd;
  3302. int rc = 1;
  3303. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  3304. return rc;
  3305. if (iocbq->vport != vport)
  3306. return rc;
  3307. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  3308. cmnd = lpfc_cmd->pCmd;
  3309. if (cmnd == NULL)
  3310. return rc;
  3311. switch (ctx_cmd) {
  3312. case LPFC_CTX_LUN:
  3313. if ((cmnd->device->id == tgt_id) &&
  3314. (cmnd->device->lun == lun_id))
  3315. rc = 0;
  3316. break;
  3317. case LPFC_CTX_TGT:
  3318. if (cmnd->device->id == tgt_id)
  3319. rc = 0;
  3320. break;
  3321. case LPFC_CTX_HOST:
  3322. rc = 0;
  3323. break;
  3324. default:
  3325. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  3326. __FUNCTION__, ctx_cmd);
  3327. break;
  3328. }
  3329. return rc;
  3330. }
  3331. int
  3332. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  3333. lpfc_ctx_cmd ctx_cmd)
  3334. {
  3335. struct lpfc_hba *phba = vport->phba;
  3336. struct lpfc_iocbq *iocbq;
  3337. int sum, i;
  3338. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  3339. iocbq = phba->sli.iocbq_lookup[i];
  3340. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  3341. ctx_cmd) == 0)
  3342. sum++;
  3343. }
  3344. return sum;
  3345. }
  3346. void
  3347. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3348. struct lpfc_iocbq *rspiocb)
  3349. {
  3350. lpfc_sli_release_iocbq(phba, cmdiocb);
  3351. return;
  3352. }
  3353. int
  3354. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  3355. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  3356. {
  3357. struct lpfc_hba *phba = vport->phba;
  3358. struct lpfc_iocbq *iocbq;
  3359. struct lpfc_iocbq *abtsiocb;
  3360. IOCB_t *cmd = NULL;
  3361. int errcnt = 0, ret_val = 0;
  3362. int i;
  3363. for (i = 1; i <= phba->sli.last_iotag; i++) {
  3364. iocbq = phba->sli.iocbq_lookup[i];
  3365. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  3366. abort_cmd) != 0)
  3367. continue;
  3368. /* issue ABTS for this IOCB based on iotag */
  3369. abtsiocb = lpfc_sli_get_iocbq(phba);
  3370. if (abtsiocb == NULL) {
  3371. errcnt++;
  3372. continue;
  3373. }
  3374. cmd = &iocbq->iocb;
  3375. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  3376. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  3377. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  3378. abtsiocb->iocb.ulpLe = 1;
  3379. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  3380. abtsiocb->vport = phba->pport;
  3381. if (lpfc_is_link_up(phba))
  3382. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  3383. else
  3384. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  3385. /* Setup callback routine and issue the command. */
  3386. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  3387. ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
  3388. if (ret_val == IOCB_ERROR) {
  3389. lpfc_sli_release_iocbq(phba, abtsiocb);
  3390. errcnt++;
  3391. continue;
  3392. }
  3393. }
  3394. return errcnt;
  3395. }
  3396. static void
  3397. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  3398. struct lpfc_iocbq *cmdiocbq,
  3399. struct lpfc_iocbq *rspiocbq)
  3400. {
  3401. wait_queue_head_t *pdone_q;
  3402. unsigned long iflags;
  3403. spin_lock_irqsave(&phba->hbalock, iflags);
  3404. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  3405. if (cmdiocbq->context2 && rspiocbq)
  3406. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  3407. &rspiocbq->iocb, sizeof(IOCB_t));
  3408. pdone_q = cmdiocbq->context_un.wait_queue;
  3409. if (pdone_q)
  3410. wake_up(pdone_q);
  3411. spin_unlock_irqrestore(&phba->hbalock, iflags);
  3412. return;
  3413. }
  3414. /*
  3415. * Issue the caller's iocb and wait for its completion, but no longer than the
  3416. * caller's timeout. Note that iocb_flags is cleared before the
  3417. * lpfc_sli_issue_call since the wake routine sets a unique value and by
  3418. * definition this is a wait function.
  3419. */
  3420. int
  3421. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  3422. struct lpfc_sli_ring *pring,
  3423. struct lpfc_iocbq *piocb,
  3424. struct lpfc_iocbq *prspiocbq,
  3425. uint32_t timeout)
  3426. {
  3427. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  3428. long timeleft, timeout_req = 0;
  3429. int retval = IOCB_SUCCESS;
  3430. uint32_t creg_val;
  3431. /*
  3432. * If the caller has provided a response iocbq buffer, then context2
  3433. * is NULL or its an error.
  3434. */
  3435. if (prspiocbq) {
  3436. if (piocb->context2)
  3437. return IOCB_ERROR;
  3438. piocb->context2 = prspiocbq;
  3439. }
  3440. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  3441. piocb->context_un.wait_queue = &done_q;
  3442. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  3443. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  3444. creg_val = readl(phba->HCregaddr);
  3445. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  3446. writel(creg_val, phba->HCregaddr);
  3447. readl(phba->HCregaddr); /* flush */
  3448. }
  3449. retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
  3450. if (retval == IOCB_SUCCESS) {
  3451. timeout_req = timeout * HZ;
  3452. timeleft = wait_event_timeout(done_q,
  3453. piocb->iocb_flag & LPFC_IO_WAKE,
  3454. timeout_req);
  3455. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  3456. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3457. "0331 IOCB wake signaled\n");
  3458. } else if (timeleft == 0) {
  3459. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3460. "0338 IOCB wait timeout error - no "
  3461. "wake response Data x%x\n", timeout);
  3462. retval = IOCB_TIMEDOUT;
  3463. } else {
  3464. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3465. "0330 IOCB wake NOT set, "
  3466. "Data x%x x%lx\n",
  3467. timeout, (timeleft / jiffies));
  3468. retval = IOCB_TIMEDOUT;
  3469. }
  3470. } else {
  3471. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3472. ":0332 IOCB wait issue failed, Data x%x\n",
  3473. retval);
  3474. retval = IOCB_ERROR;
  3475. }
  3476. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  3477. creg_val = readl(phba->HCregaddr);
  3478. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  3479. writel(creg_val, phba->HCregaddr);
  3480. readl(phba->HCregaddr); /* flush */
  3481. }
  3482. if (prspiocbq)
  3483. piocb->context2 = NULL;
  3484. piocb->context_un.wait_queue = NULL;
  3485. piocb->iocb_cmpl = NULL;
  3486. return retval;
  3487. }
  3488. int
  3489. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  3490. uint32_t timeout)
  3491. {
  3492. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  3493. int retval;
  3494. unsigned long flag;
  3495. /* The caller must leave context1 empty. */
  3496. if (pmboxq->context1)
  3497. return MBX_NOT_FINISHED;
  3498. /* setup wake call as IOCB callback */
  3499. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  3500. /* setup context field to pass wait_queue pointer to wake function */
  3501. pmboxq->context1 = &done_q;
  3502. /* now issue the command */
  3503. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  3504. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  3505. wait_event_interruptible_timeout(done_q,
  3506. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  3507. timeout * HZ);
  3508. spin_lock_irqsave(&phba->hbalock, flag);
  3509. pmboxq->context1 = NULL;
  3510. /*
  3511. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  3512. * else do not free the resources.
  3513. */
  3514. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  3515. retval = MBX_SUCCESS;
  3516. else {
  3517. retval = MBX_TIMEOUT;
  3518. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3519. }
  3520. spin_unlock_irqrestore(&phba->hbalock, flag);
  3521. }
  3522. return retval;
  3523. }
  3524. int
  3525. lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
  3526. {
  3527. struct lpfc_vport *vport = phba->pport;
  3528. int i = 0;
  3529. uint32_t ha_copy;
  3530. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) {
  3531. if (i++ > LPFC_MBOX_TMO * 1000)
  3532. return 1;
  3533. /*
  3534. * Call lpfc_sli_handle_mb_event only if a mailbox cmd
  3535. * did finish. This way we won't get the misleading
  3536. * "Stray Mailbox Interrupt" message.
  3537. */
  3538. spin_lock_irq(&phba->hbalock);
  3539. ha_copy = phba->work_ha;
  3540. phba->work_ha &= ~HA_MBATT;
  3541. spin_unlock_irq(&phba->hbalock);
  3542. if (ha_copy & HA_MBATT)
  3543. if (lpfc_sli_handle_mb_event(phba) == 0)
  3544. i = 0;
  3545. msleep(1);
  3546. }
  3547. return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
  3548. }
  3549. irqreturn_t
  3550. lpfc_intr_handler(int irq, void *dev_id)
  3551. {
  3552. struct lpfc_hba *phba;
  3553. uint32_t ha_copy;
  3554. uint32_t work_ha_copy;
  3555. unsigned long status;
  3556. uint32_t control;
  3557. MAILBOX_t *mbox, *pmbox;
  3558. struct lpfc_vport *vport;
  3559. struct lpfc_nodelist *ndlp;
  3560. struct lpfc_dmabuf *mp;
  3561. LPFC_MBOXQ_t *pmb;
  3562. int rc;
  3563. /*
  3564. * Get the driver's phba structure from the dev_id and
  3565. * assume the HBA is not interrupting.
  3566. */
  3567. phba = (struct lpfc_hba *) dev_id;
  3568. if (unlikely(!phba))
  3569. return IRQ_NONE;
  3570. /* If the pci channel is offline, ignore all the interrupts. */
  3571. if (unlikely(pci_channel_offline(phba->pcidev)))
  3572. return IRQ_NONE;
  3573. phba->sli.slistat.sli_intr++;
  3574. /*
  3575. * Call the HBA to see if it is interrupting. If not, don't claim
  3576. * the interrupt
  3577. */
  3578. /* Ignore all interrupts during initialization. */
  3579. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  3580. return IRQ_NONE;
  3581. /*
  3582. * Read host attention register to determine interrupt source
  3583. * Clear Attention Sources, except Error Attention (to
  3584. * preserve status) and Link Attention
  3585. */
  3586. spin_lock(&phba->hbalock);
  3587. ha_copy = readl(phba->HAregaddr);
  3588. /* If somebody is waiting to handle an eratt don't process it
  3589. * here. The brdkill function will do this.
  3590. */
  3591. if (phba->link_flag & LS_IGNORE_ERATT)
  3592. ha_copy &= ~HA_ERATT;
  3593. writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  3594. readl(phba->HAregaddr); /* flush */
  3595. spin_unlock(&phba->hbalock);
  3596. if (unlikely(!ha_copy))
  3597. return IRQ_NONE;
  3598. work_ha_copy = ha_copy & phba->work_ha_mask;
  3599. if (unlikely(work_ha_copy)) {
  3600. if (work_ha_copy & HA_LATT) {
  3601. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  3602. /*
  3603. * Turn off Link Attention interrupts
  3604. * until CLEAR_LA done
  3605. */
  3606. spin_lock(&phba->hbalock);
  3607. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  3608. control = readl(phba->HCregaddr);
  3609. control &= ~HC_LAINT_ENA;
  3610. writel(control, phba->HCregaddr);
  3611. readl(phba->HCregaddr); /* flush */
  3612. spin_unlock(&phba->hbalock);
  3613. }
  3614. else
  3615. work_ha_copy &= ~HA_LATT;
  3616. }
  3617. if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
  3618. /*
  3619. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  3620. * the only slow ring.
  3621. */
  3622. status = (work_ha_copy &
  3623. (HA_RXMASK << (4*LPFC_ELS_RING)));
  3624. status >>= (4*LPFC_ELS_RING);
  3625. if (status & HA_RXMASK) {
  3626. spin_lock(&phba->hbalock);
  3627. control = readl(phba->HCregaddr);
  3628. lpfc_debugfs_slow_ring_trc(phba,
  3629. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  3630. control, status,
  3631. (uint32_t)phba->sli.slistat.sli_intr);
  3632. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  3633. lpfc_debugfs_slow_ring_trc(phba,
  3634. "ISR Disable ring:"
  3635. "pwork:x%x hawork:x%x wait:x%x",
  3636. phba->work_ha, work_ha_copy,
  3637. (uint32_t)((unsigned long)
  3638. phba->work_wait));
  3639. control &=
  3640. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  3641. writel(control, phba->HCregaddr);
  3642. readl(phba->HCregaddr); /* flush */
  3643. }
  3644. else {
  3645. lpfc_debugfs_slow_ring_trc(phba,
  3646. "ISR slow ring: pwork:"
  3647. "x%x hawork:x%x wait:x%x",
  3648. phba->work_ha, work_ha_copy,
  3649. (uint32_t)((unsigned long)
  3650. phba->work_wait));
  3651. }
  3652. spin_unlock(&phba->hbalock);
  3653. }
  3654. }
  3655. if (work_ha_copy & HA_ERATT) {
  3656. /*
  3657. * There was a link/board error. Read the
  3658. * status register to retrieve the error event
  3659. * and process it.
  3660. */
  3661. phba->sli.slistat.err_attn_event++;
  3662. /* Save status info */
  3663. phba->work_hs = readl(phba->HSregaddr);
  3664. phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
  3665. phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
  3666. /* Clear Chip error bit */
  3667. writel(HA_ERATT, phba->HAregaddr);
  3668. readl(phba->HAregaddr); /* flush */
  3669. phba->pport->stopped = 1;
  3670. }
  3671. spin_lock(&phba->hbalock);
  3672. if ((work_ha_copy & HA_MBATT) &&
  3673. (phba->sli.mbox_active)) {
  3674. pmb = phba->sli.mbox_active;
  3675. pmbox = &pmb->mb;
  3676. mbox = &phba->slim2p->mbx;
  3677. vport = pmb->vport;
  3678. /* First check out the status word */
  3679. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  3680. if (pmbox->mbxOwner != OWN_HOST) {
  3681. spin_unlock(&phba->hbalock);
  3682. /*
  3683. * Stray Mailbox Interrupt, mbxCommand <cmd>
  3684. * mbxStatus <status>
  3685. */
  3686. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  3687. LOG_SLI,
  3688. "(%d):0304 Stray Mailbox "
  3689. "Interrupt mbxCommand x%x "
  3690. "mbxStatus x%x\n",
  3691. (vport ? vport->vpi : 0),
  3692. pmbox->mbxCommand,
  3693. pmbox->mbxStatus);
  3694. /* clear mailbox attention bit */
  3695. work_ha_copy &= ~HA_MBATT;
  3696. } else {
  3697. phba->sli.mbox_active = NULL;
  3698. spin_unlock(&phba->hbalock);
  3699. phba->last_completion_time = jiffies;
  3700. del_timer(&phba->sli.mbox_tmo);
  3701. if (pmb->mbox_cmpl) {
  3702. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  3703. MAILBOX_CMD_SIZE);
  3704. }
  3705. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  3706. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  3707. lpfc_debugfs_disc_trc(vport,
  3708. LPFC_DISC_TRC_MBOX_VPORT,
  3709. "MBOX dflt rpi: : "
  3710. "status:x%x rpi:x%x",
  3711. (uint32_t)pmbox->mbxStatus,
  3712. pmbox->un.varWords[0], 0);
  3713. if (!pmbox->mbxStatus) {
  3714. mp = (struct lpfc_dmabuf *)
  3715. (pmb->context1);
  3716. ndlp = (struct lpfc_nodelist *)
  3717. pmb->context2;
  3718. /* Reg_LOGIN of dflt RPI was
  3719. * successful. new lets get
  3720. * rid of the RPI using the
  3721. * same mbox buffer.
  3722. */
  3723. lpfc_unreg_login(phba,
  3724. vport->vpi,
  3725. pmbox->un.varWords[0],
  3726. pmb);
  3727. pmb->mbox_cmpl =
  3728. lpfc_mbx_cmpl_dflt_rpi;
  3729. pmb->context1 = mp;
  3730. pmb->context2 = ndlp;
  3731. pmb->vport = vport;
  3732. rc = lpfc_sli_issue_mbox(phba,
  3733. pmb,
  3734. MBX_NOWAIT);
  3735. if (rc != MBX_BUSY)
  3736. lpfc_printf_log(phba,
  3737. KERN_ERR,
  3738. LOG_MBOX | LOG_SLI,
  3739. "0306 rc should have"
  3740. "been MBX_BUSY");
  3741. goto send_current_mbox;
  3742. }
  3743. }
  3744. spin_lock(&phba->pport->work_port_lock);
  3745. phba->pport->work_port_events &=
  3746. ~WORKER_MBOX_TMO;
  3747. spin_unlock(&phba->pport->work_port_lock);
  3748. lpfc_mbox_cmpl_put(phba, pmb);
  3749. }
  3750. } else
  3751. spin_unlock(&phba->hbalock);
  3752. if ((work_ha_copy & HA_MBATT) &&
  3753. (phba->sli.mbox_active == NULL)) {
  3754. send_current_mbox:
  3755. /* Process next mailbox command if there is one */
  3756. do {
  3757. rc = lpfc_sli_issue_mbox(phba, NULL,
  3758. MBX_NOWAIT);
  3759. } while (rc == MBX_NOT_FINISHED);
  3760. if (rc != MBX_SUCCESS)
  3761. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  3762. LOG_SLI, "0349 rc should be "
  3763. "MBX_SUCCESS");
  3764. }
  3765. spin_lock(&phba->hbalock);
  3766. phba->work_ha |= work_ha_copy;
  3767. if (phba->work_wait)
  3768. lpfc_worker_wake_up(phba);
  3769. spin_unlock(&phba->hbalock);
  3770. }
  3771. ha_copy &= ~(phba->work_ha_mask);
  3772. /*
  3773. * Process all events on FCP ring. Take the optimized path for
  3774. * FCP IO. Any other IO is slow path and is handled by
  3775. * the worker thread.
  3776. */
  3777. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  3778. status >>= (4*LPFC_FCP_RING);
  3779. if (status & HA_RXMASK)
  3780. lpfc_sli_handle_fast_ring_event(phba,
  3781. &phba->sli.ring[LPFC_FCP_RING],
  3782. status);
  3783. if (phba->cfg_multi_ring_support == 2) {
  3784. /*
  3785. * Process all events on extra ring. Take the optimized path
  3786. * for extra ring IO. Any other IO is slow path and is handled
  3787. * by the worker thread.
  3788. */
  3789. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  3790. status >>= (4*LPFC_EXTRA_RING);
  3791. if (status & HA_RXMASK) {
  3792. lpfc_sli_handle_fast_ring_event(phba,
  3793. &phba->sli.ring[LPFC_EXTRA_RING],
  3794. status);
  3795. }
  3796. }
  3797. return IRQ_HANDLED;
  3798. } /* lpfc_intr_handler */