lpfc_els.c 250 KB

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