lpfc_els.c 211 KB

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