lpfc_els.c 256 KB

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