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