lpfc_els.c 260 KB

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