lpfc_hbadisc.c 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 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/kthread.h>
  24. #include <linux/interrupt.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_device.h>
  27. #include <scsi/scsi_host.h>
  28. #include <scsi/scsi_transport_fc.h>
  29. #include "lpfc_hw4.h"
  30. #include "lpfc_hw.h"
  31. #include "lpfc_nl.h"
  32. #include "lpfc_disc.h"
  33. #include "lpfc_sli.h"
  34. #include "lpfc_sli4.h"
  35. #include "lpfc_scsi.h"
  36. #include "lpfc.h"
  37. #include "lpfc_logmsg.h"
  38. #include "lpfc_crtn.h"
  39. #include "lpfc_vport.h"
  40. #include "lpfc_debugfs.h"
  41. /* AlpaArray for assignment of scsid for scan-down and bind_method */
  42. static uint8_t lpfcAlpaArray[] = {
  43. 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
  44. 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
  45. 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
  46. 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
  47. 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
  48. 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
  49. 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
  50. 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
  51. 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
  52. 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
  53. 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
  54. 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
  55. 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
  56. };
  57. static void lpfc_disc_timeout_handler(struct lpfc_vport *);
  58. static void lpfc_disc_flush_list(struct lpfc_vport *vport);
  59. static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
  60. void
  61. lpfc_terminate_rport_io(struct fc_rport *rport)
  62. {
  63. struct lpfc_rport_data *rdata;
  64. struct lpfc_nodelist * ndlp;
  65. struct lpfc_hba *phba;
  66. rdata = rport->dd_data;
  67. ndlp = rdata->pnode;
  68. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  69. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
  70. printk(KERN_ERR "Cannot find remote node"
  71. " to terminate I/O Data x%x\n",
  72. rport->port_id);
  73. return;
  74. }
  75. phba = ndlp->phba;
  76. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  77. "rport terminate: sid:x%x did:x%x flg:x%x",
  78. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  79. if (ndlp->nlp_sid != NLP_NO_SID) {
  80. lpfc_sli_abort_iocb(ndlp->vport,
  81. &phba->sli.ring[phba->sli.fcp_ring],
  82. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  83. }
  84. }
  85. /*
  86. * This function will be called when dev_loss_tmo fire.
  87. */
  88. void
  89. lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
  90. {
  91. struct lpfc_rport_data *rdata;
  92. struct lpfc_nodelist * ndlp;
  93. struct lpfc_vport *vport;
  94. struct lpfc_hba *phba;
  95. struct lpfc_work_evt *evtp;
  96. int put_node;
  97. int put_rport;
  98. rdata = rport->dd_data;
  99. ndlp = rdata->pnode;
  100. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  101. return;
  102. vport = ndlp->vport;
  103. phba = vport->phba;
  104. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  105. "rport devlosscb: sid:x%x did:x%x flg:x%x",
  106. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  107. /* Don't defer this if we are in the process of deleting the vport
  108. * or unloading the driver. The unload will cleanup the node
  109. * appropriately we just need to cleanup the ndlp rport info here.
  110. */
  111. if (vport->load_flag & FC_UNLOADING) {
  112. put_node = rdata->pnode != NULL;
  113. put_rport = ndlp->rport != NULL;
  114. rdata->pnode = NULL;
  115. ndlp->rport = NULL;
  116. if (put_node)
  117. lpfc_nlp_put(ndlp);
  118. if (put_rport)
  119. put_device(&rport->dev);
  120. return;
  121. }
  122. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
  123. return;
  124. evtp = &ndlp->dev_loss_evt;
  125. if (!list_empty(&evtp->evt_listp))
  126. return;
  127. spin_lock_irq(&phba->hbalock);
  128. /* We need to hold the node by incrementing the reference
  129. * count until this queued work is done
  130. */
  131. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  132. if (evtp->evt_arg1) {
  133. evtp->evt = LPFC_EVT_DEV_LOSS;
  134. list_add_tail(&evtp->evt_listp, &phba->work_list);
  135. lpfc_worker_wake_up(phba);
  136. }
  137. spin_unlock_irq(&phba->hbalock);
  138. return;
  139. }
  140. /*
  141. * This function is called from the worker thread when dev_loss_tmo
  142. * expire.
  143. */
  144. static void
  145. lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
  146. {
  147. struct lpfc_rport_data *rdata;
  148. struct fc_rport *rport;
  149. struct lpfc_vport *vport;
  150. struct lpfc_hba *phba;
  151. uint8_t *name;
  152. int put_node;
  153. int put_rport;
  154. int warn_on = 0;
  155. rport = ndlp->rport;
  156. if (!rport)
  157. return;
  158. rdata = rport->dd_data;
  159. name = (uint8_t *) &ndlp->nlp_portname;
  160. vport = ndlp->vport;
  161. phba = vport->phba;
  162. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  163. "rport devlosstmo:did:x%x type:x%x id:x%x",
  164. ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
  165. /* Don't defer this if we are in the process of deleting the vport
  166. * or unloading the driver. The unload will cleanup the node
  167. * appropriately we just need to cleanup the ndlp rport info here.
  168. */
  169. if (vport->load_flag & FC_UNLOADING) {
  170. if (ndlp->nlp_sid != NLP_NO_SID) {
  171. /* flush the target */
  172. lpfc_sli_abort_iocb(vport,
  173. &phba->sli.ring[phba->sli.fcp_ring],
  174. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  175. }
  176. put_node = rdata->pnode != NULL;
  177. put_rport = ndlp->rport != NULL;
  178. rdata->pnode = NULL;
  179. ndlp->rport = NULL;
  180. if (put_node)
  181. lpfc_nlp_put(ndlp);
  182. if (put_rport)
  183. put_device(&rport->dev);
  184. return;
  185. }
  186. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
  187. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  188. "0284 Devloss timeout Ignored on "
  189. "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
  190. "NPort x%x\n",
  191. *name, *(name+1), *(name+2), *(name+3),
  192. *(name+4), *(name+5), *(name+6), *(name+7),
  193. ndlp->nlp_DID);
  194. return;
  195. }
  196. if (ndlp->nlp_type & NLP_FABRIC) {
  197. /* We will clean up these Nodes in linkup */
  198. put_node = rdata->pnode != NULL;
  199. put_rport = ndlp->rport != NULL;
  200. rdata->pnode = NULL;
  201. ndlp->rport = NULL;
  202. if (put_node)
  203. lpfc_nlp_put(ndlp);
  204. if (put_rport)
  205. put_device(&rport->dev);
  206. return;
  207. }
  208. if (ndlp->nlp_sid != NLP_NO_SID) {
  209. warn_on = 1;
  210. /* flush the target */
  211. lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
  212. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  213. }
  214. if (warn_on) {
  215. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  216. "0203 Devloss timeout on "
  217. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
  218. "NPort x%06x Data: x%x x%x x%x\n",
  219. *name, *(name+1), *(name+2), *(name+3),
  220. *(name+4), *(name+5), *(name+6), *(name+7),
  221. ndlp->nlp_DID, ndlp->nlp_flag,
  222. ndlp->nlp_state, ndlp->nlp_rpi);
  223. } else {
  224. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  225. "0204 Devloss timeout on "
  226. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
  227. "NPort x%06x Data: x%x x%x x%x\n",
  228. *name, *(name+1), *(name+2), *(name+3),
  229. *(name+4), *(name+5), *(name+6), *(name+7),
  230. ndlp->nlp_DID, ndlp->nlp_flag,
  231. ndlp->nlp_state, ndlp->nlp_rpi);
  232. }
  233. put_node = rdata->pnode != NULL;
  234. put_rport = ndlp->rport != NULL;
  235. rdata->pnode = NULL;
  236. ndlp->rport = NULL;
  237. if (put_node)
  238. lpfc_nlp_put(ndlp);
  239. if (put_rport)
  240. put_device(&rport->dev);
  241. if (!(vport->load_flag & FC_UNLOADING) &&
  242. !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
  243. !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
  244. (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
  245. lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
  246. lpfc_unregister_unused_fcf(phba);
  247. }
  248. /**
  249. * lpfc_alloc_fast_evt - Allocates data structure for posting event
  250. * @phba: Pointer to hba context object.
  251. *
  252. * This function is called from the functions which need to post
  253. * events from interrupt context. This function allocates data
  254. * structure required for posting event. It also keeps track of
  255. * number of events pending and prevent event storm when there are
  256. * too many events.
  257. **/
  258. struct lpfc_fast_path_event *
  259. lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
  260. struct lpfc_fast_path_event *ret;
  261. /* If there are lot of fast event do not exhaust memory due to this */
  262. if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
  263. return NULL;
  264. ret = kzalloc(sizeof(struct lpfc_fast_path_event),
  265. GFP_ATOMIC);
  266. if (ret) {
  267. atomic_inc(&phba->fast_event_count);
  268. INIT_LIST_HEAD(&ret->work_evt.evt_listp);
  269. ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
  270. }
  271. return ret;
  272. }
  273. /**
  274. * lpfc_free_fast_evt - Frees event data structure
  275. * @phba: Pointer to hba context object.
  276. * @evt: Event object which need to be freed.
  277. *
  278. * This function frees the data structure required for posting
  279. * events.
  280. **/
  281. void
  282. lpfc_free_fast_evt(struct lpfc_hba *phba,
  283. struct lpfc_fast_path_event *evt) {
  284. atomic_dec(&phba->fast_event_count);
  285. kfree(evt);
  286. }
  287. /**
  288. * lpfc_send_fastpath_evt - Posts events generated from fast path
  289. * @phba: Pointer to hba context object.
  290. * @evtp: Event data structure.
  291. *
  292. * This function is called from worker thread, when the interrupt
  293. * context need to post an event. This function posts the event
  294. * to fc transport netlink interface.
  295. **/
  296. static void
  297. lpfc_send_fastpath_evt(struct lpfc_hba *phba,
  298. struct lpfc_work_evt *evtp)
  299. {
  300. unsigned long evt_category, evt_sub_category;
  301. struct lpfc_fast_path_event *fast_evt_data;
  302. char *evt_data;
  303. uint32_t evt_data_size;
  304. struct Scsi_Host *shost;
  305. fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
  306. work_evt);
  307. evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
  308. evt_sub_category = (unsigned long) fast_evt_data->un.
  309. fabric_evt.subcategory;
  310. shost = lpfc_shost_from_vport(fast_evt_data->vport);
  311. if (evt_category == FC_REG_FABRIC_EVENT) {
  312. if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
  313. evt_data = (char *) &fast_evt_data->un.read_check_error;
  314. evt_data_size = sizeof(fast_evt_data->un.
  315. read_check_error);
  316. } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
  317. (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
  318. evt_data = (char *) &fast_evt_data->un.fabric_evt;
  319. evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
  320. } else {
  321. lpfc_free_fast_evt(phba, fast_evt_data);
  322. return;
  323. }
  324. } else if (evt_category == FC_REG_SCSI_EVENT) {
  325. switch (evt_sub_category) {
  326. case LPFC_EVENT_QFULL:
  327. case LPFC_EVENT_DEVBSY:
  328. evt_data = (char *) &fast_evt_data->un.scsi_evt;
  329. evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
  330. break;
  331. case LPFC_EVENT_CHECK_COND:
  332. evt_data = (char *) &fast_evt_data->un.check_cond_evt;
  333. evt_data_size = sizeof(fast_evt_data->un.
  334. check_cond_evt);
  335. break;
  336. case LPFC_EVENT_VARQUEDEPTH:
  337. evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
  338. evt_data_size = sizeof(fast_evt_data->un.
  339. queue_depth_evt);
  340. break;
  341. default:
  342. lpfc_free_fast_evt(phba, fast_evt_data);
  343. return;
  344. }
  345. } else {
  346. lpfc_free_fast_evt(phba, fast_evt_data);
  347. return;
  348. }
  349. fc_host_post_vendor_event(shost,
  350. fc_get_event_number(),
  351. evt_data_size,
  352. evt_data,
  353. LPFC_NL_VENDOR_ID);
  354. lpfc_free_fast_evt(phba, fast_evt_data);
  355. return;
  356. }
  357. static void
  358. lpfc_work_list_done(struct lpfc_hba *phba)
  359. {
  360. struct lpfc_work_evt *evtp = NULL;
  361. struct lpfc_nodelist *ndlp;
  362. int free_evt;
  363. spin_lock_irq(&phba->hbalock);
  364. while (!list_empty(&phba->work_list)) {
  365. list_remove_head((&phba->work_list), evtp, typeof(*evtp),
  366. evt_listp);
  367. spin_unlock_irq(&phba->hbalock);
  368. free_evt = 1;
  369. switch (evtp->evt) {
  370. case LPFC_EVT_ELS_RETRY:
  371. ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
  372. lpfc_els_retry_delay_handler(ndlp);
  373. free_evt = 0; /* evt is part of ndlp */
  374. /* decrement the node reference count held
  375. * for this queued work
  376. */
  377. lpfc_nlp_put(ndlp);
  378. break;
  379. case LPFC_EVT_DEV_LOSS:
  380. ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
  381. lpfc_dev_loss_tmo_handler(ndlp);
  382. free_evt = 0;
  383. /* decrement the node reference count held for
  384. * this queued work
  385. */
  386. lpfc_nlp_put(ndlp);
  387. break;
  388. case LPFC_EVT_ONLINE:
  389. if (phba->link_state < LPFC_LINK_DOWN)
  390. *(int *) (evtp->evt_arg1) = lpfc_online(phba);
  391. else
  392. *(int *) (evtp->evt_arg1) = 0;
  393. complete((struct completion *)(evtp->evt_arg2));
  394. break;
  395. case LPFC_EVT_OFFLINE_PREP:
  396. if (phba->link_state >= LPFC_LINK_DOWN)
  397. lpfc_offline_prep(phba);
  398. *(int *)(evtp->evt_arg1) = 0;
  399. complete((struct completion *)(evtp->evt_arg2));
  400. break;
  401. case LPFC_EVT_OFFLINE:
  402. lpfc_offline(phba);
  403. lpfc_sli_brdrestart(phba);
  404. *(int *)(evtp->evt_arg1) =
  405. lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
  406. lpfc_unblock_mgmt_io(phba);
  407. complete((struct completion *)(evtp->evt_arg2));
  408. break;
  409. case LPFC_EVT_WARM_START:
  410. lpfc_offline(phba);
  411. lpfc_reset_barrier(phba);
  412. lpfc_sli_brdreset(phba);
  413. lpfc_hba_down_post(phba);
  414. *(int *)(evtp->evt_arg1) =
  415. lpfc_sli_brdready(phba, HS_MBRDY);
  416. lpfc_unblock_mgmt_io(phba);
  417. complete((struct completion *)(evtp->evt_arg2));
  418. break;
  419. case LPFC_EVT_KILL:
  420. lpfc_offline(phba);
  421. *(int *)(evtp->evt_arg1)
  422. = (phba->pport->stopped)
  423. ? 0 : lpfc_sli_brdkill(phba);
  424. lpfc_unblock_mgmt_io(phba);
  425. complete((struct completion *)(evtp->evt_arg2));
  426. break;
  427. case LPFC_EVT_FASTPATH_MGMT_EVT:
  428. lpfc_send_fastpath_evt(phba, evtp);
  429. free_evt = 0;
  430. break;
  431. }
  432. if (free_evt)
  433. kfree(evtp);
  434. spin_lock_irq(&phba->hbalock);
  435. }
  436. spin_unlock_irq(&phba->hbalock);
  437. }
  438. static void
  439. lpfc_work_done(struct lpfc_hba *phba)
  440. {
  441. struct lpfc_sli_ring *pring;
  442. uint32_t ha_copy, status, control, work_port_events;
  443. struct lpfc_vport **vports;
  444. struct lpfc_vport *vport;
  445. int i;
  446. spin_lock_irq(&phba->hbalock);
  447. ha_copy = phba->work_ha;
  448. phba->work_ha = 0;
  449. spin_unlock_irq(&phba->hbalock);
  450. /* First, try to post the next mailbox command to SLI4 device */
  451. if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
  452. lpfc_sli4_post_async_mbox(phba);
  453. if (ha_copy & HA_ERATT)
  454. /* Handle the error attention event */
  455. lpfc_handle_eratt(phba);
  456. if (ha_copy & HA_MBATT)
  457. lpfc_sli_handle_mb_event(phba);
  458. if (ha_copy & HA_LATT)
  459. lpfc_handle_latt(phba);
  460. /* Process SLI4 events */
  461. if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
  462. if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
  463. lpfc_sli4_fcp_xri_abort_event_proc(phba);
  464. if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
  465. lpfc_sli4_els_xri_abort_event_proc(phba);
  466. if (phba->hba_flag & ASYNC_EVENT)
  467. lpfc_sli4_async_event_proc(phba);
  468. if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
  469. spin_lock_irq(&phba->hbalock);
  470. phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
  471. spin_unlock_irq(&phba->hbalock);
  472. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  473. }
  474. if (phba->hba_flag & HBA_RECEIVE_BUFFER)
  475. lpfc_sli4_handle_received_buffer(phba);
  476. }
  477. vports = lpfc_create_vport_work_array(phba);
  478. if (vports != NULL)
  479. for (i = 0; i <= phba->max_vports; i++) {
  480. /*
  481. * We could have no vports in array if unloading, so if
  482. * this happens then just use the pport
  483. */
  484. if (vports[i] == NULL && i == 0)
  485. vport = phba->pport;
  486. else
  487. vport = vports[i];
  488. if (vport == NULL)
  489. break;
  490. spin_lock_irq(&vport->work_port_lock);
  491. work_port_events = vport->work_port_events;
  492. vport->work_port_events &= ~work_port_events;
  493. spin_unlock_irq(&vport->work_port_lock);
  494. if (work_port_events & WORKER_DISC_TMO)
  495. lpfc_disc_timeout_handler(vport);
  496. if (work_port_events & WORKER_ELS_TMO)
  497. lpfc_els_timeout_handler(vport);
  498. if (work_port_events & WORKER_HB_TMO)
  499. lpfc_hb_timeout_handler(phba);
  500. if (work_port_events & WORKER_MBOX_TMO)
  501. lpfc_mbox_timeout_handler(phba);
  502. if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
  503. lpfc_unblock_fabric_iocbs(phba);
  504. if (work_port_events & WORKER_FDMI_TMO)
  505. lpfc_fdmi_timeout_handler(vport);
  506. if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
  507. lpfc_ramp_down_queue_handler(phba);
  508. if (work_port_events & WORKER_RAMP_UP_QUEUE)
  509. lpfc_ramp_up_queue_handler(phba);
  510. }
  511. lpfc_destroy_vport_work_array(phba, vports);
  512. pring = &phba->sli.ring[LPFC_ELS_RING];
  513. status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  514. status >>= (4*LPFC_ELS_RING);
  515. if ((status & HA_RXMASK)
  516. || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
  517. if (pring->flag & LPFC_STOP_IOCB_EVENT) {
  518. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  519. /* Set the lpfc data pending flag */
  520. set_bit(LPFC_DATA_READY, &phba->data_flags);
  521. } else {
  522. pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
  523. lpfc_sli_handle_slow_ring_event(phba, pring,
  524. (status &
  525. HA_RXMASK));
  526. }
  527. /*
  528. * Turn on Ring interrupts
  529. */
  530. if (phba->sli_rev <= LPFC_SLI_REV3) {
  531. spin_lock_irq(&phba->hbalock);
  532. control = readl(phba->HCregaddr);
  533. if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
  534. lpfc_debugfs_slow_ring_trc(phba,
  535. "WRK Enable ring: cntl:x%x hacopy:x%x",
  536. control, ha_copy, 0);
  537. control |= (HC_R0INT_ENA << LPFC_ELS_RING);
  538. writel(control, phba->HCregaddr);
  539. readl(phba->HCregaddr); /* flush */
  540. } else {
  541. lpfc_debugfs_slow_ring_trc(phba,
  542. "WRK Ring ok: cntl:x%x hacopy:x%x",
  543. control, ha_copy, 0);
  544. }
  545. spin_unlock_irq(&phba->hbalock);
  546. }
  547. }
  548. lpfc_work_list_done(phba);
  549. }
  550. int
  551. lpfc_do_work(void *p)
  552. {
  553. struct lpfc_hba *phba = p;
  554. int rc;
  555. set_user_nice(current, -20);
  556. phba->data_flags = 0;
  557. while (!kthread_should_stop()) {
  558. /* wait and check worker queue activities */
  559. rc = wait_event_interruptible(phba->work_waitq,
  560. (test_and_clear_bit(LPFC_DATA_READY,
  561. &phba->data_flags)
  562. || kthread_should_stop()));
  563. /* Signal wakeup shall terminate the worker thread */
  564. if (rc) {
  565. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  566. "0433 Wakeup on signal: rc=x%x\n", rc);
  567. break;
  568. }
  569. /* Attend pending lpfc data processing */
  570. lpfc_work_done(phba);
  571. }
  572. phba->worker_thread = NULL;
  573. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  574. "0432 Worker thread stopped.\n");
  575. return 0;
  576. }
  577. /*
  578. * This is only called to handle FC worker events. Since this a rare
  579. * occurance, we allocate a struct lpfc_work_evt structure here instead of
  580. * embedding it in the IOCB.
  581. */
  582. int
  583. lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
  584. uint32_t evt)
  585. {
  586. struct lpfc_work_evt *evtp;
  587. unsigned long flags;
  588. /*
  589. * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
  590. * be queued to worker thread for processing
  591. */
  592. evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
  593. if (!evtp)
  594. return 0;
  595. evtp->evt_arg1 = arg1;
  596. evtp->evt_arg2 = arg2;
  597. evtp->evt = evt;
  598. spin_lock_irqsave(&phba->hbalock, flags);
  599. list_add_tail(&evtp->evt_listp, &phba->work_list);
  600. spin_unlock_irqrestore(&phba->hbalock, flags);
  601. lpfc_worker_wake_up(phba);
  602. return 1;
  603. }
  604. void
  605. lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
  606. {
  607. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  608. struct lpfc_hba *phba = vport->phba;
  609. struct lpfc_nodelist *ndlp, *next_ndlp;
  610. int rc;
  611. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  612. if (!NLP_CHK_NODE_ACT(ndlp))
  613. continue;
  614. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  615. continue;
  616. if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
  617. ((vport->port_type == LPFC_NPIV_PORT) &&
  618. (ndlp->nlp_DID == NameServer_DID)))
  619. lpfc_unreg_rpi(vport, ndlp);
  620. /* Leave Fabric nodes alone on link down */
  621. if (!remove && ndlp->nlp_type & NLP_FABRIC)
  622. continue;
  623. rc = lpfc_disc_state_machine(vport, ndlp, NULL,
  624. remove
  625. ? NLP_EVT_DEVICE_RM
  626. : NLP_EVT_DEVICE_RECOVERY);
  627. }
  628. if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
  629. lpfc_mbx_unreg_vpi(vport);
  630. spin_lock_irq(shost->host_lock);
  631. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  632. spin_unlock_irq(shost->host_lock);
  633. }
  634. }
  635. void
  636. lpfc_port_link_failure(struct lpfc_vport *vport)
  637. {
  638. /* Cleanup any outstanding RSCN activity */
  639. lpfc_els_flush_rscn(vport);
  640. /* Cleanup any outstanding ELS commands */
  641. lpfc_els_flush_cmd(vport);
  642. lpfc_cleanup_rpis(vport, 0);
  643. /* Turn off discovery timer if its running */
  644. lpfc_can_disctmo(vport);
  645. }
  646. void
  647. lpfc_linkdown_port(struct lpfc_vport *vport)
  648. {
  649. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  650. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
  651. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  652. "Link Down: state:x%x rtry:x%x flg:x%x",
  653. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  654. lpfc_port_link_failure(vport);
  655. }
  656. int
  657. lpfc_linkdown(struct lpfc_hba *phba)
  658. {
  659. struct lpfc_vport *vport = phba->pport;
  660. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  661. struct lpfc_vport **vports;
  662. LPFC_MBOXQ_t *mb;
  663. int i;
  664. if (phba->link_state == LPFC_LINK_DOWN)
  665. return 0;
  666. spin_lock_irq(&phba->hbalock);
  667. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_DISCOVERED);
  668. if (phba->link_state > LPFC_LINK_DOWN) {
  669. phba->link_state = LPFC_LINK_DOWN;
  670. phba->pport->fc_flag &= ~FC_LBIT;
  671. }
  672. spin_unlock_irq(&phba->hbalock);
  673. vports = lpfc_create_vport_work_array(phba);
  674. if (vports != NULL)
  675. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  676. /* Issue a LINK DOWN event to all nodes */
  677. lpfc_linkdown_port(vports[i]);
  678. }
  679. lpfc_destroy_vport_work_array(phba, vports);
  680. /* Clean up any firmware default rpi's */
  681. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  682. if (mb) {
  683. lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
  684. mb->vport = vport;
  685. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  686. if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
  687. == MBX_NOT_FINISHED) {
  688. mempool_free(mb, phba->mbox_mem_pool);
  689. }
  690. }
  691. /* Setup myDID for link up if we are in pt2pt mode */
  692. if (phba->pport->fc_flag & FC_PT2PT) {
  693. phba->pport->fc_myDID = 0;
  694. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  695. if (mb) {
  696. lpfc_config_link(phba, mb);
  697. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  698. mb->vport = vport;
  699. if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
  700. == MBX_NOT_FINISHED) {
  701. mempool_free(mb, phba->mbox_mem_pool);
  702. }
  703. }
  704. spin_lock_irq(shost->host_lock);
  705. phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
  706. spin_unlock_irq(shost->host_lock);
  707. }
  708. return 0;
  709. }
  710. static void
  711. lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
  712. {
  713. struct lpfc_nodelist *ndlp;
  714. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  715. if (!NLP_CHK_NODE_ACT(ndlp))
  716. continue;
  717. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  718. continue;
  719. if (ndlp->nlp_type & NLP_FABRIC) {
  720. /* On Linkup its safe to clean up the ndlp
  721. * from Fabric connections.
  722. */
  723. if (ndlp->nlp_DID != Fabric_DID)
  724. lpfc_unreg_rpi(vport, ndlp);
  725. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  726. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  727. /* Fail outstanding IO now since device is
  728. * marked for PLOGI.
  729. */
  730. lpfc_unreg_rpi(vport, ndlp);
  731. }
  732. }
  733. }
  734. static void
  735. lpfc_linkup_port(struct lpfc_vport *vport)
  736. {
  737. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  738. struct lpfc_hba *phba = vport->phba;
  739. if ((vport->load_flag & FC_UNLOADING) != 0)
  740. return;
  741. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  742. "Link Up: top:x%x speed:x%x flg:x%x",
  743. phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
  744. /* If NPIV is not enabled, only bring the physical port up */
  745. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  746. (vport != phba->pport))
  747. return;
  748. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
  749. spin_lock_irq(shost->host_lock);
  750. vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
  751. FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
  752. vport->fc_flag |= FC_NDISC_ACTIVE;
  753. vport->fc_ns_retry = 0;
  754. spin_unlock_irq(shost->host_lock);
  755. if (vport->fc_flag & FC_LBIT)
  756. lpfc_linkup_cleanup_nodes(vport);
  757. }
  758. static int
  759. lpfc_linkup(struct lpfc_hba *phba)
  760. {
  761. struct lpfc_vport **vports;
  762. int i;
  763. phba->link_state = LPFC_LINK_UP;
  764. /* Unblock fabric iocbs if they are blocked */
  765. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  766. del_timer_sync(&phba->fabric_block_timer);
  767. vports = lpfc_create_vport_work_array(phba);
  768. if (vports != NULL)
  769. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  770. lpfc_linkup_port(vports[i]);
  771. lpfc_destroy_vport_work_array(phba, vports);
  772. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  773. (phba->sli_rev < LPFC_SLI_REV4))
  774. lpfc_issue_clear_la(phba, phba->pport);
  775. return 0;
  776. }
  777. /*
  778. * This routine handles processing a CLEAR_LA mailbox
  779. * command upon completion. It is setup in the LPFC_MBOXQ
  780. * as the completion routine when the command is
  781. * handed off to the SLI layer.
  782. */
  783. static void
  784. lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  785. {
  786. struct lpfc_vport *vport = pmb->vport;
  787. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  788. struct lpfc_sli *psli = &phba->sli;
  789. MAILBOX_t *mb = &pmb->u.mb;
  790. uint32_t control;
  791. /* Since we don't do discovery right now, turn these off here */
  792. psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  793. psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  794. psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  795. /* Check for error */
  796. if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
  797. /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
  798. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  799. "0320 CLEAR_LA mbxStatus error x%x hba "
  800. "state x%x\n",
  801. mb->mbxStatus, vport->port_state);
  802. phba->link_state = LPFC_HBA_ERROR;
  803. goto out;
  804. }
  805. if (vport->port_type == LPFC_PHYSICAL_PORT)
  806. phba->link_state = LPFC_HBA_READY;
  807. spin_lock_irq(&phba->hbalock);
  808. psli->sli_flag |= LPFC_PROCESS_LA;
  809. control = readl(phba->HCregaddr);
  810. control |= HC_LAINT_ENA;
  811. writel(control, phba->HCregaddr);
  812. readl(phba->HCregaddr); /* flush */
  813. spin_unlock_irq(&phba->hbalock);
  814. mempool_free(pmb, phba->mbox_mem_pool);
  815. return;
  816. out:
  817. /* Device Discovery completes */
  818. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  819. "0225 Device Discovery completes\n");
  820. mempool_free(pmb, phba->mbox_mem_pool);
  821. spin_lock_irq(shost->host_lock);
  822. vport->fc_flag &= ~FC_ABORT_DISCOVERY;
  823. spin_unlock_irq(shost->host_lock);
  824. lpfc_can_disctmo(vport);
  825. /* turn on Link Attention interrupts */
  826. spin_lock_irq(&phba->hbalock);
  827. psli->sli_flag |= LPFC_PROCESS_LA;
  828. control = readl(phba->HCregaddr);
  829. control |= HC_LAINT_ENA;
  830. writel(control, phba->HCregaddr);
  831. readl(phba->HCregaddr); /* flush */
  832. spin_unlock_irq(&phba->hbalock);
  833. return;
  834. }
  835. static void
  836. lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  837. {
  838. struct lpfc_vport *vport = pmb->vport;
  839. if (pmb->u.mb.mbxStatus)
  840. goto out;
  841. mempool_free(pmb, phba->mbox_mem_pool);
  842. if (phba->fc_topology == TOPOLOGY_LOOP &&
  843. vport->fc_flag & FC_PUBLIC_LOOP &&
  844. !(vport->fc_flag & FC_LBIT)) {
  845. /* Need to wait for FAN - use discovery timer
  846. * for timeout. port_state is identically
  847. * LPFC_LOCAL_CFG_LINK while waiting for FAN
  848. */
  849. lpfc_set_disctmo(vport);
  850. return;
  851. }
  852. /* Start discovery by sending a FLOGI. port_state is identically
  853. * LPFC_FLOGI while waiting for FLOGI cmpl
  854. */
  855. if (vport->port_state != LPFC_FLOGI) {
  856. lpfc_initial_flogi(vport);
  857. }
  858. return;
  859. out:
  860. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  861. "0306 CONFIG_LINK mbxStatus error x%x "
  862. "HBA state x%x\n",
  863. pmb->u.mb.mbxStatus, vport->port_state);
  864. mempool_free(pmb, phba->mbox_mem_pool);
  865. lpfc_linkdown(phba);
  866. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  867. "0200 CONFIG_LINK bad hba state x%x\n",
  868. vport->port_state);
  869. lpfc_issue_clear_la(phba, vport);
  870. return;
  871. }
  872. static void
  873. lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  874. {
  875. struct lpfc_vport *vport = mboxq->vport;
  876. unsigned long flags;
  877. if (mboxq->u.mb.mbxStatus) {
  878. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  879. "2017 REG_FCFI mbxStatus error x%x "
  880. "HBA state x%x\n",
  881. mboxq->u.mb.mbxStatus, vport->port_state);
  882. mempool_free(mboxq, phba->mbox_mem_pool);
  883. return;
  884. }
  885. /* Start FCoE discovery by sending a FLOGI. */
  886. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
  887. /* Set the FCFI registered flag */
  888. spin_lock_irqsave(&phba->hbalock, flags);
  889. phba->fcf.fcf_flag |= FCF_REGISTERED;
  890. spin_unlock_irqrestore(&phba->hbalock, flags);
  891. /* If there is a pending FCoE event, restart FCF table scan. */
  892. if (lpfc_check_pending_fcoe_event(phba, 1)) {
  893. mempool_free(mboxq, phba->mbox_mem_pool);
  894. return;
  895. }
  896. if (vport->port_state != LPFC_FLOGI) {
  897. spin_lock_irqsave(&phba->hbalock, flags);
  898. phba->fcf.fcf_flag |= (FCF_DISCOVERED | FCF_IN_USE);
  899. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  900. spin_unlock_irqrestore(&phba->hbalock, flags);
  901. lpfc_initial_flogi(vport);
  902. }
  903. mempool_free(mboxq, phba->mbox_mem_pool);
  904. return;
  905. }
  906. /**
  907. * lpfc_fab_name_match - Check if the fcf fabric name match.
  908. * @fab_name: pointer to fabric name.
  909. * @new_fcf_record: pointer to fcf record.
  910. *
  911. * This routine compare the fcf record's fabric name with provided
  912. * fabric name. If the fabric name are identical this function
  913. * returns 1 else return 0.
  914. **/
  915. static uint32_t
  916. lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
  917. {
  918. if ((fab_name[0] ==
  919. bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record)) &&
  920. (fab_name[1] ==
  921. bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) &&
  922. (fab_name[2] ==
  923. bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) &&
  924. (fab_name[3] ==
  925. bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) &&
  926. (fab_name[4] ==
  927. bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) &&
  928. (fab_name[5] ==
  929. bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) &&
  930. (fab_name[6] ==
  931. bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) &&
  932. (fab_name[7] ==
  933. bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)))
  934. return 1;
  935. else
  936. return 0;
  937. }
  938. /**
  939. * lpfc_sw_name_match - Check if the fcf switch name match.
  940. * @fab_name: pointer to fabric name.
  941. * @new_fcf_record: pointer to fcf record.
  942. *
  943. * This routine compare the fcf record's switch name with provided
  944. * switch name. If the switch name are identical this function
  945. * returns 1 else return 0.
  946. **/
  947. static uint32_t
  948. lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
  949. {
  950. if ((sw_name[0] ==
  951. bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record)) &&
  952. (sw_name[1] ==
  953. bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) &&
  954. (sw_name[2] ==
  955. bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) &&
  956. (sw_name[3] ==
  957. bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) &&
  958. (sw_name[4] ==
  959. bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) &&
  960. (sw_name[5] ==
  961. bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) &&
  962. (sw_name[6] ==
  963. bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) &&
  964. (sw_name[7] ==
  965. bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)))
  966. return 1;
  967. else
  968. return 0;
  969. }
  970. /**
  971. * lpfc_mac_addr_match - Check if the fcf mac address match.
  972. * @phba: pointer to lpfc hba data structure.
  973. * @new_fcf_record: pointer to fcf record.
  974. *
  975. * This routine compare the fcf record's mac address with HBA's
  976. * FCF mac address. If the mac addresses are identical this function
  977. * returns 1 else return 0.
  978. **/
  979. static uint32_t
  980. lpfc_mac_addr_match(struct lpfc_hba *phba, struct fcf_record *new_fcf_record)
  981. {
  982. if ((phba->fcf.mac_addr[0] ==
  983. bf_get(lpfc_fcf_record_mac_0, new_fcf_record)) &&
  984. (phba->fcf.mac_addr[1] ==
  985. bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) &&
  986. (phba->fcf.mac_addr[2] ==
  987. bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) &&
  988. (phba->fcf.mac_addr[3] ==
  989. bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) &&
  990. (phba->fcf.mac_addr[4] ==
  991. bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) &&
  992. (phba->fcf.mac_addr[5] ==
  993. bf_get(lpfc_fcf_record_mac_5, new_fcf_record)))
  994. return 1;
  995. else
  996. return 0;
  997. }
  998. /**
  999. * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
  1000. * @phba: pointer to lpfc hba data structure.
  1001. * @new_fcf_record: pointer to fcf record.
  1002. *
  1003. * This routine copies the FCF information from the FCF
  1004. * record to lpfc_hba data structure.
  1005. **/
  1006. static void
  1007. lpfc_copy_fcf_record(struct lpfc_hba *phba, struct fcf_record *new_fcf_record)
  1008. {
  1009. phba->fcf.fabric_name[0] =
  1010. bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
  1011. phba->fcf.fabric_name[1] =
  1012. bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
  1013. phba->fcf.fabric_name[2] =
  1014. bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
  1015. phba->fcf.fabric_name[3] =
  1016. bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
  1017. phba->fcf.fabric_name[4] =
  1018. bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
  1019. phba->fcf.fabric_name[5] =
  1020. bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
  1021. phba->fcf.fabric_name[6] =
  1022. bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
  1023. phba->fcf.fabric_name[7] =
  1024. bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
  1025. phba->fcf.mac_addr[0] =
  1026. bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
  1027. phba->fcf.mac_addr[1] =
  1028. bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
  1029. phba->fcf.mac_addr[2] =
  1030. bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
  1031. phba->fcf.mac_addr[3] =
  1032. bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
  1033. phba->fcf.mac_addr[4] =
  1034. bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
  1035. phba->fcf.mac_addr[5] =
  1036. bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
  1037. phba->fcf.fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
  1038. phba->fcf.priority = new_fcf_record->fip_priority;
  1039. phba->fcf.switch_name[0] =
  1040. bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
  1041. phba->fcf.switch_name[1] =
  1042. bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
  1043. phba->fcf.switch_name[2] =
  1044. bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
  1045. phba->fcf.switch_name[3] =
  1046. bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
  1047. phba->fcf.switch_name[4] =
  1048. bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
  1049. phba->fcf.switch_name[5] =
  1050. bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
  1051. phba->fcf.switch_name[6] =
  1052. bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
  1053. phba->fcf.switch_name[7] =
  1054. bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
  1055. }
  1056. /**
  1057. * lpfc_register_fcf - Register the FCF with hba.
  1058. * @phba: pointer to lpfc hba data structure.
  1059. *
  1060. * This routine issues a register fcfi mailbox command to register
  1061. * the fcf with HBA.
  1062. **/
  1063. static void
  1064. lpfc_register_fcf(struct lpfc_hba *phba)
  1065. {
  1066. LPFC_MBOXQ_t *fcf_mbxq;
  1067. int rc;
  1068. unsigned long flags;
  1069. spin_lock_irqsave(&phba->hbalock, flags);
  1070. /* If the FCF is not availabe do nothing. */
  1071. if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
  1072. spin_unlock_irqrestore(&phba->hbalock, flags);
  1073. return;
  1074. }
  1075. /* The FCF is already registered, start discovery */
  1076. if (phba->fcf.fcf_flag & FCF_REGISTERED) {
  1077. phba->fcf.fcf_flag |= (FCF_DISCOVERED | FCF_IN_USE);
  1078. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1079. spin_unlock_irqrestore(&phba->hbalock, flags);
  1080. if (phba->pport->port_state != LPFC_FLOGI)
  1081. lpfc_initial_flogi(phba->pport);
  1082. return;
  1083. }
  1084. spin_unlock_irqrestore(&phba->hbalock, flags);
  1085. fcf_mbxq = mempool_alloc(phba->mbox_mem_pool,
  1086. GFP_KERNEL);
  1087. if (!fcf_mbxq)
  1088. return;
  1089. lpfc_reg_fcfi(phba, fcf_mbxq);
  1090. fcf_mbxq->vport = phba->pport;
  1091. fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
  1092. rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
  1093. if (rc == MBX_NOT_FINISHED)
  1094. mempool_free(fcf_mbxq, phba->mbox_mem_pool);
  1095. return;
  1096. }
  1097. /**
  1098. * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
  1099. * @phba: pointer to lpfc hba data structure.
  1100. * @new_fcf_record: pointer to fcf record.
  1101. * @boot_flag: Indicates if this record used by boot bios.
  1102. * @addr_mode: The address mode to be used by this FCF
  1103. *
  1104. * This routine compare the fcf record with connect list obtained from the
  1105. * config region to decide if this FCF can be used for SAN discovery. It returns
  1106. * 1 if this record can be used for SAN discovery else return zero. If this FCF
  1107. * record can be used for SAN discovery, the boot_flag will indicate if this FCF
  1108. * is used by boot bios and addr_mode will indicate the addressing mode to be
  1109. * used for this FCF when the function returns.
  1110. * If the FCF record need to be used with a particular vlan id, the vlan is
  1111. * set in the vlan_id on return of the function. If not VLAN tagging need to
  1112. * be used with the FCF vlan_id will be set to 0xFFFF;
  1113. **/
  1114. static int
  1115. lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
  1116. struct fcf_record *new_fcf_record,
  1117. uint32_t *boot_flag, uint32_t *addr_mode,
  1118. uint16_t *vlan_id)
  1119. {
  1120. struct lpfc_fcf_conn_entry *conn_entry;
  1121. /* If FCF not available return 0 */
  1122. if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
  1123. !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record))
  1124. return 0;
  1125. if (!phba->cfg_enable_fip) {
  1126. *boot_flag = 0;
  1127. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1128. new_fcf_record);
  1129. if (phba->valid_vlan)
  1130. *vlan_id = phba->vlan_id;
  1131. else
  1132. *vlan_id = 0xFFFF;
  1133. return 1;
  1134. }
  1135. /*
  1136. * If there are no FCF connection table entry, driver connect to all
  1137. * FCFs.
  1138. */
  1139. if (list_empty(&phba->fcf_conn_rec_list)) {
  1140. *boot_flag = 0;
  1141. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1142. new_fcf_record);
  1143. /*
  1144. * When there are no FCF connect entries, use driver's default
  1145. * addressing mode - FPMA.
  1146. */
  1147. if (*addr_mode & LPFC_FCF_FPMA)
  1148. *addr_mode = LPFC_FCF_FPMA;
  1149. *vlan_id = 0xFFFF;
  1150. return 1;
  1151. }
  1152. list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, list) {
  1153. if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
  1154. continue;
  1155. if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
  1156. !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
  1157. new_fcf_record))
  1158. continue;
  1159. if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
  1160. !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
  1161. new_fcf_record))
  1162. continue;
  1163. if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
  1164. /*
  1165. * If the vlan bit map does not have the bit set for the
  1166. * vlan id to be used, then it is not a match.
  1167. */
  1168. if (!(new_fcf_record->vlan_bitmap
  1169. [conn_entry->conn_rec.vlan_tag / 8] &
  1170. (1 << (conn_entry->conn_rec.vlan_tag % 8))))
  1171. continue;
  1172. }
  1173. /*
  1174. * If connection record does not support any addressing mode,
  1175. * skip the FCF record.
  1176. */
  1177. if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
  1178. & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
  1179. continue;
  1180. /*
  1181. * Check if the connection record specifies a required
  1182. * addressing mode.
  1183. */
  1184. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1185. !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
  1186. /*
  1187. * If SPMA required but FCF not support this continue.
  1188. */
  1189. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1190. !(bf_get(lpfc_fcf_record_mac_addr_prov,
  1191. new_fcf_record) & LPFC_FCF_SPMA))
  1192. continue;
  1193. /*
  1194. * If FPMA required but FCF not support this continue.
  1195. */
  1196. if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1197. !(bf_get(lpfc_fcf_record_mac_addr_prov,
  1198. new_fcf_record) & LPFC_FCF_FPMA))
  1199. continue;
  1200. }
  1201. /*
  1202. * This fcf record matches filtering criteria.
  1203. */
  1204. if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
  1205. *boot_flag = 1;
  1206. else
  1207. *boot_flag = 0;
  1208. /*
  1209. * If user did not specify any addressing mode, or if the
  1210. * prefered addressing mode specified by user is not supported
  1211. * by FCF, allow fabric to pick the addressing mode.
  1212. */
  1213. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1214. new_fcf_record);
  1215. /*
  1216. * If the user specified a required address mode, assign that
  1217. * address mode
  1218. */
  1219. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1220. (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
  1221. *addr_mode = (conn_entry->conn_rec.flags &
  1222. FCFCNCT_AM_SPMA) ?
  1223. LPFC_FCF_SPMA : LPFC_FCF_FPMA;
  1224. /*
  1225. * If the user specified a prefered address mode, use the
  1226. * addr mode only if FCF support the addr_mode.
  1227. */
  1228. else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1229. (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
  1230. (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1231. (*addr_mode & LPFC_FCF_SPMA))
  1232. *addr_mode = LPFC_FCF_SPMA;
  1233. else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1234. (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
  1235. !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1236. (*addr_mode & LPFC_FCF_FPMA))
  1237. *addr_mode = LPFC_FCF_FPMA;
  1238. if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
  1239. *vlan_id = conn_entry->conn_rec.vlan_tag;
  1240. else
  1241. *vlan_id = 0xFFFF;
  1242. return 1;
  1243. }
  1244. return 0;
  1245. }
  1246. /**
  1247. * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
  1248. * @phba: pointer to lpfc hba data structure.
  1249. * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
  1250. *
  1251. * This function check if there is any fcoe event pending while driver
  1252. * scan FCF entries. If there is any pending event, it will restart the
  1253. * FCF saning and return 1 else return 0.
  1254. */
  1255. int
  1256. lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
  1257. {
  1258. LPFC_MBOXQ_t *mbox;
  1259. int rc;
  1260. /*
  1261. * If the Link is up and no FCoE events while in the
  1262. * FCF discovery, no need to restart FCF discovery.
  1263. */
  1264. if ((phba->link_state >= LPFC_LINK_UP) &&
  1265. (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
  1266. return 0;
  1267. spin_lock_irq(&phba->hbalock);
  1268. phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
  1269. spin_unlock_irq(&phba->hbalock);
  1270. if (phba->link_state >= LPFC_LINK_UP)
  1271. lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
  1272. if (unreg_fcf) {
  1273. spin_lock_irq(&phba->hbalock);
  1274. phba->fcf.fcf_flag &= ~FCF_REGISTERED;
  1275. spin_unlock_irq(&phba->hbalock);
  1276. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1277. if (!mbox) {
  1278. lpfc_printf_log(phba, KERN_ERR,
  1279. LOG_DISCOVERY|LOG_MBOX,
  1280. "2610 UNREG_FCFI mbox allocation failed\n");
  1281. return 1;
  1282. }
  1283. lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
  1284. mbox->vport = phba->pport;
  1285. mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
  1286. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  1287. if (rc == MBX_NOT_FINISHED) {
  1288. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  1289. "2611 UNREG_FCFI issue mbox failed\n");
  1290. mempool_free(mbox, phba->mbox_mem_pool);
  1291. }
  1292. }
  1293. return 1;
  1294. }
  1295. /**
  1296. * lpfc_mbx_cmpl_read_fcf_record - Completion handler for read_fcf mbox.
  1297. * @phba: pointer to lpfc hba data structure.
  1298. * @mboxq: pointer to mailbox object.
  1299. *
  1300. * This function iterate through all the fcf records available in
  1301. * HBA and choose the optimal FCF record for discovery. After finding
  1302. * the FCF for discovery it register the FCF record and kick start
  1303. * discovery.
  1304. * If FCF_IN_USE flag is set in currently used FCF, the routine try to
  1305. * use a FCF record which match fabric name and mac address of the
  1306. * currently used FCF record.
  1307. * If the driver support only one FCF, it will try to use the FCF record
  1308. * used by BOOT_BIOS.
  1309. */
  1310. void
  1311. lpfc_mbx_cmpl_read_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1312. {
  1313. void *virt_addr;
  1314. dma_addr_t phys_addr;
  1315. uint8_t *bytep;
  1316. struct lpfc_mbx_sge sge;
  1317. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  1318. uint32_t shdr_status, shdr_add_status;
  1319. union lpfc_sli4_cfg_shdr *shdr;
  1320. struct fcf_record *new_fcf_record;
  1321. int rc;
  1322. uint32_t boot_flag, addr_mode;
  1323. uint32_t next_fcf_index;
  1324. unsigned long flags;
  1325. uint16_t vlan_id;
  1326. /* If there is pending FCoE event restart FCF table scan */
  1327. if (lpfc_check_pending_fcoe_event(phba, 0)) {
  1328. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1329. return;
  1330. }
  1331. /* Get the first SGE entry from the non-embedded DMA memory. This
  1332. * routine only uses a single SGE.
  1333. */
  1334. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  1335. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  1336. if (unlikely(!mboxq->sge_array)) {
  1337. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1338. "2524 Failed to get the non-embedded SGE "
  1339. "virtual address\n");
  1340. goto out;
  1341. }
  1342. virt_addr = mboxq->sge_array->addr[0];
  1343. shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
  1344. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  1345. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  1346. &shdr->response);
  1347. /*
  1348. * The FCF Record was read and there is no reason for the driver
  1349. * to maintain the FCF record data or memory. Instead, just need
  1350. * to book keeping the FCFIs can be used.
  1351. */
  1352. if (shdr_status || shdr_add_status) {
  1353. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1354. "2521 READ_FCF_RECORD mailbox failed "
  1355. "with status x%x add_status x%x, mbx\n",
  1356. shdr_status, shdr_add_status);
  1357. goto out;
  1358. }
  1359. /* Interpreting the returned information of FCF records */
  1360. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  1361. lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
  1362. sizeof(struct lpfc_mbx_read_fcf_tbl));
  1363. next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
  1364. new_fcf_record = (struct fcf_record *)(virt_addr +
  1365. sizeof(struct lpfc_mbx_read_fcf_tbl));
  1366. lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
  1367. sizeof(struct fcf_record));
  1368. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  1369. rc = lpfc_match_fcf_conn_list(phba, new_fcf_record,
  1370. &boot_flag, &addr_mode,
  1371. &vlan_id);
  1372. /*
  1373. * If the fcf record does not match with connect list entries
  1374. * read the next entry.
  1375. */
  1376. if (!rc)
  1377. goto read_next_fcf;
  1378. /*
  1379. * If this is not the first FCF discovery of the HBA, use last
  1380. * FCF record for the discovery.
  1381. */
  1382. spin_lock_irqsave(&phba->hbalock, flags);
  1383. if (phba->fcf.fcf_flag & FCF_IN_USE) {
  1384. if (lpfc_fab_name_match(phba->fcf.fabric_name,
  1385. new_fcf_record) &&
  1386. lpfc_sw_name_match(phba->fcf.switch_name,
  1387. new_fcf_record) &&
  1388. lpfc_mac_addr_match(phba, new_fcf_record)) {
  1389. phba->fcf.fcf_flag |= FCF_AVAILABLE;
  1390. spin_unlock_irqrestore(&phba->hbalock, flags);
  1391. goto out;
  1392. }
  1393. spin_unlock_irqrestore(&phba->hbalock, flags);
  1394. goto read_next_fcf;
  1395. }
  1396. if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
  1397. /*
  1398. * If the current FCF record does not have boot flag
  1399. * set and new fcf record has boot flag set, use the
  1400. * new fcf record.
  1401. */
  1402. if (boot_flag && !(phba->fcf.fcf_flag & FCF_BOOT_ENABLE)) {
  1403. /* Use this FCF record */
  1404. lpfc_copy_fcf_record(phba, new_fcf_record);
  1405. phba->fcf.addr_mode = addr_mode;
  1406. phba->fcf.fcf_flag |= FCF_BOOT_ENABLE;
  1407. if (vlan_id != 0xFFFF) {
  1408. phba->fcf.fcf_flag |= FCF_VALID_VLAN;
  1409. phba->fcf.vlan_id = vlan_id;
  1410. }
  1411. spin_unlock_irqrestore(&phba->hbalock, flags);
  1412. goto read_next_fcf;
  1413. }
  1414. /*
  1415. * If the current FCF record has boot flag set and the
  1416. * new FCF record does not have boot flag, read the next
  1417. * FCF record.
  1418. */
  1419. if (!boot_flag && (phba->fcf.fcf_flag & FCF_BOOT_ENABLE)) {
  1420. spin_unlock_irqrestore(&phba->hbalock, flags);
  1421. goto read_next_fcf;
  1422. }
  1423. /*
  1424. * If there is a record with lower priority value for
  1425. * the current FCF, use that record.
  1426. */
  1427. if (lpfc_fab_name_match(phba->fcf.fabric_name,
  1428. new_fcf_record) &&
  1429. (new_fcf_record->fip_priority < phba->fcf.priority)) {
  1430. /* Use this FCF record */
  1431. lpfc_copy_fcf_record(phba, new_fcf_record);
  1432. phba->fcf.addr_mode = addr_mode;
  1433. if (vlan_id != 0xFFFF) {
  1434. phba->fcf.fcf_flag |= FCF_VALID_VLAN;
  1435. phba->fcf.vlan_id = vlan_id;
  1436. }
  1437. spin_unlock_irqrestore(&phba->hbalock, flags);
  1438. goto read_next_fcf;
  1439. }
  1440. spin_unlock_irqrestore(&phba->hbalock, flags);
  1441. goto read_next_fcf;
  1442. }
  1443. /*
  1444. * This is the first available FCF record, use this
  1445. * record.
  1446. */
  1447. lpfc_copy_fcf_record(phba, new_fcf_record);
  1448. phba->fcf.addr_mode = addr_mode;
  1449. if (boot_flag)
  1450. phba->fcf.fcf_flag |= FCF_BOOT_ENABLE;
  1451. phba->fcf.fcf_flag |= FCF_AVAILABLE;
  1452. if (vlan_id != 0xFFFF) {
  1453. phba->fcf.fcf_flag |= FCF_VALID_VLAN;
  1454. phba->fcf.vlan_id = vlan_id;
  1455. }
  1456. spin_unlock_irqrestore(&phba->hbalock, flags);
  1457. goto read_next_fcf;
  1458. read_next_fcf:
  1459. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1460. if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0)
  1461. lpfc_register_fcf(phba);
  1462. else
  1463. lpfc_sli4_read_fcf_record(phba, next_fcf_index);
  1464. return;
  1465. out:
  1466. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1467. lpfc_register_fcf(phba);
  1468. return;
  1469. }
  1470. /**
  1471. * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
  1472. * @phba: pointer to lpfc hba data structure.
  1473. * @mboxq: pointer to mailbox data structure.
  1474. *
  1475. * This function handles completion of init vpi mailbox command.
  1476. */
  1477. static void
  1478. lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1479. {
  1480. struct lpfc_vport *vport = mboxq->vport;
  1481. if (mboxq->u.mb.mbxStatus) {
  1482. lpfc_printf_vlog(vport, KERN_ERR,
  1483. LOG_MBOX,
  1484. "2609 Init VPI mailbox failed 0x%x\n",
  1485. mboxq->u.mb.mbxStatus);
  1486. mempool_free(mboxq, phba->mbox_mem_pool);
  1487. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1488. return;
  1489. }
  1490. vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
  1491. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  1492. lpfc_initial_fdisc(vport);
  1493. else {
  1494. lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
  1495. lpfc_printf_vlog(vport, KERN_ERR,
  1496. LOG_ELS,
  1497. "2606 No NPIV Fabric support\n");
  1498. }
  1499. return;
  1500. }
  1501. /**
  1502. * lpfc_start_fdiscs - send fdiscs for each vports on this port.
  1503. * @phba: pointer to lpfc hba data structure.
  1504. *
  1505. * This function loops through the list of vports on the @phba and issues an
  1506. * FDISC if possible.
  1507. */
  1508. void
  1509. lpfc_start_fdiscs(struct lpfc_hba *phba)
  1510. {
  1511. struct lpfc_vport **vports;
  1512. int i;
  1513. LPFC_MBOXQ_t *mboxq;
  1514. int rc;
  1515. vports = lpfc_create_vport_work_array(phba);
  1516. if (vports != NULL) {
  1517. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  1518. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  1519. continue;
  1520. /* There are no vpi for this vport */
  1521. if (vports[i]->vpi > phba->max_vpi) {
  1522. lpfc_vport_set_state(vports[i],
  1523. FC_VPORT_FAILED);
  1524. continue;
  1525. }
  1526. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1527. lpfc_vport_set_state(vports[i],
  1528. FC_VPORT_LINKDOWN);
  1529. continue;
  1530. }
  1531. if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
  1532. mboxq = mempool_alloc(phba->mbox_mem_pool,
  1533. GFP_KERNEL);
  1534. if (!mboxq) {
  1535. lpfc_printf_vlog(vports[i], KERN_ERR,
  1536. LOG_MBOX, "2607 Failed to allocate "
  1537. "init_vpi mailbox\n");
  1538. continue;
  1539. }
  1540. lpfc_init_vpi(phba, mboxq, vports[i]->vpi);
  1541. mboxq->vport = vports[i];
  1542. mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
  1543. rc = lpfc_sli_issue_mbox(phba, mboxq,
  1544. MBX_NOWAIT);
  1545. if (rc == MBX_NOT_FINISHED) {
  1546. lpfc_printf_vlog(vports[i], KERN_ERR,
  1547. LOG_MBOX, "2608 Failed to issue "
  1548. "init_vpi mailbox\n");
  1549. mempool_free(mboxq,
  1550. phba->mbox_mem_pool);
  1551. }
  1552. continue;
  1553. }
  1554. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  1555. lpfc_initial_fdisc(vports[i]);
  1556. else {
  1557. lpfc_vport_set_state(vports[i],
  1558. FC_VPORT_NO_FABRIC_SUPP);
  1559. lpfc_printf_vlog(vports[i], KERN_ERR,
  1560. LOG_ELS,
  1561. "0259 No NPIV "
  1562. "Fabric support\n");
  1563. }
  1564. }
  1565. }
  1566. lpfc_destroy_vport_work_array(phba, vports);
  1567. }
  1568. void
  1569. lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1570. {
  1571. struct lpfc_dmabuf *dmabuf = mboxq->context1;
  1572. struct lpfc_vport *vport = mboxq->vport;
  1573. if (mboxq->u.mb.mbxStatus) {
  1574. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1575. "2018 REG_VFI mbxStatus error x%x "
  1576. "HBA state x%x\n",
  1577. mboxq->u.mb.mbxStatus, vport->port_state);
  1578. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1579. /* FLOGI failed, use loop map to make discovery list */
  1580. lpfc_disc_list_loopmap(vport);
  1581. /* Start discovery */
  1582. lpfc_disc_start(vport);
  1583. goto fail_free_mem;
  1584. }
  1585. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1586. goto fail_free_mem;
  1587. }
  1588. /* Mark the vport has registered with its VFI */
  1589. vport->vfi_state |= LPFC_VFI_REGISTERED;
  1590. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  1591. lpfc_start_fdiscs(phba);
  1592. lpfc_do_scr_ns_plogi(phba, vport);
  1593. }
  1594. fail_free_mem:
  1595. mempool_free(mboxq, phba->mbox_mem_pool);
  1596. lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
  1597. kfree(dmabuf);
  1598. return;
  1599. }
  1600. static void
  1601. lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1602. {
  1603. MAILBOX_t *mb = &pmb->u.mb;
  1604. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
  1605. struct lpfc_vport *vport = pmb->vport;
  1606. /* Check for error */
  1607. if (mb->mbxStatus) {
  1608. /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
  1609. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1610. "0319 READ_SPARAM mbxStatus error x%x "
  1611. "hba state x%x>\n",
  1612. mb->mbxStatus, vport->port_state);
  1613. lpfc_linkdown(phba);
  1614. goto out;
  1615. }
  1616. memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
  1617. sizeof (struct serv_parm));
  1618. if (phba->cfg_soft_wwnn)
  1619. u64_to_wwn(phba->cfg_soft_wwnn,
  1620. vport->fc_sparam.nodeName.u.wwn);
  1621. if (phba->cfg_soft_wwpn)
  1622. u64_to_wwn(phba->cfg_soft_wwpn,
  1623. vport->fc_sparam.portName.u.wwn);
  1624. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  1625. sizeof(vport->fc_nodename));
  1626. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  1627. sizeof(vport->fc_portname));
  1628. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  1629. memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
  1630. memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
  1631. }
  1632. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1633. kfree(mp);
  1634. mempool_free(pmb, phba->mbox_mem_pool);
  1635. return;
  1636. out:
  1637. pmb->context1 = NULL;
  1638. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1639. kfree(mp);
  1640. lpfc_issue_clear_la(phba, vport);
  1641. mempool_free(pmb, phba->mbox_mem_pool);
  1642. return;
  1643. }
  1644. static void
  1645. lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
  1646. {
  1647. struct lpfc_vport *vport = phba->pport;
  1648. LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
  1649. int i;
  1650. struct lpfc_dmabuf *mp;
  1651. int rc;
  1652. struct fcf_record *fcf_record;
  1653. sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1654. spin_lock_irq(&phba->hbalock);
  1655. switch (la->UlnkSpeed) {
  1656. case LA_1GHZ_LINK:
  1657. phba->fc_linkspeed = LA_1GHZ_LINK;
  1658. break;
  1659. case LA_2GHZ_LINK:
  1660. phba->fc_linkspeed = LA_2GHZ_LINK;
  1661. break;
  1662. case LA_4GHZ_LINK:
  1663. phba->fc_linkspeed = LA_4GHZ_LINK;
  1664. break;
  1665. case LA_8GHZ_LINK:
  1666. phba->fc_linkspeed = LA_8GHZ_LINK;
  1667. break;
  1668. case LA_10GHZ_LINK:
  1669. phba->fc_linkspeed = LA_10GHZ_LINK;
  1670. break;
  1671. default:
  1672. phba->fc_linkspeed = LA_UNKNW_LINK;
  1673. break;
  1674. }
  1675. phba->fc_topology = la->topology;
  1676. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  1677. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1678. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  1679. if (phba->cfg_enable_npiv)
  1680. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1681. "1309 Link Up Event npiv not supported in loop "
  1682. "topology\n");
  1683. /* Get Loop Map information */
  1684. if (la->il)
  1685. vport->fc_flag |= FC_LBIT;
  1686. vport->fc_myDID = la->granted_AL_PA;
  1687. i = la->un.lilpBde64.tus.f.bdeSize;
  1688. if (i == 0) {
  1689. phba->alpa_map[0] = 0;
  1690. } else {
  1691. if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
  1692. int numalpa, j, k;
  1693. union {
  1694. uint8_t pamap[16];
  1695. struct {
  1696. uint32_t wd1;
  1697. uint32_t wd2;
  1698. uint32_t wd3;
  1699. uint32_t wd4;
  1700. } pa;
  1701. } un;
  1702. numalpa = phba->alpa_map[0];
  1703. j = 0;
  1704. while (j < numalpa) {
  1705. memset(un.pamap, 0, 16);
  1706. for (k = 1; j < numalpa; k++) {
  1707. un.pamap[k - 1] =
  1708. phba->alpa_map[j + 1];
  1709. j++;
  1710. if (k == 16)
  1711. break;
  1712. }
  1713. /* Link Up Event ALPA map */
  1714. lpfc_printf_log(phba,
  1715. KERN_WARNING,
  1716. LOG_LINK_EVENT,
  1717. "1304 Link Up Event "
  1718. "ALPA map Data: x%x "
  1719. "x%x x%x x%x\n",
  1720. un.pa.wd1, un.pa.wd2,
  1721. un.pa.wd3, un.pa.wd4);
  1722. }
  1723. }
  1724. }
  1725. } else {
  1726. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
  1727. if (phba->max_vpi && phba->cfg_enable_npiv &&
  1728. (phba->sli_rev == 3))
  1729. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  1730. }
  1731. vport->fc_myDID = phba->fc_pref_DID;
  1732. vport->fc_flag |= FC_LBIT;
  1733. }
  1734. spin_unlock_irq(&phba->hbalock);
  1735. lpfc_linkup(phba);
  1736. if (sparam_mbox) {
  1737. lpfc_read_sparam(phba, sparam_mbox, 0);
  1738. sparam_mbox->vport = vport;
  1739. sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
  1740. rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
  1741. if (rc == MBX_NOT_FINISHED) {
  1742. mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
  1743. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1744. kfree(mp);
  1745. mempool_free(sparam_mbox, phba->mbox_mem_pool);
  1746. goto out;
  1747. }
  1748. }
  1749. if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  1750. cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1751. if (!cfglink_mbox)
  1752. goto out;
  1753. vport->port_state = LPFC_LOCAL_CFG_LINK;
  1754. lpfc_config_link(phba, cfglink_mbox);
  1755. cfglink_mbox->vport = vport;
  1756. cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
  1757. rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
  1758. if (rc == MBX_NOT_FINISHED) {
  1759. mempool_free(cfglink_mbox, phba->mbox_mem_pool);
  1760. goto out;
  1761. }
  1762. } else {
  1763. vport->port_state = LPFC_VPORT_UNKNOWN;
  1764. /*
  1765. * Add the driver's default FCF record at FCF index 0 now. This
  1766. * is phase 1 implementation that support FCF index 0 and driver
  1767. * defaults.
  1768. */
  1769. if (phba->cfg_enable_fip == 0) {
  1770. fcf_record = kzalloc(sizeof(struct fcf_record),
  1771. GFP_KERNEL);
  1772. if (unlikely(!fcf_record)) {
  1773. lpfc_printf_log(phba, KERN_ERR,
  1774. LOG_MBOX | LOG_SLI,
  1775. "2554 Could not allocate memmory for "
  1776. "fcf record\n");
  1777. rc = -ENODEV;
  1778. goto out;
  1779. }
  1780. lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
  1781. LPFC_FCOE_FCF_DEF_INDEX);
  1782. rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
  1783. if (unlikely(rc)) {
  1784. lpfc_printf_log(phba, KERN_ERR,
  1785. LOG_MBOX | LOG_SLI,
  1786. "2013 Could not manually add FCF "
  1787. "record 0, status %d\n", rc);
  1788. rc = -ENODEV;
  1789. kfree(fcf_record);
  1790. goto out;
  1791. }
  1792. kfree(fcf_record);
  1793. }
  1794. /*
  1795. * The driver is expected to do FIP/FCF. Call the port
  1796. * and get the FCF Table.
  1797. */
  1798. spin_lock_irq(&phba->hbalock);
  1799. if (phba->hba_flag & FCF_DISC_INPROGRESS) {
  1800. spin_unlock_irq(&phba->hbalock);
  1801. return;
  1802. }
  1803. spin_unlock_irq(&phba->hbalock);
  1804. rc = lpfc_sli4_read_fcf_record(phba,
  1805. LPFC_FCOE_FCF_GET_FIRST);
  1806. if (rc)
  1807. goto out;
  1808. }
  1809. return;
  1810. out:
  1811. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1812. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1813. "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
  1814. vport->port_state, sparam_mbox, cfglink_mbox);
  1815. lpfc_issue_clear_la(phba, vport);
  1816. return;
  1817. }
  1818. static void
  1819. lpfc_enable_la(struct lpfc_hba *phba)
  1820. {
  1821. uint32_t control;
  1822. struct lpfc_sli *psli = &phba->sli;
  1823. spin_lock_irq(&phba->hbalock);
  1824. psli->sli_flag |= LPFC_PROCESS_LA;
  1825. if (phba->sli_rev <= LPFC_SLI_REV3) {
  1826. control = readl(phba->HCregaddr);
  1827. control |= HC_LAINT_ENA;
  1828. writel(control, phba->HCregaddr);
  1829. readl(phba->HCregaddr); /* flush */
  1830. }
  1831. spin_unlock_irq(&phba->hbalock);
  1832. }
  1833. static void
  1834. lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
  1835. {
  1836. lpfc_linkdown(phba);
  1837. lpfc_enable_la(phba);
  1838. lpfc_unregister_unused_fcf(phba);
  1839. /* turn on Link Attention interrupts - no CLEAR_LA needed */
  1840. }
  1841. /*
  1842. * This routine handles processing a READ_LA mailbox
  1843. * command upon completion. It is setup in the LPFC_MBOXQ
  1844. * as the completion routine when the command is
  1845. * handed off to the SLI layer.
  1846. */
  1847. void
  1848. lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1849. {
  1850. struct lpfc_vport *vport = pmb->vport;
  1851. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1852. READ_LA_VAR *la;
  1853. MAILBOX_t *mb = &pmb->u.mb;
  1854. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1855. /* Unblock ELS traffic */
  1856. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  1857. /* Check for error */
  1858. if (mb->mbxStatus) {
  1859. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1860. "1307 READ_LA mbox error x%x state x%x\n",
  1861. mb->mbxStatus, vport->port_state);
  1862. lpfc_mbx_issue_link_down(phba);
  1863. phba->link_state = LPFC_HBA_ERROR;
  1864. goto lpfc_mbx_cmpl_read_la_free_mbuf;
  1865. }
  1866. la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
  1867. memcpy(&phba->alpa_map[0], mp->virt, 128);
  1868. spin_lock_irq(shost->host_lock);
  1869. if (la->pb)
  1870. vport->fc_flag |= FC_BYPASSED_MODE;
  1871. else
  1872. vport->fc_flag &= ~FC_BYPASSED_MODE;
  1873. spin_unlock_irq(shost->host_lock);
  1874. if ((phba->fc_eventTag < la->eventTag) ||
  1875. (phba->fc_eventTag == la->eventTag)) {
  1876. phba->fc_stat.LinkMultiEvent++;
  1877. if (la->attType == AT_LINK_UP)
  1878. if (phba->fc_eventTag != 0)
  1879. lpfc_linkdown(phba);
  1880. }
  1881. phba->fc_eventTag = la->eventTag;
  1882. if (la->mm)
  1883. phba->sli.sli_flag |= LPFC_MENLO_MAINT;
  1884. else
  1885. phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
  1886. if (la->attType == AT_LINK_UP && (!la->mm)) {
  1887. phba->fc_stat.LinkUp++;
  1888. if (phba->link_flag & LS_LOOPBACK_MODE) {
  1889. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1890. "1306 Link Up Event in loop back mode "
  1891. "x%x received Data: x%x x%x x%x x%x\n",
  1892. la->eventTag, phba->fc_eventTag,
  1893. la->granted_AL_PA, la->UlnkSpeed,
  1894. phba->alpa_map[0]);
  1895. } else {
  1896. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1897. "1303 Link Up Event x%x received "
  1898. "Data: x%x x%x x%x x%x x%x x%x %d\n",
  1899. la->eventTag, phba->fc_eventTag,
  1900. la->granted_AL_PA, la->UlnkSpeed,
  1901. phba->alpa_map[0],
  1902. la->mm, la->fa,
  1903. phba->wait_4_mlo_maint_flg);
  1904. }
  1905. lpfc_mbx_process_link_up(phba, la);
  1906. } else if (la->attType == AT_LINK_DOWN) {
  1907. phba->fc_stat.LinkDown++;
  1908. if (phba->link_flag & LS_LOOPBACK_MODE) {
  1909. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1910. "1308 Link Down Event in loop back mode "
  1911. "x%x received "
  1912. "Data: x%x x%x x%x\n",
  1913. la->eventTag, phba->fc_eventTag,
  1914. phba->pport->port_state, vport->fc_flag);
  1915. }
  1916. else {
  1917. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1918. "1305 Link Down Event x%x received "
  1919. "Data: x%x x%x x%x x%x x%x\n",
  1920. la->eventTag, phba->fc_eventTag,
  1921. phba->pport->port_state, vport->fc_flag,
  1922. la->mm, la->fa);
  1923. }
  1924. lpfc_mbx_issue_link_down(phba);
  1925. }
  1926. if (la->mm && la->attType == AT_LINK_UP) {
  1927. if (phba->link_state != LPFC_LINK_DOWN) {
  1928. phba->fc_stat.LinkDown++;
  1929. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1930. "1312 Link Down Event x%x received "
  1931. "Data: x%x x%x x%x\n",
  1932. la->eventTag, phba->fc_eventTag,
  1933. phba->pport->port_state, vport->fc_flag);
  1934. lpfc_mbx_issue_link_down(phba);
  1935. } else
  1936. lpfc_enable_la(phba);
  1937. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1938. "1310 Menlo Maint Mode Link up Event x%x rcvd "
  1939. "Data: x%x x%x x%x\n",
  1940. la->eventTag, phba->fc_eventTag,
  1941. phba->pport->port_state, vport->fc_flag);
  1942. /*
  1943. * The cmnd that triggered this will be waiting for this
  1944. * signal.
  1945. */
  1946. /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
  1947. if (phba->wait_4_mlo_maint_flg) {
  1948. phba->wait_4_mlo_maint_flg = 0;
  1949. wake_up_interruptible(&phba->wait_4_mlo_m_q);
  1950. }
  1951. }
  1952. if (la->fa) {
  1953. if (la->mm)
  1954. lpfc_issue_clear_la(phba, vport);
  1955. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1956. "1311 fa %d\n", la->fa);
  1957. }
  1958. lpfc_mbx_cmpl_read_la_free_mbuf:
  1959. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1960. kfree(mp);
  1961. mempool_free(pmb, phba->mbox_mem_pool);
  1962. return;
  1963. }
  1964. /*
  1965. * This routine handles processing a REG_LOGIN mailbox
  1966. * command upon completion. It is setup in the LPFC_MBOXQ
  1967. * as the completion routine when the command is
  1968. * handed off to the SLI layer.
  1969. */
  1970. void
  1971. lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1972. {
  1973. struct lpfc_vport *vport = pmb->vport;
  1974. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1975. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  1976. pmb->context1 = NULL;
  1977. /* Good status, call state machine */
  1978. lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
  1979. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1980. kfree(mp);
  1981. mempool_free(pmb, phba->mbox_mem_pool);
  1982. /* decrement the node reference count held for this callback
  1983. * function.
  1984. */
  1985. lpfc_nlp_put(ndlp);
  1986. return;
  1987. }
  1988. static void
  1989. lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1990. {
  1991. MAILBOX_t *mb = &pmb->u.mb;
  1992. struct lpfc_vport *vport = pmb->vport;
  1993. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1994. switch (mb->mbxStatus) {
  1995. case 0x0011:
  1996. case 0x0020:
  1997. case 0x9700:
  1998. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  1999. "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
  2000. mb->mbxStatus);
  2001. break;
  2002. }
  2003. vport->unreg_vpi_cmpl = VPORT_OK;
  2004. mempool_free(pmb, phba->mbox_mem_pool);
  2005. /*
  2006. * This shost reference might have been taken at the beginning of
  2007. * lpfc_vport_delete()
  2008. */
  2009. if (vport->load_flag & FC_UNLOADING)
  2010. scsi_host_put(shost);
  2011. }
  2012. int
  2013. lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
  2014. {
  2015. struct lpfc_hba *phba = vport->phba;
  2016. LPFC_MBOXQ_t *mbox;
  2017. int rc;
  2018. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2019. if (!mbox)
  2020. return 1;
  2021. lpfc_unreg_vpi(phba, vport->vpi, mbox);
  2022. mbox->vport = vport;
  2023. mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
  2024. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2025. if (rc == MBX_NOT_FINISHED) {
  2026. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  2027. "1800 Could not issue unreg_vpi\n");
  2028. mempool_free(mbox, phba->mbox_mem_pool);
  2029. vport->unreg_vpi_cmpl = VPORT_ERROR;
  2030. return rc;
  2031. }
  2032. return 0;
  2033. }
  2034. static void
  2035. lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2036. {
  2037. struct lpfc_vport *vport = pmb->vport;
  2038. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2039. MAILBOX_t *mb = &pmb->u.mb;
  2040. switch (mb->mbxStatus) {
  2041. case 0x0011:
  2042. case 0x9601:
  2043. case 0x9602:
  2044. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2045. "0912 cmpl_reg_vpi, mb status = 0x%x\n",
  2046. mb->mbxStatus);
  2047. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2048. spin_lock_irq(shost->host_lock);
  2049. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  2050. spin_unlock_irq(shost->host_lock);
  2051. vport->fc_myDID = 0;
  2052. goto out;
  2053. }
  2054. vport->num_disc_nodes = 0;
  2055. /* go thru NPR list and issue ELS PLOGIs */
  2056. if (vport->fc_npr_cnt)
  2057. lpfc_els_disc_plogi(vport);
  2058. if (!vport->num_disc_nodes) {
  2059. spin_lock_irq(shost->host_lock);
  2060. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  2061. spin_unlock_irq(shost->host_lock);
  2062. lpfc_can_disctmo(vport);
  2063. }
  2064. vport->port_state = LPFC_VPORT_READY;
  2065. out:
  2066. mempool_free(pmb, phba->mbox_mem_pool);
  2067. return;
  2068. }
  2069. /**
  2070. * lpfc_create_static_vport - Read HBA config region to create static vports.
  2071. * @phba: pointer to lpfc hba data structure.
  2072. *
  2073. * This routine issue a DUMP mailbox command for config region 22 to get
  2074. * the list of static vports to be created. The function create vports
  2075. * based on the information returned from the HBA.
  2076. **/
  2077. void
  2078. lpfc_create_static_vport(struct lpfc_hba *phba)
  2079. {
  2080. LPFC_MBOXQ_t *pmb = NULL;
  2081. MAILBOX_t *mb;
  2082. struct static_vport_info *vport_info;
  2083. int rc = 0, i;
  2084. struct fc_vport_identifiers vport_id;
  2085. struct fc_vport *new_fc_vport;
  2086. struct Scsi_Host *shost;
  2087. struct lpfc_vport *vport;
  2088. uint16_t offset = 0;
  2089. uint8_t *vport_buff;
  2090. struct lpfc_dmabuf *mp;
  2091. uint32_t byte_count = 0;
  2092. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2093. if (!pmb) {
  2094. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2095. "0542 lpfc_create_static_vport failed to"
  2096. " allocate mailbox memory\n");
  2097. return;
  2098. }
  2099. mb = &pmb->u.mb;
  2100. vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
  2101. if (!vport_info) {
  2102. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2103. "0543 lpfc_create_static_vport failed to"
  2104. " allocate vport_info\n");
  2105. mempool_free(pmb, phba->mbox_mem_pool);
  2106. return;
  2107. }
  2108. vport_buff = (uint8_t *) vport_info;
  2109. do {
  2110. if (lpfc_dump_static_vport(phba, pmb, offset))
  2111. goto out;
  2112. pmb->vport = phba->pport;
  2113. rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO);
  2114. if ((rc != MBX_SUCCESS) || mb->mbxStatus) {
  2115. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2116. "0544 lpfc_create_static_vport failed to"
  2117. " issue dump mailbox command ret 0x%x "
  2118. "status 0x%x\n",
  2119. rc, mb->mbxStatus);
  2120. goto out;
  2121. }
  2122. if (phba->sli_rev == LPFC_SLI_REV4) {
  2123. byte_count = pmb->u.mqe.un.mb_words[5];
  2124. mp = (struct lpfc_dmabuf *) pmb->context2;
  2125. if (byte_count > sizeof(struct static_vport_info) -
  2126. offset)
  2127. byte_count = sizeof(struct static_vport_info)
  2128. - offset;
  2129. memcpy(vport_buff + offset, mp->virt, byte_count);
  2130. offset += byte_count;
  2131. } else {
  2132. if (mb->un.varDmp.word_cnt >
  2133. sizeof(struct static_vport_info) - offset)
  2134. mb->un.varDmp.word_cnt =
  2135. sizeof(struct static_vport_info)
  2136. - offset;
  2137. byte_count = mb->un.varDmp.word_cnt;
  2138. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  2139. vport_buff + offset,
  2140. byte_count);
  2141. offset += byte_count;
  2142. }
  2143. } while (byte_count &&
  2144. offset < sizeof(struct static_vport_info));
  2145. if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
  2146. ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
  2147. != VPORT_INFO_REV)) {
  2148. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2149. "0545 lpfc_create_static_vport bad"
  2150. " information header 0x%x 0x%x\n",
  2151. le32_to_cpu(vport_info->signature),
  2152. le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
  2153. goto out;
  2154. }
  2155. shost = lpfc_shost_from_vport(phba->pport);
  2156. for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
  2157. memset(&vport_id, 0, sizeof(vport_id));
  2158. vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
  2159. vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
  2160. if (!vport_id.port_name || !vport_id.node_name)
  2161. continue;
  2162. vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
  2163. vport_id.vport_type = FC_PORTTYPE_NPIV;
  2164. vport_id.disable = false;
  2165. new_fc_vport = fc_vport_create(shost, 0, &vport_id);
  2166. if (!new_fc_vport) {
  2167. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2168. "0546 lpfc_create_static_vport failed to"
  2169. " create vport\n");
  2170. continue;
  2171. }
  2172. vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
  2173. vport->vport_flag |= STATIC_VPORT;
  2174. }
  2175. out:
  2176. kfree(vport_info);
  2177. if (rc != MBX_TIMEOUT) {
  2178. if (pmb->context2) {
  2179. mp = (struct lpfc_dmabuf *) pmb->context2;
  2180. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2181. kfree(mp);
  2182. }
  2183. mempool_free(pmb, phba->mbox_mem_pool);
  2184. }
  2185. return;
  2186. }
  2187. /*
  2188. * This routine handles processing a Fabric REG_LOGIN mailbox
  2189. * command upon completion. It is setup in the LPFC_MBOXQ
  2190. * as the completion routine when the command is
  2191. * handed off to the SLI layer.
  2192. */
  2193. void
  2194. lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2195. {
  2196. struct lpfc_vport *vport = pmb->vport;
  2197. MAILBOX_t *mb = &pmb->u.mb;
  2198. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2199. struct lpfc_nodelist *ndlp;
  2200. ndlp = (struct lpfc_nodelist *) pmb->context2;
  2201. pmb->context1 = NULL;
  2202. pmb->context2 = NULL;
  2203. if (mb->mbxStatus) {
  2204. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  2205. "0258 Register Fabric login error: 0x%x\n",
  2206. mb->mbxStatus);
  2207. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2208. kfree(mp);
  2209. mempool_free(pmb, phba->mbox_mem_pool);
  2210. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2211. /* FLOGI failed, use loop map to make discovery list */
  2212. lpfc_disc_list_loopmap(vport);
  2213. /* Start discovery */
  2214. lpfc_disc_start(vport);
  2215. /* Decrement the reference count to ndlp after the
  2216. * reference to the ndlp are done.
  2217. */
  2218. lpfc_nlp_put(ndlp);
  2219. return;
  2220. }
  2221. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2222. /* Decrement the reference count to ndlp after the reference
  2223. * to the ndlp are done.
  2224. */
  2225. lpfc_nlp_put(ndlp);
  2226. return;
  2227. }
  2228. ndlp->nlp_rpi = mb->un.varWords[0];
  2229. ndlp->nlp_flag |= NLP_RPI_VALID;
  2230. ndlp->nlp_type |= NLP_FABRIC;
  2231. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2232. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  2233. lpfc_start_fdiscs(phba);
  2234. lpfc_do_scr_ns_plogi(phba, vport);
  2235. }
  2236. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2237. kfree(mp);
  2238. mempool_free(pmb, phba->mbox_mem_pool);
  2239. /* Drop the reference count from the mbox at the end after
  2240. * all the current reference to the ndlp have been done.
  2241. */
  2242. lpfc_nlp_put(ndlp);
  2243. return;
  2244. }
  2245. /*
  2246. * This routine handles processing a NameServer REG_LOGIN mailbox
  2247. * command upon completion. It is setup in the LPFC_MBOXQ
  2248. * as the completion routine when the command is
  2249. * handed off to the SLI layer.
  2250. */
  2251. void
  2252. lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2253. {
  2254. MAILBOX_t *mb = &pmb->u.mb;
  2255. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2256. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2257. struct lpfc_vport *vport = pmb->vport;
  2258. if (mb->mbxStatus) {
  2259. out:
  2260. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2261. "0260 Register NameServer error: 0x%x\n",
  2262. mb->mbxStatus);
  2263. /* decrement the node reference count held for this
  2264. * callback function.
  2265. */
  2266. lpfc_nlp_put(ndlp);
  2267. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2268. kfree(mp);
  2269. mempool_free(pmb, phba->mbox_mem_pool);
  2270. /* If no other thread is using the ndlp, free it */
  2271. lpfc_nlp_not_used(ndlp);
  2272. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2273. /*
  2274. * RegLogin failed, use loop map to make discovery
  2275. * list
  2276. */
  2277. lpfc_disc_list_loopmap(vport);
  2278. /* Start discovery */
  2279. lpfc_disc_start(vport);
  2280. return;
  2281. }
  2282. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2283. return;
  2284. }
  2285. pmb->context1 = NULL;
  2286. ndlp->nlp_rpi = mb->un.varWords[0];
  2287. ndlp->nlp_flag |= NLP_RPI_VALID;
  2288. ndlp->nlp_type |= NLP_FABRIC;
  2289. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2290. if (vport->port_state < LPFC_VPORT_READY) {
  2291. /* Link up discovery requires Fabric registration. */
  2292. lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
  2293. lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
  2294. lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
  2295. lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
  2296. lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
  2297. /* Issue SCR just before NameServer GID_FT Query */
  2298. lpfc_issue_els_scr(vport, SCR_DID, 0);
  2299. }
  2300. vport->fc_ns_retry = 0;
  2301. /* Good status, issue CT Request to NameServer */
  2302. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
  2303. /* Cannot issue NameServer Query, so finish up discovery */
  2304. goto out;
  2305. }
  2306. /* decrement the node reference count held for this
  2307. * callback function.
  2308. */
  2309. lpfc_nlp_put(ndlp);
  2310. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2311. kfree(mp);
  2312. mempool_free(pmb, phba->mbox_mem_pool);
  2313. return;
  2314. }
  2315. static void
  2316. lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2317. {
  2318. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2319. struct fc_rport *rport;
  2320. struct lpfc_rport_data *rdata;
  2321. struct fc_rport_identifiers rport_ids;
  2322. struct lpfc_hba *phba = vport->phba;
  2323. /* Remote port has reappeared. Re-register w/ FC transport */
  2324. rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  2325. rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  2326. rport_ids.port_id = ndlp->nlp_DID;
  2327. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2328. /*
  2329. * We leave our node pointer in rport->dd_data when we unregister a
  2330. * FCP target port. But fc_remote_port_add zeros the space to which
  2331. * rport->dd_data points. So, if we're reusing a previously
  2332. * registered port, drop the reference that we took the last time we
  2333. * registered the port.
  2334. */
  2335. if (ndlp->rport && ndlp->rport->dd_data &&
  2336. ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
  2337. lpfc_nlp_put(ndlp);
  2338. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  2339. "rport add: did:x%x flg:x%x type x%x",
  2340. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  2341. ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
  2342. if (!rport || !get_device(&rport->dev)) {
  2343. dev_printk(KERN_WARNING, &phba->pcidev->dev,
  2344. "Warning: fc_remote_port_add failed\n");
  2345. return;
  2346. }
  2347. /* initialize static port data */
  2348. rport->maxframe_size = ndlp->nlp_maxframe;
  2349. rport->supported_classes = ndlp->nlp_class_sup;
  2350. rdata = rport->dd_data;
  2351. rdata->pnode = lpfc_nlp_get(ndlp);
  2352. if (ndlp->nlp_type & NLP_FCP_TARGET)
  2353. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  2354. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  2355. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  2356. if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
  2357. fc_remote_port_rolechg(rport, rport_ids.roles);
  2358. if ((rport->scsi_target_id != -1) &&
  2359. (rport->scsi_target_id < LPFC_MAX_TARGET)) {
  2360. ndlp->nlp_sid = rport->scsi_target_id;
  2361. }
  2362. return;
  2363. }
  2364. static void
  2365. lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
  2366. {
  2367. struct fc_rport *rport = ndlp->rport;
  2368. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  2369. "rport delete: did:x%x flg:x%x type x%x",
  2370. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  2371. fc_remote_port_delete(rport);
  2372. return;
  2373. }
  2374. static void
  2375. lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
  2376. {
  2377. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2378. spin_lock_irq(shost->host_lock);
  2379. switch (state) {
  2380. case NLP_STE_UNUSED_NODE:
  2381. vport->fc_unused_cnt += count;
  2382. break;
  2383. case NLP_STE_PLOGI_ISSUE:
  2384. vport->fc_plogi_cnt += count;
  2385. break;
  2386. case NLP_STE_ADISC_ISSUE:
  2387. vport->fc_adisc_cnt += count;
  2388. break;
  2389. case NLP_STE_REG_LOGIN_ISSUE:
  2390. vport->fc_reglogin_cnt += count;
  2391. break;
  2392. case NLP_STE_PRLI_ISSUE:
  2393. vport->fc_prli_cnt += count;
  2394. break;
  2395. case NLP_STE_UNMAPPED_NODE:
  2396. vport->fc_unmap_cnt += count;
  2397. break;
  2398. case NLP_STE_MAPPED_NODE:
  2399. vport->fc_map_cnt += count;
  2400. break;
  2401. case NLP_STE_NPR_NODE:
  2402. vport->fc_npr_cnt += count;
  2403. break;
  2404. }
  2405. spin_unlock_irq(shost->host_lock);
  2406. }
  2407. static void
  2408. lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2409. int old_state, int new_state)
  2410. {
  2411. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2412. if (new_state == NLP_STE_UNMAPPED_NODE) {
  2413. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  2414. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  2415. ndlp->nlp_type |= NLP_FC_NODE;
  2416. }
  2417. if (new_state == NLP_STE_MAPPED_NODE)
  2418. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  2419. if (new_state == NLP_STE_NPR_NODE)
  2420. ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
  2421. /* Transport interface */
  2422. if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
  2423. old_state == NLP_STE_UNMAPPED_NODE)) {
  2424. vport->phba->nport_event_cnt++;
  2425. lpfc_unregister_remote_port(ndlp);
  2426. }
  2427. if (new_state == NLP_STE_MAPPED_NODE ||
  2428. new_state == NLP_STE_UNMAPPED_NODE) {
  2429. vport->phba->nport_event_cnt++;
  2430. /*
  2431. * Tell the fc transport about the port, if we haven't
  2432. * already. If we have, and it's a scsi entity, be
  2433. * sure to unblock any attached scsi devices
  2434. */
  2435. lpfc_register_remote_port(vport, ndlp);
  2436. }
  2437. if ((new_state == NLP_STE_MAPPED_NODE) &&
  2438. (vport->stat_data_enabled)) {
  2439. /*
  2440. * A new target is discovered, if there is no buffer for
  2441. * statistical data collection allocate buffer.
  2442. */
  2443. ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
  2444. sizeof(struct lpfc_scsicmd_bkt),
  2445. GFP_KERNEL);
  2446. if (!ndlp->lat_data)
  2447. lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
  2448. "0286 lpfc_nlp_state_cleanup failed to "
  2449. "allocate statistical data buffer DID "
  2450. "0x%x\n", ndlp->nlp_DID);
  2451. }
  2452. /*
  2453. * if we added to Mapped list, but the remote port
  2454. * registration failed or assigned a target id outside
  2455. * our presentable range - move the node to the
  2456. * Unmapped List
  2457. */
  2458. if (new_state == NLP_STE_MAPPED_NODE &&
  2459. (!ndlp->rport ||
  2460. ndlp->rport->scsi_target_id == -1 ||
  2461. ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
  2462. spin_lock_irq(shost->host_lock);
  2463. ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
  2464. spin_unlock_irq(shost->host_lock);
  2465. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2466. }
  2467. }
  2468. static char *
  2469. lpfc_nlp_state_name(char *buffer, size_t size, int state)
  2470. {
  2471. static char *states[] = {
  2472. [NLP_STE_UNUSED_NODE] = "UNUSED",
  2473. [NLP_STE_PLOGI_ISSUE] = "PLOGI",
  2474. [NLP_STE_ADISC_ISSUE] = "ADISC",
  2475. [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
  2476. [NLP_STE_PRLI_ISSUE] = "PRLI",
  2477. [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
  2478. [NLP_STE_MAPPED_NODE] = "MAPPED",
  2479. [NLP_STE_NPR_NODE] = "NPR",
  2480. };
  2481. if (state < NLP_STE_MAX_STATE && states[state])
  2482. strlcpy(buffer, states[state], size);
  2483. else
  2484. snprintf(buffer, size, "unknown (%d)", state);
  2485. return buffer;
  2486. }
  2487. void
  2488. lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2489. int state)
  2490. {
  2491. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2492. int old_state = ndlp->nlp_state;
  2493. char name1[16], name2[16];
  2494. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2495. "0904 NPort state transition x%06x, %s -> %s\n",
  2496. ndlp->nlp_DID,
  2497. lpfc_nlp_state_name(name1, sizeof(name1), old_state),
  2498. lpfc_nlp_state_name(name2, sizeof(name2), state));
  2499. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  2500. "node statechg did:x%x old:%d ste:%d",
  2501. ndlp->nlp_DID, old_state, state);
  2502. if (old_state == NLP_STE_NPR_NODE &&
  2503. state != NLP_STE_NPR_NODE)
  2504. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2505. if (old_state == NLP_STE_UNMAPPED_NODE) {
  2506. ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
  2507. ndlp->nlp_type &= ~NLP_FC_NODE;
  2508. }
  2509. if (list_empty(&ndlp->nlp_listp)) {
  2510. spin_lock_irq(shost->host_lock);
  2511. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  2512. spin_unlock_irq(shost->host_lock);
  2513. } else if (old_state)
  2514. lpfc_nlp_counters(vport, old_state, -1);
  2515. ndlp->nlp_state = state;
  2516. lpfc_nlp_counters(vport, state, 1);
  2517. lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
  2518. }
  2519. void
  2520. lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2521. {
  2522. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2523. if (list_empty(&ndlp->nlp_listp)) {
  2524. spin_lock_irq(shost->host_lock);
  2525. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  2526. spin_unlock_irq(shost->host_lock);
  2527. }
  2528. }
  2529. void
  2530. lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2531. {
  2532. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2533. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2534. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  2535. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  2536. spin_lock_irq(shost->host_lock);
  2537. list_del_init(&ndlp->nlp_listp);
  2538. spin_unlock_irq(shost->host_lock);
  2539. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  2540. NLP_STE_UNUSED_NODE);
  2541. }
  2542. static void
  2543. lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2544. {
  2545. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2546. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  2547. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  2548. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  2549. NLP_STE_UNUSED_NODE);
  2550. }
  2551. /**
  2552. * lpfc_initialize_node - Initialize all fields of node object
  2553. * @vport: Pointer to Virtual Port object.
  2554. * @ndlp: Pointer to FC node object.
  2555. * @did: FC_ID of the node.
  2556. *
  2557. * This function is always called when node object need to be initialized.
  2558. * It initializes all the fields of the node object. Although the reference
  2559. * to phba from @ndlp can be obtained indirectly through it's reference to
  2560. * @vport, a direct reference to phba is taken here by @ndlp. This is due
  2561. * to the life-span of the @ndlp might go beyond the existence of @vport as
  2562. * the final release of ndlp is determined by its reference count. And, the
  2563. * operation on @ndlp needs the reference to phba.
  2564. **/
  2565. static inline void
  2566. lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2567. uint32_t did)
  2568. {
  2569. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  2570. INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
  2571. init_timer(&ndlp->nlp_delayfunc);
  2572. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  2573. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  2574. ndlp->nlp_DID = did;
  2575. ndlp->vport = vport;
  2576. ndlp->phba = vport->phba;
  2577. ndlp->nlp_sid = NLP_NO_SID;
  2578. kref_init(&ndlp->kref);
  2579. NLP_INT_NODE_ACT(ndlp);
  2580. atomic_set(&ndlp->cmd_pending, 0);
  2581. ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
  2582. }
  2583. struct lpfc_nodelist *
  2584. lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2585. int state)
  2586. {
  2587. struct lpfc_hba *phba = vport->phba;
  2588. uint32_t did;
  2589. unsigned long flags;
  2590. if (!ndlp)
  2591. return NULL;
  2592. spin_lock_irqsave(&phba->ndlp_lock, flags);
  2593. /* The ndlp should not be in memory free mode */
  2594. if (NLP_CHK_FREE_REQ(ndlp)) {
  2595. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2596. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2597. "0277 lpfc_enable_node: ndlp:x%p "
  2598. "usgmap:x%x refcnt:%d\n",
  2599. (void *)ndlp, ndlp->nlp_usg_map,
  2600. atomic_read(&ndlp->kref.refcount));
  2601. return NULL;
  2602. }
  2603. /* The ndlp should not already be in active mode */
  2604. if (NLP_CHK_NODE_ACT(ndlp)) {
  2605. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2606. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2607. "0278 lpfc_enable_node: ndlp:x%p "
  2608. "usgmap:x%x refcnt:%d\n",
  2609. (void *)ndlp, ndlp->nlp_usg_map,
  2610. atomic_read(&ndlp->kref.refcount));
  2611. return NULL;
  2612. }
  2613. /* Keep the original DID */
  2614. did = ndlp->nlp_DID;
  2615. /* re-initialize ndlp except of ndlp linked list pointer */
  2616. memset((((char *)ndlp) + sizeof (struct list_head)), 0,
  2617. sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
  2618. lpfc_initialize_node(vport, ndlp, did);
  2619. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2620. if (state != NLP_STE_UNUSED_NODE)
  2621. lpfc_nlp_set_state(vport, ndlp, state);
  2622. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  2623. "node enable: did:x%x",
  2624. ndlp->nlp_DID, 0, 0);
  2625. return ndlp;
  2626. }
  2627. void
  2628. lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2629. {
  2630. /*
  2631. * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
  2632. * be used if we wish to issue the "last" lpfc_nlp_put() to remove
  2633. * the ndlp from the vport. The ndlp marked as UNUSED on the list
  2634. * until ALL other outstanding threads have completed. We check
  2635. * that the ndlp not already in the UNUSED state before we proceed.
  2636. */
  2637. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  2638. return;
  2639. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
  2640. lpfc_nlp_put(ndlp);
  2641. return;
  2642. }
  2643. /*
  2644. * Start / ReStart rescue timer for Discovery / RSCN handling
  2645. */
  2646. void
  2647. lpfc_set_disctmo(struct lpfc_vport *vport)
  2648. {
  2649. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2650. struct lpfc_hba *phba = vport->phba;
  2651. uint32_t tmo;
  2652. if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
  2653. /* For FAN, timeout should be greater than edtov */
  2654. tmo = (((phba->fc_edtov + 999) / 1000) + 1);
  2655. } else {
  2656. /* Normal discovery timeout should be > than ELS/CT timeout
  2657. * FC spec states we need 3 * ratov for CT requests
  2658. */
  2659. tmo = ((phba->fc_ratov * 3) + 3);
  2660. }
  2661. if (!timer_pending(&vport->fc_disctmo)) {
  2662. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2663. "set disc timer: tmo:x%x state:x%x flg:x%x",
  2664. tmo, vport->port_state, vport->fc_flag);
  2665. }
  2666. mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
  2667. spin_lock_irq(shost->host_lock);
  2668. vport->fc_flag |= FC_DISC_TMO;
  2669. spin_unlock_irq(shost->host_lock);
  2670. /* Start Discovery Timer state <hba_state> */
  2671. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2672. "0247 Start Discovery Timer state x%x "
  2673. "Data: x%x x%lx x%x x%x\n",
  2674. vport->port_state, tmo,
  2675. (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
  2676. vport->fc_adisc_cnt);
  2677. return;
  2678. }
  2679. /*
  2680. * Cancel rescue timer for Discovery / RSCN handling
  2681. */
  2682. int
  2683. lpfc_can_disctmo(struct lpfc_vport *vport)
  2684. {
  2685. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2686. unsigned long iflags;
  2687. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2688. "can disc timer: state:x%x rtry:x%x flg:x%x",
  2689. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  2690. /* Turn off discovery timer if its running */
  2691. if (vport->fc_flag & FC_DISC_TMO) {
  2692. spin_lock_irqsave(shost->host_lock, iflags);
  2693. vport->fc_flag &= ~FC_DISC_TMO;
  2694. spin_unlock_irqrestore(shost->host_lock, iflags);
  2695. del_timer_sync(&vport->fc_disctmo);
  2696. spin_lock_irqsave(&vport->work_port_lock, iflags);
  2697. vport->work_port_events &= ~WORKER_DISC_TMO;
  2698. spin_unlock_irqrestore(&vport->work_port_lock, iflags);
  2699. }
  2700. /* Cancel Discovery Timer state <hba_state> */
  2701. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2702. "0248 Cancel Discovery Timer state x%x "
  2703. "Data: x%x x%x x%x\n",
  2704. vport->port_state, vport->fc_flag,
  2705. vport->fc_plogi_cnt, vport->fc_adisc_cnt);
  2706. return 0;
  2707. }
  2708. /*
  2709. * Check specified ring for outstanding IOCB on the SLI queue
  2710. * Return true if iocb matches the specified nport
  2711. */
  2712. int
  2713. lpfc_check_sli_ndlp(struct lpfc_hba *phba,
  2714. struct lpfc_sli_ring *pring,
  2715. struct lpfc_iocbq *iocb,
  2716. struct lpfc_nodelist *ndlp)
  2717. {
  2718. struct lpfc_sli *psli = &phba->sli;
  2719. IOCB_t *icmd = &iocb->iocb;
  2720. struct lpfc_vport *vport = ndlp->vport;
  2721. if (iocb->vport != vport)
  2722. return 0;
  2723. if (pring->ringno == LPFC_ELS_RING) {
  2724. switch (icmd->ulpCommand) {
  2725. case CMD_GEN_REQUEST64_CR:
  2726. if (iocb->context_un.ndlp == ndlp)
  2727. return 1;
  2728. case CMD_ELS_REQUEST64_CR:
  2729. if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
  2730. return 1;
  2731. case CMD_XMIT_ELS_RSP64_CX:
  2732. if (iocb->context1 == (uint8_t *) ndlp)
  2733. return 1;
  2734. }
  2735. } else if (pring->ringno == psli->extra_ring) {
  2736. } else if (pring->ringno == psli->fcp_ring) {
  2737. /* Skip match check if waiting to relogin to FCP target */
  2738. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  2739. (ndlp->nlp_flag & NLP_DELAY_TMO)) {
  2740. return 0;
  2741. }
  2742. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
  2743. return 1;
  2744. }
  2745. } else if (pring->ringno == psli->next_ring) {
  2746. }
  2747. return 0;
  2748. }
  2749. /*
  2750. * Free resources / clean up outstanding I/Os
  2751. * associated with nlp_rpi in the LPFC_NODELIST entry.
  2752. */
  2753. static int
  2754. lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  2755. {
  2756. LIST_HEAD(completions);
  2757. struct lpfc_sli *psli;
  2758. struct lpfc_sli_ring *pring;
  2759. struct lpfc_iocbq *iocb, *next_iocb;
  2760. uint32_t rpi, i;
  2761. lpfc_fabric_abort_nport(ndlp);
  2762. /*
  2763. * Everything that matches on txcmplq will be returned
  2764. * by firmware with a no rpi error.
  2765. */
  2766. psli = &phba->sli;
  2767. rpi = ndlp->nlp_rpi;
  2768. if (ndlp->nlp_flag & NLP_RPI_VALID) {
  2769. /* Now process each ring */
  2770. for (i = 0; i < psli->num_rings; i++) {
  2771. pring = &psli->ring[i];
  2772. spin_lock_irq(&phba->hbalock);
  2773. list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
  2774. list) {
  2775. /*
  2776. * Check to see if iocb matches the nport we are
  2777. * looking for
  2778. */
  2779. if ((lpfc_check_sli_ndlp(phba, pring, iocb,
  2780. ndlp))) {
  2781. /* It matches, so deque and call compl
  2782. with an error */
  2783. list_move_tail(&iocb->list,
  2784. &completions);
  2785. pring->txq_cnt--;
  2786. }
  2787. }
  2788. spin_unlock_irq(&phba->hbalock);
  2789. }
  2790. }
  2791. /* Cancel all the IOCBs from the completions list */
  2792. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2793. IOERR_SLI_ABORTED);
  2794. return 0;
  2795. }
  2796. /*
  2797. * Free rpi associated with LPFC_NODELIST entry.
  2798. * This routine is called from lpfc_freenode(), when we are removing
  2799. * a LPFC_NODELIST entry. It is also called if the driver initiates a
  2800. * LOGO that completes successfully, and we are waiting to PLOGI back
  2801. * to the remote NPort. In addition, it is called after we receive
  2802. * and unsolicated ELS cmd, send back a rsp, the rsp completes and
  2803. * we are waiting to PLOGI back to the remote NPort.
  2804. */
  2805. int
  2806. lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2807. {
  2808. struct lpfc_hba *phba = vport->phba;
  2809. LPFC_MBOXQ_t *mbox;
  2810. int rc;
  2811. if (ndlp->nlp_flag & NLP_RPI_VALID) {
  2812. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2813. if (mbox) {
  2814. lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
  2815. mbox->vport = vport;
  2816. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2817. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2818. if (rc == MBX_NOT_FINISHED)
  2819. mempool_free(mbox, phba->mbox_mem_pool);
  2820. }
  2821. lpfc_no_rpi(phba, ndlp);
  2822. ndlp->nlp_rpi = 0;
  2823. ndlp->nlp_flag &= ~NLP_RPI_VALID;
  2824. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2825. return 1;
  2826. }
  2827. return 0;
  2828. }
  2829. void
  2830. lpfc_unreg_all_rpis(struct lpfc_vport *vport)
  2831. {
  2832. struct lpfc_hba *phba = vport->phba;
  2833. LPFC_MBOXQ_t *mbox;
  2834. int rc;
  2835. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2836. if (mbox) {
  2837. lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
  2838. mbox->vport = vport;
  2839. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2840. mbox->context1 = NULL;
  2841. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  2842. if (rc != MBX_TIMEOUT)
  2843. mempool_free(mbox, phba->mbox_mem_pool);
  2844. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  2845. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  2846. "1836 Could not issue "
  2847. "unreg_login(all_rpis) status %d\n", rc);
  2848. }
  2849. }
  2850. void
  2851. lpfc_unreg_default_rpis(struct lpfc_vport *vport)
  2852. {
  2853. struct lpfc_hba *phba = vport->phba;
  2854. LPFC_MBOXQ_t *mbox;
  2855. int rc;
  2856. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2857. if (mbox) {
  2858. lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
  2859. mbox->vport = vport;
  2860. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2861. mbox->context1 = NULL;
  2862. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  2863. if (rc != MBX_TIMEOUT)
  2864. mempool_free(mbox, phba->mbox_mem_pool);
  2865. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  2866. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  2867. "1815 Could not issue "
  2868. "unreg_did (default rpis) status %d\n",
  2869. rc);
  2870. }
  2871. }
  2872. /*
  2873. * Free resources associated with LPFC_NODELIST entry
  2874. * so it can be freed.
  2875. */
  2876. static int
  2877. lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2878. {
  2879. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2880. struct lpfc_hba *phba = vport->phba;
  2881. LPFC_MBOXQ_t *mb, *nextmb;
  2882. struct lpfc_dmabuf *mp;
  2883. /* Cleanup node for NPort <nlp_DID> */
  2884. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2885. "0900 Cleanup node for NPort x%x "
  2886. "Data: x%x x%x x%x\n",
  2887. ndlp->nlp_DID, ndlp->nlp_flag,
  2888. ndlp->nlp_state, ndlp->nlp_rpi);
  2889. if (NLP_CHK_FREE_REQ(ndlp)) {
  2890. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2891. "0280 lpfc_cleanup_node: ndlp:x%p "
  2892. "usgmap:x%x refcnt:%d\n",
  2893. (void *)ndlp, ndlp->nlp_usg_map,
  2894. atomic_read(&ndlp->kref.refcount));
  2895. lpfc_dequeue_node(vport, ndlp);
  2896. } else {
  2897. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2898. "0281 lpfc_cleanup_node: ndlp:x%p "
  2899. "usgmap:x%x refcnt:%d\n",
  2900. (void *)ndlp, ndlp->nlp_usg_map,
  2901. atomic_read(&ndlp->kref.refcount));
  2902. lpfc_disable_node(vport, ndlp);
  2903. }
  2904. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  2905. if ((mb = phba->sli.mbox_active)) {
  2906. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  2907. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  2908. mb->context2 = NULL;
  2909. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2910. }
  2911. }
  2912. spin_lock_irq(&phba->hbalock);
  2913. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  2914. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  2915. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  2916. mp = (struct lpfc_dmabuf *) (mb->context1);
  2917. if (mp) {
  2918. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2919. kfree(mp);
  2920. }
  2921. list_del(&mb->list);
  2922. mempool_free(mb, phba->mbox_mem_pool);
  2923. /* We shall not invoke the lpfc_nlp_put to decrement
  2924. * the ndlp reference count as we are in the process
  2925. * of lpfc_nlp_release.
  2926. */
  2927. }
  2928. }
  2929. spin_unlock_irq(&phba->hbalock);
  2930. lpfc_els_abort(phba, ndlp);
  2931. spin_lock_irq(shost->host_lock);
  2932. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  2933. spin_unlock_irq(shost->host_lock);
  2934. ndlp->nlp_last_elscmd = 0;
  2935. del_timer_sync(&ndlp->nlp_delayfunc);
  2936. list_del_init(&ndlp->els_retry_evt.evt_listp);
  2937. list_del_init(&ndlp->dev_loss_evt.evt_listp);
  2938. lpfc_unreg_rpi(vport, ndlp);
  2939. return 0;
  2940. }
  2941. /*
  2942. * Check to see if we can free the nlp back to the freelist.
  2943. * If we are in the middle of using the nlp in the discovery state
  2944. * machine, defer the free till we reach the end of the state machine.
  2945. */
  2946. static void
  2947. lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2948. {
  2949. struct lpfc_hba *phba = vport->phba;
  2950. struct lpfc_rport_data *rdata;
  2951. LPFC_MBOXQ_t *mbox;
  2952. int rc;
  2953. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2954. if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
  2955. !(ndlp->nlp_flag & NLP_RPI_VALID)) {
  2956. /* For this case we need to cleanup the default rpi
  2957. * allocated by the firmware.
  2958. */
  2959. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
  2960. != NULL) {
  2961. rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
  2962. (uint8_t *) &vport->fc_sparam, mbox, 0);
  2963. if (rc) {
  2964. mempool_free(mbox, phba->mbox_mem_pool);
  2965. }
  2966. else {
  2967. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  2968. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  2969. mbox->vport = vport;
  2970. mbox->context2 = NULL;
  2971. rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2972. if (rc == MBX_NOT_FINISHED) {
  2973. mempool_free(mbox, phba->mbox_mem_pool);
  2974. }
  2975. }
  2976. }
  2977. }
  2978. lpfc_cleanup_node(vport, ndlp);
  2979. /*
  2980. * We can get here with a non-NULL ndlp->rport because when we
  2981. * unregister a rport we don't break the rport/node linkage. So if we
  2982. * do, make sure we don't leaving any dangling pointers behind.
  2983. */
  2984. if (ndlp->rport) {
  2985. rdata = ndlp->rport->dd_data;
  2986. rdata->pnode = NULL;
  2987. ndlp->rport = NULL;
  2988. }
  2989. }
  2990. static int
  2991. lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2992. uint32_t did)
  2993. {
  2994. D_ID mydid, ndlpdid, matchdid;
  2995. if (did == Bcast_DID)
  2996. return 0;
  2997. /* First check for Direct match */
  2998. if (ndlp->nlp_DID == did)
  2999. return 1;
  3000. /* Next check for area/domain identically equals 0 match */
  3001. mydid.un.word = vport->fc_myDID;
  3002. if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
  3003. return 0;
  3004. }
  3005. matchdid.un.word = did;
  3006. ndlpdid.un.word = ndlp->nlp_DID;
  3007. if (matchdid.un.b.id == ndlpdid.un.b.id) {
  3008. if ((mydid.un.b.domain == matchdid.un.b.domain) &&
  3009. (mydid.un.b.area == matchdid.un.b.area)) {
  3010. if ((ndlpdid.un.b.domain == 0) &&
  3011. (ndlpdid.un.b.area == 0)) {
  3012. if (ndlpdid.un.b.id)
  3013. return 1;
  3014. }
  3015. return 0;
  3016. }
  3017. matchdid.un.word = ndlp->nlp_DID;
  3018. if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
  3019. (mydid.un.b.area == ndlpdid.un.b.area)) {
  3020. if ((matchdid.un.b.domain == 0) &&
  3021. (matchdid.un.b.area == 0)) {
  3022. if (matchdid.un.b.id)
  3023. return 1;
  3024. }
  3025. }
  3026. }
  3027. return 0;
  3028. }
  3029. /* Search for a nodelist entry */
  3030. static struct lpfc_nodelist *
  3031. __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  3032. {
  3033. struct lpfc_nodelist *ndlp;
  3034. uint32_t data1;
  3035. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  3036. if (lpfc_matchdid(vport, ndlp, did)) {
  3037. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  3038. ((uint32_t) ndlp->nlp_xri << 16) |
  3039. ((uint32_t) ndlp->nlp_type << 8) |
  3040. ((uint32_t) ndlp->nlp_rpi & 0xff));
  3041. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3042. "0929 FIND node DID "
  3043. "Data: x%p x%x x%x x%x\n",
  3044. ndlp, ndlp->nlp_DID,
  3045. ndlp->nlp_flag, data1);
  3046. return ndlp;
  3047. }
  3048. }
  3049. /* FIND node did <did> NOT FOUND */
  3050. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3051. "0932 FIND node did x%x NOT FOUND.\n", did);
  3052. return NULL;
  3053. }
  3054. struct lpfc_nodelist *
  3055. lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  3056. {
  3057. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3058. struct lpfc_nodelist *ndlp;
  3059. spin_lock_irq(shost->host_lock);
  3060. ndlp = __lpfc_findnode_did(vport, did);
  3061. spin_unlock_irq(shost->host_lock);
  3062. return ndlp;
  3063. }
  3064. struct lpfc_nodelist *
  3065. lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
  3066. {
  3067. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3068. struct lpfc_nodelist *ndlp;
  3069. ndlp = lpfc_findnode_did(vport, did);
  3070. if (!ndlp) {
  3071. if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
  3072. lpfc_rscn_payload_check(vport, did) == 0)
  3073. return NULL;
  3074. ndlp = (struct lpfc_nodelist *)
  3075. mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
  3076. if (!ndlp)
  3077. return NULL;
  3078. lpfc_nlp_init(vport, ndlp, did);
  3079. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3080. spin_lock_irq(shost->host_lock);
  3081. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3082. spin_unlock_irq(shost->host_lock);
  3083. return ndlp;
  3084. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3085. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
  3086. if (!ndlp)
  3087. return NULL;
  3088. spin_lock_irq(shost->host_lock);
  3089. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3090. spin_unlock_irq(shost->host_lock);
  3091. return ndlp;
  3092. }
  3093. if ((vport->fc_flag & FC_RSCN_MODE) &&
  3094. !(vport->fc_flag & FC_NDISC_ACTIVE)) {
  3095. if (lpfc_rscn_payload_check(vport, did)) {
  3096. /* If we've already recieved a PLOGI from this NPort
  3097. * we don't need to try to discover it again.
  3098. */
  3099. if (ndlp->nlp_flag & NLP_RCV_PLOGI)
  3100. return NULL;
  3101. /* Since this node is marked for discovery,
  3102. * delay timeout is not needed.
  3103. */
  3104. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3105. spin_lock_irq(shost->host_lock);
  3106. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3107. spin_unlock_irq(shost->host_lock);
  3108. } else
  3109. ndlp = NULL;
  3110. } else {
  3111. /* If we've already recieved a PLOGI from this NPort,
  3112. * or we are already in the process of discovery on it,
  3113. * we don't need to try to discover it again.
  3114. */
  3115. if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
  3116. ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  3117. ndlp->nlp_flag & NLP_RCV_PLOGI)
  3118. return NULL;
  3119. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3120. spin_lock_irq(shost->host_lock);
  3121. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3122. spin_unlock_irq(shost->host_lock);
  3123. }
  3124. return ndlp;
  3125. }
  3126. /* Build a list of nodes to discover based on the loopmap */
  3127. void
  3128. lpfc_disc_list_loopmap(struct lpfc_vport *vport)
  3129. {
  3130. struct lpfc_hba *phba = vport->phba;
  3131. int j;
  3132. uint32_t alpa, index;
  3133. if (!lpfc_is_link_up(phba))
  3134. return;
  3135. if (phba->fc_topology != TOPOLOGY_LOOP)
  3136. return;
  3137. /* Check for loop map present or not */
  3138. if (phba->alpa_map[0]) {
  3139. for (j = 1; j <= phba->alpa_map[0]; j++) {
  3140. alpa = phba->alpa_map[j];
  3141. if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
  3142. continue;
  3143. lpfc_setup_disc_node(vport, alpa);
  3144. }
  3145. } else {
  3146. /* No alpamap, so try all alpa's */
  3147. for (j = 0; j < FC_MAXLOOP; j++) {
  3148. /* If cfg_scan_down is set, start from highest
  3149. * ALPA (0xef) to lowest (0x1).
  3150. */
  3151. if (vport->cfg_scan_down)
  3152. index = j;
  3153. else
  3154. index = FC_MAXLOOP - j - 1;
  3155. alpa = lpfcAlpaArray[index];
  3156. if ((vport->fc_myDID & 0xff) == alpa)
  3157. continue;
  3158. lpfc_setup_disc_node(vport, alpa);
  3159. }
  3160. }
  3161. return;
  3162. }
  3163. void
  3164. lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
  3165. {
  3166. LPFC_MBOXQ_t *mbox;
  3167. struct lpfc_sli *psli = &phba->sli;
  3168. struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
  3169. struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
  3170. struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
  3171. int rc;
  3172. /*
  3173. * if it's not a physical port or if we already send
  3174. * clear_la then don't send it.
  3175. */
  3176. if ((phba->link_state >= LPFC_CLEAR_LA) ||
  3177. (vport->port_type != LPFC_PHYSICAL_PORT) ||
  3178. (phba->sli_rev == LPFC_SLI_REV4))
  3179. return;
  3180. /* Link up discovery */
  3181. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
  3182. phba->link_state = LPFC_CLEAR_LA;
  3183. lpfc_clear_la(phba, mbox);
  3184. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  3185. mbox->vport = vport;
  3186. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3187. if (rc == MBX_NOT_FINISHED) {
  3188. mempool_free(mbox, phba->mbox_mem_pool);
  3189. lpfc_disc_flush_list(vport);
  3190. extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  3191. fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  3192. next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  3193. phba->link_state = LPFC_HBA_ERROR;
  3194. }
  3195. }
  3196. }
  3197. /* Reg_vpi to tell firmware to resume normal operations */
  3198. void
  3199. lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  3200. {
  3201. LPFC_MBOXQ_t *regvpimbox;
  3202. regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3203. if (regvpimbox) {
  3204. lpfc_reg_vpi(vport, regvpimbox);
  3205. regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
  3206. regvpimbox->vport = vport;
  3207. if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
  3208. == MBX_NOT_FINISHED) {
  3209. mempool_free(regvpimbox, phba->mbox_mem_pool);
  3210. }
  3211. }
  3212. }
  3213. /* Start Link up / RSCN discovery on NPR nodes */
  3214. void
  3215. lpfc_disc_start(struct lpfc_vport *vport)
  3216. {
  3217. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3218. struct lpfc_hba *phba = vport->phba;
  3219. uint32_t num_sent;
  3220. uint32_t clear_la_pending;
  3221. int did_changed;
  3222. if (!lpfc_is_link_up(phba))
  3223. return;
  3224. if (phba->link_state == LPFC_CLEAR_LA)
  3225. clear_la_pending = 1;
  3226. else
  3227. clear_la_pending = 0;
  3228. if (vport->port_state < LPFC_VPORT_READY)
  3229. vport->port_state = LPFC_DISC_AUTH;
  3230. lpfc_set_disctmo(vport);
  3231. if (vport->fc_prevDID == vport->fc_myDID)
  3232. did_changed = 0;
  3233. else
  3234. did_changed = 1;
  3235. vport->fc_prevDID = vport->fc_myDID;
  3236. vport->num_disc_nodes = 0;
  3237. /* Start Discovery state <hba_state> */
  3238. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3239. "0202 Start Discovery hba state x%x "
  3240. "Data: x%x x%x x%x\n",
  3241. vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
  3242. vport->fc_adisc_cnt);
  3243. /* First do ADISCs - if any */
  3244. num_sent = lpfc_els_disc_adisc(vport);
  3245. if (num_sent)
  3246. return;
  3247. /*
  3248. * For SLI3, cmpl_reg_vpi will set port_state to READY, and
  3249. * continue discovery.
  3250. */
  3251. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3252. !(vport->fc_flag & FC_PT2PT) &&
  3253. !(vport->fc_flag & FC_RSCN_MODE) &&
  3254. (phba->sli_rev < LPFC_SLI_REV4)) {
  3255. lpfc_issue_reg_vpi(phba, vport);
  3256. return;
  3257. }
  3258. /*
  3259. * For SLI2, we need to set port_state to READY and continue
  3260. * discovery.
  3261. */
  3262. if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
  3263. /* If we get here, there is nothing to ADISC */
  3264. if (vport->port_type == LPFC_PHYSICAL_PORT)
  3265. lpfc_issue_clear_la(phba, vport);
  3266. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  3267. vport->num_disc_nodes = 0;
  3268. /* go thru NPR nodes and issue ELS PLOGIs */
  3269. if (vport->fc_npr_cnt)
  3270. lpfc_els_disc_plogi(vport);
  3271. if (!vport->num_disc_nodes) {
  3272. spin_lock_irq(shost->host_lock);
  3273. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  3274. spin_unlock_irq(shost->host_lock);
  3275. lpfc_can_disctmo(vport);
  3276. }
  3277. }
  3278. vport->port_state = LPFC_VPORT_READY;
  3279. } else {
  3280. /* Next do PLOGIs - if any */
  3281. num_sent = lpfc_els_disc_plogi(vport);
  3282. if (num_sent)
  3283. return;
  3284. if (vport->fc_flag & FC_RSCN_MODE) {
  3285. /* Check to see if more RSCNs came in while we
  3286. * were processing this one.
  3287. */
  3288. if ((vport->fc_rscn_id_cnt == 0) &&
  3289. (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
  3290. spin_lock_irq(shost->host_lock);
  3291. vport->fc_flag &= ~FC_RSCN_MODE;
  3292. spin_unlock_irq(shost->host_lock);
  3293. lpfc_can_disctmo(vport);
  3294. } else
  3295. lpfc_els_handle_rscn(vport);
  3296. }
  3297. }
  3298. return;
  3299. }
  3300. /*
  3301. * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
  3302. * ring the match the sppecified nodelist.
  3303. */
  3304. static void
  3305. lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  3306. {
  3307. LIST_HEAD(completions);
  3308. struct lpfc_sli *psli;
  3309. IOCB_t *icmd;
  3310. struct lpfc_iocbq *iocb, *next_iocb;
  3311. struct lpfc_sli_ring *pring;
  3312. psli = &phba->sli;
  3313. pring = &psli->ring[LPFC_ELS_RING];
  3314. /* Error matching iocb on txq or txcmplq
  3315. * First check the txq.
  3316. */
  3317. spin_lock_irq(&phba->hbalock);
  3318. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  3319. if (iocb->context1 != ndlp) {
  3320. continue;
  3321. }
  3322. icmd = &iocb->iocb;
  3323. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  3324. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  3325. list_move_tail(&iocb->list, &completions);
  3326. pring->txq_cnt--;
  3327. }
  3328. }
  3329. /* Next check the txcmplq */
  3330. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  3331. if (iocb->context1 != ndlp) {
  3332. continue;
  3333. }
  3334. icmd = &iocb->iocb;
  3335. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
  3336. icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
  3337. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3338. }
  3339. }
  3340. spin_unlock_irq(&phba->hbalock);
  3341. /* Cancel all the IOCBs from the completions list */
  3342. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3343. IOERR_SLI_ABORTED);
  3344. }
  3345. static void
  3346. lpfc_disc_flush_list(struct lpfc_vport *vport)
  3347. {
  3348. struct lpfc_nodelist *ndlp, *next_ndlp;
  3349. struct lpfc_hba *phba = vport->phba;
  3350. if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
  3351. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  3352. nlp_listp) {
  3353. if (!NLP_CHK_NODE_ACT(ndlp))
  3354. continue;
  3355. if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  3356. ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
  3357. lpfc_free_tx(phba, ndlp);
  3358. }
  3359. }
  3360. }
  3361. }
  3362. void
  3363. lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
  3364. {
  3365. lpfc_els_flush_rscn(vport);
  3366. lpfc_els_flush_cmd(vport);
  3367. lpfc_disc_flush_list(vport);
  3368. }
  3369. /*****************************************************************************/
  3370. /*
  3371. * NAME: lpfc_disc_timeout
  3372. *
  3373. * FUNCTION: Fibre Channel driver discovery timeout routine.
  3374. *
  3375. * EXECUTION ENVIRONMENT: interrupt only
  3376. *
  3377. * CALLED FROM:
  3378. * Timer function
  3379. *
  3380. * RETURNS:
  3381. * none
  3382. */
  3383. /*****************************************************************************/
  3384. void
  3385. lpfc_disc_timeout(unsigned long ptr)
  3386. {
  3387. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  3388. struct lpfc_hba *phba = vport->phba;
  3389. uint32_t tmo_posted;
  3390. unsigned long flags = 0;
  3391. if (unlikely(!phba))
  3392. return;
  3393. spin_lock_irqsave(&vport->work_port_lock, flags);
  3394. tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
  3395. if (!tmo_posted)
  3396. vport->work_port_events |= WORKER_DISC_TMO;
  3397. spin_unlock_irqrestore(&vport->work_port_lock, flags);
  3398. if (!tmo_posted)
  3399. lpfc_worker_wake_up(phba);
  3400. return;
  3401. }
  3402. static void
  3403. lpfc_disc_timeout_handler(struct lpfc_vport *vport)
  3404. {
  3405. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3406. struct lpfc_hba *phba = vport->phba;
  3407. struct lpfc_sli *psli = &phba->sli;
  3408. struct lpfc_nodelist *ndlp, *next_ndlp;
  3409. LPFC_MBOXQ_t *initlinkmbox;
  3410. int rc, clrlaerr = 0;
  3411. if (!(vport->fc_flag & FC_DISC_TMO))
  3412. return;
  3413. spin_lock_irq(shost->host_lock);
  3414. vport->fc_flag &= ~FC_DISC_TMO;
  3415. spin_unlock_irq(shost->host_lock);
  3416. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3417. "disc timeout: state:x%x rtry:x%x flg:x%x",
  3418. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  3419. switch (vport->port_state) {
  3420. case LPFC_LOCAL_CFG_LINK:
  3421. /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
  3422. * FAN
  3423. */
  3424. /* FAN timeout */
  3425. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  3426. "0221 FAN timeout\n");
  3427. /* Start discovery by sending FLOGI, clean up old rpis */
  3428. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  3429. nlp_listp) {
  3430. if (!NLP_CHK_NODE_ACT(ndlp))
  3431. continue;
  3432. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  3433. continue;
  3434. if (ndlp->nlp_type & NLP_FABRIC) {
  3435. /* Clean up the ndlp on Fabric connections */
  3436. lpfc_drop_node(vport, ndlp);
  3437. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  3438. /* Fail outstanding IO now since device
  3439. * is marked for PLOGI.
  3440. */
  3441. lpfc_unreg_rpi(vport, ndlp);
  3442. }
  3443. }
  3444. if (vport->port_state != LPFC_FLOGI) {
  3445. lpfc_initial_flogi(vport);
  3446. return;
  3447. }
  3448. break;
  3449. case LPFC_FDISC:
  3450. case LPFC_FLOGI:
  3451. /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
  3452. /* Initial FLOGI timeout */
  3453. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3454. "0222 Initial %s timeout\n",
  3455. vport->vpi ? "FDISC" : "FLOGI");
  3456. /* Assume no Fabric and go on with discovery.
  3457. * Check for outstanding ELS FLOGI to abort.
  3458. */
  3459. /* FLOGI failed, so just use loop map to make discovery list */
  3460. lpfc_disc_list_loopmap(vport);
  3461. /* Start discovery */
  3462. lpfc_disc_start(vport);
  3463. break;
  3464. case LPFC_FABRIC_CFG_LINK:
  3465. /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
  3466. NameServer login */
  3467. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3468. "0223 Timeout while waiting for "
  3469. "NameServer login\n");
  3470. /* Next look for NameServer ndlp */
  3471. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  3472. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  3473. lpfc_els_abort(phba, ndlp);
  3474. /* ReStart discovery */
  3475. goto restart_disc;
  3476. case LPFC_NS_QRY:
  3477. /* Check for wait for NameServer Rsp timeout */
  3478. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3479. "0224 NameServer Query timeout "
  3480. "Data: x%x x%x\n",
  3481. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  3482. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  3483. /* Try it one more time */
  3484. vport->fc_ns_retry++;
  3485. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  3486. vport->fc_ns_retry, 0);
  3487. if (rc == 0)
  3488. break;
  3489. }
  3490. vport->fc_ns_retry = 0;
  3491. restart_disc:
  3492. /*
  3493. * Discovery is over.
  3494. * set port_state to PORT_READY if SLI2.
  3495. * cmpl_reg_vpi will set port_state to READY for SLI3.
  3496. */
  3497. if (phba->sli_rev < LPFC_SLI_REV4) {
  3498. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  3499. lpfc_issue_reg_vpi(phba, vport);
  3500. else { /* NPIV Not enabled */
  3501. lpfc_issue_clear_la(phba, vport);
  3502. vport->port_state = LPFC_VPORT_READY;
  3503. }
  3504. }
  3505. /* Setup and issue mailbox INITIALIZE LINK command */
  3506. initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3507. if (!initlinkmbox) {
  3508. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3509. "0206 Device Discovery "
  3510. "completion error\n");
  3511. phba->link_state = LPFC_HBA_ERROR;
  3512. break;
  3513. }
  3514. lpfc_linkdown(phba);
  3515. lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
  3516. phba->cfg_link_speed);
  3517. initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  3518. initlinkmbox->vport = vport;
  3519. initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3520. rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
  3521. lpfc_set_loopback_flag(phba);
  3522. if (rc == MBX_NOT_FINISHED)
  3523. mempool_free(initlinkmbox, phba->mbox_mem_pool);
  3524. break;
  3525. case LPFC_DISC_AUTH:
  3526. /* Node Authentication timeout */
  3527. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3528. "0227 Node Authentication timeout\n");
  3529. lpfc_disc_flush_list(vport);
  3530. /*
  3531. * set port_state to PORT_READY if SLI2.
  3532. * cmpl_reg_vpi will set port_state to READY for SLI3.
  3533. */
  3534. if (phba->sli_rev < LPFC_SLI_REV4) {
  3535. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  3536. lpfc_issue_reg_vpi(phba, vport);
  3537. else { /* NPIV Not enabled */
  3538. lpfc_issue_clear_la(phba, vport);
  3539. vport->port_state = LPFC_VPORT_READY;
  3540. }
  3541. }
  3542. break;
  3543. case LPFC_VPORT_READY:
  3544. if (vport->fc_flag & FC_RSCN_MODE) {
  3545. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3546. "0231 RSCN timeout Data: x%x "
  3547. "x%x\n",
  3548. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  3549. /* Cleanup any outstanding ELS commands */
  3550. lpfc_els_flush_cmd(vport);
  3551. lpfc_els_flush_rscn(vport);
  3552. lpfc_disc_flush_list(vport);
  3553. }
  3554. break;
  3555. default:
  3556. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3557. "0273 Unexpected discovery timeout, "
  3558. "vport State x%x\n", vport->port_state);
  3559. break;
  3560. }
  3561. switch (phba->link_state) {
  3562. case LPFC_CLEAR_LA:
  3563. /* CLEAR LA timeout */
  3564. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3565. "0228 CLEAR LA timeout\n");
  3566. clrlaerr = 1;
  3567. break;
  3568. case LPFC_LINK_UP:
  3569. lpfc_issue_clear_la(phba, vport);
  3570. /* Drop thru */
  3571. case LPFC_LINK_UNKNOWN:
  3572. case LPFC_WARM_START:
  3573. case LPFC_INIT_START:
  3574. case LPFC_INIT_MBX_CMDS:
  3575. case LPFC_LINK_DOWN:
  3576. case LPFC_HBA_ERROR:
  3577. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3578. "0230 Unexpected timeout, hba link "
  3579. "state x%x\n", phba->link_state);
  3580. clrlaerr = 1;
  3581. break;
  3582. case LPFC_HBA_READY:
  3583. break;
  3584. }
  3585. if (clrlaerr) {
  3586. lpfc_disc_flush_list(vport);
  3587. psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  3588. psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  3589. psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  3590. vport->port_state = LPFC_VPORT_READY;
  3591. }
  3592. return;
  3593. }
  3594. /*
  3595. * This routine handles processing a NameServer REG_LOGIN mailbox
  3596. * command upon completion. It is setup in the LPFC_MBOXQ
  3597. * as the completion routine when the command is
  3598. * handed off to the SLI layer.
  3599. */
  3600. void
  3601. lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3602. {
  3603. MAILBOX_t *mb = &pmb->u.mb;
  3604. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  3605. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3606. struct lpfc_vport *vport = pmb->vport;
  3607. pmb->context1 = NULL;
  3608. ndlp->nlp_rpi = mb->un.varWords[0];
  3609. ndlp->nlp_flag |= NLP_RPI_VALID;
  3610. ndlp->nlp_type |= NLP_FABRIC;
  3611. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  3612. /*
  3613. * Start issuing Fabric-Device Management Interface (FDMI) command to
  3614. * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
  3615. * fdmi-on=2 (supporting RPA/hostnmae)
  3616. */
  3617. if (vport->cfg_fdmi_on == 1)
  3618. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  3619. else
  3620. mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
  3621. /* decrement the node reference count held for this callback
  3622. * function.
  3623. */
  3624. lpfc_nlp_put(ndlp);
  3625. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3626. kfree(mp);
  3627. mempool_free(pmb, phba->mbox_mem_pool);
  3628. return;
  3629. }
  3630. static int
  3631. lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
  3632. {
  3633. uint16_t *rpi = param;
  3634. return ndlp->nlp_rpi == *rpi;
  3635. }
  3636. static int
  3637. lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
  3638. {
  3639. return memcmp(&ndlp->nlp_portname, param,
  3640. sizeof(ndlp->nlp_portname)) == 0;
  3641. }
  3642. static struct lpfc_nodelist *
  3643. __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
  3644. {
  3645. struct lpfc_nodelist *ndlp;
  3646. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  3647. if (filter(ndlp, param))
  3648. return ndlp;
  3649. }
  3650. return NULL;
  3651. }
  3652. /*
  3653. * This routine looks up the ndlp lists for the given RPI. If rpi found it
  3654. * returns the node list element pointer else return NULL.
  3655. */
  3656. struct lpfc_nodelist *
  3657. __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
  3658. {
  3659. return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
  3660. }
  3661. /*
  3662. * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
  3663. * returns the node element list pointer else return NULL.
  3664. */
  3665. struct lpfc_nodelist *
  3666. lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
  3667. {
  3668. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3669. struct lpfc_nodelist *ndlp;
  3670. spin_lock_irq(shost->host_lock);
  3671. ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
  3672. spin_unlock_irq(shost->host_lock);
  3673. return ndlp;
  3674. }
  3675. void
  3676. lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3677. uint32_t did)
  3678. {
  3679. memset(ndlp, 0, sizeof (struct lpfc_nodelist));
  3680. lpfc_initialize_node(vport, ndlp, did);
  3681. INIT_LIST_HEAD(&ndlp->nlp_listp);
  3682. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  3683. "node init: did:x%x",
  3684. ndlp->nlp_DID, 0, 0);
  3685. return;
  3686. }
  3687. /* This routine releases all resources associated with a specifc NPort's ndlp
  3688. * and mempool_free's the nodelist.
  3689. */
  3690. static void
  3691. lpfc_nlp_release(struct kref *kref)
  3692. {
  3693. struct lpfc_hba *phba;
  3694. unsigned long flags;
  3695. struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
  3696. kref);
  3697. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3698. "node release: did:x%x flg:x%x type:x%x",
  3699. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  3700. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
  3701. "0279 lpfc_nlp_release: ndlp:x%p "
  3702. "usgmap:x%x refcnt:%d\n",
  3703. (void *)ndlp, ndlp->nlp_usg_map,
  3704. atomic_read(&ndlp->kref.refcount));
  3705. /* remove ndlp from action. */
  3706. lpfc_nlp_remove(ndlp->vport, ndlp);
  3707. /* clear the ndlp active flag for all release cases */
  3708. phba = ndlp->phba;
  3709. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3710. NLP_CLR_NODE_ACT(ndlp);
  3711. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3712. /* free ndlp memory for final ndlp release */
  3713. if (NLP_CHK_FREE_REQ(ndlp)) {
  3714. kfree(ndlp->lat_data);
  3715. mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
  3716. }
  3717. }
  3718. /* This routine bumps the reference count for a ndlp structure to ensure
  3719. * that one discovery thread won't free a ndlp while another discovery thread
  3720. * is using it.
  3721. */
  3722. struct lpfc_nodelist *
  3723. lpfc_nlp_get(struct lpfc_nodelist *ndlp)
  3724. {
  3725. struct lpfc_hba *phba;
  3726. unsigned long flags;
  3727. if (ndlp) {
  3728. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3729. "node get: did:x%x flg:x%x refcnt:x%x",
  3730. ndlp->nlp_DID, ndlp->nlp_flag,
  3731. atomic_read(&ndlp->kref.refcount));
  3732. /* The check of ndlp usage to prevent incrementing the
  3733. * ndlp reference count that is in the process of being
  3734. * released.
  3735. */
  3736. phba = ndlp->phba;
  3737. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3738. if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
  3739. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3740. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  3741. "0276 lpfc_nlp_get: ndlp:x%p "
  3742. "usgmap:x%x refcnt:%d\n",
  3743. (void *)ndlp, ndlp->nlp_usg_map,
  3744. atomic_read(&ndlp->kref.refcount));
  3745. return NULL;
  3746. } else
  3747. kref_get(&ndlp->kref);
  3748. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3749. }
  3750. return ndlp;
  3751. }
  3752. /* This routine decrements the reference count for a ndlp structure. If the
  3753. * count goes to 0, this indicates the the associated nodelist should be
  3754. * freed. Returning 1 indicates the ndlp resource has been released; on the
  3755. * other hand, returning 0 indicates the ndlp resource has not been released
  3756. * yet.
  3757. */
  3758. int
  3759. lpfc_nlp_put(struct lpfc_nodelist *ndlp)
  3760. {
  3761. struct lpfc_hba *phba;
  3762. unsigned long flags;
  3763. if (!ndlp)
  3764. return 1;
  3765. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3766. "node put: did:x%x flg:x%x refcnt:x%x",
  3767. ndlp->nlp_DID, ndlp->nlp_flag,
  3768. atomic_read(&ndlp->kref.refcount));
  3769. phba = ndlp->phba;
  3770. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3771. /* Check the ndlp memory free acknowledge flag to avoid the
  3772. * possible race condition that kref_put got invoked again
  3773. * after previous one has done ndlp memory free.
  3774. */
  3775. if (NLP_CHK_FREE_ACK(ndlp)) {
  3776. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3777. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  3778. "0274 lpfc_nlp_put: ndlp:x%p "
  3779. "usgmap:x%x refcnt:%d\n",
  3780. (void *)ndlp, ndlp->nlp_usg_map,
  3781. atomic_read(&ndlp->kref.refcount));
  3782. return 1;
  3783. }
  3784. /* Check the ndlp inactivate log flag to avoid the possible
  3785. * race condition that kref_put got invoked again after ndlp
  3786. * is already in inactivating state.
  3787. */
  3788. if (NLP_CHK_IACT_REQ(ndlp)) {
  3789. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3790. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  3791. "0275 lpfc_nlp_put: ndlp:x%p "
  3792. "usgmap:x%x refcnt:%d\n",
  3793. (void *)ndlp, ndlp->nlp_usg_map,
  3794. atomic_read(&ndlp->kref.refcount));
  3795. return 1;
  3796. }
  3797. /* For last put, mark the ndlp usage flags to make sure no
  3798. * other kref_get and kref_put on the same ndlp shall get
  3799. * in between the process when the final kref_put has been
  3800. * invoked on this ndlp.
  3801. */
  3802. if (atomic_read(&ndlp->kref.refcount) == 1) {
  3803. /* Indicate ndlp is put to inactive state. */
  3804. NLP_SET_IACT_REQ(ndlp);
  3805. /* Acknowledge ndlp memory free has been seen. */
  3806. if (NLP_CHK_FREE_REQ(ndlp))
  3807. NLP_SET_FREE_ACK(ndlp);
  3808. }
  3809. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3810. /* Note, the kref_put returns 1 when decrementing a reference
  3811. * count that was 1, it invokes the release callback function,
  3812. * but it still left the reference count as 1 (not actually
  3813. * performs the last decrementation). Otherwise, it actually
  3814. * decrements the reference count and returns 0.
  3815. */
  3816. return kref_put(&ndlp->kref, lpfc_nlp_release);
  3817. }
  3818. /* This routine free's the specified nodelist if it is not in use
  3819. * by any other discovery thread. This routine returns 1 if the
  3820. * ndlp has been freed. A return value of 0 indicates the ndlp is
  3821. * not yet been released.
  3822. */
  3823. int
  3824. lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
  3825. {
  3826. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3827. "node not used: did:x%x flg:x%x refcnt:x%x",
  3828. ndlp->nlp_DID, ndlp->nlp_flag,
  3829. atomic_read(&ndlp->kref.refcount));
  3830. if (atomic_read(&ndlp->kref.refcount) == 1)
  3831. if (lpfc_nlp_put(ndlp))
  3832. return 1;
  3833. return 0;
  3834. }
  3835. /**
  3836. * lpfc_fcf_inuse - Check if FCF can be unregistered.
  3837. * @phba: Pointer to hba context object.
  3838. *
  3839. * This function iterate through all FC nodes associated
  3840. * will all vports to check if there is any node with
  3841. * fc_rports associated with it. If there is an fc_rport
  3842. * associated with the node, then the node is either in
  3843. * discovered state or its devloss_timer is pending.
  3844. */
  3845. static int
  3846. lpfc_fcf_inuse(struct lpfc_hba *phba)
  3847. {
  3848. struct lpfc_vport **vports;
  3849. int i, ret = 0;
  3850. struct lpfc_nodelist *ndlp;
  3851. struct Scsi_Host *shost;
  3852. vports = lpfc_create_vport_work_array(phba);
  3853. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3854. shost = lpfc_shost_from_vport(vports[i]);
  3855. spin_lock_irq(shost->host_lock);
  3856. list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
  3857. if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
  3858. (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
  3859. ret = 1;
  3860. spin_unlock_irq(shost->host_lock);
  3861. goto out;
  3862. }
  3863. }
  3864. spin_unlock_irq(shost->host_lock);
  3865. }
  3866. out:
  3867. lpfc_destroy_vport_work_array(phba, vports);
  3868. return ret;
  3869. }
  3870. /**
  3871. * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
  3872. * @phba: Pointer to hba context object.
  3873. * @mboxq: Pointer to mailbox object.
  3874. *
  3875. * This function frees memory associated with the mailbox command.
  3876. */
  3877. static void
  3878. lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  3879. {
  3880. struct lpfc_vport *vport = mboxq->vport;
  3881. if (mboxq->u.mb.mbxStatus) {
  3882. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3883. "2555 UNREG_VFI mbxStatus error x%x "
  3884. "HBA state x%x\n",
  3885. mboxq->u.mb.mbxStatus, vport->port_state);
  3886. }
  3887. mempool_free(mboxq, phba->mbox_mem_pool);
  3888. return;
  3889. }
  3890. /**
  3891. * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
  3892. * @phba: Pointer to hba context object.
  3893. * @mboxq: Pointer to mailbox object.
  3894. *
  3895. * This function frees memory associated with the mailbox command.
  3896. */
  3897. static void
  3898. lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  3899. {
  3900. struct lpfc_vport *vport = mboxq->vport;
  3901. if (mboxq->u.mb.mbxStatus) {
  3902. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3903. "2550 UNREG_FCFI mbxStatus error x%x "
  3904. "HBA state x%x\n",
  3905. mboxq->u.mb.mbxStatus, vport->port_state);
  3906. }
  3907. mempool_free(mboxq, phba->mbox_mem_pool);
  3908. return;
  3909. }
  3910. /**
  3911. * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
  3912. * @phba: Pointer to hba context object.
  3913. *
  3914. * This function check if there are any connected remote port for the FCF and
  3915. * if all the devices are disconnected, this function unregister FCFI.
  3916. * This function also tries to use another FCF for discovery.
  3917. */
  3918. void
  3919. lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
  3920. {
  3921. LPFC_MBOXQ_t *mbox;
  3922. int rc;
  3923. struct lpfc_vport **vports;
  3924. int i;
  3925. spin_lock_irq(&phba->hbalock);
  3926. /*
  3927. * If HBA is not running in FIP mode or
  3928. * If HBA does not support FCoE or
  3929. * If FCF is not registered.
  3930. * do nothing.
  3931. */
  3932. if (!(phba->hba_flag & HBA_FCOE_SUPPORT) ||
  3933. !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
  3934. (phba->cfg_enable_fip == 0)) {
  3935. spin_unlock_irq(&phba->hbalock);
  3936. return;
  3937. }
  3938. spin_unlock_irq(&phba->hbalock);
  3939. if (lpfc_fcf_inuse(phba))
  3940. return;
  3941. /* Unregister VPIs */
  3942. vports = lpfc_create_vport_work_array(phba);
  3943. if (vports &&
  3944. (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
  3945. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3946. lpfc_mbx_unreg_vpi(vports[i]);
  3947. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  3948. vports[i]->vfi_state &= ~LPFC_VFI_REGISTERED;
  3949. }
  3950. lpfc_destroy_vport_work_array(phba, vports);
  3951. /* Unregister VFI */
  3952. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3953. if (!mbox) {
  3954. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3955. "2556 UNREG_VFI mbox allocation failed"
  3956. "HBA state x%x\n",
  3957. phba->pport->port_state);
  3958. return;
  3959. }
  3960. lpfc_unreg_vfi(mbox, phba->pport->vfi);
  3961. mbox->vport = phba->pport;
  3962. mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl;
  3963. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3964. if (rc == MBX_NOT_FINISHED) {
  3965. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3966. "2557 UNREG_VFI issue mbox failed rc x%x "
  3967. "HBA state x%x\n",
  3968. rc, phba->pport->port_state);
  3969. mempool_free(mbox, phba->mbox_mem_pool);
  3970. return;
  3971. }
  3972. /* Unregister FCF */
  3973. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3974. if (!mbox) {
  3975. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3976. "2551 UNREG_FCFI mbox allocation failed"
  3977. "HBA state x%x\n",
  3978. phba->pport->port_state);
  3979. return;
  3980. }
  3981. lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
  3982. mbox->vport = phba->pport;
  3983. mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
  3984. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3985. if (rc == MBX_NOT_FINISHED) {
  3986. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3987. "2552 UNREG_FCFI issue mbox failed rc x%x "
  3988. "HBA state x%x\n",
  3989. rc, phba->pport->port_state);
  3990. mempool_free(mbox, phba->mbox_mem_pool);
  3991. return;
  3992. }
  3993. spin_lock_irq(&phba->hbalock);
  3994. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_REGISTERED |
  3995. FCF_DISCOVERED | FCF_BOOT_ENABLE | FCF_IN_USE |
  3996. FCF_VALID_VLAN);
  3997. spin_unlock_irq(&phba->hbalock);
  3998. /*
  3999. * If driver is not unloading, check if there is any other
  4000. * FCF record that can be used for discovery.
  4001. */
  4002. if ((phba->pport->load_flag & FC_UNLOADING) ||
  4003. (phba->link_state < LPFC_LINK_UP))
  4004. return;
  4005. rc = lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
  4006. if (rc)
  4007. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4008. "2553 lpfc_unregister_unused_fcf failed to read FCF"
  4009. " record HBA state x%x\n",
  4010. phba->pport->port_state);
  4011. }
  4012. /**
  4013. * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
  4014. * @phba: Pointer to hba context object.
  4015. * @buff: Buffer containing the FCF connection table as in the config
  4016. * region.
  4017. * This function create driver data structure for the FCF connection
  4018. * record table read from config region 23.
  4019. */
  4020. static void
  4021. lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
  4022. uint8_t *buff)
  4023. {
  4024. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  4025. struct lpfc_fcf_conn_hdr *conn_hdr;
  4026. struct lpfc_fcf_conn_rec *conn_rec;
  4027. uint32_t record_count;
  4028. int i;
  4029. /* Free the current connect table */
  4030. list_for_each_entry_safe(conn_entry, next_conn_entry,
  4031. &phba->fcf_conn_rec_list, list)
  4032. kfree(conn_entry);
  4033. conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
  4034. record_count = conn_hdr->length * sizeof(uint32_t)/
  4035. sizeof(struct lpfc_fcf_conn_rec);
  4036. conn_rec = (struct lpfc_fcf_conn_rec *)
  4037. (buff + sizeof(struct lpfc_fcf_conn_hdr));
  4038. for (i = 0; i < record_count; i++) {
  4039. if (!(conn_rec[i].flags & FCFCNCT_VALID))
  4040. continue;
  4041. conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
  4042. GFP_KERNEL);
  4043. if (!conn_entry) {
  4044. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4045. "2566 Failed to allocate connection"
  4046. " table entry\n");
  4047. return;
  4048. }
  4049. memcpy(&conn_entry->conn_rec, &conn_rec[i],
  4050. sizeof(struct lpfc_fcf_conn_rec));
  4051. conn_entry->conn_rec.vlan_tag =
  4052. le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF;
  4053. conn_entry->conn_rec.flags =
  4054. le16_to_cpu(conn_entry->conn_rec.flags);
  4055. list_add_tail(&conn_entry->list,
  4056. &phba->fcf_conn_rec_list);
  4057. }
  4058. }
  4059. /**
  4060. * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
  4061. * @phba: Pointer to hba context object.
  4062. * @buff: Buffer containing the FCoE parameter data structure.
  4063. *
  4064. * This function update driver data structure with config
  4065. * parameters read from config region 23.
  4066. */
  4067. static void
  4068. lpfc_read_fcoe_param(struct lpfc_hba *phba,
  4069. uint8_t *buff)
  4070. {
  4071. struct lpfc_fip_param_hdr *fcoe_param_hdr;
  4072. struct lpfc_fcoe_params *fcoe_param;
  4073. fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
  4074. buff;
  4075. fcoe_param = (struct lpfc_fcoe_params *)
  4076. (buff + sizeof(struct lpfc_fip_param_hdr));
  4077. if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
  4078. (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
  4079. return;
  4080. if (bf_get(lpfc_fip_param_hdr_fipp_mode, fcoe_param_hdr) ==
  4081. FIPP_MODE_ON)
  4082. phba->cfg_enable_fip = 1;
  4083. if (bf_get(lpfc_fip_param_hdr_fipp_mode, fcoe_param_hdr) ==
  4084. FIPP_MODE_OFF)
  4085. phba->cfg_enable_fip = 0;
  4086. if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
  4087. phba->valid_vlan = 1;
  4088. phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
  4089. 0xFFF;
  4090. }
  4091. phba->fc_map[0] = fcoe_param->fc_map[0];
  4092. phba->fc_map[1] = fcoe_param->fc_map[1];
  4093. phba->fc_map[2] = fcoe_param->fc_map[2];
  4094. return;
  4095. }
  4096. /**
  4097. * lpfc_get_rec_conf23 - Get a record type in config region data.
  4098. * @buff: Buffer containing config region 23 data.
  4099. * @size: Size of the data buffer.
  4100. * @rec_type: Record type to be searched.
  4101. *
  4102. * This function searches config region data to find the begining
  4103. * of the record specified by record_type. If record found, this
  4104. * function return pointer to the record else return NULL.
  4105. */
  4106. static uint8_t *
  4107. lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
  4108. {
  4109. uint32_t offset = 0, rec_length;
  4110. if ((buff[0] == LPFC_REGION23_LAST_REC) ||
  4111. (size < sizeof(uint32_t)))
  4112. return NULL;
  4113. rec_length = buff[offset + 1];
  4114. /*
  4115. * One TLV record has one word header and number of data words
  4116. * specified in the rec_length field of the record header.
  4117. */
  4118. while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
  4119. <= size) {
  4120. if (buff[offset] == rec_type)
  4121. return &buff[offset];
  4122. if (buff[offset] == LPFC_REGION23_LAST_REC)
  4123. return NULL;
  4124. offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
  4125. rec_length = buff[offset + 1];
  4126. }
  4127. return NULL;
  4128. }
  4129. /**
  4130. * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
  4131. * @phba: Pointer to lpfc_hba data structure.
  4132. * @buff: Buffer containing config region 23 data.
  4133. * @size: Size of the data buffer.
  4134. *
  4135. * This fuction parse the FCoE config parameters in config region 23 and
  4136. * populate driver data structure with the parameters.
  4137. */
  4138. void
  4139. lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
  4140. uint8_t *buff,
  4141. uint32_t size)
  4142. {
  4143. uint32_t offset = 0, rec_length;
  4144. uint8_t *rec_ptr;
  4145. /*
  4146. * If data size is less than 2 words signature and version cannot be
  4147. * verified.
  4148. */
  4149. if (size < 2*sizeof(uint32_t))
  4150. return;
  4151. /* Check the region signature first */
  4152. if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
  4153. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4154. "2567 Config region 23 has bad signature\n");
  4155. return;
  4156. }
  4157. offset += 4;
  4158. /* Check the data structure version */
  4159. if (buff[offset] != LPFC_REGION23_VERSION) {
  4160. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4161. "2568 Config region 23 has bad version\n");
  4162. return;
  4163. }
  4164. offset += 4;
  4165. rec_length = buff[offset + 1];
  4166. /* Read FCoE param record */
  4167. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  4168. size - offset, FCOE_PARAM_TYPE);
  4169. if (rec_ptr)
  4170. lpfc_read_fcoe_param(phba, rec_ptr);
  4171. /* Read FCF connection table */
  4172. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  4173. size - offset, FCOE_CONN_TBL_TYPE);
  4174. if (rec_ptr)
  4175. lpfc_read_fcf_conn_tbl(phba, rec_ptr);
  4176. }