lpfc_els.c 234 KB

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