lpfc_hbadisc.c 132 KB

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