lpfc_init.c 462 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  10. * *
  11. * This program is free software; you can redistribute it and/or *
  12. * modify it under the terms of version 2 of the GNU General *
  13. * Public License as published by the Free Software Foundation. *
  14. * This program is distributed in the hope that it will be useful. *
  15. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  16. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  17. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  18. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  19. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  20. * more details, a copy of which can be found in the file COPYING *
  21. * included with this package. *
  22. *******************************************************************/
  23. #include <linux/blkdev.h>
  24. #include <linux/delay.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/idr.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/module.h>
  29. #include <linux/kthread.h>
  30. #include <linux/pci.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/ctype.h>
  33. #include <linux/aer.h>
  34. #include <linux/slab.h>
  35. #include <linux/firmware.h>
  36. #include <linux/miscdevice.h>
  37. #include <linux/percpu.h>
  38. #include <linux/msi.h>
  39. #include <linux/irq.h>
  40. #include <linux/bitops.h>
  41. #include <linux/crash_dump.h>
  42. #include <linux/cpu.h>
  43. #include <linux/cpuhotplug.h>
  44. #include <scsi/scsi.h>
  45. #include <scsi/scsi_device.h>
  46. #include <scsi/scsi_host.h>
  47. #include <scsi/scsi_transport_fc.h>
  48. #include <scsi/scsi_tcq.h>
  49. #include <scsi/fc/fc_fs.h>
  50. #include "lpfc_hw4.h"
  51. #include "lpfc_hw.h"
  52. #include "lpfc_sli.h"
  53. #include "lpfc_sli4.h"
  54. #include "lpfc_nl.h"
  55. #include "lpfc_disc.h"
  56. #include "lpfc.h"
  57. #include "lpfc_scsi.h"
  58. #include "lpfc_nvme.h"
  59. #include "lpfc_logmsg.h"
  60. #include "lpfc_crtn.h"
  61. #include "lpfc_vport.h"
  62. #include "lpfc_version.h"
  63. #include "lpfc_ids.h"
  64. static enum cpuhp_state lpfc_cpuhp_state;
  65. /* Used when mapping IRQ vectors in a driver centric manner */
  66. static uint32_t lpfc_present_cpu;
  67. static bool lpfc_pldv_detect;
  68. static void __lpfc_cpuhp_remove(struct lpfc_hba *phba);
  69. static void lpfc_cpuhp_remove(struct lpfc_hba *phba);
  70. static void lpfc_cpuhp_add(struct lpfc_hba *phba);
  71. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  72. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  73. static int lpfc_sli4_queue_verify(struct lpfc_hba *);
  74. static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
  75. static int lpfc_setup_endian_order(struct lpfc_hba *);
  76. static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
  77. static void lpfc_free_els_sgl_list(struct lpfc_hba *);
  78. static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
  79. static void lpfc_init_sgl_list(struct lpfc_hba *);
  80. static int lpfc_init_active_sgl_array(struct lpfc_hba *);
  81. static void lpfc_free_active_sgl(struct lpfc_hba *);
  82. static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
  83. static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
  84. static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
  85. static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
  86. static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
  87. static void lpfc_sli4_disable_intr(struct lpfc_hba *);
  88. static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
  89. static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
  90. static uint16_t lpfc_find_cpu_handle(struct lpfc_hba *, uint16_t, int);
  91. static void lpfc_setup_bg(struct lpfc_hba *, struct Scsi_Host *);
  92. static int lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *);
  93. static void lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba);
  94. static struct scsi_transport_template *lpfc_transport_template = NULL;
  95. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  96. static DEFINE_IDR(lpfc_hba_index);
  97. #define LPFC_NVMET_BUF_POST 254
  98. static int lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport);
  99. /**
  100. * lpfc_config_port_prep - Perform lpfc initialization prior to config port
  101. * @phba: pointer to lpfc hba data structure.
  102. *
  103. * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
  104. * mailbox command. It retrieves the revision information from the HBA and
  105. * collects the Vital Product Data (VPD) about the HBA for preparing the
  106. * configuration of the HBA.
  107. *
  108. * Return codes:
  109. * 0 - success.
  110. * -ERESTART - requests the SLI layer to reset the HBA and try again.
  111. * Any other value - indicates an error.
  112. **/
  113. int
  114. lpfc_config_port_prep(struct lpfc_hba *phba)
  115. {
  116. lpfc_vpd_t *vp = &phba->vpd;
  117. int i = 0, rc;
  118. LPFC_MBOXQ_t *pmb;
  119. MAILBOX_t *mb;
  120. char *lpfc_vpd_data = NULL;
  121. uint16_t offset = 0;
  122. static char licensed[56] =
  123. "key unlock for use with gnu public licensed code only\0";
  124. static int init_key = 1;
  125. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  126. if (!pmb) {
  127. phba->link_state = LPFC_HBA_ERROR;
  128. return -ENOMEM;
  129. }
  130. mb = &pmb->u.mb;
  131. phba->link_state = LPFC_INIT_MBX_CMDS;
  132. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  133. if (init_key) {
  134. uint32_t *ptext = (uint32_t *) licensed;
  135. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  136. *ptext = cpu_to_be32(*ptext);
  137. init_key = 0;
  138. }
  139. lpfc_read_nv(phba, pmb);
  140. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  141. sizeof (mb->un.varRDnvp.rsvd3));
  142. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  143. sizeof (licensed));
  144. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  145. if (rc != MBX_SUCCESS) {
  146. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  147. "0324 Config Port initialization "
  148. "error, mbxCmd x%x READ_NVPARM, "
  149. "mbxStatus x%x\n",
  150. mb->mbxCommand, mb->mbxStatus);
  151. mempool_free(pmb, phba->mbox_mem_pool);
  152. return -ERESTART;
  153. }
  154. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  155. sizeof(phba->wwnn));
  156. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  157. sizeof(phba->wwpn));
  158. }
  159. /*
  160. * Clear all option bits except LPFC_SLI3_BG_ENABLED,
  161. * which was already set in lpfc_get_cfgparam()
  162. */
  163. phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED;
  164. /* Setup and issue mailbox READ REV command */
  165. lpfc_read_rev(phba, pmb);
  166. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  167. if (rc != MBX_SUCCESS) {
  168. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  169. "0439 Adapter failed to init, mbxCmd x%x "
  170. "READ_REV, mbxStatus x%x\n",
  171. mb->mbxCommand, mb->mbxStatus);
  172. mempool_free( pmb, phba->mbox_mem_pool);
  173. return -ERESTART;
  174. }
  175. /*
  176. * The value of rr must be 1 since the driver set the cv field to 1.
  177. * This setting requires the FW to set all revision fields.
  178. */
  179. if (mb->un.varRdRev.rr == 0) {
  180. vp->rev.rBit = 0;
  181. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  182. "0440 Adapter failed to init, READ_REV has "
  183. "missing revision information.\n");
  184. mempool_free(pmb, phba->mbox_mem_pool);
  185. return -ERESTART;
  186. }
  187. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
  188. mempool_free(pmb, phba->mbox_mem_pool);
  189. return -EINVAL;
  190. }
  191. /* Save information as VPD data */
  192. vp->rev.rBit = 1;
  193. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  194. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  195. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  196. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  197. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  198. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  199. vp->rev.smRev = mb->un.varRdRev.smRev;
  200. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  201. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  202. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  203. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  204. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  205. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  206. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  207. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  208. /* If the sli feature level is less then 9, we must
  209. * tear down all RPIs and VPIs on link down if NPIV
  210. * is enabled.
  211. */
  212. if (vp->rev.feaLevelHigh < 9)
  213. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  214. if (lpfc_is_LC_HBA(phba->pcidev->device))
  215. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  216. sizeof (phba->RandomData));
  217. /* Get adapter VPD information */
  218. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  219. if (!lpfc_vpd_data)
  220. goto out_free_mbox;
  221. do {
  222. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
  223. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  224. if (rc != MBX_SUCCESS) {
  225. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  226. "0441 VPD not present on adapter, "
  227. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  228. mb->mbxCommand, mb->mbxStatus);
  229. mb->un.varDmp.word_cnt = 0;
  230. }
  231. /* dump mem may return a zero when finished or we got a
  232. * mailbox error, either way we are done.
  233. */
  234. if (mb->un.varDmp.word_cnt == 0)
  235. break;
  236. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  237. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  238. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  239. lpfc_vpd_data + offset,
  240. mb->un.varDmp.word_cnt);
  241. offset += mb->un.varDmp.word_cnt;
  242. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  243. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  244. kfree(lpfc_vpd_data);
  245. out_free_mbox:
  246. mempool_free(pmb, phba->mbox_mem_pool);
  247. return 0;
  248. }
  249. /**
  250. * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
  251. * @phba: pointer to lpfc hba data structure.
  252. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  253. *
  254. * This is the completion handler for driver's configuring asynchronous event
  255. * mailbox command to the device. If the mailbox command returns successfully,
  256. * it will set internal async event support flag to 1; otherwise, it will
  257. * set internal async event support flag to 0.
  258. **/
  259. static void
  260. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  261. {
  262. if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
  263. phba->temp_sensor_support = 1;
  264. else
  265. phba->temp_sensor_support = 0;
  266. mempool_free(pmboxq, phba->mbox_mem_pool);
  267. return;
  268. }
  269. /**
  270. * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
  271. * @phba: pointer to lpfc hba data structure.
  272. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  273. *
  274. * This is the completion handler for dump mailbox command for getting
  275. * wake up parameters. When this command complete, the response contain
  276. * Option rom version of the HBA. This function translate the version number
  277. * into a human readable string and store it in OptionROMVersion.
  278. **/
  279. static void
  280. lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  281. {
  282. struct prog_id *prg;
  283. uint32_t prog_id_word;
  284. char dist = ' ';
  285. /* character array used for decoding dist type. */
  286. char dist_char[] = "nabx";
  287. if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
  288. mempool_free(pmboxq, phba->mbox_mem_pool);
  289. return;
  290. }
  291. prg = (struct prog_id *) &prog_id_word;
  292. /* word 7 contain option rom version */
  293. prog_id_word = pmboxq->u.mb.un.varWords[7];
  294. /* Decode the Option rom version word to a readable string */
  295. dist = dist_char[prg->dist];
  296. if ((prg->dist == 3) && (prg->num == 0))
  297. snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
  298. prg->ver, prg->rev, prg->lev);
  299. else
  300. snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
  301. prg->ver, prg->rev, prg->lev,
  302. dist, prg->num);
  303. mempool_free(pmboxq, phba->mbox_mem_pool);
  304. return;
  305. }
  306. /**
  307. * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
  308. * @vport: pointer to lpfc vport data structure.
  309. *
  310. *
  311. * Return codes
  312. * None.
  313. **/
  314. void
  315. lpfc_update_vport_wwn(struct lpfc_vport *vport)
  316. {
  317. struct lpfc_hba *phba = vport->phba;
  318. /*
  319. * If the name is empty or there exists a soft name
  320. * then copy the service params name, otherwise use the fc name
  321. */
  322. if (vport->fc_nodename.u.wwn[0] == 0)
  323. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  324. sizeof(struct lpfc_name));
  325. else
  326. memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
  327. sizeof(struct lpfc_name));
  328. /*
  329. * If the port name has changed, then set the Param changes flag
  330. * to unreg the login
  331. */
  332. if (vport->fc_portname.u.wwn[0] != 0 &&
  333. memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
  334. sizeof(struct lpfc_name))) {
  335. vport->vport_flag |= FAWWPN_PARAM_CHG;
  336. if (phba->sli_rev == LPFC_SLI_REV4 &&
  337. vport->port_type == LPFC_PHYSICAL_PORT &&
  338. phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_FABRIC) {
  339. if (!(phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_CONFIG))
  340. phba->sli4_hba.fawwpn_flag &=
  341. ~LPFC_FAWWPN_FABRIC;
  342. lpfc_printf_log(phba, KERN_INFO,
  343. LOG_SLI | LOG_DISCOVERY | LOG_ELS,
  344. "2701 FA-PWWN change WWPN from %llx to "
  345. "%llx: vflag x%x fawwpn_flag x%x\n",
  346. wwn_to_u64(vport->fc_portname.u.wwn),
  347. wwn_to_u64
  348. (vport->fc_sparam.portName.u.wwn),
  349. vport->vport_flag,
  350. phba->sli4_hba.fawwpn_flag);
  351. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  352. sizeof(struct lpfc_name));
  353. }
  354. }
  355. if (vport->fc_portname.u.wwn[0] == 0)
  356. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  357. sizeof(struct lpfc_name));
  358. else
  359. memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
  360. sizeof(struct lpfc_name));
  361. }
  362. /**
  363. * lpfc_config_port_post - Perform lpfc initialization after config port
  364. * @phba: pointer to lpfc hba data structure.
  365. *
  366. * This routine will do LPFC initialization after the CONFIG_PORT mailbox
  367. * command call. It performs all internal resource and state setups on the
  368. * port: post IOCB buffers, enable appropriate host interrupt attentions,
  369. * ELS ring timers, etc.
  370. *
  371. * Return codes
  372. * 0 - success.
  373. * Any other value - error.
  374. **/
  375. int
  376. lpfc_config_port_post(struct lpfc_hba *phba)
  377. {
  378. struct lpfc_vport *vport = phba->pport;
  379. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  380. LPFC_MBOXQ_t *pmb;
  381. MAILBOX_t *mb;
  382. struct lpfc_dmabuf *mp;
  383. struct lpfc_sli *psli = &phba->sli;
  384. uint32_t status, timeout;
  385. int i, j;
  386. int rc;
  387. spin_lock_irq(&phba->hbalock);
  388. /*
  389. * If the Config port completed correctly the HBA is not
  390. * over heated any more.
  391. */
  392. if (phba->over_temp_state == HBA_OVER_TEMP)
  393. phba->over_temp_state = HBA_NORMAL_TEMP;
  394. spin_unlock_irq(&phba->hbalock);
  395. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  396. if (!pmb) {
  397. phba->link_state = LPFC_HBA_ERROR;
  398. return -ENOMEM;
  399. }
  400. mb = &pmb->u.mb;
  401. /* Get login parameters for NID. */
  402. rc = lpfc_read_sparam(phba, pmb, 0);
  403. if (rc) {
  404. mempool_free(pmb, phba->mbox_mem_pool);
  405. return -ENOMEM;
  406. }
  407. pmb->vport = vport;
  408. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  409. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  410. "0448 Adapter failed init, mbxCmd x%x "
  411. "READ_SPARM mbxStatus x%x\n",
  412. mb->mbxCommand, mb->mbxStatus);
  413. phba->link_state = LPFC_HBA_ERROR;
  414. lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
  415. return -EIO;
  416. }
  417. mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
  418. /* This dmabuf was allocated by lpfc_read_sparam. The dmabuf is no
  419. * longer needed. Prevent unintended ctx_buf access as the mbox is
  420. * reused.
  421. */
  422. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  423. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  424. kfree(mp);
  425. pmb->ctx_buf = NULL;
  426. lpfc_update_vport_wwn(vport);
  427. /* Update the fc_host data structures with new wwn. */
  428. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  429. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  430. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  431. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  432. /* This should be consolidated into parse_vpd ? - mr */
  433. if (phba->SerialNumber[0] == 0) {
  434. uint8_t *outptr;
  435. outptr = &vport->fc_nodename.u.s.IEEE[0];
  436. for (i = 0; i < 12; i++) {
  437. status = *outptr++;
  438. j = ((status & 0xf0) >> 4);
  439. if (j <= 9)
  440. phba->SerialNumber[i] =
  441. (char)((uint8_t) 0x30 + (uint8_t) j);
  442. else
  443. phba->SerialNumber[i] =
  444. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  445. i++;
  446. j = (status & 0xf);
  447. if (j <= 9)
  448. phba->SerialNumber[i] =
  449. (char)((uint8_t) 0x30 + (uint8_t) j);
  450. else
  451. phba->SerialNumber[i] =
  452. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  453. }
  454. }
  455. lpfc_read_config(phba, pmb);
  456. pmb->vport = vport;
  457. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  458. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  459. "0453 Adapter failed to init, mbxCmd x%x "
  460. "READ_CONFIG, mbxStatus x%x\n",
  461. mb->mbxCommand, mb->mbxStatus);
  462. phba->link_state = LPFC_HBA_ERROR;
  463. mempool_free( pmb, phba->mbox_mem_pool);
  464. return -EIO;
  465. }
  466. /* Check if the port is disabled */
  467. lpfc_sli_read_link_ste(phba);
  468. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  469. if (phba->cfg_hba_queue_depth > mb->un.varRdConfig.max_xri) {
  470. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  471. "3359 HBA queue depth changed from %d to %d\n",
  472. phba->cfg_hba_queue_depth,
  473. mb->un.varRdConfig.max_xri);
  474. phba->cfg_hba_queue_depth = mb->un.varRdConfig.max_xri;
  475. }
  476. phba->lmt = mb->un.varRdConfig.lmt;
  477. /* Get the default values for Model Name and Description */
  478. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  479. phba->link_state = LPFC_LINK_DOWN;
  480. /* Only process IOCBs on ELS ring till hba_state is READY */
  481. if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
  482. psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
  483. if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
  484. psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
  485. /* Post receive buffers for desired rings */
  486. if (phba->sli_rev != 3)
  487. lpfc_post_rcv_buf(phba);
  488. /*
  489. * Configure HBA MSI-X attention conditions to messages if MSI-X mode
  490. */
  491. if (phba->intr_type == MSIX) {
  492. rc = lpfc_config_msi(phba, pmb);
  493. if (rc) {
  494. mempool_free(pmb, phba->mbox_mem_pool);
  495. return -EIO;
  496. }
  497. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  498. if (rc != MBX_SUCCESS) {
  499. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  500. "0352 Config MSI mailbox command "
  501. "failed, mbxCmd x%x, mbxStatus x%x\n",
  502. pmb->u.mb.mbxCommand,
  503. pmb->u.mb.mbxStatus);
  504. mempool_free(pmb, phba->mbox_mem_pool);
  505. return -EIO;
  506. }
  507. }
  508. spin_lock_irq(&phba->hbalock);
  509. /* Initialize ERATT handling flag */
  510. phba->hba_flag &= ~HBA_ERATT_HANDLED;
  511. /* Enable appropriate host interrupts */
  512. if (lpfc_readl(phba->HCregaddr, &status)) {
  513. spin_unlock_irq(&phba->hbalock);
  514. return -EIO;
  515. }
  516. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  517. if (psli->num_rings > 0)
  518. status |= HC_R0INT_ENA;
  519. if (psli->num_rings > 1)
  520. status |= HC_R1INT_ENA;
  521. if (psli->num_rings > 2)
  522. status |= HC_R2INT_ENA;
  523. if (psli->num_rings > 3)
  524. status |= HC_R3INT_ENA;
  525. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  526. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  527. status &= ~(HC_R0INT_ENA);
  528. writel(status, phba->HCregaddr);
  529. readl(phba->HCregaddr); /* flush */
  530. spin_unlock_irq(&phba->hbalock);
  531. /* Set up ring-0 (ELS) timer */
  532. timeout = phba->fc_ratov * 2;
  533. mod_timer(&vport->els_tmofunc,
  534. jiffies + msecs_to_jiffies(1000 * timeout));
  535. /* Set up heart beat (HB) timer */
  536. mod_timer(&phba->hb_tmofunc,
  537. jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  538. phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
  539. phba->last_completion_time = jiffies;
  540. /* Set up error attention (ERATT) polling timer */
  541. mod_timer(&phba->eratt_poll,
  542. jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
  543. if (phba->hba_flag & LINK_DISABLED) {
  544. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  545. "2598 Adapter Link is disabled.\n");
  546. lpfc_down_link(phba, pmb);
  547. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  548. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  549. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  550. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  551. "2599 Adapter failed to issue DOWN_LINK"
  552. " mbox command rc 0x%x\n", rc);
  553. mempool_free(pmb, phba->mbox_mem_pool);
  554. return -EIO;
  555. }
  556. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  557. mempool_free(pmb, phba->mbox_mem_pool);
  558. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  559. if (rc)
  560. return rc;
  561. }
  562. /* MBOX buffer will be freed in mbox compl */
  563. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  564. if (!pmb) {
  565. phba->link_state = LPFC_HBA_ERROR;
  566. return -ENOMEM;
  567. }
  568. lpfc_config_async(phba, pmb, LPFC_ELS_RING);
  569. pmb->mbox_cmpl = lpfc_config_async_cmpl;
  570. pmb->vport = phba->pport;
  571. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  572. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  573. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  574. "0456 Adapter failed to issue "
  575. "ASYNCEVT_ENABLE mbox status x%x\n",
  576. rc);
  577. mempool_free(pmb, phba->mbox_mem_pool);
  578. }
  579. /* Get Option rom version */
  580. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  581. if (!pmb) {
  582. phba->link_state = LPFC_HBA_ERROR;
  583. return -ENOMEM;
  584. }
  585. lpfc_dump_wakeup_param(phba, pmb);
  586. pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
  587. pmb->vport = phba->pport;
  588. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  589. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  590. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  591. "0435 Adapter failed "
  592. "to get Option ROM version status x%x\n", rc);
  593. mempool_free(pmb, phba->mbox_mem_pool);
  594. }
  595. return 0;
  596. }
  597. /**
  598. * lpfc_sli4_refresh_params - update driver copy of params.
  599. * @phba: Pointer to HBA context object.
  600. *
  601. * This is called to refresh driver copy of dynamic fields from the
  602. * common_get_sli4_parameters descriptor.
  603. **/
  604. int
  605. lpfc_sli4_refresh_params(struct lpfc_hba *phba)
  606. {
  607. LPFC_MBOXQ_t *mboxq;
  608. struct lpfc_mqe *mqe;
  609. struct lpfc_sli4_parameters *mbx_sli4_parameters;
  610. int length, rc;
  611. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  612. if (!mboxq)
  613. return -ENOMEM;
  614. mqe = &mboxq->u.mqe;
  615. /* Read the port's SLI4 Config Parameters */
  616. length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
  617. sizeof(struct lpfc_sli4_cfg_mhdr));
  618. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  619. LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
  620. length, LPFC_SLI4_MBX_EMBED);
  621. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  622. if (unlikely(rc)) {
  623. mempool_free(mboxq, phba->mbox_mem_pool);
  624. return rc;
  625. }
  626. mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
  627. /* Are we forcing MI off via module parameter? */
  628. if (phba->cfg_enable_mi)
  629. phba->sli4_hba.pc_sli4_params.mi_ver =
  630. bf_get(cfg_mi_ver, mbx_sli4_parameters);
  631. else
  632. phba->sli4_hba.pc_sli4_params.mi_ver = 0;
  633. phba->sli4_hba.pc_sli4_params.cmf =
  634. bf_get(cfg_cmf, mbx_sli4_parameters);
  635. phba->sli4_hba.pc_sli4_params.pls =
  636. bf_get(cfg_pvl, mbx_sli4_parameters);
  637. mempool_free(mboxq, phba->mbox_mem_pool);
  638. return rc;
  639. }
  640. /**
  641. * lpfc_hba_init_link - Initialize the FC link
  642. * @phba: pointer to lpfc hba data structure.
  643. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  644. *
  645. * This routine will issue the INIT_LINK mailbox command call.
  646. * It is available to other drivers through the lpfc_hba data
  647. * structure for use as a delayed link up mechanism with the
  648. * module parameter lpfc_suppress_link_up.
  649. *
  650. * Return code
  651. * 0 - success
  652. * Any other value - error
  653. **/
  654. static int
  655. lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
  656. {
  657. return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
  658. }
  659. /**
  660. * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
  661. * @phba: pointer to lpfc hba data structure.
  662. * @fc_topology: desired fc topology.
  663. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  664. *
  665. * This routine will issue the INIT_LINK mailbox command call.
  666. * It is available to other drivers through the lpfc_hba data
  667. * structure for use as a delayed link up mechanism with the
  668. * module parameter lpfc_suppress_link_up.
  669. *
  670. * Return code
  671. * 0 - success
  672. * Any other value - error
  673. **/
  674. int
  675. lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
  676. uint32_t flag)
  677. {
  678. struct lpfc_vport *vport = phba->pport;
  679. LPFC_MBOXQ_t *pmb;
  680. MAILBOX_t *mb;
  681. int rc;
  682. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  683. if (!pmb) {
  684. phba->link_state = LPFC_HBA_ERROR;
  685. return -ENOMEM;
  686. }
  687. mb = &pmb->u.mb;
  688. pmb->vport = vport;
  689. if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
  690. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
  691. !(phba->lmt & LMT_1Gb)) ||
  692. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
  693. !(phba->lmt & LMT_2Gb)) ||
  694. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
  695. !(phba->lmt & LMT_4Gb)) ||
  696. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
  697. !(phba->lmt & LMT_8Gb)) ||
  698. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
  699. !(phba->lmt & LMT_10Gb)) ||
  700. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
  701. !(phba->lmt & LMT_16Gb)) ||
  702. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
  703. !(phba->lmt & LMT_32Gb)) ||
  704. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
  705. !(phba->lmt & LMT_64Gb))) {
  706. /* Reset link speed to auto */
  707. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  708. "1302 Invalid speed for this board:%d "
  709. "Reset link speed to auto.\n",
  710. phba->cfg_link_speed);
  711. phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
  712. }
  713. lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
  714. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  715. if (phba->sli_rev < LPFC_SLI_REV4)
  716. lpfc_set_loopback_flag(phba);
  717. rc = lpfc_sli_issue_mbox(phba, pmb, flag);
  718. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  719. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  720. "0498 Adapter failed to init, mbxCmd x%x "
  721. "INIT_LINK, mbxStatus x%x\n",
  722. mb->mbxCommand, mb->mbxStatus);
  723. if (phba->sli_rev <= LPFC_SLI_REV3) {
  724. /* Clear all interrupt enable conditions */
  725. writel(0, phba->HCregaddr);
  726. readl(phba->HCregaddr); /* flush */
  727. /* Clear all pending interrupts */
  728. writel(0xffffffff, phba->HAregaddr);
  729. readl(phba->HAregaddr); /* flush */
  730. }
  731. phba->link_state = LPFC_HBA_ERROR;
  732. if (rc != MBX_BUSY || flag == MBX_POLL)
  733. mempool_free(pmb, phba->mbox_mem_pool);
  734. return -EIO;
  735. }
  736. phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
  737. if (flag == MBX_POLL)
  738. mempool_free(pmb, phba->mbox_mem_pool);
  739. return 0;
  740. }
  741. /**
  742. * lpfc_hba_down_link - this routine downs the FC link
  743. * @phba: pointer to lpfc hba data structure.
  744. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  745. *
  746. * This routine will issue the DOWN_LINK mailbox command call.
  747. * It is available to other drivers through the lpfc_hba data
  748. * structure for use to stop the link.
  749. *
  750. * Return code
  751. * 0 - success
  752. * Any other value - error
  753. **/
  754. static int
  755. lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
  756. {
  757. LPFC_MBOXQ_t *pmb;
  758. int rc;
  759. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  760. if (!pmb) {
  761. phba->link_state = LPFC_HBA_ERROR;
  762. return -ENOMEM;
  763. }
  764. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  765. "0491 Adapter Link is disabled.\n");
  766. lpfc_down_link(phba, pmb);
  767. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  768. rc = lpfc_sli_issue_mbox(phba, pmb, flag);
  769. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  770. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  771. "2522 Adapter failed to issue DOWN_LINK"
  772. " mbox command rc 0x%x\n", rc);
  773. mempool_free(pmb, phba->mbox_mem_pool);
  774. return -EIO;
  775. }
  776. if (flag == MBX_POLL)
  777. mempool_free(pmb, phba->mbox_mem_pool);
  778. return 0;
  779. }
  780. /**
  781. * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
  782. * @phba: pointer to lpfc HBA data structure.
  783. *
  784. * This routine will do LPFC uninitialization before the HBA is reset when
  785. * bringing down the SLI Layer.
  786. *
  787. * Return codes
  788. * 0 - success.
  789. * Any other value - error.
  790. **/
  791. int
  792. lpfc_hba_down_prep(struct lpfc_hba *phba)
  793. {
  794. struct lpfc_vport **vports;
  795. int i;
  796. if (phba->sli_rev <= LPFC_SLI_REV3) {
  797. /* Disable interrupts */
  798. writel(0, phba->HCregaddr);
  799. readl(phba->HCregaddr); /* flush */
  800. }
  801. if (phba->pport->load_flag & FC_UNLOADING)
  802. lpfc_cleanup_discovery_resources(phba->pport);
  803. else {
  804. vports = lpfc_create_vport_work_array(phba);
  805. if (vports != NULL)
  806. for (i = 0; i <= phba->max_vports &&
  807. vports[i] != NULL; i++)
  808. lpfc_cleanup_discovery_resources(vports[i]);
  809. lpfc_destroy_vport_work_array(phba, vports);
  810. }
  811. return 0;
  812. }
  813. /**
  814. * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
  815. * rspiocb which got deferred
  816. *
  817. * @phba: pointer to lpfc HBA data structure.
  818. *
  819. * This routine will cleanup completed slow path events after HBA is reset
  820. * when bringing down the SLI Layer.
  821. *
  822. *
  823. * Return codes
  824. * void.
  825. **/
  826. static void
  827. lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
  828. {
  829. struct lpfc_iocbq *rspiocbq;
  830. struct hbq_dmabuf *dmabuf;
  831. struct lpfc_cq_event *cq_event;
  832. spin_lock_irq(&phba->hbalock);
  833. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  834. spin_unlock_irq(&phba->hbalock);
  835. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  836. /* Get the response iocb from the head of work queue */
  837. spin_lock_irq(&phba->hbalock);
  838. list_remove_head(&phba->sli4_hba.sp_queue_event,
  839. cq_event, struct lpfc_cq_event, list);
  840. spin_unlock_irq(&phba->hbalock);
  841. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  842. case CQE_CODE_COMPL_WQE:
  843. rspiocbq = container_of(cq_event, struct lpfc_iocbq,
  844. cq_event);
  845. lpfc_sli_release_iocbq(phba, rspiocbq);
  846. break;
  847. case CQE_CODE_RECEIVE:
  848. case CQE_CODE_RECEIVE_V1:
  849. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  850. cq_event);
  851. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  852. }
  853. }
  854. }
  855. /**
  856. * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
  857. * @phba: pointer to lpfc HBA data structure.
  858. *
  859. * This routine will cleanup posted ELS buffers after the HBA is reset
  860. * when bringing down the SLI Layer.
  861. *
  862. *
  863. * Return codes
  864. * void.
  865. **/
  866. static void
  867. lpfc_hba_free_post_buf(struct lpfc_hba *phba)
  868. {
  869. struct lpfc_sli *psli = &phba->sli;
  870. struct lpfc_sli_ring *pring;
  871. struct lpfc_dmabuf *mp, *next_mp;
  872. LIST_HEAD(buflist);
  873. int count;
  874. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  875. lpfc_sli_hbqbuf_free_all(phba);
  876. else {
  877. /* Cleanup preposted buffers on the ELS ring */
  878. pring = &psli->sli3_ring[LPFC_ELS_RING];
  879. spin_lock_irq(&phba->hbalock);
  880. list_splice_init(&pring->postbufq, &buflist);
  881. spin_unlock_irq(&phba->hbalock);
  882. count = 0;
  883. list_for_each_entry_safe(mp, next_mp, &buflist, list) {
  884. list_del(&mp->list);
  885. count++;
  886. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  887. kfree(mp);
  888. }
  889. spin_lock_irq(&phba->hbalock);
  890. pring->postbufq_cnt -= count;
  891. spin_unlock_irq(&phba->hbalock);
  892. }
  893. }
  894. /**
  895. * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
  896. * @phba: pointer to lpfc HBA data structure.
  897. *
  898. * This routine will cleanup the txcmplq after the HBA is reset when bringing
  899. * down the SLI Layer.
  900. *
  901. * Return codes
  902. * void
  903. **/
  904. static void
  905. lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
  906. {
  907. struct lpfc_sli *psli = &phba->sli;
  908. struct lpfc_queue *qp = NULL;
  909. struct lpfc_sli_ring *pring;
  910. LIST_HEAD(completions);
  911. int i;
  912. struct lpfc_iocbq *piocb, *next_iocb;
  913. if (phba->sli_rev != LPFC_SLI_REV4) {
  914. for (i = 0; i < psli->num_rings; i++) {
  915. pring = &psli->sli3_ring[i];
  916. spin_lock_irq(&phba->hbalock);
  917. /* At this point in time the HBA is either reset or DOA
  918. * Nothing should be on txcmplq as it will
  919. * NEVER complete.
  920. */
  921. list_splice_init(&pring->txcmplq, &completions);
  922. pring->txcmplq_cnt = 0;
  923. spin_unlock_irq(&phba->hbalock);
  924. lpfc_sli_abort_iocb_ring(phba, pring);
  925. }
  926. /* Cancel all the IOCBs from the completions list */
  927. lpfc_sli_cancel_iocbs(phba, &completions,
  928. IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
  929. return;
  930. }
  931. list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
  932. pring = qp->pring;
  933. if (!pring)
  934. continue;
  935. spin_lock_irq(&pring->ring_lock);
  936. list_for_each_entry_safe(piocb, next_iocb,
  937. &pring->txcmplq, list)
  938. piocb->cmd_flag &= ~LPFC_IO_ON_TXCMPLQ;
  939. list_splice_init(&pring->txcmplq, &completions);
  940. pring->txcmplq_cnt = 0;
  941. spin_unlock_irq(&pring->ring_lock);
  942. lpfc_sli_abort_iocb_ring(phba, pring);
  943. }
  944. /* Cancel all the IOCBs from the completions list */
  945. lpfc_sli_cancel_iocbs(phba, &completions,
  946. IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
  947. }
  948. /**
  949. * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
  950. * @phba: pointer to lpfc HBA data structure.
  951. *
  952. * This routine will do uninitialization after the HBA is reset when bring
  953. * down the SLI Layer.
  954. *
  955. * Return codes
  956. * 0 - success.
  957. * Any other value - error.
  958. **/
  959. static int
  960. lpfc_hba_down_post_s3(struct lpfc_hba *phba)
  961. {
  962. lpfc_hba_free_post_buf(phba);
  963. lpfc_hba_clean_txcmplq(phba);
  964. return 0;
  965. }
  966. /**
  967. * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
  968. * @phba: pointer to lpfc HBA data structure.
  969. *
  970. * This routine will do uninitialization after the HBA is reset when bring
  971. * down the SLI Layer.
  972. *
  973. * Return codes
  974. * 0 - success.
  975. * Any other value - error.
  976. **/
  977. static int
  978. lpfc_hba_down_post_s4(struct lpfc_hba *phba)
  979. {
  980. struct lpfc_io_buf *psb, *psb_next;
  981. struct lpfc_async_xchg_ctx *ctxp, *ctxp_next;
  982. struct lpfc_sli4_hdw_queue *qp;
  983. LIST_HEAD(aborts);
  984. LIST_HEAD(nvme_aborts);
  985. LIST_HEAD(nvmet_aborts);
  986. struct lpfc_sglq *sglq_entry = NULL;
  987. int cnt, idx;
  988. lpfc_sli_hbqbuf_free_all(phba);
  989. lpfc_hba_clean_txcmplq(phba);
  990. /* At this point in time the HBA is either reset or DOA. Either
  991. * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
  992. * on the lpfc_els_sgl_list so that it can either be freed if the
  993. * driver is unloading or reposted if the driver is restarting
  994. * the port.
  995. */
  996. /* sgl_list_lock required because worker thread uses this
  997. * list.
  998. */
  999. spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
  1000. list_for_each_entry(sglq_entry,
  1001. &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
  1002. sglq_entry->state = SGL_FREED;
  1003. list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
  1004. &phba->sli4_hba.lpfc_els_sgl_list);
  1005. spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
  1006. /* abts_xxxx_buf_list_lock required because worker thread uses this
  1007. * list.
  1008. */
  1009. spin_lock_irq(&phba->hbalock);
  1010. cnt = 0;
  1011. for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
  1012. qp = &phba->sli4_hba.hdwq[idx];
  1013. spin_lock(&qp->abts_io_buf_list_lock);
  1014. list_splice_init(&qp->lpfc_abts_io_buf_list,
  1015. &aborts);
  1016. list_for_each_entry_safe(psb, psb_next, &aborts, list) {
  1017. psb->pCmd = NULL;
  1018. psb->status = IOSTAT_SUCCESS;
  1019. cnt++;
  1020. }
  1021. spin_lock(&qp->io_buf_list_put_lock);
  1022. list_splice_init(&aborts, &qp->lpfc_io_buf_list_put);
  1023. qp->put_io_bufs += qp->abts_scsi_io_bufs;
  1024. qp->put_io_bufs += qp->abts_nvme_io_bufs;
  1025. qp->abts_scsi_io_bufs = 0;
  1026. qp->abts_nvme_io_bufs = 0;
  1027. spin_unlock(&qp->io_buf_list_put_lock);
  1028. spin_unlock(&qp->abts_io_buf_list_lock);
  1029. }
  1030. spin_unlock_irq(&phba->hbalock);
  1031. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  1032. spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
  1033. list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
  1034. &nvmet_aborts);
  1035. spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock);
  1036. list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
  1037. ctxp->flag &= ~(LPFC_NVME_XBUSY | LPFC_NVME_ABORT_OP);
  1038. lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
  1039. }
  1040. }
  1041. lpfc_sli4_free_sp_events(phba);
  1042. return cnt;
  1043. }
  1044. /**
  1045. * lpfc_hba_down_post - Wrapper func for hba down post routine
  1046. * @phba: pointer to lpfc HBA data structure.
  1047. *
  1048. * This routine wraps the actual SLI3 or SLI4 routine for performing
  1049. * uninitialization after the HBA is reset when bring down the SLI Layer.
  1050. *
  1051. * Return codes
  1052. * 0 - success.
  1053. * Any other value - error.
  1054. **/
  1055. int
  1056. lpfc_hba_down_post(struct lpfc_hba *phba)
  1057. {
  1058. return (*phba->lpfc_hba_down_post)(phba);
  1059. }
  1060. /**
  1061. * lpfc_hb_timeout - The HBA-timer timeout handler
  1062. * @t: timer context used to obtain the pointer to lpfc hba data structure.
  1063. *
  1064. * This is the HBA-timer timeout handler registered to the lpfc driver. When
  1065. * this timer fires, a HBA timeout event shall be posted to the lpfc driver
  1066. * work-port-events bitmap and the worker thread is notified. This timeout
  1067. * event will be used by the worker thread to invoke the actual timeout
  1068. * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
  1069. * be performed in the timeout handler and the HBA timeout event bit shall
  1070. * be cleared by the worker thread after it has taken the event bitmap out.
  1071. **/
  1072. static void
  1073. lpfc_hb_timeout(struct timer_list *t)
  1074. {
  1075. struct lpfc_hba *phba;
  1076. uint32_t tmo_posted;
  1077. unsigned long iflag;
  1078. phba = from_timer(phba, t, hb_tmofunc);
  1079. /* Check for heart beat timeout conditions */
  1080. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  1081. tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
  1082. if (!tmo_posted)
  1083. phba->pport->work_port_events |= WORKER_HB_TMO;
  1084. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  1085. /* Tell the worker thread there is work to do */
  1086. if (!tmo_posted)
  1087. lpfc_worker_wake_up(phba);
  1088. return;
  1089. }
  1090. /**
  1091. * lpfc_rrq_timeout - The RRQ-timer timeout handler
  1092. * @t: timer context used to obtain the pointer to lpfc hba data structure.
  1093. *
  1094. * This is the RRQ-timer timeout handler registered to the lpfc driver. When
  1095. * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
  1096. * work-port-events bitmap and the worker thread is notified. This timeout
  1097. * event will be used by the worker thread to invoke the actual timeout
  1098. * handler routine, lpfc_rrq_handler. Any periodical operations will
  1099. * be performed in the timeout handler and the RRQ timeout event bit shall
  1100. * be cleared by the worker thread after it has taken the event bitmap out.
  1101. **/
  1102. static void
  1103. lpfc_rrq_timeout(struct timer_list *t)
  1104. {
  1105. struct lpfc_hba *phba;
  1106. unsigned long iflag;
  1107. phba = from_timer(phba, t, rrq_tmr);
  1108. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  1109. if (!(phba->pport->load_flag & FC_UNLOADING))
  1110. phba->hba_flag |= HBA_RRQ_ACTIVE;
  1111. else
  1112. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  1113. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  1114. if (!(phba->pport->load_flag & FC_UNLOADING))
  1115. lpfc_worker_wake_up(phba);
  1116. }
  1117. /**
  1118. * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
  1119. * @phba: pointer to lpfc hba data structure.
  1120. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  1121. *
  1122. * This is the callback function to the lpfc heart-beat mailbox command.
  1123. * If configured, the lpfc driver issues the heart-beat mailbox command to
  1124. * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
  1125. * heart-beat mailbox command is issued, the driver shall set up heart-beat
  1126. * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
  1127. * heart-beat outstanding state. Once the mailbox command comes back and
  1128. * no error conditions detected, the heart-beat mailbox command timer is
  1129. * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
  1130. * state is cleared for the next heart-beat. If the timer expired with the
  1131. * heart-beat outstanding state set, the driver will put the HBA offline.
  1132. **/
  1133. static void
  1134. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  1135. {
  1136. unsigned long drvr_flag;
  1137. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1138. phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
  1139. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1140. /* Check and reset heart-beat timer if necessary */
  1141. mempool_free(pmboxq, phba->mbox_mem_pool);
  1142. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  1143. !(phba->link_state == LPFC_HBA_ERROR) &&
  1144. !(phba->pport->load_flag & FC_UNLOADING))
  1145. mod_timer(&phba->hb_tmofunc,
  1146. jiffies +
  1147. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  1148. return;
  1149. }
  1150. /*
  1151. * lpfc_idle_stat_delay_work - idle_stat tracking
  1152. *
  1153. * This routine tracks per-cq idle_stat and determines polling decisions.
  1154. *
  1155. * Return codes:
  1156. * None
  1157. **/
  1158. static void
  1159. lpfc_idle_stat_delay_work(struct work_struct *work)
  1160. {
  1161. struct lpfc_hba *phba = container_of(to_delayed_work(work),
  1162. struct lpfc_hba,
  1163. idle_stat_delay_work);
  1164. struct lpfc_queue *cq;
  1165. struct lpfc_sli4_hdw_queue *hdwq;
  1166. struct lpfc_idle_stat *idle_stat;
  1167. u32 i, idle_percent;
  1168. u64 wall, wall_idle, diff_wall, diff_idle, busy_time;
  1169. if (phba->pport->load_flag & FC_UNLOADING)
  1170. return;
  1171. if (phba->link_state == LPFC_HBA_ERROR ||
  1172. phba->pport->fc_flag & FC_OFFLINE_MODE ||
  1173. phba->cmf_active_mode != LPFC_CFG_OFF)
  1174. goto requeue;
  1175. for_each_present_cpu(i) {
  1176. hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq];
  1177. cq = hdwq->io_cq;
  1178. /* Skip if we've already handled this cq's primary CPU */
  1179. if (cq->chann != i)
  1180. continue;
  1181. idle_stat = &phba->sli4_hba.idle_stat[i];
  1182. /* get_cpu_idle_time returns values as running counters. Thus,
  1183. * to know the amount for this period, the prior counter values
  1184. * need to be subtracted from the current counter values.
  1185. * From there, the idle time stat can be calculated as a
  1186. * percentage of 100 - the sum of the other consumption times.
  1187. */
  1188. wall_idle = get_cpu_idle_time(i, &wall, 1);
  1189. diff_idle = wall_idle - idle_stat->prev_idle;
  1190. diff_wall = wall - idle_stat->prev_wall;
  1191. if (diff_wall <= diff_idle)
  1192. busy_time = 0;
  1193. else
  1194. busy_time = diff_wall - diff_idle;
  1195. idle_percent = div64_u64(100 * busy_time, diff_wall);
  1196. idle_percent = 100 - idle_percent;
  1197. if (idle_percent < 15)
  1198. cq->poll_mode = LPFC_QUEUE_WORK;
  1199. else
  1200. cq->poll_mode = LPFC_IRQ_POLL;
  1201. idle_stat->prev_idle = wall_idle;
  1202. idle_stat->prev_wall = wall;
  1203. }
  1204. requeue:
  1205. schedule_delayed_work(&phba->idle_stat_delay_work,
  1206. msecs_to_jiffies(LPFC_IDLE_STAT_DELAY));
  1207. }
  1208. static void
  1209. lpfc_hb_eq_delay_work(struct work_struct *work)
  1210. {
  1211. struct lpfc_hba *phba = container_of(to_delayed_work(work),
  1212. struct lpfc_hba, eq_delay_work);
  1213. struct lpfc_eq_intr_info *eqi, *eqi_new;
  1214. struct lpfc_queue *eq, *eq_next;
  1215. unsigned char *ena_delay = NULL;
  1216. uint32_t usdelay;
  1217. int i;
  1218. if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING)
  1219. return;
  1220. if (phba->link_state == LPFC_HBA_ERROR ||
  1221. phba->pport->fc_flag & FC_OFFLINE_MODE)
  1222. goto requeue;
  1223. ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay),
  1224. GFP_KERNEL);
  1225. if (!ena_delay)
  1226. goto requeue;
  1227. for (i = 0; i < phba->cfg_irq_chann; i++) {
  1228. /* Get the EQ corresponding to the IRQ vector */
  1229. eq = phba->sli4_hba.hba_eq_hdl[i].eq;
  1230. if (!eq)
  1231. continue;
  1232. if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) {
  1233. eq->q_flag &= ~HBA_EQ_DELAY_CHK;
  1234. ena_delay[eq->last_cpu] = 1;
  1235. }
  1236. }
  1237. for_each_present_cpu(i) {
  1238. eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
  1239. if (ena_delay[i]) {
  1240. usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP;
  1241. if (usdelay > LPFC_MAX_AUTO_EQ_DELAY)
  1242. usdelay = LPFC_MAX_AUTO_EQ_DELAY;
  1243. } else {
  1244. usdelay = 0;
  1245. }
  1246. eqi->icnt = 0;
  1247. list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) {
  1248. if (unlikely(eq->last_cpu != i)) {
  1249. eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info,
  1250. eq->last_cpu);
  1251. list_move_tail(&eq->cpu_list, &eqi_new->list);
  1252. continue;
  1253. }
  1254. if (usdelay != eq->q_mode)
  1255. lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1,
  1256. usdelay);
  1257. }
  1258. }
  1259. kfree(ena_delay);
  1260. requeue:
  1261. queue_delayed_work(phba->wq, &phba->eq_delay_work,
  1262. msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
  1263. }
  1264. /**
  1265. * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution
  1266. * @phba: pointer to lpfc hba data structure.
  1267. *
  1268. * For each heartbeat, this routine does some heuristic methods to adjust
  1269. * XRI distribution. The goal is to fully utilize free XRIs.
  1270. **/
  1271. static void lpfc_hb_mxp_handler(struct lpfc_hba *phba)
  1272. {
  1273. u32 i;
  1274. u32 hwq_count;
  1275. hwq_count = phba->cfg_hdw_queue;
  1276. for (i = 0; i < hwq_count; i++) {
  1277. /* Adjust XRIs in private pool */
  1278. lpfc_adjust_pvt_pool_count(phba, i);
  1279. /* Adjust high watermark */
  1280. lpfc_adjust_high_watermark(phba, i);
  1281. #ifdef LPFC_MXP_STAT
  1282. /* Snapshot pbl, pvt and busy count */
  1283. lpfc_snapshot_mxp(phba, i);
  1284. #endif
  1285. }
  1286. }
  1287. /**
  1288. * lpfc_issue_hb_mbox - Issues heart-beat mailbox command
  1289. * @phba: pointer to lpfc hba data structure.
  1290. *
  1291. * If a HB mbox is not already in progrees, this routine will allocate
  1292. * a LPFC_MBOXQ_t, populate it with a MBX_HEARTBEAT (0x31) command,
  1293. * and issue it. The HBA_HBEAT_INP flag means the command is in progress.
  1294. **/
  1295. int
  1296. lpfc_issue_hb_mbox(struct lpfc_hba *phba)
  1297. {
  1298. LPFC_MBOXQ_t *pmboxq;
  1299. int retval;
  1300. /* Is a Heartbeat mbox already in progress */
  1301. if (phba->hba_flag & HBA_HBEAT_INP)
  1302. return 0;
  1303. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1304. if (!pmboxq)
  1305. return -ENOMEM;
  1306. lpfc_heart_beat(phba, pmboxq);
  1307. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  1308. pmboxq->vport = phba->pport;
  1309. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  1310. if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
  1311. mempool_free(pmboxq, phba->mbox_mem_pool);
  1312. return -ENXIO;
  1313. }
  1314. phba->hba_flag |= HBA_HBEAT_INP;
  1315. return 0;
  1316. }
  1317. /**
  1318. * lpfc_issue_hb_tmo - Signals heartbeat timer to issue mbox command
  1319. * @phba: pointer to lpfc hba data structure.
  1320. *
  1321. * The heartbeat timer (every 5 sec) will fire. If the HBA_HBEAT_TMO
  1322. * flag is set, it will force a MBX_HEARTBEAT mbox command, regardless
  1323. * of the value of lpfc_enable_hba_heartbeat.
  1324. * If lpfc_enable_hba_heartbeat is set, the timeout routine will always
  1325. * try to issue a MBX_HEARTBEAT mbox command.
  1326. **/
  1327. void
  1328. lpfc_issue_hb_tmo(struct lpfc_hba *phba)
  1329. {
  1330. if (phba->cfg_enable_hba_heartbeat)
  1331. return;
  1332. phba->hba_flag |= HBA_HBEAT_TMO;
  1333. }
  1334. /**
  1335. * lpfc_hb_timeout_handler - The HBA-timer timeout handler
  1336. * @phba: pointer to lpfc hba data structure.
  1337. *
  1338. * This is the actual HBA-timer timeout handler to be invoked by the worker
  1339. * thread whenever the HBA timer fired and HBA-timeout event posted. This
  1340. * handler performs any periodic operations needed for the device. If such
  1341. * periodic event has already been attended to either in the interrupt handler
  1342. * or by processing slow-ring or fast-ring events within the HBA-timer
  1343. * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
  1344. * the timer for the next timeout period. If lpfc heart-beat mailbox command
  1345. * is configured and there is no heart-beat mailbox command outstanding, a
  1346. * heart-beat mailbox is issued and timer set properly. Otherwise, if there
  1347. * has been a heart-beat mailbox command outstanding, the HBA shall be put
  1348. * to offline.
  1349. **/
  1350. void
  1351. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  1352. {
  1353. struct lpfc_vport **vports;
  1354. struct lpfc_dmabuf *buf_ptr;
  1355. int retval = 0;
  1356. int i, tmo;
  1357. struct lpfc_sli *psli = &phba->sli;
  1358. LIST_HEAD(completions);
  1359. if (phba->cfg_xri_rebalancing) {
  1360. /* Multi-XRI pools handler */
  1361. lpfc_hb_mxp_handler(phba);
  1362. }
  1363. vports = lpfc_create_vport_work_array(phba);
  1364. if (vports != NULL)
  1365. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  1366. lpfc_rcv_seq_check_edtov(vports[i]);
  1367. lpfc_fdmi_change_check(vports[i]);
  1368. }
  1369. lpfc_destroy_vport_work_array(phba, vports);
  1370. if ((phba->link_state == LPFC_HBA_ERROR) ||
  1371. (phba->pport->load_flag & FC_UNLOADING) ||
  1372. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  1373. return;
  1374. if (phba->elsbuf_cnt &&
  1375. (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
  1376. spin_lock_irq(&phba->hbalock);
  1377. list_splice_init(&phba->elsbuf, &completions);
  1378. phba->elsbuf_cnt = 0;
  1379. phba->elsbuf_prev_cnt = 0;
  1380. spin_unlock_irq(&phba->hbalock);
  1381. while (!list_empty(&completions)) {
  1382. list_remove_head(&completions, buf_ptr,
  1383. struct lpfc_dmabuf, list);
  1384. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1385. kfree(buf_ptr);
  1386. }
  1387. }
  1388. phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
  1389. /* If there is no heart beat outstanding, issue a heartbeat command */
  1390. if (phba->cfg_enable_hba_heartbeat) {
  1391. /* If IOs are completing, no need to issue a MBX_HEARTBEAT */
  1392. spin_lock_irq(&phba->pport->work_port_lock);
  1393. if (time_after(phba->last_completion_time +
  1394. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
  1395. jiffies)) {
  1396. spin_unlock_irq(&phba->pport->work_port_lock);
  1397. if (phba->hba_flag & HBA_HBEAT_INP)
  1398. tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
  1399. else
  1400. tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
  1401. goto out;
  1402. }
  1403. spin_unlock_irq(&phba->pport->work_port_lock);
  1404. /* Check if a MBX_HEARTBEAT is already in progress */
  1405. if (phba->hba_flag & HBA_HBEAT_INP) {
  1406. /*
  1407. * If heart beat timeout called with HBA_HBEAT_INP set
  1408. * we need to give the hb mailbox cmd a chance to
  1409. * complete or TMO.
  1410. */
  1411. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1412. "0459 Adapter heartbeat still outstanding: "
  1413. "last compl time was %d ms.\n",
  1414. jiffies_to_msecs(jiffies
  1415. - phba->last_completion_time));
  1416. tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
  1417. } else {
  1418. if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
  1419. (list_empty(&psli->mboxq))) {
  1420. retval = lpfc_issue_hb_mbox(phba);
  1421. if (retval) {
  1422. tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
  1423. goto out;
  1424. }
  1425. phba->skipped_hb = 0;
  1426. } else if (time_before_eq(phba->last_completion_time,
  1427. phba->skipped_hb)) {
  1428. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1429. "2857 Last completion time not "
  1430. " updated in %d ms\n",
  1431. jiffies_to_msecs(jiffies
  1432. - phba->last_completion_time));
  1433. } else
  1434. phba->skipped_hb = jiffies;
  1435. tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
  1436. goto out;
  1437. }
  1438. } else {
  1439. /* Check to see if we want to force a MBX_HEARTBEAT */
  1440. if (phba->hba_flag & HBA_HBEAT_TMO) {
  1441. retval = lpfc_issue_hb_mbox(phba);
  1442. if (retval)
  1443. tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
  1444. else
  1445. tmo = (1000 * LPFC_HB_MBOX_TIMEOUT);
  1446. goto out;
  1447. }
  1448. tmo = (1000 * LPFC_HB_MBOX_INTERVAL);
  1449. }
  1450. out:
  1451. mod_timer(&phba->hb_tmofunc, jiffies + msecs_to_jiffies(tmo));
  1452. }
  1453. /**
  1454. * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
  1455. * @phba: pointer to lpfc hba data structure.
  1456. *
  1457. * This routine is called to bring the HBA offline when HBA hardware error
  1458. * other than Port Error 6 has been detected.
  1459. **/
  1460. static void
  1461. lpfc_offline_eratt(struct lpfc_hba *phba)
  1462. {
  1463. struct lpfc_sli *psli = &phba->sli;
  1464. spin_lock_irq(&phba->hbalock);
  1465. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1466. spin_unlock_irq(&phba->hbalock);
  1467. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1468. lpfc_offline(phba);
  1469. lpfc_reset_barrier(phba);
  1470. spin_lock_irq(&phba->hbalock);
  1471. lpfc_sli_brdreset(phba);
  1472. spin_unlock_irq(&phba->hbalock);
  1473. lpfc_hba_down_post(phba);
  1474. lpfc_sli_brdready(phba, HS_MBRDY);
  1475. lpfc_unblock_mgmt_io(phba);
  1476. phba->link_state = LPFC_HBA_ERROR;
  1477. return;
  1478. }
  1479. /**
  1480. * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
  1481. * @phba: pointer to lpfc hba data structure.
  1482. *
  1483. * This routine is called to bring a SLI4 HBA offline when HBA hardware error
  1484. * other than Port Error 6 has been detected.
  1485. **/
  1486. void
  1487. lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
  1488. {
  1489. spin_lock_irq(&phba->hbalock);
  1490. if (phba->link_state == LPFC_HBA_ERROR &&
  1491. test_bit(HBA_PCI_ERR, &phba->bit_flags)) {
  1492. spin_unlock_irq(&phba->hbalock);
  1493. return;
  1494. }
  1495. phba->link_state = LPFC_HBA_ERROR;
  1496. spin_unlock_irq(&phba->hbalock);
  1497. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1498. lpfc_sli_flush_io_rings(phba);
  1499. lpfc_offline(phba);
  1500. lpfc_hba_down_post(phba);
  1501. lpfc_unblock_mgmt_io(phba);
  1502. }
  1503. /**
  1504. * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
  1505. * @phba: pointer to lpfc hba data structure.
  1506. *
  1507. * This routine is invoked to handle the deferred HBA hardware error
  1508. * conditions. This type of error is indicated by HBA by setting ER1
  1509. * and another ER bit in the host status register. The driver will
  1510. * wait until the ER1 bit clears before handling the error condition.
  1511. **/
  1512. static void
  1513. lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
  1514. {
  1515. uint32_t old_host_status = phba->work_hs;
  1516. struct lpfc_sli *psli = &phba->sli;
  1517. /* If the pci channel is offline, ignore possible errors,
  1518. * since we cannot communicate with the pci card anyway.
  1519. */
  1520. if (pci_channel_offline(phba->pcidev)) {
  1521. spin_lock_irq(&phba->hbalock);
  1522. phba->hba_flag &= ~DEFER_ERATT;
  1523. spin_unlock_irq(&phba->hbalock);
  1524. return;
  1525. }
  1526. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1527. "0479 Deferred Adapter Hardware Error "
  1528. "Data: x%x x%x x%x\n",
  1529. phba->work_hs, phba->work_status[0],
  1530. phba->work_status[1]);
  1531. spin_lock_irq(&phba->hbalock);
  1532. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1533. spin_unlock_irq(&phba->hbalock);
  1534. /*
  1535. * Firmware stops when it triggred erratt. That could cause the I/Os
  1536. * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
  1537. * SCSI layer retry it after re-establishing link.
  1538. */
  1539. lpfc_sli_abort_fcp_rings(phba);
  1540. /*
  1541. * There was a firmware error. Take the hba offline and then
  1542. * attempt to restart it.
  1543. */
  1544. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  1545. lpfc_offline(phba);
  1546. /* Wait for the ER1 bit to clear.*/
  1547. while (phba->work_hs & HS_FFER1) {
  1548. msleep(100);
  1549. if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
  1550. phba->work_hs = UNPLUG_ERR ;
  1551. break;
  1552. }
  1553. /* If driver is unloading let the worker thread continue */
  1554. if (phba->pport->load_flag & FC_UNLOADING) {
  1555. phba->work_hs = 0;
  1556. break;
  1557. }
  1558. }
  1559. /*
  1560. * This is to ptrotect against a race condition in which
  1561. * first write to the host attention register clear the
  1562. * host status register.
  1563. */
  1564. if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
  1565. phba->work_hs = old_host_status & ~HS_FFER1;
  1566. spin_lock_irq(&phba->hbalock);
  1567. phba->hba_flag &= ~DEFER_ERATT;
  1568. spin_unlock_irq(&phba->hbalock);
  1569. phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
  1570. phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
  1571. }
  1572. static void
  1573. lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
  1574. {
  1575. struct lpfc_board_event_header board_event;
  1576. struct Scsi_Host *shost;
  1577. board_event.event_type = FC_REG_BOARD_EVENT;
  1578. board_event.subcategory = LPFC_EVENT_PORTINTERR;
  1579. shost = lpfc_shost_from_vport(phba->pport);
  1580. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1581. sizeof(board_event),
  1582. (char *) &board_event,
  1583. LPFC_NL_VENDOR_ID);
  1584. }
  1585. /**
  1586. * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
  1587. * @phba: pointer to lpfc hba data structure.
  1588. *
  1589. * This routine is invoked to handle the following HBA hardware error
  1590. * conditions:
  1591. * 1 - HBA error attention interrupt
  1592. * 2 - DMA ring index out of range
  1593. * 3 - Mailbox command came back as unknown
  1594. **/
  1595. static void
  1596. lpfc_handle_eratt_s3(struct lpfc_hba *phba)
  1597. {
  1598. struct lpfc_vport *vport = phba->pport;
  1599. struct lpfc_sli *psli = &phba->sli;
  1600. uint32_t event_data;
  1601. unsigned long temperature;
  1602. struct temp_event temp_event_data;
  1603. struct Scsi_Host *shost;
  1604. /* If the pci channel is offline, ignore possible errors,
  1605. * since we cannot communicate with the pci card anyway.
  1606. */
  1607. if (pci_channel_offline(phba->pcidev)) {
  1608. spin_lock_irq(&phba->hbalock);
  1609. phba->hba_flag &= ~DEFER_ERATT;
  1610. spin_unlock_irq(&phba->hbalock);
  1611. return;
  1612. }
  1613. /* If resets are disabled then leave the HBA alone and return */
  1614. if (!phba->cfg_enable_hba_reset)
  1615. return;
  1616. /* Send an internal error event to mgmt application */
  1617. lpfc_board_errevt_to_mgmt(phba);
  1618. if (phba->hba_flag & DEFER_ERATT)
  1619. lpfc_handle_deferred_eratt(phba);
  1620. if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
  1621. if (phba->work_hs & HS_FFER6)
  1622. /* Re-establishing Link */
  1623. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1624. "1301 Re-establishing Link "
  1625. "Data: x%x x%x x%x\n",
  1626. phba->work_hs, phba->work_status[0],
  1627. phba->work_status[1]);
  1628. if (phba->work_hs & HS_FFER8)
  1629. /* Device Zeroization */
  1630. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1631. "2861 Host Authentication device "
  1632. "zeroization Data:x%x x%x x%x\n",
  1633. phba->work_hs, phba->work_status[0],
  1634. phba->work_status[1]);
  1635. spin_lock_irq(&phba->hbalock);
  1636. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1637. spin_unlock_irq(&phba->hbalock);
  1638. /*
  1639. * Firmware stops when it triggled erratt with HS_FFER6.
  1640. * That could cause the I/Os dropped by the firmware.
  1641. * Error iocb (I/O) on txcmplq and let the SCSI layer
  1642. * retry it after re-establishing link.
  1643. */
  1644. lpfc_sli_abort_fcp_rings(phba);
  1645. /*
  1646. * There was a firmware error. Take the hba offline and then
  1647. * attempt to restart it.
  1648. */
  1649. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1650. lpfc_offline(phba);
  1651. lpfc_sli_brdrestart(phba);
  1652. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  1653. lpfc_unblock_mgmt_io(phba);
  1654. return;
  1655. }
  1656. lpfc_unblock_mgmt_io(phba);
  1657. } else if (phba->work_hs & HS_CRIT_TEMP) {
  1658. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  1659. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  1660. temp_event_data.event_code = LPFC_CRIT_TEMP;
  1661. temp_event_data.data = (uint32_t)temperature;
  1662. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1663. "0406 Adapter maximum temperature exceeded "
  1664. "(%ld), taking this port offline "
  1665. "Data: x%x x%x x%x\n",
  1666. temperature, phba->work_hs,
  1667. phba->work_status[0], phba->work_status[1]);
  1668. shost = lpfc_shost_from_vport(phba->pport);
  1669. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1670. sizeof(temp_event_data),
  1671. (char *) &temp_event_data,
  1672. SCSI_NL_VID_TYPE_PCI
  1673. | PCI_VENDOR_ID_EMULEX);
  1674. spin_lock_irq(&phba->hbalock);
  1675. phba->over_temp_state = HBA_OVER_TEMP;
  1676. spin_unlock_irq(&phba->hbalock);
  1677. lpfc_offline_eratt(phba);
  1678. } else {
  1679. /* The if clause above forces this code path when the status
  1680. * failure is a value other than FFER6. Do not call the offline
  1681. * twice. This is the adapter hardware error path.
  1682. */
  1683. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1684. "0457 Adapter Hardware Error "
  1685. "Data: x%x x%x x%x\n",
  1686. phba->work_hs,
  1687. phba->work_status[0], phba->work_status[1]);
  1688. event_data = FC_REG_DUMP_EVENT;
  1689. shost = lpfc_shost_from_vport(vport);
  1690. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1691. sizeof(event_data), (char *) &event_data,
  1692. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1693. lpfc_offline_eratt(phba);
  1694. }
  1695. return;
  1696. }
  1697. /**
  1698. * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
  1699. * @phba: pointer to lpfc hba data structure.
  1700. * @mbx_action: flag for mailbox shutdown action.
  1701. * @en_rn_msg: send reset/port recovery message.
  1702. * This routine is invoked to perform an SLI4 port PCI function reset in
  1703. * response to port status register polling attention. It waits for port
  1704. * status register (ERR, RDY, RN) bits before proceeding with function reset.
  1705. * During this process, interrupt vectors are freed and later requested
  1706. * for handling possible port resource change.
  1707. **/
  1708. static int
  1709. lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
  1710. bool en_rn_msg)
  1711. {
  1712. int rc;
  1713. uint32_t intr_mode;
  1714. LPFC_MBOXQ_t *mboxq;
  1715. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
  1716. LPFC_SLI_INTF_IF_TYPE_2) {
  1717. /*
  1718. * On error status condition, driver need to wait for port
  1719. * ready before performing reset.
  1720. */
  1721. rc = lpfc_sli4_pdev_status_reg_wait(phba);
  1722. if (rc)
  1723. return rc;
  1724. }
  1725. /* need reset: attempt for port recovery */
  1726. if (en_rn_msg)
  1727. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1728. "2887 Reset Needed: Attempting Port "
  1729. "Recovery...\n");
  1730. /* If we are no wait, the HBA has been reset and is not
  1731. * functional, thus we should clear
  1732. * (LPFC_SLI_ACTIVE | LPFC_SLI_MBOX_ACTIVE) flags.
  1733. */
  1734. if (mbx_action == LPFC_MBX_NO_WAIT) {
  1735. spin_lock_irq(&phba->hbalock);
  1736. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  1737. if (phba->sli.mbox_active) {
  1738. mboxq = phba->sli.mbox_active;
  1739. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  1740. __lpfc_mbox_cmpl_put(phba, mboxq);
  1741. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  1742. phba->sli.mbox_active = NULL;
  1743. }
  1744. spin_unlock_irq(&phba->hbalock);
  1745. }
  1746. lpfc_offline_prep(phba, mbx_action);
  1747. lpfc_sli_flush_io_rings(phba);
  1748. lpfc_offline(phba);
  1749. /* release interrupt for possible resource change */
  1750. lpfc_sli4_disable_intr(phba);
  1751. rc = lpfc_sli_brdrestart(phba);
  1752. if (rc) {
  1753. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1754. "6309 Failed to restart board\n");
  1755. return rc;
  1756. }
  1757. /* request and enable interrupt */
  1758. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  1759. if (intr_mode == LPFC_INTR_ERROR) {
  1760. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1761. "3175 Failed to enable interrupt\n");
  1762. return -EIO;
  1763. }
  1764. phba->intr_mode = intr_mode;
  1765. rc = lpfc_online(phba);
  1766. if (rc == 0)
  1767. lpfc_unblock_mgmt_io(phba);
  1768. return rc;
  1769. }
  1770. /**
  1771. * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
  1772. * @phba: pointer to lpfc hba data structure.
  1773. *
  1774. * This routine is invoked to handle the SLI4 HBA hardware error attention
  1775. * conditions.
  1776. **/
  1777. static void
  1778. lpfc_handle_eratt_s4(struct lpfc_hba *phba)
  1779. {
  1780. struct lpfc_vport *vport = phba->pport;
  1781. uint32_t event_data;
  1782. struct Scsi_Host *shost;
  1783. uint32_t if_type;
  1784. struct lpfc_register portstat_reg = {0};
  1785. uint32_t reg_err1, reg_err2;
  1786. uint32_t uerrlo_reg, uemasklo_reg;
  1787. uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
  1788. bool en_rn_msg = true;
  1789. struct temp_event temp_event_data;
  1790. struct lpfc_register portsmphr_reg;
  1791. int rc, i;
  1792. /* If the pci channel is offline, ignore possible errors, since
  1793. * we cannot communicate with the pci card anyway.
  1794. */
  1795. if (pci_channel_offline(phba->pcidev)) {
  1796. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1797. "3166 pci channel is offline\n");
  1798. lpfc_sli_flush_io_rings(phba);
  1799. return;
  1800. }
  1801. memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
  1802. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  1803. switch (if_type) {
  1804. case LPFC_SLI_INTF_IF_TYPE_0:
  1805. pci_rd_rc1 = lpfc_readl(
  1806. phba->sli4_hba.u.if_type0.UERRLOregaddr,
  1807. &uerrlo_reg);
  1808. pci_rd_rc2 = lpfc_readl(
  1809. phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
  1810. &uemasklo_reg);
  1811. /* consider PCI bus read error as pci_channel_offline */
  1812. if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
  1813. return;
  1814. if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
  1815. lpfc_sli4_offline_eratt(phba);
  1816. return;
  1817. }
  1818. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1819. "7623 Checking UE recoverable");
  1820. for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
  1821. if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  1822. &portsmphr_reg.word0))
  1823. continue;
  1824. smphr_port_status = bf_get(lpfc_port_smphr_port_status,
  1825. &portsmphr_reg);
  1826. if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
  1827. LPFC_PORT_SEM_UE_RECOVERABLE)
  1828. break;
  1829. /*Sleep for 1Sec, before checking SEMAPHORE */
  1830. msleep(1000);
  1831. }
  1832. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1833. "4827 smphr_port_status x%x : Waited %dSec",
  1834. smphr_port_status, i);
  1835. /* Recoverable UE, reset the HBA device */
  1836. if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
  1837. LPFC_PORT_SEM_UE_RECOVERABLE) {
  1838. for (i = 0; i < 20; i++) {
  1839. msleep(1000);
  1840. if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  1841. &portsmphr_reg.word0) &&
  1842. (LPFC_POST_STAGE_PORT_READY ==
  1843. bf_get(lpfc_port_smphr_port_status,
  1844. &portsmphr_reg))) {
  1845. rc = lpfc_sli4_port_sta_fn_reset(phba,
  1846. LPFC_MBX_NO_WAIT, en_rn_msg);
  1847. if (rc == 0)
  1848. return;
  1849. lpfc_printf_log(phba, KERN_ERR,
  1850. LOG_TRACE_EVENT,
  1851. "4215 Failed to recover UE");
  1852. break;
  1853. }
  1854. }
  1855. }
  1856. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1857. "7624 Firmware not ready: Failing UE recovery,"
  1858. " waited %dSec", i);
  1859. phba->link_state = LPFC_HBA_ERROR;
  1860. break;
  1861. case LPFC_SLI_INTF_IF_TYPE_2:
  1862. case LPFC_SLI_INTF_IF_TYPE_6:
  1863. pci_rd_rc1 = lpfc_readl(
  1864. phba->sli4_hba.u.if_type2.STATUSregaddr,
  1865. &portstat_reg.word0);
  1866. /* consider PCI bus read error as pci_channel_offline */
  1867. if (pci_rd_rc1 == -EIO) {
  1868. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1869. "3151 PCI bus read access failure: x%x\n",
  1870. readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
  1871. lpfc_sli4_offline_eratt(phba);
  1872. return;
  1873. }
  1874. reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  1875. reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  1876. if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
  1877. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1878. "2889 Port Overtemperature event, "
  1879. "taking port offline Data: x%x x%x\n",
  1880. reg_err1, reg_err2);
  1881. phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
  1882. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  1883. temp_event_data.event_code = LPFC_CRIT_TEMP;
  1884. temp_event_data.data = 0xFFFFFFFF;
  1885. shost = lpfc_shost_from_vport(phba->pport);
  1886. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1887. sizeof(temp_event_data),
  1888. (char *)&temp_event_data,
  1889. SCSI_NL_VID_TYPE_PCI
  1890. | PCI_VENDOR_ID_EMULEX);
  1891. spin_lock_irq(&phba->hbalock);
  1892. phba->over_temp_state = HBA_OVER_TEMP;
  1893. spin_unlock_irq(&phba->hbalock);
  1894. lpfc_sli4_offline_eratt(phba);
  1895. return;
  1896. }
  1897. if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1898. reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
  1899. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1900. "3143 Port Down: Firmware Update "
  1901. "Detected\n");
  1902. en_rn_msg = false;
  1903. } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1904. reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
  1905. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1906. "3144 Port Down: Debug Dump\n");
  1907. else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1908. reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
  1909. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1910. "3145 Port Down: Provisioning\n");
  1911. /* If resets are disabled then leave the HBA alone and return */
  1912. if (!phba->cfg_enable_hba_reset)
  1913. return;
  1914. /* Check port status register for function reset */
  1915. rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
  1916. en_rn_msg);
  1917. if (rc == 0) {
  1918. /* don't report event on forced debug dump */
  1919. if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1920. reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
  1921. return;
  1922. else
  1923. break;
  1924. }
  1925. /* fall through for not able to recover */
  1926. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1927. "3152 Unrecoverable error\n");
  1928. phba->link_state = LPFC_HBA_ERROR;
  1929. break;
  1930. case LPFC_SLI_INTF_IF_TYPE_1:
  1931. default:
  1932. break;
  1933. }
  1934. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1935. "3123 Report dump event to upper layer\n");
  1936. /* Send an internal error event to mgmt application */
  1937. lpfc_board_errevt_to_mgmt(phba);
  1938. event_data = FC_REG_DUMP_EVENT;
  1939. shost = lpfc_shost_from_vport(vport);
  1940. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1941. sizeof(event_data), (char *) &event_data,
  1942. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1943. }
  1944. /**
  1945. * lpfc_handle_eratt - Wrapper func for handling hba error attention
  1946. * @phba: pointer to lpfc HBA data structure.
  1947. *
  1948. * This routine wraps the actual SLI3 or SLI4 hba error attention handling
  1949. * routine from the API jump table function pointer from the lpfc_hba struct.
  1950. *
  1951. * Return codes
  1952. * 0 - success.
  1953. * Any other value - error.
  1954. **/
  1955. void
  1956. lpfc_handle_eratt(struct lpfc_hba *phba)
  1957. {
  1958. (*phba->lpfc_handle_eratt)(phba);
  1959. }
  1960. /**
  1961. * lpfc_handle_latt - The HBA link event handler
  1962. * @phba: pointer to lpfc hba data structure.
  1963. *
  1964. * This routine is invoked from the worker thread to handle a HBA host
  1965. * attention link event. SLI3 only.
  1966. **/
  1967. void
  1968. lpfc_handle_latt(struct lpfc_hba *phba)
  1969. {
  1970. struct lpfc_vport *vport = phba->pport;
  1971. struct lpfc_sli *psli = &phba->sli;
  1972. LPFC_MBOXQ_t *pmb;
  1973. volatile uint32_t control;
  1974. int rc = 0;
  1975. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1976. if (!pmb) {
  1977. rc = 1;
  1978. goto lpfc_handle_latt_err_exit;
  1979. }
  1980. rc = lpfc_mbox_rsrc_prep(phba, pmb);
  1981. if (rc) {
  1982. rc = 2;
  1983. mempool_free(pmb, phba->mbox_mem_pool);
  1984. goto lpfc_handle_latt_err_exit;
  1985. }
  1986. /* Cleanup any outstanding ELS commands */
  1987. lpfc_els_flush_all_cmd(phba);
  1988. psli->slistat.link_event++;
  1989. lpfc_read_topology(phba, pmb, (struct lpfc_dmabuf *)pmb->ctx_buf);
  1990. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  1991. pmb->vport = vport;
  1992. /* Block ELS IOCBs until we have processed this mbox command */
  1993. phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  1994. rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
  1995. if (rc == MBX_NOT_FINISHED) {
  1996. rc = 4;
  1997. goto lpfc_handle_latt_free_mbuf;
  1998. }
  1999. /* Clear Link Attention in HA REG */
  2000. spin_lock_irq(&phba->hbalock);
  2001. writel(HA_LATT, phba->HAregaddr);
  2002. readl(phba->HAregaddr); /* flush */
  2003. spin_unlock_irq(&phba->hbalock);
  2004. return;
  2005. lpfc_handle_latt_free_mbuf:
  2006. phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  2007. lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
  2008. lpfc_handle_latt_err_exit:
  2009. /* Enable Link attention interrupts */
  2010. spin_lock_irq(&phba->hbalock);
  2011. psli->sli_flag |= LPFC_PROCESS_LA;
  2012. control = readl(phba->HCregaddr);
  2013. control |= HC_LAINT_ENA;
  2014. writel(control, phba->HCregaddr);
  2015. readl(phba->HCregaddr); /* flush */
  2016. /* Clear Link Attention in HA REG */
  2017. writel(HA_LATT, phba->HAregaddr);
  2018. readl(phba->HAregaddr); /* flush */
  2019. spin_unlock_irq(&phba->hbalock);
  2020. lpfc_linkdown(phba);
  2021. phba->link_state = LPFC_HBA_ERROR;
  2022. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  2023. "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
  2024. return;
  2025. }
  2026. static void
  2027. lpfc_fill_vpd(struct lpfc_hba *phba, uint8_t *vpd, int length, int *pindex)
  2028. {
  2029. int i, j;
  2030. while (length > 0) {
  2031. /* Look for Serial Number */
  2032. if ((vpd[*pindex] == 'S') && (vpd[*pindex + 1] == 'N')) {
  2033. *pindex += 2;
  2034. i = vpd[*pindex];
  2035. *pindex += 1;
  2036. j = 0;
  2037. length -= (3+i);
  2038. while (i--) {
  2039. phba->SerialNumber[j++] = vpd[(*pindex)++];
  2040. if (j == 31)
  2041. break;
  2042. }
  2043. phba->SerialNumber[j] = 0;
  2044. continue;
  2045. } else if ((vpd[*pindex] == 'V') && (vpd[*pindex + 1] == '1')) {
  2046. phba->vpd_flag |= VPD_MODEL_DESC;
  2047. *pindex += 2;
  2048. i = vpd[*pindex];
  2049. *pindex += 1;
  2050. j = 0;
  2051. length -= (3+i);
  2052. while (i--) {
  2053. phba->ModelDesc[j++] = vpd[(*pindex)++];
  2054. if (j == 255)
  2055. break;
  2056. }
  2057. phba->ModelDesc[j] = 0;
  2058. continue;
  2059. } else if ((vpd[*pindex] == 'V') && (vpd[*pindex + 1] == '2')) {
  2060. phba->vpd_flag |= VPD_MODEL_NAME;
  2061. *pindex += 2;
  2062. i = vpd[*pindex];
  2063. *pindex += 1;
  2064. j = 0;
  2065. length -= (3+i);
  2066. while (i--) {
  2067. phba->ModelName[j++] = vpd[(*pindex)++];
  2068. if (j == 79)
  2069. break;
  2070. }
  2071. phba->ModelName[j] = 0;
  2072. continue;
  2073. } else if ((vpd[*pindex] == 'V') && (vpd[*pindex + 1] == '3')) {
  2074. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  2075. *pindex += 2;
  2076. i = vpd[*pindex];
  2077. *pindex += 1;
  2078. j = 0;
  2079. length -= (3+i);
  2080. while (i--) {
  2081. phba->ProgramType[j++] = vpd[(*pindex)++];
  2082. if (j == 255)
  2083. break;
  2084. }
  2085. phba->ProgramType[j] = 0;
  2086. continue;
  2087. } else if ((vpd[*pindex] == 'V') && (vpd[*pindex + 1] == '4')) {
  2088. phba->vpd_flag |= VPD_PORT;
  2089. *pindex += 2;
  2090. i = vpd[*pindex];
  2091. *pindex += 1;
  2092. j = 0;
  2093. length -= (3 + i);
  2094. while (i--) {
  2095. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  2096. (phba->sli4_hba.pport_name_sta ==
  2097. LPFC_SLI4_PPNAME_GET)) {
  2098. j++;
  2099. (*pindex)++;
  2100. } else
  2101. phba->Port[j++] = vpd[(*pindex)++];
  2102. if (j == 19)
  2103. break;
  2104. }
  2105. if ((phba->sli_rev != LPFC_SLI_REV4) ||
  2106. (phba->sli4_hba.pport_name_sta ==
  2107. LPFC_SLI4_PPNAME_NON))
  2108. phba->Port[j] = 0;
  2109. continue;
  2110. } else {
  2111. *pindex += 2;
  2112. i = vpd[*pindex];
  2113. *pindex += 1;
  2114. *pindex += i;
  2115. length -= (3 + i);
  2116. }
  2117. }
  2118. }
  2119. /**
  2120. * lpfc_parse_vpd - Parse VPD (Vital Product Data)
  2121. * @phba: pointer to lpfc hba data structure.
  2122. * @vpd: pointer to the vital product data.
  2123. * @len: length of the vital product data in bytes.
  2124. *
  2125. * This routine parses the Vital Product Data (VPD). The VPD is treated as
  2126. * an array of characters. In this routine, the ModelName, ProgramType, and
  2127. * ModelDesc, etc. fields of the phba data structure will be populated.
  2128. *
  2129. * Return codes
  2130. * 0 - pointer to the VPD passed in is NULL
  2131. * 1 - success
  2132. **/
  2133. int
  2134. lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
  2135. {
  2136. uint8_t lenlo, lenhi;
  2137. int Length;
  2138. int i;
  2139. int finished = 0;
  2140. int index = 0;
  2141. if (!vpd)
  2142. return 0;
  2143. /* Vital Product */
  2144. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2145. "0455 Vital Product Data: x%x x%x x%x x%x\n",
  2146. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  2147. (uint32_t) vpd[3]);
  2148. while (!finished && (index < (len - 4))) {
  2149. switch (vpd[index]) {
  2150. case 0x82:
  2151. case 0x91:
  2152. index += 1;
  2153. lenlo = vpd[index];
  2154. index += 1;
  2155. lenhi = vpd[index];
  2156. index += 1;
  2157. i = ((((unsigned short)lenhi) << 8) + lenlo);
  2158. index += i;
  2159. break;
  2160. case 0x90:
  2161. index += 1;
  2162. lenlo = vpd[index];
  2163. index += 1;
  2164. lenhi = vpd[index];
  2165. index += 1;
  2166. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  2167. if (Length > len - index)
  2168. Length = len - index;
  2169. lpfc_fill_vpd(phba, vpd, Length, &index);
  2170. finished = 0;
  2171. break;
  2172. case 0x78:
  2173. finished = 1;
  2174. break;
  2175. default:
  2176. index ++;
  2177. break;
  2178. }
  2179. }
  2180. return(1);
  2181. }
  2182. /**
  2183. * lpfc_get_atto_model_desc - Retrieve ATTO HBA device model name and description
  2184. * @phba: pointer to lpfc hba data structure.
  2185. * @mdp: pointer to the data structure to hold the derived model name.
  2186. * @descp: pointer to the data structure to hold the derived description.
  2187. *
  2188. * This routine retrieves HBA's description based on its registered PCI device
  2189. * ID. The @descp passed into this function points to an array of 256 chars. It
  2190. * shall be returned with the model name, maximum speed, and the host bus type.
  2191. * The @mdp passed into this function points to an array of 80 chars. When the
  2192. * function returns, the @mdp will be filled with the model name.
  2193. **/
  2194. static void
  2195. lpfc_get_atto_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  2196. {
  2197. uint16_t sub_dev_id = phba->pcidev->subsystem_device;
  2198. char *model = "<Unknown>";
  2199. int tbolt = 0;
  2200. switch (sub_dev_id) {
  2201. case PCI_DEVICE_ID_CLRY_161E:
  2202. model = "161E";
  2203. break;
  2204. case PCI_DEVICE_ID_CLRY_162E:
  2205. model = "162E";
  2206. break;
  2207. case PCI_DEVICE_ID_CLRY_164E:
  2208. model = "164E";
  2209. break;
  2210. case PCI_DEVICE_ID_CLRY_161P:
  2211. model = "161P";
  2212. break;
  2213. case PCI_DEVICE_ID_CLRY_162P:
  2214. model = "162P";
  2215. break;
  2216. case PCI_DEVICE_ID_CLRY_164P:
  2217. model = "164P";
  2218. break;
  2219. case PCI_DEVICE_ID_CLRY_321E:
  2220. model = "321E";
  2221. break;
  2222. case PCI_DEVICE_ID_CLRY_322E:
  2223. model = "322E";
  2224. break;
  2225. case PCI_DEVICE_ID_CLRY_324E:
  2226. model = "324E";
  2227. break;
  2228. case PCI_DEVICE_ID_CLRY_321P:
  2229. model = "321P";
  2230. break;
  2231. case PCI_DEVICE_ID_CLRY_322P:
  2232. model = "322P";
  2233. break;
  2234. case PCI_DEVICE_ID_CLRY_324P:
  2235. model = "324P";
  2236. break;
  2237. case PCI_DEVICE_ID_TLFC_2XX2:
  2238. model = "2XX2";
  2239. tbolt = 1;
  2240. break;
  2241. case PCI_DEVICE_ID_TLFC_3162:
  2242. model = "3162";
  2243. tbolt = 1;
  2244. break;
  2245. case PCI_DEVICE_ID_TLFC_3322:
  2246. model = "3322";
  2247. tbolt = 1;
  2248. break;
  2249. default:
  2250. model = "Unknown";
  2251. break;
  2252. }
  2253. if (mdp && mdp[0] == '\0')
  2254. snprintf(mdp, 79, "%s", model);
  2255. if (descp && descp[0] == '\0')
  2256. snprintf(descp, 255,
  2257. "ATTO %s%s, Fibre Channel Adapter Initiator, Port %s",
  2258. (tbolt) ? "ThunderLink FC " : "Celerity FC-",
  2259. model,
  2260. phba->Port);
  2261. }
  2262. /**
  2263. * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
  2264. * @phba: pointer to lpfc hba data structure.
  2265. * @mdp: pointer to the data structure to hold the derived model name.
  2266. * @descp: pointer to the data structure to hold the derived description.
  2267. *
  2268. * This routine retrieves HBA's description based on its registered PCI device
  2269. * ID. The @descp passed into this function points to an array of 256 chars. It
  2270. * shall be returned with the model name, maximum speed, and the host bus type.
  2271. * The @mdp passed into this function points to an array of 80 chars. When the
  2272. * function returns, the @mdp will be filled with the model name.
  2273. **/
  2274. static void
  2275. lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  2276. {
  2277. lpfc_vpd_t *vp;
  2278. uint16_t dev_id = phba->pcidev->device;
  2279. int max_speed;
  2280. int GE = 0;
  2281. int oneConnect = 0; /* default is not a oneConnect */
  2282. struct {
  2283. char *name;
  2284. char *bus;
  2285. char *function;
  2286. } m = {"<Unknown>", "", ""};
  2287. if (mdp && mdp[0] != '\0'
  2288. && descp && descp[0] != '\0')
  2289. return;
  2290. if (phba->pcidev->vendor == PCI_VENDOR_ID_ATTO) {
  2291. lpfc_get_atto_model_desc(phba, mdp, descp);
  2292. return;
  2293. }
  2294. if (phba->lmt & LMT_64Gb)
  2295. max_speed = 64;
  2296. else if (phba->lmt & LMT_32Gb)
  2297. max_speed = 32;
  2298. else if (phba->lmt & LMT_16Gb)
  2299. max_speed = 16;
  2300. else if (phba->lmt & LMT_10Gb)
  2301. max_speed = 10;
  2302. else if (phba->lmt & LMT_8Gb)
  2303. max_speed = 8;
  2304. else if (phba->lmt & LMT_4Gb)
  2305. max_speed = 4;
  2306. else if (phba->lmt & LMT_2Gb)
  2307. max_speed = 2;
  2308. else if (phba->lmt & LMT_1Gb)
  2309. max_speed = 1;
  2310. else
  2311. max_speed = 0;
  2312. vp = &phba->vpd;
  2313. switch (dev_id) {
  2314. case PCI_DEVICE_ID_FIREFLY:
  2315. m = (typeof(m)){"LP6000", "PCI",
  2316. "Obsolete, Unsupported Fibre Channel Adapter"};
  2317. break;
  2318. case PCI_DEVICE_ID_SUPERFLY:
  2319. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  2320. m = (typeof(m)){"LP7000", "PCI", ""};
  2321. else
  2322. m = (typeof(m)){"LP7000E", "PCI", ""};
  2323. m.function = "Obsolete, Unsupported Fibre Channel Adapter";
  2324. break;
  2325. case PCI_DEVICE_ID_DRAGONFLY:
  2326. m = (typeof(m)){"LP8000", "PCI",
  2327. "Obsolete, Unsupported Fibre Channel Adapter"};
  2328. break;
  2329. case PCI_DEVICE_ID_CENTAUR:
  2330. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  2331. m = (typeof(m)){"LP9002", "PCI", ""};
  2332. else
  2333. m = (typeof(m)){"LP9000", "PCI", ""};
  2334. m.function = "Obsolete, Unsupported Fibre Channel Adapter";
  2335. break;
  2336. case PCI_DEVICE_ID_RFLY:
  2337. m = (typeof(m)){"LP952", "PCI",
  2338. "Obsolete, Unsupported Fibre Channel Adapter"};
  2339. break;
  2340. case PCI_DEVICE_ID_PEGASUS:
  2341. m = (typeof(m)){"LP9802", "PCI-X",
  2342. "Obsolete, Unsupported Fibre Channel Adapter"};
  2343. break;
  2344. case PCI_DEVICE_ID_THOR:
  2345. m = (typeof(m)){"LP10000", "PCI-X",
  2346. "Obsolete, Unsupported Fibre Channel Adapter"};
  2347. break;
  2348. case PCI_DEVICE_ID_VIPER:
  2349. m = (typeof(m)){"LPX1000", "PCI-X",
  2350. "Obsolete, Unsupported Fibre Channel Adapter"};
  2351. break;
  2352. case PCI_DEVICE_ID_PFLY:
  2353. m = (typeof(m)){"LP982", "PCI-X",
  2354. "Obsolete, Unsupported Fibre Channel Adapter"};
  2355. break;
  2356. case PCI_DEVICE_ID_TFLY:
  2357. m = (typeof(m)){"LP1050", "PCI-X",
  2358. "Obsolete, Unsupported Fibre Channel Adapter"};
  2359. break;
  2360. case PCI_DEVICE_ID_HELIOS:
  2361. m = (typeof(m)){"LP11000", "PCI-X2",
  2362. "Obsolete, Unsupported Fibre Channel Adapter"};
  2363. break;
  2364. case PCI_DEVICE_ID_HELIOS_SCSP:
  2365. m = (typeof(m)){"LP11000-SP", "PCI-X2",
  2366. "Obsolete, Unsupported Fibre Channel Adapter"};
  2367. break;
  2368. case PCI_DEVICE_ID_HELIOS_DCSP:
  2369. m = (typeof(m)){"LP11002-SP", "PCI-X2",
  2370. "Obsolete, Unsupported Fibre Channel Adapter"};
  2371. break;
  2372. case PCI_DEVICE_ID_NEPTUNE:
  2373. m = (typeof(m)){"LPe1000", "PCIe",
  2374. "Obsolete, Unsupported Fibre Channel Adapter"};
  2375. break;
  2376. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  2377. m = (typeof(m)){"LPe1000-SP", "PCIe",
  2378. "Obsolete, Unsupported Fibre Channel Adapter"};
  2379. break;
  2380. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  2381. m = (typeof(m)){"LPe1002-SP", "PCIe",
  2382. "Obsolete, Unsupported Fibre Channel Adapter"};
  2383. break;
  2384. case PCI_DEVICE_ID_BMID:
  2385. m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
  2386. break;
  2387. case PCI_DEVICE_ID_BSMB:
  2388. m = (typeof(m)){"LP111", "PCI-X2",
  2389. "Obsolete, Unsupported Fibre Channel Adapter"};
  2390. break;
  2391. case PCI_DEVICE_ID_ZEPHYR:
  2392. m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
  2393. break;
  2394. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  2395. m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
  2396. break;
  2397. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  2398. m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
  2399. GE = 1;
  2400. break;
  2401. case PCI_DEVICE_ID_ZMID:
  2402. m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
  2403. break;
  2404. case PCI_DEVICE_ID_ZSMB:
  2405. m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
  2406. break;
  2407. case PCI_DEVICE_ID_LP101:
  2408. m = (typeof(m)){"LP101", "PCI-X",
  2409. "Obsolete, Unsupported Fibre Channel Adapter"};
  2410. break;
  2411. case PCI_DEVICE_ID_LP10000S:
  2412. m = (typeof(m)){"LP10000-S", "PCI",
  2413. "Obsolete, Unsupported Fibre Channel Adapter"};
  2414. break;
  2415. case PCI_DEVICE_ID_LP11000S:
  2416. m = (typeof(m)){"LP11000-S", "PCI-X2",
  2417. "Obsolete, Unsupported Fibre Channel Adapter"};
  2418. break;
  2419. case PCI_DEVICE_ID_LPE11000S:
  2420. m = (typeof(m)){"LPe11000-S", "PCIe",
  2421. "Obsolete, Unsupported Fibre Channel Adapter"};
  2422. break;
  2423. case PCI_DEVICE_ID_SAT:
  2424. m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
  2425. break;
  2426. case PCI_DEVICE_ID_SAT_MID:
  2427. m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
  2428. break;
  2429. case PCI_DEVICE_ID_SAT_SMB:
  2430. m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
  2431. break;
  2432. case PCI_DEVICE_ID_SAT_DCSP:
  2433. m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
  2434. break;
  2435. case PCI_DEVICE_ID_SAT_SCSP:
  2436. m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
  2437. break;
  2438. case PCI_DEVICE_ID_SAT_S:
  2439. m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
  2440. break;
  2441. case PCI_DEVICE_ID_PROTEUS_VF:
  2442. m = (typeof(m)){"LPev12000", "PCIe IOV",
  2443. "Obsolete, Unsupported Fibre Channel Adapter"};
  2444. break;
  2445. case PCI_DEVICE_ID_PROTEUS_PF:
  2446. m = (typeof(m)){"LPev12000", "PCIe IOV",
  2447. "Obsolete, Unsupported Fibre Channel Adapter"};
  2448. break;
  2449. case PCI_DEVICE_ID_PROTEUS_S:
  2450. m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
  2451. "Obsolete, Unsupported Fibre Channel Adapter"};
  2452. break;
  2453. case PCI_DEVICE_ID_TIGERSHARK:
  2454. oneConnect = 1;
  2455. m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
  2456. break;
  2457. case PCI_DEVICE_ID_TOMCAT:
  2458. oneConnect = 1;
  2459. m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
  2460. break;
  2461. case PCI_DEVICE_ID_FALCON:
  2462. m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
  2463. "EmulexSecure Fibre"};
  2464. break;
  2465. case PCI_DEVICE_ID_BALIUS:
  2466. m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
  2467. "Obsolete, Unsupported Fibre Channel Adapter"};
  2468. break;
  2469. case PCI_DEVICE_ID_LANCER_FC:
  2470. m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
  2471. break;
  2472. case PCI_DEVICE_ID_LANCER_FC_VF:
  2473. m = (typeof(m)){"LPe16000", "PCIe",
  2474. "Obsolete, Unsupported Fibre Channel Adapter"};
  2475. break;
  2476. case PCI_DEVICE_ID_LANCER_FCOE:
  2477. oneConnect = 1;
  2478. m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
  2479. break;
  2480. case PCI_DEVICE_ID_LANCER_FCOE_VF:
  2481. oneConnect = 1;
  2482. m = (typeof(m)){"OCe15100", "PCIe",
  2483. "Obsolete, Unsupported FCoE"};
  2484. break;
  2485. case PCI_DEVICE_ID_LANCER_G6_FC:
  2486. m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
  2487. break;
  2488. case PCI_DEVICE_ID_LANCER_G7_FC:
  2489. m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
  2490. break;
  2491. case PCI_DEVICE_ID_LANCER_G7P_FC:
  2492. m = (typeof(m)){"LPe38000", "PCIe", "Fibre Channel Adapter"};
  2493. break;
  2494. case PCI_DEVICE_ID_SKYHAWK:
  2495. case PCI_DEVICE_ID_SKYHAWK_VF:
  2496. oneConnect = 1;
  2497. m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
  2498. break;
  2499. default:
  2500. m = (typeof(m)){"Unknown", "", ""};
  2501. break;
  2502. }
  2503. if (mdp && mdp[0] == '\0')
  2504. snprintf(mdp, 79,"%s", m.name);
  2505. /*
  2506. * oneConnect hba requires special processing, they are all initiators
  2507. * and we put the port number on the end
  2508. */
  2509. if (descp && descp[0] == '\0') {
  2510. if (oneConnect)
  2511. snprintf(descp, 255,
  2512. "Emulex OneConnect %s, %s Initiator %s",
  2513. m.name, m.function,
  2514. phba->Port);
  2515. else if (max_speed == 0)
  2516. snprintf(descp, 255,
  2517. "Emulex %s %s %s",
  2518. m.name, m.bus, m.function);
  2519. else
  2520. snprintf(descp, 255,
  2521. "Emulex %s %d%s %s %s",
  2522. m.name, max_speed, (GE) ? "GE" : "Gb",
  2523. m.bus, m.function);
  2524. }
  2525. }
  2526. /**
  2527. * lpfc_sli3_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
  2528. * @phba: pointer to lpfc hba data structure.
  2529. * @pring: pointer to a IOCB ring.
  2530. * @cnt: the number of IOCBs to be posted to the IOCB ring.
  2531. *
  2532. * This routine posts a given number of IOCBs with the associated DMA buffer
  2533. * descriptors specified by the cnt argument to the given IOCB ring.
  2534. *
  2535. * Return codes
  2536. * The number of IOCBs NOT able to be posted to the IOCB ring.
  2537. **/
  2538. int
  2539. lpfc_sli3_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
  2540. {
  2541. IOCB_t *icmd;
  2542. struct lpfc_iocbq *iocb;
  2543. struct lpfc_dmabuf *mp1, *mp2;
  2544. cnt += pring->missbufcnt;
  2545. /* While there are buffers to post */
  2546. while (cnt > 0) {
  2547. /* Allocate buffer for command iocb */
  2548. iocb = lpfc_sli_get_iocbq(phba);
  2549. if (iocb == NULL) {
  2550. pring->missbufcnt = cnt;
  2551. return cnt;
  2552. }
  2553. icmd = &iocb->iocb;
  2554. /* 2 buffers can be posted per command */
  2555. /* Allocate buffer to post */
  2556. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  2557. if (mp1)
  2558. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
  2559. if (!mp1 || !mp1->virt) {
  2560. kfree(mp1);
  2561. lpfc_sli_release_iocbq(phba, iocb);
  2562. pring->missbufcnt = cnt;
  2563. return cnt;
  2564. }
  2565. INIT_LIST_HEAD(&mp1->list);
  2566. /* Allocate buffer to post */
  2567. if (cnt > 1) {
  2568. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  2569. if (mp2)
  2570. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  2571. &mp2->phys);
  2572. if (!mp2 || !mp2->virt) {
  2573. kfree(mp2);
  2574. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  2575. kfree(mp1);
  2576. lpfc_sli_release_iocbq(phba, iocb);
  2577. pring->missbufcnt = cnt;
  2578. return cnt;
  2579. }
  2580. INIT_LIST_HEAD(&mp2->list);
  2581. } else {
  2582. mp2 = NULL;
  2583. }
  2584. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  2585. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  2586. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  2587. icmd->ulpBdeCount = 1;
  2588. cnt--;
  2589. if (mp2) {
  2590. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  2591. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  2592. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  2593. cnt--;
  2594. icmd->ulpBdeCount = 2;
  2595. }
  2596. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  2597. icmd->ulpLe = 1;
  2598. if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
  2599. IOCB_ERROR) {
  2600. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  2601. kfree(mp1);
  2602. cnt++;
  2603. if (mp2) {
  2604. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  2605. kfree(mp2);
  2606. cnt++;
  2607. }
  2608. lpfc_sli_release_iocbq(phba, iocb);
  2609. pring->missbufcnt = cnt;
  2610. return cnt;
  2611. }
  2612. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  2613. if (mp2)
  2614. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  2615. }
  2616. pring->missbufcnt = 0;
  2617. return 0;
  2618. }
  2619. /**
  2620. * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
  2621. * @phba: pointer to lpfc hba data structure.
  2622. *
  2623. * This routine posts initial receive IOCB buffers to the ELS ring. The
  2624. * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
  2625. * set to 64 IOCBs. SLI3 only.
  2626. *
  2627. * Return codes
  2628. * 0 - success (currently always success)
  2629. **/
  2630. static int
  2631. lpfc_post_rcv_buf(struct lpfc_hba *phba)
  2632. {
  2633. struct lpfc_sli *psli = &phba->sli;
  2634. /* Ring 0, ELS / CT buffers */
  2635. lpfc_sli3_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
  2636. /* Ring 2 - FCP no buffers needed */
  2637. return 0;
  2638. }
  2639. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  2640. /**
  2641. * lpfc_sha_init - Set up initial array of hash table entries
  2642. * @HashResultPointer: pointer to an array as hash table.
  2643. *
  2644. * This routine sets up the initial values to the array of hash table entries
  2645. * for the LC HBAs.
  2646. **/
  2647. static void
  2648. lpfc_sha_init(uint32_t * HashResultPointer)
  2649. {
  2650. HashResultPointer[0] = 0x67452301;
  2651. HashResultPointer[1] = 0xEFCDAB89;
  2652. HashResultPointer[2] = 0x98BADCFE;
  2653. HashResultPointer[3] = 0x10325476;
  2654. HashResultPointer[4] = 0xC3D2E1F0;
  2655. }
  2656. /**
  2657. * lpfc_sha_iterate - Iterate initial hash table with the working hash table
  2658. * @HashResultPointer: pointer to an initial/result hash table.
  2659. * @HashWorkingPointer: pointer to an working hash table.
  2660. *
  2661. * This routine iterates an initial hash table pointed by @HashResultPointer
  2662. * with the values from the working hash table pointeed by @HashWorkingPointer.
  2663. * The results are putting back to the initial hash table, returned through
  2664. * the @HashResultPointer as the result hash table.
  2665. **/
  2666. static void
  2667. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  2668. {
  2669. int t;
  2670. uint32_t TEMP;
  2671. uint32_t A, B, C, D, E;
  2672. t = 16;
  2673. do {
  2674. HashWorkingPointer[t] =
  2675. S(1,
  2676. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  2677. 8] ^
  2678. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  2679. } while (++t <= 79);
  2680. t = 0;
  2681. A = HashResultPointer[0];
  2682. B = HashResultPointer[1];
  2683. C = HashResultPointer[2];
  2684. D = HashResultPointer[3];
  2685. E = HashResultPointer[4];
  2686. do {
  2687. if (t < 20) {
  2688. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  2689. } else if (t < 40) {
  2690. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  2691. } else if (t < 60) {
  2692. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  2693. } else {
  2694. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  2695. }
  2696. TEMP += S(5, A) + E + HashWorkingPointer[t];
  2697. E = D;
  2698. D = C;
  2699. C = S(30, B);
  2700. B = A;
  2701. A = TEMP;
  2702. } while (++t <= 79);
  2703. HashResultPointer[0] += A;
  2704. HashResultPointer[1] += B;
  2705. HashResultPointer[2] += C;
  2706. HashResultPointer[3] += D;
  2707. HashResultPointer[4] += E;
  2708. }
  2709. /**
  2710. * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
  2711. * @RandomChallenge: pointer to the entry of host challenge random number array.
  2712. * @HashWorking: pointer to the entry of the working hash array.
  2713. *
  2714. * This routine calculates the working hash array referred by @HashWorking
  2715. * from the challenge random numbers associated with the host, referred by
  2716. * @RandomChallenge. The result is put into the entry of the working hash
  2717. * array and returned by reference through @HashWorking.
  2718. **/
  2719. static void
  2720. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  2721. {
  2722. *HashWorking = (*RandomChallenge ^ *HashWorking);
  2723. }
  2724. /**
  2725. * lpfc_hba_init - Perform special handling for LC HBA initialization
  2726. * @phba: pointer to lpfc hba data structure.
  2727. * @hbainit: pointer to an array of unsigned 32-bit integers.
  2728. *
  2729. * This routine performs the special handling for LC HBA initialization.
  2730. **/
  2731. void
  2732. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  2733. {
  2734. int t;
  2735. uint32_t *HashWorking;
  2736. uint32_t *pwwnn = (uint32_t *) phba->wwnn;
  2737. HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
  2738. if (!HashWorking)
  2739. return;
  2740. HashWorking[0] = HashWorking[78] = *pwwnn++;
  2741. HashWorking[1] = HashWorking[79] = *pwwnn;
  2742. for (t = 0; t < 7; t++)
  2743. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  2744. lpfc_sha_init(hbainit);
  2745. lpfc_sha_iterate(hbainit, HashWorking);
  2746. kfree(HashWorking);
  2747. }
  2748. /**
  2749. * lpfc_cleanup - Performs vport cleanups before deleting a vport
  2750. * @vport: pointer to a virtual N_Port data structure.
  2751. *
  2752. * This routine performs the necessary cleanups before deleting the @vport.
  2753. * It invokes the discovery state machine to perform necessary state
  2754. * transitions and to release the ndlps associated with the @vport. Note,
  2755. * the physical port is treated as @vport 0.
  2756. **/
  2757. void
  2758. lpfc_cleanup(struct lpfc_vport *vport)
  2759. {
  2760. struct lpfc_hba *phba = vport->phba;
  2761. struct lpfc_nodelist *ndlp, *next_ndlp;
  2762. int i = 0;
  2763. if (phba->link_state > LPFC_LINK_DOWN)
  2764. lpfc_port_link_failure(vport);
  2765. /* Clean up VMID resources */
  2766. if (lpfc_is_vmid_enabled(phba))
  2767. lpfc_vmid_vport_cleanup(vport);
  2768. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2769. if (vport->port_type != LPFC_PHYSICAL_PORT &&
  2770. ndlp->nlp_DID == Fabric_DID) {
  2771. /* Just free up ndlp with Fabric_DID for vports */
  2772. lpfc_nlp_put(ndlp);
  2773. continue;
  2774. }
  2775. if (ndlp->nlp_DID == Fabric_Cntl_DID &&
  2776. ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  2777. lpfc_nlp_put(ndlp);
  2778. continue;
  2779. }
  2780. /* Fabric Ports not in UNMAPPED state are cleaned up in the
  2781. * DEVICE_RM event.
  2782. */
  2783. if (ndlp->nlp_type & NLP_FABRIC &&
  2784. ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
  2785. lpfc_disc_state_machine(vport, ndlp, NULL,
  2786. NLP_EVT_DEVICE_RECOVERY);
  2787. if (!(ndlp->fc4_xpt_flags & (NVME_XPT_REGD|SCSI_XPT_REGD)))
  2788. lpfc_disc_state_machine(vport, ndlp, NULL,
  2789. NLP_EVT_DEVICE_RM);
  2790. }
  2791. /* This is a special case flush to return all
  2792. * IOs before entering this loop. There are
  2793. * two points in the code where a flush is
  2794. * avoided if the FC_UNLOADING flag is set.
  2795. * one is in the multipool destroy,
  2796. * (this prevents a crash) and the other is
  2797. * in the nvme abort handler, ( also prevents
  2798. * a crash). Both of these exceptions are
  2799. * cases where the slot is still accessible.
  2800. * The flush here is only when the pci slot
  2801. * is offline.
  2802. */
  2803. if (vport->load_flag & FC_UNLOADING &&
  2804. pci_channel_offline(phba->pcidev))
  2805. lpfc_sli_flush_io_rings(vport->phba);
  2806. /* At this point, ALL ndlp's should be gone
  2807. * because of the previous NLP_EVT_DEVICE_RM.
  2808. * Lets wait for this to happen, if needed.
  2809. */
  2810. while (!list_empty(&vport->fc_nodes)) {
  2811. if (i++ > 3000) {
  2812. lpfc_printf_vlog(vport, KERN_ERR,
  2813. LOG_TRACE_EVENT,
  2814. "0233 Nodelist not empty\n");
  2815. list_for_each_entry_safe(ndlp, next_ndlp,
  2816. &vport->fc_nodes, nlp_listp) {
  2817. lpfc_printf_vlog(ndlp->vport, KERN_ERR,
  2818. LOG_DISCOVERY,
  2819. "0282 did:x%x ndlp:x%px "
  2820. "refcnt:%d xflags x%x nflag x%x\n",
  2821. ndlp->nlp_DID, (void *)ndlp,
  2822. kref_read(&ndlp->kref),
  2823. ndlp->fc4_xpt_flags,
  2824. ndlp->nlp_flag);
  2825. }
  2826. break;
  2827. }
  2828. /* Wait for any activity on ndlps to settle */
  2829. msleep(10);
  2830. }
  2831. lpfc_cleanup_vports_rrqs(vport, NULL);
  2832. }
  2833. /**
  2834. * lpfc_stop_vport_timers - Stop all the timers associated with a vport
  2835. * @vport: pointer to a virtual N_Port data structure.
  2836. *
  2837. * This routine stops all the timers associated with a @vport. This function
  2838. * is invoked before disabling or deleting a @vport. Note that the physical
  2839. * port is treated as @vport 0.
  2840. **/
  2841. void
  2842. lpfc_stop_vport_timers(struct lpfc_vport *vport)
  2843. {
  2844. del_timer_sync(&vport->els_tmofunc);
  2845. del_timer_sync(&vport->delayed_disc_tmo);
  2846. lpfc_can_disctmo(vport);
  2847. return;
  2848. }
  2849. /**
  2850. * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
  2851. * @phba: pointer to lpfc hba data structure.
  2852. *
  2853. * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
  2854. * caller of this routine should already hold the host lock.
  2855. **/
  2856. void
  2857. __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
  2858. {
  2859. /* Clear pending FCF rediscovery wait flag */
  2860. phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
  2861. /* Now, try to stop the timer */
  2862. del_timer(&phba->fcf.redisc_wait);
  2863. }
  2864. /**
  2865. * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
  2866. * @phba: pointer to lpfc hba data structure.
  2867. *
  2868. * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
  2869. * checks whether the FCF rediscovery wait timer is pending with the host
  2870. * lock held before proceeding with disabling the timer and clearing the
  2871. * wait timer pendig flag.
  2872. **/
  2873. void
  2874. lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
  2875. {
  2876. spin_lock_irq(&phba->hbalock);
  2877. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
  2878. /* FCF rediscovery timer already fired or stopped */
  2879. spin_unlock_irq(&phba->hbalock);
  2880. return;
  2881. }
  2882. __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
  2883. /* Clear failover in progress flags */
  2884. phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
  2885. spin_unlock_irq(&phba->hbalock);
  2886. }
  2887. /**
  2888. * lpfc_cmf_stop - Stop CMF processing
  2889. * @phba: pointer to lpfc hba data structure.
  2890. *
  2891. * This is called when the link goes down or if CMF mode is turned OFF.
  2892. * It is also called when going offline or unloaded just before the
  2893. * congestion info buffer is unregistered.
  2894. **/
  2895. void
  2896. lpfc_cmf_stop(struct lpfc_hba *phba)
  2897. {
  2898. int cpu;
  2899. struct lpfc_cgn_stat *cgs;
  2900. /* We only do something if CMF is enabled */
  2901. if (!phba->sli4_hba.pc_sli4_params.cmf)
  2902. return;
  2903. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  2904. "6221 Stop CMF / Cancel Timer\n");
  2905. /* Cancel the CMF timer */
  2906. hrtimer_cancel(&phba->cmf_timer);
  2907. /* Zero CMF counters */
  2908. atomic_set(&phba->cmf_busy, 0);
  2909. for_each_present_cpu(cpu) {
  2910. cgs = per_cpu_ptr(phba->cmf_stat, cpu);
  2911. atomic64_set(&cgs->total_bytes, 0);
  2912. atomic64_set(&cgs->rcv_bytes, 0);
  2913. atomic_set(&cgs->rx_io_cnt, 0);
  2914. atomic64_set(&cgs->rx_latency, 0);
  2915. }
  2916. atomic_set(&phba->cmf_bw_wait, 0);
  2917. /* Resume any blocked IO - Queue unblock on workqueue */
  2918. queue_work(phba->wq, &phba->unblock_request_work);
  2919. }
  2920. static inline uint64_t
  2921. lpfc_get_max_line_rate(struct lpfc_hba *phba)
  2922. {
  2923. uint64_t rate = lpfc_sli_port_speed_get(phba);
  2924. return ((((unsigned long)rate) * 1024 * 1024) / 10);
  2925. }
  2926. void
  2927. lpfc_cmf_signal_init(struct lpfc_hba *phba)
  2928. {
  2929. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  2930. "6223 Signal CMF init\n");
  2931. /* Use the new fc_linkspeed to recalculate */
  2932. phba->cmf_interval_rate = LPFC_CMF_INTERVAL;
  2933. phba->cmf_max_line_rate = lpfc_get_max_line_rate(phba);
  2934. phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate *
  2935. phba->cmf_interval_rate, 1000);
  2936. phba->cmf_max_bytes_per_interval = phba->cmf_link_byte_count;
  2937. /* This is a signal to firmware to sync up CMF BW with link speed */
  2938. lpfc_issue_cmf_sync_wqe(phba, 0, 0);
  2939. }
  2940. /**
  2941. * lpfc_cmf_start - Start CMF processing
  2942. * @phba: pointer to lpfc hba data structure.
  2943. *
  2944. * This is called when the link comes up or if CMF mode is turned OFF
  2945. * to Monitor or Managed.
  2946. **/
  2947. void
  2948. lpfc_cmf_start(struct lpfc_hba *phba)
  2949. {
  2950. struct lpfc_cgn_stat *cgs;
  2951. int cpu;
  2952. /* We only do something if CMF is enabled */
  2953. if (!phba->sli4_hba.pc_sli4_params.cmf ||
  2954. phba->cmf_active_mode == LPFC_CFG_OFF)
  2955. return;
  2956. /* Reinitialize congestion buffer info */
  2957. lpfc_init_congestion_buf(phba);
  2958. atomic_set(&phba->cgn_fabric_warn_cnt, 0);
  2959. atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
  2960. atomic_set(&phba->cgn_sync_alarm_cnt, 0);
  2961. atomic_set(&phba->cgn_sync_warn_cnt, 0);
  2962. atomic_set(&phba->cmf_busy, 0);
  2963. for_each_present_cpu(cpu) {
  2964. cgs = per_cpu_ptr(phba->cmf_stat, cpu);
  2965. atomic64_set(&cgs->total_bytes, 0);
  2966. atomic64_set(&cgs->rcv_bytes, 0);
  2967. atomic_set(&cgs->rx_io_cnt, 0);
  2968. atomic64_set(&cgs->rx_latency, 0);
  2969. }
  2970. phba->cmf_latency.tv_sec = 0;
  2971. phba->cmf_latency.tv_nsec = 0;
  2972. lpfc_cmf_signal_init(phba);
  2973. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  2974. "6222 Start CMF / Timer\n");
  2975. phba->cmf_timer_cnt = 0;
  2976. hrtimer_start(&phba->cmf_timer,
  2977. ktime_set(0, LPFC_CMF_INTERVAL * 1000000),
  2978. HRTIMER_MODE_REL);
  2979. /* Setup for latency check in IO cmpl routines */
  2980. ktime_get_real_ts64(&phba->cmf_latency);
  2981. atomic_set(&phba->cmf_bw_wait, 0);
  2982. atomic_set(&phba->cmf_stop_io, 0);
  2983. }
  2984. /**
  2985. * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
  2986. * @phba: pointer to lpfc hba data structure.
  2987. *
  2988. * This routine stops all the timers associated with a HBA. This function is
  2989. * invoked before either putting a HBA offline or unloading the driver.
  2990. **/
  2991. void
  2992. lpfc_stop_hba_timers(struct lpfc_hba *phba)
  2993. {
  2994. if (phba->pport)
  2995. lpfc_stop_vport_timers(phba->pport);
  2996. cancel_delayed_work_sync(&phba->eq_delay_work);
  2997. cancel_delayed_work_sync(&phba->idle_stat_delay_work);
  2998. del_timer_sync(&phba->sli.mbox_tmo);
  2999. del_timer_sync(&phba->fabric_block_timer);
  3000. del_timer_sync(&phba->eratt_poll);
  3001. del_timer_sync(&phba->hb_tmofunc);
  3002. if (phba->sli_rev == LPFC_SLI_REV4) {
  3003. del_timer_sync(&phba->rrq_tmr);
  3004. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  3005. }
  3006. phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
  3007. switch (phba->pci_dev_grp) {
  3008. case LPFC_PCI_DEV_LP:
  3009. /* Stop any LightPulse device specific driver timers */
  3010. del_timer_sync(&phba->fcp_poll_timer);
  3011. break;
  3012. case LPFC_PCI_DEV_OC:
  3013. /* Stop any OneConnect device specific driver timers */
  3014. lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
  3015. break;
  3016. default:
  3017. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  3018. "0297 Invalid device group (x%x)\n",
  3019. phba->pci_dev_grp);
  3020. break;
  3021. }
  3022. return;
  3023. }
  3024. /**
  3025. * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
  3026. * @phba: pointer to lpfc hba data structure.
  3027. * @mbx_action: flag for mailbox no wait action.
  3028. *
  3029. * This routine marks a HBA's management interface as blocked. Once the HBA's
  3030. * management interface is marked as blocked, all the user space access to
  3031. * the HBA, whether they are from sysfs interface or libdfc interface will
  3032. * all be blocked. The HBA is set to block the management interface when the
  3033. * driver prepares the HBA interface for online or offline.
  3034. **/
  3035. static void
  3036. lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
  3037. {
  3038. unsigned long iflag;
  3039. uint8_t actcmd = MBX_HEARTBEAT;
  3040. unsigned long timeout;
  3041. spin_lock_irqsave(&phba->hbalock, iflag);
  3042. phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
  3043. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3044. if (mbx_action == LPFC_MBX_NO_WAIT)
  3045. return;
  3046. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  3047. spin_lock_irqsave(&phba->hbalock, iflag);
  3048. if (phba->sli.mbox_active) {
  3049. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  3050. /* Determine how long we might wait for the active mailbox
  3051. * command to be gracefully completed by firmware.
  3052. */
  3053. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  3054. phba->sli.mbox_active) * 1000) + jiffies;
  3055. }
  3056. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3057. /* Wait for the outstnading mailbox command to complete */
  3058. while (phba->sli.mbox_active) {
  3059. /* Check active mailbox complete status every 2ms */
  3060. msleep(2);
  3061. if (time_after(jiffies, timeout)) {
  3062. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  3063. "2813 Mgmt IO is Blocked %x "
  3064. "- mbox cmd %x still active\n",
  3065. phba->sli.sli_flag, actcmd);
  3066. break;
  3067. }
  3068. }
  3069. }
  3070. /**
  3071. * lpfc_sli4_node_prep - Assign RPIs for active nodes.
  3072. * @phba: pointer to lpfc hba data structure.
  3073. *
  3074. * Allocate RPIs for all active remote nodes. This is needed whenever
  3075. * an SLI4 adapter is reset and the driver is not unloading. Its purpose
  3076. * is to fixup the temporary rpi assignments.
  3077. **/
  3078. void
  3079. lpfc_sli4_node_prep(struct lpfc_hba *phba)
  3080. {
  3081. struct lpfc_nodelist *ndlp, *next_ndlp;
  3082. struct lpfc_vport **vports;
  3083. int i, rpi;
  3084. if (phba->sli_rev != LPFC_SLI_REV4)
  3085. return;
  3086. vports = lpfc_create_vport_work_array(phba);
  3087. if (vports == NULL)
  3088. return;
  3089. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3090. if (vports[i]->load_flag & FC_UNLOADING)
  3091. continue;
  3092. list_for_each_entry_safe(ndlp, next_ndlp,
  3093. &vports[i]->fc_nodes,
  3094. nlp_listp) {
  3095. rpi = lpfc_sli4_alloc_rpi(phba);
  3096. if (rpi == LPFC_RPI_ALLOC_ERROR) {
  3097. /* TODO print log? */
  3098. continue;
  3099. }
  3100. ndlp->nlp_rpi = rpi;
  3101. lpfc_printf_vlog(ndlp->vport, KERN_INFO,
  3102. LOG_NODE | LOG_DISCOVERY,
  3103. "0009 Assign RPI x%x to ndlp x%px "
  3104. "DID:x%06x flg:x%x\n",
  3105. ndlp->nlp_rpi, ndlp, ndlp->nlp_DID,
  3106. ndlp->nlp_flag);
  3107. }
  3108. }
  3109. lpfc_destroy_vport_work_array(phba, vports);
  3110. }
  3111. /**
  3112. * lpfc_create_expedite_pool - create expedite pool
  3113. * @phba: pointer to lpfc hba data structure.
  3114. *
  3115. * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0
  3116. * to expedite pool. Mark them as expedite.
  3117. **/
  3118. static void lpfc_create_expedite_pool(struct lpfc_hba *phba)
  3119. {
  3120. struct lpfc_sli4_hdw_queue *qp;
  3121. struct lpfc_io_buf *lpfc_ncmd;
  3122. struct lpfc_io_buf *lpfc_ncmd_next;
  3123. struct lpfc_epd_pool *epd_pool;
  3124. unsigned long iflag;
  3125. epd_pool = &phba->epd_pool;
  3126. qp = &phba->sli4_hba.hdwq[0];
  3127. spin_lock_init(&epd_pool->lock);
  3128. spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
  3129. spin_lock(&epd_pool->lock);
  3130. INIT_LIST_HEAD(&epd_pool->list);
  3131. list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
  3132. &qp->lpfc_io_buf_list_put, list) {
  3133. list_move_tail(&lpfc_ncmd->list, &epd_pool->list);
  3134. lpfc_ncmd->expedite = true;
  3135. qp->put_io_bufs--;
  3136. epd_pool->count++;
  3137. if (epd_pool->count >= XRI_BATCH)
  3138. break;
  3139. }
  3140. spin_unlock(&epd_pool->lock);
  3141. spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
  3142. }
  3143. /**
  3144. * lpfc_destroy_expedite_pool - destroy expedite pool
  3145. * @phba: pointer to lpfc hba data structure.
  3146. *
  3147. * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put
  3148. * of HWQ 0. Clear the mark.
  3149. **/
  3150. static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba)
  3151. {
  3152. struct lpfc_sli4_hdw_queue *qp;
  3153. struct lpfc_io_buf *lpfc_ncmd;
  3154. struct lpfc_io_buf *lpfc_ncmd_next;
  3155. struct lpfc_epd_pool *epd_pool;
  3156. unsigned long iflag;
  3157. epd_pool = &phba->epd_pool;
  3158. qp = &phba->sli4_hba.hdwq[0];
  3159. spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
  3160. spin_lock(&epd_pool->lock);
  3161. list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
  3162. &epd_pool->list, list) {
  3163. list_move_tail(&lpfc_ncmd->list,
  3164. &qp->lpfc_io_buf_list_put);
  3165. lpfc_ncmd->flags = false;
  3166. qp->put_io_bufs++;
  3167. epd_pool->count--;
  3168. }
  3169. spin_unlock(&epd_pool->lock);
  3170. spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
  3171. }
  3172. /**
  3173. * lpfc_create_multixri_pools - create multi-XRI pools
  3174. * @phba: pointer to lpfc hba data structure.
  3175. *
  3176. * This routine initialize public, private per HWQ. Then, move XRIs from
  3177. * lpfc_io_buf_list_put to public pool. High and low watermark are also
  3178. * Initialized.
  3179. **/
  3180. void lpfc_create_multixri_pools(struct lpfc_hba *phba)
  3181. {
  3182. u32 i, j;
  3183. u32 hwq_count;
  3184. u32 count_per_hwq;
  3185. struct lpfc_io_buf *lpfc_ncmd;
  3186. struct lpfc_io_buf *lpfc_ncmd_next;
  3187. unsigned long iflag;
  3188. struct lpfc_sli4_hdw_queue *qp;
  3189. struct lpfc_multixri_pool *multixri_pool;
  3190. struct lpfc_pbl_pool *pbl_pool;
  3191. struct lpfc_pvt_pool *pvt_pool;
  3192. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3193. "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n",
  3194. phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu,
  3195. phba->sli4_hba.io_xri_cnt);
  3196. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
  3197. lpfc_create_expedite_pool(phba);
  3198. hwq_count = phba->cfg_hdw_queue;
  3199. count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count;
  3200. for (i = 0; i < hwq_count; i++) {
  3201. multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL);
  3202. if (!multixri_pool) {
  3203. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3204. "1238 Failed to allocate memory for "
  3205. "multixri_pool\n");
  3206. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
  3207. lpfc_destroy_expedite_pool(phba);
  3208. j = 0;
  3209. while (j < i) {
  3210. qp = &phba->sli4_hba.hdwq[j];
  3211. kfree(qp->p_multixri_pool);
  3212. j++;
  3213. }
  3214. phba->cfg_xri_rebalancing = 0;
  3215. return;
  3216. }
  3217. qp = &phba->sli4_hba.hdwq[i];
  3218. qp->p_multixri_pool = multixri_pool;
  3219. multixri_pool->xri_limit = count_per_hwq;
  3220. multixri_pool->rrb_next_hwqid = i;
  3221. /* Deal with public free xri pool */
  3222. pbl_pool = &multixri_pool->pbl_pool;
  3223. spin_lock_init(&pbl_pool->lock);
  3224. spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
  3225. spin_lock(&pbl_pool->lock);
  3226. INIT_LIST_HEAD(&pbl_pool->list);
  3227. list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
  3228. &qp->lpfc_io_buf_list_put, list) {
  3229. list_move_tail(&lpfc_ncmd->list, &pbl_pool->list);
  3230. qp->put_io_bufs--;
  3231. pbl_pool->count++;
  3232. }
  3233. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3234. "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n",
  3235. pbl_pool->count, i);
  3236. spin_unlock(&pbl_pool->lock);
  3237. spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
  3238. /* Deal with private free xri pool */
  3239. pvt_pool = &multixri_pool->pvt_pool;
  3240. pvt_pool->high_watermark = multixri_pool->xri_limit / 2;
  3241. pvt_pool->low_watermark = XRI_BATCH;
  3242. spin_lock_init(&pvt_pool->lock);
  3243. spin_lock_irqsave(&pvt_pool->lock, iflag);
  3244. INIT_LIST_HEAD(&pvt_pool->list);
  3245. pvt_pool->count = 0;
  3246. spin_unlock_irqrestore(&pvt_pool->lock, iflag);
  3247. }
  3248. }
  3249. /**
  3250. * lpfc_destroy_multixri_pools - destroy multi-XRI pools
  3251. * @phba: pointer to lpfc hba data structure.
  3252. *
  3253. * This routine returns XRIs from public/private to lpfc_io_buf_list_put.
  3254. **/
  3255. static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba)
  3256. {
  3257. u32 i;
  3258. u32 hwq_count;
  3259. struct lpfc_io_buf *lpfc_ncmd;
  3260. struct lpfc_io_buf *lpfc_ncmd_next;
  3261. unsigned long iflag;
  3262. struct lpfc_sli4_hdw_queue *qp;
  3263. struct lpfc_multixri_pool *multixri_pool;
  3264. struct lpfc_pbl_pool *pbl_pool;
  3265. struct lpfc_pvt_pool *pvt_pool;
  3266. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
  3267. lpfc_destroy_expedite_pool(phba);
  3268. if (!(phba->pport->load_flag & FC_UNLOADING))
  3269. lpfc_sli_flush_io_rings(phba);
  3270. hwq_count = phba->cfg_hdw_queue;
  3271. for (i = 0; i < hwq_count; i++) {
  3272. qp = &phba->sli4_hba.hdwq[i];
  3273. multixri_pool = qp->p_multixri_pool;
  3274. if (!multixri_pool)
  3275. continue;
  3276. qp->p_multixri_pool = NULL;
  3277. spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag);
  3278. /* Deal with public free xri pool */
  3279. pbl_pool = &multixri_pool->pbl_pool;
  3280. spin_lock(&pbl_pool->lock);
  3281. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3282. "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n",
  3283. pbl_pool->count, i);
  3284. list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
  3285. &pbl_pool->list, list) {
  3286. list_move_tail(&lpfc_ncmd->list,
  3287. &qp->lpfc_io_buf_list_put);
  3288. qp->put_io_bufs++;
  3289. pbl_pool->count--;
  3290. }
  3291. INIT_LIST_HEAD(&pbl_pool->list);
  3292. pbl_pool->count = 0;
  3293. spin_unlock(&pbl_pool->lock);
  3294. /* Deal with private free xri pool */
  3295. pvt_pool = &multixri_pool->pvt_pool;
  3296. spin_lock(&pvt_pool->lock);
  3297. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3298. "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n",
  3299. pvt_pool->count, i);
  3300. list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
  3301. &pvt_pool->list, list) {
  3302. list_move_tail(&lpfc_ncmd->list,
  3303. &qp->lpfc_io_buf_list_put);
  3304. qp->put_io_bufs++;
  3305. pvt_pool->count--;
  3306. }
  3307. INIT_LIST_HEAD(&pvt_pool->list);
  3308. pvt_pool->count = 0;
  3309. spin_unlock(&pvt_pool->lock);
  3310. spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag);
  3311. kfree(multixri_pool);
  3312. }
  3313. }
  3314. /**
  3315. * lpfc_online - Initialize and bring a HBA online
  3316. * @phba: pointer to lpfc hba data structure.
  3317. *
  3318. * This routine initializes the HBA and brings a HBA online. During this
  3319. * process, the management interface is blocked to prevent user space access
  3320. * to the HBA interfering with the driver initialization.
  3321. *
  3322. * Return codes
  3323. * 0 - successful
  3324. * 1 - failed
  3325. **/
  3326. int
  3327. lpfc_online(struct lpfc_hba *phba)
  3328. {
  3329. struct lpfc_vport *vport;
  3330. struct lpfc_vport **vports;
  3331. int i, error = 0;
  3332. bool vpis_cleared = false;
  3333. if (!phba)
  3334. return 0;
  3335. vport = phba->pport;
  3336. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  3337. return 0;
  3338. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3339. "0458 Bring Adapter online\n");
  3340. lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
  3341. if (phba->sli_rev == LPFC_SLI_REV4) {
  3342. if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
  3343. lpfc_unblock_mgmt_io(phba);
  3344. return 1;
  3345. }
  3346. spin_lock_irq(&phba->hbalock);
  3347. if (!phba->sli4_hba.max_cfg_param.vpi_used)
  3348. vpis_cleared = true;
  3349. spin_unlock_irq(&phba->hbalock);
  3350. /* Reestablish the local initiator port.
  3351. * The offline process destroyed the previous lport.
  3352. */
  3353. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
  3354. !phba->nvmet_support) {
  3355. error = lpfc_nvme_create_localport(phba->pport);
  3356. if (error)
  3357. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  3358. "6132 NVME restore reg failed "
  3359. "on nvmei error x%x\n", error);
  3360. }
  3361. } else {
  3362. lpfc_sli_queue_init(phba);
  3363. if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
  3364. lpfc_unblock_mgmt_io(phba);
  3365. return 1;
  3366. }
  3367. }
  3368. vports = lpfc_create_vport_work_array(phba);
  3369. if (vports != NULL) {
  3370. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3371. struct Scsi_Host *shost;
  3372. shost = lpfc_shost_from_vport(vports[i]);
  3373. spin_lock_irq(shost->host_lock);
  3374. vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
  3375. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  3376. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  3377. if (phba->sli_rev == LPFC_SLI_REV4) {
  3378. vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  3379. if ((vpis_cleared) &&
  3380. (vports[i]->port_type !=
  3381. LPFC_PHYSICAL_PORT))
  3382. vports[i]->vpi = 0;
  3383. }
  3384. spin_unlock_irq(shost->host_lock);
  3385. }
  3386. }
  3387. lpfc_destroy_vport_work_array(phba, vports);
  3388. if (phba->cfg_xri_rebalancing)
  3389. lpfc_create_multixri_pools(phba);
  3390. lpfc_cpuhp_add(phba);
  3391. lpfc_unblock_mgmt_io(phba);
  3392. return 0;
  3393. }
  3394. /**
  3395. * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
  3396. * @phba: pointer to lpfc hba data structure.
  3397. *
  3398. * This routine marks a HBA's management interface as not blocked. Once the
  3399. * HBA's management interface is marked as not blocked, all the user space
  3400. * access to the HBA, whether they are from sysfs interface or libdfc
  3401. * interface will be allowed. The HBA is set to block the management interface
  3402. * when the driver prepares the HBA interface for online or offline and then
  3403. * set to unblock the management interface afterwards.
  3404. **/
  3405. void
  3406. lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
  3407. {
  3408. unsigned long iflag;
  3409. spin_lock_irqsave(&phba->hbalock, iflag);
  3410. phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
  3411. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3412. }
  3413. /**
  3414. * lpfc_offline_prep - Prepare a HBA to be brought offline
  3415. * @phba: pointer to lpfc hba data structure.
  3416. * @mbx_action: flag for mailbox shutdown action.
  3417. *
  3418. * This routine is invoked to prepare a HBA to be brought offline. It performs
  3419. * unregistration login to all the nodes on all vports and flushes the mailbox
  3420. * queue to make it ready to be brought offline.
  3421. **/
  3422. void
  3423. lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
  3424. {
  3425. struct lpfc_vport *vport = phba->pport;
  3426. struct lpfc_nodelist *ndlp, *next_ndlp;
  3427. struct lpfc_vport **vports;
  3428. struct Scsi_Host *shost;
  3429. int i;
  3430. int offline;
  3431. bool hba_pci_err;
  3432. if (vport->fc_flag & FC_OFFLINE_MODE)
  3433. return;
  3434. lpfc_block_mgmt_io(phba, mbx_action);
  3435. lpfc_linkdown(phba);
  3436. offline = pci_channel_offline(phba->pcidev);
  3437. hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags);
  3438. /* Issue an unreg_login to all nodes on all vports */
  3439. vports = lpfc_create_vport_work_array(phba);
  3440. if (vports != NULL) {
  3441. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3442. if (vports[i]->load_flag & FC_UNLOADING)
  3443. continue;
  3444. shost = lpfc_shost_from_vport(vports[i]);
  3445. spin_lock_irq(shost->host_lock);
  3446. vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
  3447. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  3448. vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
  3449. spin_unlock_irq(shost->host_lock);
  3450. shost = lpfc_shost_from_vport(vports[i]);
  3451. list_for_each_entry_safe(ndlp, next_ndlp,
  3452. &vports[i]->fc_nodes,
  3453. nlp_listp) {
  3454. spin_lock_irq(&ndlp->lock);
  3455. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  3456. spin_unlock_irq(&ndlp->lock);
  3457. if (offline || hba_pci_err) {
  3458. spin_lock_irq(&ndlp->lock);
  3459. ndlp->nlp_flag &= ~(NLP_UNREG_INP |
  3460. NLP_RPI_REGISTERED);
  3461. spin_unlock_irq(&ndlp->lock);
  3462. if (phba->sli_rev == LPFC_SLI_REV4)
  3463. lpfc_sli_rpi_release(vports[i],
  3464. ndlp);
  3465. } else {
  3466. lpfc_unreg_rpi(vports[i], ndlp);
  3467. }
  3468. /*
  3469. * Whenever an SLI4 port goes offline, free the
  3470. * RPI. Get a new RPI when the adapter port
  3471. * comes back online.
  3472. */
  3473. if (phba->sli_rev == LPFC_SLI_REV4) {
  3474. lpfc_printf_vlog(vports[i], KERN_INFO,
  3475. LOG_NODE | LOG_DISCOVERY,
  3476. "0011 Free RPI x%x on "
  3477. "ndlp: x%px did x%x\n",
  3478. ndlp->nlp_rpi, ndlp,
  3479. ndlp->nlp_DID);
  3480. lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
  3481. ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
  3482. }
  3483. if (ndlp->nlp_type & NLP_FABRIC) {
  3484. lpfc_disc_state_machine(vports[i], ndlp,
  3485. NULL, NLP_EVT_DEVICE_RECOVERY);
  3486. /* Don't remove the node unless the node
  3487. * has been unregistered with the
  3488. * transport, and we're not in recovery
  3489. * before dev_loss_tmo triggered.
  3490. * Otherwise, let dev_loss take care of
  3491. * the node.
  3492. */
  3493. if (!(ndlp->save_flags &
  3494. NLP_IN_RECOV_POST_DEV_LOSS) &&
  3495. !(ndlp->fc4_xpt_flags &
  3496. (NVME_XPT_REGD | SCSI_XPT_REGD)))
  3497. lpfc_disc_state_machine
  3498. (vports[i], ndlp,
  3499. NULL,
  3500. NLP_EVT_DEVICE_RM);
  3501. }
  3502. }
  3503. }
  3504. }
  3505. lpfc_destroy_vport_work_array(phba, vports);
  3506. lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
  3507. if (phba->wq)
  3508. flush_workqueue(phba->wq);
  3509. }
  3510. /**
  3511. * lpfc_offline - Bring a HBA offline
  3512. * @phba: pointer to lpfc hba data structure.
  3513. *
  3514. * This routine actually brings a HBA offline. It stops all the timers
  3515. * associated with the HBA, brings down the SLI layer, and eventually
  3516. * marks the HBA as in offline state for the upper layer protocol.
  3517. **/
  3518. void
  3519. lpfc_offline(struct lpfc_hba *phba)
  3520. {
  3521. struct Scsi_Host *shost;
  3522. struct lpfc_vport **vports;
  3523. int i;
  3524. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  3525. return;
  3526. /* stop port and all timers associated with this hba */
  3527. lpfc_stop_port(phba);
  3528. /* Tear down the local and target port registrations. The
  3529. * nvme transports need to cleanup.
  3530. */
  3531. lpfc_nvmet_destroy_targetport(phba);
  3532. lpfc_nvme_destroy_localport(phba->pport);
  3533. vports = lpfc_create_vport_work_array(phba);
  3534. if (vports != NULL)
  3535. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  3536. lpfc_stop_vport_timers(vports[i]);
  3537. lpfc_destroy_vport_work_array(phba, vports);
  3538. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3539. "0460 Bring Adapter offline\n");
  3540. /* Bring down the SLI Layer and cleanup. The HBA is offline
  3541. now. */
  3542. lpfc_sli_hba_down(phba);
  3543. spin_lock_irq(&phba->hbalock);
  3544. phba->work_ha = 0;
  3545. spin_unlock_irq(&phba->hbalock);
  3546. vports = lpfc_create_vport_work_array(phba);
  3547. if (vports != NULL)
  3548. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3549. shost = lpfc_shost_from_vport(vports[i]);
  3550. spin_lock_irq(shost->host_lock);
  3551. vports[i]->work_port_events = 0;
  3552. vports[i]->fc_flag |= FC_OFFLINE_MODE;
  3553. spin_unlock_irq(shost->host_lock);
  3554. }
  3555. lpfc_destroy_vport_work_array(phba, vports);
  3556. /* If OFFLINE flag is clear (i.e. unloading), cpuhp removal is handled
  3557. * in hba_unset
  3558. */
  3559. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  3560. __lpfc_cpuhp_remove(phba);
  3561. if (phba->cfg_xri_rebalancing)
  3562. lpfc_destroy_multixri_pools(phba);
  3563. }
  3564. /**
  3565. * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
  3566. * @phba: pointer to lpfc hba data structure.
  3567. *
  3568. * This routine is to free all the SCSI buffers and IOCBs from the driver
  3569. * list back to kernel. It is called from lpfc_pci_remove_one to free
  3570. * the internal resources before the device is removed from the system.
  3571. **/
  3572. static void
  3573. lpfc_scsi_free(struct lpfc_hba *phba)
  3574. {
  3575. struct lpfc_io_buf *sb, *sb_next;
  3576. if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
  3577. return;
  3578. spin_lock_irq(&phba->hbalock);
  3579. /* Release all the lpfc_scsi_bufs maintained by this host. */
  3580. spin_lock(&phba->scsi_buf_list_put_lock);
  3581. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
  3582. list) {
  3583. list_del(&sb->list);
  3584. dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
  3585. sb->dma_handle);
  3586. kfree(sb);
  3587. phba->total_scsi_bufs--;
  3588. }
  3589. spin_unlock(&phba->scsi_buf_list_put_lock);
  3590. spin_lock(&phba->scsi_buf_list_get_lock);
  3591. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
  3592. list) {
  3593. list_del(&sb->list);
  3594. dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
  3595. sb->dma_handle);
  3596. kfree(sb);
  3597. phba->total_scsi_bufs--;
  3598. }
  3599. spin_unlock(&phba->scsi_buf_list_get_lock);
  3600. spin_unlock_irq(&phba->hbalock);
  3601. }
  3602. /**
  3603. * lpfc_io_free - Free all the IO buffers and IOCBs from driver lists
  3604. * @phba: pointer to lpfc hba data structure.
  3605. *
  3606. * This routine is to free all the IO buffers and IOCBs from the driver
  3607. * list back to kernel. It is called from lpfc_pci_remove_one to free
  3608. * the internal resources before the device is removed from the system.
  3609. **/
  3610. void
  3611. lpfc_io_free(struct lpfc_hba *phba)
  3612. {
  3613. struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
  3614. struct lpfc_sli4_hdw_queue *qp;
  3615. int idx;
  3616. for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
  3617. qp = &phba->sli4_hba.hdwq[idx];
  3618. /* Release all the lpfc_nvme_bufs maintained by this host. */
  3619. spin_lock(&qp->io_buf_list_put_lock);
  3620. list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
  3621. &qp->lpfc_io_buf_list_put,
  3622. list) {
  3623. list_del(&lpfc_ncmd->list);
  3624. qp->put_io_bufs--;
  3625. dma_pool_free(phba->lpfc_sg_dma_buf_pool,
  3626. lpfc_ncmd->data, lpfc_ncmd->dma_handle);
  3627. if (phba->cfg_xpsgl && !phba->nvmet_support)
  3628. lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
  3629. lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
  3630. kfree(lpfc_ncmd);
  3631. qp->total_io_bufs--;
  3632. }
  3633. spin_unlock(&qp->io_buf_list_put_lock);
  3634. spin_lock(&qp->io_buf_list_get_lock);
  3635. list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
  3636. &qp->lpfc_io_buf_list_get,
  3637. list) {
  3638. list_del(&lpfc_ncmd->list);
  3639. qp->get_io_bufs--;
  3640. dma_pool_free(phba->lpfc_sg_dma_buf_pool,
  3641. lpfc_ncmd->data, lpfc_ncmd->dma_handle);
  3642. if (phba->cfg_xpsgl && !phba->nvmet_support)
  3643. lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
  3644. lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
  3645. kfree(lpfc_ncmd);
  3646. qp->total_io_bufs--;
  3647. }
  3648. spin_unlock(&qp->io_buf_list_get_lock);
  3649. }
  3650. }
  3651. /**
  3652. * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
  3653. * @phba: pointer to lpfc hba data structure.
  3654. *
  3655. * This routine first calculates the sizes of the current els and allocated
  3656. * scsi sgl lists, and then goes through all sgls to updates the physical
  3657. * XRIs assigned due to port function reset. During port initialization, the
  3658. * current els and allocated scsi sgl lists are 0s.
  3659. *
  3660. * Return codes
  3661. * 0 - successful (for now, it always returns 0)
  3662. **/
  3663. int
  3664. lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
  3665. {
  3666. struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
  3667. uint16_t i, lxri, xri_cnt, els_xri_cnt;
  3668. LIST_HEAD(els_sgl_list);
  3669. int rc;
  3670. /*
  3671. * update on pci function's els xri-sgl list
  3672. */
  3673. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  3674. if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
  3675. /* els xri-sgl expanded */
  3676. xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
  3677. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3678. "3157 ELS xri-sgl count increased from "
  3679. "%d to %d\n", phba->sli4_hba.els_xri_cnt,
  3680. els_xri_cnt);
  3681. /* allocate the additional els sgls */
  3682. for (i = 0; i < xri_cnt; i++) {
  3683. sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
  3684. GFP_KERNEL);
  3685. if (sglq_entry == NULL) {
  3686. lpfc_printf_log(phba, KERN_ERR,
  3687. LOG_TRACE_EVENT,
  3688. "2562 Failure to allocate an "
  3689. "ELS sgl entry:%d\n", i);
  3690. rc = -ENOMEM;
  3691. goto out_free_mem;
  3692. }
  3693. sglq_entry->buff_type = GEN_BUFF_TYPE;
  3694. sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
  3695. &sglq_entry->phys);
  3696. if (sglq_entry->virt == NULL) {
  3697. kfree(sglq_entry);
  3698. lpfc_printf_log(phba, KERN_ERR,
  3699. LOG_TRACE_EVENT,
  3700. "2563 Failure to allocate an "
  3701. "ELS mbuf:%d\n", i);
  3702. rc = -ENOMEM;
  3703. goto out_free_mem;
  3704. }
  3705. sglq_entry->sgl = sglq_entry->virt;
  3706. memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
  3707. sglq_entry->state = SGL_FREED;
  3708. list_add_tail(&sglq_entry->list, &els_sgl_list);
  3709. }
  3710. spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
  3711. list_splice_init(&els_sgl_list,
  3712. &phba->sli4_hba.lpfc_els_sgl_list);
  3713. spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
  3714. } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
  3715. /* els xri-sgl shrinked */
  3716. xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
  3717. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3718. "3158 ELS xri-sgl count decreased from "
  3719. "%d to %d\n", phba->sli4_hba.els_xri_cnt,
  3720. els_xri_cnt);
  3721. spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
  3722. list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
  3723. &els_sgl_list);
  3724. /* release extra els sgls from list */
  3725. for (i = 0; i < xri_cnt; i++) {
  3726. list_remove_head(&els_sgl_list,
  3727. sglq_entry, struct lpfc_sglq, list);
  3728. if (sglq_entry) {
  3729. __lpfc_mbuf_free(phba, sglq_entry->virt,
  3730. sglq_entry->phys);
  3731. kfree(sglq_entry);
  3732. }
  3733. }
  3734. list_splice_init(&els_sgl_list,
  3735. &phba->sli4_hba.lpfc_els_sgl_list);
  3736. spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
  3737. } else
  3738. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3739. "3163 ELS xri-sgl count unchanged: %d\n",
  3740. els_xri_cnt);
  3741. phba->sli4_hba.els_xri_cnt = els_xri_cnt;
  3742. /* update xris to els sgls on the list */
  3743. sglq_entry = NULL;
  3744. sglq_entry_next = NULL;
  3745. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  3746. &phba->sli4_hba.lpfc_els_sgl_list, list) {
  3747. lxri = lpfc_sli4_next_xritag(phba);
  3748. if (lxri == NO_XRI) {
  3749. lpfc_printf_log(phba, KERN_ERR,
  3750. LOG_TRACE_EVENT,
  3751. "2400 Failed to allocate xri for "
  3752. "ELS sgl\n");
  3753. rc = -ENOMEM;
  3754. goto out_free_mem;
  3755. }
  3756. sglq_entry->sli4_lxritag = lxri;
  3757. sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  3758. }
  3759. return 0;
  3760. out_free_mem:
  3761. lpfc_free_els_sgl_list(phba);
  3762. return rc;
  3763. }
  3764. /**
  3765. * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
  3766. * @phba: pointer to lpfc hba data structure.
  3767. *
  3768. * This routine first calculates the sizes of the current els and allocated
  3769. * scsi sgl lists, and then goes through all sgls to updates the physical
  3770. * XRIs assigned due to port function reset. During port initialization, the
  3771. * current els and allocated scsi sgl lists are 0s.
  3772. *
  3773. * Return codes
  3774. * 0 - successful (for now, it always returns 0)
  3775. **/
  3776. int
  3777. lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
  3778. {
  3779. struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
  3780. uint16_t i, lxri, xri_cnt, els_xri_cnt;
  3781. uint16_t nvmet_xri_cnt;
  3782. LIST_HEAD(nvmet_sgl_list);
  3783. int rc;
  3784. /*
  3785. * update on pci function's nvmet xri-sgl list
  3786. */
  3787. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  3788. /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
  3789. nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
  3790. if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
  3791. /* els xri-sgl expanded */
  3792. xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
  3793. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3794. "6302 NVMET xri-sgl cnt grew from %d to %d\n",
  3795. phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
  3796. /* allocate the additional nvmet sgls */
  3797. for (i = 0; i < xri_cnt; i++) {
  3798. sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
  3799. GFP_KERNEL);
  3800. if (sglq_entry == NULL) {
  3801. lpfc_printf_log(phba, KERN_ERR,
  3802. LOG_TRACE_EVENT,
  3803. "6303 Failure to allocate an "
  3804. "NVMET sgl entry:%d\n", i);
  3805. rc = -ENOMEM;
  3806. goto out_free_mem;
  3807. }
  3808. sglq_entry->buff_type = NVMET_BUFF_TYPE;
  3809. sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
  3810. &sglq_entry->phys);
  3811. if (sglq_entry->virt == NULL) {
  3812. kfree(sglq_entry);
  3813. lpfc_printf_log(phba, KERN_ERR,
  3814. LOG_TRACE_EVENT,
  3815. "6304 Failure to allocate an "
  3816. "NVMET buf:%d\n", i);
  3817. rc = -ENOMEM;
  3818. goto out_free_mem;
  3819. }
  3820. sglq_entry->sgl = sglq_entry->virt;
  3821. memset(sglq_entry->sgl, 0,
  3822. phba->cfg_sg_dma_buf_size);
  3823. sglq_entry->state = SGL_FREED;
  3824. list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
  3825. }
  3826. spin_lock_irq(&phba->hbalock);
  3827. spin_lock(&phba->sli4_hba.sgl_list_lock);
  3828. list_splice_init(&nvmet_sgl_list,
  3829. &phba->sli4_hba.lpfc_nvmet_sgl_list);
  3830. spin_unlock(&phba->sli4_hba.sgl_list_lock);
  3831. spin_unlock_irq(&phba->hbalock);
  3832. } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
  3833. /* nvmet xri-sgl shrunk */
  3834. xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
  3835. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3836. "6305 NVMET xri-sgl count decreased from "
  3837. "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
  3838. nvmet_xri_cnt);
  3839. spin_lock_irq(&phba->hbalock);
  3840. spin_lock(&phba->sli4_hba.sgl_list_lock);
  3841. list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
  3842. &nvmet_sgl_list);
  3843. /* release extra nvmet sgls from list */
  3844. for (i = 0; i < xri_cnt; i++) {
  3845. list_remove_head(&nvmet_sgl_list,
  3846. sglq_entry, struct lpfc_sglq, list);
  3847. if (sglq_entry) {
  3848. lpfc_nvmet_buf_free(phba, sglq_entry->virt,
  3849. sglq_entry->phys);
  3850. kfree(sglq_entry);
  3851. }
  3852. }
  3853. list_splice_init(&nvmet_sgl_list,
  3854. &phba->sli4_hba.lpfc_nvmet_sgl_list);
  3855. spin_unlock(&phba->sli4_hba.sgl_list_lock);
  3856. spin_unlock_irq(&phba->hbalock);
  3857. } else
  3858. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3859. "6306 NVMET xri-sgl count unchanged: %d\n",
  3860. nvmet_xri_cnt);
  3861. phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
  3862. /* update xris to nvmet sgls on the list */
  3863. sglq_entry = NULL;
  3864. sglq_entry_next = NULL;
  3865. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  3866. &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
  3867. lxri = lpfc_sli4_next_xritag(phba);
  3868. if (lxri == NO_XRI) {
  3869. lpfc_printf_log(phba, KERN_ERR,
  3870. LOG_TRACE_EVENT,
  3871. "6307 Failed to allocate xri for "
  3872. "NVMET sgl\n");
  3873. rc = -ENOMEM;
  3874. goto out_free_mem;
  3875. }
  3876. sglq_entry->sli4_lxritag = lxri;
  3877. sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  3878. }
  3879. return 0;
  3880. out_free_mem:
  3881. lpfc_free_nvmet_sgl_list(phba);
  3882. return rc;
  3883. }
  3884. int
  3885. lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf)
  3886. {
  3887. LIST_HEAD(blist);
  3888. struct lpfc_sli4_hdw_queue *qp;
  3889. struct lpfc_io_buf *lpfc_cmd;
  3890. struct lpfc_io_buf *iobufp, *prev_iobufp;
  3891. int idx, cnt, xri, inserted;
  3892. cnt = 0;
  3893. for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
  3894. qp = &phba->sli4_hba.hdwq[idx];
  3895. spin_lock_irq(&qp->io_buf_list_get_lock);
  3896. spin_lock(&qp->io_buf_list_put_lock);
  3897. /* Take everything off the get and put lists */
  3898. list_splice_init(&qp->lpfc_io_buf_list_get, &blist);
  3899. list_splice(&qp->lpfc_io_buf_list_put, &blist);
  3900. INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
  3901. INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
  3902. cnt += qp->get_io_bufs + qp->put_io_bufs;
  3903. qp->get_io_bufs = 0;
  3904. qp->put_io_bufs = 0;
  3905. qp->total_io_bufs = 0;
  3906. spin_unlock(&qp->io_buf_list_put_lock);
  3907. spin_unlock_irq(&qp->io_buf_list_get_lock);
  3908. }
  3909. /*
  3910. * Take IO buffers off blist and put on cbuf sorted by XRI.
  3911. * This is because POST_SGL takes a sequential range of XRIs
  3912. * to post to the firmware.
  3913. */
  3914. for (idx = 0; idx < cnt; idx++) {
  3915. list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list);
  3916. if (!lpfc_cmd)
  3917. return cnt;
  3918. if (idx == 0) {
  3919. list_add_tail(&lpfc_cmd->list, cbuf);
  3920. continue;
  3921. }
  3922. xri = lpfc_cmd->cur_iocbq.sli4_xritag;
  3923. inserted = 0;
  3924. prev_iobufp = NULL;
  3925. list_for_each_entry(iobufp, cbuf, list) {
  3926. if (xri < iobufp->cur_iocbq.sli4_xritag) {
  3927. if (prev_iobufp)
  3928. list_add(&lpfc_cmd->list,
  3929. &prev_iobufp->list);
  3930. else
  3931. list_add(&lpfc_cmd->list, cbuf);
  3932. inserted = 1;
  3933. break;
  3934. }
  3935. prev_iobufp = iobufp;
  3936. }
  3937. if (!inserted)
  3938. list_add_tail(&lpfc_cmd->list, cbuf);
  3939. }
  3940. return cnt;
  3941. }
  3942. int
  3943. lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf)
  3944. {
  3945. struct lpfc_sli4_hdw_queue *qp;
  3946. struct lpfc_io_buf *lpfc_cmd;
  3947. int idx, cnt;
  3948. qp = phba->sli4_hba.hdwq;
  3949. cnt = 0;
  3950. while (!list_empty(cbuf)) {
  3951. for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
  3952. list_remove_head(cbuf, lpfc_cmd,
  3953. struct lpfc_io_buf, list);
  3954. if (!lpfc_cmd)
  3955. return cnt;
  3956. cnt++;
  3957. qp = &phba->sli4_hba.hdwq[idx];
  3958. lpfc_cmd->hdwq_no = idx;
  3959. lpfc_cmd->hdwq = qp;
  3960. lpfc_cmd->cur_iocbq.cmd_cmpl = NULL;
  3961. spin_lock(&qp->io_buf_list_put_lock);
  3962. list_add_tail(&lpfc_cmd->list,
  3963. &qp->lpfc_io_buf_list_put);
  3964. qp->put_io_bufs++;
  3965. qp->total_io_bufs++;
  3966. spin_unlock(&qp->io_buf_list_put_lock);
  3967. }
  3968. }
  3969. return cnt;
  3970. }
  3971. /**
  3972. * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping
  3973. * @phba: pointer to lpfc hba data structure.
  3974. *
  3975. * This routine first calculates the sizes of the current els and allocated
  3976. * scsi sgl lists, and then goes through all sgls to updates the physical
  3977. * XRIs assigned due to port function reset. During port initialization, the
  3978. * current els and allocated scsi sgl lists are 0s.
  3979. *
  3980. * Return codes
  3981. * 0 - successful (for now, it always returns 0)
  3982. **/
  3983. int
  3984. lpfc_sli4_io_sgl_update(struct lpfc_hba *phba)
  3985. {
  3986. struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
  3987. uint16_t i, lxri, els_xri_cnt;
  3988. uint16_t io_xri_cnt, io_xri_max;
  3989. LIST_HEAD(io_sgl_list);
  3990. int rc, cnt;
  3991. /*
  3992. * update on pci function's allocated nvme xri-sgl list
  3993. */
  3994. /* maximum number of xris available for nvme buffers */
  3995. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  3996. io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
  3997. phba->sli4_hba.io_xri_max = io_xri_max;
  3998. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3999. "6074 Current allocated XRI sgl count:%d, "
  4000. "maximum XRI count:%d els_xri_cnt:%d\n\n",
  4001. phba->sli4_hba.io_xri_cnt,
  4002. phba->sli4_hba.io_xri_max,
  4003. els_xri_cnt);
  4004. cnt = lpfc_io_buf_flush(phba, &io_sgl_list);
  4005. if (phba->sli4_hba.io_xri_cnt > phba->sli4_hba.io_xri_max) {
  4006. /* max nvme xri shrunk below the allocated nvme buffers */
  4007. io_xri_cnt = phba->sli4_hba.io_xri_cnt -
  4008. phba->sli4_hba.io_xri_max;
  4009. /* release the extra allocated nvme buffers */
  4010. for (i = 0; i < io_xri_cnt; i++) {
  4011. list_remove_head(&io_sgl_list, lpfc_ncmd,
  4012. struct lpfc_io_buf, list);
  4013. if (lpfc_ncmd) {
  4014. dma_pool_free(phba->lpfc_sg_dma_buf_pool,
  4015. lpfc_ncmd->data,
  4016. lpfc_ncmd->dma_handle);
  4017. kfree(lpfc_ncmd);
  4018. }
  4019. }
  4020. phba->sli4_hba.io_xri_cnt -= io_xri_cnt;
  4021. }
  4022. /* update xris associated to remaining allocated nvme buffers */
  4023. lpfc_ncmd = NULL;
  4024. lpfc_ncmd_next = NULL;
  4025. phba->sli4_hba.io_xri_cnt = cnt;
  4026. list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
  4027. &io_sgl_list, list) {
  4028. lxri = lpfc_sli4_next_xritag(phba);
  4029. if (lxri == NO_XRI) {
  4030. lpfc_printf_log(phba, KERN_ERR,
  4031. LOG_TRACE_EVENT,
  4032. "6075 Failed to allocate xri for "
  4033. "nvme buffer\n");
  4034. rc = -ENOMEM;
  4035. goto out_free_mem;
  4036. }
  4037. lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
  4038. lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  4039. }
  4040. cnt = lpfc_io_buf_replenish(phba, &io_sgl_list);
  4041. return 0;
  4042. out_free_mem:
  4043. lpfc_io_free(phba);
  4044. return rc;
  4045. }
  4046. /**
  4047. * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec
  4048. * @phba: Pointer to lpfc hba data structure.
  4049. * @num_to_alloc: The requested number of buffers to allocate.
  4050. *
  4051. * This routine allocates nvme buffers for device with SLI-4 interface spec,
  4052. * the nvme buffer contains all the necessary information needed to initiate
  4053. * an I/O. After allocating up to @num_to_allocate IO buffers and put
  4054. * them on a list, it post them to the port by using SGL block post.
  4055. *
  4056. * Return codes:
  4057. * int - number of IO buffers that were allocated and posted.
  4058. * 0 = failure, less than num_to_alloc is a partial failure.
  4059. **/
  4060. int
  4061. lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc)
  4062. {
  4063. struct lpfc_io_buf *lpfc_ncmd;
  4064. struct lpfc_iocbq *pwqeq;
  4065. uint16_t iotag, lxri = 0;
  4066. int bcnt, num_posted;
  4067. LIST_HEAD(prep_nblist);
  4068. LIST_HEAD(post_nblist);
  4069. LIST_HEAD(nvme_nblist);
  4070. phba->sli4_hba.io_xri_cnt = 0;
  4071. for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
  4072. lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL);
  4073. if (!lpfc_ncmd)
  4074. break;
  4075. /*
  4076. * Get memory from the pci pool to map the virt space to
  4077. * pci bus space for an I/O. The DMA buffer includes the
  4078. * number of SGE's necessary to support the sg_tablesize.
  4079. */
  4080. lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool,
  4081. GFP_KERNEL,
  4082. &lpfc_ncmd->dma_handle);
  4083. if (!lpfc_ncmd->data) {
  4084. kfree(lpfc_ncmd);
  4085. break;
  4086. }
  4087. if (phba->cfg_xpsgl && !phba->nvmet_support) {
  4088. INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list);
  4089. } else {
  4090. /*
  4091. * 4K Page alignment is CRITICAL to BlockGuard, double
  4092. * check to be sure.
  4093. */
  4094. if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
  4095. (((unsigned long)(lpfc_ncmd->data) &
  4096. (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
  4097. lpfc_printf_log(phba, KERN_ERR,
  4098. LOG_TRACE_EVENT,
  4099. "3369 Memory alignment err: "
  4100. "addr=%lx\n",
  4101. (unsigned long)lpfc_ncmd->data);
  4102. dma_pool_free(phba->lpfc_sg_dma_buf_pool,
  4103. lpfc_ncmd->data,
  4104. lpfc_ncmd->dma_handle);
  4105. kfree(lpfc_ncmd);
  4106. break;
  4107. }
  4108. }
  4109. INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list);
  4110. lxri = lpfc_sli4_next_xritag(phba);
  4111. if (lxri == NO_XRI) {
  4112. dma_pool_free(phba->lpfc_sg_dma_buf_pool,
  4113. lpfc_ncmd->data, lpfc_ncmd->dma_handle);
  4114. kfree(lpfc_ncmd);
  4115. break;
  4116. }
  4117. pwqeq = &lpfc_ncmd->cur_iocbq;
  4118. /* Allocate iotag for lpfc_ncmd->cur_iocbq. */
  4119. iotag = lpfc_sli_next_iotag(phba, pwqeq);
  4120. if (iotag == 0) {
  4121. dma_pool_free(phba->lpfc_sg_dma_buf_pool,
  4122. lpfc_ncmd->data, lpfc_ncmd->dma_handle);
  4123. kfree(lpfc_ncmd);
  4124. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4125. "6121 Failed to allocate IOTAG for"
  4126. " XRI:0x%x\n", lxri);
  4127. lpfc_sli4_free_xri(phba, lxri);
  4128. break;
  4129. }
  4130. pwqeq->sli4_lxritag = lxri;
  4131. pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  4132. /* Initialize local short-hand pointers. */
  4133. lpfc_ncmd->dma_sgl = lpfc_ncmd->data;
  4134. lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle;
  4135. lpfc_ncmd->cur_iocbq.io_buf = lpfc_ncmd;
  4136. spin_lock_init(&lpfc_ncmd->buf_lock);
  4137. /* add the nvme buffer to a post list */
  4138. list_add_tail(&lpfc_ncmd->list, &post_nblist);
  4139. phba->sli4_hba.io_xri_cnt++;
  4140. }
  4141. lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
  4142. "6114 Allocate %d out of %d requested new NVME "
  4143. "buffers of size x%zu bytes\n", bcnt, num_to_alloc,
  4144. sizeof(*lpfc_ncmd));
  4145. /* post the list of nvme buffer sgls to port if available */
  4146. if (!list_empty(&post_nblist))
  4147. num_posted = lpfc_sli4_post_io_sgl_list(
  4148. phba, &post_nblist, bcnt);
  4149. else
  4150. num_posted = 0;
  4151. return num_posted;
  4152. }
  4153. static uint64_t
  4154. lpfc_get_wwpn(struct lpfc_hba *phba)
  4155. {
  4156. uint64_t wwn;
  4157. int rc;
  4158. LPFC_MBOXQ_t *mboxq;
  4159. MAILBOX_t *mb;
  4160. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  4161. GFP_KERNEL);
  4162. if (!mboxq)
  4163. return (uint64_t)-1;
  4164. /* First get WWN of HBA instance */
  4165. lpfc_read_nv(phba, mboxq);
  4166. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4167. if (rc != MBX_SUCCESS) {
  4168. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4169. "6019 Mailbox failed , mbxCmd x%x "
  4170. "READ_NV, mbxStatus x%x\n",
  4171. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4172. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  4173. mempool_free(mboxq, phba->mbox_mem_pool);
  4174. return (uint64_t) -1;
  4175. }
  4176. mb = &mboxq->u.mb;
  4177. memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
  4178. /* wwn is WWPN of HBA instance */
  4179. mempool_free(mboxq, phba->mbox_mem_pool);
  4180. if (phba->sli_rev == LPFC_SLI_REV4)
  4181. return be64_to_cpu(wwn);
  4182. else
  4183. return rol64(wwn, 32);
  4184. }
  4185. static unsigned short lpfc_get_sg_tablesize(struct lpfc_hba *phba)
  4186. {
  4187. if (phba->sli_rev == LPFC_SLI_REV4)
  4188. if (phba->cfg_xpsgl && !phba->nvmet_support)
  4189. return LPFC_MAX_SG_TABLESIZE;
  4190. else
  4191. return phba->cfg_scsi_seg_cnt;
  4192. else
  4193. return phba->cfg_sg_seg_cnt;
  4194. }
  4195. /**
  4196. * lpfc_vmid_res_alloc - Allocates resources for VMID
  4197. * @phba: pointer to lpfc hba data structure.
  4198. * @vport: pointer to vport data structure
  4199. *
  4200. * This routine allocated the resources needed for the VMID.
  4201. *
  4202. * Return codes
  4203. * 0 on Success
  4204. * Non-0 on Failure
  4205. */
  4206. static int
  4207. lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport)
  4208. {
  4209. /* VMID feature is supported only on SLI4 */
  4210. if (phba->sli_rev == LPFC_SLI_REV3) {
  4211. phba->cfg_vmid_app_header = 0;
  4212. phba->cfg_vmid_priority_tagging = 0;
  4213. }
  4214. if (lpfc_is_vmid_enabled(phba)) {
  4215. vport->vmid =
  4216. kcalloc(phba->cfg_max_vmid, sizeof(struct lpfc_vmid),
  4217. GFP_KERNEL);
  4218. if (!vport->vmid)
  4219. return -ENOMEM;
  4220. rwlock_init(&vport->vmid_lock);
  4221. /* Set the VMID parameters for the vport */
  4222. vport->vmid_priority_tagging = phba->cfg_vmid_priority_tagging;
  4223. vport->vmid_inactivity_timeout =
  4224. phba->cfg_vmid_inactivity_timeout;
  4225. vport->max_vmid = phba->cfg_max_vmid;
  4226. vport->cur_vmid_cnt = 0;
  4227. vport->vmid_priority_range = bitmap_zalloc
  4228. (LPFC_VMID_MAX_PRIORITY_RANGE, GFP_KERNEL);
  4229. if (!vport->vmid_priority_range) {
  4230. kfree(vport->vmid);
  4231. return -ENOMEM;
  4232. }
  4233. hash_init(vport->hash_table);
  4234. }
  4235. return 0;
  4236. }
  4237. /**
  4238. * lpfc_create_port - Create an FC port
  4239. * @phba: pointer to lpfc hba data structure.
  4240. * @instance: a unique integer ID to this FC port.
  4241. * @dev: pointer to the device data structure.
  4242. *
  4243. * This routine creates a FC port for the upper layer protocol. The FC port
  4244. * can be created on top of either a physical port or a virtual port provided
  4245. * by the HBA. This routine also allocates a SCSI host data structure (shost)
  4246. * and associates the FC port created before adding the shost into the SCSI
  4247. * layer.
  4248. *
  4249. * Return codes
  4250. * @vport - pointer to the virtual N_Port data structure.
  4251. * NULL - port create failed.
  4252. **/
  4253. struct lpfc_vport *
  4254. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  4255. {
  4256. struct lpfc_vport *vport;
  4257. struct Scsi_Host *shost = NULL;
  4258. struct scsi_host_template *template;
  4259. int error = 0;
  4260. int i;
  4261. uint64_t wwn;
  4262. bool use_no_reset_hba = false;
  4263. int rc;
  4264. if (lpfc_no_hba_reset_cnt) {
  4265. if (phba->sli_rev < LPFC_SLI_REV4 &&
  4266. dev == &phba->pcidev->dev) {
  4267. /* Reset the port first */
  4268. lpfc_sli_brdrestart(phba);
  4269. rc = lpfc_sli_chipset_init(phba);
  4270. if (rc)
  4271. return NULL;
  4272. }
  4273. wwn = lpfc_get_wwpn(phba);
  4274. }
  4275. for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
  4276. if (wwn == lpfc_no_hba_reset[i]) {
  4277. lpfc_printf_log(phba, KERN_ERR,
  4278. LOG_TRACE_EVENT,
  4279. "6020 Setting use_no_reset port=%llx\n",
  4280. wwn);
  4281. use_no_reset_hba = true;
  4282. break;
  4283. }
  4284. }
  4285. /* Seed template for SCSI host registration */
  4286. if (dev == &phba->pcidev->dev) {
  4287. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
  4288. /* Seed physical port template */
  4289. template = &lpfc_template;
  4290. if (use_no_reset_hba)
  4291. /* template is for a no reset SCSI Host */
  4292. template->eh_host_reset_handler = NULL;
  4293. /* Seed updated value of sg_tablesize */
  4294. template->sg_tablesize = lpfc_get_sg_tablesize(phba);
  4295. } else {
  4296. /* NVMET is for physical port only */
  4297. template = &lpfc_template_nvme;
  4298. }
  4299. } else {
  4300. /* Seed vport template */
  4301. template = &lpfc_vport_template;
  4302. /* Seed updated value of sg_tablesize */
  4303. template->sg_tablesize = lpfc_get_sg_tablesize(phba);
  4304. }
  4305. shost = scsi_host_alloc(template, sizeof(struct lpfc_vport));
  4306. if (!shost)
  4307. goto out;
  4308. vport = (struct lpfc_vport *) shost->hostdata;
  4309. vport->phba = phba;
  4310. vport->load_flag |= FC_LOADING;
  4311. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  4312. vport->fc_rscn_flush = 0;
  4313. lpfc_get_vport_cfgparam(vport);
  4314. /* Adjust value in vport */
  4315. vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type;
  4316. shost->unique_id = instance;
  4317. shost->max_id = LPFC_MAX_TARGET;
  4318. shost->max_lun = vport->cfg_max_luns;
  4319. shost->this_id = -1;
  4320. shost->max_cmd_len = 16;
  4321. if (phba->sli_rev == LPFC_SLI_REV4) {
  4322. if (!phba->cfg_fcp_mq_threshold ||
  4323. phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue)
  4324. phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue;
  4325. shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(),
  4326. phba->cfg_fcp_mq_threshold);
  4327. shost->dma_boundary =
  4328. phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
  4329. } else
  4330. /* SLI-3 has a limited number of hardware queues (3),
  4331. * thus there is only one for FCP processing.
  4332. */
  4333. shost->nr_hw_queues = 1;
  4334. /*
  4335. * Set initial can_queue value since 0 is no longer supported and
  4336. * scsi_add_host will fail. This will be adjusted later based on the
  4337. * max xri value determined in hba setup.
  4338. */
  4339. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  4340. if (dev != &phba->pcidev->dev) {
  4341. shost->transportt = lpfc_vport_transport_template;
  4342. vport->port_type = LPFC_NPIV_PORT;
  4343. } else {
  4344. shost->transportt = lpfc_transport_template;
  4345. vport->port_type = LPFC_PHYSICAL_PORT;
  4346. }
  4347. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
  4348. "9081 CreatePort TMPLATE type %x TBLsize %d "
  4349. "SEGcnt %d/%d\n",
  4350. vport->port_type, shost->sg_tablesize,
  4351. phba->cfg_scsi_seg_cnt, phba->cfg_sg_seg_cnt);
  4352. /* Allocate the resources for VMID */
  4353. rc = lpfc_vmid_res_alloc(phba, vport);
  4354. if (rc)
  4355. goto out_put_shost;
  4356. /* Initialize all internally managed lists. */
  4357. INIT_LIST_HEAD(&vport->fc_nodes);
  4358. INIT_LIST_HEAD(&vport->rcv_buffer_list);
  4359. spin_lock_init(&vport->work_port_lock);
  4360. timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
  4361. timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
  4362. timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
  4363. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
  4364. lpfc_setup_bg(phba, shost);
  4365. error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
  4366. if (error)
  4367. goto out_free_vmid;
  4368. spin_lock_irq(&phba->port_list_lock);
  4369. list_add_tail(&vport->listentry, &phba->port_list);
  4370. spin_unlock_irq(&phba->port_list_lock);
  4371. return vport;
  4372. out_free_vmid:
  4373. kfree(vport->vmid);
  4374. bitmap_free(vport->vmid_priority_range);
  4375. out_put_shost:
  4376. scsi_host_put(shost);
  4377. out:
  4378. return NULL;
  4379. }
  4380. /**
  4381. * destroy_port - destroy an FC port
  4382. * @vport: pointer to an lpfc virtual N_Port data structure.
  4383. *
  4384. * This routine destroys a FC port from the upper layer protocol. All the
  4385. * resources associated with the port are released.
  4386. **/
  4387. void
  4388. destroy_port(struct lpfc_vport *vport)
  4389. {
  4390. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4391. struct lpfc_hba *phba = vport->phba;
  4392. lpfc_debugfs_terminate(vport);
  4393. fc_remove_host(shost);
  4394. scsi_remove_host(shost);
  4395. spin_lock_irq(&phba->port_list_lock);
  4396. list_del_init(&vport->listentry);
  4397. spin_unlock_irq(&phba->port_list_lock);
  4398. lpfc_cleanup(vport);
  4399. return;
  4400. }
  4401. /**
  4402. * lpfc_get_instance - Get a unique integer ID
  4403. *
  4404. * This routine allocates a unique integer ID from lpfc_hba_index pool. It
  4405. * uses the kernel idr facility to perform the task.
  4406. *
  4407. * Return codes:
  4408. * instance - a unique integer ID allocated as the new instance.
  4409. * -1 - lpfc get instance failed.
  4410. **/
  4411. int
  4412. lpfc_get_instance(void)
  4413. {
  4414. int ret;
  4415. ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
  4416. return ret < 0 ? -1 : ret;
  4417. }
  4418. /**
  4419. * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
  4420. * @shost: pointer to SCSI host data structure.
  4421. * @time: elapsed time of the scan in jiffies.
  4422. *
  4423. * This routine is called by the SCSI layer with a SCSI host to determine
  4424. * whether the scan host is finished.
  4425. *
  4426. * Note: there is no scan_start function as adapter initialization will have
  4427. * asynchronously kicked off the link initialization.
  4428. *
  4429. * Return codes
  4430. * 0 - SCSI host scan is not over yet.
  4431. * 1 - SCSI host scan is over.
  4432. **/
  4433. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  4434. {
  4435. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4436. struct lpfc_hba *phba = vport->phba;
  4437. int stat = 0;
  4438. spin_lock_irq(shost->host_lock);
  4439. if (vport->load_flag & FC_UNLOADING) {
  4440. stat = 1;
  4441. goto finished;
  4442. }
  4443. if (time >= msecs_to_jiffies(30 * 1000)) {
  4444. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4445. "0461 Scanning longer than 30 "
  4446. "seconds. Continuing initialization\n");
  4447. stat = 1;
  4448. goto finished;
  4449. }
  4450. if (time >= msecs_to_jiffies(15 * 1000) &&
  4451. phba->link_state <= LPFC_LINK_DOWN) {
  4452. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4453. "0465 Link down longer than 15 "
  4454. "seconds. Continuing initialization\n");
  4455. stat = 1;
  4456. goto finished;
  4457. }
  4458. if (vport->port_state != LPFC_VPORT_READY)
  4459. goto finished;
  4460. if (vport->num_disc_nodes || vport->fc_prli_sent)
  4461. goto finished;
  4462. if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
  4463. goto finished;
  4464. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  4465. goto finished;
  4466. stat = 1;
  4467. finished:
  4468. spin_unlock_irq(shost->host_lock);
  4469. return stat;
  4470. }
  4471. static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost)
  4472. {
  4473. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  4474. struct lpfc_hba *phba = vport->phba;
  4475. fc_host_supported_speeds(shost) = 0;
  4476. /*
  4477. * Avoid reporting supported link speed for FCoE as it can't be
  4478. * controlled via FCoE.
  4479. */
  4480. if (phba->hba_flag & HBA_FCOE_MODE)
  4481. return;
  4482. if (phba->lmt & LMT_256Gb)
  4483. fc_host_supported_speeds(shost) |= FC_PORTSPEED_256GBIT;
  4484. if (phba->lmt & LMT_128Gb)
  4485. fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT;
  4486. if (phba->lmt & LMT_64Gb)
  4487. fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
  4488. if (phba->lmt & LMT_32Gb)
  4489. fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
  4490. if (phba->lmt & LMT_16Gb)
  4491. fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
  4492. if (phba->lmt & LMT_10Gb)
  4493. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  4494. if (phba->lmt & LMT_8Gb)
  4495. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  4496. if (phba->lmt & LMT_4Gb)
  4497. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  4498. if (phba->lmt & LMT_2Gb)
  4499. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  4500. if (phba->lmt & LMT_1Gb)
  4501. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  4502. }
  4503. /**
  4504. * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
  4505. * @shost: pointer to SCSI host data structure.
  4506. *
  4507. * This routine initializes a given SCSI host attributes on a FC port. The
  4508. * SCSI host can be either on top of a physical port or a virtual port.
  4509. **/
  4510. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  4511. {
  4512. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4513. struct lpfc_hba *phba = vport->phba;
  4514. /*
  4515. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  4516. */
  4517. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4518. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4519. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  4520. memset(fc_host_supported_fc4s(shost), 0,
  4521. sizeof(fc_host_supported_fc4s(shost)));
  4522. fc_host_supported_fc4s(shost)[2] = 1;
  4523. fc_host_supported_fc4s(shost)[7] = 1;
  4524. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  4525. sizeof fc_host_symbolic_name(shost));
  4526. lpfc_host_supported_speeds_set(shost);
  4527. fc_host_maxframe_size(shost) =
  4528. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  4529. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  4530. fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
  4531. /* This value is also unchanging */
  4532. memset(fc_host_active_fc4s(shost), 0,
  4533. sizeof(fc_host_active_fc4s(shost)));
  4534. fc_host_active_fc4s(shost)[2] = 1;
  4535. fc_host_active_fc4s(shost)[7] = 1;
  4536. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  4537. spin_lock_irq(shost->host_lock);
  4538. vport->load_flag &= ~FC_LOADING;
  4539. spin_unlock_irq(shost->host_lock);
  4540. }
  4541. /**
  4542. * lpfc_stop_port_s3 - Stop SLI3 device port
  4543. * @phba: pointer to lpfc hba data structure.
  4544. *
  4545. * This routine is invoked to stop an SLI3 device port, it stops the device
  4546. * from generating interrupts and stops the device driver's timers for the
  4547. * device.
  4548. **/
  4549. static void
  4550. lpfc_stop_port_s3(struct lpfc_hba *phba)
  4551. {
  4552. /* Clear all interrupt enable conditions */
  4553. writel(0, phba->HCregaddr);
  4554. readl(phba->HCregaddr); /* flush */
  4555. /* Clear all pending interrupts */
  4556. writel(0xffffffff, phba->HAregaddr);
  4557. readl(phba->HAregaddr); /* flush */
  4558. /* Reset some HBA SLI setup states */
  4559. lpfc_stop_hba_timers(phba);
  4560. phba->pport->work_port_events = 0;
  4561. }
  4562. /**
  4563. * lpfc_stop_port_s4 - Stop SLI4 device port
  4564. * @phba: pointer to lpfc hba data structure.
  4565. *
  4566. * This routine is invoked to stop an SLI4 device port, it stops the device
  4567. * from generating interrupts and stops the device driver's timers for the
  4568. * device.
  4569. **/
  4570. static void
  4571. lpfc_stop_port_s4(struct lpfc_hba *phba)
  4572. {
  4573. /* Reset some HBA SLI4 setup states */
  4574. lpfc_stop_hba_timers(phba);
  4575. if (phba->pport)
  4576. phba->pport->work_port_events = 0;
  4577. phba->sli4_hba.intr_enable = 0;
  4578. }
  4579. /**
  4580. * lpfc_stop_port - Wrapper function for stopping hba port
  4581. * @phba: Pointer to HBA context object.
  4582. *
  4583. * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
  4584. * the API jump table function pointer from the lpfc_hba struct.
  4585. **/
  4586. void
  4587. lpfc_stop_port(struct lpfc_hba *phba)
  4588. {
  4589. phba->lpfc_stop_port(phba);
  4590. if (phba->wq)
  4591. flush_workqueue(phba->wq);
  4592. }
  4593. /**
  4594. * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
  4595. * @phba: Pointer to hba for which this call is being executed.
  4596. *
  4597. * This routine starts the timer waiting for the FCF rediscovery to complete.
  4598. **/
  4599. void
  4600. lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
  4601. {
  4602. unsigned long fcf_redisc_wait_tmo =
  4603. (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
  4604. /* Start fcf rediscovery wait period timer */
  4605. mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
  4606. spin_lock_irq(&phba->hbalock);
  4607. /* Allow action to new fcf asynchronous event */
  4608. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
  4609. /* Mark the FCF rediscovery pending state */
  4610. phba->fcf.fcf_flag |= FCF_REDISC_PEND;
  4611. spin_unlock_irq(&phba->hbalock);
  4612. }
  4613. /**
  4614. * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
  4615. * @t: Timer context used to obtain the pointer to lpfc hba data structure.
  4616. *
  4617. * This routine is invoked when waiting for FCF table rediscover has been
  4618. * timed out. If new FCF record(s) has (have) been discovered during the
  4619. * wait period, a new FCF event shall be added to the FCOE async event
  4620. * list, and then worker thread shall be waked up for processing from the
  4621. * worker thread context.
  4622. **/
  4623. static void
  4624. lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
  4625. {
  4626. struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
  4627. /* Don't send FCF rediscovery event if timer cancelled */
  4628. spin_lock_irq(&phba->hbalock);
  4629. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
  4630. spin_unlock_irq(&phba->hbalock);
  4631. return;
  4632. }
  4633. /* Clear FCF rediscovery timer pending flag */
  4634. phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
  4635. /* FCF rediscovery event to worker thread */
  4636. phba->fcf.fcf_flag |= FCF_REDISC_EVT;
  4637. spin_unlock_irq(&phba->hbalock);
  4638. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  4639. "2776 FCF rediscover quiescent timer expired\n");
  4640. /* wake up worker thread */
  4641. lpfc_worker_wake_up(phba);
  4642. }
  4643. /**
  4644. * lpfc_vmid_poll - VMID timeout detection
  4645. * @t: Timer context used to obtain the pointer to lpfc hba data structure.
  4646. *
  4647. * This routine is invoked when there is no I/O on by a VM for the specified
  4648. * amount of time. When this situation is detected, the VMID has to be
  4649. * deregistered from the switch and all the local resources freed. The VMID
  4650. * will be reassigned to the VM once the I/O begins.
  4651. **/
  4652. static void
  4653. lpfc_vmid_poll(struct timer_list *t)
  4654. {
  4655. struct lpfc_hba *phba = from_timer(phba, t, inactive_vmid_poll);
  4656. u32 wake_up = 0;
  4657. /* check if there is a need to issue QFPA */
  4658. if (phba->pport->vmid_priority_tagging) {
  4659. wake_up = 1;
  4660. phba->pport->work_port_events |= WORKER_CHECK_VMID_ISSUE_QFPA;
  4661. }
  4662. /* Is the vmid inactivity timer enabled */
  4663. if (phba->pport->vmid_inactivity_timeout ||
  4664. phba->pport->load_flag & FC_DEREGISTER_ALL_APP_ID) {
  4665. wake_up = 1;
  4666. phba->pport->work_port_events |= WORKER_CHECK_INACTIVE_VMID;
  4667. }
  4668. if (wake_up)
  4669. lpfc_worker_wake_up(phba);
  4670. /* restart the timer for the next iteration */
  4671. mod_timer(&phba->inactive_vmid_poll, jiffies + msecs_to_jiffies(1000 *
  4672. LPFC_VMID_TIMER));
  4673. }
  4674. /**
  4675. * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
  4676. * @phba: pointer to lpfc hba data structure.
  4677. * @acqe_link: pointer to the async link completion queue entry.
  4678. *
  4679. * This routine is to parse the SLI4 link-attention link fault code.
  4680. **/
  4681. static void
  4682. lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
  4683. struct lpfc_acqe_link *acqe_link)
  4684. {
  4685. switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
  4686. case LPFC_ASYNC_LINK_FAULT_NONE:
  4687. case LPFC_ASYNC_LINK_FAULT_LOCAL:
  4688. case LPFC_ASYNC_LINK_FAULT_REMOTE:
  4689. case LPFC_ASYNC_LINK_FAULT_LR_LRR:
  4690. break;
  4691. default:
  4692. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4693. "0398 Unknown link fault code: x%x\n",
  4694. bf_get(lpfc_acqe_link_fault, acqe_link));
  4695. break;
  4696. }
  4697. }
  4698. /**
  4699. * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
  4700. * @phba: pointer to lpfc hba data structure.
  4701. * @acqe_link: pointer to the async link completion queue entry.
  4702. *
  4703. * This routine is to parse the SLI4 link attention type and translate it
  4704. * into the base driver's link attention type coding.
  4705. *
  4706. * Return: Link attention type in terms of base driver's coding.
  4707. **/
  4708. static uint8_t
  4709. lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
  4710. struct lpfc_acqe_link *acqe_link)
  4711. {
  4712. uint8_t att_type;
  4713. switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
  4714. case LPFC_ASYNC_LINK_STATUS_DOWN:
  4715. case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
  4716. att_type = LPFC_ATT_LINK_DOWN;
  4717. break;
  4718. case LPFC_ASYNC_LINK_STATUS_UP:
  4719. /* Ignore physical link up events - wait for logical link up */
  4720. att_type = LPFC_ATT_RESERVED;
  4721. break;
  4722. case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
  4723. att_type = LPFC_ATT_LINK_UP;
  4724. break;
  4725. default:
  4726. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4727. "0399 Invalid link attention type: x%x\n",
  4728. bf_get(lpfc_acqe_link_status, acqe_link));
  4729. att_type = LPFC_ATT_RESERVED;
  4730. break;
  4731. }
  4732. return att_type;
  4733. }
  4734. /**
  4735. * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
  4736. * @phba: pointer to lpfc hba data structure.
  4737. *
  4738. * This routine is to get an SLI3 FC port's link speed in Mbps.
  4739. *
  4740. * Return: link speed in terms of Mbps.
  4741. **/
  4742. uint32_t
  4743. lpfc_sli_port_speed_get(struct lpfc_hba *phba)
  4744. {
  4745. uint32_t link_speed;
  4746. if (!lpfc_is_link_up(phba))
  4747. return 0;
  4748. if (phba->sli_rev <= LPFC_SLI_REV3) {
  4749. switch (phba->fc_linkspeed) {
  4750. case LPFC_LINK_SPEED_1GHZ:
  4751. link_speed = 1000;
  4752. break;
  4753. case LPFC_LINK_SPEED_2GHZ:
  4754. link_speed = 2000;
  4755. break;
  4756. case LPFC_LINK_SPEED_4GHZ:
  4757. link_speed = 4000;
  4758. break;
  4759. case LPFC_LINK_SPEED_8GHZ:
  4760. link_speed = 8000;
  4761. break;
  4762. case LPFC_LINK_SPEED_10GHZ:
  4763. link_speed = 10000;
  4764. break;
  4765. case LPFC_LINK_SPEED_16GHZ:
  4766. link_speed = 16000;
  4767. break;
  4768. default:
  4769. link_speed = 0;
  4770. }
  4771. } else {
  4772. if (phba->sli4_hba.link_state.logical_speed)
  4773. link_speed =
  4774. phba->sli4_hba.link_state.logical_speed;
  4775. else
  4776. link_speed = phba->sli4_hba.link_state.speed;
  4777. }
  4778. return link_speed;
  4779. }
  4780. /**
  4781. * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
  4782. * @phba: pointer to lpfc hba data structure.
  4783. * @evt_code: asynchronous event code.
  4784. * @speed_code: asynchronous event link speed code.
  4785. *
  4786. * This routine is to parse the giving SLI4 async event link speed code into
  4787. * value of Mbps for the link speed.
  4788. *
  4789. * Return: link speed in terms of Mbps.
  4790. **/
  4791. static uint32_t
  4792. lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
  4793. uint8_t speed_code)
  4794. {
  4795. uint32_t port_speed;
  4796. switch (evt_code) {
  4797. case LPFC_TRAILER_CODE_LINK:
  4798. switch (speed_code) {
  4799. case LPFC_ASYNC_LINK_SPEED_ZERO:
  4800. port_speed = 0;
  4801. break;
  4802. case LPFC_ASYNC_LINK_SPEED_10MBPS:
  4803. port_speed = 10;
  4804. break;
  4805. case LPFC_ASYNC_LINK_SPEED_100MBPS:
  4806. port_speed = 100;
  4807. break;
  4808. case LPFC_ASYNC_LINK_SPEED_1GBPS:
  4809. port_speed = 1000;
  4810. break;
  4811. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  4812. port_speed = 10000;
  4813. break;
  4814. case LPFC_ASYNC_LINK_SPEED_20GBPS:
  4815. port_speed = 20000;
  4816. break;
  4817. case LPFC_ASYNC_LINK_SPEED_25GBPS:
  4818. port_speed = 25000;
  4819. break;
  4820. case LPFC_ASYNC_LINK_SPEED_40GBPS:
  4821. port_speed = 40000;
  4822. break;
  4823. case LPFC_ASYNC_LINK_SPEED_100GBPS:
  4824. port_speed = 100000;
  4825. break;
  4826. default:
  4827. port_speed = 0;
  4828. }
  4829. break;
  4830. case LPFC_TRAILER_CODE_FC:
  4831. switch (speed_code) {
  4832. case LPFC_FC_LA_SPEED_UNKNOWN:
  4833. port_speed = 0;
  4834. break;
  4835. case LPFC_FC_LA_SPEED_1G:
  4836. port_speed = 1000;
  4837. break;
  4838. case LPFC_FC_LA_SPEED_2G:
  4839. port_speed = 2000;
  4840. break;
  4841. case LPFC_FC_LA_SPEED_4G:
  4842. port_speed = 4000;
  4843. break;
  4844. case LPFC_FC_LA_SPEED_8G:
  4845. port_speed = 8000;
  4846. break;
  4847. case LPFC_FC_LA_SPEED_10G:
  4848. port_speed = 10000;
  4849. break;
  4850. case LPFC_FC_LA_SPEED_16G:
  4851. port_speed = 16000;
  4852. break;
  4853. case LPFC_FC_LA_SPEED_32G:
  4854. port_speed = 32000;
  4855. break;
  4856. case LPFC_FC_LA_SPEED_64G:
  4857. port_speed = 64000;
  4858. break;
  4859. case LPFC_FC_LA_SPEED_128G:
  4860. port_speed = 128000;
  4861. break;
  4862. case LPFC_FC_LA_SPEED_256G:
  4863. port_speed = 256000;
  4864. break;
  4865. default:
  4866. port_speed = 0;
  4867. }
  4868. break;
  4869. default:
  4870. port_speed = 0;
  4871. }
  4872. return port_speed;
  4873. }
  4874. /**
  4875. * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
  4876. * @phba: pointer to lpfc hba data structure.
  4877. * @acqe_link: pointer to the async link completion queue entry.
  4878. *
  4879. * This routine is to handle the SLI4 asynchronous FCoE link event.
  4880. **/
  4881. static void
  4882. lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
  4883. struct lpfc_acqe_link *acqe_link)
  4884. {
  4885. LPFC_MBOXQ_t *pmb;
  4886. MAILBOX_t *mb;
  4887. struct lpfc_mbx_read_top *la;
  4888. uint8_t att_type;
  4889. int rc;
  4890. att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
  4891. if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
  4892. return;
  4893. phba->fcoe_eventtag = acqe_link->event_tag;
  4894. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4895. if (!pmb) {
  4896. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4897. "0395 The mboxq allocation failed\n");
  4898. return;
  4899. }
  4900. rc = lpfc_mbox_rsrc_prep(phba, pmb);
  4901. if (rc) {
  4902. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4903. "0396 mailbox allocation failed\n");
  4904. goto out_free_pmb;
  4905. }
  4906. /* Cleanup any outstanding ELS commands */
  4907. lpfc_els_flush_all_cmd(phba);
  4908. /* Block ELS IOCBs until we have done process link event */
  4909. phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
  4910. /* Update link event statistics */
  4911. phba->sli.slistat.link_event++;
  4912. /* Create lpfc_handle_latt mailbox command from link ACQE */
  4913. lpfc_read_topology(phba, pmb, (struct lpfc_dmabuf *)pmb->ctx_buf);
  4914. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  4915. pmb->vport = phba->pport;
  4916. /* Keep the link status for extra SLI4 state machine reference */
  4917. phba->sli4_hba.link_state.speed =
  4918. lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
  4919. bf_get(lpfc_acqe_link_speed, acqe_link));
  4920. phba->sli4_hba.link_state.duplex =
  4921. bf_get(lpfc_acqe_link_duplex, acqe_link);
  4922. phba->sli4_hba.link_state.status =
  4923. bf_get(lpfc_acqe_link_status, acqe_link);
  4924. phba->sli4_hba.link_state.type =
  4925. bf_get(lpfc_acqe_link_type, acqe_link);
  4926. phba->sli4_hba.link_state.number =
  4927. bf_get(lpfc_acqe_link_number, acqe_link);
  4928. phba->sli4_hba.link_state.fault =
  4929. bf_get(lpfc_acqe_link_fault, acqe_link);
  4930. phba->sli4_hba.link_state.logical_speed =
  4931. bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
  4932. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4933. "2900 Async FC/FCoE Link event - Speed:%dGBit "
  4934. "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
  4935. "Logical speed:%dMbps Fault:%d\n",
  4936. phba->sli4_hba.link_state.speed,
  4937. phba->sli4_hba.link_state.topology,
  4938. phba->sli4_hba.link_state.status,
  4939. phba->sli4_hba.link_state.type,
  4940. phba->sli4_hba.link_state.number,
  4941. phba->sli4_hba.link_state.logical_speed,
  4942. phba->sli4_hba.link_state.fault);
  4943. /*
  4944. * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
  4945. * topology info. Note: Optional for non FC-AL ports.
  4946. */
  4947. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  4948. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  4949. if (rc == MBX_NOT_FINISHED)
  4950. goto out_free_pmb;
  4951. return;
  4952. }
  4953. /*
  4954. * For FCoE Mode: fill in all the topology information we need and call
  4955. * the READ_TOPOLOGY completion routine to continue without actually
  4956. * sending the READ_TOPOLOGY mailbox command to the port.
  4957. */
  4958. /* Initialize completion status */
  4959. mb = &pmb->u.mb;
  4960. mb->mbxStatus = MBX_SUCCESS;
  4961. /* Parse port fault information field */
  4962. lpfc_sli4_parse_latt_fault(phba, acqe_link);
  4963. /* Parse and translate link attention fields */
  4964. la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
  4965. la->eventTag = acqe_link->event_tag;
  4966. bf_set(lpfc_mbx_read_top_att_type, la, att_type);
  4967. bf_set(lpfc_mbx_read_top_link_spd, la,
  4968. (bf_get(lpfc_acqe_link_speed, acqe_link)));
  4969. /* Fake the the following irrelvant fields */
  4970. bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
  4971. bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
  4972. bf_set(lpfc_mbx_read_top_il, la, 0);
  4973. bf_set(lpfc_mbx_read_top_pb, la, 0);
  4974. bf_set(lpfc_mbx_read_top_fa, la, 0);
  4975. bf_set(lpfc_mbx_read_top_mm, la, 0);
  4976. /* Invoke the lpfc_handle_latt mailbox command callback function */
  4977. lpfc_mbx_cmpl_read_topology(phba, pmb);
  4978. return;
  4979. out_free_pmb:
  4980. lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
  4981. }
  4982. /**
  4983. * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
  4984. * topology.
  4985. * @phba: pointer to lpfc hba data structure.
  4986. * @speed_code: asynchronous event link speed code.
  4987. *
  4988. * This routine is to parse the giving SLI4 async event link speed code into
  4989. * value of Read topology link speed.
  4990. *
  4991. * Return: link speed in terms of Read topology.
  4992. **/
  4993. static uint8_t
  4994. lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code)
  4995. {
  4996. uint8_t port_speed;
  4997. switch (speed_code) {
  4998. case LPFC_FC_LA_SPEED_1G:
  4999. port_speed = LPFC_LINK_SPEED_1GHZ;
  5000. break;
  5001. case LPFC_FC_LA_SPEED_2G:
  5002. port_speed = LPFC_LINK_SPEED_2GHZ;
  5003. break;
  5004. case LPFC_FC_LA_SPEED_4G:
  5005. port_speed = LPFC_LINK_SPEED_4GHZ;
  5006. break;
  5007. case LPFC_FC_LA_SPEED_8G:
  5008. port_speed = LPFC_LINK_SPEED_8GHZ;
  5009. break;
  5010. case LPFC_FC_LA_SPEED_16G:
  5011. port_speed = LPFC_LINK_SPEED_16GHZ;
  5012. break;
  5013. case LPFC_FC_LA_SPEED_32G:
  5014. port_speed = LPFC_LINK_SPEED_32GHZ;
  5015. break;
  5016. case LPFC_FC_LA_SPEED_64G:
  5017. port_speed = LPFC_LINK_SPEED_64GHZ;
  5018. break;
  5019. case LPFC_FC_LA_SPEED_128G:
  5020. port_speed = LPFC_LINK_SPEED_128GHZ;
  5021. break;
  5022. case LPFC_FC_LA_SPEED_256G:
  5023. port_speed = LPFC_LINK_SPEED_256GHZ;
  5024. break;
  5025. default:
  5026. port_speed = 0;
  5027. break;
  5028. }
  5029. return port_speed;
  5030. }
  5031. void
  5032. lpfc_cgn_dump_rxmonitor(struct lpfc_hba *phba)
  5033. {
  5034. if (!phba->rx_monitor) {
  5035. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  5036. "4411 Rx Monitor Info is empty.\n");
  5037. } else {
  5038. lpfc_rx_monitor_report(phba, phba->rx_monitor, NULL, 0,
  5039. LPFC_MAX_RXMONITOR_DUMP);
  5040. }
  5041. }
  5042. /**
  5043. * lpfc_cgn_update_stat - Save data into congestion stats buffer
  5044. * @phba: pointer to lpfc hba data structure.
  5045. * @dtag: FPIN descriptor received
  5046. *
  5047. * Increment the FPIN received counter/time when it happens.
  5048. */
  5049. void
  5050. lpfc_cgn_update_stat(struct lpfc_hba *phba, uint32_t dtag)
  5051. {
  5052. struct lpfc_cgn_info *cp;
  5053. struct tm broken;
  5054. struct timespec64 cur_time;
  5055. u32 cnt;
  5056. u32 value;
  5057. /* Make sure we have a congestion info buffer */
  5058. if (!phba->cgn_i)
  5059. return;
  5060. cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
  5061. ktime_get_real_ts64(&cur_time);
  5062. time64_to_tm(cur_time.tv_sec, 0, &broken);
  5063. /* Update congestion statistics */
  5064. switch (dtag) {
  5065. case ELS_DTAG_LNK_INTEGRITY:
  5066. cnt = le32_to_cpu(cp->link_integ_notification);
  5067. cnt++;
  5068. cp->link_integ_notification = cpu_to_le32(cnt);
  5069. cp->cgn_stat_lnk_month = broken.tm_mon + 1;
  5070. cp->cgn_stat_lnk_day = broken.tm_mday;
  5071. cp->cgn_stat_lnk_year = broken.tm_year - 100;
  5072. cp->cgn_stat_lnk_hour = broken.tm_hour;
  5073. cp->cgn_stat_lnk_min = broken.tm_min;
  5074. cp->cgn_stat_lnk_sec = broken.tm_sec;
  5075. break;
  5076. case ELS_DTAG_DELIVERY:
  5077. cnt = le32_to_cpu(cp->delivery_notification);
  5078. cnt++;
  5079. cp->delivery_notification = cpu_to_le32(cnt);
  5080. cp->cgn_stat_del_month = broken.tm_mon + 1;
  5081. cp->cgn_stat_del_day = broken.tm_mday;
  5082. cp->cgn_stat_del_year = broken.tm_year - 100;
  5083. cp->cgn_stat_del_hour = broken.tm_hour;
  5084. cp->cgn_stat_del_min = broken.tm_min;
  5085. cp->cgn_stat_del_sec = broken.tm_sec;
  5086. break;
  5087. case ELS_DTAG_PEER_CONGEST:
  5088. cnt = le32_to_cpu(cp->cgn_peer_notification);
  5089. cnt++;
  5090. cp->cgn_peer_notification = cpu_to_le32(cnt);
  5091. cp->cgn_stat_peer_month = broken.tm_mon + 1;
  5092. cp->cgn_stat_peer_day = broken.tm_mday;
  5093. cp->cgn_stat_peer_year = broken.tm_year - 100;
  5094. cp->cgn_stat_peer_hour = broken.tm_hour;
  5095. cp->cgn_stat_peer_min = broken.tm_min;
  5096. cp->cgn_stat_peer_sec = broken.tm_sec;
  5097. break;
  5098. case ELS_DTAG_CONGESTION:
  5099. cnt = le32_to_cpu(cp->cgn_notification);
  5100. cnt++;
  5101. cp->cgn_notification = cpu_to_le32(cnt);
  5102. cp->cgn_stat_cgn_month = broken.tm_mon + 1;
  5103. cp->cgn_stat_cgn_day = broken.tm_mday;
  5104. cp->cgn_stat_cgn_year = broken.tm_year - 100;
  5105. cp->cgn_stat_cgn_hour = broken.tm_hour;
  5106. cp->cgn_stat_cgn_min = broken.tm_min;
  5107. cp->cgn_stat_cgn_sec = broken.tm_sec;
  5108. }
  5109. if (phba->cgn_fpin_frequency &&
  5110. phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) {
  5111. value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency;
  5112. cp->cgn_stat_npm = value;
  5113. }
  5114. value = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
  5115. LPFC_CGN_CRC32_SEED);
  5116. cp->cgn_info_crc = cpu_to_le32(value);
  5117. }
  5118. /**
  5119. * lpfc_cgn_save_evt_cnt - Save data into registered congestion buffer
  5120. * @phba: pointer to lpfc hba data structure.
  5121. *
  5122. * Save the congestion event data every minute.
  5123. * On the hour collapse all the minute data into hour data. Every day
  5124. * collapse all the hour data into daily data. Separate driver
  5125. * and fabrc congestion event counters that will be saved out
  5126. * to the registered congestion buffer every minute.
  5127. */
  5128. static void
  5129. lpfc_cgn_save_evt_cnt(struct lpfc_hba *phba)
  5130. {
  5131. struct lpfc_cgn_info *cp;
  5132. struct tm broken;
  5133. struct timespec64 cur_time;
  5134. uint32_t i, index;
  5135. uint16_t value, mvalue;
  5136. uint64_t bps;
  5137. uint32_t mbps;
  5138. uint32_t dvalue, wvalue, lvalue, avalue;
  5139. uint64_t latsum;
  5140. __le16 *ptr;
  5141. __le32 *lptr;
  5142. __le16 *mptr;
  5143. /* Make sure we have a congestion info buffer */
  5144. if (!phba->cgn_i)
  5145. return;
  5146. cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
  5147. if (time_before(jiffies, phba->cgn_evt_timestamp))
  5148. return;
  5149. phba->cgn_evt_timestamp = jiffies +
  5150. msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN);
  5151. phba->cgn_evt_minute++;
  5152. /* We should get to this point in the routine on 1 minute intervals */
  5153. ktime_get_real_ts64(&cur_time);
  5154. time64_to_tm(cur_time.tv_sec, 0, &broken);
  5155. if (phba->cgn_fpin_frequency &&
  5156. phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) {
  5157. value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency;
  5158. cp->cgn_stat_npm = value;
  5159. }
  5160. /* Read and clear the latency counters for this minute */
  5161. lvalue = atomic_read(&phba->cgn_latency_evt_cnt);
  5162. latsum = atomic64_read(&phba->cgn_latency_evt);
  5163. atomic_set(&phba->cgn_latency_evt_cnt, 0);
  5164. atomic64_set(&phba->cgn_latency_evt, 0);
  5165. /* We need to store MB/sec bandwidth in the congestion information.
  5166. * block_cnt is count of 512 byte blocks for the entire minute,
  5167. * bps will get bytes per sec before finally converting to MB/sec.
  5168. */
  5169. bps = div_u64(phba->rx_block_cnt, LPFC_SEC_MIN) * 512;
  5170. phba->rx_block_cnt = 0;
  5171. mvalue = bps / (1024 * 1024); /* convert to MB/sec */
  5172. /* Every minute */
  5173. /* cgn parameters */
  5174. cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
  5175. cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
  5176. cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
  5177. cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
  5178. /* Fill in default LUN qdepth */
  5179. value = (uint16_t)(phba->pport->cfg_lun_queue_depth);
  5180. cp->cgn_lunq = cpu_to_le16(value);
  5181. /* Record congestion buffer info - every minute
  5182. * cgn_driver_evt_cnt (Driver events)
  5183. * cgn_fabric_warn_cnt (Congestion Warnings)
  5184. * cgn_latency_evt_cnt / cgn_latency_evt (IO Latency)
  5185. * cgn_fabric_alarm_cnt (Congestion Alarms)
  5186. */
  5187. index = ++cp->cgn_index_minute;
  5188. if (cp->cgn_index_minute == LPFC_MIN_HOUR) {
  5189. cp->cgn_index_minute = 0;
  5190. index = 0;
  5191. }
  5192. /* Get the number of driver events in this sample and reset counter */
  5193. dvalue = atomic_read(&phba->cgn_driver_evt_cnt);
  5194. atomic_set(&phba->cgn_driver_evt_cnt, 0);
  5195. /* Get the number of warning events - FPIN and Signal for this minute */
  5196. wvalue = 0;
  5197. if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) ||
  5198. phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
  5199. phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
  5200. wvalue = atomic_read(&phba->cgn_fabric_warn_cnt);
  5201. atomic_set(&phba->cgn_fabric_warn_cnt, 0);
  5202. /* Get the number of alarm events - FPIN and Signal for this minute */
  5203. avalue = 0;
  5204. if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) ||
  5205. phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM)
  5206. avalue = atomic_read(&phba->cgn_fabric_alarm_cnt);
  5207. atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
  5208. /* Collect the driver, warning, alarm and latency counts for this
  5209. * minute into the driver congestion buffer.
  5210. */
  5211. ptr = &cp->cgn_drvr_min[index];
  5212. value = (uint16_t)dvalue;
  5213. *ptr = cpu_to_le16(value);
  5214. ptr = &cp->cgn_warn_min[index];
  5215. value = (uint16_t)wvalue;
  5216. *ptr = cpu_to_le16(value);
  5217. ptr = &cp->cgn_alarm_min[index];
  5218. value = (uint16_t)avalue;
  5219. *ptr = cpu_to_le16(value);
  5220. lptr = &cp->cgn_latency_min[index];
  5221. if (lvalue) {
  5222. lvalue = (uint32_t)div_u64(latsum, lvalue);
  5223. *lptr = cpu_to_le32(lvalue);
  5224. } else {
  5225. *lptr = 0;
  5226. }
  5227. /* Collect the bandwidth value into the driver's congesion buffer. */
  5228. mptr = &cp->cgn_bw_min[index];
  5229. *mptr = cpu_to_le16(mvalue);
  5230. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  5231. "2418 Congestion Info - minute (%d): %d %d %d %d %d\n",
  5232. index, dvalue, wvalue, *lptr, mvalue, avalue);
  5233. /* Every hour */
  5234. if ((phba->cgn_evt_minute % LPFC_MIN_HOUR) == 0) {
  5235. /* Record congestion buffer info - every hour
  5236. * Collapse all minutes into an hour
  5237. */
  5238. index = ++cp->cgn_index_hour;
  5239. if (cp->cgn_index_hour == LPFC_HOUR_DAY) {
  5240. cp->cgn_index_hour = 0;
  5241. index = 0;
  5242. }
  5243. dvalue = 0;
  5244. wvalue = 0;
  5245. lvalue = 0;
  5246. avalue = 0;
  5247. mvalue = 0;
  5248. mbps = 0;
  5249. for (i = 0; i < LPFC_MIN_HOUR; i++) {
  5250. dvalue += le16_to_cpu(cp->cgn_drvr_min[i]);
  5251. wvalue += le16_to_cpu(cp->cgn_warn_min[i]);
  5252. lvalue += le32_to_cpu(cp->cgn_latency_min[i]);
  5253. mbps += le16_to_cpu(cp->cgn_bw_min[i]);
  5254. avalue += le16_to_cpu(cp->cgn_alarm_min[i]);
  5255. }
  5256. if (lvalue) /* Avg of latency averages */
  5257. lvalue /= LPFC_MIN_HOUR;
  5258. if (mbps) /* Avg of Bandwidth averages */
  5259. mvalue = mbps / LPFC_MIN_HOUR;
  5260. lptr = &cp->cgn_drvr_hr[index];
  5261. *lptr = cpu_to_le32(dvalue);
  5262. lptr = &cp->cgn_warn_hr[index];
  5263. *lptr = cpu_to_le32(wvalue);
  5264. lptr = &cp->cgn_latency_hr[index];
  5265. *lptr = cpu_to_le32(lvalue);
  5266. mptr = &cp->cgn_bw_hr[index];
  5267. *mptr = cpu_to_le16(mvalue);
  5268. lptr = &cp->cgn_alarm_hr[index];
  5269. *lptr = cpu_to_le32(avalue);
  5270. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  5271. "2419 Congestion Info - hour "
  5272. "(%d): %d %d %d %d %d\n",
  5273. index, dvalue, wvalue, lvalue, mvalue, avalue);
  5274. }
  5275. /* Every day */
  5276. if ((phba->cgn_evt_minute % LPFC_MIN_DAY) == 0) {
  5277. /* Record congestion buffer info - every hour
  5278. * Collapse all hours into a day. Rotate days
  5279. * after LPFC_MAX_CGN_DAYS.
  5280. */
  5281. index = ++cp->cgn_index_day;
  5282. if (cp->cgn_index_day == LPFC_MAX_CGN_DAYS) {
  5283. cp->cgn_index_day = 0;
  5284. index = 0;
  5285. }
  5286. /* Anytime we overwrite daily index 0, after we wrap,
  5287. * we will be overwriting the oldest day, so we must
  5288. * update the congestion data start time for that day.
  5289. * That start time should have previously been saved after
  5290. * we wrote the last days worth of data.
  5291. */
  5292. if ((phba->hba_flag & HBA_CGN_DAY_WRAP) && index == 0) {
  5293. time64_to_tm(phba->cgn_daily_ts.tv_sec, 0, &broken);
  5294. cp->cgn_info_month = broken.tm_mon + 1;
  5295. cp->cgn_info_day = broken.tm_mday;
  5296. cp->cgn_info_year = broken.tm_year - 100;
  5297. cp->cgn_info_hour = broken.tm_hour;
  5298. cp->cgn_info_minute = broken.tm_min;
  5299. cp->cgn_info_second = broken.tm_sec;
  5300. lpfc_printf_log
  5301. (phba, KERN_INFO, LOG_CGN_MGMT,
  5302. "2646 CGNInfo idx0 Start Time: "
  5303. "%d/%d/%d %d:%d:%d\n",
  5304. cp->cgn_info_day, cp->cgn_info_month,
  5305. cp->cgn_info_year, cp->cgn_info_hour,
  5306. cp->cgn_info_minute, cp->cgn_info_second);
  5307. }
  5308. dvalue = 0;
  5309. wvalue = 0;
  5310. lvalue = 0;
  5311. mvalue = 0;
  5312. mbps = 0;
  5313. avalue = 0;
  5314. for (i = 0; i < LPFC_HOUR_DAY; i++) {
  5315. dvalue += le32_to_cpu(cp->cgn_drvr_hr[i]);
  5316. wvalue += le32_to_cpu(cp->cgn_warn_hr[i]);
  5317. lvalue += le32_to_cpu(cp->cgn_latency_hr[i]);
  5318. mbps += le16_to_cpu(cp->cgn_bw_hr[i]);
  5319. avalue += le32_to_cpu(cp->cgn_alarm_hr[i]);
  5320. }
  5321. if (lvalue) /* Avg of latency averages */
  5322. lvalue /= LPFC_HOUR_DAY;
  5323. if (mbps) /* Avg of Bandwidth averages */
  5324. mvalue = mbps / LPFC_HOUR_DAY;
  5325. lptr = &cp->cgn_drvr_day[index];
  5326. *lptr = cpu_to_le32(dvalue);
  5327. lptr = &cp->cgn_warn_day[index];
  5328. *lptr = cpu_to_le32(wvalue);
  5329. lptr = &cp->cgn_latency_day[index];
  5330. *lptr = cpu_to_le32(lvalue);
  5331. mptr = &cp->cgn_bw_day[index];
  5332. *mptr = cpu_to_le16(mvalue);
  5333. lptr = &cp->cgn_alarm_day[index];
  5334. *lptr = cpu_to_le32(avalue);
  5335. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  5336. "2420 Congestion Info - daily (%d): "
  5337. "%d %d %d %d %d\n",
  5338. index, dvalue, wvalue, lvalue, mvalue, avalue);
  5339. /* We just wrote LPFC_MAX_CGN_DAYS of data,
  5340. * so we are wrapped on any data after this.
  5341. * Save this as the start time for the next day.
  5342. */
  5343. if (index == (LPFC_MAX_CGN_DAYS - 1)) {
  5344. phba->hba_flag |= HBA_CGN_DAY_WRAP;
  5345. ktime_get_real_ts64(&phba->cgn_daily_ts);
  5346. }
  5347. }
  5348. /* Use the frequency found in the last rcv'ed FPIN */
  5349. value = phba->cgn_fpin_frequency;
  5350. cp->cgn_warn_freq = cpu_to_le16(value);
  5351. cp->cgn_alarm_freq = cpu_to_le16(value);
  5352. lvalue = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
  5353. LPFC_CGN_CRC32_SEED);
  5354. cp->cgn_info_crc = cpu_to_le32(lvalue);
  5355. }
  5356. /**
  5357. * lpfc_calc_cmf_latency - latency from start of rxate timer interval
  5358. * @phba: The Hba for which this call is being executed.
  5359. *
  5360. * The routine calculates the latency from the beginning of the CMF timer
  5361. * interval to the current point in time. It is called from IO completion
  5362. * when we exceed our Bandwidth limitation for the time interval.
  5363. */
  5364. uint32_t
  5365. lpfc_calc_cmf_latency(struct lpfc_hba *phba)
  5366. {
  5367. struct timespec64 cmpl_time;
  5368. uint32_t msec = 0;
  5369. ktime_get_real_ts64(&cmpl_time);
  5370. /* This routine works on a ms granularity so sec and usec are
  5371. * converted accordingly.
  5372. */
  5373. if (cmpl_time.tv_sec == phba->cmf_latency.tv_sec) {
  5374. msec = (cmpl_time.tv_nsec - phba->cmf_latency.tv_nsec) /
  5375. NSEC_PER_MSEC;
  5376. } else {
  5377. if (cmpl_time.tv_nsec >= phba->cmf_latency.tv_nsec) {
  5378. msec = (cmpl_time.tv_sec -
  5379. phba->cmf_latency.tv_sec) * MSEC_PER_SEC;
  5380. msec += ((cmpl_time.tv_nsec -
  5381. phba->cmf_latency.tv_nsec) / NSEC_PER_MSEC);
  5382. } else {
  5383. msec = (cmpl_time.tv_sec - phba->cmf_latency.tv_sec -
  5384. 1) * MSEC_PER_SEC;
  5385. msec += (((NSEC_PER_SEC - phba->cmf_latency.tv_nsec) +
  5386. cmpl_time.tv_nsec) / NSEC_PER_MSEC);
  5387. }
  5388. }
  5389. return msec;
  5390. }
  5391. /**
  5392. * lpfc_cmf_timer - This is the timer function for one congestion
  5393. * rate interval.
  5394. * @timer: Pointer to the high resolution timer that expired
  5395. */
  5396. static enum hrtimer_restart
  5397. lpfc_cmf_timer(struct hrtimer *timer)
  5398. {
  5399. struct lpfc_hba *phba = container_of(timer, struct lpfc_hba,
  5400. cmf_timer);
  5401. struct rx_info_entry entry;
  5402. uint32_t io_cnt;
  5403. uint32_t busy, max_read;
  5404. uint64_t total, rcv, lat, mbpi, extra, cnt;
  5405. int timer_interval = LPFC_CMF_INTERVAL;
  5406. uint32_t ms;
  5407. struct lpfc_cgn_stat *cgs;
  5408. int cpu;
  5409. /* Only restart the timer if congestion mgmt is on */
  5410. if (phba->cmf_active_mode == LPFC_CFG_OFF ||
  5411. !phba->cmf_latency.tv_sec) {
  5412. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  5413. "6224 CMF timer exit: %d %lld\n",
  5414. phba->cmf_active_mode,
  5415. (uint64_t)phba->cmf_latency.tv_sec);
  5416. return HRTIMER_NORESTART;
  5417. }
  5418. /* If pport is not ready yet, just exit and wait for
  5419. * the next timer cycle to hit.
  5420. */
  5421. if (!phba->pport)
  5422. goto skip;
  5423. /* Do not block SCSI IO while in the timer routine since
  5424. * total_bytes will be cleared
  5425. */
  5426. atomic_set(&phba->cmf_stop_io, 1);
  5427. /* First we need to calculate the actual ms between
  5428. * the last timer interrupt and this one. We ask for
  5429. * LPFC_CMF_INTERVAL, however the actual time may
  5430. * vary depending on system overhead.
  5431. */
  5432. ms = lpfc_calc_cmf_latency(phba);
  5433. /* Immediately after we calculate the time since the last
  5434. * timer interrupt, set the start time for the next
  5435. * interrupt
  5436. */
  5437. ktime_get_real_ts64(&phba->cmf_latency);
  5438. phba->cmf_link_byte_count =
  5439. div_u64(phba->cmf_max_line_rate * LPFC_CMF_INTERVAL, 1000);
  5440. /* Collect all the stats from the prior timer interval */
  5441. total = 0;
  5442. io_cnt = 0;
  5443. lat = 0;
  5444. rcv = 0;
  5445. for_each_present_cpu(cpu) {
  5446. cgs = per_cpu_ptr(phba->cmf_stat, cpu);
  5447. total += atomic64_xchg(&cgs->total_bytes, 0);
  5448. io_cnt += atomic_xchg(&cgs->rx_io_cnt, 0);
  5449. lat += atomic64_xchg(&cgs->rx_latency, 0);
  5450. rcv += atomic64_xchg(&cgs->rcv_bytes, 0);
  5451. }
  5452. /* Before we issue another CMF_SYNC_WQE, retrieve the BW
  5453. * returned from the last CMF_SYNC_WQE issued, from
  5454. * cmf_last_sync_bw. This will be the target BW for
  5455. * this next timer interval.
  5456. */
  5457. if (phba->cmf_active_mode == LPFC_CFG_MANAGED &&
  5458. phba->link_state != LPFC_LINK_DOWN &&
  5459. phba->hba_flag & HBA_SETUP) {
  5460. mbpi = phba->cmf_last_sync_bw;
  5461. phba->cmf_last_sync_bw = 0;
  5462. extra = 0;
  5463. /* Calculate any extra bytes needed to account for the
  5464. * timer accuracy. If we are less than LPFC_CMF_INTERVAL
  5465. * calculate the adjustment needed for total to reflect
  5466. * a full LPFC_CMF_INTERVAL.
  5467. */
  5468. if (ms && ms < LPFC_CMF_INTERVAL) {
  5469. cnt = div_u64(total, ms); /* bytes per ms */
  5470. cnt *= LPFC_CMF_INTERVAL; /* what total should be */
  5471. /* If the timeout is scheduled to be shorter,
  5472. * this value may skew the data, so cap it at mbpi.
  5473. */
  5474. if ((phba->hba_flag & HBA_SHORT_CMF) && cnt > mbpi)
  5475. cnt = mbpi;
  5476. extra = cnt - total;
  5477. }
  5478. lpfc_issue_cmf_sync_wqe(phba, LPFC_CMF_INTERVAL, total + extra);
  5479. } else {
  5480. /* For Monitor mode or link down we want mbpi
  5481. * to be the full link speed
  5482. */
  5483. mbpi = phba->cmf_link_byte_count;
  5484. extra = 0;
  5485. }
  5486. phba->cmf_timer_cnt++;
  5487. if (io_cnt) {
  5488. /* Update congestion info buffer latency in us */
  5489. atomic_add(io_cnt, &phba->cgn_latency_evt_cnt);
  5490. atomic64_add(lat, &phba->cgn_latency_evt);
  5491. }
  5492. busy = atomic_xchg(&phba->cmf_busy, 0);
  5493. max_read = atomic_xchg(&phba->rx_max_read_cnt, 0);
  5494. /* Calculate MBPI for the next timer interval */
  5495. if (mbpi) {
  5496. if (mbpi > phba->cmf_link_byte_count ||
  5497. phba->cmf_active_mode == LPFC_CFG_MONITOR)
  5498. mbpi = phba->cmf_link_byte_count;
  5499. /* Change max_bytes_per_interval to what the prior
  5500. * CMF_SYNC_WQE cmpl indicated.
  5501. */
  5502. if (mbpi != phba->cmf_max_bytes_per_interval)
  5503. phba->cmf_max_bytes_per_interval = mbpi;
  5504. }
  5505. /* Save rxmonitor information for debug */
  5506. if (phba->rx_monitor) {
  5507. entry.total_bytes = total;
  5508. entry.cmf_bytes = total + extra;
  5509. entry.rcv_bytes = rcv;
  5510. entry.cmf_busy = busy;
  5511. entry.cmf_info = phba->cmf_active_info;
  5512. if (io_cnt) {
  5513. entry.avg_io_latency = div_u64(lat, io_cnt);
  5514. entry.avg_io_size = div_u64(rcv, io_cnt);
  5515. } else {
  5516. entry.avg_io_latency = 0;
  5517. entry.avg_io_size = 0;
  5518. }
  5519. entry.max_read_cnt = max_read;
  5520. entry.io_cnt = io_cnt;
  5521. entry.max_bytes_per_interval = mbpi;
  5522. if (phba->cmf_active_mode == LPFC_CFG_MANAGED)
  5523. entry.timer_utilization = phba->cmf_last_ts;
  5524. else
  5525. entry.timer_utilization = ms;
  5526. entry.timer_interval = ms;
  5527. phba->cmf_last_ts = 0;
  5528. lpfc_rx_monitor_record(phba->rx_monitor, &entry);
  5529. }
  5530. if (phba->cmf_active_mode == LPFC_CFG_MONITOR) {
  5531. /* If Monitor mode, check if we are oversubscribed
  5532. * against the full line rate.
  5533. */
  5534. if (mbpi && total > mbpi)
  5535. atomic_inc(&phba->cgn_driver_evt_cnt);
  5536. }
  5537. phba->rx_block_cnt += div_u64(rcv, 512); /* save 512 byte block cnt */
  5538. /* Each minute save Fabric and Driver congestion information */
  5539. lpfc_cgn_save_evt_cnt(phba);
  5540. phba->hba_flag &= ~HBA_SHORT_CMF;
  5541. /* Since we need to call lpfc_cgn_save_evt_cnt every minute, on the
  5542. * minute, adjust our next timer interval, if needed, to ensure a
  5543. * 1 minute granularity when we get the next timer interrupt.
  5544. */
  5545. if (time_after(jiffies + msecs_to_jiffies(LPFC_CMF_INTERVAL),
  5546. phba->cgn_evt_timestamp)) {
  5547. timer_interval = jiffies_to_msecs(phba->cgn_evt_timestamp -
  5548. jiffies);
  5549. if (timer_interval <= 0)
  5550. timer_interval = LPFC_CMF_INTERVAL;
  5551. else
  5552. phba->hba_flag |= HBA_SHORT_CMF;
  5553. /* If we adjust timer_interval, max_bytes_per_interval
  5554. * needs to be adjusted as well.
  5555. */
  5556. phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate *
  5557. timer_interval, 1000);
  5558. if (phba->cmf_active_mode == LPFC_CFG_MONITOR)
  5559. phba->cmf_max_bytes_per_interval =
  5560. phba->cmf_link_byte_count;
  5561. }
  5562. /* Since total_bytes has already been zero'ed, its okay to unblock
  5563. * after max_bytes_per_interval is setup.
  5564. */
  5565. if (atomic_xchg(&phba->cmf_bw_wait, 0))
  5566. queue_work(phba->wq, &phba->unblock_request_work);
  5567. /* SCSI IO is now unblocked */
  5568. atomic_set(&phba->cmf_stop_io, 0);
  5569. skip:
  5570. hrtimer_forward_now(timer,
  5571. ktime_set(0, timer_interval * NSEC_PER_MSEC));
  5572. return HRTIMER_RESTART;
  5573. }
  5574. #define trunk_link_status(__idx)\
  5575. bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
  5576. ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
  5577. "Link up" : "Link down") : "NA"
  5578. /* Did port __idx reported an error */
  5579. #define trunk_port_fault(__idx)\
  5580. bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
  5581. (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
  5582. static void
  5583. lpfc_update_trunk_link_status(struct lpfc_hba *phba,
  5584. struct lpfc_acqe_fc_la *acqe_fc)
  5585. {
  5586. uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc);
  5587. uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc);
  5588. u8 cnt = 0;
  5589. phba->sli4_hba.link_state.speed =
  5590. lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
  5591. bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
  5592. phba->sli4_hba.link_state.logical_speed =
  5593. bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
  5594. /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
  5595. phba->fc_linkspeed =
  5596. lpfc_async_link_speed_to_read_top(
  5597. phba,
  5598. bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
  5599. if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) {
  5600. phba->trunk_link.link0.state =
  5601. bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc)
  5602. ? LPFC_LINK_UP : LPFC_LINK_DOWN;
  5603. phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0;
  5604. cnt++;
  5605. }
  5606. if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) {
  5607. phba->trunk_link.link1.state =
  5608. bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc)
  5609. ? LPFC_LINK_UP : LPFC_LINK_DOWN;
  5610. phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0;
  5611. cnt++;
  5612. }
  5613. if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) {
  5614. phba->trunk_link.link2.state =
  5615. bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc)
  5616. ? LPFC_LINK_UP : LPFC_LINK_DOWN;
  5617. phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0;
  5618. cnt++;
  5619. }
  5620. if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) {
  5621. phba->trunk_link.link3.state =
  5622. bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc)
  5623. ? LPFC_LINK_UP : LPFC_LINK_DOWN;
  5624. phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0;
  5625. cnt++;
  5626. }
  5627. if (cnt)
  5628. phba->trunk_link.phy_lnk_speed =
  5629. phba->sli4_hba.link_state.logical_speed / (cnt * 1000);
  5630. else
  5631. phba->trunk_link.phy_lnk_speed = LPFC_LINK_SPEED_UNKNOWN;
  5632. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  5633. "2910 Async FC Trunking Event - Speed:%d\n"
  5634. "\tLogical speed:%d "
  5635. "port0: %s port1: %s port2: %s port3: %s\n",
  5636. phba->sli4_hba.link_state.speed,
  5637. phba->sli4_hba.link_state.logical_speed,
  5638. trunk_link_status(0), trunk_link_status(1),
  5639. trunk_link_status(2), trunk_link_status(3));
  5640. if (phba->cmf_active_mode != LPFC_CFG_OFF)
  5641. lpfc_cmf_signal_init(phba);
  5642. if (port_fault)
  5643. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  5644. "3202 trunk error:0x%x (%s) seen on port0:%s "
  5645. /*
  5646. * SLI-4: We have only 0xA error codes
  5647. * defined as of now. print an appropriate
  5648. * message in case driver needs to be updated.
  5649. */
  5650. "port1:%s port2:%s port3:%s\n", err, err > 0xA ?
  5651. "UNDEFINED. update driver." : trunk_errmsg[err],
  5652. trunk_port_fault(0), trunk_port_fault(1),
  5653. trunk_port_fault(2), trunk_port_fault(3));
  5654. }
  5655. /**
  5656. * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
  5657. * @phba: pointer to lpfc hba data structure.
  5658. * @acqe_fc: pointer to the async fc completion queue entry.
  5659. *
  5660. * This routine is to handle the SLI4 asynchronous FC event. It will simply log
  5661. * that the event was received and then issue a read_topology mailbox command so
  5662. * that the rest of the driver will treat it the same as SLI3.
  5663. **/
  5664. static void
  5665. lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
  5666. {
  5667. LPFC_MBOXQ_t *pmb;
  5668. MAILBOX_t *mb;
  5669. struct lpfc_mbx_read_top *la;
  5670. int rc;
  5671. if (bf_get(lpfc_trailer_type, acqe_fc) !=
  5672. LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
  5673. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  5674. "2895 Non FC link Event detected.(%d)\n",
  5675. bf_get(lpfc_trailer_type, acqe_fc));
  5676. return;
  5677. }
  5678. if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
  5679. LPFC_FC_LA_TYPE_TRUNKING_EVENT) {
  5680. lpfc_update_trunk_link_status(phba, acqe_fc);
  5681. return;
  5682. }
  5683. /* Keep the link status for extra SLI4 state machine reference */
  5684. phba->sli4_hba.link_state.speed =
  5685. lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
  5686. bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
  5687. phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
  5688. phba->sli4_hba.link_state.topology =
  5689. bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
  5690. phba->sli4_hba.link_state.status =
  5691. bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
  5692. phba->sli4_hba.link_state.type =
  5693. bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
  5694. phba->sli4_hba.link_state.number =
  5695. bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
  5696. phba->sli4_hba.link_state.fault =
  5697. bf_get(lpfc_acqe_link_fault, acqe_fc);
  5698. if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
  5699. LPFC_FC_LA_TYPE_LINK_DOWN)
  5700. phba->sli4_hba.link_state.logical_speed = 0;
  5701. else if (!phba->sli4_hba.conf_trunk)
  5702. phba->sli4_hba.link_state.logical_speed =
  5703. bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
  5704. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  5705. "2896 Async FC event - Speed:%dGBaud Topology:x%x "
  5706. "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
  5707. "%dMbps Fault:%d\n",
  5708. phba->sli4_hba.link_state.speed,
  5709. phba->sli4_hba.link_state.topology,
  5710. phba->sli4_hba.link_state.status,
  5711. phba->sli4_hba.link_state.type,
  5712. phba->sli4_hba.link_state.number,
  5713. phba->sli4_hba.link_state.logical_speed,
  5714. phba->sli4_hba.link_state.fault);
  5715. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5716. if (!pmb) {
  5717. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  5718. "2897 The mboxq allocation failed\n");
  5719. return;
  5720. }
  5721. rc = lpfc_mbox_rsrc_prep(phba, pmb);
  5722. if (rc) {
  5723. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  5724. "2898 The mboxq prep failed\n");
  5725. goto out_free_pmb;
  5726. }
  5727. /* Cleanup any outstanding ELS commands */
  5728. lpfc_els_flush_all_cmd(phba);
  5729. /* Block ELS IOCBs until we have done process link event */
  5730. phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
  5731. /* Update link event statistics */
  5732. phba->sli.slistat.link_event++;
  5733. /* Create lpfc_handle_latt mailbox command from link ACQE */
  5734. lpfc_read_topology(phba, pmb, (struct lpfc_dmabuf *)pmb->ctx_buf);
  5735. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  5736. pmb->vport = phba->pport;
  5737. if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
  5738. phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
  5739. switch (phba->sli4_hba.link_state.status) {
  5740. case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
  5741. phba->link_flag |= LS_MDS_LINK_DOWN;
  5742. break;
  5743. case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
  5744. phba->link_flag |= LS_MDS_LOOPBACK;
  5745. break;
  5746. default:
  5747. break;
  5748. }
  5749. /* Initialize completion status */
  5750. mb = &pmb->u.mb;
  5751. mb->mbxStatus = MBX_SUCCESS;
  5752. /* Parse port fault information field */
  5753. lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
  5754. /* Parse and translate link attention fields */
  5755. la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
  5756. la->eventTag = acqe_fc->event_tag;
  5757. if (phba->sli4_hba.link_state.status ==
  5758. LPFC_FC_LA_TYPE_UNEXP_WWPN) {
  5759. bf_set(lpfc_mbx_read_top_att_type, la,
  5760. LPFC_FC_LA_TYPE_UNEXP_WWPN);
  5761. } else {
  5762. bf_set(lpfc_mbx_read_top_att_type, la,
  5763. LPFC_FC_LA_TYPE_LINK_DOWN);
  5764. }
  5765. /* Invoke the mailbox command callback function */
  5766. lpfc_mbx_cmpl_read_topology(phba, pmb);
  5767. return;
  5768. }
  5769. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  5770. if (rc == MBX_NOT_FINISHED)
  5771. goto out_free_pmb;
  5772. return;
  5773. out_free_pmb:
  5774. lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
  5775. }
  5776. /**
  5777. * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
  5778. * @phba: pointer to lpfc hba data structure.
  5779. * @acqe_sli: pointer to the async SLI completion queue entry.
  5780. *
  5781. * This routine is to handle the SLI4 asynchronous SLI events.
  5782. **/
  5783. static void
  5784. lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
  5785. {
  5786. char port_name;
  5787. char message[128];
  5788. uint8_t status;
  5789. uint8_t evt_type;
  5790. uint8_t operational = 0;
  5791. struct temp_event temp_event_data;
  5792. struct lpfc_acqe_misconfigured_event *misconfigured;
  5793. struct lpfc_acqe_cgn_signal *cgn_signal;
  5794. struct Scsi_Host *shost;
  5795. struct lpfc_vport **vports;
  5796. int rc, i, cnt;
  5797. evt_type = bf_get(lpfc_trailer_type, acqe_sli);
  5798. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  5799. "2901 Async SLI event - Type:%d, Event Data: x%08x "
  5800. "x%08x x%08x x%08x\n", evt_type,
  5801. acqe_sli->event_data1, acqe_sli->event_data2,
  5802. acqe_sli->event_data3, acqe_sli->trailer);
  5803. port_name = phba->Port[0];
  5804. if (port_name == 0x00)
  5805. port_name = '?'; /* get port name is empty */
  5806. switch (evt_type) {
  5807. case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
  5808. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5809. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5810. temp_event_data.data = (uint32_t)acqe_sli->event_data1;
  5811. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5812. "3190 Over Temperature:%d Celsius- Port Name %c\n",
  5813. acqe_sli->event_data1, port_name);
  5814. phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
  5815. shost = lpfc_shost_from_vport(phba->pport);
  5816. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5817. sizeof(temp_event_data),
  5818. (char *)&temp_event_data,
  5819. SCSI_NL_VID_TYPE_PCI
  5820. | PCI_VENDOR_ID_EMULEX);
  5821. break;
  5822. case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
  5823. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5824. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5825. temp_event_data.data = (uint32_t)acqe_sli->event_data1;
  5826. lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_LDS_EVENT,
  5827. "3191 Normal Temperature:%d Celsius - Port Name %c\n",
  5828. acqe_sli->event_data1, port_name);
  5829. shost = lpfc_shost_from_vport(phba->pport);
  5830. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5831. sizeof(temp_event_data),
  5832. (char *)&temp_event_data,
  5833. SCSI_NL_VID_TYPE_PCI
  5834. | PCI_VENDOR_ID_EMULEX);
  5835. break;
  5836. case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
  5837. misconfigured = (struct lpfc_acqe_misconfigured_event *)
  5838. &acqe_sli->event_data1;
  5839. /* fetch the status for this port */
  5840. switch (phba->sli4_hba.lnk_info.lnk_no) {
  5841. case LPFC_LINK_NUMBER_0:
  5842. status = bf_get(lpfc_sli_misconfigured_port0_state,
  5843. &misconfigured->theEvent);
  5844. operational = bf_get(lpfc_sli_misconfigured_port0_op,
  5845. &misconfigured->theEvent);
  5846. break;
  5847. case LPFC_LINK_NUMBER_1:
  5848. status = bf_get(lpfc_sli_misconfigured_port1_state,
  5849. &misconfigured->theEvent);
  5850. operational = bf_get(lpfc_sli_misconfigured_port1_op,
  5851. &misconfigured->theEvent);
  5852. break;
  5853. case LPFC_LINK_NUMBER_2:
  5854. status = bf_get(lpfc_sli_misconfigured_port2_state,
  5855. &misconfigured->theEvent);
  5856. operational = bf_get(lpfc_sli_misconfigured_port2_op,
  5857. &misconfigured->theEvent);
  5858. break;
  5859. case LPFC_LINK_NUMBER_3:
  5860. status = bf_get(lpfc_sli_misconfigured_port3_state,
  5861. &misconfigured->theEvent);
  5862. operational = bf_get(lpfc_sli_misconfigured_port3_op,
  5863. &misconfigured->theEvent);
  5864. break;
  5865. default:
  5866. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  5867. "3296 "
  5868. "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
  5869. "event: Invalid link %d",
  5870. phba->sli4_hba.lnk_info.lnk_no);
  5871. return;
  5872. }
  5873. /* Skip if optic state unchanged */
  5874. if (phba->sli4_hba.lnk_info.optic_state == status)
  5875. return;
  5876. switch (status) {
  5877. case LPFC_SLI_EVENT_STATUS_VALID:
  5878. sprintf(message, "Physical Link is functional");
  5879. break;
  5880. case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
  5881. sprintf(message, "Optics faulted/incorrectly "
  5882. "installed/not installed - Reseat optics, "
  5883. "if issue not resolved, replace.");
  5884. break;
  5885. case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
  5886. sprintf(message,
  5887. "Optics of two types installed - Remove one "
  5888. "optic or install matching pair of optics.");
  5889. break;
  5890. case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
  5891. sprintf(message, "Incompatible optics - Replace with "
  5892. "compatible optics for card to function.");
  5893. break;
  5894. case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
  5895. sprintf(message, "Unqualified optics - Replace with "
  5896. "Avago optics for Warranty and Technical "
  5897. "Support - Link is%s operational",
  5898. (operational) ? " not" : "");
  5899. break;
  5900. case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
  5901. sprintf(message, "Uncertified optics - Replace with "
  5902. "Avago-certified optics to enable link "
  5903. "operation - Link is%s operational",
  5904. (operational) ? " not" : "");
  5905. break;
  5906. default:
  5907. /* firmware is reporting a status we don't know about */
  5908. sprintf(message, "Unknown event status x%02x", status);
  5909. break;
  5910. }
  5911. /* Issue READ_CONFIG mbox command to refresh supported speeds */
  5912. rc = lpfc_sli4_read_config(phba);
  5913. if (rc) {
  5914. phba->lmt = 0;
  5915. lpfc_printf_log(phba, KERN_ERR,
  5916. LOG_TRACE_EVENT,
  5917. "3194 Unable to retrieve supported "
  5918. "speeds, rc = 0x%x\n", rc);
  5919. }
  5920. rc = lpfc_sli4_refresh_params(phba);
  5921. if (rc) {
  5922. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5923. "3174 Unable to update pls support, "
  5924. "rc x%x\n", rc);
  5925. }
  5926. vports = lpfc_create_vport_work_array(phba);
  5927. if (vports != NULL) {
  5928. for (i = 0; i <= phba->max_vports && vports[i] != NULL;
  5929. i++) {
  5930. shost = lpfc_shost_from_vport(vports[i]);
  5931. lpfc_host_supported_speeds_set(shost);
  5932. }
  5933. }
  5934. lpfc_destroy_vport_work_array(phba, vports);
  5935. phba->sli4_hba.lnk_info.optic_state = status;
  5936. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5937. "3176 Port Name %c %s\n", port_name, message);
  5938. break;
  5939. case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
  5940. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  5941. "3192 Remote DPort Test Initiated - "
  5942. "Event Data1:x%08x Event Data2: x%08x\n",
  5943. acqe_sli->event_data1, acqe_sli->event_data2);
  5944. break;
  5945. case LPFC_SLI_EVENT_TYPE_PORT_PARAMS_CHG:
  5946. /* Call FW to obtain active parms */
  5947. lpfc_sli4_cgn_parm_chg_evt(phba);
  5948. break;
  5949. case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN:
  5950. /* Misconfigured WWN. Reports that the SLI Port is configured
  5951. * to use FA-WWN, but the attached device doesn’t support it.
  5952. * Event Data1 - N.A, Event Data2 - N.A
  5953. * This event only happens on the physical port.
  5954. */
  5955. lpfc_log_msg(phba, KERN_WARNING, LOG_SLI | LOG_DISCOVERY,
  5956. "2699 Misconfigured FA-PWWN - Attached device "
  5957. "does not support FA-PWWN\n");
  5958. phba->sli4_hba.fawwpn_flag &= ~LPFC_FAWWPN_FABRIC;
  5959. memset(phba->pport->fc_portname.u.wwn, 0,
  5960. sizeof(struct lpfc_name));
  5961. break;
  5962. case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE:
  5963. /* EEPROM failure. No driver action is required */
  5964. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5965. "2518 EEPROM failure - "
  5966. "Event Data1: x%08x Event Data2: x%08x\n",
  5967. acqe_sli->event_data1, acqe_sli->event_data2);
  5968. break;
  5969. case LPFC_SLI_EVENT_TYPE_CGN_SIGNAL:
  5970. if (phba->cmf_active_mode == LPFC_CFG_OFF)
  5971. break;
  5972. cgn_signal = (struct lpfc_acqe_cgn_signal *)
  5973. &acqe_sli->event_data1;
  5974. phba->cgn_acqe_cnt++;
  5975. cnt = bf_get(lpfc_warn_acqe, cgn_signal);
  5976. atomic64_add(cnt, &phba->cgn_acqe_stat.warn);
  5977. atomic64_add(cgn_signal->alarm_cnt, &phba->cgn_acqe_stat.alarm);
  5978. /* no threshold for CMF, even 1 signal will trigger an event */
  5979. /* Alarm overrides warning, so check that first */
  5980. if (cgn_signal->alarm_cnt) {
  5981. if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
  5982. /* Keep track of alarm cnt for CMF_SYNC_WQE */
  5983. atomic_add(cgn_signal->alarm_cnt,
  5984. &phba->cgn_sync_alarm_cnt);
  5985. }
  5986. } else if (cnt) {
  5987. /* signal action needs to be taken */
  5988. if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
  5989. phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
  5990. /* Keep track of warning cnt for CMF_SYNC_WQE */
  5991. atomic_add(cnt, &phba->cgn_sync_warn_cnt);
  5992. }
  5993. }
  5994. break;
  5995. case LPFC_SLI_EVENT_TYPE_RD_SIGNAL:
  5996. /* May be accompanied by a temperature event */
  5997. lpfc_printf_log(phba, KERN_INFO,
  5998. LOG_SLI | LOG_LINK_EVENT | LOG_LDS_EVENT,
  5999. "2902 Remote Degrade Signaling: x%08x x%08x "
  6000. "x%08x\n",
  6001. acqe_sli->event_data1, acqe_sli->event_data2,
  6002. acqe_sli->event_data3);
  6003. break;
  6004. default:
  6005. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6006. "3193 Unrecognized SLI event, type: 0x%x",
  6007. evt_type);
  6008. break;
  6009. }
  6010. }
  6011. /**
  6012. * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
  6013. * @vport: pointer to vport data structure.
  6014. *
  6015. * This routine is to perform Clear Virtual Link (CVL) on a vport in
  6016. * response to a CVL event.
  6017. *
  6018. * Return the pointer to the ndlp with the vport if successful, otherwise
  6019. * return NULL.
  6020. **/
  6021. static struct lpfc_nodelist *
  6022. lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
  6023. {
  6024. struct lpfc_nodelist *ndlp;
  6025. struct Scsi_Host *shost;
  6026. struct lpfc_hba *phba;
  6027. if (!vport)
  6028. return NULL;
  6029. phba = vport->phba;
  6030. if (!phba)
  6031. return NULL;
  6032. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  6033. if (!ndlp) {
  6034. /* Cannot find existing Fabric ndlp, so allocate a new one */
  6035. ndlp = lpfc_nlp_init(vport, Fabric_DID);
  6036. if (!ndlp)
  6037. return NULL;
  6038. /* Set the node type */
  6039. ndlp->nlp_type |= NLP_FABRIC;
  6040. /* Put ndlp onto node list */
  6041. lpfc_enqueue_node(vport, ndlp);
  6042. }
  6043. if ((phba->pport->port_state < LPFC_FLOGI) &&
  6044. (phba->pport->port_state != LPFC_VPORT_FAILED))
  6045. return NULL;
  6046. /* If virtual link is not yet instantiated ignore CVL */
  6047. if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
  6048. && (vport->port_state != LPFC_VPORT_FAILED))
  6049. return NULL;
  6050. shost = lpfc_shost_from_vport(vport);
  6051. if (!shost)
  6052. return NULL;
  6053. lpfc_linkdown_port(vport);
  6054. lpfc_cleanup_pending_mbox(vport);
  6055. spin_lock_irq(shost->host_lock);
  6056. vport->fc_flag |= FC_VPORT_CVL_RCVD;
  6057. spin_unlock_irq(shost->host_lock);
  6058. return ndlp;
  6059. }
  6060. /**
  6061. * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
  6062. * @phba: pointer to lpfc hba data structure.
  6063. *
  6064. * This routine is to perform Clear Virtual Link (CVL) on all vports in
  6065. * response to a FCF dead event.
  6066. **/
  6067. static void
  6068. lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
  6069. {
  6070. struct lpfc_vport **vports;
  6071. int i;
  6072. vports = lpfc_create_vport_work_array(phba);
  6073. if (vports)
  6074. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  6075. lpfc_sli4_perform_vport_cvl(vports[i]);
  6076. lpfc_destroy_vport_work_array(phba, vports);
  6077. }
  6078. /**
  6079. * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
  6080. * @phba: pointer to lpfc hba data structure.
  6081. * @acqe_fip: pointer to the async fcoe completion queue entry.
  6082. *
  6083. * This routine is to handle the SLI4 asynchronous fcoe event.
  6084. **/
  6085. static void
  6086. lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
  6087. struct lpfc_acqe_fip *acqe_fip)
  6088. {
  6089. uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
  6090. int rc;
  6091. struct lpfc_vport *vport;
  6092. struct lpfc_nodelist *ndlp;
  6093. int active_vlink_present;
  6094. struct lpfc_vport **vports;
  6095. int i;
  6096. phba->fc_eventTag = acqe_fip->event_tag;
  6097. phba->fcoe_eventtag = acqe_fip->event_tag;
  6098. switch (event_type) {
  6099. case LPFC_FIP_EVENT_TYPE_NEW_FCF:
  6100. case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
  6101. if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
  6102. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6103. "2546 New FCF event, evt_tag:x%x, "
  6104. "index:x%x\n",
  6105. acqe_fip->event_tag,
  6106. acqe_fip->index);
  6107. else
  6108. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
  6109. LOG_DISCOVERY,
  6110. "2788 FCF param modified event, "
  6111. "evt_tag:x%x, index:x%x\n",
  6112. acqe_fip->event_tag,
  6113. acqe_fip->index);
  6114. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  6115. /*
  6116. * During period of FCF discovery, read the FCF
  6117. * table record indexed by the event to update
  6118. * FCF roundrobin failover eligible FCF bmask.
  6119. */
  6120. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  6121. LOG_DISCOVERY,
  6122. "2779 Read FCF (x%x) for updating "
  6123. "roundrobin FCF failover bmask\n",
  6124. acqe_fip->index);
  6125. rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
  6126. }
  6127. /* If the FCF discovery is in progress, do nothing. */
  6128. spin_lock_irq(&phba->hbalock);
  6129. if (phba->hba_flag & FCF_TS_INPROG) {
  6130. spin_unlock_irq(&phba->hbalock);
  6131. break;
  6132. }
  6133. /* If fast FCF failover rescan event is pending, do nothing */
  6134. if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
  6135. spin_unlock_irq(&phba->hbalock);
  6136. break;
  6137. }
  6138. /* If the FCF has been in discovered state, do nothing. */
  6139. if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
  6140. spin_unlock_irq(&phba->hbalock);
  6141. break;
  6142. }
  6143. spin_unlock_irq(&phba->hbalock);
  6144. /* Otherwise, scan the entire FCF table and re-discover SAN */
  6145. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  6146. "2770 Start FCF table scan per async FCF "
  6147. "event, evt_tag:x%x, index:x%x\n",
  6148. acqe_fip->event_tag, acqe_fip->index);
  6149. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  6150. LPFC_FCOE_FCF_GET_FIRST);
  6151. if (rc)
  6152. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6153. "2547 Issue FCF scan read FCF mailbox "
  6154. "command failed (x%x)\n", rc);
  6155. break;
  6156. case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
  6157. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6158. "2548 FCF Table full count 0x%x tag 0x%x\n",
  6159. bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
  6160. acqe_fip->event_tag);
  6161. break;
  6162. case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
  6163. phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
  6164. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6165. "2549 FCF (x%x) disconnected from network, "
  6166. "tag:x%x\n", acqe_fip->index,
  6167. acqe_fip->event_tag);
  6168. /*
  6169. * If we are in the middle of FCF failover process, clear
  6170. * the corresponding FCF bit in the roundrobin bitmap.
  6171. */
  6172. spin_lock_irq(&phba->hbalock);
  6173. if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
  6174. (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
  6175. spin_unlock_irq(&phba->hbalock);
  6176. /* Update FLOGI FCF failover eligible FCF bmask */
  6177. lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
  6178. break;
  6179. }
  6180. spin_unlock_irq(&phba->hbalock);
  6181. /* If the event is not for currently used fcf do nothing */
  6182. if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
  6183. break;
  6184. /*
  6185. * Otherwise, request the port to rediscover the entire FCF
  6186. * table for a fast recovery from case that the current FCF
  6187. * is no longer valid as we are not in the middle of FCF
  6188. * failover process already.
  6189. */
  6190. spin_lock_irq(&phba->hbalock);
  6191. /* Mark the fast failover process in progress */
  6192. phba->fcf.fcf_flag |= FCF_DEAD_DISC;
  6193. spin_unlock_irq(&phba->hbalock);
  6194. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  6195. "2771 Start FCF fast failover process due to "
  6196. "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
  6197. "\n", acqe_fip->event_tag, acqe_fip->index);
  6198. rc = lpfc_sli4_redisc_fcf_table(phba);
  6199. if (rc) {
  6200. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  6201. LOG_TRACE_EVENT,
  6202. "2772 Issue FCF rediscover mailbox "
  6203. "command failed, fail through to FCF "
  6204. "dead event\n");
  6205. spin_lock_irq(&phba->hbalock);
  6206. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  6207. spin_unlock_irq(&phba->hbalock);
  6208. /*
  6209. * Last resort will fail over by treating this
  6210. * as a link down to FCF registration.
  6211. */
  6212. lpfc_sli4_fcf_dead_failthrough(phba);
  6213. } else {
  6214. /* Reset FCF roundrobin bmask for new discovery */
  6215. lpfc_sli4_clear_fcf_rr_bmask(phba);
  6216. /*
  6217. * Handling fast FCF failover to a DEAD FCF event is
  6218. * considered equalivant to receiving CVL to all vports.
  6219. */
  6220. lpfc_sli4_perform_all_vport_cvl(phba);
  6221. }
  6222. break;
  6223. case LPFC_FIP_EVENT_TYPE_CVL:
  6224. phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
  6225. lpfc_printf_log(phba, KERN_ERR,
  6226. LOG_TRACE_EVENT,
  6227. "2718 Clear Virtual Link Received for VPI 0x%x"
  6228. " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
  6229. vport = lpfc_find_vport_by_vpid(phba,
  6230. acqe_fip->index);
  6231. ndlp = lpfc_sli4_perform_vport_cvl(vport);
  6232. if (!ndlp)
  6233. break;
  6234. active_vlink_present = 0;
  6235. vports = lpfc_create_vport_work_array(phba);
  6236. if (vports) {
  6237. for (i = 0; i <= phba->max_vports && vports[i] != NULL;
  6238. i++) {
  6239. if ((!(vports[i]->fc_flag &
  6240. FC_VPORT_CVL_RCVD)) &&
  6241. (vports[i]->port_state > LPFC_FDISC)) {
  6242. active_vlink_present = 1;
  6243. break;
  6244. }
  6245. }
  6246. lpfc_destroy_vport_work_array(phba, vports);
  6247. }
  6248. /*
  6249. * Don't re-instantiate if vport is marked for deletion.
  6250. * If we are here first then vport_delete is going to wait
  6251. * for discovery to complete.
  6252. */
  6253. if (!(vport->load_flag & FC_UNLOADING) &&
  6254. active_vlink_present) {
  6255. /*
  6256. * If there are other active VLinks present,
  6257. * re-instantiate the Vlink using FDISC.
  6258. */
  6259. mod_timer(&ndlp->nlp_delayfunc,
  6260. jiffies + msecs_to_jiffies(1000));
  6261. spin_lock_irq(&ndlp->lock);
  6262. ndlp->nlp_flag |= NLP_DELAY_TMO;
  6263. spin_unlock_irq(&ndlp->lock);
  6264. ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
  6265. vport->port_state = LPFC_FDISC;
  6266. } else {
  6267. /*
  6268. * Otherwise, we request port to rediscover
  6269. * the entire FCF table for a fast recovery
  6270. * from possible case that the current FCF
  6271. * is no longer valid if we are not already
  6272. * in the FCF failover process.
  6273. */
  6274. spin_lock_irq(&phba->hbalock);
  6275. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  6276. spin_unlock_irq(&phba->hbalock);
  6277. break;
  6278. }
  6279. /* Mark the fast failover process in progress */
  6280. phba->fcf.fcf_flag |= FCF_ACVL_DISC;
  6281. spin_unlock_irq(&phba->hbalock);
  6282. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  6283. LOG_DISCOVERY,
  6284. "2773 Start FCF failover per CVL, "
  6285. "evt_tag:x%x\n", acqe_fip->event_tag);
  6286. rc = lpfc_sli4_redisc_fcf_table(phba);
  6287. if (rc) {
  6288. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  6289. LOG_TRACE_EVENT,
  6290. "2774 Issue FCF rediscover "
  6291. "mailbox command failed, "
  6292. "through to CVL event\n");
  6293. spin_lock_irq(&phba->hbalock);
  6294. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  6295. spin_unlock_irq(&phba->hbalock);
  6296. /*
  6297. * Last resort will be re-try on the
  6298. * the current registered FCF entry.
  6299. */
  6300. lpfc_retry_pport_discovery(phba);
  6301. } else
  6302. /*
  6303. * Reset FCF roundrobin bmask for new
  6304. * discovery.
  6305. */
  6306. lpfc_sli4_clear_fcf_rr_bmask(phba);
  6307. }
  6308. break;
  6309. default:
  6310. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6311. "0288 Unknown FCoE event type 0x%x event tag "
  6312. "0x%x\n", event_type, acqe_fip->event_tag);
  6313. break;
  6314. }
  6315. }
  6316. /**
  6317. * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
  6318. * @phba: pointer to lpfc hba data structure.
  6319. * @acqe_dcbx: pointer to the async dcbx completion queue entry.
  6320. *
  6321. * This routine is to handle the SLI4 asynchronous dcbx event.
  6322. **/
  6323. static void
  6324. lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
  6325. struct lpfc_acqe_dcbx *acqe_dcbx)
  6326. {
  6327. phba->fc_eventTag = acqe_dcbx->event_tag;
  6328. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6329. "0290 The SLI4 DCBX asynchronous event is not "
  6330. "handled yet\n");
  6331. }
  6332. /**
  6333. * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
  6334. * @phba: pointer to lpfc hba data structure.
  6335. * @acqe_grp5: pointer to the async grp5 completion queue entry.
  6336. *
  6337. * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
  6338. * is an asynchronous notified of a logical link speed change. The Port
  6339. * reports the logical link speed in units of 10Mbps.
  6340. **/
  6341. static void
  6342. lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
  6343. struct lpfc_acqe_grp5 *acqe_grp5)
  6344. {
  6345. uint16_t prev_ll_spd;
  6346. phba->fc_eventTag = acqe_grp5->event_tag;
  6347. phba->fcoe_eventtag = acqe_grp5->event_tag;
  6348. prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
  6349. phba->sli4_hba.link_state.logical_speed =
  6350. (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
  6351. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6352. "2789 GRP5 Async Event: Updating logical link speed "
  6353. "from %dMbps to %dMbps\n", prev_ll_spd,
  6354. phba->sli4_hba.link_state.logical_speed);
  6355. }
  6356. /**
  6357. * lpfc_sli4_async_cmstat_evt - Process the asynchronous cmstat event
  6358. * @phba: pointer to lpfc hba data structure.
  6359. *
  6360. * This routine is to handle the SLI4 asynchronous cmstat event. A cmstat event
  6361. * is an asynchronous notification of a request to reset CM stats.
  6362. **/
  6363. static void
  6364. lpfc_sli4_async_cmstat_evt(struct lpfc_hba *phba)
  6365. {
  6366. if (!phba->cgn_i)
  6367. return;
  6368. lpfc_init_congestion_stat(phba);
  6369. }
  6370. /**
  6371. * lpfc_cgn_params_val - Validate FW congestion parameters.
  6372. * @phba: pointer to lpfc hba data structure.
  6373. * @p_cfg_param: pointer to FW provided congestion parameters.
  6374. *
  6375. * This routine validates the congestion parameters passed
  6376. * by the FW to the driver via an ACQE event.
  6377. **/
  6378. static void
  6379. lpfc_cgn_params_val(struct lpfc_hba *phba, struct lpfc_cgn_param *p_cfg_param)
  6380. {
  6381. spin_lock_irq(&phba->hbalock);
  6382. if (!lpfc_rangecheck(p_cfg_param->cgn_param_mode, LPFC_CFG_OFF,
  6383. LPFC_CFG_MONITOR)) {
  6384. lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT,
  6385. "6225 CMF mode param out of range: %d\n",
  6386. p_cfg_param->cgn_param_mode);
  6387. p_cfg_param->cgn_param_mode = LPFC_CFG_OFF;
  6388. }
  6389. spin_unlock_irq(&phba->hbalock);
  6390. }
  6391. static const char * const lpfc_cmf_mode_to_str[] = {
  6392. "OFF",
  6393. "MANAGED",
  6394. "MONITOR",
  6395. };
  6396. /**
  6397. * lpfc_cgn_params_parse - Process a FW cong parm change event
  6398. * @phba: pointer to lpfc hba data structure.
  6399. * @p_cgn_param: pointer to a data buffer with the FW cong params.
  6400. * @len: the size of pdata in bytes.
  6401. *
  6402. * This routine validates the congestion management buffer signature
  6403. * from the FW, validates the contents and makes corrections for
  6404. * valid, in-range values. If the signature magic is correct and
  6405. * after parameter validation, the contents are copied to the driver's
  6406. * @phba structure. If the magic is incorrect, an error message is
  6407. * logged.
  6408. **/
  6409. static void
  6410. lpfc_cgn_params_parse(struct lpfc_hba *phba,
  6411. struct lpfc_cgn_param *p_cgn_param, uint32_t len)
  6412. {
  6413. struct lpfc_cgn_info *cp;
  6414. uint32_t crc, oldmode;
  6415. char acr_string[4] = {0};
  6416. /* Make sure the FW has encoded the correct magic number to
  6417. * validate the congestion parameter in FW memory.
  6418. */
  6419. if (p_cgn_param->cgn_param_magic == LPFC_CFG_PARAM_MAGIC_NUM) {
  6420. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
  6421. "4668 FW cgn parm buffer data: "
  6422. "magic 0x%x version %d mode %d "
  6423. "level0 %d level1 %d "
  6424. "level2 %d byte13 %d "
  6425. "byte14 %d byte15 %d "
  6426. "byte11 %d byte12 %d activeMode %d\n",
  6427. p_cgn_param->cgn_param_magic,
  6428. p_cgn_param->cgn_param_version,
  6429. p_cgn_param->cgn_param_mode,
  6430. p_cgn_param->cgn_param_level0,
  6431. p_cgn_param->cgn_param_level1,
  6432. p_cgn_param->cgn_param_level2,
  6433. p_cgn_param->byte13,
  6434. p_cgn_param->byte14,
  6435. p_cgn_param->byte15,
  6436. p_cgn_param->byte11,
  6437. p_cgn_param->byte12,
  6438. phba->cmf_active_mode);
  6439. oldmode = phba->cmf_active_mode;
  6440. /* Any parameters out of range are corrected to defaults
  6441. * by this routine. No need to fail.
  6442. */
  6443. lpfc_cgn_params_val(phba, p_cgn_param);
  6444. /* Parameters are verified, move them into driver storage */
  6445. spin_lock_irq(&phba->hbalock);
  6446. memcpy(&phba->cgn_p, p_cgn_param,
  6447. sizeof(struct lpfc_cgn_param));
  6448. /* Update parameters in congestion info buffer now */
  6449. if (phba->cgn_i) {
  6450. cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
  6451. cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
  6452. cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
  6453. cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
  6454. cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
  6455. crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
  6456. LPFC_CGN_CRC32_SEED);
  6457. cp->cgn_info_crc = cpu_to_le32(crc);
  6458. }
  6459. spin_unlock_irq(&phba->hbalock);
  6460. phba->cmf_active_mode = phba->cgn_p.cgn_param_mode;
  6461. switch (oldmode) {
  6462. case LPFC_CFG_OFF:
  6463. if (phba->cgn_p.cgn_param_mode != LPFC_CFG_OFF) {
  6464. /* Turning CMF on */
  6465. lpfc_cmf_start(phba);
  6466. if (phba->link_state >= LPFC_LINK_UP) {
  6467. phba->cgn_reg_fpin =
  6468. phba->cgn_init_reg_fpin;
  6469. phba->cgn_reg_signal =
  6470. phba->cgn_init_reg_signal;
  6471. lpfc_issue_els_edc(phba->pport, 0);
  6472. }
  6473. }
  6474. break;
  6475. case LPFC_CFG_MANAGED:
  6476. switch (phba->cgn_p.cgn_param_mode) {
  6477. case LPFC_CFG_OFF:
  6478. /* Turning CMF off */
  6479. lpfc_cmf_stop(phba);
  6480. if (phba->link_state >= LPFC_LINK_UP)
  6481. lpfc_issue_els_edc(phba->pport, 0);
  6482. break;
  6483. case LPFC_CFG_MONITOR:
  6484. phba->cmf_max_bytes_per_interval =
  6485. phba->cmf_link_byte_count;
  6486. /* Resume blocked IO - unblock on workqueue */
  6487. queue_work(phba->wq,
  6488. &phba->unblock_request_work);
  6489. break;
  6490. }
  6491. break;
  6492. case LPFC_CFG_MONITOR:
  6493. switch (phba->cgn_p.cgn_param_mode) {
  6494. case LPFC_CFG_OFF:
  6495. /* Turning CMF off */
  6496. lpfc_cmf_stop(phba);
  6497. if (phba->link_state >= LPFC_LINK_UP)
  6498. lpfc_issue_els_edc(phba->pport, 0);
  6499. break;
  6500. case LPFC_CFG_MANAGED:
  6501. lpfc_cmf_signal_init(phba);
  6502. break;
  6503. }
  6504. break;
  6505. }
  6506. if (oldmode != LPFC_CFG_OFF ||
  6507. oldmode != phba->cgn_p.cgn_param_mode) {
  6508. if (phba->cgn_p.cgn_param_mode == LPFC_CFG_MANAGED)
  6509. scnprintf(acr_string, sizeof(acr_string), "%u",
  6510. phba->cgn_p.cgn_param_level0);
  6511. else
  6512. scnprintf(acr_string, sizeof(acr_string), "NA");
  6513. dev_info(&phba->pcidev->dev, "%d: "
  6514. "4663 CMF: Mode %s acr %s\n",
  6515. phba->brd_no,
  6516. lpfc_cmf_mode_to_str
  6517. [phba->cgn_p.cgn_param_mode],
  6518. acr_string);
  6519. }
  6520. } else {
  6521. lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
  6522. "4669 FW cgn parm buf wrong magic 0x%x "
  6523. "version %d\n", p_cgn_param->cgn_param_magic,
  6524. p_cgn_param->cgn_param_version);
  6525. }
  6526. }
  6527. /**
  6528. * lpfc_sli4_cgn_params_read - Read and Validate FW congestion parameters.
  6529. * @phba: pointer to lpfc hba data structure.
  6530. *
  6531. * This routine issues a read_object mailbox command to
  6532. * get the congestion management parameters from the FW
  6533. * parses it and updates the driver maintained values.
  6534. *
  6535. * Returns
  6536. * 0 if the object was empty
  6537. * -Eval if an error was encountered
  6538. * Count if bytes were read from object
  6539. **/
  6540. int
  6541. lpfc_sli4_cgn_params_read(struct lpfc_hba *phba)
  6542. {
  6543. int ret = 0;
  6544. struct lpfc_cgn_param *p_cgn_param = NULL;
  6545. u32 *pdata = NULL;
  6546. u32 len = 0;
  6547. /* Find out if the FW has a new set of congestion parameters. */
  6548. len = sizeof(struct lpfc_cgn_param);
  6549. pdata = kzalloc(len, GFP_KERNEL);
  6550. if (!pdata)
  6551. return -ENOMEM;
  6552. ret = lpfc_read_object(phba, (char *)LPFC_PORT_CFG_NAME,
  6553. pdata, len);
  6554. /* 0 means no data. A negative means error. A positive means
  6555. * bytes were copied.
  6556. */
  6557. if (!ret) {
  6558. lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
  6559. "4670 CGN RD OBJ returns no data\n");
  6560. goto rd_obj_err;
  6561. } else if (ret < 0) {
  6562. /* Some error. Just exit and return it to the caller.*/
  6563. goto rd_obj_err;
  6564. }
  6565. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
  6566. "6234 READ CGN PARAMS Successful %d\n", len);
  6567. /* Parse data pointer over len and update the phba congestion
  6568. * parameters with values passed back. The receive rate values
  6569. * may have been altered in FW, but take no action here.
  6570. */
  6571. p_cgn_param = (struct lpfc_cgn_param *)pdata;
  6572. lpfc_cgn_params_parse(phba, p_cgn_param, len);
  6573. rd_obj_err:
  6574. kfree(pdata);
  6575. return ret;
  6576. }
  6577. /**
  6578. * lpfc_sli4_cgn_parm_chg_evt - Process a FW congestion param change event
  6579. * @phba: pointer to lpfc hba data structure.
  6580. *
  6581. * The FW generated Async ACQE SLI event calls this routine when
  6582. * the event type is an SLI Internal Port Event and the Event Code
  6583. * indicates a change to the FW maintained congestion parameters.
  6584. *
  6585. * This routine executes a Read_Object mailbox call to obtain the
  6586. * current congestion parameters maintained in FW and corrects
  6587. * the driver's active congestion parameters.
  6588. *
  6589. * The acqe event is not passed because there is no further data
  6590. * required.
  6591. *
  6592. * Returns nonzero error if event processing encountered an error.
  6593. * Zero otherwise for success.
  6594. **/
  6595. static int
  6596. lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *phba)
  6597. {
  6598. int ret = 0;
  6599. if (!phba->sli4_hba.pc_sli4_params.cmf) {
  6600. lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
  6601. "4664 Cgn Evt when E2E off. Drop event\n");
  6602. return -EACCES;
  6603. }
  6604. /* If the event is claiming an empty object, it's ok. A write
  6605. * could have cleared it. Only error is a negative return
  6606. * status.
  6607. */
  6608. ret = lpfc_sli4_cgn_params_read(phba);
  6609. if (ret < 0) {
  6610. lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
  6611. "4667 Error reading Cgn Params (%d)\n",
  6612. ret);
  6613. } else if (!ret) {
  6614. lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
  6615. "4673 CGN Event empty object.\n");
  6616. }
  6617. return ret;
  6618. }
  6619. /**
  6620. * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
  6621. * @phba: pointer to lpfc hba data structure.
  6622. *
  6623. * This routine is invoked by the worker thread to process all the pending
  6624. * SLI4 asynchronous events.
  6625. **/
  6626. void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
  6627. {
  6628. struct lpfc_cq_event *cq_event;
  6629. unsigned long iflags;
  6630. /* First, declare the async event has been handled */
  6631. spin_lock_irqsave(&phba->hbalock, iflags);
  6632. phba->hba_flag &= ~ASYNC_EVENT;
  6633. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6634. /* Now, handle all the async events */
  6635. spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
  6636. while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
  6637. list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
  6638. cq_event, struct lpfc_cq_event, list);
  6639. spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock,
  6640. iflags);
  6641. /* Process the asynchronous event */
  6642. switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
  6643. case LPFC_TRAILER_CODE_LINK:
  6644. lpfc_sli4_async_link_evt(phba,
  6645. &cq_event->cqe.acqe_link);
  6646. break;
  6647. case LPFC_TRAILER_CODE_FCOE:
  6648. lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
  6649. break;
  6650. case LPFC_TRAILER_CODE_DCBX:
  6651. lpfc_sli4_async_dcbx_evt(phba,
  6652. &cq_event->cqe.acqe_dcbx);
  6653. break;
  6654. case LPFC_TRAILER_CODE_GRP5:
  6655. lpfc_sli4_async_grp5_evt(phba,
  6656. &cq_event->cqe.acqe_grp5);
  6657. break;
  6658. case LPFC_TRAILER_CODE_FC:
  6659. lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
  6660. break;
  6661. case LPFC_TRAILER_CODE_SLI:
  6662. lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
  6663. break;
  6664. case LPFC_TRAILER_CODE_CMSTAT:
  6665. lpfc_sli4_async_cmstat_evt(phba);
  6666. break;
  6667. default:
  6668. lpfc_printf_log(phba, KERN_ERR,
  6669. LOG_TRACE_EVENT,
  6670. "1804 Invalid asynchronous event code: "
  6671. "x%x\n", bf_get(lpfc_trailer_code,
  6672. &cq_event->cqe.mcqe_cmpl));
  6673. break;
  6674. }
  6675. /* Free the completion event processed to the free pool */
  6676. lpfc_sli4_cq_event_release(phba, cq_event);
  6677. spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
  6678. }
  6679. spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
  6680. }
  6681. /**
  6682. * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
  6683. * @phba: pointer to lpfc hba data structure.
  6684. *
  6685. * This routine is invoked by the worker thread to process FCF table
  6686. * rediscovery pending completion event.
  6687. **/
  6688. void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
  6689. {
  6690. int rc;
  6691. spin_lock_irq(&phba->hbalock);
  6692. /* Clear FCF rediscovery timeout event */
  6693. phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
  6694. /* Clear driver fast failover FCF record flag */
  6695. phba->fcf.failover_rec.flag = 0;
  6696. /* Set state for FCF fast failover */
  6697. phba->fcf.fcf_flag |= FCF_REDISC_FOV;
  6698. spin_unlock_irq(&phba->hbalock);
  6699. /* Scan FCF table from the first entry to re-discover SAN */
  6700. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  6701. "2777 Start post-quiescent FCF table scan\n");
  6702. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
  6703. if (rc)
  6704. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6705. "2747 Issue FCF scan read FCF mailbox "
  6706. "command failed 0x%x\n", rc);
  6707. }
  6708. /**
  6709. * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
  6710. * @phba: pointer to lpfc hba data structure.
  6711. * @dev_grp: The HBA PCI-Device group number.
  6712. *
  6713. * This routine is invoked to set up the per HBA PCI-Device group function
  6714. * API jump table entries.
  6715. *
  6716. * Return: 0 if success, otherwise -ENODEV
  6717. **/
  6718. int
  6719. lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6720. {
  6721. int rc;
  6722. /* Set up lpfc PCI-device group */
  6723. phba->pci_dev_grp = dev_grp;
  6724. /* The LPFC_PCI_DEV_OC uses SLI4 */
  6725. if (dev_grp == LPFC_PCI_DEV_OC)
  6726. phba->sli_rev = LPFC_SLI_REV4;
  6727. /* Set up device INIT API function jump table */
  6728. rc = lpfc_init_api_table_setup(phba, dev_grp);
  6729. if (rc)
  6730. return -ENODEV;
  6731. /* Set up SCSI API function jump table */
  6732. rc = lpfc_scsi_api_table_setup(phba, dev_grp);
  6733. if (rc)
  6734. return -ENODEV;
  6735. /* Set up SLI API function jump table */
  6736. rc = lpfc_sli_api_table_setup(phba, dev_grp);
  6737. if (rc)
  6738. return -ENODEV;
  6739. /* Set up MBOX API function jump table */
  6740. rc = lpfc_mbox_api_table_setup(phba, dev_grp);
  6741. if (rc)
  6742. return -ENODEV;
  6743. return 0;
  6744. }
  6745. /**
  6746. * lpfc_log_intr_mode - Log the active interrupt mode
  6747. * @phba: pointer to lpfc hba data structure.
  6748. * @intr_mode: active interrupt mode adopted.
  6749. *
  6750. * This routine it invoked to log the currently used active interrupt mode
  6751. * to the device.
  6752. **/
  6753. static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
  6754. {
  6755. switch (intr_mode) {
  6756. case 0:
  6757. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6758. "0470 Enable INTx interrupt mode.\n");
  6759. break;
  6760. case 1:
  6761. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6762. "0481 Enabled MSI interrupt mode.\n");
  6763. break;
  6764. case 2:
  6765. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6766. "0480 Enabled MSI-X interrupt mode.\n");
  6767. break;
  6768. default:
  6769. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6770. "0482 Illegal interrupt mode.\n");
  6771. break;
  6772. }
  6773. return;
  6774. }
  6775. /**
  6776. * lpfc_enable_pci_dev - Enable a generic PCI device.
  6777. * @phba: pointer to lpfc hba data structure.
  6778. *
  6779. * This routine is invoked to enable the PCI device that is common to all
  6780. * PCI devices.
  6781. *
  6782. * Return codes
  6783. * 0 - successful
  6784. * other values - error
  6785. **/
  6786. static int
  6787. lpfc_enable_pci_dev(struct lpfc_hba *phba)
  6788. {
  6789. struct pci_dev *pdev;
  6790. /* Obtain PCI device reference */
  6791. if (!phba->pcidev)
  6792. goto out_error;
  6793. else
  6794. pdev = phba->pcidev;
  6795. /* Enable PCI device */
  6796. if (pci_enable_device_mem(pdev))
  6797. goto out_error;
  6798. /* Request PCI resource for the device */
  6799. if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
  6800. goto out_disable_device;
  6801. /* Set up device as PCI master and save state for EEH */
  6802. pci_set_master(pdev);
  6803. pci_try_set_mwi(pdev);
  6804. pci_save_state(pdev);
  6805. /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
  6806. if (pci_is_pcie(pdev))
  6807. pdev->needs_freset = 1;
  6808. return 0;
  6809. out_disable_device:
  6810. pci_disable_device(pdev);
  6811. out_error:
  6812. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6813. "1401 Failed to enable pci device\n");
  6814. return -ENODEV;
  6815. }
  6816. /**
  6817. * lpfc_disable_pci_dev - Disable a generic PCI device.
  6818. * @phba: pointer to lpfc hba data structure.
  6819. *
  6820. * This routine is invoked to disable the PCI device that is common to all
  6821. * PCI devices.
  6822. **/
  6823. static void
  6824. lpfc_disable_pci_dev(struct lpfc_hba *phba)
  6825. {
  6826. struct pci_dev *pdev;
  6827. /* Obtain PCI device reference */
  6828. if (!phba->pcidev)
  6829. return;
  6830. else
  6831. pdev = phba->pcidev;
  6832. /* Release PCI resource and disable PCI device */
  6833. pci_release_mem_regions(pdev);
  6834. pci_disable_device(pdev);
  6835. return;
  6836. }
  6837. /**
  6838. * lpfc_reset_hba - Reset a hba
  6839. * @phba: pointer to lpfc hba data structure.
  6840. *
  6841. * This routine is invoked to reset a hba device. It brings the HBA
  6842. * offline, performs a board restart, and then brings the board back
  6843. * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
  6844. * on outstanding mailbox commands.
  6845. **/
  6846. void
  6847. lpfc_reset_hba(struct lpfc_hba *phba)
  6848. {
  6849. int rc = 0;
  6850. /* If resets are disabled then set error state and return. */
  6851. if (!phba->cfg_enable_hba_reset) {
  6852. phba->link_state = LPFC_HBA_ERROR;
  6853. return;
  6854. }
  6855. /* If not LPFC_SLI_ACTIVE, force all IO to be flushed */
  6856. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) {
  6857. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  6858. } else {
  6859. if (test_bit(MBX_TMO_ERR, &phba->bit_flags)) {
  6860. /* Perform a PCI function reset to start from clean */
  6861. rc = lpfc_pci_function_reset(phba);
  6862. lpfc_els_flush_all_cmd(phba);
  6863. }
  6864. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  6865. lpfc_sli_flush_io_rings(phba);
  6866. }
  6867. lpfc_offline(phba);
  6868. clear_bit(MBX_TMO_ERR, &phba->bit_flags);
  6869. if (unlikely(rc)) {
  6870. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6871. "8888 PCI function reset failed rc %x\n",
  6872. rc);
  6873. } else {
  6874. lpfc_sli_brdrestart(phba);
  6875. lpfc_online(phba);
  6876. lpfc_unblock_mgmt_io(phba);
  6877. }
  6878. }
  6879. /**
  6880. * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
  6881. * @phba: pointer to lpfc hba data structure.
  6882. *
  6883. * This function enables the PCI SR-IOV virtual functions to a physical
  6884. * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
  6885. * enable the number of virtual functions to the physical function. As
  6886. * not all devices support SR-IOV, the return code from the pci_enable_sriov()
  6887. * API call does not considered as an error condition for most of the device.
  6888. **/
  6889. uint16_t
  6890. lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
  6891. {
  6892. struct pci_dev *pdev = phba->pcidev;
  6893. uint16_t nr_virtfn;
  6894. int pos;
  6895. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
  6896. if (pos == 0)
  6897. return 0;
  6898. pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
  6899. return nr_virtfn;
  6900. }
  6901. /**
  6902. * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
  6903. * @phba: pointer to lpfc hba data structure.
  6904. * @nr_vfn: number of virtual functions to be enabled.
  6905. *
  6906. * This function enables the PCI SR-IOV virtual functions to a physical
  6907. * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
  6908. * enable the number of virtual functions to the physical function. As
  6909. * not all devices support SR-IOV, the return code from the pci_enable_sriov()
  6910. * API call does not considered as an error condition for most of the device.
  6911. **/
  6912. int
  6913. lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
  6914. {
  6915. struct pci_dev *pdev = phba->pcidev;
  6916. uint16_t max_nr_vfn;
  6917. int rc;
  6918. max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
  6919. if (nr_vfn > max_nr_vfn) {
  6920. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6921. "3057 Requested vfs (%d) greater than "
  6922. "supported vfs (%d)", nr_vfn, max_nr_vfn);
  6923. return -EINVAL;
  6924. }
  6925. rc = pci_enable_sriov(pdev, nr_vfn);
  6926. if (rc) {
  6927. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6928. "2806 Failed to enable sriov on this device "
  6929. "with vfn number nr_vf:%d, rc:%d\n",
  6930. nr_vfn, rc);
  6931. } else
  6932. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6933. "2807 Successful enable sriov on this device "
  6934. "with vfn number nr_vf:%d\n", nr_vfn);
  6935. return rc;
  6936. }
  6937. static void
  6938. lpfc_unblock_requests_work(struct work_struct *work)
  6939. {
  6940. struct lpfc_hba *phba = container_of(work, struct lpfc_hba,
  6941. unblock_request_work);
  6942. lpfc_unblock_requests(phba);
  6943. }
  6944. /**
  6945. * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
  6946. * @phba: pointer to lpfc hba data structure.
  6947. *
  6948. * This routine is invoked to set up the driver internal resources before the
  6949. * device specific resource setup to support the HBA device it attached to.
  6950. *
  6951. * Return codes
  6952. * 0 - successful
  6953. * other values - error
  6954. **/
  6955. static int
  6956. lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
  6957. {
  6958. struct lpfc_sli *psli = &phba->sli;
  6959. /*
  6960. * Driver resources common to all SLI revisions
  6961. */
  6962. atomic_set(&phba->fast_event_count, 0);
  6963. atomic_set(&phba->dbg_log_idx, 0);
  6964. atomic_set(&phba->dbg_log_cnt, 0);
  6965. atomic_set(&phba->dbg_log_dmping, 0);
  6966. spin_lock_init(&phba->hbalock);
  6967. /* Initialize port_list spinlock */
  6968. spin_lock_init(&phba->port_list_lock);
  6969. INIT_LIST_HEAD(&phba->port_list);
  6970. INIT_LIST_HEAD(&phba->work_list);
  6971. /* Initialize the wait queue head for the kernel thread */
  6972. init_waitqueue_head(&phba->work_waitq);
  6973. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6974. "1403 Protocols supported %s %s %s\n",
  6975. ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
  6976. "SCSI" : " "),
  6977. ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
  6978. "NVME" : " "),
  6979. (phba->nvmet_support ? "NVMET" : " "));
  6980. /* Initialize the IO buffer list used by driver for SLI3 SCSI */
  6981. spin_lock_init(&phba->scsi_buf_list_get_lock);
  6982. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
  6983. spin_lock_init(&phba->scsi_buf_list_put_lock);
  6984. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
  6985. /* Initialize the fabric iocb list */
  6986. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  6987. /* Initialize list to save ELS buffers */
  6988. INIT_LIST_HEAD(&phba->elsbuf);
  6989. /* Initialize FCF connection rec list */
  6990. INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
  6991. /* Initialize OAS configuration list */
  6992. spin_lock_init(&phba->devicelock);
  6993. INIT_LIST_HEAD(&phba->luns);
  6994. /* MBOX heartbeat timer */
  6995. timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
  6996. /* Fabric block timer */
  6997. timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
  6998. /* EA polling mode timer */
  6999. timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
  7000. /* Heartbeat timer */
  7001. timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
  7002. INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work);
  7003. INIT_DELAYED_WORK(&phba->idle_stat_delay_work,
  7004. lpfc_idle_stat_delay_work);
  7005. INIT_WORK(&phba->unblock_request_work, lpfc_unblock_requests_work);
  7006. return 0;
  7007. }
  7008. /**
  7009. * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
  7010. * @phba: pointer to lpfc hba data structure.
  7011. *
  7012. * This routine is invoked to set up the driver internal resources specific to
  7013. * support the SLI-3 HBA device it attached to.
  7014. *
  7015. * Return codes
  7016. * 0 - successful
  7017. * other values - error
  7018. **/
  7019. static int
  7020. lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
  7021. {
  7022. int rc, entry_sz;
  7023. /*
  7024. * Initialize timers used by driver
  7025. */
  7026. /* FCP polling mode timer */
  7027. timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
  7028. /* Host attention work mask setup */
  7029. phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
  7030. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  7031. /* Get all the module params for configuring this host */
  7032. lpfc_get_cfgparam(phba);
  7033. /* Set up phase-1 common device driver resources */
  7034. rc = lpfc_setup_driver_resource_phase1(phba);
  7035. if (rc)
  7036. return -ENODEV;
  7037. if (!phba->sli.sli3_ring)
  7038. phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
  7039. sizeof(struct lpfc_sli_ring),
  7040. GFP_KERNEL);
  7041. if (!phba->sli.sli3_ring)
  7042. return -ENOMEM;
  7043. /*
  7044. * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
  7045. * used to create the sg_dma_buf_pool must be dynamically calculated.
  7046. */
  7047. if (phba->sli_rev == LPFC_SLI_REV4)
  7048. entry_sz = sizeof(struct sli4_sge);
  7049. else
  7050. entry_sz = sizeof(struct ulp_bde64);
  7051. /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
  7052. if (phba->cfg_enable_bg) {
  7053. /*
  7054. * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
  7055. * the FCP rsp, and a BDE for each. Sice we have no control
  7056. * over how many protection data segments the SCSI Layer
  7057. * will hand us (ie: there could be one for every block
  7058. * in the IO), we just allocate enough BDEs to accomidate
  7059. * our max amount and we need to limit lpfc_sg_seg_cnt to
  7060. * minimize the risk of running out.
  7061. */
  7062. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  7063. sizeof(struct fcp_rsp) +
  7064. (LPFC_MAX_SG_SEG_CNT * entry_sz);
  7065. if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
  7066. phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
  7067. /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
  7068. phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
  7069. } else {
  7070. /*
  7071. * The scsi_buf for a regular I/O will hold the FCP cmnd,
  7072. * the FCP rsp, a BDE for each, and a BDE for up to
  7073. * cfg_sg_seg_cnt data segments.
  7074. */
  7075. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  7076. sizeof(struct fcp_rsp) +
  7077. ((phba->cfg_sg_seg_cnt + 2) * entry_sz);
  7078. /* Total BDEs in BPL for scsi_sg_list */
  7079. phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
  7080. }
  7081. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
  7082. "9088 INIT sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
  7083. phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
  7084. phba->cfg_total_seg_cnt);
  7085. phba->max_vpi = LPFC_MAX_VPI;
  7086. /* This will be set to correct value after config_port mbox */
  7087. phba->max_vports = 0;
  7088. /*
  7089. * Initialize the SLI Layer to run with lpfc HBAs.
  7090. */
  7091. lpfc_sli_setup(phba);
  7092. lpfc_sli_queue_init(phba);
  7093. /* Allocate device driver memory */
  7094. if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
  7095. return -ENOMEM;
  7096. phba->lpfc_sg_dma_buf_pool =
  7097. dma_pool_create("lpfc_sg_dma_buf_pool",
  7098. &phba->pcidev->dev, phba->cfg_sg_dma_buf_size,
  7099. BPL_ALIGN_SZ, 0);
  7100. if (!phba->lpfc_sg_dma_buf_pool)
  7101. goto fail_free_mem;
  7102. phba->lpfc_cmd_rsp_buf_pool =
  7103. dma_pool_create("lpfc_cmd_rsp_buf_pool",
  7104. &phba->pcidev->dev,
  7105. sizeof(struct fcp_cmnd) +
  7106. sizeof(struct fcp_rsp),
  7107. BPL_ALIGN_SZ, 0);
  7108. if (!phba->lpfc_cmd_rsp_buf_pool)
  7109. goto fail_free_dma_buf_pool;
  7110. /*
  7111. * Enable sr-iov virtual functions if supported and configured
  7112. * through the module parameter.
  7113. */
  7114. if (phba->cfg_sriov_nr_virtfn > 0) {
  7115. rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
  7116. phba->cfg_sriov_nr_virtfn);
  7117. if (rc) {
  7118. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7119. "2808 Requested number of SR-IOV "
  7120. "virtual functions (%d) is not "
  7121. "supported\n",
  7122. phba->cfg_sriov_nr_virtfn);
  7123. phba->cfg_sriov_nr_virtfn = 0;
  7124. }
  7125. }
  7126. return 0;
  7127. fail_free_dma_buf_pool:
  7128. dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
  7129. phba->lpfc_sg_dma_buf_pool = NULL;
  7130. fail_free_mem:
  7131. lpfc_mem_free(phba);
  7132. return -ENOMEM;
  7133. }
  7134. /**
  7135. * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
  7136. * @phba: pointer to lpfc hba data structure.
  7137. *
  7138. * This routine is invoked to unset the driver internal resources set up
  7139. * specific for supporting the SLI-3 HBA device it attached to.
  7140. **/
  7141. static void
  7142. lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
  7143. {
  7144. /* Free device driver memory allocated */
  7145. lpfc_mem_free_all(phba);
  7146. return;
  7147. }
  7148. /**
  7149. * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
  7150. * @phba: pointer to lpfc hba data structure.
  7151. *
  7152. * This routine is invoked to set up the driver internal resources specific to
  7153. * support the SLI-4 HBA device it attached to.
  7154. *
  7155. * Return codes
  7156. * 0 - successful
  7157. * other values - error
  7158. **/
  7159. static int
  7160. lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
  7161. {
  7162. LPFC_MBOXQ_t *mboxq;
  7163. MAILBOX_t *mb;
  7164. int rc, i, max_buf_size;
  7165. int longs;
  7166. int extra;
  7167. uint64_t wwn;
  7168. u32 if_type;
  7169. u32 if_fam;
  7170. phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
  7171. phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1;
  7172. phba->sli4_hba.curr_disp_cpu = 0;
  7173. /* Get all the module params for configuring this host */
  7174. lpfc_get_cfgparam(phba);
  7175. /* Set up phase-1 common device driver resources */
  7176. rc = lpfc_setup_driver_resource_phase1(phba);
  7177. if (rc)
  7178. return -ENODEV;
  7179. /* Before proceed, wait for POST done and device ready */
  7180. rc = lpfc_sli4_post_status_check(phba);
  7181. if (rc)
  7182. return -ENODEV;
  7183. /* Allocate all driver workqueues here */
  7184. /* The lpfc_wq workqueue for deferred irq use */
  7185. phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
  7186. if (!phba->wq)
  7187. return -ENOMEM;
  7188. /*
  7189. * Initialize timers used by driver
  7190. */
  7191. timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
  7192. /* FCF rediscover timer */
  7193. timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
  7194. /* CMF congestion timer */
  7195. hrtimer_init(&phba->cmf_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  7196. phba->cmf_timer.function = lpfc_cmf_timer;
  7197. /*
  7198. * Control structure for handling external multi-buffer mailbox
  7199. * command pass-through.
  7200. */
  7201. memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
  7202. sizeof(struct lpfc_mbox_ext_buf_ctx));
  7203. INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
  7204. phba->max_vpi = LPFC_MAX_VPI;
  7205. /* This will be set to correct value after the read_config mbox */
  7206. phba->max_vports = 0;
  7207. /* Program the default value of vlan_id and fc_map */
  7208. phba->valid_vlan = 0;
  7209. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  7210. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  7211. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  7212. /*
  7213. * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
  7214. * we will associate a new ring, for each EQ/CQ/WQ tuple.
  7215. * The WQ create will allocate the ring.
  7216. */
  7217. /* Initialize buffer queue management fields */
  7218. INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
  7219. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
  7220. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
  7221. /* for VMID idle timeout if VMID is enabled */
  7222. if (lpfc_is_vmid_enabled(phba))
  7223. timer_setup(&phba->inactive_vmid_poll, lpfc_vmid_poll, 0);
  7224. /*
  7225. * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
  7226. */
  7227. /* Initialize the Abort buffer list used by driver */
  7228. spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock);
  7229. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list);
  7230. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  7231. /* Initialize the Abort nvme buffer list used by driver */
  7232. spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock);
  7233. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
  7234. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
  7235. spin_lock_init(&phba->sli4_hba.t_active_list_lock);
  7236. INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list);
  7237. }
  7238. /* This abort list used by worker thread */
  7239. spin_lock_init(&phba->sli4_hba.sgl_list_lock);
  7240. spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
  7241. spin_lock_init(&phba->sli4_hba.asynce_list_lock);
  7242. spin_lock_init(&phba->sli4_hba.els_xri_abrt_list_lock);
  7243. /*
  7244. * Initialize driver internal slow-path work queues
  7245. */
  7246. /* Driver internel slow-path CQ Event pool */
  7247. INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
  7248. /* Response IOCB work queue list */
  7249. INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
  7250. /* Asynchronous event CQ Event work queue list */
  7251. INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
  7252. /* Slow-path XRI aborted CQ Event work queue list */
  7253. INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
  7254. /* Receive queue CQ Event work queue list */
  7255. INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
  7256. /* Initialize extent block lists. */
  7257. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
  7258. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
  7259. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
  7260. INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
  7261. /* Initialize mboxq lists. If the early init routines fail
  7262. * these lists need to be correctly initialized.
  7263. */
  7264. INIT_LIST_HEAD(&phba->sli.mboxq);
  7265. INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
  7266. /* initialize optic_state to 0xFF */
  7267. phba->sli4_hba.lnk_info.optic_state = 0xff;
  7268. /* Allocate device driver memory */
  7269. rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
  7270. if (rc)
  7271. goto out_destroy_workqueue;
  7272. /* IF Type 2 ports get initialized now. */
  7273. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
  7274. LPFC_SLI_INTF_IF_TYPE_2) {
  7275. rc = lpfc_pci_function_reset(phba);
  7276. if (unlikely(rc)) {
  7277. rc = -ENODEV;
  7278. goto out_free_mem;
  7279. }
  7280. phba->temp_sensor_support = 1;
  7281. }
  7282. /* Create the bootstrap mailbox command */
  7283. rc = lpfc_create_bootstrap_mbox(phba);
  7284. if (unlikely(rc))
  7285. goto out_free_mem;
  7286. /* Set up the host's endian order with the device. */
  7287. rc = lpfc_setup_endian_order(phba);
  7288. if (unlikely(rc))
  7289. goto out_free_bsmbx;
  7290. /* Set up the hba's configuration parameters. */
  7291. rc = lpfc_sli4_read_config(phba);
  7292. if (unlikely(rc))
  7293. goto out_free_bsmbx;
  7294. if (phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_CONFIG) {
  7295. /* Right now the link is down, if FA-PWWN is configured the
  7296. * firmware will try FLOGI before the driver gets a link up.
  7297. * If it fails, the driver should get a MISCONFIGURED async
  7298. * event which will clear this flag. The only notification
  7299. * the driver gets is if it fails, if it succeeds there is no
  7300. * notification given. Assume success.
  7301. */
  7302. phba->sli4_hba.fawwpn_flag |= LPFC_FAWWPN_FABRIC;
  7303. }
  7304. rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
  7305. if (unlikely(rc))
  7306. goto out_free_bsmbx;
  7307. /* IF Type 0 ports get initialized now. */
  7308. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  7309. LPFC_SLI_INTF_IF_TYPE_0) {
  7310. rc = lpfc_pci_function_reset(phba);
  7311. if (unlikely(rc))
  7312. goto out_free_bsmbx;
  7313. }
  7314. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  7315. GFP_KERNEL);
  7316. if (!mboxq) {
  7317. rc = -ENOMEM;
  7318. goto out_free_bsmbx;
  7319. }
  7320. /* Check for NVMET being configured */
  7321. phba->nvmet_support = 0;
  7322. if (lpfc_enable_nvmet_cnt) {
  7323. /* First get WWN of HBA instance */
  7324. lpfc_read_nv(phba, mboxq);
  7325. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7326. if (rc != MBX_SUCCESS) {
  7327. lpfc_printf_log(phba, KERN_ERR,
  7328. LOG_TRACE_EVENT,
  7329. "6016 Mailbox failed , mbxCmd x%x "
  7330. "READ_NV, mbxStatus x%x\n",
  7331. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  7332. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  7333. mempool_free(mboxq, phba->mbox_mem_pool);
  7334. rc = -EIO;
  7335. goto out_free_bsmbx;
  7336. }
  7337. mb = &mboxq->u.mb;
  7338. memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
  7339. sizeof(uint64_t));
  7340. wwn = cpu_to_be64(wwn);
  7341. phba->sli4_hba.wwnn.u.name = wwn;
  7342. memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
  7343. sizeof(uint64_t));
  7344. /* wwn is WWPN of HBA instance */
  7345. wwn = cpu_to_be64(wwn);
  7346. phba->sli4_hba.wwpn.u.name = wwn;
  7347. /* Check to see if it matches any module parameter */
  7348. for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
  7349. if (wwn == lpfc_enable_nvmet[i]) {
  7350. #if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
  7351. if (lpfc_nvmet_mem_alloc(phba))
  7352. break;
  7353. phba->nvmet_support = 1; /* a match */
  7354. lpfc_printf_log(phba, KERN_ERR,
  7355. LOG_TRACE_EVENT,
  7356. "6017 NVME Target %016llx\n",
  7357. wwn);
  7358. #else
  7359. lpfc_printf_log(phba, KERN_ERR,
  7360. LOG_TRACE_EVENT,
  7361. "6021 Can't enable NVME Target."
  7362. " NVME_TARGET_FC infrastructure"
  7363. " is not in kernel\n");
  7364. #endif
  7365. /* Not supported for NVMET */
  7366. phba->cfg_xri_rebalancing = 0;
  7367. if (phba->irq_chann_mode == NHT_MODE) {
  7368. phba->cfg_irq_chann =
  7369. phba->sli4_hba.num_present_cpu;
  7370. phba->cfg_hdw_queue =
  7371. phba->sli4_hba.num_present_cpu;
  7372. phba->irq_chann_mode = NORMAL_MODE;
  7373. }
  7374. break;
  7375. }
  7376. }
  7377. }
  7378. lpfc_nvme_mod_param_dep(phba);
  7379. /*
  7380. * Get sli4 parameters that override parameters from Port capabilities.
  7381. * If this call fails, it isn't critical unless the SLI4 parameters come
  7382. * back in conflict.
  7383. */
  7384. rc = lpfc_get_sli4_parameters(phba, mboxq);
  7385. if (rc) {
  7386. if_type = bf_get(lpfc_sli_intf_if_type,
  7387. &phba->sli4_hba.sli_intf);
  7388. if_fam = bf_get(lpfc_sli_intf_sli_family,
  7389. &phba->sli4_hba.sli_intf);
  7390. if (phba->sli4_hba.extents_in_use &&
  7391. phba->sli4_hba.rpi_hdrs_in_use) {
  7392. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7393. "2999 Unsupported SLI4 Parameters "
  7394. "Extents and RPI headers enabled.\n");
  7395. if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
  7396. if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
  7397. mempool_free(mboxq, phba->mbox_mem_pool);
  7398. rc = -EIO;
  7399. goto out_free_bsmbx;
  7400. }
  7401. }
  7402. if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
  7403. if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
  7404. mempool_free(mboxq, phba->mbox_mem_pool);
  7405. rc = -EIO;
  7406. goto out_free_bsmbx;
  7407. }
  7408. }
  7409. /*
  7410. * 1 for cmd, 1 for rsp, NVME adds an extra one
  7411. * for boundary conditions in its max_sgl_segment template.
  7412. */
  7413. extra = 2;
  7414. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
  7415. extra++;
  7416. /*
  7417. * It doesn't matter what family our adapter is in, we are
  7418. * limited to 2 Pages, 512 SGEs, for our SGL.
  7419. * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
  7420. */
  7421. max_buf_size = (2 * SLI4_PAGE_SIZE);
  7422. /*
  7423. * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
  7424. * used to create the sg_dma_buf_pool must be calculated.
  7425. */
  7426. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
  7427. /* Both cfg_enable_bg and cfg_external_dif code paths */
  7428. /*
  7429. * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
  7430. * the FCP rsp, and a SGE. Sice we have no control
  7431. * over how many protection segments the SCSI Layer
  7432. * will hand us (ie: there could be one for every block
  7433. * in the IO), just allocate enough SGEs to accomidate
  7434. * our max amount and we need to limit lpfc_sg_seg_cnt
  7435. * to minimize the risk of running out.
  7436. */
  7437. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  7438. sizeof(struct fcp_rsp) + max_buf_size;
  7439. /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
  7440. phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
  7441. /*
  7442. * If supporting DIF, reduce the seg count for scsi to
  7443. * allow room for the DIF sges.
  7444. */
  7445. if (phba->cfg_enable_bg &&
  7446. phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
  7447. phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
  7448. else
  7449. phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
  7450. } else {
  7451. /*
  7452. * The scsi_buf for a regular I/O holds the FCP cmnd,
  7453. * the FCP rsp, a SGE for each, and a SGE for up to
  7454. * cfg_sg_seg_cnt data segments.
  7455. */
  7456. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  7457. sizeof(struct fcp_rsp) +
  7458. ((phba->cfg_sg_seg_cnt + extra) *
  7459. sizeof(struct sli4_sge));
  7460. /* Total SGEs for scsi_sg_list */
  7461. phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
  7462. phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
  7463. /*
  7464. * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
  7465. * need to post 1 page for the SGL.
  7466. */
  7467. }
  7468. if (phba->cfg_xpsgl && !phba->nvmet_support)
  7469. phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE;
  7470. else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
  7471. phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
  7472. else
  7473. phba->cfg_sg_dma_buf_size =
  7474. SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
  7475. phba->border_sge_num = phba->cfg_sg_dma_buf_size /
  7476. sizeof(struct sli4_sge);
  7477. /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
  7478. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  7479. if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
  7480. lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
  7481. "6300 Reducing NVME sg segment "
  7482. "cnt to %d\n",
  7483. LPFC_MAX_NVME_SEG_CNT);
  7484. phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
  7485. } else
  7486. phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
  7487. }
  7488. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
  7489. "9087 sg_seg_cnt:%d dmabuf_size:%d "
  7490. "total:%d scsi:%d nvme:%d\n",
  7491. phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
  7492. phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
  7493. phba->cfg_nvme_seg_cnt);
  7494. if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE)
  7495. i = phba->cfg_sg_dma_buf_size;
  7496. else
  7497. i = SLI4_PAGE_SIZE;
  7498. phba->lpfc_sg_dma_buf_pool =
  7499. dma_pool_create("lpfc_sg_dma_buf_pool",
  7500. &phba->pcidev->dev,
  7501. phba->cfg_sg_dma_buf_size,
  7502. i, 0);
  7503. if (!phba->lpfc_sg_dma_buf_pool) {
  7504. rc = -ENOMEM;
  7505. goto out_free_bsmbx;
  7506. }
  7507. phba->lpfc_cmd_rsp_buf_pool =
  7508. dma_pool_create("lpfc_cmd_rsp_buf_pool",
  7509. &phba->pcidev->dev,
  7510. sizeof(struct fcp_cmnd) +
  7511. sizeof(struct fcp_rsp),
  7512. i, 0);
  7513. if (!phba->lpfc_cmd_rsp_buf_pool) {
  7514. rc = -ENOMEM;
  7515. goto out_free_sg_dma_buf;
  7516. }
  7517. mempool_free(mboxq, phba->mbox_mem_pool);
  7518. /* Verify OAS is supported */
  7519. lpfc_sli4_oas_verify(phba);
  7520. /* Verify RAS support on adapter */
  7521. lpfc_sli4_ras_init(phba);
  7522. /* Verify all the SLI4 queues */
  7523. rc = lpfc_sli4_queue_verify(phba);
  7524. if (rc)
  7525. goto out_free_cmd_rsp_buf;
  7526. /* Create driver internal CQE event pool */
  7527. rc = lpfc_sli4_cq_event_pool_create(phba);
  7528. if (rc)
  7529. goto out_free_cmd_rsp_buf;
  7530. /* Initialize sgl lists per host */
  7531. lpfc_init_sgl_list(phba);
  7532. /* Allocate and initialize active sgl array */
  7533. rc = lpfc_init_active_sgl_array(phba);
  7534. if (rc) {
  7535. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7536. "1430 Failed to initialize sgl list.\n");
  7537. goto out_destroy_cq_event_pool;
  7538. }
  7539. rc = lpfc_sli4_init_rpi_hdrs(phba);
  7540. if (rc) {
  7541. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7542. "1432 Failed to initialize rpi headers.\n");
  7543. goto out_free_active_sgl;
  7544. }
  7545. /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
  7546. longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
  7547. phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
  7548. GFP_KERNEL);
  7549. if (!phba->fcf.fcf_rr_bmask) {
  7550. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7551. "2759 Failed allocate memory for FCF round "
  7552. "robin failover bmask\n");
  7553. rc = -ENOMEM;
  7554. goto out_remove_rpi_hdrs;
  7555. }
  7556. phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann,
  7557. sizeof(struct lpfc_hba_eq_hdl),
  7558. GFP_KERNEL);
  7559. if (!phba->sli4_hba.hba_eq_hdl) {
  7560. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7561. "2572 Failed allocate memory for "
  7562. "fast-path per-EQ handle array\n");
  7563. rc = -ENOMEM;
  7564. goto out_free_fcf_rr_bmask;
  7565. }
  7566. phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu,
  7567. sizeof(struct lpfc_vector_map_info),
  7568. GFP_KERNEL);
  7569. if (!phba->sli4_hba.cpu_map) {
  7570. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7571. "3327 Failed allocate memory for msi-x "
  7572. "interrupt vector mapping\n");
  7573. rc = -ENOMEM;
  7574. goto out_free_hba_eq_hdl;
  7575. }
  7576. phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info);
  7577. if (!phba->sli4_hba.eq_info) {
  7578. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7579. "3321 Failed allocation for per_cpu stats\n");
  7580. rc = -ENOMEM;
  7581. goto out_free_hba_cpu_map;
  7582. }
  7583. phba->sli4_hba.idle_stat = kcalloc(phba->sli4_hba.num_possible_cpu,
  7584. sizeof(*phba->sli4_hba.idle_stat),
  7585. GFP_KERNEL);
  7586. if (!phba->sli4_hba.idle_stat) {
  7587. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7588. "3390 Failed allocation for idle_stat\n");
  7589. rc = -ENOMEM;
  7590. goto out_free_hba_eq_info;
  7591. }
  7592. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  7593. phba->sli4_hba.c_stat = alloc_percpu(struct lpfc_hdwq_stat);
  7594. if (!phba->sli4_hba.c_stat) {
  7595. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7596. "3332 Failed allocating per cpu hdwq stats\n");
  7597. rc = -ENOMEM;
  7598. goto out_free_hba_idle_stat;
  7599. }
  7600. #endif
  7601. phba->cmf_stat = alloc_percpu(struct lpfc_cgn_stat);
  7602. if (!phba->cmf_stat) {
  7603. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7604. "3331 Failed allocating per cpu cgn stats\n");
  7605. rc = -ENOMEM;
  7606. goto out_free_hba_hdwq_info;
  7607. }
  7608. /*
  7609. * Enable sr-iov virtual functions if supported and configured
  7610. * through the module parameter.
  7611. */
  7612. if (phba->cfg_sriov_nr_virtfn > 0) {
  7613. rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
  7614. phba->cfg_sriov_nr_virtfn);
  7615. if (rc) {
  7616. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7617. "3020 Requested number of SR-IOV "
  7618. "virtual functions (%d) is not "
  7619. "supported\n",
  7620. phba->cfg_sriov_nr_virtfn);
  7621. phba->cfg_sriov_nr_virtfn = 0;
  7622. }
  7623. }
  7624. return 0;
  7625. out_free_hba_hdwq_info:
  7626. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  7627. free_percpu(phba->sli4_hba.c_stat);
  7628. out_free_hba_idle_stat:
  7629. #endif
  7630. kfree(phba->sli4_hba.idle_stat);
  7631. out_free_hba_eq_info:
  7632. free_percpu(phba->sli4_hba.eq_info);
  7633. out_free_hba_cpu_map:
  7634. kfree(phba->sli4_hba.cpu_map);
  7635. out_free_hba_eq_hdl:
  7636. kfree(phba->sli4_hba.hba_eq_hdl);
  7637. out_free_fcf_rr_bmask:
  7638. kfree(phba->fcf.fcf_rr_bmask);
  7639. out_remove_rpi_hdrs:
  7640. lpfc_sli4_remove_rpi_hdrs(phba);
  7641. out_free_active_sgl:
  7642. lpfc_free_active_sgl(phba);
  7643. out_destroy_cq_event_pool:
  7644. lpfc_sli4_cq_event_pool_destroy(phba);
  7645. out_free_cmd_rsp_buf:
  7646. dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool);
  7647. phba->lpfc_cmd_rsp_buf_pool = NULL;
  7648. out_free_sg_dma_buf:
  7649. dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
  7650. phba->lpfc_sg_dma_buf_pool = NULL;
  7651. out_free_bsmbx:
  7652. lpfc_destroy_bootstrap_mbox(phba);
  7653. out_free_mem:
  7654. lpfc_mem_free(phba);
  7655. out_destroy_workqueue:
  7656. destroy_workqueue(phba->wq);
  7657. phba->wq = NULL;
  7658. return rc;
  7659. }
  7660. /**
  7661. * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
  7662. * @phba: pointer to lpfc hba data structure.
  7663. *
  7664. * This routine is invoked to unset the driver internal resources set up
  7665. * specific for supporting the SLI-4 HBA device it attached to.
  7666. **/
  7667. static void
  7668. lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
  7669. {
  7670. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  7671. free_percpu(phba->sli4_hba.eq_info);
  7672. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  7673. free_percpu(phba->sli4_hba.c_stat);
  7674. #endif
  7675. free_percpu(phba->cmf_stat);
  7676. kfree(phba->sli4_hba.idle_stat);
  7677. /* Free memory allocated for msi-x interrupt vector to CPU mapping */
  7678. kfree(phba->sli4_hba.cpu_map);
  7679. phba->sli4_hba.num_possible_cpu = 0;
  7680. phba->sli4_hba.num_present_cpu = 0;
  7681. phba->sli4_hba.curr_disp_cpu = 0;
  7682. cpumask_clear(&phba->sli4_hba.irq_aff_mask);
  7683. /* Free memory allocated for fast-path work queue handles */
  7684. kfree(phba->sli4_hba.hba_eq_hdl);
  7685. /* Free the allocated rpi headers. */
  7686. lpfc_sli4_remove_rpi_hdrs(phba);
  7687. lpfc_sli4_remove_rpis(phba);
  7688. /* Free eligible FCF index bmask */
  7689. kfree(phba->fcf.fcf_rr_bmask);
  7690. /* Free the ELS sgl list */
  7691. lpfc_free_active_sgl(phba);
  7692. lpfc_free_els_sgl_list(phba);
  7693. lpfc_free_nvmet_sgl_list(phba);
  7694. /* Free the completion queue EQ event pool */
  7695. lpfc_sli4_cq_event_release_all(phba);
  7696. lpfc_sli4_cq_event_pool_destroy(phba);
  7697. /* Release resource identifiers. */
  7698. lpfc_sli4_dealloc_resource_identifiers(phba);
  7699. /* Free the bsmbx region. */
  7700. lpfc_destroy_bootstrap_mbox(phba);
  7701. /* Free the SLI Layer memory with SLI4 HBAs */
  7702. lpfc_mem_free_all(phba);
  7703. /* Free the current connect table */
  7704. list_for_each_entry_safe(conn_entry, next_conn_entry,
  7705. &phba->fcf_conn_rec_list, list) {
  7706. list_del_init(&conn_entry->list);
  7707. kfree(conn_entry);
  7708. }
  7709. return;
  7710. }
  7711. /**
  7712. * lpfc_init_api_table_setup - Set up init api function jump table
  7713. * @phba: The hba struct for which this call is being executed.
  7714. * @dev_grp: The HBA PCI-Device group number.
  7715. *
  7716. * This routine sets up the device INIT interface API function jump table
  7717. * in @phba struct.
  7718. *
  7719. * Returns: 0 - success, -ENODEV - failure.
  7720. **/
  7721. int
  7722. lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7723. {
  7724. phba->lpfc_hba_init_link = lpfc_hba_init_link;
  7725. phba->lpfc_hba_down_link = lpfc_hba_down_link;
  7726. phba->lpfc_selective_reset = lpfc_selective_reset;
  7727. switch (dev_grp) {
  7728. case LPFC_PCI_DEV_LP:
  7729. phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
  7730. phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
  7731. phba->lpfc_stop_port = lpfc_stop_port_s3;
  7732. break;
  7733. case LPFC_PCI_DEV_OC:
  7734. phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
  7735. phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
  7736. phba->lpfc_stop_port = lpfc_stop_port_s4;
  7737. break;
  7738. default:
  7739. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7740. "1431 Invalid HBA PCI-device group: 0x%x\n",
  7741. dev_grp);
  7742. return -ENODEV;
  7743. }
  7744. return 0;
  7745. }
  7746. /**
  7747. * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
  7748. * @phba: pointer to lpfc hba data structure.
  7749. *
  7750. * This routine is invoked to set up the driver internal resources after the
  7751. * device specific resource setup to support the HBA device it attached to.
  7752. *
  7753. * Return codes
  7754. * 0 - successful
  7755. * other values - error
  7756. **/
  7757. static int
  7758. lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
  7759. {
  7760. int error;
  7761. /* Startup the kernel thread for this host adapter. */
  7762. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  7763. "lpfc_worker_%d", phba->brd_no);
  7764. if (IS_ERR(phba->worker_thread)) {
  7765. error = PTR_ERR(phba->worker_thread);
  7766. return error;
  7767. }
  7768. return 0;
  7769. }
  7770. /**
  7771. * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
  7772. * @phba: pointer to lpfc hba data structure.
  7773. *
  7774. * This routine is invoked to unset the driver internal resources set up after
  7775. * the device specific resource setup for supporting the HBA device it
  7776. * attached to.
  7777. **/
  7778. static void
  7779. lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
  7780. {
  7781. if (phba->wq) {
  7782. destroy_workqueue(phba->wq);
  7783. phba->wq = NULL;
  7784. }
  7785. /* Stop kernel worker thread */
  7786. if (phba->worker_thread)
  7787. kthread_stop(phba->worker_thread);
  7788. }
  7789. /**
  7790. * lpfc_free_iocb_list - Free iocb list.
  7791. * @phba: pointer to lpfc hba data structure.
  7792. *
  7793. * This routine is invoked to free the driver's IOCB list and memory.
  7794. **/
  7795. void
  7796. lpfc_free_iocb_list(struct lpfc_hba *phba)
  7797. {
  7798. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  7799. spin_lock_irq(&phba->hbalock);
  7800. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  7801. &phba->lpfc_iocb_list, list) {
  7802. list_del(&iocbq_entry->list);
  7803. kfree(iocbq_entry);
  7804. phba->total_iocbq_bufs--;
  7805. }
  7806. spin_unlock_irq(&phba->hbalock);
  7807. return;
  7808. }
  7809. /**
  7810. * lpfc_init_iocb_list - Allocate and initialize iocb list.
  7811. * @phba: pointer to lpfc hba data structure.
  7812. * @iocb_count: number of requested iocbs
  7813. *
  7814. * This routine is invoked to allocate and initizlize the driver's IOCB
  7815. * list and set up the IOCB tag array accordingly.
  7816. *
  7817. * Return codes
  7818. * 0 - successful
  7819. * other values - error
  7820. **/
  7821. int
  7822. lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
  7823. {
  7824. struct lpfc_iocbq *iocbq_entry = NULL;
  7825. uint16_t iotag;
  7826. int i;
  7827. /* Initialize and populate the iocb list per host. */
  7828. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  7829. for (i = 0; i < iocb_count; i++) {
  7830. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  7831. if (iocbq_entry == NULL) {
  7832. printk(KERN_ERR "%s: only allocated %d iocbs of "
  7833. "expected %d count. Unloading driver.\n",
  7834. __func__, i, iocb_count);
  7835. goto out_free_iocbq;
  7836. }
  7837. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  7838. if (iotag == 0) {
  7839. kfree(iocbq_entry);
  7840. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  7841. "Unloading driver.\n", __func__);
  7842. goto out_free_iocbq;
  7843. }
  7844. iocbq_entry->sli4_lxritag = NO_XRI;
  7845. iocbq_entry->sli4_xritag = NO_XRI;
  7846. spin_lock_irq(&phba->hbalock);
  7847. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  7848. phba->total_iocbq_bufs++;
  7849. spin_unlock_irq(&phba->hbalock);
  7850. }
  7851. return 0;
  7852. out_free_iocbq:
  7853. lpfc_free_iocb_list(phba);
  7854. return -ENOMEM;
  7855. }
  7856. /**
  7857. * lpfc_free_sgl_list - Free a given sgl list.
  7858. * @phba: pointer to lpfc hba data structure.
  7859. * @sglq_list: pointer to the head of sgl list.
  7860. *
  7861. * This routine is invoked to free a give sgl list and memory.
  7862. **/
  7863. void
  7864. lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
  7865. {
  7866. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  7867. list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
  7868. list_del(&sglq_entry->list);
  7869. lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
  7870. kfree(sglq_entry);
  7871. }
  7872. }
  7873. /**
  7874. * lpfc_free_els_sgl_list - Free els sgl list.
  7875. * @phba: pointer to lpfc hba data structure.
  7876. *
  7877. * This routine is invoked to free the driver's els sgl list and memory.
  7878. **/
  7879. static void
  7880. lpfc_free_els_sgl_list(struct lpfc_hba *phba)
  7881. {
  7882. LIST_HEAD(sglq_list);
  7883. /* Retrieve all els sgls from driver list */
  7884. spin_lock_irq(&phba->sli4_hba.sgl_list_lock);
  7885. list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
  7886. spin_unlock_irq(&phba->sli4_hba.sgl_list_lock);
  7887. /* Now free the sgl list */
  7888. lpfc_free_sgl_list(phba, &sglq_list);
  7889. }
  7890. /**
  7891. * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
  7892. * @phba: pointer to lpfc hba data structure.
  7893. *
  7894. * This routine is invoked to free the driver's nvmet sgl list and memory.
  7895. **/
  7896. static void
  7897. lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
  7898. {
  7899. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  7900. LIST_HEAD(sglq_list);
  7901. /* Retrieve all nvmet sgls from driver list */
  7902. spin_lock_irq(&phba->hbalock);
  7903. spin_lock(&phba->sli4_hba.sgl_list_lock);
  7904. list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
  7905. spin_unlock(&phba->sli4_hba.sgl_list_lock);
  7906. spin_unlock_irq(&phba->hbalock);
  7907. /* Now free the sgl list */
  7908. list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
  7909. list_del(&sglq_entry->list);
  7910. lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
  7911. kfree(sglq_entry);
  7912. }
  7913. /* Update the nvmet_xri_cnt to reflect no current sgls.
  7914. * The next initialization cycle sets the count and allocates
  7915. * the sgls over again.
  7916. */
  7917. phba->sli4_hba.nvmet_xri_cnt = 0;
  7918. }
  7919. /**
  7920. * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
  7921. * @phba: pointer to lpfc hba data structure.
  7922. *
  7923. * This routine is invoked to allocate the driver's active sgl memory.
  7924. * This array will hold the sglq_entry's for active IOs.
  7925. **/
  7926. static int
  7927. lpfc_init_active_sgl_array(struct lpfc_hba *phba)
  7928. {
  7929. int size;
  7930. size = sizeof(struct lpfc_sglq *);
  7931. size *= phba->sli4_hba.max_cfg_param.max_xri;
  7932. phba->sli4_hba.lpfc_sglq_active_list =
  7933. kzalloc(size, GFP_KERNEL);
  7934. if (!phba->sli4_hba.lpfc_sglq_active_list)
  7935. return -ENOMEM;
  7936. return 0;
  7937. }
  7938. /**
  7939. * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
  7940. * @phba: pointer to lpfc hba data structure.
  7941. *
  7942. * This routine is invoked to walk through the array of active sglq entries
  7943. * and free all of the resources.
  7944. * This is just a place holder for now.
  7945. **/
  7946. static void
  7947. lpfc_free_active_sgl(struct lpfc_hba *phba)
  7948. {
  7949. kfree(phba->sli4_hba.lpfc_sglq_active_list);
  7950. }
  7951. /**
  7952. * lpfc_init_sgl_list - Allocate and initialize sgl list.
  7953. * @phba: pointer to lpfc hba data structure.
  7954. *
  7955. * This routine is invoked to allocate and initizlize the driver's sgl
  7956. * list and set up the sgl xritag tag array accordingly.
  7957. *
  7958. **/
  7959. static void
  7960. lpfc_init_sgl_list(struct lpfc_hba *phba)
  7961. {
  7962. /* Initialize and populate the sglq list per host/VF. */
  7963. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
  7964. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  7965. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
  7966. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
  7967. /* els xri-sgl book keeping */
  7968. phba->sli4_hba.els_xri_cnt = 0;
  7969. /* nvme xri-buffer book keeping */
  7970. phba->sli4_hba.io_xri_cnt = 0;
  7971. }
  7972. /**
  7973. * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
  7974. * @phba: pointer to lpfc hba data structure.
  7975. *
  7976. * This routine is invoked to post rpi header templates to the
  7977. * port for those SLI4 ports that do not support extents. This routine
  7978. * posts a PAGE_SIZE memory region to the port to hold up to
  7979. * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
  7980. * and should be called only when interrupts are disabled.
  7981. *
  7982. * Return codes
  7983. * 0 - successful
  7984. * -ERROR - otherwise.
  7985. **/
  7986. int
  7987. lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
  7988. {
  7989. int rc = 0;
  7990. struct lpfc_rpi_hdr *rpi_hdr;
  7991. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
  7992. if (!phba->sli4_hba.rpi_hdrs_in_use)
  7993. return rc;
  7994. if (phba->sli4_hba.extents_in_use)
  7995. return -EIO;
  7996. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  7997. if (!rpi_hdr) {
  7998. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7999. "0391 Error during rpi post operation\n");
  8000. lpfc_sli4_remove_rpis(phba);
  8001. rc = -ENODEV;
  8002. }
  8003. return rc;
  8004. }
  8005. /**
  8006. * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
  8007. * @phba: pointer to lpfc hba data structure.
  8008. *
  8009. * This routine is invoked to allocate a single 4KB memory region to
  8010. * support rpis and stores them in the phba. This single region
  8011. * provides support for up to 64 rpis. The region is used globally
  8012. * by the device.
  8013. *
  8014. * Returns:
  8015. * A valid rpi hdr on success.
  8016. * A NULL pointer on any failure.
  8017. **/
  8018. struct lpfc_rpi_hdr *
  8019. lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
  8020. {
  8021. uint16_t rpi_limit, curr_rpi_range;
  8022. struct lpfc_dmabuf *dmabuf;
  8023. struct lpfc_rpi_hdr *rpi_hdr;
  8024. /*
  8025. * If the SLI4 port supports extents, posting the rpi header isn't
  8026. * required. Set the expected maximum count and let the actual value
  8027. * get set when extents are fully allocated.
  8028. */
  8029. if (!phba->sli4_hba.rpi_hdrs_in_use)
  8030. return NULL;
  8031. if (phba->sli4_hba.extents_in_use)
  8032. return NULL;
  8033. /* The limit on the logical index is just the max_rpi count. */
  8034. rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
  8035. spin_lock_irq(&phba->hbalock);
  8036. /*
  8037. * Establish the starting RPI in this header block. The starting
  8038. * rpi is normalized to a zero base because the physical rpi is
  8039. * port based.
  8040. */
  8041. curr_rpi_range = phba->sli4_hba.next_rpi;
  8042. spin_unlock_irq(&phba->hbalock);
  8043. /* Reached full RPI range */
  8044. if (curr_rpi_range == rpi_limit)
  8045. return NULL;
  8046. /*
  8047. * First allocate the protocol header region for the port. The
  8048. * port expects a 4KB DMA-mapped memory region that is 4K aligned.
  8049. */
  8050. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8051. if (!dmabuf)
  8052. return NULL;
  8053. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8054. LPFC_HDR_TEMPLATE_SIZE,
  8055. &dmabuf->phys, GFP_KERNEL);
  8056. if (!dmabuf->virt) {
  8057. rpi_hdr = NULL;
  8058. goto err_free_dmabuf;
  8059. }
  8060. if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
  8061. rpi_hdr = NULL;
  8062. goto err_free_coherent;
  8063. }
  8064. /* Save the rpi header data for cleanup later. */
  8065. rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
  8066. if (!rpi_hdr)
  8067. goto err_free_coherent;
  8068. rpi_hdr->dmabuf = dmabuf;
  8069. rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
  8070. rpi_hdr->page_count = 1;
  8071. spin_lock_irq(&phba->hbalock);
  8072. /* The rpi_hdr stores the logical index only. */
  8073. rpi_hdr->start_rpi = curr_rpi_range;
  8074. rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
  8075. list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
  8076. spin_unlock_irq(&phba->hbalock);
  8077. return rpi_hdr;
  8078. err_free_coherent:
  8079. dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
  8080. dmabuf->virt, dmabuf->phys);
  8081. err_free_dmabuf:
  8082. kfree(dmabuf);
  8083. return NULL;
  8084. }
  8085. /**
  8086. * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
  8087. * @phba: pointer to lpfc hba data structure.
  8088. *
  8089. * This routine is invoked to remove all memory resources allocated
  8090. * to support rpis for SLI4 ports not supporting extents. This routine
  8091. * presumes the caller has released all rpis consumed by fabric or port
  8092. * logins and is prepared to have the header pages removed.
  8093. **/
  8094. void
  8095. lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
  8096. {
  8097. struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
  8098. if (!phba->sli4_hba.rpi_hdrs_in_use)
  8099. goto exit;
  8100. list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
  8101. &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  8102. list_del(&rpi_hdr->list);
  8103. dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
  8104. rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
  8105. kfree(rpi_hdr->dmabuf);
  8106. kfree(rpi_hdr);
  8107. }
  8108. exit:
  8109. /* There are no rpis available to the port now. */
  8110. phba->sli4_hba.next_rpi = 0;
  8111. }
  8112. /**
  8113. * lpfc_hba_alloc - Allocate driver hba data structure for a device.
  8114. * @pdev: pointer to pci device data structure.
  8115. *
  8116. * This routine is invoked to allocate the driver hba data structure for an
  8117. * HBA device. If the allocation is successful, the phba reference to the
  8118. * PCI device data structure is set.
  8119. *
  8120. * Return codes
  8121. * pointer to @phba - successful
  8122. * NULL - error
  8123. **/
  8124. static struct lpfc_hba *
  8125. lpfc_hba_alloc(struct pci_dev *pdev)
  8126. {
  8127. struct lpfc_hba *phba;
  8128. /* Allocate memory for HBA structure */
  8129. phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
  8130. if (!phba) {
  8131. dev_err(&pdev->dev, "failed to allocate hba struct\n");
  8132. return NULL;
  8133. }
  8134. /* Set reference to PCI device in HBA structure */
  8135. phba->pcidev = pdev;
  8136. /* Assign an unused board number */
  8137. phba->brd_no = lpfc_get_instance();
  8138. if (phba->brd_no < 0) {
  8139. kfree(phba);
  8140. return NULL;
  8141. }
  8142. phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
  8143. spin_lock_init(&phba->ct_ev_lock);
  8144. INIT_LIST_HEAD(&phba->ct_ev_waiters);
  8145. return phba;
  8146. }
  8147. /**
  8148. * lpfc_hba_free - Free driver hba data structure with a device.
  8149. * @phba: pointer to lpfc hba data structure.
  8150. *
  8151. * This routine is invoked to free the driver hba data structure with an
  8152. * HBA device.
  8153. **/
  8154. static void
  8155. lpfc_hba_free(struct lpfc_hba *phba)
  8156. {
  8157. if (phba->sli_rev == LPFC_SLI_REV4)
  8158. kfree(phba->sli4_hba.hdwq);
  8159. /* Release the driver assigned board number */
  8160. idr_remove(&lpfc_hba_index, phba->brd_no);
  8161. /* Free memory allocated with sli3 rings */
  8162. kfree(phba->sli.sli3_ring);
  8163. phba->sli.sli3_ring = NULL;
  8164. kfree(phba);
  8165. return;
  8166. }
  8167. /**
  8168. * lpfc_setup_fdmi_mask - Setup initial FDMI mask for HBA and Port attributes
  8169. * @vport: pointer to lpfc vport data structure.
  8170. *
  8171. * This routine is will setup initial FDMI attribute masks for
  8172. * FDMI2 or SmartSAN depending on module parameters. The driver will attempt
  8173. * to get these attributes first before falling back, the attribute
  8174. * fallback hierarchy is SmartSAN -> FDMI2 -> FMDI1
  8175. **/
  8176. void
  8177. lpfc_setup_fdmi_mask(struct lpfc_vport *vport)
  8178. {
  8179. struct lpfc_hba *phba = vport->phba;
  8180. vport->load_flag |= FC_ALLOW_FDMI;
  8181. if (phba->cfg_enable_SmartSAN ||
  8182. phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT) {
  8183. /* Setup appropriate attribute masks */
  8184. vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
  8185. if (phba->cfg_enable_SmartSAN)
  8186. vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
  8187. else
  8188. vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
  8189. }
  8190. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  8191. "6077 Setup FDMI mask: hba x%x port x%x\n",
  8192. vport->fdmi_hba_mask, vport->fdmi_port_mask);
  8193. }
  8194. /**
  8195. * lpfc_create_shost - Create hba physical port with associated scsi host.
  8196. * @phba: pointer to lpfc hba data structure.
  8197. *
  8198. * This routine is invoked to create HBA physical port and associate a SCSI
  8199. * host with it.
  8200. *
  8201. * Return codes
  8202. * 0 - successful
  8203. * other values - error
  8204. **/
  8205. static int
  8206. lpfc_create_shost(struct lpfc_hba *phba)
  8207. {
  8208. struct lpfc_vport *vport;
  8209. struct Scsi_Host *shost;
  8210. /* Initialize HBA FC structure */
  8211. phba->fc_edtov = FF_DEF_EDTOV;
  8212. phba->fc_ratov = FF_DEF_RATOV;
  8213. phba->fc_altov = FF_DEF_ALTOV;
  8214. phba->fc_arbtov = FF_DEF_ARBTOV;
  8215. atomic_set(&phba->sdev_cnt, 0);
  8216. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  8217. if (!vport)
  8218. return -ENODEV;
  8219. shost = lpfc_shost_from_vport(vport);
  8220. phba->pport = vport;
  8221. if (phba->nvmet_support) {
  8222. /* Only 1 vport (pport) will support NVME target */
  8223. phba->targetport = NULL;
  8224. phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
  8225. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC,
  8226. "6076 NVME Target Found\n");
  8227. }
  8228. lpfc_debugfs_initialize(vport);
  8229. /* Put reference to SCSI host to driver's device private data */
  8230. pci_set_drvdata(phba->pcidev, shost);
  8231. lpfc_setup_fdmi_mask(vport);
  8232. /*
  8233. * At this point we are fully registered with PSA. In addition,
  8234. * any initial discovery should be completed.
  8235. */
  8236. return 0;
  8237. }
  8238. /**
  8239. * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
  8240. * @phba: pointer to lpfc hba data structure.
  8241. *
  8242. * This routine is invoked to destroy HBA physical port and the associated
  8243. * SCSI host.
  8244. **/
  8245. static void
  8246. lpfc_destroy_shost(struct lpfc_hba *phba)
  8247. {
  8248. struct lpfc_vport *vport = phba->pport;
  8249. /* Destroy physical port that associated with the SCSI host */
  8250. destroy_port(vport);
  8251. return;
  8252. }
  8253. /**
  8254. * lpfc_setup_bg - Setup Block guard structures and debug areas.
  8255. * @phba: pointer to lpfc hba data structure.
  8256. * @shost: the shost to be used to detect Block guard settings.
  8257. *
  8258. * This routine sets up the local Block guard protocol settings for @shost.
  8259. * This routine also allocates memory for debugging bg buffers.
  8260. **/
  8261. static void
  8262. lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
  8263. {
  8264. uint32_t old_mask;
  8265. uint32_t old_guard;
  8266. if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
  8267. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8268. "1478 Registering BlockGuard with the "
  8269. "SCSI layer\n");
  8270. old_mask = phba->cfg_prot_mask;
  8271. old_guard = phba->cfg_prot_guard;
  8272. /* Only allow supported values */
  8273. phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
  8274. SHOST_DIX_TYPE0_PROTECTION |
  8275. SHOST_DIX_TYPE1_PROTECTION);
  8276. phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
  8277. SHOST_DIX_GUARD_CRC);
  8278. /* DIF Type 1 protection for profiles AST1/C1 is end to end */
  8279. if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
  8280. phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
  8281. if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
  8282. if ((old_mask != phba->cfg_prot_mask) ||
  8283. (old_guard != phba->cfg_prot_guard))
  8284. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8285. "1475 Registering BlockGuard with the "
  8286. "SCSI layer: mask %d guard %d\n",
  8287. phba->cfg_prot_mask,
  8288. phba->cfg_prot_guard);
  8289. scsi_host_set_prot(shost, phba->cfg_prot_mask);
  8290. scsi_host_set_guard(shost, phba->cfg_prot_guard);
  8291. } else
  8292. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8293. "1479 Not Registering BlockGuard with the SCSI "
  8294. "layer, Bad protection parameters: %d %d\n",
  8295. old_mask, old_guard);
  8296. }
  8297. }
  8298. /**
  8299. * lpfc_post_init_setup - Perform necessary device post initialization setup.
  8300. * @phba: pointer to lpfc hba data structure.
  8301. *
  8302. * This routine is invoked to perform all the necessary post initialization
  8303. * setup for the device.
  8304. **/
  8305. static void
  8306. lpfc_post_init_setup(struct lpfc_hba *phba)
  8307. {
  8308. struct Scsi_Host *shost;
  8309. struct lpfc_adapter_event_header adapter_event;
  8310. /* Get the default values for Model Name and Description */
  8311. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  8312. /*
  8313. * hba setup may have changed the hba_queue_depth so we need to
  8314. * adjust the value of can_queue.
  8315. */
  8316. shost = pci_get_drvdata(phba->pcidev);
  8317. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  8318. lpfc_host_attrib_init(shost);
  8319. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  8320. spin_lock_irq(shost->host_lock);
  8321. lpfc_poll_start_timer(phba);
  8322. spin_unlock_irq(shost->host_lock);
  8323. }
  8324. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8325. "0428 Perform SCSI scan\n");
  8326. /* Send board arrival event to upper layer */
  8327. adapter_event.event_type = FC_REG_ADAPTER_EVENT;
  8328. adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
  8329. fc_host_post_vendor_event(shost, fc_get_event_number(),
  8330. sizeof(adapter_event),
  8331. (char *) &adapter_event,
  8332. LPFC_NL_VENDOR_ID);
  8333. return;
  8334. }
  8335. /**
  8336. * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
  8337. * @phba: pointer to lpfc hba data structure.
  8338. *
  8339. * This routine is invoked to set up the PCI device memory space for device
  8340. * with SLI-3 interface spec.
  8341. *
  8342. * Return codes
  8343. * 0 - successful
  8344. * other values - error
  8345. **/
  8346. static int
  8347. lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
  8348. {
  8349. struct pci_dev *pdev = phba->pcidev;
  8350. unsigned long bar0map_len, bar2map_len;
  8351. int i, hbq_count;
  8352. void *ptr;
  8353. int error;
  8354. if (!pdev)
  8355. return -ENODEV;
  8356. /* Set the device DMA mask size */
  8357. error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  8358. if (error)
  8359. error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  8360. if (error)
  8361. return error;
  8362. error = -ENODEV;
  8363. /* Get the bus address of Bar0 and Bar2 and the number of bytes
  8364. * required by each mapping.
  8365. */
  8366. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  8367. bar0map_len = pci_resource_len(pdev, 0);
  8368. phba->pci_bar2_map = pci_resource_start(pdev, 2);
  8369. bar2map_len = pci_resource_len(pdev, 2);
  8370. /* Map HBA SLIM to a kernel virtual address. */
  8371. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  8372. if (!phba->slim_memmap_p) {
  8373. dev_printk(KERN_ERR, &pdev->dev,
  8374. "ioremap failed for SLIM memory.\n");
  8375. goto out;
  8376. }
  8377. /* Map HBA Control Registers to a kernel virtual address. */
  8378. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  8379. if (!phba->ctrl_regs_memmap_p) {
  8380. dev_printk(KERN_ERR, &pdev->dev,
  8381. "ioremap failed for HBA control registers.\n");
  8382. goto out_iounmap_slim;
  8383. }
  8384. /* Allocate memory for SLI-2 structures */
  8385. phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  8386. &phba->slim2p.phys, GFP_KERNEL);
  8387. if (!phba->slim2p.virt)
  8388. goto out_iounmap;
  8389. phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
  8390. phba->mbox_ext = (phba->slim2p.virt +
  8391. offsetof(struct lpfc_sli2_slim, mbx_ext_words));
  8392. phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
  8393. phba->IOCBs = (phba->slim2p.virt +
  8394. offsetof(struct lpfc_sli2_slim, IOCBs));
  8395. phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
  8396. lpfc_sli_hbq_size(),
  8397. &phba->hbqslimp.phys,
  8398. GFP_KERNEL);
  8399. if (!phba->hbqslimp.virt)
  8400. goto out_free_slim;
  8401. hbq_count = lpfc_sli_hbq_count();
  8402. ptr = phba->hbqslimp.virt;
  8403. for (i = 0; i < hbq_count; ++i) {
  8404. phba->hbqs[i].hbq_virt = ptr;
  8405. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  8406. ptr += (lpfc_hbq_defs[i]->entry_count *
  8407. sizeof(struct lpfc_hbq_entry));
  8408. }
  8409. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  8410. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  8411. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  8412. phba->MBslimaddr = phba->slim_memmap_p;
  8413. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  8414. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  8415. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  8416. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  8417. return 0;
  8418. out_free_slim:
  8419. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  8420. phba->slim2p.virt, phba->slim2p.phys);
  8421. out_iounmap:
  8422. iounmap(phba->ctrl_regs_memmap_p);
  8423. out_iounmap_slim:
  8424. iounmap(phba->slim_memmap_p);
  8425. out:
  8426. return error;
  8427. }
  8428. /**
  8429. * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
  8430. * @phba: pointer to lpfc hba data structure.
  8431. *
  8432. * This routine is invoked to unset the PCI device memory space for device
  8433. * with SLI-3 interface spec.
  8434. **/
  8435. static void
  8436. lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
  8437. {
  8438. struct pci_dev *pdev;
  8439. /* Obtain PCI device reference */
  8440. if (!phba->pcidev)
  8441. return;
  8442. else
  8443. pdev = phba->pcidev;
  8444. /* Free coherent DMA memory allocated */
  8445. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  8446. phba->hbqslimp.virt, phba->hbqslimp.phys);
  8447. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  8448. phba->slim2p.virt, phba->slim2p.phys);
  8449. /* I/O memory unmap */
  8450. iounmap(phba->ctrl_regs_memmap_p);
  8451. iounmap(phba->slim_memmap_p);
  8452. return;
  8453. }
  8454. /**
  8455. * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
  8456. * @phba: pointer to lpfc hba data structure.
  8457. *
  8458. * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
  8459. * done and check status.
  8460. *
  8461. * Return 0 if successful, otherwise -ENODEV.
  8462. **/
  8463. int
  8464. lpfc_sli4_post_status_check(struct lpfc_hba *phba)
  8465. {
  8466. struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
  8467. struct lpfc_register reg_data;
  8468. int i, port_error = 0;
  8469. uint32_t if_type;
  8470. memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
  8471. memset(&reg_data, 0, sizeof(reg_data));
  8472. if (!phba->sli4_hba.PSMPHRregaddr)
  8473. return -ENODEV;
  8474. /* Wait up to 30 seconds for the SLI Port POST done and ready */
  8475. for (i = 0; i < 3000; i++) {
  8476. if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  8477. &portsmphr_reg.word0) ||
  8478. (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
  8479. /* Port has a fatal POST error, break out */
  8480. port_error = -ENODEV;
  8481. break;
  8482. }
  8483. if (LPFC_POST_STAGE_PORT_READY ==
  8484. bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
  8485. break;
  8486. msleep(10);
  8487. }
  8488. /*
  8489. * If there was a port error during POST, then don't proceed with
  8490. * other register reads as the data may not be valid. Just exit.
  8491. */
  8492. if (port_error) {
  8493. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8494. "1408 Port Failed POST - portsmphr=0x%x, "
  8495. "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
  8496. "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
  8497. portsmphr_reg.word0,
  8498. bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
  8499. bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
  8500. bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
  8501. bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
  8502. bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
  8503. bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
  8504. bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
  8505. bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
  8506. } else {
  8507. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8508. "2534 Device Info: SLIFamily=0x%x, "
  8509. "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
  8510. "SLIHint_2=0x%x, FT=0x%x\n",
  8511. bf_get(lpfc_sli_intf_sli_family,
  8512. &phba->sli4_hba.sli_intf),
  8513. bf_get(lpfc_sli_intf_slirev,
  8514. &phba->sli4_hba.sli_intf),
  8515. bf_get(lpfc_sli_intf_if_type,
  8516. &phba->sli4_hba.sli_intf),
  8517. bf_get(lpfc_sli_intf_sli_hint1,
  8518. &phba->sli4_hba.sli_intf),
  8519. bf_get(lpfc_sli_intf_sli_hint2,
  8520. &phba->sli4_hba.sli_intf),
  8521. bf_get(lpfc_sli_intf_func_type,
  8522. &phba->sli4_hba.sli_intf));
  8523. /*
  8524. * Check for other Port errors during the initialization
  8525. * process. Fail the load if the port did not come up
  8526. * correctly.
  8527. */
  8528. if_type = bf_get(lpfc_sli_intf_if_type,
  8529. &phba->sli4_hba.sli_intf);
  8530. switch (if_type) {
  8531. case LPFC_SLI_INTF_IF_TYPE_0:
  8532. phba->sli4_hba.ue_mask_lo =
  8533. readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
  8534. phba->sli4_hba.ue_mask_hi =
  8535. readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
  8536. uerrlo_reg.word0 =
  8537. readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
  8538. uerrhi_reg.word0 =
  8539. readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
  8540. if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
  8541. (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
  8542. lpfc_printf_log(phba, KERN_ERR,
  8543. LOG_TRACE_EVENT,
  8544. "1422 Unrecoverable Error "
  8545. "Detected during POST "
  8546. "uerr_lo_reg=0x%x, "
  8547. "uerr_hi_reg=0x%x, "
  8548. "ue_mask_lo_reg=0x%x, "
  8549. "ue_mask_hi_reg=0x%x\n",
  8550. uerrlo_reg.word0,
  8551. uerrhi_reg.word0,
  8552. phba->sli4_hba.ue_mask_lo,
  8553. phba->sli4_hba.ue_mask_hi);
  8554. port_error = -ENODEV;
  8555. }
  8556. break;
  8557. case LPFC_SLI_INTF_IF_TYPE_2:
  8558. case LPFC_SLI_INTF_IF_TYPE_6:
  8559. /* Final checks. The port status should be clean. */
  8560. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  8561. &reg_data.word0) ||
  8562. (bf_get(lpfc_sliport_status_err, &reg_data) &&
  8563. !bf_get(lpfc_sliport_status_rn, &reg_data))) {
  8564. phba->work_status[0] =
  8565. readl(phba->sli4_hba.u.if_type2.
  8566. ERR1regaddr);
  8567. phba->work_status[1] =
  8568. readl(phba->sli4_hba.u.if_type2.
  8569. ERR2regaddr);
  8570. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8571. "2888 Unrecoverable port error "
  8572. "following POST: port status reg "
  8573. "0x%x, port_smphr reg 0x%x, "
  8574. "error 1=0x%x, error 2=0x%x\n",
  8575. reg_data.word0,
  8576. portsmphr_reg.word0,
  8577. phba->work_status[0],
  8578. phba->work_status[1]);
  8579. port_error = -ENODEV;
  8580. break;
  8581. }
  8582. if (lpfc_pldv_detect &&
  8583. bf_get(lpfc_sli_intf_sli_family,
  8584. &phba->sli4_hba.sli_intf) ==
  8585. LPFC_SLI_INTF_FAMILY_G6)
  8586. pci_write_config_byte(phba->pcidev,
  8587. LPFC_SLI_INTF, CFG_PLD);
  8588. break;
  8589. case LPFC_SLI_INTF_IF_TYPE_1:
  8590. default:
  8591. break;
  8592. }
  8593. }
  8594. return port_error;
  8595. }
  8596. /**
  8597. * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
  8598. * @phba: pointer to lpfc hba data structure.
  8599. * @if_type: The SLI4 interface type getting configured.
  8600. *
  8601. * This routine is invoked to set up SLI4 BAR0 PCI config space register
  8602. * memory map.
  8603. **/
  8604. static void
  8605. lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
  8606. {
  8607. switch (if_type) {
  8608. case LPFC_SLI_INTF_IF_TYPE_0:
  8609. phba->sli4_hba.u.if_type0.UERRLOregaddr =
  8610. phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
  8611. phba->sli4_hba.u.if_type0.UERRHIregaddr =
  8612. phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
  8613. phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
  8614. phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
  8615. phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
  8616. phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
  8617. phba->sli4_hba.SLIINTFregaddr =
  8618. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
  8619. break;
  8620. case LPFC_SLI_INTF_IF_TYPE_2:
  8621. phba->sli4_hba.u.if_type2.EQDregaddr =
  8622. phba->sli4_hba.conf_regs_memmap_p +
  8623. LPFC_CTL_PORT_EQ_DELAY_OFFSET;
  8624. phba->sli4_hba.u.if_type2.ERR1regaddr =
  8625. phba->sli4_hba.conf_regs_memmap_p +
  8626. LPFC_CTL_PORT_ER1_OFFSET;
  8627. phba->sli4_hba.u.if_type2.ERR2regaddr =
  8628. phba->sli4_hba.conf_regs_memmap_p +
  8629. LPFC_CTL_PORT_ER2_OFFSET;
  8630. phba->sli4_hba.u.if_type2.CTRLregaddr =
  8631. phba->sli4_hba.conf_regs_memmap_p +
  8632. LPFC_CTL_PORT_CTL_OFFSET;
  8633. phba->sli4_hba.u.if_type2.STATUSregaddr =
  8634. phba->sli4_hba.conf_regs_memmap_p +
  8635. LPFC_CTL_PORT_STA_OFFSET;
  8636. phba->sli4_hba.SLIINTFregaddr =
  8637. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
  8638. phba->sli4_hba.PSMPHRregaddr =
  8639. phba->sli4_hba.conf_regs_memmap_p +
  8640. LPFC_CTL_PORT_SEM_OFFSET;
  8641. phba->sli4_hba.RQDBregaddr =
  8642. phba->sli4_hba.conf_regs_memmap_p +
  8643. LPFC_ULP0_RQ_DOORBELL;
  8644. phba->sli4_hba.WQDBregaddr =
  8645. phba->sli4_hba.conf_regs_memmap_p +
  8646. LPFC_ULP0_WQ_DOORBELL;
  8647. phba->sli4_hba.CQDBregaddr =
  8648. phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
  8649. phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
  8650. phba->sli4_hba.MQDBregaddr =
  8651. phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
  8652. phba->sli4_hba.BMBXregaddr =
  8653. phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
  8654. break;
  8655. case LPFC_SLI_INTF_IF_TYPE_6:
  8656. phba->sli4_hba.u.if_type2.EQDregaddr =
  8657. phba->sli4_hba.conf_regs_memmap_p +
  8658. LPFC_CTL_PORT_EQ_DELAY_OFFSET;
  8659. phba->sli4_hba.u.if_type2.ERR1regaddr =
  8660. phba->sli4_hba.conf_regs_memmap_p +
  8661. LPFC_CTL_PORT_ER1_OFFSET;
  8662. phba->sli4_hba.u.if_type2.ERR2regaddr =
  8663. phba->sli4_hba.conf_regs_memmap_p +
  8664. LPFC_CTL_PORT_ER2_OFFSET;
  8665. phba->sli4_hba.u.if_type2.CTRLregaddr =
  8666. phba->sli4_hba.conf_regs_memmap_p +
  8667. LPFC_CTL_PORT_CTL_OFFSET;
  8668. phba->sli4_hba.u.if_type2.STATUSregaddr =
  8669. phba->sli4_hba.conf_regs_memmap_p +
  8670. LPFC_CTL_PORT_STA_OFFSET;
  8671. phba->sli4_hba.PSMPHRregaddr =
  8672. phba->sli4_hba.conf_regs_memmap_p +
  8673. LPFC_CTL_PORT_SEM_OFFSET;
  8674. phba->sli4_hba.BMBXregaddr =
  8675. phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
  8676. break;
  8677. case LPFC_SLI_INTF_IF_TYPE_1:
  8678. default:
  8679. dev_printk(KERN_ERR, &phba->pcidev->dev,
  8680. "FATAL - unsupported SLI4 interface type - %d\n",
  8681. if_type);
  8682. break;
  8683. }
  8684. }
  8685. /**
  8686. * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
  8687. * @phba: pointer to lpfc hba data structure.
  8688. * @if_type: sli if type to operate on.
  8689. *
  8690. * This routine is invoked to set up SLI4 BAR1 register memory map.
  8691. **/
  8692. static void
  8693. lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
  8694. {
  8695. switch (if_type) {
  8696. case LPFC_SLI_INTF_IF_TYPE_0:
  8697. phba->sli4_hba.PSMPHRregaddr =
  8698. phba->sli4_hba.ctrl_regs_memmap_p +
  8699. LPFC_SLIPORT_IF0_SMPHR;
  8700. phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  8701. LPFC_HST_ISR0;
  8702. phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  8703. LPFC_HST_IMR0;
  8704. phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  8705. LPFC_HST_ISCR0;
  8706. break;
  8707. case LPFC_SLI_INTF_IF_TYPE_6:
  8708. phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
  8709. LPFC_IF6_RQ_DOORBELL;
  8710. phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
  8711. LPFC_IF6_WQ_DOORBELL;
  8712. phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
  8713. LPFC_IF6_CQ_DOORBELL;
  8714. phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
  8715. LPFC_IF6_EQ_DOORBELL;
  8716. phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
  8717. LPFC_IF6_MQ_DOORBELL;
  8718. break;
  8719. case LPFC_SLI_INTF_IF_TYPE_2:
  8720. case LPFC_SLI_INTF_IF_TYPE_1:
  8721. default:
  8722. dev_err(&phba->pcidev->dev,
  8723. "FATAL - unsupported SLI4 interface type - %d\n",
  8724. if_type);
  8725. break;
  8726. }
  8727. }
  8728. /**
  8729. * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
  8730. * @phba: pointer to lpfc hba data structure.
  8731. * @vf: virtual function number
  8732. *
  8733. * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
  8734. * based on the given viftual function number, @vf.
  8735. *
  8736. * Return 0 if successful, otherwise -ENODEV.
  8737. **/
  8738. static int
  8739. lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
  8740. {
  8741. if (vf > LPFC_VIR_FUNC_MAX)
  8742. return -ENODEV;
  8743. phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  8744. vf * LPFC_VFR_PAGE_SIZE +
  8745. LPFC_ULP0_RQ_DOORBELL);
  8746. phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  8747. vf * LPFC_VFR_PAGE_SIZE +
  8748. LPFC_ULP0_WQ_DOORBELL);
  8749. phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  8750. vf * LPFC_VFR_PAGE_SIZE +
  8751. LPFC_EQCQ_DOORBELL);
  8752. phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
  8753. phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  8754. vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
  8755. phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  8756. vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
  8757. return 0;
  8758. }
  8759. /**
  8760. * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
  8761. * @phba: pointer to lpfc hba data structure.
  8762. *
  8763. * This routine is invoked to create the bootstrap mailbox
  8764. * region consistent with the SLI-4 interface spec. This
  8765. * routine allocates all memory necessary to communicate
  8766. * mailbox commands to the port and sets up all alignment
  8767. * needs. No locks are expected to be held when calling
  8768. * this routine.
  8769. *
  8770. * Return codes
  8771. * 0 - successful
  8772. * -ENOMEM - could not allocated memory.
  8773. **/
  8774. static int
  8775. lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
  8776. {
  8777. uint32_t bmbx_size;
  8778. struct lpfc_dmabuf *dmabuf;
  8779. struct dma_address *dma_address;
  8780. uint32_t pa_addr;
  8781. uint64_t phys_addr;
  8782. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8783. if (!dmabuf)
  8784. return -ENOMEM;
  8785. /*
  8786. * The bootstrap mailbox region is comprised of 2 parts
  8787. * plus an alignment restriction of 16 bytes.
  8788. */
  8789. bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
  8790. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size,
  8791. &dmabuf->phys, GFP_KERNEL);
  8792. if (!dmabuf->virt) {
  8793. kfree(dmabuf);
  8794. return -ENOMEM;
  8795. }
  8796. /*
  8797. * Initialize the bootstrap mailbox pointers now so that the register
  8798. * operations are simple later. The mailbox dma address is required
  8799. * to be 16-byte aligned. Also align the virtual memory as each
  8800. * maibox is copied into the bmbx mailbox region before issuing the
  8801. * command to the port.
  8802. */
  8803. phba->sli4_hba.bmbx.dmabuf = dmabuf;
  8804. phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
  8805. phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
  8806. LPFC_ALIGN_16_BYTE);
  8807. phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
  8808. LPFC_ALIGN_16_BYTE);
  8809. /*
  8810. * Set the high and low physical addresses now. The SLI4 alignment
  8811. * requirement is 16 bytes and the mailbox is posted to the port
  8812. * as two 30-bit addresses. The other data is a bit marking whether
  8813. * the 30-bit address is the high or low address.
  8814. * Upcast bmbx aphys to 64bits so shift instruction compiles
  8815. * clean on 32 bit machines.
  8816. */
  8817. dma_address = &phba->sli4_hba.bmbx.dma_address;
  8818. phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
  8819. pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
  8820. dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
  8821. LPFC_BMBX_BIT1_ADDR_HI);
  8822. pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
  8823. dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
  8824. LPFC_BMBX_BIT1_ADDR_LO);
  8825. return 0;
  8826. }
  8827. /**
  8828. * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
  8829. * @phba: pointer to lpfc hba data structure.
  8830. *
  8831. * This routine is invoked to teardown the bootstrap mailbox
  8832. * region and release all host resources. This routine requires
  8833. * the caller to ensure all mailbox commands recovered, no
  8834. * additional mailbox comands are sent, and interrupts are disabled
  8835. * before calling this routine.
  8836. *
  8837. **/
  8838. static void
  8839. lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
  8840. {
  8841. dma_free_coherent(&phba->pcidev->dev,
  8842. phba->sli4_hba.bmbx.bmbx_size,
  8843. phba->sli4_hba.bmbx.dmabuf->virt,
  8844. phba->sli4_hba.bmbx.dmabuf->phys);
  8845. kfree(phba->sli4_hba.bmbx.dmabuf);
  8846. memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
  8847. }
  8848. static const char * const lpfc_topo_to_str[] = {
  8849. "Loop then P2P",
  8850. "Loopback",
  8851. "P2P Only",
  8852. "Unsupported",
  8853. "Loop Only",
  8854. "Unsupported",
  8855. "P2P then Loop",
  8856. };
  8857. #define LINK_FLAGS_DEF 0x0
  8858. #define LINK_FLAGS_P2P 0x1
  8859. #define LINK_FLAGS_LOOP 0x2
  8860. /**
  8861. * lpfc_map_topology - Map the topology read from READ_CONFIG
  8862. * @phba: pointer to lpfc hba data structure.
  8863. * @rd_config: pointer to read config data
  8864. *
  8865. * This routine is invoked to map the topology values as read
  8866. * from the read config mailbox command. If the persistent
  8867. * topology feature is supported, the firmware will provide the
  8868. * saved topology information to be used in INIT_LINK
  8869. **/
  8870. static void
  8871. lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config)
  8872. {
  8873. u8 ptv, tf, pt;
  8874. ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config);
  8875. tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config);
  8876. pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config);
  8877. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8878. "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x",
  8879. ptv, tf, pt);
  8880. if (!ptv) {
  8881. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8882. "2019 FW does not support persistent topology "
  8883. "Using driver parameter defined value [%s]",
  8884. lpfc_topo_to_str[phba->cfg_topology]);
  8885. return;
  8886. }
  8887. /* FW supports persistent topology - override module parameter value */
  8888. phba->hba_flag |= HBA_PERSISTENT_TOPO;
  8889. /* if ASIC_GEN_NUM >= 0xC) */
  8890. if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  8891. LPFC_SLI_INTF_IF_TYPE_6) ||
  8892. (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
  8893. LPFC_SLI_INTF_FAMILY_G6)) {
  8894. if (!tf) {
  8895. phba->cfg_topology = ((pt == LINK_FLAGS_LOOP)
  8896. ? FLAGS_TOPOLOGY_MODE_LOOP
  8897. : FLAGS_TOPOLOGY_MODE_PT_PT);
  8898. } else {
  8899. phba->hba_flag &= ~HBA_PERSISTENT_TOPO;
  8900. }
  8901. } else { /* G5 */
  8902. if (tf) {
  8903. /* If topology failover set - pt is '0' or '1' */
  8904. phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP :
  8905. FLAGS_TOPOLOGY_MODE_LOOP_PT);
  8906. } else {
  8907. phba->cfg_topology = ((pt == LINK_FLAGS_P2P)
  8908. ? FLAGS_TOPOLOGY_MODE_PT_PT
  8909. : FLAGS_TOPOLOGY_MODE_LOOP);
  8910. }
  8911. }
  8912. if (phba->hba_flag & HBA_PERSISTENT_TOPO) {
  8913. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8914. "2020 Using persistent topology value [%s]",
  8915. lpfc_topo_to_str[phba->cfg_topology]);
  8916. } else {
  8917. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8918. "2021 Invalid topology values from FW "
  8919. "Using driver parameter defined value [%s]",
  8920. lpfc_topo_to_str[phba->cfg_topology]);
  8921. }
  8922. }
  8923. /**
  8924. * lpfc_sli4_read_config - Get the config parameters.
  8925. * @phba: pointer to lpfc hba data structure.
  8926. *
  8927. * This routine is invoked to read the configuration parameters from the HBA.
  8928. * The configuration parameters are used to set the base and maximum values
  8929. * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
  8930. * allocation for the port.
  8931. *
  8932. * Return codes
  8933. * 0 - successful
  8934. * -ENOMEM - No available memory
  8935. * -EIO - The mailbox failed to complete successfully.
  8936. **/
  8937. int
  8938. lpfc_sli4_read_config(struct lpfc_hba *phba)
  8939. {
  8940. LPFC_MBOXQ_t *pmb;
  8941. struct lpfc_mbx_read_config *rd_config;
  8942. union lpfc_sli4_cfg_shdr *shdr;
  8943. uint32_t shdr_status, shdr_add_status;
  8944. struct lpfc_mbx_get_func_cfg *get_func_cfg;
  8945. struct lpfc_rsrc_desc_fcfcoe *desc;
  8946. char *pdesc_0;
  8947. uint16_t forced_link_speed;
  8948. uint32_t if_type, qmin, fawwpn;
  8949. int length, i, rc = 0, rc2;
  8950. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8951. if (!pmb) {
  8952. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8953. "2011 Unable to allocate memory for issuing "
  8954. "SLI_CONFIG_SPECIAL mailbox command\n");
  8955. return -ENOMEM;
  8956. }
  8957. lpfc_read_config(phba, pmb);
  8958. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  8959. if (rc != MBX_SUCCESS) {
  8960. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8961. "2012 Mailbox failed , mbxCmd x%x "
  8962. "READ_CONFIG, mbxStatus x%x\n",
  8963. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  8964. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  8965. rc = -EIO;
  8966. } else {
  8967. rd_config = &pmb->u.mqe.un.rd_config;
  8968. if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
  8969. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  8970. phba->sli4_hba.lnk_info.lnk_tp =
  8971. bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
  8972. phba->sli4_hba.lnk_info.lnk_no =
  8973. bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
  8974. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8975. "3081 lnk_type:%d, lnk_numb:%d\n",
  8976. phba->sli4_hba.lnk_info.lnk_tp,
  8977. phba->sli4_hba.lnk_info.lnk_no);
  8978. } else
  8979. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8980. "3082 Mailbox (x%x) returned ldv:x0\n",
  8981. bf_get(lpfc_mqe_command, &pmb->u.mqe));
  8982. if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
  8983. phba->bbcredit_support = 1;
  8984. phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
  8985. }
  8986. fawwpn = bf_get(lpfc_mbx_rd_conf_fawwpn, rd_config);
  8987. if (fawwpn) {
  8988. lpfc_printf_log(phba, KERN_INFO,
  8989. LOG_INIT | LOG_DISCOVERY,
  8990. "2702 READ_CONFIG: FA-PWWN is "
  8991. "configured on\n");
  8992. phba->sli4_hba.fawwpn_flag |= LPFC_FAWWPN_CONFIG;
  8993. } else {
  8994. /* Clear FW configured flag, preserve driver flag */
  8995. phba->sli4_hba.fawwpn_flag &= ~LPFC_FAWWPN_CONFIG;
  8996. }
  8997. phba->sli4_hba.conf_trunk =
  8998. bf_get(lpfc_mbx_rd_conf_trunk, rd_config);
  8999. phba->sli4_hba.extents_in_use =
  9000. bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
  9001. phba->sli4_hba.max_cfg_param.max_xri =
  9002. bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
  9003. /* Reduce resource usage in kdump environment */
  9004. if (is_kdump_kernel() &&
  9005. phba->sli4_hba.max_cfg_param.max_xri > 512)
  9006. phba->sli4_hba.max_cfg_param.max_xri = 512;
  9007. phba->sli4_hba.max_cfg_param.xri_base =
  9008. bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
  9009. phba->sli4_hba.max_cfg_param.max_vpi =
  9010. bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
  9011. /* Limit the max we support */
  9012. if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
  9013. phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
  9014. phba->sli4_hba.max_cfg_param.vpi_base =
  9015. bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
  9016. phba->sli4_hba.max_cfg_param.max_rpi =
  9017. bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
  9018. phba->sli4_hba.max_cfg_param.rpi_base =
  9019. bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
  9020. phba->sli4_hba.max_cfg_param.max_vfi =
  9021. bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
  9022. phba->sli4_hba.max_cfg_param.vfi_base =
  9023. bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
  9024. phba->sli4_hba.max_cfg_param.max_fcfi =
  9025. bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
  9026. phba->sli4_hba.max_cfg_param.max_eq =
  9027. bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
  9028. phba->sli4_hba.max_cfg_param.max_rq =
  9029. bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
  9030. phba->sli4_hba.max_cfg_param.max_wq =
  9031. bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
  9032. phba->sli4_hba.max_cfg_param.max_cq =
  9033. bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
  9034. phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
  9035. phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
  9036. phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
  9037. phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
  9038. phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
  9039. (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
  9040. phba->max_vports = phba->max_vpi;
  9041. /* Next decide on FPIN or Signal E2E CGN support
  9042. * For congestion alarms and warnings valid combination are:
  9043. * 1. FPIN alarms / FPIN warnings
  9044. * 2. Signal alarms / Signal warnings
  9045. * 3. FPIN alarms / Signal warnings
  9046. * 4. Signal alarms / FPIN warnings
  9047. *
  9048. * Initialize the adapter frequency to 100 mSecs
  9049. */
  9050. phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
  9051. phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
  9052. phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
  9053. if (lpfc_use_cgn_signal) {
  9054. if (bf_get(lpfc_mbx_rd_conf_wcs, rd_config)) {
  9055. phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
  9056. phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
  9057. }
  9058. if (bf_get(lpfc_mbx_rd_conf_acs, rd_config)) {
  9059. /* MUST support both alarm and warning
  9060. * because EDC does not support alarm alone.
  9061. */
  9062. if (phba->cgn_reg_signal !=
  9063. EDC_CG_SIG_WARN_ONLY) {
  9064. /* Must support both or none */
  9065. phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH;
  9066. phba->cgn_reg_signal =
  9067. EDC_CG_SIG_NOTSUPPORTED;
  9068. } else {
  9069. phba->cgn_reg_signal =
  9070. EDC_CG_SIG_WARN_ALARM;
  9071. phba->cgn_reg_fpin =
  9072. LPFC_CGN_FPIN_NONE;
  9073. }
  9074. }
  9075. }
  9076. /* Set the congestion initial signal and fpin values. */
  9077. phba->cgn_init_reg_fpin = phba->cgn_reg_fpin;
  9078. phba->cgn_init_reg_signal = phba->cgn_reg_signal;
  9079. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  9080. "6446 READ_CONFIG reg_sig x%x reg_fpin:x%x\n",
  9081. phba->cgn_reg_signal, phba->cgn_reg_fpin);
  9082. lpfc_map_topology(phba, rd_config);
  9083. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9084. "2003 cfg params Extents? %d "
  9085. "XRI(B:%d M:%d), "
  9086. "VPI(B:%d M:%d) "
  9087. "VFI(B:%d M:%d) "
  9088. "RPI(B:%d M:%d) "
  9089. "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d lmt:x%x\n",
  9090. phba->sli4_hba.extents_in_use,
  9091. phba->sli4_hba.max_cfg_param.xri_base,
  9092. phba->sli4_hba.max_cfg_param.max_xri,
  9093. phba->sli4_hba.max_cfg_param.vpi_base,
  9094. phba->sli4_hba.max_cfg_param.max_vpi,
  9095. phba->sli4_hba.max_cfg_param.vfi_base,
  9096. phba->sli4_hba.max_cfg_param.max_vfi,
  9097. phba->sli4_hba.max_cfg_param.rpi_base,
  9098. phba->sli4_hba.max_cfg_param.max_rpi,
  9099. phba->sli4_hba.max_cfg_param.max_fcfi,
  9100. phba->sli4_hba.max_cfg_param.max_eq,
  9101. phba->sli4_hba.max_cfg_param.max_cq,
  9102. phba->sli4_hba.max_cfg_param.max_wq,
  9103. phba->sli4_hba.max_cfg_param.max_rq,
  9104. phba->lmt);
  9105. /*
  9106. * Calculate queue resources based on how
  9107. * many WQ/CQ/EQs are available.
  9108. */
  9109. qmin = phba->sli4_hba.max_cfg_param.max_wq;
  9110. if (phba->sli4_hba.max_cfg_param.max_cq < qmin)
  9111. qmin = phba->sli4_hba.max_cfg_param.max_cq;
  9112. if (phba->sli4_hba.max_cfg_param.max_eq < qmin)
  9113. qmin = phba->sli4_hba.max_cfg_param.max_eq;
  9114. /*
  9115. * Whats left after this can go toward NVME / FCP.
  9116. * The minus 4 accounts for ELS, NVME LS, MBOX
  9117. * plus one extra. When configured for
  9118. * NVMET, FCP io channel WQs are not created.
  9119. */
  9120. qmin -= 4;
  9121. /* Check to see if there is enough for NVME */
  9122. if ((phba->cfg_irq_chann > qmin) ||
  9123. (phba->cfg_hdw_queue > qmin)) {
  9124. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9125. "2005 Reducing Queues - "
  9126. "FW resource limitation: "
  9127. "WQ %d CQ %d EQ %d: min %d: "
  9128. "IRQ %d HDWQ %d\n",
  9129. phba->sli4_hba.max_cfg_param.max_wq,
  9130. phba->sli4_hba.max_cfg_param.max_cq,
  9131. phba->sli4_hba.max_cfg_param.max_eq,
  9132. qmin, phba->cfg_irq_chann,
  9133. phba->cfg_hdw_queue);
  9134. if (phba->cfg_irq_chann > qmin)
  9135. phba->cfg_irq_chann = qmin;
  9136. if (phba->cfg_hdw_queue > qmin)
  9137. phba->cfg_hdw_queue = qmin;
  9138. }
  9139. }
  9140. if (rc)
  9141. goto read_cfg_out;
  9142. /* Update link speed if forced link speed is supported */
  9143. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  9144. if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
  9145. forced_link_speed =
  9146. bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
  9147. if (forced_link_speed) {
  9148. phba->hba_flag |= HBA_FORCED_LINK_SPEED;
  9149. switch (forced_link_speed) {
  9150. case LINK_SPEED_1G:
  9151. phba->cfg_link_speed =
  9152. LPFC_USER_LINK_SPEED_1G;
  9153. break;
  9154. case LINK_SPEED_2G:
  9155. phba->cfg_link_speed =
  9156. LPFC_USER_LINK_SPEED_2G;
  9157. break;
  9158. case LINK_SPEED_4G:
  9159. phba->cfg_link_speed =
  9160. LPFC_USER_LINK_SPEED_4G;
  9161. break;
  9162. case LINK_SPEED_8G:
  9163. phba->cfg_link_speed =
  9164. LPFC_USER_LINK_SPEED_8G;
  9165. break;
  9166. case LINK_SPEED_10G:
  9167. phba->cfg_link_speed =
  9168. LPFC_USER_LINK_SPEED_10G;
  9169. break;
  9170. case LINK_SPEED_16G:
  9171. phba->cfg_link_speed =
  9172. LPFC_USER_LINK_SPEED_16G;
  9173. break;
  9174. case LINK_SPEED_32G:
  9175. phba->cfg_link_speed =
  9176. LPFC_USER_LINK_SPEED_32G;
  9177. break;
  9178. case LINK_SPEED_64G:
  9179. phba->cfg_link_speed =
  9180. LPFC_USER_LINK_SPEED_64G;
  9181. break;
  9182. case 0xffff:
  9183. phba->cfg_link_speed =
  9184. LPFC_USER_LINK_SPEED_AUTO;
  9185. break;
  9186. default:
  9187. lpfc_printf_log(phba, KERN_ERR,
  9188. LOG_TRACE_EVENT,
  9189. "0047 Unrecognized link "
  9190. "speed : %d\n",
  9191. forced_link_speed);
  9192. phba->cfg_link_speed =
  9193. LPFC_USER_LINK_SPEED_AUTO;
  9194. }
  9195. }
  9196. }
  9197. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  9198. length = phba->sli4_hba.max_cfg_param.max_xri -
  9199. lpfc_sli4_get_els_iocb_cnt(phba);
  9200. if (phba->cfg_hba_queue_depth > length) {
  9201. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9202. "3361 HBA queue depth changed from %d to %d\n",
  9203. phba->cfg_hba_queue_depth, length);
  9204. phba->cfg_hba_queue_depth = length;
  9205. }
  9206. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
  9207. LPFC_SLI_INTF_IF_TYPE_2)
  9208. goto read_cfg_out;
  9209. /* get the pf# and vf# for SLI4 if_type 2 port */
  9210. length = (sizeof(struct lpfc_mbx_get_func_cfg) -
  9211. sizeof(struct lpfc_sli4_cfg_mhdr));
  9212. lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
  9213. LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
  9214. length, LPFC_SLI4_MBX_EMBED);
  9215. rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  9216. shdr = (union lpfc_sli4_cfg_shdr *)
  9217. &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
  9218. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9219. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9220. if (rc2 || shdr_status || shdr_add_status) {
  9221. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9222. "3026 Mailbox failed , mbxCmd x%x "
  9223. "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
  9224. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  9225. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  9226. goto read_cfg_out;
  9227. }
  9228. /* search for fc_fcoe resrouce descriptor */
  9229. get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
  9230. pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
  9231. desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
  9232. length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
  9233. if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
  9234. length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
  9235. else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
  9236. goto read_cfg_out;
  9237. for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
  9238. desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
  9239. if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
  9240. bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
  9241. phba->sli4_hba.iov.pf_number =
  9242. bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
  9243. phba->sli4_hba.iov.vf_number =
  9244. bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
  9245. break;
  9246. }
  9247. }
  9248. if (i < LPFC_RSRC_DESC_MAX_NUM)
  9249. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9250. "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
  9251. "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
  9252. phba->sli4_hba.iov.vf_number);
  9253. else
  9254. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9255. "3028 GET_FUNCTION_CONFIG: failed to find "
  9256. "Resource Descriptor:x%x\n",
  9257. LPFC_RSRC_DESC_TYPE_FCFCOE);
  9258. read_cfg_out:
  9259. mempool_free(pmb, phba->mbox_mem_pool);
  9260. return rc;
  9261. }
  9262. /**
  9263. * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
  9264. * @phba: pointer to lpfc hba data structure.
  9265. *
  9266. * This routine is invoked to setup the port-side endian order when
  9267. * the port if_type is 0. This routine has no function for other
  9268. * if_types.
  9269. *
  9270. * Return codes
  9271. * 0 - successful
  9272. * -ENOMEM - No available memory
  9273. * -EIO - The mailbox failed to complete successfully.
  9274. **/
  9275. static int
  9276. lpfc_setup_endian_order(struct lpfc_hba *phba)
  9277. {
  9278. LPFC_MBOXQ_t *mboxq;
  9279. uint32_t if_type, rc = 0;
  9280. uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
  9281. HOST_ENDIAN_HIGH_WORD1};
  9282. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  9283. switch (if_type) {
  9284. case LPFC_SLI_INTF_IF_TYPE_0:
  9285. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  9286. GFP_KERNEL);
  9287. if (!mboxq) {
  9288. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9289. "0492 Unable to allocate memory for "
  9290. "issuing SLI_CONFIG_SPECIAL mailbox "
  9291. "command\n");
  9292. return -ENOMEM;
  9293. }
  9294. /*
  9295. * The SLI4_CONFIG_SPECIAL mailbox command requires the first
  9296. * two words to contain special data values and no other data.
  9297. */
  9298. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  9299. memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
  9300. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  9301. if (rc != MBX_SUCCESS) {
  9302. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9303. "0493 SLI_CONFIG_SPECIAL mailbox "
  9304. "failed with status x%x\n",
  9305. rc);
  9306. rc = -EIO;
  9307. }
  9308. mempool_free(mboxq, phba->mbox_mem_pool);
  9309. break;
  9310. case LPFC_SLI_INTF_IF_TYPE_6:
  9311. case LPFC_SLI_INTF_IF_TYPE_2:
  9312. case LPFC_SLI_INTF_IF_TYPE_1:
  9313. default:
  9314. break;
  9315. }
  9316. return rc;
  9317. }
  9318. /**
  9319. * lpfc_sli4_queue_verify - Verify and update EQ counts
  9320. * @phba: pointer to lpfc hba data structure.
  9321. *
  9322. * This routine is invoked to check the user settable queue counts for EQs.
  9323. * After this routine is called the counts will be set to valid values that
  9324. * adhere to the constraints of the system's interrupt vectors and the port's
  9325. * queue resources.
  9326. *
  9327. * Return codes
  9328. * 0 - successful
  9329. * -ENOMEM - No available memory
  9330. **/
  9331. static int
  9332. lpfc_sli4_queue_verify(struct lpfc_hba *phba)
  9333. {
  9334. /*
  9335. * Sanity check for configured queue parameters against the run-time
  9336. * device parameters
  9337. */
  9338. if (phba->nvmet_support) {
  9339. if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq)
  9340. phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
  9341. if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
  9342. phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
  9343. }
  9344. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9345. "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n",
  9346. phba->cfg_hdw_queue, phba->cfg_irq_chann,
  9347. phba->cfg_nvmet_mrq);
  9348. /* Get EQ depth from module parameter, fake the default for now */
  9349. phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
  9350. phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
  9351. /* Get CQ depth from module parameter, fake the default for now */
  9352. phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
  9353. phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
  9354. return 0;
  9355. }
  9356. static int
  9357. lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx)
  9358. {
  9359. struct lpfc_queue *qdesc;
  9360. u32 wqesize;
  9361. int cpu;
  9362. cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ);
  9363. /* Create Fast Path IO CQs */
  9364. if (phba->enab_exp_wqcq_pages)
  9365. /* Increase the CQ size when WQEs contain an embedded cdb */
  9366. qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
  9367. phba->sli4_hba.cq_esize,
  9368. LPFC_CQE_EXP_COUNT, cpu);
  9369. else
  9370. qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
  9371. phba->sli4_hba.cq_esize,
  9372. phba->sli4_hba.cq_ecount, cpu);
  9373. if (!qdesc) {
  9374. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9375. "0499 Failed allocate fast-path IO CQ (%d)\n",
  9376. idx);
  9377. return 1;
  9378. }
  9379. qdesc->qe_valid = 1;
  9380. qdesc->hdwq = idx;
  9381. qdesc->chann = cpu;
  9382. phba->sli4_hba.hdwq[idx].io_cq = qdesc;
  9383. /* Create Fast Path IO WQs */
  9384. if (phba->enab_exp_wqcq_pages) {
  9385. /* Increase the WQ size when WQEs contain an embedded cdb */
  9386. wqesize = (phba->fcp_embed_io) ?
  9387. LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
  9388. qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
  9389. wqesize,
  9390. LPFC_WQE_EXP_COUNT, cpu);
  9391. } else
  9392. qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
  9393. phba->sli4_hba.wq_esize,
  9394. phba->sli4_hba.wq_ecount, cpu);
  9395. if (!qdesc) {
  9396. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9397. "0503 Failed allocate fast-path IO WQ (%d)\n",
  9398. idx);
  9399. return 1;
  9400. }
  9401. qdesc->hdwq = idx;
  9402. qdesc->chann = cpu;
  9403. phba->sli4_hba.hdwq[idx].io_wq = qdesc;
  9404. list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
  9405. return 0;
  9406. }
  9407. /**
  9408. * lpfc_sli4_queue_create - Create all the SLI4 queues
  9409. * @phba: pointer to lpfc hba data structure.
  9410. *
  9411. * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
  9412. * operation. For each SLI4 queue type, the parameters such as queue entry
  9413. * count (queue depth) shall be taken from the module parameter. For now,
  9414. * we just use some constant number as place holder.
  9415. *
  9416. * Return codes
  9417. * 0 - successful
  9418. * -ENOMEM - No availble memory
  9419. * -EIO - The mailbox failed to complete successfully.
  9420. **/
  9421. int
  9422. lpfc_sli4_queue_create(struct lpfc_hba *phba)
  9423. {
  9424. struct lpfc_queue *qdesc;
  9425. int idx, cpu, eqcpu;
  9426. struct lpfc_sli4_hdw_queue *qp;
  9427. struct lpfc_vector_map_info *cpup;
  9428. struct lpfc_vector_map_info *eqcpup;
  9429. struct lpfc_eq_intr_info *eqi;
  9430. /*
  9431. * Create HBA Record arrays.
  9432. * Both NVME and FCP will share that same vectors / EQs
  9433. */
  9434. phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
  9435. phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
  9436. phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
  9437. phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
  9438. phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
  9439. phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
  9440. phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
  9441. phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
  9442. phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
  9443. phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
  9444. if (!phba->sli4_hba.hdwq) {
  9445. phba->sli4_hba.hdwq = kcalloc(
  9446. phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue),
  9447. GFP_KERNEL);
  9448. if (!phba->sli4_hba.hdwq) {
  9449. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9450. "6427 Failed allocate memory for "
  9451. "fast-path Hardware Queue array\n");
  9452. goto out_error;
  9453. }
  9454. /* Prepare hardware queues to take IO buffers */
  9455. for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
  9456. qp = &phba->sli4_hba.hdwq[idx];
  9457. spin_lock_init(&qp->io_buf_list_get_lock);
  9458. spin_lock_init(&qp->io_buf_list_put_lock);
  9459. INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get);
  9460. INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
  9461. qp->get_io_bufs = 0;
  9462. qp->put_io_bufs = 0;
  9463. qp->total_io_bufs = 0;
  9464. spin_lock_init(&qp->abts_io_buf_list_lock);
  9465. INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list);
  9466. qp->abts_scsi_io_bufs = 0;
  9467. qp->abts_nvme_io_bufs = 0;
  9468. INIT_LIST_HEAD(&qp->sgl_list);
  9469. INIT_LIST_HEAD(&qp->cmd_rsp_buf_list);
  9470. spin_lock_init(&qp->hdwq_lock);
  9471. }
  9472. }
  9473. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  9474. if (phba->nvmet_support) {
  9475. phba->sli4_hba.nvmet_cqset = kcalloc(
  9476. phba->cfg_nvmet_mrq,
  9477. sizeof(struct lpfc_queue *),
  9478. GFP_KERNEL);
  9479. if (!phba->sli4_hba.nvmet_cqset) {
  9480. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9481. "3121 Fail allocate memory for "
  9482. "fast-path CQ set array\n");
  9483. goto out_error;
  9484. }
  9485. phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
  9486. phba->cfg_nvmet_mrq,
  9487. sizeof(struct lpfc_queue *),
  9488. GFP_KERNEL);
  9489. if (!phba->sli4_hba.nvmet_mrq_hdr) {
  9490. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9491. "3122 Fail allocate memory for "
  9492. "fast-path RQ set hdr array\n");
  9493. goto out_error;
  9494. }
  9495. phba->sli4_hba.nvmet_mrq_data = kcalloc(
  9496. phba->cfg_nvmet_mrq,
  9497. sizeof(struct lpfc_queue *),
  9498. GFP_KERNEL);
  9499. if (!phba->sli4_hba.nvmet_mrq_data) {
  9500. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9501. "3124 Fail allocate memory for "
  9502. "fast-path RQ set data array\n");
  9503. goto out_error;
  9504. }
  9505. }
  9506. }
  9507. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
  9508. /* Create HBA Event Queues (EQs) */
  9509. for_each_present_cpu(cpu) {
  9510. /* We only want to create 1 EQ per vector, even though
  9511. * multiple CPUs might be using that vector. so only
  9512. * selects the CPUs that are LPFC_CPU_FIRST_IRQ.
  9513. */
  9514. cpup = &phba->sli4_hba.cpu_map[cpu];
  9515. if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
  9516. continue;
  9517. /* Get a ptr to the Hardware Queue associated with this CPU */
  9518. qp = &phba->sli4_hba.hdwq[cpup->hdwq];
  9519. /* Allocate an EQ */
  9520. qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
  9521. phba->sli4_hba.eq_esize,
  9522. phba->sli4_hba.eq_ecount, cpu);
  9523. if (!qdesc) {
  9524. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9525. "0497 Failed allocate EQ (%d)\n",
  9526. cpup->hdwq);
  9527. goto out_error;
  9528. }
  9529. qdesc->qe_valid = 1;
  9530. qdesc->hdwq = cpup->hdwq;
  9531. qdesc->chann = cpu; /* First CPU this EQ is affinitized to */
  9532. qdesc->last_cpu = qdesc->chann;
  9533. /* Save the allocated EQ in the Hardware Queue */
  9534. qp->hba_eq = qdesc;
  9535. eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu);
  9536. list_add(&qdesc->cpu_list, &eqi->list);
  9537. }
  9538. /* Now we need to populate the other Hardware Queues, that share
  9539. * an IRQ vector, with the associated EQ ptr.
  9540. */
  9541. for_each_present_cpu(cpu) {
  9542. cpup = &phba->sli4_hba.cpu_map[cpu];
  9543. /* Check for EQ already allocated in previous loop */
  9544. if (cpup->flag & LPFC_CPU_FIRST_IRQ)
  9545. continue;
  9546. /* Check for multiple CPUs per hdwq */
  9547. qp = &phba->sli4_hba.hdwq[cpup->hdwq];
  9548. if (qp->hba_eq)
  9549. continue;
  9550. /* We need to share an EQ for this hdwq */
  9551. eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ);
  9552. eqcpup = &phba->sli4_hba.cpu_map[eqcpu];
  9553. qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq;
  9554. }
  9555. /* Allocate IO Path SLI4 CQ/WQs */
  9556. for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
  9557. if (lpfc_alloc_io_wq_cq(phba, idx))
  9558. goto out_error;
  9559. }
  9560. if (phba->nvmet_support) {
  9561. for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
  9562. cpu = lpfc_find_cpu_handle(phba, idx,
  9563. LPFC_FIND_BY_HDWQ);
  9564. qdesc = lpfc_sli4_queue_alloc(phba,
  9565. LPFC_DEFAULT_PAGE_SIZE,
  9566. phba->sli4_hba.cq_esize,
  9567. phba->sli4_hba.cq_ecount,
  9568. cpu);
  9569. if (!qdesc) {
  9570. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9571. "3142 Failed allocate NVME "
  9572. "CQ Set (%d)\n", idx);
  9573. goto out_error;
  9574. }
  9575. qdesc->qe_valid = 1;
  9576. qdesc->hdwq = idx;
  9577. qdesc->chann = cpu;
  9578. phba->sli4_hba.nvmet_cqset[idx] = qdesc;
  9579. }
  9580. }
  9581. /*
  9582. * Create Slow Path Completion Queues (CQs)
  9583. */
  9584. cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ);
  9585. /* Create slow-path Mailbox Command Complete Queue */
  9586. qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
  9587. phba->sli4_hba.cq_esize,
  9588. phba->sli4_hba.cq_ecount, cpu);
  9589. if (!qdesc) {
  9590. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9591. "0500 Failed allocate slow-path mailbox CQ\n");
  9592. goto out_error;
  9593. }
  9594. qdesc->qe_valid = 1;
  9595. phba->sli4_hba.mbx_cq = qdesc;
  9596. /* Create slow-path ELS Complete Queue */
  9597. qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
  9598. phba->sli4_hba.cq_esize,
  9599. phba->sli4_hba.cq_ecount, cpu);
  9600. if (!qdesc) {
  9601. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9602. "0501 Failed allocate slow-path ELS CQ\n");
  9603. goto out_error;
  9604. }
  9605. qdesc->qe_valid = 1;
  9606. qdesc->chann = cpu;
  9607. phba->sli4_hba.els_cq = qdesc;
  9608. /*
  9609. * Create Slow Path Work Queues (WQs)
  9610. */
  9611. /* Create Mailbox Command Queue */
  9612. qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
  9613. phba->sli4_hba.mq_esize,
  9614. phba->sli4_hba.mq_ecount, cpu);
  9615. if (!qdesc) {
  9616. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9617. "0505 Failed allocate slow-path MQ\n");
  9618. goto out_error;
  9619. }
  9620. qdesc->chann = cpu;
  9621. phba->sli4_hba.mbx_wq = qdesc;
  9622. /*
  9623. * Create ELS Work Queues
  9624. */
  9625. /* Create slow-path ELS Work Queue */
  9626. qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
  9627. phba->sli4_hba.wq_esize,
  9628. phba->sli4_hba.wq_ecount, cpu);
  9629. if (!qdesc) {
  9630. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9631. "0504 Failed allocate slow-path ELS WQ\n");
  9632. goto out_error;
  9633. }
  9634. qdesc->chann = cpu;
  9635. phba->sli4_hba.els_wq = qdesc;
  9636. list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
  9637. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  9638. /* Create NVME LS Complete Queue */
  9639. qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
  9640. phba->sli4_hba.cq_esize,
  9641. phba->sli4_hba.cq_ecount, cpu);
  9642. if (!qdesc) {
  9643. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9644. "6079 Failed allocate NVME LS CQ\n");
  9645. goto out_error;
  9646. }
  9647. qdesc->chann = cpu;
  9648. qdesc->qe_valid = 1;
  9649. phba->sli4_hba.nvmels_cq = qdesc;
  9650. /* Create NVME LS Work Queue */
  9651. qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
  9652. phba->sli4_hba.wq_esize,
  9653. phba->sli4_hba.wq_ecount, cpu);
  9654. if (!qdesc) {
  9655. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9656. "6080 Failed allocate NVME LS WQ\n");
  9657. goto out_error;
  9658. }
  9659. qdesc->chann = cpu;
  9660. phba->sli4_hba.nvmels_wq = qdesc;
  9661. list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
  9662. }
  9663. /*
  9664. * Create Receive Queue (RQ)
  9665. */
  9666. /* Create Receive Queue for header */
  9667. qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
  9668. phba->sli4_hba.rq_esize,
  9669. phba->sli4_hba.rq_ecount, cpu);
  9670. if (!qdesc) {
  9671. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9672. "0506 Failed allocate receive HRQ\n");
  9673. goto out_error;
  9674. }
  9675. phba->sli4_hba.hdr_rq = qdesc;
  9676. /* Create Receive Queue for data */
  9677. qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
  9678. phba->sli4_hba.rq_esize,
  9679. phba->sli4_hba.rq_ecount, cpu);
  9680. if (!qdesc) {
  9681. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9682. "0507 Failed allocate receive DRQ\n");
  9683. goto out_error;
  9684. }
  9685. phba->sli4_hba.dat_rq = qdesc;
  9686. if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
  9687. phba->nvmet_support) {
  9688. for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
  9689. cpu = lpfc_find_cpu_handle(phba, idx,
  9690. LPFC_FIND_BY_HDWQ);
  9691. /* Create NVMET Receive Queue for header */
  9692. qdesc = lpfc_sli4_queue_alloc(phba,
  9693. LPFC_DEFAULT_PAGE_SIZE,
  9694. phba->sli4_hba.rq_esize,
  9695. LPFC_NVMET_RQE_DEF_COUNT,
  9696. cpu);
  9697. if (!qdesc) {
  9698. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9699. "3146 Failed allocate "
  9700. "receive HRQ\n");
  9701. goto out_error;
  9702. }
  9703. qdesc->hdwq = idx;
  9704. phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
  9705. /* Only needed for header of RQ pair */
  9706. qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp),
  9707. GFP_KERNEL,
  9708. cpu_to_node(cpu));
  9709. if (qdesc->rqbp == NULL) {
  9710. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9711. "6131 Failed allocate "
  9712. "Header RQBP\n");
  9713. goto out_error;
  9714. }
  9715. /* Put list in known state in case driver load fails. */
  9716. INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
  9717. /* Create NVMET Receive Queue for data */
  9718. qdesc = lpfc_sli4_queue_alloc(phba,
  9719. LPFC_DEFAULT_PAGE_SIZE,
  9720. phba->sli4_hba.rq_esize,
  9721. LPFC_NVMET_RQE_DEF_COUNT,
  9722. cpu);
  9723. if (!qdesc) {
  9724. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9725. "3156 Failed allocate "
  9726. "receive DRQ\n");
  9727. goto out_error;
  9728. }
  9729. qdesc->hdwq = idx;
  9730. phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
  9731. }
  9732. }
  9733. /* Clear NVME stats */
  9734. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  9735. for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
  9736. memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0,
  9737. sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat));
  9738. }
  9739. }
  9740. /* Clear SCSI stats */
  9741. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
  9742. for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
  9743. memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0,
  9744. sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat));
  9745. }
  9746. }
  9747. return 0;
  9748. out_error:
  9749. lpfc_sli4_queue_destroy(phba);
  9750. return -ENOMEM;
  9751. }
  9752. static inline void
  9753. __lpfc_sli4_release_queue(struct lpfc_queue **qp)
  9754. {
  9755. if (*qp != NULL) {
  9756. lpfc_sli4_queue_free(*qp);
  9757. *qp = NULL;
  9758. }
  9759. }
  9760. static inline void
  9761. lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
  9762. {
  9763. int idx;
  9764. if (*qs == NULL)
  9765. return;
  9766. for (idx = 0; idx < max; idx++)
  9767. __lpfc_sli4_release_queue(&(*qs)[idx]);
  9768. kfree(*qs);
  9769. *qs = NULL;
  9770. }
  9771. static inline void
  9772. lpfc_sli4_release_hdwq(struct lpfc_hba *phba)
  9773. {
  9774. struct lpfc_sli4_hdw_queue *hdwq;
  9775. struct lpfc_queue *eq;
  9776. uint32_t idx;
  9777. hdwq = phba->sli4_hba.hdwq;
  9778. /* Loop thru all Hardware Queues */
  9779. for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
  9780. /* Free the CQ/WQ corresponding to the Hardware Queue */
  9781. lpfc_sli4_queue_free(hdwq[idx].io_cq);
  9782. lpfc_sli4_queue_free(hdwq[idx].io_wq);
  9783. hdwq[idx].hba_eq = NULL;
  9784. hdwq[idx].io_cq = NULL;
  9785. hdwq[idx].io_wq = NULL;
  9786. if (phba->cfg_xpsgl && !phba->nvmet_support)
  9787. lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]);
  9788. lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]);
  9789. }
  9790. /* Loop thru all IRQ vectors */
  9791. for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
  9792. /* Free the EQ corresponding to the IRQ vector */
  9793. eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
  9794. lpfc_sli4_queue_free(eq);
  9795. phba->sli4_hba.hba_eq_hdl[idx].eq = NULL;
  9796. }
  9797. }
  9798. /**
  9799. * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
  9800. * @phba: pointer to lpfc hba data structure.
  9801. *
  9802. * This routine is invoked to release all the SLI4 queues with the FCoE HBA
  9803. * operation.
  9804. *
  9805. * Return codes
  9806. * 0 - successful
  9807. * -ENOMEM - No available memory
  9808. * -EIO - The mailbox failed to complete successfully.
  9809. **/
  9810. void
  9811. lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
  9812. {
  9813. /*
  9814. * Set FREE_INIT before beginning to free the queues.
  9815. * Wait until the users of queues to acknowledge to
  9816. * release queues by clearing FREE_WAIT.
  9817. */
  9818. spin_lock_irq(&phba->hbalock);
  9819. phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT;
  9820. while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) {
  9821. spin_unlock_irq(&phba->hbalock);
  9822. msleep(20);
  9823. spin_lock_irq(&phba->hbalock);
  9824. }
  9825. spin_unlock_irq(&phba->hbalock);
  9826. lpfc_sli4_cleanup_poll_list(phba);
  9827. /* Release HBA eqs */
  9828. if (phba->sli4_hba.hdwq)
  9829. lpfc_sli4_release_hdwq(phba);
  9830. if (phba->nvmet_support) {
  9831. lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
  9832. phba->cfg_nvmet_mrq);
  9833. lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
  9834. phba->cfg_nvmet_mrq);
  9835. lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
  9836. phba->cfg_nvmet_mrq);
  9837. }
  9838. /* Release mailbox command work queue */
  9839. __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
  9840. /* Release ELS work queue */
  9841. __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
  9842. /* Release ELS work queue */
  9843. __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
  9844. /* Release unsolicited receive queue */
  9845. __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
  9846. __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
  9847. /* Release ELS complete queue */
  9848. __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
  9849. /* Release NVME LS complete queue */
  9850. __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
  9851. /* Release mailbox command complete queue */
  9852. __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
  9853. /* Everything on this list has been freed */
  9854. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
  9855. /* Done with freeing the queues */
  9856. spin_lock_irq(&phba->hbalock);
  9857. phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT;
  9858. spin_unlock_irq(&phba->hbalock);
  9859. }
  9860. int
  9861. lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
  9862. {
  9863. struct lpfc_rqb *rqbp;
  9864. struct lpfc_dmabuf *h_buf;
  9865. struct rqb_dmabuf *rqb_buffer;
  9866. rqbp = rq->rqbp;
  9867. while (!list_empty(&rqbp->rqb_buffer_list)) {
  9868. list_remove_head(&rqbp->rqb_buffer_list, h_buf,
  9869. struct lpfc_dmabuf, list);
  9870. rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
  9871. (rqbp->rqb_free_buffer)(phba, rqb_buffer);
  9872. rqbp->buffer_count--;
  9873. }
  9874. return 1;
  9875. }
  9876. static int
  9877. lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
  9878. struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
  9879. int qidx, uint32_t qtype)
  9880. {
  9881. struct lpfc_sli_ring *pring;
  9882. int rc;
  9883. if (!eq || !cq || !wq) {
  9884. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9885. "6085 Fast-path %s (%d) not allocated\n",
  9886. ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
  9887. return -ENOMEM;
  9888. }
  9889. /* create the Cq first */
  9890. rc = lpfc_cq_create(phba, cq, eq,
  9891. (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
  9892. if (rc) {
  9893. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9894. "6086 Failed setup of CQ (%d), rc = 0x%x\n",
  9895. qidx, (uint32_t)rc);
  9896. return rc;
  9897. }
  9898. if (qtype != LPFC_MBOX) {
  9899. /* Setup cq_map for fast lookup */
  9900. if (cq_map)
  9901. *cq_map = cq->queue_id;
  9902. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9903. "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
  9904. qidx, cq->queue_id, qidx, eq->queue_id);
  9905. /* create the wq */
  9906. rc = lpfc_wq_create(phba, wq, cq, qtype);
  9907. if (rc) {
  9908. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9909. "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n",
  9910. qidx, (uint32_t)rc);
  9911. /* no need to tear down cq - caller will do so */
  9912. return rc;
  9913. }
  9914. /* Bind this CQ/WQ to the NVME ring */
  9915. pring = wq->pring;
  9916. pring->sli.sli4.wqp = (void *)wq;
  9917. cq->pring = pring;
  9918. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9919. "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
  9920. qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
  9921. } else {
  9922. rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
  9923. if (rc) {
  9924. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9925. "0539 Failed setup of slow-path MQ: "
  9926. "rc = 0x%x\n", rc);
  9927. /* no need to tear down cq - caller will do so */
  9928. return rc;
  9929. }
  9930. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9931. "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
  9932. phba->sli4_hba.mbx_wq->queue_id,
  9933. phba->sli4_hba.mbx_cq->queue_id);
  9934. }
  9935. return 0;
  9936. }
  9937. /**
  9938. * lpfc_setup_cq_lookup - Setup the CQ lookup table
  9939. * @phba: pointer to lpfc hba data structure.
  9940. *
  9941. * This routine will populate the cq_lookup table by all
  9942. * available CQ queue_id's.
  9943. **/
  9944. static void
  9945. lpfc_setup_cq_lookup(struct lpfc_hba *phba)
  9946. {
  9947. struct lpfc_queue *eq, *childq;
  9948. int qidx;
  9949. memset(phba->sli4_hba.cq_lookup, 0,
  9950. (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1)));
  9951. /* Loop thru all IRQ vectors */
  9952. for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
  9953. /* Get the EQ corresponding to the IRQ vector */
  9954. eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
  9955. if (!eq)
  9956. continue;
  9957. /* Loop through all CQs associated with that EQ */
  9958. list_for_each_entry(childq, &eq->child_list, list) {
  9959. if (childq->queue_id > phba->sli4_hba.cq_max)
  9960. continue;
  9961. if (childq->subtype == LPFC_IO)
  9962. phba->sli4_hba.cq_lookup[childq->queue_id] =
  9963. childq;
  9964. }
  9965. }
  9966. }
  9967. /**
  9968. * lpfc_sli4_queue_setup - Set up all the SLI4 queues
  9969. * @phba: pointer to lpfc hba data structure.
  9970. *
  9971. * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
  9972. * operation.
  9973. *
  9974. * Return codes
  9975. * 0 - successful
  9976. * -ENOMEM - No available memory
  9977. * -EIO - The mailbox failed to complete successfully.
  9978. **/
  9979. int
  9980. lpfc_sli4_queue_setup(struct lpfc_hba *phba)
  9981. {
  9982. uint32_t shdr_status, shdr_add_status;
  9983. union lpfc_sli4_cfg_shdr *shdr;
  9984. struct lpfc_vector_map_info *cpup;
  9985. struct lpfc_sli4_hdw_queue *qp;
  9986. LPFC_MBOXQ_t *mboxq;
  9987. int qidx, cpu;
  9988. uint32_t length, usdelay;
  9989. int rc = -ENOMEM;
  9990. /* Check for dual-ULP support */
  9991. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9992. if (!mboxq) {
  9993. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9994. "3249 Unable to allocate memory for "
  9995. "QUERY_FW_CFG mailbox command\n");
  9996. return -ENOMEM;
  9997. }
  9998. length = (sizeof(struct lpfc_mbx_query_fw_config) -
  9999. sizeof(struct lpfc_sli4_cfg_mhdr));
  10000. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  10001. LPFC_MBOX_OPCODE_QUERY_FW_CFG,
  10002. length, LPFC_SLI4_MBX_EMBED);
  10003. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10004. shdr = (union lpfc_sli4_cfg_shdr *)
  10005. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  10006. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10007. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10008. if (shdr_status || shdr_add_status || rc) {
  10009. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10010. "3250 QUERY_FW_CFG mailbox failed with status "
  10011. "x%x add_status x%x, mbx status x%x\n",
  10012. shdr_status, shdr_add_status, rc);
  10013. mempool_free(mboxq, phba->mbox_mem_pool);
  10014. rc = -ENXIO;
  10015. goto out_error;
  10016. }
  10017. phba->sli4_hba.fw_func_mode =
  10018. mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
  10019. phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
  10020. phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
  10021. phba->sli4_hba.physical_port =
  10022. mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
  10023. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10024. "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
  10025. "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
  10026. phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
  10027. mempool_free(mboxq, phba->mbox_mem_pool);
  10028. /*
  10029. * Set up HBA Event Queues (EQs)
  10030. */
  10031. qp = phba->sli4_hba.hdwq;
  10032. /* Set up HBA event queue */
  10033. if (!qp) {
  10034. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10035. "3147 Fast-path EQs not allocated\n");
  10036. rc = -ENOMEM;
  10037. goto out_error;
  10038. }
  10039. /* Loop thru all IRQ vectors */
  10040. for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
  10041. /* Create HBA Event Queues (EQs) in order */
  10042. for_each_present_cpu(cpu) {
  10043. cpup = &phba->sli4_hba.cpu_map[cpu];
  10044. /* Look for the CPU thats using that vector with
  10045. * LPFC_CPU_FIRST_IRQ set.
  10046. */
  10047. if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
  10048. continue;
  10049. if (qidx != cpup->eq)
  10050. continue;
  10051. /* Create an EQ for that vector */
  10052. rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq,
  10053. phba->cfg_fcp_imax);
  10054. if (rc) {
  10055. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10056. "0523 Failed setup of fast-path"
  10057. " EQ (%d), rc = 0x%x\n",
  10058. cpup->eq, (uint32_t)rc);
  10059. goto out_destroy;
  10060. }
  10061. /* Save the EQ for that vector in the hba_eq_hdl */
  10062. phba->sli4_hba.hba_eq_hdl[cpup->eq].eq =
  10063. qp[cpup->hdwq].hba_eq;
  10064. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10065. "2584 HBA EQ setup: queue[%d]-id=%d\n",
  10066. cpup->eq,
  10067. qp[cpup->hdwq].hba_eq->queue_id);
  10068. }
  10069. }
  10070. /* Loop thru all Hardware Queues */
  10071. for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
  10072. cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ);
  10073. cpup = &phba->sli4_hba.cpu_map[cpu];
  10074. /* Create the CQ/WQ corresponding to the Hardware Queue */
  10075. rc = lpfc_create_wq_cq(phba,
  10076. phba->sli4_hba.hdwq[cpup->hdwq].hba_eq,
  10077. qp[qidx].io_cq,
  10078. qp[qidx].io_wq,
  10079. &phba->sli4_hba.hdwq[qidx].io_cq_map,
  10080. qidx,
  10081. LPFC_IO);
  10082. if (rc) {
  10083. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10084. "0535 Failed to setup fastpath "
  10085. "IO WQ/CQ (%d), rc = 0x%x\n",
  10086. qidx, (uint32_t)rc);
  10087. goto out_destroy;
  10088. }
  10089. }
  10090. /*
  10091. * Set up Slow Path Complete Queues (CQs)
  10092. */
  10093. /* Set up slow-path MBOX CQ/MQ */
  10094. if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
  10095. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10096. "0528 %s not allocated\n",
  10097. phba->sli4_hba.mbx_cq ?
  10098. "Mailbox WQ" : "Mailbox CQ");
  10099. rc = -ENOMEM;
  10100. goto out_destroy;
  10101. }
  10102. rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
  10103. phba->sli4_hba.mbx_cq,
  10104. phba->sli4_hba.mbx_wq,
  10105. NULL, 0, LPFC_MBOX);
  10106. if (rc) {
  10107. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10108. "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
  10109. (uint32_t)rc);
  10110. goto out_destroy;
  10111. }
  10112. if (phba->nvmet_support) {
  10113. if (!phba->sli4_hba.nvmet_cqset) {
  10114. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10115. "3165 Fast-path NVME CQ Set "
  10116. "array not allocated\n");
  10117. rc = -ENOMEM;
  10118. goto out_destroy;
  10119. }
  10120. if (phba->cfg_nvmet_mrq > 1) {
  10121. rc = lpfc_cq_create_set(phba,
  10122. phba->sli4_hba.nvmet_cqset,
  10123. qp,
  10124. LPFC_WCQ, LPFC_NVMET);
  10125. if (rc) {
  10126. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10127. "3164 Failed setup of NVME CQ "
  10128. "Set, rc = 0x%x\n",
  10129. (uint32_t)rc);
  10130. goto out_destroy;
  10131. }
  10132. } else {
  10133. /* Set up NVMET Receive Complete Queue */
  10134. rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
  10135. qp[0].hba_eq,
  10136. LPFC_WCQ, LPFC_NVMET);
  10137. if (rc) {
  10138. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10139. "6089 Failed setup NVMET CQ: "
  10140. "rc = 0x%x\n", (uint32_t)rc);
  10141. goto out_destroy;
  10142. }
  10143. phba->sli4_hba.nvmet_cqset[0]->chann = 0;
  10144. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10145. "6090 NVMET CQ setup: cq-id=%d, "
  10146. "parent eq-id=%d\n",
  10147. phba->sli4_hba.nvmet_cqset[0]->queue_id,
  10148. qp[0].hba_eq->queue_id);
  10149. }
  10150. }
  10151. /* Set up slow-path ELS WQ/CQ */
  10152. if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
  10153. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10154. "0530 ELS %s not allocated\n",
  10155. phba->sli4_hba.els_cq ? "WQ" : "CQ");
  10156. rc = -ENOMEM;
  10157. goto out_destroy;
  10158. }
  10159. rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
  10160. phba->sli4_hba.els_cq,
  10161. phba->sli4_hba.els_wq,
  10162. NULL, 0, LPFC_ELS);
  10163. if (rc) {
  10164. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10165. "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
  10166. (uint32_t)rc);
  10167. goto out_destroy;
  10168. }
  10169. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10170. "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
  10171. phba->sli4_hba.els_wq->queue_id,
  10172. phba->sli4_hba.els_cq->queue_id);
  10173. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  10174. /* Set up NVME LS Complete Queue */
  10175. if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
  10176. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10177. "6091 LS %s not allocated\n",
  10178. phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
  10179. rc = -ENOMEM;
  10180. goto out_destroy;
  10181. }
  10182. rc = lpfc_create_wq_cq(phba, qp[0].hba_eq,
  10183. phba->sli4_hba.nvmels_cq,
  10184. phba->sli4_hba.nvmels_wq,
  10185. NULL, 0, LPFC_NVME_LS);
  10186. if (rc) {
  10187. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10188. "0526 Failed setup of NVVME LS WQ/CQ: "
  10189. "rc = 0x%x\n", (uint32_t)rc);
  10190. goto out_destroy;
  10191. }
  10192. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10193. "6096 ELS WQ setup: wq-id=%d, "
  10194. "parent cq-id=%d\n",
  10195. phba->sli4_hba.nvmels_wq->queue_id,
  10196. phba->sli4_hba.nvmels_cq->queue_id);
  10197. }
  10198. /*
  10199. * Create NVMET Receive Queue (RQ)
  10200. */
  10201. if (phba->nvmet_support) {
  10202. if ((!phba->sli4_hba.nvmet_cqset) ||
  10203. (!phba->sli4_hba.nvmet_mrq_hdr) ||
  10204. (!phba->sli4_hba.nvmet_mrq_data)) {
  10205. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10206. "6130 MRQ CQ Queues not "
  10207. "allocated\n");
  10208. rc = -ENOMEM;
  10209. goto out_destroy;
  10210. }
  10211. if (phba->cfg_nvmet_mrq > 1) {
  10212. rc = lpfc_mrq_create(phba,
  10213. phba->sli4_hba.nvmet_mrq_hdr,
  10214. phba->sli4_hba.nvmet_mrq_data,
  10215. phba->sli4_hba.nvmet_cqset,
  10216. LPFC_NVMET);
  10217. if (rc) {
  10218. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10219. "6098 Failed setup of NVMET "
  10220. "MRQ: rc = 0x%x\n",
  10221. (uint32_t)rc);
  10222. goto out_destroy;
  10223. }
  10224. } else {
  10225. rc = lpfc_rq_create(phba,
  10226. phba->sli4_hba.nvmet_mrq_hdr[0],
  10227. phba->sli4_hba.nvmet_mrq_data[0],
  10228. phba->sli4_hba.nvmet_cqset[0],
  10229. LPFC_NVMET);
  10230. if (rc) {
  10231. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10232. "6057 Failed setup of NVMET "
  10233. "Receive Queue: rc = 0x%x\n",
  10234. (uint32_t)rc);
  10235. goto out_destroy;
  10236. }
  10237. lpfc_printf_log(
  10238. phba, KERN_INFO, LOG_INIT,
  10239. "6099 NVMET RQ setup: hdr-rq-id=%d, "
  10240. "dat-rq-id=%d parent cq-id=%d\n",
  10241. phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
  10242. phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
  10243. phba->sli4_hba.nvmet_cqset[0]->queue_id);
  10244. }
  10245. }
  10246. if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
  10247. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10248. "0540 Receive Queue not allocated\n");
  10249. rc = -ENOMEM;
  10250. goto out_destroy;
  10251. }
  10252. rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  10253. phba->sli4_hba.els_cq, LPFC_USOL);
  10254. if (rc) {
  10255. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10256. "0541 Failed setup of Receive Queue: "
  10257. "rc = 0x%x\n", (uint32_t)rc);
  10258. goto out_destroy;
  10259. }
  10260. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10261. "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
  10262. "parent cq-id=%d\n",
  10263. phba->sli4_hba.hdr_rq->queue_id,
  10264. phba->sli4_hba.dat_rq->queue_id,
  10265. phba->sli4_hba.els_cq->queue_id);
  10266. if (phba->cfg_fcp_imax)
  10267. usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
  10268. else
  10269. usdelay = 0;
  10270. for (qidx = 0; qidx < phba->cfg_irq_chann;
  10271. qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
  10272. lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
  10273. usdelay);
  10274. if (phba->sli4_hba.cq_max) {
  10275. kfree(phba->sli4_hba.cq_lookup);
  10276. phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1),
  10277. sizeof(struct lpfc_queue *), GFP_KERNEL);
  10278. if (!phba->sli4_hba.cq_lookup) {
  10279. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10280. "0549 Failed setup of CQ Lookup table: "
  10281. "size 0x%x\n", phba->sli4_hba.cq_max);
  10282. rc = -ENOMEM;
  10283. goto out_destroy;
  10284. }
  10285. lpfc_setup_cq_lookup(phba);
  10286. }
  10287. return 0;
  10288. out_destroy:
  10289. lpfc_sli4_queue_unset(phba);
  10290. out_error:
  10291. return rc;
  10292. }
  10293. /**
  10294. * lpfc_sli4_queue_unset - Unset all the SLI4 queues
  10295. * @phba: pointer to lpfc hba data structure.
  10296. *
  10297. * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
  10298. * operation.
  10299. *
  10300. * Return codes
  10301. * 0 - successful
  10302. * -ENOMEM - No available memory
  10303. * -EIO - The mailbox failed to complete successfully.
  10304. **/
  10305. void
  10306. lpfc_sli4_queue_unset(struct lpfc_hba *phba)
  10307. {
  10308. struct lpfc_sli4_hdw_queue *qp;
  10309. struct lpfc_queue *eq;
  10310. int qidx;
  10311. /* Unset mailbox command work queue */
  10312. if (phba->sli4_hba.mbx_wq)
  10313. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  10314. /* Unset NVME LS work queue */
  10315. if (phba->sli4_hba.nvmels_wq)
  10316. lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
  10317. /* Unset ELS work queue */
  10318. if (phba->sli4_hba.els_wq)
  10319. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  10320. /* Unset unsolicited receive queue */
  10321. if (phba->sli4_hba.hdr_rq)
  10322. lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
  10323. phba->sli4_hba.dat_rq);
  10324. /* Unset mailbox command complete queue */
  10325. if (phba->sli4_hba.mbx_cq)
  10326. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  10327. /* Unset ELS complete queue */
  10328. if (phba->sli4_hba.els_cq)
  10329. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  10330. /* Unset NVME LS complete queue */
  10331. if (phba->sli4_hba.nvmels_cq)
  10332. lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
  10333. if (phba->nvmet_support) {
  10334. /* Unset NVMET MRQ queue */
  10335. if (phba->sli4_hba.nvmet_mrq_hdr) {
  10336. for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
  10337. lpfc_rq_destroy(
  10338. phba,
  10339. phba->sli4_hba.nvmet_mrq_hdr[qidx],
  10340. phba->sli4_hba.nvmet_mrq_data[qidx]);
  10341. }
  10342. /* Unset NVMET CQ Set complete queue */
  10343. if (phba->sli4_hba.nvmet_cqset) {
  10344. for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
  10345. lpfc_cq_destroy(
  10346. phba, phba->sli4_hba.nvmet_cqset[qidx]);
  10347. }
  10348. }
  10349. /* Unset fast-path SLI4 queues */
  10350. if (phba->sli4_hba.hdwq) {
  10351. /* Loop thru all Hardware Queues */
  10352. for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
  10353. /* Destroy the CQ/WQ corresponding to Hardware Queue */
  10354. qp = &phba->sli4_hba.hdwq[qidx];
  10355. lpfc_wq_destroy(phba, qp->io_wq);
  10356. lpfc_cq_destroy(phba, qp->io_cq);
  10357. }
  10358. /* Loop thru all IRQ vectors */
  10359. for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
  10360. /* Destroy the EQ corresponding to the IRQ vector */
  10361. eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
  10362. lpfc_eq_destroy(phba, eq);
  10363. }
  10364. }
  10365. kfree(phba->sli4_hba.cq_lookup);
  10366. phba->sli4_hba.cq_lookup = NULL;
  10367. phba->sli4_hba.cq_max = 0;
  10368. }
  10369. /**
  10370. * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
  10371. * @phba: pointer to lpfc hba data structure.
  10372. *
  10373. * This routine is invoked to allocate and set up a pool of completion queue
  10374. * events. The body of the completion queue event is a completion queue entry
  10375. * CQE. For now, this pool is used for the interrupt service routine to queue
  10376. * the following HBA completion queue events for the worker thread to process:
  10377. * - Mailbox asynchronous events
  10378. * - Receive queue completion unsolicited events
  10379. * Later, this can be used for all the slow-path events.
  10380. *
  10381. * Return codes
  10382. * 0 - successful
  10383. * -ENOMEM - No available memory
  10384. **/
  10385. static int
  10386. lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
  10387. {
  10388. struct lpfc_cq_event *cq_event;
  10389. int i;
  10390. for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
  10391. cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
  10392. if (!cq_event)
  10393. goto out_pool_create_fail;
  10394. list_add_tail(&cq_event->list,
  10395. &phba->sli4_hba.sp_cqe_event_pool);
  10396. }
  10397. return 0;
  10398. out_pool_create_fail:
  10399. lpfc_sli4_cq_event_pool_destroy(phba);
  10400. return -ENOMEM;
  10401. }
  10402. /**
  10403. * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
  10404. * @phba: pointer to lpfc hba data structure.
  10405. *
  10406. * This routine is invoked to free the pool of completion queue events at
  10407. * driver unload time. Note that, it is the responsibility of the driver
  10408. * cleanup routine to free all the outstanding completion-queue events
  10409. * allocated from this pool back into the pool before invoking this routine
  10410. * to destroy the pool.
  10411. **/
  10412. static void
  10413. lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
  10414. {
  10415. struct lpfc_cq_event *cq_event, *next_cq_event;
  10416. list_for_each_entry_safe(cq_event, next_cq_event,
  10417. &phba->sli4_hba.sp_cqe_event_pool, list) {
  10418. list_del(&cq_event->list);
  10419. kfree(cq_event);
  10420. }
  10421. }
  10422. /**
  10423. * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  10424. * @phba: pointer to lpfc hba data structure.
  10425. *
  10426. * This routine is the lock free version of the API invoked to allocate a
  10427. * completion-queue event from the free pool.
  10428. *
  10429. * Return: Pointer to the newly allocated completion-queue event if successful
  10430. * NULL otherwise.
  10431. **/
  10432. struct lpfc_cq_event *
  10433. __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  10434. {
  10435. struct lpfc_cq_event *cq_event = NULL;
  10436. list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
  10437. struct lpfc_cq_event, list);
  10438. return cq_event;
  10439. }
  10440. /**
  10441. * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  10442. * @phba: pointer to lpfc hba data structure.
  10443. *
  10444. * This routine is the lock version of the API invoked to allocate a
  10445. * completion-queue event from the free pool.
  10446. *
  10447. * Return: Pointer to the newly allocated completion-queue event if successful
  10448. * NULL otherwise.
  10449. **/
  10450. struct lpfc_cq_event *
  10451. lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  10452. {
  10453. struct lpfc_cq_event *cq_event;
  10454. unsigned long iflags;
  10455. spin_lock_irqsave(&phba->hbalock, iflags);
  10456. cq_event = __lpfc_sli4_cq_event_alloc(phba);
  10457. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10458. return cq_event;
  10459. }
  10460. /**
  10461. * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  10462. * @phba: pointer to lpfc hba data structure.
  10463. * @cq_event: pointer to the completion queue event to be freed.
  10464. *
  10465. * This routine is the lock free version of the API invoked to release a
  10466. * completion-queue event back into the free pool.
  10467. **/
  10468. void
  10469. __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  10470. struct lpfc_cq_event *cq_event)
  10471. {
  10472. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
  10473. }
  10474. /**
  10475. * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  10476. * @phba: pointer to lpfc hba data structure.
  10477. * @cq_event: pointer to the completion queue event to be freed.
  10478. *
  10479. * This routine is the lock version of the API invoked to release a
  10480. * completion-queue event back into the free pool.
  10481. **/
  10482. void
  10483. lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  10484. struct lpfc_cq_event *cq_event)
  10485. {
  10486. unsigned long iflags;
  10487. spin_lock_irqsave(&phba->hbalock, iflags);
  10488. __lpfc_sli4_cq_event_release(phba, cq_event);
  10489. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10490. }
  10491. /**
  10492. * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
  10493. * @phba: pointer to lpfc hba data structure.
  10494. *
  10495. * This routine is to free all the pending completion-queue events to the
  10496. * back into the free pool for device reset.
  10497. **/
  10498. static void
  10499. lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
  10500. {
  10501. LIST_HEAD(cq_event_list);
  10502. struct lpfc_cq_event *cq_event;
  10503. unsigned long iflags;
  10504. /* Retrieve all the pending WCQEs from pending WCQE lists */
  10505. /* Pending ELS XRI abort events */
  10506. spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
  10507. list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  10508. &cq_event_list);
  10509. spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
  10510. /* Pending asynnc events */
  10511. spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
  10512. list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
  10513. &cq_event_list);
  10514. spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
  10515. while (!list_empty(&cq_event_list)) {
  10516. list_remove_head(&cq_event_list, cq_event,
  10517. struct lpfc_cq_event, list);
  10518. lpfc_sli4_cq_event_release(phba, cq_event);
  10519. }
  10520. }
  10521. /**
  10522. * lpfc_pci_function_reset - Reset pci function.
  10523. * @phba: pointer to lpfc hba data structure.
  10524. *
  10525. * This routine is invoked to request a PCI function reset. It will destroys
  10526. * all resources assigned to the PCI function which originates this request.
  10527. *
  10528. * Return codes
  10529. * 0 - successful
  10530. * -ENOMEM - No available memory
  10531. * -EIO - The mailbox failed to complete successfully.
  10532. **/
  10533. int
  10534. lpfc_pci_function_reset(struct lpfc_hba *phba)
  10535. {
  10536. LPFC_MBOXQ_t *mboxq;
  10537. uint32_t rc = 0, if_type;
  10538. uint32_t shdr_status, shdr_add_status;
  10539. uint32_t rdy_chk;
  10540. uint32_t port_reset = 0;
  10541. union lpfc_sli4_cfg_shdr *shdr;
  10542. struct lpfc_register reg_data;
  10543. uint16_t devid;
  10544. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  10545. switch (if_type) {
  10546. case LPFC_SLI_INTF_IF_TYPE_0:
  10547. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  10548. GFP_KERNEL);
  10549. if (!mboxq) {
  10550. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10551. "0494 Unable to allocate memory for "
  10552. "issuing SLI_FUNCTION_RESET mailbox "
  10553. "command\n");
  10554. return -ENOMEM;
  10555. }
  10556. /* Setup PCI function reset mailbox-ioctl command */
  10557. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  10558. LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
  10559. LPFC_SLI4_MBX_EMBED);
  10560. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10561. shdr = (union lpfc_sli4_cfg_shdr *)
  10562. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  10563. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10564. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  10565. &shdr->response);
  10566. mempool_free(mboxq, phba->mbox_mem_pool);
  10567. if (shdr_status || shdr_add_status || rc) {
  10568. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10569. "0495 SLI_FUNCTION_RESET mailbox "
  10570. "failed with status x%x add_status x%x,"
  10571. " mbx status x%x\n",
  10572. shdr_status, shdr_add_status, rc);
  10573. rc = -ENXIO;
  10574. }
  10575. break;
  10576. case LPFC_SLI_INTF_IF_TYPE_2:
  10577. case LPFC_SLI_INTF_IF_TYPE_6:
  10578. wait:
  10579. /*
  10580. * Poll the Port Status Register and wait for RDY for
  10581. * up to 30 seconds. If the port doesn't respond, treat
  10582. * it as an error.
  10583. */
  10584. for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
  10585. if (lpfc_readl(phba->sli4_hba.u.if_type2.
  10586. STATUSregaddr, &reg_data.word0)) {
  10587. rc = -ENODEV;
  10588. goto out;
  10589. }
  10590. if (bf_get(lpfc_sliport_status_rdy, &reg_data))
  10591. break;
  10592. msleep(20);
  10593. }
  10594. if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
  10595. phba->work_status[0] = readl(
  10596. phba->sli4_hba.u.if_type2.ERR1regaddr);
  10597. phba->work_status[1] = readl(
  10598. phba->sli4_hba.u.if_type2.ERR2regaddr);
  10599. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10600. "2890 Port not ready, port status reg "
  10601. "0x%x error 1=0x%x, error 2=0x%x\n",
  10602. reg_data.word0,
  10603. phba->work_status[0],
  10604. phba->work_status[1]);
  10605. rc = -ENODEV;
  10606. goto out;
  10607. }
  10608. if (bf_get(lpfc_sliport_status_pldv, &reg_data))
  10609. lpfc_pldv_detect = true;
  10610. if (!port_reset) {
  10611. /*
  10612. * Reset the port now
  10613. */
  10614. reg_data.word0 = 0;
  10615. bf_set(lpfc_sliport_ctrl_end, &reg_data,
  10616. LPFC_SLIPORT_LITTLE_ENDIAN);
  10617. bf_set(lpfc_sliport_ctrl_ip, &reg_data,
  10618. LPFC_SLIPORT_INIT_PORT);
  10619. writel(reg_data.word0, phba->sli4_hba.u.if_type2.
  10620. CTRLregaddr);
  10621. /* flush */
  10622. pci_read_config_word(phba->pcidev,
  10623. PCI_DEVICE_ID, &devid);
  10624. port_reset = 1;
  10625. msleep(20);
  10626. goto wait;
  10627. } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
  10628. rc = -ENODEV;
  10629. goto out;
  10630. }
  10631. break;
  10632. case LPFC_SLI_INTF_IF_TYPE_1:
  10633. default:
  10634. break;
  10635. }
  10636. out:
  10637. /* Catch the not-ready port failure after a port reset. */
  10638. if (rc) {
  10639. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10640. "3317 HBA not functional: IP Reset Failed "
  10641. "try: echo fw_reset > board_mode\n");
  10642. rc = -ENODEV;
  10643. }
  10644. return rc;
  10645. }
  10646. /**
  10647. * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
  10648. * @phba: pointer to lpfc hba data structure.
  10649. *
  10650. * This routine is invoked to set up the PCI device memory space for device
  10651. * with SLI-4 interface spec.
  10652. *
  10653. * Return codes
  10654. * 0 - successful
  10655. * other values - error
  10656. **/
  10657. static int
  10658. lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
  10659. {
  10660. struct pci_dev *pdev = phba->pcidev;
  10661. unsigned long bar0map_len, bar1map_len, bar2map_len;
  10662. int error;
  10663. uint32_t if_type;
  10664. if (!pdev)
  10665. return -ENODEV;
  10666. /* Set the device DMA mask size */
  10667. error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  10668. if (error)
  10669. error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  10670. if (error)
  10671. return error;
  10672. /*
  10673. * The BARs and register set definitions and offset locations are
  10674. * dependent on the if_type.
  10675. */
  10676. if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
  10677. &phba->sli4_hba.sli_intf.word0)) {
  10678. return -ENODEV;
  10679. }
  10680. /* There is no SLI3 failback for SLI4 devices. */
  10681. if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
  10682. LPFC_SLI_INTF_VALID) {
  10683. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10684. "2894 SLI_INTF reg contents invalid "
  10685. "sli_intf reg 0x%x\n",
  10686. phba->sli4_hba.sli_intf.word0);
  10687. return -ENODEV;
  10688. }
  10689. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  10690. /*
  10691. * Get the bus address of SLI4 device Bar regions and the
  10692. * number of bytes required by each mapping. The mapping of the
  10693. * particular PCI BARs regions is dependent on the type of
  10694. * SLI4 device.
  10695. */
  10696. if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
  10697. phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
  10698. bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
  10699. /*
  10700. * Map SLI4 PCI Config Space Register base to a kernel virtual
  10701. * addr
  10702. */
  10703. phba->sli4_hba.conf_regs_memmap_p =
  10704. ioremap(phba->pci_bar0_map, bar0map_len);
  10705. if (!phba->sli4_hba.conf_regs_memmap_p) {
  10706. dev_printk(KERN_ERR, &pdev->dev,
  10707. "ioremap failed for SLI4 PCI config "
  10708. "registers.\n");
  10709. return -ENODEV;
  10710. }
  10711. phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
  10712. /* Set up BAR0 PCI config space register memory map */
  10713. lpfc_sli4_bar0_register_memmap(phba, if_type);
  10714. } else {
  10715. phba->pci_bar0_map = pci_resource_start(pdev, 1);
  10716. bar0map_len = pci_resource_len(pdev, 1);
  10717. if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
  10718. dev_printk(KERN_ERR, &pdev->dev,
  10719. "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
  10720. return -ENODEV;
  10721. }
  10722. phba->sli4_hba.conf_regs_memmap_p =
  10723. ioremap(phba->pci_bar0_map, bar0map_len);
  10724. if (!phba->sli4_hba.conf_regs_memmap_p) {
  10725. dev_printk(KERN_ERR, &pdev->dev,
  10726. "ioremap failed for SLI4 PCI config "
  10727. "registers.\n");
  10728. return -ENODEV;
  10729. }
  10730. lpfc_sli4_bar0_register_memmap(phba, if_type);
  10731. }
  10732. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  10733. if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
  10734. /*
  10735. * Map SLI4 if type 0 HBA Control Register base to a
  10736. * kernel virtual address and setup the registers.
  10737. */
  10738. phba->pci_bar1_map = pci_resource_start(pdev,
  10739. PCI_64BIT_BAR2);
  10740. bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
  10741. phba->sli4_hba.ctrl_regs_memmap_p =
  10742. ioremap(phba->pci_bar1_map,
  10743. bar1map_len);
  10744. if (!phba->sli4_hba.ctrl_regs_memmap_p) {
  10745. dev_err(&pdev->dev,
  10746. "ioremap failed for SLI4 HBA "
  10747. "control registers.\n");
  10748. error = -ENOMEM;
  10749. goto out_iounmap_conf;
  10750. }
  10751. phba->pci_bar2_memmap_p =
  10752. phba->sli4_hba.ctrl_regs_memmap_p;
  10753. lpfc_sli4_bar1_register_memmap(phba, if_type);
  10754. } else {
  10755. error = -ENOMEM;
  10756. goto out_iounmap_conf;
  10757. }
  10758. }
  10759. if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
  10760. (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
  10761. /*
  10762. * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
  10763. * virtual address and setup the registers.
  10764. */
  10765. phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
  10766. bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
  10767. phba->sli4_hba.drbl_regs_memmap_p =
  10768. ioremap(phba->pci_bar1_map, bar1map_len);
  10769. if (!phba->sli4_hba.drbl_regs_memmap_p) {
  10770. dev_err(&pdev->dev,
  10771. "ioremap failed for SLI4 HBA doorbell registers.\n");
  10772. error = -ENOMEM;
  10773. goto out_iounmap_conf;
  10774. }
  10775. phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
  10776. lpfc_sli4_bar1_register_memmap(phba, if_type);
  10777. }
  10778. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  10779. if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
  10780. /*
  10781. * Map SLI4 if type 0 HBA Doorbell Register base to
  10782. * a kernel virtual address and setup the registers.
  10783. */
  10784. phba->pci_bar2_map = pci_resource_start(pdev,
  10785. PCI_64BIT_BAR4);
  10786. bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
  10787. phba->sli4_hba.drbl_regs_memmap_p =
  10788. ioremap(phba->pci_bar2_map,
  10789. bar2map_len);
  10790. if (!phba->sli4_hba.drbl_regs_memmap_p) {
  10791. dev_err(&pdev->dev,
  10792. "ioremap failed for SLI4 HBA"
  10793. " doorbell registers.\n");
  10794. error = -ENOMEM;
  10795. goto out_iounmap_ctrl;
  10796. }
  10797. phba->pci_bar4_memmap_p =
  10798. phba->sli4_hba.drbl_regs_memmap_p;
  10799. error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
  10800. if (error)
  10801. goto out_iounmap_all;
  10802. } else {
  10803. error = -ENOMEM;
  10804. goto out_iounmap_ctrl;
  10805. }
  10806. }
  10807. if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
  10808. pci_resource_start(pdev, PCI_64BIT_BAR4)) {
  10809. /*
  10810. * Map SLI4 if type 6 HBA DPP Register base to a kernel
  10811. * virtual address and setup the registers.
  10812. */
  10813. phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
  10814. bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
  10815. phba->sli4_hba.dpp_regs_memmap_p =
  10816. ioremap(phba->pci_bar2_map, bar2map_len);
  10817. if (!phba->sli4_hba.dpp_regs_memmap_p) {
  10818. dev_err(&pdev->dev,
  10819. "ioremap failed for SLI4 HBA dpp registers.\n");
  10820. error = -ENOMEM;
  10821. goto out_iounmap_all;
  10822. }
  10823. phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
  10824. }
  10825. /* Set up the EQ/CQ register handeling functions now */
  10826. switch (if_type) {
  10827. case LPFC_SLI_INTF_IF_TYPE_0:
  10828. case LPFC_SLI_INTF_IF_TYPE_2:
  10829. phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
  10830. phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db;
  10831. phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db;
  10832. break;
  10833. case LPFC_SLI_INTF_IF_TYPE_6:
  10834. phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
  10835. phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db;
  10836. phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_if6_write_cq_db;
  10837. break;
  10838. default:
  10839. break;
  10840. }
  10841. return 0;
  10842. out_iounmap_all:
  10843. if (phba->sli4_hba.drbl_regs_memmap_p)
  10844. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  10845. out_iounmap_ctrl:
  10846. if (phba->sli4_hba.ctrl_regs_memmap_p)
  10847. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  10848. out_iounmap_conf:
  10849. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  10850. return error;
  10851. }
  10852. /**
  10853. * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
  10854. * @phba: pointer to lpfc hba data structure.
  10855. *
  10856. * This routine is invoked to unset the PCI device memory space for device
  10857. * with SLI-4 interface spec.
  10858. **/
  10859. static void
  10860. lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
  10861. {
  10862. uint32_t if_type;
  10863. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  10864. switch (if_type) {
  10865. case LPFC_SLI_INTF_IF_TYPE_0:
  10866. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  10867. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  10868. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  10869. break;
  10870. case LPFC_SLI_INTF_IF_TYPE_2:
  10871. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  10872. break;
  10873. case LPFC_SLI_INTF_IF_TYPE_6:
  10874. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  10875. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  10876. if (phba->sli4_hba.dpp_regs_memmap_p)
  10877. iounmap(phba->sli4_hba.dpp_regs_memmap_p);
  10878. break;
  10879. case LPFC_SLI_INTF_IF_TYPE_1:
  10880. default:
  10881. dev_printk(KERN_ERR, &phba->pcidev->dev,
  10882. "FATAL - unsupported SLI4 interface type - %d\n",
  10883. if_type);
  10884. break;
  10885. }
  10886. }
  10887. /**
  10888. * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
  10889. * @phba: pointer to lpfc hba data structure.
  10890. *
  10891. * This routine is invoked to enable the MSI-X interrupt vectors to device
  10892. * with SLI-3 interface specs.
  10893. *
  10894. * Return codes
  10895. * 0 - successful
  10896. * other values - error
  10897. **/
  10898. static int
  10899. lpfc_sli_enable_msix(struct lpfc_hba *phba)
  10900. {
  10901. int rc;
  10902. LPFC_MBOXQ_t *pmb;
  10903. /* Set up MSI-X multi-message vectors */
  10904. rc = pci_alloc_irq_vectors(phba->pcidev,
  10905. LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
  10906. if (rc < 0) {
  10907. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10908. "0420 PCI enable MSI-X failed (%d)\n", rc);
  10909. goto vec_fail_out;
  10910. }
  10911. /*
  10912. * Assign MSI-X vectors to interrupt handlers
  10913. */
  10914. /* vector-0 is associated to slow-path handler */
  10915. rc = request_irq(pci_irq_vector(phba->pcidev, 0),
  10916. &lpfc_sli_sp_intr_handler, 0,
  10917. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  10918. if (rc) {
  10919. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10920. "0421 MSI-X slow-path request_irq failed "
  10921. "(%d)\n", rc);
  10922. goto msi_fail_out;
  10923. }
  10924. /* vector-1 is associated to fast-path handler */
  10925. rc = request_irq(pci_irq_vector(phba->pcidev, 1),
  10926. &lpfc_sli_fp_intr_handler, 0,
  10927. LPFC_FP_DRIVER_HANDLER_NAME, phba);
  10928. if (rc) {
  10929. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10930. "0429 MSI-X fast-path request_irq failed "
  10931. "(%d)\n", rc);
  10932. goto irq_fail_out;
  10933. }
  10934. /*
  10935. * Configure HBA MSI-X attention conditions to messages
  10936. */
  10937. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10938. if (!pmb) {
  10939. rc = -ENOMEM;
  10940. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10941. "0474 Unable to allocate memory for issuing "
  10942. "MBOX_CONFIG_MSI command\n");
  10943. goto mem_fail_out;
  10944. }
  10945. rc = lpfc_config_msi(phba, pmb);
  10946. if (rc)
  10947. goto mbx_fail_out;
  10948. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  10949. if (rc != MBX_SUCCESS) {
  10950. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  10951. "0351 Config MSI mailbox command failed, "
  10952. "mbxCmd x%x, mbxStatus x%x\n",
  10953. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
  10954. goto mbx_fail_out;
  10955. }
  10956. /* Free memory allocated for mailbox command */
  10957. mempool_free(pmb, phba->mbox_mem_pool);
  10958. return rc;
  10959. mbx_fail_out:
  10960. /* Free memory allocated for mailbox command */
  10961. mempool_free(pmb, phba->mbox_mem_pool);
  10962. mem_fail_out:
  10963. /* free the irq already requested */
  10964. free_irq(pci_irq_vector(phba->pcidev, 1), phba);
  10965. irq_fail_out:
  10966. /* free the irq already requested */
  10967. free_irq(pci_irq_vector(phba->pcidev, 0), phba);
  10968. msi_fail_out:
  10969. /* Unconfigure MSI-X capability structure */
  10970. pci_free_irq_vectors(phba->pcidev);
  10971. vec_fail_out:
  10972. return rc;
  10973. }
  10974. /**
  10975. * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
  10976. * @phba: pointer to lpfc hba data structure.
  10977. *
  10978. * This routine is invoked to enable the MSI interrupt mode to device with
  10979. * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
  10980. * enable the MSI vector. The device driver is responsible for calling the
  10981. * request_irq() to register MSI vector with a interrupt the handler, which
  10982. * is done in this function.
  10983. *
  10984. * Return codes
  10985. * 0 - successful
  10986. * other values - error
  10987. */
  10988. static int
  10989. lpfc_sli_enable_msi(struct lpfc_hba *phba)
  10990. {
  10991. int rc;
  10992. rc = pci_enable_msi(phba->pcidev);
  10993. if (!rc)
  10994. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10995. "0012 PCI enable MSI mode success.\n");
  10996. else {
  10997. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10998. "0471 PCI enable MSI mode failed (%d)\n", rc);
  10999. return rc;
  11000. }
  11001. rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  11002. 0, LPFC_DRIVER_NAME, phba);
  11003. if (rc) {
  11004. pci_disable_msi(phba->pcidev);
  11005. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  11006. "0478 MSI request_irq failed (%d)\n", rc);
  11007. }
  11008. return rc;
  11009. }
  11010. /**
  11011. * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
  11012. * @phba: pointer to lpfc hba data structure.
  11013. * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
  11014. *
  11015. * This routine is invoked to enable device interrupt and associate driver's
  11016. * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
  11017. * spec. Depends on the interrupt mode configured to the driver, the driver
  11018. * will try to fallback from the configured interrupt mode to an interrupt
  11019. * mode which is supported by the platform, kernel, and device in the order
  11020. * of:
  11021. * MSI-X -> MSI -> IRQ.
  11022. *
  11023. * Return codes
  11024. * 0 - successful
  11025. * other values - error
  11026. **/
  11027. static uint32_t
  11028. lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  11029. {
  11030. uint32_t intr_mode = LPFC_INTR_ERROR;
  11031. int retval;
  11032. /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
  11033. retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
  11034. if (retval)
  11035. return intr_mode;
  11036. phba->hba_flag &= ~HBA_NEEDS_CFG_PORT;
  11037. if (cfg_mode == 2) {
  11038. /* Now, try to enable MSI-X interrupt mode */
  11039. retval = lpfc_sli_enable_msix(phba);
  11040. if (!retval) {
  11041. /* Indicate initialization to MSI-X mode */
  11042. phba->intr_type = MSIX;
  11043. intr_mode = 2;
  11044. }
  11045. }
  11046. /* Fallback to MSI if MSI-X initialization failed */
  11047. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  11048. retval = lpfc_sli_enable_msi(phba);
  11049. if (!retval) {
  11050. /* Indicate initialization to MSI mode */
  11051. phba->intr_type = MSI;
  11052. intr_mode = 1;
  11053. }
  11054. }
  11055. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  11056. if (phba->intr_type == NONE) {
  11057. retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  11058. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  11059. if (!retval) {
  11060. /* Indicate initialization to INTx mode */
  11061. phba->intr_type = INTx;
  11062. intr_mode = 0;
  11063. }
  11064. }
  11065. return intr_mode;
  11066. }
  11067. /**
  11068. * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
  11069. * @phba: pointer to lpfc hba data structure.
  11070. *
  11071. * This routine is invoked to disable device interrupt and disassociate the
  11072. * driver's interrupt handler(s) from interrupt vector(s) to device with
  11073. * SLI-3 interface spec. Depending on the interrupt mode, the driver will
  11074. * release the interrupt vector(s) for the message signaled interrupt.
  11075. **/
  11076. static void
  11077. lpfc_sli_disable_intr(struct lpfc_hba *phba)
  11078. {
  11079. int nr_irqs, i;
  11080. if (phba->intr_type == MSIX)
  11081. nr_irqs = LPFC_MSIX_VECTORS;
  11082. else
  11083. nr_irqs = 1;
  11084. for (i = 0; i < nr_irqs; i++)
  11085. free_irq(pci_irq_vector(phba->pcidev, i), phba);
  11086. pci_free_irq_vectors(phba->pcidev);
  11087. /* Reset interrupt management states */
  11088. phba->intr_type = NONE;
  11089. phba->sli.slistat.sli_intr = 0;
  11090. }
  11091. /**
  11092. * lpfc_find_cpu_handle - Find the CPU that corresponds to the specified Queue
  11093. * @phba: pointer to lpfc hba data structure.
  11094. * @id: EQ vector index or Hardware Queue index
  11095. * @match: LPFC_FIND_BY_EQ = match by EQ
  11096. * LPFC_FIND_BY_HDWQ = match by Hardware Queue
  11097. * Return the CPU that matches the selection criteria
  11098. */
  11099. static uint16_t
  11100. lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match)
  11101. {
  11102. struct lpfc_vector_map_info *cpup;
  11103. int cpu;
  11104. /* Loop through all CPUs */
  11105. for_each_present_cpu(cpu) {
  11106. cpup = &phba->sli4_hba.cpu_map[cpu];
  11107. /* If we are matching by EQ, there may be multiple CPUs using
  11108. * using the same vector, so select the one with
  11109. * LPFC_CPU_FIRST_IRQ set.
  11110. */
  11111. if ((match == LPFC_FIND_BY_EQ) &&
  11112. (cpup->flag & LPFC_CPU_FIRST_IRQ) &&
  11113. (cpup->eq == id))
  11114. return cpu;
  11115. /* If matching by HDWQ, select the first CPU that matches */
  11116. if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id))
  11117. return cpu;
  11118. }
  11119. return 0;
  11120. }
  11121. #ifdef CONFIG_X86
  11122. /**
  11123. * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded
  11124. * @phba: pointer to lpfc hba data structure.
  11125. * @cpu: CPU map index
  11126. * @phys_id: CPU package physical id
  11127. * @core_id: CPU core id
  11128. */
  11129. static int
  11130. lpfc_find_hyper(struct lpfc_hba *phba, int cpu,
  11131. uint16_t phys_id, uint16_t core_id)
  11132. {
  11133. struct lpfc_vector_map_info *cpup;
  11134. int idx;
  11135. for_each_present_cpu(idx) {
  11136. cpup = &phba->sli4_hba.cpu_map[idx];
  11137. /* Does the cpup match the one we are looking for */
  11138. if ((cpup->phys_id == phys_id) &&
  11139. (cpup->core_id == core_id) &&
  11140. (cpu != idx))
  11141. return 1;
  11142. }
  11143. return 0;
  11144. }
  11145. #endif
  11146. /*
  11147. * lpfc_assign_eq_map_info - Assigns eq for vector_map structure
  11148. * @phba: pointer to lpfc hba data structure.
  11149. * @eqidx: index for eq and irq vector
  11150. * @flag: flags to set for vector_map structure
  11151. * @cpu: cpu used to index vector_map structure
  11152. *
  11153. * The routine assigns eq info into vector_map structure
  11154. */
  11155. static inline void
  11156. lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag,
  11157. unsigned int cpu)
  11158. {
  11159. struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu];
  11160. struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx);
  11161. cpup->eq = eqidx;
  11162. cpup->flag |= flag;
  11163. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11164. "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n",
  11165. cpu, eqhdl->irq, cpup->eq, cpup->flag);
  11166. }
  11167. /**
  11168. * lpfc_cpu_map_array_init - Initialize cpu_map structure
  11169. * @phba: pointer to lpfc hba data structure.
  11170. *
  11171. * The routine initializes the cpu_map array structure
  11172. */
  11173. static void
  11174. lpfc_cpu_map_array_init(struct lpfc_hba *phba)
  11175. {
  11176. struct lpfc_vector_map_info *cpup;
  11177. struct lpfc_eq_intr_info *eqi;
  11178. int cpu;
  11179. for_each_possible_cpu(cpu) {
  11180. cpup = &phba->sli4_hba.cpu_map[cpu];
  11181. cpup->phys_id = LPFC_VECTOR_MAP_EMPTY;
  11182. cpup->core_id = LPFC_VECTOR_MAP_EMPTY;
  11183. cpup->hdwq = LPFC_VECTOR_MAP_EMPTY;
  11184. cpup->eq = LPFC_VECTOR_MAP_EMPTY;
  11185. cpup->flag = 0;
  11186. eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu);
  11187. INIT_LIST_HEAD(&eqi->list);
  11188. eqi->icnt = 0;
  11189. }
  11190. }
  11191. /**
  11192. * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure
  11193. * @phba: pointer to lpfc hba data structure.
  11194. *
  11195. * The routine initializes the hba_eq_hdl array structure
  11196. */
  11197. static void
  11198. lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba)
  11199. {
  11200. struct lpfc_hba_eq_hdl *eqhdl;
  11201. int i;
  11202. for (i = 0; i < phba->cfg_irq_chann; i++) {
  11203. eqhdl = lpfc_get_eq_hdl(i);
  11204. eqhdl->irq = LPFC_IRQ_EMPTY;
  11205. eqhdl->phba = phba;
  11206. }
  11207. }
  11208. /**
  11209. * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
  11210. * @phba: pointer to lpfc hba data structure.
  11211. * @vectors: number of msix vectors allocated.
  11212. *
  11213. * The routine will figure out the CPU affinity assignment for every
  11214. * MSI-X vector allocated for the HBA.
  11215. * In addition, the CPU to IO channel mapping will be calculated
  11216. * and the phba->sli4_hba.cpu_map array will reflect this.
  11217. */
  11218. static void
  11219. lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
  11220. {
  11221. int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu;
  11222. int max_phys_id, min_phys_id;
  11223. int max_core_id, min_core_id;
  11224. struct lpfc_vector_map_info *cpup;
  11225. struct lpfc_vector_map_info *new_cpup;
  11226. #ifdef CONFIG_X86
  11227. struct cpuinfo_x86 *cpuinfo;
  11228. #endif
  11229. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  11230. struct lpfc_hdwq_stat *c_stat;
  11231. #endif
  11232. max_phys_id = 0;
  11233. min_phys_id = LPFC_VECTOR_MAP_EMPTY;
  11234. max_core_id = 0;
  11235. min_core_id = LPFC_VECTOR_MAP_EMPTY;
  11236. /* Update CPU map with physical id and core id of each CPU */
  11237. for_each_present_cpu(cpu) {
  11238. cpup = &phba->sli4_hba.cpu_map[cpu];
  11239. #ifdef CONFIG_X86
  11240. cpuinfo = &cpu_data(cpu);
  11241. cpup->phys_id = cpuinfo->phys_proc_id;
  11242. cpup->core_id = cpuinfo->cpu_core_id;
  11243. if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id))
  11244. cpup->flag |= LPFC_CPU_MAP_HYPER;
  11245. #else
  11246. /* No distinction between CPUs for other platforms */
  11247. cpup->phys_id = 0;
  11248. cpup->core_id = cpu;
  11249. #endif
  11250. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11251. "3328 CPU %d physid %d coreid %d flag x%x\n",
  11252. cpu, cpup->phys_id, cpup->core_id, cpup->flag);
  11253. if (cpup->phys_id > max_phys_id)
  11254. max_phys_id = cpup->phys_id;
  11255. if (cpup->phys_id < min_phys_id)
  11256. min_phys_id = cpup->phys_id;
  11257. if (cpup->core_id > max_core_id)
  11258. max_core_id = cpup->core_id;
  11259. if (cpup->core_id < min_core_id)
  11260. min_core_id = cpup->core_id;
  11261. }
  11262. /* After looking at each irq vector assigned to this pcidev, its
  11263. * possible to see that not ALL CPUs have been accounted for.
  11264. * Next we will set any unassigned (unaffinitized) cpu map
  11265. * entries to a IRQ on the same phys_id.
  11266. */
  11267. first_cpu = cpumask_first(cpu_present_mask);
  11268. start_cpu = first_cpu;
  11269. for_each_present_cpu(cpu) {
  11270. cpup = &phba->sli4_hba.cpu_map[cpu];
  11271. /* Is this CPU entry unassigned */
  11272. if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
  11273. /* Mark CPU as IRQ not assigned by the kernel */
  11274. cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
  11275. /* If so, find a new_cpup thats on the the SAME
  11276. * phys_id as cpup. start_cpu will start where we
  11277. * left off so all unassigned entries don't get assgined
  11278. * the IRQ of the first entry.
  11279. */
  11280. new_cpu = start_cpu;
  11281. for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
  11282. new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
  11283. if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
  11284. (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) &&
  11285. (new_cpup->phys_id == cpup->phys_id))
  11286. goto found_same;
  11287. new_cpu = cpumask_next(
  11288. new_cpu, cpu_present_mask);
  11289. if (new_cpu == nr_cpumask_bits)
  11290. new_cpu = first_cpu;
  11291. }
  11292. /* At this point, we leave the CPU as unassigned */
  11293. continue;
  11294. found_same:
  11295. /* We found a matching phys_id, so copy the IRQ info */
  11296. cpup->eq = new_cpup->eq;
  11297. /* Bump start_cpu to the next slot to minmize the
  11298. * chance of having multiple unassigned CPU entries
  11299. * selecting the same IRQ.
  11300. */
  11301. start_cpu = cpumask_next(new_cpu, cpu_present_mask);
  11302. if (start_cpu == nr_cpumask_bits)
  11303. start_cpu = first_cpu;
  11304. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11305. "3337 Set Affinity: CPU %d "
  11306. "eq %d from peer cpu %d same "
  11307. "phys_id (%d)\n",
  11308. cpu, cpup->eq, new_cpu,
  11309. cpup->phys_id);
  11310. }
  11311. }
  11312. /* Set any unassigned cpu map entries to a IRQ on any phys_id */
  11313. start_cpu = first_cpu;
  11314. for_each_present_cpu(cpu) {
  11315. cpup = &phba->sli4_hba.cpu_map[cpu];
  11316. /* Is this entry unassigned */
  11317. if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
  11318. /* Mark it as IRQ not assigned by the kernel */
  11319. cpup->flag |= LPFC_CPU_MAP_UNASSIGN;
  11320. /* If so, find a new_cpup thats on ANY phys_id
  11321. * as the cpup. start_cpu will start where we
  11322. * left off so all unassigned entries don't get
  11323. * assigned the IRQ of the first entry.
  11324. */
  11325. new_cpu = start_cpu;
  11326. for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
  11327. new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
  11328. if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
  11329. (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY))
  11330. goto found_any;
  11331. new_cpu = cpumask_next(
  11332. new_cpu, cpu_present_mask);
  11333. if (new_cpu == nr_cpumask_bits)
  11334. new_cpu = first_cpu;
  11335. }
  11336. /* We should never leave an entry unassigned */
  11337. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11338. "3339 Set Affinity: CPU %d "
  11339. "eq %d UNASSIGNED\n",
  11340. cpup->hdwq, cpup->eq);
  11341. continue;
  11342. found_any:
  11343. /* We found an available entry, copy the IRQ info */
  11344. cpup->eq = new_cpup->eq;
  11345. /* Bump start_cpu to the next slot to minmize the
  11346. * chance of having multiple unassigned CPU entries
  11347. * selecting the same IRQ.
  11348. */
  11349. start_cpu = cpumask_next(new_cpu, cpu_present_mask);
  11350. if (start_cpu == nr_cpumask_bits)
  11351. start_cpu = first_cpu;
  11352. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11353. "3338 Set Affinity: CPU %d "
  11354. "eq %d from peer cpu %d (%d/%d)\n",
  11355. cpu, cpup->eq, new_cpu,
  11356. new_cpup->phys_id, new_cpup->core_id);
  11357. }
  11358. }
  11359. /* Assign hdwq indices that are unique across all cpus in the map
  11360. * that are also FIRST_CPUs.
  11361. */
  11362. idx = 0;
  11363. for_each_present_cpu(cpu) {
  11364. cpup = &phba->sli4_hba.cpu_map[cpu];
  11365. /* Only FIRST IRQs get a hdwq index assignment. */
  11366. if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
  11367. continue;
  11368. /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */
  11369. cpup->hdwq = idx;
  11370. idx++;
  11371. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11372. "3333 Set Affinity: CPU %d (phys %d core %d): "
  11373. "hdwq %d eq %d flg x%x\n",
  11374. cpu, cpup->phys_id, cpup->core_id,
  11375. cpup->hdwq, cpup->eq, cpup->flag);
  11376. }
  11377. /* Associate a hdwq with each cpu_map entry
  11378. * This will be 1 to 1 - hdwq to cpu, unless there are less
  11379. * hardware queues then CPUs. For that case we will just round-robin
  11380. * the available hardware queues as they get assigned to CPUs.
  11381. * The next_idx is the idx from the FIRST_CPU loop above to account
  11382. * for irq_chann < hdwq. The idx is used for round-robin assignments
  11383. * and needs to start at 0.
  11384. */
  11385. next_idx = idx;
  11386. start_cpu = 0;
  11387. idx = 0;
  11388. for_each_present_cpu(cpu) {
  11389. cpup = &phba->sli4_hba.cpu_map[cpu];
  11390. /* FIRST cpus are already mapped. */
  11391. if (cpup->flag & LPFC_CPU_FIRST_IRQ)
  11392. continue;
  11393. /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq
  11394. * of the unassigned cpus to the next idx so that all
  11395. * hdw queues are fully utilized.
  11396. */
  11397. if (next_idx < phba->cfg_hdw_queue) {
  11398. cpup->hdwq = next_idx;
  11399. next_idx++;
  11400. continue;
  11401. }
  11402. /* Not a First CPU and all hdw_queues are used. Reuse a
  11403. * Hardware Queue for another CPU, so be smart about it
  11404. * and pick one that has its IRQ/EQ mapped to the same phys_id
  11405. * (CPU package) and core_id.
  11406. */
  11407. new_cpu = start_cpu;
  11408. for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
  11409. new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
  11410. if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
  11411. new_cpup->phys_id == cpup->phys_id &&
  11412. new_cpup->core_id == cpup->core_id) {
  11413. goto found_hdwq;
  11414. }
  11415. new_cpu = cpumask_next(new_cpu, cpu_present_mask);
  11416. if (new_cpu == nr_cpumask_bits)
  11417. new_cpu = first_cpu;
  11418. }
  11419. /* If we can't match both phys_id and core_id,
  11420. * settle for just a phys_id match.
  11421. */
  11422. new_cpu = start_cpu;
  11423. for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
  11424. new_cpup = &phba->sli4_hba.cpu_map[new_cpu];
  11425. if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
  11426. new_cpup->phys_id == cpup->phys_id)
  11427. goto found_hdwq;
  11428. new_cpu = cpumask_next(new_cpu, cpu_present_mask);
  11429. if (new_cpu == nr_cpumask_bits)
  11430. new_cpu = first_cpu;
  11431. }
  11432. /* Otherwise just round robin on cfg_hdw_queue */
  11433. cpup->hdwq = idx % phba->cfg_hdw_queue;
  11434. idx++;
  11435. goto logit;
  11436. found_hdwq:
  11437. /* We found an available entry, copy the IRQ info */
  11438. start_cpu = cpumask_next(new_cpu, cpu_present_mask);
  11439. if (start_cpu == nr_cpumask_bits)
  11440. start_cpu = first_cpu;
  11441. cpup->hdwq = new_cpup->hdwq;
  11442. logit:
  11443. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11444. "3335 Set Affinity: CPU %d (phys %d core %d): "
  11445. "hdwq %d eq %d flg x%x\n",
  11446. cpu, cpup->phys_id, cpup->core_id,
  11447. cpup->hdwq, cpup->eq, cpup->flag);
  11448. }
  11449. /*
  11450. * Initialize the cpu_map slots for not-present cpus in case
  11451. * a cpu is hot-added. Perform a simple hdwq round robin assignment.
  11452. */
  11453. idx = 0;
  11454. for_each_possible_cpu(cpu) {
  11455. cpup = &phba->sli4_hba.cpu_map[cpu];
  11456. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  11457. c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, cpu);
  11458. c_stat->hdwq_no = cpup->hdwq;
  11459. #endif
  11460. if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY)
  11461. continue;
  11462. cpup->hdwq = idx++ % phba->cfg_hdw_queue;
  11463. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  11464. c_stat->hdwq_no = cpup->hdwq;
  11465. #endif
  11466. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11467. "3340 Set Affinity: not present "
  11468. "CPU %d hdwq %d\n",
  11469. cpu, cpup->hdwq);
  11470. }
  11471. /* The cpu_map array will be used later during initialization
  11472. * when EQ / CQ / WQs are allocated and configured.
  11473. */
  11474. return;
  11475. }
  11476. /**
  11477. * lpfc_cpuhp_get_eq
  11478. *
  11479. * @phba: pointer to lpfc hba data structure.
  11480. * @cpu: cpu going offline
  11481. * @eqlist: eq list to append to
  11482. */
  11483. static int
  11484. lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu,
  11485. struct list_head *eqlist)
  11486. {
  11487. const struct cpumask *maskp;
  11488. struct lpfc_queue *eq;
  11489. struct cpumask *tmp;
  11490. u16 idx;
  11491. tmp = kzalloc(cpumask_size(), GFP_KERNEL);
  11492. if (!tmp)
  11493. return -ENOMEM;
  11494. for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
  11495. maskp = pci_irq_get_affinity(phba->pcidev, idx);
  11496. if (!maskp)
  11497. continue;
  11498. /*
  11499. * if irq is not affinitized to the cpu going
  11500. * then we don't need to poll the eq attached
  11501. * to it.
  11502. */
  11503. if (!cpumask_and(tmp, maskp, cpumask_of(cpu)))
  11504. continue;
  11505. /* get the cpus that are online and are affini-
  11506. * tized to this irq vector. If the count is
  11507. * more than 1 then cpuhp is not going to shut-
  11508. * down this vector. Since this cpu has not
  11509. * gone offline yet, we need >1.
  11510. */
  11511. cpumask_and(tmp, maskp, cpu_online_mask);
  11512. if (cpumask_weight(tmp) > 1)
  11513. continue;
  11514. /* Now that we have an irq to shutdown, get the eq
  11515. * mapped to this irq. Note: multiple hdwq's in
  11516. * the software can share an eq, but eventually
  11517. * only eq will be mapped to this vector
  11518. */
  11519. eq = phba->sli4_hba.hba_eq_hdl[idx].eq;
  11520. list_add(&eq->_poll_list, eqlist);
  11521. }
  11522. kfree(tmp);
  11523. return 0;
  11524. }
  11525. static void __lpfc_cpuhp_remove(struct lpfc_hba *phba)
  11526. {
  11527. if (phba->sli_rev != LPFC_SLI_REV4)
  11528. return;
  11529. cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state,
  11530. &phba->cpuhp);
  11531. /*
  11532. * unregistering the instance doesn't stop the polling
  11533. * timer. Wait for the poll timer to retire.
  11534. */
  11535. synchronize_rcu();
  11536. del_timer_sync(&phba->cpuhp_poll_timer);
  11537. }
  11538. static void lpfc_cpuhp_remove(struct lpfc_hba *phba)
  11539. {
  11540. if (phba->pport && (phba->pport->fc_flag & FC_OFFLINE_MODE))
  11541. return;
  11542. __lpfc_cpuhp_remove(phba);
  11543. }
  11544. static void lpfc_cpuhp_add(struct lpfc_hba *phba)
  11545. {
  11546. if (phba->sli_rev != LPFC_SLI_REV4)
  11547. return;
  11548. rcu_read_lock();
  11549. if (!list_empty(&phba->poll_list))
  11550. mod_timer(&phba->cpuhp_poll_timer,
  11551. jiffies + msecs_to_jiffies(LPFC_POLL_HB));
  11552. rcu_read_unlock();
  11553. cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state,
  11554. &phba->cpuhp);
  11555. }
  11556. static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval)
  11557. {
  11558. if (phba->pport->load_flag & FC_UNLOADING) {
  11559. *retval = -EAGAIN;
  11560. return true;
  11561. }
  11562. if (phba->sli_rev != LPFC_SLI_REV4) {
  11563. *retval = 0;
  11564. return true;
  11565. }
  11566. /* proceed with the hotplug */
  11567. return false;
  11568. }
  11569. /**
  11570. * lpfc_irq_set_aff - set IRQ affinity
  11571. * @eqhdl: EQ handle
  11572. * @cpu: cpu to set affinity
  11573. *
  11574. **/
  11575. static inline void
  11576. lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu)
  11577. {
  11578. cpumask_clear(&eqhdl->aff_mask);
  11579. cpumask_set_cpu(cpu, &eqhdl->aff_mask);
  11580. irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
  11581. irq_set_affinity(eqhdl->irq, &eqhdl->aff_mask);
  11582. }
  11583. /**
  11584. * lpfc_irq_clear_aff - clear IRQ affinity
  11585. * @eqhdl: EQ handle
  11586. *
  11587. **/
  11588. static inline void
  11589. lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl)
  11590. {
  11591. cpumask_clear(&eqhdl->aff_mask);
  11592. irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING);
  11593. }
  11594. /**
  11595. * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event
  11596. * @phba: pointer to HBA context object.
  11597. * @cpu: cpu going offline/online
  11598. * @offline: true, cpu is going offline. false, cpu is coming online.
  11599. *
  11600. * If cpu is going offline, we'll try our best effort to find the next
  11601. * online cpu on the phba's original_mask and migrate all offlining IRQ
  11602. * affinities.
  11603. *
  11604. * If cpu is coming online, reaffinitize the IRQ back to the onlining cpu.
  11605. *
  11606. * Note: Call only if NUMA or NHT mode is enabled, otherwise rely on
  11607. * PCI_IRQ_AFFINITY to auto-manage IRQ affinity.
  11608. *
  11609. **/
  11610. static void
  11611. lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline)
  11612. {
  11613. struct lpfc_vector_map_info *cpup;
  11614. struct cpumask *aff_mask;
  11615. unsigned int cpu_select, cpu_next, idx;
  11616. const struct cpumask *orig_mask;
  11617. if (phba->irq_chann_mode == NORMAL_MODE)
  11618. return;
  11619. orig_mask = &phba->sli4_hba.irq_aff_mask;
  11620. if (!cpumask_test_cpu(cpu, orig_mask))
  11621. return;
  11622. cpup = &phba->sli4_hba.cpu_map[cpu];
  11623. if (!(cpup->flag & LPFC_CPU_FIRST_IRQ))
  11624. return;
  11625. if (offline) {
  11626. /* Find next online CPU on original mask */
  11627. cpu_next = cpumask_next_wrap(cpu, orig_mask, cpu, true);
  11628. cpu_select = lpfc_next_online_cpu(orig_mask, cpu_next);
  11629. /* Found a valid CPU */
  11630. if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) {
  11631. /* Go through each eqhdl and ensure offlining
  11632. * cpu aff_mask is migrated
  11633. */
  11634. for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
  11635. aff_mask = lpfc_get_aff_mask(idx);
  11636. /* Migrate affinity */
  11637. if (cpumask_test_cpu(cpu, aff_mask))
  11638. lpfc_irq_set_aff(lpfc_get_eq_hdl(idx),
  11639. cpu_select);
  11640. }
  11641. } else {
  11642. /* Rely on irqbalance if no online CPUs left on NUMA */
  11643. for (idx = 0; idx < phba->cfg_irq_chann; idx++)
  11644. lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx));
  11645. }
  11646. } else {
  11647. /* Migrate affinity back to this CPU */
  11648. lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu);
  11649. }
  11650. }
  11651. static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node)
  11652. {
  11653. struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
  11654. struct lpfc_queue *eq, *next;
  11655. LIST_HEAD(eqlist);
  11656. int retval;
  11657. if (!phba) {
  11658. WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
  11659. return 0;
  11660. }
  11661. if (__lpfc_cpuhp_checks(phba, &retval))
  11662. return retval;
  11663. lpfc_irq_rebalance(phba, cpu, true);
  11664. retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist);
  11665. if (retval)
  11666. return retval;
  11667. /* start polling on these eq's */
  11668. list_for_each_entry_safe(eq, next, &eqlist, _poll_list) {
  11669. list_del_init(&eq->_poll_list);
  11670. lpfc_sli4_start_polling(eq);
  11671. }
  11672. return 0;
  11673. }
  11674. static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node)
  11675. {
  11676. struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp);
  11677. struct lpfc_queue *eq, *next;
  11678. unsigned int n;
  11679. int retval;
  11680. if (!phba) {
  11681. WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id());
  11682. return 0;
  11683. }
  11684. if (__lpfc_cpuhp_checks(phba, &retval))
  11685. return retval;
  11686. lpfc_irq_rebalance(phba, cpu, false);
  11687. list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) {
  11688. n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ);
  11689. if (n == cpu)
  11690. lpfc_sli4_stop_polling(eq);
  11691. }
  11692. return 0;
  11693. }
  11694. /**
  11695. * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
  11696. * @phba: pointer to lpfc hba data structure.
  11697. *
  11698. * This routine is invoked to enable the MSI-X interrupt vectors to device
  11699. * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them
  11700. * to cpus on the system.
  11701. *
  11702. * When cfg_irq_numa is enabled, the adapter will only allocate vectors for
  11703. * the number of cpus on the same numa node as this adapter. The vectors are
  11704. * allocated without requesting OS affinity mapping. A vector will be
  11705. * allocated and assigned to each online and offline cpu. If the cpu is
  11706. * online, then affinity will be set to that cpu. If the cpu is offline, then
  11707. * affinity will be set to the nearest peer cpu within the numa node that is
  11708. * online. If there are no online cpus within the numa node, affinity is not
  11709. * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping
  11710. * is consistent with the way cpu online/offline is handled when cfg_irq_numa is
  11711. * configured.
  11712. *
  11713. * If numa mode is not enabled and there is more than 1 vector allocated, then
  11714. * the driver relies on the managed irq interface where the OS assigns vector to
  11715. * cpu affinity. The driver will then use that affinity mapping to setup its
  11716. * cpu mapping table.
  11717. *
  11718. * Return codes
  11719. * 0 - successful
  11720. * other values - error
  11721. **/
  11722. static int
  11723. lpfc_sli4_enable_msix(struct lpfc_hba *phba)
  11724. {
  11725. int vectors, rc, index;
  11726. char *name;
  11727. const struct cpumask *aff_mask = NULL;
  11728. unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids;
  11729. struct lpfc_vector_map_info *cpup;
  11730. struct lpfc_hba_eq_hdl *eqhdl;
  11731. const struct cpumask *maskp;
  11732. unsigned int flags = PCI_IRQ_MSIX;
  11733. /* Set up MSI-X multi-message vectors */
  11734. vectors = phba->cfg_irq_chann;
  11735. if (phba->irq_chann_mode != NORMAL_MODE)
  11736. aff_mask = &phba->sli4_hba.irq_aff_mask;
  11737. if (aff_mask) {
  11738. cpu_cnt = cpumask_weight(aff_mask);
  11739. vectors = min(phba->cfg_irq_chann, cpu_cnt);
  11740. /* cpu: iterates over aff_mask including offline or online
  11741. * cpu_select: iterates over online aff_mask to set affinity
  11742. */
  11743. cpu = cpumask_first(aff_mask);
  11744. cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
  11745. } else {
  11746. flags |= PCI_IRQ_AFFINITY;
  11747. }
  11748. rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags);
  11749. if (rc < 0) {
  11750. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11751. "0484 PCI enable MSI-X failed (%d)\n", rc);
  11752. goto vec_fail_out;
  11753. }
  11754. vectors = rc;
  11755. /* Assign MSI-X vectors to interrupt handlers */
  11756. for (index = 0; index < vectors; index++) {
  11757. eqhdl = lpfc_get_eq_hdl(index);
  11758. name = eqhdl->handler_name;
  11759. memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
  11760. snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
  11761. LPFC_DRIVER_HANDLER_NAME"%d", index);
  11762. eqhdl->idx = index;
  11763. rc = pci_irq_vector(phba->pcidev, index);
  11764. if (rc < 0) {
  11765. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  11766. "0489 MSI-X fast-path (%d) "
  11767. "pci_irq_vec failed (%d)\n", index, rc);
  11768. goto cfg_fail_out;
  11769. }
  11770. eqhdl->irq = rc;
  11771. rc = request_irq(eqhdl->irq, &lpfc_sli4_hba_intr_handler, 0,
  11772. name, eqhdl);
  11773. if (rc) {
  11774. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  11775. "0486 MSI-X fast-path (%d) "
  11776. "request_irq failed (%d)\n", index, rc);
  11777. goto cfg_fail_out;
  11778. }
  11779. if (aff_mask) {
  11780. /* If found a neighboring online cpu, set affinity */
  11781. if (cpu_select < nr_cpu_ids)
  11782. lpfc_irq_set_aff(eqhdl, cpu_select);
  11783. /* Assign EQ to cpu_map */
  11784. lpfc_assign_eq_map_info(phba, index,
  11785. LPFC_CPU_FIRST_IRQ,
  11786. cpu);
  11787. /* Iterate to next offline or online cpu in aff_mask */
  11788. cpu = cpumask_next(cpu, aff_mask);
  11789. /* Find next online cpu in aff_mask to set affinity */
  11790. cpu_select = lpfc_next_online_cpu(aff_mask, cpu);
  11791. } else if (vectors == 1) {
  11792. cpu = cpumask_first(cpu_present_mask);
  11793. lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ,
  11794. cpu);
  11795. } else {
  11796. maskp = pci_irq_get_affinity(phba->pcidev, index);
  11797. /* Loop through all CPUs associated with vector index */
  11798. for_each_cpu_and(cpu, maskp, cpu_present_mask) {
  11799. cpup = &phba->sli4_hba.cpu_map[cpu];
  11800. /* If this is the first CPU thats assigned to
  11801. * this vector, set LPFC_CPU_FIRST_IRQ.
  11802. *
  11803. * With certain platforms its possible that irq
  11804. * vectors are affinitized to all the cpu's.
  11805. * This can result in each cpu_map.eq to be set
  11806. * to the last vector, resulting in overwrite
  11807. * of all the previous cpu_map.eq. Ensure that
  11808. * each vector receives a place in cpu_map.
  11809. * Later call to lpfc_cpu_affinity_check will
  11810. * ensure we are nicely balanced out.
  11811. */
  11812. if (cpup->eq != LPFC_VECTOR_MAP_EMPTY)
  11813. continue;
  11814. lpfc_assign_eq_map_info(phba, index,
  11815. LPFC_CPU_FIRST_IRQ,
  11816. cpu);
  11817. break;
  11818. }
  11819. }
  11820. }
  11821. if (vectors != phba->cfg_irq_chann) {
  11822. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  11823. "3238 Reducing IO channels to match number of "
  11824. "MSI-X vectors, requested %d got %d\n",
  11825. phba->cfg_irq_chann, vectors);
  11826. if (phba->cfg_irq_chann > vectors)
  11827. phba->cfg_irq_chann = vectors;
  11828. }
  11829. return rc;
  11830. cfg_fail_out:
  11831. /* free the irq already requested */
  11832. for (--index; index >= 0; index--) {
  11833. eqhdl = lpfc_get_eq_hdl(index);
  11834. lpfc_irq_clear_aff(eqhdl);
  11835. free_irq(eqhdl->irq, eqhdl);
  11836. }
  11837. /* Unconfigure MSI-X capability structure */
  11838. pci_free_irq_vectors(phba->pcidev);
  11839. vec_fail_out:
  11840. return rc;
  11841. }
  11842. /**
  11843. * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
  11844. * @phba: pointer to lpfc hba data structure.
  11845. *
  11846. * This routine is invoked to enable the MSI interrupt mode to device with
  11847. * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is
  11848. * called to enable the MSI vector. The device driver is responsible for
  11849. * calling the request_irq() to register MSI vector with a interrupt the
  11850. * handler, which is done in this function.
  11851. *
  11852. * Return codes
  11853. * 0 - successful
  11854. * other values - error
  11855. **/
  11856. static int
  11857. lpfc_sli4_enable_msi(struct lpfc_hba *phba)
  11858. {
  11859. int rc, index;
  11860. unsigned int cpu;
  11861. struct lpfc_hba_eq_hdl *eqhdl;
  11862. rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1,
  11863. PCI_IRQ_MSI | PCI_IRQ_AFFINITY);
  11864. if (rc > 0)
  11865. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11866. "0487 PCI enable MSI mode success.\n");
  11867. else {
  11868. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11869. "0488 PCI enable MSI mode failed (%d)\n", rc);
  11870. return rc ? rc : -1;
  11871. }
  11872. rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  11873. 0, LPFC_DRIVER_NAME, phba);
  11874. if (rc) {
  11875. pci_free_irq_vectors(phba->pcidev);
  11876. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  11877. "0490 MSI request_irq failed (%d)\n", rc);
  11878. return rc;
  11879. }
  11880. eqhdl = lpfc_get_eq_hdl(0);
  11881. rc = pci_irq_vector(phba->pcidev, 0);
  11882. if (rc < 0) {
  11883. pci_free_irq_vectors(phba->pcidev);
  11884. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  11885. "0496 MSI pci_irq_vec failed (%d)\n", rc);
  11886. return rc;
  11887. }
  11888. eqhdl->irq = rc;
  11889. cpu = cpumask_first(cpu_present_mask);
  11890. lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu);
  11891. for (index = 0; index < phba->cfg_irq_chann; index++) {
  11892. eqhdl = lpfc_get_eq_hdl(index);
  11893. eqhdl->idx = index;
  11894. }
  11895. return 0;
  11896. }
  11897. /**
  11898. * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
  11899. * @phba: pointer to lpfc hba data structure.
  11900. * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X).
  11901. *
  11902. * This routine is invoked to enable device interrupt and associate driver's
  11903. * interrupt handler(s) to interrupt vector(s) to device with SLI-4
  11904. * interface spec. Depends on the interrupt mode configured to the driver,
  11905. * the driver will try to fallback from the configured interrupt mode to an
  11906. * interrupt mode which is supported by the platform, kernel, and device in
  11907. * the order of:
  11908. * MSI-X -> MSI -> IRQ.
  11909. *
  11910. * Return codes
  11911. * Interrupt mode (2, 1, 0) - successful
  11912. * LPFC_INTR_ERROR - error
  11913. **/
  11914. static uint32_t
  11915. lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  11916. {
  11917. uint32_t intr_mode = LPFC_INTR_ERROR;
  11918. int retval, idx;
  11919. if (cfg_mode == 2) {
  11920. /* Preparation before conf_msi mbox cmd */
  11921. retval = 0;
  11922. if (!retval) {
  11923. /* Now, try to enable MSI-X interrupt mode */
  11924. retval = lpfc_sli4_enable_msix(phba);
  11925. if (!retval) {
  11926. /* Indicate initialization to MSI-X mode */
  11927. phba->intr_type = MSIX;
  11928. intr_mode = 2;
  11929. }
  11930. }
  11931. }
  11932. /* Fallback to MSI if MSI-X initialization failed */
  11933. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  11934. retval = lpfc_sli4_enable_msi(phba);
  11935. if (!retval) {
  11936. /* Indicate initialization to MSI mode */
  11937. phba->intr_type = MSI;
  11938. intr_mode = 1;
  11939. }
  11940. }
  11941. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  11942. if (phba->intr_type == NONE) {
  11943. retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  11944. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  11945. if (!retval) {
  11946. struct lpfc_hba_eq_hdl *eqhdl;
  11947. unsigned int cpu;
  11948. /* Indicate initialization to INTx mode */
  11949. phba->intr_type = INTx;
  11950. intr_mode = 0;
  11951. eqhdl = lpfc_get_eq_hdl(0);
  11952. retval = pci_irq_vector(phba->pcidev, 0);
  11953. if (retval < 0) {
  11954. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  11955. "0502 INTR pci_irq_vec failed (%d)\n",
  11956. retval);
  11957. return LPFC_INTR_ERROR;
  11958. }
  11959. eqhdl->irq = retval;
  11960. cpu = cpumask_first(cpu_present_mask);
  11961. lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ,
  11962. cpu);
  11963. for (idx = 0; idx < phba->cfg_irq_chann; idx++) {
  11964. eqhdl = lpfc_get_eq_hdl(idx);
  11965. eqhdl->idx = idx;
  11966. }
  11967. }
  11968. }
  11969. return intr_mode;
  11970. }
  11971. /**
  11972. * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
  11973. * @phba: pointer to lpfc hba data structure.
  11974. *
  11975. * This routine is invoked to disable device interrupt and disassociate
  11976. * the driver's interrupt handler(s) from interrupt vector(s) to device
  11977. * with SLI-4 interface spec. Depending on the interrupt mode, the driver
  11978. * will release the interrupt vector(s) for the message signaled interrupt.
  11979. **/
  11980. static void
  11981. lpfc_sli4_disable_intr(struct lpfc_hba *phba)
  11982. {
  11983. /* Disable the currently initialized interrupt mode */
  11984. if (phba->intr_type == MSIX) {
  11985. int index;
  11986. struct lpfc_hba_eq_hdl *eqhdl;
  11987. /* Free up MSI-X multi-message vectors */
  11988. for (index = 0; index < phba->cfg_irq_chann; index++) {
  11989. eqhdl = lpfc_get_eq_hdl(index);
  11990. lpfc_irq_clear_aff(eqhdl);
  11991. free_irq(eqhdl->irq, eqhdl);
  11992. }
  11993. } else {
  11994. free_irq(phba->pcidev->irq, phba);
  11995. }
  11996. pci_free_irq_vectors(phba->pcidev);
  11997. /* Reset interrupt management states */
  11998. phba->intr_type = NONE;
  11999. phba->sli.slistat.sli_intr = 0;
  12000. }
  12001. /**
  12002. * lpfc_unset_hba - Unset SLI3 hba device initialization
  12003. * @phba: pointer to lpfc hba data structure.
  12004. *
  12005. * This routine is invoked to unset the HBA device initialization steps to
  12006. * a device with SLI-3 interface spec.
  12007. **/
  12008. static void
  12009. lpfc_unset_hba(struct lpfc_hba *phba)
  12010. {
  12011. struct lpfc_vport *vport = phba->pport;
  12012. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  12013. spin_lock_irq(shost->host_lock);
  12014. vport->load_flag |= FC_UNLOADING;
  12015. spin_unlock_irq(shost->host_lock);
  12016. kfree(phba->vpi_bmask);
  12017. kfree(phba->vpi_ids);
  12018. lpfc_stop_hba_timers(phba);
  12019. phba->pport->work_port_events = 0;
  12020. lpfc_sli_hba_down(phba);
  12021. lpfc_sli_brdrestart(phba);
  12022. lpfc_sli_disable_intr(phba);
  12023. return;
  12024. }
  12025. /**
  12026. * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
  12027. * @phba: Pointer to HBA context object.
  12028. *
  12029. * This function is called in the SLI4 code path to wait for completion
  12030. * of device's XRIs exchange busy. It will check the XRI exchange busy
  12031. * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
  12032. * that, it will check the XRI exchange busy on outstanding FCP and ELS
  12033. * I/Os every 30 seconds, log error message, and wait forever. Only when
  12034. * all XRI exchange busy complete, the driver unload shall proceed with
  12035. * invoking the function reset ioctl mailbox command to the CNA and the
  12036. * the rest of the driver unload resource release.
  12037. **/
  12038. static void
  12039. lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
  12040. {
  12041. struct lpfc_sli4_hdw_queue *qp;
  12042. int idx, ccnt;
  12043. int wait_time = 0;
  12044. int io_xri_cmpl = 1;
  12045. int nvmet_xri_cmpl = 1;
  12046. int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  12047. /* Driver just aborted IOs during the hba_unset process. Pause
  12048. * here to give the HBA time to complete the IO and get entries
  12049. * into the abts lists.
  12050. */
  12051. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
  12052. /* Wait for NVME pending IO to flush back to transport. */
  12053. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
  12054. lpfc_nvme_wait_for_io_drain(phba);
  12055. ccnt = 0;
  12056. for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
  12057. qp = &phba->sli4_hba.hdwq[idx];
  12058. io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list);
  12059. if (!io_xri_cmpl) /* if list is NOT empty */
  12060. ccnt++;
  12061. }
  12062. if (ccnt)
  12063. io_xri_cmpl = 0;
  12064. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  12065. nvmet_xri_cmpl =
  12066. list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
  12067. }
  12068. while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) {
  12069. if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
  12070. if (!nvmet_xri_cmpl)
  12071. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12072. "6424 NVMET XRI exchange busy "
  12073. "wait time: %d seconds.\n",
  12074. wait_time/1000);
  12075. if (!io_xri_cmpl)
  12076. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12077. "6100 IO XRI exchange busy "
  12078. "wait time: %d seconds.\n",
  12079. wait_time/1000);
  12080. if (!els_xri_cmpl)
  12081. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12082. "2878 ELS XRI exchange busy "
  12083. "wait time: %d seconds.\n",
  12084. wait_time/1000);
  12085. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
  12086. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
  12087. } else {
  12088. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
  12089. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
  12090. }
  12091. ccnt = 0;
  12092. for (idx = 0; idx < phba->cfg_hdw_queue; idx++) {
  12093. qp = &phba->sli4_hba.hdwq[idx];
  12094. io_xri_cmpl = list_empty(
  12095. &qp->lpfc_abts_io_buf_list);
  12096. if (!io_xri_cmpl) /* if list is NOT empty */
  12097. ccnt++;
  12098. }
  12099. if (ccnt)
  12100. io_xri_cmpl = 0;
  12101. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  12102. nvmet_xri_cmpl = list_empty(
  12103. &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
  12104. }
  12105. els_xri_cmpl =
  12106. list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  12107. }
  12108. }
  12109. /**
  12110. * lpfc_sli4_hba_unset - Unset the fcoe hba
  12111. * @phba: Pointer to HBA context object.
  12112. *
  12113. * This function is called in the SLI4 code path to reset the HBA's FCoE
  12114. * function. The caller is not required to hold any lock. This routine
  12115. * issues PCI function reset mailbox command to reset the FCoE function.
  12116. * At the end of the function, it calls lpfc_hba_down_post function to
  12117. * free any pending commands.
  12118. **/
  12119. static void
  12120. lpfc_sli4_hba_unset(struct lpfc_hba *phba)
  12121. {
  12122. int wait_cnt = 0;
  12123. LPFC_MBOXQ_t *mboxq;
  12124. struct pci_dev *pdev = phba->pcidev;
  12125. lpfc_stop_hba_timers(phba);
  12126. hrtimer_cancel(&phba->cmf_timer);
  12127. if (phba->pport)
  12128. phba->sli4_hba.intr_enable = 0;
  12129. /*
  12130. * Gracefully wait out the potential current outstanding asynchronous
  12131. * mailbox command.
  12132. */
  12133. /* First, block any pending async mailbox command from posted */
  12134. spin_lock_irq(&phba->hbalock);
  12135. phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  12136. spin_unlock_irq(&phba->hbalock);
  12137. /* Now, trying to wait it out if we can */
  12138. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  12139. msleep(10);
  12140. if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
  12141. break;
  12142. }
  12143. /* Forcefully release the outstanding mailbox command if timed out */
  12144. if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  12145. spin_lock_irq(&phba->hbalock);
  12146. mboxq = phba->sli.mbox_active;
  12147. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  12148. __lpfc_mbox_cmpl_put(phba, mboxq);
  12149. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  12150. phba->sli.mbox_active = NULL;
  12151. spin_unlock_irq(&phba->hbalock);
  12152. }
  12153. /* Abort all iocbs associated with the hba */
  12154. lpfc_sli_hba_iocb_abort(phba);
  12155. if (!pci_channel_offline(phba->pcidev))
  12156. /* Wait for completion of device XRI exchange busy */
  12157. lpfc_sli4_xri_exchange_busy_wait(phba);
  12158. /* per-phba callback de-registration for hotplug event */
  12159. if (phba->pport)
  12160. lpfc_cpuhp_remove(phba);
  12161. /* Disable PCI subsystem interrupt */
  12162. lpfc_sli4_disable_intr(phba);
  12163. /* Disable SR-IOV if enabled */
  12164. if (phba->cfg_sriov_nr_virtfn)
  12165. pci_disable_sriov(pdev);
  12166. /* Stop kthread signal shall trigger work_done one more time */
  12167. kthread_stop(phba->worker_thread);
  12168. /* Disable FW logging to host memory */
  12169. lpfc_ras_stop_fwlog(phba);
  12170. /* Reset SLI4 HBA FCoE function */
  12171. lpfc_pci_function_reset(phba);
  12172. /* release all queue allocated resources. */
  12173. lpfc_sli4_queue_destroy(phba);
  12174. /* Free RAS DMA memory */
  12175. if (phba->ras_fwlog.ras_enabled)
  12176. lpfc_sli4_ras_dma_free(phba);
  12177. /* Stop the SLI4 device port */
  12178. if (phba->pport)
  12179. phba->pport->work_port_events = 0;
  12180. }
  12181. static uint32_t
  12182. lpfc_cgn_crc32(uint32_t crc, u8 byte)
  12183. {
  12184. uint32_t msb = 0;
  12185. uint32_t bit;
  12186. for (bit = 0; bit < 8; bit++) {
  12187. msb = (crc >> 31) & 1;
  12188. crc <<= 1;
  12189. if (msb ^ (byte & 1)) {
  12190. crc ^= LPFC_CGN_CRC32_MAGIC_NUMBER;
  12191. crc |= 1;
  12192. }
  12193. byte >>= 1;
  12194. }
  12195. return crc;
  12196. }
  12197. static uint32_t
  12198. lpfc_cgn_reverse_bits(uint32_t wd)
  12199. {
  12200. uint32_t result = 0;
  12201. uint32_t i;
  12202. for (i = 0; i < 32; i++) {
  12203. result <<= 1;
  12204. result |= (1 & (wd >> i));
  12205. }
  12206. return result;
  12207. }
  12208. /*
  12209. * The routine corresponds with the algorithm the HBA firmware
  12210. * uses to validate the data integrity.
  12211. */
  12212. uint32_t
  12213. lpfc_cgn_calc_crc32(void *ptr, uint32_t byteLen, uint32_t crc)
  12214. {
  12215. uint32_t i;
  12216. uint32_t result;
  12217. uint8_t *data = (uint8_t *)ptr;
  12218. for (i = 0; i < byteLen; ++i)
  12219. crc = lpfc_cgn_crc32(crc, data[i]);
  12220. result = ~lpfc_cgn_reverse_bits(crc);
  12221. return result;
  12222. }
  12223. void
  12224. lpfc_init_congestion_buf(struct lpfc_hba *phba)
  12225. {
  12226. struct lpfc_cgn_info *cp;
  12227. struct timespec64 cmpl_time;
  12228. struct tm broken;
  12229. uint16_t size;
  12230. uint32_t crc;
  12231. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  12232. "6235 INIT Congestion Buffer %p\n", phba->cgn_i);
  12233. if (!phba->cgn_i)
  12234. return;
  12235. cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
  12236. atomic_set(&phba->cgn_fabric_warn_cnt, 0);
  12237. atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
  12238. atomic_set(&phba->cgn_sync_alarm_cnt, 0);
  12239. atomic_set(&phba->cgn_sync_warn_cnt, 0);
  12240. atomic_set(&phba->cgn_driver_evt_cnt, 0);
  12241. atomic_set(&phba->cgn_latency_evt_cnt, 0);
  12242. atomic64_set(&phba->cgn_latency_evt, 0);
  12243. phba->cgn_evt_minute = 0;
  12244. phba->hba_flag &= ~HBA_CGN_DAY_WRAP;
  12245. memset(cp, 0xff, offsetof(struct lpfc_cgn_info, cgn_stat));
  12246. cp->cgn_info_size = cpu_to_le16(LPFC_CGN_INFO_SZ);
  12247. cp->cgn_info_version = LPFC_CGN_INFO_V3;
  12248. /* cgn parameters */
  12249. cp->cgn_info_mode = phba->cgn_p.cgn_param_mode;
  12250. cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
  12251. cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
  12252. cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
  12253. ktime_get_real_ts64(&cmpl_time);
  12254. time64_to_tm(cmpl_time.tv_sec, 0, &broken);
  12255. cp->cgn_info_month = broken.tm_mon + 1;
  12256. cp->cgn_info_day = broken.tm_mday;
  12257. cp->cgn_info_year = broken.tm_year - 100; /* relative to 2000 */
  12258. cp->cgn_info_hour = broken.tm_hour;
  12259. cp->cgn_info_minute = broken.tm_min;
  12260. cp->cgn_info_second = broken.tm_sec;
  12261. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
  12262. "2643 CGNInfo Init: Start Time "
  12263. "%d/%d/%d %d:%d:%d\n",
  12264. cp->cgn_info_day, cp->cgn_info_month,
  12265. cp->cgn_info_year, cp->cgn_info_hour,
  12266. cp->cgn_info_minute, cp->cgn_info_second);
  12267. /* Fill in default LUN qdepth */
  12268. if (phba->pport) {
  12269. size = (uint16_t)(phba->pport->cfg_lun_queue_depth);
  12270. cp->cgn_lunq = cpu_to_le16(size);
  12271. }
  12272. /* last used Index initialized to 0xff already */
  12273. cp->cgn_warn_freq = cpu_to_le16(LPFC_FPIN_INIT_FREQ);
  12274. cp->cgn_alarm_freq = cpu_to_le16(LPFC_FPIN_INIT_FREQ);
  12275. crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
  12276. cp->cgn_info_crc = cpu_to_le32(crc);
  12277. phba->cgn_evt_timestamp = jiffies +
  12278. msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN);
  12279. }
  12280. void
  12281. lpfc_init_congestion_stat(struct lpfc_hba *phba)
  12282. {
  12283. struct lpfc_cgn_info *cp;
  12284. struct timespec64 cmpl_time;
  12285. struct tm broken;
  12286. uint32_t crc;
  12287. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  12288. "6236 INIT Congestion Stat %p\n", phba->cgn_i);
  12289. if (!phba->cgn_i)
  12290. return;
  12291. cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
  12292. memset(&cp->cgn_stat, 0, sizeof(cp->cgn_stat));
  12293. ktime_get_real_ts64(&cmpl_time);
  12294. time64_to_tm(cmpl_time.tv_sec, 0, &broken);
  12295. cp->cgn_stat_month = broken.tm_mon + 1;
  12296. cp->cgn_stat_day = broken.tm_mday;
  12297. cp->cgn_stat_year = broken.tm_year - 100; /* relative to 2000 */
  12298. cp->cgn_stat_hour = broken.tm_hour;
  12299. cp->cgn_stat_minute = broken.tm_min;
  12300. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT,
  12301. "2647 CGNstat Init: Start Time "
  12302. "%d/%d/%d %d:%d\n",
  12303. cp->cgn_stat_day, cp->cgn_stat_month,
  12304. cp->cgn_stat_year, cp->cgn_stat_hour,
  12305. cp->cgn_stat_minute);
  12306. crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
  12307. cp->cgn_info_crc = cpu_to_le32(crc);
  12308. }
  12309. /**
  12310. * __lpfc_reg_congestion_buf - register congestion info buffer with HBA
  12311. * @phba: Pointer to hba context object.
  12312. * @reg: flag to determine register or unregister.
  12313. */
  12314. static int
  12315. __lpfc_reg_congestion_buf(struct lpfc_hba *phba, int reg)
  12316. {
  12317. struct lpfc_mbx_reg_congestion_buf *reg_congestion_buf;
  12318. union lpfc_sli4_cfg_shdr *shdr;
  12319. uint32_t shdr_status, shdr_add_status;
  12320. LPFC_MBOXQ_t *mboxq;
  12321. int length, rc;
  12322. if (!phba->cgn_i)
  12323. return -ENXIO;
  12324. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12325. if (!mboxq) {
  12326. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  12327. "2641 REG_CONGESTION_BUF mbox allocation fail: "
  12328. "HBA state x%x reg %d\n",
  12329. phba->pport->port_state, reg);
  12330. return -ENOMEM;
  12331. }
  12332. length = (sizeof(struct lpfc_mbx_reg_congestion_buf) -
  12333. sizeof(struct lpfc_sli4_cfg_mhdr));
  12334. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  12335. LPFC_MBOX_OPCODE_REG_CONGESTION_BUF, length,
  12336. LPFC_SLI4_MBX_EMBED);
  12337. reg_congestion_buf = &mboxq->u.mqe.un.reg_congestion_buf;
  12338. bf_set(lpfc_mbx_reg_cgn_buf_type, reg_congestion_buf, 1);
  12339. if (reg > 0)
  12340. bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 1);
  12341. else
  12342. bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 0);
  12343. reg_congestion_buf->length = sizeof(struct lpfc_cgn_info);
  12344. reg_congestion_buf->addr_lo =
  12345. putPaddrLow(phba->cgn_i->phys);
  12346. reg_congestion_buf->addr_hi =
  12347. putPaddrHigh(phba->cgn_i->phys);
  12348. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  12349. shdr = (union lpfc_sli4_cfg_shdr *)
  12350. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  12351. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12352. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  12353. &shdr->response);
  12354. mempool_free(mboxq, phba->mbox_mem_pool);
  12355. if (shdr_status || shdr_add_status || rc) {
  12356. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12357. "2642 REG_CONGESTION_BUF mailbox "
  12358. "failed with status x%x add_status x%x,"
  12359. " mbx status x%x reg %d\n",
  12360. shdr_status, shdr_add_status, rc, reg);
  12361. return -ENXIO;
  12362. }
  12363. return 0;
  12364. }
  12365. int
  12366. lpfc_unreg_congestion_buf(struct lpfc_hba *phba)
  12367. {
  12368. lpfc_cmf_stop(phba);
  12369. return __lpfc_reg_congestion_buf(phba, 0);
  12370. }
  12371. int
  12372. lpfc_reg_congestion_buf(struct lpfc_hba *phba)
  12373. {
  12374. return __lpfc_reg_congestion_buf(phba, 1);
  12375. }
  12376. /**
  12377. * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
  12378. * @phba: Pointer to HBA context object.
  12379. * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
  12380. *
  12381. * This function is called in the SLI4 code path to read the port's
  12382. * sli4 capabilities.
  12383. *
  12384. * This function may be be called from any context that can block-wait
  12385. * for the completion. The expectation is that this routine is called
  12386. * typically from probe_one or from the online routine.
  12387. **/
  12388. int
  12389. lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  12390. {
  12391. int rc;
  12392. struct lpfc_mqe *mqe = &mboxq->u.mqe;
  12393. struct lpfc_pc_sli4_params *sli4_params;
  12394. uint32_t mbox_tmo;
  12395. int length;
  12396. bool exp_wqcq_pages = true;
  12397. struct lpfc_sli4_parameters *mbx_sli4_parameters;
  12398. /*
  12399. * By default, the driver assumes the SLI4 port requires RPI
  12400. * header postings. The SLI4_PARAM response will correct this
  12401. * assumption.
  12402. */
  12403. phba->sli4_hba.rpi_hdrs_in_use = 1;
  12404. /* Read the port's SLI4 Config Parameters */
  12405. length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
  12406. sizeof(struct lpfc_sli4_cfg_mhdr));
  12407. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  12408. LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
  12409. length, LPFC_SLI4_MBX_EMBED);
  12410. if (!phba->sli4_hba.intr_enable)
  12411. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  12412. else {
  12413. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  12414. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  12415. }
  12416. if (unlikely(rc))
  12417. return rc;
  12418. sli4_params = &phba->sli4_hba.pc_sli4_params;
  12419. mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
  12420. sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
  12421. sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
  12422. sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
  12423. sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
  12424. mbx_sli4_parameters);
  12425. sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
  12426. mbx_sli4_parameters);
  12427. if (bf_get(cfg_phwq, mbx_sli4_parameters))
  12428. phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
  12429. else
  12430. phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
  12431. sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
  12432. sli4_params->loopbk_scope = bf_get(cfg_loopbk_scope,
  12433. mbx_sli4_parameters);
  12434. sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
  12435. sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
  12436. sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
  12437. sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
  12438. sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
  12439. sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
  12440. sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
  12441. sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
  12442. sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
  12443. sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters);
  12444. sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
  12445. mbx_sli4_parameters);
  12446. sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
  12447. sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
  12448. mbx_sli4_parameters);
  12449. phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
  12450. phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
  12451. /* Check for Extended Pre-Registered SGL support */
  12452. phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters);
  12453. /* Check for firmware nvme support */
  12454. rc = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
  12455. bf_get(cfg_xib, mbx_sli4_parameters));
  12456. if (rc) {
  12457. /* Save this to indicate the Firmware supports NVME */
  12458. sli4_params->nvme = 1;
  12459. /* Firmware NVME support, check driver FC4 NVME support */
  12460. if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) {
  12461. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
  12462. "6133 Disabling NVME support: "
  12463. "FC4 type not supported: x%x\n",
  12464. phba->cfg_enable_fc4_type);
  12465. goto fcponly;
  12466. }
  12467. } else {
  12468. /* No firmware NVME support, check driver FC4 NVME support */
  12469. sli4_params->nvme = 0;
  12470. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  12471. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
  12472. "6101 Disabling NVME support: Not "
  12473. "supported by firmware (%d %d) x%x\n",
  12474. bf_get(cfg_nvme, mbx_sli4_parameters),
  12475. bf_get(cfg_xib, mbx_sli4_parameters),
  12476. phba->cfg_enable_fc4_type);
  12477. fcponly:
  12478. phba->nvmet_support = 0;
  12479. phba->cfg_nvmet_mrq = 0;
  12480. phba->cfg_nvme_seg_cnt = 0;
  12481. /* If no FC4 type support, move to just SCSI support */
  12482. if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
  12483. return -ENODEV;
  12484. phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
  12485. }
  12486. }
  12487. /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
  12488. * accommodate 512K and 1M IOs in a single nvme buf.
  12489. */
  12490. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
  12491. phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
  12492. /* Enable embedded Payload BDE if support is indicated */
  12493. if (bf_get(cfg_pbde, mbx_sli4_parameters))
  12494. phba->cfg_enable_pbde = 1;
  12495. else
  12496. phba->cfg_enable_pbde = 0;
  12497. /*
  12498. * To support Suppress Response feature we must satisfy 3 conditions.
  12499. * lpfc_suppress_rsp module parameter must be set (default).
  12500. * In SLI4-Parameters Descriptor:
  12501. * Extended Inline Buffers (XIB) must be supported.
  12502. * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
  12503. * (double negative).
  12504. */
  12505. if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
  12506. !(bf_get(cfg_nosr, mbx_sli4_parameters)))
  12507. phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
  12508. else
  12509. phba->cfg_suppress_rsp = 0;
  12510. if (bf_get(cfg_eqdr, mbx_sli4_parameters))
  12511. phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
  12512. /* Make sure that sge_supp_len can be handled by the driver */
  12513. if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
  12514. sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
  12515. /*
  12516. * Check whether the adapter supports an embedded copy of the
  12517. * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
  12518. * to use this option, 128-byte WQEs must be used.
  12519. */
  12520. if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
  12521. phba->fcp_embed_io = 1;
  12522. else
  12523. phba->fcp_embed_io = 0;
  12524. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
  12525. "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
  12526. bf_get(cfg_xib, mbx_sli4_parameters),
  12527. phba->cfg_enable_pbde,
  12528. phba->fcp_embed_io, sli4_params->nvme,
  12529. phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
  12530. if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  12531. LPFC_SLI_INTF_IF_TYPE_2) &&
  12532. (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
  12533. LPFC_SLI_INTF_FAMILY_LNCR_A0))
  12534. exp_wqcq_pages = false;
  12535. if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
  12536. (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
  12537. exp_wqcq_pages &&
  12538. (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
  12539. phba->enab_exp_wqcq_pages = 1;
  12540. else
  12541. phba->enab_exp_wqcq_pages = 0;
  12542. /*
  12543. * Check if the SLI port supports MDS Diagnostics
  12544. */
  12545. if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
  12546. phba->mds_diags_support = 1;
  12547. else
  12548. phba->mds_diags_support = 0;
  12549. /*
  12550. * Check if the SLI port supports NSLER
  12551. */
  12552. if (bf_get(cfg_nsler, mbx_sli4_parameters))
  12553. phba->nsler = 1;
  12554. else
  12555. phba->nsler = 0;
  12556. return 0;
  12557. }
  12558. /**
  12559. * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
  12560. * @pdev: pointer to PCI device
  12561. * @pid: pointer to PCI device identifier
  12562. *
  12563. * This routine is to be called to attach a device with SLI-3 interface spec
  12564. * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  12565. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  12566. * information of the device and driver to see if the driver state that it can
  12567. * support this kind of device. If the match is successful, the driver core
  12568. * invokes this routine. If this routine determines it can claim the HBA, it
  12569. * does all the initialization that it needs to do to handle the HBA properly.
  12570. *
  12571. * Return code
  12572. * 0 - driver can claim the device
  12573. * negative value - driver can not claim the device
  12574. **/
  12575. static int
  12576. lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
  12577. {
  12578. struct lpfc_hba *phba;
  12579. struct lpfc_vport *vport = NULL;
  12580. struct Scsi_Host *shost = NULL;
  12581. int error;
  12582. uint32_t cfg_mode, intr_mode;
  12583. /* Allocate memory for HBA structure */
  12584. phba = lpfc_hba_alloc(pdev);
  12585. if (!phba)
  12586. return -ENOMEM;
  12587. /* Perform generic PCI device enabling operation */
  12588. error = lpfc_enable_pci_dev(phba);
  12589. if (error)
  12590. goto out_free_phba;
  12591. /* Set up SLI API function jump table for PCI-device group-0 HBAs */
  12592. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
  12593. if (error)
  12594. goto out_disable_pci_dev;
  12595. /* Set up SLI-3 specific device PCI memory space */
  12596. error = lpfc_sli_pci_mem_setup(phba);
  12597. if (error) {
  12598. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12599. "1402 Failed to set up pci memory space.\n");
  12600. goto out_disable_pci_dev;
  12601. }
  12602. /* Set up SLI-3 specific device driver resources */
  12603. error = lpfc_sli_driver_resource_setup(phba);
  12604. if (error) {
  12605. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12606. "1404 Failed to set up driver resource.\n");
  12607. goto out_unset_pci_mem_s3;
  12608. }
  12609. /* Initialize and populate the iocb list per host */
  12610. error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
  12611. if (error) {
  12612. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12613. "1405 Failed to initialize iocb list.\n");
  12614. goto out_unset_driver_resource_s3;
  12615. }
  12616. /* Set up common device driver resources */
  12617. error = lpfc_setup_driver_resource_phase2(phba);
  12618. if (error) {
  12619. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12620. "1406 Failed to set up driver resource.\n");
  12621. goto out_free_iocb_list;
  12622. }
  12623. /* Get the default values for Model Name and Description */
  12624. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  12625. /* Create SCSI host to the physical port */
  12626. error = lpfc_create_shost(phba);
  12627. if (error) {
  12628. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12629. "1407 Failed to create scsi host.\n");
  12630. goto out_unset_driver_resource;
  12631. }
  12632. /* Configure sysfs attributes */
  12633. vport = phba->pport;
  12634. error = lpfc_alloc_sysfs_attr(vport);
  12635. if (error) {
  12636. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12637. "1476 Failed to allocate sysfs attr\n");
  12638. goto out_destroy_shost;
  12639. }
  12640. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  12641. /* Now, trying to enable interrupt and bring up the device */
  12642. cfg_mode = phba->cfg_use_msi;
  12643. while (true) {
  12644. /* Put device to a known state before enabling interrupt */
  12645. lpfc_stop_port(phba);
  12646. /* Configure and enable interrupt */
  12647. intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
  12648. if (intr_mode == LPFC_INTR_ERROR) {
  12649. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12650. "0431 Failed to enable interrupt.\n");
  12651. error = -ENODEV;
  12652. goto out_free_sysfs_attr;
  12653. }
  12654. /* SLI-3 HBA setup */
  12655. if (lpfc_sli_hba_setup(phba)) {
  12656. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12657. "1477 Failed to set up hba\n");
  12658. error = -ENODEV;
  12659. goto out_remove_device;
  12660. }
  12661. /* Wait 50ms for the interrupts of previous mailbox commands */
  12662. msleep(50);
  12663. /* Check active interrupts on message signaled interrupts */
  12664. if (intr_mode == 0 ||
  12665. phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
  12666. /* Log the current active interrupt mode */
  12667. phba->intr_mode = intr_mode;
  12668. lpfc_log_intr_mode(phba, intr_mode);
  12669. break;
  12670. } else {
  12671. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12672. "0447 Configure interrupt mode (%d) "
  12673. "failed active interrupt test.\n",
  12674. intr_mode);
  12675. /* Disable the current interrupt mode */
  12676. lpfc_sli_disable_intr(phba);
  12677. /* Try next level of interrupt mode */
  12678. cfg_mode = --intr_mode;
  12679. }
  12680. }
  12681. /* Perform post initialization setup */
  12682. lpfc_post_init_setup(phba);
  12683. /* Check if there are static vports to be created. */
  12684. lpfc_create_static_vport(phba);
  12685. return 0;
  12686. out_remove_device:
  12687. lpfc_unset_hba(phba);
  12688. out_free_sysfs_attr:
  12689. lpfc_free_sysfs_attr(vport);
  12690. out_destroy_shost:
  12691. lpfc_destroy_shost(phba);
  12692. out_unset_driver_resource:
  12693. lpfc_unset_driver_resource_phase2(phba);
  12694. out_free_iocb_list:
  12695. lpfc_free_iocb_list(phba);
  12696. out_unset_driver_resource_s3:
  12697. lpfc_sli_driver_resource_unset(phba);
  12698. out_unset_pci_mem_s3:
  12699. lpfc_sli_pci_mem_unset(phba);
  12700. out_disable_pci_dev:
  12701. lpfc_disable_pci_dev(phba);
  12702. if (shost)
  12703. scsi_host_put(shost);
  12704. out_free_phba:
  12705. lpfc_hba_free(phba);
  12706. return error;
  12707. }
  12708. /**
  12709. * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
  12710. * @pdev: pointer to PCI device
  12711. *
  12712. * This routine is to be called to disattach a device with SLI-3 interface
  12713. * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  12714. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  12715. * device to be removed from the PCI subsystem properly.
  12716. **/
  12717. static void
  12718. lpfc_pci_remove_one_s3(struct pci_dev *pdev)
  12719. {
  12720. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  12721. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  12722. struct lpfc_vport **vports;
  12723. struct lpfc_hba *phba = vport->phba;
  12724. int i;
  12725. spin_lock_irq(&phba->hbalock);
  12726. vport->load_flag |= FC_UNLOADING;
  12727. spin_unlock_irq(&phba->hbalock);
  12728. lpfc_free_sysfs_attr(vport);
  12729. /* Release all the vports against this physical port */
  12730. vports = lpfc_create_vport_work_array(phba);
  12731. if (vports != NULL)
  12732. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  12733. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  12734. continue;
  12735. fc_vport_terminate(vports[i]->fc_vport);
  12736. }
  12737. lpfc_destroy_vport_work_array(phba, vports);
  12738. /* Remove FC host with the physical port */
  12739. fc_remove_host(shost);
  12740. scsi_remove_host(shost);
  12741. /* Clean up all nodes, mailboxes and IOs. */
  12742. lpfc_cleanup(vport);
  12743. /*
  12744. * Bring down the SLI Layer. This step disable all interrupts,
  12745. * clears the rings, discards all mailbox commands, and resets
  12746. * the HBA.
  12747. */
  12748. /* HBA interrupt will be disabled after this call */
  12749. lpfc_sli_hba_down(phba);
  12750. /* Stop kthread signal shall trigger work_done one more time */
  12751. kthread_stop(phba->worker_thread);
  12752. /* Final cleanup of txcmplq and reset the HBA */
  12753. lpfc_sli_brdrestart(phba);
  12754. kfree(phba->vpi_bmask);
  12755. kfree(phba->vpi_ids);
  12756. lpfc_stop_hba_timers(phba);
  12757. spin_lock_irq(&phba->port_list_lock);
  12758. list_del_init(&vport->listentry);
  12759. spin_unlock_irq(&phba->port_list_lock);
  12760. lpfc_debugfs_terminate(vport);
  12761. /* Disable SR-IOV if enabled */
  12762. if (phba->cfg_sriov_nr_virtfn)
  12763. pci_disable_sriov(pdev);
  12764. /* Disable interrupt */
  12765. lpfc_sli_disable_intr(phba);
  12766. scsi_host_put(shost);
  12767. /*
  12768. * Call scsi_free before mem_free since scsi bufs are released to their
  12769. * corresponding pools here.
  12770. */
  12771. lpfc_scsi_free(phba);
  12772. lpfc_free_iocb_list(phba);
  12773. lpfc_mem_free_all(phba);
  12774. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  12775. phba->hbqslimp.virt, phba->hbqslimp.phys);
  12776. /* Free resources associated with SLI2 interface */
  12777. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  12778. phba->slim2p.virt, phba->slim2p.phys);
  12779. /* unmap adapter SLIM and Control Registers */
  12780. iounmap(phba->ctrl_regs_memmap_p);
  12781. iounmap(phba->slim_memmap_p);
  12782. lpfc_hba_free(phba);
  12783. pci_release_mem_regions(pdev);
  12784. pci_disable_device(pdev);
  12785. }
  12786. /**
  12787. * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
  12788. * @dev_d: pointer to device
  12789. *
  12790. * This routine is to be called from the kernel's PCI subsystem to support
  12791. * system Power Management (PM) to device with SLI-3 interface spec. When
  12792. * PM invokes this method, it quiesces the device by stopping the driver's
  12793. * worker thread for the device, turning off device's interrupt and DMA,
  12794. * and bring the device offline. Note that as the driver implements the
  12795. * minimum PM requirements to a power-aware driver's PM support for the
  12796. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  12797. * to the suspend() method call will be treated as SUSPEND and the driver will
  12798. * fully reinitialize its device during resume() method call, the driver will
  12799. * set device to PCI_D3hot state in PCI config space instead of setting it
  12800. * according to the @msg provided by the PM.
  12801. *
  12802. * Return code
  12803. * 0 - driver suspended the device
  12804. * Error otherwise
  12805. **/
  12806. static int __maybe_unused
  12807. lpfc_pci_suspend_one_s3(struct device *dev_d)
  12808. {
  12809. struct Scsi_Host *shost = dev_get_drvdata(dev_d);
  12810. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  12811. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12812. "0473 PCI device Power Management suspend.\n");
  12813. /* Bring down the device */
  12814. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  12815. lpfc_offline(phba);
  12816. kthread_stop(phba->worker_thread);
  12817. /* Disable interrupt from device */
  12818. lpfc_sli_disable_intr(phba);
  12819. return 0;
  12820. }
  12821. /**
  12822. * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
  12823. * @dev_d: pointer to device
  12824. *
  12825. * This routine is to be called from the kernel's PCI subsystem to support
  12826. * system Power Management (PM) to device with SLI-3 interface spec. When PM
  12827. * invokes this method, it restores the device's PCI config space state and
  12828. * fully reinitializes the device and brings it online. Note that as the
  12829. * driver implements the minimum PM requirements to a power-aware driver's
  12830. * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
  12831. * FREEZE) to the suspend() method call will be treated as SUSPEND and the
  12832. * driver will fully reinitialize its device during resume() method call,
  12833. * the device will be set to PCI_D0 directly in PCI config space before
  12834. * restoring the state.
  12835. *
  12836. * Return code
  12837. * 0 - driver suspended the device
  12838. * Error otherwise
  12839. **/
  12840. static int __maybe_unused
  12841. lpfc_pci_resume_one_s3(struct device *dev_d)
  12842. {
  12843. struct Scsi_Host *shost = dev_get_drvdata(dev_d);
  12844. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  12845. uint32_t intr_mode;
  12846. int error;
  12847. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12848. "0452 PCI device Power Management resume.\n");
  12849. /* Startup the kernel thread for this host adapter. */
  12850. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  12851. "lpfc_worker_%d", phba->brd_no);
  12852. if (IS_ERR(phba->worker_thread)) {
  12853. error = PTR_ERR(phba->worker_thread);
  12854. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12855. "0434 PM resume failed to start worker "
  12856. "thread: error=x%x.\n", error);
  12857. return error;
  12858. }
  12859. /* Init cpu_map array */
  12860. lpfc_cpu_map_array_init(phba);
  12861. /* Init hba_eq_hdl array */
  12862. lpfc_hba_eq_hdl_array_init(phba);
  12863. /* Configure and enable interrupt */
  12864. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  12865. if (intr_mode == LPFC_INTR_ERROR) {
  12866. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12867. "0430 PM resume Failed to enable interrupt\n");
  12868. return -EIO;
  12869. } else
  12870. phba->intr_mode = intr_mode;
  12871. /* Restart HBA and bring it online */
  12872. lpfc_sli_brdrestart(phba);
  12873. lpfc_online(phba);
  12874. /* Log the current active interrupt mode */
  12875. lpfc_log_intr_mode(phba, phba->intr_mode);
  12876. return 0;
  12877. }
  12878. /**
  12879. * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
  12880. * @phba: pointer to lpfc hba data structure.
  12881. *
  12882. * This routine is called to prepare the SLI3 device for PCI slot recover. It
  12883. * aborts all the outstanding SCSI I/Os to the pci device.
  12884. **/
  12885. static void
  12886. lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
  12887. {
  12888. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12889. "2723 PCI channel I/O abort preparing for recovery\n");
  12890. /*
  12891. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  12892. * and let the SCSI mid-layer to retry them to recover.
  12893. */
  12894. lpfc_sli_abort_fcp_rings(phba);
  12895. }
  12896. /**
  12897. * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
  12898. * @phba: pointer to lpfc hba data structure.
  12899. *
  12900. * This routine is called to prepare the SLI3 device for PCI slot reset. It
  12901. * disables the device interrupt and pci device, and aborts the internal FCP
  12902. * pending I/Os.
  12903. **/
  12904. static void
  12905. lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
  12906. {
  12907. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12908. "2710 PCI channel disable preparing for reset\n");
  12909. /* Block any management I/Os to the device */
  12910. lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
  12911. /* Block all SCSI devices' I/Os on the host */
  12912. lpfc_scsi_dev_block(phba);
  12913. /* Flush all driver's outstanding SCSI I/Os as we are to reset */
  12914. lpfc_sli_flush_io_rings(phba);
  12915. /* stop all timers */
  12916. lpfc_stop_hba_timers(phba);
  12917. /* Disable interrupt and pci device */
  12918. lpfc_sli_disable_intr(phba);
  12919. pci_disable_device(phba->pcidev);
  12920. }
  12921. /**
  12922. * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
  12923. * @phba: pointer to lpfc hba data structure.
  12924. *
  12925. * This routine is called to prepare the SLI3 device for PCI slot permanently
  12926. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  12927. * pending I/Os.
  12928. **/
  12929. static void
  12930. lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  12931. {
  12932. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12933. "2711 PCI channel permanent disable for failure\n");
  12934. /* Block all SCSI devices' I/Os on the host */
  12935. lpfc_scsi_dev_block(phba);
  12936. lpfc_sli4_prep_dev_for_reset(phba);
  12937. /* stop all timers */
  12938. lpfc_stop_hba_timers(phba);
  12939. /* Clean up all driver's outstanding SCSI I/Os */
  12940. lpfc_sli_flush_io_rings(phba);
  12941. }
  12942. /**
  12943. * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
  12944. * @pdev: pointer to PCI device.
  12945. * @state: the current PCI connection state.
  12946. *
  12947. * This routine is called from the PCI subsystem for I/O error handling to
  12948. * device with SLI-3 interface spec. This function is called by the PCI
  12949. * subsystem after a PCI bus error affecting this device has been detected.
  12950. * When this function is invoked, it will need to stop all the I/Os and
  12951. * interrupt(s) to the device. Once that is done, it will return
  12952. * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
  12953. * as desired.
  12954. *
  12955. * Return codes
  12956. * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
  12957. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  12958. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  12959. **/
  12960. static pci_ers_result_t
  12961. lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
  12962. {
  12963. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  12964. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  12965. switch (state) {
  12966. case pci_channel_io_normal:
  12967. /* Non-fatal error, prepare for recovery */
  12968. lpfc_sli_prep_dev_for_recover(phba);
  12969. return PCI_ERS_RESULT_CAN_RECOVER;
  12970. case pci_channel_io_frozen:
  12971. /* Fatal error, prepare for slot reset */
  12972. lpfc_sli_prep_dev_for_reset(phba);
  12973. return PCI_ERS_RESULT_NEED_RESET;
  12974. case pci_channel_io_perm_failure:
  12975. /* Permanent failure, prepare for device down */
  12976. lpfc_sli_prep_dev_for_perm_failure(phba);
  12977. return PCI_ERS_RESULT_DISCONNECT;
  12978. default:
  12979. /* Unknown state, prepare and request slot reset */
  12980. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12981. "0472 Unknown PCI error state: x%x\n", state);
  12982. lpfc_sli_prep_dev_for_reset(phba);
  12983. return PCI_ERS_RESULT_NEED_RESET;
  12984. }
  12985. }
  12986. /**
  12987. * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
  12988. * @pdev: pointer to PCI device.
  12989. *
  12990. * This routine is called from the PCI subsystem for error handling to
  12991. * device with SLI-3 interface spec. This is called after PCI bus has been
  12992. * reset to restart the PCI card from scratch, as if from a cold-boot.
  12993. * During the PCI subsystem error recovery, after driver returns
  12994. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  12995. * recovery and then call this routine before calling the .resume method
  12996. * to recover the device. This function will initialize the HBA device,
  12997. * enable the interrupt, but it will just put the HBA to offline state
  12998. * without passing any I/O traffic.
  12999. *
  13000. * Return codes
  13001. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  13002. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  13003. */
  13004. static pci_ers_result_t
  13005. lpfc_io_slot_reset_s3(struct pci_dev *pdev)
  13006. {
  13007. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  13008. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  13009. struct lpfc_sli *psli = &phba->sli;
  13010. uint32_t intr_mode;
  13011. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  13012. if (pci_enable_device_mem(pdev)) {
  13013. printk(KERN_ERR "lpfc: Cannot re-enable "
  13014. "PCI device after reset.\n");
  13015. return PCI_ERS_RESULT_DISCONNECT;
  13016. }
  13017. pci_restore_state(pdev);
  13018. /*
  13019. * As the new kernel behavior of pci_restore_state() API call clears
  13020. * device saved_state flag, need to save the restored state again.
  13021. */
  13022. pci_save_state(pdev);
  13023. if (pdev->is_busmaster)
  13024. pci_set_master(pdev);
  13025. spin_lock_irq(&phba->hbalock);
  13026. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  13027. spin_unlock_irq(&phba->hbalock);
  13028. /* Configure and enable interrupt */
  13029. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  13030. if (intr_mode == LPFC_INTR_ERROR) {
  13031. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13032. "0427 Cannot re-enable interrupt after "
  13033. "slot reset.\n");
  13034. return PCI_ERS_RESULT_DISCONNECT;
  13035. } else
  13036. phba->intr_mode = intr_mode;
  13037. /* Take device offline, it will perform cleanup */
  13038. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  13039. lpfc_offline(phba);
  13040. lpfc_sli_brdrestart(phba);
  13041. /* Log the current active interrupt mode */
  13042. lpfc_log_intr_mode(phba, phba->intr_mode);
  13043. return PCI_ERS_RESULT_RECOVERED;
  13044. }
  13045. /**
  13046. * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
  13047. * @pdev: pointer to PCI device
  13048. *
  13049. * This routine is called from the PCI subsystem for error handling to device
  13050. * with SLI-3 interface spec. It is called when kernel error recovery tells
  13051. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  13052. * error recovery. After this call, traffic can start to flow from this device
  13053. * again.
  13054. */
  13055. static void
  13056. lpfc_io_resume_s3(struct pci_dev *pdev)
  13057. {
  13058. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  13059. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  13060. /* Bring device online, it will be no-op for non-fatal error resume */
  13061. lpfc_online(phba);
  13062. }
  13063. /**
  13064. * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
  13065. * @phba: pointer to lpfc hba data structure.
  13066. *
  13067. * returns the number of ELS/CT IOCBs to reserve
  13068. **/
  13069. int
  13070. lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
  13071. {
  13072. int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
  13073. if (phba->sli_rev == LPFC_SLI_REV4) {
  13074. if (max_xri <= 100)
  13075. return 10;
  13076. else if (max_xri <= 256)
  13077. return 25;
  13078. else if (max_xri <= 512)
  13079. return 50;
  13080. else if (max_xri <= 1024)
  13081. return 100;
  13082. else if (max_xri <= 1536)
  13083. return 150;
  13084. else if (max_xri <= 2048)
  13085. return 200;
  13086. else
  13087. return 250;
  13088. } else
  13089. return 0;
  13090. }
  13091. /**
  13092. * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
  13093. * @phba: pointer to lpfc hba data structure.
  13094. *
  13095. * returns the number of ELS/CT + NVMET IOCBs to reserve
  13096. **/
  13097. int
  13098. lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
  13099. {
  13100. int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
  13101. if (phba->nvmet_support)
  13102. max_xri += LPFC_NVMET_BUF_POST;
  13103. return max_xri;
  13104. }
  13105. static int
  13106. lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
  13107. uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
  13108. const struct firmware *fw)
  13109. {
  13110. int rc;
  13111. u8 sli_family;
  13112. sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
  13113. /* Three cases: (1) FW was not supported on the detected adapter.
  13114. * (2) FW update has been locked out administratively.
  13115. * (3) Some other error during FW update.
  13116. * In each case, an unmaskable message is written to the console
  13117. * for admin diagnosis.
  13118. */
  13119. if (offset == ADD_STATUS_FW_NOT_SUPPORTED ||
  13120. (sli_family == LPFC_SLI_INTF_FAMILY_G6 &&
  13121. magic_number != MAGIC_NUMBER_G6) ||
  13122. (sli_family == LPFC_SLI_INTF_FAMILY_G7 &&
  13123. magic_number != MAGIC_NUMBER_G7) ||
  13124. (sli_family == LPFC_SLI_INTF_FAMILY_G7P &&
  13125. magic_number != MAGIC_NUMBER_G7P)) {
  13126. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13127. "3030 This firmware version is not supported on"
  13128. " this HBA model. Device:%x Magic:%x Type:%x "
  13129. "ID:%x Size %d %zd\n",
  13130. phba->pcidev->device, magic_number, ftype, fid,
  13131. fsize, fw->size);
  13132. rc = -EINVAL;
  13133. } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) {
  13134. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13135. "3021 Firmware downloads have been prohibited "
  13136. "by a system configuration setting on "
  13137. "Device:%x Magic:%x Type:%x ID:%x Size %d "
  13138. "%zd\n",
  13139. phba->pcidev->device, magic_number, ftype, fid,
  13140. fsize, fw->size);
  13141. rc = -EACCES;
  13142. } else {
  13143. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13144. "3022 FW Download failed. Add Status x%x "
  13145. "Device:%x Magic:%x Type:%x ID:%x Size %d "
  13146. "%zd\n",
  13147. offset, phba->pcidev->device, magic_number,
  13148. ftype, fid, fsize, fw->size);
  13149. rc = -EIO;
  13150. }
  13151. return rc;
  13152. }
  13153. /**
  13154. * lpfc_write_firmware - attempt to write a firmware image to the port
  13155. * @fw: pointer to firmware image returned from request_firmware.
  13156. * @context: pointer to firmware image returned from request_firmware.
  13157. *
  13158. **/
  13159. static void
  13160. lpfc_write_firmware(const struct firmware *fw, void *context)
  13161. {
  13162. struct lpfc_hba *phba = (struct lpfc_hba *)context;
  13163. char fwrev[FW_REV_STR_SIZE];
  13164. struct lpfc_grp_hdr *image;
  13165. struct list_head dma_buffer_list;
  13166. int i, rc = 0;
  13167. struct lpfc_dmabuf *dmabuf, *next;
  13168. uint32_t offset = 0, temp_offset = 0;
  13169. uint32_t magic_number, ftype, fid, fsize;
  13170. /* It can be null in no-wait mode, sanity check */
  13171. if (!fw) {
  13172. rc = -ENXIO;
  13173. goto out;
  13174. }
  13175. image = (struct lpfc_grp_hdr *)fw->data;
  13176. magic_number = be32_to_cpu(image->magic_number);
  13177. ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
  13178. fid = bf_get_be32(lpfc_grp_hdr_id, image);
  13179. fsize = be32_to_cpu(image->size);
  13180. INIT_LIST_HEAD(&dma_buffer_list);
  13181. lpfc_decode_firmware_rev(phba, fwrev, 1);
  13182. if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
  13183. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13184. "3023 Updating Firmware, Current Version:%s "
  13185. "New Version:%s\n",
  13186. fwrev, image->revision);
  13187. for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
  13188. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
  13189. GFP_KERNEL);
  13190. if (!dmabuf) {
  13191. rc = -ENOMEM;
  13192. goto release_out;
  13193. }
  13194. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  13195. SLI4_PAGE_SIZE,
  13196. &dmabuf->phys,
  13197. GFP_KERNEL);
  13198. if (!dmabuf->virt) {
  13199. kfree(dmabuf);
  13200. rc = -ENOMEM;
  13201. goto release_out;
  13202. }
  13203. list_add_tail(&dmabuf->list, &dma_buffer_list);
  13204. }
  13205. while (offset < fw->size) {
  13206. temp_offset = offset;
  13207. list_for_each_entry(dmabuf, &dma_buffer_list, list) {
  13208. if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
  13209. memcpy(dmabuf->virt,
  13210. fw->data + temp_offset,
  13211. fw->size - temp_offset);
  13212. temp_offset = fw->size;
  13213. break;
  13214. }
  13215. memcpy(dmabuf->virt, fw->data + temp_offset,
  13216. SLI4_PAGE_SIZE);
  13217. temp_offset += SLI4_PAGE_SIZE;
  13218. }
  13219. rc = lpfc_wr_object(phba, &dma_buffer_list,
  13220. (fw->size - offset), &offset);
  13221. if (rc) {
  13222. rc = lpfc_log_write_firmware_error(phba, offset,
  13223. magic_number,
  13224. ftype,
  13225. fid,
  13226. fsize,
  13227. fw);
  13228. goto release_out;
  13229. }
  13230. }
  13231. rc = offset;
  13232. } else
  13233. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13234. "3029 Skipped Firmware update, Current "
  13235. "Version:%s New Version:%s\n",
  13236. fwrev, image->revision);
  13237. release_out:
  13238. list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
  13239. list_del(&dmabuf->list);
  13240. dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
  13241. dmabuf->virt, dmabuf->phys);
  13242. kfree(dmabuf);
  13243. }
  13244. release_firmware(fw);
  13245. out:
  13246. if (rc < 0)
  13247. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13248. "3062 Firmware update error, status %d.\n", rc);
  13249. else
  13250. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13251. "3024 Firmware update success: size %d.\n", rc);
  13252. }
  13253. /**
  13254. * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
  13255. * @phba: pointer to lpfc hba data structure.
  13256. * @fw_upgrade: which firmware to update.
  13257. *
  13258. * This routine is called to perform Linux generic firmware upgrade on device
  13259. * that supports such feature.
  13260. **/
  13261. int
  13262. lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
  13263. {
  13264. uint8_t file_name[ELX_MODEL_NAME_SIZE];
  13265. int ret;
  13266. const struct firmware *fw;
  13267. /* Only supported on SLI4 interface type 2 for now */
  13268. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
  13269. LPFC_SLI_INTF_IF_TYPE_2)
  13270. return -EPERM;
  13271. snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
  13272. if (fw_upgrade == INT_FW_UPGRADE) {
  13273. ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT,
  13274. file_name, &phba->pcidev->dev,
  13275. GFP_KERNEL, (void *)phba,
  13276. lpfc_write_firmware);
  13277. } else if (fw_upgrade == RUN_FW_UPGRADE) {
  13278. ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
  13279. if (!ret)
  13280. lpfc_write_firmware(fw, (void *)phba);
  13281. } else {
  13282. ret = -EINVAL;
  13283. }
  13284. return ret;
  13285. }
  13286. /**
  13287. * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
  13288. * @pdev: pointer to PCI device
  13289. * @pid: pointer to PCI device identifier
  13290. *
  13291. * This routine is called from the kernel's PCI subsystem to device with
  13292. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  13293. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  13294. * information of the device and driver to see if the driver state that it
  13295. * can support this kind of device. If the match is successful, the driver
  13296. * core invokes this routine. If this routine determines it can claim the HBA,
  13297. * it does all the initialization that it needs to do to handle the HBA
  13298. * properly.
  13299. *
  13300. * Return code
  13301. * 0 - driver can claim the device
  13302. * negative value - driver can not claim the device
  13303. **/
  13304. static int
  13305. lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
  13306. {
  13307. struct lpfc_hba *phba;
  13308. struct lpfc_vport *vport = NULL;
  13309. struct Scsi_Host *shost = NULL;
  13310. int error;
  13311. uint32_t cfg_mode, intr_mode;
  13312. /* Allocate memory for HBA structure */
  13313. phba = lpfc_hba_alloc(pdev);
  13314. if (!phba)
  13315. return -ENOMEM;
  13316. INIT_LIST_HEAD(&phba->poll_list);
  13317. /* Perform generic PCI device enabling operation */
  13318. error = lpfc_enable_pci_dev(phba);
  13319. if (error)
  13320. goto out_free_phba;
  13321. /* Set up SLI API function jump table for PCI-device group-1 HBAs */
  13322. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
  13323. if (error)
  13324. goto out_disable_pci_dev;
  13325. /* Set up SLI-4 specific device PCI memory space */
  13326. error = lpfc_sli4_pci_mem_setup(phba);
  13327. if (error) {
  13328. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13329. "1410 Failed to set up pci memory space.\n");
  13330. goto out_disable_pci_dev;
  13331. }
  13332. /* Set up SLI-4 Specific device driver resources */
  13333. error = lpfc_sli4_driver_resource_setup(phba);
  13334. if (error) {
  13335. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13336. "1412 Failed to set up driver resource.\n");
  13337. goto out_unset_pci_mem_s4;
  13338. }
  13339. INIT_LIST_HEAD(&phba->active_rrq_list);
  13340. INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
  13341. /* Set up common device driver resources */
  13342. error = lpfc_setup_driver_resource_phase2(phba);
  13343. if (error) {
  13344. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13345. "1414 Failed to set up driver resource.\n");
  13346. goto out_unset_driver_resource_s4;
  13347. }
  13348. /* Get the default values for Model Name and Description */
  13349. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  13350. /* Now, trying to enable interrupt and bring up the device */
  13351. cfg_mode = phba->cfg_use_msi;
  13352. /* Put device to a known state before enabling interrupt */
  13353. phba->pport = NULL;
  13354. lpfc_stop_port(phba);
  13355. /* Init cpu_map array */
  13356. lpfc_cpu_map_array_init(phba);
  13357. /* Init hba_eq_hdl array */
  13358. lpfc_hba_eq_hdl_array_init(phba);
  13359. /* Configure and enable interrupt */
  13360. intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
  13361. if (intr_mode == LPFC_INTR_ERROR) {
  13362. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13363. "0426 Failed to enable interrupt.\n");
  13364. error = -ENODEV;
  13365. goto out_unset_driver_resource;
  13366. }
  13367. /* Default to single EQ for non-MSI-X */
  13368. if (phba->intr_type != MSIX) {
  13369. phba->cfg_irq_chann = 1;
  13370. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  13371. if (phba->nvmet_support)
  13372. phba->cfg_nvmet_mrq = 1;
  13373. }
  13374. }
  13375. lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
  13376. /* Create SCSI host to the physical port */
  13377. error = lpfc_create_shost(phba);
  13378. if (error) {
  13379. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13380. "1415 Failed to create scsi host.\n");
  13381. goto out_disable_intr;
  13382. }
  13383. vport = phba->pport;
  13384. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  13385. /* Configure sysfs attributes */
  13386. error = lpfc_alloc_sysfs_attr(vport);
  13387. if (error) {
  13388. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13389. "1416 Failed to allocate sysfs attr\n");
  13390. goto out_destroy_shost;
  13391. }
  13392. /* Set up SLI-4 HBA */
  13393. if (lpfc_sli4_hba_setup(phba)) {
  13394. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13395. "1421 Failed to set up hba\n");
  13396. error = -ENODEV;
  13397. goto out_free_sysfs_attr;
  13398. }
  13399. /* Log the current active interrupt mode */
  13400. phba->intr_mode = intr_mode;
  13401. lpfc_log_intr_mode(phba, intr_mode);
  13402. /* Perform post initialization setup */
  13403. lpfc_post_init_setup(phba);
  13404. /* NVME support in FW earlier in the driver load corrects the
  13405. * FC4 type making a check for nvme_support unnecessary.
  13406. */
  13407. if (phba->nvmet_support == 0) {
  13408. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  13409. /* Create NVME binding with nvme_fc_transport. This
  13410. * ensures the vport is initialized. If the localport
  13411. * create fails, it should not unload the driver to
  13412. * support field issues.
  13413. */
  13414. error = lpfc_nvme_create_localport(vport);
  13415. if (error) {
  13416. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13417. "6004 NVME registration "
  13418. "failed, error x%x\n",
  13419. error);
  13420. }
  13421. }
  13422. }
  13423. /* check for firmware upgrade or downgrade */
  13424. if (phba->cfg_request_firmware_upgrade)
  13425. lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
  13426. /* Check if there are static vports to be created. */
  13427. lpfc_create_static_vport(phba);
  13428. timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0);
  13429. cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp);
  13430. return 0;
  13431. out_free_sysfs_attr:
  13432. lpfc_free_sysfs_attr(vport);
  13433. out_destroy_shost:
  13434. lpfc_destroy_shost(phba);
  13435. out_disable_intr:
  13436. lpfc_sli4_disable_intr(phba);
  13437. out_unset_driver_resource:
  13438. lpfc_unset_driver_resource_phase2(phba);
  13439. out_unset_driver_resource_s4:
  13440. lpfc_sli4_driver_resource_unset(phba);
  13441. out_unset_pci_mem_s4:
  13442. lpfc_sli4_pci_mem_unset(phba);
  13443. out_disable_pci_dev:
  13444. lpfc_disable_pci_dev(phba);
  13445. if (shost)
  13446. scsi_host_put(shost);
  13447. out_free_phba:
  13448. lpfc_hba_free(phba);
  13449. return error;
  13450. }
  13451. /**
  13452. * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
  13453. * @pdev: pointer to PCI device
  13454. *
  13455. * This routine is called from the kernel's PCI subsystem to device with
  13456. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  13457. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  13458. * device to be removed from the PCI subsystem properly.
  13459. **/
  13460. static void
  13461. lpfc_pci_remove_one_s4(struct pci_dev *pdev)
  13462. {
  13463. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  13464. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  13465. struct lpfc_vport **vports;
  13466. struct lpfc_hba *phba = vport->phba;
  13467. int i;
  13468. /* Mark the device unloading flag */
  13469. spin_lock_irq(&phba->hbalock);
  13470. vport->load_flag |= FC_UNLOADING;
  13471. spin_unlock_irq(&phba->hbalock);
  13472. if (phba->cgn_i)
  13473. lpfc_unreg_congestion_buf(phba);
  13474. lpfc_free_sysfs_attr(vport);
  13475. /* Release all the vports against this physical port */
  13476. vports = lpfc_create_vport_work_array(phba);
  13477. if (vports != NULL)
  13478. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  13479. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  13480. continue;
  13481. fc_vport_terminate(vports[i]->fc_vport);
  13482. }
  13483. lpfc_destroy_vport_work_array(phba, vports);
  13484. /* Remove FC host with the physical port */
  13485. fc_remove_host(shost);
  13486. scsi_remove_host(shost);
  13487. /* Perform ndlp cleanup on the physical port. The nvme and nvmet
  13488. * localports are destroyed after to cleanup all transport memory.
  13489. */
  13490. lpfc_cleanup(vport);
  13491. lpfc_nvmet_destroy_targetport(phba);
  13492. lpfc_nvme_destroy_localport(vport);
  13493. /* De-allocate multi-XRI pools */
  13494. if (phba->cfg_xri_rebalancing)
  13495. lpfc_destroy_multixri_pools(phba);
  13496. /*
  13497. * Bring down the SLI Layer. This step disables all interrupts,
  13498. * clears the rings, discards all mailbox commands, and resets
  13499. * the HBA FCoE function.
  13500. */
  13501. lpfc_debugfs_terminate(vport);
  13502. lpfc_stop_hba_timers(phba);
  13503. spin_lock_irq(&phba->port_list_lock);
  13504. list_del_init(&vport->listentry);
  13505. spin_unlock_irq(&phba->port_list_lock);
  13506. /* Perform scsi free before driver resource_unset since scsi
  13507. * buffers are released to their corresponding pools here.
  13508. */
  13509. lpfc_io_free(phba);
  13510. lpfc_free_iocb_list(phba);
  13511. lpfc_sli4_hba_unset(phba);
  13512. lpfc_unset_driver_resource_phase2(phba);
  13513. lpfc_sli4_driver_resource_unset(phba);
  13514. /* Unmap adapter Control and Doorbell registers */
  13515. lpfc_sli4_pci_mem_unset(phba);
  13516. /* Release PCI resources and disable device's PCI function */
  13517. scsi_host_put(shost);
  13518. lpfc_disable_pci_dev(phba);
  13519. /* Finally, free the driver's device data structure */
  13520. lpfc_hba_free(phba);
  13521. return;
  13522. }
  13523. /**
  13524. * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
  13525. * @dev_d: pointer to device
  13526. *
  13527. * This routine is called from the kernel's PCI subsystem to support system
  13528. * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
  13529. * this method, it quiesces the device by stopping the driver's worker
  13530. * thread for the device, turning off device's interrupt and DMA, and bring
  13531. * the device offline. Note that as the driver implements the minimum PM
  13532. * requirements to a power-aware driver's PM support for suspend/resume -- all
  13533. * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
  13534. * method call will be treated as SUSPEND and the driver will fully
  13535. * reinitialize its device during resume() method call, the driver will set
  13536. * device to PCI_D3hot state in PCI config space instead of setting it
  13537. * according to the @msg provided by the PM.
  13538. *
  13539. * Return code
  13540. * 0 - driver suspended the device
  13541. * Error otherwise
  13542. **/
  13543. static int __maybe_unused
  13544. lpfc_pci_suspend_one_s4(struct device *dev_d)
  13545. {
  13546. struct Scsi_Host *shost = dev_get_drvdata(dev_d);
  13547. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  13548. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  13549. "2843 PCI device Power Management suspend.\n");
  13550. /* Bring down the device */
  13551. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  13552. lpfc_offline(phba);
  13553. kthread_stop(phba->worker_thread);
  13554. /* Disable interrupt from device */
  13555. lpfc_sli4_disable_intr(phba);
  13556. lpfc_sli4_queue_destroy(phba);
  13557. return 0;
  13558. }
  13559. /**
  13560. * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
  13561. * @dev_d: pointer to device
  13562. *
  13563. * This routine is called from the kernel's PCI subsystem to support system
  13564. * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
  13565. * this method, it restores the device's PCI config space state and fully
  13566. * reinitializes the device and brings it online. Note that as the driver
  13567. * implements the minimum PM requirements to a power-aware driver's PM for
  13568. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  13569. * to the suspend() method call will be treated as SUSPEND and the driver
  13570. * will fully reinitialize its device during resume() method call, the device
  13571. * will be set to PCI_D0 directly in PCI config space before restoring the
  13572. * state.
  13573. *
  13574. * Return code
  13575. * 0 - driver suspended the device
  13576. * Error otherwise
  13577. **/
  13578. static int __maybe_unused
  13579. lpfc_pci_resume_one_s4(struct device *dev_d)
  13580. {
  13581. struct Scsi_Host *shost = dev_get_drvdata(dev_d);
  13582. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  13583. uint32_t intr_mode;
  13584. int error;
  13585. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  13586. "0292 PCI device Power Management resume.\n");
  13587. /* Startup the kernel thread for this host adapter. */
  13588. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  13589. "lpfc_worker_%d", phba->brd_no);
  13590. if (IS_ERR(phba->worker_thread)) {
  13591. error = PTR_ERR(phba->worker_thread);
  13592. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13593. "0293 PM resume failed to start worker "
  13594. "thread: error=x%x.\n", error);
  13595. return error;
  13596. }
  13597. /* Configure and enable interrupt */
  13598. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  13599. if (intr_mode == LPFC_INTR_ERROR) {
  13600. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13601. "0294 PM resume Failed to enable interrupt\n");
  13602. return -EIO;
  13603. } else
  13604. phba->intr_mode = intr_mode;
  13605. /* Restart HBA and bring it online */
  13606. lpfc_sli_brdrestart(phba);
  13607. lpfc_online(phba);
  13608. /* Log the current active interrupt mode */
  13609. lpfc_log_intr_mode(phba, phba->intr_mode);
  13610. return 0;
  13611. }
  13612. /**
  13613. * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
  13614. * @phba: pointer to lpfc hba data structure.
  13615. *
  13616. * This routine is called to prepare the SLI4 device for PCI slot recover. It
  13617. * aborts all the outstanding SCSI I/Os to the pci device.
  13618. **/
  13619. static void
  13620. lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
  13621. {
  13622. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13623. "2828 PCI channel I/O abort preparing for recovery\n");
  13624. /*
  13625. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  13626. * and let the SCSI mid-layer to retry them to recover.
  13627. */
  13628. lpfc_sli_abort_fcp_rings(phba);
  13629. }
  13630. /**
  13631. * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
  13632. * @phba: pointer to lpfc hba data structure.
  13633. *
  13634. * This routine is called to prepare the SLI4 device for PCI slot reset. It
  13635. * disables the device interrupt and pci device, and aborts the internal FCP
  13636. * pending I/Os.
  13637. **/
  13638. static void
  13639. lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
  13640. {
  13641. int offline = pci_channel_offline(phba->pcidev);
  13642. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13643. "2826 PCI channel disable preparing for reset offline"
  13644. " %d\n", offline);
  13645. /* Block any management I/Os to the device */
  13646. lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
  13647. /* HBA_PCI_ERR was set in io_error_detect */
  13648. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  13649. /* Flush all driver's outstanding I/Os as we are to reset */
  13650. lpfc_sli_flush_io_rings(phba);
  13651. lpfc_offline(phba);
  13652. /* stop all timers */
  13653. lpfc_stop_hba_timers(phba);
  13654. lpfc_sli4_queue_destroy(phba);
  13655. /* Disable interrupt and pci device */
  13656. lpfc_sli4_disable_intr(phba);
  13657. pci_disable_device(phba->pcidev);
  13658. }
  13659. /**
  13660. * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
  13661. * @phba: pointer to lpfc hba data structure.
  13662. *
  13663. * This routine is called to prepare the SLI4 device for PCI slot permanently
  13664. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  13665. * pending I/Os.
  13666. **/
  13667. static void
  13668. lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  13669. {
  13670. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13671. "2827 PCI channel permanent disable for failure\n");
  13672. /* Block all SCSI devices' I/Os on the host */
  13673. lpfc_scsi_dev_block(phba);
  13674. /* stop all timers */
  13675. lpfc_stop_hba_timers(phba);
  13676. /* Clean up all driver's outstanding I/Os */
  13677. lpfc_sli_flush_io_rings(phba);
  13678. }
  13679. /**
  13680. * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
  13681. * @pdev: pointer to PCI device.
  13682. * @state: the current PCI connection state.
  13683. *
  13684. * This routine is called from the PCI subsystem for error handling to device
  13685. * with SLI-4 interface spec. This function is called by the PCI subsystem
  13686. * after a PCI bus error affecting this device has been detected. When this
  13687. * function is invoked, it will need to stop all the I/Os and interrupt(s)
  13688. * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
  13689. * for the PCI subsystem to perform proper recovery as desired.
  13690. *
  13691. * Return codes
  13692. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  13693. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  13694. **/
  13695. static pci_ers_result_t
  13696. lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
  13697. {
  13698. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  13699. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  13700. bool hba_pci_err;
  13701. switch (state) {
  13702. case pci_channel_io_normal:
  13703. /* Non-fatal error, prepare for recovery */
  13704. lpfc_sli4_prep_dev_for_recover(phba);
  13705. return PCI_ERS_RESULT_CAN_RECOVER;
  13706. case pci_channel_io_frozen:
  13707. hba_pci_err = test_and_set_bit(HBA_PCI_ERR, &phba->bit_flags);
  13708. /* Fatal error, prepare for slot reset */
  13709. if (!hba_pci_err)
  13710. lpfc_sli4_prep_dev_for_reset(phba);
  13711. else
  13712. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13713. "2832 Already handling PCI error "
  13714. "state: x%x\n", state);
  13715. return PCI_ERS_RESULT_NEED_RESET;
  13716. case pci_channel_io_perm_failure:
  13717. set_bit(HBA_PCI_ERR, &phba->bit_flags);
  13718. /* Permanent failure, prepare for device down */
  13719. lpfc_sli4_prep_dev_for_perm_failure(phba);
  13720. return PCI_ERS_RESULT_DISCONNECT;
  13721. default:
  13722. hba_pci_err = test_and_set_bit(HBA_PCI_ERR, &phba->bit_flags);
  13723. if (!hba_pci_err)
  13724. lpfc_sli4_prep_dev_for_reset(phba);
  13725. /* Unknown state, prepare and request slot reset */
  13726. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13727. "2825 Unknown PCI error state: x%x\n", state);
  13728. lpfc_sli4_prep_dev_for_reset(phba);
  13729. return PCI_ERS_RESULT_NEED_RESET;
  13730. }
  13731. }
  13732. /**
  13733. * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
  13734. * @pdev: pointer to PCI device.
  13735. *
  13736. * This routine is called from the PCI subsystem for error handling to device
  13737. * with SLI-4 interface spec. It is called after PCI bus has been reset to
  13738. * restart the PCI card from scratch, as if from a cold-boot. During the
  13739. * PCI subsystem error recovery, after the driver returns
  13740. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  13741. * recovery and then call this routine before calling the .resume method to
  13742. * recover the device. This function will initialize the HBA device, enable
  13743. * the interrupt, but it will just put the HBA to offline state without
  13744. * passing any I/O traffic.
  13745. *
  13746. * Return codes
  13747. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  13748. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  13749. */
  13750. static pci_ers_result_t
  13751. lpfc_io_slot_reset_s4(struct pci_dev *pdev)
  13752. {
  13753. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  13754. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  13755. struct lpfc_sli *psli = &phba->sli;
  13756. uint32_t intr_mode;
  13757. bool hba_pci_err;
  13758. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  13759. if (pci_enable_device_mem(pdev)) {
  13760. printk(KERN_ERR "lpfc: Cannot re-enable "
  13761. "PCI device after reset.\n");
  13762. return PCI_ERS_RESULT_DISCONNECT;
  13763. }
  13764. pci_restore_state(pdev);
  13765. hba_pci_err = test_and_clear_bit(HBA_PCI_ERR, &phba->bit_flags);
  13766. if (!hba_pci_err)
  13767. dev_info(&pdev->dev,
  13768. "hba_pci_err was not set, recovering slot reset.\n");
  13769. /*
  13770. * As the new kernel behavior of pci_restore_state() API call clears
  13771. * device saved_state flag, need to save the restored state again.
  13772. */
  13773. pci_save_state(pdev);
  13774. if (pdev->is_busmaster)
  13775. pci_set_master(pdev);
  13776. spin_lock_irq(&phba->hbalock);
  13777. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  13778. spin_unlock_irq(&phba->hbalock);
  13779. /* Init cpu_map array */
  13780. lpfc_cpu_map_array_init(phba);
  13781. /* Configure and enable interrupt */
  13782. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  13783. if (intr_mode == LPFC_INTR_ERROR) {
  13784. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13785. "2824 Cannot re-enable interrupt after "
  13786. "slot reset.\n");
  13787. return PCI_ERS_RESULT_DISCONNECT;
  13788. } else
  13789. phba->intr_mode = intr_mode;
  13790. lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann);
  13791. /* Log the current active interrupt mode */
  13792. lpfc_log_intr_mode(phba, phba->intr_mode);
  13793. return PCI_ERS_RESULT_RECOVERED;
  13794. }
  13795. /**
  13796. * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
  13797. * @pdev: pointer to PCI device
  13798. *
  13799. * This routine is called from the PCI subsystem for error handling to device
  13800. * with SLI-4 interface spec. It is called when kernel error recovery tells
  13801. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  13802. * error recovery. After this call, traffic can start to flow from this device
  13803. * again.
  13804. **/
  13805. static void
  13806. lpfc_io_resume_s4(struct pci_dev *pdev)
  13807. {
  13808. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  13809. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  13810. /*
  13811. * In case of slot reset, as function reset is performed through
  13812. * mailbox command which needs DMA to be enabled, this operation
  13813. * has to be moved to the io resume phase. Taking device offline
  13814. * will perform the necessary cleanup.
  13815. */
  13816. if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
  13817. /* Perform device reset */
  13818. lpfc_sli_brdrestart(phba);
  13819. /* Bring the device back online */
  13820. lpfc_online(phba);
  13821. }
  13822. }
  13823. /**
  13824. * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
  13825. * @pdev: pointer to PCI device
  13826. * @pid: pointer to PCI device identifier
  13827. *
  13828. * This routine is to be registered to the kernel's PCI subsystem. When an
  13829. * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
  13830. * at PCI device-specific information of the device and driver to see if the
  13831. * driver state that it can support this kind of device. If the match is
  13832. * successful, the driver core invokes this routine. This routine dispatches
  13833. * the action to the proper SLI-3 or SLI-4 device probing routine, which will
  13834. * do all the initialization that it needs to do to handle the HBA device
  13835. * properly.
  13836. *
  13837. * Return code
  13838. * 0 - driver can claim the device
  13839. * negative value - driver can not claim the device
  13840. **/
  13841. static int
  13842. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  13843. {
  13844. int rc;
  13845. struct lpfc_sli_intf intf;
  13846. if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
  13847. return -ENODEV;
  13848. if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
  13849. (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
  13850. rc = lpfc_pci_probe_one_s4(pdev, pid);
  13851. else
  13852. rc = lpfc_pci_probe_one_s3(pdev, pid);
  13853. return rc;
  13854. }
  13855. /**
  13856. * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
  13857. * @pdev: pointer to PCI device
  13858. *
  13859. * This routine is to be registered to the kernel's PCI subsystem. When an
  13860. * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
  13861. * This routine dispatches the action to the proper SLI-3 or SLI-4 device
  13862. * remove routine, which will perform all the necessary cleanup for the
  13863. * device to be removed from the PCI subsystem properly.
  13864. **/
  13865. static void
  13866. lpfc_pci_remove_one(struct pci_dev *pdev)
  13867. {
  13868. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  13869. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  13870. switch (phba->pci_dev_grp) {
  13871. case LPFC_PCI_DEV_LP:
  13872. lpfc_pci_remove_one_s3(pdev);
  13873. break;
  13874. case LPFC_PCI_DEV_OC:
  13875. lpfc_pci_remove_one_s4(pdev);
  13876. break;
  13877. default:
  13878. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13879. "1424 Invalid PCI device group: 0x%x\n",
  13880. phba->pci_dev_grp);
  13881. break;
  13882. }
  13883. return;
  13884. }
  13885. /**
  13886. * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
  13887. * @dev: pointer to device
  13888. *
  13889. * This routine is to be registered to the kernel's PCI subsystem to support
  13890. * system Power Management (PM). When PM invokes this method, it dispatches
  13891. * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
  13892. * suspend the device.
  13893. *
  13894. * Return code
  13895. * 0 - driver suspended the device
  13896. * Error otherwise
  13897. **/
  13898. static int __maybe_unused
  13899. lpfc_pci_suspend_one(struct device *dev)
  13900. {
  13901. struct Scsi_Host *shost = dev_get_drvdata(dev);
  13902. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  13903. int rc = -ENODEV;
  13904. switch (phba->pci_dev_grp) {
  13905. case LPFC_PCI_DEV_LP:
  13906. rc = lpfc_pci_suspend_one_s3(dev);
  13907. break;
  13908. case LPFC_PCI_DEV_OC:
  13909. rc = lpfc_pci_suspend_one_s4(dev);
  13910. break;
  13911. default:
  13912. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13913. "1425 Invalid PCI device group: 0x%x\n",
  13914. phba->pci_dev_grp);
  13915. break;
  13916. }
  13917. return rc;
  13918. }
  13919. /**
  13920. * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
  13921. * @dev: pointer to device
  13922. *
  13923. * This routine is to be registered to the kernel's PCI subsystem to support
  13924. * system Power Management (PM). When PM invokes this method, it dispatches
  13925. * the action to the proper SLI-3 or SLI-4 device resume routine, which will
  13926. * resume the device.
  13927. *
  13928. * Return code
  13929. * 0 - driver suspended the device
  13930. * Error otherwise
  13931. **/
  13932. static int __maybe_unused
  13933. lpfc_pci_resume_one(struct device *dev)
  13934. {
  13935. struct Scsi_Host *shost = dev_get_drvdata(dev);
  13936. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  13937. int rc = -ENODEV;
  13938. switch (phba->pci_dev_grp) {
  13939. case LPFC_PCI_DEV_LP:
  13940. rc = lpfc_pci_resume_one_s3(dev);
  13941. break;
  13942. case LPFC_PCI_DEV_OC:
  13943. rc = lpfc_pci_resume_one_s4(dev);
  13944. break;
  13945. default:
  13946. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13947. "1426 Invalid PCI device group: 0x%x\n",
  13948. phba->pci_dev_grp);
  13949. break;
  13950. }
  13951. return rc;
  13952. }
  13953. /**
  13954. * lpfc_io_error_detected - lpfc method for handling PCI I/O error
  13955. * @pdev: pointer to PCI device.
  13956. * @state: the current PCI connection state.
  13957. *
  13958. * This routine is registered to the PCI subsystem for error handling. This
  13959. * function is called by the PCI subsystem after a PCI bus error affecting
  13960. * this device has been detected. When this routine is invoked, it dispatches
  13961. * the action to the proper SLI-3 or SLI-4 device error detected handling
  13962. * routine, which will perform the proper error detected operation.
  13963. *
  13964. * Return codes
  13965. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  13966. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  13967. **/
  13968. static pci_ers_result_t
  13969. lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  13970. {
  13971. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  13972. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  13973. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  13974. if (phba->link_state == LPFC_HBA_ERROR &&
  13975. phba->hba_flag & HBA_IOQ_FLUSH)
  13976. return PCI_ERS_RESULT_NEED_RESET;
  13977. switch (phba->pci_dev_grp) {
  13978. case LPFC_PCI_DEV_LP:
  13979. rc = lpfc_io_error_detected_s3(pdev, state);
  13980. break;
  13981. case LPFC_PCI_DEV_OC:
  13982. rc = lpfc_io_error_detected_s4(pdev, state);
  13983. break;
  13984. default:
  13985. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13986. "1427 Invalid PCI device group: 0x%x\n",
  13987. phba->pci_dev_grp);
  13988. break;
  13989. }
  13990. return rc;
  13991. }
  13992. /**
  13993. * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
  13994. * @pdev: pointer to PCI device.
  13995. *
  13996. * This routine is registered to the PCI subsystem for error handling. This
  13997. * function is called after PCI bus has been reset to restart the PCI card
  13998. * from scratch, as if from a cold-boot. When this routine is invoked, it
  13999. * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
  14000. * routine, which will perform the proper device reset.
  14001. *
  14002. * Return codes
  14003. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  14004. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  14005. **/
  14006. static pci_ers_result_t
  14007. lpfc_io_slot_reset(struct pci_dev *pdev)
  14008. {
  14009. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  14010. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  14011. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  14012. switch (phba->pci_dev_grp) {
  14013. case LPFC_PCI_DEV_LP:
  14014. rc = lpfc_io_slot_reset_s3(pdev);
  14015. break;
  14016. case LPFC_PCI_DEV_OC:
  14017. rc = lpfc_io_slot_reset_s4(pdev);
  14018. break;
  14019. default:
  14020. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  14021. "1428 Invalid PCI device group: 0x%x\n",
  14022. phba->pci_dev_grp);
  14023. break;
  14024. }
  14025. return rc;
  14026. }
  14027. /**
  14028. * lpfc_io_resume - lpfc method for resuming PCI I/O operation
  14029. * @pdev: pointer to PCI device
  14030. *
  14031. * This routine is registered to the PCI subsystem for error handling. It
  14032. * is called when kernel error recovery tells the lpfc driver that it is
  14033. * OK to resume normal PCI operation after PCI bus error recovery. When
  14034. * this routine is invoked, it dispatches the action to the proper SLI-3
  14035. * or SLI-4 device io_resume routine, which will resume the device operation.
  14036. **/
  14037. static void
  14038. lpfc_io_resume(struct pci_dev *pdev)
  14039. {
  14040. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  14041. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  14042. switch (phba->pci_dev_grp) {
  14043. case LPFC_PCI_DEV_LP:
  14044. lpfc_io_resume_s3(pdev);
  14045. break;
  14046. case LPFC_PCI_DEV_OC:
  14047. lpfc_io_resume_s4(pdev);
  14048. break;
  14049. default:
  14050. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  14051. "1429 Invalid PCI device group: 0x%x\n",
  14052. phba->pci_dev_grp);
  14053. break;
  14054. }
  14055. return;
  14056. }
  14057. /**
  14058. * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
  14059. * @phba: pointer to lpfc hba data structure.
  14060. *
  14061. * This routine checks to see if OAS is supported for this adapter. If
  14062. * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
  14063. * the enable oas flag is cleared and the pool created for OAS device data
  14064. * is destroyed.
  14065. *
  14066. **/
  14067. static void
  14068. lpfc_sli4_oas_verify(struct lpfc_hba *phba)
  14069. {
  14070. if (!phba->cfg_EnableXLane)
  14071. return;
  14072. if (phba->sli4_hba.pc_sli4_params.oas_supported) {
  14073. phba->cfg_fof = 1;
  14074. } else {
  14075. phba->cfg_fof = 0;
  14076. mempool_destroy(phba->device_data_mem_pool);
  14077. phba->device_data_mem_pool = NULL;
  14078. }
  14079. return;
  14080. }
  14081. /**
  14082. * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
  14083. * @phba: pointer to lpfc hba data structure.
  14084. *
  14085. * This routine checks to see if RAS is supported by the adapter. Check the
  14086. * function through which RAS support enablement is to be done.
  14087. **/
  14088. void
  14089. lpfc_sli4_ras_init(struct lpfc_hba *phba)
  14090. {
  14091. /* if ASIC_GEN_NUM >= 0xC) */
  14092. if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  14093. LPFC_SLI_INTF_IF_TYPE_6) ||
  14094. (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
  14095. LPFC_SLI_INTF_FAMILY_G6)) {
  14096. phba->ras_fwlog.ras_hwsupport = true;
  14097. if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) &&
  14098. phba->cfg_ras_fwlog_buffsize)
  14099. phba->ras_fwlog.ras_enabled = true;
  14100. else
  14101. phba->ras_fwlog.ras_enabled = false;
  14102. } else {
  14103. phba->ras_fwlog.ras_hwsupport = false;
  14104. }
  14105. }
  14106. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  14107. static const struct pci_error_handlers lpfc_err_handler = {
  14108. .error_detected = lpfc_io_error_detected,
  14109. .slot_reset = lpfc_io_slot_reset,
  14110. .resume = lpfc_io_resume,
  14111. };
  14112. static SIMPLE_DEV_PM_OPS(lpfc_pci_pm_ops_one,
  14113. lpfc_pci_suspend_one,
  14114. lpfc_pci_resume_one);
  14115. static struct pci_driver lpfc_driver = {
  14116. .name = LPFC_DRIVER_NAME,
  14117. .id_table = lpfc_id_table,
  14118. .probe = lpfc_pci_probe_one,
  14119. .remove = lpfc_pci_remove_one,
  14120. .shutdown = lpfc_pci_remove_one,
  14121. .driver.pm = &lpfc_pci_pm_ops_one,
  14122. .err_handler = &lpfc_err_handler,
  14123. };
  14124. static const struct file_operations lpfc_mgmt_fop = {
  14125. .owner = THIS_MODULE,
  14126. };
  14127. static struct miscdevice lpfc_mgmt_dev = {
  14128. .minor = MISC_DYNAMIC_MINOR,
  14129. .name = "lpfcmgmt",
  14130. .fops = &lpfc_mgmt_fop,
  14131. };
  14132. /**
  14133. * lpfc_init - lpfc module initialization routine
  14134. *
  14135. * This routine is to be invoked when the lpfc module is loaded into the
  14136. * kernel. The special kernel macro module_init() is used to indicate the
  14137. * role of this routine to the kernel as lpfc module entry point.
  14138. *
  14139. * Return codes
  14140. * 0 - successful
  14141. * -ENOMEM - FC attach transport failed
  14142. * all others - failed
  14143. */
  14144. static int __init
  14145. lpfc_init(void)
  14146. {
  14147. int error = 0;
  14148. pr_info(LPFC_MODULE_DESC "\n");
  14149. pr_info(LPFC_COPYRIGHT "\n");
  14150. error = misc_register(&lpfc_mgmt_dev);
  14151. if (error)
  14152. printk(KERN_ERR "Could not register lpfcmgmt device, "
  14153. "misc_register returned with status %d", error);
  14154. error = -ENOMEM;
  14155. lpfc_transport_functions.vport_create = lpfc_vport_create;
  14156. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  14157. lpfc_transport_template =
  14158. fc_attach_transport(&lpfc_transport_functions);
  14159. if (lpfc_transport_template == NULL)
  14160. goto unregister;
  14161. lpfc_vport_transport_template =
  14162. fc_attach_transport(&lpfc_vport_transport_functions);
  14163. if (lpfc_vport_transport_template == NULL) {
  14164. fc_release_transport(lpfc_transport_template);
  14165. goto unregister;
  14166. }
  14167. lpfc_wqe_cmd_template();
  14168. lpfc_nvmet_cmd_template();
  14169. /* Initialize in case vector mapping is needed */
  14170. lpfc_present_cpu = num_present_cpus();
  14171. lpfc_pldv_detect = false;
  14172. error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
  14173. "lpfc/sli4:online",
  14174. lpfc_cpu_online, lpfc_cpu_offline);
  14175. if (error < 0)
  14176. goto cpuhp_failure;
  14177. lpfc_cpuhp_state = error;
  14178. error = pci_register_driver(&lpfc_driver);
  14179. if (error)
  14180. goto unwind;
  14181. return error;
  14182. unwind:
  14183. cpuhp_remove_multi_state(lpfc_cpuhp_state);
  14184. cpuhp_failure:
  14185. fc_release_transport(lpfc_transport_template);
  14186. fc_release_transport(lpfc_vport_transport_template);
  14187. unregister:
  14188. misc_deregister(&lpfc_mgmt_dev);
  14189. return error;
  14190. }
  14191. void lpfc_dmp_dbg(struct lpfc_hba *phba)
  14192. {
  14193. unsigned int start_idx;
  14194. unsigned int dbg_cnt;
  14195. unsigned int temp_idx;
  14196. int i;
  14197. int j = 0;
  14198. unsigned long rem_nsec;
  14199. if (atomic_cmpxchg(&phba->dbg_log_dmping, 0, 1) != 0)
  14200. return;
  14201. start_idx = (unsigned int)atomic_read(&phba->dbg_log_idx) % DBG_LOG_SZ;
  14202. dbg_cnt = (unsigned int)atomic_read(&phba->dbg_log_cnt);
  14203. if (!dbg_cnt)
  14204. goto out;
  14205. temp_idx = start_idx;
  14206. if (dbg_cnt >= DBG_LOG_SZ) {
  14207. dbg_cnt = DBG_LOG_SZ;
  14208. temp_idx -= 1;
  14209. } else {
  14210. if ((start_idx + dbg_cnt) > (DBG_LOG_SZ - 1)) {
  14211. temp_idx = (start_idx + dbg_cnt) % DBG_LOG_SZ;
  14212. } else {
  14213. if (start_idx < dbg_cnt)
  14214. start_idx = DBG_LOG_SZ - (dbg_cnt - start_idx);
  14215. else
  14216. start_idx -= dbg_cnt;
  14217. }
  14218. }
  14219. dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n",
  14220. start_idx, temp_idx, dbg_cnt);
  14221. for (i = 0; i < dbg_cnt; i++) {
  14222. if ((start_idx + i) < DBG_LOG_SZ)
  14223. temp_idx = (start_idx + i) % DBG_LOG_SZ;
  14224. else
  14225. temp_idx = j++;
  14226. rem_nsec = do_div(phba->dbg_log[temp_idx].t_ns, NSEC_PER_SEC);
  14227. dev_info(&phba->pcidev->dev, "%d: [%5lu.%06lu] %s",
  14228. temp_idx,
  14229. (unsigned long)phba->dbg_log[temp_idx].t_ns,
  14230. rem_nsec / 1000,
  14231. phba->dbg_log[temp_idx].log);
  14232. }
  14233. out:
  14234. atomic_set(&phba->dbg_log_cnt, 0);
  14235. atomic_set(&phba->dbg_log_dmping, 0);
  14236. }
  14237. __printf(2, 3)
  14238. void lpfc_dbg_print(struct lpfc_hba *phba, const char *fmt, ...)
  14239. {
  14240. unsigned int idx;
  14241. va_list args;
  14242. int dbg_dmping = atomic_read(&phba->dbg_log_dmping);
  14243. struct va_format vaf;
  14244. va_start(args, fmt);
  14245. if (unlikely(dbg_dmping)) {
  14246. vaf.fmt = fmt;
  14247. vaf.va = &args;
  14248. dev_info(&phba->pcidev->dev, "%pV", &vaf);
  14249. va_end(args);
  14250. return;
  14251. }
  14252. idx = (unsigned int)atomic_fetch_add(1, &phba->dbg_log_idx) %
  14253. DBG_LOG_SZ;
  14254. atomic_inc(&phba->dbg_log_cnt);
  14255. vscnprintf(phba->dbg_log[idx].log,
  14256. sizeof(phba->dbg_log[idx].log), fmt, args);
  14257. va_end(args);
  14258. phba->dbg_log[idx].t_ns = local_clock();
  14259. }
  14260. /**
  14261. * lpfc_exit - lpfc module removal routine
  14262. *
  14263. * This routine is invoked when the lpfc module is removed from the kernel.
  14264. * The special kernel macro module_exit() is used to indicate the role of
  14265. * this routine to the kernel as lpfc module exit point.
  14266. */
  14267. static void __exit
  14268. lpfc_exit(void)
  14269. {
  14270. misc_deregister(&lpfc_mgmt_dev);
  14271. pci_unregister_driver(&lpfc_driver);
  14272. cpuhp_remove_multi_state(lpfc_cpuhp_state);
  14273. fc_release_transport(lpfc_transport_template);
  14274. fc_release_transport(lpfc_vport_transport_template);
  14275. idr_destroy(&lpfc_hba_index);
  14276. }
  14277. module_init(lpfc_init);
  14278. module_exit(lpfc_exit);
  14279. MODULE_LICENSE("GPL");
  14280. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  14281. MODULE_AUTHOR("Broadcom");
  14282. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);