lpfc_hbadisc.c 131 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731
  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. }
  475. vports = lpfc_create_vport_work_array(phba);
  476. if (vports != NULL)
  477. for (i = 0; i <= phba->max_vports; i++) {
  478. /*
  479. * We could have no vports in array if unloading, so if
  480. * this happens then just use the pport
  481. */
  482. if (vports[i] == NULL && i == 0)
  483. vport = phba->pport;
  484. else
  485. vport = vports[i];
  486. if (vport == NULL)
  487. break;
  488. spin_lock_irq(&vport->work_port_lock);
  489. work_port_events = vport->work_port_events;
  490. vport->work_port_events &= ~work_port_events;
  491. spin_unlock_irq(&vport->work_port_lock);
  492. if (work_port_events & WORKER_DISC_TMO)
  493. lpfc_disc_timeout_handler(vport);
  494. if (work_port_events & WORKER_ELS_TMO)
  495. lpfc_els_timeout_handler(vport);
  496. if (work_port_events & WORKER_HB_TMO)
  497. lpfc_hb_timeout_handler(phba);
  498. if (work_port_events & WORKER_MBOX_TMO)
  499. lpfc_mbox_timeout_handler(phba);
  500. if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
  501. lpfc_unblock_fabric_iocbs(phba);
  502. if (work_port_events & WORKER_FDMI_TMO)
  503. lpfc_fdmi_timeout_handler(vport);
  504. if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
  505. lpfc_ramp_down_queue_handler(phba);
  506. if (work_port_events & WORKER_RAMP_UP_QUEUE)
  507. lpfc_ramp_up_queue_handler(phba);
  508. }
  509. lpfc_destroy_vport_work_array(phba, vports);
  510. pring = &phba->sli.ring[LPFC_ELS_RING];
  511. status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  512. status >>= (4*LPFC_ELS_RING);
  513. if ((status & HA_RXMASK) ||
  514. (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
  515. (phba->hba_flag & HBA_RECEIVE_BUFFER)) {
  516. if (pring->flag & LPFC_STOP_IOCB_EVENT) {
  517. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  518. /* Set the lpfc data pending flag */
  519. set_bit(LPFC_DATA_READY, &phba->data_flags);
  520. } else {
  521. pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
  522. lpfc_sli_handle_slow_ring_event(phba, pring,
  523. (status &
  524. HA_RXMASK));
  525. }
  526. /*
  527. * Turn on Ring interrupts
  528. */
  529. if (phba->sli_rev <= LPFC_SLI_REV3) {
  530. spin_lock_irq(&phba->hbalock);
  531. control = readl(phba->HCregaddr);
  532. if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
  533. lpfc_debugfs_slow_ring_trc(phba,
  534. "WRK Enable ring: cntl:x%x hacopy:x%x",
  535. control, ha_copy, 0);
  536. control |= (HC_R0INT_ENA << LPFC_ELS_RING);
  537. writel(control, phba->HCregaddr);
  538. readl(phba->HCregaddr); /* flush */
  539. } else {
  540. lpfc_debugfs_slow_ring_trc(phba,
  541. "WRK Ring ok: cntl:x%x hacopy:x%x",
  542. control, ha_copy, 0);
  543. }
  544. spin_unlock_irq(&phba->hbalock);
  545. }
  546. }
  547. lpfc_work_list_done(phba);
  548. }
  549. int
  550. lpfc_do_work(void *p)
  551. {
  552. struct lpfc_hba *phba = p;
  553. int rc;
  554. set_user_nice(current, -20);
  555. phba->data_flags = 0;
  556. while (!kthread_should_stop()) {
  557. /* wait and check worker queue activities */
  558. rc = wait_event_interruptible(phba->work_waitq,
  559. (test_and_clear_bit(LPFC_DATA_READY,
  560. &phba->data_flags)
  561. || kthread_should_stop()));
  562. /* Signal wakeup shall terminate the worker thread */
  563. if (rc) {
  564. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  565. "0433 Wakeup on signal: rc=x%x\n", rc);
  566. break;
  567. }
  568. /* Attend pending lpfc data processing */
  569. lpfc_work_done(phba);
  570. }
  571. phba->worker_thread = NULL;
  572. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  573. "0432 Worker thread stopped.\n");
  574. return 0;
  575. }
  576. /*
  577. * This is only called to handle FC worker events. Since this a rare
  578. * occurance, we allocate a struct lpfc_work_evt structure here instead of
  579. * embedding it in the IOCB.
  580. */
  581. int
  582. lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
  583. uint32_t evt)
  584. {
  585. struct lpfc_work_evt *evtp;
  586. unsigned long flags;
  587. /*
  588. * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
  589. * be queued to worker thread for processing
  590. */
  591. evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
  592. if (!evtp)
  593. return 0;
  594. evtp->evt_arg1 = arg1;
  595. evtp->evt_arg2 = arg2;
  596. evtp->evt = evt;
  597. spin_lock_irqsave(&phba->hbalock, flags);
  598. list_add_tail(&evtp->evt_listp, &phba->work_list);
  599. spin_unlock_irqrestore(&phba->hbalock, flags);
  600. lpfc_worker_wake_up(phba);
  601. return 1;
  602. }
  603. void
  604. lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
  605. {
  606. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  607. struct lpfc_hba *phba = vport->phba;
  608. struct lpfc_nodelist *ndlp, *next_ndlp;
  609. int rc;
  610. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  611. if (!NLP_CHK_NODE_ACT(ndlp))
  612. continue;
  613. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  614. continue;
  615. if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
  616. ((vport->port_type == LPFC_NPIV_PORT) &&
  617. (ndlp->nlp_DID == NameServer_DID)))
  618. lpfc_unreg_rpi(vport, ndlp);
  619. /* Leave Fabric nodes alone on link down */
  620. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  621. (!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. phba->fcf.fcf_flag |= (FCF_DISCOVERED | FCF_IN_USE);
  897. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  898. if (vport->port_state != LPFC_FLOGI) {
  899. spin_lock_irqsave(&phba->hbalock, flags);
  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. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1073. spin_unlock_irqrestore(&phba->hbalock, flags);
  1074. return;
  1075. }
  1076. /* The FCF is already registered, start discovery */
  1077. if (phba->fcf.fcf_flag & FCF_REGISTERED) {
  1078. phba->fcf.fcf_flag |= (FCF_DISCOVERED | FCF_IN_USE);
  1079. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1080. spin_unlock_irqrestore(&phba->hbalock, flags);
  1081. if (phba->pport->port_state != LPFC_FLOGI)
  1082. lpfc_initial_flogi(phba->pport);
  1083. return;
  1084. }
  1085. spin_unlock_irqrestore(&phba->hbalock, flags);
  1086. fcf_mbxq = mempool_alloc(phba->mbox_mem_pool,
  1087. GFP_KERNEL);
  1088. if (!fcf_mbxq) {
  1089. spin_lock_irqsave(&phba->hbalock, flags);
  1090. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1091. spin_unlock_irqrestore(&phba->hbalock, flags);
  1092. return;
  1093. }
  1094. lpfc_reg_fcfi(phba, fcf_mbxq);
  1095. fcf_mbxq->vport = phba->pport;
  1096. fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
  1097. rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
  1098. if (rc == MBX_NOT_FINISHED) {
  1099. spin_lock_irqsave(&phba->hbalock, flags);
  1100. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1101. spin_unlock_irqrestore(&phba->hbalock, flags);
  1102. mempool_free(fcf_mbxq, phba->mbox_mem_pool);
  1103. }
  1104. return;
  1105. }
  1106. /**
  1107. * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
  1108. * @phba: pointer to lpfc hba data structure.
  1109. * @new_fcf_record: pointer to fcf record.
  1110. * @boot_flag: Indicates if this record used by boot bios.
  1111. * @addr_mode: The address mode to be used by this FCF
  1112. *
  1113. * This routine compare the fcf record with connect list obtained from the
  1114. * config region to decide if this FCF can be used for SAN discovery. It returns
  1115. * 1 if this record can be used for SAN discovery else return zero. If this FCF
  1116. * record can be used for SAN discovery, the boot_flag will indicate if this FCF
  1117. * is used by boot bios and addr_mode will indicate the addressing mode to be
  1118. * used for this FCF when the function returns.
  1119. * If the FCF record need to be used with a particular vlan id, the vlan is
  1120. * set in the vlan_id on return of the function. If not VLAN tagging need to
  1121. * be used with the FCF vlan_id will be set to 0xFFFF;
  1122. **/
  1123. static int
  1124. lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
  1125. struct fcf_record *new_fcf_record,
  1126. uint32_t *boot_flag, uint32_t *addr_mode,
  1127. uint16_t *vlan_id)
  1128. {
  1129. struct lpfc_fcf_conn_entry *conn_entry;
  1130. int i, j, fcf_vlan_id = 0;
  1131. /* Find the lowest VLAN id in the FCF record */
  1132. for (i = 0; i < 512; i++) {
  1133. if (new_fcf_record->vlan_bitmap[i]) {
  1134. fcf_vlan_id = i * 8;
  1135. j = 0;
  1136. while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
  1137. j++;
  1138. fcf_vlan_id++;
  1139. }
  1140. break;
  1141. }
  1142. }
  1143. /* If FCF not available return 0 */
  1144. if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
  1145. !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record))
  1146. return 0;
  1147. if (!phba->cfg_enable_fip) {
  1148. *boot_flag = 0;
  1149. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1150. new_fcf_record);
  1151. if (phba->valid_vlan)
  1152. *vlan_id = phba->vlan_id;
  1153. else
  1154. *vlan_id = 0xFFFF;
  1155. return 1;
  1156. }
  1157. /*
  1158. * If there are no FCF connection table entry, driver connect to all
  1159. * FCFs.
  1160. */
  1161. if (list_empty(&phba->fcf_conn_rec_list)) {
  1162. *boot_flag = 0;
  1163. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1164. new_fcf_record);
  1165. /*
  1166. * When there are no FCF connect entries, use driver's default
  1167. * addressing mode - FPMA.
  1168. */
  1169. if (*addr_mode & LPFC_FCF_FPMA)
  1170. *addr_mode = LPFC_FCF_FPMA;
  1171. /* If FCF record report a vlan id use that vlan id */
  1172. if (fcf_vlan_id)
  1173. *vlan_id = fcf_vlan_id;
  1174. else
  1175. *vlan_id = 0xFFFF;
  1176. return 1;
  1177. }
  1178. list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, list) {
  1179. if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
  1180. continue;
  1181. if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
  1182. !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
  1183. new_fcf_record))
  1184. continue;
  1185. if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
  1186. !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
  1187. new_fcf_record))
  1188. continue;
  1189. if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
  1190. /*
  1191. * If the vlan bit map does not have the bit set for the
  1192. * vlan id to be used, then it is not a match.
  1193. */
  1194. if (!(new_fcf_record->vlan_bitmap
  1195. [conn_entry->conn_rec.vlan_tag / 8] &
  1196. (1 << (conn_entry->conn_rec.vlan_tag % 8))))
  1197. continue;
  1198. }
  1199. /*
  1200. * If connection record does not support any addressing mode,
  1201. * skip the FCF record.
  1202. */
  1203. if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
  1204. & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
  1205. continue;
  1206. /*
  1207. * Check if the connection record specifies a required
  1208. * addressing mode.
  1209. */
  1210. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1211. !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
  1212. /*
  1213. * If SPMA required but FCF not support this continue.
  1214. */
  1215. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1216. !(bf_get(lpfc_fcf_record_mac_addr_prov,
  1217. new_fcf_record) & LPFC_FCF_SPMA))
  1218. continue;
  1219. /*
  1220. * If FPMA required but FCF not support this continue.
  1221. */
  1222. if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1223. !(bf_get(lpfc_fcf_record_mac_addr_prov,
  1224. new_fcf_record) & LPFC_FCF_FPMA))
  1225. continue;
  1226. }
  1227. /*
  1228. * This fcf record matches filtering criteria.
  1229. */
  1230. if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
  1231. *boot_flag = 1;
  1232. else
  1233. *boot_flag = 0;
  1234. /*
  1235. * If user did not specify any addressing mode, or if the
  1236. * prefered addressing mode specified by user is not supported
  1237. * by FCF, allow fabric to pick the addressing mode.
  1238. */
  1239. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1240. new_fcf_record);
  1241. /*
  1242. * If the user specified a required address mode, assign that
  1243. * address mode
  1244. */
  1245. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1246. (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
  1247. *addr_mode = (conn_entry->conn_rec.flags &
  1248. FCFCNCT_AM_SPMA) ?
  1249. LPFC_FCF_SPMA : LPFC_FCF_FPMA;
  1250. /*
  1251. * If the user specified a prefered address mode, use the
  1252. * addr mode only if FCF support the addr_mode.
  1253. */
  1254. else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1255. (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
  1256. (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1257. (*addr_mode & LPFC_FCF_SPMA))
  1258. *addr_mode = LPFC_FCF_SPMA;
  1259. else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1260. (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
  1261. !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1262. (*addr_mode & LPFC_FCF_FPMA))
  1263. *addr_mode = LPFC_FCF_FPMA;
  1264. /* If matching connect list has a vlan id, use it */
  1265. if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
  1266. *vlan_id = conn_entry->conn_rec.vlan_tag;
  1267. /*
  1268. * If no vlan id is specified in connect list, use the vlan id
  1269. * in the FCF record
  1270. */
  1271. else if (fcf_vlan_id)
  1272. *vlan_id = fcf_vlan_id;
  1273. else
  1274. *vlan_id = 0xFFFF;
  1275. return 1;
  1276. }
  1277. return 0;
  1278. }
  1279. /**
  1280. * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
  1281. * @phba: pointer to lpfc hba data structure.
  1282. * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
  1283. *
  1284. * This function check if there is any fcoe event pending while driver
  1285. * scan FCF entries. If there is any pending event, it will restart the
  1286. * FCF saning and return 1 else return 0.
  1287. */
  1288. int
  1289. lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
  1290. {
  1291. LPFC_MBOXQ_t *mbox;
  1292. int rc;
  1293. /*
  1294. * If the Link is up and no FCoE events while in the
  1295. * FCF discovery, no need to restart FCF discovery.
  1296. */
  1297. if ((phba->link_state >= LPFC_LINK_UP) &&
  1298. (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
  1299. return 0;
  1300. spin_lock_irq(&phba->hbalock);
  1301. phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
  1302. spin_unlock_irq(&phba->hbalock);
  1303. if (phba->link_state >= LPFC_LINK_UP)
  1304. lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
  1305. else
  1306. /*
  1307. * Do not continue FCF discovery and clear FCF_DISC_INPROGRESS
  1308. * flag
  1309. */
  1310. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1311. if (unreg_fcf) {
  1312. spin_lock_irq(&phba->hbalock);
  1313. phba->fcf.fcf_flag &= ~FCF_REGISTERED;
  1314. spin_unlock_irq(&phba->hbalock);
  1315. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1316. if (!mbox) {
  1317. lpfc_printf_log(phba, KERN_ERR,
  1318. LOG_DISCOVERY|LOG_MBOX,
  1319. "2610 UNREG_FCFI mbox allocation failed\n");
  1320. return 1;
  1321. }
  1322. lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
  1323. mbox->vport = phba->pport;
  1324. mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
  1325. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  1326. if (rc == MBX_NOT_FINISHED) {
  1327. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  1328. "2611 UNREG_FCFI issue mbox failed\n");
  1329. mempool_free(mbox, phba->mbox_mem_pool);
  1330. }
  1331. }
  1332. return 1;
  1333. }
  1334. /**
  1335. * lpfc_mbx_cmpl_read_fcf_record - Completion handler for read_fcf mbox.
  1336. * @phba: pointer to lpfc hba data structure.
  1337. * @mboxq: pointer to mailbox object.
  1338. *
  1339. * This function iterate through all the fcf records available in
  1340. * HBA and choose the optimal FCF record for discovery. After finding
  1341. * the FCF for discovery it register the FCF record and kick start
  1342. * discovery.
  1343. * If FCF_IN_USE flag is set in currently used FCF, the routine try to
  1344. * use a FCF record which match fabric name and mac address of the
  1345. * currently used FCF record.
  1346. * If the driver support only one FCF, it will try to use the FCF record
  1347. * used by BOOT_BIOS.
  1348. */
  1349. void
  1350. lpfc_mbx_cmpl_read_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1351. {
  1352. void *virt_addr;
  1353. dma_addr_t phys_addr;
  1354. uint8_t *bytep;
  1355. struct lpfc_mbx_sge sge;
  1356. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  1357. uint32_t shdr_status, shdr_add_status;
  1358. union lpfc_sli4_cfg_shdr *shdr;
  1359. struct fcf_record *new_fcf_record;
  1360. int rc;
  1361. uint32_t boot_flag, addr_mode;
  1362. uint32_t next_fcf_index;
  1363. unsigned long flags;
  1364. uint16_t vlan_id;
  1365. /* If there is pending FCoE event restart FCF table scan */
  1366. if (lpfc_check_pending_fcoe_event(phba, 0)) {
  1367. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1368. return;
  1369. }
  1370. /* Get the first SGE entry from the non-embedded DMA memory. This
  1371. * routine only uses a single SGE.
  1372. */
  1373. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  1374. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  1375. if (unlikely(!mboxq->sge_array)) {
  1376. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1377. "2524 Failed to get the non-embedded SGE "
  1378. "virtual address\n");
  1379. goto out;
  1380. }
  1381. virt_addr = mboxq->sge_array->addr[0];
  1382. shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
  1383. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  1384. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  1385. &shdr->response);
  1386. /*
  1387. * The FCF Record was read and there is no reason for the driver
  1388. * to maintain the FCF record data or memory. Instead, just need
  1389. * to book keeping the FCFIs can be used.
  1390. */
  1391. if (shdr_status || shdr_add_status) {
  1392. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1393. "2521 READ_FCF_RECORD mailbox failed "
  1394. "with status x%x add_status x%x, mbx\n",
  1395. shdr_status, shdr_add_status);
  1396. goto out;
  1397. }
  1398. /* Interpreting the returned information of FCF records */
  1399. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  1400. lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
  1401. sizeof(struct lpfc_mbx_read_fcf_tbl));
  1402. next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
  1403. new_fcf_record = (struct fcf_record *)(virt_addr +
  1404. sizeof(struct lpfc_mbx_read_fcf_tbl));
  1405. lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
  1406. sizeof(struct fcf_record));
  1407. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  1408. rc = lpfc_match_fcf_conn_list(phba, new_fcf_record,
  1409. &boot_flag, &addr_mode,
  1410. &vlan_id);
  1411. /*
  1412. * If the fcf record does not match with connect list entries
  1413. * read the next entry.
  1414. */
  1415. if (!rc)
  1416. goto read_next_fcf;
  1417. /*
  1418. * If this is not the first FCF discovery of the HBA, use last
  1419. * FCF record for the discovery.
  1420. */
  1421. spin_lock_irqsave(&phba->hbalock, flags);
  1422. if (phba->fcf.fcf_flag & FCF_IN_USE) {
  1423. if (lpfc_fab_name_match(phba->fcf.fabric_name,
  1424. new_fcf_record) &&
  1425. lpfc_sw_name_match(phba->fcf.switch_name,
  1426. new_fcf_record) &&
  1427. lpfc_mac_addr_match(phba, new_fcf_record)) {
  1428. phba->fcf.fcf_flag |= FCF_AVAILABLE;
  1429. spin_unlock_irqrestore(&phba->hbalock, flags);
  1430. goto out;
  1431. }
  1432. spin_unlock_irqrestore(&phba->hbalock, flags);
  1433. goto read_next_fcf;
  1434. }
  1435. if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
  1436. /*
  1437. * If the current FCF record does not have boot flag
  1438. * set and new fcf record has boot flag set, use the
  1439. * new fcf record.
  1440. */
  1441. if (boot_flag && !(phba->fcf.fcf_flag & FCF_BOOT_ENABLE)) {
  1442. /* Use this FCF record */
  1443. lpfc_copy_fcf_record(phba, new_fcf_record);
  1444. phba->fcf.addr_mode = addr_mode;
  1445. phba->fcf.fcf_flag |= FCF_BOOT_ENABLE;
  1446. if (vlan_id != 0xFFFF) {
  1447. phba->fcf.fcf_flag |= FCF_VALID_VLAN;
  1448. phba->fcf.vlan_id = vlan_id;
  1449. }
  1450. spin_unlock_irqrestore(&phba->hbalock, flags);
  1451. goto read_next_fcf;
  1452. }
  1453. /*
  1454. * If the current FCF record has boot flag set and the
  1455. * new FCF record does not have boot flag, read the next
  1456. * FCF record.
  1457. */
  1458. if (!boot_flag && (phba->fcf.fcf_flag & FCF_BOOT_ENABLE)) {
  1459. spin_unlock_irqrestore(&phba->hbalock, flags);
  1460. goto read_next_fcf;
  1461. }
  1462. /*
  1463. * If there is a record with lower priority value for
  1464. * the current FCF, use that record.
  1465. */
  1466. if (lpfc_fab_name_match(phba->fcf.fabric_name,
  1467. new_fcf_record) &&
  1468. (new_fcf_record->fip_priority < phba->fcf.priority)) {
  1469. /* Use this FCF record */
  1470. lpfc_copy_fcf_record(phba, new_fcf_record);
  1471. phba->fcf.addr_mode = addr_mode;
  1472. if (vlan_id != 0xFFFF) {
  1473. phba->fcf.fcf_flag |= FCF_VALID_VLAN;
  1474. phba->fcf.vlan_id = vlan_id;
  1475. }
  1476. spin_unlock_irqrestore(&phba->hbalock, flags);
  1477. goto read_next_fcf;
  1478. }
  1479. spin_unlock_irqrestore(&phba->hbalock, flags);
  1480. goto read_next_fcf;
  1481. }
  1482. /*
  1483. * This is the first available FCF record, use this
  1484. * record.
  1485. */
  1486. lpfc_copy_fcf_record(phba, new_fcf_record);
  1487. phba->fcf.addr_mode = addr_mode;
  1488. if (boot_flag)
  1489. phba->fcf.fcf_flag |= FCF_BOOT_ENABLE;
  1490. phba->fcf.fcf_flag |= FCF_AVAILABLE;
  1491. if (vlan_id != 0xFFFF) {
  1492. phba->fcf.fcf_flag |= FCF_VALID_VLAN;
  1493. phba->fcf.vlan_id = vlan_id;
  1494. }
  1495. spin_unlock_irqrestore(&phba->hbalock, flags);
  1496. goto read_next_fcf;
  1497. read_next_fcf:
  1498. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1499. if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0)
  1500. lpfc_register_fcf(phba);
  1501. else
  1502. lpfc_sli4_read_fcf_record(phba, next_fcf_index);
  1503. return;
  1504. out:
  1505. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1506. lpfc_register_fcf(phba);
  1507. return;
  1508. }
  1509. /**
  1510. * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
  1511. * @phba: pointer to lpfc hba data structure.
  1512. * @mboxq: pointer to mailbox data structure.
  1513. *
  1514. * This function handles completion of init vpi mailbox command.
  1515. */
  1516. static void
  1517. lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1518. {
  1519. struct lpfc_vport *vport = mboxq->vport;
  1520. if (mboxq->u.mb.mbxStatus) {
  1521. lpfc_printf_vlog(vport, KERN_ERR,
  1522. LOG_MBOX,
  1523. "2609 Init VPI mailbox failed 0x%x\n",
  1524. mboxq->u.mb.mbxStatus);
  1525. mempool_free(mboxq, phba->mbox_mem_pool);
  1526. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1527. return;
  1528. }
  1529. vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
  1530. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  1531. lpfc_initial_fdisc(vport);
  1532. else {
  1533. lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
  1534. lpfc_printf_vlog(vport, KERN_ERR,
  1535. LOG_ELS,
  1536. "2606 No NPIV Fabric support\n");
  1537. }
  1538. return;
  1539. }
  1540. /**
  1541. * lpfc_start_fdiscs - send fdiscs for each vports on this port.
  1542. * @phba: pointer to lpfc hba data structure.
  1543. *
  1544. * This function loops through the list of vports on the @phba and issues an
  1545. * FDISC if possible.
  1546. */
  1547. void
  1548. lpfc_start_fdiscs(struct lpfc_hba *phba)
  1549. {
  1550. struct lpfc_vport **vports;
  1551. int i;
  1552. LPFC_MBOXQ_t *mboxq;
  1553. int rc;
  1554. vports = lpfc_create_vport_work_array(phba);
  1555. if (vports != NULL) {
  1556. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  1557. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  1558. continue;
  1559. /* There are no vpi for this vport */
  1560. if (vports[i]->vpi > phba->max_vpi) {
  1561. lpfc_vport_set_state(vports[i],
  1562. FC_VPORT_FAILED);
  1563. continue;
  1564. }
  1565. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1566. lpfc_vport_set_state(vports[i],
  1567. FC_VPORT_LINKDOWN);
  1568. continue;
  1569. }
  1570. if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
  1571. mboxq = mempool_alloc(phba->mbox_mem_pool,
  1572. GFP_KERNEL);
  1573. if (!mboxq) {
  1574. lpfc_printf_vlog(vports[i], KERN_ERR,
  1575. LOG_MBOX, "2607 Failed to allocate "
  1576. "init_vpi mailbox\n");
  1577. continue;
  1578. }
  1579. lpfc_init_vpi(phba, mboxq, vports[i]->vpi);
  1580. mboxq->vport = vports[i];
  1581. mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
  1582. rc = lpfc_sli_issue_mbox(phba, mboxq,
  1583. MBX_NOWAIT);
  1584. if (rc == MBX_NOT_FINISHED) {
  1585. lpfc_printf_vlog(vports[i], KERN_ERR,
  1586. LOG_MBOX, "2608 Failed to issue "
  1587. "init_vpi mailbox\n");
  1588. mempool_free(mboxq,
  1589. phba->mbox_mem_pool);
  1590. }
  1591. continue;
  1592. }
  1593. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  1594. lpfc_initial_fdisc(vports[i]);
  1595. else {
  1596. lpfc_vport_set_state(vports[i],
  1597. FC_VPORT_NO_FABRIC_SUPP);
  1598. lpfc_printf_vlog(vports[i], KERN_ERR,
  1599. LOG_ELS,
  1600. "0259 No NPIV "
  1601. "Fabric support\n");
  1602. }
  1603. }
  1604. }
  1605. lpfc_destroy_vport_work_array(phba, vports);
  1606. }
  1607. void
  1608. lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1609. {
  1610. struct lpfc_dmabuf *dmabuf = mboxq->context1;
  1611. struct lpfc_vport *vport = mboxq->vport;
  1612. if (mboxq->u.mb.mbxStatus) {
  1613. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1614. "2018 REG_VFI mbxStatus error x%x "
  1615. "HBA state x%x\n",
  1616. mboxq->u.mb.mbxStatus, vport->port_state);
  1617. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1618. /* FLOGI failed, use loop map to make discovery list */
  1619. lpfc_disc_list_loopmap(vport);
  1620. /* Start discovery */
  1621. lpfc_disc_start(vport);
  1622. goto fail_free_mem;
  1623. }
  1624. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1625. goto fail_free_mem;
  1626. }
  1627. /* Mark the vport has registered with its VFI */
  1628. vport->vfi_state |= LPFC_VFI_REGISTERED;
  1629. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  1630. lpfc_start_fdiscs(phba);
  1631. lpfc_do_scr_ns_plogi(phba, vport);
  1632. }
  1633. fail_free_mem:
  1634. mempool_free(mboxq, phba->mbox_mem_pool);
  1635. lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
  1636. kfree(dmabuf);
  1637. return;
  1638. }
  1639. static void
  1640. lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1641. {
  1642. MAILBOX_t *mb = &pmb->u.mb;
  1643. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
  1644. struct lpfc_vport *vport = pmb->vport;
  1645. /* Check for error */
  1646. if (mb->mbxStatus) {
  1647. /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
  1648. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1649. "0319 READ_SPARAM mbxStatus error x%x "
  1650. "hba state x%x>\n",
  1651. mb->mbxStatus, vport->port_state);
  1652. lpfc_linkdown(phba);
  1653. goto out;
  1654. }
  1655. memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
  1656. sizeof (struct serv_parm));
  1657. if (phba->cfg_soft_wwnn)
  1658. u64_to_wwn(phba->cfg_soft_wwnn,
  1659. vport->fc_sparam.nodeName.u.wwn);
  1660. if (phba->cfg_soft_wwpn)
  1661. u64_to_wwn(phba->cfg_soft_wwpn,
  1662. vport->fc_sparam.portName.u.wwn);
  1663. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  1664. sizeof(vport->fc_nodename));
  1665. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  1666. sizeof(vport->fc_portname));
  1667. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  1668. memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
  1669. memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
  1670. }
  1671. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1672. kfree(mp);
  1673. mempool_free(pmb, phba->mbox_mem_pool);
  1674. return;
  1675. out:
  1676. pmb->context1 = NULL;
  1677. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1678. kfree(mp);
  1679. lpfc_issue_clear_la(phba, vport);
  1680. mempool_free(pmb, phba->mbox_mem_pool);
  1681. return;
  1682. }
  1683. static void
  1684. lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
  1685. {
  1686. struct lpfc_vport *vport = phba->pport;
  1687. LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
  1688. int i;
  1689. struct lpfc_dmabuf *mp;
  1690. int rc;
  1691. struct fcf_record *fcf_record;
  1692. sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1693. spin_lock_irq(&phba->hbalock);
  1694. switch (la->UlnkSpeed) {
  1695. case LA_1GHZ_LINK:
  1696. phba->fc_linkspeed = LA_1GHZ_LINK;
  1697. break;
  1698. case LA_2GHZ_LINK:
  1699. phba->fc_linkspeed = LA_2GHZ_LINK;
  1700. break;
  1701. case LA_4GHZ_LINK:
  1702. phba->fc_linkspeed = LA_4GHZ_LINK;
  1703. break;
  1704. case LA_8GHZ_LINK:
  1705. phba->fc_linkspeed = LA_8GHZ_LINK;
  1706. break;
  1707. case LA_10GHZ_LINK:
  1708. phba->fc_linkspeed = LA_10GHZ_LINK;
  1709. break;
  1710. default:
  1711. phba->fc_linkspeed = LA_UNKNW_LINK;
  1712. break;
  1713. }
  1714. phba->fc_topology = la->topology;
  1715. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  1716. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1717. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  1718. if (phba->cfg_enable_npiv)
  1719. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1720. "1309 Link Up Event npiv not supported in loop "
  1721. "topology\n");
  1722. /* Get Loop Map information */
  1723. if (la->il)
  1724. vport->fc_flag |= FC_LBIT;
  1725. vport->fc_myDID = la->granted_AL_PA;
  1726. i = la->un.lilpBde64.tus.f.bdeSize;
  1727. if (i == 0) {
  1728. phba->alpa_map[0] = 0;
  1729. } else {
  1730. if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
  1731. int numalpa, j, k;
  1732. union {
  1733. uint8_t pamap[16];
  1734. struct {
  1735. uint32_t wd1;
  1736. uint32_t wd2;
  1737. uint32_t wd3;
  1738. uint32_t wd4;
  1739. } pa;
  1740. } un;
  1741. numalpa = phba->alpa_map[0];
  1742. j = 0;
  1743. while (j < numalpa) {
  1744. memset(un.pamap, 0, 16);
  1745. for (k = 1; j < numalpa; k++) {
  1746. un.pamap[k - 1] =
  1747. phba->alpa_map[j + 1];
  1748. j++;
  1749. if (k == 16)
  1750. break;
  1751. }
  1752. /* Link Up Event ALPA map */
  1753. lpfc_printf_log(phba,
  1754. KERN_WARNING,
  1755. LOG_LINK_EVENT,
  1756. "1304 Link Up Event "
  1757. "ALPA map Data: x%x "
  1758. "x%x x%x x%x\n",
  1759. un.pa.wd1, un.pa.wd2,
  1760. un.pa.wd3, un.pa.wd4);
  1761. }
  1762. }
  1763. }
  1764. } else {
  1765. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
  1766. if (phba->max_vpi && phba->cfg_enable_npiv &&
  1767. (phba->sli_rev == 3))
  1768. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  1769. }
  1770. vport->fc_myDID = phba->fc_pref_DID;
  1771. vport->fc_flag |= FC_LBIT;
  1772. }
  1773. spin_unlock_irq(&phba->hbalock);
  1774. lpfc_linkup(phba);
  1775. if (sparam_mbox) {
  1776. lpfc_read_sparam(phba, sparam_mbox, 0);
  1777. sparam_mbox->vport = vport;
  1778. sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
  1779. rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
  1780. if (rc == MBX_NOT_FINISHED) {
  1781. mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
  1782. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1783. kfree(mp);
  1784. mempool_free(sparam_mbox, phba->mbox_mem_pool);
  1785. goto out;
  1786. }
  1787. }
  1788. if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  1789. cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1790. if (!cfglink_mbox)
  1791. goto out;
  1792. vport->port_state = LPFC_LOCAL_CFG_LINK;
  1793. lpfc_config_link(phba, cfglink_mbox);
  1794. cfglink_mbox->vport = vport;
  1795. cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
  1796. rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
  1797. if (rc == MBX_NOT_FINISHED) {
  1798. mempool_free(cfglink_mbox, phba->mbox_mem_pool);
  1799. goto out;
  1800. }
  1801. } else {
  1802. vport->port_state = LPFC_VPORT_UNKNOWN;
  1803. /*
  1804. * Add the driver's default FCF record at FCF index 0 now. This
  1805. * is phase 1 implementation that support FCF index 0 and driver
  1806. * defaults.
  1807. */
  1808. if (phba->cfg_enable_fip == 0) {
  1809. fcf_record = kzalloc(sizeof(struct fcf_record),
  1810. GFP_KERNEL);
  1811. if (unlikely(!fcf_record)) {
  1812. lpfc_printf_log(phba, KERN_ERR,
  1813. LOG_MBOX | LOG_SLI,
  1814. "2554 Could not allocate memmory for "
  1815. "fcf record\n");
  1816. rc = -ENODEV;
  1817. goto out;
  1818. }
  1819. lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
  1820. LPFC_FCOE_FCF_DEF_INDEX);
  1821. rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
  1822. if (unlikely(rc)) {
  1823. lpfc_printf_log(phba, KERN_ERR,
  1824. LOG_MBOX | LOG_SLI,
  1825. "2013 Could not manually add FCF "
  1826. "record 0, status %d\n", rc);
  1827. rc = -ENODEV;
  1828. kfree(fcf_record);
  1829. goto out;
  1830. }
  1831. kfree(fcf_record);
  1832. }
  1833. /*
  1834. * The driver is expected to do FIP/FCF. Call the port
  1835. * and get the FCF Table.
  1836. */
  1837. spin_lock_irq(&phba->hbalock);
  1838. if (phba->hba_flag & FCF_DISC_INPROGRESS) {
  1839. spin_unlock_irq(&phba->hbalock);
  1840. return;
  1841. }
  1842. spin_unlock_irq(&phba->hbalock);
  1843. rc = lpfc_sli4_read_fcf_record(phba,
  1844. LPFC_FCOE_FCF_GET_FIRST);
  1845. if (rc)
  1846. goto out;
  1847. }
  1848. return;
  1849. out:
  1850. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1851. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1852. "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
  1853. vport->port_state, sparam_mbox, cfglink_mbox);
  1854. lpfc_issue_clear_la(phba, vport);
  1855. return;
  1856. }
  1857. static void
  1858. lpfc_enable_la(struct lpfc_hba *phba)
  1859. {
  1860. uint32_t control;
  1861. struct lpfc_sli *psli = &phba->sli;
  1862. spin_lock_irq(&phba->hbalock);
  1863. psli->sli_flag |= LPFC_PROCESS_LA;
  1864. if (phba->sli_rev <= LPFC_SLI_REV3) {
  1865. control = readl(phba->HCregaddr);
  1866. control |= HC_LAINT_ENA;
  1867. writel(control, phba->HCregaddr);
  1868. readl(phba->HCregaddr); /* flush */
  1869. }
  1870. spin_unlock_irq(&phba->hbalock);
  1871. }
  1872. static void
  1873. lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
  1874. {
  1875. lpfc_linkdown(phba);
  1876. lpfc_enable_la(phba);
  1877. lpfc_unregister_unused_fcf(phba);
  1878. /* turn on Link Attention interrupts - no CLEAR_LA needed */
  1879. }
  1880. /*
  1881. * This routine handles processing a READ_LA mailbox
  1882. * command upon completion. It is setup in the LPFC_MBOXQ
  1883. * as the completion routine when the command is
  1884. * handed off to the SLI layer.
  1885. */
  1886. void
  1887. lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1888. {
  1889. struct lpfc_vport *vport = pmb->vport;
  1890. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1891. READ_LA_VAR *la;
  1892. MAILBOX_t *mb = &pmb->u.mb;
  1893. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1894. /* Unblock ELS traffic */
  1895. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  1896. /* Check for error */
  1897. if (mb->mbxStatus) {
  1898. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1899. "1307 READ_LA mbox error x%x state x%x\n",
  1900. mb->mbxStatus, vport->port_state);
  1901. lpfc_mbx_issue_link_down(phba);
  1902. phba->link_state = LPFC_HBA_ERROR;
  1903. goto lpfc_mbx_cmpl_read_la_free_mbuf;
  1904. }
  1905. la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
  1906. memcpy(&phba->alpa_map[0], mp->virt, 128);
  1907. spin_lock_irq(shost->host_lock);
  1908. if (la->pb)
  1909. vport->fc_flag |= FC_BYPASSED_MODE;
  1910. else
  1911. vport->fc_flag &= ~FC_BYPASSED_MODE;
  1912. spin_unlock_irq(shost->host_lock);
  1913. if ((phba->fc_eventTag < la->eventTag) ||
  1914. (phba->fc_eventTag == la->eventTag)) {
  1915. phba->fc_stat.LinkMultiEvent++;
  1916. if (la->attType == AT_LINK_UP)
  1917. if (phba->fc_eventTag != 0)
  1918. lpfc_linkdown(phba);
  1919. }
  1920. phba->fc_eventTag = la->eventTag;
  1921. if (la->mm)
  1922. phba->sli.sli_flag |= LPFC_MENLO_MAINT;
  1923. else
  1924. phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
  1925. phba->link_events++;
  1926. if (la->attType == AT_LINK_UP && (!la->mm)) {
  1927. phba->fc_stat.LinkUp++;
  1928. if (phba->link_flag & LS_LOOPBACK_MODE) {
  1929. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1930. "1306 Link Up Event in loop back mode "
  1931. "x%x received Data: x%x x%x x%x x%x\n",
  1932. la->eventTag, phba->fc_eventTag,
  1933. la->granted_AL_PA, la->UlnkSpeed,
  1934. phba->alpa_map[0]);
  1935. } else {
  1936. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1937. "1303 Link Up Event x%x received "
  1938. "Data: x%x x%x x%x x%x x%x x%x %d\n",
  1939. la->eventTag, phba->fc_eventTag,
  1940. la->granted_AL_PA, la->UlnkSpeed,
  1941. phba->alpa_map[0],
  1942. la->mm, la->fa,
  1943. phba->wait_4_mlo_maint_flg);
  1944. }
  1945. lpfc_mbx_process_link_up(phba, la);
  1946. } else if (la->attType == AT_LINK_DOWN) {
  1947. phba->fc_stat.LinkDown++;
  1948. if (phba->link_flag & LS_LOOPBACK_MODE) {
  1949. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1950. "1308 Link Down Event in loop back mode "
  1951. "x%x received "
  1952. "Data: x%x x%x x%x\n",
  1953. la->eventTag, phba->fc_eventTag,
  1954. phba->pport->port_state, vport->fc_flag);
  1955. }
  1956. else {
  1957. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1958. "1305 Link Down Event x%x received "
  1959. "Data: x%x x%x x%x x%x x%x\n",
  1960. la->eventTag, phba->fc_eventTag,
  1961. phba->pport->port_state, vport->fc_flag,
  1962. la->mm, la->fa);
  1963. }
  1964. lpfc_mbx_issue_link_down(phba);
  1965. }
  1966. if (la->mm && la->attType == AT_LINK_UP) {
  1967. if (phba->link_state != LPFC_LINK_DOWN) {
  1968. phba->fc_stat.LinkDown++;
  1969. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1970. "1312 Link Down Event x%x received "
  1971. "Data: x%x x%x x%x\n",
  1972. la->eventTag, phba->fc_eventTag,
  1973. phba->pport->port_state, vport->fc_flag);
  1974. lpfc_mbx_issue_link_down(phba);
  1975. } else
  1976. lpfc_enable_la(phba);
  1977. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1978. "1310 Menlo Maint Mode Link up Event x%x rcvd "
  1979. "Data: x%x x%x x%x\n",
  1980. la->eventTag, phba->fc_eventTag,
  1981. phba->pport->port_state, vport->fc_flag);
  1982. /*
  1983. * The cmnd that triggered this will be waiting for this
  1984. * signal.
  1985. */
  1986. /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
  1987. if (phba->wait_4_mlo_maint_flg) {
  1988. phba->wait_4_mlo_maint_flg = 0;
  1989. wake_up_interruptible(&phba->wait_4_mlo_m_q);
  1990. }
  1991. }
  1992. if (la->fa) {
  1993. if (la->mm)
  1994. lpfc_issue_clear_la(phba, vport);
  1995. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1996. "1311 fa %d\n", la->fa);
  1997. }
  1998. lpfc_mbx_cmpl_read_la_free_mbuf:
  1999. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2000. kfree(mp);
  2001. mempool_free(pmb, phba->mbox_mem_pool);
  2002. return;
  2003. }
  2004. /*
  2005. * This routine handles processing a REG_LOGIN mailbox
  2006. * command upon completion. It is setup in the LPFC_MBOXQ
  2007. * as the completion routine when the command is
  2008. * handed off to the SLI layer.
  2009. */
  2010. void
  2011. lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2012. {
  2013. struct lpfc_vport *vport = pmb->vport;
  2014. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2015. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2016. pmb->context1 = NULL;
  2017. /* Good status, call state machine */
  2018. lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
  2019. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2020. kfree(mp);
  2021. mempool_free(pmb, phba->mbox_mem_pool);
  2022. /* decrement the node reference count held for this callback
  2023. * function.
  2024. */
  2025. lpfc_nlp_put(ndlp);
  2026. return;
  2027. }
  2028. static void
  2029. lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2030. {
  2031. MAILBOX_t *mb = &pmb->u.mb;
  2032. struct lpfc_vport *vport = pmb->vport;
  2033. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2034. switch (mb->mbxStatus) {
  2035. case 0x0011:
  2036. case 0x0020:
  2037. case 0x9700:
  2038. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2039. "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
  2040. mb->mbxStatus);
  2041. break;
  2042. }
  2043. vport->unreg_vpi_cmpl = VPORT_OK;
  2044. mempool_free(pmb, phba->mbox_mem_pool);
  2045. /*
  2046. * This shost reference might have been taken at the beginning of
  2047. * lpfc_vport_delete()
  2048. */
  2049. if (vport->load_flag & FC_UNLOADING)
  2050. scsi_host_put(shost);
  2051. }
  2052. int
  2053. lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
  2054. {
  2055. struct lpfc_hba *phba = vport->phba;
  2056. LPFC_MBOXQ_t *mbox;
  2057. int rc;
  2058. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2059. if (!mbox)
  2060. return 1;
  2061. lpfc_unreg_vpi(phba, vport->vpi, mbox);
  2062. mbox->vport = vport;
  2063. mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
  2064. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2065. if (rc == MBX_NOT_FINISHED) {
  2066. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  2067. "1800 Could not issue unreg_vpi\n");
  2068. mempool_free(mbox, phba->mbox_mem_pool);
  2069. vport->unreg_vpi_cmpl = VPORT_ERROR;
  2070. return rc;
  2071. }
  2072. return 0;
  2073. }
  2074. static void
  2075. lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2076. {
  2077. struct lpfc_vport *vport = pmb->vport;
  2078. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2079. MAILBOX_t *mb = &pmb->u.mb;
  2080. switch (mb->mbxStatus) {
  2081. case 0x0011:
  2082. case 0x9601:
  2083. case 0x9602:
  2084. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2085. "0912 cmpl_reg_vpi, mb status = 0x%x\n",
  2086. mb->mbxStatus);
  2087. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2088. spin_lock_irq(shost->host_lock);
  2089. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  2090. spin_unlock_irq(shost->host_lock);
  2091. vport->fc_myDID = 0;
  2092. goto out;
  2093. }
  2094. vport->num_disc_nodes = 0;
  2095. /* go thru NPR list and issue ELS PLOGIs */
  2096. if (vport->fc_npr_cnt)
  2097. lpfc_els_disc_plogi(vport);
  2098. if (!vport->num_disc_nodes) {
  2099. spin_lock_irq(shost->host_lock);
  2100. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  2101. spin_unlock_irq(shost->host_lock);
  2102. lpfc_can_disctmo(vport);
  2103. }
  2104. vport->port_state = LPFC_VPORT_READY;
  2105. out:
  2106. mempool_free(pmb, phba->mbox_mem_pool);
  2107. return;
  2108. }
  2109. /**
  2110. * lpfc_create_static_vport - Read HBA config region to create static vports.
  2111. * @phba: pointer to lpfc hba data structure.
  2112. *
  2113. * This routine issue a DUMP mailbox command for config region 22 to get
  2114. * the list of static vports to be created. The function create vports
  2115. * based on the information returned from the HBA.
  2116. **/
  2117. void
  2118. lpfc_create_static_vport(struct lpfc_hba *phba)
  2119. {
  2120. LPFC_MBOXQ_t *pmb = NULL;
  2121. MAILBOX_t *mb;
  2122. struct static_vport_info *vport_info;
  2123. int rc = 0, i;
  2124. struct fc_vport_identifiers vport_id;
  2125. struct fc_vport *new_fc_vport;
  2126. struct Scsi_Host *shost;
  2127. struct lpfc_vport *vport;
  2128. uint16_t offset = 0;
  2129. uint8_t *vport_buff;
  2130. struct lpfc_dmabuf *mp;
  2131. uint32_t byte_count = 0;
  2132. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2133. if (!pmb) {
  2134. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2135. "0542 lpfc_create_static_vport failed to"
  2136. " allocate mailbox memory\n");
  2137. return;
  2138. }
  2139. mb = &pmb->u.mb;
  2140. vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
  2141. if (!vport_info) {
  2142. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2143. "0543 lpfc_create_static_vport failed to"
  2144. " allocate vport_info\n");
  2145. mempool_free(pmb, phba->mbox_mem_pool);
  2146. return;
  2147. }
  2148. vport_buff = (uint8_t *) vport_info;
  2149. do {
  2150. if (lpfc_dump_static_vport(phba, pmb, offset))
  2151. goto out;
  2152. pmb->vport = phba->pport;
  2153. rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO);
  2154. if ((rc != MBX_SUCCESS) || mb->mbxStatus) {
  2155. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2156. "0544 lpfc_create_static_vport failed to"
  2157. " issue dump mailbox command ret 0x%x "
  2158. "status 0x%x\n",
  2159. rc, mb->mbxStatus);
  2160. goto out;
  2161. }
  2162. if (phba->sli_rev == LPFC_SLI_REV4) {
  2163. byte_count = pmb->u.mqe.un.mb_words[5];
  2164. mp = (struct lpfc_dmabuf *) pmb->context2;
  2165. if (byte_count > sizeof(struct static_vport_info) -
  2166. offset)
  2167. byte_count = sizeof(struct static_vport_info)
  2168. - offset;
  2169. memcpy(vport_buff + offset, mp->virt, byte_count);
  2170. offset += byte_count;
  2171. } else {
  2172. if (mb->un.varDmp.word_cnt >
  2173. sizeof(struct static_vport_info) - offset)
  2174. mb->un.varDmp.word_cnt =
  2175. sizeof(struct static_vport_info)
  2176. - offset;
  2177. byte_count = mb->un.varDmp.word_cnt;
  2178. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  2179. vport_buff + offset,
  2180. byte_count);
  2181. offset += byte_count;
  2182. }
  2183. } while (byte_count &&
  2184. offset < sizeof(struct static_vport_info));
  2185. if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
  2186. ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
  2187. != VPORT_INFO_REV)) {
  2188. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2189. "0545 lpfc_create_static_vport bad"
  2190. " information header 0x%x 0x%x\n",
  2191. le32_to_cpu(vport_info->signature),
  2192. le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
  2193. goto out;
  2194. }
  2195. shost = lpfc_shost_from_vport(phba->pport);
  2196. for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
  2197. memset(&vport_id, 0, sizeof(vport_id));
  2198. vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
  2199. vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
  2200. if (!vport_id.port_name || !vport_id.node_name)
  2201. continue;
  2202. vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
  2203. vport_id.vport_type = FC_PORTTYPE_NPIV;
  2204. vport_id.disable = false;
  2205. new_fc_vport = fc_vport_create(shost, 0, &vport_id);
  2206. if (!new_fc_vport) {
  2207. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2208. "0546 lpfc_create_static_vport failed to"
  2209. " create vport\n");
  2210. continue;
  2211. }
  2212. vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
  2213. vport->vport_flag |= STATIC_VPORT;
  2214. }
  2215. out:
  2216. kfree(vport_info);
  2217. if (rc != MBX_TIMEOUT) {
  2218. if (pmb->context2) {
  2219. mp = (struct lpfc_dmabuf *) pmb->context2;
  2220. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2221. kfree(mp);
  2222. }
  2223. mempool_free(pmb, phba->mbox_mem_pool);
  2224. }
  2225. return;
  2226. }
  2227. /*
  2228. * This routine handles processing a Fabric REG_LOGIN mailbox
  2229. * command upon completion. It is setup in the LPFC_MBOXQ
  2230. * as the completion routine when the command is
  2231. * handed off to the SLI layer.
  2232. */
  2233. void
  2234. lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2235. {
  2236. struct lpfc_vport *vport = pmb->vport;
  2237. MAILBOX_t *mb = &pmb->u.mb;
  2238. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2239. struct lpfc_nodelist *ndlp;
  2240. ndlp = (struct lpfc_nodelist *) pmb->context2;
  2241. pmb->context1 = NULL;
  2242. pmb->context2 = NULL;
  2243. if (mb->mbxStatus) {
  2244. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  2245. "0258 Register Fabric login error: 0x%x\n",
  2246. mb->mbxStatus);
  2247. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2248. kfree(mp);
  2249. mempool_free(pmb, phba->mbox_mem_pool);
  2250. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2251. /* FLOGI failed, use loop map to make discovery list */
  2252. lpfc_disc_list_loopmap(vport);
  2253. /* Start discovery */
  2254. lpfc_disc_start(vport);
  2255. /* Decrement the reference count to ndlp after the
  2256. * reference to the ndlp are done.
  2257. */
  2258. lpfc_nlp_put(ndlp);
  2259. return;
  2260. }
  2261. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2262. /* Decrement the reference count to ndlp after the reference
  2263. * to the ndlp are done.
  2264. */
  2265. lpfc_nlp_put(ndlp);
  2266. return;
  2267. }
  2268. ndlp->nlp_rpi = mb->un.varWords[0];
  2269. ndlp->nlp_flag |= NLP_RPI_VALID;
  2270. ndlp->nlp_type |= NLP_FABRIC;
  2271. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2272. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  2273. lpfc_start_fdiscs(phba);
  2274. lpfc_do_scr_ns_plogi(phba, vport);
  2275. }
  2276. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2277. kfree(mp);
  2278. mempool_free(pmb, phba->mbox_mem_pool);
  2279. /* Drop the reference count from the mbox at the end after
  2280. * all the current reference to the ndlp have been done.
  2281. */
  2282. lpfc_nlp_put(ndlp);
  2283. return;
  2284. }
  2285. /*
  2286. * This routine handles processing a NameServer REG_LOGIN mailbox
  2287. * command upon completion. It is setup in the LPFC_MBOXQ
  2288. * as the completion routine when the command is
  2289. * handed off to the SLI layer.
  2290. */
  2291. void
  2292. lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2293. {
  2294. MAILBOX_t *mb = &pmb->u.mb;
  2295. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2296. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2297. struct lpfc_vport *vport = pmb->vport;
  2298. if (mb->mbxStatus) {
  2299. out:
  2300. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2301. "0260 Register NameServer error: 0x%x\n",
  2302. mb->mbxStatus);
  2303. /* decrement the node reference count held for this
  2304. * callback function.
  2305. */
  2306. lpfc_nlp_put(ndlp);
  2307. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2308. kfree(mp);
  2309. mempool_free(pmb, phba->mbox_mem_pool);
  2310. /* If no other thread is using the ndlp, free it */
  2311. lpfc_nlp_not_used(ndlp);
  2312. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2313. /*
  2314. * RegLogin failed, use loop map to make discovery
  2315. * list
  2316. */
  2317. lpfc_disc_list_loopmap(vport);
  2318. /* Start discovery */
  2319. lpfc_disc_start(vport);
  2320. return;
  2321. }
  2322. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2323. return;
  2324. }
  2325. pmb->context1 = NULL;
  2326. ndlp->nlp_rpi = mb->un.varWords[0];
  2327. ndlp->nlp_flag |= NLP_RPI_VALID;
  2328. ndlp->nlp_type |= NLP_FABRIC;
  2329. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2330. if (vport->port_state < LPFC_VPORT_READY) {
  2331. /* Link up discovery requires Fabric registration. */
  2332. lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
  2333. lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
  2334. lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
  2335. lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
  2336. lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
  2337. /* Issue SCR just before NameServer GID_FT Query */
  2338. lpfc_issue_els_scr(vport, SCR_DID, 0);
  2339. }
  2340. vport->fc_ns_retry = 0;
  2341. /* Good status, issue CT Request to NameServer */
  2342. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
  2343. /* Cannot issue NameServer Query, so finish up discovery */
  2344. goto out;
  2345. }
  2346. /* decrement the node reference count held for this
  2347. * callback function.
  2348. */
  2349. lpfc_nlp_put(ndlp);
  2350. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2351. kfree(mp);
  2352. mempool_free(pmb, phba->mbox_mem_pool);
  2353. return;
  2354. }
  2355. static void
  2356. lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2357. {
  2358. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2359. struct fc_rport *rport;
  2360. struct lpfc_rport_data *rdata;
  2361. struct fc_rport_identifiers rport_ids;
  2362. struct lpfc_hba *phba = vport->phba;
  2363. /* Remote port has reappeared. Re-register w/ FC transport */
  2364. rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  2365. rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  2366. rport_ids.port_id = ndlp->nlp_DID;
  2367. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2368. /*
  2369. * We leave our node pointer in rport->dd_data when we unregister a
  2370. * FCP target port. But fc_remote_port_add zeros the space to which
  2371. * rport->dd_data points. So, if we're reusing a previously
  2372. * registered port, drop the reference that we took the last time we
  2373. * registered the port.
  2374. */
  2375. if (ndlp->rport && ndlp->rport->dd_data &&
  2376. ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
  2377. lpfc_nlp_put(ndlp);
  2378. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  2379. "rport add: did:x%x flg:x%x type x%x",
  2380. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  2381. ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
  2382. if (!rport || !get_device(&rport->dev)) {
  2383. dev_printk(KERN_WARNING, &phba->pcidev->dev,
  2384. "Warning: fc_remote_port_add failed\n");
  2385. return;
  2386. }
  2387. /* initialize static port data */
  2388. rport->maxframe_size = ndlp->nlp_maxframe;
  2389. rport->supported_classes = ndlp->nlp_class_sup;
  2390. rdata = rport->dd_data;
  2391. rdata->pnode = lpfc_nlp_get(ndlp);
  2392. if (ndlp->nlp_type & NLP_FCP_TARGET)
  2393. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  2394. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  2395. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  2396. if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
  2397. fc_remote_port_rolechg(rport, rport_ids.roles);
  2398. if ((rport->scsi_target_id != -1) &&
  2399. (rport->scsi_target_id < LPFC_MAX_TARGET)) {
  2400. ndlp->nlp_sid = rport->scsi_target_id;
  2401. }
  2402. return;
  2403. }
  2404. static void
  2405. lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
  2406. {
  2407. struct fc_rport *rport = ndlp->rport;
  2408. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  2409. "rport delete: did:x%x flg:x%x type x%x",
  2410. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  2411. fc_remote_port_delete(rport);
  2412. return;
  2413. }
  2414. static void
  2415. lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
  2416. {
  2417. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2418. spin_lock_irq(shost->host_lock);
  2419. switch (state) {
  2420. case NLP_STE_UNUSED_NODE:
  2421. vport->fc_unused_cnt += count;
  2422. break;
  2423. case NLP_STE_PLOGI_ISSUE:
  2424. vport->fc_plogi_cnt += count;
  2425. break;
  2426. case NLP_STE_ADISC_ISSUE:
  2427. vport->fc_adisc_cnt += count;
  2428. break;
  2429. case NLP_STE_REG_LOGIN_ISSUE:
  2430. vport->fc_reglogin_cnt += count;
  2431. break;
  2432. case NLP_STE_PRLI_ISSUE:
  2433. vport->fc_prli_cnt += count;
  2434. break;
  2435. case NLP_STE_UNMAPPED_NODE:
  2436. vport->fc_unmap_cnt += count;
  2437. break;
  2438. case NLP_STE_MAPPED_NODE:
  2439. vport->fc_map_cnt += count;
  2440. break;
  2441. case NLP_STE_NPR_NODE:
  2442. vport->fc_npr_cnt += count;
  2443. break;
  2444. }
  2445. spin_unlock_irq(shost->host_lock);
  2446. }
  2447. static void
  2448. lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2449. int old_state, int new_state)
  2450. {
  2451. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2452. if (new_state == NLP_STE_UNMAPPED_NODE) {
  2453. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  2454. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  2455. ndlp->nlp_type |= NLP_FC_NODE;
  2456. }
  2457. if (new_state == NLP_STE_MAPPED_NODE)
  2458. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  2459. if (new_state == NLP_STE_NPR_NODE)
  2460. ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
  2461. /* Transport interface */
  2462. if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
  2463. old_state == NLP_STE_UNMAPPED_NODE)) {
  2464. vport->phba->nport_event_cnt++;
  2465. lpfc_unregister_remote_port(ndlp);
  2466. }
  2467. if (new_state == NLP_STE_MAPPED_NODE ||
  2468. new_state == NLP_STE_UNMAPPED_NODE) {
  2469. vport->phba->nport_event_cnt++;
  2470. /*
  2471. * Tell the fc transport about the port, if we haven't
  2472. * already. If we have, and it's a scsi entity, be
  2473. * sure to unblock any attached scsi devices
  2474. */
  2475. lpfc_register_remote_port(vport, ndlp);
  2476. }
  2477. if ((new_state == NLP_STE_MAPPED_NODE) &&
  2478. (vport->stat_data_enabled)) {
  2479. /*
  2480. * A new target is discovered, if there is no buffer for
  2481. * statistical data collection allocate buffer.
  2482. */
  2483. ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
  2484. sizeof(struct lpfc_scsicmd_bkt),
  2485. GFP_KERNEL);
  2486. if (!ndlp->lat_data)
  2487. lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
  2488. "0286 lpfc_nlp_state_cleanup failed to "
  2489. "allocate statistical data buffer DID "
  2490. "0x%x\n", ndlp->nlp_DID);
  2491. }
  2492. /*
  2493. * if we added to Mapped list, but the remote port
  2494. * registration failed or assigned a target id outside
  2495. * our presentable range - move the node to the
  2496. * Unmapped List
  2497. */
  2498. if (new_state == NLP_STE_MAPPED_NODE &&
  2499. (!ndlp->rport ||
  2500. ndlp->rport->scsi_target_id == -1 ||
  2501. ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
  2502. spin_lock_irq(shost->host_lock);
  2503. ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
  2504. spin_unlock_irq(shost->host_lock);
  2505. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2506. }
  2507. }
  2508. static char *
  2509. lpfc_nlp_state_name(char *buffer, size_t size, int state)
  2510. {
  2511. static char *states[] = {
  2512. [NLP_STE_UNUSED_NODE] = "UNUSED",
  2513. [NLP_STE_PLOGI_ISSUE] = "PLOGI",
  2514. [NLP_STE_ADISC_ISSUE] = "ADISC",
  2515. [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
  2516. [NLP_STE_PRLI_ISSUE] = "PRLI",
  2517. [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
  2518. [NLP_STE_MAPPED_NODE] = "MAPPED",
  2519. [NLP_STE_NPR_NODE] = "NPR",
  2520. };
  2521. if (state < NLP_STE_MAX_STATE && states[state])
  2522. strlcpy(buffer, states[state], size);
  2523. else
  2524. snprintf(buffer, size, "unknown (%d)", state);
  2525. return buffer;
  2526. }
  2527. void
  2528. lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2529. int state)
  2530. {
  2531. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2532. int old_state = ndlp->nlp_state;
  2533. char name1[16], name2[16];
  2534. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2535. "0904 NPort state transition x%06x, %s -> %s\n",
  2536. ndlp->nlp_DID,
  2537. lpfc_nlp_state_name(name1, sizeof(name1), old_state),
  2538. lpfc_nlp_state_name(name2, sizeof(name2), state));
  2539. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  2540. "node statechg did:x%x old:%d ste:%d",
  2541. ndlp->nlp_DID, old_state, state);
  2542. if (old_state == NLP_STE_NPR_NODE &&
  2543. state != NLP_STE_NPR_NODE)
  2544. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2545. if (old_state == NLP_STE_UNMAPPED_NODE) {
  2546. ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
  2547. ndlp->nlp_type &= ~NLP_FC_NODE;
  2548. }
  2549. if (list_empty(&ndlp->nlp_listp)) {
  2550. spin_lock_irq(shost->host_lock);
  2551. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  2552. spin_unlock_irq(shost->host_lock);
  2553. } else if (old_state)
  2554. lpfc_nlp_counters(vport, old_state, -1);
  2555. ndlp->nlp_state = state;
  2556. lpfc_nlp_counters(vport, state, 1);
  2557. lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
  2558. }
  2559. void
  2560. lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2561. {
  2562. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2563. if (list_empty(&ndlp->nlp_listp)) {
  2564. spin_lock_irq(shost->host_lock);
  2565. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  2566. spin_unlock_irq(shost->host_lock);
  2567. }
  2568. }
  2569. void
  2570. lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2571. {
  2572. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2573. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2574. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  2575. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  2576. spin_lock_irq(shost->host_lock);
  2577. list_del_init(&ndlp->nlp_listp);
  2578. spin_unlock_irq(shost->host_lock);
  2579. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  2580. NLP_STE_UNUSED_NODE);
  2581. }
  2582. static void
  2583. lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2584. {
  2585. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2586. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  2587. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  2588. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  2589. NLP_STE_UNUSED_NODE);
  2590. }
  2591. /**
  2592. * lpfc_initialize_node - Initialize all fields of node object
  2593. * @vport: Pointer to Virtual Port object.
  2594. * @ndlp: Pointer to FC node object.
  2595. * @did: FC_ID of the node.
  2596. *
  2597. * This function is always called when node object need to be initialized.
  2598. * It initializes all the fields of the node object. Although the reference
  2599. * to phba from @ndlp can be obtained indirectly through it's reference to
  2600. * @vport, a direct reference to phba is taken here by @ndlp. This is due
  2601. * to the life-span of the @ndlp might go beyond the existence of @vport as
  2602. * the final release of ndlp is determined by its reference count. And, the
  2603. * operation on @ndlp needs the reference to phba.
  2604. **/
  2605. static inline void
  2606. lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2607. uint32_t did)
  2608. {
  2609. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  2610. INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
  2611. init_timer(&ndlp->nlp_delayfunc);
  2612. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  2613. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  2614. ndlp->nlp_DID = did;
  2615. ndlp->vport = vport;
  2616. ndlp->phba = vport->phba;
  2617. ndlp->nlp_sid = NLP_NO_SID;
  2618. kref_init(&ndlp->kref);
  2619. NLP_INT_NODE_ACT(ndlp);
  2620. atomic_set(&ndlp->cmd_pending, 0);
  2621. ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
  2622. }
  2623. struct lpfc_nodelist *
  2624. lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2625. int state)
  2626. {
  2627. struct lpfc_hba *phba = vport->phba;
  2628. uint32_t did;
  2629. unsigned long flags;
  2630. if (!ndlp)
  2631. return NULL;
  2632. spin_lock_irqsave(&phba->ndlp_lock, flags);
  2633. /* The ndlp should not be in memory free mode */
  2634. if (NLP_CHK_FREE_REQ(ndlp)) {
  2635. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2636. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2637. "0277 lpfc_enable_node: ndlp:x%p "
  2638. "usgmap:x%x refcnt:%d\n",
  2639. (void *)ndlp, ndlp->nlp_usg_map,
  2640. atomic_read(&ndlp->kref.refcount));
  2641. return NULL;
  2642. }
  2643. /* The ndlp should not already be in active mode */
  2644. if (NLP_CHK_NODE_ACT(ndlp)) {
  2645. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2646. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2647. "0278 lpfc_enable_node: ndlp:x%p "
  2648. "usgmap:x%x refcnt:%d\n",
  2649. (void *)ndlp, ndlp->nlp_usg_map,
  2650. atomic_read(&ndlp->kref.refcount));
  2651. return NULL;
  2652. }
  2653. /* Keep the original DID */
  2654. did = ndlp->nlp_DID;
  2655. /* re-initialize ndlp except of ndlp linked list pointer */
  2656. memset((((char *)ndlp) + sizeof (struct list_head)), 0,
  2657. sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
  2658. lpfc_initialize_node(vport, ndlp, did);
  2659. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2660. if (state != NLP_STE_UNUSED_NODE)
  2661. lpfc_nlp_set_state(vport, ndlp, state);
  2662. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  2663. "node enable: did:x%x",
  2664. ndlp->nlp_DID, 0, 0);
  2665. return ndlp;
  2666. }
  2667. void
  2668. lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2669. {
  2670. /*
  2671. * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
  2672. * be used if we wish to issue the "last" lpfc_nlp_put() to remove
  2673. * the ndlp from the vport. The ndlp marked as UNUSED on the list
  2674. * until ALL other outstanding threads have completed. We check
  2675. * that the ndlp not already in the UNUSED state before we proceed.
  2676. */
  2677. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  2678. return;
  2679. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
  2680. lpfc_nlp_put(ndlp);
  2681. return;
  2682. }
  2683. /*
  2684. * Start / ReStart rescue timer for Discovery / RSCN handling
  2685. */
  2686. void
  2687. lpfc_set_disctmo(struct lpfc_vport *vport)
  2688. {
  2689. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2690. struct lpfc_hba *phba = vport->phba;
  2691. uint32_t tmo;
  2692. if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
  2693. /* For FAN, timeout should be greater than edtov */
  2694. tmo = (((phba->fc_edtov + 999) / 1000) + 1);
  2695. } else {
  2696. /* Normal discovery timeout should be > than ELS/CT timeout
  2697. * FC spec states we need 3 * ratov for CT requests
  2698. */
  2699. tmo = ((phba->fc_ratov * 3) + 3);
  2700. }
  2701. if (!timer_pending(&vport->fc_disctmo)) {
  2702. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2703. "set disc timer: tmo:x%x state:x%x flg:x%x",
  2704. tmo, vport->port_state, vport->fc_flag);
  2705. }
  2706. mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
  2707. spin_lock_irq(shost->host_lock);
  2708. vport->fc_flag |= FC_DISC_TMO;
  2709. spin_unlock_irq(shost->host_lock);
  2710. /* Start Discovery Timer state <hba_state> */
  2711. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2712. "0247 Start Discovery Timer state x%x "
  2713. "Data: x%x x%lx x%x x%x\n",
  2714. vport->port_state, tmo,
  2715. (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
  2716. vport->fc_adisc_cnt);
  2717. return;
  2718. }
  2719. /*
  2720. * Cancel rescue timer for Discovery / RSCN handling
  2721. */
  2722. int
  2723. lpfc_can_disctmo(struct lpfc_vport *vport)
  2724. {
  2725. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2726. unsigned long iflags;
  2727. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2728. "can disc timer: state:x%x rtry:x%x flg:x%x",
  2729. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  2730. /* Turn off discovery timer if its running */
  2731. if (vport->fc_flag & FC_DISC_TMO) {
  2732. spin_lock_irqsave(shost->host_lock, iflags);
  2733. vport->fc_flag &= ~FC_DISC_TMO;
  2734. spin_unlock_irqrestore(shost->host_lock, iflags);
  2735. del_timer_sync(&vport->fc_disctmo);
  2736. spin_lock_irqsave(&vport->work_port_lock, iflags);
  2737. vport->work_port_events &= ~WORKER_DISC_TMO;
  2738. spin_unlock_irqrestore(&vport->work_port_lock, iflags);
  2739. }
  2740. /* Cancel Discovery Timer state <hba_state> */
  2741. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2742. "0248 Cancel Discovery Timer state x%x "
  2743. "Data: x%x x%x x%x\n",
  2744. vport->port_state, vport->fc_flag,
  2745. vport->fc_plogi_cnt, vport->fc_adisc_cnt);
  2746. return 0;
  2747. }
  2748. /*
  2749. * Check specified ring for outstanding IOCB on the SLI queue
  2750. * Return true if iocb matches the specified nport
  2751. */
  2752. int
  2753. lpfc_check_sli_ndlp(struct lpfc_hba *phba,
  2754. struct lpfc_sli_ring *pring,
  2755. struct lpfc_iocbq *iocb,
  2756. struct lpfc_nodelist *ndlp)
  2757. {
  2758. struct lpfc_sli *psli = &phba->sli;
  2759. IOCB_t *icmd = &iocb->iocb;
  2760. struct lpfc_vport *vport = ndlp->vport;
  2761. if (iocb->vport != vport)
  2762. return 0;
  2763. if (pring->ringno == LPFC_ELS_RING) {
  2764. switch (icmd->ulpCommand) {
  2765. case CMD_GEN_REQUEST64_CR:
  2766. if (iocb->context_un.ndlp == ndlp)
  2767. return 1;
  2768. case CMD_ELS_REQUEST64_CR:
  2769. if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
  2770. return 1;
  2771. case CMD_XMIT_ELS_RSP64_CX:
  2772. if (iocb->context1 == (uint8_t *) ndlp)
  2773. return 1;
  2774. }
  2775. } else if (pring->ringno == psli->extra_ring) {
  2776. } else if (pring->ringno == psli->fcp_ring) {
  2777. /* Skip match check if waiting to relogin to FCP target */
  2778. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  2779. (ndlp->nlp_flag & NLP_DELAY_TMO)) {
  2780. return 0;
  2781. }
  2782. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
  2783. return 1;
  2784. }
  2785. } else if (pring->ringno == psli->next_ring) {
  2786. }
  2787. return 0;
  2788. }
  2789. /*
  2790. * Free resources / clean up outstanding I/Os
  2791. * associated with nlp_rpi in the LPFC_NODELIST entry.
  2792. */
  2793. static int
  2794. lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  2795. {
  2796. LIST_HEAD(completions);
  2797. struct lpfc_sli *psli;
  2798. struct lpfc_sli_ring *pring;
  2799. struct lpfc_iocbq *iocb, *next_iocb;
  2800. uint32_t rpi, i;
  2801. lpfc_fabric_abort_nport(ndlp);
  2802. /*
  2803. * Everything that matches on txcmplq will be returned
  2804. * by firmware with a no rpi error.
  2805. */
  2806. psli = &phba->sli;
  2807. rpi = ndlp->nlp_rpi;
  2808. if (ndlp->nlp_flag & NLP_RPI_VALID) {
  2809. /* Now process each ring */
  2810. for (i = 0; i < psli->num_rings; i++) {
  2811. pring = &psli->ring[i];
  2812. spin_lock_irq(&phba->hbalock);
  2813. list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
  2814. list) {
  2815. /*
  2816. * Check to see if iocb matches the nport we are
  2817. * looking for
  2818. */
  2819. if ((lpfc_check_sli_ndlp(phba, pring, iocb,
  2820. ndlp))) {
  2821. /* It matches, so deque and call compl
  2822. with an error */
  2823. list_move_tail(&iocb->list,
  2824. &completions);
  2825. pring->txq_cnt--;
  2826. }
  2827. }
  2828. spin_unlock_irq(&phba->hbalock);
  2829. }
  2830. }
  2831. /* Cancel all the IOCBs from the completions list */
  2832. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2833. IOERR_SLI_ABORTED);
  2834. return 0;
  2835. }
  2836. /*
  2837. * Free rpi associated with LPFC_NODELIST entry.
  2838. * This routine is called from lpfc_freenode(), when we are removing
  2839. * a LPFC_NODELIST entry. It is also called if the driver initiates a
  2840. * LOGO that completes successfully, and we are waiting to PLOGI back
  2841. * to the remote NPort. In addition, it is called after we receive
  2842. * and unsolicated ELS cmd, send back a rsp, the rsp completes and
  2843. * we are waiting to PLOGI back to the remote NPort.
  2844. */
  2845. int
  2846. lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2847. {
  2848. struct lpfc_hba *phba = vport->phba;
  2849. LPFC_MBOXQ_t *mbox;
  2850. int rc;
  2851. if (ndlp->nlp_flag & NLP_RPI_VALID) {
  2852. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2853. if (mbox) {
  2854. lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
  2855. mbox->vport = vport;
  2856. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2857. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2858. if (rc == MBX_NOT_FINISHED)
  2859. mempool_free(mbox, phba->mbox_mem_pool);
  2860. }
  2861. lpfc_no_rpi(phba, ndlp);
  2862. ndlp->nlp_rpi = 0;
  2863. ndlp->nlp_flag &= ~NLP_RPI_VALID;
  2864. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2865. return 1;
  2866. }
  2867. return 0;
  2868. }
  2869. void
  2870. lpfc_unreg_all_rpis(struct lpfc_vport *vport)
  2871. {
  2872. struct lpfc_hba *phba = vport->phba;
  2873. LPFC_MBOXQ_t *mbox;
  2874. int rc;
  2875. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2876. if (mbox) {
  2877. lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
  2878. mbox->vport = vport;
  2879. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2880. mbox->context1 = NULL;
  2881. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  2882. if (rc != MBX_TIMEOUT)
  2883. mempool_free(mbox, phba->mbox_mem_pool);
  2884. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  2885. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  2886. "1836 Could not issue "
  2887. "unreg_login(all_rpis) status %d\n", rc);
  2888. }
  2889. }
  2890. void
  2891. lpfc_unreg_default_rpis(struct lpfc_vport *vport)
  2892. {
  2893. struct lpfc_hba *phba = vport->phba;
  2894. LPFC_MBOXQ_t *mbox;
  2895. int rc;
  2896. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2897. if (mbox) {
  2898. lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
  2899. mbox->vport = vport;
  2900. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2901. mbox->context1 = NULL;
  2902. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  2903. if (rc != MBX_TIMEOUT)
  2904. mempool_free(mbox, phba->mbox_mem_pool);
  2905. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  2906. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  2907. "1815 Could not issue "
  2908. "unreg_did (default rpis) status %d\n",
  2909. rc);
  2910. }
  2911. }
  2912. /*
  2913. * Free resources associated with LPFC_NODELIST entry
  2914. * so it can be freed.
  2915. */
  2916. static int
  2917. lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2918. {
  2919. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2920. struct lpfc_hba *phba = vport->phba;
  2921. LPFC_MBOXQ_t *mb, *nextmb;
  2922. struct lpfc_dmabuf *mp;
  2923. /* Cleanup node for NPort <nlp_DID> */
  2924. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2925. "0900 Cleanup node for NPort x%x "
  2926. "Data: x%x x%x x%x\n",
  2927. ndlp->nlp_DID, ndlp->nlp_flag,
  2928. ndlp->nlp_state, ndlp->nlp_rpi);
  2929. if (NLP_CHK_FREE_REQ(ndlp)) {
  2930. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2931. "0280 lpfc_cleanup_node: ndlp:x%p "
  2932. "usgmap:x%x refcnt:%d\n",
  2933. (void *)ndlp, ndlp->nlp_usg_map,
  2934. atomic_read(&ndlp->kref.refcount));
  2935. lpfc_dequeue_node(vport, ndlp);
  2936. } else {
  2937. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2938. "0281 lpfc_cleanup_node: ndlp:x%p "
  2939. "usgmap:x%x refcnt:%d\n",
  2940. (void *)ndlp, ndlp->nlp_usg_map,
  2941. atomic_read(&ndlp->kref.refcount));
  2942. lpfc_disable_node(vport, ndlp);
  2943. }
  2944. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  2945. if ((mb = phba->sli.mbox_active)) {
  2946. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  2947. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  2948. mb->context2 = NULL;
  2949. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2950. }
  2951. }
  2952. spin_lock_irq(&phba->hbalock);
  2953. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  2954. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  2955. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  2956. mp = (struct lpfc_dmabuf *) (mb->context1);
  2957. if (mp) {
  2958. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2959. kfree(mp);
  2960. }
  2961. list_del(&mb->list);
  2962. mempool_free(mb, phba->mbox_mem_pool);
  2963. /* We shall not invoke the lpfc_nlp_put to decrement
  2964. * the ndlp reference count as we are in the process
  2965. * of lpfc_nlp_release.
  2966. */
  2967. }
  2968. }
  2969. spin_unlock_irq(&phba->hbalock);
  2970. lpfc_els_abort(phba, ndlp);
  2971. spin_lock_irq(shost->host_lock);
  2972. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  2973. spin_unlock_irq(shost->host_lock);
  2974. ndlp->nlp_last_elscmd = 0;
  2975. del_timer_sync(&ndlp->nlp_delayfunc);
  2976. list_del_init(&ndlp->els_retry_evt.evt_listp);
  2977. list_del_init(&ndlp->dev_loss_evt.evt_listp);
  2978. lpfc_unreg_rpi(vport, ndlp);
  2979. return 0;
  2980. }
  2981. /*
  2982. * Check to see if we can free the nlp back to the freelist.
  2983. * If we are in the middle of using the nlp in the discovery state
  2984. * machine, defer the free till we reach the end of the state machine.
  2985. */
  2986. static void
  2987. lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2988. {
  2989. struct lpfc_hba *phba = vport->phba;
  2990. struct lpfc_rport_data *rdata;
  2991. LPFC_MBOXQ_t *mbox;
  2992. int rc;
  2993. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2994. if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
  2995. !(ndlp->nlp_flag & NLP_RPI_VALID)) {
  2996. /* For this case we need to cleanup the default rpi
  2997. * allocated by the firmware.
  2998. */
  2999. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
  3000. != NULL) {
  3001. rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
  3002. (uint8_t *) &vport->fc_sparam, mbox, 0);
  3003. if (rc) {
  3004. mempool_free(mbox, phba->mbox_mem_pool);
  3005. }
  3006. else {
  3007. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  3008. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  3009. mbox->vport = vport;
  3010. mbox->context2 = NULL;
  3011. rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3012. if (rc == MBX_NOT_FINISHED) {
  3013. mempool_free(mbox, phba->mbox_mem_pool);
  3014. }
  3015. }
  3016. }
  3017. }
  3018. lpfc_cleanup_node(vport, ndlp);
  3019. /*
  3020. * We can get here with a non-NULL ndlp->rport because when we
  3021. * unregister a rport we don't break the rport/node linkage. So if we
  3022. * do, make sure we don't leaving any dangling pointers behind.
  3023. */
  3024. if (ndlp->rport) {
  3025. rdata = ndlp->rport->dd_data;
  3026. rdata->pnode = NULL;
  3027. ndlp->rport = NULL;
  3028. }
  3029. }
  3030. static int
  3031. lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3032. uint32_t did)
  3033. {
  3034. D_ID mydid, ndlpdid, matchdid;
  3035. if (did == Bcast_DID)
  3036. return 0;
  3037. /* First check for Direct match */
  3038. if (ndlp->nlp_DID == did)
  3039. return 1;
  3040. /* Next check for area/domain identically equals 0 match */
  3041. mydid.un.word = vport->fc_myDID;
  3042. if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
  3043. return 0;
  3044. }
  3045. matchdid.un.word = did;
  3046. ndlpdid.un.word = ndlp->nlp_DID;
  3047. if (matchdid.un.b.id == ndlpdid.un.b.id) {
  3048. if ((mydid.un.b.domain == matchdid.un.b.domain) &&
  3049. (mydid.un.b.area == matchdid.un.b.area)) {
  3050. if ((ndlpdid.un.b.domain == 0) &&
  3051. (ndlpdid.un.b.area == 0)) {
  3052. if (ndlpdid.un.b.id)
  3053. return 1;
  3054. }
  3055. return 0;
  3056. }
  3057. matchdid.un.word = ndlp->nlp_DID;
  3058. if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
  3059. (mydid.un.b.area == ndlpdid.un.b.area)) {
  3060. if ((matchdid.un.b.domain == 0) &&
  3061. (matchdid.un.b.area == 0)) {
  3062. if (matchdid.un.b.id)
  3063. return 1;
  3064. }
  3065. }
  3066. }
  3067. return 0;
  3068. }
  3069. /* Search for a nodelist entry */
  3070. static struct lpfc_nodelist *
  3071. __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  3072. {
  3073. struct lpfc_nodelist *ndlp;
  3074. uint32_t data1;
  3075. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  3076. if (lpfc_matchdid(vport, ndlp, did)) {
  3077. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  3078. ((uint32_t) ndlp->nlp_xri << 16) |
  3079. ((uint32_t) ndlp->nlp_type << 8) |
  3080. ((uint32_t) ndlp->nlp_rpi & 0xff));
  3081. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3082. "0929 FIND node DID "
  3083. "Data: x%p x%x x%x x%x\n",
  3084. ndlp, ndlp->nlp_DID,
  3085. ndlp->nlp_flag, data1);
  3086. return ndlp;
  3087. }
  3088. }
  3089. /* FIND node did <did> NOT FOUND */
  3090. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3091. "0932 FIND node did x%x NOT FOUND.\n", did);
  3092. return NULL;
  3093. }
  3094. struct lpfc_nodelist *
  3095. lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  3096. {
  3097. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3098. struct lpfc_nodelist *ndlp;
  3099. spin_lock_irq(shost->host_lock);
  3100. ndlp = __lpfc_findnode_did(vport, did);
  3101. spin_unlock_irq(shost->host_lock);
  3102. return ndlp;
  3103. }
  3104. struct lpfc_nodelist *
  3105. lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
  3106. {
  3107. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3108. struct lpfc_nodelist *ndlp;
  3109. ndlp = lpfc_findnode_did(vport, did);
  3110. if (!ndlp) {
  3111. if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
  3112. lpfc_rscn_payload_check(vport, did) == 0)
  3113. return NULL;
  3114. ndlp = (struct lpfc_nodelist *)
  3115. mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
  3116. if (!ndlp)
  3117. return NULL;
  3118. lpfc_nlp_init(vport, ndlp, did);
  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. return ndlp;
  3124. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3125. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
  3126. if (!ndlp)
  3127. return NULL;
  3128. spin_lock_irq(shost->host_lock);
  3129. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3130. spin_unlock_irq(shost->host_lock);
  3131. return ndlp;
  3132. }
  3133. if ((vport->fc_flag & FC_RSCN_MODE) &&
  3134. !(vport->fc_flag & FC_NDISC_ACTIVE)) {
  3135. if (lpfc_rscn_payload_check(vport, did)) {
  3136. /* If we've already recieved a PLOGI from this NPort
  3137. * we don't need to try to discover it again.
  3138. */
  3139. if (ndlp->nlp_flag & NLP_RCV_PLOGI)
  3140. return NULL;
  3141. /* Since this node is marked for discovery,
  3142. * delay timeout is not needed.
  3143. */
  3144. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3145. spin_lock_irq(shost->host_lock);
  3146. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3147. spin_unlock_irq(shost->host_lock);
  3148. } else
  3149. ndlp = NULL;
  3150. } else {
  3151. /* If we've already recieved a PLOGI from this NPort,
  3152. * or we are already in the process of discovery on it,
  3153. * we don't need to try to discover it again.
  3154. */
  3155. if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
  3156. ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  3157. ndlp->nlp_flag & NLP_RCV_PLOGI)
  3158. return NULL;
  3159. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3160. spin_lock_irq(shost->host_lock);
  3161. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3162. spin_unlock_irq(shost->host_lock);
  3163. }
  3164. return ndlp;
  3165. }
  3166. /* Build a list of nodes to discover based on the loopmap */
  3167. void
  3168. lpfc_disc_list_loopmap(struct lpfc_vport *vport)
  3169. {
  3170. struct lpfc_hba *phba = vport->phba;
  3171. int j;
  3172. uint32_t alpa, index;
  3173. if (!lpfc_is_link_up(phba))
  3174. return;
  3175. if (phba->fc_topology != TOPOLOGY_LOOP)
  3176. return;
  3177. /* Check for loop map present or not */
  3178. if (phba->alpa_map[0]) {
  3179. for (j = 1; j <= phba->alpa_map[0]; j++) {
  3180. alpa = phba->alpa_map[j];
  3181. if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
  3182. continue;
  3183. lpfc_setup_disc_node(vport, alpa);
  3184. }
  3185. } else {
  3186. /* No alpamap, so try all alpa's */
  3187. for (j = 0; j < FC_MAXLOOP; j++) {
  3188. /* If cfg_scan_down is set, start from highest
  3189. * ALPA (0xef) to lowest (0x1).
  3190. */
  3191. if (vport->cfg_scan_down)
  3192. index = j;
  3193. else
  3194. index = FC_MAXLOOP - j - 1;
  3195. alpa = lpfcAlpaArray[index];
  3196. if ((vport->fc_myDID & 0xff) == alpa)
  3197. continue;
  3198. lpfc_setup_disc_node(vport, alpa);
  3199. }
  3200. }
  3201. return;
  3202. }
  3203. void
  3204. lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
  3205. {
  3206. LPFC_MBOXQ_t *mbox;
  3207. struct lpfc_sli *psli = &phba->sli;
  3208. struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
  3209. struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
  3210. struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
  3211. int rc;
  3212. /*
  3213. * if it's not a physical port or if we already send
  3214. * clear_la then don't send it.
  3215. */
  3216. if ((phba->link_state >= LPFC_CLEAR_LA) ||
  3217. (vport->port_type != LPFC_PHYSICAL_PORT) ||
  3218. (phba->sli_rev == LPFC_SLI_REV4))
  3219. return;
  3220. /* Link up discovery */
  3221. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
  3222. phba->link_state = LPFC_CLEAR_LA;
  3223. lpfc_clear_la(phba, mbox);
  3224. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  3225. mbox->vport = vport;
  3226. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3227. if (rc == MBX_NOT_FINISHED) {
  3228. mempool_free(mbox, phba->mbox_mem_pool);
  3229. lpfc_disc_flush_list(vport);
  3230. extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  3231. fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  3232. next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  3233. phba->link_state = LPFC_HBA_ERROR;
  3234. }
  3235. }
  3236. }
  3237. /* Reg_vpi to tell firmware to resume normal operations */
  3238. void
  3239. lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  3240. {
  3241. LPFC_MBOXQ_t *regvpimbox;
  3242. regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3243. if (regvpimbox) {
  3244. lpfc_reg_vpi(vport, regvpimbox);
  3245. regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
  3246. regvpimbox->vport = vport;
  3247. if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
  3248. == MBX_NOT_FINISHED) {
  3249. mempool_free(regvpimbox, phba->mbox_mem_pool);
  3250. }
  3251. }
  3252. }
  3253. /* Start Link up / RSCN discovery on NPR nodes */
  3254. void
  3255. lpfc_disc_start(struct lpfc_vport *vport)
  3256. {
  3257. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3258. struct lpfc_hba *phba = vport->phba;
  3259. uint32_t num_sent;
  3260. uint32_t clear_la_pending;
  3261. int did_changed;
  3262. if (!lpfc_is_link_up(phba))
  3263. return;
  3264. if (phba->link_state == LPFC_CLEAR_LA)
  3265. clear_la_pending = 1;
  3266. else
  3267. clear_la_pending = 0;
  3268. if (vport->port_state < LPFC_VPORT_READY)
  3269. vport->port_state = LPFC_DISC_AUTH;
  3270. lpfc_set_disctmo(vport);
  3271. if (vport->fc_prevDID == vport->fc_myDID)
  3272. did_changed = 0;
  3273. else
  3274. did_changed = 1;
  3275. vport->fc_prevDID = vport->fc_myDID;
  3276. vport->num_disc_nodes = 0;
  3277. /* Start Discovery state <hba_state> */
  3278. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3279. "0202 Start Discovery hba state x%x "
  3280. "Data: x%x x%x x%x\n",
  3281. vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
  3282. vport->fc_adisc_cnt);
  3283. /* First do ADISCs - if any */
  3284. num_sent = lpfc_els_disc_adisc(vport);
  3285. if (num_sent)
  3286. return;
  3287. /*
  3288. * For SLI3, cmpl_reg_vpi will set port_state to READY, and
  3289. * continue discovery.
  3290. */
  3291. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3292. !(vport->fc_flag & FC_PT2PT) &&
  3293. !(vport->fc_flag & FC_RSCN_MODE) &&
  3294. (phba->sli_rev < LPFC_SLI_REV4)) {
  3295. lpfc_issue_reg_vpi(phba, vport);
  3296. return;
  3297. }
  3298. /*
  3299. * For SLI2, we need to set port_state to READY and continue
  3300. * discovery.
  3301. */
  3302. if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
  3303. /* If we get here, there is nothing to ADISC */
  3304. if (vport->port_type == LPFC_PHYSICAL_PORT)
  3305. lpfc_issue_clear_la(phba, vport);
  3306. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  3307. vport->num_disc_nodes = 0;
  3308. /* go thru NPR nodes and issue ELS PLOGIs */
  3309. if (vport->fc_npr_cnt)
  3310. lpfc_els_disc_plogi(vport);
  3311. if (!vport->num_disc_nodes) {
  3312. spin_lock_irq(shost->host_lock);
  3313. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  3314. spin_unlock_irq(shost->host_lock);
  3315. lpfc_can_disctmo(vport);
  3316. }
  3317. }
  3318. vport->port_state = LPFC_VPORT_READY;
  3319. } else {
  3320. /* Next do PLOGIs - if any */
  3321. num_sent = lpfc_els_disc_plogi(vport);
  3322. if (num_sent)
  3323. return;
  3324. if (vport->fc_flag & FC_RSCN_MODE) {
  3325. /* Check to see if more RSCNs came in while we
  3326. * were processing this one.
  3327. */
  3328. if ((vport->fc_rscn_id_cnt == 0) &&
  3329. (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
  3330. spin_lock_irq(shost->host_lock);
  3331. vport->fc_flag &= ~FC_RSCN_MODE;
  3332. spin_unlock_irq(shost->host_lock);
  3333. lpfc_can_disctmo(vport);
  3334. } else
  3335. lpfc_els_handle_rscn(vport);
  3336. }
  3337. }
  3338. return;
  3339. }
  3340. /*
  3341. * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
  3342. * ring the match the sppecified nodelist.
  3343. */
  3344. static void
  3345. lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  3346. {
  3347. LIST_HEAD(completions);
  3348. struct lpfc_sli *psli;
  3349. IOCB_t *icmd;
  3350. struct lpfc_iocbq *iocb, *next_iocb;
  3351. struct lpfc_sli_ring *pring;
  3352. psli = &phba->sli;
  3353. pring = &psli->ring[LPFC_ELS_RING];
  3354. /* Error matching iocb on txq or txcmplq
  3355. * First check the txq.
  3356. */
  3357. spin_lock_irq(&phba->hbalock);
  3358. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  3359. if (iocb->context1 != ndlp) {
  3360. continue;
  3361. }
  3362. icmd = &iocb->iocb;
  3363. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  3364. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  3365. list_move_tail(&iocb->list, &completions);
  3366. pring->txq_cnt--;
  3367. }
  3368. }
  3369. /* Next check the txcmplq */
  3370. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  3371. if (iocb->context1 != ndlp) {
  3372. continue;
  3373. }
  3374. icmd = &iocb->iocb;
  3375. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
  3376. icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
  3377. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3378. }
  3379. }
  3380. spin_unlock_irq(&phba->hbalock);
  3381. /* Cancel all the IOCBs from the completions list */
  3382. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3383. IOERR_SLI_ABORTED);
  3384. }
  3385. static void
  3386. lpfc_disc_flush_list(struct lpfc_vport *vport)
  3387. {
  3388. struct lpfc_nodelist *ndlp, *next_ndlp;
  3389. struct lpfc_hba *phba = vport->phba;
  3390. if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
  3391. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  3392. nlp_listp) {
  3393. if (!NLP_CHK_NODE_ACT(ndlp))
  3394. continue;
  3395. if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  3396. ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
  3397. lpfc_free_tx(phba, ndlp);
  3398. }
  3399. }
  3400. }
  3401. }
  3402. void
  3403. lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
  3404. {
  3405. lpfc_els_flush_rscn(vport);
  3406. lpfc_els_flush_cmd(vport);
  3407. lpfc_disc_flush_list(vport);
  3408. }
  3409. /*****************************************************************************/
  3410. /*
  3411. * NAME: lpfc_disc_timeout
  3412. *
  3413. * FUNCTION: Fibre Channel driver discovery timeout routine.
  3414. *
  3415. * EXECUTION ENVIRONMENT: interrupt only
  3416. *
  3417. * CALLED FROM:
  3418. * Timer function
  3419. *
  3420. * RETURNS:
  3421. * none
  3422. */
  3423. /*****************************************************************************/
  3424. void
  3425. lpfc_disc_timeout(unsigned long ptr)
  3426. {
  3427. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  3428. struct lpfc_hba *phba = vport->phba;
  3429. uint32_t tmo_posted;
  3430. unsigned long flags = 0;
  3431. if (unlikely(!phba))
  3432. return;
  3433. spin_lock_irqsave(&vport->work_port_lock, flags);
  3434. tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
  3435. if (!tmo_posted)
  3436. vport->work_port_events |= WORKER_DISC_TMO;
  3437. spin_unlock_irqrestore(&vport->work_port_lock, flags);
  3438. if (!tmo_posted)
  3439. lpfc_worker_wake_up(phba);
  3440. return;
  3441. }
  3442. static void
  3443. lpfc_disc_timeout_handler(struct lpfc_vport *vport)
  3444. {
  3445. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3446. struct lpfc_hba *phba = vport->phba;
  3447. struct lpfc_sli *psli = &phba->sli;
  3448. struct lpfc_nodelist *ndlp, *next_ndlp;
  3449. LPFC_MBOXQ_t *initlinkmbox;
  3450. int rc, clrlaerr = 0;
  3451. if (!(vport->fc_flag & FC_DISC_TMO))
  3452. return;
  3453. spin_lock_irq(shost->host_lock);
  3454. vport->fc_flag &= ~FC_DISC_TMO;
  3455. spin_unlock_irq(shost->host_lock);
  3456. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3457. "disc timeout: state:x%x rtry:x%x flg:x%x",
  3458. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  3459. switch (vport->port_state) {
  3460. case LPFC_LOCAL_CFG_LINK:
  3461. /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
  3462. * FAN
  3463. */
  3464. /* FAN timeout */
  3465. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  3466. "0221 FAN timeout\n");
  3467. /* Start discovery by sending FLOGI, clean up old rpis */
  3468. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  3469. nlp_listp) {
  3470. if (!NLP_CHK_NODE_ACT(ndlp))
  3471. continue;
  3472. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  3473. continue;
  3474. if (ndlp->nlp_type & NLP_FABRIC) {
  3475. /* Clean up the ndlp on Fabric connections */
  3476. lpfc_drop_node(vport, ndlp);
  3477. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  3478. /* Fail outstanding IO now since device
  3479. * is marked for PLOGI.
  3480. */
  3481. lpfc_unreg_rpi(vport, ndlp);
  3482. }
  3483. }
  3484. if (vport->port_state != LPFC_FLOGI) {
  3485. lpfc_initial_flogi(vport);
  3486. return;
  3487. }
  3488. break;
  3489. case LPFC_FDISC:
  3490. case LPFC_FLOGI:
  3491. /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
  3492. /* Initial FLOGI timeout */
  3493. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3494. "0222 Initial %s timeout\n",
  3495. vport->vpi ? "FDISC" : "FLOGI");
  3496. /* Assume no Fabric and go on with discovery.
  3497. * Check for outstanding ELS FLOGI to abort.
  3498. */
  3499. /* FLOGI failed, so just use loop map to make discovery list */
  3500. lpfc_disc_list_loopmap(vport);
  3501. /* Start discovery */
  3502. lpfc_disc_start(vport);
  3503. break;
  3504. case LPFC_FABRIC_CFG_LINK:
  3505. /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
  3506. NameServer login */
  3507. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3508. "0223 Timeout while waiting for "
  3509. "NameServer login\n");
  3510. /* Next look for NameServer ndlp */
  3511. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  3512. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  3513. lpfc_els_abort(phba, ndlp);
  3514. /* ReStart discovery */
  3515. goto restart_disc;
  3516. case LPFC_NS_QRY:
  3517. /* Check for wait for NameServer Rsp timeout */
  3518. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3519. "0224 NameServer Query timeout "
  3520. "Data: x%x x%x\n",
  3521. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  3522. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  3523. /* Try it one more time */
  3524. vport->fc_ns_retry++;
  3525. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  3526. vport->fc_ns_retry, 0);
  3527. if (rc == 0)
  3528. break;
  3529. }
  3530. vport->fc_ns_retry = 0;
  3531. restart_disc:
  3532. /*
  3533. * Discovery is over.
  3534. * set port_state to PORT_READY if SLI2.
  3535. * cmpl_reg_vpi will set port_state to READY for SLI3.
  3536. */
  3537. if (phba->sli_rev < LPFC_SLI_REV4) {
  3538. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  3539. lpfc_issue_reg_vpi(phba, vport);
  3540. else { /* NPIV Not enabled */
  3541. lpfc_issue_clear_la(phba, vport);
  3542. vport->port_state = LPFC_VPORT_READY;
  3543. }
  3544. }
  3545. /* Setup and issue mailbox INITIALIZE LINK command */
  3546. initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3547. if (!initlinkmbox) {
  3548. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3549. "0206 Device Discovery "
  3550. "completion error\n");
  3551. phba->link_state = LPFC_HBA_ERROR;
  3552. break;
  3553. }
  3554. lpfc_linkdown(phba);
  3555. lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
  3556. phba->cfg_link_speed);
  3557. initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  3558. initlinkmbox->vport = vport;
  3559. initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3560. rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
  3561. lpfc_set_loopback_flag(phba);
  3562. if (rc == MBX_NOT_FINISHED)
  3563. mempool_free(initlinkmbox, phba->mbox_mem_pool);
  3564. break;
  3565. case LPFC_DISC_AUTH:
  3566. /* Node Authentication timeout */
  3567. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3568. "0227 Node Authentication timeout\n");
  3569. lpfc_disc_flush_list(vport);
  3570. /*
  3571. * set port_state to PORT_READY if SLI2.
  3572. * cmpl_reg_vpi will set port_state to READY for SLI3.
  3573. */
  3574. if (phba->sli_rev < LPFC_SLI_REV4) {
  3575. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  3576. lpfc_issue_reg_vpi(phba, vport);
  3577. else { /* NPIV Not enabled */
  3578. lpfc_issue_clear_la(phba, vport);
  3579. vport->port_state = LPFC_VPORT_READY;
  3580. }
  3581. }
  3582. break;
  3583. case LPFC_VPORT_READY:
  3584. if (vport->fc_flag & FC_RSCN_MODE) {
  3585. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3586. "0231 RSCN timeout Data: x%x "
  3587. "x%x\n",
  3588. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  3589. /* Cleanup any outstanding ELS commands */
  3590. lpfc_els_flush_cmd(vport);
  3591. lpfc_els_flush_rscn(vport);
  3592. lpfc_disc_flush_list(vport);
  3593. }
  3594. break;
  3595. default:
  3596. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3597. "0273 Unexpected discovery timeout, "
  3598. "vport State x%x\n", vport->port_state);
  3599. break;
  3600. }
  3601. switch (phba->link_state) {
  3602. case LPFC_CLEAR_LA:
  3603. /* CLEAR LA timeout */
  3604. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3605. "0228 CLEAR LA timeout\n");
  3606. clrlaerr = 1;
  3607. break;
  3608. case LPFC_LINK_UP:
  3609. lpfc_issue_clear_la(phba, vport);
  3610. /* Drop thru */
  3611. case LPFC_LINK_UNKNOWN:
  3612. case LPFC_WARM_START:
  3613. case LPFC_INIT_START:
  3614. case LPFC_INIT_MBX_CMDS:
  3615. case LPFC_LINK_DOWN:
  3616. case LPFC_HBA_ERROR:
  3617. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3618. "0230 Unexpected timeout, hba link "
  3619. "state x%x\n", phba->link_state);
  3620. clrlaerr = 1;
  3621. break;
  3622. case LPFC_HBA_READY:
  3623. break;
  3624. }
  3625. if (clrlaerr) {
  3626. lpfc_disc_flush_list(vport);
  3627. psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  3628. psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  3629. psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  3630. vport->port_state = LPFC_VPORT_READY;
  3631. }
  3632. return;
  3633. }
  3634. /*
  3635. * This routine handles processing a NameServer REG_LOGIN mailbox
  3636. * command upon completion. It is setup in the LPFC_MBOXQ
  3637. * as the completion routine when the command is
  3638. * handed off to the SLI layer.
  3639. */
  3640. void
  3641. lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3642. {
  3643. MAILBOX_t *mb = &pmb->u.mb;
  3644. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  3645. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3646. struct lpfc_vport *vport = pmb->vport;
  3647. pmb->context1 = NULL;
  3648. ndlp->nlp_rpi = mb->un.varWords[0];
  3649. ndlp->nlp_flag |= NLP_RPI_VALID;
  3650. ndlp->nlp_type |= NLP_FABRIC;
  3651. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  3652. /*
  3653. * Start issuing Fabric-Device Management Interface (FDMI) command to
  3654. * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
  3655. * fdmi-on=2 (supporting RPA/hostnmae)
  3656. */
  3657. if (vport->cfg_fdmi_on == 1)
  3658. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  3659. else
  3660. mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
  3661. /* decrement the node reference count held for this callback
  3662. * function.
  3663. */
  3664. lpfc_nlp_put(ndlp);
  3665. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3666. kfree(mp);
  3667. mempool_free(pmb, phba->mbox_mem_pool);
  3668. return;
  3669. }
  3670. static int
  3671. lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
  3672. {
  3673. uint16_t *rpi = param;
  3674. return ndlp->nlp_rpi == *rpi;
  3675. }
  3676. static int
  3677. lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
  3678. {
  3679. return memcmp(&ndlp->nlp_portname, param,
  3680. sizeof(ndlp->nlp_portname)) == 0;
  3681. }
  3682. static struct lpfc_nodelist *
  3683. __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
  3684. {
  3685. struct lpfc_nodelist *ndlp;
  3686. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  3687. if (filter(ndlp, param))
  3688. return ndlp;
  3689. }
  3690. return NULL;
  3691. }
  3692. /*
  3693. * This routine looks up the ndlp lists for the given RPI. If rpi found it
  3694. * returns the node list element pointer else return NULL.
  3695. */
  3696. struct lpfc_nodelist *
  3697. __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
  3698. {
  3699. return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
  3700. }
  3701. /*
  3702. * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
  3703. * returns the node element list pointer else return NULL.
  3704. */
  3705. struct lpfc_nodelist *
  3706. lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
  3707. {
  3708. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3709. struct lpfc_nodelist *ndlp;
  3710. spin_lock_irq(shost->host_lock);
  3711. ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
  3712. spin_unlock_irq(shost->host_lock);
  3713. return ndlp;
  3714. }
  3715. void
  3716. lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3717. uint32_t did)
  3718. {
  3719. memset(ndlp, 0, sizeof (struct lpfc_nodelist));
  3720. lpfc_initialize_node(vport, ndlp, did);
  3721. INIT_LIST_HEAD(&ndlp->nlp_listp);
  3722. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  3723. "node init: did:x%x",
  3724. ndlp->nlp_DID, 0, 0);
  3725. return;
  3726. }
  3727. /* This routine releases all resources associated with a specifc NPort's ndlp
  3728. * and mempool_free's the nodelist.
  3729. */
  3730. static void
  3731. lpfc_nlp_release(struct kref *kref)
  3732. {
  3733. struct lpfc_hba *phba;
  3734. unsigned long flags;
  3735. struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
  3736. kref);
  3737. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3738. "node release: did:x%x flg:x%x type:x%x",
  3739. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  3740. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
  3741. "0279 lpfc_nlp_release: ndlp:x%p "
  3742. "usgmap:x%x refcnt:%d\n",
  3743. (void *)ndlp, ndlp->nlp_usg_map,
  3744. atomic_read(&ndlp->kref.refcount));
  3745. /* remove ndlp from action. */
  3746. lpfc_nlp_remove(ndlp->vport, ndlp);
  3747. /* clear the ndlp active flag for all release cases */
  3748. phba = ndlp->phba;
  3749. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3750. NLP_CLR_NODE_ACT(ndlp);
  3751. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3752. /* free ndlp memory for final ndlp release */
  3753. if (NLP_CHK_FREE_REQ(ndlp)) {
  3754. kfree(ndlp->lat_data);
  3755. mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
  3756. }
  3757. }
  3758. /* This routine bumps the reference count for a ndlp structure to ensure
  3759. * that one discovery thread won't free a ndlp while another discovery thread
  3760. * is using it.
  3761. */
  3762. struct lpfc_nodelist *
  3763. lpfc_nlp_get(struct lpfc_nodelist *ndlp)
  3764. {
  3765. struct lpfc_hba *phba;
  3766. unsigned long flags;
  3767. if (ndlp) {
  3768. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3769. "node get: did:x%x flg:x%x refcnt:x%x",
  3770. ndlp->nlp_DID, ndlp->nlp_flag,
  3771. atomic_read(&ndlp->kref.refcount));
  3772. /* The check of ndlp usage to prevent incrementing the
  3773. * ndlp reference count that is in the process of being
  3774. * released.
  3775. */
  3776. phba = ndlp->phba;
  3777. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3778. if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
  3779. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3780. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  3781. "0276 lpfc_nlp_get: ndlp:x%p "
  3782. "usgmap:x%x refcnt:%d\n",
  3783. (void *)ndlp, ndlp->nlp_usg_map,
  3784. atomic_read(&ndlp->kref.refcount));
  3785. return NULL;
  3786. } else
  3787. kref_get(&ndlp->kref);
  3788. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3789. }
  3790. return ndlp;
  3791. }
  3792. /* This routine decrements the reference count for a ndlp structure. If the
  3793. * count goes to 0, this indicates the the associated nodelist should be
  3794. * freed. Returning 1 indicates the ndlp resource has been released; on the
  3795. * other hand, returning 0 indicates the ndlp resource has not been released
  3796. * yet.
  3797. */
  3798. int
  3799. lpfc_nlp_put(struct lpfc_nodelist *ndlp)
  3800. {
  3801. struct lpfc_hba *phba;
  3802. unsigned long flags;
  3803. if (!ndlp)
  3804. return 1;
  3805. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3806. "node put: did:x%x flg:x%x refcnt:x%x",
  3807. ndlp->nlp_DID, ndlp->nlp_flag,
  3808. atomic_read(&ndlp->kref.refcount));
  3809. phba = ndlp->phba;
  3810. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3811. /* Check the ndlp memory free acknowledge flag to avoid the
  3812. * possible race condition that kref_put got invoked again
  3813. * after previous one has done ndlp memory free.
  3814. */
  3815. if (NLP_CHK_FREE_ACK(ndlp)) {
  3816. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3817. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  3818. "0274 lpfc_nlp_put: ndlp:x%p "
  3819. "usgmap:x%x refcnt:%d\n",
  3820. (void *)ndlp, ndlp->nlp_usg_map,
  3821. atomic_read(&ndlp->kref.refcount));
  3822. return 1;
  3823. }
  3824. /* Check the ndlp inactivate log flag to avoid the possible
  3825. * race condition that kref_put got invoked again after ndlp
  3826. * is already in inactivating state.
  3827. */
  3828. if (NLP_CHK_IACT_REQ(ndlp)) {
  3829. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3830. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  3831. "0275 lpfc_nlp_put: ndlp:x%p "
  3832. "usgmap:x%x refcnt:%d\n",
  3833. (void *)ndlp, ndlp->nlp_usg_map,
  3834. atomic_read(&ndlp->kref.refcount));
  3835. return 1;
  3836. }
  3837. /* For last put, mark the ndlp usage flags to make sure no
  3838. * other kref_get and kref_put on the same ndlp shall get
  3839. * in between the process when the final kref_put has been
  3840. * invoked on this ndlp.
  3841. */
  3842. if (atomic_read(&ndlp->kref.refcount) == 1) {
  3843. /* Indicate ndlp is put to inactive state. */
  3844. NLP_SET_IACT_REQ(ndlp);
  3845. /* Acknowledge ndlp memory free has been seen. */
  3846. if (NLP_CHK_FREE_REQ(ndlp))
  3847. NLP_SET_FREE_ACK(ndlp);
  3848. }
  3849. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3850. /* Note, the kref_put returns 1 when decrementing a reference
  3851. * count that was 1, it invokes the release callback function,
  3852. * but it still left the reference count as 1 (not actually
  3853. * performs the last decrementation). Otherwise, it actually
  3854. * decrements the reference count and returns 0.
  3855. */
  3856. return kref_put(&ndlp->kref, lpfc_nlp_release);
  3857. }
  3858. /* This routine free's the specified nodelist if it is not in use
  3859. * by any other discovery thread. This routine returns 1 if the
  3860. * ndlp has been freed. A return value of 0 indicates the ndlp is
  3861. * not yet been released.
  3862. */
  3863. int
  3864. lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
  3865. {
  3866. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3867. "node not used: did:x%x flg:x%x refcnt:x%x",
  3868. ndlp->nlp_DID, ndlp->nlp_flag,
  3869. atomic_read(&ndlp->kref.refcount));
  3870. if (atomic_read(&ndlp->kref.refcount) == 1)
  3871. if (lpfc_nlp_put(ndlp))
  3872. return 1;
  3873. return 0;
  3874. }
  3875. /**
  3876. * lpfc_fcf_inuse - Check if FCF can be unregistered.
  3877. * @phba: Pointer to hba context object.
  3878. *
  3879. * This function iterate through all FC nodes associated
  3880. * will all vports to check if there is any node with
  3881. * fc_rports associated with it. If there is an fc_rport
  3882. * associated with the node, then the node is either in
  3883. * discovered state or its devloss_timer is pending.
  3884. */
  3885. static int
  3886. lpfc_fcf_inuse(struct lpfc_hba *phba)
  3887. {
  3888. struct lpfc_vport **vports;
  3889. int i, ret = 0;
  3890. struct lpfc_nodelist *ndlp;
  3891. struct Scsi_Host *shost;
  3892. vports = lpfc_create_vport_work_array(phba);
  3893. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3894. shost = lpfc_shost_from_vport(vports[i]);
  3895. spin_lock_irq(shost->host_lock);
  3896. list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
  3897. if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
  3898. (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
  3899. ret = 1;
  3900. spin_unlock_irq(shost->host_lock);
  3901. goto out;
  3902. }
  3903. }
  3904. spin_unlock_irq(shost->host_lock);
  3905. }
  3906. out:
  3907. lpfc_destroy_vport_work_array(phba, vports);
  3908. return ret;
  3909. }
  3910. /**
  3911. * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
  3912. * @phba: Pointer to hba context object.
  3913. * @mboxq: Pointer to mailbox object.
  3914. *
  3915. * This function frees memory associated with the mailbox command.
  3916. */
  3917. static void
  3918. lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  3919. {
  3920. struct lpfc_vport *vport = mboxq->vport;
  3921. if (mboxq->u.mb.mbxStatus) {
  3922. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3923. "2555 UNREG_VFI mbxStatus error x%x "
  3924. "HBA state x%x\n",
  3925. mboxq->u.mb.mbxStatus, vport->port_state);
  3926. }
  3927. mempool_free(mboxq, phba->mbox_mem_pool);
  3928. return;
  3929. }
  3930. /**
  3931. * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
  3932. * @phba: Pointer to hba context object.
  3933. * @mboxq: Pointer to mailbox object.
  3934. *
  3935. * This function frees memory associated with the mailbox command.
  3936. */
  3937. static void
  3938. lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  3939. {
  3940. struct lpfc_vport *vport = mboxq->vport;
  3941. if (mboxq->u.mb.mbxStatus) {
  3942. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3943. "2550 UNREG_FCFI mbxStatus error x%x "
  3944. "HBA state x%x\n",
  3945. mboxq->u.mb.mbxStatus, vport->port_state);
  3946. }
  3947. mempool_free(mboxq, phba->mbox_mem_pool);
  3948. return;
  3949. }
  3950. /**
  3951. * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
  3952. * @phba: Pointer to hba context object.
  3953. *
  3954. * This function check if there are any connected remote port for the FCF and
  3955. * if all the devices are disconnected, this function unregister FCFI.
  3956. * This function also tries to use another FCF for discovery.
  3957. */
  3958. void
  3959. lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
  3960. {
  3961. LPFC_MBOXQ_t *mbox;
  3962. int rc;
  3963. struct lpfc_vport **vports;
  3964. int i;
  3965. spin_lock_irq(&phba->hbalock);
  3966. /*
  3967. * If HBA is not running in FIP mode or
  3968. * If HBA does not support FCoE or
  3969. * If FCF is not registered.
  3970. * do nothing.
  3971. */
  3972. if (!(phba->hba_flag & HBA_FCOE_SUPPORT) ||
  3973. !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
  3974. (phba->cfg_enable_fip == 0)) {
  3975. spin_unlock_irq(&phba->hbalock);
  3976. return;
  3977. }
  3978. spin_unlock_irq(&phba->hbalock);
  3979. if (lpfc_fcf_inuse(phba))
  3980. return;
  3981. /* At this point, all discovery is aborted */
  3982. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3983. /* Unregister VPIs */
  3984. vports = lpfc_create_vport_work_array(phba);
  3985. if (vports &&
  3986. (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
  3987. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3988. lpfc_mbx_unreg_vpi(vports[i]);
  3989. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  3990. vports[i]->vfi_state &= ~LPFC_VFI_REGISTERED;
  3991. }
  3992. lpfc_destroy_vport_work_array(phba, vports);
  3993. /* Unregister VFI */
  3994. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3995. if (!mbox) {
  3996. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3997. "2556 UNREG_VFI mbox allocation failed"
  3998. "HBA state x%x\n",
  3999. phba->pport->port_state);
  4000. return;
  4001. }
  4002. lpfc_unreg_vfi(mbox, phba->pport);
  4003. mbox->vport = phba->pport;
  4004. mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl;
  4005. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4006. if (rc == MBX_NOT_FINISHED) {
  4007. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4008. "2557 UNREG_VFI issue mbox failed rc x%x "
  4009. "HBA state x%x\n",
  4010. rc, phba->pport->port_state);
  4011. mempool_free(mbox, phba->mbox_mem_pool);
  4012. return;
  4013. }
  4014. /* Unregister FCF */
  4015. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4016. if (!mbox) {
  4017. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4018. "2551 UNREG_FCFI mbox allocation failed"
  4019. "HBA state x%x\n",
  4020. phba->pport->port_state);
  4021. return;
  4022. }
  4023. lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
  4024. mbox->vport = phba->pport;
  4025. mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
  4026. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4027. if (rc == MBX_NOT_FINISHED) {
  4028. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4029. "2552 UNREG_FCFI issue mbox failed rc x%x "
  4030. "HBA state x%x\n",
  4031. rc, phba->pport->port_state);
  4032. mempool_free(mbox, phba->mbox_mem_pool);
  4033. return;
  4034. }
  4035. spin_lock_irq(&phba->hbalock);
  4036. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_REGISTERED |
  4037. FCF_DISCOVERED | FCF_BOOT_ENABLE | FCF_IN_USE |
  4038. FCF_VALID_VLAN);
  4039. spin_unlock_irq(&phba->hbalock);
  4040. /*
  4041. * If driver is not unloading, check if there is any other
  4042. * FCF record that can be used for discovery.
  4043. */
  4044. if ((phba->pport->load_flag & FC_UNLOADING) ||
  4045. (phba->link_state < LPFC_LINK_UP))
  4046. return;
  4047. rc = lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
  4048. if (rc)
  4049. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4050. "2553 lpfc_unregister_unused_fcf failed to read FCF"
  4051. " record HBA state x%x\n",
  4052. phba->pport->port_state);
  4053. }
  4054. /**
  4055. * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
  4056. * @phba: Pointer to hba context object.
  4057. * @buff: Buffer containing the FCF connection table as in the config
  4058. * region.
  4059. * This function create driver data structure for the FCF connection
  4060. * record table read from config region 23.
  4061. */
  4062. static void
  4063. lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
  4064. uint8_t *buff)
  4065. {
  4066. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  4067. struct lpfc_fcf_conn_hdr *conn_hdr;
  4068. struct lpfc_fcf_conn_rec *conn_rec;
  4069. uint32_t record_count;
  4070. int i;
  4071. /* Free the current connect table */
  4072. list_for_each_entry_safe(conn_entry, next_conn_entry,
  4073. &phba->fcf_conn_rec_list, list) {
  4074. list_del_init(&conn_entry->list);
  4075. kfree(conn_entry);
  4076. }
  4077. conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
  4078. record_count = conn_hdr->length * sizeof(uint32_t)/
  4079. sizeof(struct lpfc_fcf_conn_rec);
  4080. conn_rec = (struct lpfc_fcf_conn_rec *)
  4081. (buff + sizeof(struct lpfc_fcf_conn_hdr));
  4082. for (i = 0; i < record_count; i++) {
  4083. if (!(conn_rec[i].flags & FCFCNCT_VALID))
  4084. continue;
  4085. conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
  4086. GFP_KERNEL);
  4087. if (!conn_entry) {
  4088. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4089. "2566 Failed to allocate connection"
  4090. " table entry\n");
  4091. return;
  4092. }
  4093. memcpy(&conn_entry->conn_rec, &conn_rec[i],
  4094. sizeof(struct lpfc_fcf_conn_rec));
  4095. conn_entry->conn_rec.vlan_tag =
  4096. le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF;
  4097. conn_entry->conn_rec.flags =
  4098. le16_to_cpu(conn_entry->conn_rec.flags);
  4099. list_add_tail(&conn_entry->list,
  4100. &phba->fcf_conn_rec_list);
  4101. }
  4102. }
  4103. /**
  4104. * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
  4105. * @phba: Pointer to hba context object.
  4106. * @buff: Buffer containing the FCoE parameter data structure.
  4107. *
  4108. * This function update driver data structure with config
  4109. * parameters read from config region 23.
  4110. */
  4111. static void
  4112. lpfc_read_fcoe_param(struct lpfc_hba *phba,
  4113. uint8_t *buff)
  4114. {
  4115. struct lpfc_fip_param_hdr *fcoe_param_hdr;
  4116. struct lpfc_fcoe_params *fcoe_param;
  4117. fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
  4118. buff;
  4119. fcoe_param = (struct lpfc_fcoe_params *)
  4120. (buff + sizeof(struct lpfc_fip_param_hdr));
  4121. if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
  4122. (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
  4123. return;
  4124. if (bf_get(lpfc_fip_param_hdr_fipp_mode, fcoe_param_hdr) ==
  4125. FIPP_MODE_ON)
  4126. phba->cfg_enable_fip = 1;
  4127. if (bf_get(lpfc_fip_param_hdr_fipp_mode, fcoe_param_hdr) ==
  4128. FIPP_MODE_OFF)
  4129. phba->cfg_enable_fip = 0;
  4130. if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
  4131. phba->valid_vlan = 1;
  4132. phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
  4133. 0xFFF;
  4134. }
  4135. phba->fc_map[0] = fcoe_param->fc_map[0];
  4136. phba->fc_map[1] = fcoe_param->fc_map[1];
  4137. phba->fc_map[2] = fcoe_param->fc_map[2];
  4138. return;
  4139. }
  4140. /**
  4141. * lpfc_get_rec_conf23 - Get a record type in config region data.
  4142. * @buff: Buffer containing config region 23 data.
  4143. * @size: Size of the data buffer.
  4144. * @rec_type: Record type to be searched.
  4145. *
  4146. * This function searches config region data to find the begining
  4147. * of the record specified by record_type. If record found, this
  4148. * function return pointer to the record else return NULL.
  4149. */
  4150. static uint8_t *
  4151. lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
  4152. {
  4153. uint32_t offset = 0, rec_length;
  4154. if ((buff[0] == LPFC_REGION23_LAST_REC) ||
  4155. (size < sizeof(uint32_t)))
  4156. return NULL;
  4157. rec_length = buff[offset + 1];
  4158. /*
  4159. * One TLV record has one word header and number of data words
  4160. * specified in the rec_length field of the record header.
  4161. */
  4162. while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
  4163. <= size) {
  4164. if (buff[offset] == rec_type)
  4165. return &buff[offset];
  4166. if (buff[offset] == LPFC_REGION23_LAST_REC)
  4167. return NULL;
  4168. offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
  4169. rec_length = buff[offset + 1];
  4170. }
  4171. return NULL;
  4172. }
  4173. /**
  4174. * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
  4175. * @phba: Pointer to lpfc_hba data structure.
  4176. * @buff: Buffer containing config region 23 data.
  4177. * @size: Size of the data buffer.
  4178. *
  4179. * This fuction parse the FCoE config parameters in config region 23 and
  4180. * populate driver data structure with the parameters.
  4181. */
  4182. void
  4183. lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
  4184. uint8_t *buff,
  4185. uint32_t size)
  4186. {
  4187. uint32_t offset = 0, rec_length;
  4188. uint8_t *rec_ptr;
  4189. /*
  4190. * If data size is less than 2 words signature and version cannot be
  4191. * verified.
  4192. */
  4193. if (size < 2*sizeof(uint32_t))
  4194. return;
  4195. /* Check the region signature first */
  4196. if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
  4197. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4198. "2567 Config region 23 has bad signature\n");
  4199. return;
  4200. }
  4201. offset += 4;
  4202. /* Check the data structure version */
  4203. if (buff[offset] != LPFC_REGION23_VERSION) {
  4204. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4205. "2568 Config region 23 has bad version\n");
  4206. return;
  4207. }
  4208. offset += 4;
  4209. rec_length = buff[offset + 1];
  4210. /* Read FCoE param record */
  4211. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  4212. size - offset, FCOE_PARAM_TYPE);
  4213. if (rec_ptr)
  4214. lpfc_read_fcoe_param(phba, rec_ptr);
  4215. /* Read FCF connection table */
  4216. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  4217. size - offset, FCOE_CONN_TBL_TYPE);
  4218. if (rec_ptr)
  4219. lpfc_read_fcf_conn_tbl(phba, rec_ptr);
  4220. }