lpfc_sli.c 104 KB

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