lpfc_els.c 129 KB

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