lpfc_els.c 219 KB

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