lpfc_els.c 129 KB

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