lpfc_hbadisc.c 131 KB

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