lpfc_els.c 209 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. lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
  248. kfree(pbuflist);
  249. els_iocb_free_prsp_exit:
  250. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  251. kfree(prsp);
  252. els_iocb_free_pcmb_exit:
  253. kfree(pcmd);
  254. lpfc_sli_release_iocbq(phba, elsiocb);
  255. return NULL;
  256. }
  257. /**
  258. * lpfc_issue_fabric_reglogin: Issue fabric registration login for a vport.
  259. * @vport: pointer to a host virtual N_Port data structure.
  260. *
  261. * This routine issues a fabric registration login for a @vport. An
  262. * active ndlp node with Fabric_DID must already exist for this @vport.
  263. * The routine invokes two mailbox commands to carry out fabric registration
  264. * login through the HBA firmware: the first mailbox command requests the
  265. * HBA to perform link configuration for the @vport; and the second mailbox
  266. * command requests the HBA to perform the actual fabric registration login
  267. * with the @vport.
  268. *
  269. * Return code
  270. * 0 - successfully issued fabric registration login for @vport
  271. * -ENXIO -- failed to issue fabric registration login for @vport
  272. **/
  273. static int
  274. lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
  275. {
  276. struct lpfc_hba *phba = vport->phba;
  277. LPFC_MBOXQ_t *mbox;
  278. struct lpfc_dmabuf *mp;
  279. struct lpfc_nodelist *ndlp;
  280. struct serv_parm *sp;
  281. int rc;
  282. int err = 0;
  283. sp = &phba->fc_fabparam;
  284. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  285. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  286. err = 1;
  287. goto fail;
  288. }
  289. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  290. if (!mbox) {
  291. err = 2;
  292. goto fail;
  293. }
  294. vport->port_state = LPFC_FABRIC_CFG_LINK;
  295. lpfc_config_link(phba, mbox);
  296. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  297. mbox->vport = vport;
  298. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  299. if (rc == MBX_NOT_FINISHED) {
  300. err = 3;
  301. goto fail_free_mbox;
  302. }
  303. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  304. if (!mbox) {
  305. err = 4;
  306. goto fail;
  307. }
  308. rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
  309. 0);
  310. if (rc) {
  311. err = 5;
  312. goto fail_free_mbox;
  313. }
  314. mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
  315. mbox->vport = vport;
  316. /* increment the reference count on ndlp to hold reference
  317. * for the callback routine.
  318. */
  319. mbox->context2 = lpfc_nlp_get(ndlp);
  320. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  321. if (rc == MBX_NOT_FINISHED) {
  322. err = 6;
  323. goto fail_issue_reg_login;
  324. }
  325. return 0;
  326. fail_issue_reg_login:
  327. /* decrement the reference count on ndlp just incremented
  328. * for the failed mbox command.
  329. */
  330. lpfc_nlp_put(ndlp);
  331. mp = (struct lpfc_dmabuf *) mbox->context1;
  332. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  333. kfree(mp);
  334. fail_free_mbox:
  335. mempool_free(mbox, phba->mbox_mem_pool);
  336. fail:
  337. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  338. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  339. "0249 Cannot issue Register Fabric login: Err %d\n", err);
  340. return -ENXIO;
  341. }
  342. /**
  343. * lpfc_cmpl_els_flogi_fabric: Completion function for flogi to a fabric port.
  344. * @vport: pointer to a host virtual N_Port data structure.
  345. * @ndlp: pointer to a node-list data structure.
  346. * @sp: pointer to service parameter data structure.
  347. * @irsp: pointer to the IOCB within the lpfc response IOCB.
  348. *
  349. * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
  350. * function to handle the completion of a Fabric Login (FLOGI) into a fabric
  351. * port in a fabric topology. It properly sets up the parameters to the @ndlp
  352. * from the IOCB response. It also check the newly assigned N_Port ID to the
  353. * @vport against the previously assigned N_Port ID. If it is different from
  354. * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
  355. * is invoked on all the remaining nodes with the @vport to unregister the
  356. * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
  357. * is invoked to register login to the fabric.
  358. *
  359. * Return code
  360. * 0 - Success (currently, always return 0)
  361. **/
  362. static int
  363. lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  364. struct serv_parm *sp, IOCB_t *irsp)
  365. {
  366. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  367. struct lpfc_hba *phba = vport->phba;
  368. struct lpfc_nodelist *np;
  369. struct lpfc_nodelist *next_np;
  370. spin_lock_irq(shost->host_lock);
  371. vport->fc_flag |= FC_FABRIC;
  372. spin_unlock_irq(shost->host_lock);
  373. phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
  374. if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
  375. phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
  376. phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
  377. if (phba->fc_topology == TOPOLOGY_LOOP) {
  378. spin_lock_irq(shost->host_lock);
  379. vport->fc_flag |= FC_PUBLIC_LOOP;
  380. spin_unlock_irq(shost->host_lock);
  381. } else {
  382. /*
  383. * If we are a N-port connected to a Fabric, fixup sparam's so
  384. * logins to devices on remote loops work.
  385. */
  386. vport->fc_sparam.cmn.altBbCredit = 1;
  387. }
  388. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  389. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
  390. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
  391. ndlp->nlp_class_sup = 0;
  392. if (sp->cls1.classValid)
  393. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  394. if (sp->cls2.classValid)
  395. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  396. if (sp->cls3.classValid)
  397. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  398. if (sp->cls4.classValid)
  399. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  400. ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  401. sp->cmn.bbRcvSizeLsb;
  402. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  403. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  404. if (sp->cmn.response_multiple_NPort) {
  405. lpfc_printf_vlog(vport, KERN_WARNING,
  406. LOG_ELS | LOG_VPORT,
  407. "1816 FLOGI NPIV supported, "
  408. "response data 0x%x\n",
  409. sp->cmn.response_multiple_NPort);
  410. phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
  411. } else {
  412. /* Because we asked f/w for NPIV it still expects us
  413. to call reg_vnpid atleast for the physcial host */
  414. lpfc_printf_vlog(vport, KERN_WARNING,
  415. LOG_ELS | LOG_VPORT,
  416. "1817 Fabric does not support NPIV "
  417. "- configuring single port mode.\n");
  418. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  419. }
  420. }
  421. if ((vport->fc_prevDID != vport->fc_myDID) &&
  422. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  423. /* If our NportID changed, we need to ensure all
  424. * remaining NPORTs get unreg_login'ed.
  425. */
  426. list_for_each_entry_safe(np, next_np,
  427. &vport->fc_nodes, nlp_listp) {
  428. if (!NLP_CHK_NODE_ACT(np))
  429. continue;
  430. if ((np->nlp_state != NLP_STE_NPR_NODE) ||
  431. !(np->nlp_flag & NLP_NPR_ADISC))
  432. continue;
  433. spin_lock_irq(shost->host_lock);
  434. np->nlp_flag &= ~NLP_NPR_ADISC;
  435. spin_unlock_irq(shost->host_lock);
  436. lpfc_unreg_rpi(vport, np);
  437. }
  438. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  439. lpfc_mbx_unreg_vpi(vport);
  440. spin_lock_irq(shost->host_lock);
  441. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  442. spin_unlock_irq(shost->host_lock);
  443. }
  444. }
  445. lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
  446. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
  447. vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
  448. lpfc_register_new_vport(phba, vport, ndlp);
  449. return 0;
  450. }
  451. lpfc_issue_fabric_reglogin(vport);
  452. return 0;
  453. }
  454. /**
  455. * lpfc_cmpl_els_flogi_nport: Completion function for flogi to an N_Port.
  456. * @vport: pointer to a host virtual N_Port data structure.
  457. * @ndlp: pointer to a node-list data structure.
  458. * @sp: pointer to service parameter data structure.
  459. *
  460. * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
  461. * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
  462. * in a point-to-point topology. First, the @vport's N_Port Name is compared
  463. * with the received N_Port Name: if the @vport's N_Port Name is greater than
  464. * the received N_Port Name lexicographically, this node shall assign local
  465. * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
  466. * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
  467. * this node shall just wait for the remote node to issue PLOGI and assign
  468. * N_Port IDs.
  469. *
  470. * Return code
  471. * 0 - Success
  472. * -ENXIO - Fail
  473. **/
  474. static int
  475. lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  476. struct serv_parm *sp)
  477. {
  478. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  479. struct lpfc_hba *phba = vport->phba;
  480. LPFC_MBOXQ_t *mbox;
  481. int rc;
  482. spin_lock_irq(shost->host_lock);
  483. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  484. spin_unlock_irq(shost->host_lock);
  485. phba->fc_edtov = FF_DEF_EDTOV;
  486. phba->fc_ratov = FF_DEF_RATOV;
  487. rc = memcmp(&vport->fc_portname, &sp->portName,
  488. sizeof(vport->fc_portname));
  489. if (rc >= 0) {
  490. /* This side will initiate the PLOGI */
  491. spin_lock_irq(shost->host_lock);
  492. vport->fc_flag |= FC_PT2PT_PLOGI;
  493. spin_unlock_irq(shost->host_lock);
  494. /*
  495. * N_Port ID cannot be 0, set our to LocalID the other
  496. * side will be RemoteID.
  497. */
  498. /* not equal */
  499. if (rc)
  500. vport->fc_myDID = PT2PT_LocalID;
  501. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  502. if (!mbox)
  503. goto fail;
  504. lpfc_config_link(phba, mbox);
  505. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  506. mbox->vport = vport;
  507. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  508. if (rc == MBX_NOT_FINISHED) {
  509. mempool_free(mbox, phba->mbox_mem_pool);
  510. goto fail;
  511. }
  512. /* Decrement ndlp reference count indicating that ndlp can be
  513. * safely released when other references to it are done.
  514. */
  515. lpfc_nlp_put(ndlp);
  516. ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
  517. if (!ndlp) {
  518. /*
  519. * Cannot find existing Fabric ndlp, so allocate a
  520. * new one
  521. */
  522. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  523. if (!ndlp)
  524. goto fail;
  525. lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
  526. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  527. ndlp = lpfc_enable_node(vport, ndlp,
  528. NLP_STE_UNUSED_NODE);
  529. if(!ndlp)
  530. goto fail;
  531. }
  532. memcpy(&ndlp->nlp_portname, &sp->portName,
  533. sizeof(struct lpfc_name));
  534. memcpy(&ndlp->nlp_nodename, &sp->nodeName,
  535. sizeof(struct lpfc_name));
  536. /* Set state will put ndlp onto node list if not already done */
  537. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  538. spin_lock_irq(shost->host_lock);
  539. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  540. spin_unlock_irq(shost->host_lock);
  541. } else
  542. /* This side will wait for the PLOGI, decrement ndlp reference
  543. * count indicating that ndlp can be released when other
  544. * references to it are done.
  545. */
  546. lpfc_nlp_put(ndlp);
  547. /* If we are pt2pt with another NPort, force NPIV off! */
  548. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  549. spin_lock_irq(shost->host_lock);
  550. vport->fc_flag |= FC_PT2PT;
  551. spin_unlock_irq(shost->host_lock);
  552. /* Start discovery - this should just do CLEAR_LA */
  553. lpfc_disc_start(vport);
  554. return 0;
  555. fail:
  556. return -ENXIO;
  557. }
  558. /**
  559. * lpfc_cmpl_els_flogi: Completion callback function for flogi.
  560. * @phba: pointer to lpfc hba data structure.
  561. * @cmdiocb: pointer to lpfc command iocb data structure.
  562. * @rspiocb: pointer to lpfc response iocb data structure.
  563. *
  564. * This routine is the top-level completion callback function for issuing
  565. * a Fabric Login (FLOGI) command. If the response IOCB reported error,
  566. * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
  567. * retry has been made (either immediately or delayed with lpfc_els_retry()
  568. * returning 1), the command IOCB will be released and function returned.
  569. * If the retry attempt has been given up (possibly reach the maximum
  570. * number of retries), one additional decrement of ndlp reference shall be
  571. * invoked before going out after releasing the command IOCB. This will
  572. * actually release the remote node (Note, lpfc_els_free_iocb() will also
  573. * invoke one decrement of ndlp reference count). If no error reported in
  574. * the IOCB status, the command Port ID field is used to determine whether
  575. * this is a point-to-point topology or a fabric topology: if the Port ID
  576. * field is assigned, it is a fabric topology; otherwise, it is a
  577. * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
  578. * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
  579. * specific topology completion conditions.
  580. **/
  581. static void
  582. lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  583. struct lpfc_iocbq *rspiocb)
  584. {
  585. struct lpfc_vport *vport = cmdiocb->vport;
  586. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  587. IOCB_t *irsp = &rspiocb->iocb;
  588. struct lpfc_nodelist *ndlp = cmdiocb->context1;
  589. struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
  590. struct serv_parm *sp;
  591. int rc;
  592. /* Check to see if link went down during discovery */
  593. if (lpfc_els_chk_latt(vport)) {
  594. /* One additional decrement on node reference count to
  595. * trigger the release of the node
  596. */
  597. lpfc_nlp_put(ndlp);
  598. goto out;
  599. }
  600. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  601. "FLOGI cmpl: status:x%x/x%x state:x%x",
  602. irsp->ulpStatus, irsp->un.ulpWord[4],
  603. vport->port_state);
  604. if (irsp->ulpStatus) {
  605. /* Check for retry */
  606. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  607. goto out;
  608. /* FLOGI failed, so there is no fabric */
  609. spin_lock_irq(shost->host_lock);
  610. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  611. spin_unlock_irq(shost->host_lock);
  612. /* If private loop, then allow max outstanding els to be
  613. * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
  614. * alpa map would take too long otherwise.
  615. */
  616. if (phba->alpa_map[0] == 0) {
  617. vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
  618. }
  619. /* FLOGI failure */
  620. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  621. "0100 FLOGI failure Data: x%x x%x "
  622. "x%x\n",
  623. irsp->ulpStatus, irsp->un.ulpWord[4],
  624. irsp->ulpTimeout);
  625. goto flogifail;
  626. }
  627. /*
  628. * The FLogI succeeded. Sync the data for the CPU before
  629. * accessing it.
  630. */
  631. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  632. sp = prsp->virt + sizeof(uint32_t);
  633. /* FLOGI completes successfully */
  634. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  635. "0101 FLOGI completes sucessfully "
  636. "Data: x%x x%x x%x x%x\n",
  637. irsp->un.ulpWord[4], sp->cmn.e_d_tov,
  638. sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
  639. if (vport->port_state == LPFC_FLOGI) {
  640. /*
  641. * If Common Service Parameters indicate Nport
  642. * we are point to point, if Fport we are Fabric.
  643. */
  644. if (sp->cmn.fPort)
  645. rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
  646. else
  647. rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
  648. if (!rc)
  649. goto out;
  650. }
  651. flogifail:
  652. lpfc_nlp_put(ndlp);
  653. if (!lpfc_error_lost_link(irsp)) {
  654. /* FLOGI failed, so just use loop map to make discovery list */
  655. lpfc_disc_list_loopmap(vport);
  656. /* Start discovery */
  657. lpfc_disc_start(vport);
  658. } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  659. ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
  660. (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
  661. (phba->link_state != LPFC_CLEAR_LA)) {
  662. /* If FLOGI failed enable link interrupt. */
  663. lpfc_issue_clear_la(phba, vport);
  664. }
  665. out:
  666. lpfc_els_free_iocb(phba, cmdiocb);
  667. }
  668. /**
  669. * lpfc_issue_els_flogi: Issue an flogi iocb command for a vport.
  670. * @vport: pointer to a host virtual N_Port data structure.
  671. * @ndlp: pointer to a node-list data structure.
  672. * @retry: number of retries to the command IOCB.
  673. *
  674. * This routine issues a Fabric Login (FLOGI) Request ELS command
  675. * for a @vport. The initiator service parameters are put into the payload
  676. * of the FLOGI Request IOCB and the top-level callback function pointer
  677. * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
  678. * function field. The lpfc_issue_fabric_iocb routine is invoked to send
  679. * out FLOGI ELS command with one outstanding fabric IOCB at a time.
  680. *
  681. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  682. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  683. * will be stored into the context1 field of the IOCB for the completion
  684. * callback function to the FLOGI ELS command.
  685. *
  686. * Return code
  687. * 0 - successfully issued flogi iocb for @vport
  688. * 1 - failed to issue flogi iocb for @vport
  689. **/
  690. static int
  691. lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  692. uint8_t retry)
  693. {
  694. struct lpfc_hba *phba = vport->phba;
  695. struct serv_parm *sp;
  696. IOCB_t *icmd;
  697. struct lpfc_iocbq *elsiocb;
  698. struct lpfc_sli_ring *pring;
  699. uint8_t *pcmd;
  700. uint16_t cmdsize;
  701. uint32_t tmo;
  702. int rc;
  703. pring = &phba->sli.ring[LPFC_ELS_RING];
  704. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  705. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  706. ndlp->nlp_DID, ELS_CMD_FLOGI);
  707. if (!elsiocb)
  708. return 1;
  709. icmd = &elsiocb->iocb;
  710. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  711. /* For FLOGI request, remainder of payload is service parameters */
  712. *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
  713. pcmd += sizeof(uint32_t);
  714. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  715. sp = (struct serv_parm *) pcmd;
  716. /* Setup CSPs accordingly for Fabric */
  717. sp->cmn.e_d_tov = 0;
  718. sp->cmn.w2.r_a_tov = 0;
  719. sp->cls1.classValid = 0;
  720. sp->cls2.seqDelivery = 1;
  721. sp->cls3.seqDelivery = 1;
  722. if (sp->cmn.fcphLow < FC_PH3)
  723. sp->cmn.fcphLow = FC_PH3;
  724. if (sp->cmn.fcphHigh < FC_PH3)
  725. sp->cmn.fcphHigh = FC_PH3;
  726. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  727. sp->cmn.request_multiple_Nport = 1;
  728. /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
  729. icmd->ulpCt_h = 1;
  730. icmd->ulpCt_l = 0;
  731. }
  732. if (phba->fc_topology != TOPOLOGY_LOOP) {
  733. icmd->un.elsreq64.myID = 0;
  734. icmd->un.elsreq64.fl = 1;
  735. }
  736. tmo = phba->fc_ratov;
  737. phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
  738. lpfc_set_disctmo(vport);
  739. phba->fc_ratov = tmo;
  740. phba->fc_stat.elsXmitFLOGI++;
  741. elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
  742. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  743. "Issue FLOGI: opt:x%x",
  744. phba->sli3_options, 0, 0);
  745. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  746. if (rc == IOCB_ERROR) {
  747. lpfc_els_free_iocb(phba, elsiocb);
  748. return 1;
  749. }
  750. return 0;
  751. }
  752. /**
  753. * lpfc_els_abort_flogi: Abort all outstanding flogi iocbs.
  754. * @phba: pointer to lpfc hba data structure.
  755. *
  756. * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
  757. * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
  758. * list and issues an abort IOCB commond on each outstanding IOCB that
  759. * contains a active Fabric_DID ndlp. Note that this function is to issue
  760. * the abort IOCB command on all the outstanding IOCBs, thus when this
  761. * function returns, it does not guarantee all the IOCBs are actually aborted.
  762. *
  763. * Return code
  764. * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0)
  765. **/
  766. int
  767. lpfc_els_abort_flogi(struct lpfc_hba *phba)
  768. {
  769. struct lpfc_sli_ring *pring;
  770. struct lpfc_iocbq *iocb, *next_iocb;
  771. struct lpfc_nodelist *ndlp;
  772. IOCB_t *icmd;
  773. /* Abort outstanding I/O on NPort <nlp_DID> */
  774. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  775. "0201 Abort outstanding I/O on NPort x%x\n",
  776. Fabric_DID);
  777. pring = &phba->sli.ring[LPFC_ELS_RING];
  778. /*
  779. * Check the txcmplq for an iocb that matches the nport the driver is
  780. * searching for.
  781. */
  782. spin_lock_irq(&phba->hbalock);
  783. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  784. icmd = &iocb->iocb;
  785. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
  786. icmd->un.elsreq64.bdl.ulpIoTag32) {
  787. ndlp = (struct lpfc_nodelist *)(iocb->context1);
  788. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  789. (ndlp->nlp_DID == Fabric_DID))
  790. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  791. }
  792. }
  793. spin_unlock_irq(&phba->hbalock);
  794. return 0;
  795. }
  796. /**
  797. * lpfc_initial_flogi: Issue an initial fabric login for a vport.
  798. * @vport: pointer to a host virtual N_Port data structure.
  799. *
  800. * This routine issues an initial Fabric Login (FLOGI) for the @vport
  801. * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
  802. * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
  803. * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
  804. * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
  805. * is then invoked with the @vport and the ndlp to perform the FLOGI for the
  806. * @vport.
  807. *
  808. * Return code
  809. * 0 - failed to issue initial flogi for @vport
  810. * 1 - successfully issued initial flogi for @vport
  811. **/
  812. int
  813. lpfc_initial_flogi(struct lpfc_vport *vport)
  814. {
  815. struct lpfc_hba *phba = vport->phba;
  816. struct lpfc_nodelist *ndlp;
  817. vport->port_state = LPFC_FLOGI;
  818. lpfc_set_disctmo(vport);
  819. /* First look for the Fabric ndlp */
  820. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  821. if (!ndlp) {
  822. /* Cannot find existing Fabric ndlp, so allocate a new one */
  823. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  824. if (!ndlp)
  825. return 0;
  826. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  827. /* Put ndlp onto node list */
  828. lpfc_enqueue_node(vport, ndlp);
  829. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  830. /* re-setup ndlp without removing from node list */
  831. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  832. if (!ndlp)
  833. return 0;
  834. }
  835. if (lpfc_issue_els_flogi(vport, ndlp, 0))
  836. /* This decrement of reference count to node shall kick off
  837. * the release of the node.
  838. */
  839. lpfc_nlp_put(ndlp);
  840. return 1;
  841. }
  842. /**
  843. * lpfc_initial_fdisc: Issue an initial fabric discovery for a vport.
  844. * @vport: pointer to a host virtual N_Port data structure.
  845. *
  846. * This routine issues an initial Fabric Discover (FDISC) for the @vport
  847. * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
  848. * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
  849. * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
  850. * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
  851. * is then invoked with the @vport and the ndlp to perform the FDISC for the
  852. * @vport.
  853. *
  854. * Return code
  855. * 0 - failed to issue initial fdisc for @vport
  856. * 1 - successfully issued initial fdisc for @vport
  857. **/
  858. int
  859. lpfc_initial_fdisc(struct lpfc_vport *vport)
  860. {
  861. struct lpfc_hba *phba = vport->phba;
  862. struct lpfc_nodelist *ndlp;
  863. /* First look for the Fabric ndlp */
  864. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  865. if (!ndlp) {
  866. /* Cannot find existing Fabric ndlp, so allocate a new one */
  867. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  868. if (!ndlp)
  869. return 0;
  870. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  871. /* Put ndlp onto node list */
  872. lpfc_enqueue_node(vport, ndlp);
  873. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  874. /* re-setup ndlp without removing from node list */
  875. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  876. if (!ndlp)
  877. return 0;
  878. }
  879. if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
  880. /* decrement node reference count to trigger the release of
  881. * the node.
  882. */
  883. lpfc_nlp_put(ndlp);
  884. return 0;
  885. }
  886. return 1;
  887. }
  888. /**
  889. * lpfc_more_plogi: Check and issue remaining plogis for a vport.
  890. * @vport: pointer to a host virtual N_Port data structure.
  891. *
  892. * This routine checks whether there are more remaining Port Logins
  893. * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
  894. * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
  895. * to issue ELS PLOGIs up to the configured discover threads with the
  896. * @vport (@vport->cfg_discovery_threads). The function also decrement
  897. * the @vport's num_disc_node by 1 if it is not already 0.
  898. **/
  899. void
  900. lpfc_more_plogi(struct lpfc_vport *vport)
  901. {
  902. int sentplogi;
  903. if (vport->num_disc_nodes)
  904. vport->num_disc_nodes--;
  905. /* Continue discovery with <num_disc_nodes> PLOGIs to go */
  906. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  907. "0232 Continue discovery with %d PLOGIs to go "
  908. "Data: x%x x%x x%x\n",
  909. vport->num_disc_nodes, vport->fc_plogi_cnt,
  910. vport->fc_flag, vport->port_state);
  911. /* Check to see if there are more PLOGIs to be sent */
  912. if (vport->fc_flag & FC_NLP_MORE)
  913. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  914. sentplogi = lpfc_els_disc_plogi(vport);
  915. return;
  916. }
  917. /**
  918. * lpfc_plogi_confirm_nport: Confirm pologi wwpn matches stored ndlp.
  919. * @phba: pointer to lpfc hba data structure.
  920. * @prsp: pointer to response IOCB payload.
  921. * @ndlp: pointer to a node-list data structure.
  922. *
  923. * This routine checks and indicates whether the WWPN of an N_Port, retrieved
  924. * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
  925. * The following cases are considered N_Port confirmed:
  926. * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
  927. * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
  928. * it does not have WWPN assigned either. If the WWPN is confirmed, the
  929. * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
  930. * 1) if there is a node on vport list other than the @ndlp with the same
  931. * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
  932. * on that node to release the RPI associated with the node; 2) if there is
  933. * no node found on vport list with the same WWPN of the N_Port PLOGI logged
  934. * into, a new node shall be allocated (or activated). In either case, the
  935. * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
  936. * be released and the new_ndlp shall be put on to the vport node list and
  937. * its pointer returned as the confirmed node.
  938. *
  939. * Note that before the @ndlp got "released", the keepDID from not-matching
  940. * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
  941. * of the @ndlp. This is because the release of @ndlp is actually to put it
  942. * into an inactive state on the vport node list and the vport node list
  943. * management algorithm does not allow two node with a same DID.
  944. *
  945. * Return code
  946. * pointer to the PLOGI N_Port @ndlp
  947. **/
  948. static struct lpfc_nodelist *
  949. lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
  950. struct lpfc_nodelist *ndlp)
  951. {
  952. struct lpfc_vport *vport = ndlp->vport;
  953. struct lpfc_nodelist *new_ndlp;
  954. struct lpfc_rport_data *rdata;
  955. struct fc_rport *rport;
  956. struct serv_parm *sp;
  957. uint8_t name[sizeof(struct lpfc_name)];
  958. uint32_t rc, keepDID = 0;
  959. /* Fabric nodes can have the same WWPN so we don't bother searching
  960. * by WWPN. Just return the ndlp that was given to us.
  961. */
  962. if (ndlp->nlp_type & NLP_FABRIC)
  963. return ndlp;
  964. sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
  965. memset(name, 0, sizeof(struct lpfc_name));
  966. /* Now we find out if the NPort we are logging into, matches the WWPN
  967. * we have for that ndlp. If not, we have some work to do.
  968. */
  969. new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
  970. if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
  971. return ndlp;
  972. if (!new_ndlp) {
  973. rc = memcmp(&ndlp->nlp_portname, name,
  974. sizeof(struct lpfc_name));
  975. if (!rc)
  976. return ndlp;
  977. new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
  978. if (!new_ndlp)
  979. return ndlp;
  980. lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
  981. } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
  982. rc = memcmp(&ndlp->nlp_portname, name,
  983. sizeof(struct lpfc_name));
  984. if (!rc)
  985. return ndlp;
  986. new_ndlp = lpfc_enable_node(vport, new_ndlp,
  987. NLP_STE_UNUSED_NODE);
  988. if (!new_ndlp)
  989. return ndlp;
  990. keepDID = new_ndlp->nlp_DID;
  991. } else
  992. keepDID = new_ndlp->nlp_DID;
  993. lpfc_unreg_rpi(vport, new_ndlp);
  994. new_ndlp->nlp_DID = ndlp->nlp_DID;
  995. new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
  996. if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
  997. new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  998. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  999. /* Set state will put new_ndlp on to node list if not already done */
  1000. lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
  1001. /* Move this back to NPR state */
  1002. if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
  1003. /* The new_ndlp is replacing ndlp totally, so we need
  1004. * to put ndlp on UNUSED list and try to free it.
  1005. */
  1006. /* Fix up the rport accordingly */
  1007. rport = ndlp->rport;
  1008. if (rport) {
  1009. rdata = rport->dd_data;
  1010. if (rdata->pnode == ndlp) {
  1011. lpfc_nlp_put(ndlp);
  1012. ndlp->rport = NULL;
  1013. rdata->pnode = lpfc_nlp_get(new_ndlp);
  1014. new_ndlp->rport = rport;
  1015. }
  1016. new_ndlp->nlp_type = ndlp->nlp_type;
  1017. }
  1018. /* We shall actually free the ndlp with both nlp_DID and
  1019. * nlp_portname fields equals 0 to avoid any ndlp on the
  1020. * nodelist never to be used.
  1021. */
  1022. if (ndlp->nlp_DID == 0) {
  1023. spin_lock_irq(&phba->ndlp_lock);
  1024. NLP_SET_FREE_REQ(ndlp);
  1025. spin_unlock_irq(&phba->ndlp_lock);
  1026. }
  1027. /* Two ndlps cannot have the same did on the nodelist */
  1028. ndlp->nlp_DID = keepDID;
  1029. lpfc_drop_node(vport, ndlp);
  1030. }
  1031. else {
  1032. lpfc_unreg_rpi(vport, ndlp);
  1033. /* Two ndlps cannot have the same did */
  1034. ndlp->nlp_DID = keepDID;
  1035. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1036. }
  1037. return new_ndlp;
  1038. }
  1039. /**
  1040. * lpfc_end_rscn: Check and handle more rscn for a vport.
  1041. * @vport: pointer to a host virtual N_Port data structure.
  1042. *
  1043. * This routine checks whether more Registration State Change
  1044. * Notifications (RSCNs) came in while the discovery state machine was in
  1045. * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
  1046. * invoked to handle the additional RSCNs for the @vport. Otherwise, the
  1047. * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
  1048. * handling the RSCNs.
  1049. **/
  1050. void
  1051. lpfc_end_rscn(struct lpfc_vport *vport)
  1052. {
  1053. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1054. if (vport->fc_flag & FC_RSCN_MODE) {
  1055. /*
  1056. * Check to see if more RSCNs came in while we were
  1057. * processing this one.
  1058. */
  1059. if (vport->fc_rscn_id_cnt ||
  1060. (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
  1061. lpfc_els_handle_rscn(vport);
  1062. else {
  1063. spin_lock_irq(shost->host_lock);
  1064. vport->fc_flag &= ~FC_RSCN_MODE;
  1065. spin_unlock_irq(shost->host_lock);
  1066. }
  1067. }
  1068. }
  1069. /**
  1070. * lpfc_cmpl_els_plogi: Completion callback function for plogi.
  1071. * @phba: pointer to lpfc hba data structure.
  1072. * @cmdiocb: pointer to lpfc command iocb data structure.
  1073. * @rspiocb: pointer to lpfc response iocb data structure.
  1074. *
  1075. * This routine is the completion callback function for issuing the Port
  1076. * Login (PLOGI) command. For PLOGI completion, there must be an active
  1077. * ndlp on the vport node list that matches the remote node ID from the
  1078. * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
  1079. * ignored and command IOCB released. The PLOGI response IOCB status is
  1080. * checked for error conditons. If there is error status reported, PLOGI
  1081. * retry shall be attempted by invoking the lpfc_els_retry() routine.
  1082. * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
  1083. * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
  1084. * (DSM) is set for this PLOGI completion. Finally, it checks whether
  1085. * there are additional N_Port nodes with the vport that need to perform
  1086. * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
  1087. * PLOGIs.
  1088. **/
  1089. static void
  1090. lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1091. struct lpfc_iocbq *rspiocb)
  1092. {
  1093. struct lpfc_vport *vport = cmdiocb->vport;
  1094. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1095. IOCB_t *irsp;
  1096. struct lpfc_nodelist *ndlp;
  1097. struct lpfc_dmabuf *prsp;
  1098. int disc, rc, did, type;
  1099. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1100. cmdiocb->context_un.rsp_iocb = rspiocb;
  1101. irsp = &rspiocb->iocb;
  1102. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1103. "PLOGI cmpl: status:x%x/x%x did:x%x",
  1104. irsp->ulpStatus, irsp->un.ulpWord[4],
  1105. irsp->un.elsreq64.remoteID);
  1106. ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
  1107. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  1108. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1109. "0136 PLOGI completes to NPort x%x "
  1110. "with no ndlp. Data: x%x x%x x%x\n",
  1111. irsp->un.elsreq64.remoteID,
  1112. irsp->ulpStatus, irsp->un.ulpWord[4],
  1113. irsp->ulpIoTag);
  1114. goto out;
  1115. }
  1116. /* Since ndlp can be freed in the disc state machine, note if this node
  1117. * is being used during discovery.
  1118. */
  1119. spin_lock_irq(shost->host_lock);
  1120. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  1121. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1122. spin_unlock_irq(shost->host_lock);
  1123. rc = 0;
  1124. /* PLOGI completes to NPort <nlp_DID> */
  1125. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1126. "0102 PLOGI completes to NPort x%x "
  1127. "Data: x%x x%x x%x x%x x%x\n",
  1128. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1129. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  1130. /* Check to see if link went down during discovery */
  1131. if (lpfc_els_chk_latt(vport)) {
  1132. spin_lock_irq(shost->host_lock);
  1133. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1134. spin_unlock_irq(shost->host_lock);
  1135. goto out;
  1136. }
  1137. /* ndlp could be freed in DSM, save these values now */
  1138. type = ndlp->nlp_type;
  1139. did = ndlp->nlp_DID;
  1140. if (irsp->ulpStatus) {
  1141. /* Check for retry */
  1142. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1143. /* ELS command is being retried */
  1144. if (disc) {
  1145. spin_lock_irq(shost->host_lock);
  1146. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1147. spin_unlock_irq(shost->host_lock);
  1148. }
  1149. goto out;
  1150. }
  1151. /* PLOGI failed */
  1152. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1153. if (lpfc_error_lost_link(irsp))
  1154. rc = NLP_STE_FREED_NODE;
  1155. else
  1156. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1157. NLP_EVT_CMPL_PLOGI);
  1158. } else {
  1159. /* Good status, call state machine */
  1160. prsp = list_entry(((struct lpfc_dmabuf *)
  1161. cmdiocb->context2)->list.next,
  1162. struct lpfc_dmabuf, list);
  1163. ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
  1164. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1165. NLP_EVT_CMPL_PLOGI);
  1166. }
  1167. if (disc && vport->num_disc_nodes) {
  1168. /* Check to see if there are more PLOGIs to be sent */
  1169. lpfc_more_plogi(vport);
  1170. if (vport->num_disc_nodes == 0) {
  1171. spin_lock_irq(shost->host_lock);
  1172. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1173. spin_unlock_irq(shost->host_lock);
  1174. lpfc_can_disctmo(vport);
  1175. lpfc_end_rscn(vport);
  1176. }
  1177. }
  1178. out:
  1179. lpfc_els_free_iocb(phba, cmdiocb);
  1180. return;
  1181. }
  1182. /**
  1183. * lpfc_issue_els_plogi: Issue an plogi iocb command for a vport.
  1184. * @vport: pointer to a host virtual N_Port data structure.
  1185. * @did: destination port identifier.
  1186. * @retry: number of retries to the command IOCB.
  1187. *
  1188. * This routine issues a Port Login (PLOGI) command to a remote N_Port
  1189. * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
  1190. * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
  1191. * This routine constructs the proper feilds of the PLOGI IOCB and invokes
  1192. * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
  1193. *
  1194. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1195. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1196. * will be stored into the context1 field of the IOCB for the completion
  1197. * callback function to the PLOGI ELS command.
  1198. *
  1199. * Return code
  1200. * 0 - Successfully issued a plogi for @vport
  1201. * 1 - failed to issue a plogi for @vport
  1202. **/
  1203. int
  1204. lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
  1205. {
  1206. struct lpfc_hba *phba = vport->phba;
  1207. struct serv_parm *sp;
  1208. IOCB_t *icmd;
  1209. struct lpfc_nodelist *ndlp;
  1210. struct lpfc_iocbq *elsiocb;
  1211. struct lpfc_sli_ring *pring;
  1212. struct lpfc_sli *psli;
  1213. uint8_t *pcmd;
  1214. uint16_t cmdsize;
  1215. int ret;
  1216. psli = &phba->sli;
  1217. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1218. ndlp = lpfc_findnode_did(vport, did);
  1219. if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
  1220. ndlp = NULL;
  1221. /* If ndlp is not NULL, we will bump the reference count on it */
  1222. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  1223. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  1224. ELS_CMD_PLOGI);
  1225. if (!elsiocb)
  1226. return 1;
  1227. icmd = &elsiocb->iocb;
  1228. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1229. /* For PLOGI request, remainder of payload is service parameters */
  1230. *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
  1231. pcmd += sizeof(uint32_t);
  1232. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  1233. sp = (struct serv_parm *) pcmd;
  1234. if (sp->cmn.fcphLow < FC_PH_4_3)
  1235. sp->cmn.fcphLow = FC_PH_4_3;
  1236. if (sp->cmn.fcphHigh < FC_PH3)
  1237. sp->cmn.fcphHigh = FC_PH3;
  1238. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1239. "Issue PLOGI: did:x%x",
  1240. did, 0, 0);
  1241. phba->fc_stat.elsXmitPLOGI++;
  1242. elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
  1243. ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  1244. if (ret == IOCB_ERROR) {
  1245. lpfc_els_free_iocb(phba, elsiocb);
  1246. return 1;
  1247. }
  1248. return 0;
  1249. }
  1250. /**
  1251. * lpfc_cmpl_els_prli: Completion callback function for prli.
  1252. * @phba: pointer to lpfc hba data structure.
  1253. * @cmdiocb: pointer to lpfc command iocb data structure.
  1254. * @rspiocb: pointer to lpfc response iocb data structure.
  1255. *
  1256. * This routine is the completion callback function for a Process Login
  1257. * (PRLI) ELS command. The PRLI response IOCB status is checked for error
  1258. * status. If there is error status reported, PRLI retry shall be attempted
  1259. * by invoking the lpfc_els_retry() routine. Otherwise, the state
  1260. * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
  1261. * ndlp to mark the PRLI completion.
  1262. **/
  1263. static void
  1264. lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1265. struct lpfc_iocbq *rspiocb)
  1266. {
  1267. struct lpfc_vport *vport = cmdiocb->vport;
  1268. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1269. IOCB_t *irsp;
  1270. struct lpfc_sli *psli;
  1271. struct lpfc_nodelist *ndlp;
  1272. psli = &phba->sli;
  1273. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1274. cmdiocb->context_un.rsp_iocb = rspiocb;
  1275. irsp = &(rspiocb->iocb);
  1276. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1277. spin_lock_irq(shost->host_lock);
  1278. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  1279. spin_unlock_irq(shost->host_lock);
  1280. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1281. "PRLI cmpl: status:x%x/x%x did:x%x",
  1282. irsp->ulpStatus, irsp->un.ulpWord[4],
  1283. ndlp->nlp_DID);
  1284. /* PRLI completes to NPort <nlp_DID> */
  1285. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1286. "0103 PRLI completes to NPort x%x "
  1287. "Data: x%x x%x x%x x%x\n",
  1288. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1289. irsp->ulpTimeout, vport->num_disc_nodes);
  1290. vport->fc_prli_sent--;
  1291. /* Check to see if link went down during discovery */
  1292. if (lpfc_els_chk_latt(vport))
  1293. goto out;
  1294. if (irsp->ulpStatus) {
  1295. /* Check for retry */
  1296. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1297. /* ELS command is being retried */
  1298. goto out;
  1299. }
  1300. /* PRLI failed */
  1301. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1302. if (lpfc_error_lost_link(irsp))
  1303. goto out;
  1304. else
  1305. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1306. NLP_EVT_CMPL_PRLI);
  1307. } else
  1308. /* Good status, call state machine */
  1309. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1310. NLP_EVT_CMPL_PRLI);
  1311. out:
  1312. lpfc_els_free_iocb(phba, cmdiocb);
  1313. return;
  1314. }
  1315. /**
  1316. * lpfc_issue_els_prli: Issue a prli iocb command for a vport.
  1317. * @vport: pointer to a host virtual N_Port data structure.
  1318. * @ndlp: pointer to a node-list data structure.
  1319. * @retry: number of retries to the command IOCB.
  1320. *
  1321. * This routine issues a Process Login (PRLI) ELS command for the
  1322. * @vport. The PRLI service parameters are set up in the payload of the
  1323. * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
  1324. * is put to the IOCB completion callback func field before invoking the
  1325. * routine lpfc_sli_issue_iocb() to send out PRLI command.
  1326. *
  1327. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1328. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1329. * will be stored into the context1 field of the IOCB for the completion
  1330. * callback function to the PRLI ELS command.
  1331. *
  1332. * Return code
  1333. * 0 - successfully issued prli iocb command for @vport
  1334. * 1 - failed to issue prli iocb command for @vport
  1335. **/
  1336. int
  1337. lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1338. uint8_t retry)
  1339. {
  1340. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1341. struct lpfc_hba *phba = vport->phba;
  1342. PRLI *npr;
  1343. IOCB_t *icmd;
  1344. struct lpfc_iocbq *elsiocb;
  1345. struct lpfc_sli_ring *pring;
  1346. struct lpfc_sli *psli;
  1347. uint8_t *pcmd;
  1348. uint16_t cmdsize;
  1349. psli = &phba->sli;
  1350. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1351. cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
  1352. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1353. ndlp->nlp_DID, ELS_CMD_PRLI);
  1354. if (!elsiocb)
  1355. return 1;
  1356. icmd = &elsiocb->iocb;
  1357. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1358. /* For PRLI request, remainder of payload is service parameters */
  1359. memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
  1360. *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
  1361. pcmd += sizeof(uint32_t);
  1362. /* For PRLI, remainder of payload is PRLI parameter page */
  1363. npr = (PRLI *) pcmd;
  1364. /*
  1365. * If our firmware version is 3.20 or later,
  1366. * set the following bits for FC-TAPE support.
  1367. */
  1368. if (phba->vpd.rev.feaLevelHigh >= 0x02) {
  1369. npr->ConfmComplAllowed = 1;
  1370. npr->Retry = 1;
  1371. npr->TaskRetryIdReq = 1;
  1372. }
  1373. npr->estabImagePair = 1;
  1374. npr->readXferRdyDis = 1;
  1375. /* For FCP support */
  1376. npr->prliType = PRLI_FCP_TYPE;
  1377. npr->initiatorFunc = 1;
  1378. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1379. "Issue PRLI: did:x%x",
  1380. ndlp->nlp_DID, 0, 0);
  1381. phba->fc_stat.elsXmitPRLI++;
  1382. elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
  1383. spin_lock_irq(shost->host_lock);
  1384. ndlp->nlp_flag |= NLP_PRLI_SND;
  1385. spin_unlock_irq(shost->host_lock);
  1386. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1387. spin_lock_irq(shost->host_lock);
  1388. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  1389. spin_unlock_irq(shost->host_lock);
  1390. lpfc_els_free_iocb(phba, elsiocb);
  1391. return 1;
  1392. }
  1393. vport->fc_prli_sent++;
  1394. return 0;
  1395. }
  1396. /**
  1397. * lpfc_rscn_disc: Perform rscn discovery for a vport.
  1398. * @vport: pointer to a host virtual N_Port data structure.
  1399. *
  1400. * This routine performs Registration State Change Notification (RSCN)
  1401. * discovery for a @vport. If the @vport's node port recovery count is not
  1402. * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
  1403. * the nodes that need recovery. If none of the PLOGI were needed through
  1404. * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
  1405. * invoked to check and handle possible more RSCN came in during the period
  1406. * of processing the current ones.
  1407. **/
  1408. static void
  1409. lpfc_rscn_disc(struct lpfc_vport *vport)
  1410. {
  1411. lpfc_can_disctmo(vport);
  1412. /* RSCN discovery */
  1413. /* go thru NPR nodes and issue ELS PLOGIs */
  1414. if (vport->fc_npr_cnt)
  1415. if (lpfc_els_disc_plogi(vport))
  1416. return;
  1417. lpfc_end_rscn(vport);
  1418. }
  1419. /**
  1420. * lpfc_adisc_done: Complete the adisc phase of discovery.
  1421. * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
  1422. *
  1423. * This function is called when the final ADISC is completed during discovery.
  1424. * This function handles clearing link attention or issuing reg_vpi depending
  1425. * on whether npiv is enabled. This function also kicks off the PLOGI phase of
  1426. * discovery.
  1427. * This function is called with no locks held.
  1428. **/
  1429. static void
  1430. lpfc_adisc_done(struct lpfc_vport *vport)
  1431. {
  1432. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1433. struct lpfc_hba *phba = vport->phba;
  1434. /*
  1435. * For NPIV, cmpl_reg_vpi will set port_state to READY,
  1436. * and continue discovery.
  1437. */
  1438. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1439. !(vport->fc_flag & FC_RSCN_MODE)) {
  1440. lpfc_issue_reg_vpi(phba, vport);
  1441. return;
  1442. }
  1443. /*
  1444. * For SLI2, we need to set port_state to READY
  1445. * and continue discovery.
  1446. */
  1447. if (vport->port_state < LPFC_VPORT_READY) {
  1448. /* If we get here, there is nothing to ADISC */
  1449. if (vport->port_type == LPFC_PHYSICAL_PORT)
  1450. lpfc_issue_clear_la(phba, vport);
  1451. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  1452. vport->num_disc_nodes = 0;
  1453. /* go thru NPR list, issue ELS PLOGIs */
  1454. if (vport->fc_npr_cnt)
  1455. lpfc_els_disc_plogi(vport);
  1456. if (!vport->num_disc_nodes) {
  1457. spin_lock_irq(shost->host_lock);
  1458. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1459. spin_unlock_irq(shost->host_lock);
  1460. lpfc_can_disctmo(vport);
  1461. lpfc_end_rscn(vport);
  1462. }
  1463. }
  1464. vport->port_state = LPFC_VPORT_READY;
  1465. } else
  1466. lpfc_rscn_disc(vport);
  1467. }
  1468. /**
  1469. * lpfc_more_adisc: Issue more adisc as needed.
  1470. * @vport: pointer to a host virtual N_Port data structure.
  1471. *
  1472. * This routine determines whether there are more ndlps on a @vport
  1473. * node list need to have Address Discover (ADISC) issued. If so, it will
  1474. * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
  1475. * remaining nodes which need to have ADISC sent.
  1476. **/
  1477. void
  1478. lpfc_more_adisc(struct lpfc_vport *vport)
  1479. {
  1480. int sentadisc;
  1481. if (vport->num_disc_nodes)
  1482. vport->num_disc_nodes--;
  1483. /* Continue discovery with <num_disc_nodes> ADISCs to go */
  1484. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1485. "0210 Continue discovery with %d ADISCs to go "
  1486. "Data: x%x x%x x%x\n",
  1487. vport->num_disc_nodes, vport->fc_adisc_cnt,
  1488. vport->fc_flag, vport->port_state);
  1489. /* Check to see if there are more ADISCs to be sent */
  1490. if (vport->fc_flag & FC_NLP_MORE) {
  1491. lpfc_set_disctmo(vport);
  1492. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  1493. sentadisc = lpfc_els_disc_adisc(vport);
  1494. }
  1495. if (!vport->num_disc_nodes)
  1496. lpfc_adisc_done(vport);
  1497. return;
  1498. }
  1499. /**
  1500. * lpfc_cmpl_els_adisc: Completion callback function for adisc.
  1501. * @phba: pointer to lpfc hba data structure.
  1502. * @cmdiocb: pointer to lpfc command iocb data structure.
  1503. * @rspiocb: pointer to lpfc response iocb data structure.
  1504. *
  1505. * This routine is the completion function for issuing the Address Discover
  1506. * (ADISC) command. It first checks to see whether link went down during
  1507. * the discovery process. If so, the node will be marked as node port
  1508. * recovery for issuing discover IOCB by the link attention handler and
  1509. * exit. Otherwise, the response status is checked. If error was reported
  1510. * in the response status, the ADISC command shall be retried by invoking
  1511. * the lpfc_els_retry() routine. Otherwise, if no error was reported in
  1512. * the response status, the state machine is invoked to set transition
  1513. * with respect to NLP_EVT_CMPL_ADISC event.
  1514. **/
  1515. static void
  1516. lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1517. struct lpfc_iocbq *rspiocb)
  1518. {
  1519. struct lpfc_vport *vport = cmdiocb->vport;
  1520. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1521. IOCB_t *irsp;
  1522. struct lpfc_nodelist *ndlp;
  1523. int disc;
  1524. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1525. cmdiocb->context_un.rsp_iocb = rspiocb;
  1526. irsp = &(rspiocb->iocb);
  1527. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1528. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1529. "ADISC cmpl: status:x%x/x%x did:x%x",
  1530. irsp->ulpStatus, irsp->un.ulpWord[4],
  1531. ndlp->nlp_DID);
  1532. /* Since ndlp can be freed in the disc state machine, note if this node
  1533. * is being used during discovery.
  1534. */
  1535. spin_lock_irq(shost->host_lock);
  1536. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  1537. ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
  1538. spin_unlock_irq(shost->host_lock);
  1539. /* ADISC completes to NPort <nlp_DID> */
  1540. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1541. "0104 ADISC completes to NPort x%x "
  1542. "Data: x%x x%x x%x x%x x%x\n",
  1543. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1544. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  1545. /* Check to see if link went down during discovery */
  1546. if (lpfc_els_chk_latt(vport)) {
  1547. spin_lock_irq(shost->host_lock);
  1548. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1549. spin_unlock_irq(shost->host_lock);
  1550. goto out;
  1551. }
  1552. if (irsp->ulpStatus) {
  1553. /* Check for retry */
  1554. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1555. /* ELS command is being retried */
  1556. if (disc) {
  1557. spin_lock_irq(shost->host_lock);
  1558. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1559. spin_unlock_irq(shost->host_lock);
  1560. lpfc_set_disctmo(vport);
  1561. }
  1562. goto out;
  1563. }
  1564. /* ADISC failed */
  1565. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1566. if (!lpfc_error_lost_link(irsp))
  1567. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1568. NLP_EVT_CMPL_ADISC);
  1569. } else
  1570. /* Good status, call state machine */
  1571. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1572. NLP_EVT_CMPL_ADISC);
  1573. /* Check to see if there are more ADISCs to be sent */
  1574. if (disc && vport->num_disc_nodes)
  1575. lpfc_more_adisc(vport);
  1576. out:
  1577. lpfc_els_free_iocb(phba, cmdiocb);
  1578. return;
  1579. }
  1580. /**
  1581. * lpfc_issue_els_adisc: Issue an address discover iocb to an node on a vport.
  1582. * @vport: pointer to a virtual N_Port data structure.
  1583. * @ndlp: pointer to a node-list data structure.
  1584. * @retry: number of retries to the command IOCB.
  1585. *
  1586. * This routine issues an Address Discover (ADISC) for an @ndlp on a
  1587. * @vport. It prepares the payload of the ADISC ELS command, updates the
  1588. * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
  1589. * to issue the ADISC ELS command.
  1590. *
  1591. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1592. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1593. * will be stored into the context1 field of the IOCB for the completion
  1594. * callback function to the ADISC ELS command.
  1595. *
  1596. * Return code
  1597. * 0 - successfully issued adisc
  1598. * 1 - failed to issue adisc
  1599. **/
  1600. int
  1601. lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1602. uint8_t retry)
  1603. {
  1604. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1605. struct lpfc_hba *phba = vport->phba;
  1606. ADISC *ap;
  1607. IOCB_t *icmd;
  1608. struct lpfc_iocbq *elsiocb;
  1609. struct lpfc_sli *psli = &phba->sli;
  1610. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  1611. uint8_t *pcmd;
  1612. uint16_t cmdsize;
  1613. cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
  1614. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1615. ndlp->nlp_DID, ELS_CMD_ADISC);
  1616. if (!elsiocb)
  1617. return 1;
  1618. icmd = &elsiocb->iocb;
  1619. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1620. /* For ADISC request, remainder of payload is service parameters */
  1621. *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
  1622. pcmd += sizeof(uint32_t);
  1623. /* Fill in ADISC payload */
  1624. ap = (ADISC *) pcmd;
  1625. ap->hardAL_PA = phba->fc_pref_ALPA;
  1626. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  1627. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  1628. ap->DID = be32_to_cpu(vport->fc_myDID);
  1629. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1630. "Issue ADISC: did:x%x",
  1631. ndlp->nlp_DID, 0, 0);
  1632. phba->fc_stat.elsXmitADISC++;
  1633. elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
  1634. spin_lock_irq(shost->host_lock);
  1635. ndlp->nlp_flag |= NLP_ADISC_SND;
  1636. spin_unlock_irq(shost->host_lock);
  1637. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1638. spin_lock_irq(shost->host_lock);
  1639. ndlp->nlp_flag &= ~NLP_ADISC_SND;
  1640. spin_unlock_irq(shost->host_lock);
  1641. lpfc_els_free_iocb(phba, elsiocb);
  1642. return 1;
  1643. }
  1644. return 0;
  1645. }
  1646. /**
  1647. * lpfc_cmpl_els_logo: Completion callback function for logo.
  1648. * @phba: pointer to lpfc hba data structure.
  1649. * @cmdiocb: pointer to lpfc command iocb data structure.
  1650. * @rspiocb: pointer to lpfc response iocb data structure.
  1651. *
  1652. * This routine is the completion function for issuing the ELS Logout (LOGO)
  1653. * command. If no error status was reported from the LOGO response, the
  1654. * state machine of the associated ndlp shall be invoked for transition with
  1655. * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
  1656. * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
  1657. **/
  1658. static void
  1659. lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1660. struct lpfc_iocbq *rspiocb)
  1661. {
  1662. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1663. struct lpfc_vport *vport = ndlp->vport;
  1664. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1665. IOCB_t *irsp;
  1666. struct lpfc_sli *psli;
  1667. psli = &phba->sli;
  1668. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1669. cmdiocb->context_un.rsp_iocb = rspiocb;
  1670. irsp = &(rspiocb->iocb);
  1671. spin_lock_irq(shost->host_lock);
  1672. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  1673. spin_unlock_irq(shost->host_lock);
  1674. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1675. "LOGO cmpl: status:x%x/x%x did:x%x",
  1676. irsp->ulpStatus, irsp->un.ulpWord[4],
  1677. ndlp->nlp_DID);
  1678. /* LOGO completes to NPort <nlp_DID> */
  1679. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1680. "0105 LOGO completes to NPort x%x "
  1681. "Data: x%x x%x x%x x%x\n",
  1682. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1683. irsp->ulpTimeout, vport->num_disc_nodes);
  1684. /* Check to see if link went down during discovery */
  1685. if (lpfc_els_chk_latt(vport))
  1686. goto out;
  1687. if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
  1688. /* NLP_EVT_DEVICE_RM should unregister the RPI
  1689. * which should abort all outstanding IOs.
  1690. */
  1691. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1692. NLP_EVT_DEVICE_RM);
  1693. goto out;
  1694. }
  1695. if (irsp->ulpStatus) {
  1696. /* Check for retry */
  1697. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  1698. /* ELS command is being retried */
  1699. goto out;
  1700. /* LOGO failed */
  1701. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1702. if (lpfc_error_lost_link(irsp))
  1703. goto out;
  1704. else
  1705. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1706. NLP_EVT_CMPL_LOGO);
  1707. } else
  1708. /* Good status, call state machine.
  1709. * This will unregister the rpi if needed.
  1710. */
  1711. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1712. NLP_EVT_CMPL_LOGO);
  1713. out:
  1714. lpfc_els_free_iocb(phba, cmdiocb);
  1715. return;
  1716. }
  1717. /**
  1718. * lpfc_issue_els_logo: Issue a logo to an node on a vport.
  1719. * @vport: pointer to a virtual N_Port data structure.
  1720. * @ndlp: pointer to a node-list data structure.
  1721. * @retry: number of retries to the command IOCB.
  1722. *
  1723. * This routine constructs and issues an ELS Logout (LOGO) iocb command
  1724. * to a remote node, referred by an @ndlp on a @vport. It constructs the
  1725. * payload of the IOCB, properly sets up the @ndlp state, and invokes the
  1726. * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
  1727. *
  1728. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1729. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1730. * will be stored into the context1 field of the IOCB for the completion
  1731. * callback function to the LOGO ELS command.
  1732. *
  1733. * Return code
  1734. * 0 - successfully issued logo
  1735. * 1 - failed to issue logo
  1736. **/
  1737. int
  1738. lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1739. uint8_t retry)
  1740. {
  1741. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1742. struct lpfc_hba *phba = vport->phba;
  1743. IOCB_t *icmd;
  1744. struct lpfc_iocbq *elsiocb;
  1745. struct lpfc_sli_ring *pring;
  1746. struct lpfc_sli *psli;
  1747. uint8_t *pcmd;
  1748. uint16_t cmdsize;
  1749. int rc;
  1750. psli = &phba->sli;
  1751. pring = &psli->ring[LPFC_ELS_RING];
  1752. spin_lock_irq(shost->host_lock);
  1753. if (ndlp->nlp_flag & NLP_LOGO_SND) {
  1754. spin_unlock_irq(shost->host_lock);
  1755. return 0;
  1756. }
  1757. spin_unlock_irq(shost->host_lock);
  1758. cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
  1759. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1760. ndlp->nlp_DID, ELS_CMD_LOGO);
  1761. if (!elsiocb)
  1762. return 1;
  1763. icmd = &elsiocb->iocb;
  1764. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1765. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  1766. pcmd += sizeof(uint32_t);
  1767. /* Fill in LOGO payload */
  1768. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  1769. pcmd += sizeof(uint32_t);
  1770. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  1771. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1772. "Issue LOGO: did:x%x",
  1773. ndlp->nlp_DID, 0, 0);
  1774. phba->fc_stat.elsXmitLOGO++;
  1775. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
  1776. spin_lock_irq(shost->host_lock);
  1777. ndlp->nlp_flag |= NLP_LOGO_SND;
  1778. spin_unlock_irq(shost->host_lock);
  1779. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  1780. if (rc == IOCB_ERROR) {
  1781. spin_lock_irq(shost->host_lock);
  1782. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  1783. spin_unlock_irq(shost->host_lock);
  1784. lpfc_els_free_iocb(phba, elsiocb);
  1785. return 1;
  1786. }
  1787. return 0;
  1788. }
  1789. /**
  1790. * lpfc_cmpl_els_cmd: Completion callback function for generic els command.
  1791. * @phba: pointer to lpfc hba data structure.
  1792. * @cmdiocb: pointer to lpfc command iocb data structure.
  1793. * @rspiocb: pointer to lpfc response iocb data structure.
  1794. *
  1795. * This routine is a generic completion callback function for ELS commands.
  1796. * Specifically, it is the callback function which does not need to perform
  1797. * any command specific operations. It is currently used by the ELS command
  1798. * issuing routines for the ELS State Change Request (SCR),
  1799. * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
  1800. * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
  1801. * certain debug loggings, this callback function simply invokes the
  1802. * lpfc_els_chk_latt() routine to check whether link went down during the
  1803. * discovery process.
  1804. **/
  1805. static void
  1806. lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1807. struct lpfc_iocbq *rspiocb)
  1808. {
  1809. struct lpfc_vport *vport = cmdiocb->vport;
  1810. IOCB_t *irsp;
  1811. irsp = &rspiocb->iocb;
  1812. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1813. "ELS cmd cmpl: status:x%x/x%x did:x%x",
  1814. irsp->ulpStatus, irsp->un.ulpWord[4],
  1815. irsp->un.elsreq64.remoteID);
  1816. /* ELS cmd tag <ulpIoTag> completes */
  1817. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1818. "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
  1819. irsp->ulpIoTag, irsp->ulpStatus,
  1820. irsp->un.ulpWord[4], irsp->ulpTimeout);
  1821. /* Check to see if link went down during discovery */
  1822. lpfc_els_chk_latt(vport);
  1823. lpfc_els_free_iocb(phba, cmdiocb);
  1824. return;
  1825. }
  1826. /**
  1827. * lpfc_issue_els_scr: Issue a scr to an node on a vport.
  1828. * @vport: pointer to a host virtual N_Port data structure.
  1829. * @nportid: N_Port identifier to the remote node.
  1830. * @retry: number of retries to the command IOCB.
  1831. *
  1832. * This routine issues a State Change Request (SCR) to a fabric node
  1833. * on a @vport. The remote node @nportid is passed into the function. It
  1834. * first search the @vport node list to find the matching ndlp. If no such
  1835. * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
  1836. * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
  1837. * routine is invoked to send the SCR IOCB.
  1838. *
  1839. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1840. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1841. * will be stored into the context1 field of the IOCB for the completion
  1842. * callback function to the SCR ELS command.
  1843. *
  1844. * Return code
  1845. * 0 - Successfully issued scr command
  1846. * 1 - Failed to issue scr command
  1847. **/
  1848. int
  1849. lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  1850. {
  1851. struct lpfc_hba *phba = vport->phba;
  1852. IOCB_t *icmd;
  1853. struct lpfc_iocbq *elsiocb;
  1854. struct lpfc_sli_ring *pring;
  1855. struct lpfc_sli *psli;
  1856. uint8_t *pcmd;
  1857. uint16_t cmdsize;
  1858. struct lpfc_nodelist *ndlp;
  1859. psli = &phba->sli;
  1860. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1861. cmdsize = (sizeof(uint32_t) + sizeof(SCR));
  1862. ndlp = lpfc_findnode_did(vport, nportid);
  1863. if (!ndlp) {
  1864. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1865. if (!ndlp)
  1866. return 1;
  1867. lpfc_nlp_init(vport, ndlp, nportid);
  1868. lpfc_enqueue_node(vport, ndlp);
  1869. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  1870. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  1871. if (!ndlp)
  1872. return 1;
  1873. }
  1874. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1875. ndlp->nlp_DID, ELS_CMD_SCR);
  1876. if (!elsiocb) {
  1877. /* This will trigger the release of the node just
  1878. * allocated
  1879. */
  1880. lpfc_nlp_put(ndlp);
  1881. return 1;
  1882. }
  1883. icmd = &elsiocb->iocb;
  1884. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1885. *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
  1886. pcmd += sizeof(uint32_t);
  1887. /* For SCR, remainder of payload is SCR parameter page */
  1888. memset(pcmd, 0, sizeof(SCR));
  1889. ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
  1890. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1891. "Issue SCR: did:x%x",
  1892. ndlp->nlp_DID, 0, 0);
  1893. phba->fc_stat.elsXmitSCR++;
  1894. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  1895. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1896. /* The additional lpfc_nlp_put will cause the following
  1897. * lpfc_els_free_iocb routine to trigger the rlease of
  1898. * the node.
  1899. */
  1900. lpfc_nlp_put(ndlp);
  1901. lpfc_els_free_iocb(phba, elsiocb);
  1902. return 1;
  1903. }
  1904. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  1905. * trigger the release of node.
  1906. */
  1907. lpfc_nlp_put(ndlp);
  1908. return 0;
  1909. }
  1910. /**
  1911. * lpfc_issue_els_farpr: Issue a farp to an node on a vport.
  1912. * @vport: pointer to a host virtual N_Port data structure.
  1913. * @nportid: N_Port identifier to the remote node.
  1914. * @retry: number of retries to the command IOCB.
  1915. *
  1916. * This routine issues a Fibre Channel Address Resolution Response
  1917. * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
  1918. * is passed into the function. It first search the @vport node list to find
  1919. * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
  1920. * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
  1921. * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
  1922. *
  1923. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1924. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1925. * will be stored into the context1 field of the IOCB for the completion
  1926. * callback function to the PARPR ELS command.
  1927. *
  1928. * Return code
  1929. * 0 - Successfully issued farpr command
  1930. * 1 - Failed to issue farpr command
  1931. **/
  1932. static int
  1933. lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  1934. {
  1935. struct lpfc_hba *phba = vport->phba;
  1936. IOCB_t *icmd;
  1937. struct lpfc_iocbq *elsiocb;
  1938. struct lpfc_sli_ring *pring;
  1939. struct lpfc_sli *psli;
  1940. FARP *fp;
  1941. uint8_t *pcmd;
  1942. uint32_t *lp;
  1943. uint16_t cmdsize;
  1944. struct lpfc_nodelist *ondlp;
  1945. struct lpfc_nodelist *ndlp;
  1946. psli = &phba->sli;
  1947. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1948. cmdsize = (sizeof(uint32_t) + sizeof(FARP));
  1949. ndlp = lpfc_findnode_did(vport, nportid);
  1950. if (!ndlp) {
  1951. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1952. if (!ndlp)
  1953. return 1;
  1954. lpfc_nlp_init(vport, ndlp, nportid);
  1955. lpfc_enqueue_node(vport, ndlp);
  1956. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  1957. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  1958. if (!ndlp)
  1959. return 1;
  1960. }
  1961. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1962. ndlp->nlp_DID, ELS_CMD_RNID);
  1963. if (!elsiocb) {
  1964. /* This will trigger the release of the node just
  1965. * allocated
  1966. */
  1967. lpfc_nlp_put(ndlp);
  1968. return 1;
  1969. }
  1970. icmd = &elsiocb->iocb;
  1971. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1972. *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
  1973. pcmd += sizeof(uint32_t);
  1974. /* Fill in FARPR payload */
  1975. fp = (FARP *) (pcmd);
  1976. memset(fp, 0, sizeof(FARP));
  1977. lp = (uint32_t *) pcmd;
  1978. *lp++ = be32_to_cpu(nportid);
  1979. *lp++ = be32_to_cpu(vport->fc_myDID);
  1980. fp->Rflags = 0;
  1981. fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
  1982. memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
  1983. memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  1984. ondlp = lpfc_findnode_did(vport, nportid);
  1985. if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
  1986. memcpy(&fp->OportName, &ondlp->nlp_portname,
  1987. sizeof(struct lpfc_name));
  1988. memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
  1989. sizeof(struct lpfc_name));
  1990. }
  1991. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1992. "Issue FARPR: did:x%x",
  1993. ndlp->nlp_DID, 0, 0);
  1994. phba->fc_stat.elsXmitFARPR++;
  1995. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  1996. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1997. /* The additional lpfc_nlp_put will cause the following
  1998. * lpfc_els_free_iocb routine to trigger the release of
  1999. * the node.
  2000. */
  2001. lpfc_nlp_put(ndlp);
  2002. lpfc_els_free_iocb(phba, elsiocb);
  2003. return 1;
  2004. }
  2005. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  2006. * trigger the release of the node.
  2007. */
  2008. lpfc_nlp_put(ndlp);
  2009. return 0;
  2010. }
  2011. /**
  2012. * lpfc_cancel_retry_delay_tmo: Cancel the timer with delayed iocb-cmd retry.
  2013. * @vport: pointer to a host virtual N_Port data structure.
  2014. * @nlp: pointer to a node-list data structure.
  2015. *
  2016. * This routine cancels the timer with a delayed IOCB-command retry for
  2017. * a @vport's @ndlp. It stops the timer for the delayed function retrial and
  2018. * removes the ELS retry event if it presents. In addition, if the
  2019. * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
  2020. * commands are sent for the @vport's nodes that require issuing discovery
  2021. * ADISC.
  2022. **/
  2023. void
  2024. lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
  2025. {
  2026. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2027. struct lpfc_work_evt *evtp;
  2028. if (!(nlp->nlp_flag & NLP_DELAY_TMO))
  2029. return;
  2030. spin_lock_irq(shost->host_lock);
  2031. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  2032. spin_unlock_irq(shost->host_lock);
  2033. del_timer_sync(&nlp->nlp_delayfunc);
  2034. nlp->nlp_last_elscmd = 0;
  2035. if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
  2036. list_del_init(&nlp->els_retry_evt.evt_listp);
  2037. /* Decrement nlp reference count held for the delayed retry */
  2038. evtp = &nlp->els_retry_evt;
  2039. lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
  2040. }
  2041. if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
  2042. spin_lock_irq(shost->host_lock);
  2043. nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  2044. spin_unlock_irq(shost->host_lock);
  2045. if (vport->num_disc_nodes) {
  2046. if (vport->port_state < LPFC_VPORT_READY) {
  2047. /* Check if there are more ADISCs to be sent */
  2048. lpfc_more_adisc(vport);
  2049. } else {
  2050. /* Check if there are more PLOGIs to be sent */
  2051. lpfc_more_plogi(vport);
  2052. if (vport->num_disc_nodes == 0) {
  2053. spin_lock_irq(shost->host_lock);
  2054. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  2055. spin_unlock_irq(shost->host_lock);
  2056. lpfc_can_disctmo(vport);
  2057. lpfc_end_rscn(vport);
  2058. }
  2059. }
  2060. }
  2061. }
  2062. return;
  2063. }
  2064. /**
  2065. * lpfc_els_retry_delay: Timer function with a ndlp delayed function timer.
  2066. * @ptr: holder for the pointer to the timer function associated data (ndlp).
  2067. *
  2068. * This routine is invoked by the ndlp delayed-function timer to check
  2069. * whether there is any pending ELS retry event(s) with the node. If not, it
  2070. * simply returns. Otherwise, if there is at least one ELS delayed event, it
  2071. * adds the delayed events to the HBA work list and invokes the
  2072. * lpfc_worker_wake_up() routine to wake up worker thread to process the
  2073. * event. Note that lpfc_nlp_get() is called before posting the event to
  2074. * the work list to hold reference count of ndlp so that it guarantees the
  2075. * reference to ndlp will still be available when the worker thread gets
  2076. * to the event associated with the ndlp.
  2077. **/
  2078. void
  2079. lpfc_els_retry_delay(unsigned long ptr)
  2080. {
  2081. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
  2082. struct lpfc_vport *vport = ndlp->vport;
  2083. struct lpfc_hba *phba = vport->phba;
  2084. unsigned long flags;
  2085. struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
  2086. spin_lock_irqsave(&phba->hbalock, flags);
  2087. if (!list_empty(&evtp->evt_listp)) {
  2088. spin_unlock_irqrestore(&phba->hbalock, flags);
  2089. return;
  2090. }
  2091. /* We need to hold the node by incrementing the reference
  2092. * count until the queued work is done
  2093. */
  2094. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  2095. if (evtp->evt_arg1) {
  2096. evtp->evt = LPFC_EVT_ELS_RETRY;
  2097. list_add_tail(&evtp->evt_listp, &phba->work_list);
  2098. lpfc_worker_wake_up(phba);
  2099. }
  2100. spin_unlock_irqrestore(&phba->hbalock, flags);
  2101. return;
  2102. }
  2103. /**
  2104. * lpfc_els_retry_delay_handler: Work thread handler for ndlp delayed function.
  2105. * @ndlp: pointer to a node-list data structure.
  2106. *
  2107. * This routine is the worker-thread handler for processing the @ndlp delayed
  2108. * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
  2109. * the last ELS command from the associated ndlp and invokes the proper ELS
  2110. * function according to the delayed ELS command to retry the command.
  2111. **/
  2112. void
  2113. lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
  2114. {
  2115. struct lpfc_vport *vport = ndlp->vport;
  2116. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2117. uint32_t cmd, did, retry;
  2118. spin_lock_irq(shost->host_lock);
  2119. did = ndlp->nlp_DID;
  2120. cmd = ndlp->nlp_last_elscmd;
  2121. ndlp->nlp_last_elscmd = 0;
  2122. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  2123. spin_unlock_irq(shost->host_lock);
  2124. return;
  2125. }
  2126. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  2127. spin_unlock_irq(shost->host_lock);
  2128. /*
  2129. * If a discovery event readded nlp_delayfunc after timer
  2130. * firing and before processing the timer, cancel the
  2131. * nlp_delayfunc.
  2132. */
  2133. del_timer_sync(&ndlp->nlp_delayfunc);
  2134. retry = ndlp->nlp_retry;
  2135. switch (cmd) {
  2136. case ELS_CMD_FLOGI:
  2137. lpfc_issue_els_flogi(vport, ndlp, retry);
  2138. break;
  2139. case ELS_CMD_PLOGI:
  2140. if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
  2141. ndlp->nlp_prev_state = ndlp->nlp_state;
  2142. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2143. }
  2144. break;
  2145. case ELS_CMD_ADISC:
  2146. if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
  2147. ndlp->nlp_prev_state = ndlp->nlp_state;
  2148. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  2149. }
  2150. break;
  2151. case ELS_CMD_PRLI:
  2152. if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
  2153. ndlp->nlp_prev_state = ndlp->nlp_state;
  2154. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  2155. }
  2156. break;
  2157. case ELS_CMD_LOGO:
  2158. if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
  2159. ndlp->nlp_prev_state = ndlp->nlp_state;
  2160. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  2161. }
  2162. break;
  2163. case ELS_CMD_FDISC:
  2164. lpfc_issue_els_fdisc(vport, ndlp, retry);
  2165. break;
  2166. }
  2167. return;
  2168. }
  2169. /**
  2170. * lpfc_els_retry: Make retry decision on an els command iocb.
  2171. * @phba: pointer to lpfc hba data structure.
  2172. * @cmdiocb: pointer to lpfc command iocb data structure.
  2173. * @rspiocb: pointer to lpfc response iocb data structure.
  2174. *
  2175. * This routine makes a retry decision on an ELS command IOCB, which has
  2176. * failed. The following ELS IOCBs use this function for retrying the command
  2177. * when previously issued command responsed with error status: FLOGI, PLOGI,
  2178. * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
  2179. * returned error status, it makes the decision whether a retry shall be
  2180. * issued for the command, and whether a retry shall be made immediately or
  2181. * delayed. In the former case, the corresponding ELS command issuing-function
  2182. * is called to retry the command. In the later case, the ELS command shall
  2183. * be posted to the ndlp delayed event and delayed function timer set to the
  2184. * ndlp for the delayed command issusing.
  2185. *
  2186. * Return code
  2187. * 0 - No retry of els command is made
  2188. * 1 - Immediate or delayed retry of els command is made
  2189. **/
  2190. static int
  2191. lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2192. struct lpfc_iocbq *rspiocb)
  2193. {
  2194. struct lpfc_vport *vport = cmdiocb->vport;
  2195. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2196. IOCB_t *irsp = &rspiocb->iocb;
  2197. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2198. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2199. uint32_t *elscmd;
  2200. struct ls_rjt stat;
  2201. int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
  2202. int logerr = 0;
  2203. uint32_t cmd = 0;
  2204. uint32_t did;
  2205. /* Note: context2 may be 0 for internal driver abort
  2206. * of delays ELS command.
  2207. */
  2208. if (pcmd && pcmd->virt) {
  2209. elscmd = (uint32_t *) (pcmd->virt);
  2210. cmd = *elscmd++;
  2211. }
  2212. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  2213. did = ndlp->nlp_DID;
  2214. else {
  2215. /* We should only hit this case for retrying PLOGI */
  2216. did = irsp->un.elsreq64.remoteID;
  2217. ndlp = lpfc_findnode_did(vport, did);
  2218. if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  2219. && (cmd != ELS_CMD_PLOGI))
  2220. return 1;
  2221. }
  2222. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2223. "Retry ELS: wd7:x%x wd4:x%x did:x%x",
  2224. *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
  2225. switch (irsp->ulpStatus) {
  2226. case IOSTAT_FCP_RSP_ERROR:
  2227. case IOSTAT_REMOTE_STOP:
  2228. break;
  2229. case IOSTAT_LOCAL_REJECT:
  2230. switch ((irsp->un.ulpWord[4] & 0xff)) {
  2231. case IOERR_LOOP_OPEN_FAILURE:
  2232. if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
  2233. delay = 1000;
  2234. retry = 1;
  2235. break;
  2236. case IOERR_ILLEGAL_COMMAND:
  2237. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2238. "0124 Retry illegal cmd x%x "
  2239. "retry:x%x delay:x%x\n",
  2240. cmd, cmdiocb->retry, delay);
  2241. retry = 1;
  2242. /* All command's retry policy */
  2243. maxretry = 8;
  2244. if (cmdiocb->retry > 2)
  2245. delay = 1000;
  2246. break;
  2247. case IOERR_NO_RESOURCES:
  2248. logerr = 1; /* HBA out of resources */
  2249. retry = 1;
  2250. if (cmdiocb->retry > 100)
  2251. delay = 100;
  2252. maxretry = 250;
  2253. break;
  2254. case IOERR_ILLEGAL_FRAME:
  2255. delay = 100;
  2256. retry = 1;
  2257. break;
  2258. case IOERR_SEQUENCE_TIMEOUT:
  2259. case IOERR_INVALID_RPI:
  2260. retry = 1;
  2261. break;
  2262. }
  2263. break;
  2264. case IOSTAT_NPORT_RJT:
  2265. case IOSTAT_FABRIC_RJT:
  2266. if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  2267. retry = 1;
  2268. break;
  2269. }
  2270. break;
  2271. case IOSTAT_NPORT_BSY:
  2272. case IOSTAT_FABRIC_BSY:
  2273. logerr = 1; /* Fabric / Remote NPort out of resources */
  2274. retry = 1;
  2275. break;
  2276. case IOSTAT_LS_RJT:
  2277. stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
  2278. /* Added for Vendor specifc support
  2279. * Just keep retrying for these Rsn / Exp codes
  2280. */
  2281. switch (stat.un.b.lsRjtRsnCode) {
  2282. case LSRJT_UNABLE_TPC:
  2283. if (stat.un.b.lsRjtRsnCodeExp ==
  2284. LSEXP_CMD_IN_PROGRESS) {
  2285. if (cmd == ELS_CMD_PLOGI) {
  2286. delay = 1000;
  2287. maxretry = 48;
  2288. }
  2289. retry = 1;
  2290. break;
  2291. }
  2292. if (cmd == ELS_CMD_PLOGI) {
  2293. delay = 1000;
  2294. maxretry = lpfc_max_els_tries + 1;
  2295. retry = 1;
  2296. break;
  2297. }
  2298. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2299. (cmd == ELS_CMD_FDISC) &&
  2300. (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
  2301. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2302. "0125 FDISC Failed (x%x). "
  2303. "Fabric out of resources\n",
  2304. stat.un.lsRjtError);
  2305. lpfc_vport_set_state(vport,
  2306. FC_VPORT_NO_FABRIC_RSCS);
  2307. }
  2308. break;
  2309. case LSRJT_LOGICAL_BSY:
  2310. if ((cmd == ELS_CMD_PLOGI) ||
  2311. (cmd == ELS_CMD_PRLI)) {
  2312. delay = 1000;
  2313. maxretry = 48;
  2314. } else if (cmd == ELS_CMD_FDISC) {
  2315. /* FDISC retry policy */
  2316. maxretry = 48;
  2317. if (cmdiocb->retry >= 32)
  2318. delay = 1000;
  2319. }
  2320. retry = 1;
  2321. break;
  2322. case LSRJT_LOGICAL_ERR:
  2323. /* There are some cases where switches return this
  2324. * error when they are not ready and should be returning
  2325. * Logical Busy. We should delay every time.
  2326. */
  2327. if (cmd == ELS_CMD_FDISC &&
  2328. stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
  2329. maxretry = 3;
  2330. delay = 1000;
  2331. retry = 1;
  2332. break;
  2333. }
  2334. case LSRJT_PROTOCOL_ERR:
  2335. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2336. (cmd == ELS_CMD_FDISC) &&
  2337. ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
  2338. (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
  2339. ) {
  2340. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2341. "0122 FDISC Failed (x%x). "
  2342. "Fabric Detected Bad WWN\n",
  2343. stat.un.lsRjtError);
  2344. lpfc_vport_set_state(vport,
  2345. FC_VPORT_FABRIC_REJ_WWN);
  2346. }
  2347. break;
  2348. }
  2349. break;
  2350. case IOSTAT_INTERMED_RSP:
  2351. case IOSTAT_BA_RJT:
  2352. break;
  2353. default:
  2354. break;
  2355. }
  2356. if (did == FDMI_DID)
  2357. retry = 1;
  2358. if ((cmd == ELS_CMD_FLOGI) &&
  2359. (phba->fc_topology != TOPOLOGY_LOOP) &&
  2360. !lpfc_error_lost_link(irsp)) {
  2361. /* FLOGI retry policy */
  2362. retry = 1;
  2363. maxretry = 48;
  2364. if (cmdiocb->retry >= 32)
  2365. delay = 1000;
  2366. }
  2367. if ((++cmdiocb->retry) >= maxretry) {
  2368. phba->fc_stat.elsRetryExceeded++;
  2369. retry = 0;
  2370. }
  2371. if ((vport->load_flag & FC_UNLOADING) != 0)
  2372. retry = 0;
  2373. if (retry) {
  2374. /* Retry ELS command <elsCmd> to remote NPORT <did> */
  2375. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2376. "0107 Retry ELS command x%x to remote "
  2377. "NPORT x%x Data: x%x x%x\n",
  2378. cmd, did, cmdiocb->retry, delay);
  2379. if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
  2380. ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  2381. ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
  2382. /* Don't reset timer for no resources */
  2383. /* If discovery / RSCN timer is running, reset it */
  2384. if (timer_pending(&vport->fc_disctmo) ||
  2385. (vport->fc_flag & FC_RSCN_MODE))
  2386. lpfc_set_disctmo(vport);
  2387. }
  2388. phba->fc_stat.elsXmitRetry++;
  2389. if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
  2390. phba->fc_stat.elsDelayRetry++;
  2391. ndlp->nlp_retry = cmdiocb->retry;
  2392. /* delay is specified in milliseconds */
  2393. mod_timer(&ndlp->nlp_delayfunc,
  2394. jiffies + msecs_to_jiffies(delay));
  2395. spin_lock_irq(shost->host_lock);
  2396. ndlp->nlp_flag |= NLP_DELAY_TMO;
  2397. spin_unlock_irq(shost->host_lock);
  2398. ndlp->nlp_prev_state = ndlp->nlp_state;
  2399. if (cmd == ELS_CMD_PRLI)
  2400. lpfc_nlp_set_state(vport, ndlp,
  2401. NLP_STE_REG_LOGIN_ISSUE);
  2402. else
  2403. lpfc_nlp_set_state(vport, ndlp,
  2404. NLP_STE_NPR_NODE);
  2405. ndlp->nlp_last_elscmd = cmd;
  2406. return 1;
  2407. }
  2408. switch (cmd) {
  2409. case ELS_CMD_FLOGI:
  2410. lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
  2411. return 1;
  2412. case ELS_CMD_FDISC:
  2413. lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
  2414. return 1;
  2415. case ELS_CMD_PLOGI:
  2416. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  2417. ndlp->nlp_prev_state = ndlp->nlp_state;
  2418. lpfc_nlp_set_state(vport, ndlp,
  2419. NLP_STE_PLOGI_ISSUE);
  2420. }
  2421. lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
  2422. return 1;
  2423. case ELS_CMD_ADISC:
  2424. ndlp->nlp_prev_state = ndlp->nlp_state;
  2425. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  2426. lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
  2427. return 1;
  2428. case ELS_CMD_PRLI:
  2429. ndlp->nlp_prev_state = ndlp->nlp_state;
  2430. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  2431. lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
  2432. return 1;
  2433. case ELS_CMD_LOGO:
  2434. ndlp->nlp_prev_state = ndlp->nlp_state;
  2435. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  2436. lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
  2437. return 1;
  2438. }
  2439. }
  2440. /* No retry ELS command <elsCmd> to remote NPORT <did> */
  2441. if (logerr) {
  2442. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2443. "0137 No retry ELS command x%x to remote "
  2444. "NPORT x%x: Out of Resources: Error:x%x/%x\n",
  2445. cmd, did, irsp->ulpStatus,
  2446. irsp->un.ulpWord[4]);
  2447. }
  2448. else {
  2449. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2450. "0108 No retry ELS command x%x to remote "
  2451. "NPORT x%x Retried:%d Error:x%x/%x\n",
  2452. cmd, did, cmdiocb->retry, irsp->ulpStatus,
  2453. irsp->un.ulpWord[4]);
  2454. }
  2455. return 0;
  2456. }
  2457. /**
  2458. * lpfc_els_free_data: Free lpfc dma buffer and data structure with an iocb.
  2459. * @phba: pointer to lpfc hba data structure.
  2460. * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
  2461. *
  2462. * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
  2463. * associated with a command IOCB back to the lpfc DMA buffer pool. It first
  2464. * checks to see whether there is a lpfc DMA buffer associated with the
  2465. * response of the command IOCB. If so, it will be released before releasing
  2466. * the lpfc DMA buffer associated with the IOCB itself.
  2467. *
  2468. * Return code
  2469. * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
  2470. **/
  2471. static int
  2472. lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
  2473. {
  2474. struct lpfc_dmabuf *buf_ptr;
  2475. /* Free the response before processing the command. */
  2476. if (!list_empty(&buf_ptr1->list)) {
  2477. list_remove_head(&buf_ptr1->list, buf_ptr,
  2478. struct lpfc_dmabuf,
  2479. list);
  2480. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  2481. kfree(buf_ptr);
  2482. }
  2483. lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
  2484. kfree(buf_ptr1);
  2485. return 0;
  2486. }
  2487. /**
  2488. * lpfc_els_free_bpl: Free lpfc dma buffer and data structure with bpl.
  2489. * @phba: pointer to lpfc hba data structure.
  2490. * @buf_ptr: pointer to the lpfc dma buffer data structure.
  2491. *
  2492. * This routine releases the lpfc Direct Memory Access (DMA) buffer
  2493. * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
  2494. * pool.
  2495. *
  2496. * Return code
  2497. * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
  2498. **/
  2499. static int
  2500. lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
  2501. {
  2502. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  2503. kfree(buf_ptr);
  2504. return 0;
  2505. }
  2506. /**
  2507. * lpfc_els_free_iocb: Free a command iocb and its associated resources.
  2508. * @phba: pointer to lpfc hba data structure.
  2509. * @elsiocb: pointer to lpfc els command iocb data structure.
  2510. *
  2511. * This routine frees a command IOCB and its associated resources. The
  2512. * command IOCB data structure contains the reference to various associated
  2513. * resources, these fields must be set to NULL if the associated reference
  2514. * not present:
  2515. * context1 - reference to ndlp
  2516. * context2 - reference to cmd
  2517. * context2->next - reference to rsp
  2518. * context3 - reference to bpl
  2519. *
  2520. * It first properly decrements the reference count held on ndlp for the
  2521. * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
  2522. * set, it invokes the lpfc_els_free_data() routine to release the Direct
  2523. * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
  2524. * adds the DMA buffer the @phba data structure for the delayed release.
  2525. * If reference to the Buffer Pointer List (BPL) is present, the
  2526. * lpfc_els_free_bpl() routine is invoked to release the DMA memory
  2527. * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
  2528. * invoked to release the IOCB data structure back to @phba IOCBQ list.
  2529. *
  2530. * Return code
  2531. * 0 - Success (currently, always return 0)
  2532. **/
  2533. int
  2534. lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
  2535. {
  2536. struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
  2537. struct lpfc_nodelist *ndlp;
  2538. ndlp = (struct lpfc_nodelist *)elsiocb->context1;
  2539. if (ndlp) {
  2540. if (ndlp->nlp_flag & NLP_DEFER_RM) {
  2541. lpfc_nlp_put(ndlp);
  2542. /* If the ndlp is not being used by another discovery
  2543. * thread, free it.
  2544. */
  2545. if (!lpfc_nlp_not_used(ndlp)) {
  2546. /* If ndlp is being used by another discovery
  2547. * thread, just clear NLP_DEFER_RM
  2548. */
  2549. ndlp->nlp_flag &= ~NLP_DEFER_RM;
  2550. }
  2551. }
  2552. else
  2553. lpfc_nlp_put(ndlp);
  2554. elsiocb->context1 = NULL;
  2555. }
  2556. /* context2 = cmd, context2->next = rsp, context3 = bpl */
  2557. if (elsiocb->context2) {
  2558. if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
  2559. /* Firmware could still be in progress of DMAing
  2560. * payload, so don't free data buffer till after
  2561. * a hbeat.
  2562. */
  2563. elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
  2564. buf_ptr = elsiocb->context2;
  2565. elsiocb->context2 = NULL;
  2566. if (buf_ptr) {
  2567. buf_ptr1 = NULL;
  2568. spin_lock_irq(&phba->hbalock);
  2569. if (!list_empty(&buf_ptr->list)) {
  2570. list_remove_head(&buf_ptr->list,
  2571. buf_ptr1, struct lpfc_dmabuf,
  2572. list);
  2573. INIT_LIST_HEAD(&buf_ptr1->list);
  2574. list_add_tail(&buf_ptr1->list,
  2575. &phba->elsbuf);
  2576. phba->elsbuf_cnt++;
  2577. }
  2578. INIT_LIST_HEAD(&buf_ptr->list);
  2579. list_add_tail(&buf_ptr->list, &phba->elsbuf);
  2580. phba->elsbuf_cnt++;
  2581. spin_unlock_irq(&phba->hbalock);
  2582. }
  2583. } else {
  2584. buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
  2585. lpfc_els_free_data(phba, buf_ptr1);
  2586. }
  2587. }
  2588. if (elsiocb->context3) {
  2589. buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
  2590. lpfc_els_free_bpl(phba, buf_ptr);
  2591. }
  2592. lpfc_sli_release_iocbq(phba, elsiocb);
  2593. return 0;
  2594. }
  2595. /**
  2596. * lpfc_cmpl_els_logo_acc: Completion callback function to logo acc response.
  2597. * @phba: pointer to lpfc hba data structure.
  2598. * @cmdiocb: pointer to lpfc command iocb data structure.
  2599. * @rspiocb: pointer to lpfc response iocb data structure.
  2600. *
  2601. * This routine is the completion callback function to the Logout (LOGO)
  2602. * Accept (ACC) Response ELS command. This routine is invoked to indicate
  2603. * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
  2604. * release the ndlp if it has the last reference remaining (reference count
  2605. * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
  2606. * field to NULL to inform the following lpfc_els_free_iocb() routine no
  2607. * ndlp reference count needs to be decremented. Otherwise, the ndlp
  2608. * reference use-count shall be decremented by the lpfc_els_free_iocb()
  2609. * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
  2610. * IOCB data structure.
  2611. **/
  2612. static void
  2613. lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2614. struct lpfc_iocbq *rspiocb)
  2615. {
  2616. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2617. struct lpfc_vport *vport = cmdiocb->vport;
  2618. IOCB_t *irsp;
  2619. irsp = &rspiocb->iocb;
  2620. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2621. "ACC LOGO cmpl: status:x%x/x%x did:x%x",
  2622. irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
  2623. /* ACC to LOGO completes to NPort <nlp_DID> */
  2624. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2625. "0109 ACC to LOGO completes to NPort x%x "
  2626. "Data: x%x x%x x%x\n",
  2627. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2628. ndlp->nlp_rpi);
  2629. if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
  2630. /* NPort Recovery mode or node is just allocated */
  2631. if (!lpfc_nlp_not_used(ndlp)) {
  2632. /* If the ndlp is being used by another discovery
  2633. * thread, just unregister the RPI.
  2634. */
  2635. lpfc_unreg_rpi(vport, ndlp);
  2636. } else {
  2637. /* Indicate the node has already released, should
  2638. * not reference to it from within lpfc_els_free_iocb.
  2639. */
  2640. cmdiocb->context1 = NULL;
  2641. }
  2642. }
  2643. lpfc_els_free_iocb(phba, cmdiocb);
  2644. return;
  2645. }
  2646. /**
  2647. * lpfc_mbx_cmpl_dflt_rpi: Completion callbk func for unreg dflt rpi mbox cmd.
  2648. * @phba: pointer to lpfc hba data structure.
  2649. * @pmb: pointer to the driver internal queue element for mailbox command.
  2650. *
  2651. * This routine is the completion callback function for unregister default
  2652. * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
  2653. * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
  2654. * decrements the ndlp reference count held for this completion callback
  2655. * function. After that, it invokes the lpfc_nlp_not_used() to check
  2656. * whether there is only one reference left on the ndlp. If so, it will
  2657. * perform one more decrement and trigger the release of the ndlp.
  2658. **/
  2659. void
  2660. lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2661. {
  2662. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2663. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2664. pmb->context1 = NULL;
  2665. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2666. kfree(mp);
  2667. mempool_free(pmb, phba->mbox_mem_pool);
  2668. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  2669. lpfc_nlp_put(ndlp);
  2670. /* This is the end of the default RPI cleanup logic for this
  2671. * ndlp. If no other discovery threads are using this ndlp.
  2672. * we should free all resources associated with it.
  2673. */
  2674. lpfc_nlp_not_used(ndlp);
  2675. }
  2676. return;
  2677. }
  2678. /**
  2679. * lpfc_cmpl_els_rsp: Completion callback function for els response iocb cmd.
  2680. * @phba: pointer to lpfc hba data structure.
  2681. * @cmdiocb: pointer to lpfc command iocb data structure.
  2682. * @rspiocb: pointer to lpfc response iocb data structure.
  2683. *
  2684. * This routine is the completion callback function for ELS Response IOCB
  2685. * command. In normal case, this callback function just properly sets the
  2686. * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
  2687. * field in the command IOCB is not NULL, the referred mailbox command will
  2688. * be send out, and then invokes the lpfc_els_free_iocb() routine to release
  2689. * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
  2690. * link down event occurred during the discovery, the lpfc_nlp_not_used()
  2691. * routine shall be invoked trying to release the ndlp if no other threads
  2692. * are currently referring it.
  2693. **/
  2694. static void
  2695. lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2696. struct lpfc_iocbq *rspiocb)
  2697. {
  2698. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2699. struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
  2700. struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
  2701. IOCB_t *irsp;
  2702. uint8_t *pcmd;
  2703. LPFC_MBOXQ_t *mbox = NULL;
  2704. struct lpfc_dmabuf *mp = NULL;
  2705. uint32_t ls_rjt = 0;
  2706. irsp = &rspiocb->iocb;
  2707. if (cmdiocb->context_un.mbox)
  2708. mbox = cmdiocb->context_un.mbox;
  2709. /* First determine if this is a LS_RJT cmpl. Note, this callback
  2710. * function can have cmdiocb->contest1 (ndlp) field set to NULL.
  2711. */
  2712. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
  2713. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  2714. (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
  2715. /* A LS_RJT associated with Default RPI cleanup has its own
  2716. * seperate code path.
  2717. */
  2718. if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  2719. ls_rjt = 1;
  2720. }
  2721. /* Check to see if link went down during discovery */
  2722. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
  2723. if (mbox) {
  2724. mp = (struct lpfc_dmabuf *) mbox->context1;
  2725. if (mp) {
  2726. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2727. kfree(mp);
  2728. }
  2729. mempool_free(mbox, phba->mbox_mem_pool);
  2730. }
  2731. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  2732. (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  2733. if (lpfc_nlp_not_used(ndlp)) {
  2734. ndlp = NULL;
  2735. /* Indicate the node has already released,
  2736. * should not reference to it from within
  2737. * the routine lpfc_els_free_iocb.
  2738. */
  2739. cmdiocb->context1 = NULL;
  2740. }
  2741. goto out;
  2742. }
  2743. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2744. "ELS rsp cmpl: status:x%x/x%x did:x%x",
  2745. irsp->ulpStatus, irsp->un.ulpWord[4],
  2746. cmdiocb->iocb.un.elsreq64.remoteID);
  2747. /* ELS response tag <ulpIoTag> completes */
  2748. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2749. "0110 ELS response tag x%x completes "
  2750. "Data: x%x x%x x%x x%x x%x x%x x%x\n",
  2751. cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
  2752. rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
  2753. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2754. ndlp->nlp_rpi);
  2755. if (mbox) {
  2756. if ((rspiocb->iocb.ulpStatus == 0)
  2757. && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
  2758. lpfc_unreg_rpi(vport, ndlp);
  2759. /* Increment reference count to ndlp to hold the
  2760. * reference to ndlp for the callback function.
  2761. */
  2762. mbox->context2 = lpfc_nlp_get(ndlp);
  2763. mbox->vport = vport;
  2764. if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
  2765. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  2766. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  2767. }
  2768. else {
  2769. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  2770. ndlp->nlp_prev_state = ndlp->nlp_state;
  2771. lpfc_nlp_set_state(vport, ndlp,
  2772. NLP_STE_REG_LOGIN_ISSUE);
  2773. }
  2774. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  2775. != MBX_NOT_FINISHED)
  2776. goto out;
  2777. else
  2778. /* Decrement the ndlp reference count we
  2779. * set for this failed mailbox command.
  2780. */
  2781. lpfc_nlp_put(ndlp);
  2782. /* ELS rsp: Cannot issue reg_login for <NPortid> */
  2783. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2784. "0138 ELS rsp: Cannot issue reg_login for x%x "
  2785. "Data: x%x x%x x%x\n",
  2786. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2787. ndlp->nlp_rpi);
  2788. if (lpfc_nlp_not_used(ndlp)) {
  2789. ndlp = NULL;
  2790. /* Indicate node has already been released,
  2791. * should not reference to it from within
  2792. * the routine lpfc_els_free_iocb.
  2793. */
  2794. cmdiocb->context1 = NULL;
  2795. }
  2796. } else {
  2797. /* Do not drop node for lpfc_els_abort'ed ELS cmds */
  2798. if (!lpfc_error_lost_link(irsp) &&
  2799. ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  2800. if (lpfc_nlp_not_used(ndlp)) {
  2801. ndlp = NULL;
  2802. /* Indicate node has already been
  2803. * released, should not reference
  2804. * to it from within the routine
  2805. * lpfc_els_free_iocb.
  2806. */
  2807. cmdiocb->context1 = NULL;
  2808. }
  2809. }
  2810. }
  2811. mp = (struct lpfc_dmabuf *) mbox->context1;
  2812. if (mp) {
  2813. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2814. kfree(mp);
  2815. }
  2816. mempool_free(mbox, phba->mbox_mem_pool);
  2817. }
  2818. out:
  2819. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  2820. spin_lock_irq(shost->host_lock);
  2821. ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
  2822. spin_unlock_irq(shost->host_lock);
  2823. /* If the node is not being used by another discovery thread,
  2824. * and we are sending a reject, we are done with it.
  2825. * Release driver reference count here and free associated
  2826. * resources.
  2827. */
  2828. if (ls_rjt)
  2829. if (lpfc_nlp_not_used(ndlp))
  2830. /* Indicate node has already been released,
  2831. * should not reference to it from within
  2832. * the routine lpfc_els_free_iocb.
  2833. */
  2834. cmdiocb->context1 = NULL;
  2835. }
  2836. lpfc_els_free_iocb(phba, cmdiocb);
  2837. return;
  2838. }
  2839. /**
  2840. * lpfc_els_rsp_acc: Prepare and issue an acc response iocb command.
  2841. * @vport: pointer to a host virtual N_Port data structure.
  2842. * @flag: the els command code to be accepted.
  2843. * @oldiocb: pointer to the original lpfc command iocb data structure.
  2844. * @ndlp: pointer to a node-list data structure.
  2845. * @mbox: pointer to the driver internal queue element for mailbox command.
  2846. *
  2847. * This routine prepares and issues an Accept (ACC) response IOCB
  2848. * command. It uses the @flag to properly set up the IOCB field for the
  2849. * specific ACC response command to be issued and invokes the
  2850. * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
  2851. * @mbox pointer is passed in, it will be put into the context_un.mbox
  2852. * field of the IOCB for the completion callback function to issue the
  2853. * mailbox command to the HBA later when callback is invoked.
  2854. *
  2855. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2856. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2857. * will be stored into the context1 field of the IOCB for the completion
  2858. * callback function to the corresponding response ELS IOCB command.
  2859. *
  2860. * Return code
  2861. * 0 - Successfully issued acc response
  2862. * 1 - Failed to issue acc response
  2863. **/
  2864. int
  2865. lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
  2866. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  2867. LPFC_MBOXQ_t *mbox)
  2868. {
  2869. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2870. struct lpfc_hba *phba = vport->phba;
  2871. IOCB_t *icmd;
  2872. IOCB_t *oldcmd;
  2873. struct lpfc_iocbq *elsiocb;
  2874. struct lpfc_sli_ring *pring;
  2875. struct lpfc_sli *psli;
  2876. uint8_t *pcmd;
  2877. uint16_t cmdsize;
  2878. int rc;
  2879. ELS_PKT *els_pkt_ptr;
  2880. psli = &phba->sli;
  2881. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2882. oldcmd = &oldiocb->iocb;
  2883. switch (flag) {
  2884. case ELS_CMD_ACC:
  2885. cmdsize = sizeof(uint32_t);
  2886. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2887. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  2888. if (!elsiocb) {
  2889. spin_lock_irq(shost->host_lock);
  2890. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2891. spin_unlock_irq(shost->host_lock);
  2892. return 1;
  2893. }
  2894. icmd = &elsiocb->iocb;
  2895. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2896. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2897. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2898. pcmd += sizeof(uint32_t);
  2899. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2900. "Issue ACC: did:x%x flg:x%x",
  2901. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2902. break;
  2903. case ELS_CMD_PLOGI:
  2904. cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
  2905. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2906. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  2907. if (!elsiocb)
  2908. return 1;
  2909. icmd = &elsiocb->iocb;
  2910. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2911. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2912. if (mbox)
  2913. elsiocb->context_un.mbox = mbox;
  2914. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2915. pcmd += sizeof(uint32_t);
  2916. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  2917. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2918. "Issue ACC PLOGI: did:x%x flg:x%x",
  2919. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2920. break;
  2921. case ELS_CMD_PRLO:
  2922. cmdsize = sizeof(uint32_t) + sizeof(PRLO);
  2923. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2924. ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
  2925. if (!elsiocb)
  2926. return 1;
  2927. icmd = &elsiocb->iocb;
  2928. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2929. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2930. memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
  2931. sizeof(uint32_t) + sizeof(PRLO));
  2932. *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
  2933. els_pkt_ptr = (ELS_PKT *) pcmd;
  2934. els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
  2935. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2936. "Issue ACC PRLO: did:x%x flg:x%x",
  2937. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2938. break;
  2939. default:
  2940. return 1;
  2941. }
  2942. /* Xmit ELS ACC response tag <ulpIoTag> */
  2943. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2944. "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
  2945. "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
  2946. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2947. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2948. ndlp->nlp_rpi);
  2949. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  2950. spin_lock_irq(shost->host_lock);
  2951. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2952. spin_unlock_irq(shost->host_lock);
  2953. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
  2954. } else {
  2955. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2956. }
  2957. phba->fc_stat.elsXmitACC++;
  2958. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2959. if (rc == IOCB_ERROR) {
  2960. lpfc_els_free_iocb(phba, elsiocb);
  2961. return 1;
  2962. }
  2963. return 0;
  2964. }
  2965. /**
  2966. * lpfc_els_rsp_reject: Propare and issue a rjt response iocb command.
  2967. * @vport: pointer to a virtual N_Port data structure.
  2968. * @rejectError:
  2969. * @oldiocb: pointer to the original lpfc command iocb data structure.
  2970. * @ndlp: pointer to a node-list data structure.
  2971. * @mbox: pointer to the driver internal queue element for mailbox command.
  2972. *
  2973. * This routine prepares and issue an Reject (RJT) response IOCB
  2974. * command. If a @mbox pointer is passed in, it will be put into the
  2975. * context_un.mbox field of the IOCB for the completion callback function
  2976. * to issue to the HBA later.
  2977. *
  2978. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2979. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2980. * will be stored into the context1 field of the IOCB for the completion
  2981. * callback function to the reject response ELS IOCB command.
  2982. *
  2983. * Return code
  2984. * 0 - Successfully issued reject response
  2985. * 1 - Failed to issue reject response
  2986. **/
  2987. int
  2988. lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
  2989. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  2990. LPFC_MBOXQ_t *mbox)
  2991. {
  2992. struct lpfc_hba *phba = vport->phba;
  2993. IOCB_t *icmd;
  2994. IOCB_t *oldcmd;
  2995. struct lpfc_iocbq *elsiocb;
  2996. struct lpfc_sli_ring *pring;
  2997. struct lpfc_sli *psli;
  2998. uint8_t *pcmd;
  2999. uint16_t cmdsize;
  3000. int rc;
  3001. psli = &phba->sli;
  3002. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  3003. cmdsize = 2 * sizeof(uint32_t);
  3004. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3005. ndlp->nlp_DID, ELS_CMD_LS_RJT);
  3006. if (!elsiocb)
  3007. return 1;
  3008. icmd = &elsiocb->iocb;
  3009. oldcmd = &oldiocb->iocb;
  3010. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  3011. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3012. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  3013. pcmd += sizeof(uint32_t);
  3014. *((uint32_t *) (pcmd)) = rejectError;
  3015. if (mbox)
  3016. elsiocb->context_un.mbox = mbox;
  3017. /* Xmit ELS RJT <err> response tag <ulpIoTag> */
  3018. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3019. "0129 Xmit ELS RJT x%x response tag x%x "
  3020. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  3021. "rpi x%x\n",
  3022. rejectError, elsiocb->iotag,
  3023. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  3024. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  3025. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3026. "Issue LS_RJT: did:x%x flg:x%x err:x%x",
  3027. ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
  3028. phba->fc_stat.elsXmitLSRJT++;
  3029. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3030. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  3031. if (rc == IOCB_ERROR) {
  3032. lpfc_els_free_iocb(phba, elsiocb);
  3033. return 1;
  3034. }
  3035. return 0;
  3036. }
  3037. /**
  3038. * lpfc_els_rsp_adisc_acc: Prepare and issue acc response to adisc iocb cmd.
  3039. * @vport: pointer to a virtual N_Port data structure.
  3040. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3041. * @ndlp: pointer to a node-list data structure.
  3042. *
  3043. * This routine prepares and issues an Accept (ACC) response to Address
  3044. * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
  3045. * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
  3046. *
  3047. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3048. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3049. * will be stored into the context1 field of the IOCB for the completion
  3050. * callback function to the ADISC Accept response ELS IOCB command.
  3051. *
  3052. * Return code
  3053. * 0 - Successfully issued acc adisc response
  3054. * 1 - Failed to issue adisc acc response
  3055. **/
  3056. int
  3057. lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  3058. struct lpfc_nodelist *ndlp)
  3059. {
  3060. struct lpfc_hba *phba = vport->phba;
  3061. struct lpfc_sli *psli = &phba->sli;
  3062. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  3063. ADISC *ap;
  3064. IOCB_t *icmd, *oldcmd;
  3065. struct lpfc_iocbq *elsiocb;
  3066. uint8_t *pcmd;
  3067. uint16_t cmdsize;
  3068. int rc;
  3069. cmdsize = sizeof(uint32_t) + sizeof(ADISC);
  3070. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3071. ndlp->nlp_DID, ELS_CMD_ACC);
  3072. if (!elsiocb)
  3073. return 1;
  3074. icmd = &elsiocb->iocb;
  3075. oldcmd = &oldiocb->iocb;
  3076. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  3077. /* Xmit ADISC ACC response tag <ulpIoTag> */
  3078. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3079. "0130 Xmit ADISC ACC response iotag x%x xri: "
  3080. "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
  3081. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3082. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3083. ndlp->nlp_rpi);
  3084. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3085. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3086. pcmd += sizeof(uint32_t);
  3087. ap = (ADISC *) (pcmd);
  3088. ap->hardAL_PA = phba->fc_pref_ALPA;
  3089. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  3090. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  3091. ap->DID = be32_to_cpu(vport->fc_myDID);
  3092. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3093. "Issue ACC ADISC: did:x%x flg:x%x",
  3094. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3095. phba->fc_stat.elsXmitACC++;
  3096. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3097. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  3098. if (rc == IOCB_ERROR) {
  3099. lpfc_els_free_iocb(phba, elsiocb);
  3100. return 1;
  3101. }
  3102. return 0;
  3103. }
  3104. /**
  3105. * lpfc_els_rsp_prli_acc: Prepare and issue acc response to prli iocb cmd.
  3106. * @vport: pointer to a virtual N_Port data structure.
  3107. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3108. * @ndlp: pointer to a node-list data structure.
  3109. *
  3110. * This routine prepares and issues an Accept (ACC) response to Process
  3111. * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
  3112. * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
  3113. *
  3114. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3115. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3116. * will be stored into the context1 field of the IOCB for the completion
  3117. * callback function to the PRLI Accept response ELS IOCB command.
  3118. *
  3119. * Return code
  3120. * 0 - Successfully issued acc prli response
  3121. * 1 - Failed to issue acc prli response
  3122. **/
  3123. int
  3124. lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  3125. struct lpfc_nodelist *ndlp)
  3126. {
  3127. struct lpfc_hba *phba = vport->phba;
  3128. PRLI *npr;
  3129. lpfc_vpd_t *vpd;
  3130. IOCB_t *icmd;
  3131. IOCB_t *oldcmd;
  3132. struct lpfc_iocbq *elsiocb;
  3133. struct lpfc_sli_ring *pring;
  3134. struct lpfc_sli *psli;
  3135. uint8_t *pcmd;
  3136. uint16_t cmdsize;
  3137. int rc;
  3138. psli = &phba->sli;
  3139. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  3140. cmdsize = sizeof(uint32_t) + sizeof(PRLI);
  3141. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3142. ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
  3143. if (!elsiocb)
  3144. return 1;
  3145. icmd = &elsiocb->iocb;
  3146. oldcmd = &oldiocb->iocb;
  3147. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  3148. /* Xmit PRLI ACC response tag <ulpIoTag> */
  3149. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3150. "0131 Xmit PRLI ACC response tag x%x xri x%x, "
  3151. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  3152. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3153. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3154. ndlp->nlp_rpi);
  3155. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3156. *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
  3157. pcmd += sizeof(uint32_t);
  3158. /* For PRLI, remainder of payload is PRLI parameter page */
  3159. memset(pcmd, 0, sizeof(PRLI));
  3160. npr = (PRLI *) pcmd;
  3161. vpd = &phba->vpd;
  3162. /*
  3163. * If the remote port is a target and our firmware version is 3.20 or
  3164. * later, set the following bits for FC-TAPE support.
  3165. */
  3166. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  3167. (vpd->rev.feaLevelHigh >= 0x02)) {
  3168. npr->ConfmComplAllowed = 1;
  3169. npr->Retry = 1;
  3170. npr->TaskRetryIdReq = 1;
  3171. }
  3172. npr->acceptRspCode = PRLI_REQ_EXECUTED;
  3173. npr->estabImagePair = 1;
  3174. npr->readXferRdyDis = 1;
  3175. npr->ConfmComplAllowed = 1;
  3176. npr->prliType = PRLI_FCP_TYPE;
  3177. npr->initiatorFunc = 1;
  3178. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3179. "Issue ACC PRLI: did:x%x flg:x%x",
  3180. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3181. phba->fc_stat.elsXmitACC++;
  3182. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3183. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  3184. if (rc == IOCB_ERROR) {
  3185. lpfc_els_free_iocb(phba, elsiocb);
  3186. return 1;
  3187. }
  3188. return 0;
  3189. }
  3190. /**
  3191. * lpfc_els_rsp_rnid_acc: Issue rnid acc response iocb command.
  3192. * @vport: pointer to a virtual N_Port data structure.
  3193. * @format: rnid command format.
  3194. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3195. * @ndlp: pointer to a node-list data structure.
  3196. *
  3197. * This routine issues a Request Node Identification Data (RNID) Accept
  3198. * (ACC) response. It constructs the RNID ACC response command according to
  3199. * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
  3200. * issue the response. Note that this command does not need to hold the ndlp
  3201. * reference count for the callback. So, the ndlp reference count taken by
  3202. * the lpfc_prep_els_iocb() routine is put back and the context1 field of
  3203. * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
  3204. * there is no ndlp reference available.
  3205. *
  3206. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3207. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3208. * will be stored into the context1 field of the IOCB for the completion
  3209. * callback function. However, for the RNID Accept Response ELS command,
  3210. * this is undone later by this routine after the IOCB is allocated.
  3211. *
  3212. * Return code
  3213. * 0 - Successfully issued acc rnid response
  3214. * 1 - Failed to issue acc rnid response
  3215. **/
  3216. static int
  3217. lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
  3218. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  3219. {
  3220. struct lpfc_hba *phba = vport->phba;
  3221. RNID *rn;
  3222. IOCB_t *icmd, *oldcmd;
  3223. struct lpfc_iocbq *elsiocb;
  3224. struct lpfc_sli_ring *pring;
  3225. struct lpfc_sli *psli;
  3226. uint8_t *pcmd;
  3227. uint16_t cmdsize;
  3228. int rc;
  3229. psli = &phba->sli;
  3230. pring = &psli->ring[LPFC_ELS_RING];
  3231. cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
  3232. + (2 * sizeof(struct lpfc_name));
  3233. if (format)
  3234. cmdsize += sizeof(RNID_TOP_DISC);
  3235. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3236. ndlp->nlp_DID, ELS_CMD_ACC);
  3237. if (!elsiocb)
  3238. return 1;
  3239. icmd = &elsiocb->iocb;
  3240. oldcmd = &oldiocb->iocb;
  3241. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  3242. /* Xmit RNID ACC response tag <ulpIoTag> */
  3243. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3244. "0132 Xmit RNID ACC response tag x%x xri x%x\n",
  3245. elsiocb->iotag, elsiocb->iocb.ulpContext);
  3246. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3247. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3248. pcmd += sizeof(uint32_t);
  3249. memset(pcmd, 0, sizeof(RNID));
  3250. rn = (RNID *) (pcmd);
  3251. rn->Format = format;
  3252. rn->CommonLen = (2 * sizeof(struct lpfc_name));
  3253. memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  3254. memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  3255. switch (format) {
  3256. case 0:
  3257. rn->SpecificLen = 0;
  3258. break;
  3259. case RNID_TOPOLOGY_DISC:
  3260. rn->SpecificLen = sizeof(RNID_TOP_DISC);
  3261. memcpy(&rn->un.topologyDisc.portName,
  3262. &vport->fc_portname, sizeof(struct lpfc_name));
  3263. rn->un.topologyDisc.unitType = RNID_HBA;
  3264. rn->un.topologyDisc.physPort = 0;
  3265. rn->un.topologyDisc.attachedNodes = 0;
  3266. break;
  3267. default:
  3268. rn->CommonLen = 0;
  3269. rn->SpecificLen = 0;
  3270. break;
  3271. }
  3272. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3273. "Issue ACC RNID: did:x%x flg:x%x",
  3274. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3275. phba->fc_stat.elsXmitACC++;
  3276. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3277. lpfc_nlp_put(ndlp);
  3278. elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
  3279. * it could be freed */
  3280. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  3281. if (rc == IOCB_ERROR) {
  3282. lpfc_els_free_iocb(phba, elsiocb);
  3283. return 1;
  3284. }
  3285. return 0;
  3286. }
  3287. /**
  3288. * lpfc_els_disc_adisc: Issue remaining adisc iocbs to npr nodes of a vport.
  3289. * @vport: pointer to a host virtual N_Port data structure.
  3290. *
  3291. * This routine issues Address Discover (ADISC) ELS commands to those
  3292. * N_Ports which are in node port recovery state and ADISC has not been issued
  3293. * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
  3294. * lpfc_issue_els_adisc() routine, the per @vport number of discover count
  3295. * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
  3296. * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
  3297. * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
  3298. * IOCBs quit for later pick up. On the other hand, after walking through
  3299. * all the ndlps with the @vport and there is none ADISC IOCB issued, the
  3300. * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
  3301. * no more ADISC need to be sent.
  3302. *
  3303. * Return code
  3304. * The number of N_Ports with adisc issued.
  3305. **/
  3306. int
  3307. lpfc_els_disc_adisc(struct lpfc_vport *vport)
  3308. {
  3309. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3310. struct lpfc_nodelist *ndlp, *next_ndlp;
  3311. int sentadisc = 0;
  3312. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  3313. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  3314. if (!NLP_CHK_NODE_ACT(ndlp))
  3315. continue;
  3316. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  3317. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  3318. (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
  3319. spin_lock_irq(shost->host_lock);
  3320. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  3321. spin_unlock_irq(shost->host_lock);
  3322. ndlp->nlp_prev_state = ndlp->nlp_state;
  3323. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  3324. lpfc_issue_els_adisc(vport, ndlp, 0);
  3325. sentadisc++;
  3326. vport->num_disc_nodes++;
  3327. if (vport->num_disc_nodes >=
  3328. vport->cfg_discovery_threads) {
  3329. spin_lock_irq(shost->host_lock);
  3330. vport->fc_flag |= FC_NLP_MORE;
  3331. spin_unlock_irq(shost->host_lock);
  3332. break;
  3333. }
  3334. }
  3335. }
  3336. if (sentadisc == 0) {
  3337. spin_lock_irq(shost->host_lock);
  3338. vport->fc_flag &= ~FC_NLP_MORE;
  3339. spin_unlock_irq(shost->host_lock);
  3340. }
  3341. return sentadisc;
  3342. }
  3343. /**
  3344. * lpfc_els_disc_plogi: Issue plogi for all npr nodes of a vport before adisc.
  3345. * @vport: pointer to a host virtual N_Port data structure.
  3346. *
  3347. * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
  3348. * which are in node port recovery state, with a @vport. Each time an ELS
  3349. * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
  3350. * the per @vport number of discover count (num_disc_nodes) shall be
  3351. * incremented. If the num_disc_nodes reaches a pre-configured threshold
  3352. * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
  3353. * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
  3354. * later pick up. On the other hand, after walking through all the ndlps with
  3355. * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
  3356. * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
  3357. * PLOGI need to be sent.
  3358. *
  3359. * Return code
  3360. * The number of N_Ports with plogi issued.
  3361. **/
  3362. int
  3363. lpfc_els_disc_plogi(struct lpfc_vport *vport)
  3364. {
  3365. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3366. struct lpfc_nodelist *ndlp, *next_ndlp;
  3367. int sentplogi = 0;
  3368. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  3369. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  3370. if (!NLP_CHK_NODE_ACT(ndlp))
  3371. continue;
  3372. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  3373. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  3374. (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
  3375. (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
  3376. ndlp->nlp_prev_state = ndlp->nlp_state;
  3377. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  3378. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  3379. sentplogi++;
  3380. vport->num_disc_nodes++;
  3381. if (vport->num_disc_nodes >=
  3382. vport->cfg_discovery_threads) {
  3383. spin_lock_irq(shost->host_lock);
  3384. vport->fc_flag |= FC_NLP_MORE;
  3385. spin_unlock_irq(shost->host_lock);
  3386. break;
  3387. }
  3388. }
  3389. }
  3390. if (sentplogi) {
  3391. lpfc_set_disctmo(vport);
  3392. }
  3393. else {
  3394. spin_lock_irq(shost->host_lock);
  3395. vport->fc_flag &= ~FC_NLP_MORE;
  3396. spin_unlock_irq(shost->host_lock);
  3397. }
  3398. return sentplogi;
  3399. }
  3400. /**
  3401. * lpfc_els_flush_rscn: Clean up any rscn activities with a vport.
  3402. * @vport: pointer to a host virtual N_Port data structure.
  3403. *
  3404. * This routine cleans up any Registration State Change Notification
  3405. * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
  3406. * @vport together with the host_lock is used to prevent multiple thread
  3407. * trying to access the RSCN array on a same @vport at the same time.
  3408. **/
  3409. void
  3410. lpfc_els_flush_rscn(struct lpfc_vport *vport)
  3411. {
  3412. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3413. struct lpfc_hba *phba = vport->phba;
  3414. int i;
  3415. spin_lock_irq(shost->host_lock);
  3416. if (vport->fc_rscn_flush) {
  3417. /* Another thread is walking fc_rscn_id_list on this vport */
  3418. spin_unlock_irq(shost->host_lock);
  3419. return;
  3420. }
  3421. /* Indicate we are walking lpfc_els_flush_rscn on this vport */
  3422. vport->fc_rscn_flush = 1;
  3423. spin_unlock_irq(shost->host_lock);
  3424. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  3425. lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
  3426. vport->fc_rscn_id_list[i] = NULL;
  3427. }
  3428. spin_lock_irq(shost->host_lock);
  3429. vport->fc_rscn_id_cnt = 0;
  3430. vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
  3431. spin_unlock_irq(shost->host_lock);
  3432. lpfc_can_disctmo(vport);
  3433. /* Indicate we are done walking this fc_rscn_id_list */
  3434. vport->fc_rscn_flush = 0;
  3435. }
  3436. /**
  3437. * lpfc_rscn_payload_check: Check whether there is a pending rscn to a did.
  3438. * @vport: pointer to a host virtual N_Port data structure.
  3439. * @did: remote destination port identifier.
  3440. *
  3441. * This routine checks whether there is any pending Registration State
  3442. * Configuration Notification (RSCN) to a @did on @vport.
  3443. *
  3444. * Return code
  3445. * None zero - The @did matched with a pending rscn
  3446. * 0 - not able to match @did with a pending rscn
  3447. **/
  3448. int
  3449. lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
  3450. {
  3451. D_ID ns_did;
  3452. D_ID rscn_did;
  3453. uint32_t *lp;
  3454. uint32_t payload_len, i;
  3455. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3456. ns_did.un.word = did;
  3457. /* Never match fabric nodes for RSCNs */
  3458. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  3459. return 0;
  3460. /* If we are doing a FULL RSCN rediscovery, match everything */
  3461. if (vport->fc_flag & FC_RSCN_DISCOVERY)
  3462. return did;
  3463. spin_lock_irq(shost->host_lock);
  3464. if (vport->fc_rscn_flush) {
  3465. /* Another thread is walking fc_rscn_id_list on this vport */
  3466. spin_unlock_irq(shost->host_lock);
  3467. return 0;
  3468. }
  3469. /* Indicate we are walking fc_rscn_id_list on this vport */
  3470. vport->fc_rscn_flush = 1;
  3471. spin_unlock_irq(shost->host_lock);
  3472. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  3473. lp = vport->fc_rscn_id_list[i]->virt;
  3474. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  3475. payload_len -= sizeof(uint32_t); /* take off word 0 */
  3476. while (payload_len) {
  3477. rscn_did.un.word = be32_to_cpu(*lp++);
  3478. payload_len -= sizeof(uint32_t);
  3479. switch (rscn_did.un.b.resv) {
  3480. case 0: /* Single N_Port ID effected */
  3481. if (ns_did.un.word == rscn_did.un.word)
  3482. goto return_did_out;
  3483. break;
  3484. case 1: /* Whole N_Port Area effected */
  3485. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  3486. && (ns_did.un.b.area == rscn_did.un.b.area))
  3487. goto return_did_out;
  3488. break;
  3489. case 2: /* Whole N_Port Domain effected */
  3490. if (ns_did.un.b.domain == rscn_did.un.b.domain)
  3491. goto return_did_out;
  3492. break;
  3493. default:
  3494. /* Unknown Identifier in RSCN node */
  3495. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3496. "0217 Unknown Identifier in "
  3497. "RSCN payload Data: x%x\n",
  3498. rscn_did.un.word);
  3499. case 3: /* Whole Fabric effected */
  3500. goto return_did_out;
  3501. }
  3502. }
  3503. }
  3504. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  3505. vport->fc_rscn_flush = 0;
  3506. return 0;
  3507. return_did_out:
  3508. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  3509. vport->fc_rscn_flush = 0;
  3510. return did;
  3511. }
  3512. /**
  3513. * lpfc_rscn_recovery_check: Send recovery event to vport nodes matching rscn
  3514. * @vport: pointer to a host virtual N_Port data structure.
  3515. *
  3516. * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
  3517. * state machine for a @vport's nodes that are with pending RSCN (Registration
  3518. * State Change Notification).
  3519. *
  3520. * Return code
  3521. * 0 - Successful (currently alway return 0)
  3522. **/
  3523. static int
  3524. lpfc_rscn_recovery_check(struct lpfc_vport *vport)
  3525. {
  3526. struct lpfc_nodelist *ndlp = NULL;
  3527. /* Move all affected nodes by pending RSCNs to NPR state. */
  3528. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  3529. if (!NLP_CHK_NODE_ACT(ndlp) ||
  3530. (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
  3531. !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
  3532. continue;
  3533. lpfc_disc_state_machine(vport, ndlp, NULL,
  3534. NLP_EVT_DEVICE_RECOVERY);
  3535. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3536. }
  3537. return 0;
  3538. }
  3539. /**
  3540. * lpfc_send_rscn_event: Send an RSCN event to management application.
  3541. * @vport: pointer to a host virtual N_Port data structure.
  3542. * @cmdiocb: pointer to lpfc command iocb data structure.
  3543. *
  3544. * lpfc_send_rscn_event sends an RSCN netlink event to management
  3545. * applications.
  3546. */
  3547. static void
  3548. lpfc_send_rscn_event(struct lpfc_vport *vport,
  3549. struct lpfc_iocbq *cmdiocb)
  3550. {
  3551. struct lpfc_dmabuf *pcmd;
  3552. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3553. uint32_t *payload_ptr;
  3554. uint32_t payload_len;
  3555. struct lpfc_rscn_event_header *rscn_event_data;
  3556. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3557. payload_ptr = (uint32_t *) pcmd->virt;
  3558. payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
  3559. rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
  3560. payload_len, GFP_KERNEL);
  3561. if (!rscn_event_data) {
  3562. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3563. "0147 Failed to allocate memory for RSCN event\n");
  3564. return;
  3565. }
  3566. rscn_event_data->event_type = FC_REG_RSCN_EVENT;
  3567. rscn_event_data->payload_length = payload_len;
  3568. memcpy(rscn_event_data->rscn_payload, payload_ptr,
  3569. payload_len);
  3570. fc_host_post_vendor_event(shost,
  3571. fc_get_event_number(),
  3572. sizeof(struct lpfc_els_event_header) + payload_len,
  3573. (char *)rscn_event_data,
  3574. LPFC_NL_VENDOR_ID);
  3575. kfree(rscn_event_data);
  3576. }
  3577. /**
  3578. * lpfc_els_rcv_rscn: Process an unsolicited rscn iocb.
  3579. * @vport: pointer to a host virtual N_Port data structure.
  3580. * @cmdiocb: pointer to lpfc command iocb data structure.
  3581. * @ndlp: pointer to a node-list data structure.
  3582. *
  3583. * This routine processes an unsolicited RSCN (Registration State Change
  3584. * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
  3585. * to invoke fc_host_post_event() routine to the FC transport layer. If the
  3586. * discover state machine is about to begin discovery, it just accepts the
  3587. * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
  3588. * contains N_Port IDs for other vports on this HBA, it just accepts the
  3589. * RSCN and ignore processing it. If the state machine is in the recovery
  3590. * state, the fc_rscn_id_list of this @vport is walked and the
  3591. * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
  3592. * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
  3593. * routine is invoked to handle the RSCN event.
  3594. *
  3595. * Return code
  3596. * 0 - Just sent the acc response
  3597. * 1 - Sent the acc response and waited for name server completion
  3598. **/
  3599. static int
  3600. lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3601. struct lpfc_nodelist *ndlp)
  3602. {
  3603. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3604. struct lpfc_hba *phba = vport->phba;
  3605. struct lpfc_dmabuf *pcmd;
  3606. uint32_t *lp, *datap;
  3607. IOCB_t *icmd;
  3608. uint32_t payload_len, length, nportid, *cmd;
  3609. int rscn_cnt;
  3610. int rscn_id = 0, hba_id = 0;
  3611. int i;
  3612. icmd = &cmdiocb->iocb;
  3613. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3614. lp = (uint32_t *) pcmd->virt;
  3615. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  3616. payload_len -= sizeof(uint32_t); /* take off word 0 */
  3617. /* RSCN received */
  3618. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3619. "0214 RSCN received Data: x%x x%x x%x x%x\n",
  3620. vport->fc_flag, payload_len, *lp,
  3621. vport->fc_rscn_id_cnt);
  3622. /* Send an RSCN event to the management application */
  3623. lpfc_send_rscn_event(vport, cmdiocb);
  3624. for (i = 0; i < payload_len/sizeof(uint32_t); i++)
  3625. fc_host_post_event(shost, fc_get_event_number(),
  3626. FCH_EVT_RSCN, lp[i]);
  3627. /* If we are about to begin discovery, just ACC the RSCN.
  3628. * Discovery processing will satisfy it.
  3629. */
  3630. if (vport->port_state <= LPFC_NS_QRY) {
  3631. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3632. "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
  3633. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  3634. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  3635. return 0;
  3636. }
  3637. /* If this RSCN just contains NPortIDs for other vports on this HBA,
  3638. * just ACC and ignore it.
  3639. */
  3640. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3641. !(vport->cfg_peer_port_login)) {
  3642. i = payload_len;
  3643. datap = lp;
  3644. while (i > 0) {
  3645. nportid = *datap++;
  3646. nportid = ((be32_to_cpu(nportid)) & Mask_DID);
  3647. i -= sizeof(uint32_t);
  3648. rscn_id++;
  3649. if (lpfc_find_vport_by_did(phba, nportid))
  3650. hba_id++;
  3651. }
  3652. if (rscn_id == hba_id) {
  3653. /* ALL NPortIDs in RSCN are on HBA */
  3654. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3655. "0219 Ignore RSCN "
  3656. "Data: x%x x%x x%x x%x\n",
  3657. vport->fc_flag, payload_len,
  3658. *lp, vport->fc_rscn_id_cnt);
  3659. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3660. "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
  3661. ndlp->nlp_DID, vport->port_state,
  3662. ndlp->nlp_flag);
  3663. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
  3664. ndlp, NULL);
  3665. return 0;
  3666. }
  3667. }
  3668. spin_lock_irq(shost->host_lock);
  3669. if (vport->fc_rscn_flush) {
  3670. /* Another thread is walking fc_rscn_id_list on this vport */
  3671. spin_unlock_irq(shost->host_lock);
  3672. vport->fc_flag |= FC_RSCN_DISCOVERY;
  3673. /* Send back ACC */
  3674. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  3675. return 0;
  3676. }
  3677. /* Indicate we are walking fc_rscn_id_list on this vport */
  3678. vport->fc_rscn_flush = 1;
  3679. spin_unlock_irq(shost->host_lock);
  3680. /* Get the array count after sucessfully have the token */
  3681. rscn_cnt = vport->fc_rscn_id_cnt;
  3682. /* If we are already processing an RSCN, save the received
  3683. * RSCN payload buffer, cmdiocb->context2 to process later.
  3684. */
  3685. if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
  3686. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3687. "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
  3688. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  3689. spin_lock_irq(shost->host_lock);
  3690. vport->fc_flag |= FC_RSCN_DEFERRED;
  3691. if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
  3692. !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
  3693. vport->fc_flag |= FC_RSCN_MODE;
  3694. spin_unlock_irq(shost->host_lock);
  3695. if (rscn_cnt) {
  3696. cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
  3697. length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
  3698. }
  3699. if ((rscn_cnt) &&
  3700. (payload_len + length <= LPFC_BPL_SIZE)) {
  3701. *cmd &= ELS_CMD_MASK;
  3702. *cmd |= cpu_to_be32(payload_len + length);
  3703. memcpy(((uint8_t *)cmd) + length, lp,
  3704. payload_len);
  3705. } else {
  3706. vport->fc_rscn_id_list[rscn_cnt] = pcmd;
  3707. vport->fc_rscn_id_cnt++;
  3708. /* If we zero, cmdiocb->context2, the calling
  3709. * routine will not try to free it.
  3710. */
  3711. cmdiocb->context2 = NULL;
  3712. }
  3713. /* Deferred RSCN */
  3714. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3715. "0235 Deferred RSCN "
  3716. "Data: x%x x%x x%x\n",
  3717. vport->fc_rscn_id_cnt, vport->fc_flag,
  3718. vport->port_state);
  3719. } else {
  3720. vport->fc_flag |= FC_RSCN_DISCOVERY;
  3721. spin_unlock_irq(shost->host_lock);
  3722. /* ReDiscovery RSCN */
  3723. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3724. "0234 ReDiscovery RSCN "
  3725. "Data: x%x x%x x%x\n",
  3726. vport->fc_rscn_id_cnt, vport->fc_flag,
  3727. vport->port_state);
  3728. }
  3729. /* Indicate we are done walking fc_rscn_id_list on this vport */
  3730. vport->fc_rscn_flush = 0;
  3731. /* Send back ACC */
  3732. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  3733. /* send RECOVERY event for ALL nodes that match RSCN payload */
  3734. lpfc_rscn_recovery_check(vport);
  3735. spin_lock_irq(shost->host_lock);
  3736. vport->fc_flag &= ~FC_RSCN_DEFERRED;
  3737. spin_unlock_irq(shost->host_lock);
  3738. return 0;
  3739. }
  3740. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3741. "RCV RSCN: did:x%x/ste:x%x flg:x%x",
  3742. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  3743. spin_lock_irq(shost->host_lock);
  3744. vport->fc_flag |= FC_RSCN_MODE;
  3745. spin_unlock_irq(shost->host_lock);
  3746. vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
  3747. /* Indicate we are done walking fc_rscn_id_list on this vport */
  3748. vport->fc_rscn_flush = 0;
  3749. /*
  3750. * If we zero, cmdiocb->context2, the calling routine will
  3751. * not try to free it.
  3752. */
  3753. cmdiocb->context2 = NULL;
  3754. lpfc_set_disctmo(vport);
  3755. /* Send back ACC */
  3756. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  3757. /* send RECOVERY event for ALL nodes that match RSCN payload */
  3758. lpfc_rscn_recovery_check(vport);
  3759. return lpfc_els_handle_rscn(vport);
  3760. }
  3761. /**
  3762. * lpfc_els_handle_rscn: Handle rscn for a vport.
  3763. * @vport: pointer to a host virtual N_Port data structure.
  3764. *
  3765. * This routine handles the Registration State Configuration Notification
  3766. * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
  3767. * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
  3768. * if the ndlp to NameServer exists, a Common Transport (CT) command to the
  3769. * NameServer shall be issued. If CT command to the NameServer fails to be
  3770. * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
  3771. * RSCN activities with the @vport.
  3772. *
  3773. * Return code
  3774. * 0 - Cleaned up rscn on the @vport
  3775. * 1 - Wait for plogi to name server before proceed
  3776. **/
  3777. int
  3778. lpfc_els_handle_rscn(struct lpfc_vport *vport)
  3779. {
  3780. struct lpfc_nodelist *ndlp;
  3781. struct lpfc_hba *phba = vport->phba;
  3782. /* Ignore RSCN if the port is being torn down. */
  3783. if (vport->load_flag & FC_UNLOADING) {
  3784. lpfc_els_flush_rscn(vport);
  3785. return 0;
  3786. }
  3787. /* Start timer for RSCN processing */
  3788. lpfc_set_disctmo(vport);
  3789. /* RSCN processed */
  3790. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3791. "0215 RSCN processed Data: x%x x%x x%x x%x\n",
  3792. vport->fc_flag, 0, vport->fc_rscn_id_cnt,
  3793. vport->port_state);
  3794. /* To process RSCN, first compare RSCN data with NameServer */
  3795. vport->fc_ns_retry = 0;
  3796. vport->num_disc_nodes = 0;
  3797. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  3798. if (ndlp && NLP_CHK_NODE_ACT(ndlp)
  3799. && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  3800. /* Good ndlp, issue CT Request to NameServer */
  3801. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
  3802. /* Wait for NameServer query cmpl before we can
  3803. continue */
  3804. return 1;
  3805. } else {
  3806. /* If login to NameServer does not exist, issue one */
  3807. /* Good status, issue PLOGI to NameServer */
  3808. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  3809. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  3810. /* Wait for NameServer login cmpl before we can
  3811. continue */
  3812. return 1;
  3813. if (ndlp) {
  3814. ndlp = lpfc_enable_node(vport, ndlp,
  3815. NLP_STE_PLOGI_ISSUE);
  3816. if (!ndlp) {
  3817. lpfc_els_flush_rscn(vport);
  3818. return 0;
  3819. }
  3820. ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
  3821. } else {
  3822. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3823. if (!ndlp) {
  3824. lpfc_els_flush_rscn(vport);
  3825. return 0;
  3826. }
  3827. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  3828. ndlp->nlp_prev_state = ndlp->nlp_state;
  3829. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  3830. }
  3831. ndlp->nlp_type |= NLP_FABRIC;
  3832. lpfc_issue_els_plogi(vport, NameServer_DID, 0);
  3833. /* Wait for NameServer login cmpl before we can
  3834. * continue
  3835. */
  3836. return 1;
  3837. }
  3838. lpfc_els_flush_rscn(vport);
  3839. return 0;
  3840. }
  3841. /**
  3842. * lpfc_els_rcv_flogi: Process an unsolicited flogi iocb.
  3843. * @vport: pointer to a host virtual N_Port data structure.
  3844. * @cmdiocb: pointer to lpfc command iocb data structure.
  3845. * @ndlp: pointer to a node-list data structure.
  3846. *
  3847. * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
  3848. * unsolicited event. An unsolicited FLOGI can be received in a point-to-
  3849. * point topology. As an unsolicited FLOGI should not be received in a loop
  3850. * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
  3851. * lpfc_check_sparm() routine is invoked to check the parameters in the
  3852. * unsolicited FLOGI. If parameters validation failed, the routine
  3853. * lpfc_els_rsp_reject() shall be called with reject reason code set to
  3854. * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
  3855. * FLOGI shall be compared with the Port WWN of the @vport to determine who
  3856. * will initiate PLOGI. The higher lexicographical value party shall has
  3857. * higher priority (as the winning port) and will initiate PLOGI and
  3858. * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
  3859. * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
  3860. * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
  3861. *
  3862. * Return code
  3863. * 0 - Successfully processed the unsolicited flogi
  3864. * 1 - Failed to process the unsolicited flogi
  3865. **/
  3866. static int
  3867. lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3868. struct lpfc_nodelist *ndlp)
  3869. {
  3870. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3871. struct lpfc_hba *phba = vport->phba;
  3872. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3873. uint32_t *lp = (uint32_t *) pcmd->virt;
  3874. IOCB_t *icmd = &cmdiocb->iocb;
  3875. struct serv_parm *sp;
  3876. LPFC_MBOXQ_t *mbox;
  3877. struct ls_rjt stat;
  3878. uint32_t cmd, did;
  3879. int rc;
  3880. cmd = *lp++;
  3881. sp = (struct serv_parm *) lp;
  3882. /* FLOGI received */
  3883. lpfc_set_disctmo(vport);
  3884. if (phba->fc_topology == TOPOLOGY_LOOP) {
  3885. /* We should never receive a FLOGI in loop mode, ignore it */
  3886. did = icmd->un.elsreq64.remoteID;
  3887. /* An FLOGI ELS command <elsCmd> was received from DID <did> in
  3888. Loop Mode */
  3889. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3890. "0113 An FLOGI ELS command x%x was "
  3891. "received from DID x%x in Loop Mode\n",
  3892. cmd, did);
  3893. return 1;
  3894. }
  3895. did = Fabric_DID;
  3896. if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
  3897. /* For a FLOGI we accept, then if our portname is greater
  3898. * then the remote portname we initiate Nport login.
  3899. */
  3900. rc = memcmp(&vport->fc_portname, &sp->portName,
  3901. sizeof(struct lpfc_name));
  3902. if (!rc) {
  3903. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3904. if (!mbox)
  3905. return 1;
  3906. lpfc_linkdown(phba);
  3907. lpfc_init_link(phba, mbox,
  3908. phba->cfg_topology,
  3909. phba->cfg_link_speed);
  3910. mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
  3911. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3912. mbox->vport = vport;
  3913. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3914. lpfc_set_loopback_flag(phba);
  3915. if (rc == MBX_NOT_FINISHED) {
  3916. mempool_free(mbox, phba->mbox_mem_pool);
  3917. }
  3918. return 1;
  3919. } else if (rc > 0) { /* greater than */
  3920. spin_lock_irq(shost->host_lock);
  3921. vport->fc_flag |= FC_PT2PT_PLOGI;
  3922. spin_unlock_irq(shost->host_lock);
  3923. }
  3924. spin_lock_irq(shost->host_lock);
  3925. vport->fc_flag |= FC_PT2PT;
  3926. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  3927. spin_unlock_irq(shost->host_lock);
  3928. } else {
  3929. /* Reject this request because invalid parameters */
  3930. stat.un.b.lsRjtRsvd0 = 0;
  3931. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  3932. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  3933. stat.un.b.vendorUnique = 0;
  3934. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  3935. NULL);
  3936. return 1;
  3937. }
  3938. /* Send back ACC */
  3939. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
  3940. return 0;
  3941. }
  3942. /**
  3943. * lpfc_els_rcv_rnid: Process an unsolicited rnid iocb.
  3944. * @vport: pointer to a host virtual N_Port data structure.
  3945. * @cmdiocb: pointer to lpfc command iocb data structure.
  3946. * @ndlp: pointer to a node-list data structure.
  3947. *
  3948. * This routine processes Request Node Identification Data (RNID) IOCB
  3949. * received as an ELS unsolicited event. Only when the RNID specified format
  3950. * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
  3951. * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
  3952. * Accept (ACC) the RNID ELS command. All the other RNID formats are
  3953. * rejected by invoking the lpfc_els_rsp_reject() routine.
  3954. *
  3955. * Return code
  3956. * 0 - Successfully processed rnid iocb (currently always return 0)
  3957. **/
  3958. static int
  3959. lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3960. struct lpfc_nodelist *ndlp)
  3961. {
  3962. struct lpfc_dmabuf *pcmd;
  3963. uint32_t *lp;
  3964. IOCB_t *icmd;
  3965. RNID *rn;
  3966. struct ls_rjt stat;
  3967. uint32_t cmd, did;
  3968. icmd = &cmdiocb->iocb;
  3969. did = icmd->un.elsreq64.remoteID;
  3970. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3971. lp = (uint32_t *) pcmd->virt;
  3972. cmd = *lp++;
  3973. rn = (RNID *) lp;
  3974. /* RNID received */
  3975. switch (rn->Format) {
  3976. case 0:
  3977. case RNID_TOPOLOGY_DISC:
  3978. /* Send back ACC */
  3979. lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
  3980. break;
  3981. default:
  3982. /* Reject this request because format not supported */
  3983. stat.un.b.lsRjtRsvd0 = 0;
  3984. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  3985. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  3986. stat.un.b.vendorUnique = 0;
  3987. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  3988. NULL);
  3989. }
  3990. return 0;
  3991. }
  3992. /**
  3993. * lpfc_els_rcv_lirr: Process an unsolicited lirr iocb.
  3994. * @vport: pointer to a host virtual N_Port data structure.
  3995. * @cmdiocb: pointer to lpfc command iocb data structure.
  3996. * @ndlp: pointer to a node-list data structure.
  3997. *
  3998. * This routine processes a Link Incident Report Registration(LIRR) IOCB
  3999. * received as an ELS unsolicited event. Currently, this function just invokes
  4000. * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
  4001. *
  4002. * Return code
  4003. * 0 - Successfully processed lirr iocb (currently always return 0)
  4004. **/
  4005. static int
  4006. lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4007. struct lpfc_nodelist *ndlp)
  4008. {
  4009. struct ls_rjt stat;
  4010. /* For now, unconditionally reject this command */
  4011. stat.un.b.lsRjtRsvd0 = 0;
  4012. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  4013. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  4014. stat.un.b.vendorUnique = 0;
  4015. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  4016. return 0;
  4017. }
  4018. /**
  4019. * lpfc_els_rsp_rps_acc: Completion callbk func for MBX_READ_LNK_STAT mbox cmd.
  4020. * @phba: pointer to lpfc hba data structure.
  4021. * @pmb: pointer to the driver internal queue element for mailbox command.
  4022. *
  4023. * This routine is the completion callback function for the MBX_READ_LNK_STAT
  4024. * mailbox command. This callback function is to actually send the Accept
  4025. * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
  4026. * collects the link statistics from the completion of the MBX_READ_LNK_STAT
  4027. * mailbox command, constructs the RPS response with the link statistics
  4028. * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
  4029. * response to the RPS.
  4030. *
  4031. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4032. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4033. * will be stored into the context1 field of the IOCB for the completion
  4034. * callback function to the RPS Accept Response ELS IOCB command.
  4035. *
  4036. **/
  4037. static void
  4038. lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  4039. {
  4040. struct lpfc_sli *psli = &phba->sli;
  4041. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  4042. MAILBOX_t *mb;
  4043. IOCB_t *icmd;
  4044. RPS_RSP *rps_rsp;
  4045. uint8_t *pcmd;
  4046. struct lpfc_iocbq *elsiocb;
  4047. struct lpfc_nodelist *ndlp;
  4048. uint16_t xri, status;
  4049. uint32_t cmdsize;
  4050. mb = &pmb->mb;
  4051. ndlp = (struct lpfc_nodelist *) pmb->context2;
  4052. xri = (uint16_t) ((unsigned long)(pmb->context1));
  4053. pmb->context1 = NULL;
  4054. pmb->context2 = NULL;
  4055. if (mb->mbxStatus) {
  4056. mempool_free(pmb, phba->mbox_mem_pool);
  4057. return;
  4058. }
  4059. cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
  4060. mempool_free(pmb, phba->mbox_mem_pool);
  4061. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  4062. lpfc_max_els_tries, ndlp,
  4063. ndlp->nlp_DID, ELS_CMD_ACC);
  4064. /* Decrement the ndlp reference count from previous mbox command */
  4065. lpfc_nlp_put(ndlp);
  4066. if (!elsiocb)
  4067. return;
  4068. icmd = &elsiocb->iocb;
  4069. icmd->ulpContext = xri;
  4070. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4071. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4072. pcmd += sizeof(uint32_t); /* Skip past command */
  4073. rps_rsp = (RPS_RSP *)pcmd;
  4074. if (phba->fc_topology != TOPOLOGY_LOOP)
  4075. status = 0x10;
  4076. else
  4077. status = 0x8;
  4078. if (phba->pport->fc_flag & FC_FABRIC)
  4079. status |= 0x4;
  4080. rps_rsp->rsvd1 = 0;
  4081. rps_rsp->portStatus = cpu_to_be16(status);
  4082. rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
  4083. rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
  4084. rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
  4085. rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
  4086. rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
  4087. rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
  4088. /* Xmit ELS RPS ACC response tag <ulpIoTag> */
  4089. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  4090. "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
  4091. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  4092. elsiocb->iotag, elsiocb->iocb.ulpContext,
  4093. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4094. ndlp->nlp_rpi);
  4095. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4096. phba->fc_stat.elsXmitACC++;
  4097. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
  4098. lpfc_els_free_iocb(phba, elsiocb);
  4099. return;
  4100. }
  4101. /**
  4102. * lpfc_els_rcv_rps: Process an unsolicited rps iocb.
  4103. * @vport: pointer to a host virtual N_Port data structure.
  4104. * @cmdiocb: pointer to lpfc command iocb data structure.
  4105. * @ndlp: pointer to a node-list data structure.
  4106. *
  4107. * This routine processes Read Port Status (RPS) IOCB received as an
  4108. * ELS unsolicited event. It first checks the remote port state. If the
  4109. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  4110. * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
  4111. * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
  4112. * for reading the HBA link statistics. It is for the callback function,
  4113. * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
  4114. * to actually sending out RPS Accept (ACC) response.
  4115. *
  4116. * Return codes
  4117. * 0 - Successfully processed rps iocb (currently always return 0)
  4118. **/
  4119. static int
  4120. lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4121. struct lpfc_nodelist *ndlp)
  4122. {
  4123. struct lpfc_hba *phba = vport->phba;
  4124. uint32_t *lp;
  4125. uint8_t flag;
  4126. LPFC_MBOXQ_t *mbox;
  4127. struct lpfc_dmabuf *pcmd;
  4128. RPS *rps;
  4129. struct ls_rjt stat;
  4130. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  4131. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  4132. /* reject the unsolicited RPS request and done with it */
  4133. goto reject_out;
  4134. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4135. lp = (uint32_t *) pcmd->virt;
  4136. flag = (be32_to_cpu(*lp++) & 0xf);
  4137. rps = (RPS *) lp;
  4138. if ((flag == 0) ||
  4139. ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
  4140. ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
  4141. sizeof(struct lpfc_name)) == 0))) {
  4142. printk("Fix me....\n");
  4143. dump_stack();
  4144. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
  4145. if (mbox) {
  4146. lpfc_read_lnk_stat(phba, mbox);
  4147. mbox->context1 =
  4148. (void *)((unsigned long) cmdiocb->iocb.ulpContext);
  4149. mbox->context2 = lpfc_nlp_get(ndlp);
  4150. mbox->vport = vport;
  4151. mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
  4152. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  4153. != MBX_NOT_FINISHED)
  4154. /* Mbox completion will send ELS Response */
  4155. return 0;
  4156. /* Decrement reference count used for the failed mbox
  4157. * command.
  4158. */
  4159. lpfc_nlp_put(ndlp);
  4160. mempool_free(mbox, phba->mbox_mem_pool);
  4161. }
  4162. }
  4163. reject_out:
  4164. /* issue rejection response */
  4165. stat.un.b.lsRjtRsvd0 = 0;
  4166. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  4167. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  4168. stat.un.b.vendorUnique = 0;
  4169. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  4170. return 0;
  4171. }
  4172. /**
  4173. * lpfc_els_rsp_rpl_acc: Issue an accept rpl els command.
  4174. * @vport: pointer to a host virtual N_Port data structure.
  4175. * @cmdsize: size of the ELS command.
  4176. * @oldiocb: pointer to the original lpfc command iocb data structure.
  4177. * @ndlp: pointer to a node-list data structure.
  4178. *
  4179. * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
  4180. * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
  4181. *
  4182. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4183. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4184. * will be stored into the context1 field of the IOCB for the completion
  4185. * callback function to the RPL Accept Response ELS command.
  4186. *
  4187. * Return code
  4188. * 0 - Successfully issued ACC RPL ELS command
  4189. * 1 - Failed to issue ACC RPL ELS command
  4190. **/
  4191. static int
  4192. lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
  4193. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  4194. {
  4195. struct lpfc_hba *phba = vport->phba;
  4196. IOCB_t *icmd, *oldcmd;
  4197. RPL_RSP rpl_rsp;
  4198. struct lpfc_iocbq *elsiocb;
  4199. struct lpfc_sli *psli = &phba->sli;
  4200. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  4201. uint8_t *pcmd;
  4202. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  4203. ndlp->nlp_DID, ELS_CMD_ACC);
  4204. if (!elsiocb)
  4205. return 1;
  4206. icmd = &elsiocb->iocb;
  4207. oldcmd = &oldiocb->iocb;
  4208. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  4209. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4210. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4211. pcmd += sizeof(uint16_t);
  4212. *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
  4213. pcmd += sizeof(uint16_t);
  4214. /* Setup the RPL ACC payload */
  4215. rpl_rsp.listLen = be32_to_cpu(1);
  4216. rpl_rsp.index = 0;
  4217. rpl_rsp.port_num_blk.portNum = 0;
  4218. rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
  4219. memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
  4220. sizeof(struct lpfc_name));
  4221. memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
  4222. /* Xmit ELS RPL ACC response tag <ulpIoTag> */
  4223. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4224. "0120 Xmit ELS RPL ACC response tag x%x "
  4225. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  4226. "rpi x%x\n",
  4227. elsiocb->iotag, elsiocb->iocb.ulpContext,
  4228. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4229. ndlp->nlp_rpi);
  4230. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4231. phba->fc_stat.elsXmitACC++;
  4232. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  4233. lpfc_els_free_iocb(phba, elsiocb);
  4234. return 1;
  4235. }
  4236. return 0;
  4237. }
  4238. /**
  4239. * lpfc_els_rcv_rpl: Process an unsolicited rpl iocb.
  4240. * @vport: pointer to a host virtual N_Port data structure.
  4241. * @cmdiocb: pointer to lpfc command iocb data structure.
  4242. * @ndlp: pointer to a node-list data structure.
  4243. *
  4244. * This routine processes Read Port List (RPL) IOCB received as an ELS
  4245. * unsolicited event. It first checks the remote port state. If the remote
  4246. * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
  4247. * invokes the lpfc_els_rsp_reject() routine to send reject response.
  4248. * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
  4249. * to accept the RPL.
  4250. *
  4251. * Return code
  4252. * 0 - Successfully processed rpl iocb (currently always return 0)
  4253. **/
  4254. static int
  4255. lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4256. struct lpfc_nodelist *ndlp)
  4257. {
  4258. struct lpfc_dmabuf *pcmd;
  4259. uint32_t *lp;
  4260. uint32_t maxsize;
  4261. uint16_t cmdsize;
  4262. RPL *rpl;
  4263. struct ls_rjt stat;
  4264. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  4265. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  4266. /* issue rejection response */
  4267. stat.un.b.lsRjtRsvd0 = 0;
  4268. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  4269. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  4270. stat.un.b.vendorUnique = 0;
  4271. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  4272. NULL);
  4273. /* rejected the unsolicited RPL request and done with it */
  4274. return 0;
  4275. }
  4276. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4277. lp = (uint32_t *) pcmd->virt;
  4278. rpl = (RPL *) (lp + 1);
  4279. maxsize = be32_to_cpu(rpl->maxsize);
  4280. /* We support only one port */
  4281. if ((rpl->index == 0) &&
  4282. ((maxsize == 0) ||
  4283. ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
  4284. cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
  4285. } else {
  4286. cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
  4287. }
  4288. lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
  4289. return 0;
  4290. }
  4291. /**
  4292. * lpfc_els_rcv_farp: Process an unsolicited farp request els command.
  4293. * @vport: pointer to a virtual N_Port data structure.
  4294. * @cmdiocb: pointer to lpfc command iocb data structure.
  4295. * @ndlp: pointer to a node-list data structure.
  4296. *
  4297. * This routine processes Fibre Channel Address Resolution Protocol
  4298. * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
  4299. * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
  4300. * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
  4301. * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
  4302. * remote PortName is compared against the FC PortName stored in the @vport
  4303. * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
  4304. * compared against the FC NodeName stored in the @vport data structure.
  4305. * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
  4306. * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
  4307. * invoked to send out FARP Response to the remote node. Before sending the
  4308. * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
  4309. * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
  4310. * routine is invoked to log into the remote port first.
  4311. *
  4312. * Return code
  4313. * 0 - Either the FARP Match Mode not supported or successfully processed
  4314. **/
  4315. static int
  4316. lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4317. struct lpfc_nodelist *ndlp)
  4318. {
  4319. struct lpfc_dmabuf *pcmd;
  4320. uint32_t *lp;
  4321. IOCB_t *icmd;
  4322. FARP *fp;
  4323. uint32_t cmd, cnt, did;
  4324. icmd = &cmdiocb->iocb;
  4325. did = icmd->un.elsreq64.remoteID;
  4326. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4327. lp = (uint32_t *) pcmd->virt;
  4328. cmd = *lp++;
  4329. fp = (FARP *) lp;
  4330. /* FARP-REQ received from DID <did> */
  4331. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4332. "0601 FARP-REQ received from DID x%x\n", did);
  4333. /* We will only support match on WWPN or WWNN */
  4334. if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
  4335. return 0;
  4336. }
  4337. cnt = 0;
  4338. /* If this FARP command is searching for my portname */
  4339. if (fp->Mflags & FARP_MATCH_PORT) {
  4340. if (memcmp(&fp->RportName, &vport->fc_portname,
  4341. sizeof(struct lpfc_name)) == 0)
  4342. cnt = 1;
  4343. }
  4344. /* If this FARP command is searching for my nodename */
  4345. if (fp->Mflags & FARP_MATCH_NODE) {
  4346. if (memcmp(&fp->RnodeName, &vport->fc_nodename,
  4347. sizeof(struct lpfc_name)) == 0)
  4348. cnt = 1;
  4349. }
  4350. if (cnt) {
  4351. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  4352. (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
  4353. /* Log back into the node before sending the FARP. */
  4354. if (fp->Rflags & FARP_REQUEST_PLOGI) {
  4355. ndlp->nlp_prev_state = ndlp->nlp_state;
  4356. lpfc_nlp_set_state(vport, ndlp,
  4357. NLP_STE_PLOGI_ISSUE);
  4358. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  4359. }
  4360. /* Send a FARP response to that node */
  4361. if (fp->Rflags & FARP_REQUEST_FARPR)
  4362. lpfc_issue_els_farpr(vport, did, 0);
  4363. }
  4364. }
  4365. return 0;
  4366. }
  4367. /**
  4368. * lpfc_els_rcv_farpr: Process an unsolicited farp response iocb.
  4369. * @vport: pointer to a host virtual N_Port data structure.
  4370. * @cmdiocb: pointer to lpfc command iocb data structure.
  4371. * @ndlp: pointer to a node-list data structure.
  4372. *
  4373. * This routine processes Fibre Channel Address Resolution Protocol
  4374. * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
  4375. * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
  4376. * the FARP response request.
  4377. *
  4378. * Return code
  4379. * 0 - Successfully processed FARPR IOCB (currently always return 0)
  4380. **/
  4381. static int
  4382. lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4383. struct lpfc_nodelist *ndlp)
  4384. {
  4385. struct lpfc_dmabuf *pcmd;
  4386. uint32_t *lp;
  4387. IOCB_t *icmd;
  4388. uint32_t cmd, did;
  4389. icmd = &cmdiocb->iocb;
  4390. did = icmd->un.elsreq64.remoteID;
  4391. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4392. lp = (uint32_t *) pcmd->virt;
  4393. cmd = *lp++;
  4394. /* FARP-RSP received from DID <did> */
  4395. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4396. "0600 FARP-RSP received from DID x%x\n", did);
  4397. /* ACCEPT the Farp resp request */
  4398. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4399. return 0;
  4400. }
  4401. /**
  4402. * lpfc_els_rcv_fan: Process an unsolicited fan iocb command.
  4403. * @vport: pointer to a host virtual N_Port data structure.
  4404. * @cmdiocb: pointer to lpfc command iocb data structure.
  4405. * @fan_ndlp: pointer to a node-list data structure.
  4406. *
  4407. * This routine processes a Fabric Address Notification (FAN) IOCB
  4408. * command received as an ELS unsolicited event. The FAN ELS command will
  4409. * only be processed on a physical port (i.e., the @vport represents the
  4410. * physical port). The fabric NodeName and PortName from the FAN IOCB are
  4411. * compared against those in the phba data structure. If any of those is
  4412. * different, the lpfc_initial_flogi() routine is invoked to initialize
  4413. * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
  4414. * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
  4415. * is invoked to register login to the fabric.
  4416. *
  4417. * Return code
  4418. * 0 - Successfully processed fan iocb (currently always return 0).
  4419. **/
  4420. static int
  4421. lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4422. struct lpfc_nodelist *fan_ndlp)
  4423. {
  4424. struct lpfc_hba *phba = vport->phba;
  4425. uint32_t *lp;
  4426. FAN *fp;
  4427. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
  4428. lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
  4429. fp = (FAN *) ++lp;
  4430. /* FAN received; Fan does not have a reply sequence */
  4431. if ((vport == phba->pport) &&
  4432. (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
  4433. if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
  4434. sizeof(struct lpfc_name))) ||
  4435. (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
  4436. sizeof(struct lpfc_name)))) {
  4437. /* This port has switched fabrics. FLOGI is required */
  4438. lpfc_initial_flogi(vport);
  4439. } else {
  4440. /* FAN verified - skip FLOGI */
  4441. vport->fc_myDID = vport->fc_prevDID;
  4442. lpfc_issue_fabric_reglogin(vport);
  4443. }
  4444. }
  4445. return 0;
  4446. }
  4447. /**
  4448. * lpfc_els_timeout: Handler funciton to the els timer.
  4449. * @ptr: holder for the timer function associated data.
  4450. *
  4451. * This routine is invoked by the ELS timer after timeout. It posts the ELS
  4452. * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
  4453. * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
  4454. * up the worker thread. It is for the worker thread to invoke the routine
  4455. * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
  4456. **/
  4457. void
  4458. lpfc_els_timeout(unsigned long ptr)
  4459. {
  4460. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  4461. struct lpfc_hba *phba = vport->phba;
  4462. uint32_t tmo_posted;
  4463. unsigned long iflag;
  4464. spin_lock_irqsave(&vport->work_port_lock, iflag);
  4465. tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
  4466. if (!tmo_posted)
  4467. vport->work_port_events |= WORKER_ELS_TMO;
  4468. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  4469. if (!tmo_posted)
  4470. lpfc_worker_wake_up(phba);
  4471. return;
  4472. }
  4473. /**
  4474. * lpfc_els_timeout_handler: Process an els timeout event.
  4475. * @vport: pointer to a virtual N_Port data structure.
  4476. *
  4477. * This routine is the actual handler function that processes an ELS timeout
  4478. * event. It walks the ELS ring to get and abort all the IOCBs (except the
  4479. * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
  4480. * invoking the lpfc_sli_issue_abort_iotag() routine.
  4481. **/
  4482. void
  4483. lpfc_els_timeout_handler(struct lpfc_vport *vport)
  4484. {
  4485. struct lpfc_hba *phba = vport->phba;
  4486. struct lpfc_sli_ring *pring;
  4487. struct lpfc_iocbq *tmp_iocb, *piocb;
  4488. IOCB_t *cmd = NULL;
  4489. struct lpfc_dmabuf *pcmd;
  4490. uint32_t els_command = 0;
  4491. uint32_t timeout;
  4492. uint32_t remote_ID = 0xffffffff;
  4493. /* If the timer is already canceled do nothing */
  4494. if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
  4495. return;
  4496. }
  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. }