lpfc_sli.c 108 KB

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