lpfc_els.c 248 KB

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