lpfc_els.c 131 KB

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