lpfc_hbadisc.c 141 KB

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