lpfc_els.c 219 KB

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