lpfc_els.c 139 KB

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