lpfc_els.c 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061
  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. if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
  1674. (cmd == ELS_CMD_FDISC)) {
  1675. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1676. "0124 FDISC failed (3/6) "
  1677. "retrying...\n");
  1678. lpfc_mbx_unreg_vpi(vport);
  1679. retry = 1;
  1680. /* FDISC retry policy */
  1681. maxretry = 48;
  1682. if (cmdiocb->retry >= 32)
  1683. delay = 1000;
  1684. }
  1685. break;
  1686. case IOERR_NO_RESOURCES:
  1687. logerr = 1; /* HBA out of resources */
  1688. retry = 1;
  1689. if (cmdiocb->retry > 100)
  1690. delay = 100;
  1691. maxretry = 250;
  1692. break;
  1693. case IOERR_ILLEGAL_FRAME:
  1694. delay = 100;
  1695. retry = 1;
  1696. break;
  1697. case IOERR_SEQUENCE_TIMEOUT:
  1698. case IOERR_INVALID_RPI:
  1699. retry = 1;
  1700. break;
  1701. }
  1702. break;
  1703. case IOSTAT_NPORT_RJT:
  1704. case IOSTAT_FABRIC_RJT:
  1705. if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  1706. retry = 1;
  1707. break;
  1708. }
  1709. break;
  1710. case IOSTAT_NPORT_BSY:
  1711. case IOSTAT_FABRIC_BSY:
  1712. logerr = 1; /* Fabric / Remote NPort out of resources */
  1713. retry = 1;
  1714. break;
  1715. case IOSTAT_LS_RJT:
  1716. stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
  1717. /* Added for Vendor specifc support
  1718. * Just keep retrying for these Rsn / Exp codes
  1719. */
  1720. switch (stat.un.b.lsRjtRsnCode) {
  1721. case LSRJT_UNABLE_TPC:
  1722. if (stat.un.b.lsRjtRsnCodeExp ==
  1723. LSEXP_CMD_IN_PROGRESS) {
  1724. if (cmd == ELS_CMD_PLOGI) {
  1725. delay = 1000;
  1726. maxretry = 48;
  1727. }
  1728. retry = 1;
  1729. break;
  1730. }
  1731. if (cmd == ELS_CMD_PLOGI) {
  1732. delay = 1000;
  1733. maxretry = lpfc_max_els_tries + 1;
  1734. retry = 1;
  1735. break;
  1736. }
  1737. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1738. (cmd == ELS_CMD_FDISC) &&
  1739. (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
  1740. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1741. "0125 FDISC Failed (x%x). "
  1742. "Fabric out of resources\n",
  1743. stat.un.lsRjtError);
  1744. lpfc_vport_set_state(vport,
  1745. FC_VPORT_NO_FABRIC_RSCS);
  1746. }
  1747. break;
  1748. case LSRJT_LOGICAL_BSY:
  1749. if ((cmd == ELS_CMD_PLOGI) ||
  1750. (cmd == ELS_CMD_PRLI)) {
  1751. delay = 1000;
  1752. maxretry = 48;
  1753. } else if (cmd == ELS_CMD_FDISC) {
  1754. /* FDISC retry policy */
  1755. maxretry = 48;
  1756. if (cmdiocb->retry >= 32)
  1757. delay = 1000;
  1758. }
  1759. retry = 1;
  1760. break;
  1761. case LSRJT_LOGICAL_ERR:
  1762. case LSRJT_PROTOCOL_ERR:
  1763. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1764. (cmd == ELS_CMD_FDISC) &&
  1765. ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
  1766. (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
  1767. ) {
  1768. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1769. "0123 FDISC Failed (x%x). "
  1770. "Fabric Detected Bad WWN\n",
  1771. stat.un.lsRjtError);
  1772. lpfc_vport_set_state(vport,
  1773. FC_VPORT_FABRIC_REJ_WWN);
  1774. }
  1775. break;
  1776. }
  1777. break;
  1778. case IOSTAT_INTERMED_RSP:
  1779. case IOSTAT_BA_RJT:
  1780. break;
  1781. default:
  1782. break;
  1783. }
  1784. if (did == FDMI_DID)
  1785. retry = 1;
  1786. if ((cmd == ELS_CMD_FLOGI) &&
  1787. (phba->fc_topology != TOPOLOGY_LOOP) &&
  1788. !lpfc_error_lost_link(irsp)) {
  1789. /* FLOGI retry policy */
  1790. retry = 1;
  1791. maxretry = 48;
  1792. if (cmdiocb->retry >= 32)
  1793. delay = 1000;
  1794. }
  1795. if ((++cmdiocb->retry) >= maxretry) {
  1796. phba->fc_stat.elsRetryExceeded++;
  1797. retry = 0;
  1798. }
  1799. if ((vport->load_flag & FC_UNLOADING) != 0)
  1800. retry = 0;
  1801. if (retry) {
  1802. /* Retry ELS command <elsCmd> to remote NPORT <did> */
  1803. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1804. "0107 Retry ELS command x%x to remote "
  1805. "NPORT x%x Data: x%x x%x\n",
  1806. cmd, did, cmdiocb->retry, delay);
  1807. if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
  1808. ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  1809. ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
  1810. /* Don't reset timer for no resources */
  1811. /* If discovery / RSCN timer is running, reset it */
  1812. if (timer_pending(&vport->fc_disctmo) ||
  1813. (vport->fc_flag & FC_RSCN_MODE))
  1814. lpfc_set_disctmo(vport);
  1815. }
  1816. phba->fc_stat.elsXmitRetry++;
  1817. if (ndlp && delay) {
  1818. phba->fc_stat.elsDelayRetry++;
  1819. ndlp->nlp_retry = cmdiocb->retry;
  1820. /* delay is specified in milliseconds */
  1821. mod_timer(&ndlp->nlp_delayfunc,
  1822. jiffies + msecs_to_jiffies(delay));
  1823. spin_lock_irq(shost->host_lock);
  1824. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1825. spin_unlock_irq(shost->host_lock);
  1826. ndlp->nlp_prev_state = ndlp->nlp_state;
  1827. if (cmd == ELS_CMD_PRLI)
  1828. lpfc_nlp_set_state(vport, ndlp,
  1829. NLP_STE_REG_LOGIN_ISSUE);
  1830. else
  1831. lpfc_nlp_set_state(vport, ndlp,
  1832. NLP_STE_NPR_NODE);
  1833. ndlp->nlp_last_elscmd = cmd;
  1834. return 1;
  1835. }
  1836. switch (cmd) {
  1837. case ELS_CMD_FLOGI:
  1838. lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
  1839. return 1;
  1840. case ELS_CMD_FDISC:
  1841. lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
  1842. return 1;
  1843. case ELS_CMD_PLOGI:
  1844. if (ndlp) {
  1845. ndlp->nlp_prev_state = ndlp->nlp_state;
  1846. lpfc_nlp_set_state(vport, ndlp,
  1847. NLP_STE_PLOGI_ISSUE);
  1848. }
  1849. lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
  1850. return 1;
  1851. case ELS_CMD_ADISC:
  1852. ndlp->nlp_prev_state = ndlp->nlp_state;
  1853. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  1854. lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
  1855. return 1;
  1856. case ELS_CMD_PRLI:
  1857. ndlp->nlp_prev_state = ndlp->nlp_state;
  1858. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  1859. lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
  1860. return 1;
  1861. case ELS_CMD_LOGO:
  1862. ndlp->nlp_prev_state = ndlp->nlp_state;
  1863. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1864. lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
  1865. return 1;
  1866. }
  1867. }
  1868. /* No retry ELS command <elsCmd> to remote NPORT <did> */
  1869. if (logerr) {
  1870. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1871. "0137 No retry ELS command x%x to remote "
  1872. "NPORT x%x: Out of Resources: Error:x%x/%x\n",
  1873. cmd, did, irsp->ulpStatus,
  1874. irsp->un.ulpWord[4]);
  1875. }
  1876. else {
  1877. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1878. "0108 No retry ELS command x%x to remote "
  1879. "NPORT x%x Retried:%d Error:x%x/%x\n",
  1880. cmd, did, cmdiocb->retry, irsp->ulpStatus,
  1881. irsp->un.ulpWord[4]);
  1882. }
  1883. return 0;
  1884. }
  1885. static int
  1886. lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
  1887. {
  1888. struct lpfc_dmabuf *buf_ptr;
  1889. /* Free the response before processing the command. */
  1890. if (!list_empty(&buf_ptr1->list)) {
  1891. list_remove_head(&buf_ptr1->list, buf_ptr,
  1892. struct lpfc_dmabuf,
  1893. list);
  1894. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1895. kfree(buf_ptr);
  1896. }
  1897. lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
  1898. kfree(buf_ptr1);
  1899. return 0;
  1900. }
  1901. static int
  1902. lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
  1903. {
  1904. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1905. kfree(buf_ptr);
  1906. return 0;
  1907. }
  1908. int
  1909. lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
  1910. {
  1911. struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
  1912. struct lpfc_nodelist *ndlp;
  1913. ndlp = (struct lpfc_nodelist *)elsiocb->context1;
  1914. if (ndlp) {
  1915. if (ndlp->nlp_flag & NLP_DEFER_RM) {
  1916. lpfc_nlp_put(ndlp);
  1917. /* If the ndlp is not being used by another discovery
  1918. * thread, free it.
  1919. */
  1920. if (!lpfc_nlp_not_used(ndlp)) {
  1921. /* If ndlp is being used by another discovery
  1922. * thread, just clear NLP_DEFER_RM
  1923. */
  1924. ndlp->nlp_flag &= ~NLP_DEFER_RM;
  1925. }
  1926. }
  1927. else
  1928. lpfc_nlp_put(ndlp);
  1929. elsiocb->context1 = NULL;
  1930. }
  1931. /* context2 = cmd, context2->next = rsp, context3 = bpl */
  1932. if (elsiocb->context2) {
  1933. if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
  1934. /* Firmware could still be in progress of DMAing
  1935. * payload, so don't free data buffer till after
  1936. * a hbeat.
  1937. */
  1938. elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
  1939. buf_ptr = elsiocb->context2;
  1940. elsiocb->context2 = NULL;
  1941. if (buf_ptr) {
  1942. buf_ptr1 = NULL;
  1943. spin_lock_irq(&phba->hbalock);
  1944. if (!list_empty(&buf_ptr->list)) {
  1945. list_remove_head(&buf_ptr->list,
  1946. buf_ptr1, struct lpfc_dmabuf,
  1947. list);
  1948. INIT_LIST_HEAD(&buf_ptr1->list);
  1949. list_add_tail(&buf_ptr1->list,
  1950. &phba->elsbuf);
  1951. phba->elsbuf_cnt++;
  1952. }
  1953. INIT_LIST_HEAD(&buf_ptr->list);
  1954. list_add_tail(&buf_ptr->list, &phba->elsbuf);
  1955. phba->elsbuf_cnt++;
  1956. spin_unlock_irq(&phba->hbalock);
  1957. }
  1958. } else {
  1959. buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
  1960. lpfc_els_free_data(phba, buf_ptr1);
  1961. }
  1962. }
  1963. if (elsiocb->context3) {
  1964. buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
  1965. lpfc_els_free_bpl(phba, buf_ptr);
  1966. }
  1967. lpfc_sli_release_iocbq(phba, elsiocb);
  1968. return 0;
  1969. }
  1970. static void
  1971. lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1972. struct lpfc_iocbq *rspiocb)
  1973. {
  1974. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1975. struct lpfc_vport *vport = cmdiocb->vport;
  1976. IOCB_t *irsp;
  1977. irsp = &rspiocb->iocb;
  1978. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  1979. "ACC LOGO cmpl: status:x%x/x%x did:x%x",
  1980. irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
  1981. /* ACC to LOGO completes to NPort <nlp_DID> */
  1982. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1983. "0109 ACC to LOGO completes to NPort x%x "
  1984. "Data: x%x x%x x%x\n",
  1985. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  1986. ndlp->nlp_rpi);
  1987. if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
  1988. /* NPort Recovery mode or node is just allocated */
  1989. if (!lpfc_nlp_not_used(ndlp)) {
  1990. /* If the ndlp is being used by another discovery
  1991. * thread, just unregister the RPI.
  1992. */
  1993. lpfc_unreg_rpi(vport, ndlp);
  1994. } else {
  1995. /* Indicate the node has already released, should
  1996. * not reference to it from within lpfc_els_free_iocb.
  1997. */
  1998. cmdiocb->context1 = NULL;
  1999. }
  2000. }
  2001. lpfc_els_free_iocb(phba, cmdiocb);
  2002. return;
  2003. }
  2004. void
  2005. lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2006. {
  2007. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2008. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2009. pmb->context1 = NULL;
  2010. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2011. kfree(mp);
  2012. mempool_free(pmb, phba->mbox_mem_pool);
  2013. if (ndlp) {
  2014. lpfc_nlp_put(ndlp);
  2015. /* This is the end of the default RPI cleanup logic for this
  2016. * ndlp. If no other discovery threads are using this ndlp.
  2017. * we should free all resources associated with it.
  2018. */
  2019. lpfc_nlp_not_used(ndlp);
  2020. }
  2021. return;
  2022. }
  2023. static void
  2024. lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2025. struct lpfc_iocbq *rspiocb)
  2026. {
  2027. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2028. struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
  2029. struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
  2030. IOCB_t *irsp;
  2031. uint8_t *pcmd;
  2032. LPFC_MBOXQ_t *mbox = NULL;
  2033. struct lpfc_dmabuf *mp = NULL;
  2034. uint32_t ls_rjt = 0;
  2035. irsp = &rspiocb->iocb;
  2036. if (cmdiocb->context_un.mbox)
  2037. mbox = cmdiocb->context_un.mbox;
  2038. /* First determine if this is a LS_RJT cmpl. Note, this callback
  2039. * function can have cmdiocb->contest1 (ndlp) field set to NULL.
  2040. */
  2041. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
  2042. if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
  2043. /* A LS_RJT associated with Default RPI cleanup has its own
  2044. * seperate code path.
  2045. */
  2046. if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  2047. ls_rjt = 1;
  2048. }
  2049. /* Check to see if link went down during discovery */
  2050. if (!ndlp || lpfc_els_chk_latt(vport)) {
  2051. if (mbox) {
  2052. mp = (struct lpfc_dmabuf *) mbox->context1;
  2053. if (mp) {
  2054. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2055. kfree(mp);
  2056. }
  2057. mempool_free(mbox, phba->mbox_mem_pool);
  2058. }
  2059. if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  2060. if (lpfc_nlp_not_used(ndlp)) {
  2061. ndlp = NULL;
  2062. /* Indicate the node has already released,
  2063. * should not reference to it from within
  2064. * the routine lpfc_els_free_iocb.
  2065. */
  2066. cmdiocb->context1 = NULL;
  2067. }
  2068. goto out;
  2069. }
  2070. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2071. "ELS rsp cmpl: status:x%x/x%x did:x%x",
  2072. irsp->ulpStatus, irsp->un.ulpWord[4],
  2073. cmdiocb->iocb.un.elsreq64.remoteID);
  2074. /* ELS response tag <ulpIoTag> completes */
  2075. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2076. "0110 ELS response tag x%x completes "
  2077. "Data: x%x x%x x%x x%x x%x x%x x%x\n",
  2078. cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
  2079. rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
  2080. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2081. ndlp->nlp_rpi);
  2082. if (mbox) {
  2083. if ((rspiocb->iocb.ulpStatus == 0)
  2084. && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
  2085. lpfc_unreg_rpi(vport, ndlp);
  2086. /* Increment reference count to ndlp to hold the
  2087. * reference to ndlp for the callback function.
  2088. */
  2089. mbox->context2 = lpfc_nlp_get(ndlp);
  2090. mbox->vport = vport;
  2091. if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
  2092. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  2093. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  2094. }
  2095. else {
  2096. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  2097. ndlp->nlp_prev_state = ndlp->nlp_state;
  2098. lpfc_nlp_set_state(vport, ndlp,
  2099. NLP_STE_REG_LOGIN_ISSUE);
  2100. }
  2101. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  2102. != MBX_NOT_FINISHED)
  2103. goto out;
  2104. else
  2105. /* Decrement the ndlp reference count we
  2106. * set for this failed mailbox command.
  2107. */
  2108. lpfc_nlp_put(ndlp);
  2109. /* ELS rsp: Cannot issue reg_login for <NPortid> */
  2110. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2111. "0138 ELS rsp: Cannot issue reg_login for x%x "
  2112. "Data: x%x x%x x%x\n",
  2113. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2114. ndlp->nlp_rpi);
  2115. if (lpfc_nlp_not_used(ndlp)) {
  2116. ndlp = NULL;
  2117. /* Indicate node has already been released,
  2118. * should not reference to it from within
  2119. * the routine lpfc_els_free_iocb.
  2120. */
  2121. cmdiocb->context1 = NULL;
  2122. }
  2123. } else {
  2124. /* Do not drop node for lpfc_els_abort'ed ELS cmds */
  2125. if (!lpfc_error_lost_link(irsp) &&
  2126. ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  2127. if (lpfc_nlp_not_used(ndlp)) {
  2128. ndlp = NULL;
  2129. /* Indicate node has already been
  2130. * released, should not reference
  2131. * to it from within the routine
  2132. * lpfc_els_free_iocb.
  2133. */
  2134. cmdiocb->context1 = NULL;
  2135. }
  2136. }
  2137. }
  2138. mp = (struct lpfc_dmabuf *) mbox->context1;
  2139. if (mp) {
  2140. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2141. kfree(mp);
  2142. }
  2143. mempool_free(mbox, phba->mbox_mem_pool);
  2144. }
  2145. out:
  2146. if (ndlp) {
  2147. spin_lock_irq(shost->host_lock);
  2148. ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
  2149. spin_unlock_irq(shost->host_lock);
  2150. /* If the node is not being used by another discovery thread,
  2151. * and we are sending a reject, we are done with it.
  2152. * Release driver reference count here and free associated
  2153. * resources.
  2154. */
  2155. if (ls_rjt)
  2156. if (lpfc_nlp_not_used(ndlp))
  2157. /* Indicate node has already been released,
  2158. * should not reference to it from within
  2159. * the routine lpfc_els_free_iocb.
  2160. */
  2161. cmdiocb->context1 = NULL;
  2162. }
  2163. lpfc_els_free_iocb(phba, cmdiocb);
  2164. return;
  2165. }
  2166. int
  2167. lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
  2168. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  2169. LPFC_MBOXQ_t *mbox)
  2170. {
  2171. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2172. struct lpfc_hba *phba = vport->phba;
  2173. IOCB_t *icmd;
  2174. IOCB_t *oldcmd;
  2175. struct lpfc_iocbq *elsiocb;
  2176. struct lpfc_sli_ring *pring;
  2177. struct lpfc_sli *psli;
  2178. uint8_t *pcmd;
  2179. uint16_t cmdsize;
  2180. int rc;
  2181. ELS_PKT *els_pkt_ptr;
  2182. psli = &phba->sli;
  2183. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2184. oldcmd = &oldiocb->iocb;
  2185. switch (flag) {
  2186. case ELS_CMD_ACC:
  2187. cmdsize = sizeof(uint32_t);
  2188. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2189. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  2190. if (!elsiocb) {
  2191. spin_lock_irq(shost->host_lock);
  2192. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2193. spin_unlock_irq(shost->host_lock);
  2194. return 1;
  2195. }
  2196. icmd = &elsiocb->iocb;
  2197. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2198. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2199. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2200. pcmd += sizeof(uint32_t);
  2201. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2202. "Issue ACC: did:x%x flg:x%x",
  2203. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2204. break;
  2205. case ELS_CMD_PLOGI:
  2206. cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
  2207. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2208. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  2209. if (!elsiocb)
  2210. return 1;
  2211. icmd = &elsiocb->iocb;
  2212. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2213. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2214. if (mbox)
  2215. elsiocb->context_un.mbox = mbox;
  2216. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2217. pcmd += sizeof(uint32_t);
  2218. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  2219. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2220. "Issue ACC PLOGI: did:x%x flg:x%x",
  2221. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2222. break;
  2223. case ELS_CMD_PRLO:
  2224. cmdsize = sizeof(uint32_t) + sizeof(PRLO);
  2225. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2226. ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
  2227. if (!elsiocb)
  2228. return 1;
  2229. icmd = &elsiocb->iocb;
  2230. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2231. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2232. memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
  2233. sizeof(uint32_t) + sizeof(PRLO));
  2234. *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
  2235. els_pkt_ptr = (ELS_PKT *) pcmd;
  2236. els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
  2237. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2238. "Issue ACC PRLO: did:x%x flg:x%x",
  2239. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2240. break;
  2241. default:
  2242. return 1;
  2243. }
  2244. /* Xmit ELS ACC response tag <ulpIoTag> */
  2245. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2246. "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
  2247. "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
  2248. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2249. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2250. ndlp->nlp_rpi);
  2251. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  2252. spin_lock_irq(shost->host_lock);
  2253. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2254. spin_unlock_irq(shost->host_lock);
  2255. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
  2256. } else {
  2257. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2258. }
  2259. phba->fc_stat.elsXmitACC++;
  2260. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2261. if (rc == IOCB_ERROR) {
  2262. lpfc_els_free_iocb(phba, elsiocb);
  2263. return 1;
  2264. }
  2265. return 0;
  2266. }
  2267. int
  2268. lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
  2269. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  2270. LPFC_MBOXQ_t *mbox)
  2271. {
  2272. struct lpfc_hba *phba = vport->phba;
  2273. IOCB_t *icmd;
  2274. IOCB_t *oldcmd;
  2275. struct lpfc_iocbq *elsiocb;
  2276. struct lpfc_sli_ring *pring;
  2277. struct lpfc_sli *psli;
  2278. uint8_t *pcmd;
  2279. uint16_t cmdsize;
  2280. int rc;
  2281. psli = &phba->sli;
  2282. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2283. cmdsize = 2 * sizeof(uint32_t);
  2284. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2285. ndlp->nlp_DID, ELS_CMD_LS_RJT);
  2286. if (!elsiocb)
  2287. return 1;
  2288. icmd = &elsiocb->iocb;
  2289. oldcmd = &oldiocb->iocb;
  2290. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2291. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2292. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  2293. pcmd += sizeof(uint32_t);
  2294. *((uint32_t *) (pcmd)) = rejectError;
  2295. if (mbox)
  2296. elsiocb->context_un.mbox = mbox;
  2297. /* Xmit ELS RJT <err> response tag <ulpIoTag> */
  2298. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2299. "0129 Xmit ELS RJT x%x response tag x%x "
  2300. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  2301. "rpi x%x\n",
  2302. rejectError, elsiocb->iotag,
  2303. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  2304. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  2305. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2306. "Issue LS_RJT: did:x%x flg:x%x err:x%x",
  2307. ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
  2308. phba->fc_stat.elsXmitLSRJT++;
  2309. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2310. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2311. if (rc == IOCB_ERROR) {
  2312. lpfc_els_free_iocb(phba, elsiocb);
  2313. return 1;
  2314. }
  2315. return 0;
  2316. }
  2317. int
  2318. lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  2319. struct lpfc_nodelist *ndlp)
  2320. {
  2321. struct lpfc_hba *phba = vport->phba;
  2322. struct lpfc_sli *psli = &phba->sli;
  2323. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  2324. ADISC *ap;
  2325. IOCB_t *icmd, *oldcmd;
  2326. struct lpfc_iocbq *elsiocb;
  2327. uint8_t *pcmd;
  2328. uint16_t cmdsize;
  2329. int rc;
  2330. cmdsize = sizeof(uint32_t) + sizeof(ADISC);
  2331. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2332. ndlp->nlp_DID, ELS_CMD_ACC);
  2333. if (!elsiocb)
  2334. return 1;
  2335. icmd = &elsiocb->iocb;
  2336. oldcmd = &oldiocb->iocb;
  2337. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2338. /* Xmit ADISC ACC response tag <ulpIoTag> */
  2339. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2340. "0130 Xmit ADISC ACC response iotag x%x xri: "
  2341. "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
  2342. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2343. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2344. ndlp->nlp_rpi);
  2345. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2346. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2347. pcmd += sizeof(uint32_t);
  2348. ap = (ADISC *) (pcmd);
  2349. ap->hardAL_PA = phba->fc_pref_ALPA;
  2350. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2351. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2352. ap->DID = be32_to_cpu(vport->fc_myDID);
  2353. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2354. "Issue ACC ADISC: did:x%x flg:x%x",
  2355. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2356. phba->fc_stat.elsXmitACC++;
  2357. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2358. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2359. if (rc == IOCB_ERROR) {
  2360. lpfc_els_free_iocb(phba, elsiocb);
  2361. return 1;
  2362. }
  2363. return 0;
  2364. }
  2365. int
  2366. lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  2367. struct lpfc_nodelist *ndlp)
  2368. {
  2369. struct lpfc_hba *phba = vport->phba;
  2370. PRLI *npr;
  2371. lpfc_vpd_t *vpd;
  2372. IOCB_t *icmd;
  2373. IOCB_t *oldcmd;
  2374. struct lpfc_iocbq *elsiocb;
  2375. struct lpfc_sli_ring *pring;
  2376. struct lpfc_sli *psli;
  2377. uint8_t *pcmd;
  2378. uint16_t cmdsize;
  2379. int rc;
  2380. psli = &phba->sli;
  2381. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2382. cmdsize = sizeof(uint32_t) + sizeof(PRLI);
  2383. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2384. ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
  2385. if (!elsiocb)
  2386. return 1;
  2387. icmd = &elsiocb->iocb;
  2388. oldcmd = &oldiocb->iocb;
  2389. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2390. /* Xmit PRLI ACC response tag <ulpIoTag> */
  2391. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2392. "0131 Xmit PRLI ACC response tag x%x xri x%x, "
  2393. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  2394. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2395. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2396. ndlp->nlp_rpi);
  2397. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2398. *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
  2399. pcmd += sizeof(uint32_t);
  2400. /* For PRLI, remainder of payload is PRLI parameter page */
  2401. memset(pcmd, 0, sizeof(PRLI));
  2402. npr = (PRLI *) pcmd;
  2403. vpd = &phba->vpd;
  2404. /*
  2405. * If our firmware version is 3.20 or later,
  2406. * set the following bits for FC-TAPE support.
  2407. */
  2408. if (vpd->rev.feaLevelHigh >= 0x02) {
  2409. npr->ConfmComplAllowed = 1;
  2410. npr->Retry = 1;
  2411. npr->TaskRetryIdReq = 1;
  2412. }
  2413. npr->acceptRspCode = PRLI_REQ_EXECUTED;
  2414. npr->estabImagePair = 1;
  2415. npr->readXferRdyDis = 1;
  2416. npr->ConfmComplAllowed = 1;
  2417. npr->prliType = PRLI_FCP_TYPE;
  2418. npr->initiatorFunc = 1;
  2419. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2420. "Issue ACC PRLI: did:x%x flg:x%x",
  2421. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2422. phba->fc_stat.elsXmitACC++;
  2423. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2424. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2425. if (rc == IOCB_ERROR) {
  2426. lpfc_els_free_iocb(phba, elsiocb);
  2427. return 1;
  2428. }
  2429. return 0;
  2430. }
  2431. static int
  2432. lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
  2433. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  2434. {
  2435. struct lpfc_hba *phba = vport->phba;
  2436. RNID *rn;
  2437. IOCB_t *icmd, *oldcmd;
  2438. struct lpfc_iocbq *elsiocb;
  2439. struct lpfc_sli_ring *pring;
  2440. struct lpfc_sli *psli;
  2441. uint8_t *pcmd;
  2442. uint16_t cmdsize;
  2443. int rc;
  2444. psli = &phba->sli;
  2445. pring = &psli->ring[LPFC_ELS_RING];
  2446. cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
  2447. + (2 * sizeof(struct lpfc_name));
  2448. if (format)
  2449. cmdsize += sizeof(RNID_TOP_DISC);
  2450. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2451. ndlp->nlp_DID, ELS_CMD_ACC);
  2452. if (!elsiocb)
  2453. return 1;
  2454. icmd = &elsiocb->iocb;
  2455. oldcmd = &oldiocb->iocb;
  2456. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2457. /* Xmit RNID ACC response tag <ulpIoTag> */
  2458. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2459. "0132 Xmit RNID ACC response tag x%x xri x%x\n",
  2460. elsiocb->iotag, elsiocb->iocb.ulpContext);
  2461. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2462. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2463. pcmd += sizeof(uint32_t);
  2464. memset(pcmd, 0, sizeof(RNID));
  2465. rn = (RNID *) (pcmd);
  2466. rn->Format = format;
  2467. rn->CommonLen = (2 * sizeof(struct lpfc_name));
  2468. memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2469. memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2470. switch (format) {
  2471. case 0:
  2472. rn->SpecificLen = 0;
  2473. break;
  2474. case RNID_TOPOLOGY_DISC:
  2475. rn->SpecificLen = sizeof(RNID_TOP_DISC);
  2476. memcpy(&rn->un.topologyDisc.portName,
  2477. &vport->fc_portname, sizeof(struct lpfc_name));
  2478. rn->un.topologyDisc.unitType = RNID_HBA;
  2479. rn->un.topologyDisc.physPort = 0;
  2480. rn->un.topologyDisc.attachedNodes = 0;
  2481. break;
  2482. default:
  2483. rn->CommonLen = 0;
  2484. rn->SpecificLen = 0;
  2485. break;
  2486. }
  2487. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2488. "Issue ACC RNID: did:x%x flg:x%x",
  2489. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2490. phba->fc_stat.elsXmitACC++;
  2491. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2492. lpfc_nlp_put(ndlp);
  2493. elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
  2494. * it could be freed */
  2495. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2496. if (rc == IOCB_ERROR) {
  2497. lpfc_els_free_iocb(phba, elsiocb);
  2498. return 1;
  2499. }
  2500. return 0;
  2501. }
  2502. int
  2503. lpfc_els_disc_adisc(struct lpfc_vport *vport)
  2504. {
  2505. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2506. struct lpfc_nodelist *ndlp, *next_ndlp;
  2507. int sentadisc = 0;
  2508. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  2509. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2510. if (!NLP_CHK_NODE_ACT(ndlp))
  2511. continue;
  2512. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  2513. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  2514. (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
  2515. spin_lock_irq(shost->host_lock);
  2516. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2517. spin_unlock_irq(shost->host_lock);
  2518. ndlp->nlp_prev_state = ndlp->nlp_state;
  2519. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  2520. lpfc_issue_els_adisc(vport, ndlp, 0);
  2521. sentadisc++;
  2522. vport->num_disc_nodes++;
  2523. if (vport->num_disc_nodes >=
  2524. vport->cfg_discovery_threads) {
  2525. spin_lock_irq(shost->host_lock);
  2526. vport->fc_flag |= FC_NLP_MORE;
  2527. spin_unlock_irq(shost->host_lock);
  2528. break;
  2529. }
  2530. }
  2531. }
  2532. if (sentadisc == 0) {
  2533. spin_lock_irq(shost->host_lock);
  2534. vport->fc_flag &= ~FC_NLP_MORE;
  2535. spin_unlock_irq(shost->host_lock);
  2536. }
  2537. return sentadisc;
  2538. }
  2539. int
  2540. lpfc_els_disc_plogi(struct lpfc_vport *vport)
  2541. {
  2542. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2543. struct lpfc_nodelist *ndlp, *next_ndlp;
  2544. int sentplogi = 0;
  2545. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  2546. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2547. if (!NLP_CHK_NODE_ACT(ndlp))
  2548. continue;
  2549. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  2550. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  2551. (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
  2552. (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
  2553. ndlp->nlp_prev_state = ndlp->nlp_state;
  2554. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2555. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  2556. sentplogi++;
  2557. vport->num_disc_nodes++;
  2558. if (vport->num_disc_nodes >=
  2559. vport->cfg_discovery_threads) {
  2560. spin_lock_irq(shost->host_lock);
  2561. vport->fc_flag |= FC_NLP_MORE;
  2562. spin_unlock_irq(shost->host_lock);
  2563. break;
  2564. }
  2565. }
  2566. }
  2567. if (sentplogi) {
  2568. lpfc_set_disctmo(vport);
  2569. }
  2570. else {
  2571. spin_lock_irq(shost->host_lock);
  2572. vport->fc_flag &= ~FC_NLP_MORE;
  2573. spin_unlock_irq(shost->host_lock);
  2574. }
  2575. return sentplogi;
  2576. }
  2577. void
  2578. lpfc_els_flush_rscn(struct lpfc_vport *vport)
  2579. {
  2580. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2581. struct lpfc_hba *phba = vport->phba;
  2582. int i;
  2583. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  2584. lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
  2585. vport->fc_rscn_id_list[i] = NULL;
  2586. }
  2587. spin_lock_irq(shost->host_lock);
  2588. vport->fc_rscn_id_cnt = 0;
  2589. vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
  2590. spin_unlock_irq(shost->host_lock);
  2591. lpfc_can_disctmo(vport);
  2592. }
  2593. int
  2594. lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
  2595. {
  2596. D_ID ns_did;
  2597. D_ID rscn_did;
  2598. uint32_t *lp;
  2599. uint32_t payload_len, i;
  2600. ns_did.un.word = did;
  2601. /* Never match fabric nodes for RSCNs */
  2602. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  2603. return 0;
  2604. /* If we are doing a FULL RSCN rediscovery, match everything */
  2605. if (vport->fc_flag & FC_RSCN_DISCOVERY)
  2606. return did;
  2607. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  2608. lp = vport->fc_rscn_id_list[i]->virt;
  2609. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  2610. payload_len -= sizeof(uint32_t); /* take off word 0 */
  2611. while (payload_len) {
  2612. rscn_did.un.word = be32_to_cpu(*lp++);
  2613. payload_len -= sizeof(uint32_t);
  2614. switch (rscn_did.un.b.resv) {
  2615. case 0: /* Single N_Port ID effected */
  2616. if (ns_did.un.word == rscn_did.un.word)
  2617. return did;
  2618. break;
  2619. case 1: /* Whole N_Port Area effected */
  2620. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  2621. && (ns_did.un.b.area == rscn_did.un.b.area))
  2622. return did;
  2623. break;
  2624. case 2: /* Whole N_Port Domain effected */
  2625. if (ns_did.un.b.domain == rscn_did.un.b.domain)
  2626. return did;
  2627. break;
  2628. default:
  2629. /* Unknown Identifier in RSCN node */
  2630. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2631. "0217 Unknown Identifier in "
  2632. "RSCN payload Data: x%x\n",
  2633. rscn_did.un.word);
  2634. case 3: /* Whole Fabric effected */
  2635. return did;
  2636. }
  2637. }
  2638. }
  2639. return 0;
  2640. }
  2641. static int
  2642. lpfc_rscn_recovery_check(struct lpfc_vport *vport)
  2643. {
  2644. struct lpfc_nodelist *ndlp = NULL;
  2645. /* Look at all nodes effected by pending RSCNs and move
  2646. * them to NPR state.
  2647. */
  2648. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  2649. if (!NLP_CHK_NODE_ACT(ndlp) ||
  2650. ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
  2651. lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
  2652. continue;
  2653. lpfc_disc_state_machine(vport, ndlp, NULL,
  2654. NLP_EVT_DEVICE_RECOVERY);
  2655. /*
  2656. * Make sure NLP_DELAY_TMO is NOT running after a device
  2657. * recovery event.
  2658. */
  2659. if (ndlp->nlp_flag & NLP_DELAY_TMO)
  2660. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2661. }
  2662. return 0;
  2663. }
  2664. static int
  2665. lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2666. struct lpfc_nodelist *ndlp)
  2667. {
  2668. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2669. struct lpfc_hba *phba = vport->phba;
  2670. struct lpfc_dmabuf *pcmd;
  2671. uint32_t *lp, *datap;
  2672. IOCB_t *icmd;
  2673. uint32_t payload_len, length, nportid, *cmd;
  2674. int rscn_cnt = vport->fc_rscn_id_cnt;
  2675. int rscn_id = 0, hba_id = 0;
  2676. int i;
  2677. icmd = &cmdiocb->iocb;
  2678. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2679. lp = (uint32_t *) pcmd->virt;
  2680. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  2681. payload_len -= sizeof(uint32_t); /* take off word 0 */
  2682. /* RSCN received */
  2683. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2684. "0214 RSCN received Data: x%x x%x x%x x%x\n",
  2685. vport->fc_flag, payload_len, *lp, rscn_cnt);
  2686. for (i = 0; i < payload_len/sizeof(uint32_t); i++)
  2687. fc_host_post_event(shost, fc_get_event_number(),
  2688. FCH_EVT_RSCN, lp[i]);
  2689. /* If we are about to begin discovery, just ACC the RSCN.
  2690. * Discovery processing will satisfy it.
  2691. */
  2692. if (vport->port_state <= LPFC_NS_QRY) {
  2693. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2694. "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
  2695. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  2696. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2697. return 0;
  2698. }
  2699. /* If this RSCN just contains NPortIDs for other vports on this HBA,
  2700. * just ACC and ignore it.
  2701. */
  2702. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2703. !(vport->cfg_peer_port_login)) {
  2704. i = payload_len;
  2705. datap = lp;
  2706. while (i > 0) {
  2707. nportid = *datap++;
  2708. nportid = ((be32_to_cpu(nportid)) & Mask_DID);
  2709. i -= sizeof(uint32_t);
  2710. rscn_id++;
  2711. if (lpfc_find_vport_by_did(phba, nportid))
  2712. hba_id++;
  2713. }
  2714. if (rscn_id == hba_id) {
  2715. /* ALL NPortIDs in RSCN are on HBA */
  2716. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2717. "0214 Ignore RSCN "
  2718. "Data: x%x x%x x%x x%x\n",
  2719. vport->fc_flag, payload_len,
  2720. *lp, rscn_cnt);
  2721. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2722. "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
  2723. ndlp->nlp_DID, vport->port_state,
  2724. ndlp->nlp_flag);
  2725. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
  2726. ndlp, NULL);
  2727. return 0;
  2728. }
  2729. }
  2730. /* If we are already processing an RSCN, save the received
  2731. * RSCN payload buffer, cmdiocb->context2 to process later.
  2732. */
  2733. if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
  2734. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2735. "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
  2736. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  2737. spin_lock_irq(shost->host_lock);
  2738. vport->fc_flag |= FC_RSCN_DEFERRED;
  2739. if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
  2740. !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
  2741. vport->fc_flag |= FC_RSCN_MODE;
  2742. spin_unlock_irq(shost->host_lock);
  2743. if (rscn_cnt) {
  2744. cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
  2745. length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
  2746. }
  2747. if ((rscn_cnt) &&
  2748. (payload_len + length <= LPFC_BPL_SIZE)) {
  2749. *cmd &= ELS_CMD_MASK;
  2750. *cmd |= be32_to_cpu(payload_len + length);
  2751. memcpy(((uint8_t *)cmd) + length, lp,
  2752. payload_len);
  2753. } else {
  2754. vport->fc_rscn_id_list[rscn_cnt] = pcmd;
  2755. vport->fc_rscn_id_cnt++;
  2756. /* If we zero, cmdiocb->context2, the calling
  2757. * routine will not try to free it.
  2758. */
  2759. cmdiocb->context2 = NULL;
  2760. }
  2761. /* Deferred RSCN */
  2762. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2763. "0235 Deferred RSCN "
  2764. "Data: x%x x%x x%x\n",
  2765. vport->fc_rscn_id_cnt, vport->fc_flag,
  2766. vport->port_state);
  2767. } else {
  2768. vport->fc_flag |= FC_RSCN_DISCOVERY;
  2769. spin_unlock_irq(shost->host_lock);
  2770. /* ReDiscovery RSCN */
  2771. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2772. "0234 ReDiscovery RSCN "
  2773. "Data: x%x x%x x%x\n",
  2774. vport->fc_rscn_id_cnt, vport->fc_flag,
  2775. vport->port_state);
  2776. }
  2777. /* Send back ACC */
  2778. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2779. /* send RECOVERY event for ALL nodes that match RSCN payload */
  2780. lpfc_rscn_recovery_check(vport);
  2781. spin_lock_irq(shost->host_lock);
  2782. vport->fc_flag &= ~FC_RSCN_DEFERRED;
  2783. spin_unlock_irq(shost->host_lock);
  2784. return 0;
  2785. }
  2786. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2787. "RCV RSCN: did:x%x/ste:x%x flg:x%x",
  2788. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  2789. spin_lock_irq(shost->host_lock);
  2790. vport->fc_flag |= FC_RSCN_MODE;
  2791. spin_unlock_irq(shost->host_lock);
  2792. vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
  2793. /*
  2794. * If we zero, cmdiocb->context2, the calling routine will
  2795. * not try to free it.
  2796. */
  2797. cmdiocb->context2 = NULL;
  2798. lpfc_set_disctmo(vport);
  2799. /* Send back ACC */
  2800. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2801. /* send RECOVERY event for ALL nodes that match RSCN payload */
  2802. lpfc_rscn_recovery_check(vport);
  2803. return lpfc_els_handle_rscn(vport);
  2804. }
  2805. int
  2806. lpfc_els_handle_rscn(struct lpfc_vport *vport)
  2807. {
  2808. struct lpfc_nodelist *ndlp;
  2809. struct lpfc_hba *phba = vport->phba;
  2810. /* Ignore RSCN if the port is being torn down. */
  2811. if (vport->load_flag & FC_UNLOADING) {
  2812. lpfc_els_flush_rscn(vport);
  2813. return 0;
  2814. }
  2815. /* Start timer for RSCN processing */
  2816. lpfc_set_disctmo(vport);
  2817. /* RSCN processed */
  2818. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2819. "0215 RSCN processed Data: x%x x%x x%x x%x\n",
  2820. vport->fc_flag, 0, vport->fc_rscn_id_cnt,
  2821. vport->port_state);
  2822. /* To process RSCN, first compare RSCN data with NameServer */
  2823. vport->fc_ns_retry = 0;
  2824. vport->num_disc_nodes = 0;
  2825. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  2826. if (ndlp && NLP_CHK_NODE_ACT(ndlp)
  2827. && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  2828. /* Good ndlp, issue CT Request to NameServer */
  2829. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
  2830. /* Wait for NameServer query cmpl before we can
  2831. continue */
  2832. return 1;
  2833. } else {
  2834. /* If login to NameServer does not exist, issue one */
  2835. /* Good status, issue PLOGI to NameServer */
  2836. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  2837. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  2838. /* Wait for NameServer login cmpl before we can
  2839. continue */
  2840. return 1;
  2841. if (ndlp) {
  2842. ndlp = lpfc_enable_node(vport, ndlp,
  2843. NLP_STE_PLOGI_ISSUE);
  2844. if (!ndlp) {
  2845. lpfc_els_flush_rscn(vport);
  2846. return 0;
  2847. }
  2848. ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
  2849. } else {
  2850. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  2851. if (!ndlp) {
  2852. lpfc_els_flush_rscn(vport);
  2853. return 0;
  2854. }
  2855. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  2856. ndlp->nlp_prev_state = ndlp->nlp_state;
  2857. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2858. }
  2859. ndlp->nlp_type |= NLP_FABRIC;
  2860. lpfc_issue_els_plogi(vport, NameServer_DID, 0);
  2861. /* Wait for NameServer login cmpl before we can
  2862. * continue
  2863. */
  2864. return 1;
  2865. }
  2866. lpfc_els_flush_rscn(vport);
  2867. return 0;
  2868. }
  2869. static int
  2870. lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2871. struct lpfc_nodelist *ndlp)
  2872. {
  2873. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2874. struct lpfc_hba *phba = vport->phba;
  2875. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2876. uint32_t *lp = (uint32_t *) pcmd->virt;
  2877. IOCB_t *icmd = &cmdiocb->iocb;
  2878. struct serv_parm *sp;
  2879. LPFC_MBOXQ_t *mbox;
  2880. struct ls_rjt stat;
  2881. uint32_t cmd, did;
  2882. int rc;
  2883. cmd = *lp++;
  2884. sp = (struct serv_parm *) lp;
  2885. /* FLOGI received */
  2886. lpfc_set_disctmo(vport);
  2887. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2888. /* We should never receive a FLOGI in loop mode, ignore it */
  2889. did = icmd->un.elsreq64.remoteID;
  2890. /* An FLOGI ELS command <elsCmd> was received from DID <did> in
  2891. Loop Mode */
  2892. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2893. "0113 An FLOGI ELS command x%x was "
  2894. "received from DID x%x in Loop Mode\n",
  2895. cmd, did);
  2896. return 1;
  2897. }
  2898. did = Fabric_DID;
  2899. if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
  2900. /* For a FLOGI we accept, then if our portname is greater
  2901. * then the remote portname we initiate Nport login.
  2902. */
  2903. rc = memcmp(&vport->fc_portname, &sp->portName,
  2904. sizeof(struct lpfc_name));
  2905. if (!rc) {
  2906. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2907. if (!mbox)
  2908. return 1;
  2909. lpfc_linkdown(phba);
  2910. lpfc_init_link(phba, mbox,
  2911. phba->cfg_topology,
  2912. phba->cfg_link_speed);
  2913. mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
  2914. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2915. mbox->vport = vport;
  2916. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2917. lpfc_set_loopback_flag(phba);
  2918. if (rc == MBX_NOT_FINISHED) {
  2919. mempool_free(mbox, phba->mbox_mem_pool);
  2920. }
  2921. return 1;
  2922. } else if (rc > 0) { /* greater than */
  2923. spin_lock_irq(shost->host_lock);
  2924. vport->fc_flag |= FC_PT2PT_PLOGI;
  2925. spin_unlock_irq(shost->host_lock);
  2926. }
  2927. spin_lock_irq(shost->host_lock);
  2928. vport->fc_flag |= FC_PT2PT;
  2929. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  2930. spin_unlock_irq(shost->host_lock);
  2931. } else {
  2932. /* Reject this request because invalid parameters */
  2933. stat.un.b.lsRjtRsvd0 = 0;
  2934. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2935. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  2936. stat.un.b.vendorUnique = 0;
  2937. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  2938. NULL);
  2939. return 1;
  2940. }
  2941. /* Send back ACC */
  2942. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
  2943. return 0;
  2944. }
  2945. static int
  2946. lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2947. struct lpfc_nodelist *ndlp)
  2948. {
  2949. struct lpfc_dmabuf *pcmd;
  2950. uint32_t *lp;
  2951. IOCB_t *icmd;
  2952. RNID *rn;
  2953. struct ls_rjt stat;
  2954. uint32_t cmd, did;
  2955. icmd = &cmdiocb->iocb;
  2956. did = icmd->un.elsreq64.remoteID;
  2957. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2958. lp = (uint32_t *) pcmd->virt;
  2959. cmd = *lp++;
  2960. rn = (RNID *) lp;
  2961. /* RNID received */
  2962. switch (rn->Format) {
  2963. case 0:
  2964. case RNID_TOPOLOGY_DISC:
  2965. /* Send back ACC */
  2966. lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
  2967. break;
  2968. default:
  2969. /* Reject this request because format not supported */
  2970. stat.un.b.lsRjtRsvd0 = 0;
  2971. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2972. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2973. stat.un.b.vendorUnique = 0;
  2974. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  2975. NULL);
  2976. }
  2977. return 0;
  2978. }
  2979. static int
  2980. lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2981. struct lpfc_nodelist *ndlp)
  2982. {
  2983. struct ls_rjt stat;
  2984. /* For now, unconditionally reject this command */
  2985. stat.un.b.lsRjtRsvd0 = 0;
  2986. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2987. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2988. stat.un.b.vendorUnique = 0;
  2989. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  2990. return 0;
  2991. }
  2992. static void
  2993. lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2994. {
  2995. struct lpfc_sli *psli = &phba->sli;
  2996. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  2997. MAILBOX_t *mb;
  2998. IOCB_t *icmd;
  2999. RPS_RSP *rps_rsp;
  3000. uint8_t *pcmd;
  3001. struct lpfc_iocbq *elsiocb;
  3002. struct lpfc_nodelist *ndlp;
  3003. uint16_t xri, status;
  3004. uint32_t cmdsize;
  3005. mb = &pmb->mb;
  3006. ndlp = (struct lpfc_nodelist *) pmb->context2;
  3007. xri = (uint16_t) ((unsigned long)(pmb->context1));
  3008. pmb->context1 = NULL;
  3009. pmb->context2 = NULL;
  3010. if (mb->mbxStatus) {
  3011. mempool_free(pmb, phba->mbox_mem_pool);
  3012. return;
  3013. }
  3014. cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
  3015. mempool_free(pmb, phba->mbox_mem_pool);
  3016. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  3017. lpfc_max_els_tries, ndlp,
  3018. ndlp->nlp_DID, ELS_CMD_ACC);
  3019. /* Decrement the ndlp reference count from previous mbox command */
  3020. lpfc_nlp_put(ndlp);
  3021. if (!elsiocb)
  3022. return;
  3023. icmd = &elsiocb->iocb;
  3024. icmd->ulpContext = xri;
  3025. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3026. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3027. pcmd += sizeof(uint32_t); /* Skip past command */
  3028. rps_rsp = (RPS_RSP *)pcmd;
  3029. if (phba->fc_topology != TOPOLOGY_LOOP)
  3030. status = 0x10;
  3031. else
  3032. status = 0x8;
  3033. if (phba->pport->fc_flag & FC_FABRIC)
  3034. status |= 0x4;
  3035. rps_rsp->rsvd1 = 0;
  3036. rps_rsp->portStatus = cpu_to_be16(status);
  3037. rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
  3038. rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
  3039. rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
  3040. rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
  3041. rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
  3042. rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
  3043. /* Xmit ELS RPS ACC response tag <ulpIoTag> */
  3044. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  3045. "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
  3046. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  3047. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3048. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3049. ndlp->nlp_rpi);
  3050. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3051. phba->fc_stat.elsXmitACC++;
  3052. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
  3053. lpfc_els_free_iocb(phba, elsiocb);
  3054. return;
  3055. }
  3056. static int
  3057. lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3058. struct lpfc_nodelist *ndlp)
  3059. {
  3060. struct lpfc_hba *phba = vport->phba;
  3061. uint32_t *lp;
  3062. uint8_t flag;
  3063. LPFC_MBOXQ_t *mbox;
  3064. struct lpfc_dmabuf *pcmd;
  3065. RPS *rps;
  3066. struct ls_rjt stat;
  3067. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  3068. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  3069. stat.un.b.lsRjtRsvd0 = 0;
  3070. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  3071. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  3072. stat.un.b.vendorUnique = 0;
  3073. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  3074. NULL);
  3075. }
  3076. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3077. lp = (uint32_t *) pcmd->virt;
  3078. flag = (be32_to_cpu(*lp++) & 0xf);
  3079. rps = (RPS *) lp;
  3080. if ((flag == 0) ||
  3081. ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
  3082. ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
  3083. sizeof(struct lpfc_name)) == 0))) {
  3084. printk("Fix me....\n");
  3085. dump_stack();
  3086. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
  3087. if (mbox) {
  3088. lpfc_read_lnk_stat(phba, mbox);
  3089. mbox->context1 =
  3090. (void *)((unsigned long) cmdiocb->iocb.ulpContext);
  3091. mbox->context2 = lpfc_nlp_get(ndlp);
  3092. mbox->vport = vport;
  3093. mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
  3094. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  3095. != MBX_NOT_FINISHED)
  3096. /* Mbox completion will send ELS Response */
  3097. return 0;
  3098. /* Decrement reference count used for the failed mbox
  3099. * command.
  3100. */
  3101. lpfc_nlp_put(ndlp);
  3102. mempool_free(mbox, phba->mbox_mem_pool);
  3103. }
  3104. }
  3105. stat.un.b.lsRjtRsvd0 = 0;
  3106. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  3107. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  3108. stat.un.b.vendorUnique = 0;
  3109. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  3110. return 0;
  3111. }
  3112. static int
  3113. lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
  3114. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  3115. {
  3116. struct lpfc_hba *phba = vport->phba;
  3117. IOCB_t *icmd, *oldcmd;
  3118. RPL_RSP rpl_rsp;
  3119. struct lpfc_iocbq *elsiocb;
  3120. struct lpfc_sli *psli = &phba->sli;
  3121. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  3122. uint8_t *pcmd;
  3123. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3124. ndlp->nlp_DID, ELS_CMD_ACC);
  3125. if (!elsiocb)
  3126. return 1;
  3127. icmd = &elsiocb->iocb;
  3128. oldcmd = &oldiocb->iocb;
  3129. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  3130. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3131. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3132. pcmd += sizeof(uint16_t);
  3133. *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
  3134. pcmd += sizeof(uint16_t);
  3135. /* Setup the RPL ACC payload */
  3136. rpl_rsp.listLen = be32_to_cpu(1);
  3137. rpl_rsp.index = 0;
  3138. rpl_rsp.port_num_blk.portNum = 0;
  3139. rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
  3140. memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
  3141. sizeof(struct lpfc_name));
  3142. memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
  3143. /* Xmit ELS RPL ACC response tag <ulpIoTag> */
  3144. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3145. "0120 Xmit ELS RPL ACC response tag x%x "
  3146. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  3147. "rpi x%x\n",
  3148. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3149. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3150. ndlp->nlp_rpi);
  3151. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3152. phba->fc_stat.elsXmitACC++;
  3153. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  3154. lpfc_els_free_iocb(phba, elsiocb);
  3155. return 1;
  3156. }
  3157. return 0;
  3158. }
  3159. static int
  3160. lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3161. struct lpfc_nodelist *ndlp)
  3162. {
  3163. struct lpfc_dmabuf *pcmd;
  3164. uint32_t *lp;
  3165. uint32_t maxsize;
  3166. uint16_t cmdsize;
  3167. RPL *rpl;
  3168. struct ls_rjt stat;
  3169. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  3170. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  3171. stat.un.b.lsRjtRsvd0 = 0;
  3172. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  3173. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  3174. stat.un.b.vendorUnique = 0;
  3175. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  3176. NULL);
  3177. }
  3178. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3179. lp = (uint32_t *) pcmd->virt;
  3180. rpl = (RPL *) (lp + 1);
  3181. maxsize = be32_to_cpu(rpl->maxsize);
  3182. /* We support only one port */
  3183. if ((rpl->index == 0) &&
  3184. ((maxsize == 0) ||
  3185. ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
  3186. cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
  3187. } else {
  3188. cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
  3189. }
  3190. lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
  3191. return 0;
  3192. }
  3193. static int
  3194. lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3195. struct lpfc_nodelist *ndlp)
  3196. {
  3197. struct lpfc_dmabuf *pcmd;
  3198. uint32_t *lp;
  3199. IOCB_t *icmd;
  3200. FARP *fp;
  3201. uint32_t cmd, cnt, did;
  3202. icmd = &cmdiocb->iocb;
  3203. did = icmd->un.elsreq64.remoteID;
  3204. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3205. lp = (uint32_t *) pcmd->virt;
  3206. cmd = *lp++;
  3207. fp = (FARP *) lp;
  3208. /* FARP-REQ received from DID <did> */
  3209. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3210. "0601 FARP-REQ received from DID x%x\n", did);
  3211. /* We will only support match on WWPN or WWNN */
  3212. if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
  3213. return 0;
  3214. }
  3215. cnt = 0;
  3216. /* If this FARP command is searching for my portname */
  3217. if (fp->Mflags & FARP_MATCH_PORT) {
  3218. if (memcmp(&fp->RportName, &vport->fc_portname,
  3219. sizeof(struct lpfc_name)) == 0)
  3220. cnt = 1;
  3221. }
  3222. /* If this FARP command is searching for my nodename */
  3223. if (fp->Mflags & FARP_MATCH_NODE) {
  3224. if (memcmp(&fp->RnodeName, &vport->fc_nodename,
  3225. sizeof(struct lpfc_name)) == 0)
  3226. cnt = 1;
  3227. }
  3228. if (cnt) {
  3229. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  3230. (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
  3231. /* Log back into the node before sending the FARP. */
  3232. if (fp->Rflags & FARP_REQUEST_PLOGI) {
  3233. ndlp->nlp_prev_state = ndlp->nlp_state;
  3234. lpfc_nlp_set_state(vport, ndlp,
  3235. NLP_STE_PLOGI_ISSUE);
  3236. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  3237. }
  3238. /* Send a FARP response to that node */
  3239. if (fp->Rflags & FARP_REQUEST_FARPR)
  3240. lpfc_issue_els_farpr(vport, did, 0);
  3241. }
  3242. }
  3243. return 0;
  3244. }
  3245. static int
  3246. lpfc_els_rcv_farpr(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. uint32_t cmd, did;
  3253. icmd = &cmdiocb->iocb;
  3254. did = icmd->un.elsreq64.remoteID;
  3255. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3256. lp = (uint32_t *) pcmd->virt;
  3257. cmd = *lp++;
  3258. /* FARP-RSP received from DID <did> */
  3259. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3260. "0600 FARP-RSP received from DID x%x\n", did);
  3261. /* ACCEPT the Farp resp request */
  3262. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  3263. return 0;
  3264. }
  3265. static int
  3266. lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3267. struct lpfc_nodelist *fan_ndlp)
  3268. {
  3269. struct lpfc_dmabuf *pcmd;
  3270. uint32_t *lp;
  3271. IOCB_t *icmd;
  3272. uint32_t cmd, did;
  3273. FAN *fp;
  3274. struct lpfc_nodelist *ndlp, *next_ndlp;
  3275. struct lpfc_hba *phba = vport->phba;
  3276. /* FAN received */
  3277. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3278. "0265 FAN received\n");
  3279. icmd = &cmdiocb->iocb;
  3280. did = icmd->un.elsreq64.remoteID;
  3281. pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
  3282. lp = (uint32_t *)pcmd->virt;
  3283. cmd = *lp++;
  3284. fp = (FAN *) lp;
  3285. /* FAN received; Fan does not have a reply sequence */
  3286. if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
  3287. if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
  3288. sizeof(struct lpfc_name)) != 0) ||
  3289. (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
  3290. sizeof(struct lpfc_name)) != 0)) {
  3291. /*
  3292. * This node has switched fabrics. FLOGI is required
  3293. * Clean up the old rpi's
  3294. */
  3295. list_for_each_entry_safe(ndlp, next_ndlp,
  3296. &vport->fc_nodes, nlp_listp) {
  3297. if (!NLP_CHK_NODE_ACT(ndlp))
  3298. continue;
  3299. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  3300. continue;
  3301. if (ndlp->nlp_type & NLP_FABRIC) {
  3302. /*
  3303. * Clean up old Fabric, Nameserver and
  3304. * other NLP_FABRIC logins
  3305. */
  3306. lpfc_drop_node(vport, ndlp);
  3307. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  3308. /* Fail outstanding I/O now since this
  3309. * device is marked for PLOGI
  3310. */
  3311. lpfc_unreg_rpi(vport, ndlp);
  3312. }
  3313. }
  3314. lpfc_initial_flogi(vport);
  3315. return 0;
  3316. }
  3317. /* Discovery not needed,
  3318. * move the nodes to their original state.
  3319. */
  3320. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  3321. nlp_listp) {
  3322. if (!NLP_CHK_NODE_ACT(ndlp))
  3323. continue;
  3324. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  3325. continue;
  3326. switch (ndlp->nlp_prev_state) {
  3327. case NLP_STE_UNMAPPED_NODE:
  3328. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  3329. lpfc_nlp_set_state(vport, ndlp,
  3330. NLP_STE_UNMAPPED_NODE);
  3331. break;
  3332. case NLP_STE_MAPPED_NODE:
  3333. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  3334. lpfc_nlp_set_state(vport, ndlp,
  3335. NLP_STE_MAPPED_NODE);
  3336. break;
  3337. default:
  3338. break;
  3339. }
  3340. }
  3341. /* Start discovery - this should just do CLEAR_LA */
  3342. lpfc_disc_start(vport);
  3343. }
  3344. return 0;
  3345. }
  3346. void
  3347. lpfc_els_timeout(unsigned long ptr)
  3348. {
  3349. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  3350. struct lpfc_hba *phba = vport->phba;
  3351. unsigned long iflag;
  3352. spin_lock_irqsave(&vport->work_port_lock, iflag);
  3353. if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
  3354. vport->work_port_events |= WORKER_ELS_TMO;
  3355. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  3356. spin_lock_irqsave(&phba->hbalock, iflag);
  3357. if (phba->work_wait)
  3358. lpfc_worker_wake_up(phba);
  3359. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3360. }
  3361. else
  3362. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  3363. return;
  3364. }
  3365. void
  3366. lpfc_els_timeout_handler(struct lpfc_vport *vport)
  3367. {
  3368. struct lpfc_hba *phba = vport->phba;
  3369. struct lpfc_sli_ring *pring;
  3370. struct lpfc_iocbq *tmp_iocb, *piocb;
  3371. IOCB_t *cmd = NULL;
  3372. struct lpfc_dmabuf *pcmd;
  3373. uint32_t els_command = 0;
  3374. uint32_t timeout;
  3375. uint32_t remote_ID = 0xffffffff;
  3376. /* If the timer is already canceled do nothing */
  3377. if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
  3378. return;
  3379. }
  3380. spin_lock_irq(&phba->hbalock);
  3381. timeout = (uint32_t)(phba->fc_ratov << 1);
  3382. pring = &phba->sli.ring[LPFC_ELS_RING];
  3383. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3384. cmd = &piocb->iocb;
  3385. if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
  3386. piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  3387. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  3388. continue;
  3389. if (piocb->vport != vport)
  3390. continue;
  3391. pcmd = (struct lpfc_dmabuf *) piocb->context2;
  3392. if (pcmd)
  3393. els_command = *(uint32_t *) (pcmd->virt);
  3394. if (els_command == ELS_CMD_FARP ||
  3395. els_command == ELS_CMD_FARPR ||
  3396. els_command == ELS_CMD_FDISC)
  3397. continue;
  3398. if (vport != piocb->vport)
  3399. continue;
  3400. if (piocb->drvrTimeout > 0) {
  3401. if (piocb->drvrTimeout >= timeout)
  3402. piocb->drvrTimeout -= timeout;
  3403. else
  3404. piocb->drvrTimeout = 0;
  3405. continue;
  3406. }
  3407. remote_ID = 0xffffffff;
  3408. if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
  3409. remote_ID = cmd->un.elsreq64.remoteID;
  3410. else {
  3411. struct lpfc_nodelist *ndlp;
  3412. ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
  3413. if (ndlp)
  3414. remote_ID = ndlp->nlp_DID;
  3415. }
  3416. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3417. "0127 ELS timeout Data: x%x x%x x%x "
  3418. "x%x\n", els_command,
  3419. remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
  3420. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3421. }
  3422. spin_unlock_irq(&phba->hbalock);
  3423. if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
  3424. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  3425. }
  3426. void
  3427. lpfc_els_flush_cmd(struct lpfc_vport *vport)
  3428. {
  3429. LIST_HEAD(completions);
  3430. struct lpfc_hba *phba = vport->phba;
  3431. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3432. struct lpfc_iocbq *tmp_iocb, *piocb;
  3433. IOCB_t *cmd = NULL;
  3434. lpfc_fabric_abort_vport(vport);
  3435. spin_lock_irq(&phba->hbalock);
  3436. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  3437. cmd = &piocb->iocb;
  3438. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  3439. continue;
  3440. }
  3441. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  3442. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  3443. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  3444. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  3445. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  3446. continue;
  3447. if (piocb->vport != vport)
  3448. continue;
  3449. list_move_tail(&piocb->list, &completions);
  3450. pring->txq_cnt--;
  3451. }
  3452. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3453. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  3454. continue;
  3455. }
  3456. if (piocb->vport != vport)
  3457. continue;
  3458. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3459. }
  3460. spin_unlock_irq(&phba->hbalock);
  3461. while (!list_empty(&completions)) {
  3462. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  3463. cmd = &piocb->iocb;
  3464. list_del_init(&piocb->list);
  3465. if (!piocb->iocb_cmpl)
  3466. lpfc_sli_release_iocbq(phba, piocb);
  3467. else {
  3468. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3469. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  3470. (piocb->iocb_cmpl) (phba, piocb, piocb);
  3471. }
  3472. }
  3473. return;
  3474. }
  3475. void
  3476. lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
  3477. {
  3478. LIST_HEAD(completions);
  3479. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3480. struct lpfc_iocbq *tmp_iocb, *piocb;
  3481. IOCB_t *cmd = NULL;
  3482. lpfc_fabric_abort_hba(phba);
  3483. spin_lock_irq(&phba->hbalock);
  3484. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  3485. cmd = &piocb->iocb;
  3486. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  3487. continue;
  3488. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  3489. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  3490. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  3491. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  3492. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  3493. continue;
  3494. list_move_tail(&piocb->list, &completions);
  3495. pring->txq_cnt--;
  3496. }
  3497. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3498. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  3499. continue;
  3500. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3501. }
  3502. spin_unlock_irq(&phba->hbalock);
  3503. while (!list_empty(&completions)) {
  3504. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  3505. cmd = &piocb->iocb;
  3506. list_del_init(&piocb->list);
  3507. if (!piocb->iocb_cmpl)
  3508. lpfc_sli_release_iocbq(phba, piocb);
  3509. else {
  3510. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3511. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  3512. (piocb->iocb_cmpl) (phba, piocb, piocb);
  3513. }
  3514. }
  3515. return;
  3516. }
  3517. static void
  3518. lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3519. struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
  3520. {
  3521. struct Scsi_Host *shost;
  3522. struct lpfc_nodelist *ndlp;
  3523. struct ls_rjt stat;
  3524. uint32_t *payload;
  3525. uint32_t cmd, did, newnode, rjt_err = 0;
  3526. IOCB_t *icmd = &elsiocb->iocb;
  3527. if (!vport || !(elsiocb->context2))
  3528. goto dropit;
  3529. newnode = 0;
  3530. payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
  3531. cmd = *payload;
  3532. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
  3533. lpfc_post_buffer(phba, pring, 1, 1);
  3534. did = icmd->un.rcvels.remoteID;
  3535. if (icmd->ulpStatus) {
  3536. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3537. "RCV Unsol ELS: status:x%x/x%x did:x%x",
  3538. icmd->ulpStatus, icmd->un.ulpWord[4], did);
  3539. goto dropit;
  3540. }
  3541. /* Check to see if link went down during discovery */
  3542. if (lpfc_els_chk_latt(vport))
  3543. goto dropit;
  3544. /* Ignore traffic recevied during vport shutdown. */
  3545. if (vport->load_flag & FC_UNLOADING)
  3546. goto dropit;
  3547. ndlp = lpfc_findnode_did(vport, did);
  3548. if (!ndlp) {
  3549. /* Cannot find existing Fabric ndlp, so allocate a new one */
  3550. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3551. if (!ndlp)
  3552. goto dropit;
  3553. lpfc_nlp_init(vport, ndlp, did);
  3554. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3555. newnode = 1;
  3556. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  3557. ndlp->nlp_type |= NLP_FABRIC;
  3558. } else {
  3559. if (!NLP_CHK_NODE_ACT(ndlp)) {
  3560. ndlp = lpfc_enable_node(vport, ndlp,
  3561. NLP_STE_UNUSED_NODE);
  3562. if (!ndlp)
  3563. goto dropit;
  3564. }
  3565. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  3566. /* This is simular to the new node path */
  3567. ndlp = lpfc_nlp_get(ndlp);
  3568. if (!ndlp)
  3569. goto dropit;
  3570. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3571. newnode = 1;
  3572. }
  3573. }
  3574. phba->fc_stat.elsRcvFrame++;
  3575. if (elsiocb->context1)
  3576. lpfc_nlp_put(elsiocb->context1);
  3577. elsiocb->context1 = lpfc_nlp_get(ndlp);
  3578. elsiocb->vport = vport;
  3579. if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
  3580. cmd &= ELS_CMD_MASK;
  3581. }
  3582. /* ELS command <elsCmd> received from NPORT <did> */
  3583. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3584. "0112 ELS command x%x received from NPORT x%x "
  3585. "Data: x%x\n", cmd, did, vport->port_state);
  3586. switch (cmd) {
  3587. case ELS_CMD_PLOGI:
  3588. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3589. "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
  3590. did, vport->port_state, ndlp->nlp_flag);
  3591. phba->fc_stat.elsRcvPLOGI++;
  3592. ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
  3593. if (vport->port_state < LPFC_DISC_AUTH) {
  3594. if (!(phba->pport->fc_flag & FC_PT2PT) ||
  3595. (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
  3596. rjt_err = LSRJT_UNABLE_TPC;
  3597. break;
  3598. }
  3599. /* We get here, and drop thru, if we are PT2PT with
  3600. * another NPort and the other side has initiated
  3601. * the PLOGI before responding to our FLOGI.
  3602. */
  3603. }
  3604. shost = lpfc_shost_from_vport(vport);
  3605. spin_lock_irq(shost->host_lock);
  3606. ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
  3607. spin_unlock_irq(shost->host_lock);
  3608. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3609. NLP_EVT_RCV_PLOGI);
  3610. break;
  3611. case ELS_CMD_FLOGI:
  3612. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3613. "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
  3614. did, vport->port_state, ndlp->nlp_flag);
  3615. phba->fc_stat.elsRcvFLOGI++;
  3616. lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
  3617. if (newnode)
  3618. lpfc_nlp_put(ndlp);
  3619. break;
  3620. case ELS_CMD_LOGO:
  3621. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3622. "RCV LOGO: did:x%x/ste:x%x flg:x%x",
  3623. did, vport->port_state, ndlp->nlp_flag);
  3624. phba->fc_stat.elsRcvLOGO++;
  3625. if (vport->port_state < LPFC_DISC_AUTH) {
  3626. rjt_err = LSRJT_UNABLE_TPC;
  3627. break;
  3628. }
  3629. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
  3630. break;
  3631. case ELS_CMD_PRLO:
  3632. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3633. "RCV PRLO: did:x%x/ste:x%x flg:x%x",
  3634. did, vport->port_state, ndlp->nlp_flag);
  3635. phba->fc_stat.elsRcvPRLO++;
  3636. if (vport->port_state < LPFC_DISC_AUTH) {
  3637. rjt_err = LSRJT_UNABLE_TPC;
  3638. break;
  3639. }
  3640. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
  3641. break;
  3642. case ELS_CMD_RSCN:
  3643. phba->fc_stat.elsRcvRSCN++;
  3644. lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
  3645. if (newnode)
  3646. lpfc_nlp_put(ndlp);
  3647. break;
  3648. case ELS_CMD_ADISC:
  3649. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3650. "RCV ADISC: did:x%x/ste:x%x flg:x%x",
  3651. did, vport->port_state, ndlp->nlp_flag);
  3652. phba->fc_stat.elsRcvADISC++;
  3653. if (vport->port_state < LPFC_DISC_AUTH) {
  3654. rjt_err = LSRJT_UNABLE_TPC;
  3655. break;
  3656. }
  3657. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3658. NLP_EVT_RCV_ADISC);
  3659. break;
  3660. case ELS_CMD_PDISC:
  3661. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3662. "RCV PDISC: did:x%x/ste:x%x flg:x%x",
  3663. did, vport->port_state, ndlp->nlp_flag);
  3664. phba->fc_stat.elsRcvPDISC++;
  3665. if (vport->port_state < LPFC_DISC_AUTH) {
  3666. rjt_err = LSRJT_UNABLE_TPC;
  3667. break;
  3668. }
  3669. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3670. NLP_EVT_RCV_PDISC);
  3671. break;
  3672. case ELS_CMD_FARPR:
  3673. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3674. "RCV FARPR: did:x%x/ste:x%x flg:x%x",
  3675. did, vport->port_state, ndlp->nlp_flag);
  3676. phba->fc_stat.elsRcvFARPR++;
  3677. lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
  3678. break;
  3679. case ELS_CMD_FARP:
  3680. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3681. "RCV FARP: did:x%x/ste:x%x flg:x%x",
  3682. did, vport->port_state, ndlp->nlp_flag);
  3683. phba->fc_stat.elsRcvFARP++;
  3684. lpfc_els_rcv_farp(vport, elsiocb, ndlp);
  3685. break;
  3686. case ELS_CMD_FAN:
  3687. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3688. "RCV FAN: did:x%x/ste:x%x flg:x%x",
  3689. did, vport->port_state, ndlp->nlp_flag);
  3690. phba->fc_stat.elsRcvFAN++;
  3691. lpfc_els_rcv_fan(vport, elsiocb, ndlp);
  3692. break;
  3693. case ELS_CMD_PRLI:
  3694. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3695. "RCV PRLI: did:x%x/ste:x%x flg:x%x",
  3696. did, vport->port_state, ndlp->nlp_flag);
  3697. phba->fc_stat.elsRcvPRLI++;
  3698. if (vport->port_state < LPFC_DISC_AUTH) {
  3699. rjt_err = LSRJT_UNABLE_TPC;
  3700. break;
  3701. }
  3702. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
  3703. break;
  3704. case ELS_CMD_LIRR:
  3705. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3706. "RCV LIRR: did:x%x/ste:x%x flg:x%x",
  3707. did, vport->port_state, ndlp->nlp_flag);
  3708. phba->fc_stat.elsRcvLIRR++;
  3709. lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
  3710. if (newnode)
  3711. lpfc_nlp_put(ndlp);
  3712. break;
  3713. case ELS_CMD_RPS:
  3714. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3715. "RCV RPS: did:x%x/ste:x%x flg:x%x",
  3716. did, vport->port_state, ndlp->nlp_flag);
  3717. phba->fc_stat.elsRcvRPS++;
  3718. lpfc_els_rcv_rps(vport, elsiocb, ndlp);
  3719. if (newnode)
  3720. lpfc_nlp_put(ndlp);
  3721. break;
  3722. case ELS_CMD_RPL:
  3723. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3724. "RCV RPL: did:x%x/ste:x%x flg:x%x",
  3725. did, vport->port_state, ndlp->nlp_flag);
  3726. phba->fc_stat.elsRcvRPL++;
  3727. lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
  3728. if (newnode)
  3729. lpfc_nlp_put(ndlp);
  3730. break;
  3731. case ELS_CMD_RNID:
  3732. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3733. "RCV RNID: did:x%x/ste:x%x flg:x%x",
  3734. did, vport->port_state, ndlp->nlp_flag);
  3735. phba->fc_stat.elsRcvRNID++;
  3736. lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
  3737. if (newnode)
  3738. lpfc_nlp_put(ndlp);
  3739. break;
  3740. default:
  3741. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3742. "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
  3743. cmd, did, vport->port_state);
  3744. /* Unsupported ELS command, reject */
  3745. rjt_err = LSRJT_INVALID_CMD;
  3746. /* Unknown ELS command <elsCmd> received from NPORT <did> */
  3747. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3748. "0115 Unknown ELS command x%x "
  3749. "received from NPORT x%x\n", cmd, did);
  3750. if (newnode)
  3751. lpfc_nlp_put(ndlp);
  3752. break;
  3753. }
  3754. /* check if need to LS_RJT received ELS cmd */
  3755. if (rjt_err) {
  3756. memset(&stat, 0, sizeof(stat));
  3757. stat.un.b.lsRjtRsnCode = rjt_err;
  3758. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  3759. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
  3760. NULL);
  3761. }
  3762. return;
  3763. dropit:
  3764. if (vport && !(vport->load_flag & FC_UNLOADING))
  3765. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  3766. "(%d):0111 Dropping received ELS cmd "
  3767. "Data: x%x x%x x%x\n",
  3768. vport->vpi, icmd->ulpStatus,
  3769. icmd->un.ulpWord[4], icmd->ulpTimeout);
  3770. phba->fc_stat.elsRcvDrop++;
  3771. }
  3772. static struct lpfc_vport *
  3773. lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
  3774. {
  3775. struct lpfc_vport *vport;
  3776. unsigned long flags;
  3777. spin_lock_irqsave(&phba->hbalock, flags);
  3778. list_for_each_entry(vport, &phba->port_list, listentry) {
  3779. if (vport->vpi == vpi) {
  3780. spin_unlock_irqrestore(&phba->hbalock, flags);
  3781. return vport;
  3782. }
  3783. }
  3784. spin_unlock_irqrestore(&phba->hbalock, flags);
  3785. return NULL;
  3786. }
  3787. void
  3788. lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3789. struct lpfc_iocbq *elsiocb)
  3790. {
  3791. struct lpfc_vport *vport = phba->pport;
  3792. IOCB_t *icmd = &elsiocb->iocb;
  3793. dma_addr_t paddr;
  3794. struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
  3795. struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
  3796. elsiocb->context2 = NULL;
  3797. elsiocb->context3 = NULL;
  3798. if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
  3799. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  3800. } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
  3801. (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
  3802. phba->fc_stat.NoRcvBuf++;
  3803. /* Not enough posted buffers; Try posting more buffers */
  3804. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  3805. lpfc_post_buffer(phba, pring, 0, 1);
  3806. return;
  3807. }
  3808. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3809. (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
  3810. icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  3811. if (icmd->unsli3.rcvsli3.vpi == 0xffff)
  3812. vport = phba->pport;
  3813. else {
  3814. uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
  3815. vport = lpfc_find_vport_by_vpid(phba, vpi);
  3816. }
  3817. }
  3818. /* If there are no BDEs associated
  3819. * with this IOCB, there is nothing to do.
  3820. */
  3821. if (icmd->ulpBdeCount == 0)
  3822. return;
  3823. /* type of ELS cmd is first 32bit word
  3824. * in packet
  3825. */
  3826. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3827. elsiocb->context2 = bdeBuf1;
  3828. } else {
  3829. paddr = getPaddr(icmd->un.cont64[0].addrHigh,
  3830. icmd->un.cont64[0].addrLow);
  3831. elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
  3832. paddr);
  3833. }
  3834. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  3835. /*
  3836. * The different unsolicited event handlers would tell us
  3837. * if they are done with "mp" by setting context2 to NULL.
  3838. */
  3839. lpfc_nlp_put(elsiocb->context1);
  3840. elsiocb->context1 = NULL;
  3841. if (elsiocb->context2) {
  3842. lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
  3843. elsiocb->context2 = NULL;
  3844. }
  3845. /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
  3846. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
  3847. icmd->ulpBdeCount == 2) {
  3848. elsiocb->context2 = bdeBuf2;
  3849. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  3850. /* free mp if we are done with it */
  3851. if (elsiocb->context2) {
  3852. lpfc_in_buf_free(phba, elsiocb->context2);
  3853. elsiocb->context2 = NULL;
  3854. }
  3855. }
  3856. }
  3857. void
  3858. lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  3859. {
  3860. struct lpfc_nodelist *ndlp, *ndlp_fdmi;
  3861. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  3862. if (!ndlp) {
  3863. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3864. if (!ndlp) {
  3865. if (phba->fc_topology == TOPOLOGY_LOOP) {
  3866. lpfc_disc_start(vport);
  3867. return;
  3868. }
  3869. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3870. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3871. "0251 NameServer login: no memory\n");
  3872. return;
  3873. }
  3874. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  3875. ndlp->nlp_type |= NLP_FABRIC;
  3876. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3877. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  3878. if (!ndlp) {
  3879. if (phba->fc_topology == TOPOLOGY_LOOP) {
  3880. lpfc_disc_start(vport);
  3881. return;
  3882. }
  3883. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3884. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3885. "0348 NameServer login: node freed\n");
  3886. return;
  3887. }
  3888. }
  3889. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  3890. if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
  3891. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3892. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3893. "0252 Cannot issue NameServer login\n");
  3894. return;
  3895. }
  3896. if (vport->cfg_fdmi_on) {
  3897. ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
  3898. GFP_KERNEL);
  3899. if (ndlp_fdmi) {
  3900. lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
  3901. ndlp_fdmi->nlp_type |= NLP_FABRIC;
  3902. ndlp_fdmi->nlp_state =
  3903. NLP_STE_PLOGI_ISSUE;
  3904. lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
  3905. 0);
  3906. }
  3907. }
  3908. return;
  3909. }
  3910. static void
  3911. lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3912. {
  3913. struct lpfc_vport *vport = pmb->vport;
  3914. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3915. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3916. MAILBOX_t *mb = &pmb->mb;
  3917. spin_lock_irq(shost->host_lock);
  3918. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  3919. spin_unlock_irq(shost->host_lock);
  3920. if (mb->mbxStatus) {
  3921. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3922. "0915 Register VPI failed: 0x%x\n",
  3923. mb->mbxStatus);
  3924. switch (mb->mbxStatus) {
  3925. case 0x11: /* unsupported feature */
  3926. case 0x9603: /* max_vpi exceeded */
  3927. /* giving up on vport registration */
  3928. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3929. spin_lock_irq(shost->host_lock);
  3930. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  3931. spin_unlock_irq(shost->host_lock);
  3932. lpfc_can_disctmo(vport);
  3933. break;
  3934. default:
  3935. /* Try to recover from this error */
  3936. lpfc_mbx_unreg_vpi(vport);
  3937. spin_lock_irq(shost->host_lock);
  3938. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  3939. spin_unlock_irq(shost->host_lock);
  3940. lpfc_initial_fdisc(vport);
  3941. break;
  3942. }
  3943. } else {
  3944. if (vport == phba->pport)
  3945. lpfc_issue_fabric_reglogin(vport);
  3946. else
  3947. lpfc_do_scr_ns_plogi(phba, vport);
  3948. }
  3949. /* Now, we decrement the ndlp reference count held for this
  3950. * callback function
  3951. */
  3952. lpfc_nlp_put(ndlp);
  3953. mempool_free(pmb, phba->mbox_mem_pool);
  3954. return;
  3955. }
  3956. static void
  3957. lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
  3958. struct lpfc_nodelist *ndlp)
  3959. {
  3960. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3961. LPFC_MBOXQ_t *mbox;
  3962. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3963. if (mbox) {
  3964. lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
  3965. mbox->vport = vport;
  3966. mbox->context2 = lpfc_nlp_get(ndlp);
  3967. mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
  3968. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  3969. == MBX_NOT_FINISHED) {
  3970. /* mailbox command not success, decrement ndlp
  3971. * reference count for this command
  3972. */
  3973. lpfc_nlp_put(ndlp);
  3974. mempool_free(mbox, phba->mbox_mem_pool);
  3975. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3976. "0253 Register VPI: Can't send mbox\n");
  3977. goto mbox_err_exit;
  3978. }
  3979. } else {
  3980. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3981. "0254 Register VPI: no memory\n");
  3982. goto mbox_err_exit;
  3983. }
  3984. return;
  3985. mbox_err_exit:
  3986. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3987. spin_lock_irq(shost->host_lock);
  3988. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  3989. spin_unlock_irq(shost->host_lock);
  3990. return;
  3991. }
  3992. static void
  3993. lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3994. struct lpfc_iocbq *rspiocb)
  3995. {
  3996. struct lpfc_vport *vport = cmdiocb->vport;
  3997. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3998. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  3999. struct lpfc_nodelist *np;
  4000. struct lpfc_nodelist *next_np;
  4001. IOCB_t *irsp = &rspiocb->iocb;
  4002. struct lpfc_iocbq *piocb;
  4003. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4004. "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
  4005. irsp->ulpStatus, irsp->un.ulpWord[4],
  4006. vport->fc_prevDID);
  4007. /* Since all FDISCs are being single threaded, we
  4008. * must reset the discovery timer for ALL vports
  4009. * waiting to send FDISC when one completes.
  4010. */
  4011. list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
  4012. lpfc_set_disctmo(piocb->vport);
  4013. }
  4014. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4015. "FDISC cmpl: status:x%x/x%x prevdid:x%x",
  4016. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
  4017. if (irsp->ulpStatus) {
  4018. /* Check for retry */
  4019. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  4020. goto out;
  4021. /* FDISC failed */
  4022. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4023. "0124 FDISC failed. (%d/%d)\n",
  4024. irsp->ulpStatus, irsp->un.ulpWord[4]);
  4025. if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
  4026. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  4027. lpfc_nlp_put(ndlp);
  4028. /* giving up on FDISC. Cancel discovery timer */
  4029. lpfc_can_disctmo(vport);
  4030. } else {
  4031. spin_lock_irq(shost->host_lock);
  4032. vport->fc_flag |= FC_FABRIC;
  4033. if (vport->phba->fc_topology == TOPOLOGY_LOOP)
  4034. vport->fc_flag |= FC_PUBLIC_LOOP;
  4035. spin_unlock_irq(shost->host_lock);
  4036. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  4037. lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
  4038. if ((vport->fc_prevDID != vport->fc_myDID) &&
  4039. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  4040. /* If our NportID changed, we need to ensure all
  4041. * remaining NPORTs get unreg_login'ed so we can
  4042. * issue unreg_vpi.
  4043. */
  4044. list_for_each_entry_safe(np, next_np,
  4045. &vport->fc_nodes, nlp_listp) {
  4046. if (!NLP_CHK_NODE_ACT(ndlp) ||
  4047. (np->nlp_state != NLP_STE_NPR_NODE) ||
  4048. !(np->nlp_flag & NLP_NPR_ADISC))
  4049. continue;
  4050. spin_lock_irq(shost->host_lock);
  4051. np->nlp_flag &= ~NLP_NPR_ADISC;
  4052. spin_unlock_irq(shost->host_lock);
  4053. lpfc_unreg_rpi(vport, np);
  4054. }
  4055. lpfc_mbx_unreg_vpi(vport);
  4056. spin_lock_irq(shost->host_lock);
  4057. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  4058. spin_unlock_irq(shost->host_lock);
  4059. }
  4060. if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  4061. lpfc_register_new_vport(phba, vport, ndlp);
  4062. else
  4063. lpfc_do_scr_ns_plogi(phba, vport);
  4064. /* Unconditionaly kick off releasing fabric node for vports */
  4065. lpfc_nlp_put(ndlp);
  4066. }
  4067. out:
  4068. lpfc_els_free_iocb(phba, cmdiocb);
  4069. }
  4070. static int
  4071. lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  4072. uint8_t retry)
  4073. {
  4074. struct lpfc_hba *phba = vport->phba;
  4075. IOCB_t *icmd;
  4076. struct lpfc_iocbq *elsiocb;
  4077. struct serv_parm *sp;
  4078. uint8_t *pcmd;
  4079. uint16_t cmdsize;
  4080. int did = ndlp->nlp_DID;
  4081. int rc;
  4082. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  4083. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  4084. ELS_CMD_FDISC);
  4085. if (!elsiocb) {
  4086. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  4087. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4088. "0255 Issue FDISC: no IOCB\n");
  4089. return 1;
  4090. }
  4091. icmd = &elsiocb->iocb;
  4092. icmd->un.elsreq64.myID = 0;
  4093. icmd->un.elsreq64.fl = 1;
  4094. /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
  4095. icmd->ulpCt_h = 1;
  4096. icmd->ulpCt_l = 0;
  4097. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4098. *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
  4099. pcmd += sizeof(uint32_t); /* CSP Word 1 */
  4100. memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
  4101. sp = (struct serv_parm *) pcmd;
  4102. /* Setup CSPs accordingly for Fabric */
  4103. sp->cmn.e_d_tov = 0;
  4104. sp->cmn.w2.r_a_tov = 0;
  4105. sp->cls1.classValid = 0;
  4106. sp->cls2.seqDelivery = 1;
  4107. sp->cls3.seqDelivery = 1;
  4108. pcmd += sizeof(uint32_t); /* CSP Word 2 */
  4109. pcmd += sizeof(uint32_t); /* CSP Word 3 */
  4110. pcmd += sizeof(uint32_t); /* CSP Word 4 */
  4111. pcmd += sizeof(uint32_t); /* Port Name */
  4112. memcpy(pcmd, &vport->fc_portname, 8);
  4113. pcmd += sizeof(uint32_t); /* Node Name */
  4114. pcmd += sizeof(uint32_t); /* Node Name */
  4115. memcpy(pcmd, &vport->fc_nodename, 8);
  4116. lpfc_set_disctmo(vport);
  4117. phba->fc_stat.elsXmitFDISC++;
  4118. elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
  4119. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4120. "Issue FDISC: did:x%x",
  4121. did, 0, 0);
  4122. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  4123. if (rc == IOCB_ERROR) {
  4124. lpfc_els_free_iocb(phba, elsiocb);
  4125. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  4126. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4127. "0256 Issue FDISC: Cannot send IOCB\n");
  4128. return 1;
  4129. }
  4130. lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
  4131. vport->port_state = LPFC_FDISC;
  4132. return 0;
  4133. }
  4134. static void
  4135. lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  4136. struct lpfc_iocbq *rspiocb)
  4137. {
  4138. struct lpfc_vport *vport = cmdiocb->vport;
  4139. IOCB_t *irsp;
  4140. struct lpfc_nodelist *ndlp;
  4141. ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
  4142. irsp = &rspiocb->iocb;
  4143. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4144. "LOGO npiv cmpl: status:x%x/x%x did:x%x",
  4145. irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
  4146. lpfc_els_free_iocb(phba, cmdiocb);
  4147. vport->unreg_vpi_cmpl = VPORT_ERROR;
  4148. /* Trigger the release of the ndlp after logo */
  4149. lpfc_nlp_put(ndlp);
  4150. }
  4151. int
  4152. lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  4153. {
  4154. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4155. struct lpfc_hba *phba = vport->phba;
  4156. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4157. IOCB_t *icmd;
  4158. struct lpfc_iocbq *elsiocb;
  4159. uint8_t *pcmd;
  4160. uint16_t cmdsize;
  4161. cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
  4162. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
  4163. ELS_CMD_LOGO);
  4164. if (!elsiocb)
  4165. return 1;
  4166. icmd = &elsiocb->iocb;
  4167. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4168. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  4169. pcmd += sizeof(uint32_t);
  4170. /* Fill in LOGO payload */
  4171. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  4172. pcmd += sizeof(uint32_t);
  4173. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  4174. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4175. "Issue LOGO npiv did:x%x flg:x%x",
  4176. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  4177. elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
  4178. spin_lock_irq(shost->host_lock);
  4179. ndlp->nlp_flag |= NLP_LOGO_SND;
  4180. spin_unlock_irq(shost->host_lock);
  4181. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  4182. spin_lock_irq(shost->host_lock);
  4183. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  4184. spin_unlock_irq(shost->host_lock);
  4185. lpfc_els_free_iocb(phba, elsiocb);
  4186. return 1;
  4187. }
  4188. return 0;
  4189. }
  4190. void
  4191. lpfc_fabric_block_timeout(unsigned long ptr)
  4192. {
  4193. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4194. unsigned long iflags;
  4195. uint32_t tmo_posted;
  4196. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  4197. tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
  4198. if (!tmo_posted)
  4199. phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
  4200. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  4201. if (!tmo_posted) {
  4202. spin_lock_irqsave(&phba->hbalock, iflags);
  4203. if (phba->work_wait)
  4204. lpfc_worker_wake_up(phba);
  4205. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4206. }
  4207. }
  4208. static void
  4209. lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
  4210. {
  4211. struct lpfc_iocbq *iocb;
  4212. unsigned long iflags;
  4213. int ret;
  4214. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4215. IOCB_t *cmd;
  4216. repeat:
  4217. iocb = NULL;
  4218. spin_lock_irqsave(&phba->hbalock, iflags);
  4219. /* Post any pending iocb to the SLI layer */
  4220. if (atomic_read(&phba->fabric_iocb_count) == 0) {
  4221. list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
  4222. list);
  4223. if (iocb)
  4224. atomic_inc(&phba->fabric_iocb_count);
  4225. }
  4226. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4227. if (iocb) {
  4228. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  4229. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  4230. iocb->iocb_flag |= LPFC_IO_FABRIC;
  4231. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  4232. "Fabric sched1: ste:x%x",
  4233. iocb->vport->port_state, 0, 0);
  4234. ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
  4235. if (ret == IOCB_ERROR) {
  4236. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  4237. iocb->fabric_iocb_cmpl = NULL;
  4238. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  4239. cmd = &iocb->iocb;
  4240. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4241. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4242. iocb->iocb_cmpl(phba, iocb, iocb);
  4243. atomic_dec(&phba->fabric_iocb_count);
  4244. goto repeat;
  4245. }
  4246. }
  4247. return;
  4248. }
  4249. void
  4250. lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
  4251. {
  4252. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  4253. lpfc_resume_fabric_iocbs(phba);
  4254. return;
  4255. }
  4256. static void
  4257. lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
  4258. {
  4259. int blocked;
  4260. blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  4261. /* Start a timer to unblock fabric
  4262. * iocbs after 100ms
  4263. */
  4264. if (!blocked)
  4265. mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
  4266. return;
  4267. }
  4268. static void
  4269. lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  4270. struct lpfc_iocbq *rspiocb)
  4271. {
  4272. struct ls_rjt stat;
  4273. if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
  4274. BUG();
  4275. switch (rspiocb->iocb.ulpStatus) {
  4276. case IOSTAT_NPORT_RJT:
  4277. case IOSTAT_FABRIC_RJT:
  4278. if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  4279. lpfc_block_fabric_iocbs(phba);
  4280. }
  4281. break;
  4282. case IOSTAT_NPORT_BSY:
  4283. case IOSTAT_FABRIC_BSY:
  4284. lpfc_block_fabric_iocbs(phba);
  4285. break;
  4286. case IOSTAT_LS_RJT:
  4287. stat.un.lsRjtError =
  4288. be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
  4289. if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
  4290. (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
  4291. lpfc_block_fabric_iocbs(phba);
  4292. break;
  4293. }
  4294. if (atomic_read(&phba->fabric_iocb_count) == 0)
  4295. BUG();
  4296. cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
  4297. cmdiocb->fabric_iocb_cmpl = NULL;
  4298. cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
  4299. cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
  4300. atomic_dec(&phba->fabric_iocb_count);
  4301. if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
  4302. /* Post any pending iocbs to HBA */
  4303. lpfc_resume_fabric_iocbs(phba);
  4304. }
  4305. }
  4306. static int
  4307. lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
  4308. {
  4309. unsigned long iflags;
  4310. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4311. int ready;
  4312. int ret;
  4313. if (atomic_read(&phba->fabric_iocb_count) > 1)
  4314. BUG();
  4315. spin_lock_irqsave(&phba->hbalock, iflags);
  4316. ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
  4317. !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  4318. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4319. if (ready) {
  4320. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  4321. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  4322. iocb->iocb_flag |= LPFC_IO_FABRIC;
  4323. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  4324. "Fabric sched2: ste:x%x",
  4325. iocb->vport->port_state, 0, 0);
  4326. atomic_inc(&phba->fabric_iocb_count);
  4327. ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
  4328. if (ret == IOCB_ERROR) {
  4329. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  4330. iocb->fabric_iocb_cmpl = NULL;
  4331. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  4332. atomic_dec(&phba->fabric_iocb_count);
  4333. }
  4334. } else {
  4335. spin_lock_irqsave(&phba->hbalock, iflags);
  4336. list_add_tail(&iocb->list, &phba->fabric_iocb_list);
  4337. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4338. ret = IOCB_SUCCESS;
  4339. }
  4340. return ret;
  4341. }
  4342. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
  4343. {
  4344. LIST_HEAD(completions);
  4345. struct lpfc_hba *phba = vport->phba;
  4346. struct lpfc_iocbq *tmp_iocb, *piocb;
  4347. IOCB_t *cmd;
  4348. spin_lock_irq(&phba->hbalock);
  4349. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  4350. list) {
  4351. if (piocb->vport != vport)
  4352. continue;
  4353. list_move_tail(&piocb->list, &completions);
  4354. }
  4355. spin_unlock_irq(&phba->hbalock);
  4356. while (!list_empty(&completions)) {
  4357. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4358. list_del_init(&piocb->list);
  4359. cmd = &piocb->iocb;
  4360. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4361. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4362. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4363. }
  4364. }
  4365. void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
  4366. {
  4367. LIST_HEAD(completions);
  4368. struct lpfc_hba *phba = ndlp->vport->phba;
  4369. struct lpfc_iocbq *tmp_iocb, *piocb;
  4370. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4371. IOCB_t *cmd;
  4372. spin_lock_irq(&phba->hbalock);
  4373. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  4374. list) {
  4375. if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
  4376. list_move_tail(&piocb->list, &completions);
  4377. }
  4378. }
  4379. spin_unlock_irq(&phba->hbalock);
  4380. while (!list_empty(&completions)) {
  4381. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4382. list_del_init(&piocb->list);
  4383. cmd = &piocb->iocb;
  4384. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4385. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4386. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4387. }
  4388. }
  4389. void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
  4390. {
  4391. LIST_HEAD(completions);
  4392. struct lpfc_iocbq *piocb;
  4393. IOCB_t *cmd;
  4394. spin_lock_irq(&phba->hbalock);
  4395. list_splice_init(&phba->fabric_iocb_list, &completions);
  4396. spin_unlock_irq(&phba->hbalock);
  4397. while (!list_empty(&completions)) {
  4398. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4399. list_del_init(&piocb->list);
  4400. cmd = &piocb->iocb;
  4401. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4402. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4403. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4404. }
  4405. }
  4406. #if 0
  4407. void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
  4408. {
  4409. LIST_HEAD(completions);
  4410. struct lpfc_iocbq *tmp_iocb, *piocb;
  4411. IOCB_t *cmd;
  4412. struct lpfc_nodelist *ndlp;
  4413. spin_lock_irq(&phba->hbalock);
  4414. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  4415. list) {
  4416. cmd = &piocb->iocb;
  4417. ndlp = (struct lpfc_nodelist *) piocb->context1;
  4418. if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
  4419. ndlp != NULL &&
  4420. ndlp->nlp_DID == Fabric_DID)
  4421. list_move_tail(&piocb->list, &completions);
  4422. }
  4423. spin_unlock_irq(&phba->hbalock);
  4424. while (!list_empty(&completions)) {
  4425. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4426. list_del_init(&piocb->list);
  4427. cmd = &piocb->iocb;
  4428. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4429. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4430. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4431. }
  4432. }
  4433. #endif /* 0 */