lpfc_els.c 289 KB

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