lpfc_els.c 235 KB

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