lpfc_els.c 208 KB

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