lpfc_els.c 249 KB

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