lpfc_els.c 127 KB

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