lpfc_els.c 256 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2012 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. /* See Fibre Channel protocol T11 FC-LS for details */
  22. #include <linux/blkdev.h>
  23. #include <linux/pci.h>
  24. #include <linux/slab.h>
  25. #include <linux/interrupt.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_host.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include "lpfc_hw4.h"
  31. #include "lpfc_hw.h"
  32. #include "lpfc_sli.h"
  33. #include "lpfc_sli4.h"
  34. #include "lpfc_nl.h"
  35. #include "lpfc_disc.h"
  36. #include "lpfc_scsi.h"
  37. #include "lpfc.h"
  38. #include "lpfc_logmsg.h"
  39. #include "lpfc_crtn.h"
  40. #include "lpfc_vport.h"
  41. #include "lpfc_debugfs.h"
  42. static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
  43. struct lpfc_iocbq *);
  44. static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
  45. struct lpfc_iocbq *);
  46. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
  47. static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
  48. struct lpfc_nodelist *ndlp, uint8_t retry);
  49. static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
  50. struct lpfc_iocbq *iocb);
  51. static int lpfc_max_els_tries = 3;
  52. /**
  53. * lpfc_els_chk_latt - Check host link attention event for a vport
  54. * @vport: pointer to a host virtual N_Port data structure.
  55. *
  56. * This routine checks whether there is an outstanding host link
  57. * attention event during the discovery process with the @vport. It is done
  58. * by reading the HBA's Host Attention (HA) register. If there is any host
  59. * link attention events during this @vport's discovery process, the @vport
  60. * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
  61. * be issued if the link state is not already in host link cleared state,
  62. * and a return code shall indicate whether the host link attention event
  63. * had happened.
  64. *
  65. * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
  66. * state in LPFC_VPORT_READY, the request for checking host link attention
  67. * event will be ignored and a return code shall indicate no host link
  68. * attention event had happened.
  69. *
  70. * Return codes
  71. * 0 - no host link attention event happened
  72. * 1 - host link attention event happened
  73. **/
  74. int
  75. lpfc_els_chk_latt(struct lpfc_vport *vport)
  76. {
  77. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  78. struct lpfc_hba *phba = vport->phba;
  79. uint32_t ha_copy;
  80. if (vport->port_state >= LPFC_VPORT_READY ||
  81. phba->link_state == LPFC_LINK_DOWN ||
  82. phba->sli_rev > LPFC_SLI_REV3)
  83. return 0;
  84. /* Read the HBA Host Attention Register */
  85. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  86. return 1;
  87. if (!(ha_copy & HA_LATT))
  88. return 0;
  89. /* Pending Link Event during Discovery */
  90. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  91. "0237 Pending Link Event during "
  92. "Discovery: State x%x\n",
  93. phba->pport->port_state);
  94. /* CLEAR_LA should re-enable link attention events and
  95. * we should then immediately take a LATT event. The
  96. * LATT processing should call lpfc_linkdown() which
  97. * will cleanup any left over in-progress discovery
  98. * events.
  99. */
  100. spin_lock_irq(shost->host_lock);
  101. vport->fc_flag |= FC_ABORT_DISCOVERY;
  102. spin_unlock_irq(shost->host_lock);
  103. if (phba->link_state != LPFC_CLEAR_LA)
  104. lpfc_issue_clear_la(phba, vport);
  105. return 1;
  106. }
  107. /**
  108. * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
  109. * @vport: pointer to a host virtual N_Port data structure.
  110. * @expectRsp: flag indicating whether response is expected.
  111. * @cmdSize: size of the ELS command.
  112. * @retry: number of retries to the command IOCB when it fails.
  113. * @ndlp: pointer to a node-list data structure.
  114. * @did: destination identifier.
  115. * @elscmd: the ELS command code.
  116. *
  117. * This routine is used for allocating a lpfc-IOCB data structure from
  118. * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
  119. * passed into the routine for discovery state machine to issue an Extended
  120. * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
  121. * and preparation routine that is used by all the discovery state machine
  122. * routines and the ELS command-specific fields will be later set up by
  123. * the individual discovery machine routines after calling this routine
  124. * allocating and preparing a generic IOCB data structure. It fills in the
  125. * Buffer Descriptor Entries (BDEs), allocates buffers for both command
  126. * payload and response payload (if expected). The reference count on the
  127. * ndlp is incremented by 1 and the reference to the ndlp is put into
  128. * context1 of the IOCB data structure for this IOCB to hold the ndlp
  129. * reference for the command's callback function to access later.
  130. *
  131. * Return code
  132. * Pointer to the newly allocated/prepared els iocb data structure
  133. * NULL - when els iocb data structure allocation/preparation failed
  134. **/
  135. struct lpfc_iocbq *
  136. lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
  137. uint16_t cmdSize, uint8_t retry,
  138. struct lpfc_nodelist *ndlp, uint32_t did,
  139. uint32_t elscmd)
  140. {
  141. struct lpfc_hba *phba = vport->phba;
  142. struct lpfc_iocbq *elsiocb;
  143. struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
  144. struct ulp_bde64 *bpl;
  145. IOCB_t *icmd;
  146. if (!lpfc_is_link_up(phba))
  147. return NULL;
  148. /* Allocate buffer for command iocb */
  149. elsiocb = lpfc_sli_get_iocbq(phba);
  150. if (elsiocb == NULL)
  151. return NULL;
  152. /*
  153. * If this command is for fabric controller and HBA running
  154. * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
  155. */
  156. if ((did == Fabric_DID) &&
  157. (phba->hba_flag & HBA_FIP_SUPPORT) &&
  158. ((elscmd == ELS_CMD_FLOGI) ||
  159. (elscmd == ELS_CMD_FDISC) ||
  160. (elscmd == ELS_CMD_LOGO)))
  161. switch (elscmd) {
  162. case ELS_CMD_FLOGI:
  163. elsiocb->iocb_flag |=
  164. ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
  165. & LPFC_FIP_ELS_ID_MASK);
  166. break;
  167. case ELS_CMD_FDISC:
  168. elsiocb->iocb_flag |=
  169. ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
  170. & LPFC_FIP_ELS_ID_MASK);
  171. break;
  172. case ELS_CMD_LOGO:
  173. elsiocb->iocb_flag |=
  174. ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
  175. & LPFC_FIP_ELS_ID_MASK);
  176. break;
  177. }
  178. else
  179. elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
  180. icmd = &elsiocb->iocb;
  181. /* fill in BDEs for command */
  182. /* Allocate buffer for command payload */
  183. pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  184. if (pcmd)
  185. pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
  186. if (!pcmd || !pcmd->virt)
  187. goto els_iocb_free_pcmb_exit;
  188. INIT_LIST_HEAD(&pcmd->list);
  189. /* Allocate buffer for response payload */
  190. if (expectRsp) {
  191. prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  192. if (prsp)
  193. prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  194. &prsp->phys);
  195. if (!prsp || !prsp->virt)
  196. goto els_iocb_free_prsp_exit;
  197. INIT_LIST_HEAD(&prsp->list);
  198. } else
  199. prsp = NULL;
  200. /* Allocate buffer for Buffer ptr list */
  201. pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  202. if (pbuflist)
  203. pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  204. &pbuflist->phys);
  205. if (!pbuflist || !pbuflist->virt)
  206. goto els_iocb_free_pbuf_exit;
  207. INIT_LIST_HEAD(&pbuflist->list);
  208. if (expectRsp) {
  209. icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
  210. icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
  211. icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  212. icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
  213. icmd->un.elsreq64.remoteID = did; /* DID */
  214. icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
  215. icmd->ulpTimeout = phba->fc_ratov * 2;
  216. } else {
  217. icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
  218. icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
  219. icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  220. icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
  221. icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
  222. icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
  223. }
  224. icmd->ulpBdeCount = 1;
  225. icmd->ulpLe = 1;
  226. icmd->ulpClass = CLASS3;
  227. /*
  228. * If we have NPIV enabled, we want to send ELS traffic by VPI.
  229. * For SLI4, since the driver controls VPIs we also want to include
  230. * all ELS pt2pt protocol traffic as well.
  231. */
  232. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
  233. ((phba->sli_rev == LPFC_SLI_REV4) &&
  234. (vport->fc_flag & FC_PT2PT))) {
  235. if (expectRsp) {
  236. icmd->un.elsreq64.myID = vport->fc_myDID;
  237. /* For ELS_REQUEST64_CR, use the VPI by default */
  238. icmd->ulpContext = phba->vpi_ids[vport->vpi];
  239. }
  240. icmd->ulpCt_h = 0;
  241. /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
  242. if (elscmd == ELS_CMD_ECHO)
  243. icmd->ulpCt_l = 0; /* context = invalid RPI */
  244. else
  245. icmd->ulpCt_l = 1; /* context = VPI */
  246. }
  247. bpl = (struct ulp_bde64 *) pbuflist->virt;
  248. bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
  249. bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
  250. bpl->tus.f.bdeSize = cmdSize;
  251. bpl->tus.f.bdeFlags = 0;
  252. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  253. if (expectRsp) {
  254. bpl++;
  255. bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
  256. bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
  257. bpl->tus.f.bdeSize = FCELSSIZE;
  258. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  259. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  260. }
  261. /* prevent preparing iocb with NULL ndlp reference */
  262. elsiocb->context1 = lpfc_nlp_get(ndlp);
  263. if (!elsiocb->context1)
  264. goto els_iocb_free_pbuf_exit;
  265. elsiocb->context2 = pcmd;
  266. elsiocb->context3 = pbuflist;
  267. elsiocb->retry = retry;
  268. elsiocb->vport = vport;
  269. elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
  270. if (prsp) {
  271. list_add(&prsp->list, &pcmd->list);
  272. }
  273. if (expectRsp) {
  274. /* Xmit ELS command <elsCmd> to remote NPORT <did> */
  275. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  276. "0116 Xmit ELS command x%x to remote "
  277. "NPORT x%x I/O tag: x%x, port state: x%x\n",
  278. elscmd, did, elsiocb->iotag,
  279. vport->port_state);
  280. } else {
  281. /* Xmit ELS response <elsCmd> to remote NPORT <did> */
  282. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  283. "0117 Xmit ELS response x%x to remote "
  284. "NPORT x%x I/O tag: x%x, size: x%x\n",
  285. elscmd, ndlp->nlp_DID, elsiocb->iotag,
  286. cmdSize);
  287. }
  288. return elsiocb;
  289. els_iocb_free_pbuf_exit:
  290. if (expectRsp)
  291. lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
  292. kfree(pbuflist);
  293. els_iocb_free_prsp_exit:
  294. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  295. kfree(prsp);
  296. els_iocb_free_pcmb_exit:
  297. kfree(pcmd);
  298. lpfc_sli_release_iocbq(phba, elsiocb);
  299. return NULL;
  300. }
  301. /**
  302. * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
  303. * @vport: pointer to a host virtual N_Port data structure.
  304. *
  305. * This routine issues a fabric registration login for a @vport. An
  306. * active ndlp node with Fabric_DID must already exist for this @vport.
  307. * The routine invokes two mailbox commands to carry out fabric registration
  308. * login through the HBA firmware: the first mailbox command requests the
  309. * HBA to perform link configuration for the @vport; and the second mailbox
  310. * command requests the HBA to perform the actual fabric registration login
  311. * with the @vport.
  312. *
  313. * Return code
  314. * 0 - successfully issued fabric registration login for @vport
  315. * -ENXIO -- failed to issue fabric registration login for @vport
  316. **/
  317. int
  318. lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
  319. {
  320. struct lpfc_hba *phba = vport->phba;
  321. LPFC_MBOXQ_t *mbox;
  322. struct lpfc_dmabuf *mp;
  323. struct lpfc_nodelist *ndlp;
  324. struct serv_parm *sp;
  325. int rc;
  326. int err = 0;
  327. sp = &phba->fc_fabparam;
  328. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  329. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  330. err = 1;
  331. goto fail;
  332. }
  333. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  334. if (!mbox) {
  335. err = 2;
  336. goto fail;
  337. }
  338. vport->port_state = LPFC_FABRIC_CFG_LINK;
  339. lpfc_config_link(phba, mbox);
  340. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  341. mbox->vport = vport;
  342. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  343. if (rc == MBX_NOT_FINISHED) {
  344. err = 3;
  345. goto fail_free_mbox;
  346. }
  347. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  348. if (!mbox) {
  349. err = 4;
  350. goto fail;
  351. }
  352. rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
  353. ndlp->nlp_rpi);
  354. if (rc) {
  355. err = 5;
  356. goto fail_free_mbox;
  357. }
  358. mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
  359. mbox->vport = vport;
  360. /* increment the reference count on ndlp to hold reference
  361. * for the callback routine.
  362. */
  363. mbox->context2 = lpfc_nlp_get(ndlp);
  364. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  365. if (rc == MBX_NOT_FINISHED) {
  366. err = 6;
  367. goto fail_issue_reg_login;
  368. }
  369. return 0;
  370. fail_issue_reg_login:
  371. /* decrement the reference count on ndlp just incremented
  372. * for the failed mbox command.
  373. */
  374. lpfc_nlp_put(ndlp);
  375. mp = (struct lpfc_dmabuf *) mbox->context1;
  376. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  377. kfree(mp);
  378. fail_free_mbox:
  379. mempool_free(mbox, phba->mbox_mem_pool);
  380. fail:
  381. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  382. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  383. "0249 Cannot issue Register Fabric login: Err %d\n", err);
  384. return -ENXIO;
  385. }
  386. /**
  387. * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
  388. * @vport: pointer to a host virtual N_Port data structure.
  389. *
  390. * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
  391. * the @vport. This mailbox command is necessary for SLI4 port only.
  392. *
  393. * Return code
  394. * 0 - successfully issued REG_VFI for @vport
  395. * A failure code otherwise.
  396. **/
  397. int
  398. lpfc_issue_reg_vfi(struct lpfc_vport *vport)
  399. {
  400. struct lpfc_hba *phba = vport->phba;
  401. LPFC_MBOXQ_t *mboxq;
  402. struct lpfc_nodelist *ndlp;
  403. struct serv_parm *sp;
  404. struct lpfc_dmabuf *dmabuf;
  405. int rc = 0;
  406. sp = &phba->fc_fabparam;
  407. /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
  408. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  409. !(phba->link_flag & LS_LOOPBACK_MODE) &&
  410. !(vport->fc_flag & FC_PT2PT)) {
  411. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  412. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  413. rc = -ENODEV;
  414. goto fail;
  415. }
  416. }
  417. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  418. if (!dmabuf) {
  419. rc = -ENOMEM;
  420. goto fail;
  421. }
  422. dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
  423. if (!dmabuf->virt) {
  424. rc = -ENOMEM;
  425. goto fail_free_dmabuf;
  426. }
  427. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  428. if (!mboxq) {
  429. rc = -ENOMEM;
  430. goto fail_free_coherent;
  431. }
  432. vport->port_state = LPFC_FABRIC_CFG_LINK;
  433. memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
  434. lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
  435. mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
  436. mboxq->vport = vport;
  437. mboxq->context1 = dmabuf;
  438. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  439. if (rc == MBX_NOT_FINISHED) {
  440. rc = -ENXIO;
  441. goto fail_free_mbox;
  442. }
  443. return 0;
  444. fail_free_mbox:
  445. mempool_free(mboxq, phba->mbox_mem_pool);
  446. fail_free_coherent:
  447. lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
  448. fail_free_dmabuf:
  449. kfree(dmabuf);
  450. fail:
  451. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  452. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  453. "0289 Issue Register VFI failed: Err %d\n", rc);
  454. return rc;
  455. }
  456. /**
  457. * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
  458. * @vport: pointer to a host virtual N_Port data structure.
  459. *
  460. * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
  461. * the @vport. This mailbox command is necessary for SLI4 port only.
  462. *
  463. * Return code
  464. * 0 - successfully issued REG_VFI for @vport
  465. * A failure code otherwise.
  466. **/
  467. int
  468. lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
  469. {
  470. struct lpfc_hba *phba = vport->phba;
  471. struct Scsi_Host *shost;
  472. LPFC_MBOXQ_t *mboxq;
  473. int rc;
  474. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  475. if (!mboxq) {
  476. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  477. "2556 UNREG_VFI mbox allocation failed"
  478. "HBA state x%x\n", phba->pport->port_state);
  479. return -ENOMEM;
  480. }
  481. lpfc_unreg_vfi(mboxq, vport);
  482. mboxq->vport = vport;
  483. mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
  484. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  485. if (rc == MBX_NOT_FINISHED) {
  486. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  487. "2557 UNREG_VFI issue mbox failed rc x%x "
  488. "HBA state x%x\n",
  489. rc, phba->pport->port_state);
  490. mempool_free(mboxq, phba->mbox_mem_pool);
  491. return -EIO;
  492. }
  493. shost = lpfc_shost_from_vport(vport);
  494. spin_lock_irq(shost->host_lock);
  495. vport->fc_flag &= ~FC_VFI_REGISTERED;
  496. spin_unlock_irq(shost->host_lock);
  497. return 0;
  498. }
  499. /**
  500. * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
  501. * @vport: pointer to a host virtual N_Port data structure.
  502. * @sp: pointer to service parameter data structure.
  503. *
  504. * This routine is called from FLOGI/FDISC completion handler functions.
  505. * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
  506. * node nodename is changed in the completion service parameter else return
  507. * 0. This function also set flag in the vport data structure to delay
  508. * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
  509. * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
  510. * node nodename is changed in the completion service parameter.
  511. *
  512. * Return code
  513. * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
  514. * 1 - FCID or Fabric Nodename or Fabric portname is changed.
  515. *
  516. **/
  517. static uint8_t
  518. lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
  519. struct serv_parm *sp)
  520. {
  521. uint8_t fabric_param_changed = 0;
  522. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  523. if ((vport->fc_prevDID != vport->fc_myDID) ||
  524. memcmp(&vport->fabric_portname, &sp->portName,
  525. sizeof(struct lpfc_name)) ||
  526. memcmp(&vport->fabric_nodename, &sp->nodeName,
  527. sizeof(struct lpfc_name)))
  528. fabric_param_changed = 1;
  529. /*
  530. * Word 1 Bit 31 in common service parameter is overloaded.
  531. * Word 1 Bit 31 in FLOGI request is multiple NPort request
  532. * Word 1 Bit 31 in FLOGI response is clean address bit
  533. *
  534. * If fabric parameter is changed and clean address bit is
  535. * cleared delay nport discovery if
  536. * - vport->fc_prevDID != 0 (not initial discovery) OR
  537. * - lpfc_delay_discovery module parameter is set.
  538. */
  539. if (fabric_param_changed && !sp->cmn.clean_address_bit &&
  540. (vport->fc_prevDID || lpfc_delay_discovery)) {
  541. spin_lock_irq(shost->host_lock);
  542. vport->fc_flag |= FC_DISC_DELAYED;
  543. spin_unlock_irq(shost->host_lock);
  544. }
  545. return fabric_param_changed;
  546. }
  547. /**
  548. * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
  549. * @vport: pointer to a host virtual N_Port data structure.
  550. * @ndlp: pointer to a node-list data structure.
  551. * @sp: pointer to service parameter data structure.
  552. * @irsp: pointer to the IOCB within the lpfc response IOCB.
  553. *
  554. * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
  555. * function to handle the completion of a Fabric Login (FLOGI) into a fabric
  556. * port in a fabric topology. It properly sets up the parameters to the @ndlp
  557. * from the IOCB response. It also check the newly assigned N_Port ID to the
  558. * @vport against the previously assigned N_Port ID. If it is different from
  559. * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
  560. * is invoked on all the remaining nodes with the @vport to unregister the
  561. * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
  562. * is invoked to register login to the fabric.
  563. *
  564. * Return code
  565. * 0 - Success (currently, always return 0)
  566. **/
  567. static int
  568. lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  569. struct serv_parm *sp, IOCB_t *irsp)
  570. {
  571. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  572. struct lpfc_hba *phba = vport->phba;
  573. struct lpfc_nodelist *np;
  574. struct lpfc_nodelist *next_np;
  575. uint8_t fabric_param_changed;
  576. spin_lock_irq(shost->host_lock);
  577. vport->fc_flag |= FC_FABRIC;
  578. spin_unlock_irq(shost->host_lock);
  579. phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
  580. if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
  581. phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
  582. phba->fc_edtovResol = sp->cmn.edtovResolution;
  583. phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
  584. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  585. spin_lock_irq(shost->host_lock);
  586. vport->fc_flag |= FC_PUBLIC_LOOP;
  587. spin_unlock_irq(shost->host_lock);
  588. }
  589. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  590. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
  591. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
  592. ndlp->nlp_class_sup = 0;
  593. if (sp->cls1.classValid)
  594. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  595. if (sp->cls2.classValid)
  596. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  597. if (sp->cls3.classValid)
  598. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  599. if (sp->cls4.classValid)
  600. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  601. ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  602. sp->cmn.bbRcvSizeLsb;
  603. fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
  604. memcpy(&vport->fabric_portname, &sp->portName,
  605. sizeof(struct lpfc_name));
  606. memcpy(&vport->fabric_nodename, &sp->nodeName,
  607. sizeof(struct lpfc_name));
  608. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  609. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  610. if (sp->cmn.response_multiple_NPort) {
  611. lpfc_printf_vlog(vport, KERN_WARNING,
  612. LOG_ELS | LOG_VPORT,
  613. "1816 FLOGI NPIV supported, "
  614. "response data 0x%x\n",
  615. sp->cmn.response_multiple_NPort);
  616. spin_lock_irq(&phba->hbalock);
  617. phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
  618. spin_unlock_irq(&phba->hbalock);
  619. } else {
  620. /* Because we asked f/w for NPIV it still expects us
  621. to call reg_vnpid atleast for the physcial host */
  622. lpfc_printf_vlog(vport, KERN_WARNING,
  623. LOG_ELS | LOG_VPORT,
  624. "1817 Fabric does not support NPIV "
  625. "- configuring single port mode.\n");
  626. spin_lock_irq(&phba->hbalock);
  627. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  628. spin_unlock_irq(&phba->hbalock);
  629. }
  630. }
  631. if (fabric_param_changed &&
  632. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  633. /* If our NportID changed, we need to ensure all
  634. * remaining NPORTs get unreg_login'ed.
  635. */
  636. list_for_each_entry_safe(np, next_np,
  637. &vport->fc_nodes, nlp_listp) {
  638. if (!NLP_CHK_NODE_ACT(np))
  639. continue;
  640. if ((np->nlp_state != NLP_STE_NPR_NODE) ||
  641. !(np->nlp_flag & NLP_NPR_ADISC))
  642. continue;
  643. spin_lock_irq(shost->host_lock);
  644. np->nlp_flag &= ~NLP_NPR_ADISC;
  645. spin_unlock_irq(shost->host_lock);
  646. lpfc_unreg_rpi(vport, np);
  647. }
  648. lpfc_cleanup_pending_mbox(vport);
  649. if (phba->sli_rev == LPFC_SLI_REV4) {
  650. lpfc_sli4_unreg_all_rpis(vport);
  651. lpfc_mbx_unreg_vpi(vport);
  652. spin_lock_irq(shost->host_lock);
  653. vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  654. spin_unlock_irq(shost->host_lock);
  655. }
  656. /*
  657. * For SLI3 and SLI4, the VPI needs to be reregistered in
  658. * response to this fabric parameter change event.
  659. */
  660. spin_lock_irq(shost->host_lock);
  661. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  662. spin_unlock_irq(shost->host_lock);
  663. } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
  664. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  665. /*
  666. * Driver needs to re-reg VPI in order for f/w
  667. * to update the MAC address.
  668. */
  669. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  670. lpfc_register_new_vport(phba, vport, ndlp);
  671. return 0;
  672. }
  673. if (phba->sli_rev < LPFC_SLI_REV4) {
  674. lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
  675. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
  676. vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  677. lpfc_register_new_vport(phba, vport, ndlp);
  678. else
  679. lpfc_issue_fabric_reglogin(vport);
  680. } else {
  681. ndlp->nlp_type |= NLP_FABRIC;
  682. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  683. if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
  684. (vport->vpi_state & LPFC_VPI_REGISTERED)) {
  685. lpfc_start_fdiscs(phba);
  686. lpfc_do_scr_ns_plogi(phba, vport);
  687. } else if (vport->fc_flag & FC_VFI_REGISTERED)
  688. lpfc_issue_init_vpi(vport);
  689. else {
  690. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  691. "3135 Need register VFI: (x%x/%x)\n",
  692. vport->fc_prevDID, vport->fc_myDID);
  693. lpfc_issue_reg_vfi(vport);
  694. }
  695. }
  696. return 0;
  697. }
  698. /**
  699. * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
  700. * @vport: pointer to a host virtual N_Port data structure.
  701. * @ndlp: pointer to a node-list data structure.
  702. * @sp: pointer to service parameter data structure.
  703. *
  704. * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
  705. * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
  706. * in a point-to-point topology. First, the @vport's N_Port Name is compared
  707. * with the received N_Port Name: if the @vport's N_Port Name is greater than
  708. * the received N_Port Name lexicographically, this node shall assign local
  709. * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
  710. * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
  711. * this node shall just wait for the remote node to issue PLOGI and assign
  712. * N_Port IDs.
  713. *
  714. * Return code
  715. * 0 - Success
  716. * -ENXIO - Fail
  717. **/
  718. static int
  719. lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  720. struct serv_parm *sp)
  721. {
  722. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  723. struct lpfc_hba *phba = vport->phba;
  724. LPFC_MBOXQ_t *mbox;
  725. int rc;
  726. spin_lock_irq(shost->host_lock);
  727. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  728. spin_unlock_irq(shost->host_lock);
  729. phba->fc_edtov = FF_DEF_EDTOV;
  730. phba->fc_ratov = FF_DEF_RATOV;
  731. rc = memcmp(&vport->fc_portname, &sp->portName,
  732. sizeof(vport->fc_portname));
  733. if (rc >= 0) {
  734. /* This side will initiate the PLOGI */
  735. spin_lock_irq(shost->host_lock);
  736. vport->fc_flag |= FC_PT2PT_PLOGI;
  737. spin_unlock_irq(shost->host_lock);
  738. /*
  739. * N_Port ID cannot be 0, set our to LocalID the other
  740. * side will be RemoteID.
  741. */
  742. /* not equal */
  743. if (rc)
  744. vport->fc_myDID = PT2PT_LocalID;
  745. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  746. if (!mbox)
  747. goto fail;
  748. lpfc_config_link(phba, mbox);
  749. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  750. mbox->vport = vport;
  751. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  752. if (rc == MBX_NOT_FINISHED) {
  753. mempool_free(mbox, phba->mbox_mem_pool);
  754. goto fail;
  755. }
  756. /*
  757. * For SLI4, the VFI/VPI are registered AFTER the
  758. * Nport with the higher WWPN sends the PLOGI with
  759. * an assigned NPortId.
  760. */
  761. /* not equal */
  762. if ((phba->sli_rev == LPFC_SLI_REV4) && rc)
  763. lpfc_issue_reg_vfi(vport);
  764. /* Decrement ndlp reference count indicating that ndlp can be
  765. * safely released when other references to it are done.
  766. */
  767. lpfc_nlp_put(ndlp);
  768. ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
  769. if (!ndlp) {
  770. /*
  771. * Cannot find existing Fabric ndlp, so allocate a
  772. * new one
  773. */
  774. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  775. if (!ndlp)
  776. goto fail;
  777. lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
  778. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  779. ndlp = lpfc_enable_node(vport, ndlp,
  780. NLP_STE_UNUSED_NODE);
  781. if(!ndlp)
  782. goto fail;
  783. }
  784. memcpy(&ndlp->nlp_portname, &sp->portName,
  785. sizeof(struct lpfc_name));
  786. memcpy(&ndlp->nlp_nodename, &sp->nodeName,
  787. sizeof(struct lpfc_name));
  788. /* Set state will put ndlp onto node list if not already done */
  789. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  790. spin_lock_irq(shost->host_lock);
  791. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  792. spin_unlock_irq(shost->host_lock);
  793. } else
  794. /* This side will wait for the PLOGI, decrement ndlp reference
  795. * count indicating that ndlp can be released when other
  796. * references to it are done.
  797. */
  798. lpfc_nlp_put(ndlp);
  799. /* If we are pt2pt with another NPort, force NPIV off! */
  800. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  801. spin_lock_irq(shost->host_lock);
  802. vport->fc_flag |= FC_PT2PT;
  803. spin_unlock_irq(shost->host_lock);
  804. /* Start discovery - this should just do CLEAR_LA */
  805. lpfc_disc_start(vport);
  806. return 0;
  807. fail:
  808. return -ENXIO;
  809. }
  810. /**
  811. * lpfc_cmpl_els_flogi - Completion callback function for flogi
  812. * @phba: pointer to lpfc hba data structure.
  813. * @cmdiocb: pointer to lpfc command iocb data structure.
  814. * @rspiocb: pointer to lpfc response iocb data structure.
  815. *
  816. * This routine is the top-level completion callback function for issuing
  817. * a Fabric Login (FLOGI) command. If the response IOCB reported error,
  818. * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
  819. * retry has been made (either immediately or delayed with lpfc_els_retry()
  820. * returning 1), the command IOCB will be released and function returned.
  821. * If the retry attempt has been given up (possibly reach the maximum
  822. * number of retries), one additional decrement of ndlp reference shall be
  823. * invoked before going out after releasing the command IOCB. This will
  824. * actually release the remote node (Note, lpfc_els_free_iocb() will also
  825. * invoke one decrement of ndlp reference count). If no error reported in
  826. * the IOCB status, the command Port ID field is used to determine whether
  827. * this is a point-to-point topology or a fabric topology: if the Port ID
  828. * field is assigned, it is a fabric topology; otherwise, it is a
  829. * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
  830. * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
  831. * specific topology completion conditions.
  832. **/
  833. static void
  834. lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  835. struct lpfc_iocbq *rspiocb)
  836. {
  837. struct lpfc_vport *vport = cmdiocb->vport;
  838. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  839. IOCB_t *irsp = &rspiocb->iocb;
  840. struct lpfc_nodelist *ndlp = cmdiocb->context1;
  841. struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
  842. struct serv_parm *sp;
  843. uint16_t fcf_index;
  844. int rc;
  845. /* Check to see if link went down during discovery */
  846. if (lpfc_els_chk_latt(vport)) {
  847. /* One additional decrement on node reference count to
  848. * trigger the release of the node
  849. */
  850. lpfc_nlp_put(ndlp);
  851. goto out;
  852. }
  853. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  854. "FLOGI cmpl: status:x%x/x%x state:x%x",
  855. irsp->ulpStatus, irsp->un.ulpWord[4],
  856. vport->port_state);
  857. if (irsp->ulpStatus) {
  858. /*
  859. * In case of FIP mode, perform roundrobin FCF failover
  860. * due to new FCF discovery
  861. */
  862. if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
  863. (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
  864. if (phba->link_state < LPFC_LINK_UP)
  865. goto stop_rr_fcf_flogi;
  866. if ((phba->fcoe_cvl_eventtag_attn ==
  867. phba->fcoe_cvl_eventtag) &&
  868. (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  869. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  870. IOERR_SLI_ABORTED))
  871. goto stop_rr_fcf_flogi;
  872. else
  873. phba->fcoe_cvl_eventtag_attn =
  874. phba->fcoe_cvl_eventtag;
  875. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
  876. "2611 FLOGI failed on FCF (x%x), "
  877. "status:x%x/x%x, tmo:x%x, perform "
  878. "roundrobin FCF failover\n",
  879. phba->fcf.current_rec.fcf_indx,
  880. irsp->ulpStatus, irsp->un.ulpWord[4],
  881. irsp->ulpTimeout);
  882. lpfc_sli4_set_fcf_flogi_fail(phba,
  883. phba->fcf.current_rec.fcf_indx);
  884. fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
  885. rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
  886. if (rc)
  887. goto out;
  888. }
  889. stop_rr_fcf_flogi:
  890. /* FLOGI failure */
  891. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  892. "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
  893. irsp->ulpStatus, irsp->un.ulpWord[4],
  894. irsp->ulpTimeout);
  895. /* Check for retry */
  896. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  897. goto out;
  898. /* FLOGI failure */
  899. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  900. "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
  901. irsp->ulpStatus, irsp->un.ulpWord[4],
  902. irsp->ulpTimeout);
  903. /* FLOGI failed, so there is no fabric */
  904. spin_lock_irq(shost->host_lock);
  905. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  906. spin_unlock_irq(shost->host_lock);
  907. /* If private loop, then allow max outstanding els to be
  908. * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
  909. * alpa map would take too long otherwise.
  910. */
  911. if (phba->alpa_map[0] == 0)
  912. vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
  913. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  914. (!(vport->fc_flag & FC_VFI_REGISTERED) ||
  915. (vport->fc_prevDID != vport->fc_myDID))) {
  916. if (vport->fc_flag & FC_VFI_REGISTERED)
  917. lpfc_sli4_unreg_all_rpis(vport);
  918. lpfc_issue_reg_vfi(vport);
  919. lpfc_nlp_put(ndlp);
  920. goto out;
  921. }
  922. goto flogifail;
  923. }
  924. spin_lock_irq(shost->host_lock);
  925. vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
  926. vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
  927. spin_unlock_irq(shost->host_lock);
  928. /*
  929. * The FLogI succeeded. Sync the data for the CPU before
  930. * accessing it.
  931. */
  932. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  933. sp = prsp->virt + sizeof(uint32_t);
  934. /* FLOGI completes successfully */
  935. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  936. "0101 FLOGI completes successfully "
  937. "Data: x%x x%x x%x x%x\n",
  938. irsp->un.ulpWord[4], sp->cmn.e_d_tov,
  939. sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
  940. if (vport->port_state == LPFC_FLOGI) {
  941. /*
  942. * If Common Service Parameters indicate Nport
  943. * we are point to point, if Fport we are Fabric.
  944. */
  945. if (sp->cmn.fPort)
  946. rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
  947. else if (!(phba->hba_flag & HBA_FCOE_MODE))
  948. rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
  949. else {
  950. lpfc_printf_vlog(vport, KERN_ERR,
  951. LOG_FIP | LOG_ELS,
  952. "2831 FLOGI response with cleared Fabric "
  953. "bit fcf_index 0x%x "
  954. "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
  955. "Fabric Name "
  956. "%02x%02x%02x%02x%02x%02x%02x%02x\n",
  957. phba->fcf.current_rec.fcf_indx,
  958. phba->fcf.current_rec.switch_name[0],
  959. phba->fcf.current_rec.switch_name[1],
  960. phba->fcf.current_rec.switch_name[2],
  961. phba->fcf.current_rec.switch_name[3],
  962. phba->fcf.current_rec.switch_name[4],
  963. phba->fcf.current_rec.switch_name[5],
  964. phba->fcf.current_rec.switch_name[6],
  965. phba->fcf.current_rec.switch_name[7],
  966. phba->fcf.current_rec.fabric_name[0],
  967. phba->fcf.current_rec.fabric_name[1],
  968. phba->fcf.current_rec.fabric_name[2],
  969. phba->fcf.current_rec.fabric_name[3],
  970. phba->fcf.current_rec.fabric_name[4],
  971. phba->fcf.current_rec.fabric_name[5],
  972. phba->fcf.current_rec.fabric_name[6],
  973. phba->fcf.current_rec.fabric_name[7]);
  974. lpfc_nlp_put(ndlp);
  975. spin_lock_irq(&phba->hbalock);
  976. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  977. phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
  978. spin_unlock_irq(&phba->hbalock);
  979. goto out;
  980. }
  981. if (!rc) {
  982. /* Mark the FCF discovery process done */
  983. if (phba->hba_flag & HBA_FIP_SUPPORT)
  984. lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
  985. LOG_ELS,
  986. "2769 FLOGI to FCF (x%x) "
  987. "completed successfully\n",
  988. phba->fcf.current_rec.fcf_indx);
  989. spin_lock_irq(&phba->hbalock);
  990. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  991. phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
  992. spin_unlock_irq(&phba->hbalock);
  993. goto out;
  994. }
  995. }
  996. flogifail:
  997. lpfc_nlp_put(ndlp);
  998. if (!lpfc_error_lost_link(irsp)) {
  999. /* FLOGI failed, so just use loop map to make discovery list */
  1000. lpfc_disc_list_loopmap(vport);
  1001. /* Start discovery */
  1002. lpfc_disc_start(vport);
  1003. } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  1004. (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
  1005. IOERR_SLI_ABORTED) &&
  1006. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
  1007. IOERR_SLI_DOWN))) &&
  1008. (phba->link_state != LPFC_CLEAR_LA)) {
  1009. /* If FLOGI failed enable link interrupt. */
  1010. lpfc_issue_clear_la(phba, vport);
  1011. }
  1012. out:
  1013. lpfc_els_free_iocb(phba, cmdiocb);
  1014. }
  1015. /**
  1016. * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
  1017. * @vport: pointer to a host virtual N_Port data structure.
  1018. * @ndlp: pointer to a node-list data structure.
  1019. * @retry: number of retries to the command IOCB.
  1020. *
  1021. * This routine issues a Fabric Login (FLOGI) Request ELS command
  1022. * for a @vport. The initiator service parameters are put into the payload
  1023. * of the FLOGI Request IOCB and the top-level callback function pointer
  1024. * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
  1025. * function field. The lpfc_issue_fabric_iocb routine is invoked to send
  1026. * out FLOGI ELS command with one outstanding fabric IOCB at a time.
  1027. *
  1028. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1029. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1030. * will be stored into the context1 field of the IOCB for the completion
  1031. * callback function to the FLOGI ELS command.
  1032. *
  1033. * Return code
  1034. * 0 - successfully issued flogi iocb for @vport
  1035. * 1 - failed to issue flogi iocb for @vport
  1036. **/
  1037. static int
  1038. lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1039. uint8_t retry)
  1040. {
  1041. struct lpfc_hba *phba = vport->phba;
  1042. struct serv_parm *sp;
  1043. IOCB_t *icmd;
  1044. struct lpfc_iocbq *elsiocb;
  1045. struct lpfc_sli_ring *pring;
  1046. uint8_t *pcmd;
  1047. uint16_t cmdsize;
  1048. uint32_t tmo;
  1049. int rc;
  1050. pring = &phba->sli.ring[LPFC_ELS_RING];
  1051. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  1052. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1053. ndlp->nlp_DID, ELS_CMD_FLOGI);
  1054. if (!elsiocb)
  1055. return 1;
  1056. icmd = &elsiocb->iocb;
  1057. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1058. /* For FLOGI request, remainder of payload is service parameters */
  1059. *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
  1060. pcmd += sizeof(uint32_t);
  1061. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  1062. sp = (struct serv_parm *) pcmd;
  1063. /* Setup CSPs accordingly for Fabric */
  1064. sp->cmn.e_d_tov = 0;
  1065. sp->cmn.w2.r_a_tov = 0;
  1066. sp->cmn.virtual_fabric_support = 0;
  1067. sp->cls1.classValid = 0;
  1068. sp->cls2.seqDelivery = 1;
  1069. sp->cls3.seqDelivery = 1;
  1070. if (sp->cmn.fcphLow < FC_PH3)
  1071. sp->cmn.fcphLow = FC_PH3;
  1072. if (sp->cmn.fcphHigh < FC_PH3)
  1073. sp->cmn.fcphHigh = FC_PH3;
  1074. if (phba->sli_rev == LPFC_SLI_REV4) {
  1075. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  1076. LPFC_SLI_INTF_IF_TYPE_0) {
  1077. elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
  1078. elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
  1079. /* FLOGI needs to be 3 for WQE FCFI */
  1080. /* Set the fcfi to the fcfi we registered with */
  1081. elsiocb->iocb.ulpContext = phba->fcf.fcfi;
  1082. }
  1083. } else {
  1084. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  1085. sp->cmn.request_multiple_Nport = 1;
  1086. /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
  1087. icmd->ulpCt_h = 1;
  1088. icmd->ulpCt_l = 0;
  1089. } else
  1090. sp->cmn.request_multiple_Nport = 0;
  1091. }
  1092. if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
  1093. icmd->un.elsreq64.myID = 0;
  1094. icmd->un.elsreq64.fl = 1;
  1095. }
  1096. tmo = phba->fc_ratov;
  1097. phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
  1098. lpfc_set_disctmo(vport);
  1099. phba->fc_ratov = tmo;
  1100. phba->fc_stat.elsXmitFLOGI++;
  1101. elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
  1102. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1103. "Issue FLOGI: opt:x%x",
  1104. phba->sli3_options, 0, 0);
  1105. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  1106. if (rc == IOCB_ERROR) {
  1107. lpfc_els_free_iocb(phba, elsiocb);
  1108. return 1;
  1109. }
  1110. return 0;
  1111. }
  1112. /**
  1113. * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
  1114. * @phba: pointer to lpfc hba data structure.
  1115. *
  1116. * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
  1117. * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
  1118. * list and issues an abort IOCB commond on each outstanding IOCB that
  1119. * contains a active Fabric_DID ndlp. Note that this function is to issue
  1120. * the abort IOCB command on all the outstanding IOCBs, thus when this
  1121. * function returns, it does not guarantee all the IOCBs are actually aborted.
  1122. *
  1123. * Return code
  1124. * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
  1125. **/
  1126. int
  1127. lpfc_els_abort_flogi(struct lpfc_hba *phba)
  1128. {
  1129. struct lpfc_sli_ring *pring;
  1130. struct lpfc_iocbq *iocb, *next_iocb;
  1131. struct lpfc_nodelist *ndlp;
  1132. IOCB_t *icmd;
  1133. /* Abort outstanding I/O on NPort <nlp_DID> */
  1134. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1135. "0201 Abort outstanding I/O on NPort x%x\n",
  1136. Fabric_DID);
  1137. pring = &phba->sli.ring[LPFC_ELS_RING];
  1138. /*
  1139. * Check the txcmplq for an iocb that matches the nport the driver is
  1140. * searching for.
  1141. */
  1142. spin_lock_irq(&phba->hbalock);
  1143. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  1144. icmd = &iocb->iocb;
  1145. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
  1146. ndlp = (struct lpfc_nodelist *)(iocb->context1);
  1147. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  1148. (ndlp->nlp_DID == Fabric_DID))
  1149. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  1150. }
  1151. }
  1152. spin_unlock_irq(&phba->hbalock);
  1153. return 0;
  1154. }
  1155. /**
  1156. * lpfc_initial_flogi - Issue an initial fabric login for a vport
  1157. * @vport: pointer to a host virtual N_Port data structure.
  1158. *
  1159. * This routine issues an initial Fabric Login (FLOGI) for the @vport
  1160. * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
  1161. * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
  1162. * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
  1163. * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
  1164. * is then invoked with the @vport and the ndlp to perform the FLOGI for the
  1165. * @vport.
  1166. *
  1167. * Return code
  1168. * 0 - failed to issue initial flogi for @vport
  1169. * 1 - successfully issued initial flogi for @vport
  1170. **/
  1171. int
  1172. lpfc_initial_flogi(struct lpfc_vport *vport)
  1173. {
  1174. struct lpfc_hba *phba = vport->phba;
  1175. struct lpfc_nodelist *ndlp;
  1176. vport->port_state = LPFC_FLOGI;
  1177. lpfc_set_disctmo(vport);
  1178. /* First look for the Fabric ndlp */
  1179. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  1180. if (!ndlp) {
  1181. /* Cannot find existing Fabric ndlp, so allocate a new one */
  1182. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1183. if (!ndlp)
  1184. return 0;
  1185. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  1186. /* Set the node type */
  1187. ndlp->nlp_type |= NLP_FABRIC;
  1188. /* Put ndlp onto node list */
  1189. lpfc_enqueue_node(vport, ndlp);
  1190. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  1191. /* re-setup ndlp without removing from node list */
  1192. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  1193. if (!ndlp)
  1194. return 0;
  1195. }
  1196. if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
  1197. /* This decrement of reference count to node shall kick off
  1198. * the release of the node.
  1199. */
  1200. lpfc_nlp_put(ndlp);
  1201. return 0;
  1202. }
  1203. return 1;
  1204. }
  1205. /**
  1206. * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
  1207. * @vport: pointer to a host virtual N_Port data structure.
  1208. *
  1209. * This routine issues an initial Fabric Discover (FDISC) for the @vport
  1210. * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
  1211. * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
  1212. * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
  1213. * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
  1214. * is then invoked with the @vport and the ndlp to perform the FDISC for the
  1215. * @vport.
  1216. *
  1217. * Return code
  1218. * 0 - failed to issue initial fdisc for @vport
  1219. * 1 - successfully issued initial fdisc for @vport
  1220. **/
  1221. int
  1222. lpfc_initial_fdisc(struct lpfc_vport *vport)
  1223. {
  1224. struct lpfc_hba *phba = vport->phba;
  1225. struct lpfc_nodelist *ndlp;
  1226. /* First look for the Fabric ndlp */
  1227. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  1228. if (!ndlp) {
  1229. /* Cannot find existing Fabric ndlp, so allocate a new one */
  1230. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1231. if (!ndlp)
  1232. return 0;
  1233. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  1234. /* Put ndlp onto node list */
  1235. lpfc_enqueue_node(vport, ndlp);
  1236. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  1237. /* re-setup ndlp without removing from node list */
  1238. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  1239. if (!ndlp)
  1240. return 0;
  1241. }
  1242. if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
  1243. /* decrement node reference count to trigger the release of
  1244. * the node.
  1245. */
  1246. lpfc_nlp_put(ndlp);
  1247. return 0;
  1248. }
  1249. return 1;
  1250. }
  1251. /**
  1252. * lpfc_more_plogi - Check and issue remaining plogis for a vport
  1253. * @vport: pointer to a host virtual N_Port data structure.
  1254. *
  1255. * This routine checks whether there are more remaining Port Logins
  1256. * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
  1257. * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
  1258. * to issue ELS PLOGIs up to the configured discover threads with the
  1259. * @vport (@vport->cfg_discovery_threads). The function also decrement
  1260. * the @vport's num_disc_node by 1 if it is not already 0.
  1261. **/
  1262. void
  1263. lpfc_more_plogi(struct lpfc_vport *vport)
  1264. {
  1265. int sentplogi;
  1266. if (vport->num_disc_nodes)
  1267. vport->num_disc_nodes--;
  1268. /* Continue discovery with <num_disc_nodes> PLOGIs to go */
  1269. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1270. "0232 Continue discovery with %d PLOGIs to go "
  1271. "Data: x%x x%x x%x\n",
  1272. vport->num_disc_nodes, vport->fc_plogi_cnt,
  1273. vport->fc_flag, vport->port_state);
  1274. /* Check to see if there are more PLOGIs to be sent */
  1275. if (vport->fc_flag & FC_NLP_MORE)
  1276. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  1277. sentplogi = lpfc_els_disc_plogi(vport);
  1278. return;
  1279. }
  1280. /**
  1281. * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
  1282. * @phba: pointer to lpfc hba data structure.
  1283. * @prsp: pointer to response IOCB payload.
  1284. * @ndlp: pointer to a node-list data structure.
  1285. *
  1286. * This routine checks and indicates whether the WWPN of an N_Port, retrieved
  1287. * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
  1288. * The following cases are considered N_Port confirmed:
  1289. * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
  1290. * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
  1291. * it does not have WWPN assigned either. If the WWPN is confirmed, the
  1292. * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
  1293. * 1) if there is a node on vport list other than the @ndlp with the same
  1294. * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
  1295. * on that node to release the RPI associated with the node; 2) if there is
  1296. * no node found on vport list with the same WWPN of the N_Port PLOGI logged
  1297. * into, a new node shall be allocated (or activated). In either case, the
  1298. * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
  1299. * be released and the new_ndlp shall be put on to the vport node list and
  1300. * its pointer returned as the confirmed node.
  1301. *
  1302. * Note that before the @ndlp got "released", the keepDID from not-matching
  1303. * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
  1304. * of the @ndlp. This is because the release of @ndlp is actually to put it
  1305. * into an inactive state on the vport node list and the vport node list
  1306. * management algorithm does not allow two node with a same DID.
  1307. *
  1308. * Return code
  1309. * pointer to the PLOGI N_Port @ndlp
  1310. **/
  1311. static struct lpfc_nodelist *
  1312. lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
  1313. struct lpfc_nodelist *ndlp)
  1314. {
  1315. struct lpfc_vport *vport = ndlp->vport;
  1316. struct lpfc_nodelist *new_ndlp;
  1317. struct lpfc_rport_data *rdata;
  1318. struct fc_rport *rport;
  1319. struct serv_parm *sp;
  1320. uint8_t name[sizeof(struct lpfc_name)];
  1321. uint32_t rc, keepDID = 0;
  1322. int put_node;
  1323. int put_rport;
  1324. struct lpfc_node_rrqs rrq;
  1325. /* Fabric nodes can have the same WWPN so we don't bother searching
  1326. * by WWPN. Just return the ndlp that was given to us.
  1327. */
  1328. if (ndlp->nlp_type & NLP_FABRIC)
  1329. return ndlp;
  1330. sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
  1331. memset(name, 0, sizeof(struct lpfc_name));
  1332. /* Now we find out if the NPort we are logging into, matches the WWPN
  1333. * we have for that ndlp. If not, we have some work to do.
  1334. */
  1335. new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
  1336. if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
  1337. return ndlp;
  1338. memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
  1339. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1340. "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
  1341. ndlp, ndlp->nlp_DID, new_ndlp);
  1342. if (!new_ndlp) {
  1343. rc = memcmp(&ndlp->nlp_portname, name,
  1344. sizeof(struct lpfc_name));
  1345. if (!rc)
  1346. return ndlp;
  1347. new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
  1348. if (!new_ndlp)
  1349. return ndlp;
  1350. lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
  1351. } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
  1352. rc = memcmp(&ndlp->nlp_portname, name,
  1353. sizeof(struct lpfc_name));
  1354. if (!rc)
  1355. return ndlp;
  1356. new_ndlp = lpfc_enable_node(vport, new_ndlp,
  1357. NLP_STE_UNUSED_NODE);
  1358. if (!new_ndlp)
  1359. return ndlp;
  1360. keepDID = new_ndlp->nlp_DID;
  1361. if (phba->sli_rev == LPFC_SLI_REV4)
  1362. memcpy(&rrq.xri_bitmap,
  1363. &new_ndlp->active_rrqs.xri_bitmap,
  1364. sizeof(new_ndlp->active_rrqs.xri_bitmap));
  1365. } else {
  1366. keepDID = new_ndlp->nlp_DID;
  1367. if (phba->sli_rev == LPFC_SLI_REV4)
  1368. memcpy(&rrq.xri_bitmap,
  1369. &new_ndlp->active_rrqs.xri_bitmap,
  1370. sizeof(new_ndlp->active_rrqs.xri_bitmap));
  1371. }
  1372. lpfc_unreg_rpi(vport, new_ndlp);
  1373. new_ndlp->nlp_DID = ndlp->nlp_DID;
  1374. new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
  1375. if (phba->sli_rev == LPFC_SLI_REV4)
  1376. memcpy(new_ndlp->active_rrqs.xri_bitmap,
  1377. &ndlp->active_rrqs.xri_bitmap,
  1378. sizeof(ndlp->active_rrqs.xri_bitmap));
  1379. if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
  1380. new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1381. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1382. /* Set state will put new_ndlp on to node list if not already done */
  1383. lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
  1384. /* Move this back to NPR state */
  1385. if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
  1386. /* The new_ndlp is replacing ndlp totally, so we need
  1387. * to put ndlp on UNUSED list and try to free it.
  1388. */
  1389. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1390. "3179 PLOGI confirm NEW: %x %x\n",
  1391. new_ndlp->nlp_DID, keepDID);
  1392. /* Fix up the rport accordingly */
  1393. rport = ndlp->rport;
  1394. if (rport) {
  1395. rdata = rport->dd_data;
  1396. if (rdata->pnode == ndlp) {
  1397. lpfc_nlp_put(ndlp);
  1398. ndlp->rport = NULL;
  1399. rdata->pnode = lpfc_nlp_get(new_ndlp);
  1400. new_ndlp->rport = rport;
  1401. }
  1402. new_ndlp->nlp_type = ndlp->nlp_type;
  1403. }
  1404. /* We shall actually free the ndlp with both nlp_DID and
  1405. * nlp_portname fields equals 0 to avoid any ndlp on the
  1406. * nodelist never to be used.
  1407. */
  1408. if (ndlp->nlp_DID == 0) {
  1409. spin_lock_irq(&phba->ndlp_lock);
  1410. NLP_SET_FREE_REQ(ndlp);
  1411. spin_unlock_irq(&phba->ndlp_lock);
  1412. }
  1413. /* Two ndlps cannot have the same did on the nodelist */
  1414. ndlp->nlp_DID = keepDID;
  1415. if (phba->sli_rev == LPFC_SLI_REV4)
  1416. memcpy(&ndlp->active_rrqs.xri_bitmap,
  1417. &rrq.xri_bitmap,
  1418. sizeof(ndlp->active_rrqs.xri_bitmap));
  1419. lpfc_drop_node(vport, ndlp);
  1420. }
  1421. else {
  1422. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1423. "3180 PLOGI confirm SWAP: %x %x\n",
  1424. new_ndlp->nlp_DID, keepDID);
  1425. lpfc_unreg_rpi(vport, ndlp);
  1426. /* Two ndlps cannot have the same did */
  1427. ndlp->nlp_DID = keepDID;
  1428. if (phba->sli_rev == LPFC_SLI_REV4)
  1429. memcpy(&ndlp->active_rrqs.xri_bitmap,
  1430. &rrq.xri_bitmap,
  1431. sizeof(ndlp->active_rrqs.xri_bitmap));
  1432. /* Since we are swapping the ndlp passed in with the new one
  1433. * and the did has already been swapped, copy over state.
  1434. * The new WWNs are already in new_ndlp since thats what
  1435. * we looked it up by in the begining of this routine.
  1436. */
  1437. new_ndlp->nlp_state = ndlp->nlp_state;
  1438. /* Since we are switching over to the new_ndlp, the old
  1439. * ndlp should be put in the NPR state, unless we have
  1440. * already started re-discovery on it.
  1441. */
  1442. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  1443. (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
  1444. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1445. /* Fix up the rport accordingly */
  1446. rport = ndlp->rport;
  1447. if (rport) {
  1448. rdata = rport->dd_data;
  1449. put_node = rdata->pnode != NULL;
  1450. put_rport = ndlp->rport != NULL;
  1451. rdata->pnode = NULL;
  1452. ndlp->rport = NULL;
  1453. if (put_node)
  1454. lpfc_nlp_put(ndlp);
  1455. if (put_rport)
  1456. put_device(&rport->dev);
  1457. }
  1458. }
  1459. return new_ndlp;
  1460. }
  1461. /**
  1462. * lpfc_end_rscn - Check and handle more rscn for a vport
  1463. * @vport: pointer to a host virtual N_Port data structure.
  1464. *
  1465. * This routine checks whether more Registration State Change
  1466. * Notifications (RSCNs) came in while the discovery state machine was in
  1467. * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
  1468. * invoked to handle the additional RSCNs for the @vport. Otherwise, the
  1469. * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
  1470. * handling the RSCNs.
  1471. **/
  1472. void
  1473. lpfc_end_rscn(struct lpfc_vport *vport)
  1474. {
  1475. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1476. if (vport->fc_flag & FC_RSCN_MODE) {
  1477. /*
  1478. * Check to see if more RSCNs came in while we were
  1479. * processing this one.
  1480. */
  1481. if (vport->fc_rscn_id_cnt ||
  1482. (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
  1483. lpfc_els_handle_rscn(vport);
  1484. else {
  1485. spin_lock_irq(shost->host_lock);
  1486. vport->fc_flag &= ~FC_RSCN_MODE;
  1487. spin_unlock_irq(shost->host_lock);
  1488. }
  1489. }
  1490. }
  1491. /**
  1492. * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
  1493. * @phba: pointer to lpfc hba data structure.
  1494. * @cmdiocb: pointer to lpfc command iocb data structure.
  1495. * @rspiocb: pointer to lpfc response iocb data structure.
  1496. *
  1497. * This routine will call the clear rrq function to free the rrq and
  1498. * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
  1499. * exist then the clear_rrq is still called because the rrq needs to
  1500. * be freed.
  1501. **/
  1502. static void
  1503. lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1504. struct lpfc_iocbq *rspiocb)
  1505. {
  1506. struct lpfc_vport *vport = cmdiocb->vport;
  1507. IOCB_t *irsp;
  1508. struct lpfc_nodelist *ndlp;
  1509. struct lpfc_node_rrq *rrq;
  1510. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1511. rrq = cmdiocb->context_un.rrq;
  1512. cmdiocb->context_un.rsp_iocb = rspiocb;
  1513. irsp = &rspiocb->iocb;
  1514. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1515. "RRQ cmpl: status:x%x/x%x did:x%x",
  1516. irsp->ulpStatus, irsp->un.ulpWord[4],
  1517. irsp->un.elsreq64.remoteID);
  1518. ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
  1519. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
  1520. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1521. "2882 RRQ completes to NPort x%x "
  1522. "with no ndlp. Data: x%x x%x x%x\n",
  1523. irsp->un.elsreq64.remoteID,
  1524. irsp->ulpStatus, irsp->un.ulpWord[4],
  1525. irsp->ulpIoTag);
  1526. goto out;
  1527. }
  1528. /* rrq completes to NPort <nlp_DID> */
  1529. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1530. "2880 RRQ completes to NPort x%x "
  1531. "Data: x%x x%x x%x x%x x%x\n",
  1532. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1533. irsp->ulpTimeout, rrq->xritag, rrq->rxid);
  1534. if (irsp->ulpStatus) {
  1535. /* Check for retry */
  1536. /* RRQ failed Don't print the vport to vport rjts */
  1537. if (irsp->ulpStatus != IOSTAT_LS_RJT ||
  1538. (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
  1539. ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
  1540. (phba)->pport->cfg_log_verbose & LOG_ELS)
  1541. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1542. "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
  1543. ndlp->nlp_DID, irsp->ulpStatus,
  1544. irsp->un.ulpWord[4]);
  1545. }
  1546. out:
  1547. if (rrq)
  1548. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  1549. lpfc_els_free_iocb(phba, cmdiocb);
  1550. return;
  1551. }
  1552. /**
  1553. * lpfc_cmpl_els_plogi - Completion callback function for plogi
  1554. * @phba: pointer to lpfc hba data structure.
  1555. * @cmdiocb: pointer to lpfc command iocb data structure.
  1556. * @rspiocb: pointer to lpfc response iocb data structure.
  1557. *
  1558. * This routine is the completion callback function for issuing the Port
  1559. * Login (PLOGI) command. For PLOGI completion, there must be an active
  1560. * ndlp on the vport node list that matches the remote node ID from the
  1561. * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
  1562. * ignored and command IOCB released. The PLOGI response IOCB status is
  1563. * checked for error conditons. If there is error status reported, PLOGI
  1564. * retry shall be attempted by invoking the lpfc_els_retry() routine.
  1565. * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
  1566. * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
  1567. * (DSM) is set for this PLOGI completion. Finally, it checks whether
  1568. * there are additional N_Port nodes with the vport that need to perform
  1569. * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
  1570. * PLOGIs.
  1571. **/
  1572. static void
  1573. lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1574. struct lpfc_iocbq *rspiocb)
  1575. {
  1576. struct lpfc_vport *vport = cmdiocb->vport;
  1577. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1578. IOCB_t *irsp;
  1579. struct lpfc_nodelist *ndlp;
  1580. struct lpfc_dmabuf *prsp;
  1581. int disc, rc, did, type;
  1582. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1583. cmdiocb->context_un.rsp_iocb = rspiocb;
  1584. irsp = &rspiocb->iocb;
  1585. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1586. "PLOGI cmpl: status:x%x/x%x did:x%x",
  1587. irsp->ulpStatus, irsp->un.ulpWord[4],
  1588. irsp->un.elsreq64.remoteID);
  1589. ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
  1590. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  1591. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1592. "0136 PLOGI completes to NPort x%x "
  1593. "with no ndlp. Data: x%x x%x x%x\n",
  1594. irsp->un.elsreq64.remoteID,
  1595. irsp->ulpStatus, irsp->un.ulpWord[4],
  1596. irsp->ulpIoTag);
  1597. goto out;
  1598. }
  1599. /* Since ndlp can be freed in the disc state machine, note if this node
  1600. * is being used during discovery.
  1601. */
  1602. spin_lock_irq(shost->host_lock);
  1603. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  1604. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1605. spin_unlock_irq(shost->host_lock);
  1606. rc = 0;
  1607. /* PLOGI completes to NPort <nlp_DID> */
  1608. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1609. "0102 PLOGI completes to NPort x%x "
  1610. "Data: x%x x%x x%x x%x x%x\n",
  1611. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1612. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  1613. /* Check to see if link went down during discovery */
  1614. if (lpfc_els_chk_latt(vport)) {
  1615. spin_lock_irq(shost->host_lock);
  1616. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1617. spin_unlock_irq(shost->host_lock);
  1618. goto out;
  1619. }
  1620. /* ndlp could be freed in DSM, save these values now */
  1621. type = ndlp->nlp_type;
  1622. did = ndlp->nlp_DID;
  1623. if (irsp->ulpStatus) {
  1624. /* Check for retry */
  1625. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1626. /* ELS command is being retried */
  1627. if (disc) {
  1628. spin_lock_irq(shost->host_lock);
  1629. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1630. spin_unlock_irq(shost->host_lock);
  1631. }
  1632. goto out;
  1633. }
  1634. /* PLOGI failed Don't print the vport to vport rjts */
  1635. if (irsp->ulpStatus != IOSTAT_LS_RJT ||
  1636. (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
  1637. ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
  1638. (phba)->pport->cfg_log_verbose & LOG_ELS)
  1639. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1640. "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
  1641. ndlp->nlp_DID, irsp->ulpStatus,
  1642. irsp->un.ulpWord[4]);
  1643. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1644. if (lpfc_error_lost_link(irsp))
  1645. rc = NLP_STE_FREED_NODE;
  1646. else
  1647. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1648. NLP_EVT_CMPL_PLOGI);
  1649. } else {
  1650. /* Good status, call state machine */
  1651. prsp = list_entry(((struct lpfc_dmabuf *)
  1652. cmdiocb->context2)->list.next,
  1653. struct lpfc_dmabuf, list);
  1654. ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
  1655. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1656. NLP_EVT_CMPL_PLOGI);
  1657. }
  1658. if (disc && vport->num_disc_nodes) {
  1659. /* Check to see if there are more PLOGIs to be sent */
  1660. lpfc_more_plogi(vport);
  1661. if (vport->num_disc_nodes == 0) {
  1662. spin_lock_irq(shost->host_lock);
  1663. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1664. spin_unlock_irq(shost->host_lock);
  1665. lpfc_can_disctmo(vport);
  1666. lpfc_end_rscn(vport);
  1667. }
  1668. }
  1669. out:
  1670. lpfc_els_free_iocb(phba, cmdiocb);
  1671. return;
  1672. }
  1673. /**
  1674. * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
  1675. * @vport: pointer to a host virtual N_Port data structure.
  1676. * @did: destination port identifier.
  1677. * @retry: number of retries to the command IOCB.
  1678. *
  1679. * This routine issues a Port Login (PLOGI) command to a remote N_Port
  1680. * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
  1681. * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
  1682. * This routine constructs the proper feilds of the PLOGI IOCB and invokes
  1683. * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
  1684. *
  1685. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1686. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1687. * will be stored into the context1 field of the IOCB for the completion
  1688. * callback function to the PLOGI ELS command.
  1689. *
  1690. * Return code
  1691. * 0 - Successfully issued a plogi for @vport
  1692. * 1 - failed to issue a plogi for @vport
  1693. **/
  1694. int
  1695. lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
  1696. {
  1697. struct lpfc_hba *phba = vport->phba;
  1698. struct serv_parm *sp;
  1699. IOCB_t *icmd;
  1700. struct lpfc_nodelist *ndlp;
  1701. struct lpfc_iocbq *elsiocb;
  1702. struct lpfc_sli *psli;
  1703. uint8_t *pcmd;
  1704. uint16_t cmdsize;
  1705. int ret;
  1706. psli = &phba->sli;
  1707. ndlp = lpfc_findnode_did(vport, did);
  1708. if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
  1709. ndlp = NULL;
  1710. /* If ndlp is not NULL, we will bump the reference count on it */
  1711. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  1712. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  1713. ELS_CMD_PLOGI);
  1714. if (!elsiocb)
  1715. return 1;
  1716. icmd = &elsiocb->iocb;
  1717. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1718. /* For PLOGI request, remainder of payload is service parameters */
  1719. *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
  1720. pcmd += sizeof(uint32_t);
  1721. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  1722. sp = (struct serv_parm *) pcmd;
  1723. /*
  1724. * If we are a N-port connected to a Fabric, fix-up paramm's so logins
  1725. * to device on remote loops work.
  1726. */
  1727. if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
  1728. sp->cmn.altBbCredit = 1;
  1729. if (sp->cmn.fcphLow < FC_PH_4_3)
  1730. sp->cmn.fcphLow = FC_PH_4_3;
  1731. if (sp->cmn.fcphHigh < FC_PH3)
  1732. sp->cmn.fcphHigh = FC_PH3;
  1733. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1734. "Issue PLOGI: did:x%x",
  1735. did, 0, 0);
  1736. phba->fc_stat.elsXmitPLOGI++;
  1737. elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
  1738. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  1739. if (ret == IOCB_ERROR) {
  1740. lpfc_els_free_iocb(phba, elsiocb);
  1741. return 1;
  1742. }
  1743. return 0;
  1744. }
  1745. /**
  1746. * lpfc_cmpl_els_prli - Completion callback function for prli
  1747. * @phba: pointer to lpfc hba data structure.
  1748. * @cmdiocb: pointer to lpfc command iocb data structure.
  1749. * @rspiocb: pointer to lpfc response iocb data structure.
  1750. *
  1751. * This routine is the completion callback function for a Process Login
  1752. * (PRLI) ELS command. The PRLI response IOCB status is checked for error
  1753. * status. If there is error status reported, PRLI retry shall be attempted
  1754. * by invoking the lpfc_els_retry() routine. Otherwise, the state
  1755. * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
  1756. * ndlp to mark the PRLI completion.
  1757. **/
  1758. static void
  1759. lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1760. struct lpfc_iocbq *rspiocb)
  1761. {
  1762. struct lpfc_vport *vport = cmdiocb->vport;
  1763. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1764. IOCB_t *irsp;
  1765. struct lpfc_sli *psli;
  1766. struct lpfc_nodelist *ndlp;
  1767. psli = &phba->sli;
  1768. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1769. cmdiocb->context_un.rsp_iocb = rspiocb;
  1770. irsp = &(rspiocb->iocb);
  1771. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1772. spin_lock_irq(shost->host_lock);
  1773. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  1774. spin_unlock_irq(shost->host_lock);
  1775. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1776. "PRLI cmpl: status:x%x/x%x did:x%x",
  1777. irsp->ulpStatus, irsp->un.ulpWord[4],
  1778. ndlp->nlp_DID);
  1779. /* PRLI completes to NPort <nlp_DID> */
  1780. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1781. "0103 PRLI completes to NPort x%x "
  1782. "Data: x%x x%x x%x x%x\n",
  1783. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1784. irsp->ulpTimeout, vport->num_disc_nodes);
  1785. vport->fc_prli_sent--;
  1786. /* Check to see if link went down during discovery */
  1787. if (lpfc_els_chk_latt(vport))
  1788. goto out;
  1789. if (irsp->ulpStatus) {
  1790. /* Check for retry */
  1791. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1792. /* ELS command is being retried */
  1793. goto out;
  1794. }
  1795. /* PRLI failed */
  1796. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1797. "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
  1798. ndlp->nlp_DID, irsp->ulpStatus,
  1799. irsp->un.ulpWord[4]);
  1800. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1801. if (lpfc_error_lost_link(irsp))
  1802. goto out;
  1803. else
  1804. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1805. NLP_EVT_CMPL_PRLI);
  1806. } else
  1807. /* Good status, call state machine */
  1808. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1809. NLP_EVT_CMPL_PRLI);
  1810. out:
  1811. lpfc_els_free_iocb(phba, cmdiocb);
  1812. return;
  1813. }
  1814. /**
  1815. * lpfc_issue_els_prli - Issue a prli iocb command for a vport
  1816. * @vport: pointer to a host virtual N_Port data structure.
  1817. * @ndlp: pointer to a node-list data structure.
  1818. * @retry: number of retries to the command IOCB.
  1819. *
  1820. * This routine issues a Process Login (PRLI) ELS command for the
  1821. * @vport. The PRLI service parameters are set up in the payload of the
  1822. * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
  1823. * is put to the IOCB completion callback func field before invoking the
  1824. * routine lpfc_sli_issue_iocb() to send out PRLI command.
  1825. *
  1826. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1827. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1828. * will be stored into the context1 field of the IOCB for the completion
  1829. * callback function to the PRLI ELS command.
  1830. *
  1831. * Return code
  1832. * 0 - successfully issued prli iocb command for @vport
  1833. * 1 - failed to issue prli iocb command for @vport
  1834. **/
  1835. int
  1836. lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1837. uint8_t retry)
  1838. {
  1839. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1840. struct lpfc_hba *phba = vport->phba;
  1841. PRLI *npr;
  1842. IOCB_t *icmd;
  1843. struct lpfc_iocbq *elsiocb;
  1844. uint8_t *pcmd;
  1845. uint16_t cmdsize;
  1846. cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
  1847. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1848. ndlp->nlp_DID, ELS_CMD_PRLI);
  1849. if (!elsiocb)
  1850. return 1;
  1851. icmd = &elsiocb->iocb;
  1852. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1853. /* For PRLI request, remainder of payload is service parameters */
  1854. memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
  1855. *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
  1856. pcmd += sizeof(uint32_t);
  1857. /* For PRLI, remainder of payload is PRLI parameter page */
  1858. npr = (PRLI *) pcmd;
  1859. /*
  1860. * If our firmware version is 3.20 or later,
  1861. * set the following bits for FC-TAPE support.
  1862. */
  1863. if (phba->vpd.rev.feaLevelHigh >= 0x02) {
  1864. npr->ConfmComplAllowed = 1;
  1865. npr->Retry = 1;
  1866. npr->TaskRetryIdReq = 1;
  1867. }
  1868. npr->estabImagePair = 1;
  1869. npr->readXferRdyDis = 1;
  1870. /* For FCP support */
  1871. npr->prliType = PRLI_FCP_TYPE;
  1872. npr->initiatorFunc = 1;
  1873. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1874. "Issue PRLI: did:x%x",
  1875. ndlp->nlp_DID, 0, 0);
  1876. phba->fc_stat.elsXmitPRLI++;
  1877. elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
  1878. spin_lock_irq(shost->host_lock);
  1879. ndlp->nlp_flag |= NLP_PRLI_SND;
  1880. spin_unlock_irq(shost->host_lock);
  1881. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  1882. IOCB_ERROR) {
  1883. spin_lock_irq(shost->host_lock);
  1884. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  1885. spin_unlock_irq(shost->host_lock);
  1886. lpfc_els_free_iocb(phba, elsiocb);
  1887. return 1;
  1888. }
  1889. vport->fc_prli_sent++;
  1890. return 0;
  1891. }
  1892. /**
  1893. * lpfc_rscn_disc - Perform rscn discovery for a vport
  1894. * @vport: pointer to a host virtual N_Port data structure.
  1895. *
  1896. * This routine performs Registration State Change Notification (RSCN)
  1897. * discovery for a @vport. If the @vport's node port recovery count is not
  1898. * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
  1899. * the nodes that need recovery. If none of the PLOGI were needed through
  1900. * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
  1901. * invoked to check and handle possible more RSCN came in during the period
  1902. * of processing the current ones.
  1903. **/
  1904. static void
  1905. lpfc_rscn_disc(struct lpfc_vport *vport)
  1906. {
  1907. lpfc_can_disctmo(vport);
  1908. /* RSCN discovery */
  1909. /* go thru NPR nodes and issue ELS PLOGIs */
  1910. if (vport->fc_npr_cnt)
  1911. if (lpfc_els_disc_plogi(vport))
  1912. return;
  1913. lpfc_end_rscn(vport);
  1914. }
  1915. /**
  1916. * lpfc_adisc_done - Complete the adisc phase of discovery
  1917. * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
  1918. *
  1919. * This function is called when the final ADISC is completed during discovery.
  1920. * This function handles clearing link attention or issuing reg_vpi depending
  1921. * on whether npiv is enabled. This function also kicks off the PLOGI phase of
  1922. * discovery.
  1923. * This function is called with no locks held.
  1924. **/
  1925. static void
  1926. lpfc_adisc_done(struct lpfc_vport *vport)
  1927. {
  1928. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1929. struct lpfc_hba *phba = vport->phba;
  1930. /*
  1931. * For NPIV, cmpl_reg_vpi will set port_state to READY,
  1932. * and continue discovery.
  1933. */
  1934. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1935. !(vport->fc_flag & FC_RSCN_MODE) &&
  1936. (phba->sli_rev < LPFC_SLI_REV4)) {
  1937. lpfc_issue_reg_vpi(phba, vport);
  1938. return;
  1939. }
  1940. /*
  1941. * For SLI2, we need to set port_state to READY
  1942. * and continue discovery.
  1943. */
  1944. if (vport->port_state < LPFC_VPORT_READY) {
  1945. /* If we get here, there is nothing to ADISC */
  1946. if (vport->port_type == LPFC_PHYSICAL_PORT)
  1947. lpfc_issue_clear_la(phba, vport);
  1948. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  1949. vport->num_disc_nodes = 0;
  1950. /* go thru NPR list, issue ELS PLOGIs */
  1951. if (vport->fc_npr_cnt)
  1952. lpfc_els_disc_plogi(vport);
  1953. if (!vport->num_disc_nodes) {
  1954. spin_lock_irq(shost->host_lock);
  1955. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1956. spin_unlock_irq(shost->host_lock);
  1957. lpfc_can_disctmo(vport);
  1958. lpfc_end_rscn(vport);
  1959. }
  1960. }
  1961. vport->port_state = LPFC_VPORT_READY;
  1962. } else
  1963. lpfc_rscn_disc(vport);
  1964. }
  1965. /**
  1966. * lpfc_more_adisc - Issue more adisc as needed
  1967. * @vport: pointer to a host virtual N_Port data structure.
  1968. *
  1969. * This routine determines whether there are more ndlps on a @vport
  1970. * node list need to have Address Discover (ADISC) issued. If so, it will
  1971. * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
  1972. * remaining nodes which need to have ADISC sent.
  1973. **/
  1974. void
  1975. lpfc_more_adisc(struct lpfc_vport *vport)
  1976. {
  1977. int sentadisc;
  1978. if (vport->num_disc_nodes)
  1979. vport->num_disc_nodes--;
  1980. /* Continue discovery with <num_disc_nodes> ADISCs to go */
  1981. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1982. "0210 Continue discovery with %d ADISCs to go "
  1983. "Data: x%x x%x x%x\n",
  1984. vport->num_disc_nodes, vport->fc_adisc_cnt,
  1985. vport->fc_flag, vport->port_state);
  1986. /* Check to see if there are more ADISCs to be sent */
  1987. if (vport->fc_flag & FC_NLP_MORE) {
  1988. lpfc_set_disctmo(vport);
  1989. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  1990. sentadisc = lpfc_els_disc_adisc(vport);
  1991. }
  1992. if (!vport->num_disc_nodes)
  1993. lpfc_adisc_done(vport);
  1994. return;
  1995. }
  1996. /**
  1997. * lpfc_cmpl_els_adisc - Completion callback function for adisc
  1998. * @phba: pointer to lpfc hba data structure.
  1999. * @cmdiocb: pointer to lpfc command iocb data structure.
  2000. * @rspiocb: pointer to lpfc response iocb data structure.
  2001. *
  2002. * This routine is the completion function for issuing the Address Discover
  2003. * (ADISC) command. It first checks to see whether link went down during
  2004. * the discovery process. If so, the node will be marked as node port
  2005. * recovery for issuing discover IOCB by the link attention handler and
  2006. * exit. Otherwise, the response status is checked. If error was reported
  2007. * in the response status, the ADISC command shall be retried by invoking
  2008. * the lpfc_els_retry() routine. Otherwise, if no error was reported in
  2009. * the response status, the state machine is invoked to set transition
  2010. * with respect to NLP_EVT_CMPL_ADISC event.
  2011. **/
  2012. static void
  2013. lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2014. struct lpfc_iocbq *rspiocb)
  2015. {
  2016. struct lpfc_vport *vport = cmdiocb->vport;
  2017. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2018. IOCB_t *irsp;
  2019. struct lpfc_nodelist *ndlp;
  2020. int disc;
  2021. /* we pass cmdiocb to state machine which needs rspiocb as well */
  2022. cmdiocb->context_un.rsp_iocb = rspiocb;
  2023. irsp = &(rspiocb->iocb);
  2024. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2025. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2026. "ADISC cmpl: status:x%x/x%x did:x%x",
  2027. irsp->ulpStatus, irsp->un.ulpWord[4],
  2028. ndlp->nlp_DID);
  2029. /* Since ndlp can be freed in the disc state machine, note if this node
  2030. * is being used during discovery.
  2031. */
  2032. spin_lock_irq(shost->host_lock);
  2033. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  2034. ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
  2035. spin_unlock_irq(shost->host_lock);
  2036. /* ADISC completes to NPort <nlp_DID> */
  2037. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2038. "0104 ADISC completes to NPort x%x "
  2039. "Data: x%x x%x x%x x%x x%x\n",
  2040. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  2041. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  2042. /* Check to see if link went down during discovery */
  2043. if (lpfc_els_chk_latt(vport)) {
  2044. spin_lock_irq(shost->host_lock);
  2045. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2046. spin_unlock_irq(shost->host_lock);
  2047. goto out;
  2048. }
  2049. if (irsp->ulpStatus) {
  2050. /* Check for retry */
  2051. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  2052. /* ELS command is being retried */
  2053. if (disc) {
  2054. spin_lock_irq(shost->host_lock);
  2055. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2056. spin_unlock_irq(shost->host_lock);
  2057. lpfc_set_disctmo(vport);
  2058. }
  2059. goto out;
  2060. }
  2061. /* ADISC failed */
  2062. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2063. "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
  2064. ndlp->nlp_DID, irsp->ulpStatus,
  2065. irsp->un.ulpWord[4]);
  2066. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  2067. if (!lpfc_error_lost_link(irsp))
  2068. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2069. NLP_EVT_CMPL_ADISC);
  2070. } else
  2071. /* Good status, call state machine */
  2072. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2073. NLP_EVT_CMPL_ADISC);
  2074. /* Check to see if there are more ADISCs to be sent */
  2075. if (disc && vport->num_disc_nodes)
  2076. lpfc_more_adisc(vport);
  2077. out:
  2078. lpfc_els_free_iocb(phba, cmdiocb);
  2079. return;
  2080. }
  2081. /**
  2082. * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
  2083. * @vport: pointer to a virtual N_Port data structure.
  2084. * @ndlp: pointer to a node-list data structure.
  2085. * @retry: number of retries to the command IOCB.
  2086. *
  2087. * This routine issues an Address Discover (ADISC) for an @ndlp on a
  2088. * @vport. It prepares the payload of the ADISC ELS command, updates the
  2089. * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
  2090. * to issue the ADISC ELS command.
  2091. *
  2092. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2093. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2094. * will be stored into the context1 field of the IOCB for the completion
  2095. * callback function to the ADISC ELS command.
  2096. *
  2097. * Return code
  2098. * 0 - successfully issued adisc
  2099. * 1 - failed to issue adisc
  2100. **/
  2101. int
  2102. lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2103. uint8_t retry)
  2104. {
  2105. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2106. struct lpfc_hba *phba = vport->phba;
  2107. ADISC *ap;
  2108. IOCB_t *icmd;
  2109. struct lpfc_iocbq *elsiocb;
  2110. uint8_t *pcmd;
  2111. uint16_t cmdsize;
  2112. cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
  2113. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2114. ndlp->nlp_DID, ELS_CMD_ADISC);
  2115. if (!elsiocb)
  2116. return 1;
  2117. icmd = &elsiocb->iocb;
  2118. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2119. /* For ADISC request, remainder of payload is service parameters */
  2120. *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
  2121. pcmd += sizeof(uint32_t);
  2122. /* Fill in ADISC payload */
  2123. ap = (ADISC *) pcmd;
  2124. ap->hardAL_PA = phba->fc_pref_ALPA;
  2125. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2126. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2127. ap->DID = be32_to_cpu(vport->fc_myDID);
  2128. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2129. "Issue ADISC: did:x%x",
  2130. ndlp->nlp_DID, 0, 0);
  2131. phba->fc_stat.elsXmitADISC++;
  2132. elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
  2133. spin_lock_irq(shost->host_lock);
  2134. ndlp->nlp_flag |= NLP_ADISC_SND;
  2135. spin_unlock_irq(shost->host_lock);
  2136. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  2137. IOCB_ERROR) {
  2138. spin_lock_irq(shost->host_lock);
  2139. ndlp->nlp_flag &= ~NLP_ADISC_SND;
  2140. spin_unlock_irq(shost->host_lock);
  2141. lpfc_els_free_iocb(phba, elsiocb);
  2142. return 1;
  2143. }
  2144. return 0;
  2145. }
  2146. /**
  2147. * lpfc_cmpl_els_logo - Completion callback function for logo
  2148. * @phba: pointer to lpfc hba data structure.
  2149. * @cmdiocb: pointer to lpfc command iocb data structure.
  2150. * @rspiocb: pointer to lpfc response iocb data structure.
  2151. *
  2152. * This routine is the completion function for issuing the ELS Logout (LOGO)
  2153. * command. If no error status was reported from the LOGO response, the
  2154. * state machine of the associated ndlp shall be invoked for transition with
  2155. * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
  2156. * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
  2157. **/
  2158. static void
  2159. lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2160. struct lpfc_iocbq *rspiocb)
  2161. {
  2162. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2163. struct lpfc_vport *vport = ndlp->vport;
  2164. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2165. IOCB_t *irsp;
  2166. struct lpfc_sli *psli;
  2167. struct lpfcMboxq *mbox;
  2168. unsigned long flags;
  2169. uint32_t skip_recovery = 0;
  2170. psli = &phba->sli;
  2171. /* we pass cmdiocb to state machine which needs rspiocb as well */
  2172. cmdiocb->context_un.rsp_iocb = rspiocb;
  2173. irsp = &(rspiocb->iocb);
  2174. spin_lock_irq(shost->host_lock);
  2175. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  2176. spin_unlock_irq(shost->host_lock);
  2177. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2178. "LOGO cmpl: status:x%x/x%x did:x%x",
  2179. irsp->ulpStatus, irsp->un.ulpWord[4],
  2180. ndlp->nlp_DID);
  2181. /* LOGO completes to NPort <nlp_DID> */
  2182. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2183. "0105 LOGO completes to NPort x%x "
  2184. "Data: x%x x%x x%x x%x\n",
  2185. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  2186. irsp->ulpTimeout, vport->num_disc_nodes);
  2187. if (lpfc_els_chk_latt(vport)) {
  2188. skip_recovery = 1;
  2189. goto out;
  2190. }
  2191. /* Check to see if link went down during discovery */
  2192. if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
  2193. /* NLP_EVT_DEVICE_RM should unregister the RPI
  2194. * which should abort all outstanding IOs.
  2195. */
  2196. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2197. NLP_EVT_DEVICE_RM);
  2198. skip_recovery = 1;
  2199. goto out;
  2200. }
  2201. if (irsp->ulpStatus) {
  2202. /* Check for retry */
  2203. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  2204. /* ELS command is being retried */
  2205. skip_recovery = 1;
  2206. goto out;
  2207. }
  2208. /* LOGO failed */
  2209. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2210. "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
  2211. ndlp->nlp_DID, irsp->ulpStatus,
  2212. irsp->un.ulpWord[4]);
  2213. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  2214. if (lpfc_error_lost_link(irsp)) {
  2215. skip_recovery = 1;
  2216. goto out;
  2217. }
  2218. }
  2219. /* Call state machine. This will unregister the rpi if needed. */
  2220. lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
  2221. out:
  2222. lpfc_els_free_iocb(phba, cmdiocb);
  2223. /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
  2224. if ((vport->fc_flag & FC_PT2PT) &&
  2225. !(vport->fc_flag & FC_PT2PT_PLOGI)) {
  2226. phba->pport->fc_myDID = 0;
  2227. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2228. if (mbox) {
  2229. lpfc_config_link(phba, mbox);
  2230. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2231. mbox->vport = vport;
  2232. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
  2233. MBX_NOT_FINISHED) {
  2234. mempool_free(mbox, phba->mbox_mem_pool);
  2235. skip_recovery = 1;
  2236. }
  2237. }
  2238. }
  2239. /*
  2240. * If the node is a target, the handling attempts to recover the port.
  2241. * For any other port type, the rpi is unregistered as an implicit
  2242. * LOGO.
  2243. */
  2244. if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
  2245. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2246. spin_lock_irqsave(shost->host_lock, flags);
  2247. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2248. spin_unlock_irqrestore(shost->host_lock, flags);
  2249. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2250. "3187 LOGO completes to NPort x%x: Start "
  2251. "Recovery Data: x%x x%x x%x x%x\n",
  2252. ndlp->nlp_DID, irsp->ulpStatus,
  2253. irsp->un.ulpWord[4], irsp->ulpTimeout,
  2254. vport->num_disc_nodes);
  2255. lpfc_disc_start(vport);
  2256. }
  2257. return;
  2258. }
  2259. /**
  2260. * lpfc_issue_els_logo - Issue a logo to an node on a vport
  2261. * @vport: pointer to a virtual N_Port data structure.
  2262. * @ndlp: pointer to a node-list data structure.
  2263. * @retry: number of retries to the command IOCB.
  2264. *
  2265. * This routine constructs and issues an ELS Logout (LOGO) iocb command
  2266. * to a remote node, referred by an @ndlp on a @vport. It constructs the
  2267. * payload of the IOCB, properly sets up the @ndlp state, and invokes the
  2268. * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
  2269. *
  2270. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2271. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2272. * will be stored into the context1 field of the IOCB for the completion
  2273. * callback function to the LOGO ELS command.
  2274. *
  2275. * Return code
  2276. * 0 - successfully issued logo
  2277. * 1 - failed to issue logo
  2278. **/
  2279. int
  2280. lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2281. uint8_t retry)
  2282. {
  2283. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2284. struct lpfc_hba *phba = vport->phba;
  2285. IOCB_t *icmd;
  2286. struct lpfc_iocbq *elsiocb;
  2287. uint8_t *pcmd;
  2288. uint16_t cmdsize;
  2289. int rc;
  2290. spin_lock_irq(shost->host_lock);
  2291. if (ndlp->nlp_flag & NLP_LOGO_SND) {
  2292. spin_unlock_irq(shost->host_lock);
  2293. return 0;
  2294. }
  2295. spin_unlock_irq(shost->host_lock);
  2296. cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
  2297. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2298. ndlp->nlp_DID, ELS_CMD_LOGO);
  2299. if (!elsiocb)
  2300. return 1;
  2301. icmd = &elsiocb->iocb;
  2302. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2303. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  2304. pcmd += sizeof(uint32_t);
  2305. /* Fill in LOGO payload */
  2306. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  2307. pcmd += sizeof(uint32_t);
  2308. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  2309. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2310. "Issue LOGO: did:x%x",
  2311. ndlp->nlp_DID, 0, 0);
  2312. /*
  2313. * If we are issuing a LOGO, we may try to recover the remote NPort
  2314. * by issuing a PLOGI later. Even though we issue ELS cmds by the
  2315. * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
  2316. * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
  2317. * for that ELS cmd. To avoid this situation, lets get rid of the
  2318. * RPI right now, before any ELS cmds are sent.
  2319. */
  2320. spin_lock_irq(shost->host_lock);
  2321. ndlp->nlp_flag |= NLP_ISSUE_LOGO;
  2322. spin_unlock_irq(shost->host_lock);
  2323. if (lpfc_unreg_rpi(vport, ndlp)) {
  2324. lpfc_els_free_iocb(phba, elsiocb);
  2325. return 0;
  2326. }
  2327. phba->fc_stat.elsXmitLOGO++;
  2328. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
  2329. spin_lock_irq(shost->host_lock);
  2330. ndlp->nlp_flag |= NLP_LOGO_SND;
  2331. ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
  2332. spin_unlock_irq(shost->host_lock);
  2333. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  2334. if (rc == IOCB_ERROR) {
  2335. spin_lock_irq(shost->host_lock);
  2336. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  2337. spin_unlock_irq(shost->host_lock);
  2338. lpfc_els_free_iocb(phba, elsiocb);
  2339. return 1;
  2340. }
  2341. return 0;
  2342. }
  2343. /**
  2344. * lpfc_cmpl_els_cmd - Completion callback function for generic els command
  2345. * @phba: pointer to lpfc hba data structure.
  2346. * @cmdiocb: pointer to lpfc command iocb data structure.
  2347. * @rspiocb: pointer to lpfc response iocb data structure.
  2348. *
  2349. * This routine is a generic completion callback function for ELS commands.
  2350. * Specifically, it is the callback function which does not need to perform
  2351. * any command specific operations. It is currently used by the ELS command
  2352. * issuing routines for the ELS State Change Request (SCR),
  2353. * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
  2354. * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
  2355. * certain debug loggings, this callback function simply invokes the
  2356. * lpfc_els_chk_latt() routine to check whether link went down during the
  2357. * discovery process.
  2358. **/
  2359. static void
  2360. lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2361. struct lpfc_iocbq *rspiocb)
  2362. {
  2363. struct lpfc_vport *vport = cmdiocb->vport;
  2364. IOCB_t *irsp;
  2365. irsp = &rspiocb->iocb;
  2366. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2367. "ELS cmd cmpl: status:x%x/x%x did:x%x",
  2368. irsp->ulpStatus, irsp->un.ulpWord[4],
  2369. irsp->un.elsreq64.remoteID);
  2370. /* ELS cmd tag <ulpIoTag> completes */
  2371. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2372. "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
  2373. irsp->ulpIoTag, irsp->ulpStatus,
  2374. irsp->un.ulpWord[4], irsp->ulpTimeout);
  2375. /* Check to see if link went down during discovery */
  2376. lpfc_els_chk_latt(vport);
  2377. lpfc_els_free_iocb(phba, cmdiocb);
  2378. return;
  2379. }
  2380. /**
  2381. * lpfc_issue_els_scr - Issue a scr to an node on a vport
  2382. * @vport: pointer to a host virtual N_Port data structure.
  2383. * @nportid: N_Port identifier to the remote node.
  2384. * @retry: number of retries to the command IOCB.
  2385. *
  2386. * This routine issues a State Change Request (SCR) to a fabric node
  2387. * on a @vport. The remote node @nportid is passed into the function. It
  2388. * first search the @vport node list to find the matching ndlp. If no such
  2389. * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
  2390. * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
  2391. * routine is invoked to send the SCR IOCB.
  2392. *
  2393. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2394. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2395. * will be stored into the context1 field of the IOCB for the completion
  2396. * callback function to the SCR ELS command.
  2397. *
  2398. * Return code
  2399. * 0 - Successfully issued scr command
  2400. * 1 - Failed to issue scr command
  2401. **/
  2402. int
  2403. lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  2404. {
  2405. struct lpfc_hba *phba = vport->phba;
  2406. IOCB_t *icmd;
  2407. struct lpfc_iocbq *elsiocb;
  2408. struct lpfc_sli *psli;
  2409. uint8_t *pcmd;
  2410. uint16_t cmdsize;
  2411. struct lpfc_nodelist *ndlp;
  2412. psli = &phba->sli;
  2413. cmdsize = (sizeof(uint32_t) + sizeof(SCR));
  2414. ndlp = lpfc_findnode_did(vport, nportid);
  2415. if (!ndlp) {
  2416. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  2417. if (!ndlp)
  2418. return 1;
  2419. lpfc_nlp_init(vport, ndlp, nportid);
  2420. lpfc_enqueue_node(vport, ndlp);
  2421. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  2422. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  2423. if (!ndlp)
  2424. return 1;
  2425. }
  2426. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2427. ndlp->nlp_DID, ELS_CMD_SCR);
  2428. if (!elsiocb) {
  2429. /* This will trigger the release of the node just
  2430. * allocated
  2431. */
  2432. lpfc_nlp_put(ndlp);
  2433. return 1;
  2434. }
  2435. icmd = &elsiocb->iocb;
  2436. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2437. *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
  2438. pcmd += sizeof(uint32_t);
  2439. /* For SCR, remainder of payload is SCR parameter page */
  2440. memset(pcmd, 0, sizeof(SCR));
  2441. ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
  2442. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2443. "Issue SCR: did:x%x",
  2444. ndlp->nlp_DID, 0, 0);
  2445. phba->fc_stat.elsXmitSCR++;
  2446. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  2447. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  2448. IOCB_ERROR) {
  2449. /* The additional lpfc_nlp_put will cause the following
  2450. * lpfc_els_free_iocb routine to trigger the rlease of
  2451. * the node.
  2452. */
  2453. lpfc_nlp_put(ndlp);
  2454. lpfc_els_free_iocb(phba, elsiocb);
  2455. return 1;
  2456. }
  2457. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  2458. * trigger the release of node.
  2459. */
  2460. lpfc_nlp_put(ndlp);
  2461. return 0;
  2462. }
  2463. /**
  2464. * lpfc_issue_els_farpr - Issue a farp to an node on a vport
  2465. * @vport: pointer to a host virtual N_Port data structure.
  2466. * @nportid: N_Port identifier to the remote node.
  2467. * @retry: number of retries to the command IOCB.
  2468. *
  2469. * This routine issues a Fibre Channel Address Resolution Response
  2470. * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
  2471. * is passed into the function. It first search the @vport node list to find
  2472. * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
  2473. * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
  2474. * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
  2475. *
  2476. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2477. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2478. * will be stored into the context1 field of the IOCB for the completion
  2479. * callback function to the PARPR ELS command.
  2480. *
  2481. * Return code
  2482. * 0 - Successfully issued farpr command
  2483. * 1 - Failed to issue farpr command
  2484. **/
  2485. static int
  2486. lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  2487. {
  2488. struct lpfc_hba *phba = vport->phba;
  2489. IOCB_t *icmd;
  2490. struct lpfc_iocbq *elsiocb;
  2491. struct lpfc_sli *psli;
  2492. FARP *fp;
  2493. uint8_t *pcmd;
  2494. uint32_t *lp;
  2495. uint16_t cmdsize;
  2496. struct lpfc_nodelist *ondlp;
  2497. struct lpfc_nodelist *ndlp;
  2498. psli = &phba->sli;
  2499. cmdsize = (sizeof(uint32_t) + sizeof(FARP));
  2500. ndlp = lpfc_findnode_did(vport, nportid);
  2501. if (!ndlp) {
  2502. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  2503. if (!ndlp)
  2504. return 1;
  2505. lpfc_nlp_init(vport, ndlp, nportid);
  2506. lpfc_enqueue_node(vport, ndlp);
  2507. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  2508. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  2509. if (!ndlp)
  2510. return 1;
  2511. }
  2512. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2513. ndlp->nlp_DID, ELS_CMD_RNID);
  2514. if (!elsiocb) {
  2515. /* This will trigger the release of the node just
  2516. * allocated
  2517. */
  2518. lpfc_nlp_put(ndlp);
  2519. return 1;
  2520. }
  2521. icmd = &elsiocb->iocb;
  2522. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2523. *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
  2524. pcmd += sizeof(uint32_t);
  2525. /* Fill in FARPR payload */
  2526. fp = (FARP *) (pcmd);
  2527. memset(fp, 0, sizeof(FARP));
  2528. lp = (uint32_t *) pcmd;
  2529. *lp++ = be32_to_cpu(nportid);
  2530. *lp++ = be32_to_cpu(vport->fc_myDID);
  2531. fp->Rflags = 0;
  2532. fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
  2533. memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
  2534. memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2535. ondlp = lpfc_findnode_did(vport, nportid);
  2536. if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
  2537. memcpy(&fp->OportName, &ondlp->nlp_portname,
  2538. sizeof(struct lpfc_name));
  2539. memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
  2540. sizeof(struct lpfc_name));
  2541. }
  2542. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2543. "Issue FARPR: did:x%x",
  2544. ndlp->nlp_DID, 0, 0);
  2545. phba->fc_stat.elsXmitFARPR++;
  2546. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  2547. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  2548. IOCB_ERROR) {
  2549. /* The additional lpfc_nlp_put will cause the following
  2550. * lpfc_els_free_iocb routine to trigger the release of
  2551. * the node.
  2552. */
  2553. lpfc_nlp_put(ndlp);
  2554. lpfc_els_free_iocb(phba, elsiocb);
  2555. return 1;
  2556. }
  2557. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  2558. * trigger the release of the node.
  2559. */
  2560. lpfc_nlp_put(ndlp);
  2561. return 0;
  2562. }
  2563. /**
  2564. * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
  2565. * @vport: pointer to a host virtual N_Port data structure.
  2566. * @nlp: pointer to a node-list data structure.
  2567. *
  2568. * This routine cancels the timer with a delayed IOCB-command retry for
  2569. * a @vport's @ndlp. It stops the timer for the delayed function retrial and
  2570. * removes the ELS retry event if it presents. In addition, if the
  2571. * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
  2572. * commands are sent for the @vport's nodes that require issuing discovery
  2573. * ADISC.
  2574. **/
  2575. void
  2576. lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
  2577. {
  2578. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2579. struct lpfc_work_evt *evtp;
  2580. if (!(nlp->nlp_flag & NLP_DELAY_TMO))
  2581. return;
  2582. spin_lock_irq(shost->host_lock);
  2583. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  2584. spin_unlock_irq(shost->host_lock);
  2585. del_timer_sync(&nlp->nlp_delayfunc);
  2586. nlp->nlp_last_elscmd = 0;
  2587. if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
  2588. list_del_init(&nlp->els_retry_evt.evt_listp);
  2589. /* Decrement nlp reference count held for the delayed retry */
  2590. evtp = &nlp->els_retry_evt;
  2591. lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
  2592. }
  2593. if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
  2594. spin_lock_irq(shost->host_lock);
  2595. nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  2596. spin_unlock_irq(shost->host_lock);
  2597. if (vport->num_disc_nodes) {
  2598. if (vport->port_state < LPFC_VPORT_READY) {
  2599. /* Check if there are more ADISCs to be sent */
  2600. lpfc_more_adisc(vport);
  2601. } else {
  2602. /* Check if there are more PLOGIs to be sent */
  2603. lpfc_more_plogi(vport);
  2604. if (vport->num_disc_nodes == 0) {
  2605. spin_lock_irq(shost->host_lock);
  2606. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  2607. spin_unlock_irq(shost->host_lock);
  2608. lpfc_can_disctmo(vport);
  2609. lpfc_end_rscn(vport);
  2610. }
  2611. }
  2612. }
  2613. }
  2614. return;
  2615. }
  2616. /**
  2617. * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
  2618. * @ptr: holder for the pointer to the timer function associated data (ndlp).
  2619. *
  2620. * This routine is invoked by the ndlp delayed-function timer to check
  2621. * whether there is any pending ELS retry event(s) with the node. If not, it
  2622. * simply returns. Otherwise, if there is at least one ELS delayed event, it
  2623. * adds the delayed events to the HBA work list and invokes the
  2624. * lpfc_worker_wake_up() routine to wake up worker thread to process the
  2625. * event. Note that lpfc_nlp_get() is called before posting the event to
  2626. * the work list to hold reference count of ndlp so that it guarantees the
  2627. * reference to ndlp will still be available when the worker thread gets
  2628. * to the event associated with the ndlp.
  2629. **/
  2630. void
  2631. lpfc_els_retry_delay(unsigned long ptr)
  2632. {
  2633. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
  2634. struct lpfc_vport *vport = ndlp->vport;
  2635. struct lpfc_hba *phba = vport->phba;
  2636. unsigned long flags;
  2637. struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
  2638. spin_lock_irqsave(&phba->hbalock, flags);
  2639. if (!list_empty(&evtp->evt_listp)) {
  2640. spin_unlock_irqrestore(&phba->hbalock, flags);
  2641. return;
  2642. }
  2643. /* We need to hold the node by incrementing the reference
  2644. * count until the queued work is done
  2645. */
  2646. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  2647. if (evtp->evt_arg1) {
  2648. evtp->evt = LPFC_EVT_ELS_RETRY;
  2649. list_add_tail(&evtp->evt_listp, &phba->work_list);
  2650. lpfc_worker_wake_up(phba);
  2651. }
  2652. spin_unlock_irqrestore(&phba->hbalock, flags);
  2653. return;
  2654. }
  2655. /**
  2656. * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
  2657. * @ndlp: pointer to a node-list data structure.
  2658. *
  2659. * This routine is the worker-thread handler for processing the @ndlp delayed
  2660. * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
  2661. * the last ELS command from the associated ndlp and invokes the proper ELS
  2662. * function according to the delayed ELS command to retry the command.
  2663. **/
  2664. void
  2665. lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
  2666. {
  2667. struct lpfc_vport *vport = ndlp->vport;
  2668. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2669. uint32_t cmd, did, retry;
  2670. spin_lock_irq(shost->host_lock);
  2671. did = ndlp->nlp_DID;
  2672. cmd = ndlp->nlp_last_elscmd;
  2673. ndlp->nlp_last_elscmd = 0;
  2674. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  2675. spin_unlock_irq(shost->host_lock);
  2676. return;
  2677. }
  2678. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  2679. spin_unlock_irq(shost->host_lock);
  2680. /*
  2681. * If a discovery event readded nlp_delayfunc after timer
  2682. * firing and before processing the timer, cancel the
  2683. * nlp_delayfunc.
  2684. */
  2685. del_timer_sync(&ndlp->nlp_delayfunc);
  2686. retry = ndlp->nlp_retry;
  2687. ndlp->nlp_retry = 0;
  2688. switch (cmd) {
  2689. case ELS_CMD_FLOGI:
  2690. lpfc_issue_els_flogi(vport, ndlp, retry);
  2691. break;
  2692. case ELS_CMD_PLOGI:
  2693. if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
  2694. ndlp->nlp_prev_state = ndlp->nlp_state;
  2695. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2696. }
  2697. break;
  2698. case ELS_CMD_ADISC:
  2699. if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
  2700. ndlp->nlp_prev_state = ndlp->nlp_state;
  2701. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  2702. }
  2703. break;
  2704. case ELS_CMD_PRLI:
  2705. if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
  2706. ndlp->nlp_prev_state = ndlp->nlp_state;
  2707. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  2708. }
  2709. break;
  2710. case ELS_CMD_LOGO:
  2711. if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
  2712. ndlp->nlp_prev_state = ndlp->nlp_state;
  2713. lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
  2714. }
  2715. break;
  2716. case ELS_CMD_FDISC:
  2717. if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
  2718. lpfc_issue_els_fdisc(vport, ndlp, retry);
  2719. break;
  2720. }
  2721. return;
  2722. }
  2723. /**
  2724. * lpfc_els_retry - Make retry decision on an els command iocb
  2725. * @phba: pointer to lpfc hba data structure.
  2726. * @cmdiocb: pointer to lpfc command iocb data structure.
  2727. * @rspiocb: pointer to lpfc response iocb data structure.
  2728. *
  2729. * This routine makes a retry decision on an ELS command IOCB, which has
  2730. * failed. The following ELS IOCBs use this function for retrying the command
  2731. * when previously issued command responsed with error status: FLOGI, PLOGI,
  2732. * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
  2733. * returned error status, it makes the decision whether a retry shall be
  2734. * issued for the command, and whether a retry shall be made immediately or
  2735. * delayed. In the former case, the corresponding ELS command issuing-function
  2736. * is called to retry the command. In the later case, the ELS command shall
  2737. * be posted to the ndlp delayed event and delayed function timer set to the
  2738. * ndlp for the delayed command issusing.
  2739. *
  2740. * Return code
  2741. * 0 - No retry of els command is made
  2742. * 1 - Immediate or delayed retry of els command is made
  2743. **/
  2744. static int
  2745. lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2746. struct lpfc_iocbq *rspiocb)
  2747. {
  2748. struct lpfc_vport *vport = cmdiocb->vport;
  2749. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2750. IOCB_t *irsp = &rspiocb->iocb;
  2751. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2752. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2753. uint32_t *elscmd;
  2754. struct ls_rjt stat;
  2755. int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
  2756. int logerr = 0;
  2757. uint32_t cmd = 0;
  2758. uint32_t did;
  2759. /* Note: context2 may be 0 for internal driver abort
  2760. * of delays ELS command.
  2761. */
  2762. if (pcmd && pcmd->virt) {
  2763. elscmd = (uint32_t *) (pcmd->virt);
  2764. cmd = *elscmd++;
  2765. }
  2766. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  2767. did = ndlp->nlp_DID;
  2768. else {
  2769. /* We should only hit this case for retrying PLOGI */
  2770. did = irsp->un.elsreq64.remoteID;
  2771. ndlp = lpfc_findnode_did(vport, did);
  2772. if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  2773. && (cmd != ELS_CMD_PLOGI))
  2774. return 1;
  2775. }
  2776. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2777. "Retry ELS: wd7:x%x wd4:x%x did:x%x",
  2778. *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
  2779. switch (irsp->ulpStatus) {
  2780. case IOSTAT_FCP_RSP_ERROR:
  2781. break;
  2782. case IOSTAT_REMOTE_STOP:
  2783. if (phba->sli_rev == LPFC_SLI_REV4) {
  2784. /* This IO was aborted by the target, we don't
  2785. * know the rxid and because we did not send the
  2786. * ABTS we cannot generate and RRQ.
  2787. */
  2788. lpfc_set_rrq_active(phba, ndlp,
  2789. cmdiocb->sli4_lxritag, 0, 0);
  2790. }
  2791. break;
  2792. case IOSTAT_LOCAL_REJECT:
  2793. switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
  2794. case IOERR_LOOP_OPEN_FAILURE:
  2795. if (cmd == ELS_CMD_FLOGI) {
  2796. if (PCI_DEVICE_ID_HORNET ==
  2797. phba->pcidev->device) {
  2798. phba->fc_topology = LPFC_TOPOLOGY_LOOP;
  2799. phba->pport->fc_myDID = 0;
  2800. phba->alpa_map[0] = 0;
  2801. phba->alpa_map[1] = 0;
  2802. }
  2803. }
  2804. if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
  2805. delay = 1000;
  2806. retry = 1;
  2807. break;
  2808. case IOERR_ILLEGAL_COMMAND:
  2809. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2810. "0124 Retry illegal cmd x%x "
  2811. "retry:x%x delay:x%x\n",
  2812. cmd, cmdiocb->retry, delay);
  2813. retry = 1;
  2814. /* All command's retry policy */
  2815. maxretry = 8;
  2816. if (cmdiocb->retry > 2)
  2817. delay = 1000;
  2818. break;
  2819. case IOERR_NO_RESOURCES:
  2820. logerr = 1; /* HBA out of resources */
  2821. retry = 1;
  2822. if (cmdiocb->retry > 100)
  2823. delay = 100;
  2824. maxretry = 250;
  2825. break;
  2826. case IOERR_ILLEGAL_FRAME:
  2827. delay = 100;
  2828. retry = 1;
  2829. break;
  2830. case IOERR_SEQUENCE_TIMEOUT:
  2831. case IOERR_INVALID_RPI:
  2832. retry = 1;
  2833. break;
  2834. }
  2835. break;
  2836. case IOSTAT_NPORT_RJT:
  2837. case IOSTAT_FABRIC_RJT:
  2838. if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  2839. retry = 1;
  2840. break;
  2841. }
  2842. break;
  2843. case IOSTAT_NPORT_BSY:
  2844. case IOSTAT_FABRIC_BSY:
  2845. logerr = 1; /* Fabric / Remote NPort out of resources */
  2846. retry = 1;
  2847. break;
  2848. case IOSTAT_LS_RJT:
  2849. stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
  2850. /* Added for Vendor specifc support
  2851. * Just keep retrying for these Rsn / Exp codes
  2852. */
  2853. switch (stat.un.b.lsRjtRsnCode) {
  2854. case LSRJT_UNABLE_TPC:
  2855. if (stat.un.b.lsRjtRsnCodeExp ==
  2856. LSEXP_CMD_IN_PROGRESS) {
  2857. if (cmd == ELS_CMD_PLOGI) {
  2858. delay = 1000;
  2859. maxretry = 48;
  2860. }
  2861. retry = 1;
  2862. break;
  2863. }
  2864. if (stat.un.b.lsRjtRsnCodeExp ==
  2865. LSEXP_CANT_GIVE_DATA) {
  2866. if (cmd == ELS_CMD_PLOGI) {
  2867. delay = 1000;
  2868. maxretry = 48;
  2869. }
  2870. retry = 1;
  2871. break;
  2872. }
  2873. if (cmd == ELS_CMD_PLOGI) {
  2874. delay = 1000;
  2875. maxretry = lpfc_max_els_tries + 1;
  2876. retry = 1;
  2877. break;
  2878. }
  2879. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2880. (cmd == ELS_CMD_FDISC) &&
  2881. (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
  2882. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2883. "0125 FDISC Failed (x%x). "
  2884. "Fabric out of resources\n",
  2885. stat.un.lsRjtError);
  2886. lpfc_vport_set_state(vport,
  2887. FC_VPORT_NO_FABRIC_RSCS);
  2888. }
  2889. break;
  2890. case LSRJT_LOGICAL_BSY:
  2891. if ((cmd == ELS_CMD_PLOGI) ||
  2892. (cmd == ELS_CMD_PRLI)) {
  2893. delay = 1000;
  2894. maxretry = 48;
  2895. } else if (cmd == ELS_CMD_FDISC) {
  2896. /* FDISC retry policy */
  2897. maxretry = 48;
  2898. if (cmdiocb->retry >= 32)
  2899. delay = 1000;
  2900. }
  2901. retry = 1;
  2902. break;
  2903. case LSRJT_LOGICAL_ERR:
  2904. /* There are some cases where switches return this
  2905. * error when they are not ready and should be returning
  2906. * Logical Busy. We should delay every time.
  2907. */
  2908. if (cmd == ELS_CMD_FDISC &&
  2909. stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
  2910. maxretry = 3;
  2911. delay = 1000;
  2912. retry = 1;
  2913. break;
  2914. }
  2915. case LSRJT_PROTOCOL_ERR:
  2916. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2917. (cmd == ELS_CMD_FDISC) &&
  2918. ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
  2919. (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
  2920. ) {
  2921. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2922. "0122 FDISC Failed (x%x). "
  2923. "Fabric Detected Bad WWN\n",
  2924. stat.un.lsRjtError);
  2925. lpfc_vport_set_state(vport,
  2926. FC_VPORT_FABRIC_REJ_WWN);
  2927. }
  2928. break;
  2929. }
  2930. break;
  2931. case IOSTAT_INTERMED_RSP:
  2932. case IOSTAT_BA_RJT:
  2933. break;
  2934. default:
  2935. break;
  2936. }
  2937. if (did == FDMI_DID)
  2938. retry = 1;
  2939. if ((cmd == ELS_CMD_FLOGI) &&
  2940. (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
  2941. !lpfc_error_lost_link(irsp)) {
  2942. /* FLOGI retry policy */
  2943. retry = 1;
  2944. /* retry FLOGI forever */
  2945. maxretry = 0;
  2946. if (cmdiocb->retry >= 100)
  2947. delay = 5000;
  2948. else if (cmdiocb->retry >= 32)
  2949. delay = 1000;
  2950. } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
  2951. /* retry FDISCs every second up to devloss */
  2952. retry = 1;
  2953. maxretry = vport->cfg_devloss_tmo;
  2954. delay = 1000;
  2955. }
  2956. cmdiocb->retry++;
  2957. if (maxretry && (cmdiocb->retry >= maxretry)) {
  2958. phba->fc_stat.elsRetryExceeded++;
  2959. retry = 0;
  2960. }
  2961. if ((vport->load_flag & FC_UNLOADING) != 0)
  2962. retry = 0;
  2963. if (retry) {
  2964. if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
  2965. /* Stop retrying PLOGI and FDISC if in FCF discovery */
  2966. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  2967. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2968. "2849 Stop retry ELS command "
  2969. "x%x to remote NPORT x%x, "
  2970. "Data: x%x x%x\n", cmd, did,
  2971. cmdiocb->retry, delay);
  2972. return 0;
  2973. }
  2974. }
  2975. /* Retry ELS command <elsCmd> to remote NPORT <did> */
  2976. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2977. "0107 Retry ELS command x%x to remote "
  2978. "NPORT x%x Data: x%x x%x\n",
  2979. cmd, did, cmdiocb->retry, delay);
  2980. if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
  2981. ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  2982. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
  2983. IOERR_NO_RESOURCES))) {
  2984. /* Don't reset timer for no resources */
  2985. /* If discovery / RSCN timer is running, reset it */
  2986. if (timer_pending(&vport->fc_disctmo) ||
  2987. (vport->fc_flag & FC_RSCN_MODE))
  2988. lpfc_set_disctmo(vport);
  2989. }
  2990. phba->fc_stat.elsXmitRetry++;
  2991. if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
  2992. phba->fc_stat.elsDelayRetry++;
  2993. ndlp->nlp_retry = cmdiocb->retry;
  2994. /* delay is specified in milliseconds */
  2995. mod_timer(&ndlp->nlp_delayfunc,
  2996. jiffies + msecs_to_jiffies(delay));
  2997. spin_lock_irq(shost->host_lock);
  2998. ndlp->nlp_flag |= NLP_DELAY_TMO;
  2999. spin_unlock_irq(shost->host_lock);
  3000. ndlp->nlp_prev_state = ndlp->nlp_state;
  3001. if (cmd == ELS_CMD_PRLI)
  3002. lpfc_nlp_set_state(vport, ndlp,
  3003. NLP_STE_REG_LOGIN_ISSUE);
  3004. else
  3005. lpfc_nlp_set_state(vport, ndlp,
  3006. NLP_STE_NPR_NODE);
  3007. ndlp->nlp_last_elscmd = cmd;
  3008. return 1;
  3009. }
  3010. switch (cmd) {
  3011. case ELS_CMD_FLOGI:
  3012. lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
  3013. return 1;
  3014. case ELS_CMD_FDISC:
  3015. lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
  3016. return 1;
  3017. case ELS_CMD_PLOGI:
  3018. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  3019. ndlp->nlp_prev_state = ndlp->nlp_state;
  3020. lpfc_nlp_set_state(vport, ndlp,
  3021. NLP_STE_PLOGI_ISSUE);
  3022. }
  3023. lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
  3024. return 1;
  3025. case ELS_CMD_ADISC:
  3026. ndlp->nlp_prev_state = ndlp->nlp_state;
  3027. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  3028. lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
  3029. return 1;
  3030. case ELS_CMD_PRLI:
  3031. ndlp->nlp_prev_state = ndlp->nlp_state;
  3032. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  3033. lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
  3034. return 1;
  3035. case ELS_CMD_LOGO:
  3036. ndlp->nlp_prev_state = ndlp->nlp_state;
  3037. lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
  3038. lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
  3039. return 1;
  3040. }
  3041. }
  3042. /* No retry ELS command <elsCmd> to remote NPORT <did> */
  3043. if (logerr) {
  3044. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3045. "0137 No retry ELS command x%x to remote "
  3046. "NPORT x%x: Out of Resources: Error:x%x/%x\n",
  3047. cmd, did, irsp->ulpStatus,
  3048. irsp->un.ulpWord[4]);
  3049. }
  3050. else {
  3051. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3052. "0108 No retry ELS command x%x to remote "
  3053. "NPORT x%x Retried:%d Error:x%x/%x\n",
  3054. cmd, did, cmdiocb->retry, irsp->ulpStatus,
  3055. irsp->un.ulpWord[4]);
  3056. }
  3057. return 0;
  3058. }
  3059. /**
  3060. * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
  3061. * @phba: pointer to lpfc hba data structure.
  3062. * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
  3063. *
  3064. * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
  3065. * associated with a command IOCB back to the lpfc DMA buffer pool. It first
  3066. * checks to see whether there is a lpfc DMA buffer associated with the
  3067. * response of the command IOCB. If so, it will be released before releasing
  3068. * the lpfc DMA buffer associated with the IOCB itself.
  3069. *
  3070. * Return code
  3071. * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
  3072. **/
  3073. static int
  3074. lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
  3075. {
  3076. struct lpfc_dmabuf *buf_ptr;
  3077. /* Free the response before processing the command. */
  3078. if (!list_empty(&buf_ptr1->list)) {
  3079. list_remove_head(&buf_ptr1->list, buf_ptr,
  3080. struct lpfc_dmabuf,
  3081. list);
  3082. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  3083. kfree(buf_ptr);
  3084. }
  3085. lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
  3086. kfree(buf_ptr1);
  3087. return 0;
  3088. }
  3089. /**
  3090. * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
  3091. * @phba: pointer to lpfc hba data structure.
  3092. * @buf_ptr: pointer to the lpfc dma buffer data structure.
  3093. *
  3094. * This routine releases the lpfc Direct Memory Access (DMA) buffer
  3095. * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
  3096. * pool.
  3097. *
  3098. * Return code
  3099. * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
  3100. **/
  3101. static int
  3102. lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
  3103. {
  3104. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  3105. kfree(buf_ptr);
  3106. return 0;
  3107. }
  3108. /**
  3109. * lpfc_els_free_iocb - Free a command iocb and its associated resources
  3110. * @phba: pointer to lpfc hba data structure.
  3111. * @elsiocb: pointer to lpfc els command iocb data structure.
  3112. *
  3113. * This routine frees a command IOCB and its associated resources. The
  3114. * command IOCB data structure contains the reference to various associated
  3115. * resources, these fields must be set to NULL if the associated reference
  3116. * not present:
  3117. * context1 - reference to ndlp
  3118. * context2 - reference to cmd
  3119. * context2->next - reference to rsp
  3120. * context3 - reference to bpl
  3121. *
  3122. * It first properly decrements the reference count held on ndlp for the
  3123. * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
  3124. * set, it invokes the lpfc_els_free_data() routine to release the Direct
  3125. * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
  3126. * adds the DMA buffer the @phba data structure for the delayed release.
  3127. * If reference to the Buffer Pointer List (BPL) is present, the
  3128. * lpfc_els_free_bpl() routine is invoked to release the DMA memory
  3129. * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
  3130. * invoked to release the IOCB data structure back to @phba IOCBQ list.
  3131. *
  3132. * Return code
  3133. * 0 - Success (currently, always return 0)
  3134. **/
  3135. int
  3136. lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
  3137. {
  3138. struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
  3139. struct lpfc_nodelist *ndlp;
  3140. ndlp = (struct lpfc_nodelist *)elsiocb->context1;
  3141. if (ndlp) {
  3142. if (ndlp->nlp_flag & NLP_DEFER_RM) {
  3143. lpfc_nlp_put(ndlp);
  3144. /* If the ndlp is not being used by another discovery
  3145. * thread, free it.
  3146. */
  3147. if (!lpfc_nlp_not_used(ndlp)) {
  3148. /* If ndlp is being used by another discovery
  3149. * thread, just clear NLP_DEFER_RM
  3150. */
  3151. ndlp->nlp_flag &= ~NLP_DEFER_RM;
  3152. }
  3153. }
  3154. else
  3155. lpfc_nlp_put(ndlp);
  3156. elsiocb->context1 = NULL;
  3157. }
  3158. /* context2 = cmd, context2->next = rsp, context3 = bpl */
  3159. if (elsiocb->context2) {
  3160. if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
  3161. /* Firmware could still be in progress of DMAing
  3162. * payload, so don't free data buffer till after
  3163. * a hbeat.
  3164. */
  3165. elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
  3166. buf_ptr = elsiocb->context2;
  3167. elsiocb->context2 = NULL;
  3168. if (buf_ptr) {
  3169. buf_ptr1 = NULL;
  3170. spin_lock_irq(&phba->hbalock);
  3171. if (!list_empty(&buf_ptr->list)) {
  3172. list_remove_head(&buf_ptr->list,
  3173. buf_ptr1, struct lpfc_dmabuf,
  3174. list);
  3175. INIT_LIST_HEAD(&buf_ptr1->list);
  3176. list_add_tail(&buf_ptr1->list,
  3177. &phba->elsbuf);
  3178. phba->elsbuf_cnt++;
  3179. }
  3180. INIT_LIST_HEAD(&buf_ptr->list);
  3181. list_add_tail(&buf_ptr->list, &phba->elsbuf);
  3182. phba->elsbuf_cnt++;
  3183. spin_unlock_irq(&phba->hbalock);
  3184. }
  3185. } else {
  3186. buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
  3187. lpfc_els_free_data(phba, buf_ptr1);
  3188. }
  3189. }
  3190. if (elsiocb->context3) {
  3191. buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
  3192. lpfc_els_free_bpl(phba, buf_ptr);
  3193. }
  3194. lpfc_sli_release_iocbq(phba, elsiocb);
  3195. return 0;
  3196. }
  3197. /**
  3198. * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
  3199. * @phba: pointer to lpfc hba data structure.
  3200. * @cmdiocb: pointer to lpfc command iocb data structure.
  3201. * @rspiocb: pointer to lpfc response iocb data structure.
  3202. *
  3203. * This routine is the completion callback function to the Logout (LOGO)
  3204. * Accept (ACC) Response ELS command. This routine is invoked to indicate
  3205. * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
  3206. * release the ndlp if it has the last reference remaining (reference count
  3207. * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
  3208. * field to NULL to inform the following lpfc_els_free_iocb() routine no
  3209. * ndlp reference count needs to be decremented. Otherwise, the ndlp
  3210. * reference use-count shall be decremented by the lpfc_els_free_iocb()
  3211. * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
  3212. * IOCB data structure.
  3213. **/
  3214. static void
  3215. lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3216. struct lpfc_iocbq *rspiocb)
  3217. {
  3218. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  3219. struct lpfc_vport *vport = cmdiocb->vport;
  3220. IOCB_t *irsp;
  3221. irsp = &rspiocb->iocb;
  3222. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3223. "ACC LOGO cmpl: status:x%x/x%x did:x%x",
  3224. irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
  3225. /* ACC to LOGO completes to NPort <nlp_DID> */
  3226. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3227. "0109 ACC to LOGO completes to NPort x%x "
  3228. "Data: x%x x%x x%x\n",
  3229. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3230. ndlp->nlp_rpi);
  3231. if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
  3232. /* NPort Recovery mode or node is just allocated */
  3233. if (!lpfc_nlp_not_used(ndlp)) {
  3234. /* If the ndlp is being used by another discovery
  3235. * thread, just unregister the RPI.
  3236. */
  3237. lpfc_unreg_rpi(vport, ndlp);
  3238. } else {
  3239. /* Indicate the node has already released, should
  3240. * not reference to it from within lpfc_els_free_iocb.
  3241. */
  3242. cmdiocb->context1 = NULL;
  3243. }
  3244. }
  3245. /*
  3246. * The driver received a LOGO from the rport and has ACK'd it.
  3247. * At this point, the driver is done so release the IOCB
  3248. */
  3249. lpfc_els_free_iocb(phba, cmdiocb);
  3250. /*
  3251. * Remove the ndlp reference if it's a fabric node that has
  3252. * sent us an unsolicted LOGO.
  3253. */
  3254. if (ndlp->nlp_type & NLP_FABRIC)
  3255. lpfc_nlp_put(ndlp);
  3256. return;
  3257. }
  3258. /**
  3259. * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
  3260. * @phba: pointer to lpfc hba data structure.
  3261. * @pmb: pointer to the driver internal queue element for mailbox command.
  3262. *
  3263. * This routine is the completion callback function for unregister default
  3264. * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
  3265. * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
  3266. * decrements the ndlp reference count held for this completion callback
  3267. * function. After that, it invokes the lpfc_nlp_not_used() to check
  3268. * whether there is only one reference left on the ndlp. If so, it will
  3269. * perform one more decrement and trigger the release of the ndlp.
  3270. **/
  3271. void
  3272. lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3273. {
  3274. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  3275. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3276. pmb->context1 = NULL;
  3277. pmb->context2 = NULL;
  3278. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3279. kfree(mp);
  3280. mempool_free(pmb, phba->mbox_mem_pool);
  3281. if (ndlp) {
  3282. if (NLP_CHK_NODE_ACT(ndlp)) {
  3283. lpfc_nlp_put(ndlp);
  3284. /* This is the end of the default RPI cleanup logic for
  3285. * this ndlp. If no other discovery threads are using
  3286. * this ndlp, free all resources associated with it.
  3287. */
  3288. lpfc_nlp_not_used(ndlp);
  3289. } else {
  3290. lpfc_drop_node(ndlp->vport, ndlp);
  3291. }
  3292. }
  3293. return;
  3294. }
  3295. /**
  3296. * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
  3297. * @phba: pointer to lpfc hba data structure.
  3298. * @cmdiocb: pointer to lpfc command iocb data structure.
  3299. * @rspiocb: pointer to lpfc response iocb data structure.
  3300. *
  3301. * This routine is the completion callback function for ELS Response IOCB
  3302. * command. In normal case, this callback function just properly sets the
  3303. * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
  3304. * field in the command IOCB is not NULL, the referred mailbox command will
  3305. * be send out, and then invokes the lpfc_els_free_iocb() routine to release
  3306. * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
  3307. * link down event occurred during the discovery, the lpfc_nlp_not_used()
  3308. * routine shall be invoked trying to release the ndlp if no other threads
  3309. * are currently referring it.
  3310. **/
  3311. static void
  3312. lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3313. struct lpfc_iocbq *rspiocb)
  3314. {
  3315. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  3316. struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
  3317. struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
  3318. IOCB_t *irsp;
  3319. uint8_t *pcmd;
  3320. LPFC_MBOXQ_t *mbox = NULL;
  3321. struct lpfc_dmabuf *mp = NULL;
  3322. uint32_t ls_rjt = 0;
  3323. irsp = &rspiocb->iocb;
  3324. if (cmdiocb->context_un.mbox)
  3325. mbox = cmdiocb->context_un.mbox;
  3326. /* First determine if this is a LS_RJT cmpl. Note, this callback
  3327. * function can have cmdiocb->contest1 (ndlp) field set to NULL.
  3328. */
  3329. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
  3330. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  3331. (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
  3332. /* A LS_RJT associated with Default RPI cleanup has its own
  3333. * separate code path.
  3334. */
  3335. if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  3336. ls_rjt = 1;
  3337. }
  3338. /* Check to see if link went down during discovery */
  3339. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
  3340. if (mbox) {
  3341. mp = (struct lpfc_dmabuf *) mbox->context1;
  3342. if (mp) {
  3343. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3344. kfree(mp);
  3345. }
  3346. mempool_free(mbox, phba->mbox_mem_pool);
  3347. }
  3348. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  3349. (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  3350. if (lpfc_nlp_not_used(ndlp)) {
  3351. ndlp = NULL;
  3352. /* Indicate the node has already released,
  3353. * should not reference to it from within
  3354. * the routine lpfc_els_free_iocb.
  3355. */
  3356. cmdiocb->context1 = NULL;
  3357. }
  3358. goto out;
  3359. }
  3360. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3361. "ELS rsp cmpl: status:x%x/x%x did:x%x",
  3362. irsp->ulpStatus, irsp->un.ulpWord[4],
  3363. cmdiocb->iocb.un.elsreq64.remoteID);
  3364. /* ELS response tag <ulpIoTag> completes */
  3365. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3366. "0110 ELS response tag x%x completes "
  3367. "Data: x%x x%x x%x x%x x%x x%x x%x\n",
  3368. cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
  3369. rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
  3370. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3371. ndlp->nlp_rpi);
  3372. if (mbox) {
  3373. if ((rspiocb->iocb.ulpStatus == 0)
  3374. && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
  3375. lpfc_unreg_rpi(vport, ndlp);
  3376. /* Increment reference count to ndlp to hold the
  3377. * reference to ndlp for the callback function.
  3378. */
  3379. mbox->context2 = lpfc_nlp_get(ndlp);
  3380. mbox->vport = vport;
  3381. if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
  3382. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  3383. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  3384. }
  3385. else {
  3386. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  3387. ndlp->nlp_prev_state = ndlp->nlp_state;
  3388. lpfc_nlp_set_state(vport, ndlp,
  3389. NLP_STE_REG_LOGIN_ISSUE);
  3390. }
  3391. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  3392. != MBX_NOT_FINISHED)
  3393. goto out;
  3394. else
  3395. /* Decrement the ndlp reference count we
  3396. * set for this failed mailbox command.
  3397. */
  3398. lpfc_nlp_put(ndlp);
  3399. /* ELS rsp: Cannot issue reg_login for <NPortid> */
  3400. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3401. "0138 ELS rsp: Cannot issue reg_login for x%x "
  3402. "Data: x%x x%x x%x\n",
  3403. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3404. ndlp->nlp_rpi);
  3405. if (lpfc_nlp_not_used(ndlp)) {
  3406. ndlp = NULL;
  3407. /* Indicate node has already been released,
  3408. * should not reference to it from within
  3409. * the routine lpfc_els_free_iocb.
  3410. */
  3411. cmdiocb->context1 = NULL;
  3412. }
  3413. } else {
  3414. /* Do not drop node for lpfc_els_abort'ed ELS cmds */
  3415. if (!lpfc_error_lost_link(irsp) &&
  3416. ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  3417. if (lpfc_nlp_not_used(ndlp)) {
  3418. ndlp = NULL;
  3419. /* Indicate node has already been
  3420. * released, should not reference
  3421. * to it from within the routine
  3422. * lpfc_els_free_iocb.
  3423. */
  3424. cmdiocb->context1 = NULL;
  3425. }
  3426. }
  3427. }
  3428. mp = (struct lpfc_dmabuf *) mbox->context1;
  3429. if (mp) {
  3430. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3431. kfree(mp);
  3432. }
  3433. mempool_free(mbox, phba->mbox_mem_pool);
  3434. }
  3435. out:
  3436. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  3437. spin_lock_irq(shost->host_lock);
  3438. ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
  3439. spin_unlock_irq(shost->host_lock);
  3440. /* If the node is not being used by another discovery thread,
  3441. * and we are sending a reject, we are done with it.
  3442. * Release driver reference count here and free associated
  3443. * resources.
  3444. */
  3445. if (ls_rjt)
  3446. if (lpfc_nlp_not_used(ndlp))
  3447. /* Indicate node has already been released,
  3448. * should not reference to it from within
  3449. * the routine lpfc_els_free_iocb.
  3450. */
  3451. cmdiocb->context1 = NULL;
  3452. }
  3453. lpfc_els_free_iocb(phba, cmdiocb);
  3454. return;
  3455. }
  3456. /**
  3457. * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
  3458. * @vport: pointer to a host virtual N_Port data structure.
  3459. * @flag: the els command code to be accepted.
  3460. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3461. * @ndlp: pointer to a node-list data structure.
  3462. * @mbox: pointer to the driver internal queue element for mailbox command.
  3463. *
  3464. * This routine prepares and issues an Accept (ACC) response IOCB
  3465. * command. It uses the @flag to properly set up the IOCB field for the
  3466. * specific ACC response command to be issued and invokes the
  3467. * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
  3468. * @mbox pointer is passed in, it will be put into the context_un.mbox
  3469. * field of the IOCB for the completion callback function to issue the
  3470. * mailbox command to the HBA later when callback is invoked.
  3471. *
  3472. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3473. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3474. * will be stored into the context1 field of the IOCB for the completion
  3475. * callback function to the corresponding response ELS IOCB command.
  3476. *
  3477. * Return code
  3478. * 0 - Successfully issued acc response
  3479. * 1 - Failed to issue acc response
  3480. **/
  3481. int
  3482. lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
  3483. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  3484. LPFC_MBOXQ_t *mbox)
  3485. {
  3486. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3487. struct lpfc_hba *phba = vport->phba;
  3488. IOCB_t *icmd;
  3489. IOCB_t *oldcmd;
  3490. struct lpfc_iocbq *elsiocb;
  3491. struct lpfc_sli *psli;
  3492. uint8_t *pcmd;
  3493. uint16_t cmdsize;
  3494. int rc;
  3495. ELS_PKT *els_pkt_ptr;
  3496. psli = &phba->sli;
  3497. oldcmd = &oldiocb->iocb;
  3498. switch (flag) {
  3499. case ELS_CMD_ACC:
  3500. cmdsize = sizeof(uint32_t);
  3501. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  3502. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  3503. if (!elsiocb) {
  3504. spin_lock_irq(shost->host_lock);
  3505. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  3506. spin_unlock_irq(shost->host_lock);
  3507. return 1;
  3508. }
  3509. icmd = &elsiocb->iocb;
  3510. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3511. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3512. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3513. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3514. pcmd += sizeof(uint32_t);
  3515. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3516. "Issue ACC: did:x%x flg:x%x",
  3517. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3518. break;
  3519. case ELS_CMD_PLOGI:
  3520. cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
  3521. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  3522. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  3523. if (!elsiocb)
  3524. return 1;
  3525. icmd = &elsiocb->iocb;
  3526. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3527. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3528. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3529. if (mbox)
  3530. elsiocb->context_un.mbox = mbox;
  3531. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3532. pcmd += sizeof(uint32_t);
  3533. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  3534. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3535. "Issue ACC PLOGI: did:x%x flg:x%x",
  3536. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3537. break;
  3538. case ELS_CMD_PRLO:
  3539. cmdsize = sizeof(uint32_t) + sizeof(PRLO);
  3540. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  3541. ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
  3542. if (!elsiocb)
  3543. return 1;
  3544. icmd = &elsiocb->iocb;
  3545. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3546. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3547. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3548. memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
  3549. sizeof(uint32_t) + sizeof(PRLO));
  3550. *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
  3551. els_pkt_ptr = (ELS_PKT *) pcmd;
  3552. els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
  3553. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3554. "Issue ACC PRLO: did:x%x flg:x%x",
  3555. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3556. break;
  3557. default:
  3558. return 1;
  3559. }
  3560. /* Xmit ELS ACC response tag <ulpIoTag> */
  3561. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3562. "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
  3563. "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
  3564. "fc_flag x%x\n",
  3565. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3566. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3567. ndlp->nlp_rpi, vport->fc_flag);
  3568. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  3569. spin_lock_irq(shost->host_lock);
  3570. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  3571. spin_unlock_irq(shost->host_lock);
  3572. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
  3573. } else {
  3574. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3575. }
  3576. phba->fc_stat.elsXmitACC++;
  3577. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3578. if (rc == IOCB_ERROR) {
  3579. lpfc_els_free_iocb(phba, elsiocb);
  3580. return 1;
  3581. }
  3582. return 0;
  3583. }
  3584. /**
  3585. * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
  3586. * @vport: pointer to a virtual N_Port data structure.
  3587. * @rejectError:
  3588. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3589. * @ndlp: pointer to a node-list data structure.
  3590. * @mbox: pointer to the driver internal queue element for mailbox command.
  3591. *
  3592. * This routine prepares and issue an Reject (RJT) response IOCB
  3593. * command. If a @mbox pointer is passed in, it will be put into the
  3594. * context_un.mbox field of the IOCB for the completion callback function
  3595. * to issue to the HBA later.
  3596. *
  3597. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3598. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3599. * will be stored into the context1 field of the IOCB for the completion
  3600. * callback function to the reject response ELS IOCB command.
  3601. *
  3602. * Return code
  3603. * 0 - Successfully issued reject response
  3604. * 1 - Failed to issue reject response
  3605. **/
  3606. int
  3607. lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
  3608. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  3609. LPFC_MBOXQ_t *mbox)
  3610. {
  3611. struct lpfc_hba *phba = vport->phba;
  3612. IOCB_t *icmd;
  3613. IOCB_t *oldcmd;
  3614. struct lpfc_iocbq *elsiocb;
  3615. struct lpfc_sli *psli;
  3616. uint8_t *pcmd;
  3617. uint16_t cmdsize;
  3618. int rc;
  3619. psli = &phba->sli;
  3620. cmdsize = 2 * sizeof(uint32_t);
  3621. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3622. ndlp->nlp_DID, ELS_CMD_LS_RJT);
  3623. if (!elsiocb)
  3624. return 1;
  3625. icmd = &elsiocb->iocb;
  3626. oldcmd = &oldiocb->iocb;
  3627. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3628. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3629. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3630. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  3631. pcmd += sizeof(uint32_t);
  3632. *((uint32_t *) (pcmd)) = rejectError;
  3633. if (mbox)
  3634. elsiocb->context_un.mbox = mbox;
  3635. /* Xmit ELS RJT <err> response tag <ulpIoTag> */
  3636. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3637. "0129 Xmit ELS RJT x%x response tag x%x "
  3638. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  3639. "rpi x%x\n",
  3640. rejectError, elsiocb->iotag,
  3641. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  3642. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  3643. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3644. "Issue LS_RJT: did:x%x flg:x%x err:x%x",
  3645. ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
  3646. phba->fc_stat.elsXmitLSRJT++;
  3647. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3648. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3649. if (rc == IOCB_ERROR) {
  3650. lpfc_els_free_iocb(phba, elsiocb);
  3651. return 1;
  3652. }
  3653. return 0;
  3654. }
  3655. /**
  3656. * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
  3657. * @vport: pointer to a virtual N_Port data structure.
  3658. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3659. * @ndlp: pointer to a node-list data structure.
  3660. *
  3661. * This routine prepares and issues an Accept (ACC) response to Address
  3662. * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
  3663. * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
  3664. *
  3665. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3666. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3667. * will be stored into the context1 field of the IOCB for the completion
  3668. * callback function to the ADISC Accept response ELS IOCB command.
  3669. *
  3670. * Return code
  3671. * 0 - Successfully issued acc adisc response
  3672. * 1 - Failed to issue adisc acc response
  3673. **/
  3674. int
  3675. lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  3676. struct lpfc_nodelist *ndlp)
  3677. {
  3678. struct lpfc_hba *phba = vport->phba;
  3679. ADISC *ap;
  3680. IOCB_t *icmd, *oldcmd;
  3681. struct lpfc_iocbq *elsiocb;
  3682. uint8_t *pcmd;
  3683. uint16_t cmdsize;
  3684. int rc;
  3685. cmdsize = sizeof(uint32_t) + sizeof(ADISC);
  3686. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3687. ndlp->nlp_DID, ELS_CMD_ACC);
  3688. if (!elsiocb)
  3689. return 1;
  3690. icmd = &elsiocb->iocb;
  3691. oldcmd = &oldiocb->iocb;
  3692. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3693. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3694. /* Xmit ADISC ACC response tag <ulpIoTag> */
  3695. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3696. "0130 Xmit ADISC ACC response iotag x%x xri: "
  3697. "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
  3698. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3699. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3700. ndlp->nlp_rpi);
  3701. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3702. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3703. pcmd += sizeof(uint32_t);
  3704. ap = (ADISC *) (pcmd);
  3705. ap->hardAL_PA = phba->fc_pref_ALPA;
  3706. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  3707. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  3708. ap->DID = be32_to_cpu(vport->fc_myDID);
  3709. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3710. "Issue ACC ADISC: did:x%x flg:x%x",
  3711. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3712. phba->fc_stat.elsXmitACC++;
  3713. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3714. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3715. if (rc == IOCB_ERROR) {
  3716. lpfc_els_free_iocb(phba, elsiocb);
  3717. return 1;
  3718. }
  3719. return 0;
  3720. }
  3721. /**
  3722. * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
  3723. * @vport: pointer to a virtual N_Port data structure.
  3724. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3725. * @ndlp: pointer to a node-list data structure.
  3726. *
  3727. * This routine prepares and issues an Accept (ACC) response to Process
  3728. * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
  3729. * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
  3730. *
  3731. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3732. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3733. * will be stored into the context1 field of the IOCB for the completion
  3734. * callback function to the PRLI Accept response ELS IOCB command.
  3735. *
  3736. * Return code
  3737. * 0 - Successfully issued acc prli response
  3738. * 1 - Failed to issue acc prli response
  3739. **/
  3740. int
  3741. lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  3742. struct lpfc_nodelist *ndlp)
  3743. {
  3744. struct lpfc_hba *phba = vport->phba;
  3745. PRLI *npr;
  3746. lpfc_vpd_t *vpd;
  3747. IOCB_t *icmd;
  3748. IOCB_t *oldcmd;
  3749. struct lpfc_iocbq *elsiocb;
  3750. struct lpfc_sli *psli;
  3751. uint8_t *pcmd;
  3752. uint16_t cmdsize;
  3753. int rc;
  3754. psli = &phba->sli;
  3755. cmdsize = sizeof(uint32_t) + sizeof(PRLI);
  3756. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3757. ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
  3758. if (!elsiocb)
  3759. return 1;
  3760. icmd = &elsiocb->iocb;
  3761. oldcmd = &oldiocb->iocb;
  3762. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3763. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3764. /* Xmit PRLI ACC response tag <ulpIoTag> */
  3765. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3766. "0131 Xmit PRLI ACC response tag x%x xri x%x, "
  3767. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  3768. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3769. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3770. ndlp->nlp_rpi);
  3771. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3772. *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
  3773. pcmd += sizeof(uint32_t);
  3774. /* For PRLI, remainder of payload is PRLI parameter page */
  3775. memset(pcmd, 0, sizeof(PRLI));
  3776. npr = (PRLI *) pcmd;
  3777. vpd = &phba->vpd;
  3778. /*
  3779. * If the remote port is a target and our firmware version is 3.20 or
  3780. * later, set the following bits for FC-TAPE support.
  3781. */
  3782. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  3783. (vpd->rev.feaLevelHigh >= 0x02)) {
  3784. npr->ConfmComplAllowed = 1;
  3785. npr->Retry = 1;
  3786. npr->TaskRetryIdReq = 1;
  3787. }
  3788. npr->acceptRspCode = PRLI_REQ_EXECUTED;
  3789. npr->estabImagePair = 1;
  3790. npr->readXferRdyDis = 1;
  3791. npr->ConfmComplAllowed = 1;
  3792. npr->prliType = PRLI_FCP_TYPE;
  3793. npr->initiatorFunc = 1;
  3794. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3795. "Issue ACC PRLI: did:x%x flg:x%x",
  3796. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3797. phba->fc_stat.elsXmitACC++;
  3798. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3799. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3800. if (rc == IOCB_ERROR) {
  3801. lpfc_els_free_iocb(phba, elsiocb);
  3802. return 1;
  3803. }
  3804. return 0;
  3805. }
  3806. /**
  3807. * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
  3808. * @vport: pointer to a virtual N_Port data structure.
  3809. * @format: rnid command format.
  3810. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3811. * @ndlp: pointer to a node-list data structure.
  3812. *
  3813. * This routine issues a Request Node Identification Data (RNID) Accept
  3814. * (ACC) response. It constructs the RNID ACC response command according to
  3815. * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
  3816. * issue the response. Note that this command does not need to hold the ndlp
  3817. * reference count for the callback. So, the ndlp reference count taken by
  3818. * the lpfc_prep_els_iocb() routine is put back and the context1 field of
  3819. * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
  3820. * there is no ndlp reference available.
  3821. *
  3822. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3823. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3824. * will be stored into the context1 field of the IOCB for the completion
  3825. * callback function. However, for the RNID Accept Response ELS command,
  3826. * this is undone later by this routine after the IOCB is allocated.
  3827. *
  3828. * Return code
  3829. * 0 - Successfully issued acc rnid response
  3830. * 1 - Failed to issue acc rnid response
  3831. **/
  3832. static int
  3833. lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
  3834. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  3835. {
  3836. struct lpfc_hba *phba = vport->phba;
  3837. RNID *rn;
  3838. IOCB_t *icmd, *oldcmd;
  3839. struct lpfc_iocbq *elsiocb;
  3840. struct lpfc_sli *psli;
  3841. uint8_t *pcmd;
  3842. uint16_t cmdsize;
  3843. int rc;
  3844. psli = &phba->sli;
  3845. cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
  3846. + (2 * sizeof(struct lpfc_name));
  3847. if (format)
  3848. cmdsize += sizeof(RNID_TOP_DISC);
  3849. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3850. ndlp->nlp_DID, ELS_CMD_ACC);
  3851. if (!elsiocb)
  3852. return 1;
  3853. icmd = &elsiocb->iocb;
  3854. oldcmd = &oldiocb->iocb;
  3855. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3856. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3857. /* Xmit RNID ACC response tag <ulpIoTag> */
  3858. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3859. "0132 Xmit RNID ACC response tag x%x xri x%x\n",
  3860. elsiocb->iotag, elsiocb->iocb.ulpContext);
  3861. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3862. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3863. pcmd += sizeof(uint32_t);
  3864. memset(pcmd, 0, sizeof(RNID));
  3865. rn = (RNID *) (pcmd);
  3866. rn->Format = format;
  3867. rn->CommonLen = (2 * sizeof(struct lpfc_name));
  3868. memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  3869. memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  3870. switch (format) {
  3871. case 0:
  3872. rn->SpecificLen = 0;
  3873. break;
  3874. case RNID_TOPOLOGY_DISC:
  3875. rn->SpecificLen = sizeof(RNID_TOP_DISC);
  3876. memcpy(&rn->un.topologyDisc.portName,
  3877. &vport->fc_portname, sizeof(struct lpfc_name));
  3878. rn->un.topologyDisc.unitType = RNID_HBA;
  3879. rn->un.topologyDisc.physPort = 0;
  3880. rn->un.topologyDisc.attachedNodes = 0;
  3881. break;
  3882. default:
  3883. rn->CommonLen = 0;
  3884. rn->SpecificLen = 0;
  3885. break;
  3886. }
  3887. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3888. "Issue ACC RNID: did:x%x flg:x%x",
  3889. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3890. phba->fc_stat.elsXmitACC++;
  3891. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3892. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3893. if (rc == IOCB_ERROR) {
  3894. lpfc_els_free_iocb(phba, elsiocb);
  3895. return 1;
  3896. }
  3897. return 0;
  3898. }
  3899. /**
  3900. * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
  3901. * @vport: pointer to a virtual N_Port data structure.
  3902. * @iocb: pointer to the lpfc command iocb data structure.
  3903. * @ndlp: pointer to a node-list data structure.
  3904. *
  3905. * Return
  3906. **/
  3907. static void
  3908. lpfc_els_clear_rrq(struct lpfc_vport *vport,
  3909. struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
  3910. {
  3911. struct lpfc_hba *phba = vport->phba;
  3912. uint8_t *pcmd;
  3913. struct RRQ *rrq;
  3914. uint16_t rxid;
  3915. uint16_t xri;
  3916. struct lpfc_node_rrq *prrq;
  3917. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
  3918. pcmd += sizeof(uint32_t);
  3919. rrq = (struct RRQ *)pcmd;
  3920. rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
  3921. rxid = bf_get(rrq_rxid, rrq);
  3922. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3923. "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
  3924. " x%x x%x\n",
  3925. be32_to_cpu(bf_get(rrq_did, rrq)),
  3926. bf_get(rrq_oxid, rrq),
  3927. rxid,
  3928. iocb->iotag, iocb->iocb.ulpContext);
  3929. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3930. "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
  3931. ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
  3932. if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
  3933. xri = bf_get(rrq_oxid, rrq);
  3934. else
  3935. xri = rxid;
  3936. prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
  3937. if (prrq)
  3938. lpfc_clr_rrq_active(phba, xri, prrq);
  3939. return;
  3940. }
  3941. /**
  3942. * lpfc_els_rsp_echo_acc - Issue echo acc response
  3943. * @vport: pointer to a virtual N_Port data structure.
  3944. * @data: pointer to echo data to return in the accept.
  3945. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3946. * @ndlp: pointer to a node-list data structure.
  3947. *
  3948. * Return code
  3949. * 0 - Successfully issued acc echo response
  3950. * 1 - Failed to issue acc echo response
  3951. **/
  3952. static int
  3953. lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
  3954. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  3955. {
  3956. struct lpfc_hba *phba = vport->phba;
  3957. struct lpfc_iocbq *elsiocb;
  3958. struct lpfc_sli *psli;
  3959. uint8_t *pcmd;
  3960. uint16_t cmdsize;
  3961. int rc;
  3962. psli = &phba->sli;
  3963. cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
  3964. /* The accumulated length can exceed the BPL_SIZE. For
  3965. * now, use this as the limit
  3966. */
  3967. if (cmdsize > LPFC_BPL_SIZE)
  3968. cmdsize = LPFC_BPL_SIZE;
  3969. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3970. ndlp->nlp_DID, ELS_CMD_ACC);
  3971. if (!elsiocb)
  3972. return 1;
  3973. elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
  3974. elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
  3975. /* Xmit ECHO ACC response tag <ulpIoTag> */
  3976. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3977. "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
  3978. elsiocb->iotag, elsiocb->iocb.ulpContext);
  3979. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3980. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3981. pcmd += sizeof(uint32_t);
  3982. memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
  3983. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3984. "Issue ACC ECHO: did:x%x flg:x%x",
  3985. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3986. phba->fc_stat.elsXmitACC++;
  3987. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3988. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3989. if (rc == IOCB_ERROR) {
  3990. lpfc_els_free_iocb(phba, elsiocb);
  3991. return 1;
  3992. }
  3993. return 0;
  3994. }
  3995. /**
  3996. * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
  3997. * @vport: pointer to a host virtual N_Port data structure.
  3998. *
  3999. * This routine issues Address Discover (ADISC) ELS commands to those
  4000. * N_Ports which are in node port recovery state and ADISC has not been issued
  4001. * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
  4002. * lpfc_issue_els_adisc() routine, the per @vport number of discover count
  4003. * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
  4004. * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
  4005. * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
  4006. * IOCBs quit for later pick up. On the other hand, after walking through
  4007. * all the ndlps with the @vport and there is none ADISC IOCB issued, the
  4008. * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
  4009. * no more ADISC need to be sent.
  4010. *
  4011. * Return code
  4012. * The number of N_Ports with adisc issued.
  4013. **/
  4014. int
  4015. lpfc_els_disc_adisc(struct lpfc_vport *vport)
  4016. {
  4017. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4018. struct lpfc_nodelist *ndlp, *next_ndlp;
  4019. int sentadisc = 0;
  4020. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  4021. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  4022. if (!NLP_CHK_NODE_ACT(ndlp))
  4023. continue;
  4024. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  4025. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  4026. (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
  4027. spin_lock_irq(shost->host_lock);
  4028. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  4029. spin_unlock_irq(shost->host_lock);
  4030. ndlp->nlp_prev_state = ndlp->nlp_state;
  4031. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  4032. lpfc_issue_els_adisc(vport, ndlp, 0);
  4033. sentadisc++;
  4034. vport->num_disc_nodes++;
  4035. if (vport->num_disc_nodes >=
  4036. vport->cfg_discovery_threads) {
  4037. spin_lock_irq(shost->host_lock);
  4038. vport->fc_flag |= FC_NLP_MORE;
  4039. spin_unlock_irq(shost->host_lock);
  4040. break;
  4041. }
  4042. }
  4043. }
  4044. if (sentadisc == 0) {
  4045. spin_lock_irq(shost->host_lock);
  4046. vport->fc_flag &= ~FC_NLP_MORE;
  4047. spin_unlock_irq(shost->host_lock);
  4048. }
  4049. return sentadisc;
  4050. }
  4051. /**
  4052. * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
  4053. * @vport: pointer to a host virtual N_Port data structure.
  4054. *
  4055. * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
  4056. * which are in node port recovery state, with a @vport. Each time an ELS
  4057. * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
  4058. * the per @vport number of discover count (num_disc_nodes) shall be
  4059. * incremented. If the num_disc_nodes reaches a pre-configured threshold
  4060. * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
  4061. * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
  4062. * later pick up. On the other hand, after walking through all the ndlps with
  4063. * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
  4064. * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
  4065. * PLOGI need to be sent.
  4066. *
  4067. * Return code
  4068. * The number of N_Ports with plogi issued.
  4069. **/
  4070. int
  4071. lpfc_els_disc_plogi(struct lpfc_vport *vport)
  4072. {
  4073. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4074. struct lpfc_nodelist *ndlp, *next_ndlp;
  4075. int sentplogi = 0;
  4076. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  4077. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  4078. if (!NLP_CHK_NODE_ACT(ndlp))
  4079. continue;
  4080. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  4081. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  4082. (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
  4083. (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
  4084. ndlp->nlp_prev_state = ndlp->nlp_state;
  4085. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  4086. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  4087. sentplogi++;
  4088. vport->num_disc_nodes++;
  4089. if (vport->num_disc_nodes >=
  4090. vport->cfg_discovery_threads) {
  4091. spin_lock_irq(shost->host_lock);
  4092. vport->fc_flag |= FC_NLP_MORE;
  4093. spin_unlock_irq(shost->host_lock);
  4094. break;
  4095. }
  4096. }
  4097. }
  4098. if (sentplogi) {
  4099. lpfc_set_disctmo(vport);
  4100. }
  4101. else {
  4102. spin_lock_irq(shost->host_lock);
  4103. vport->fc_flag &= ~FC_NLP_MORE;
  4104. spin_unlock_irq(shost->host_lock);
  4105. }
  4106. return sentplogi;
  4107. }
  4108. /**
  4109. * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
  4110. * @vport: pointer to a host virtual N_Port data structure.
  4111. *
  4112. * This routine cleans up any Registration State Change Notification
  4113. * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
  4114. * @vport together with the host_lock is used to prevent multiple thread
  4115. * trying to access the RSCN array on a same @vport at the same time.
  4116. **/
  4117. void
  4118. lpfc_els_flush_rscn(struct lpfc_vport *vport)
  4119. {
  4120. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4121. struct lpfc_hba *phba = vport->phba;
  4122. int i;
  4123. spin_lock_irq(shost->host_lock);
  4124. if (vport->fc_rscn_flush) {
  4125. /* Another thread is walking fc_rscn_id_list on this vport */
  4126. spin_unlock_irq(shost->host_lock);
  4127. return;
  4128. }
  4129. /* Indicate we are walking lpfc_els_flush_rscn on this vport */
  4130. vport->fc_rscn_flush = 1;
  4131. spin_unlock_irq(shost->host_lock);
  4132. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  4133. lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
  4134. vport->fc_rscn_id_list[i] = NULL;
  4135. }
  4136. spin_lock_irq(shost->host_lock);
  4137. vport->fc_rscn_id_cnt = 0;
  4138. vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
  4139. spin_unlock_irq(shost->host_lock);
  4140. lpfc_can_disctmo(vport);
  4141. /* Indicate we are done walking this fc_rscn_id_list */
  4142. vport->fc_rscn_flush = 0;
  4143. }
  4144. /**
  4145. * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
  4146. * @vport: pointer to a host virtual N_Port data structure.
  4147. * @did: remote destination port identifier.
  4148. *
  4149. * This routine checks whether there is any pending Registration State
  4150. * Configuration Notification (RSCN) to a @did on @vport.
  4151. *
  4152. * Return code
  4153. * None zero - The @did matched with a pending rscn
  4154. * 0 - not able to match @did with a pending rscn
  4155. **/
  4156. int
  4157. lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
  4158. {
  4159. D_ID ns_did;
  4160. D_ID rscn_did;
  4161. uint32_t *lp;
  4162. uint32_t payload_len, i;
  4163. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4164. ns_did.un.word = did;
  4165. /* Never match fabric nodes for RSCNs */
  4166. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  4167. return 0;
  4168. /* If we are doing a FULL RSCN rediscovery, match everything */
  4169. if (vport->fc_flag & FC_RSCN_DISCOVERY)
  4170. return did;
  4171. spin_lock_irq(shost->host_lock);
  4172. if (vport->fc_rscn_flush) {
  4173. /* Another thread is walking fc_rscn_id_list on this vport */
  4174. spin_unlock_irq(shost->host_lock);
  4175. return 0;
  4176. }
  4177. /* Indicate we are walking fc_rscn_id_list on this vport */
  4178. vport->fc_rscn_flush = 1;
  4179. spin_unlock_irq(shost->host_lock);
  4180. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  4181. lp = vport->fc_rscn_id_list[i]->virt;
  4182. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  4183. payload_len -= sizeof(uint32_t); /* take off word 0 */
  4184. while (payload_len) {
  4185. rscn_did.un.word = be32_to_cpu(*lp++);
  4186. payload_len -= sizeof(uint32_t);
  4187. switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
  4188. case RSCN_ADDRESS_FORMAT_PORT:
  4189. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  4190. && (ns_did.un.b.area == rscn_did.un.b.area)
  4191. && (ns_did.un.b.id == rscn_did.un.b.id))
  4192. goto return_did_out;
  4193. break;
  4194. case RSCN_ADDRESS_FORMAT_AREA:
  4195. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  4196. && (ns_did.un.b.area == rscn_did.un.b.area))
  4197. goto return_did_out;
  4198. break;
  4199. case RSCN_ADDRESS_FORMAT_DOMAIN:
  4200. if (ns_did.un.b.domain == rscn_did.un.b.domain)
  4201. goto return_did_out;
  4202. break;
  4203. case RSCN_ADDRESS_FORMAT_FABRIC:
  4204. goto return_did_out;
  4205. }
  4206. }
  4207. }
  4208. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  4209. vport->fc_rscn_flush = 0;
  4210. return 0;
  4211. return_did_out:
  4212. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  4213. vport->fc_rscn_flush = 0;
  4214. return did;
  4215. }
  4216. /**
  4217. * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
  4218. * @vport: pointer to a host virtual N_Port data structure.
  4219. *
  4220. * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
  4221. * state machine for a @vport's nodes that are with pending RSCN (Registration
  4222. * State Change Notification).
  4223. *
  4224. * Return code
  4225. * 0 - Successful (currently alway return 0)
  4226. **/
  4227. static int
  4228. lpfc_rscn_recovery_check(struct lpfc_vport *vport)
  4229. {
  4230. struct lpfc_nodelist *ndlp = NULL;
  4231. /* Move all affected nodes by pending RSCNs to NPR state. */
  4232. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  4233. if (!NLP_CHK_NODE_ACT(ndlp) ||
  4234. (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
  4235. !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
  4236. continue;
  4237. lpfc_disc_state_machine(vport, ndlp, NULL,
  4238. NLP_EVT_DEVICE_RECOVERY);
  4239. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  4240. }
  4241. return 0;
  4242. }
  4243. /**
  4244. * lpfc_send_rscn_event - Send an RSCN event to management application
  4245. * @vport: pointer to a host virtual N_Port data structure.
  4246. * @cmdiocb: pointer to lpfc command iocb data structure.
  4247. *
  4248. * lpfc_send_rscn_event sends an RSCN netlink event to management
  4249. * applications.
  4250. */
  4251. static void
  4252. lpfc_send_rscn_event(struct lpfc_vport *vport,
  4253. struct lpfc_iocbq *cmdiocb)
  4254. {
  4255. struct lpfc_dmabuf *pcmd;
  4256. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4257. uint32_t *payload_ptr;
  4258. uint32_t payload_len;
  4259. struct lpfc_rscn_event_header *rscn_event_data;
  4260. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4261. payload_ptr = (uint32_t *) pcmd->virt;
  4262. payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
  4263. rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
  4264. payload_len, GFP_KERNEL);
  4265. if (!rscn_event_data) {
  4266. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4267. "0147 Failed to allocate memory for RSCN event\n");
  4268. return;
  4269. }
  4270. rscn_event_data->event_type = FC_REG_RSCN_EVENT;
  4271. rscn_event_data->payload_length = payload_len;
  4272. memcpy(rscn_event_data->rscn_payload, payload_ptr,
  4273. payload_len);
  4274. fc_host_post_vendor_event(shost,
  4275. fc_get_event_number(),
  4276. sizeof(struct lpfc_els_event_header) + payload_len,
  4277. (char *)rscn_event_data,
  4278. LPFC_NL_VENDOR_ID);
  4279. kfree(rscn_event_data);
  4280. }
  4281. /**
  4282. * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
  4283. * @vport: pointer to a host virtual N_Port data structure.
  4284. * @cmdiocb: pointer to lpfc command iocb data structure.
  4285. * @ndlp: pointer to a node-list data structure.
  4286. *
  4287. * This routine processes an unsolicited RSCN (Registration State Change
  4288. * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
  4289. * to invoke fc_host_post_event() routine to the FC transport layer. If the
  4290. * discover state machine is about to begin discovery, it just accepts the
  4291. * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
  4292. * contains N_Port IDs for other vports on this HBA, it just accepts the
  4293. * RSCN and ignore processing it. If the state machine is in the recovery
  4294. * state, the fc_rscn_id_list of this @vport is walked and the
  4295. * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
  4296. * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
  4297. * routine is invoked to handle the RSCN event.
  4298. *
  4299. * Return code
  4300. * 0 - Just sent the acc response
  4301. * 1 - Sent the acc response and waited for name server completion
  4302. **/
  4303. static int
  4304. lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4305. struct lpfc_nodelist *ndlp)
  4306. {
  4307. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4308. struct lpfc_hba *phba = vport->phba;
  4309. struct lpfc_dmabuf *pcmd;
  4310. uint32_t *lp, *datap;
  4311. IOCB_t *icmd;
  4312. uint32_t payload_len, length, nportid, *cmd;
  4313. int rscn_cnt;
  4314. int rscn_id = 0, hba_id = 0;
  4315. int i;
  4316. icmd = &cmdiocb->iocb;
  4317. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4318. lp = (uint32_t *) pcmd->virt;
  4319. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  4320. payload_len -= sizeof(uint32_t); /* take off word 0 */
  4321. /* RSCN received */
  4322. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4323. "0214 RSCN received Data: x%x x%x x%x x%x\n",
  4324. vport->fc_flag, payload_len, *lp,
  4325. vport->fc_rscn_id_cnt);
  4326. /* Send an RSCN event to the management application */
  4327. lpfc_send_rscn_event(vport, cmdiocb);
  4328. for (i = 0; i < payload_len/sizeof(uint32_t); i++)
  4329. fc_host_post_event(shost, fc_get_event_number(),
  4330. FCH_EVT_RSCN, lp[i]);
  4331. /* If we are about to begin discovery, just ACC the RSCN.
  4332. * Discovery processing will satisfy it.
  4333. */
  4334. if (vport->port_state <= LPFC_NS_QRY) {
  4335. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  4336. "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
  4337. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  4338. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4339. return 0;
  4340. }
  4341. /* If this RSCN just contains NPortIDs for other vports on this HBA,
  4342. * just ACC and ignore it.
  4343. */
  4344. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  4345. !(vport->cfg_peer_port_login)) {
  4346. i = payload_len;
  4347. datap = lp;
  4348. while (i > 0) {
  4349. nportid = *datap++;
  4350. nportid = ((be32_to_cpu(nportid)) & Mask_DID);
  4351. i -= sizeof(uint32_t);
  4352. rscn_id++;
  4353. if (lpfc_find_vport_by_did(phba, nportid))
  4354. hba_id++;
  4355. }
  4356. if (rscn_id == hba_id) {
  4357. /* ALL NPortIDs in RSCN are on HBA */
  4358. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4359. "0219 Ignore RSCN "
  4360. "Data: x%x x%x x%x x%x\n",
  4361. vport->fc_flag, payload_len,
  4362. *lp, vport->fc_rscn_id_cnt);
  4363. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  4364. "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
  4365. ndlp->nlp_DID, vport->port_state,
  4366. ndlp->nlp_flag);
  4367. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
  4368. ndlp, NULL);
  4369. return 0;
  4370. }
  4371. }
  4372. spin_lock_irq(shost->host_lock);
  4373. if (vport->fc_rscn_flush) {
  4374. /* Another thread is walking fc_rscn_id_list on this vport */
  4375. vport->fc_flag |= FC_RSCN_DISCOVERY;
  4376. spin_unlock_irq(shost->host_lock);
  4377. /* Send back ACC */
  4378. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4379. return 0;
  4380. }
  4381. /* Indicate we are walking fc_rscn_id_list on this vport */
  4382. vport->fc_rscn_flush = 1;
  4383. spin_unlock_irq(shost->host_lock);
  4384. /* Get the array count after successfully have the token */
  4385. rscn_cnt = vport->fc_rscn_id_cnt;
  4386. /* If we are already processing an RSCN, save the received
  4387. * RSCN payload buffer, cmdiocb->context2 to process later.
  4388. */
  4389. if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
  4390. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  4391. "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
  4392. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  4393. spin_lock_irq(shost->host_lock);
  4394. vport->fc_flag |= FC_RSCN_DEFERRED;
  4395. if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
  4396. !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
  4397. vport->fc_flag |= FC_RSCN_MODE;
  4398. spin_unlock_irq(shost->host_lock);
  4399. if (rscn_cnt) {
  4400. cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
  4401. length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
  4402. }
  4403. if ((rscn_cnt) &&
  4404. (payload_len + length <= LPFC_BPL_SIZE)) {
  4405. *cmd &= ELS_CMD_MASK;
  4406. *cmd |= cpu_to_be32(payload_len + length);
  4407. memcpy(((uint8_t *)cmd) + length, lp,
  4408. payload_len);
  4409. } else {
  4410. vport->fc_rscn_id_list[rscn_cnt] = pcmd;
  4411. vport->fc_rscn_id_cnt++;
  4412. /* If we zero, cmdiocb->context2, the calling
  4413. * routine will not try to free it.
  4414. */
  4415. cmdiocb->context2 = NULL;
  4416. }
  4417. /* Deferred RSCN */
  4418. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4419. "0235 Deferred RSCN "
  4420. "Data: x%x x%x x%x\n",
  4421. vport->fc_rscn_id_cnt, vport->fc_flag,
  4422. vport->port_state);
  4423. } else {
  4424. vport->fc_flag |= FC_RSCN_DISCOVERY;
  4425. spin_unlock_irq(shost->host_lock);
  4426. /* ReDiscovery RSCN */
  4427. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4428. "0234 ReDiscovery RSCN "
  4429. "Data: x%x x%x x%x\n",
  4430. vport->fc_rscn_id_cnt, vport->fc_flag,
  4431. vport->port_state);
  4432. }
  4433. /* Indicate we are done walking fc_rscn_id_list on this vport */
  4434. vport->fc_rscn_flush = 0;
  4435. /* Send back ACC */
  4436. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4437. /* send RECOVERY event for ALL nodes that match RSCN payload */
  4438. lpfc_rscn_recovery_check(vport);
  4439. spin_lock_irq(shost->host_lock);
  4440. vport->fc_flag &= ~FC_RSCN_DEFERRED;
  4441. spin_unlock_irq(shost->host_lock);
  4442. return 0;
  4443. }
  4444. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  4445. "RCV RSCN: did:x%x/ste:x%x flg:x%x",
  4446. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  4447. spin_lock_irq(shost->host_lock);
  4448. vport->fc_flag |= FC_RSCN_MODE;
  4449. spin_unlock_irq(shost->host_lock);
  4450. vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
  4451. /* Indicate we are done walking fc_rscn_id_list on this vport */
  4452. vport->fc_rscn_flush = 0;
  4453. /*
  4454. * If we zero, cmdiocb->context2, the calling routine will
  4455. * not try to free it.
  4456. */
  4457. cmdiocb->context2 = NULL;
  4458. lpfc_set_disctmo(vport);
  4459. /* Send back ACC */
  4460. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4461. /* send RECOVERY event for ALL nodes that match RSCN payload */
  4462. lpfc_rscn_recovery_check(vport);
  4463. return lpfc_els_handle_rscn(vport);
  4464. }
  4465. /**
  4466. * lpfc_els_handle_rscn - Handle rscn for a vport
  4467. * @vport: pointer to a host virtual N_Port data structure.
  4468. *
  4469. * This routine handles the Registration State Configuration Notification
  4470. * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
  4471. * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
  4472. * if the ndlp to NameServer exists, a Common Transport (CT) command to the
  4473. * NameServer shall be issued. If CT command to the NameServer fails to be
  4474. * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
  4475. * RSCN activities with the @vport.
  4476. *
  4477. * Return code
  4478. * 0 - Cleaned up rscn on the @vport
  4479. * 1 - Wait for plogi to name server before proceed
  4480. **/
  4481. int
  4482. lpfc_els_handle_rscn(struct lpfc_vport *vport)
  4483. {
  4484. struct lpfc_nodelist *ndlp;
  4485. struct lpfc_hba *phba = vport->phba;
  4486. /* Ignore RSCN if the port is being torn down. */
  4487. if (vport->load_flag & FC_UNLOADING) {
  4488. lpfc_els_flush_rscn(vport);
  4489. return 0;
  4490. }
  4491. /* Start timer for RSCN processing */
  4492. lpfc_set_disctmo(vport);
  4493. /* RSCN processed */
  4494. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4495. "0215 RSCN processed Data: x%x x%x x%x x%x\n",
  4496. vport->fc_flag, 0, vport->fc_rscn_id_cnt,
  4497. vport->port_state);
  4498. /* To process RSCN, first compare RSCN data with NameServer */
  4499. vport->fc_ns_retry = 0;
  4500. vport->num_disc_nodes = 0;
  4501. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  4502. if (ndlp && NLP_CHK_NODE_ACT(ndlp)
  4503. && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  4504. /* Good ndlp, issue CT Request to NameServer */
  4505. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
  4506. /* Wait for NameServer query cmpl before we can
  4507. continue */
  4508. return 1;
  4509. } else {
  4510. /* If login to NameServer does not exist, issue one */
  4511. /* Good status, issue PLOGI to NameServer */
  4512. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  4513. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  4514. /* Wait for NameServer login cmpl before we can
  4515. continue */
  4516. return 1;
  4517. if (ndlp) {
  4518. ndlp = lpfc_enable_node(vport, ndlp,
  4519. NLP_STE_PLOGI_ISSUE);
  4520. if (!ndlp) {
  4521. lpfc_els_flush_rscn(vport);
  4522. return 0;
  4523. }
  4524. ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
  4525. } else {
  4526. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  4527. if (!ndlp) {
  4528. lpfc_els_flush_rscn(vport);
  4529. return 0;
  4530. }
  4531. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  4532. ndlp->nlp_prev_state = ndlp->nlp_state;
  4533. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  4534. }
  4535. ndlp->nlp_type |= NLP_FABRIC;
  4536. lpfc_issue_els_plogi(vport, NameServer_DID, 0);
  4537. /* Wait for NameServer login cmpl before we can
  4538. * continue
  4539. */
  4540. return 1;
  4541. }
  4542. lpfc_els_flush_rscn(vport);
  4543. return 0;
  4544. }
  4545. /**
  4546. * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
  4547. * @vport: pointer to a host virtual N_Port data structure.
  4548. * @cmdiocb: pointer to lpfc command iocb data structure.
  4549. * @ndlp: pointer to a node-list data structure.
  4550. *
  4551. * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
  4552. * unsolicited event. An unsolicited FLOGI can be received in a point-to-
  4553. * point topology. As an unsolicited FLOGI should not be received in a loop
  4554. * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
  4555. * lpfc_check_sparm() routine is invoked to check the parameters in the
  4556. * unsolicited FLOGI. If parameters validation failed, the routine
  4557. * lpfc_els_rsp_reject() shall be called with reject reason code set to
  4558. * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
  4559. * FLOGI shall be compared with the Port WWN of the @vport to determine who
  4560. * will initiate PLOGI. The higher lexicographical value party shall has
  4561. * higher priority (as the winning port) and will initiate PLOGI and
  4562. * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
  4563. * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
  4564. * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
  4565. *
  4566. * Return code
  4567. * 0 - Successfully processed the unsolicited flogi
  4568. * 1 - Failed to process the unsolicited flogi
  4569. **/
  4570. static int
  4571. lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4572. struct lpfc_nodelist *ndlp)
  4573. {
  4574. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4575. struct lpfc_hba *phba = vport->phba;
  4576. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4577. uint32_t *lp = (uint32_t *) pcmd->virt;
  4578. IOCB_t *icmd = &cmdiocb->iocb;
  4579. struct serv_parm *sp;
  4580. LPFC_MBOXQ_t *mbox;
  4581. struct ls_rjt stat;
  4582. uint32_t cmd, did;
  4583. int rc;
  4584. cmd = *lp++;
  4585. sp = (struct serv_parm *) lp;
  4586. /* FLOGI received */
  4587. lpfc_set_disctmo(vport);
  4588. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  4589. /* We should never receive a FLOGI in loop mode, ignore it */
  4590. did = icmd->un.elsreq64.remoteID;
  4591. /* An FLOGI ELS command <elsCmd> was received from DID <did> in
  4592. Loop Mode */
  4593. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4594. "0113 An FLOGI ELS command x%x was "
  4595. "received from DID x%x in Loop Mode\n",
  4596. cmd, did);
  4597. return 1;
  4598. }
  4599. if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
  4600. /* For a FLOGI we accept, then if our portname is greater
  4601. * then the remote portname we initiate Nport login.
  4602. */
  4603. rc = memcmp(&vport->fc_portname, &sp->portName,
  4604. sizeof(struct lpfc_name));
  4605. if (!rc) {
  4606. if (phba->sli_rev < LPFC_SLI_REV4) {
  4607. mbox = mempool_alloc(phba->mbox_mem_pool,
  4608. GFP_KERNEL);
  4609. if (!mbox)
  4610. return 1;
  4611. lpfc_linkdown(phba);
  4612. lpfc_init_link(phba, mbox,
  4613. phba->cfg_topology,
  4614. phba->cfg_link_speed);
  4615. mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  4616. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4617. mbox->vport = vport;
  4618. rc = lpfc_sli_issue_mbox(phba, mbox,
  4619. MBX_NOWAIT);
  4620. lpfc_set_loopback_flag(phba);
  4621. if (rc == MBX_NOT_FINISHED)
  4622. mempool_free(mbox, phba->mbox_mem_pool);
  4623. return 1;
  4624. } else {
  4625. /* abort the flogi coming back to ourselves
  4626. * due to external loopback on the port.
  4627. */
  4628. lpfc_els_abort_flogi(phba);
  4629. return 0;
  4630. }
  4631. } else if (rc > 0) { /* greater than */
  4632. spin_lock_irq(shost->host_lock);
  4633. vport->fc_flag |= FC_PT2PT_PLOGI;
  4634. spin_unlock_irq(shost->host_lock);
  4635. /* If we have the high WWPN we can assign our own
  4636. * myDID; otherwise, we have to WAIT for a PLOGI
  4637. * from the remote NPort to find out what it
  4638. * will be.
  4639. */
  4640. vport->fc_myDID = PT2PT_LocalID;
  4641. }
  4642. /*
  4643. * The vport state should go to LPFC_FLOGI only
  4644. * AFTER we issue a FLOGI, not receive one.
  4645. */
  4646. spin_lock_irq(shost->host_lock);
  4647. vport->fc_flag |= FC_PT2PT;
  4648. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  4649. spin_unlock_irq(shost->host_lock);
  4650. /*
  4651. * We temporarily set fc_myDID to make it look like we are
  4652. * a Fabric. This is done just so we end up with the right
  4653. * did / sid on the FLOGI ACC rsp.
  4654. */
  4655. did = vport->fc_myDID;
  4656. vport->fc_myDID = Fabric_DID;
  4657. } else {
  4658. /* Reject this request because invalid parameters */
  4659. stat.un.b.lsRjtRsvd0 = 0;
  4660. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  4661. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  4662. stat.un.b.vendorUnique = 0;
  4663. /*
  4664. * We temporarily set fc_myDID to make it look like we are
  4665. * a Fabric. This is done just so we end up with the right
  4666. * did / sid on the FLOGI LS_RJT rsp.
  4667. */
  4668. did = vport->fc_myDID;
  4669. vport->fc_myDID = Fabric_DID;
  4670. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  4671. NULL);
  4672. /* Now lets put fc_myDID back to what its supposed to be */
  4673. vport->fc_myDID = did;
  4674. return 1;
  4675. }
  4676. /* Send back ACC */
  4677. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
  4678. /* Now lets put fc_myDID back to what its supposed to be */
  4679. vport->fc_myDID = did;
  4680. if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
  4681. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4682. if (!mbox)
  4683. goto fail;
  4684. lpfc_config_link(phba, mbox);
  4685. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4686. mbox->vport = vport;
  4687. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4688. if (rc == MBX_NOT_FINISHED) {
  4689. mempool_free(mbox, phba->mbox_mem_pool);
  4690. goto fail;
  4691. }
  4692. }
  4693. return 0;
  4694. fail:
  4695. return 1;
  4696. }
  4697. /**
  4698. * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
  4699. * @vport: pointer to a host virtual N_Port data structure.
  4700. * @cmdiocb: pointer to lpfc command iocb data structure.
  4701. * @ndlp: pointer to a node-list data structure.
  4702. *
  4703. * This routine processes Request Node Identification Data (RNID) IOCB
  4704. * received as an ELS unsolicited event. Only when the RNID specified format
  4705. * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
  4706. * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
  4707. * Accept (ACC) the RNID ELS command. All the other RNID formats are
  4708. * rejected by invoking the lpfc_els_rsp_reject() routine.
  4709. *
  4710. * Return code
  4711. * 0 - Successfully processed rnid iocb (currently always return 0)
  4712. **/
  4713. static int
  4714. lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4715. struct lpfc_nodelist *ndlp)
  4716. {
  4717. struct lpfc_dmabuf *pcmd;
  4718. uint32_t *lp;
  4719. IOCB_t *icmd;
  4720. RNID *rn;
  4721. struct ls_rjt stat;
  4722. uint32_t cmd, did;
  4723. icmd = &cmdiocb->iocb;
  4724. did = icmd->un.elsreq64.remoteID;
  4725. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4726. lp = (uint32_t *) pcmd->virt;
  4727. cmd = *lp++;
  4728. rn = (RNID *) lp;
  4729. /* RNID received */
  4730. switch (rn->Format) {
  4731. case 0:
  4732. case RNID_TOPOLOGY_DISC:
  4733. /* Send back ACC */
  4734. lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
  4735. break;
  4736. default:
  4737. /* Reject this request because format not supported */
  4738. stat.un.b.lsRjtRsvd0 = 0;
  4739. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  4740. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  4741. stat.un.b.vendorUnique = 0;
  4742. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  4743. NULL);
  4744. }
  4745. return 0;
  4746. }
  4747. /**
  4748. * lpfc_els_rcv_echo - Process an unsolicited echo iocb
  4749. * @vport: pointer to a host virtual N_Port data structure.
  4750. * @cmdiocb: pointer to lpfc command iocb data structure.
  4751. * @ndlp: pointer to a node-list data structure.
  4752. *
  4753. * Return code
  4754. * 0 - Successfully processed echo iocb (currently always return 0)
  4755. **/
  4756. static int
  4757. lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4758. struct lpfc_nodelist *ndlp)
  4759. {
  4760. uint8_t *pcmd;
  4761. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
  4762. /* skip over first word of echo command to find echo data */
  4763. pcmd += sizeof(uint32_t);
  4764. lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
  4765. return 0;
  4766. }
  4767. /**
  4768. * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
  4769. * @vport: pointer to a host virtual N_Port data structure.
  4770. * @cmdiocb: pointer to lpfc command iocb data structure.
  4771. * @ndlp: pointer to a node-list data structure.
  4772. *
  4773. * This routine processes a Link Incident Report Registration(LIRR) IOCB
  4774. * received as an ELS unsolicited event. Currently, this function just invokes
  4775. * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
  4776. *
  4777. * Return code
  4778. * 0 - Successfully processed lirr iocb (currently always return 0)
  4779. **/
  4780. static int
  4781. lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4782. struct lpfc_nodelist *ndlp)
  4783. {
  4784. struct ls_rjt stat;
  4785. /* For now, unconditionally reject this command */
  4786. stat.un.b.lsRjtRsvd0 = 0;
  4787. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  4788. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  4789. stat.un.b.vendorUnique = 0;
  4790. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  4791. return 0;
  4792. }
  4793. /**
  4794. * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
  4795. * @vport: pointer to a host virtual N_Port data structure.
  4796. * @cmdiocb: pointer to lpfc command iocb data structure.
  4797. * @ndlp: pointer to a node-list data structure.
  4798. *
  4799. * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
  4800. * received as an ELS unsolicited event. A request to RRQ shall only
  4801. * be accepted if the Originator Nx_Port N_Port_ID or the Responder
  4802. * Nx_Port N_Port_ID of the target Exchange is the same as the
  4803. * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
  4804. * not accepted, an LS_RJT with reason code "Unable to perform
  4805. * command request" and reason code explanation "Invalid Originator
  4806. * S_ID" shall be returned. For now, we just unconditionally accept
  4807. * RRQ from the target.
  4808. **/
  4809. static void
  4810. lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4811. struct lpfc_nodelist *ndlp)
  4812. {
  4813. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4814. if (vport->phba->sli_rev == LPFC_SLI_REV4)
  4815. lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
  4816. }
  4817. /**
  4818. * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
  4819. * @phba: pointer to lpfc hba data structure.
  4820. * @pmb: pointer to the driver internal queue element for mailbox command.
  4821. *
  4822. * This routine is the completion callback function for the MBX_READ_LNK_STAT
  4823. * mailbox command. This callback function is to actually send the Accept
  4824. * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
  4825. * collects the link statistics from the completion of the MBX_READ_LNK_STAT
  4826. * mailbox command, constructs the RPS response with the link statistics
  4827. * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
  4828. * response to the RPS.
  4829. *
  4830. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4831. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4832. * will be stored into the context1 field of the IOCB for the completion
  4833. * callback function to the RPS Accept Response ELS IOCB command.
  4834. *
  4835. **/
  4836. static void
  4837. lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  4838. {
  4839. MAILBOX_t *mb;
  4840. IOCB_t *icmd;
  4841. struct RLS_RSP *rls_rsp;
  4842. uint8_t *pcmd;
  4843. struct lpfc_iocbq *elsiocb;
  4844. struct lpfc_nodelist *ndlp;
  4845. uint16_t oxid;
  4846. uint16_t rxid;
  4847. uint32_t cmdsize;
  4848. mb = &pmb->u.mb;
  4849. ndlp = (struct lpfc_nodelist *) pmb->context2;
  4850. rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
  4851. oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
  4852. pmb->context1 = NULL;
  4853. pmb->context2 = NULL;
  4854. if (mb->mbxStatus) {
  4855. mempool_free(pmb, phba->mbox_mem_pool);
  4856. return;
  4857. }
  4858. cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
  4859. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  4860. lpfc_max_els_tries, ndlp,
  4861. ndlp->nlp_DID, ELS_CMD_ACC);
  4862. /* Decrement the ndlp reference count from previous mbox command */
  4863. lpfc_nlp_put(ndlp);
  4864. if (!elsiocb) {
  4865. mempool_free(pmb, phba->mbox_mem_pool);
  4866. return;
  4867. }
  4868. icmd = &elsiocb->iocb;
  4869. icmd->ulpContext = rxid;
  4870. icmd->unsli3.rcvsli3.ox_id = oxid;
  4871. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4872. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4873. pcmd += sizeof(uint32_t); /* Skip past command */
  4874. rls_rsp = (struct RLS_RSP *)pcmd;
  4875. rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
  4876. rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
  4877. rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
  4878. rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
  4879. rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
  4880. rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
  4881. mempool_free(pmb, phba->mbox_mem_pool);
  4882. /* Xmit ELS RLS ACC response tag <ulpIoTag> */
  4883. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  4884. "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
  4885. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  4886. elsiocb->iotag, elsiocb->iocb.ulpContext,
  4887. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4888. ndlp->nlp_rpi);
  4889. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4890. phba->fc_stat.elsXmitACC++;
  4891. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
  4892. lpfc_els_free_iocb(phba, elsiocb);
  4893. }
  4894. /**
  4895. * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
  4896. * @phba: pointer to lpfc hba data structure.
  4897. * @pmb: pointer to the driver internal queue element for mailbox command.
  4898. *
  4899. * This routine is the completion callback function for the MBX_READ_LNK_STAT
  4900. * mailbox command. This callback function is to actually send the Accept
  4901. * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
  4902. * collects the link statistics from the completion of the MBX_READ_LNK_STAT
  4903. * mailbox command, constructs the RPS response with the link statistics
  4904. * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
  4905. * response to the RPS.
  4906. *
  4907. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4908. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4909. * will be stored into the context1 field of the IOCB for the completion
  4910. * callback function to the RPS Accept Response ELS IOCB command.
  4911. *
  4912. **/
  4913. static void
  4914. lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  4915. {
  4916. MAILBOX_t *mb;
  4917. IOCB_t *icmd;
  4918. RPS_RSP *rps_rsp;
  4919. uint8_t *pcmd;
  4920. struct lpfc_iocbq *elsiocb;
  4921. struct lpfc_nodelist *ndlp;
  4922. uint16_t status;
  4923. uint16_t oxid;
  4924. uint16_t rxid;
  4925. uint32_t cmdsize;
  4926. mb = &pmb->u.mb;
  4927. ndlp = (struct lpfc_nodelist *) pmb->context2;
  4928. rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
  4929. oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
  4930. pmb->context1 = NULL;
  4931. pmb->context2 = NULL;
  4932. if (mb->mbxStatus) {
  4933. mempool_free(pmb, phba->mbox_mem_pool);
  4934. return;
  4935. }
  4936. cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
  4937. mempool_free(pmb, phba->mbox_mem_pool);
  4938. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  4939. lpfc_max_els_tries, ndlp,
  4940. ndlp->nlp_DID, ELS_CMD_ACC);
  4941. /* Decrement the ndlp reference count from previous mbox command */
  4942. lpfc_nlp_put(ndlp);
  4943. if (!elsiocb)
  4944. return;
  4945. icmd = &elsiocb->iocb;
  4946. icmd->ulpContext = rxid;
  4947. icmd->unsli3.rcvsli3.ox_id = oxid;
  4948. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4949. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4950. pcmd += sizeof(uint32_t); /* Skip past command */
  4951. rps_rsp = (RPS_RSP *)pcmd;
  4952. if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
  4953. status = 0x10;
  4954. else
  4955. status = 0x8;
  4956. if (phba->pport->fc_flag & FC_FABRIC)
  4957. status |= 0x4;
  4958. rps_rsp->rsvd1 = 0;
  4959. rps_rsp->portStatus = cpu_to_be16(status);
  4960. rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
  4961. rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
  4962. rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
  4963. rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
  4964. rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
  4965. rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
  4966. /* Xmit ELS RPS ACC response tag <ulpIoTag> */
  4967. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  4968. "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
  4969. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  4970. elsiocb->iotag, elsiocb->iocb.ulpContext,
  4971. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4972. ndlp->nlp_rpi);
  4973. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4974. phba->fc_stat.elsXmitACC++;
  4975. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
  4976. lpfc_els_free_iocb(phba, elsiocb);
  4977. return;
  4978. }
  4979. /**
  4980. * lpfc_els_rcv_rls - Process an unsolicited rls iocb
  4981. * @vport: pointer to a host virtual N_Port data structure.
  4982. * @cmdiocb: pointer to lpfc command iocb data structure.
  4983. * @ndlp: pointer to a node-list data structure.
  4984. *
  4985. * This routine processes Read Port Status (RPL) IOCB received as an
  4986. * ELS unsolicited event. It first checks the remote port state. If the
  4987. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  4988. * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
  4989. * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
  4990. * for reading the HBA link statistics. It is for the callback function,
  4991. * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
  4992. * to actually sending out RPL Accept (ACC) response.
  4993. *
  4994. * Return codes
  4995. * 0 - Successfully processed rls iocb (currently always return 0)
  4996. **/
  4997. static int
  4998. lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4999. struct lpfc_nodelist *ndlp)
  5000. {
  5001. struct lpfc_hba *phba = vport->phba;
  5002. LPFC_MBOXQ_t *mbox;
  5003. struct lpfc_dmabuf *pcmd;
  5004. struct ls_rjt stat;
  5005. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  5006. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  5007. /* reject the unsolicited RPS request and done with it */
  5008. goto reject_out;
  5009. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5010. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
  5011. if (mbox) {
  5012. lpfc_read_lnk_stat(phba, mbox);
  5013. mbox->context1 = (void *)((unsigned long)
  5014. ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
  5015. cmdiocb->iocb.ulpContext)); /* rx_id */
  5016. mbox->context2 = lpfc_nlp_get(ndlp);
  5017. mbox->vport = vport;
  5018. mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
  5019. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  5020. != MBX_NOT_FINISHED)
  5021. /* Mbox completion will send ELS Response */
  5022. return 0;
  5023. /* Decrement reference count used for the failed mbox
  5024. * command.
  5025. */
  5026. lpfc_nlp_put(ndlp);
  5027. mempool_free(mbox, phba->mbox_mem_pool);
  5028. }
  5029. reject_out:
  5030. /* issue rejection response */
  5031. stat.un.b.lsRjtRsvd0 = 0;
  5032. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  5033. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  5034. stat.un.b.vendorUnique = 0;
  5035. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  5036. return 0;
  5037. }
  5038. /**
  5039. * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
  5040. * @vport: pointer to a host virtual N_Port data structure.
  5041. * @cmdiocb: pointer to lpfc command iocb data structure.
  5042. * @ndlp: pointer to a node-list data structure.
  5043. *
  5044. * This routine processes Read Timout Value (RTV) IOCB received as an
  5045. * ELS unsolicited event. It first checks the remote port state. If the
  5046. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  5047. * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
  5048. * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
  5049. * Value (RTV) unsolicited IOCB event.
  5050. *
  5051. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  5052. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  5053. * will be stored into the context1 field of the IOCB for the completion
  5054. * callback function to the RPS Accept Response ELS IOCB command.
  5055. *
  5056. * Return codes
  5057. * 0 - Successfully processed rtv iocb (currently always return 0)
  5058. **/
  5059. static int
  5060. lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5061. struct lpfc_nodelist *ndlp)
  5062. {
  5063. struct lpfc_hba *phba = vport->phba;
  5064. struct ls_rjt stat;
  5065. struct RTV_RSP *rtv_rsp;
  5066. uint8_t *pcmd;
  5067. struct lpfc_iocbq *elsiocb;
  5068. uint32_t cmdsize;
  5069. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  5070. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  5071. /* reject the unsolicited RPS request and done with it */
  5072. goto reject_out;
  5073. cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
  5074. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  5075. lpfc_max_els_tries, ndlp,
  5076. ndlp->nlp_DID, ELS_CMD_ACC);
  5077. if (!elsiocb)
  5078. return 1;
  5079. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  5080. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  5081. pcmd += sizeof(uint32_t); /* Skip past command */
  5082. /* use the command's xri in the response */
  5083. elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
  5084. elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
  5085. rtv_rsp = (struct RTV_RSP *)pcmd;
  5086. /* populate RTV payload */
  5087. rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
  5088. rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
  5089. bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
  5090. bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
  5091. rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
  5092. /* Xmit ELS RLS ACC response tag <ulpIoTag> */
  5093. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  5094. "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
  5095. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
  5096. "Data: x%x x%x x%x\n",
  5097. elsiocb->iotag, elsiocb->iocb.ulpContext,
  5098. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  5099. ndlp->nlp_rpi,
  5100. rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
  5101. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  5102. phba->fc_stat.elsXmitACC++;
  5103. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
  5104. lpfc_els_free_iocb(phba, elsiocb);
  5105. return 0;
  5106. reject_out:
  5107. /* issue rejection response */
  5108. stat.un.b.lsRjtRsvd0 = 0;
  5109. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  5110. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  5111. stat.un.b.vendorUnique = 0;
  5112. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  5113. return 0;
  5114. }
  5115. /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
  5116. * @vport: pointer to a host virtual N_Port data structure.
  5117. * @cmdiocb: pointer to lpfc command iocb data structure.
  5118. * @ndlp: pointer to a node-list data structure.
  5119. *
  5120. * This routine processes Read Port Status (RPS) IOCB received as an
  5121. * ELS unsolicited event. It first checks the remote port state. If the
  5122. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  5123. * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
  5124. * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
  5125. * for reading the HBA link statistics. It is for the callback function,
  5126. * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
  5127. * to actually sending out RPS Accept (ACC) response.
  5128. *
  5129. * Return codes
  5130. * 0 - Successfully processed rps iocb (currently always return 0)
  5131. **/
  5132. static int
  5133. lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5134. struct lpfc_nodelist *ndlp)
  5135. {
  5136. struct lpfc_hba *phba = vport->phba;
  5137. uint32_t *lp;
  5138. uint8_t flag;
  5139. LPFC_MBOXQ_t *mbox;
  5140. struct lpfc_dmabuf *pcmd;
  5141. RPS *rps;
  5142. struct ls_rjt stat;
  5143. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  5144. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  5145. /* reject the unsolicited RPS request and done with it */
  5146. goto reject_out;
  5147. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5148. lp = (uint32_t *) pcmd->virt;
  5149. flag = (be32_to_cpu(*lp++) & 0xf);
  5150. rps = (RPS *) lp;
  5151. if ((flag == 0) ||
  5152. ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
  5153. ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
  5154. sizeof(struct lpfc_name)) == 0))) {
  5155. printk("Fix me....\n");
  5156. dump_stack();
  5157. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
  5158. if (mbox) {
  5159. lpfc_read_lnk_stat(phba, mbox);
  5160. mbox->context1 = (void *)((unsigned long)
  5161. ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
  5162. cmdiocb->iocb.ulpContext)); /* rx_id */
  5163. mbox->context2 = lpfc_nlp_get(ndlp);
  5164. mbox->vport = vport;
  5165. mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
  5166. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  5167. != MBX_NOT_FINISHED)
  5168. /* Mbox completion will send ELS Response */
  5169. return 0;
  5170. /* Decrement reference count used for the failed mbox
  5171. * command.
  5172. */
  5173. lpfc_nlp_put(ndlp);
  5174. mempool_free(mbox, phba->mbox_mem_pool);
  5175. }
  5176. }
  5177. reject_out:
  5178. /* issue rejection response */
  5179. stat.un.b.lsRjtRsvd0 = 0;
  5180. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  5181. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  5182. stat.un.b.vendorUnique = 0;
  5183. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  5184. return 0;
  5185. }
  5186. /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
  5187. * @vport: pointer to a host virtual N_Port data structure.
  5188. * @ndlp: pointer to a node-list data structure.
  5189. * @did: DID of the target.
  5190. * @rrq: Pointer to the rrq struct.
  5191. *
  5192. * Build a ELS RRQ command and send it to the target. If the issue_iocb is
  5193. * Successful the the completion handler will clear the RRQ.
  5194. *
  5195. * Return codes
  5196. * 0 - Successfully sent rrq els iocb.
  5197. * 1 - Failed to send rrq els iocb.
  5198. **/
  5199. static int
  5200. lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  5201. uint32_t did, struct lpfc_node_rrq *rrq)
  5202. {
  5203. struct lpfc_hba *phba = vport->phba;
  5204. struct RRQ *els_rrq;
  5205. IOCB_t *icmd;
  5206. struct lpfc_iocbq *elsiocb;
  5207. uint8_t *pcmd;
  5208. uint16_t cmdsize;
  5209. int ret;
  5210. if (ndlp != rrq->ndlp)
  5211. ndlp = rrq->ndlp;
  5212. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  5213. return 1;
  5214. /* If ndlp is not NULL, we will bump the reference count on it */
  5215. cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
  5216. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
  5217. ELS_CMD_RRQ);
  5218. if (!elsiocb)
  5219. return 1;
  5220. icmd = &elsiocb->iocb;
  5221. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  5222. /* For RRQ request, remainder of payload is Exchange IDs */
  5223. *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
  5224. pcmd += sizeof(uint32_t);
  5225. els_rrq = (struct RRQ *) pcmd;
  5226. bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
  5227. bf_set(rrq_rxid, els_rrq, rrq->rxid);
  5228. bf_set(rrq_did, els_rrq, vport->fc_myDID);
  5229. els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
  5230. els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
  5231. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  5232. "Issue RRQ: did:x%x",
  5233. did, rrq->xritag, rrq->rxid);
  5234. elsiocb->context_un.rrq = rrq;
  5235. elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
  5236. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5237. if (ret == IOCB_ERROR) {
  5238. lpfc_els_free_iocb(phba, elsiocb);
  5239. return 1;
  5240. }
  5241. return 0;
  5242. }
  5243. /**
  5244. * lpfc_send_rrq - Sends ELS RRQ if needed.
  5245. * @phba: pointer to lpfc hba data structure.
  5246. * @rrq: pointer to the active rrq.
  5247. *
  5248. * This routine will call the lpfc_issue_els_rrq if the rrq is
  5249. * still active for the xri. If this function returns a failure then
  5250. * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
  5251. *
  5252. * Returns 0 Success.
  5253. * 1 Failure.
  5254. **/
  5255. int
  5256. lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
  5257. {
  5258. struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
  5259. rrq->nlp_DID);
  5260. if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
  5261. return lpfc_issue_els_rrq(rrq->vport, ndlp,
  5262. rrq->nlp_DID, rrq);
  5263. else
  5264. return 1;
  5265. }
  5266. /**
  5267. * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
  5268. * @vport: pointer to a host virtual N_Port data structure.
  5269. * @cmdsize: size of the ELS command.
  5270. * @oldiocb: pointer to the original lpfc command iocb data structure.
  5271. * @ndlp: pointer to a node-list data structure.
  5272. *
  5273. * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
  5274. * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
  5275. *
  5276. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  5277. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  5278. * will be stored into the context1 field of the IOCB for the completion
  5279. * callback function to the RPL Accept Response ELS command.
  5280. *
  5281. * Return code
  5282. * 0 - Successfully issued ACC RPL ELS command
  5283. * 1 - Failed to issue ACC RPL ELS command
  5284. **/
  5285. static int
  5286. lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
  5287. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  5288. {
  5289. struct lpfc_hba *phba = vport->phba;
  5290. IOCB_t *icmd, *oldcmd;
  5291. RPL_RSP rpl_rsp;
  5292. struct lpfc_iocbq *elsiocb;
  5293. uint8_t *pcmd;
  5294. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  5295. ndlp->nlp_DID, ELS_CMD_ACC);
  5296. if (!elsiocb)
  5297. return 1;
  5298. icmd = &elsiocb->iocb;
  5299. oldcmd = &oldiocb->iocb;
  5300. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  5301. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  5302. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  5303. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  5304. pcmd += sizeof(uint16_t);
  5305. *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
  5306. pcmd += sizeof(uint16_t);
  5307. /* Setup the RPL ACC payload */
  5308. rpl_rsp.listLen = be32_to_cpu(1);
  5309. rpl_rsp.index = 0;
  5310. rpl_rsp.port_num_blk.portNum = 0;
  5311. rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
  5312. memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
  5313. sizeof(struct lpfc_name));
  5314. memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
  5315. /* Xmit ELS RPL ACC response tag <ulpIoTag> */
  5316. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5317. "0120 Xmit ELS RPL ACC response tag x%x "
  5318. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  5319. "rpi x%x\n",
  5320. elsiocb->iotag, elsiocb->iocb.ulpContext,
  5321. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  5322. ndlp->nlp_rpi);
  5323. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  5324. phba->fc_stat.elsXmitACC++;
  5325. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  5326. IOCB_ERROR) {
  5327. lpfc_els_free_iocb(phba, elsiocb);
  5328. return 1;
  5329. }
  5330. return 0;
  5331. }
  5332. /**
  5333. * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
  5334. * @vport: pointer to a host virtual N_Port data structure.
  5335. * @cmdiocb: pointer to lpfc command iocb data structure.
  5336. * @ndlp: pointer to a node-list data structure.
  5337. *
  5338. * This routine processes Read Port List (RPL) IOCB received as an ELS
  5339. * unsolicited event. It first checks the remote port state. If the remote
  5340. * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
  5341. * invokes the lpfc_els_rsp_reject() routine to send reject response.
  5342. * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
  5343. * to accept the RPL.
  5344. *
  5345. * Return code
  5346. * 0 - Successfully processed rpl iocb (currently always return 0)
  5347. **/
  5348. static int
  5349. lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5350. struct lpfc_nodelist *ndlp)
  5351. {
  5352. struct lpfc_dmabuf *pcmd;
  5353. uint32_t *lp;
  5354. uint32_t maxsize;
  5355. uint16_t cmdsize;
  5356. RPL *rpl;
  5357. struct ls_rjt stat;
  5358. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  5359. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  5360. /* issue rejection response */
  5361. stat.un.b.lsRjtRsvd0 = 0;
  5362. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  5363. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  5364. stat.un.b.vendorUnique = 0;
  5365. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  5366. NULL);
  5367. /* rejected the unsolicited RPL request and done with it */
  5368. return 0;
  5369. }
  5370. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5371. lp = (uint32_t *) pcmd->virt;
  5372. rpl = (RPL *) (lp + 1);
  5373. maxsize = be32_to_cpu(rpl->maxsize);
  5374. /* We support only one port */
  5375. if ((rpl->index == 0) &&
  5376. ((maxsize == 0) ||
  5377. ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
  5378. cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
  5379. } else {
  5380. cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
  5381. }
  5382. lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
  5383. return 0;
  5384. }
  5385. /**
  5386. * lpfc_els_rcv_farp - Process an unsolicited farp request els command
  5387. * @vport: pointer to a virtual N_Port data structure.
  5388. * @cmdiocb: pointer to lpfc command iocb data structure.
  5389. * @ndlp: pointer to a node-list data structure.
  5390. *
  5391. * This routine processes Fibre Channel Address Resolution Protocol
  5392. * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
  5393. * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
  5394. * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
  5395. * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
  5396. * remote PortName is compared against the FC PortName stored in the @vport
  5397. * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
  5398. * compared against the FC NodeName stored in the @vport data structure.
  5399. * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
  5400. * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
  5401. * invoked to send out FARP Response to the remote node. Before sending the
  5402. * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
  5403. * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
  5404. * routine is invoked to log into the remote port first.
  5405. *
  5406. * Return code
  5407. * 0 - Either the FARP Match Mode not supported or successfully processed
  5408. **/
  5409. static int
  5410. lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5411. struct lpfc_nodelist *ndlp)
  5412. {
  5413. struct lpfc_dmabuf *pcmd;
  5414. uint32_t *lp;
  5415. IOCB_t *icmd;
  5416. FARP *fp;
  5417. uint32_t cmd, cnt, did;
  5418. icmd = &cmdiocb->iocb;
  5419. did = icmd->un.elsreq64.remoteID;
  5420. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5421. lp = (uint32_t *) pcmd->virt;
  5422. cmd = *lp++;
  5423. fp = (FARP *) lp;
  5424. /* FARP-REQ received from DID <did> */
  5425. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5426. "0601 FARP-REQ received from DID x%x\n", did);
  5427. /* We will only support match on WWPN or WWNN */
  5428. if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
  5429. return 0;
  5430. }
  5431. cnt = 0;
  5432. /* If this FARP command is searching for my portname */
  5433. if (fp->Mflags & FARP_MATCH_PORT) {
  5434. if (memcmp(&fp->RportName, &vport->fc_portname,
  5435. sizeof(struct lpfc_name)) == 0)
  5436. cnt = 1;
  5437. }
  5438. /* If this FARP command is searching for my nodename */
  5439. if (fp->Mflags & FARP_MATCH_NODE) {
  5440. if (memcmp(&fp->RnodeName, &vport->fc_nodename,
  5441. sizeof(struct lpfc_name)) == 0)
  5442. cnt = 1;
  5443. }
  5444. if (cnt) {
  5445. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  5446. (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
  5447. /* Log back into the node before sending the FARP. */
  5448. if (fp->Rflags & FARP_REQUEST_PLOGI) {
  5449. ndlp->nlp_prev_state = ndlp->nlp_state;
  5450. lpfc_nlp_set_state(vport, ndlp,
  5451. NLP_STE_PLOGI_ISSUE);
  5452. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  5453. }
  5454. /* Send a FARP response to that node */
  5455. if (fp->Rflags & FARP_REQUEST_FARPR)
  5456. lpfc_issue_els_farpr(vport, did, 0);
  5457. }
  5458. }
  5459. return 0;
  5460. }
  5461. /**
  5462. * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
  5463. * @vport: pointer to a host virtual N_Port data structure.
  5464. * @cmdiocb: pointer to lpfc command iocb data structure.
  5465. * @ndlp: pointer to a node-list data structure.
  5466. *
  5467. * This routine processes Fibre Channel Address Resolution Protocol
  5468. * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
  5469. * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
  5470. * the FARP response request.
  5471. *
  5472. * Return code
  5473. * 0 - Successfully processed FARPR IOCB (currently always return 0)
  5474. **/
  5475. static int
  5476. lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5477. struct lpfc_nodelist *ndlp)
  5478. {
  5479. struct lpfc_dmabuf *pcmd;
  5480. uint32_t *lp;
  5481. IOCB_t *icmd;
  5482. uint32_t cmd, did;
  5483. icmd = &cmdiocb->iocb;
  5484. did = icmd->un.elsreq64.remoteID;
  5485. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5486. lp = (uint32_t *) pcmd->virt;
  5487. cmd = *lp++;
  5488. /* FARP-RSP received from DID <did> */
  5489. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5490. "0600 FARP-RSP received from DID x%x\n", did);
  5491. /* ACCEPT the Farp resp request */
  5492. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  5493. return 0;
  5494. }
  5495. /**
  5496. * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
  5497. * @vport: pointer to a host virtual N_Port data structure.
  5498. * @cmdiocb: pointer to lpfc command iocb data structure.
  5499. * @fan_ndlp: pointer to a node-list data structure.
  5500. *
  5501. * This routine processes a Fabric Address Notification (FAN) IOCB
  5502. * command received as an ELS unsolicited event. The FAN ELS command will
  5503. * only be processed on a physical port (i.e., the @vport represents the
  5504. * physical port). The fabric NodeName and PortName from the FAN IOCB are
  5505. * compared against those in the phba data structure. If any of those is
  5506. * different, the lpfc_initial_flogi() routine is invoked to initialize
  5507. * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
  5508. * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
  5509. * is invoked to register login to the fabric.
  5510. *
  5511. * Return code
  5512. * 0 - Successfully processed fan iocb (currently always return 0).
  5513. **/
  5514. static int
  5515. lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5516. struct lpfc_nodelist *fan_ndlp)
  5517. {
  5518. struct lpfc_hba *phba = vport->phba;
  5519. uint32_t *lp;
  5520. FAN *fp;
  5521. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
  5522. lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
  5523. fp = (FAN *) ++lp;
  5524. /* FAN received; Fan does not have a reply sequence */
  5525. if ((vport == phba->pport) &&
  5526. (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
  5527. if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
  5528. sizeof(struct lpfc_name))) ||
  5529. (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
  5530. sizeof(struct lpfc_name)))) {
  5531. /* This port has switched fabrics. FLOGI is required */
  5532. lpfc_issue_init_vfi(vport);
  5533. } else {
  5534. /* FAN verified - skip FLOGI */
  5535. vport->fc_myDID = vport->fc_prevDID;
  5536. if (phba->sli_rev < LPFC_SLI_REV4)
  5537. lpfc_issue_fabric_reglogin(vport);
  5538. else {
  5539. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5540. "3138 Need register VFI: (x%x/%x)\n",
  5541. vport->fc_prevDID, vport->fc_myDID);
  5542. lpfc_issue_reg_vfi(vport);
  5543. }
  5544. }
  5545. }
  5546. return 0;
  5547. }
  5548. /**
  5549. * lpfc_els_timeout - Handler funciton to the els timer
  5550. * @ptr: holder for the timer function associated data.
  5551. *
  5552. * This routine is invoked by the ELS timer after timeout. It posts the ELS
  5553. * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
  5554. * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
  5555. * up the worker thread. It is for the worker thread to invoke the routine
  5556. * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
  5557. **/
  5558. void
  5559. lpfc_els_timeout(unsigned long ptr)
  5560. {
  5561. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  5562. struct lpfc_hba *phba = vport->phba;
  5563. uint32_t tmo_posted;
  5564. unsigned long iflag;
  5565. spin_lock_irqsave(&vport->work_port_lock, iflag);
  5566. tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
  5567. if (!tmo_posted)
  5568. vport->work_port_events |= WORKER_ELS_TMO;
  5569. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  5570. if (!tmo_posted)
  5571. lpfc_worker_wake_up(phba);
  5572. return;
  5573. }
  5574. /**
  5575. * lpfc_els_timeout_handler - Process an els timeout event
  5576. * @vport: pointer to a virtual N_Port data structure.
  5577. *
  5578. * This routine is the actual handler function that processes an ELS timeout
  5579. * event. It walks the ELS ring to get and abort all the IOCBs (except the
  5580. * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
  5581. * invoking the lpfc_sli_issue_abort_iotag() routine.
  5582. **/
  5583. void
  5584. lpfc_els_timeout_handler(struct lpfc_vport *vport)
  5585. {
  5586. struct lpfc_hba *phba = vport->phba;
  5587. struct lpfc_sli_ring *pring;
  5588. struct lpfc_iocbq *tmp_iocb, *piocb;
  5589. IOCB_t *cmd = NULL;
  5590. struct lpfc_dmabuf *pcmd;
  5591. uint32_t els_command = 0;
  5592. uint32_t timeout;
  5593. uint32_t remote_ID = 0xffffffff;
  5594. LIST_HEAD(txcmplq_completions);
  5595. LIST_HEAD(abort_list);
  5596. timeout = (uint32_t)(phba->fc_ratov << 1);
  5597. pring = &phba->sli.ring[LPFC_ELS_RING];
  5598. spin_lock_irq(&phba->hbalock);
  5599. list_splice_init(&pring->txcmplq, &txcmplq_completions);
  5600. spin_unlock_irq(&phba->hbalock);
  5601. list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
  5602. cmd = &piocb->iocb;
  5603. if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
  5604. piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5605. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5606. continue;
  5607. if (piocb->vport != vport)
  5608. continue;
  5609. pcmd = (struct lpfc_dmabuf *) piocb->context2;
  5610. if (pcmd)
  5611. els_command = *(uint32_t *) (pcmd->virt);
  5612. if (els_command == ELS_CMD_FARP ||
  5613. els_command == ELS_CMD_FARPR ||
  5614. els_command == ELS_CMD_FDISC)
  5615. continue;
  5616. if (piocb->drvrTimeout > 0) {
  5617. if (piocb->drvrTimeout >= timeout)
  5618. piocb->drvrTimeout -= timeout;
  5619. else
  5620. piocb->drvrTimeout = 0;
  5621. continue;
  5622. }
  5623. remote_ID = 0xffffffff;
  5624. if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
  5625. remote_ID = cmd->un.elsreq64.remoteID;
  5626. else {
  5627. struct lpfc_nodelist *ndlp;
  5628. ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
  5629. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  5630. remote_ID = ndlp->nlp_DID;
  5631. }
  5632. list_add_tail(&piocb->dlist, &abort_list);
  5633. }
  5634. spin_lock_irq(&phba->hbalock);
  5635. list_splice(&txcmplq_completions, &pring->txcmplq);
  5636. spin_unlock_irq(&phba->hbalock);
  5637. list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
  5638. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  5639. "0127 ELS timeout Data: x%x x%x x%x "
  5640. "x%x\n", els_command,
  5641. remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
  5642. spin_lock_irq(&phba->hbalock);
  5643. list_del_init(&piocb->dlist);
  5644. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  5645. spin_unlock_irq(&phba->hbalock);
  5646. }
  5647. if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
  5648. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  5649. }
  5650. /**
  5651. * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
  5652. * @vport: pointer to a host virtual N_Port data structure.
  5653. *
  5654. * This routine is used to clean up all the outstanding ELS commands on a
  5655. * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
  5656. * routine. After that, it walks the ELS transmit queue to remove all the
  5657. * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
  5658. * the IOCBs with a non-NULL completion callback function, the callback
  5659. * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
  5660. * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
  5661. * callback function, the IOCB will simply be released. Finally, it walks
  5662. * the ELS transmit completion queue to issue an abort IOCB to any transmit
  5663. * completion queue IOCB that is associated with the @vport and is not
  5664. * an IOCB from libdfc (i.e., the management plane IOCBs that are not
  5665. * part of the discovery state machine) out to HBA by invoking the
  5666. * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
  5667. * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
  5668. * the IOCBs are aborted when this function returns.
  5669. **/
  5670. void
  5671. lpfc_els_flush_cmd(struct lpfc_vport *vport)
  5672. {
  5673. LIST_HEAD(completions);
  5674. struct lpfc_hba *phba = vport->phba;
  5675. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  5676. struct lpfc_iocbq *tmp_iocb, *piocb;
  5677. IOCB_t *cmd = NULL;
  5678. lpfc_fabric_abort_vport(vport);
  5679. spin_lock_irq(&phba->hbalock);
  5680. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  5681. cmd = &piocb->iocb;
  5682. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  5683. continue;
  5684. }
  5685. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  5686. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  5687. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  5688. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  5689. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  5690. continue;
  5691. if (piocb->vport != vport)
  5692. continue;
  5693. list_move_tail(&piocb->list, &completions);
  5694. pring->txq_cnt--;
  5695. }
  5696. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  5697. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  5698. continue;
  5699. }
  5700. if (piocb->vport != vport)
  5701. continue;
  5702. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  5703. }
  5704. spin_unlock_irq(&phba->hbalock);
  5705. /* Cancell all the IOCBs from the completions list */
  5706. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  5707. IOERR_SLI_ABORTED);
  5708. return;
  5709. }
  5710. /**
  5711. * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
  5712. * @phba: pointer to lpfc hba data structure.
  5713. *
  5714. * This routine is used to clean up all the outstanding ELS commands on a
  5715. * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
  5716. * routine. After that, it walks the ELS transmit queue to remove all the
  5717. * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
  5718. * the IOCBs with the completion callback function associated, the callback
  5719. * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
  5720. * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
  5721. * callback function associated, the IOCB will simply be released. Finally,
  5722. * it walks the ELS transmit completion queue to issue an abort IOCB to any
  5723. * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
  5724. * management plane IOCBs that are not part of the discovery state machine)
  5725. * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
  5726. **/
  5727. void
  5728. lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
  5729. {
  5730. LIST_HEAD(completions);
  5731. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  5732. struct lpfc_iocbq *tmp_iocb, *piocb;
  5733. IOCB_t *cmd = NULL;
  5734. lpfc_fabric_abort_hba(phba);
  5735. spin_lock_irq(&phba->hbalock);
  5736. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  5737. cmd = &piocb->iocb;
  5738. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  5739. continue;
  5740. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  5741. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  5742. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  5743. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  5744. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  5745. continue;
  5746. list_move_tail(&piocb->list, &completions);
  5747. pring->txq_cnt--;
  5748. }
  5749. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  5750. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  5751. continue;
  5752. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  5753. }
  5754. spin_unlock_irq(&phba->hbalock);
  5755. /* Cancel all the IOCBs from the completions list */
  5756. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  5757. IOERR_SLI_ABORTED);
  5758. return;
  5759. }
  5760. /**
  5761. * lpfc_send_els_failure_event - Posts an ELS command failure event
  5762. * @phba: Pointer to hba context object.
  5763. * @cmdiocbp: Pointer to command iocb which reported error.
  5764. * @rspiocbp: Pointer to response iocb which reported error.
  5765. *
  5766. * This function sends an event when there is an ELS command
  5767. * failure.
  5768. **/
  5769. void
  5770. lpfc_send_els_failure_event(struct lpfc_hba *phba,
  5771. struct lpfc_iocbq *cmdiocbp,
  5772. struct lpfc_iocbq *rspiocbp)
  5773. {
  5774. struct lpfc_vport *vport = cmdiocbp->vport;
  5775. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5776. struct lpfc_lsrjt_event lsrjt_event;
  5777. struct lpfc_fabric_event_header fabric_event;
  5778. struct ls_rjt stat;
  5779. struct lpfc_nodelist *ndlp;
  5780. uint32_t *pcmd;
  5781. ndlp = cmdiocbp->context1;
  5782. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  5783. return;
  5784. if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
  5785. lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
  5786. lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
  5787. memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
  5788. sizeof(struct lpfc_name));
  5789. memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
  5790. sizeof(struct lpfc_name));
  5791. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  5792. cmdiocbp->context2)->virt);
  5793. lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
  5794. stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
  5795. lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
  5796. lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
  5797. fc_host_post_vendor_event(shost,
  5798. fc_get_event_number(),
  5799. sizeof(lsrjt_event),
  5800. (char *)&lsrjt_event,
  5801. LPFC_NL_VENDOR_ID);
  5802. return;
  5803. }
  5804. if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
  5805. (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
  5806. fabric_event.event_type = FC_REG_FABRIC_EVENT;
  5807. if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
  5808. fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
  5809. else
  5810. fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
  5811. memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
  5812. sizeof(struct lpfc_name));
  5813. memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
  5814. sizeof(struct lpfc_name));
  5815. fc_host_post_vendor_event(shost,
  5816. fc_get_event_number(),
  5817. sizeof(fabric_event),
  5818. (char *)&fabric_event,
  5819. LPFC_NL_VENDOR_ID);
  5820. return;
  5821. }
  5822. }
  5823. /**
  5824. * lpfc_send_els_event - Posts unsolicited els event
  5825. * @vport: Pointer to vport object.
  5826. * @ndlp: Pointer FC node object.
  5827. * @cmd: ELS command code.
  5828. *
  5829. * This function posts an event when there is an incoming
  5830. * unsolicited ELS command.
  5831. **/
  5832. static void
  5833. lpfc_send_els_event(struct lpfc_vport *vport,
  5834. struct lpfc_nodelist *ndlp,
  5835. uint32_t *payload)
  5836. {
  5837. struct lpfc_els_event_header *els_data = NULL;
  5838. struct lpfc_logo_event *logo_data = NULL;
  5839. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5840. if (*payload == ELS_CMD_LOGO) {
  5841. logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
  5842. if (!logo_data) {
  5843. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  5844. "0148 Failed to allocate memory "
  5845. "for LOGO event\n");
  5846. return;
  5847. }
  5848. els_data = &logo_data->header;
  5849. } else {
  5850. els_data = kmalloc(sizeof(struct lpfc_els_event_header),
  5851. GFP_KERNEL);
  5852. if (!els_data) {
  5853. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  5854. "0149 Failed to allocate memory "
  5855. "for ELS event\n");
  5856. return;
  5857. }
  5858. }
  5859. els_data->event_type = FC_REG_ELS_EVENT;
  5860. switch (*payload) {
  5861. case ELS_CMD_PLOGI:
  5862. els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
  5863. break;
  5864. case ELS_CMD_PRLO:
  5865. els_data->subcategory = LPFC_EVENT_PRLO_RCV;
  5866. break;
  5867. case ELS_CMD_ADISC:
  5868. els_data->subcategory = LPFC_EVENT_ADISC_RCV;
  5869. break;
  5870. case ELS_CMD_LOGO:
  5871. els_data->subcategory = LPFC_EVENT_LOGO_RCV;
  5872. /* Copy the WWPN in the LOGO payload */
  5873. memcpy(logo_data->logo_wwpn, &payload[2],
  5874. sizeof(struct lpfc_name));
  5875. break;
  5876. default:
  5877. kfree(els_data);
  5878. return;
  5879. }
  5880. memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
  5881. memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
  5882. if (*payload == ELS_CMD_LOGO) {
  5883. fc_host_post_vendor_event(shost,
  5884. fc_get_event_number(),
  5885. sizeof(struct lpfc_logo_event),
  5886. (char *)logo_data,
  5887. LPFC_NL_VENDOR_ID);
  5888. kfree(logo_data);
  5889. } else {
  5890. fc_host_post_vendor_event(shost,
  5891. fc_get_event_number(),
  5892. sizeof(struct lpfc_els_event_header),
  5893. (char *)els_data,
  5894. LPFC_NL_VENDOR_ID);
  5895. kfree(els_data);
  5896. }
  5897. return;
  5898. }
  5899. /**
  5900. * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
  5901. * @phba: pointer to lpfc hba data structure.
  5902. * @pring: pointer to a SLI ring.
  5903. * @vport: pointer to a host virtual N_Port data structure.
  5904. * @elsiocb: pointer to lpfc els command iocb data structure.
  5905. *
  5906. * This routine is used for processing the IOCB associated with a unsolicited
  5907. * event. It first determines whether there is an existing ndlp that matches
  5908. * the DID from the unsolicited IOCB. If not, it will create a new one with
  5909. * the DID from the unsolicited IOCB. The ELS command from the unsolicited
  5910. * IOCB is then used to invoke the proper routine and to set up proper state
  5911. * of the discovery state machine.
  5912. **/
  5913. static void
  5914. lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5915. struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
  5916. {
  5917. struct Scsi_Host *shost;
  5918. struct lpfc_nodelist *ndlp;
  5919. struct ls_rjt stat;
  5920. uint32_t *payload;
  5921. uint32_t cmd, did, newnode, rjt_err = 0;
  5922. IOCB_t *icmd = &elsiocb->iocb;
  5923. if (!vport || !(elsiocb->context2))
  5924. goto dropit;
  5925. newnode = 0;
  5926. payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
  5927. cmd = *payload;
  5928. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
  5929. lpfc_post_buffer(phba, pring, 1);
  5930. did = icmd->un.rcvels.remoteID;
  5931. if (icmd->ulpStatus) {
  5932. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  5933. "RCV Unsol ELS: status:x%x/x%x did:x%x",
  5934. icmd->ulpStatus, icmd->un.ulpWord[4], did);
  5935. goto dropit;
  5936. }
  5937. /* Check to see if link went down during discovery */
  5938. if (lpfc_els_chk_latt(vport))
  5939. goto dropit;
  5940. /* Ignore traffic received during vport shutdown. */
  5941. if (vport->load_flag & FC_UNLOADING)
  5942. goto dropit;
  5943. /* If NPort discovery is delayed drop incoming ELS */
  5944. if ((vport->fc_flag & FC_DISC_DELAYED) &&
  5945. (cmd != ELS_CMD_PLOGI))
  5946. goto dropit;
  5947. ndlp = lpfc_findnode_did(vport, did);
  5948. if (!ndlp) {
  5949. /* Cannot find existing Fabric ndlp, so allocate a new one */
  5950. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  5951. if (!ndlp)
  5952. goto dropit;
  5953. lpfc_nlp_init(vport, ndlp, did);
  5954. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  5955. newnode = 1;
  5956. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  5957. ndlp->nlp_type |= NLP_FABRIC;
  5958. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  5959. ndlp = lpfc_enable_node(vport, ndlp,
  5960. NLP_STE_UNUSED_NODE);
  5961. if (!ndlp)
  5962. goto dropit;
  5963. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  5964. newnode = 1;
  5965. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  5966. ndlp->nlp_type |= NLP_FABRIC;
  5967. } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  5968. /* This is similar to the new node path */
  5969. ndlp = lpfc_nlp_get(ndlp);
  5970. if (!ndlp)
  5971. goto dropit;
  5972. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  5973. newnode = 1;
  5974. }
  5975. phba->fc_stat.elsRcvFrame++;
  5976. elsiocb->context1 = lpfc_nlp_get(ndlp);
  5977. elsiocb->vport = vport;
  5978. if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
  5979. cmd &= ELS_CMD_MASK;
  5980. }
  5981. /* ELS command <elsCmd> received from NPORT <did> */
  5982. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5983. "0112 ELS command x%x received from NPORT x%x "
  5984. "Data: x%x\n", cmd, did, vport->port_state);
  5985. switch (cmd) {
  5986. case ELS_CMD_PLOGI:
  5987. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  5988. "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
  5989. did, vport->port_state, ndlp->nlp_flag);
  5990. phba->fc_stat.elsRcvPLOGI++;
  5991. ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
  5992. lpfc_send_els_event(vport, ndlp, payload);
  5993. /* If Nport discovery is delayed, reject PLOGIs */
  5994. if (vport->fc_flag & FC_DISC_DELAYED) {
  5995. rjt_err = LSRJT_UNABLE_TPC;
  5996. break;
  5997. }
  5998. if (vport->port_state < LPFC_DISC_AUTH) {
  5999. if (!(phba->pport->fc_flag & FC_PT2PT) ||
  6000. (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
  6001. rjt_err = LSRJT_UNABLE_TPC;
  6002. break;
  6003. }
  6004. /* We get here, and drop thru, if we are PT2PT with
  6005. * another NPort and the other side has initiated
  6006. * the PLOGI before responding to our FLOGI.
  6007. */
  6008. }
  6009. shost = lpfc_shost_from_vport(vport);
  6010. spin_lock_irq(shost->host_lock);
  6011. ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
  6012. spin_unlock_irq(shost->host_lock);
  6013. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  6014. NLP_EVT_RCV_PLOGI);
  6015. break;
  6016. case ELS_CMD_FLOGI:
  6017. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6018. "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
  6019. did, vport->port_state, ndlp->nlp_flag);
  6020. phba->fc_stat.elsRcvFLOGI++;
  6021. lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
  6022. if (newnode)
  6023. lpfc_nlp_put(ndlp);
  6024. break;
  6025. case ELS_CMD_LOGO:
  6026. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6027. "RCV LOGO: did:x%x/ste:x%x flg:x%x",
  6028. did, vport->port_state, ndlp->nlp_flag);
  6029. phba->fc_stat.elsRcvLOGO++;
  6030. lpfc_send_els_event(vport, ndlp, payload);
  6031. if (vport->port_state < LPFC_DISC_AUTH) {
  6032. rjt_err = LSRJT_UNABLE_TPC;
  6033. break;
  6034. }
  6035. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
  6036. break;
  6037. case ELS_CMD_PRLO:
  6038. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6039. "RCV PRLO: did:x%x/ste:x%x flg:x%x",
  6040. did, vport->port_state, ndlp->nlp_flag);
  6041. phba->fc_stat.elsRcvPRLO++;
  6042. lpfc_send_els_event(vport, ndlp, payload);
  6043. if (vport->port_state < LPFC_DISC_AUTH) {
  6044. rjt_err = LSRJT_UNABLE_TPC;
  6045. break;
  6046. }
  6047. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
  6048. break;
  6049. case ELS_CMD_RSCN:
  6050. phba->fc_stat.elsRcvRSCN++;
  6051. lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
  6052. if (newnode)
  6053. lpfc_nlp_put(ndlp);
  6054. break;
  6055. case ELS_CMD_ADISC:
  6056. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6057. "RCV ADISC: did:x%x/ste:x%x flg:x%x",
  6058. did, vport->port_state, ndlp->nlp_flag);
  6059. lpfc_send_els_event(vport, ndlp, payload);
  6060. phba->fc_stat.elsRcvADISC++;
  6061. if (vport->port_state < LPFC_DISC_AUTH) {
  6062. rjt_err = LSRJT_UNABLE_TPC;
  6063. break;
  6064. }
  6065. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  6066. NLP_EVT_RCV_ADISC);
  6067. break;
  6068. case ELS_CMD_PDISC:
  6069. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6070. "RCV PDISC: did:x%x/ste:x%x flg:x%x",
  6071. did, vport->port_state, ndlp->nlp_flag);
  6072. phba->fc_stat.elsRcvPDISC++;
  6073. if (vport->port_state < LPFC_DISC_AUTH) {
  6074. rjt_err = LSRJT_UNABLE_TPC;
  6075. break;
  6076. }
  6077. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  6078. NLP_EVT_RCV_PDISC);
  6079. break;
  6080. case ELS_CMD_FARPR:
  6081. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6082. "RCV FARPR: did:x%x/ste:x%x flg:x%x",
  6083. did, vport->port_state, ndlp->nlp_flag);
  6084. phba->fc_stat.elsRcvFARPR++;
  6085. lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
  6086. break;
  6087. case ELS_CMD_FARP:
  6088. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6089. "RCV FARP: did:x%x/ste:x%x flg:x%x",
  6090. did, vport->port_state, ndlp->nlp_flag);
  6091. phba->fc_stat.elsRcvFARP++;
  6092. lpfc_els_rcv_farp(vport, elsiocb, ndlp);
  6093. break;
  6094. case ELS_CMD_FAN:
  6095. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6096. "RCV FAN: did:x%x/ste:x%x flg:x%x",
  6097. did, vport->port_state, ndlp->nlp_flag);
  6098. phba->fc_stat.elsRcvFAN++;
  6099. lpfc_els_rcv_fan(vport, elsiocb, ndlp);
  6100. break;
  6101. case ELS_CMD_PRLI:
  6102. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6103. "RCV PRLI: did:x%x/ste:x%x flg:x%x",
  6104. did, vport->port_state, ndlp->nlp_flag);
  6105. phba->fc_stat.elsRcvPRLI++;
  6106. if (vport->port_state < LPFC_DISC_AUTH) {
  6107. rjt_err = LSRJT_UNABLE_TPC;
  6108. break;
  6109. }
  6110. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
  6111. break;
  6112. case ELS_CMD_LIRR:
  6113. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6114. "RCV LIRR: did:x%x/ste:x%x flg:x%x",
  6115. did, vport->port_state, ndlp->nlp_flag);
  6116. phba->fc_stat.elsRcvLIRR++;
  6117. lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
  6118. if (newnode)
  6119. lpfc_nlp_put(ndlp);
  6120. break;
  6121. case ELS_CMD_RLS:
  6122. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6123. "RCV RLS: did:x%x/ste:x%x flg:x%x",
  6124. did, vport->port_state, ndlp->nlp_flag);
  6125. phba->fc_stat.elsRcvRLS++;
  6126. lpfc_els_rcv_rls(vport, elsiocb, ndlp);
  6127. if (newnode)
  6128. lpfc_nlp_put(ndlp);
  6129. break;
  6130. case ELS_CMD_RPS:
  6131. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6132. "RCV RPS: did:x%x/ste:x%x flg:x%x",
  6133. did, vport->port_state, ndlp->nlp_flag);
  6134. phba->fc_stat.elsRcvRPS++;
  6135. lpfc_els_rcv_rps(vport, elsiocb, ndlp);
  6136. if (newnode)
  6137. lpfc_nlp_put(ndlp);
  6138. break;
  6139. case ELS_CMD_RPL:
  6140. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6141. "RCV RPL: did:x%x/ste:x%x flg:x%x",
  6142. did, vport->port_state, ndlp->nlp_flag);
  6143. phba->fc_stat.elsRcvRPL++;
  6144. lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
  6145. if (newnode)
  6146. lpfc_nlp_put(ndlp);
  6147. break;
  6148. case ELS_CMD_RNID:
  6149. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6150. "RCV RNID: did:x%x/ste:x%x flg:x%x",
  6151. did, vport->port_state, ndlp->nlp_flag);
  6152. phba->fc_stat.elsRcvRNID++;
  6153. lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
  6154. if (newnode)
  6155. lpfc_nlp_put(ndlp);
  6156. break;
  6157. case ELS_CMD_RTV:
  6158. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6159. "RCV RTV: did:x%x/ste:x%x flg:x%x",
  6160. did, vport->port_state, ndlp->nlp_flag);
  6161. phba->fc_stat.elsRcvRTV++;
  6162. lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
  6163. if (newnode)
  6164. lpfc_nlp_put(ndlp);
  6165. break;
  6166. case ELS_CMD_RRQ:
  6167. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6168. "RCV RRQ: did:x%x/ste:x%x flg:x%x",
  6169. did, vport->port_state, ndlp->nlp_flag);
  6170. phba->fc_stat.elsRcvRRQ++;
  6171. lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
  6172. if (newnode)
  6173. lpfc_nlp_put(ndlp);
  6174. break;
  6175. case ELS_CMD_ECHO:
  6176. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6177. "RCV ECHO: did:x%x/ste:x%x flg:x%x",
  6178. did, vport->port_state, ndlp->nlp_flag);
  6179. phba->fc_stat.elsRcvECHO++;
  6180. lpfc_els_rcv_echo(vport, elsiocb, ndlp);
  6181. if (newnode)
  6182. lpfc_nlp_put(ndlp);
  6183. break;
  6184. default:
  6185. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6186. "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
  6187. cmd, did, vport->port_state);
  6188. /* Unsupported ELS command, reject */
  6189. rjt_err = LSRJT_CMD_UNSUPPORTED;
  6190. /* Unknown ELS command <elsCmd> received from NPORT <did> */
  6191. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6192. "0115 Unknown ELS command x%x "
  6193. "received from NPORT x%x\n", cmd, did);
  6194. if (newnode)
  6195. lpfc_nlp_put(ndlp);
  6196. break;
  6197. }
  6198. /* check if need to LS_RJT received ELS cmd */
  6199. if (rjt_err) {
  6200. memset(&stat, 0, sizeof(stat));
  6201. stat.un.b.lsRjtRsnCode = rjt_err;
  6202. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  6203. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
  6204. NULL);
  6205. }
  6206. lpfc_nlp_put(elsiocb->context1);
  6207. elsiocb->context1 = NULL;
  6208. return;
  6209. dropit:
  6210. if (vport && !(vport->load_flag & FC_UNLOADING))
  6211. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6212. "0111 Dropping received ELS cmd "
  6213. "Data: x%x x%x x%x\n",
  6214. icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
  6215. phba->fc_stat.elsRcvDrop++;
  6216. }
  6217. /**
  6218. * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
  6219. * @phba: pointer to lpfc hba data structure.
  6220. * @pring: pointer to a SLI ring.
  6221. * @elsiocb: pointer to lpfc els iocb data structure.
  6222. *
  6223. * This routine is used to process an unsolicited event received from a SLI
  6224. * (Service Level Interface) ring. The actual processing of the data buffer
  6225. * associated with the unsolicited event is done by invoking the routine
  6226. * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
  6227. * SLI ring on which the unsolicited event was received.
  6228. **/
  6229. void
  6230. lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6231. struct lpfc_iocbq *elsiocb)
  6232. {
  6233. struct lpfc_vport *vport = phba->pport;
  6234. IOCB_t *icmd = &elsiocb->iocb;
  6235. dma_addr_t paddr;
  6236. struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
  6237. struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
  6238. elsiocb->context1 = NULL;
  6239. elsiocb->context2 = NULL;
  6240. elsiocb->context3 = NULL;
  6241. if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
  6242. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  6243. } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
  6244. (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  6245. IOERR_RCV_BUFFER_WAITING) {
  6246. phba->fc_stat.NoRcvBuf++;
  6247. /* Not enough posted buffers; Try posting more buffers */
  6248. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  6249. lpfc_post_buffer(phba, pring, 0);
  6250. return;
  6251. }
  6252. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  6253. (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
  6254. icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  6255. if (icmd->unsli3.rcvsli3.vpi == 0xffff)
  6256. vport = phba->pport;
  6257. else
  6258. vport = lpfc_find_vport_by_vpid(phba,
  6259. icmd->unsli3.rcvsli3.vpi);
  6260. }
  6261. /* If there are no BDEs associated
  6262. * with this IOCB, there is nothing to do.
  6263. */
  6264. if (icmd->ulpBdeCount == 0)
  6265. return;
  6266. /* type of ELS cmd is first 32bit word
  6267. * in packet
  6268. */
  6269. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  6270. elsiocb->context2 = bdeBuf1;
  6271. } else {
  6272. paddr = getPaddr(icmd->un.cont64[0].addrHigh,
  6273. icmd->un.cont64[0].addrLow);
  6274. elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
  6275. paddr);
  6276. }
  6277. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  6278. /*
  6279. * The different unsolicited event handlers would tell us
  6280. * if they are done with "mp" by setting context2 to NULL.
  6281. */
  6282. if (elsiocb->context2) {
  6283. lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
  6284. elsiocb->context2 = NULL;
  6285. }
  6286. /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
  6287. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
  6288. icmd->ulpBdeCount == 2) {
  6289. elsiocb->context2 = bdeBuf2;
  6290. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  6291. /* free mp if we are done with it */
  6292. if (elsiocb->context2) {
  6293. lpfc_in_buf_free(phba, elsiocb->context2);
  6294. elsiocb->context2 = NULL;
  6295. }
  6296. }
  6297. }
  6298. /**
  6299. * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
  6300. * @phba: pointer to lpfc hba data structure.
  6301. * @vport: pointer to a virtual N_Port data structure.
  6302. *
  6303. * This routine issues a Port Login (PLOGI) to the Name Server with
  6304. * State Change Request (SCR) for a @vport. This routine will create an
  6305. * ndlp for the Name Server associated to the @vport if such node does
  6306. * not already exist. The PLOGI to Name Server is issued by invoking the
  6307. * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
  6308. * (FDMI) is configured to the @vport, a FDMI node will be created and
  6309. * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
  6310. **/
  6311. void
  6312. lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  6313. {
  6314. struct lpfc_nodelist *ndlp, *ndlp_fdmi;
  6315. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6316. /*
  6317. * If lpfc_delay_discovery parameter is set and the clean address
  6318. * bit is cleared and fc fabric parameters chenged, delay FC NPort
  6319. * discovery.
  6320. */
  6321. spin_lock_irq(shost->host_lock);
  6322. if (vport->fc_flag & FC_DISC_DELAYED) {
  6323. spin_unlock_irq(shost->host_lock);
  6324. mod_timer(&vport->delayed_disc_tmo,
  6325. jiffies + HZ * phba->fc_ratov);
  6326. return;
  6327. }
  6328. spin_unlock_irq(shost->host_lock);
  6329. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  6330. if (!ndlp) {
  6331. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  6332. if (!ndlp) {
  6333. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  6334. lpfc_disc_start(vport);
  6335. return;
  6336. }
  6337. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6338. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6339. "0251 NameServer login: no memory\n");
  6340. return;
  6341. }
  6342. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  6343. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  6344. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  6345. if (!ndlp) {
  6346. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  6347. lpfc_disc_start(vport);
  6348. return;
  6349. }
  6350. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6351. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6352. "0348 NameServer login: node freed\n");
  6353. return;
  6354. }
  6355. }
  6356. ndlp->nlp_type |= NLP_FABRIC;
  6357. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  6358. if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
  6359. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6360. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6361. "0252 Cannot issue NameServer login\n");
  6362. return;
  6363. }
  6364. if (vport->cfg_fdmi_on) {
  6365. /* If this is the first time, allocate an ndlp and initialize
  6366. * it. Otherwise, make sure the node is enabled and then do the
  6367. * login.
  6368. */
  6369. ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
  6370. if (!ndlp_fdmi) {
  6371. ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
  6372. GFP_KERNEL);
  6373. if (ndlp_fdmi) {
  6374. lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
  6375. ndlp_fdmi->nlp_type |= NLP_FABRIC;
  6376. } else
  6377. return;
  6378. }
  6379. if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
  6380. ndlp_fdmi = lpfc_enable_node(vport,
  6381. ndlp_fdmi,
  6382. NLP_STE_NPR_NODE);
  6383. if (ndlp_fdmi) {
  6384. lpfc_nlp_set_state(vport, ndlp_fdmi,
  6385. NLP_STE_PLOGI_ISSUE);
  6386. lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
  6387. }
  6388. }
  6389. }
  6390. /**
  6391. * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
  6392. * @phba: pointer to lpfc hba data structure.
  6393. * @pmb: pointer to the driver internal queue element for mailbox command.
  6394. *
  6395. * This routine is the completion callback function to register new vport
  6396. * mailbox command. If the new vport mailbox command completes successfully,
  6397. * the fabric registration login shall be performed on physical port (the
  6398. * new vport created is actually a physical port, with VPI 0) or the port
  6399. * login to Name Server for State Change Request (SCR) will be performed
  6400. * on virtual port (real virtual port, with VPI greater than 0).
  6401. **/
  6402. static void
  6403. lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  6404. {
  6405. struct lpfc_vport *vport = pmb->vport;
  6406. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6407. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  6408. MAILBOX_t *mb = &pmb->u.mb;
  6409. int rc;
  6410. spin_lock_irq(shost->host_lock);
  6411. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  6412. spin_unlock_irq(shost->host_lock);
  6413. if (mb->mbxStatus) {
  6414. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  6415. "0915 Register VPI failed : Status: x%x"
  6416. " upd bit: x%x \n", mb->mbxStatus,
  6417. mb->un.varRegVpi.upd);
  6418. if (phba->sli_rev == LPFC_SLI_REV4 &&
  6419. mb->un.varRegVpi.upd)
  6420. goto mbox_err_exit ;
  6421. switch (mb->mbxStatus) {
  6422. case 0x11: /* unsupported feature */
  6423. case 0x9603: /* max_vpi exceeded */
  6424. case 0x9602: /* Link event since CLEAR_LA */
  6425. /* giving up on vport registration */
  6426. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6427. spin_lock_irq(shost->host_lock);
  6428. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  6429. spin_unlock_irq(shost->host_lock);
  6430. lpfc_can_disctmo(vport);
  6431. break;
  6432. /* If reg_vpi fail with invalid VPI status, re-init VPI */
  6433. case 0x20:
  6434. spin_lock_irq(shost->host_lock);
  6435. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  6436. spin_unlock_irq(shost->host_lock);
  6437. lpfc_init_vpi(phba, pmb, vport->vpi);
  6438. pmb->vport = vport;
  6439. pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
  6440. rc = lpfc_sli_issue_mbox(phba, pmb,
  6441. MBX_NOWAIT);
  6442. if (rc == MBX_NOT_FINISHED) {
  6443. lpfc_printf_vlog(vport,
  6444. KERN_ERR, LOG_MBOX,
  6445. "2732 Failed to issue INIT_VPI"
  6446. " mailbox command\n");
  6447. } else {
  6448. lpfc_nlp_put(ndlp);
  6449. return;
  6450. }
  6451. default:
  6452. /* Try to recover from this error */
  6453. if (phba->sli_rev == LPFC_SLI_REV4)
  6454. lpfc_sli4_unreg_all_rpis(vport);
  6455. lpfc_mbx_unreg_vpi(vport);
  6456. spin_lock_irq(shost->host_lock);
  6457. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  6458. spin_unlock_irq(shost->host_lock);
  6459. if (vport->port_type == LPFC_PHYSICAL_PORT
  6460. && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
  6461. lpfc_issue_init_vfi(vport);
  6462. else
  6463. lpfc_initial_fdisc(vport);
  6464. break;
  6465. }
  6466. } else {
  6467. spin_lock_irq(shost->host_lock);
  6468. vport->vpi_state |= LPFC_VPI_REGISTERED;
  6469. spin_unlock_irq(shost->host_lock);
  6470. if (vport == phba->pport) {
  6471. if (phba->sli_rev < LPFC_SLI_REV4)
  6472. lpfc_issue_fabric_reglogin(vport);
  6473. else {
  6474. /*
  6475. * If the physical port is instantiated using
  6476. * FDISC, do not start vport discovery.
  6477. */
  6478. if (vport->port_state != LPFC_FDISC)
  6479. lpfc_start_fdiscs(phba);
  6480. lpfc_do_scr_ns_plogi(phba, vport);
  6481. }
  6482. } else
  6483. lpfc_do_scr_ns_plogi(phba, vport);
  6484. }
  6485. mbox_err_exit:
  6486. /* Now, we decrement the ndlp reference count held for this
  6487. * callback function
  6488. */
  6489. lpfc_nlp_put(ndlp);
  6490. mempool_free(pmb, phba->mbox_mem_pool);
  6491. return;
  6492. }
  6493. /**
  6494. * lpfc_register_new_vport - Register a new vport with a HBA
  6495. * @phba: pointer to lpfc hba data structure.
  6496. * @vport: pointer to a host virtual N_Port data structure.
  6497. * @ndlp: pointer to a node-list data structure.
  6498. *
  6499. * This routine registers the @vport as a new virtual port with a HBA.
  6500. * It is done through a registering vpi mailbox command.
  6501. **/
  6502. void
  6503. lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
  6504. struct lpfc_nodelist *ndlp)
  6505. {
  6506. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6507. LPFC_MBOXQ_t *mbox;
  6508. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6509. if (mbox) {
  6510. lpfc_reg_vpi(vport, mbox);
  6511. mbox->vport = vport;
  6512. mbox->context2 = lpfc_nlp_get(ndlp);
  6513. mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
  6514. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  6515. == MBX_NOT_FINISHED) {
  6516. /* mailbox command not success, decrement ndlp
  6517. * reference count for this command
  6518. */
  6519. lpfc_nlp_put(ndlp);
  6520. mempool_free(mbox, phba->mbox_mem_pool);
  6521. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  6522. "0253 Register VPI: Can't send mbox\n");
  6523. goto mbox_err_exit;
  6524. }
  6525. } else {
  6526. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  6527. "0254 Register VPI: no memory\n");
  6528. goto mbox_err_exit;
  6529. }
  6530. return;
  6531. mbox_err_exit:
  6532. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6533. spin_lock_irq(shost->host_lock);
  6534. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  6535. spin_unlock_irq(shost->host_lock);
  6536. return;
  6537. }
  6538. /**
  6539. * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
  6540. * @phba: pointer to lpfc hba data structure.
  6541. *
  6542. * This routine cancels the retry delay timers to all the vports.
  6543. **/
  6544. void
  6545. lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
  6546. {
  6547. struct lpfc_vport **vports;
  6548. struct lpfc_nodelist *ndlp;
  6549. uint32_t link_state;
  6550. int i;
  6551. /* Treat this failure as linkdown for all vports */
  6552. link_state = phba->link_state;
  6553. lpfc_linkdown(phba);
  6554. phba->link_state = link_state;
  6555. vports = lpfc_create_vport_work_array(phba);
  6556. if (vports) {
  6557. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  6558. ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
  6559. if (ndlp)
  6560. lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
  6561. lpfc_els_flush_cmd(vports[i]);
  6562. }
  6563. lpfc_destroy_vport_work_array(phba, vports);
  6564. }
  6565. }
  6566. /**
  6567. * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
  6568. * @phba: pointer to lpfc hba data structure.
  6569. *
  6570. * This routine abort all pending discovery commands and
  6571. * start a timer to retry FLOGI for the physical port
  6572. * discovery.
  6573. **/
  6574. void
  6575. lpfc_retry_pport_discovery(struct lpfc_hba *phba)
  6576. {
  6577. struct lpfc_nodelist *ndlp;
  6578. struct Scsi_Host *shost;
  6579. /* Cancel the all vports retry delay retry timers */
  6580. lpfc_cancel_all_vport_retry_delay_timer(phba);
  6581. /* If fabric require FLOGI, then re-instantiate physical login */
  6582. ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
  6583. if (!ndlp)
  6584. return;
  6585. shost = lpfc_shost_from_vport(phba->pport);
  6586. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  6587. spin_lock_irq(shost->host_lock);
  6588. ndlp->nlp_flag |= NLP_DELAY_TMO;
  6589. spin_unlock_irq(shost->host_lock);
  6590. ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
  6591. phba->pport->port_state = LPFC_FLOGI;
  6592. return;
  6593. }
  6594. /**
  6595. * lpfc_fabric_login_reqd - Check if FLOGI required.
  6596. * @phba: pointer to lpfc hba data structure.
  6597. * @cmdiocb: pointer to FDISC command iocb.
  6598. * @rspiocb: pointer to FDISC response iocb.
  6599. *
  6600. * This routine checks if a FLOGI is reguired for FDISC
  6601. * to succeed.
  6602. **/
  6603. static int
  6604. lpfc_fabric_login_reqd(struct lpfc_hba *phba,
  6605. struct lpfc_iocbq *cmdiocb,
  6606. struct lpfc_iocbq *rspiocb)
  6607. {
  6608. if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
  6609. (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
  6610. return 0;
  6611. else
  6612. return 1;
  6613. }
  6614. /**
  6615. * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
  6616. * @phba: pointer to lpfc hba data structure.
  6617. * @cmdiocb: pointer to lpfc command iocb data structure.
  6618. * @rspiocb: pointer to lpfc response iocb data structure.
  6619. *
  6620. * This routine is the completion callback function to a Fabric Discover
  6621. * (FDISC) ELS command. Since all the FDISC ELS commands are issued
  6622. * single threaded, each FDISC completion callback function will reset
  6623. * the discovery timer for all vports such that the timers will not get
  6624. * unnecessary timeout. The function checks the FDISC IOCB status. If error
  6625. * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
  6626. * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
  6627. * assigned to the vport has been changed with the completion of the FDISC
  6628. * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
  6629. * are unregistered from the HBA, and then the lpfc_register_new_vport()
  6630. * routine is invoked to register new vport with the HBA. Otherwise, the
  6631. * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
  6632. * Server for State Change Request (SCR).
  6633. **/
  6634. static void
  6635. lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6636. struct lpfc_iocbq *rspiocb)
  6637. {
  6638. struct lpfc_vport *vport = cmdiocb->vport;
  6639. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6640. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  6641. struct lpfc_nodelist *np;
  6642. struct lpfc_nodelist *next_np;
  6643. IOCB_t *irsp = &rspiocb->iocb;
  6644. struct lpfc_iocbq *piocb;
  6645. struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
  6646. struct serv_parm *sp;
  6647. uint8_t fabric_param_changed;
  6648. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6649. "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
  6650. irsp->ulpStatus, irsp->un.ulpWord[4],
  6651. vport->fc_prevDID);
  6652. /* Since all FDISCs are being single threaded, we
  6653. * must reset the discovery timer for ALL vports
  6654. * waiting to send FDISC when one completes.
  6655. */
  6656. list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
  6657. lpfc_set_disctmo(piocb->vport);
  6658. }
  6659. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  6660. "FDISC cmpl: status:x%x/x%x prevdid:x%x",
  6661. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
  6662. if (irsp->ulpStatus) {
  6663. if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
  6664. lpfc_retry_pport_discovery(phba);
  6665. goto out;
  6666. }
  6667. /* Check for retry */
  6668. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  6669. goto out;
  6670. /* FDISC failed */
  6671. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6672. "0126 FDISC failed. (x%x/x%x)\n",
  6673. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6674. goto fdisc_failed;
  6675. }
  6676. spin_lock_irq(shost->host_lock);
  6677. vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
  6678. vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
  6679. vport->fc_flag |= FC_FABRIC;
  6680. if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
  6681. vport->fc_flag |= FC_PUBLIC_LOOP;
  6682. spin_unlock_irq(shost->host_lock);
  6683. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  6684. lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
  6685. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  6686. sp = prsp->virt + sizeof(uint32_t);
  6687. fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
  6688. memcpy(&vport->fabric_portname, &sp->portName,
  6689. sizeof(struct lpfc_name));
  6690. memcpy(&vport->fabric_nodename, &sp->nodeName,
  6691. sizeof(struct lpfc_name));
  6692. if (fabric_param_changed &&
  6693. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  6694. /* If our NportID changed, we need to ensure all
  6695. * remaining NPORTs get unreg_login'ed so we can
  6696. * issue unreg_vpi.
  6697. */
  6698. list_for_each_entry_safe(np, next_np,
  6699. &vport->fc_nodes, nlp_listp) {
  6700. if (!NLP_CHK_NODE_ACT(ndlp) ||
  6701. (np->nlp_state != NLP_STE_NPR_NODE) ||
  6702. !(np->nlp_flag & NLP_NPR_ADISC))
  6703. continue;
  6704. spin_lock_irq(shost->host_lock);
  6705. np->nlp_flag &= ~NLP_NPR_ADISC;
  6706. spin_unlock_irq(shost->host_lock);
  6707. lpfc_unreg_rpi(vport, np);
  6708. }
  6709. lpfc_cleanup_pending_mbox(vport);
  6710. if (phba->sli_rev == LPFC_SLI_REV4)
  6711. lpfc_sli4_unreg_all_rpis(vport);
  6712. lpfc_mbx_unreg_vpi(vport);
  6713. spin_lock_irq(shost->host_lock);
  6714. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  6715. if (phba->sli_rev == LPFC_SLI_REV4)
  6716. vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  6717. else
  6718. vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
  6719. spin_unlock_irq(shost->host_lock);
  6720. } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
  6721. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  6722. /*
  6723. * Driver needs to re-reg VPI in order for f/w
  6724. * to update the MAC address.
  6725. */
  6726. lpfc_register_new_vport(phba, vport, ndlp);
  6727. goto out;
  6728. }
  6729. if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
  6730. lpfc_issue_init_vpi(vport);
  6731. else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  6732. lpfc_register_new_vport(phba, vport, ndlp);
  6733. else
  6734. lpfc_do_scr_ns_plogi(phba, vport);
  6735. goto out;
  6736. fdisc_failed:
  6737. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6738. /* Cancel discovery timer */
  6739. lpfc_can_disctmo(vport);
  6740. lpfc_nlp_put(ndlp);
  6741. out:
  6742. lpfc_els_free_iocb(phba, cmdiocb);
  6743. }
  6744. /**
  6745. * lpfc_issue_els_fdisc - Issue a fdisc iocb command
  6746. * @vport: pointer to a virtual N_Port data structure.
  6747. * @ndlp: pointer to a node-list data structure.
  6748. * @retry: number of retries to the command IOCB.
  6749. *
  6750. * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
  6751. * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
  6752. * routine to issue the IOCB, which makes sure only one outstanding fabric
  6753. * IOCB will be sent off HBA at any given time.
  6754. *
  6755. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  6756. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  6757. * will be stored into the context1 field of the IOCB for the completion
  6758. * callback function to the FDISC ELS command.
  6759. *
  6760. * Return code
  6761. * 0 - Successfully issued fdisc iocb command
  6762. * 1 - Failed to issue fdisc iocb command
  6763. **/
  6764. static int
  6765. lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  6766. uint8_t retry)
  6767. {
  6768. struct lpfc_hba *phba = vport->phba;
  6769. IOCB_t *icmd;
  6770. struct lpfc_iocbq *elsiocb;
  6771. struct serv_parm *sp;
  6772. uint8_t *pcmd;
  6773. uint16_t cmdsize;
  6774. int did = ndlp->nlp_DID;
  6775. int rc;
  6776. vport->port_state = LPFC_FDISC;
  6777. vport->fc_myDID = 0;
  6778. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  6779. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  6780. ELS_CMD_FDISC);
  6781. if (!elsiocb) {
  6782. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6783. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6784. "0255 Issue FDISC: no IOCB\n");
  6785. return 1;
  6786. }
  6787. icmd = &elsiocb->iocb;
  6788. icmd->un.elsreq64.myID = 0;
  6789. icmd->un.elsreq64.fl = 1;
  6790. /*
  6791. * SLI3 ports require a different context type value than SLI4.
  6792. * Catch SLI3 ports here and override the prep.
  6793. */
  6794. if (phba->sli_rev == LPFC_SLI_REV3) {
  6795. icmd->ulpCt_h = 1;
  6796. icmd->ulpCt_l = 0;
  6797. }
  6798. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  6799. *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
  6800. pcmd += sizeof(uint32_t); /* CSP Word 1 */
  6801. memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
  6802. sp = (struct serv_parm *) pcmd;
  6803. /* Setup CSPs accordingly for Fabric */
  6804. sp->cmn.e_d_tov = 0;
  6805. sp->cmn.w2.r_a_tov = 0;
  6806. sp->cmn.virtual_fabric_support = 0;
  6807. sp->cls1.classValid = 0;
  6808. sp->cls2.seqDelivery = 1;
  6809. sp->cls3.seqDelivery = 1;
  6810. pcmd += sizeof(uint32_t); /* CSP Word 2 */
  6811. pcmd += sizeof(uint32_t); /* CSP Word 3 */
  6812. pcmd += sizeof(uint32_t); /* CSP Word 4 */
  6813. pcmd += sizeof(uint32_t); /* Port Name */
  6814. memcpy(pcmd, &vport->fc_portname, 8);
  6815. pcmd += sizeof(uint32_t); /* Node Name */
  6816. pcmd += sizeof(uint32_t); /* Node Name */
  6817. memcpy(pcmd, &vport->fc_nodename, 8);
  6818. lpfc_set_disctmo(vport);
  6819. phba->fc_stat.elsXmitFDISC++;
  6820. elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
  6821. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  6822. "Issue FDISC: did:x%x",
  6823. did, 0, 0);
  6824. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  6825. if (rc == IOCB_ERROR) {
  6826. lpfc_els_free_iocb(phba, elsiocb);
  6827. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6828. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6829. "0256 Issue FDISC: Cannot send IOCB\n");
  6830. return 1;
  6831. }
  6832. lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
  6833. return 0;
  6834. }
  6835. /**
  6836. * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
  6837. * @phba: pointer to lpfc hba data structure.
  6838. * @cmdiocb: pointer to lpfc command iocb data structure.
  6839. * @rspiocb: pointer to lpfc response iocb data structure.
  6840. *
  6841. * This routine is the completion callback function to the issuing of a LOGO
  6842. * ELS command off a vport. It frees the command IOCB and then decrement the
  6843. * reference count held on ndlp for this completion function, indicating that
  6844. * the reference to the ndlp is no long needed. Note that the
  6845. * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
  6846. * callback function and an additional explicit ndlp reference decrementation
  6847. * will trigger the actual release of the ndlp.
  6848. **/
  6849. static void
  6850. lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6851. struct lpfc_iocbq *rspiocb)
  6852. {
  6853. struct lpfc_vport *vport = cmdiocb->vport;
  6854. IOCB_t *irsp;
  6855. struct lpfc_nodelist *ndlp;
  6856. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6857. ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
  6858. irsp = &rspiocb->iocb;
  6859. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  6860. "LOGO npiv cmpl: status:x%x/x%x did:x%x",
  6861. irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
  6862. lpfc_els_free_iocb(phba, cmdiocb);
  6863. vport->unreg_vpi_cmpl = VPORT_ERROR;
  6864. /* Trigger the release of the ndlp after logo */
  6865. lpfc_nlp_put(ndlp);
  6866. /* NPIV LOGO completes to NPort <nlp_DID> */
  6867. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6868. "2928 NPIV LOGO completes to NPort x%x "
  6869. "Data: x%x x%x x%x x%x\n",
  6870. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  6871. irsp->ulpTimeout, vport->num_disc_nodes);
  6872. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  6873. spin_lock_irq(shost->host_lock);
  6874. vport->fc_flag &= ~FC_FABRIC;
  6875. spin_unlock_irq(shost->host_lock);
  6876. }
  6877. }
  6878. /**
  6879. * lpfc_issue_els_npiv_logo - Issue a logo off a vport
  6880. * @vport: pointer to a virtual N_Port data structure.
  6881. * @ndlp: pointer to a node-list data structure.
  6882. *
  6883. * This routine issues a LOGO ELS command to an @ndlp off a @vport.
  6884. *
  6885. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  6886. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  6887. * will be stored into the context1 field of the IOCB for the completion
  6888. * callback function to the LOGO ELS command.
  6889. *
  6890. * Return codes
  6891. * 0 - Successfully issued logo off the @vport
  6892. * 1 - Failed to issue logo off the @vport
  6893. **/
  6894. int
  6895. lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  6896. {
  6897. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6898. struct lpfc_hba *phba = vport->phba;
  6899. IOCB_t *icmd;
  6900. struct lpfc_iocbq *elsiocb;
  6901. uint8_t *pcmd;
  6902. uint16_t cmdsize;
  6903. cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
  6904. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
  6905. ELS_CMD_LOGO);
  6906. if (!elsiocb)
  6907. return 1;
  6908. icmd = &elsiocb->iocb;
  6909. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  6910. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  6911. pcmd += sizeof(uint32_t);
  6912. /* Fill in LOGO payload */
  6913. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  6914. pcmd += sizeof(uint32_t);
  6915. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  6916. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  6917. "Issue LOGO npiv did:x%x flg:x%x",
  6918. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  6919. elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
  6920. spin_lock_irq(shost->host_lock);
  6921. ndlp->nlp_flag |= NLP_LOGO_SND;
  6922. spin_unlock_irq(shost->host_lock);
  6923. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  6924. IOCB_ERROR) {
  6925. spin_lock_irq(shost->host_lock);
  6926. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  6927. spin_unlock_irq(shost->host_lock);
  6928. lpfc_els_free_iocb(phba, elsiocb);
  6929. return 1;
  6930. }
  6931. return 0;
  6932. }
  6933. /**
  6934. * lpfc_fabric_block_timeout - Handler function to the fabric block timer
  6935. * @ptr: holder for the timer function associated data.
  6936. *
  6937. * This routine is invoked by the fabric iocb block timer after
  6938. * timeout. It posts the fabric iocb block timeout event by setting the
  6939. * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
  6940. * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
  6941. * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
  6942. * posted event WORKER_FABRIC_BLOCK_TMO.
  6943. **/
  6944. void
  6945. lpfc_fabric_block_timeout(unsigned long ptr)
  6946. {
  6947. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  6948. unsigned long iflags;
  6949. uint32_t tmo_posted;
  6950. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  6951. tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
  6952. if (!tmo_posted)
  6953. phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
  6954. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  6955. if (!tmo_posted)
  6956. lpfc_worker_wake_up(phba);
  6957. return;
  6958. }
  6959. /**
  6960. * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
  6961. * @phba: pointer to lpfc hba data structure.
  6962. *
  6963. * This routine issues one fabric iocb from the driver internal list to
  6964. * the HBA. It first checks whether it's ready to issue one fabric iocb to
  6965. * the HBA (whether there is no outstanding fabric iocb). If so, it shall
  6966. * remove one pending fabric iocb from the driver internal list and invokes
  6967. * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
  6968. **/
  6969. static void
  6970. lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
  6971. {
  6972. struct lpfc_iocbq *iocb;
  6973. unsigned long iflags;
  6974. int ret;
  6975. IOCB_t *cmd;
  6976. repeat:
  6977. iocb = NULL;
  6978. spin_lock_irqsave(&phba->hbalock, iflags);
  6979. /* Post any pending iocb to the SLI layer */
  6980. if (atomic_read(&phba->fabric_iocb_count) == 0) {
  6981. list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
  6982. list);
  6983. if (iocb)
  6984. /* Increment fabric iocb count to hold the position */
  6985. atomic_inc(&phba->fabric_iocb_count);
  6986. }
  6987. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6988. if (iocb) {
  6989. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  6990. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  6991. iocb->iocb_flag |= LPFC_IO_FABRIC;
  6992. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  6993. "Fabric sched1: ste:x%x",
  6994. iocb->vport->port_state, 0, 0);
  6995. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
  6996. if (ret == IOCB_ERROR) {
  6997. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  6998. iocb->fabric_iocb_cmpl = NULL;
  6999. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  7000. cmd = &iocb->iocb;
  7001. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  7002. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  7003. iocb->iocb_cmpl(phba, iocb, iocb);
  7004. atomic_dec(&phba->fabric_iocb_count);
  7005. goto repeat;
  7006. }
  7007. }
  7008. return;
  7009. }
  7010. /**
  7011. * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
  7012. * @phba: pointer to lpfc hba data structure.
  7013. *
  7014. * This routine unblocks the issuing fabric iocb command. The function
  7015. * will clear the fabric iocb block bit and then invoke the routine
  7016. * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
  7017. * from the driver internal fabric iocb list.
  7018. **/
  7019. void
  7020. lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
  7021. {
  7022. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  7023. lpfc_resume_fabric_iocbs(phba);
  7024. return;
  7025. }
  7026. /**
  7027. * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
  7028. * @phba: pointer to lpfc hba data structure.
  7029. *
  7030. * This routine blocks the issuing fabric iocb for a specified amount of
  7031. * time (currently 100 ms). This is done by set the fabric iocb block bit
  7032. * and set up a timeout timer for 100ms. When the block bit is set, no more
  7033. * fabric iocb will be issued out of the HBA.
  7034. **/
  7035. static void
  7036. lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
  7037. {
  7038. int blocked;
  7039. blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  7040. /* Start a timer to unblock fabric iocbs after 100ms */
  7041. if (!blocked)
  7042. mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
  7043. return;
  7044. }
  7045. /**
  7046. * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
  7047. * @phba: pointer to lpfc hba data structure.
  7048. * @cmdiocb: pointer to lpfc command iocb data structure.
  7049. * @rspiocb: pointer to lpfc response iocb data structure.
  7050. *
  7051. * This routine is the callback function that is put to the fabric iocb's
  7052. * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
  7053. * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
  7054. * function first restores and invokes the original iocb's callback function
  7055. * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
  7056. * fabric bound iocb from the driver internal fabric iocb list onto the wire.
  7057. **/
  7058. static void
  7059. lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7060. struct lpfc_iocbq *rspiocb)
  7061. {
  7062. struct ls_rjt stat;
  7063. if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
  7064. BUG();
  7065. switch (rspiocb->iocb.ulpStatus) {
  7066. case IOSTAT_NPORT_RJT:
  7067. case IOSTAT_FABRIC_RJT:
  7068. if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  7069. lpfc_block_fabric_iocbs(phba);
  7070. }
  7071. break;
  7072. case IOSTAT_NPORT_BSY:
  7073. case IOSTAT_FABRIC_BSY:
  7074. lpfc_block_fabric_iocbs(phba);
  7075. break;
  7076. case IOSTAT_LS_RJT:
  7077. stat.un.lsRjtError =
  7078. be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
  7079. if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
  7080. (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
  7081. lpfc_block_fabric_iocbs(phba);
  7082. break;
  7083. }
  7084. if (atomic_read(&phba->fabric_iocb_count) == 0)
  7085. BUG();
  7086. cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
  7087. cmdiocb->fabric_iocb_cmpl = NULL;
  7088. cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
  7089. cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
  7090. atomic_dec(&phba->fabric_iocb_count);
  7091. if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
  7092. /* Post any pending iocbs to HBA */
  7093. lpfc_resume_fabric_iocbs(phba);
  7094. }
  7095. }
  7096. /**
  7097. * lpfc_issue_fabric_iocb - Issue a fabric iocb command
  7098. * @phba: pointer to lpfc hba data structure.
  7099. * @iocb: pointer to lpfc command iocb data structure.
  7100. *
  7101. * This routine is used as the top-level API for issuing a fabric iocb command
  7102. * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
  7103. * function makes sure that only one fabric bound iocb will be outstanding at
  7104. * any given time. As such, this function will first check to see whether there
  7105. * is already an outstanding fabric iocb on the wire. If so, it will put the
  7106. * newly issued iocb onto the driver internal fabric iocb list, waiting to be
  7107. * issued later. Otherwise, it will issue the iocb on the wire and update the
  7108. * fabric iocb count it indicate that there is one fabric iocb on the wire.
  7109. *
  7110. * Note, this implementation has a potential sending out fabric IOCBs out of
  7111. * order. The problem is caused by the construction of the "ready" boolen does
  7112. * not include the condition that the internal fabric IOCB list is empty. As
  7113. * such, it is possible a fabric IOCB issued by this routine might be "jump"
  7114. * ahead of the fabric IOCBs in the internal list.
  7115. *
  7116. * Return code
  7117. * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
  7118. * IOCB_ERROR - failed to issue fabric iocb
  7119. **/
  7120. static int
  7121. lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
  7122. {
  7123. unsigned long iflags;
  7124. int ready;
  7125. int ret;
  7126. if (atomic_read(&phba->fabric_iocb_count) > 1)
  7127. BUG();
  7128. spin_lock_irqsave(&phba->hbalock, iflags);
  7129. ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
  7130. !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  7131. if (ready)
  7132. /* Increment fabric iocb count to hold the position */
  7133. atomic_inc(&phba->fabric_iocb_count);
  7134. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7135. if (ready) {
  7136. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  7137. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  7138. iocb->iocb_flag |= LPFC_IO_FABRIC;
  7139. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  7140. "Fabric sched2: ste:x%x",
  7141. iocb->vport->port_state, 0, 0);
  7142. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
  7143. if (ret == IOCB_ERROR) {
  7144. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  7145. iocb->fabric_iocb_cmpl = NULL;
  7146. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  7147. atomic_dec(&phba->fabric_iocb_count);
  7148. }
  7149. } else {
  7150. spin_lock_irqsave(&phba->hbalock, iflags);
  7151. list_add_tail(&iocb->list, &phba->fabric_iocb_list);
  7152. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7153. ret = IOCB_SUCCESS;
  7154. }
  7155. return ret;
  7156. }
  7157. /**
  7158. * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
  7159. * @vport: pointer to a virtual N_Port data structure.
  7160. *
  7161. * This routine aborts all the IOCBs associated with a @vport from the
  7162. * driver internal fabric IOCB list. The list contains fabric IOCBs to be
  7163. * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
  7164. * list, removes each IOCB associated with the @vport off the list, set the
  7165. * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
  7166. * associated with the IOCB.
  7167. **/
  7168. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
  7169. {
  7170. LIST_HEAD(completions);
  7171. struct lpfc_hba *phba = vport->phba;
  7172. struct lpfc_iocbq *tmp_iocb, *piocb;
  7173. spin_lock_irq(&phba->hbalock);
  7174. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  7175. list) {
  7176. if (piocb->vport != vport)
  7177. continue;
  7178. list_move_tail(&piocb->list, &completions);
  7179. }
  7180. spin_unlock_irq(&phba->hbalock);
  7181. /* Cancel all the IOCBs from the completions list */
  7182. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7183. IOERR_SLI_ABORTED);
  7184. }
  7185. /**
  7186. * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
  7187. * @ndlp: pointer to a node-list data structure.
  7188. *
  7189. * This routine aborts all the IOCBs associated with an @ndlp from the
  7190. * driver internal fabric IOCB list. The list contains fabric IOCBs to be
  7191. * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
  7192. * list, removes each IOCB associated with the @ndlp off the list, set the
  7193. * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
  7194. * associated with the IOCB.
  7195. **/
  7196. void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
  7197. {
  7198. LIST_HEAD(completions);
  7199. struct lpfc_hba *phba = ndlp->phba;
  7200. struct lpfc_iocbq *tmp_iocb, *piocb;
  7201. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7202. spin_lock_irq(&phba->hbalock);
  7203. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  7204. list) {
  7205. if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
  7206. list_move_tail(&piocb->list, &completions);
  7207. }
  7208. }
  7209. spin_unlock_irq(&phba->hbalock);
  7210. /* Cancel all the IOCBs from the completions list */
  7211. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7212. IOERR_SLI_ABORTED);
  7213. }
  7214. /**
  7215. * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
  7216. * @phba: pointer to lpfc hba data structure.
  7217. *
  7218. * This routine aborts all the IOCBs currently on the driver internal
  7219. * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
  7220. * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
  7221. * list, removes IOCBs off the list, set the status feild to
  7222. * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
  7223. * the IOCB.
  7224. **/
  7225. void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
  7226. {
  7227. LIST_HEAD(completions);
  7228. spin_lock_irq(&phba->hbalock);
  7229. list_splice_init(&phba->fabric_iocb_list, &completions);
  7230. spin_unlock_irq(&phba->hbalock);
  7231. /* Cancel all the IOCBs from the completions list */
  7232. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7233. IOERR_SLI_ABORTED);
  7234. }
  7235. /**
  7236. * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
  7237. * @vport: pointer to lpfc vport data structure.
  7238. *
  7239. * This routine is invoked by the vport cleanup for deletions and the cleanup
  7240. * for an ndlp on removal.
  7241. **/
  7242. void
  7243. lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
  7244. {
  7245. struct lpfc_hba *phba = vport->phba;
  7246. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  7247. unsigned long iflag = 0;
  7248. spin_lock_irqsave(&phba->hbalock, iflag);
  7249. spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
  7250. list_for_each_entry_safe(sglq_entry, sglq_next,
  7251. &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
  7252. if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
  7253. sglq_entry->ndlp = NULL;
  7254. }
  7255. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  7256. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7257. return;
  7258. }
  7259. /**
  7260. * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
  7261. * @phba: pointer to lpfc hba data structure.
  7262. * @axri: pointer to the els xri abort wcqe structure.
  7263. *
  7264. * This routine is invoked by the worker thread to process a SLI4 slow-path
  7265. * ELS aborted xri.
  7266. **/
  7267. void
  7268. lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
  7269. struct sli4_wcqe_xri_aborted *axri)
  7270. {
  7271. uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
  7272. uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
  7273. uint16_t lxri = 0;
  7274. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  7275. unsigned long iflag = 0;
  7276. struct lpfc_nodelist *ndlp;
  7277. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7278. spin_lock_irqsave(&phba->hbalock, iflag);
  7279. spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
  7280. list_for_each_entry_safe(sglq_entry, sglq_next,
  7281. &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
  7282. if (sglq_entry->sli4_xritag == xri) {
  7283. list_del(&sglq_entry->list);
  7284. ndlp = sglq_entry->ndlp;
  7285. sglq_entry->ndlp = NULL;
  7286. list_add_tail(&sglq_entry->list,
  7287. &phba->sli4_hba.lpfc_sgl_list);
  7288. sglq_entry->state = SGL_FREED;
  7289. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  7290. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7291. lpfc_set_rrq_active(phba, ndlp,
  7292. sglq_entry->sli4_lxritag,
  7293. rxid, 1);
  7294. /* Check if TXQ queue needs to be serviced */
  7295. if (pring->txq_cnt)
  7296. lpfc_worker_wake_up(phba);
  7297. return;
  7298. }
  7299. }
  7300. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  7301. lxri = lpfc_sli4_xri_inrange(phba, xri);
  7302. if (lxri == NO_XRI) {
  7303. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7304. return;
  7305. }
  7306. sglq_entry = __lpfc_get_active_sglq(phba, lxri);
  7307. if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
  7308. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7309. return;
  7310. }
  7311. sglq_entry->state = SGL_XRI_ABORTED;
  7312. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7313. return;
  7314. }
  7315. /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
  7316. * @vport: pointer to virtual port object.
  7317. * @ndlp: nodelist pointer for the impacted node.
  7318. *
  7319. * The driver calls this routine in response to an SLI4 XRI ABORT CQE
  7320. * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
  7321. * the driver is required to send a LOGO to the remote node before it
  7322. * attempts to recover its login to the remote node.
  7323. */
  7324. void
  7325. lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
  7326. struct lpfc_nodelist *ndlp)
  7327. {
  7328. struct Scsi_Host *shost;
  7329. struct lpfc_hba *phba;
  7330. unsigned long flags = 0;
  7331. shost = lpfc_shost_from_vport(vport);
  7332. phba = vport->phba;
  7333. if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
  7334. lpfc_printf_log(phba, KERN_INFO,
  7335. LOG_SLI, "3093 No rport recovery needed. "
  7336. "rport in state 0x%x\n", ndlp->nlp_state);
  7337. return;
  7338. }
  7339. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7340. "3094 Start rport recovery on shost id 0x%x "
  7341. "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
  7342. "flags 0x%x\n",
  7343. shost->host_no, ndlp->nlp_DID,
  7344. vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
  7345. ndlp->nlp_flag);
  7346. /*
  7347. * The rport is not responding. Remove the FCP-2 flag to prevent
  7348. * an ADISC in the follow-up recovery code.
  7349. */
  7350. spin_lock_irqsave(shost->host_lock, flags);
  7351. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  7352. spin_unlock_irqrestore(shost->host_lock, flags);
  7353. lpfc_issue_els_logo(vport, ndlp, 0);
  7354. lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
  7355. }