lpfc_els.c 128 KB

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