lpfc_els.c 247 KB

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