lpfc_els.c 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697
  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 <scsi/scsi.h>
  25. #include <scsi/scsi_device.h>
  26. #include <scsi/scsi_host.h>
  27. #include <scsi/scsi_transport_fc.h>
  28. #include "lpfc_hw.h"
  29. #include "lpfc_sli.h"
  30. #include "lpfc_disc.h"
  31. #include "lpfc_scsi.h"
  32. #include "lpfc.h"
  33. #include "lpfc_logmsg.h"
  34. #include "lpfc_crtn.h"
  35. #include "lpfc_vport.h"
  36. #include "lpfc_debugfs.h"
  37. static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
  38. struct lpfc_iocbq *);
  39. static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
  40. struct lpfc_iocbq *);
  41. static int lpfc_max_els_tries = 3;
  42. int
  43. lpfc_els_chk_latt(struct lpfc_vport *vport)
  44. {
  45. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  46. struct lpfc_hba *phba = vport->phba;
  47. uint32_t ha_copy;
  48. if (vport->port_state >= LPFC_VPORT_READY ||
  49. phba->link_state == LPFC_LINK_DOWN)
  50. return 0;
  51. /* Read the HBA Host Attention Register */
  52. ha_copy = readl(phba->HAregaddr);
  53. if (!(ha_copy & HA_LATT))
  54. return 0;
  55. /* Pending Link Event during Discovery */
  56. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  57. "0237 Pending Link Event during "
  58. "Discovery: State x%x\n",
  59. phba->pport->port_state);
  60. /* CLEAR_LA should re-enable link attention events and
  61. * we should then imediately take a LATT event. The
  62. * LATT processing should call lpfc_linkdown() which
  63. * will cleanup any left over in-progress discovery
  64. * events.
  65. */
  66. spin_lock_irq(shost->host_lock);
  67. vport->fc_flag |= FC_ABORT_DISCOVERY;
  68. spin_unlock_irq(shost->host_lock);
  69. if (phba->link_state != LPFC_CLEAR_LA)
  70. lpfc_issue_clear_la(phba, vport);
  71. return 1;
  72. }
  73. static struct lpfc_iocbq *
  74. lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
  75. uint16_t cmdSize, uint8_t retry,
  76. struct lpfc_nodelist *ndlp, uint32_t did,
  77. uint32_t elscmd)
  78. {
  79. struct lpfc_hba *phba = vport->phba;
  80. struct lpfc_iocbq *elsiocb;
  81. struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
  82. struct ulp_bde64 *bpl;
  83. IOCB_t *icmd;
  84. if (!lpfc_is_link_up(phba))
  85. return NULL;
  86. /* Allocate buffer for command iocb */
  87. elsiocb = lpfc_sli_get_iocbq(phba);
  88. if (elsiocb == NULL)
  89. return NULL;
  90. icmd = &elsiocb->iocb;
  91. /* fill in BDEs for command */
  92. /* Allocate buffer for command payload */
  93. if (((pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
  94. ((pcmd->virt = lpfc_mbuf_alloc(phba,
  95. MEM_PRI, &(pcmd->phys))) == 0)) {
  96. kfree(pcmd);
  97. lpfc_sli_release_iocbq(phba, elsiocb);
  98. return NULL;
  99. }
  100. INIT_LIST_HEAD(&pcmd->list);
  101. /* Allocate buffer for response payload */
  102. if (expectRsp) {
  103. prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  104. if (prsp)
  105. prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  106. &prsp->phys);
  107. if (prsp == 0 || prsp->virt == 0) {
  108. kfree(prsp);
  109. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  110. kfree(pcmd);
  111. lpfc_sli_release_iocbq(phba, elsiocb);
  112. return NULL;
  113. }
  114. INIT_LIST_HEAD(&prsp->list);
  115. } else {
  116. prsp = NULL;
  117. }
  118. /* Allocate buffer for Buffer ptr list */
  119. pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  120. if (pbuflist)
  121. pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  122. &pbuflist->phys);
  123. if (pbuflist == 0 || pbuflist->virt == 0) {
  124. lpfc_sli_release_iocbq(phba, elsiocb);
  125. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  126. lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
  127. kfree(pcmd);
  128. kfree(prsp);
  129. kfree(pbuflist);
  130. return NULL;
  131. }
  132. INIT_LIST_HEAD(&pbuflist->list);
  133. icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
  134. icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
  135. icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
  136. icmd->un.elsreq64.remoteID = did; /* DID */
  137. if (expectRsp) {
  138. icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
  139. icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
  140. icmd->ulpTimeout = phba->fc_ratov * 2;
  141. } else {
  142. icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
  143. icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
  144. }
  145. icmd->ulpBdeCount = 1;
  146. icmd->ulpLe = 1;
  147. icmd->ulpClass = CLASS3;
  148. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  149. icmd->un.elsreq64.myID = vport->fc_myDID;
  150. /* For ELS_REQUEST64_CR, use the VPI by default */
  151. icmd->ulpContext = vport->vpi;
  152. icmd->ulpCt_h = 0;
  153. icmd->ulpCt_l = 1;
  154. }
  155. bpl = (struct ulp_bde64 *) pbuflist->virt;
  156. bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
  157. bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
  158. bpl->tus.f.bdeSize = cmdSize;
  159. bpl->tus.f.bdeFlags = 0;
  160. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  161. if (expectRsp) {
  162. bpl++;
  163. bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
  164. bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
  165. bpl->tus.f.bdeSize = FCELSSIZE;
  166. bpl->tus.f.bdeFlags = BUFF_USE_RCV;
  167. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  168. }
  169. elsiocb->context1 = lpfc_nlp_get(ndlp);
  170. elsiocb->context2 = pcmd;
  171. elsiocb->context3 = pbuflist;
  172. elsiocb->retry = retry;
  173. elsiocb->vport = vport;
  174. elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
  175. if (prsp) {
  176. list_add(&prsp->list, &pcmd->list);
  177. }
  178. if (expectRsp) {
  179. /* Xmit ELS command <elsCmd> to remote NPORT <did> */
  180. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  181. "0116 Xmit ELS command x%x to remote "
  182. "NPORT x%x I/O tag: x%x, port state: x%x\n",
  183. elscmd, did, elsiocb->iotag,
  184. vport->port_state);
  185. } else {
  186. /* Xmit ELS response <elsCmd> to remote NPORT <did> */
  187. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  188. "0117 Xmit ELS response x%x to remote "
  189. "NPORT x%x I/O tag: x%x, size: x%x\n",
  190. elscmd, ndlp->nlp_DID, elsiocb->iotag,
  191. cmdSize);
  192. }
  193. return elsiocb;
  194. }
  195. static int
  196. lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
  197. {
  198. struct lpfc_hba *phba = vport->phba;
  199. LPFC_MBOXQ_t *mbox;
  200. struct lpfc_dmabuf *mp;
  201. struct lpfc_nodelist *ndlp;
  202. struct serv_parm *sp;
  203. int rc;
  204. sp = &phba->fc_fabparam;
  205. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  206. if (!ndlp)
  207. goto fail;
  208. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  209. if (!mbox)
  210. goto fail;
  211. vport->port_state = LPFC_FABRIC_CFG_LINK;
  212. lpfc_config_link(phba, mbox);
  213. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  214. mbox->vport = vport;
  215. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
  216. if (rc == MBX_NOT_FINISHED)
  217. goto fail_free_mbox;
  218. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  219. if (!mbox)
  220. goto fail;
  221. rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
  222. 0);
  223. if (rc)
  224. goto fail_free_mbox;
  225. mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
  226. mbox->vport = vport;
  227. mbox->context2 = lpfc_nlp_get(ndlp);
  228. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
  229. if (rc == MBX_NOT_FINISHED)
  230. goto fail_issue_reg_login;
  231. return 0;
  232. fail_issue_reg_login:
  233. lpfc_nlp_put(ndlp);
  234. mp = (struct lpfc_dmabuf *) mbox->context1;
  235. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  236. kfree(mp);
  237. fail_free_mbox:
  238. mempool_free(mbox, phba->mbox_mem_pool);
  239. fail:
  240. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  241. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  242. "0249 Cannot issue Register Fabric login\n");
  243. return -ENXIO;
  244. }
  245. static int
  246. lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  247. struct serv_parm *sp, IOCB_t *irsp)
  248. {
  249. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  250. struct lpfc_hba *phba = vport->phba;
  251. struct lpfc_nodelist *np;
  252. struct lpfc_nodelist *next_np;
  253. spin_lock_irq(shost->host_lock);
  254. vport->fc_flag |= FC_FABRIC;
  255. spin_unlock_irq(shost->host_lock);
  256. phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
  257. if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
  258. phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
  259. phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
  260. if (phba->fc_topology == TOPOLOGY_LOOP) {
  261. spin_lock_irq(shost->host_lock);
  262. vport->fc_flag |= FC_PUBLIC_LOOP;
  263. spin_unlock_irq(shost->host_lock);
  264. } else {
  265. /*
  266. * If we are a N-port connected to a Fabric, fixup sparam's so
  267. * logins to devices on remote loops work.
  268. */
  269. vport->fc_sparam.cmn.altBbCredit = 1;
  270. }
  271. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  272. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
  273. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
  274. ndlp->nlp_class_sup = 0;
  275. if (sp->cls1.classValid)
  276. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  277. if (sp->cls2.classValid)
  278. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  279. if (sp->cls3.classValid)
  280. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  281. if (sp->cls4.classValid)
  282. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  283. ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  284. sp->cmn.bbRcvSizeLsb;
  285. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  286. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  287. if (sp->cmn.response_multiple_NPort) {
  288. lpfc_printf_vlog(vport, KERN_WARNING,
  289. LOG_ELS | LOG_VPORT,
  290. "1816 FLOGI NPIV supported, "
  291. "response data 0x%x\n",
  292. sp->cmn.response_multiple_NPort);
  293. phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
  294. } else {
  295. /* Because we asked f/w for NPIV it still expects us
  296. to call reg_vnpid atleast for the physcial host */
  297. lpfc_printf_vlog(vport, KERN_WARNING,
  298. LOG_ELS | LOG_VPORT,
  299. "1817 Fabric does not support NPIV "
  300. "- configuring single port mode.\n");
  301. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  302. }
  303. }
  304. if ((vport->fc_prevDID != vport->fc_myDID) &&
  305. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  306. /* If our NportID changed, we need to ensure all
  307. * remaining NPORTs get unreg_login'ed.
  308. */
  309. list_for_each_entry_safe(np, next_np,
  310. &vport->fc_nodes, nlp_listp) {
  311. if ((np->nlp_state != NLP_STE_NPR_NODE) ||
  312. !(np->nlp_flag & NLP_NPR_ADISC))
  313. continue;
  314. spin_lock_irq(shost->host_lock);
  315. np->nlp_flag &= ~NLP_NPR_ADISC;
  316. spin_unlock_irq(shost->host_lock);
  317. lpfc_unreg_rpi(vport, np);
  318. }
  319. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  320. lpfc_mbx_unreg_vpi(vport);
  321. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  322. }
  323. }
  324. ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
  325. lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
  326. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
  327. vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
  328. lpfc_register_new_vport(phba, vport, ndlp);
  329. return 0;
  330. }
  331. lpfc_issue_fabric_reglogin(vport);
  332. return 0;
  333. }
  334. /*
  335. * We FLOGIed into an NPort, initiate pt2pt protocol
  336. */
  337. static int
  338. lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  339. struct serv_parm *sp)
  340. {
  341. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  342. struct lpfc_hba *phba = vport->phba;
  343. LPFC_MBOXQ_t *mbox;
  344. int rc;
  345. spin_lock_irq(shost->host_lock);
  346. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  347. spin_unlock_irq(shost->host_lock);
  348. phba->fc_edtov = FF_DEF_EDTOV;
  349. phba->fc_ratov = FF_DEF_RATOV;
  350. rc = memcmp(&vport->fc_portname, &sp->portName,
  351. sizeof(vport->fc_portname));
  352. if (rc >= 0) {
  353. /* This side will initiate the PLOGI */
  354. spin_lock_irq(shost->host_lock);
  355. vport->fc_flag |= FC_PT2PT_PLOGI;
  356. spin_unlock_irq(shost->host_lock);
  357. /*
  358. * N_Port ID cannot be 0, set our to LocalID the other
  359. * side will be RemoteID.
  360. */
  361. /* not equal */
  362. if (rc)
  363. vport->fc_myDID = PT2PT_LocalID;
  364. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  365. if (!mbox)
  366. goto fail;
  367. lpfc_config_link(phba, mbox);
  368. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  369. mbox->vport = vport;
  370. rc = lpfc_sli_issue_mbox(phba, mbox,
  371. MBX_NOWAIT | MBX_STOP_IOCB);
  372. if (rc == MBX_NOT_FINISHED) {
  373. mempool_free(mbox, phba->mbox_mem_pool);
  374. goto fail;
  375. }
  376. lpfc_nlp_put(ndlp);
  377. ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
  378. if (!ndlp) {
  379. /*
  380. * Cannot find existing Fabric ndlp, so allocate a
  381. * new one
  382. */
  383. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  384. if (!ndlp)
  385. goto fail;
  386. lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
  387. }
  388. memcpy(&ndlp->nlp_portname, &sp->portName,
  389. sizeof(struct lpfc_name));
  390. memcpy(&ndlp->nlp_nodename, &sp->nodeName,
  391. sizeof(struct lpfc_name));
  392. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  393. spin_lock_irq(shost->host_lock);
  394. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  395. spin_unlock_irq(shost->host_lock);
  396. } else {
  397. /* This side will wait for the PLOGI */
  398. lpfc_nlp_put(ndlp);
  399. }
  400. spin_lock_irq(shost->host_lock);
  401. vport->fc_flag |= FC_PT2PT;
  402. spin_unlock_irq(shost->host_lock);
  403. /* Start discovery - this should just do CLEAR_LA */
  404. lpfc_disc_start(vport);
  405. return 0;
  406. fail:
  407. return -ENXIO;
  408. }
  409. static void
  410. lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  411. struct lpfc_iocbq *rspiocb)
  412. {
  413. struct lpfc_vport *vport = cmdiocb->vport;
  414. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  415. IOCB_t *irsp = &rspiocb->iocb;
  416. struct lpfc_nodelist *ndlp = cmdiocb->context1;
  417. struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
  418. struct serv_parm *sp;
  419. int rc;
  420. /* Check to see if link went down during discovery */
  421. if (lpfc_els_chk_latt(vport)) {
  422. lpfc_nlp_put(ndlp);
  423. goto out;
  424. }
  425. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  426. "FLOGI cmpl: status:x%x/x%x state:x%x",
  427. irsp->ulpStatus, irsp->un.ulpWord[4],
  428. vport->port_state);
  429. if (irsp->ulpStatus) {
  430. /* Check for retry */
  431. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  432. goto out;
  433. /* FLOGI failed, so there is no fabric */
  434. spin_lock_irq(shost->host_lock);
  435. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  436. spin_unlock_irq(shost->host_lock);
  437. /* If private loop, then allow max outstanding els to be
  438. * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
  439. * alpa map would take too long otherwise.
  440. */
  441. if (phba->alpa_map[0] == 0) {
  442. vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
  443. }
  444. /* FLOGI failure */
  445. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  446. "0100 FLOGI failure Data: x%x x%x "
  447. "x%x\n",
  448. irsp->ulpStatus, irsp->un.ulpWord[4],
  449. irsp->ulpTimeout);
  450. goto flogifail;
  451. }
  452. /*
  453. * The FLogI succeeded. Sync the data for the CPU before
  454. * accessing it.
  455. */
  456. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  457. sp = prsp->virt + sizeof(uint32_t);
  458. /* FLOGI completes successfully */
  459. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  460. "0101 FLOGI completes sucessfully "
  461. "Data: x%x x%x x%x x%x\n",
  462. irsp->un.ulpWord[4], sp->cmn.e_d_tov,
  463. sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
  464. if (vport->port_state == LPFC_FLOGI) {
  465. /*
  466. * If Common Service Parameters indicate Nport
  467. * we are point to point, if Fport we are Fabric.
  468. */
  469. if (sp->cmn.fPort)
  470. rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
  471. else
  472. rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
  473. if (!rc)
  474. goto out;
  475. }
  476. flogifail:
  477. lpfc_nlp_put(ndlp);
  478. if (!lpfc_error_lost_link(irsp)) {
  479. /* FLOGI failed, so just use loop map to make discovery list */
  480. lpfc_disc_list_loopmap(vport);
  481. /* Start discovery */
  482. lpfc_disc_start(vport);
  483. }
  484. out:
  485. lpfc_els_free_iocb(phba, cmdiocb);
  486. }
  487. static int
  488. lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  489. uint8_t retry)
  490. {
  491. struct lpfc_hba *phba = vport->phba;
  492. struct serv_parm *sp;
  493. IOCB_t *icmd;
  494. struct lpfc_iocbq *elsiocb;
  495. struct lpfc_sli_ring *pring;
  496. uint8_t *pcmd;
  497. uint16_t cmdsize;
  498. uint32_t tmo;
  499. int rc;
  500. pring = &phba->sli.ring[LPFC_ELS_RING];
  501. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  502. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  503. ndlp->nlp_DID, ELS_CMD_FLOGI);
  504. if (!elsiocb)
  505. return 1;
  506. icmd = &elsiocb->iocb;
  507. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  508. /* For FLOGI request, remainder of payload is service parameters */
  509. *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
  510. pcmd += sizeof(uint32_t);
  511. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  512. sp = (struct serv_parm *) pcmd;
  513. /* Setup CSPs accordingly for Fabric */
  514. sp->cmn.e_d_tov = 0;
  515. sp->cmn.w2.r_a_tov = 0;
  516. sp->cls1.classValid = 0;
  517. sp->cls2.seqDelivery = 1;
  518. sp->cls3.seqDelivery = 1;
  519. if (sp->cmn.fcphLow < FC_PH3)
  520. sp->cmn.fcphLow = FC_PH3;
  521. if (sp->cmn.fcphHigh < FC_PH3)
  522. sp->cmn.fcphHigh = FC_PH3;
  523. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  524. sp->cmn.request_multiple_Nport = 1;
  525. /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
  526. icmd->ulpCt_h = 1;
  527. icmd->ulpCt_l = 0;
  528. }
  529. if (phba->fc_topology != TOPOLOGY_LOOP) {
  530. icmd->un.elsreq64.myID = 0;
  531. icmd->un.elsreq64.fl = 1;
  532. }
  533. tmo = phba->fc_ratov;
  534. phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
  535. lpfc_set_disctmo(vport);
  536. phba->fc_ratov = tmo;
  537. phba->fc_stat.elsXmitFLOGI++;
  538. elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
  539. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  540. "Issue FLOGI: opt:x%x",
  541. phba->sli3_options, 0, 0);
  542. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  543. if (rc == IOCB_ERROR) {
  544. lpfc_els_free_iocb(phba, elsiocb);
  545. return 1;
  546. }
  547. return 0;
  548. }
  549. int
  550. lpfc_els_abort_flogi(struct lpfc_hba *phba)
  551. {
  552. struct lpfc_sli_ring *pring;
  553. struct lpfc_iocbq *iocb, *next_iocb;
  554. struct lpfc_nodelist *ndlp;
  555. IOCB_t *icmd;
  556. /* Abort outstanding I/O on NPort <nlp_DID> */
  557. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  558. "0201 Abort outstanding I/O on NPort x%x\n",
  559. Fabric_DID);
  560. pring = &phba->sli.ring[LPFC_ELS_RING];
  561. /*
  562. * Check the txcmplq for an iocb that matches the nport the driver is
  563. * searching for.
  564. */
  565. spin_lock_irq(&phba->hbalock);
  566. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  567. icmd = &iocb->iocb;
  568. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
  569. icmd->un.elsreq64.bdl.ulpIoTag32) {
  570. ndlp = (struct lpfc_nodelist *)(iocb->context1);
  571. if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
  572. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  573. }
  574. }
  575. }
  576. spin_unlock_irq(&phba->hbalock);
  577. return 0;
  578. }
  579. int
  580. lpfc_initial_flogi(struct lpfc_vport *vport)
  581. {
  582. struct lpfc_hba *phba = vport->phba;
  583. struct lpfc_nodelist *ndlp;
  584. /* First look for the Fabric ndlp */
  585. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  586. if (!ndlp) {
  587. /* Cannot find existing Fabric ndlp, so allocate a new one */
  588. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  589. if (!ndlp)
  590. return 0;
  591. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  592. } else {
  593. lpfc_dequeue_node(vport, ndlp);
  594. }
  595. if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
  596. lpfc_nlp_put(ndlp);
  597. }
  598. return 1;
  599. }
  600. int
  601. lpfc_initial_fdisc(struct lpfc_vport *vport)
  602. {
  603. struct lpfc_hba *phba = vport->phba;
  604. struct lpfc_nodelist *ndlp;
  605. /* First look for the Fabric ndlp */
  606. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  607. if (!ndlp) {
  608. /* Cannot find existing Fabric ndlp, so allocate a new one */
  609. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  610. if (!ndlp)
  611. return 0;
  612. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  613. } else {
  614. lpfc_dequeue_node(vport, ndlp);
  615. }
  616. if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
  617. lpfc_nlp_put(ndlp);
  618. }
  619. return 1;
  620. }
  621. static void
  622. lpfc_more_plogi(struct lpfc_vport *vport)
  623. {
  624. int sentplogi;
  625. if (vport->num_disc_nodes)
  626. vport->num_disc_nodes--;
  627. /* Continue discovery with <num_disc_nodes> PLOGIs to go */
  628. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  629. "0232 Continue discovery with %d PLOGIs to go "
  630. "Data: x%x x%x x%x\n",
  631. vport->num_disc_nodes, vport->fc_plogi_cnt,
  632. vport->fc_flag, vport->port_state);
  633. /* Check to see if there are more PLOGIs to be sent */
  634. if (vport->fc_flag & FC_NLP_MORE)
  635. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  636. sentplogi = lpfc_els_disc_plogi(vport);
  637. return;
  638. }
  639. static struct lpfc_nodelist *
  640. lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
  641. struct lpfc_nodelist *ndlp)
  642. {
  643. struct lpfc_vport *vport = ndlp->vport;
  644. struct lpfc_nodelist *new_ndlp;
  645. struct serv_parm *sp;
  646. uint8_t name[sizeof(struct lpfc_name)];
  647. uint32_t rc;
  648. /* Fabric nodes can have the same WWPN so we don't bother searching
  649. * by WWPN. Just return the ndlp that was given to us.
  650. */
  651. if (ndlp->nlp_type & NLP_FABRIC)
  652. return ndlp;
  653. sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
  654. memset(name, 0, sizeof(struct lpfc_name));
  655. /* Now we find out if the NPort we are logging into, matches the WWPN
  656. * we have for that ndlp. If not, we have some work to do.
  657. */
  658. new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
  659. if (new_ndlp == ndlp)
  660. return ndlp;
  661. if (!new_ndlp) {
  662. rc = memcmp(&ndlp->nlp_portname, name,
  663. sizeof(struct lpfc_name));
  664. if (!rc)
  665. return ndlp;
  666. new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
  667. if (!new_ndlp)
  668. return ndlp;
  669. lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
  670. }
  671. lpfc_unreg_rpi(vport, new_ndlp);
  672. new_ndlp->nlp_DID = ndlp->nlp_DID;
  673. new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
  674. lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
  675. /* Move this back to NPR state */
  676. if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0)
  677. lpfc_drop_node(vport, ndlp);
  678. else {
  679. lpfc_unreg_rpi(vport, ndlp);
  680. ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
  681. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  682. }
  683. return new_ndlp;
  684. }
  685. static void
  686. lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  687. struct lpfc_iocbq *rspiocb)
  688. {
  689. struct lpfc_vport *vport = cmdiocb->vport;
  690. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  691. IOCB_t *irsp;
  692. struct lpfc_nodelist *ndlp;
  693. struct lpfc_dmabuf *prsp;
  694. int disc, rc, did, type;
  695. /* we pass cmdiocb to state machine which needs rspiocb as well */
  696. cmdiocb->context_un.rsp_iocb = rspiocb;
  697. irsp = &rspiocb->iocb;
  698. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  699. "PLOGI cmpl: status:x%x/x%x did:x%x",
  700. irsp->ulpStatus, irsp->un.ulpWord[4],
  701. irsp->un.elsreq64.remoteID);
  702. ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
  703. if (!ndlp) {
  704. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  705. "0136 PLOGI completes to NPort x%x "
  706. "with no ndlp. Data: x%x x%x x%x\n",
  707. irsp->un.elsreq64.remoteID,
  708. irsp->ulpStatus, irsp->un.ulpWord[4],
  709. irsp->ulpIoTag);
  710. goto out;
  711. }
  712. /* Since ndlp can be freed in the disc state machine, note if this node
  713. * is being used during discovery.
  714. */
  715. spin_lock_irq(shost->host_lock);
  716. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  717. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  718. spin_unlock_irq(shost->host_lock);
  719. rc = 0;
  720. /* PLOGI completes to NPort <nlp_DID> */
  721. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  722. "0102 PLOGI completes to NPort x%x "
  723. "Data: x%x x%x x%x x%x x%x\n",
  724. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  725. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  726. /* Check to see if link went down during discovery */
  727. if (lpfc_els_chk_latt(vport)) {
  728. spin_lock_irq(shost->host_lock);
  729. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  730. spin_unlock_irq(shost->host_lock);
  731. goto out;
  732. }
  733. /* ndlp could be freed in DSM, save these values now */
  734. type = ndlp->nlp_type;
  735. did = ndlp->nlp_DID;
  736. if (irsp->ulpStatus) {
  737. /* Check for retry */
  738. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  739. /* ELS command is being retried */
  740. if (disc) {
  741. spin_lock_irq(shost->host_lock);
  742. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  743. spin_unlock_irq(shost->host_lock);
  744. }
  745. goto out;
  746. }
  747. /* PLOGI failed */
  748. if (ndlp->nlp_DID == NameServer_DID) {
  749. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  750. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  751. "0250 Nameserver login error: "
  752. "0x%x / 0x%x\n",
  753. irsp->ulpStatus, irsp->un.ulpWord[4]);
  754. }
  755. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  756. if (lpfc_error_lost_link(irsp)) {
  757. rc = NLP_STE_FREED_NODE;
  758. } else {
  759. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  760. NLP_EVT_CMPL_PLOGI);
  761. }
  762. } else {
  763. /* Good status, call state machine */
  764. prsp = list_entry(((struct lpfc_dmabuf *)
  765. cmdiocb->context2)->list.next,
  766. struct lpfc_dmabuf, list);
  767. ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
  768. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  769. NLP_EVT_CMPL_PLOGI);
  770. }
  771. if (disc && vport->num_disc_nodes) {
  772. /* Check to see if there are more PLOGIs to be sent */
  773. lpfc_more_plogi(vport);
  774. if (vport->num_disc_nodes == 0) {
  775. spin_lock_irq(shost->host_lock);
  776. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  777. spin_unlock_irq(shost->host_lock);
  778. lpfc_can_disctmo(vport);
  779. if (vport->fc_flag & FC_RSCN_MODE) {
  780. /*
  781. * Check to see if more RSCNs came in while
  782. * we were processing this one.
  783. */
  784. if ((vport->fc_rscn_id_cnt == 0) &&
  785. (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
  786. spin_lock_irq(shost->host_lock);
  787. vport->fc_flag &= ~FC_RSCN_MODE;
  788. spin_unlock_irq(shost->host_lock);
  789. } else {
  790. lpfc_els_handle_rscn(vport);
  791. }
  792. }
  793. }
  794. }
  795. out:
  796. lpfc_els_free_iocb(phba, cmdiocb);
  797. return;
  798. }
  799. int
  800. lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
  801. {
  802. struct lpfc_hba *phba = vport->phba;
  803. struct serv_parm *sp;
  804. IOCB_t *icmd;
  805. struct lpfc_iocbq *elsiocb;
  806. struct lpfc_sli_ring *pring;
  807. struct lpfc_sli *psli;
  808. uint8_t *pcmd;
  809. uint16_t cmdsize;
  810. int ret;
  811. psli = &phba->sli;
  812. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  813. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  814. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, NULL, did,
  815. ELS_CMD_PLOGI);
  816. if (!elsiocb)
  817. return 1;
  818. icmd = &elsiocb->iocb;
  819. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  820. /* For PLOGI request, remainder of payload is service parameters */
  821. *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
  822. pcmd += sizeof(uint32_t);
  823. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  824. sp = (struct serv_parm *) pcmd;
  825. if (sp->cmn.fcphLow < FC_PH_4_3)
  826. sp->cmn.fcphLow = FC_PH_4_3;
  827. if (sp->cmn.fcphHigh < FC_PH3)
  828. sp->cmn.fcphHigh = FC_PH3;
  829. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  830. "Issue PLOGI: did:x%x",
  831. did, 0, 0);
  832. phba->fc_stat.elsXmitPLOGI++;
  833. elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
  834. ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  835. if (ret == IOCB_ERROR) {
  836. lpfc_els_free_iocb(phba, elsiocb);
  837. return 1;
  838. }
  839. return 0;
  840. }
  841. static void
  842. lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  843. struct lpfc_iocbq *rspiocb)
  844. {
  845. struct lpfc_vport *vport = cmdiocb->vport;
  846. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  847. IOCB_t *irsp;
  848. struct lpfc_sli *psli;
  849. struct lpfc_nodelist *ndlp;
  850. psli = &phba->sli;
  851. /* we pass cmdiocb to state machine which needs rspiocb as well */
  852. cmdiocb->context_un.rsp_iocb = rspiocb;
  853. irsp = &(rspiocb->iocb);
  854. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  855. spin_lock_irq(shost->host_lock);
  856. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  857. spin_unlock_irq(shost->host_lock);
  858. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  859. "PRLI cmpl: status:x%x/x%x did:x%x",
  860. irsp->ulpStatus, irsp->un.ulpWord[4],
  861. ndlp->nlp_DID);
  862. /* PRLI completes to NPort <nlp_DID> */
  863. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  864. "0103 PRLI completes to NPort x%x "
  865. "Data: x%x x%x x%x x%x\n",
  866. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  867. irsp->ulpTimeout, vport->num_disc_nodes);
  868. vport->fc_prli_sent--;
  869. /* Check to see if link went down during discovery */
  870. if (lpfc_els_chk_latt(vport))
  871. goto out;
  872. if (irsp->ulpStatus) {
  873. /* Check for retry */
  874. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  875. /* ELS command is being retried */
  876. goto out;
  877. }
  878. /* PRLI failed */
  879. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  880. if (lpfc_error_lost_link(irsp)) {
  881. goto out;
  882. } else {
  883. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  884. NLP_EVT_CMPL_PRLI);
  885. }
  886. } else {
  887. /* Good status, call state machine */
  888. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  889. NLP_EVT_CMPL_PRLI);
  890. }
  891. out:
  892. lpfc_els_free_iocb(phba, cmdiocb);
  893. return;
  894. }
  895. int
  896. lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  897. uint8_t retry)
  898. {
  899. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  900. struct lpfc_hba *phba = vport->phba;
  901. PRLI *npr;
  902. IOCB_t *icmd;
  903. struct lpfc_iocbq *elsiocb;
  904. struct lpfc_sli_ring *pring;
  905. struct lpfc_sli *psli;
  906. uint8_t *pcmd;
  907. uint16_t cmdsize;
  908. psli = &phba->sli;
  909. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  910. cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
  911. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  912. ndlp->nlp_DID, ELS_CMD_PRLI);
  913. if (!elsiocb)
  914. return 1;
  915. icmd = &elsiocb->iocb;
  916. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  917. /* For PRLI request, remainder of payload is service parameters */
  918. memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
  919. *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
  920. pcmd += sizeof(uint32_t);
  921. /* For PRLI, remainder of payload is PRLI parameter page */
  922. npr = (PRLI *) pcmd;
  923. /*
  924. * If our firmware version is 3.20 or later,
  925. * set the following bits for FC-TAPE support.
  926. */
  927. if (phba->vpd.rev.feaLevelHigh >= 0x02) {
  928. npr->ConfmComplAllowed = 1;
  929. npr->Retry = 1;
  930. npr->TaskRetryIdReq = 1;
  931. }
  932. npr->estabImagePair = 1;
  933. npr->readXferRdyDis = 1;
  934. /* For FCP support */
  935. npr->prliType = PRLI_FCP_TYPE;
  936. npr->initiatorFunc = 1;
  937. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  938. "Issue PRLI: did:x%x",
  939. ndlp->nlp_DID, 0, 0);
  940. phba->fc_stat.elsXmitPRLI++;
  941. elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
  942. spin_lock_irq(shost->host_lock);
  943. ndlp->nlp_flag |= NLP_PRLI_SND;
  944. spin_unlock_irq(shost->host_lock);
  945. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  946. spin_lock_irq(shost->host_lock);
  947. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  948. spin_unlock_irq(shost->host_lock);
  949. lpfc_els_free_iocb(phba, elsiocb);
  950. return 1;
  951. }
  952. vport->fc_prli_sent++;
  953. return 0;
  954. }
  955. static void
  956. lpfc_more_adisc(struct lpfc_vport *vport)
  957. {
  958. int sentadisc;
  959. if (vport->num_disc_nodes)
  960. vport->num_disc_nodes--;
  961. /* Continue discovery with <num_disc_nodes> ADISCs to go */
  962. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  963. "0210 Continue discovery with %d ADISCs to go "
  964. "Data: x%x x%x x%x\n",
  965. vport->num_disc_nodes, vport->fc_adisc_cnt,
  966. vport->fc_flag, vport->port_state);
  967. /* Check to see if there are more ADISCs to be sent */
  968. if (vport->fc_flag & FC_NLP_MORE) {
  969. lpfc_set_disctmo(vport);
  970. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  971. sentadisc = lpfc_els_disc_adisc(vport);
  972. }
  973. return;
  974. }
  975. static void
  976. lpfc_rscn_disc(struct lpfc_vport *vport)
  977. {
  978. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  979. lpfc_can_disctmo(vport);
  980. /* RSCN discovery */
  981. /* go thru NPR nodes and issue ELS PLOGIs */
  982. if (vport->fc_npr_cnt)
  983. if (lpfc_els_disc_plogi(vport))
  984. return;
  985. if (vport->fc_flag & FC_RSCN_MODE) {
  986. /* Check to see if more RSCNs came in while we were
  987. * processing this one.
  988. */
  989. if ((vport->fc_rscn_id_cnt == 0) &&
  990. (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
  991. spin_lock_irq(shost->host_lock);
  992. vport->fc_flag &= ~FC_RSCN_MODE;
  993. spin_unlock_irq(shost->host_lock);
  994. } else {
  995. lpfc_els_handle_rscn(vport);
  996. }
  997. }
  998. }
  999. static void
  1000. lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1001. struct lpfc_iocbq *rspiocb)
  1002. {
  1003. struct lpfc_vport *vport = cmdiocb->vport;
  1004. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1005. IOCB_t *irsp;
  1006. struct lpfc_nodelist *ndlp;
  1007. int disc;
  1008. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1009. cmdiocb->context_un.rsp_iocb = rspiocb;
  1010. irsp = &(rspiocb->iocb);
  1011. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1012. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1013. "ADISC cmpl: status:x%x/x%x did:x%x",
  1014. irsp->ulpStatus, irsp->un.ulpWord[4],
  1015. ndlp->nlp_DID);
  1016. /* Since ndlp can be freed in the disc state machine, note if this node
  1017. * is being used during discovery.
  1018. */
  1019. spin_lock_irq(shost->host_lock);
  1020. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  1021. ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
  1022. spin_unlock_irq(shost->host_lock);
  1023. /* ADISC completes to NPort <nlp_DID> */
  1024. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1025. "0104 ADISC completes to NPort x%x "
  1026. "Data: x%x x%x x%x x%x x%x\n",
  1027. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1028. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  1029. /* Check to see if link went down during discovery */
  1030. if (lpfc_els_chk_latt(vport)) {
  1031. spin_lock_irq(shost->host_lock);
  1032. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1033. spin_unlock_irq(shost->host_lock);
  1034. goto out;
  1035. }
  1036. if (irsp->ulpStatus) {
  1037. /* Check for retry */
  1038. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1039. /* ELS command is being retried */
  1040. if (disc) {
  1041. spin_lock_irq(shost->host_lock);
  1042. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1043. spin_unlock_irq(shost->host_lock);
  1044. lpfc_set_disctmo(vport);
  1045. }
  1046. goto out;
  1047. }
  1048. /* ADISC failed */
  1049. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1050. if (!lpfc_error_lost_link(irsp)) {
  1051. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1052. NLP_EVT_CMPL_ADISC);
  1053. }
  1054. } else {
  1055. /* Good status, call state machine */
  1056. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1057. NLP_EVT_CMPL_ADISC);
  1058. }
  1059. if (disc && vport->num_disc_nodes) {
  1060. /* Check to see if there are more ADISCs to be sent */
  1061. lpfc_more_adisc(vport);
  1062. /* Check to see if we are done with ADISC authentication */
  1063. if (vport->num_disc_nodes == 0) {
  1064. /* If we get here, there is nothing left to ADISC */
  1065. /*
  1066. * For NPIV, cmpl_reg_vpi will set port_state to READY,
  1067. * and continue discovery.
  1068. */
  1069. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1070. !(vport->fc_flag & FC_RSCN_MODE)) {
  1071. lpfc_issue_reg_vpi(phba, vport);
  1072. goto out;
  1073. }
  1074. /*
  1075. * For SLI2, we need to set port_state to READY
  1076. * and continue discovery.
  1077. */
  1078. if (vport->port_state < LPFC_VPORT_READY) {
  1079. /* If we get here, there is nothing to ADISC */
  1080. if (vport->port_type == LPFC_PHYSICAL_PORT)
  1081. lpfc_issue_clear_la(phba, vport);
  1082. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  1083. vport->num_disc_nodes = 0;
  1084. /* go thru NPR list, issue ELS PLOGIs */
  1085. if (vport->fc_npr_cnt)
  1086. lpfc_els_disc_plogi(vport);
  1087. if (!vport->num_disc_nodes) {
  1088. spin_lock_irq(shost->host_lock);
  1089. vport->fc_flag &=
  1090. ~FC_NDISC_ACTIVE;
  1091. spin_unlock_irq(
  1092. shost->host_lock);
  1093. lpfc_can_disctmo(vport);
  1094. }
  1095. }
  1096. vport->port_state = LPFC_VPORT_READY;
  1097. } else {
  1098. lpfc_rscn_disc(vport);
  1099. }
  1100. }
  1101. }
  1102. out:
  1103. lpfc_els_free_iocb(phba, cmdiocb);
  1104. return;
  1105. }
  1106. int
  1107. lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1108. uint8_t retry)
  1109. {
  1110. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1111. struct lpfc_hba *phba = vport->phba;
  1112. ADISC *ap;
  1113. IOCB_t *icmd;
  1114. struct lpfc_iocbq *elsiocb;
  1115. struct lpfc_sli *psli = &phba->sli;
  1116. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  1117. uint8_t *pcmd;
  1118. uint16_t cmdsize;
  1119. cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
  1120. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1121. ndlp->nlp_DID, ELS_CMD_ADISC);
  1122. if (!elsiocb)
  1123. return 1;
  1124. icmd = &elsiocb->iocb;
  1125. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1126. /* For ADISC request, remainder of payload is service parameters */
  1127. *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
  1128. pcmd += sizeof(uint32_t);
  1129. /* Fill in ADISC payload */
  1130. ap = (ADISC *) pcmd;
  1131. ap->hardAL_PA = phba->fc_pref_ALPA;
  1132. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  1133. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  1134. ap->DID = be32_to_cpu(vport->fc_myDID);
  1135. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1136. "Issue ADISC: did:x%x",
  1137. ndlp->nlp_DID, 0, 0);
  1138. phba->fc_stat.elsXmitADISC++;
  1139. elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
  1140. spin_lock_irq(shost->host_lock);
  1141. ndlp->nlp_flag |= NLP_ADISC_SND;
  1142. spin_unlock_irq(shost->host_lock);
  1143. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1144. spin_lock_irq(shost->host_lock);
  1145. ndlp->nlp_flag &= ~NLP_ADISC_SND;
  1146. spin_unlock_irq(shost->host_lock);
  1147. lpfc_els_free_iocb(phba, elsiocb);
  1148. return 1;
  1149. }
  1150. return 0;
  1151. }
  1152. static void
  1153. lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1154. struct lpfc_iocbq *rspiocb)
  1155. {
  1156. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1157. struct lpfc_vport *vport = ndlp->vport;
  1158. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1159. IOCB_t *irsp;
  1160. struct lpfc_sli *psli;
  1161. psli = &phba->sli;
  1162. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1163. cmdiocb->context_un.rsp_iocb = rspiocb;
  1164. irsp = &(rspiocb->iocb);
  1165. spin_lock_irq(shost->host_lock);
  1166. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  1167. spin_unlock_irq(shost->host_lock);
  1168. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1169. "LOGO cmpl: status:x%x/x%x did:x%x",
  1170. irsp->ulpStatus, irsp->un.ulpWord[4],
  1171. ndlp->nlp_DID);
  1172. /* LOGO completes to NPort <nlp_DID> */
  1173. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1174. "0105 LOGO completes to NPort x%x "
  1175. "Data: x%x x%x x%x x%x\n",
  1176. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1177. irsp->ulpTimeout, vport->num_disc_nodes);
  1178. /* Check to see if link went down during discovery */
  1179. if (lpfc_els_chk_latt(vport))
  1180. goto out;
  1181. if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
  1182. /* NLP_EVT_DEVICE_RM should unregister the RPI
  1183. * which should abort all outstanding IOs.
  1184. */
  1185. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1186. NLP_EVT_DEVICE_RM);
  1187. goto out;
  1188. }
  1189. if (irsp->ulpStatus) {
  1190. /* Check for retry */
  1191. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  1192. /* ELS command is being retried */
  1193. goto out;
  1194. /* LOGO failed */
  1195. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1196. if (lpfc_error_lost_link(irsp))
  1197. goto out;
  1198. else
  1199. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1200. NLP_EVT_CMPL_LOGO);
  1201. } else {
  1202. /* Good status, call state machine.
  1203. * This will unregister the rpi if needed.
  1204. */
  1205. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1206. NLP_EVT_CMPL_LOGO);
  1207. }
  1208. out:
  1209. lpfc_els_free_iocb(phba, cmdiocb);
  1210. return;
  1211. }
  1212. int
  1213. lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1214. uint8_t retry)
  1215. {
  1216. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1217. struct lpfc_hba *phba = vport->phba;
  1218. IOCB_t *icmd;
  1219. struct lpfc_iocbq *elsiocb;
  1220. struct lpfc_sli_ring *pring;
  1221. struct lpfc_sli *psli;
  1222. uint8_t *pcmd;
  1223. uint16_t cmdsize;
  1224. int rc;
  1225. psli = &phba->sli;
  1226. pring = &psli->ring[LPFC_ELS_RING];
  1227. cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
  1228. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1229. ndlp->nlp_DID, ELS_CMD_LOGO);
  1230. if (!elsiocb)
  1231. return 1;
  1232. icmd = &elsiocb->iocb;
  1233. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1234. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  1235. pcmd += sizeof(uint32_t);
  1236. /* Fill in LOGO payload */
  1237. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  1238. pcmd += sizeof(uint32_t);
  1239. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  1240. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1241. "Issue LOGO: did:x%x",
  1242. ndlp->nlp_DID, 0, 0);
  1243. phba->fc_stat.elsXmitLOGO++;
  1244. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
  1245. spin_lock_irq(shost->host_lock);
  1246. ndlp->nlp_flag |= NLP_LOGO_SND;
  1247. spin_unlock_irq(shost->host_lock);
  1248. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  1249. if (rc == IOCB_ERROR) {
  1250. spin_lock_irq(shost->host_lock);
  1251. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  1252. spin_unlock_irq(shost->host_lock);
  1253. lpfc_els_free_iocb(phba, elsiocb);
  1254. return 1;
  1255. }
  1256. return 0;
  1257. }
  1258. static void
  1259. lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1260. struct lpfc_iocbq *rspiocb)
  1261. {
  1262. struct lpfc_vport *vport = cmdiocb->vport;
  1263. IOCB_t *irsp;
  1264. irsp = &rspiocb->iocb;
  1265. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1266. "ELS cmd cmpl: status:x%x/x%x did:x%x",
  1267. irsp->ulpStatus, irsp->un.ulpWord[4],
  1268. irsp->un.elsreq64.remoteID);
  1269. /* ELS cmd tag <ulpIoTag> completes */
  1270. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1271. "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
  1272. irsp->ulpIoTag, irsp->ulpStatus,
  1273. irsp->un.ulpWord[4], irsp->ulpTimeout);
  1274. /* Check to see if link went down during discovery */
  1275. lpfc_els_chk_latt(vport);
  1276. lpfc_els_free_iocb(phba, cmdiocb);
  1277. return;
  1278. }
  1279. int
  1280. lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  1281. {
  1282. struct lpfc_hba *phba = vport->phba;
  1283. IOCB_t *icmd;
  1284. struct lpfc_iocbq *elsiocb;
  1285. struct lpfc_sli_ring *pring;
  1286. struct lpfc_sli *psli;
  1287. uint8_t *pcmd;
  1288. uint16_t cmdsize;
  1289. struct lpfc_nodelist *ndlp;
  1290. psli = &phba->sli;
  1291. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1292. cmdsize = (sizeof(uint32_t) + sizeof(SCR));
  1293. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1294. if (!ndlp)
  1295. return 1;
  1296. lpfc_nlp_init(vport, ndlp, nportid);
  1297. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1298. ndlp->nlp_DID, ELS_CMD_SCR);
  1299. if (!elsiocb) {
  1300. lpfc_nlp_put(ndlp);
  1301. return 1;
  1302. }
  1303. icmd = &elsiocb->iocb;
  1304. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1305. *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
  1306. pcmd += sizeof(uint32_t);
  1307. /* For SCR, remainder of payload is SCR parameter page */
  1308. memset(pcmd, 0, sizeof(SCR));
  1309. ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
  1310. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1311. "Issue SCR: did:x%x",
  1312. ndlp->nlp_DID, 0, 0);
  1313. phba->fc_stat.elsXmitSCR++;
  1314. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  1315. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1316. lpfc_nlp_put(ndlp);
  1317. lpfc_els_free_iocb(phba, elsiocb);
  1318. return 1;
  1319. }
  1320. lpfc_nlp_put(ndlp);
  1321. return 0;
  1322. }
  1323. static int
  1324. lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  1325. {
  1326. struct lpfc_hba *phba = vport->phba;
  1327. IOCB_t *icmd;
  1328. struct lpfc_iocbq *elsiocb;
  1329. struct lpfc_sli_ring *pring;
  1330. struct lpfc_sli *psli;
  1331. FARP *fp;
  1332. uint8_t *pcmd;
  1333. uint32_t *lp;
  1334. uint16_t cmdsize;
  1335. struct lpfc_nodelist *ondlp;
  1336. struct lpfc_nodelist *ndlp;
  1337. psli = &phba->sli;
  1338. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1339. cmdsize = (sizeof(uint32_t) + sizeof(FARP));
  1340. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1341. if (!ndlp)
  1342. return 1;
  1343. lpfc_nlp_init(vport, ndlp, nportid);
  1344. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1345. ndlp->nlp_DID, ELS_CMD_RNID);
  1346. if (!elsiocb) {
  1347. lpfc_nlp_put(ndlp);
  1348. return 1;
  1349. }
  1350. icmd = &elsiocb->iocb;
  1351. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1352. *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
  1353. pcmd += sizeof(uint32_t);
  1354. /* Fill in FARPR payload */
  1355. fp = (FARP *) (pcmd);
  1356. memset(fp, 0, sizeof(FARP));
  1357. lp = (uint32_t *) pcmd;
  1358. *lp++ = be32_to_cpu(nportid);
  1359. *lp++ = be32_to_cpu(vport->fc_myDID);
  1360. fp->Rflags = 0;
  1361. fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
  1362. memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
  1363. memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  1364. ondlp = lpfc_findnode_did(vport, nportid);
  1365. if (ondlp) {
  1366. memcpy(&fp->OportName, &ondlp->nlp_portname,
  1367. sizeof(struct lpfc_name));
  1368. memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
  1369. sizeof(struct lpfc_name));
  1370. }
  1371. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1372. "Issue FARPR: did:x%x",
  1373. ndlp->nlp_DID, 0, 0);
  1374. phba->fc_stat.elsXmitFARPR++;
  1375. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  1376. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1377. lpfc_nlp_put(ndlp);
  1378. lpfc_els_free_iocb(phba, elsiocb);
  1379. return 1;
  1380. }
  1381. lpfc_nlp_put(ndlp);
  1382. return 0;
  1383. }
  1384. static void
  1385. lpfc_end_rscn(struct lpfc_vport *vport)
  1386. {
  1387. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1388. if (vport->fc_flag & FC_RSCN_MODE) {
  1389. /*
  1390. * Check to see if more RSCNs came in while we were
  1391. * processing this one.
  1392. */
  1393. if (vport->fc_rscn_id_cnt ||
  1394. (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
  1395. lpfc_els_handle_rscn(vport);
  1396. else {
  1397. spin_lock_irq(shost->host_lock);
  1398. vport->fc_flag &= ~FC_RSCN_MODE;
  1399. spin_unlock_irq(shost->host_lock);
  1400. }
  1401. }
  1402. }
  1403. void
  1404. lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
  1405. {
  1406. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1407. spin_lock_irq(shost->host_lock);
  1408. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  1409. spin_unlock_irq(shost->host_lock);
  1410. del_timer_sync(&nlp->nlp_delayfunc);
  1411. nlp->nlp_last_elscmd = 0;
  1412. if (!list_empty(&nlp->els_retry_evt.evt_listp))
  1413. list_del_init(&nlp->els_retry_evt.evt_listp);
  1414. if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
  1415. spin_lock_irq(shost->host_lock);
  1416. nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1417. spin_unlock_irq(shost->host_lock);
  1418. if (vport->num_disc_nodes) {
  1419. /* Check to see if there are more
  1420. * PLOGIs to be sent
  1421. */
  1422. lpfc_more_plogi(vport);
  1423. if (vport->num_disc_nodes == 0) {
  1424. spin_lock_irq(shost->host_lock);
  1425. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1426. spin_unlock_irq(shost->host_lock);
  1427. lpfc_can_disctmo(vport);
  1428. lpfc_end_rscn(vport);
  1429. }
  1430. }
  1431. }
  1432. return;
  1433. }
  1434. void
  1435. lpfc_els_retry_delay(unsigned long ptr)
  1436. {
  1437. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
  1438. struct lpfc_vport *vport = ndlp->vport;
  1439. struct lpfc_hba *phba = vport->phba;
  1440. unsigned long flags;
  1441. struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
  1442. ndlp = (struct lpfc_nodelist *) ptr;
  1443. phba = ndlp->vport->phba;
  1444. evtp = &ndlp->els_retry_evt;
  1445. spin_lock_irqsave(&phba->hbalock, flags);
  1446. if (!list_empty(&evtp->evt_listp)) {
  1447. spin_unlock_irqrestore(&phba->hbalock, flags);
  1448. return;
  1449. }
  1450. evtp->evt_arg1 = ndlp;
  1451. evtp->evt = LPFC_EVT_ELS_RETRY;
  1452. list_add_tail(&evtp->evt_listp, &phba->work_list);
  1453. if (phba->work_wait)
  1454. lpfc_worker_wake_up(phba);
  1455. spin_unlock_irqrestore(&phba->hbalock, flags);
  1456. return;
  1457. }
  1458. void
  1459. lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
  1460. {
  1461. struct lpfc_vport *vport = ndlp->vport;
  1462. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1463. uint32_t cmd, did, retry;
  1464. spin_lock_irq(shost->host_lock);
  1465. did = ndlp->nlp_DID;
  1466. cmd = ndlp->nlp_last_elscmd;
  1467. ndlp->nlp_last_elscmd = 0;
  1468. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1469. spin_unlock_irq(shost->host_lock);
  1470. return;
  1471. }
  1472. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  1473. spin_unlock_irq(shost->host_lock);
  1474. /*
  1475. * If a discovery event readded nlp_delayfunc after timer
  1476. * firing and before processing the timer, cancel the
  1477. * nlp_delayfunc.
  1478. */
  1479. del_timer_sync(&ndlp->nlp_delayfunc);
  1480. retry = ndlp->nlp_retry;
  1481. switch (cmd) {
  1482. case ELS_CMD_FLOGI:
  1483. lpfc_issue_els_flogi(vport, ndlp, retry);
  1484. break;
  1485. case ELS_CMD_PLOGI:
  1486. if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
  1487. ndlp->nlp_prev_state = ndlp->nlp_state;
  1488. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  1489. }
  1490. break;
  1491. case ELS_CMD_ADISC:
  1492. if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
  1493. ndlp->nlp_prev_state = ndlp->nlp_state;
  1494. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  1495. }
  1496. break;
  1497. case ELS_CMD_PRLI:
  1498. if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
  1499. ndlp->nlp_prev_state = ndlp->nlp_state;
  1500. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  1501. }
  1502. break;
  1503. case ELS_CMD_LOGO:
  1504. if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
  1505. ndlp->nlp_prev_state = ndlp->nlp_state;
  1506. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1507. }
  1508. break;
  1509. case ELS_CMD_FDISC:
  1510. lpfc_issue_els_fdisc(vport, ndlp, retry);
  1511. break;
  1512. }
  1513. return;
  1514. }
  1515. static int
  1516. lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1517. struct lpfc_iocbq *rspiocb)
  1518. {
  1519. struct lpfc_vport *vport = cmdiocb->vport;
  1520. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1521. IOCB_t *irsp = &rspiocb->iocb;
  1522. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1523. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  1524. uint32_t *elscmd;
  1525. struct ls_rjt stat;
  1526. int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
  1527. uint32_t cmd = 0;
  1528. uint32_t did;
  1529. /* Note: context2 may be 0 for internal driver abort
  1530. * of delays ELS command.
  1531. */
  1532. if (pcmd && pcmd->virt) {
  1533. elscmd = (uint32_t *) (pcmd->virt);
  1534. cmd = *elscmd++;
  1535. }
  1536. if (ndlp)
  1537. did = ndlp->nlp_DID;
  1538. else {
  1539. /* We should only hit this case for retrying PLOGI */
  1540. did = irsp->un.elsreq64.remoteID;
  1541. ndlp = lpfc_findnode_did(vport, did);
  1542. if (!ndlp && (cmd != ELS_CMD_PLOGI))
  1543. return 1;
  1544. }
  1545. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1546. "Retry ELS: wd7:x%x wd4:x%x did:x%x",
  1547. *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
  1548. switch (irsp->ulpStatus) {
  1549. case IOSTAT_FCP_RSP_ERROR:
  1550. case IOSTAT_REMOTE_STOP:
  1551. break;
  1552. case IOSTAT_LOCAL_REJECT:
  1553. switch ((irsp->un.ulpWord[4] & 0xff)) {
  1554. case IOERR_LOOP_OPEN_FAILURE:
  1555. if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
  1556. delay = 1000;
  1557. retry = 1;
  1558. break;
  1559. case IOERR_ILLEGAL_COMMAND:
  1560. if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
  1561. (cmd == ELS_CMD_FDISC)) {
  1562. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1563. "0124 FDISC failed (3/6) "
  1564. "retrying...\n");
  1565. lpfc_mbx_unreg_vpi(vport);
  1566. retry = 1;
  1567. /* FDISC retry policy */
  1568. maxretry = 48;
  1569. if (cmdiocb->retry >= 32)
  1570. delay = 1000;
  1571. }
  1572. break;
  1573. case IOERR_NO_RESOURCES:
  1574. retry = 1;
  1575. if (cmdiocb->retry > 100)
  1576. delay = 100;
  1577. maxretry = 250;
  1578. break;
  1579. case IOERR_ILLEGAL_FRAME:
  1580. delay = 100;
  1581. retry = 1;
  1582. break;
  1583. case IOERR_SEQUENCE_TIMEOUT:
  1584. case IOERR_INVALID_RPI:
  1585. retry = 1;
  1586. break;
  1587. }
  1588. break;
  1589. case IOSTAT_NPORT_RJT:
  1590. case IOSTAT_FABRIC_RJT:
  1591. if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  1592. retry = 1;
  1593. break;
  1594. }
  1595. break;
  1596. case IOSTAT_NPORT_BSY:
  1597. case IOSTAT_FABRIC_BSY:
  1598. retry = 1;
  1599. break;
  1600. case IOSTAT_LS_RJT:
  1601. stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
  1602. /* Added for Vendor specifc support
  1603. * Just keep retrying for these Rsn / Exp codes
  1604. */
  1605. switch (stat.un.b.lsRjtRsnCode) {
  1606. case LSRJT_UNABLE_TPC:
  1607. if (stat.un.b.lsRjtRsnCodeExp ==
  1608. LSEXP_CMD_IN_PROGRESS) {
  1609. if (cmd == ELS_CMD_PLOGI) {
  1610. delay = 1000;
  1611. maxretry = 48;
  1612. }
  1613. retry = 1;
  1614. break;
  1615. }
  1616. if (cmd == ELS_CMD_PLOGI) {
  1617. delay = 1000;
  1618. maxretry = lpfc_max_els_tries + 1;
  1619. retry = 1;
  1620. break;
  1621. }
  1622. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1623. (cmd == ELS_CMD_FDISC) &&
  1624. (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
  1625. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1626. "0125 FDISC Failed (x%x). "
  1627. "Fabric out of resources\n",
  1628. stat.un.lsRjtError);
  1629. lpfc_vport_set_state(vport,
  1630. FC_VPORT_NO_FABRIC_RSCS);
  1631. }
  1632. break;
  1633. case LSRJT_LOGICAL_BSY:
  1634. if ((cmd == ELS_CMD_PLOGI) ||
  1635. (cmd == ELS_CMD_PRLI)) {
  1636. delay = 1000;
  1637. maxretry = 48;
  1638. } else if (cmd == ELS_CMD_FDISC) {
  1639. /* FDISC retry policy */
  1640. maxretry = 48;
  1641. if (cmdiocb->retry >= 32)
  1642. delay = 1000;
  1643. }
  1644. retry = 1;
  1645. break;
  1646. case LSRJT_LOGICAL_ERR:
  1647. case LSRJT_PROTOCOL_ERR:
  1648. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1649. (cmd == ELS_CMD_FDISC) &&
  1650. ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
  1651. (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
  1652. ) {
  1653. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1654. "0123 FDISC Failed (x%x). "
  1655. "Fabric Detected Bad WWN\n",
  1656. stat.un.lsRjtError);
  1657. lpfc_vport_set_state(vport,
  1658. FC_VPORT_FABRIC_REJ_WWN);
  1659. }
  1660. break;
  1661. }
  1662. break;
  1663. case IOSTAT_INTERMED_RSP:
  1664. case IOSTAT_BA_RJT:
  1665. break;
  1666. default:
  1667. break;
  1668. }
  1669. if (did == FDMI_DID)
  1670. retry = 1;
  1671. if ((++cmdiocb->retry) >= maxretry) {
  1672. phba->fc_stat.elsRetryExceeded++;
  1673. retry = 0;
  1674. }
  1675. if ((vport->load_flag & FC_UNLOADING) != 0)
  1676. retry = 0;
  1677. if (retry) {
  1678. /* Retry ELS command <elsCmd> to remote NPORT <did> */
  1679. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1680. "0107 Retry ELS command x%x to remote "
  1681. "NPORT x%x Data: x%x x%x\n",
  1682. cmd, did, cmdiocb->retry, delay);
  1683. if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
  1684. ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  1685. ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
  1686. /* Don't reset timer for no resources */
  1687. /* If discovery / RSCN timer is running, reset it */
  1688. if (timer_pending(&vport->fc_disctmo) ||
  1689. (vport->fc_flag & FC_RSCN_MODE))
  1690. lpfc_set_disctmo(vport);
  1691. }
  1692. phba->fc_stat.elsXmitRetry++;
  1693. if (ndlp && delay) {
  1694. phba->fc_stat.elsDelayRetry++;
  1695. ndlp->nlp_retry = cmdiocb->retry;
  1696. /* delay is specified in milliseconds */
  1697. mod_timer(&ndlp->nlp_delayfunc,
  1698. jiffies + msecs_to_jiffies(delay));
  1699. spin_lock_irq(shost->host_lock);
  1700. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1701. spin_unlock_irq(shost->host_lock);
  1702. ndlp->nlp_prev_state = ndlp->nlp_state;
  1703. if (cmd == ELS_CMD_PRLI)
  1704. lpfc_nlp_set_state(vport, ndlp,
  1705. NLP_STE_REG_LOGIN_ISSUE);
  1706. else
  1707. lpfc_nlp_set_state(vport, ndlp,
  1708. NLP_STE_NPR_NODE);
  1709. ndlp->nlp_last_elscmd = cmd;
  1710. return 1;
  1711. }
  1712. switch (cmd) {
  1713. case ELS_CMD_FLOGI:
  1714. lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
  1715. return 1;
  1716. case ELS_CMD_FDISC:
  1717. lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
  1718. return 1;
  1719. case ELS_CMD_PLOGI:
  1720. if (ndlp) {
  1721. ndlp->nlp_prev_state = ndlp->nlp_state;
  1722. lpfc_nlp_set_state(vport, ndlp,
  1723. NLP_STE_PLOGI_ISSUE);
  1724. }
  1725. lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
  1726. return 1;
  1727. case ELS_CMD_ADISC:
  1728. ndlp->nlp_prev_state = ndlp->nlp_state;
  1729. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  1730. lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
  1731. return 1;
  1732. case ELS_CMD_PRLI:
  1733. ndlp->nlp_prev_state = ndlp->nlp_state;
  1734. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  1735. lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
  1736. return 1;
  1737. case ELS_CMD_LOGO:
  1738. ndlp->nlp_prev_state = ndlp->nlp_state;
  1739. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1740. lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
  1741. return 1;
  1742. }
  1743. }
  1744. /* No retry ELS command <elsCmd> to remote NPORT <did> */
  1745. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1746. "0108 No retry ELS command x%x to remote "
  1747. "NPORT x%x Retried:%d Error:x%x/%x\n",
  1748. cmd, did, cmdiocb->retry, irsp->ulpStatus,
  1749. irsp->un.ulpWord[4]);
  1750. return 0;
  1751. }
  1752. int
  1753. lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
  1754. {
  1755. struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
  1756. if (elsiocb->context1) {
  1757. lpfc_nlp_put(elsiocb->context1);
  1758. elsiocb->context1 = NULL;
  1759. }
  1760. /* context2 = cmd, context2->next = rsp, context3 = bpl */
  1761. if (elsiocb->context2) {
  1762. buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
  1763. /* Free the response before processing the command. */
  1764. if (!list_empty(&buf_ptr1->list)) {
  1765. list_remove_head(&buf_ptr1->list, buf_ptr,
  1766. struct lpfc_dmabuf,
  1767. list);
  1768. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1769. kfree(buf_ptr);
  1770. }
  1771. lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
  1772. kfree(buf_ptr1);
  1773. }
  1774. if (elsiocb->context3) {
  1775. buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
  1776. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1777. kfree(buf_ptr);
  1778. }
  1779. lpfc_sli_release_iocbq(phba, elsiocb);
  1780. return 0;
  1781. }
  1782. static void
  1783. lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1784. struct lpfc_iocbq *rspiocb)
  1785. {
  1786. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1787. struct lpfc_vport *vport = cmdiocb->vport;
  1788. IOCB_t *irsp;
  1789. irsp = &rspiocb->iocb;
  1790. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  1791. "ACC LOGO cmpl: status:x%x/x%x did:x%x",
  1792. irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
  1793. /* ACC to LOGO completes to NPort <nlp_DID> */
  1794. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1795. "0109 ACC to LOGO completes to NPort x%x "
  1796. "Data: x%x x%x x%x\n",
  1797. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  1798. ndlp->nlp_rpi);
  1799. switch (ndlp->nlp_state) {
  1800. case NLP_STE_UNUSED_NODE: /* node is just allocated */
  1801. lpfc_drop_node(vport, ndlp);
  1802. break;
  1803. case NLP_STE_NPR_NODE: /* NPort Recovery mode */
  1804. lpfc_unreg_rpi(vport, ndlp);
  1805. break;
  1806. default:
  1807. break;
  1808. }
  1809. lpfc_els_free_iocb(phba, cmdiocb);
  1810. return;
  1811. }
  1812. void
  1813. lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1814. {
  1815. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1816. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  1817. pmb->context1 = NULL;
  1818. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1819. kfree(mp);
  1820. mempool_free(pmb, phba->mbox_mem_pool);
  1821. lpfc_nlp_put(ndlp);
  1822. return;
  1823. }
  1824. static void
  1825. lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1826. struct lpfc_iocbq *rspiocb)
  1827. {
  1828. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1829. struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
  1830. struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
  1831. IOCB_t *irsp;
  1832. LPFC_MBOXQ_t *mbox = NULL;
  1833. struct lpfc_dmabuf *mp = NULL;
  1834. irsp = &rspiocb->iocb;
  1835. if (cmdiocb->context_un.mbox)
  1836. mbox = cmdiocb->context_un.mbox;
  1837. /* Check to see if link went down during discovery */
  1838. if (!ndlp || lpfc_els_chk_latt(vport)) {
  1839. if (mbox) {
  1840. mp = (struct lpfc_dmabuf *) mbox->context1;
  1841. if (mp) {
  1842. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1843. kfree(mp);
  1844. }
  1845. mempool_free(mbox, phba->mbox_mem_pool);
  1846. }
  1847. goto out;
  1848. }
  1849. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  1850. "ELS rsp cmpl: status:x%x/x%x did:x%x",
  1851. irsp->ulpStatus, irsp->un.ulpWord[4],
  1852. cmdiocb->iocb.un.elsreq64.remoteID);
  1853. /* ELS response tag <ulpIoTag> completes */
  1854. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1855. "0110 ELS response tag x%x completes "
  1856. "Data: x%x x%x x%x x%x x%x x%x x%x\n",
  1857. cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
  1858. rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
  1859. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  1860. ndlp->nlp_rpi);
  1861. if (mbox) {
  1862. if ((rspiocb->iocb.ulpStatus == 0)
  1863. && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
  1864. lpfc_unreg_rpi(vport, ndlp);
  1865. mbox->context2 = lpfc_nlp_get(ndlp);
  1866. mbox->vport = vport;
  1867. if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
  1868. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  1869. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  1870. }
  1871. else {
  1872. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  1873. ndlp->nlp_prev_state = ndlp->nlp_state;
  1874. lpfc_nlp_set_state(vport, ndlp,
  1875. NLP_STE_REG_LOGIN_ISSUE);
  1876. }
  1877. if (lpfc_sli_issue_mbox(phba, mbox,
  1878. (MBX_NOWAIT | MBX_STOP_IOCB))
  1879. != MBX_NOT_FINISHED) {
  1880. goto out;
  1881. }
  1882. lpfc_nlp_put(ndlp);
  1883. /* NOTE: we should have messages for unsuccessful
  1884. reglogin */
  1885. } else {
  1886. /* Do not drop node for lpfc_els_abort'ed ELS cmds */
  1887. if (!lpfc_error_lost_link(irsp) &&
  1888. ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  1889. lpfc_drop_node(vport, ndlp);
  1890. ndlp = NULL;
  1891. }
  1892. }
  1893. mp = (struct lpfc_dmabuf *) mbox->context1;
  1894. if (mp) {
  1895. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1896. kfree(mp);
  1897. }
  1898. mempool_free(mbox, phba->mbox_mem_pool);
  1899. }
  1900. out:
  1901. if (ndlp) {
  1902. spin_lock_irq(shost->host_lock);
  1903. ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
  1904. spin_unlock_irq(shost->host_lock);
  1905. }
  1906. lpfc_els_free_iocb(phba, cmdiocb);
  1907. return;
  1908. }
  1909. int
  1910. lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
  1911. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  1912. LPFC_MBOXQ_t *mbox)
  1913. {
  1914. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1915. struct lpfc_hba *phba = vport->phba;
  1916. IOCB_t *icmd;
  1917. IOCB_t *oldcmd;
  1918. struct lpfc_iocbq *elsiocb;
  1919. struct lpfc_sli_ring *pring;
  1920. struct lpfc_sli *psli;
  1921. uint8_t *pcmd;
  1922. uint16_t cmdsize;
  1923. int rc;
  1924. ELS_PKT *els_pkt_ptr;
  1925. psli = &phba->sli;
  1926. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1927. oldcmd = &oldiocb->iocb;
  1928. switch (flag) {
  1929. case ELS_CMD_ACC:
  1930. cmdsize = sizeof(uint32_t);
  1931. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  1932. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  1933. if (!elsiocb) {
  1934. spin_lock_irq(shost->host_lock);
  1935. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  1936. spin_unlock_irq(shost->host_lock);
  1937. return 1;
  1938. }
  1939. icmd = &elsiocb->iocb;
  1940. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  1941. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1942. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  1943. pcmd += sizeof(uint32_t);
  1944. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  1945. "Issue ACC: did:x%x flg:x%x",
  1946. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  1947. break;
  1948. case ELS_CMD_PLOGI:
  1949. cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
  1950. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  1951. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  1952. if (!elsiocb)
  1953. return 1;
  1954. icmd = &elsiocb->iocb;
  1955. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  1956. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1957. if (mbox)
  1958. elsiocb->context_un.mbox = mbox;
  1959. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  1960. pcmd += sizeof(uint32_t);
  1961. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  1962. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  1963. "Issue ACC PLOGI: did:x%x flg:x%x",
  1964. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  1965. break;
  1966. case ELS_CMD_PRLO:
  1967. cmdsize = sizeof(uint32_t) + sizeof(PRLO);
  1968. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  1969. ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
  1970. if (!elsiocb)
  1971. return 1;
  1972. icmd = &elsiocb->iocb;
  1973. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  1974. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1975. memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
  1976. sizeof(uint32_t) + sizeof(PRLO));
  1977. *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
  1978. els_pkt_ptr = (ELS_PKT *) pcmd;
  1979. els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
  1980. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  1981. "Issue ACC PRLO: did:x%x flg:x%x",
  1982. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  1983. break;
  1984. default:
  1985. return 1;
  1986. }
  1987. /* Xmit ELS ACC response tag <ulpIoTag> */
  1988. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1989. "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
  1990. "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
  1991. elsiocb->iotag, elsiocb->iocb.ulpContext,
  1992. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  1993. ndlp->nlp_rpi);
  1994. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  1995. spin_lock_irq(shost->host_lock);
  1996. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  1997. spin_unlock_irq(shost->host_lock);
  1998. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
  1999. } else {
  2000. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2001. }
  2002. phba->fc_stat.elsXmitACC++;
  2003. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2004. if (rc == IOCB_ERROR) {
  2005. lpfc_els_free_iocb(phba, elsiocb);
  2006. return 1;
  2007. }
  2008. return 0;
  2009. }
  2010. int
  2011. lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
  2012. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  2013. LPFC_MBOXQ_t *mbox)
  2014. {
  2015. struct lpfc_hba *phba = vport->phba;
  2016. IOCB_t *icmd;
  2017. IOCB_t *oldcmd;
  2018. struct lpfc_iocbq *elsiocb;
  2019. struct lpfc_sli_ring *pring;
  2020. struct lpfc_sli *psli;
  2021. uint8_t *pcmd;
  2022. uint16_t cmdsize;
  2023. int rc;
  2024. psli = &phba->sli;
  2025. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2026. cmdsize = 2 * sizeof(uint32_t);
  2027. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2028. ndlp->nlp_DID, ELS_CMD_LS_RJT);
  2029. if (!elsiocb)
  2030. return 1;
  2031. icmd = &elsiocb->iocb;
  2032. oldcmd = &oldiocb->iocb;
  2033. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2034. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2035. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  2036. pcmd += sizeof(uint32_t);
  2037. *((uint32_t *) (pcmd)) = rejectError;
  2038. if (mbox)
  2039. elsiocb->context_un.mbox = mbox;
  2040. /* Xmit ELS RJT <err> response tag <ulpIoTag> */
  2041. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2042. "0129 Xmit ELS RJT x%x response tag x%x "
  2043. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  2044. "rpi x%x\n",
  2045. rejectError, elsiocb->iotag,
  2046. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  2047. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  2048. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2049. "Issue LS_RJT: did:x%x flg:x%x err:x%x",
  2050. ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
  2051. phba->fc_stat.elsXmitLSRJT++;
  2052. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2053. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2054. /* If the node is in the UNUSED state, and we are sending
  2055. * a reject, we are done with it. Release driver reference
  2056. * count here. The outstanding els will release its reference on
  2057. * completion and the node can be freed then.
  2058. */
  2059. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  2060. lpfc_nlp_put(ndlp);
  2061. if (rc == IOCB_ERROR) {
  2062. lpfc_els_free_iocb(phba, elsiocb);
  2063. return 1;
  2064. }
  2065. return 0;
  2066. }
  2067. int
  2068. lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  2069. struct lpfc_nodelist *ndlp)
  2070. {
  2071. struct lpfc_hba *phba = vport->phba;
  2072. struct lpfc_sli *psli = &phba->sli;
  2073. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  2074. ADISC *ap;
  2075. IOCB_t *icmd, *oldcmd;
  2076. struct lpfc_iocbq *elsiocb;
  2077. uint8_t *pcmd;
  2078. uint16_t cmdsize;
  2079. int rc;
  2080. cmdsize = sizeof(uint32_t) + sizeof(ADISC);
  2081. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2082. ndlp->nlp_DID, ELS_CMD_ACC);
  2083. if (!elsiocb)
  2084. return 1;
  2085. icmd = &elsiocb->iocb;
  2086. oldcmd = &oldiocb->iocb;
  2087. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2088. /* Xmit ADISC ACC response tag <ulpIoTag> */
  2089. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2090. "0130 Xmit ADISC ACC response iotag x%x xri: "
  2091. "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
  2092. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2093. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2094. ndlp->nlp_rpi);
  2095. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2096. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2097. pcmd += sizeof(uint32_t);
  2098. ap = (ADISC *) (pcmd);
  2099. ap->hardAL_PA = phba->fc_pref_ALPA;
  2100. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2101. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2102. ap->DID = be32_to_cpu(vport->fc_myDID);
  2103. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2104. "Issue ACC ADISC: did:x%x flg:x%x",
  2105. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2106. phba->fc_stat.elsXmitACC++;
  2107. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2108. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2109. if (rc == IOCB_ERROR) {
  2110. lpfc_els_free_iocb(phba, elsiocb);
  2111. return 1;
  2112. }
  2113. return 0;
  2114. }
  2115. int
  2116. lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  2117. struct lpfc_nodelist *ndlp)
  2118. {
  2119. struct lpfc_hba *phba = vport->phba;
  2120. PRLI *npr;
  2121. lpfc_vpd_t *vpd;
  2122. IOCB_t *icmd;
  2123. IOCB_t *oldcmd;
  2124. struct lpfc_iocbq *elsiocb;
  2125. struct lpfc_sli_ring *pring;
  2126. struct lpfc_sli *psli;
  2127. uint8_t *pcmd;
  2128. uint16_t cmdsize;
  2129. int rc;
  2130. psli = &phba->sli;
  2131. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2132. cmdsize = sizeof(uint32_t) + sizeof(PRLI);
  2133. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2134. ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
  2135. if (!elsiocb)
  2136. return 1;
  2137. icmd = &elsiocb->iocb;
  2138. oldcmd = &oldiocb->iocb;
  2139. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2140. /* Xmit PRLI ACC response tag <ulpIoTag> */
  2141. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2142. "0131 Xmit PRLI ACC response tag x%x xri x%x, "
  2143. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  2144. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2145. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2146. ndlp->nlp_rpi);
  2147. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2148. *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
  2149. pcmd += sizeof(uint32_t);
  2150. /* For PRLI, remainder of payload is PRLI parameter page */
  2151. memset(pcmd, 0, sizeof(PRLI));
  2152. npr = (PRLI *) pcmd;
  2153. vpd = &phba->vpd;
  2154. /*
  2155. * If our firmware version is 3.20 or later,
  2156. * set the following bits for FC-TAPE support.
  2157. */
  2158. if (vpd->rev.feaLevelHigh >= 0x02) {
  2159. npr->ConfmComplAllowed = 1;
  2160. npr->Retry = 1;
  2161. npr->TaskRetryIdReq = 1;
  2162. }
  2163. npr->acceptRspCode = PRLI_REQ_EXECUTED;
  2164. npr->estabImagePair = 1;
  2165. npr->readXferRdyDis = 1;
  2166. npr->ConfmComplAllowed = 1;
  2167. npr->prliType = PRLI_FCP_TYPE;
  2168. npr->initiatorFunc = 1;
  2169. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2170. "Issue ACC PRLI: did:x%x flg:x%x",
  2171. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2172. phba->fc_stat.elsXmitACC++;
  2173. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2174. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2175. if (rc == IOCB_ERROR) {
  2176. lpfc_els_free_iocb(phba, elsiocb);
  2177. return 1;
  2178. }
  2179. return 0;
  2180. }
  2181. static int
  2182. lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
  2183. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  2184. {
  2185. struct lpfc_hba *phba = vport->phba;
  2186. RNID *rn;
  2187. IOCB_t *icmd, *oldcmd;
  2188. struct lpfc_iocbq *elsiocb;
  2189. struct lpfc_sli_ring *pring;
  2190. struct lpfc_sli *psli;
  2191. uint8_t *pcmd;
  2192. uint16_t cmdsize;
  2193. int rc;
  2194. psli = &phba->sli;
  2195. pring = &psli->ring[LPFC_ELS_RING];
  2196. cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
  2197. + (2 * sizeof(struct lpfc_name));
  2198. if (format)
  2199. cmdsize += sizeof(RNID_TOP_DISC);
  2200. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2201. ndlp->nlp_DID, ELS_CMD_ACC);
  2202. if (!elsiocb)
  2203. return 1;
  2204. icmd = &elsiocb->iocb;
  2205. oldcmd = &oldiocb->iocb;
  2206. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2207. /* Xmit RNID ACC response tag <ulpIoTag> */
  2208. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2209. "0132 Xmit RNID ACC response tag x%x xri x%x\n",
  2210. elsiocb->iotag, elsiocb->iocb.ulpContext);
  2211. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2212. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2213. pcmd += sizeof(uint32_t);
  2214. memset(pcmd, 0, sizeof(RNID));
  2215. rn = (RNID *) (pcmd);
  2216. rn->Format = format;
  2217. rn->CommonLen = (2 * sizeof(struct lpfc_name));
  2218. memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2219. memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2220. switch (format) {
  2221. case 0:
  2222. rn->SpecificLen = 0;
  2223. break;
  2224. case RNID_TOPOLOGY_DISC:
  2225. rn->SpecificLen = sizeof(RNID_TOP_DISC);
  2226. memcpy(&rn->un.topologyDisc.portName,
  2227. &vport->fc_portname, sizeof(struct lpfc_name));
  2228. rn->un.topologyDisc.unitType = RNID_HBA;
  2229. rn->un.topologyDisc.physPort = 0;
  2230. rn->un.topologyDisc.attachedNodes = 0;
  2231. break;
  2232. default:
  2233. rn->CommonLen = 0;
  2234. rn->SpecificLen = 0;
  2235. break;
  2236. }
  2237. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2238. "Issue ACC RNID: did:x%x flg:x%x",
  2239. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2240. phba->fc_stat.elsXmitACC++;
  2241. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2242. lpfc_nlp_put(ndlp);
  2243. elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
  2244. * it could be freed */
  2245. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2246. if (rc == IOCB_ERROR) {
  2247. lpfc_els_free_iocb(phba, elsiocb);
  2248. return 1;
  2249. }
  2250. return 0;
  2251. }
  2252. int
  2253. lpfc_els_disc_adisc(struct lpfc_vport *vport)
  2254. {
  2255. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2256. struct lpfc_nodelist *ndlp, *next_ndlp;
  2257. int sentadisc = 0;
  2258. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  2259. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2260. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  2261. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  2262. (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
  2263. spin_lock_irq(shost->host_lock);
  2264. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2265. spin_unlock_irq(shost->host_lock);
  2266. ndlp->nlp_prev_state = ndlp->nlp_state;
  2267. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  2268. lpfc_issue_els_adisc(vport, ndlp, 0);
  2269. sentadisc++;
  2270. vport->num_disc_nodes++;
  2271. if (vport->num_disc_nodes >=
  2272. vport->cfg_discovery_threads) {
  2273. spin_lock_irq(shost->host_lock);
  2274. vport->fc_flag |= FC_NLP_MORE;
  2275. spin_unlock_irq(shost->host_lock);
  2276. break;
  2277. }
  2278. }
  2279. }
  2280. if (sentadisc == 0) {
  2281. spin_lock_irq(shost->host_lock);
  2282. vport->fc_flag &= ~FC_NLP_MORE;
  2283. spin_unlock_irq(shost->host_lock);
  2284. }
  2285. return sentadisc;
  2286. }
  2287. int
  2288. lpfc_els_disc_plogi(struct lpfc_vport *vport)
  2289. {
  2290. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2291. struct lpfc_nodelist *ndlp, *next_ndlp;
  2292. int sentplogi = 0;
  2293. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  2294. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2295. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  2296. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  2297. (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
  2298. (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
  2299. ndlp->nlp_prev_state = ndlp->nlp_state;
  2300. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2301. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  2302. sentplogi++;
  2303. vport->num_disc_nodes++;
  2304. if (vport->num_disc_nodes >=
  2305. vport->cfg_discovery_threads) {
  2306. spin_lock_irq(shost->host_lock);
  2307. vport->fc_flag |= FC_NLP_MORE;
  2308. spin_unlock_irq(shost->host_lock);
  2309. break;
  2310. }
  2311. }
  2312. }
  2313. if (sentplogi == 0) {
  2314. spin_lock_irq(shost->host_lock);
  2315. vport->fc_flag &= ~FC_NLP_MORE;
  2316. spin_unlock_irq(shost->host_lock);
  2317. }
  2318. return sentplogi;
  2319. }
  2320. void
  2321. lpfc_els_flush_rscn(struct lpfc_vport *vport)
  2322. {
  2323. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2324. struct lpfc_hba *phba = vport->phba;
  2325. int i;
  2326. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  2327. lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
  2328. vport->fc_rscn_id_list[i] = NULL;
  2329. }
  2330. spin_lock_irq(shost->host_lock);
  2331. vport->fc_rscn_id_cnt = 0;
  2332. vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
  2333. spin_unlock_irq(shost->host_lock);
  2334. lpfc_can_disctmo(vport);
  2335. }
  2336. int
  2337. lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
  2338. {
  2339. D_ID ns_did;
  2340. D_ID rscn_did;
  2341. uint32_t *lp;
  2342. uint32_t payload_len, i;
  2343. ns_did.un.word = did;
  2344. /* Never match fabric nodes for RSCNs */
  2345. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  2346. return 0;
  2347. /* If we are doing a FULL RSCN rediscovery, match everything */
  2348. if (vport->fc_flag & FC_RSCN_DISCOVERY)
  2349. return did;
  2350. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  2351. lp = vport->fc_rscn_id_list[i]->virt;
  2352. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  2353. payload_len -= sizeof(uint32_t); /* take off word 0 */
  2354. while (payload_len) {
  2355. rscn_did.un.word = be32_to_cpu(*lp++);
  2356. payload_len -= sizeof(uint32_t);
  2357. switch (rscn_did.un.b.resv) {
  2358. case 0: /* Single N_Port ID effected */
  2359. if (ns_did.un.word == rscn_did.un.word)
  2360. return did;
  2361. break;
  2362. case 1: /* Whole N_Port Area effected */
  2363. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  2364. && (ns_did.un.b.area == rscn_did.un.b.area))
  2365. return did;
  2366. break;
  2367. case 2: /* Whole N_Port Domain effected */
  2368. if (ns_did.un.b.domain == rscn_did.un.b.domain)
  2369. return did;
  2370. break;
  2371. default:
  2372. /* Unknown Identifier in RSCN node */
  2373. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2374. "0217 Unknown Identifier in "
  2375. "RSCN payload Data: x%x\n",
  2376. rscn_did.un.word);
  2377. case 3: /* Whole Fabric effected */
  2378. return did;
  2379. }
  2380. }
  2381. }
  2382. return 0;
  2383. }
  2384. static int
  2385. lpfc_rscn_recovery_check(struct lpfc_vport *vport)
  2386. {
  2387. struct lpfc_nodelist *ndlp = NULL;
  2388. /* Look at all nodes effected by pending RSCNs and move
  2389. * them to NPR state.
  2390. */
  2391. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  2392. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
  2393. lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
  2394. continue;
  2395. lpfc_disc_state_machine(vport, ndlp, NULL,
  2396. NLP_EVT_DEVICE_RECOVERY);
  2397. /*
  2398. * Make sure NLP_DELAY_TMO is NOT running after a device
  2399. * recovery event.
  2400. */
  2401. if (ndlp->nlp_flag & NLP_DELAY_TMO)
  2402. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2403. }
  2404. return 0;
  2405. }
  2406. static int
  2407. lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2408. struct lpfc_nodelist *ndlp)
  2409. {
  2410. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2411. struct lpfc_hba *phba = vport->phba;
  2412. struct lpfc_dmabuf *pcmd;
  2413. uint32_t *lp, *datap;
  2414. IOCB_t *icmd;
  2415. uint32_t payload_len, length, nportid, *cmd;
  2416. int rscn_cnt = vport->fc_rscn_id_cnt;
  2417. int rscn_id = 0, hba_id = 0;
  2418. int i;
  2419. icmd = &cmdiocb->iocb;
  2420. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2421. lp = (uint32_t *) pcmd->virt;
  2422. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  2423. payload_len -= sizeof(uint32_t); /* take off word 0 */
  2424. /* RSCN received */
  2425. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2426. "0214 RSCN received Data: x%x x%x x%x x%x\n",
  2427. vport->fc_flag, payload_len, *lp, rscn_cnt);
  2428. for (i = 0; i < payload_len/sizeof(uint32_t); i++)
  2429. fc_host_post_event(shost, fc_get_event_number(),
  2430. FCH_EVT_RSCN, lp[i]);
  2431. /* If we are about to begin discovery, just ACC the RSCN.
  2432. * Discovery processing will satisfy it.
  2433. */
  2434. if (vport->port_state <= LPFC_NS_QRY) {
  2435. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2436. "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
  2437. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  2438. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2439. return 0;
  2440. }
  2441. /* If this RSCN just contains NPortIDs for other vports on this HBA,
  2442. * just ACC and ignore it.
  2443. */
  2444. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2445. !(vport->cfg_peer_port_login)) {
  2446. i = payload_len;
  2447. datap = lp;
  2448. while (i > 0) {
  2449. nportid = *datap++;
  2450. nportid = ((be32_to_cpu(nportid)) & Mask_DID);
  2451. i -= sizeof(uint32_t);
  2452. rscn_id++;
  2453. if (lpfc_find_vport_by_did(phba, nportid))
  2454. hba_id++;
  2455. }
  2456. if (rscn_id == hba_id) {
  2457. /* ALL NPortIDs in RSCN are on HBA */
  2458. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2459. "0214 Ignore RSCN "
  2460. "Data: x%x x%x x%x x%x\n",
  2461. vport->fc_flag, payload_len,
  2462. *lp, rscn_cnt);
  2463. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2464. "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
  2465. ndlp->nlp_DID, vport->port_state,
  2466. ndlp->nlp_flag);
  2467. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
  2468. ndlp, NULL);
  2469. return 0;
  2470. }
  2471. }
  2472. /* If we are already processing an RSCN, save the received
  2473. * RSCN payload buffer, cmdiocb->context2 to process later.
  2474. */
  2475. if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
  2476. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2477. "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
  2478. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  2479. vport->fc_flag |= FC_RSCN_DEFERRED;
  2480. if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
  2481. !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
  2482. spin_lock_irq(shost->host_lock);
  2483. vport->fc_flag |= FC_RSCN_MODE;
  2484. spin_unlock_irq(shost->host_lock);
  2485. if (rscn_cnt) {
  2486. cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
  2487. length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
  2488. }
  2489. if ((rscn_cnt) &&
  2490. (payload_len + length <= LPFC_BPL_SIZE)) {
  2491. *cmd &= ELS_CMD_MASK;
  2492. *cmd |= be32_to_cpu(payload_len + length);
  2493. memcpy(((uint8_t *)cmd) + length, lp,
  2494. payload_len);
  2495. } else {
  2496. vport->fc_rscn_id_list[rscn_cnt] = pcmd;
  2497. vport->fc_rscn_id_cnt++;
  2498. /* If we zero, cmdiocb->context2, the calling
  2499. * routine will not try to free it.
  2500. */
  2501. cmdiocb->context2 = NULL;
  2502. }
  2503. /* Deferred RSCN */
  2504. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2505. "0235 Deferred RSCN "
  2506. "Data: x%x x%x x%x\n",
  2507. vport->fc_rscn_id_cnt, vport->fc_flag,
  2508. vport->port_state);
  2509. } else {
  2510. spin_lock_irq(shost->host_lock);
  2511. vport->fc_flag |= FC_RSCN_DISCOVERY;
  2512. spin_unlock_irq(shost->host_lock);
  2513. /* ReDiscovery RSCN */
  2514. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2515. "0234 ReDiscovery RSCN "
  2516. "Data: x%x x%x x%x\n",
  2517. vport->fc_rscn_id_cnt, vport->fc_flag,
  2518. vport->port_state);
  2519. }
  2520. /* Send back ACC */
  2521. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2522. /* send RECOVERY event for ALL nodes that match RSCN payload */
  2523. lpfc_rscn_recovery_check(vport);
  2524. vport->fc_flag &= ~FC_RSCN_DEFERRED;
  2525. return 0;
  2526. }
  2527. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2528. "RCV RSCN: did:x%x/ste:x%x flg:x%x",
  2529. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  2530. spin_lock_irq(shost->host_lock);
  2531. vport->fc_flag |= FC_RSCN_MODE;
  2532. spin_unlock_irq(shost->host_lock);
  2533. vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
  2534. /*
  2535. * If we zero, cmdiocb->context2, the calling routine will
  2536. * not try to free it.
  2537. */
  2538. cmdiocb->context2 = NULL;
  2539. lpfc_set_disctmo(vport);
  2540. /* Send back ACC */
  2541. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2542. /* send RECOVERY event for ALL nodes that match RSCN payload */
  2543. lpfc_rscn_recovery_check(vport);
  2544. return lpfc_els_handle_rscn(vport);
  2545. }
  2546. int
  2547. lpfc_els_handle_rscn(struct lpfc_vport *vport)
  2548. {
  2549. struct lpfc_nodelist *ndlp;
  2550. struct lpfc_hba *phba = vport->phba;
  2551. /* Ignore RSCN if the port is being torn down. */
  2552. if (vport->load_flag & FC_UNLOADING) {
  2553. lpfc_els_flush_rscn(vport);
  2554. return 0;
  2555. }
  2556. /* Start timer for RSCN processing */
  2557. lpfc_set_disctmo(vport);
  2558. /* RSCN processed */
  2559. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2560. "0215 RSCN processed Data: x%x x%x x%x x%x\n",
  2561. vport->fc_flag, 0, vport->fc_rscn_id_cnt,
  2562. vport->port_state);
  2563. /* To process RSCN, first compare RSCN data with NameServer */
  2564. vport->fc_ns_retry = 0;
  2565. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  2566. if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  2567. /* Good ndlp, issue CT Request to NameServer */
  2568. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
  2569. /* Wait for NameServer query cmpl before we can
  2570. continue */
  2571. return 1;
  2572. } else {
  2573. /* If login to NameServer does not exist, issue one */
  2574. /* Good status, issue PLOGI to NameServer */
  2575. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  2576. if (ndlp)
  2577. /* Wait for NameServer login cmpl before we can
  2578. continue */
  2579. return 1;
  2580. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  2581. if (!ndlp) {
  2582. lpfc_els_flush_rscn(vport);
  2583. return 0;
  2584. } else {
  2585. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  2586. ndlp->nlp_type |= NLP_FABRIC;
  2587. ndlp->nlp_prev_state = ndlp->nlp_state;
  2588. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2589. lpfc_issue_els_plogi(vport, NameServer_DID, 0);
  2590. /* Wait for NameServer login cmpl before we can
  2591. continue */
  2592. return 1;
  2593. }
  2594. }
  2595. lpfc_els_flush_rscn(vport);
  2596. return 0;
  2597. }
  2598. static int
  2599. lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2600. struct lpfc_nodelist *ndlp)
  2601. {
  2602. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2603. struct lpfc_hba *phba = vport->phba;
  2604. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2605. uint32_t *lp = (uint32_t *) pcmd->virt;
  2606. IOCB_t *icmd = &cmdiocb->iocb;
  2607. struct serv_parm *sp;
  2608. LPFC_MBOXQ_t *mbox;
  2609. struct ls_rjt stat;
  2610. uint32_t cmd, did;
  2611. int rc;
  2612. cmd = *lp++;
  2613. sp = (struct serv_parm *) lp;
  2614. /* FLOGI received */
  2615. lpfc_set_disctmo(vport);
  2616. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2617. /* We should never receive a FLOGI in loop mode, ignore it */
  2618. did = icmd->un.elsreq64.remoteID;
  2619. /* An FLOGI ELS command <elsCmd> was received from DID <did> in
  2620. Loop Mode */
  2621. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2622. "0113 An FLOGI ELS command x%x was "
  2623. "received from DID x%x in Loop Mode\n",
  2624. cmd, did);
  2625. return 1;
  2626. }
  2627. did = Fabric_DID;
  2628. if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
  2629. /* For a FLOGI we accept, then if our portname is greater
  2630. * then the remote portname we initiate Nport login.
  2631. */
  2632. rc = memcmp(&vport->fc_portname, &sp->portName,
  2633. sizeof(struct lpfc_name));
  2634. if (!rc) {
  2635. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2636. if (!mbox)
  2637. return 1;
  2638. lpfc_linkdown(phba);
  2639. lpfc_init_link(phba, mbox,
  2640. phba->cfg_topology,
  2641. phba->cfg_link_speed);
  2642. mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
  2643. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2644. mbox->vport = vport;
  2645. rc = lpfc_sli_issue_mbox
  2646. (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
  2647. lpfc_set_loopback_flag(phba);
  2648. if (rc == MBX_NOT_FINISHED) {
  2649. mempool_free(mbox, phba->mbox_mem_pool);
  2650. }
  2651. return 1;
  2652. } else if (rc > 0) { /* greater than */
  2653. spin_lock_irq(shost->host_lock);
  2654. vport->fc_flag |= FC_PT2PT_PLOGI;
  2655. spin_unlock_irq(shost->host_lock);
  2656. }
  2657. spin_lock_irq(shost->host_lock);
  2658. vport->fc_flag |= FC_PT2PT;
  2659. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  2660. spin_unlock_irq(shost->host_lock);
  2661. } else {
  2662. /* Reject this request because invalid parameters */
  2663. stat.un.b.lsRjtRsvd0 = 0;
  2664. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2665. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  2666. stat.un.b.vendorUnique = 0;
  2667. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  2668. NULL);
  2669. return 1;
  2670. }
  2671. /* Send back ACC */
  2672. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
  2673. return 0;
  2674. }
  2675. static int
  2676. lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2677. struct lpfc_nodelist *ndlp)
  2678. {
  2679. struct lpfc_dmabuf *pcmd;
  2680. uint32_t *lp;
  2681. IOCB_t *icmd;
  2682. RNID *rn;
  2683. struct ls_rjt stat;
  2684. uint32_t cmd, did;
  2685. icmd = &cmdiocb->iocb;
  2686. did = icmd->un.elsreq64.remoteID;
  2687. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2688. lp = (uint32_t *) pcmd->virt;
  2689. cmd = *lp++;
  2690. rn = (RNID *) lp;
  2691. /* RNID received */
  2692. switch (rn->Format) {
  2693. case 0:
  2694. case RNID_TOPOLOGY_DISC:
  2695. /* Send back ACC */
  2696. lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
  2697. break;
  2698. default:
  2699. /* Reject this request because format not supported */
  2700. stat.un.b.lsRjtRsvd0 = 0;
  2701. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2702. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2703. stat.un.b.vendorUnique = 0;
  2704. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  2705. NULL);
  2706. }
  2707. return 0;
  2708. }
  2709. static int
  2710. lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2711. struct lpfc_nodelist *ndlp)
  2712. {
  2713. struct ls_rjt stat;
  2714. /* For now, unconditionally reject this command */
  2715. stat.un.b.lsRjtRsvd0 = 0;
  2716. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2717. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2718. stat.un.b.vendorUnique = 0;
  2719. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  2720. return 0;
  2721. }
  2722. static void
  2723. lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2724. {
  2725. struct lpfc_sli *psli = &phba->sli;
  2726. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  2727. MAILBOX_t *mb;
  2728. IOCB_t *icmd;
  2729. RPS_RSP *rps_rsp;
  2730. uint8_t *pcmd;
  2731. struct lpfc_iocbq *elsiocb;
  2732. struct lpfc_nodelist *ndlp;
  2733. uint16_t xri, status;
  2734. uint32_t cmdsize;
  2735. mb = &pmb->mb;
  2736. ndlp = (struct lpfc_nodelist *) pmb->context2;
  2737. xri = (uint16_t) ((unsigned long)(pmb->context1));
  2738. pmb->context1 = NULL;
  2739. pmb->context2 = NULL;
  2740. if (mb->mbxStatus) {
  2741. mempool_free(pmb, phba->mbox_mem_pool);
  2742. return;
  2743. }
  2744. cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
  2745. mempool_free(pmb, phba->mbox_mem_pool);
  2746. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  2747. lpfc_max_els_tries, ndlp,
  2748. ndlp->nlp_DID, ELS_CMD_ACC);
  2749. lpfc_nlp_put(ndlp);
  2750. if (!elsiocb)
  2751. return;
  2752. icmd = &elsiocb->iocb;
  2753. icmd->ulpContext = xri;
  2754. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2755. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2756. pcmd += sizeof(uint32_t); /* Skip past command */
  2757. rps_rsp = (RPS_RSP *)pcmd;
  2758. if (phba->fc_topology != TOPOLOGY_LOOP)
  2759. status = 0x10;
  2760. else
  2761. status = 0x8;
  2762. if (phba->pport->fc_flag & FC_FABRIC)
  2763. status |= 0x4;
  2764. rps_rsp->rsvd1 = 0;
  2765. rps_rsp->portStatus = be16_to_cpu(status);
  2766. rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
  2767. rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
  2768. rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
  2769. rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
  2770. rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
  2771. rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
  2772. /* Xmit ELS RPS ACC response tag <ulpIoTag> */
  2773. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  2774. "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
  2775. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  2776. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2777. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2778. ndlp->nlp_rpi);
  2779. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2780. phba->fc_stat.elsXmitACC++;
  2781. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
  2782. lpfc_els_free_iocb(phba, elsiocb);
  2783. return;
  2784. }
  2785. static int
  2786. lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2787. struct lpfc_nodelist *ndlp)
  2788. {
  2789. struct lpfc_hba *phba = vport->phba;
  2790. uint32_t *lp;
  2791. uint8_t flag;
  2792. LPFC_MBOXQ_t *mbox;
  2793. struct lpfc_dmabuf *pcmd;
  2794. RPS *rps;
  2795. struct ls_rjt stat;
  2796. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  2797. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  2798. stat.un.b.lsRjtRsvd0 = 0;
  2799. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2800. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2801. stat.un.b.vendorUnique = 0;
  2802. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  2803. NULL);
  2804. }
  2805. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2806. lp = (uint32_t *) pcmd->virt;
  2807. flag = (be32_to_cpu(*lp++) & 0xf);
  2808. rps = (RPS *) lp;
  2809. if ((flag == 0) ||
  2810. ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
  2811. ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
  2812. sizeof(struct lpfc_name)) == 0))) {
  2813. printk("Fix me....\n");
  2814. dump_stack();
  2815. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
  2816. if (mbox) {
  2817. lpfc_read_lnk_stat(phba, mbox);
  2818. mbox->context1 =
  2819. (void *)((unsigned long) cmdiocb->iocb.ulpContext);
  2820. mbox->context2 = lpfc_nlp_get(ndlp);
  2821. mbox->vport = vport;
  2822. mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
  2823. if (lpfc_sli_issue_mbox (phba, mbox,
  2824. (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED)
  2825. /* Mbox completion will send ELS Response */
  2826. return 0;
  2827. lpfc_nlp_put(ndlp);
  2828. mempool_free(mbox, phba->mbox_mem_pool);
  2829. }
  2830. }
  2831. stat.un.b.lsRjtRsvd0 = 0;
  2832. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2833. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2834. stat.un.b.vendorUnique = 0;
  2835. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  2836. return 0;
  2837. }
  2838. static int
  2839. lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
  2840. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  2841. {
  2842. struct lpfc_hba *phba = vport->phba;
  2843. IOCB_t *icmd, *oldcmd;
  2844. RPL_RSP rpl_rsp;
  2845. struct lpfc_iocbq *elsiocb;
  2846. struct lpfc_sli *psli = &phba->sli;
  2847. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  2848. uint8_t *pcmd;
  2849. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2850. ndlp->nlp_DID, ELS_CMD_ACC);
  2851. if (!elsiocb)
  2852. return 1;
  2853. icmd = &elsiocb->iocb;
  2854. oldcmd = &oldiocb->iocb;
  2855. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2856. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2857. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2858. pcmd += sizeof(uint16_t);
  2859. *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
  2860. pcmd += sizeof(uint16_t);
  2861. /* Setup the RPL ACC payload */
  2862. rpl_rsp.listLen = be32_to_cpu(1);
  2863. rpl_rsp.index = 0;
  2864. rpl_rsp.port_num_blk.portNum = 0;
  2865. rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
  2866. memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
  2867. sizeof(struct lpfc_name));
  2868. memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
  2869. /* Xmit ELS RPL ACC response tag <ulpIoTag> */
  2870. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2871. "0120 Xmit ELS RPL ACC response tag x%x "
  2872. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  2873. "rpi x%x\n",
  2874. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2875. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2876. ndlp->nlp_rpi);
  2877. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2878. phba->fc_stat.elsXmitACC++;
  2879. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  2880. lpfc_els_free_iocb(phba, elsiocb);
  2881. return 1;
  2882. }
  2883. return 0;
  2884. }
  2885. static int
  2886. lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2887. struct lpfc_nodelist *ndlp)
  2888. {
  2889. struct lpfc_dmabuf *pcmd;
  2890. uint32_t *lp;
  2891. uint32_t maxsize;
  2892. uint16_t cmdsize;
  2893. RPL *rpl;
  2894. struct ls_rjt stat;
  2895. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  2896. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  2897. stat.un.b.lsRjtRsvd0 = 0;
  2898. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2899. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2900. stat.un.b.vendorUnique = 0;
  2901. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  2902. NULL);
  2903. }
  2904. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2905. lp = (uint32_t *) pcmd->virt;
  2906. rpl = (RPL *) (lp + 1);
  2907. maxsize = be32_to_cpu(rpl->maxsize);
  2908. /* We support only one port */
  2909. if ((rpl->index == 0) &&
  2910. ((maxsize == 0) ||
  2911. ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
  2912. cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
  2913. } else {
  2914. cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
  2915. }
  2916. lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
  2917. return 0;
  2918. }
  2919. static int
  2920. lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2921. struct lpfc_nodelist *ndlp)
  2922. {
  2923. struct lpfc_dmabuf *pcmd;
  2924. uint32_t *lp;
  2925. IOCB_t *icmd;
  2926. FARP *fp;
  2927. uint32_t cmd, cnt, did;
  2928. icmd = &cmdiocb->iocb;
  2929. did = icmd->un.elsreq64.remoteID;
  2930. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2931. lp = (uint32_t *) pcmd->virt;
  2932. cmd = *lp++;
  2933. fp = (FARP *) lp;
  2934. /* FARP-REQ received from DID <did> */
  2935. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2936. "0601 FARP-REQ received from DID x%x\n", did);
  2937. /* We will only support match on WWPN or WWNN */
  2938. if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
  2939. return 0;
  2940. }
  2941. cnt = 0;
  2942. /* If this FARP command is searching for my portname */
  2943. if (fp->Mflags & FARP_MATCH_PORT) {
  2944. if (memcmp(&fp->RportName, &vport->fc_portname,
  2945. sizeof(struct lpfc_name)) == 0)
  2946. cnt = 1;
  2947. }
  2948. /* If this FARP command is searching for my nodename */
  2949. if (fp->Mflags & FARP_MATCH_NODE) {
  2950. if (memcmp(&fp->RnodeName, &vport->fc_nodename,
  2951. sizeof(struct lpfc_name)) == 0)
  2952. cnt = 1;
  2953. }
  2954. if (cnt) {
  2955. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  2956. (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
  2957. /* Log back into the node before sending the FARP. */
  2958. if (fp->Rflags & FARP_REQUEST_PLOGI) {
  2959. ndlp->nlp_prev_state = ndlp->nlp_state;
  2960. lpfc_nlp_set_state(vport, ndlp,
  2961. NLP_STE_PLOGI_ISSUE);
  2962. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  2963. }
  2964. /* Send a FARP response to that node */
  2965. if (fp->Rflags & FARP_REQUEST_FARPR)
  2966. lpfc_issue_els_farpr(vport, did, 0);
  2967. }
  2968. }
  2969. return 0;
  2970. }
  2971. static int
  2972. lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2973. struct lpfc_nodelist *ndlp)
  2974. {
  2975. struct lpfc_dmabuf *pcmd;
  2976. uint32_t *lp;
  2977. IOCB_t *icmd;
  2978. uint32_t cmd, did;
  2979. icmd = &cmdiocb->iocb;
  2980. did = icmd->un.elsreq64.remoteID;
  2981. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2982. lp = (uint32_t *) pcmd->virt;
  2983. cmd = *lp++;
  2984. /* FARP-RSP received from DID <did> */
  2985. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2986. "0600 FARP-RSP received from DID x%x\n", did);
  2987. /* ACCEPT the Farp resp request */
  2988. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2989. return 0;
  2990. }
  2991. static int
  2992. lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2993. struct lpfc_nodelist *fan_ndlp)
  2994. {
  2995. struct lpfc_dmabuf *pcmd;
  2996. uint32_t *lp;
  2997. IOCB_t *icmd;
  2998. uint32_t cmd, did;
  2999. FAN *fp;
  3000. struct lpfc_nodelist *ndlp, *next_ndlp;
  3001. struct lpfc_hba *phba = vport->phba;
  3002. /* FAN received */
  3003. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3004. "0265 FAN received\n");
  3005. icmd = &cmdiocb->iocb;
  3006. did = icmd->un.elsreq64.remoteID;
  3007. pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
  3008. lp = (uint32_t *)pcmd->virt;
  3009. cmd = *lp++;
  3010. fp = (FAN *) lp;
  3011. /* FAN received; Fan does not have a reply sequence */
  3012. if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
  3013. if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
  3014. sizeof(struct lpfc_name)) != 0) ||
  3015. (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
  3016. sizeof(struct lpfc_name)) != 0)) {
  3017. /*
  3018. * This node has switched fabrics. FLOGI is required
  3019. * Clean up the old rpi's
  3020. */
  3021. list_for_each_entry_safe(ndlp, next_ndlp,
  3022. &vport->fc_nodes, nlp_listp) {
  3023. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  3024. continue;
  3025. if (ndlp->nlp_type & NLP_FABRIC) {
  3026. /*
  3027. * Clean up old Fabric, Nameserver and
  3028. * other NLP_FABRIC logins
  3029. */
  3030. lpfc_drop_node(vport, ndlp);
  3031. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  3032. /* Fail outstanding I/O now since this
  3033. * device is marked for PLOGI
  3034. */
  3035. lpfc_unreg_rpi(vport, ndlp);
  3036. }
  3037. }
  3038. vport->port_state = LPFC_FLOGI;
  3039. lpfc_set_disctmo(vport);
  3040. lpfc_initial_flogi(vport);
  3041. return 0;
  3042. }
  3043. /* Discovery not needed,
  3044. * move the nodes to their original state.
  3045. */
  3046. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  3047. nlp_listp) {
  3048. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  3049. continue;
  3050. switch (ndlp->nlp_prev_state) {
  3051. case NLP_STE_UNMAPPED_NODE:
  3052. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  3053. lpfc_nlp_set_state(vport, ndlp,
  3054. NLP_STE_UNMAPPED_NODE);
  3055. break;
  3056. case NLP_STE_MAPPED_NODE:
  3057. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  3058. lpfc_nlp_set_state(vport, ndlp,
  3059. NLP_STE_MAPPED_NODE);
  3060. break;
  3061. default:
  3062. break;
  3063. }
  3064. }
  3065. /* Start discovery - this should just do CLEAR_LA */
  3066. lpfc_disc_start(vport);
  3067. }
  3068. return 0;
  3069. }
  3070. void
  3071. lpfc_els_timeout(unsigned long ptr)
  3072. {
  3073. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  3074. struct lpfc_hba *phba = vport->phba;
  3075. unsigned long iflag;
  3076. spin_lock_irqsave(&vport->work_port_lock, iflag);
  3077. if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
  3078. vport->work_port_events |= WORKER_ELS_TMO;
  3079. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  3080. spin_lock_irqsave(&phba->hbalock, iflag);
  3081. if (phba->work_wait)
  3082. lpfc_worker_wake_up(phba);
  3083. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3084. }
  3085. else
  3086. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  3087. return;
  3088. }
  3089. void
  3090. lpfc_els_timeout_handler(struct lpfc_vport *vport)
  3091. {
  3092. struct lpfc_hba *phba = vport->phba;
  3093. struct lpfc_sli_ring *pring;
  3094. struct lpfc_iocbq *tmp_iocb, *piocb;
  3095. IOCB_t *cmd = NULL;
  3096. struct lpfc_dmabuf *pcmd;
  3097. uint32_t els_command = 0;
  3098. uint32_t timeout;
  3099. uint32_t remote_ID = 0xffffffff;
  3100. /* If the timer is already canceled do nothing */
  3101. if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
  3102. return;
  3103. }
  3104. spin_lock_irq(&phba->hbalock);
  3105. timeout = (uint32_t)(phba->fc_ratov << 1);
  3106. pring = &phba->sli.ring[LPFC_ELS_RING];
  3107. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3108. cmd = &piocb->iocb;
  3109. if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
  3110. piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  3111. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  3112. continue;
  3113. if (piocb->vport != vport)
  3114. continue;
  3115. pcmd = (struct lpfc_dmabuf *) piocb->context2;
  3116. if (pcmd)
  3117. els_command = *(uint32_t *) (pcmd->virt);
  3118. if (els_command == ELS_CMD_FARP ||
  3119. els_command == ELS_CMD_FARPR ||
  3120. els_command == ELS_CMD_FDISC)
  3121. continue;
  3122. if (vport != piocb->vport)
  3123. continue;
  3124. if (piocb->drvrTimeout > 0) {
  3125. if (piocb->drvrTimeout >= timeout)
  3126. piocb->drvrTimeout -= timeout;
  3127. else
  3128. piocb->drvrTimeout = 0;
  3129. continue;
  3130. }
  3131. remote_ID = 0xffffffff;
  3132. if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
  3133. remote_ID = cmd->un.elsreq64.remoteID;
  3134. else {
  3135. struct lpfc_nodelist *ndlp;
  3136. ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
  3137. if (ndlp)
  3138. remote_ID = ndlp->nlp_DID;
  3139. }
  3140. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3141. "0127 ELS timeout Data: x%x x%x x%x "
  3142. "x%x\n", els_command,
  3143. remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
  3144. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3145. }
  3146. spin_unlock_irq(&phba->hbalock);
  3147. if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
  3148. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  3149. }
  3150. void
  3151. lpfc_els_flush_cmd(struct lpfc_vport *vport)
  3152. {
  3153. LIST_HEAD(completions);
  3154. struct lpfc_hba *phba = vport->phba;
  3155. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3156. struct lpfc_iocbq *tmp_iocb, *piocb;
  3157. IOCB_t *cmd = NULL;
  3158. lpfc_fabric_abort_vport(vport);
  3159. spin_lock_irq(&phba->hbalock);
  3160. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  3161. cmd = &piocb->iocb;
  3162. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  3163. continue;
  3164. }
  3165. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  3166. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  3167. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  3168. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  3169. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  3170. continue;
  3171. if (piocb->vport != vport)
  3172. continue;
  3173. list_move_tail(&piocb->list, &completions);
  3174. pring->txq_cnt--;
  3175. }
  3176. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3177. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  3178. continue;
  3179. }
  3180. if (piocb->vport != vport)
  3181. continue;
  3182. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3183. }
  3184. spin_unlock_irq(&phba->hbalock);
  3185. while (!list_empty(&completions)) {
  3186. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  3187. cmd = &piocb->iocb;
  3188. list_del_init(&piocb->list);
  3189. if (!piocb->iocb_cmpl)
  3190. lpfc_sli_release_iocbq(phba, piocb);
  3191. else {
  3192. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3193. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  3194. (piocb->iocb_cmpl) (phba, piocb, piocb);
  3195. }
  3196. }
  3197. return;
  3198. }
  3199. void
  3200. lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
  3201. {
  3202. LIST_HEAD(completions);
  3203. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3204. struct lpfc_iocbq *tmp_iocb, *piocb;
  3205. IOCB_t *cmd = NULL;
  3206. lpfc_fabric_abort_hba(phba);
  3207. spin_lock_irq(&phba->hbalock);
  3208. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  3209. cmd = &piocb->iocb;
  3210. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  3211. continue;
  3212. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  3213. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  3214. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  3215. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  3216. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  3217. continue;
  3218. list_move_tail(&piocb->list, &completions);
  3219. pring->txq_cnt--;
  3220. }
  3221. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3222. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  3223. continue;
  3224. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3225. }
  3226. spin_unlock_irq(&phba->hbalock);
  3227. while (!list_empty(&completions)) {
  3228. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  3229. cmd = &piocb->iocb;
  3230. list_del_init(&piocb->list);
  3231. if (!piocb->iocb_cmpl)
  3232. lpfc_sli_release_iocbq(phba, piocb);
  3233. else {
  3234. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3235. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  3236. (piocb->iocb_cmpl) (phba, piocb, piocb);
  3237. }
  3238. }
  3239. return;
  3240. }
  3241. static void
  3242. lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3243. struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
  3244. {
  3245. struct lpfc_nodelist *ndlp;
  3246. struct ls_rjt stat;
  3247. uint32_t *payload;
  3248. uint32_t cmd, did, newnode, rjt_err = 0;
  3249. IOCB_t *icmd = &elsiocb->iocb;
  3250. if (vport == NULL || elsiocb->context2 == NULL)
  3251. goto dropit;
  3252. newnode = 0;
  3253. payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
  3254. cmd = *payload;
  3255. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
  3256. lpfc_post_buffer(phba, pring, 1, 1);
  3257. did = icmd->un.rcvels.remoteID;
  3258. if (icmd->ulpStatus) {
  3259. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3260. "RCV Unsol ELS: status:x%x/x%x did:x%x",
  3261. icmd->ulpStatus, icmd->un.ulpWord[4], did);
  3262. goto dropit;
  3263. }
  3264. /* Check to see if link went down during discovery */
  3265. if (lpfc_els_chk_latt(vport))
  3266. goto dropit;
  3267. /* Ignore traffic recevied during vport shutdown. */
  3268. if (vport->load_flag & FC_UNLOADING)
  3269. goto dropit;
  3270. ndlp = lpfc_findnode_did(vport, did);
  3271. if (!ndlp) {
  3272. /* Cannot find existing Fabric ndlp, so allocate a new one */
  3273. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3274. if (!ndlp)
  3275. goto dropit;
  3276. lpfc_nlp_init(vport, ndlp, did);
  3277. newnode = 1;
  3278. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
  3279. ndlp->nlp_type |= NLP_FABRIC;
  3280. }
  3281. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
  3282. }
  3283. phba->fc_stat.elsRcvFrame++;
  3284. if (elsiocb->context1)
  3285. lpfc_nlp_put(elsiocb->context1);
  3286. elsiocb->context1 = lpfc_nlp_get(ndlp);
  3287. elsiocb->vport = vport;
  3288. if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
  3289. cmd &= ELS_CMD_MASK;
  3290. }
  3291. /* ELS command <elsCmd> received from NPORT <did> */
  3292. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3293. "0112 ELS command x%x received from NPORT x%x "
  3294. "Data: x%x\n", cmd, did, vport->port_state);
  3295. switch (cmd) {
  3296. case ELS_CMD_PLOGI:
  3297. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3298. "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
  3299. did, vport->port_state, ndlp->nlp_flag);
  3300. phba->fc_stat.elsRcvPLOGI++;
  3301. ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
  3302. if (vport->port_state < LPFC_DISC_AUTH) {
  3303. rjt_err = LSRJT_UNABLE_TPC;
  3304. break;
  3305. }
  3306. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3307. NLP_EVT_RCV_PLOGI);
  3308. break;
  3309. case ELS_CMD_FLOGI:
  3310. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3311. "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
  3312. did, vport->port_state, ndlp->nlp_flag);
  3313. phba->fc_stat.elsRcvFLOGI++;
  3314. lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
  3315. if (newnode)
  3316. lpfc_drop_node(vport, ndlp);
  3317. break;
  3318. case ELS_CMD_LOGO:
  3319. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3320. "RCV LOGO: did:x%x/ste:x%x flg:x%x",
  3321. did, vport->port_state, ndlp->nlp_flag);
  3322. phba->fc_stat.elsRcvLOGO++;
  3323. if (vport->port_state < LPFC_DISC_AUTH) {
  3324. rjt_err = LSRJT_UNABLE_TPC;
  3325. break;
  3326. }
  3327. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
  3328. break;
  3329. case ELS_CMD_PRLO:
  3330. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3331. "RCV PRLO: did:x%x/ste:x%x flg:x%x",
  3332. did, vport->port_state, ndlp->nlp_flag);
  3333. phba->fc_stat.elsRcvPRLO++;
  3334. if (vport->port_state < LPFC_DISC_AUTH) {
  3335. rjt_err = LSRJT_UNABLE_TPC;
  3336. break;
  3337. }
  3338. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
  3339. break;
  3340. case ELS_CMD_RSCN:
  3341. phba->fc_stat.elsRcvRSCN++;
  3342. lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
  3343. if (newnode)
  3344. lpfc_drop_node(vport, ndlp);
  3345. break;
  3346. case ELS_CMD_ADISC:
  3347. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3348. "RCV ADISC: did:x%x/ste:x%x flg:x%x",
  3349. did, vport->port_state, ndlp->nlp_flag);
  3350. phba->fc_stat.elsRcvADISC++;
  3351. if (vport->port_state < LPFC_DISC_AUTH) {
  3352. rjt_err = LSRJT_UNABLE_TPC;
  3353. break;
  3354. }
  3355. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3356. NLP_EVT_RCV_ADISC);
  3357. break;
  3358. case ELS_CMD_PDISC:
  3359. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3360. "RCV PDISC: did:x%x/ste:x%x flg:x%x",
  3361. did, vport->port_state, ndlp->nlp_flag);
  3362. phba->fc_stat.elsRcvPDISC++;
  3363. if (vport->port_state < LPFC_DISC_AUTH) {
  3364. rjt_err = LSRJT_UNABLE_TPC;
  3365. break;
  3366. }
  3367. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3368. NLP_EVT_RCV_PDISC);
  3369. break;
  3370. case ELS_CMD_FARPR:
  3371. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3372. "RCV FARPR: did:x%x/ste:x%x flg:x%x",
  3373. did, vport->port_state, ndlp->nlp_flag);
  3374. phba->fc_stat.elsRcvFARPR++;
  3375. lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
  3376. break;
  3377. case ELS_CMD_FARP:
  3378. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3379. "RCV FARP: did:x%x/ste:x%x flg:x%x",
  3380. did, vport->port_state, ndlp->nlp_flag);
  3381. phba->fc_stat.elsRcvFARP++;
  3382. lpfc_els_rcv_farp(vport, elsiocb, ndlp);
  3383. break;
  3384. case ELS_CMD_FAN:
  3385. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3386. "RCV FAN: did:x%x/ste:x%x flg:x%x",
  3387. did, vport->port_state, ndlp->nlp_flag);
  3388. phba->fc_stat.elsRcvFAN++;
  3389. lpfc_els_rcv_fan(vport, elsiocb, ndlp);
  3390. break;
  3391. case ELS_CMD_PRLI:
  3392. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3393. "RCV PRLI: did:x%x/ste:x%x flg:x%x",
  3394. did, vport->port_state, ndlp->nlp_flag);
  3395. phba->fc_stat.elsRcvPRLI++;
  3396. if (vport->port_state < LPFC_DISC_AUTH) {
  3397. rjt_err = LSRJT_UNABLE_TPC;
  3398. break;
  3399. }
  3400. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
  3401. break;
  3402. case ELS_CMD_LIRR:
  3403. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3404. "RCV LIRR: did:x%x/ste:x%x flg:x%x",
  3405. did, vport->port_state, ndlp->nlp_flag);
  3406. phba->fc_stat.elsRcvLIRR++;
  3407. lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
  3408. if (newnode)
  3409. lpfc_drop_node(vport, ndlp);
  3410. break;
  3411. case ELS_CMD_RPS:
  3412. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3413. "RCV RPS: did:x%x/ste:x%x flg:x%x",
  3414. did, vport->port_state, ndlp->nlp_flag);
  3415. phba->fc_stat.elsRcvRPS++;
  3416. lpfc_els_rcv_rps(vport, elsiocb, ndlp);
  3417. if (newnode)
  3418. lpfc_drop_node(vport, ndlp);
  3419. break;
  3420. case ELS_CMD_RPL:
  3421. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3422. "RCV RPL: did:x%x/ste:x%x flg:x%x",
  3423. did, vport->port_state, ndlp->nlp_flag);
  3424. phba->fc_stat.elsRcvRPL++;
  3425. lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
  3426. if (newnode)
  3427. lpfc_drop_node(vport, ndlp);
  3428. break;
  3429. case ELS_CMD_RNID:
  3430. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3431. "RCV RNID: did:x%x/ste:x%x flg:x%x",
  3432. did, vport->port_state, ndlp->nlp_flag);
  3433. phba->fc_stat.elsRcvRNID++;
  3434. lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
  3435. if (newnode)
  3436. lpfc_drop_node(vport, ndlp);
  3437. break;
  3438. default:
  3439. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3440. "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
  3441. cmd, did, vport->port_state);
  3442. /* Unsupported ELS command, reject */
  3443. rjt_err = LSRJT_INVALID_CMD;
  3444. /* Unknown ELS command <elsCmd> received from NPORT <did> */
  3445. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3446. "0115 Unknown ELS command x%x "
  3447. "received from NPORT x%x\n", cmd, did);
  3448. if (newnode)
  3449. lpfc_drop_node(vport, ndlp);
  3450. break;
  3451. }
  3452. /* check if need to LS_RJT received ELS cmd */
  3453. if (rjt_err) {
  3454. memset(&stat, 0, sizeof(stat));
  3455. stat.un.b.lsRjtRsnCode = rjt_err;
  3456. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  3457. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
  3458. NULL);
  3459. }
  3460. return;
  3461. dropit:
  3462. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  3463. "(%d):0111 Dropping received ELS cmd "
  3464. "Data: x%x x%x x%x\n",
  3465. vport ? vport->vpi : 0xffff, icmd->ulpStatus,
  3466. icmd->un.ulpWord[4], icmd->ulpTimeout);
  3467. phba->fc_stat.elsRcvDrop++;
  3468. }
  3469. static struct lpfc_vport *
  3470. lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
  3471. {
  3472. struct lpfc_vport *vport;
  3473. unsigned long flags;
  3474. spin_lock_irqsave(&phba->hbalock, flags);
  3475. list_for_each_entry(vport, &phba->port_list, listentry) {
  3476. if (vport->vpi == vpi) {
  3477. spin_unlock_irqrestore(&phba->hbalock, flags);
  3478. return vport;
  3479. }
  3480. }
  3481. spin_unlock_irqrestore(&phba->hbalock, flags);
  3482. return NULL;
  3483. }
  3484. void
  3485. lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3486. struct lpfc_iocbq *elsiocb)
  3487. {
  3488. struct lpfc_vport *vport = phba->pport;
  3489. IOCB_t *icmd = &elsiocb->iocb;
  3490. dma_addr_t paddr;
  3491. struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
  3492. struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
  3493. elsiocb->context2 = NULL;
  3494. elsiocb->context3 = NULL;
  3495. if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
  3496. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  3497. } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
  3498. (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
  3499. phba->fc_stat.NoRcvBuf++;
  3500. /* Not enough posted buffers; Try posting more buffers */
  3501. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  3502. lpfc_post_buffer(phba, pring, 0, 1);
  3503. return;
  3504. }
  3505. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3506. (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
  3507. icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  3508. if (icmd->unsli3.rcvsli3.vpi == 0xffff)
  3509. vport = phba->pport;
  3510. else {
  3511. uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
  3512. vport = lpfc_find_vport_by_vpid(phba, vpi);
  3513. }
  3514. }
  3515. /* If there are no BDEs associated
  3516. * with this IOCB, there is nothing to do.
  3517. */
  3518. if (icmd->ulpBdeCount == 0)
  3519. return;
  3520. /* type of ELS cmd is first 32bit word
  3521. * in packet
  3522. */
  3523. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3524. elsiocb->context2 = bdeBuf1;
  3525. } else {
  3526. paddr = getPaddr(icmd->un.cont64[0].addrHigh,
  3527. icmd->un.cont64[0].addrLow);
  3528. elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
  3529. paddr);
  3530. }
  3531. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  3532. /*
  3533. * The different unsolicited event handlers would tell us
  3534. * if they are done with "mp" by setting context2 to NULL.
  3535. */
  3536. lpfc_nlp_put(elsiocb->context1);
  3537. elsiocb->context1 = NULL;
  3538. if (elsiocb->context2) {
  3539. lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
  3540. elsiocb->context2 = NULL;
  3541. }
  3542. /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
  3543. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
  3544. icmd->ulpBdeCount == 2) {
  3545. elsiocb->context2 = bdeBuf2;
  3546. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  3547. /* free mp if we are done with it */
  3548. if (elsiocb->context2) {
  3549. lpfc_in_buf_free(phba, elsiocb->context2);
  3550. elsiocb->context2 = NULL;
  3551. }
  3552. }
  3553. }
  3554. void
  3555. lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  3556. {
  3557. struct lpfc_nodelist *ndlp, *ndlp_fdmi;
  3558. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  3559. if (!ndlp) {
  3560. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3561. if (!ndlp) {
  3562. if (phba->fc_topology == TOPOLOGY_LOOP) {
  3563. lpfc_disc_start(vport);
  3564. return;
  3565. }
  3566. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3567. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3568. "0251 NameServer login: no memory\n");
  3569. return;
  3570. }
  3571. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  3572. ndlp->nlp_type |= NLP_FABRIC;
  3573. }
  3574. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  3575. if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
  3576. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3577. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3578. "0252 Cannot issue NameServer login\n");
  3579. return;
  3580. }
  3581. if (vport->cfg_fdmi_on) {
  3582. ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
  3583. GFP_KERNEL);
  3584. if (ndlp_fdmi) {
  3585. lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
  3586. ndlp_fdmi->nlp_type |= NLP_FABRIC;
  3587. ndlp_fdmi->nlp_state =
  3588. NLP_STE_PLOGI_ISSUE;
  3589. lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
  3590. 0);
  3591. }
  3592. }
  3593. return;
  3594. }
  3595. static void
  3596. lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3597. {
  3598. struct lpfc_vport *vport = pmb->vport;
  3599. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3600. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3601. MAILBOX_t *mb = &pmb->mb;
  3602. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  3603. lpfc_nlp_put(ndlp);
  3604. if (mb->mbxStatus) {
  3605. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3606. "0915 Register VPI failed: 0x%x\n",
  3607. mb->mbxStatus);
  3608. switch (mb->mbxStatus) {
  3609. case 0x11: /* unsupported feature */
  3610. case 0x9603: /* max_vpi exceeded */
  3611. /* giving up on vport registration */
  3612. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3613. spin_lock_irq(shost->host_lock);
  3614. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  3615. spin_unlock_irq(shost->host_lock);
  3616. lpfc_can_disctmo(vport);
  3617. break;
  3618. default:
  3619. /* Try to recover from this error */
  3620. lpfc_mbx_unreg_vpi(vport);
  3621. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  3622. lpfc_initial_fdisc(vport);
  3623. break;
  3624. }
  3625. } else {
  3626. if (vport == phba->pport)
  3627. lpfc_issue_fabric_reglogin(vport);
  3628. else
  3629. lpfc_do_scr_ns_plogi(phba, vport);
  3630. }
  3631. mempool_free(pmb, phba->mbox_mem_pool);
  3632. return;
  3633. }
  3634. void
  3635. lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
  3636. struct lpfc_nodelist *ndlp)
  3637. {
  3638. LPFC_MBOXQ_t *mbox;
  3639. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3640. if (mbox) {
  3641. lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
  3642. mbox->vport = vport;
  3643. mbox->context2 = lpfc_nlp_get(ndlp);
  3644. mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
  3645. if (lpfc_sli_issue_mbox(phba, mbox,
  3646. MBX_NOWAIT | MBX_STOP_IOCB)
  3647. == MBX_NOT_FINISHED) {
  3648. mempool_free(mbox, phba->mbox_mem_pool);
  3649. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  3650. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3651. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3652. "0253 Register VPI: Can't send mbox\n");
  3653. }
  3654. } else {
  3655. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3656. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3657. "0254 Register VPI: no memory\n");
  3658. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  3659. lpfc_nlp_put(ndlp);
  3660. }
  3661. }
  3662. static void
  3663. lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3664. struct lpfc_iocbq *rspiocb)
  3665. {
  3666. struct lpfc_vport *vport = cmdiocb->vport;
  3667. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3668. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  3669. struct lpfc_nodelist *np;
  3670. struct lpfc_nodelist *next_np;
  3671. IOCB_t *irsp = &rspiocb->iocb;
  3672. struct lpfc_iocbq *piocb;
  3673. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3674. "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
  3675. irsp->ulpStatus, irsp->un.ulpWord[4],
  3676. vport->fc_prevDID);
  3677. /* Since all FDISCs are being single threaded, we
  3678. * must reset the discovery timer for ALL vports
  3679. * waiting to send FDISC when one completes.
  3680. */
  3681. list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
  3682. lpfc_set_disctmo(piocb->vport);
  3683. }
  3684. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3685. "FDISC cmpl: status:x%x/x%x prevdid:x%x",
  3686. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
  3687. if (irsp->ulpStatus) {
  3688. /* Check for retry */
  3689. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  3690. goto out;
  3691. /* FDISC failed */
  3692. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3693. "0124 FDISC failed. (%d/%d)\n",
  3694. irsp->ulpStatus, irsp->un.ulpWord[4]);
  3695. if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
  3696. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3697. lpfc_nlp_put(ndlp);
  3698. /* giving up on FDISC. Cancel discovery timer */
  3699. lpfc_can_disctmo(vport);
  3700. } else {
  3701. spin_lock_irq(shost->host_lock);
  3702. vport->fc_flag |= FC_FABRIC;
  3703. if (vport->phba->fc_topology == TOPOLOGY_LOOP)
  3704. vport->fc_flag |= FC_PUBLIC_LOOP;
  3705. spin_unlock_irq(shost->host_lock);
  3706. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  3707. lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
  3708. if ((vport->fc_prevDID != vport->fc_myDID) &&
  3709. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  3710. /* If our NportID changed, we need to ensure all
  3711. * remaining NPORTs get unreg_login'ed so we can
  3712. * issue unreg_vpi.
  3713. */
  3714. list_for_each_entry_safe(np, next_np,
  3715. &vport->fc_nodes, nlp_listp) {
  3716. if (np->nlp_state != NLP_STE_NPR_NODE
  3717. || !(np->nlp_flag & NLP_NPR_ADISC))
  3718. continue;
  3719. spin_lock_irq(shost->host_lock);
  3720. np->nlp_flag &= ~NLP_NPR_ADISC;
  3721. spin_unlock_irq(shost->host_lock);
  3722. lpfc_unreg_rpi(vport, np);
  3723. }
  3724. lpfc_mbx_unreg_vpi(vport);
  3725. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  3726. }
  3727. if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  3728. lpfc_register_new_vport(phba, vport, ndlp);
  3729. else
  3730. lpfc_do_scr_ns_plogi(phba, vport);
  3731. lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
  3732. }
  3733. out:
  3734. lpfc_els_free_iocb(phba, cmdiocb);
  3735. }
  3736. int
  3737. lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3738. uint8_t retry)
  3739. {
  3740. struct lpfc_hba *phba = vport->phba;
  3741. IOCB_t *icmd;
  3742. struct lpfc_iocbq *elsiocb;
  3743. struct serv_parm *sp;
  3744. uint8_t *pcmd;
  3745. uint16_t cmdsize;
  3746. int did = ndlp->nlp_DID;
  3747. int rc;
  3748. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  3749. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  3750. ELS_CMD_FDISC);
  3751. if (!elsiocb) {
  3752. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3753. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3754. "0255 Issue FDISC: no IOCB\n");
  3755. return 1;
  3756. }
  3757. icmd = &elsiocb->iocb;
  3758. icmd->un.elsreq64.myID = 0;
  3759. icmd->un.elsreq64.fl = 1;
  3760. /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
  3761. icmd->ulpCt_h = 1;
  3762. icmd->ulpCt_l = 0;
  3763. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3764. *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
  3765. pcmd += sizeof(uint32_t); /* CSP Word 1 */
  3766. memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
  3767. sp = (struct serv_parm *) pcmd;
  3768. /* Setup CSPs accordingly for Fabric */
  3769. sp->cmn.e_d_tov = 0;
  3770. sp->cmn.w2.r_a_tov = 0;
  3771. sp->cls1.classValid = 0;
  3772. sp->cls2.seqDelivery = 1;
  3773. sp->cls3.seqDelivery = 1;
  3774. pcmd += sizeof(uint32_t); /* CSP Word 2 */
  3775. pcmd += sizeof(uint32_t); /* CSP Word 3 */
  3776. pcmd += sizeof(uint32_t); /* CSP Word 4 */
  3777. pcmd += sizeof(uint32_t); /* Port Name */
  3778. memcpy(pcmd, &vport->fc_portname, 8);
  3779. pcmd += sizeof(uint32_t); /* Node Name */
  3780. pcmd += sizeof(uint32_t); /* Node Name */
  3781. memcpy(pcmd, &vport->fc_nodename, 8);
  3782. lpfc_set_disctmo(vport);
  3783. phba->fc_stat.elsXmitFDISC++;
  3784. elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
  3785. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3786. "Issue FDISC: did:x%x",
  3787. did, 0, 0);
  3788. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  3789. if (rc == IOCB_ERROR) {
  3790. lpfc_els_free_iocb(phba, elsiocb);
  3791. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3792. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3793. "0256 Issue FDISC: Cannot send IOCB\n");
  3794. return 1;
  3795. }
  3796. lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
  3797. vport->port_state = LPFC_FDISC;
  3798. return 0;
  3799. }
  3800. static void
  3801. lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3802. struct lpfc_iocbq *rspiocb)
  3803. {
  3804. struct lpfc_vport *vport = cmdiocb->vport;
  3805. IOCB_t *irsp;
  3806. irsp = &rspiocb->iocb;
  3807. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3808. "LOGO npiv cmpl: status:x%x/x%x did:x%x",
  3809. irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
  3810. lpfc_els_free_iocb(phba, cmdiocb);
  3811. vport->unreg_vpi_cmpl = VPORT_ERROR;
  3812. }
  3813. int
  3814. lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3815. {
  3816. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3817. struct lpfc_hba *phba = vport->phba;
  3818. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3819. IOCB_t *icmd;
  3820. struct lpfc_iocbq *elsiocb;
  3821. uint8_t *pcmd;
  3822. uint16_t cmdsize;
  3823. cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
  3824. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
  3825. ELS_CMD_LOGO);
  3826. if (!elsiocb)
  3827. return 1;
  3828. icmd = &elsiocb->iocb;
  3829. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3830. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  3831. pcmd += sizeof(uint32_t);
  3832. /* Fill in LOGO payload */
  3833. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  3834. pcmd += sizeof(uint32_t);
  3835. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  3836. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3837. "Issue LOGO npiv did:x%x flg:x%x",
  3838. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3839. elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
  3840. spin_lock_irq(shost->host_lock);
  3841. ndlp->nlp_flag |= NLP_LOGO_SND;
  3842. spin_unlock_irq(shost->host_lock);
  3843. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  3844. spin_lock_irq(shost->host_lock);
  3845. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  3846. spin_unlock_irq(shost->host_lock);
  3847. lpfc_els_free_iocb(phba, elsiocb);
  3848. return 1;
  3849. }
  3850. return 0;
  3851. }
  3852. void
  3853. lpfc_fabric_block_timeout(unsigned long ptr)
  3854. {
  3855. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  3856. unsigned long iflags;
  3857. uint32_t tmo_posted;
  3858. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  3859. tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
  3860. if (!tmo_posted)
  3861. phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
  3862. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  3863. if (!tmo_posted) {
  3864. spin_lock_irqsave(&phba->hbalock, iflags);
  3865. if (phba->work_wait)
  3866. lpfc_worker_wake_up(phba);
  3867. spin_unlock_irqrestore(&phba->hbalock, iflags);
  3868. }
  3869. }
  3870. static void
  3871. lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
  3872. {
  3873. struct lpfc_iocbq *iocb;
  3874. unsigned long iflags;
  3875. int ret;
  3876. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3877. IOCB_t *cmd;
  3878. repeat:
  3879. iocb = NULL;
  3880. spin_lock_irqsave(&phba->hbalock, iflags);
  3881. /* Post any pending iocb to the SLI layer */
  3882. if (atomic_read(&phba->fabric_iocb_count) == 0) {
  3883. list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
  3884. list);
  3885. if (iocb)
  3886. atomic_inc(&phba->fabric_iocb_count);
  3887. }
  3888. spin_unlock_irqrestore(&phba->hbalock, iflags);
  3889. if (iocb) {
  3890. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  3891. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  3892. iocb->iocb_flag |= LPFC_IO_FABRIC;
  3893. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  3894. "Fabric sched1: ste:x%x",
  3895. iocb->vport->port_state, 0, 0);
  3896. ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
  3897. if (ret == IOCB_ERROR) {
  3898. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  3899. iocb->fabric_iocb_cmpl = NULL;
  3900. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  3901. cmd = &iocb->iocb;
  3902. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3903. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  3904. iocb->iocb_cmpl(phba, iocb, iocb);
  3905. atomic_dec(&phba->fabric_iocb_count);
  3906. goto repeat;
  3907. }
  3908. }
  3909. return;
  3910. }
  3911. void
  3912. lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
  3913. {
  3914. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  3915. lpfc_resume_fabric_iocbs(phba);
  3916. return;
  3917. }
  3918. static void
  3919. lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
  3920. {
  3921. int blocked;
  3922. blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  3923. /* Start a timer to unblock fabric
  3924. * iocbs after 100ms
  3925. */
  3926. if (!blocked)
  3927. mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
  3928. return;
  3929. }
  3930. static void
  3931. lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3932. struct lpfc_iocbq *rspiocb)
  3933. {
  3934. struct ls_rjt stat;
  3935. if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
  3936. BUG();
  3937. switch (rspiocb->iocb.ulpStatus) {
  3938. case IOSTAT_NPORT_RJT:
  3939. case IOSTAT_FABRIC_RJT:
  3940. if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  3941. lpfc_block_fabric_iocbs(phba);
  3942. }
  3943. break;
  3944. case IOSTAT_NPORT_BSY:
  3945. case IOSTAT_FABRIC_BSY:
  3946. lpfc_block_fabric_iocbs(phba);
  3947. break;
  3948. case IOSTAT_LS_RJT:
  3949. stat.un.lsRjtError =
  3950. be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
  3951. if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
  3952. (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
  3953. lpfc_block_fabric_iocbs(phba);
  3954. break;
  3955. }
  3956. if (atomic_read(&phba->fabric_iocb_count) == 0)
  3957. BUG();
  3958. cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
  3959. cmdiocb->fabric_iocb_cmpl = NULL;
  3960. cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
  3961. cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
  3962. atomic_dec(&phba->fabric_iocb_count);
  3963. if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
  3964. /* Post any pending iocbs to HBA */
  3965. lpfc_resume_fabric_iocbs(phba);
  3966. }
  3967. }
  3968. int
  3969. lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
  3970. {
  3971. unsigned long iflags;
  3972. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3973. int ready;
  3974. int ret;
  3975. if (atomic_read(&phba->fabric_iocb_count) > 1)
  3976. BUG();
  3977. spin_lock_irqsave(&phba->hbalock, iflags);
  3978. ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
  3979. !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  3980. spin_unlock_irqrestore(&phba->hbalock, iflags);
  3981. if (ready) {
  3982. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  3983. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  3984. iocb->iocb_flag |= LPFC_IO_FABRIC;
  3985. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  3986. "Fabric sched2: ste:x%x",
  3987. iocb->vport->port_state, 0, 0);
  3988. atomic_inc(&phba->fabric_iocb_count);
  3989. ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
  3990. if (ret == IOCB_ERROR) {
  3991. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  3992. iocb->fabric_iocb_cmpl = NULL;
  3993. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  3994. atomic_dec(&phba->fabric_iocb_count);
  3995. }
  3996. } else {
  3997. spin_lock_irqsave(&phba->hbalock, iflags);
  3998. list_add_tail(&iocb->list, &phba->fabric_iocb_list);
  3999. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4000. ret = IOCB_SUCCESS;
  4001. }
  4002. return ret;
  4003. }
  4004. void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
  4005. {
  4006. LIST_HEAD(completions);
  4007. struct lpfc_hba *phba = vport->phba;
  4008. struct lpfc_iocbq *tmp_iocb, *piocb;
  4009. IOCB_t *cmd;
  4010. spin_lock_irq(&phba->hbalock);
  4011. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  4012. list) {
  4013. if (piocb->vport != vport)
  4014. continue;
  4015. list_move_tail(&piocb->list, &completions);
  4016. }
  4017. spin_unlock_irq(&phba->hbalock);
  4018. while (!list_empty(&completions)) {
  4019. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4020. list_del_init(&piocb->list);
  4021. cmd = &piocb->iocb;
  4022. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4023. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4024. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4025. }
  4026. }
  4027. void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
  4028. {
  4029. LIST_HEAD(completions);
  4030. struct lpfc_hba *phba = ndlp->vport->phba;
  4031. struct lpfc_iocbq *tmp_iocb, *piocb;
  4032. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4033. IOCB_t *cmd;
  4034. spin_lock_irq(&phba->hbalock);
  4035. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  4036. list) {
  4037. if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
  4038. list_move_tail(&piocb->list, &completions);
  4039. }
  4040. }
  4041. spin_unlock_irq(&phba->hbalock);
  4042. while (!list_empty(&completions)) {
  4043. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4044. list_del_init(&piocb->list);
  4045. cmd = &piocb->iocb;
  4046. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4047. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4048. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4049. }
  4050. }
  4051. void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
  4052. {
  4053. LIST_HEAD(completions);
  4054. struct lpfc_iocbq *piocb;
  4055. IOCB_t *cmd;
  4056. spin_lock_irq(&phba->hbalock);
  4057. list_splice_init(&phba->fabric_iocb_list, &completions);
  4058. spin_unlock_irq(&phba->hbalock);
  4059. while (!list_empty(&completions)) {
  4060. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4061. list_del_init(&piocb->list);
  4062. cmd = &piocb->iocb;
  4063. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4064. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4065. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4066. }
  4067. }
  4068. void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
  4069. {
  4070. LIST_HEAD(completions);
  4071. struct lpfc_iocbq *tmp_iocb, *piocb;
  4072. IOCB_t *cmd;
  4073. struct lpfc_nodelist *ndlp;
  4074. spin_lock_irq(&phba->hbalock);
  4075. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  4076. list) {
  4077. cmd = &piocb->iocb;
  4078. ndlp = (struct lpfc_nodelist *) piocb->context1;
  4079. if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
  4080. ndlp != NULL &&
  4081. ndlp->nlp_DID == Fabric_DID)
  4082. list_move_tail(&piocb->list, &completions);
  4083. }
  4084. spin_unlock_irq(&phba->hbalock);
  4085. while (!list_empty(&completions)) {
  4086. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4087. list_del_init(&piocb->list);
  4088. cmd = &piocb->iocb;
  4089. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4090. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4091. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4092. }
  4093. }