lpfc_els.c 299 KB

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