lpfc_init.c 325 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2013 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/idr.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/module.h>
  27. #include <linux/kthread.h>
  28. #include <linux/pci.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/ctype.h>
  31. #include <linux/aer.h>
  32. #include <linux/slab.h>
  33. #include <linux/firmware.h>
  34. #include <linux/miscdevice.h>
  35. #include <linux/percpu.h>
  36. #include <scsi/scsi.h>
  37. #include <scsi/scsi_device.h>
  38. #include <scsi/scsi_host.h>
  39. #include <scsi/scsi_transport_fc.h>
  40. #include "lpfc_hw4.h"
  41. #include "lpfc_hw.h"
  42. #include "lpfc_sli.h"
  43. #include "lpfc_sli4.h"
  44. #include "lpfc_nl.h"
  45. #include "lpfc_disc.h"
  46. #include "lpfc_scsi.h"
  47. #include "lpfc.h"
  48. #include "lpfc_logmsg.h"
  49. #include "lpfc_crtn.h"
  50. #include "lpfc_vport.h"
  51. #include "lpfc_version.h"
  52. char *_dump_buf_data;
  53. unsigned long _dump_buf_data_order;
  54. char *_dump_buf_dif;
  55. unsigned long _dump_buf_dif_order;
  56. spinlock_t _dump_buf_lock;
  57. /* Used when mapping IRQ vectors in a driver centric manner */
  58. uint16_t *lpfc_used_cpu;
  59. uint32_t lpfc_present_cpu;
  60. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  61. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  62. static int lpfc_sli4_queue_verify(struct lpfc_hba *);
  63. static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
  64. static int lpfc_setup_endian_order(struct lpfc_hba *);
  65. static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
  66. static void lpfc_free_els_sgl_list(struct lpfc_hba *);
  67. static void lpfc_init_sgl_list(struct lpfc_hba *);
  68. static int lpfc_init_active_sgl_array(struct lpfc_hba *);
  69. static void lpfc_free_active_sgl(struct lpfc_hba *);
  70. static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
  71. static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
  72. static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
  73. static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
  74. static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
  75. static void lpfc_sli4_disable_intr(struct lpfc_hba *);
  76. static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
  77. static struct scsi_transport_template *lpfc_transport_template = NULL;
  78. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  79. static DEFINE_IDR(lpfc_hba_index);
  80. /**
  81. * lpfc_config_port_prep - Perform lpfc initialization prior to config port
  82. * @phba: pointer to lpfc hba data structure.
  83. *
  84. * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
  85. * mailbox command. It retrieves the revision information from the HBA and
  86. * collects the Vital Product Data (VPD) about the HBA for preparing the
  87. * configuration of the HBA.
  88. *
  89. * Return codes:
  90. * 0 - success.
  91. * -ERESTART - requests the SLI layer to reset the HBA and try again.
  92. * Any other value - indicates an error.
  93. **/
  94. int
  95. lpfc_config_port_prep(struct lpfc_hba *phba)
  96. {
  97. lpfc_vpd_t *vp = &phba->vpd;
  98. int i = 0, rc;
  99. LPFC_MBOXQ_t *pmb;
  100. MAILBOX_t *mb;
  101. char *lpfc_vpd_data = NULL;
  102. uint16_t offset = 0;
  103. static char licensed[56] =
  104. "key unlock for use with gnu public licensed code only\0";
  105. static int init_key = 1;
  106. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  107. if (!pmb) {
  108. phba->link_state = LPFC_HBA_ERROR;
  109. return -ENOMEM;
  110. }
  111. mb = &pmb->u.mb;
  112. phba->link_state = LPFC_INIT_MBX_CMDS;
  113. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  114. if (init_key) {
  115. uint32_t *ptext = (uint32_t *) licensed;
  116. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  117. *ptext = cpu_to_be32(*ptext);
  118. init_key = 0;
  119. }
  120. lpfc_read_nv(phba, pmb);
  121. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  122. sizeof (mb->un.varRDnvp.rsvd3));
  123. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  124. sizeof (licensed));
  125. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  126. if (rc != MBX_SUCCESS) {
  127. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  128. "0324 Config Port initialization "
  129. "error, mbxCmd x%x READ_NVPARM, "
  130. "mbxStatus x%x\n",
  131. mb->mbxCommand, mb->mbxStatus);
  132. mempool_free(pmb, phba->mbox_mem_pool);
  133. return -ERESTART;
  134. }
  135. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  136. sizeof(phba->wwnn));
  137. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  138. sizeof(phba->wwpn));
  139. }
  140. phba->sli3_options = 0x0;
  141. /* Setup and issue mailbox READ REV command */
  142. lpfc_read_rev(phba, pmb);
  143. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  144. if (rc != MBX_SUCCESS) {
  145. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  146. "0439 Adapter failed to init, mbxCmd x%x "
  147. "READ_REV, mbxStatus x%x\n",
  148. mb->mbxCommand, mb->mbxStatus);
  149. mempool_free( pmb, phba->mbox_mem_pool);
  150. return -ERESTART;
  151. }
  152. /*
  153. * The value of rr must be 1 since the driver set the cv field to 1.
  154. * This setting requires the FW to set all revision fields.
  155. */
  156. if (mb->un.varRdRev.rr == 0) {
  157. vp->rev.rBit = 0;
  158. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  159. "0440 Adapter failed to init, READ_REV has "
  160. "missing revision information.\n");
  161. mempool_free(pmb, phba->mbox_mem_pool);
  162. return -ERESTART;
  163. }
  164. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
  165. mempool_free(pmb, phba->mbox_mem_pool);
  166. return -EINVAL;
  167. }
  168. /* Save information as VPD data */
  169. vp->rev.rBit = 1;
  170. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  171. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  172. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  173. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  174. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  175. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  176. vp->rev.smRev = mb->un.varRdRev.smRev;
  177. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  178. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  179. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  180. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  181. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  182. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  183. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  184. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  185. /* If the sli feature level is less then 9, we must
  186. * tear down all RPIs and VPIs on link down if NPIV
  187. * is enabled.
  188. */
  189. if (vp->rev.feaLevelHigh < 9)
  190. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  191. if (lpfc_is_LC_HBA(phba->pcidev->device))
  192. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  193. sizeof (phba->RandomData));
  194. /* Get adapter VPD information */
  195. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  196. if (!lpfc_vpd_data)
  197. goto out_free_mbox;
  198. do {
  199. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
  200. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  201. if (rc != MBX_SUCCESS) {
  202. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  203. "0441 VPD not present on adapter, "
  204. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  205. mb->mbxCommand, mb->mbxStatus);
  206. mb->un.varDmp.word_cnt = 0;
  207. }
  208. /* dump mem may return a zero when finished or we got a
  209. * mailbox error, either way we are done.
  210. */
  211. if (mb->un.varDmp.word_cnt == 0)
  212. break;
  213. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  214. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  215. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  216. lpfc_vpd_data + offset,
  217. mb->un.varDmp.word_cnt);
  218. offset += mb->un.varDmp.word_cnt;
  219. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  220. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  221. kfree(lpfc_vpd_data);
  222. out_free_mbox:
  223. mempool_free(pmb, phba->mbox_mem_pool);
  224. return 0;
  225. }
  226. /**
  227. * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
  228. * @phba: pointer to lpfc hba data structure.
  229. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  230. *
  231. * This is the completion handler for driver's configuring asynchronous event
  232. * mailbox command to the device. If the mailbox command returns successfully,
  233. * it will set internal async event support flag to 1; otherwise, it will
  234. * set internal async event support flag to 0.
  235. **/
  236. static void
  237. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  238. {
  239. if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
  240. phba->temp_sensor_support = 1;
  241. else
  242. phba->temp_sensor_support = 0;
  243. mempool_free(pmboxq, phba->mbox_mem_pool);
  244. return;
  245. }
  246. /**
  247. * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
  248. * @phba: pointer to lpfc hba data structure.
  249. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  250. *
  251. * This is the completion handler for dump mailbox command for getting
  252. * wake up parameters. When this command complete, the response contain
  253. * Option rom version of the HBA. This function translate the version number
  254. * into a human readable string and store it in OptionROMVersion.
  255. **/
  256. static void
  257. lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  258. {
  259. struct prog_id *prg;
  260. uint32_t prog_id_word;
  261. char dist = ' ';
  262. /* character array used for decoding dist type. */
  263. char dist_char[] = "nabx";
  264. if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
  265. mempool_free(pmboxq, phba->mbox_mem_pool);
  266. return;
  267. }
  268. prg = (struct prog_id *) &prog_id_word;
  269. /* word 7 contain option rom version */
  270. prog_id_word = pmboxq->u.mb.un.varWords[7];
  271. /* Decode the Option rom version word to a readable string */
  272. if (prg->dist < 4)
  273. dist = dist_char[prg->dist];
  274. if ((prg->dist == 3) && (prg->num == 0))
  275. sprintf(phba->OptionROMVersion, "%d.%d%d",
  276. prg->ver, prg->rev, prg->lev);
  277. else
  278. sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
  279. prg->ver, prg->rev, prg->lev,
  280. dist, prg->num);
  281. mempool_free(pmboxq, phba->mbox_mem_pool);
  282. return;
  283. }
  284. /**
  285. * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
  286. * cfg_soft_wwnn, cfg_soft_wwpn
  287. * @vport: pointer to lpfc vport data structure.
  288. *
  289. *
  290. * Return codes
  291. * None.
  292. **/
  293. void
  294. lpfc_update_vport_wwn(struct lpfc_vport *vport)
  295. {
  296. /* If the soft name exists then update it using the service params */
  297. if (vport->phba->cfg_soft_wwnn)
  298. u64_to_wwn(vport->phba->cfg_soft_wwnn,
  299. vport->fc_sparam.nodeName.u.wwn);
  300. if (vport->phba->cfg_soft_wwpn)
  301. u64_to_wwn(vport->phba->cfg_soft_wwpn,
  302. vport->fc_sparam.portName.u.wwn);
  303. /*
  304. * If the name is empty or there exists a soft name
  305. * then copy the service params name, otherwise use the fc name
  306. */
  307. if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
  308. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  309. sizeof(struct lpfc_name));
  310. else
  311. memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
  312. sizeof(struct lpfc_name));
  313. if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
  314. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  315. sizeof(struct lpfc_name));
  316. else
  317. memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
  318. sizeof(struct lpfc_name));
  319. }
  320. /**
  321. * lpfc_config_port_post - Perform lpfc initialization after config port
  322. * @phba: pointer to lpfc hba data structure.
  323. *
  324. * This routine will do LPFC initialization after the CONFIG_PORT mailbox
  325. * command call. It performs all internal resource and state setups on the
  326. * port: post IOCB buffers, enable appropriate host interrupt attentions,
  327. * ELS ring timers, etc.
  328. *
  329. * Return codes
  330. * 0 - success.
  331. * Any other value - error.
  332. **/
  333. int
  334. lpfc_config_port_post(struct lpfc_hba *phba)
  335. {
  336. struct lpfc_vport *vport = phba->pport;
  337. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  338. LPFC_MBOXQ_t *pmb;
  339. MAILBOX_t *mb;
  340. struct lpfc_dmabuf *mp;
  341. struct lpfc_sli *psli = &phba->sli;
  342. uint32_t status, timeout;
  343. int i, j;
  344. int rc;
  345. spin_lock_irq(&phba->hbalock);
  346. /*
  347. * If the Config port completed correctly the HBA is not
  348. * over heated any more.
  349. */
  350. if (phba->over_temp_state == HBA_OVER_TEMP)
  351. phba->over_temp_state = HBA_NORMAL_TEMP;
  352. spin_unlock_irq(&phba->hbalock);
  353. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  354. if (!pmb) {
  355. phba->link_state = LPFC_HBA_ERROR;
  356. return -ENOMEM;
  357. }
  358. mb = &pmb->u.mb;
  359. /* Get login parameters for NID. */
  360. rc = lpfc_read_sparam(phba, pmb, 0);
  361. if (rc) {
  362. mempool_free(pmb, phba->mbox_mem_pool);
  363. return -ENOMEM;
  364. }
  365. pmb->vport = vport;
  366. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  367. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  368. "0448 Adapter failed init, mbxCmd x%x "
  369. "READ_SPARM mbxStatus x%x\n",
  370. mb->mbxCommand, mb->mbxStatus);
  371. phba->link_state = LPFC_HBA_ERROR;
  372. mp = (struct lpfc_dmabuf *) pmb->context1;
  373. mempool_free(pmb, phba->mbox_mem_pool);
  374. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  375. kfree(mp);
  376. return -EIO;
  377. }
  378. mp = (struct lpfc_dmabuf *) pmb->context1;
  379. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  380. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  381. kfree(mp);
  382. pmb->context1 = NULL;
  383. lpfc_update_vport_wwn(vport);
  384. /* Update the fc_host data structures with new wwn. */
  385. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  386. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  387. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  388. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  389. /* This should be consolidated into parse_vpd ? - mr */
  390. if (phba->SerialNumber[0] == 0) {
  391. uint8_t *outptr;
  392. outptr = &vport->fc_nodename.u.s.IEEE[0];
  393. for (i = 0; i < 12; i++) {
  394. status = *outptr++;
  395. j = ((status & 0xf0) >> 4);
  396. if (j <= 9)
  397. phba->SerialNumber[i] =
  398. (char)((uint8_t) 0x30 + (uint8_t) j);
  399. else
  400. phba->SerialNumber[i] =
  401. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  402. i++;
  403. j = (status & 0xf);
  404. if (j <= 9)
  405. phba->SerialNumber[i] =
  406. (char)((uint8_t) 0x30 + (uint8_t) j);
  407. else
  408. phba->SerialNumber[i] =
  409. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  410. }
  411. }
  412. lpfc_read_config(phba, pmb);
  413. pmb->vport = vport;
  414. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  415. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  416. "0453 Adapter failed to init, mbxCmd x%x "
  417. "READ_CONFIG, mbxStatus x%x\n",
  418. mb->mbxCommand, mb->mbxStatus);
  419. phba->link_state = LPFC_HBA_ERROR;
  420. mempool_free( pmb, phba->mbox_mem_pool);
  421. return -EIO;
  422. }
  423. /* Check if the port is disabled */
  424. lpfc_sli_read_link_ste(phba);
  425. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  426. i = (mb->un.varRdConfig.max_xri + 1);
  427. if (phba->cfg_hba_queue_depth > i) {
  428. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  429. "3359 HBA queue depth changed from %d to %d\n",
  430. phba->cfg_hba_queue_depth, i);
  431. phba->cfg_hba_queue_depth = i;
  432. }
  433. /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
  434. i = (mb->un.varRdConfig.max_xri >> 3);
  435. if (phba->pport->cfg_lun_queue_depth > i) {
  436. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  437. "3360 LUN queue depth changed from %d to %d\n",
  438. phba->pport->cfg_lun_queue_depth, i);
  439. phba->pport->cfg_lun_queue_depth = i;
  440. }
  441. phba->lmt = mb->un.varRdConfig.lmt;
  442. /* Get the default values for Model Name and Description */
  443. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  444. phba->link_state = LPFC_LINK_DOWN;
  445. /* Only process IOCBs on ELS ring till hba_state is READY */
  446. if (psli->ring[psli->extra_ring].sli.sli3.cmdringaddr)
  447. psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
  448. if (psli->ring[psli->fcp_ring].sli.sli3.cmdringaddr)
  449. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  450. if (psli->ring[psli->next_ring].sli.sli3.cmdringaddr)
  451. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  452. /* Post receive buffers for desired rings */
  453. if (phba->sli_rev != 3)
  454. lpfc_post_rcv_buf(phba);
  455. /*
  456. * Configure HBA MSI-X attention conditions to messages if MSI-X mode
  457. */
  458. if (phba->intr_type == MSIX) {
  459. rc = lpfc_config_msi(phba, pmb);
  460. if (rc) {
  461. mempool_free(pmb, phba->mbox_mem_pool);
  462. return -EIO;
  463. }
  464. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  465. if (rc != MBX_SUCCESS) {
  466. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  467. "0352 Config MSI mailbox command "
  468. "failed, mbxCmd x%x, mbxStatus x%x\n",
  469. pmb->u.mb.mbxCommand,
  470. pmb->u.mb.mbxStatus);
  471. mempool_free(pmb, phba->mbox_mem_pool);
  472. return -EIO;
  473. }
  474. }
  475. spin_lock_irq(&phba->hbalock);
  476. /* Initialize ERATT handling flag */
  477. phba->hba_flag &= ~HBA_ERATT_HANDLED;
  478. /* Enable appropriate host interrupts */
  479. if (lpfc_readl(phba->HCregaddr, &status)) {
  480. spin_unlock_irq(&phba->hbalock);
  481. return -EIO;
  482. }
  483. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  484. if (psli->num_rings > 0)
  485. status |= HC_R0INT_ENA;
  486. if (psli->num_rings > 1)
  487. status |= HC_R1INT_ENA;
  488. if (psli->num_rings > 2)
  489. status |= HC_R2INT_ENA;
  490. if (psli->num_rings > 3)
  491. status |= HC_R3INT_ENA;
  492. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  493. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  494. status &= ~(HC_R0INT_ENA);
  495. writel(status, phba->HCregaddr);
  496. readl(phba->HCregaddr); /* flush */
  497. spin_unlock_irq(&phba->hbalock);
  498. /* Set up ring-0 (ELS) timer */
  499. timeout = phba->fc_ratov * 2;
  500. mod_timer(&vport->els_tmofunc,
  501. jiffies + msecs_to_jiffies(1000 * timeout));
  502. /* Set up heart beat (HB) timer */
  503. mod_timer(&phba->hb_tmofunc,
  504. jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  505. phba->hb_outstanding = 0;
  506. phba->last_completion_time = jiffies;
  507. /* Set up error attention (ERATT) polling timer */
  508. mod_timer(&phba->eratt_poll,
  509. jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
  510. if (phba->hba_flag & LINK_DISABLED) {
  511. lpfc_printf_log(phba,
  512. KERN_ERR, LOG_INIT,
  513. "2598 Adapter Link is disabled.\n");
  514. lpfc_down_link(phba, pmb);
  515. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  516. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  517. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  518. lpfc_printf_log(phba,
  519. KERN_ERR, LOG_INIT,
  520. "2599 Adapter failed to issue DOWN_LINK"
  521. " mbox command rc 0x%x\n", rc);
  522. mempool_free(pmb, phba->mbox_mem_pool);
  523. return -EIO;
  524. }
  525. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  526. mempool_free(pmb, phba->mbox_mem_pool);
  527. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  528. if (rc)
  529. return rc;
  530. }
  531. /* MBOX buffer will be freed in mbox compl */
  532. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  533. if (!pmb) {
  534. phba->link_state = LPFC_HBA_ERROR;
  535. return -ENOMEM;
  536. }
  537. lpfc_config_async(phba, pmb, LPFC_ELS_RING);
  538. pmb->mbox_cmpl = lpfc_config_async_cmpl;
  539. pmb->vport = phba->pport;
  540. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  541. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  542. lpfc_printf_log(phba,
  543. KERN_ERR,
  544. LOG_INIT,
  545. "0456 Adapter failed to issue "
  546. "ASYNCEVT_ENABLE mbox status x%x\n",
  547. rc);
  548. mempool_free(pmb, phba->mbox_mem_pool);
  549. }
  550. /* Get Option rom version */
  551. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  552. if (!pmb) {
  553. phba->link_state = LPFC_HBA_ERROR;
  554. return -ENOMEM;
  555. }
  556. lpfc_dump_wakeup_param(phba, pmb);
  557. pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
  558. pmb->vport = phba->pport;
  559. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  560. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  561. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
  562. "to get Option ROM version status x%x\n", rc);
  563. mempool_free(pmb, phba->mbox_mem_pool);
  564. }
  565. return 0;
  566. }
  567. /**
  568. * lpfc_hba_init_link - Initialize the FC link
  569. * @phba: pointer to lpfc hba data structure.
  570. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  571. *
  572. * This routine will issue the INIT_LINK mailbox command call.
  573. * It is available to other drivers through the lpfc_hba data
  574. * structure for use as a delayed link up mechanism with the
  575. * module parameter lpfc_suppress_link_up.
  576. *
  577. * Return code
  578. * 0 - success
  579. * Any other value - error
  580. **/
  581. int
  582. lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
  583. {
  584. return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
  585. }
  586. /**
  587. * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
  588. * @phba: pointer to lpfc hba data structure.
  589. * @fc_topology: desired fc topology.
  590. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  591. *
  592. * This routine will issue the INIT_LINK mailbox command call.
  593. * It is available to other drivers through the lpfc_hba data
  594. * structure for use as a delayed link up mechanism with the
  595. * module parameter lpfc_suppress_link_up.
  596. *
  597. * Return code
  598. * 0 - success
  599. * Any other value - error
  600. **/
  601. int
  602. lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
  603. uint32_t flag)
  604. {
  605. struct lpfc_vport *vport = phba->pport;
  606. LPFC_MBOXQ_t *pmb;
  607. MAILBOX_t *mb;
  608. int rc;
  609. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  610. if (!pmb) {
  611. phba->link_state = LPFC_HBA_ERROR;
  612. return -ENOMEM;
  613. }
  614. mb = &pmb->u.mb;
  615. pmb->vport = vport;
  616. if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
  617. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
  618. !(phba->lmt & LMT_1Gb)) ||
  619. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
  620. !(phba->lmt & LMT_2Gb)) ||
  621. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
  622. !(phba->lmt & LMT_4Gb)) ||
  623. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
  624. !(phba->lmt & LMT_8Gb)) ||
  625. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
  626. !(phba->lmt & LMT_10Gb)) ||
  627. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
  628. !(phba->lmt & LMT_16Gb))) {
  629. /* Reset link speed to auto */
  630. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  631. "1302 Invalid speed for this board:%d "
  632. "Reset link speed to auto.\n",
  633. phba->cfg_link_speed);
  634. phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
  635. }
  636. lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
  637. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  638. if (phba->sli_rev < LPFC_SLI_REV4)
  639. lpfc_set_loopback_flag(phba);
  640. rc = lpfc_sli_issue_mbox(phba, pmb, flag);
  641. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  642. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  643. "0498 Adapter failed to init, mbxCmd x%x "
  644. "INIT_LINK, mbxStatus x%x\n",
  645. mb->mbxCommand, mb->mbxStatus);
  646. if (phba->sli_rev <= LPFC_SLI_REV3) {
  647. /* Clear all interrupt enable conditions */
  648. writel(0, phba->HCregaddr);
  649. readl(phba->HCregaddr); /* flush */
  650. /* Clear all pending interrupts */
  651. writel(0xffffffff, phba->HAregaddr);
  652. readl(phba->HAregaddr); /* flush */
  653. }
  654. phba->link_state = LPFC_HBA_ERROR;
  655. if (rc != MBX_BUSY || flag == MBX_POLL)
  656. mempool_free(pmb, phba->mbox_mem_pool);
  657. return -EIO;
  658. }
  659. phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
  660. if (flag == MBX_POLL)
  661. mempool_free(pmb, phba->mbox_mem_pool);
  662. return 0;
  663. }
  664. /**
  665. * lpfc_hba_down_link - this routine downs the FC link
  666. * @phba: pointer to lpfc hba data structure.
  667. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  668. *
  669. * This routine will issue the DOWN_LINK mailbox command call.
  670. * It is available to other drivers through the lpfc_hba data
  671. * structure for use to stop the link.
  672. *
  673. * Return code
  674. * 0 - success
  675. * Any other value - error
  676. **/
  677. int
  678. lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
  679. {
  680. LPFC_MBOXQ_t *pmb;
  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. lpfc_printf_log(phba,
  688. KERN_ERR, LOG_INIT,
  689. "0491 Adapter Link is disabled.\n");
  690. lpfc_down_link(phba, pmb);
  691. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  692. rc = lpfc_sli_issue_mbox(phba, pmb, flag);
  693. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  694. lpfc_printf_log(phba,
  695. KERN_ERR, LOG_INIT,
  696. "2522 Adapter failed to issue DOWN_LINK"
  697. " mbox command rc 0x%x\n", rc);
  698. mempool_free(pmb, phba->mbox_mem_pool);
  699. return -EIO;
  700. }
  701. if (flag == MBX_POLL)
  702. mempool_free(pmb, phba->mbox_mem_pool);
  703. return 0;
  704. }
  705. /**
  706. * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
  707. * @phba: pointer to lpfc HBA data structure.
  708. *
  709. * This routine will do LPFC uninitialization before the HBA is reset when
  710. * bringing down the SLI Layer.
  711. *
  712. * Return codes
  713. * 0 - success.
  714. * Any other value - error.
  715. **/
  716. int
  717. lpfc_hba_down_prep(struct lpfc_hba *phba)
  718. {
  719. struct lpfc_vport **vports;
  720. int i;
  721. if (phba->sli_rev <= LPFC_SLI_REV3) {
  722. /* Disable interrupts */
  723. writel(0, phba->HCregaddr);
  724. readl(phba->HCregaddr); /* flush */
  725. }
  726. if (phba->pport->load_flag & FC_UNLOADING)
  727. lpfc_cleanup_discovery_resources(phba->pport);
  728. else {
  729. vports = lpfc_create_vport_work_array(phba);
  730. if (vports != NULL)
  731. for (i = 0; i <= phba->max_vports &&
  732. vports[i] != NULL; i++)
  733. lpfc_cleanup_discovery_resources(vports[i]);
  734. lpfc_destroy_vport_work_array(phba, vports);
  735. }
  736. return 0;
  737. }
  738. /**
  739. * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
  740. * @phba: pointer to lpfc HBA data structure.
  741. *
  742. * This routine will do uninitialization after the HBA is reset when bring
  743. * down the SLI Layer.
  744. *
  745. * Return codes
  746. * 0 - success.
  747. * Any other value - error.
  748. **/
  749. static int
  750. lpfc_hba_down_post_s3(struct lpfc_hba *phba)
  751. {
  752. struct lpfc_sli *psli = &phba->sli;
  753. struct lpfc_sli_ring *pring;
  754. struct lpfc_dmabuf *mp, *next_mp;
  755. LIST_HEAD(completions);
  756. int i;
  757. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  758. lpfc_sli_hbqbuf_free_all(phba);
  759. else {
  760. /* Cleanup preposted buffers on the ELS ring */
  761. pring = &psli->ring[LPFC_ELS_RING];
  762. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  763. list_del(&mp->list);
  764. pring->postbufq_cnt--;
  765. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  766. kfree(mp);
  767. }
  768. }
  769. spin_lock_irq(&phba->hbalock);
  770. for (i = 0; i < psli->num_rings; i++) {
  771. pring = &psli->ring[i];
  772. /* At this point in time the HBA is either reset or DOA. Either
  773. * way, nothing should be on txcmplq as it will NEVER complete.
  774. */
  775. list_splice_init(&pring->txcmplq, &completions);
  776. spin_unlock_irq(&phba->hbalock);
  777. /* Cancel all the IOCBs from the completions list */
  778. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  779. IOERR_SLI_ABORTED);
  780. lpfc_sli_abort_iocb_ring(phba, pring);
  781. spin_lock_irq(&phba->hbalock);
  782. }
  783. spin_unlock_irq(&phba->hbalock);
  784. return 0;
  785. }
  786. /**
  787. * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
  788. * @phba: pointer to lpfc HBA data structure.
  789. *
  790. * This routine will do uninitialization after the HBA is reset when bring
  791. * down the SLI Layer.
  792. *
  793. * Return codes
  794. * 0 - success.
  795. * Any other value - error.
  796. **/
  797. static int
  798. lpfc_hba_down_post_s4(struct lpfc_hba *phba)
  799. {
  800. struct lpfc_scsi_buf *psb, *psb_next;
  801. LIST_HEAD(aborts);
  802. int ret;
  803. unsigned long iflag = 0;
  804. struct lpfc_sglq *sglq_entry = NULL;
  805. ret = lpfc_hba_down_post_s3(phba);
  806. if (ret)
  807. return ret;
  808. /* At this point in time the HBA is either reset or DOA. Either
  809. * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
  810. * on the lpfc_sgl_list so that it can either be freed if the
  811. * driver is unloading or reposted if the driver is restarting
  812. * the port.
  813. */
  814. spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
  815. /* scsl_buf_list */
  816. /* abts_sgl_list_lock required because worker thread uses this
  817. * list.
  818. */
  819. spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
  820. list_for_each_entry(sglq_entry,
  821. &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
  822. sglq_entry->state = SGL_FREED;
  823. list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
  824. &phba->sli4_hba.lpfc_sgl_list);
  825. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  826. /* abts_scsi_buf_list_lock required because worker thread uses this
  827. * list.
  828. */
  829. spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  830. list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
  831. &aborts);
  832. spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  833. spin_unlock_irq(&phba->hbalock);
  834. list_for_each_entry_safe(psb, psb_next, &aborts, list) {
  835. psb->pCmd = NULL;
  836. psb->status = IOSTAT_SUCCESS;
  837. }
  838. spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
  839. list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
  840. spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
  841. return 0;
  842. }
  843. /**
  844. * lpfc_hba_down_post - Wrapper func for hba down post routine
  845. * @phba: pointer to lpfc HBA data structure.
  846. *
  847. * This routine wraps the actual SLI3 or SLI4 routine for performing
  848. * uninitialization after the HBA is reset when bring down the SLI Layer.
  849. *
  850. * Return codes
  851. * 0 - success.
  852. * Any other value - error.
  853. **/
  854. int
  855. lpfc_hba_down_post(struct lpfc_hba *phba)
  856. {
  857. return (*phba->lpfc_hba_down_post)(phba);
  858. }
  859. /**
  860. * lpfc_hb_timeout - The HBA-timer timeout handler
  861. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  862. *
  863. * This is the HBA-timer timeout handler registered to the lpfc driver. When
  864. * this timer fires, a HBA timeout event shall be posted to the lpfc driver
  865. * work-port-events bitmap and the worker thread is notified. This timeout
  866. * event will be used by the worker thread to invoke the actual timeout
  867. * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
  868. * be performed in the timeout handler and the HBA timeout event bit shall
  869. * be cleared by the worker thread after it has taken the event bitmap out.
  870. **/
  871. static void
  872. lpfc_hb_timeout(unsigned long ptr)
  873. {
  874. struct lpfc_hba *phba;
  875. uint32_t tmo_posted;
  876. unsigned long iflag;
  877. phba = (struct lpfc_hba *)ptr;
  878. /* Check for heart beat timeout conditions */
  879. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  880. tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
  881. if (!tmo_posted)
  882. phba->pport->work_port_events |= WORKER_HB_TMO;
  883. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  884. /* Tell the worker thread there is work to do */
  885. if (!tmo_posted)
  886. lpfc_worker_wake_up(phba);
  887. return;
  888. }
  889. /**
  890. * lpfc_rrq_timeout - The RRQ-timer timeout handler
  891. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  892. *
  893. * This is the RRQ-timer timeout handler registered to the lpfc driver. When
  894. * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
  895. * work-port-events bitmap and the worker thread is notified. This timeout
  896. * event will be used by the worker thread to invoke the actual timeout
  897. * handler routine, lpfc_rrq_handler. Any periodical operations will
  898. * be performed in the timeout handler and the RRQ timeout event bit shall
  899. * be cleared by the worker thread after it has taken the event bitmap out.
  900. **/
  901. static void
  902. lpfc_rrq_timeout(unsigned long ptr)
  903. {
  904. struct lpfc_hba *phba;
  905. unsigned long iflag;
  906. phba = (struct lpfc_hba *)ptr;
  907. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  908. phba->hba_flag |= HBA_RRQ_ACTIVE;
  909. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  910. lpfc_worker_wake_up(phba);
  911. }
  912. /**
  913. * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
  914. * @phba: pointer to lpfc hba data structure.
  915. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  916. *
  917. * This is the callback function to the lpfc heart-beat mailbox command.
  918. * If configured, the lpfc driver issues the heart-beat mailbox command to
  919. * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
  920. * heart-beat mailbox command is issued, the driver shall set up heart-beat
  921. * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
  922. * heart-beat outstanding state. Once the mailbox command comes back and
  923. * no error conditions detected, the heart-beat mailbox command timer is
  924. * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
  925. * state is cleared for the next heart-beat. If the timer expired with the
  926. * heart-beat outstanding state set, the driver will put the HBA offline.
  927. **/
  928. static void
  929. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  930. {
  931. unsigned long drvr_flag;
  932. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  933. phba->hb_outstanding = 0;
  934. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  935. /* Check and reset heart-beat timer is necessary */
  936. mempool_free(pmboxq, phba->mbox_mem_pool);
  937. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  938. !(phba->link_state == LPFC_HBA_ERROR) &&
  939. !(phba->pport->load_flag & FC_UNLOADING))
  940. mod_timer(&phba->hb_tmofunc,
  941. jiffies +
  942. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  943. return;
  944. }
  945. /**
  946. * lpfc_hb_timeout_handler - The HBA-timer timeout handler
  947. * @phba: pointer to lpfc hba data structure.
  948. *
  949. * This is the actual HBA-timer timeout handler to be invoked by the worker
  950. * thread whenever the HBA timer fired and HBA-timeout event posted. This
  951. * handler performs any periodic operations needed for the device. If such
  952. * periodic event has already been attended to either in the interrupt handler
  953. * or by processing slow-ring or fast-ring events within the HBA-timer
  954. * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
  955. * the timer for the next timeout period. If lpfc heart-beat mailbox command
  956. * is configured and there is no heart-beat mailbox command outstanding, a
  957. * heart-beat mailbox is issued and timer set properly. Otherwise, if there
  958. * has been a heart-beat mailbox command outstanding, the HBA shall be put
  959. * to offline.
  960. **/
  961. void
  962. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  963. {
  964. struct lpfc_vport **vports;
  965. LPFC_MBOXQ_t *pmboxq;
  966. struct lpfc_dmabuf *buf_ptr;
  967. int retval, i;
  968. struct lpfc_sli *psli = &phba->sli;
  969. LIST_HEAD(completions);
  970. vports = lpfc_create_vport_work_array(phba);
  971. if (vports != NULL)
  972. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  973. lpfc_rcv_seq_check_edtov(vports[i]);
  974. lpfc_destroy_vport_work_array(phba, vports);
  975. if ((phba->link_state == LPFC_HBA_ERROR) ||
  976. (phba->pport->load_flag & FC_UNLOADING) ||
  977. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  978. return;
  979. spin_lock_irq(&phba->pport->work_port_lock);
  980. if (time_after(phba->last_completion_time +
  981. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
  982. jiffies)) {
  983. spin_unlock_irq(&phba->pport->work_port_lock);
  984. if (!phba->hb_outstanding)
  985. mod_timer(&phba->hb_tmofunc,
  986. jiffies +
  987. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  988. else
  989. mod_timer(&phba->hb_tmofunc,
  990. jiffies +
  991. msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
  992. return;
  993. }
  994. spin_unlock_irq(&phba->pport->work_port_lock);
  995. if (phba->elsbuf_cnt &&
  996. (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
  997. spin_lock_irq(&phba->hbalock);
  998. list_splice_init(&phba->elsbuf, &completions);
  999. phba->elsbuf_cnt = 0;
  1000. phba->elsbuf_prev_cnt = 0;
  1001. spin_unlock_irq(&phba->hbalock);
  1002. while (!list_empty(&completions)) {
  1003. list_remove_head(&completions, buf_ptr,
  1004. struct lpfc_dmabuf, list);
  1005. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1006. kfree(buf_ptr);
  1007. }
  1008. }
  1009. phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
  1010. /* If there is no heart beat outstanding, issue a heartbeat command */
  1011. if (phba->cfg_enable_hba_heartbeat) {
  1012. if (!phba->hb_outstanding) {
  1013. if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
  1014. (list_empty(&psli->mboxq))) {
  1015. pmboxq = mempool_alloc(phba->mbox_mem_pool,
  1016. GFP_KERNEL);
  1017. if (!pmboxq) {
  1018. mod_timer(&phba->hb_tmofunc,
  1019. jiffies +
  1020. msecs_to_jiffies(1000 *
  1021. LPFC_HB_MBOX_INTERVAL));
  1022. return;
  1023. }
  1024. lpfc_heart_beat(phba, pmboxq);
  1025. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  1026. pmboxq->vport = phba->pport;
  1027. retval = lpfc_sli_issue_mbox(phba, pmboxq,
  1028. MBX_NOWAIT);
  1029. if (retval != MBX_BUSY &&
  1030. retval != MBX_SUCCESS) {
  1031. mempool_free(pmboxq,
  1032. phba->mbox_mem_pool);
  1033. mod_timer(&phba->hb_tmofunc,
  1034. jiffies +
  1035. msecs_to_jiffies(1000 *
  1036. LPFC_HB_MBOX_INTERVAL));
  1037. return;
  1038. }
  1039. phba->skipped_hb = 0;
  1040. phba->hb_outstanding = 1;
  1041. } else if (time_before_eq(phba->last_completion_time,
  1042. phba->skipped_hb)) {
  1043. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1044. "2857 Last completion time not "
  1045. " updated in %d ms\n",
  1046. jiffies_to_msecs(jiffies
  1047. - phba->last_completion_time));
  1048. } else
  1049. phba->skipped_hb = jiffies;
  1050. mod_timer(&phba->hb_tmofunc,
  1051. jiffies +
  1052. msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
  1053. return;
  1054. } else {
  1055. /*
  1056. * If heart beat timeout called with hb_outstanding set
  1057. * we need to give the hb mailbox cmd a chance to
  1058. * complete or TMO.
  1059. */
  1060. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1061. "0459 Adapter heartbeat still out"
  1062. "standing:last compl time was %d ms.\n",
  1063. jiffies_to_msecs(jiffies
  1064. - phba->last_completion_time));
  1065. mod_timer(&phba->hb_tmofunc,
  1066. jiffies +
  1067. msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
  1068. }
  1069. }
  1070. }
  1071. /**
  1072. * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
  1073. * @phba: pointer to lpfc hba data structure.
  1074. *
  1075. * This routine is called to bring the HBA offline when HBA hardware error
  1076. * other than Port Error 6 has been detected.
  1077. **/
  1078. static void
  1079. lpfc_offline_eratt(struct lpfc_hba *phba)
  1080. {
  1081. struct lpfc_sli *psli = &phba->sli;
  1082. spin_lock_irq(&phba->hbalock);
  1083. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1084. spin_unlock_irq(&phba->hbalock);
  1085. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1086. lpfc_offline(phba);
  1087. lpfc_reset_barrier(phba);
  1088. spin_lock_irq(&phba->hbalock);
  1089. lpfc_sli_brdreset(phba);
  1090. spin_unlock_irq(&phba->hbalock);
  1091. lpfc_hba_down_post(phba);
  1092. lpfc_sli_brdready(phba, HS_MBRDY);
  1093. lpfc_unblock_mgmt_io(phba);
  1094. phba->link_state = LPFC_HBA_ERROR;
  1095. return;
  1096. }
  1097. /**
  1098. * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
  1099. * @phba: pointer to lpfc hba data structure.
  1100. *
  1101. * This routine is called to bring a SLI4 HBA offline when HBA hardware error
  1102. * other than Port Error 6 has been detected.
  1103. **/
  1104. void
  1105. lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
  1106. {
  1107. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1108. lpfc_offline(phba);
  1109. lpfc_sli4_brdreset(phba);
  1110. lpfc_hba_down_post(phba);
  1111. lpfc_sli4_post_status_check(phba);
  1112. lpfc_unblock_mgmt_io(phba);
  1113. phba->link_state = LPFC_HBA_ERROR;
  1114. }
  1115. /**
  1116. * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
  1117. * @phba: pointer to lpfc hba data structure.
  1118. *
  1119. * This routine is invoked to handle the deferred HBA hardware error
  1120. * conditions. This type of error is indicated by HBA by setting ER1
  1121. * and another ER bit in the host status register. The driver will
  1122. * wait until the ER1 bit clears before handling the error condition.
  1123. **/
  1124. static void
  1125. lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
  1126. {
  1127. uint32_t old_host_status = phba->work_hs;
  1128. struct lpfc_sli_ring *pring;
  1129. struct lpfc_sli *psli = &phba->sli;
  1130. /* If the pci channel is offline, ignore possible errors,
  1131. * since we cannot communicate with the pci card anyway.
  1132. */
  1133. if (pci_channel_offline(phba->pcidev)) {
  1134. spin_lock_irq(&phba->hbalock);
  1135. phba->hba_flag &= ~DEFER_ERATT;
  1136. spin_unlock_irq(&phba->hbalock);
  1137. return;
  1138. }
  1139. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1140. "0479 Deferred Adapter Hardware Error "
  1141. "Data: x%x x%x x%x\n",
  1142. phba->work_hs,
  1143. phba->work_status[0], phba->work_status[1]);
  1144. spin_lock_irq(&phba->hbalock);
  1145. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1146. spin_unlock_irq(&phba->hbalock);
  1147. /*
  1148. * Firmware stops when it triggred erratt. That could cause the I/Os
  1149. * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
  1150. * SCSI layer retry it after re-establishing link.
  1151. */
  1152. pring = &psli->ring[psli->fcp_ring];
  1153. lpfc_sli_abort_iocb_ring(phba, pring);
  1154. /*
  1155. * There was a firmware error. Take the hba offline and then
  1156. * attempt to restart it.
  1157. */
  1158. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  1159. lpfc_offline(phba);
  1160. /* Wait for the ER1 bit to clear.*/
  1161. while (phba->work_hs & HS_FFER1) {
  1162. msleep(100);
  1163. if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
  1164. phba->work_hs = UNPLUG_ERR ;
  1165. break;
  1166. }
  1167. /* If driver is unloading let the worker thread continue */
  1168. if (phba->pport->load_flag & FC_UNLOADING) {
  1169. phba->work_hs = 0;
  1170. break;
  1171. }
  1172. }
  1173. /*
  1174. * This is to ptrotect against a race condition in which
  1175. * first write to the host attention register clear the
  1176. * host status register.
  1177. */
  1178. if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
  1179. phba->work_hs = old_host_status & ~HS_FFER1;
  1180. spin_lock_irq(&phba->hbalock);
  1181. phba->hba_flag &= ~DEFER_ERATT;
  1182. spin_unlock_irq(&phba->hbalock);
  1183. phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
  1184. phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
  1185. }
  1186. static void
  1187. lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
  1188. {
  1189. struct lpfc_board_event_header board_event;
  1190. struct Scsi_Host *shost;
  1191. board_event.event_type = FC_REG_BOARD_EVENT;
  1192. board_event.subcategory = LPFC_EVENT_PORTINTERR;
  1193. shost = lpfc_shost_from_vport(phba->pport);
  1194. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1195. sizeof(board_event),
  1196. (char *) &board_event,
  1197. LPFC_NL_VENDOR_ID);
  1198. }
  1199. /**
  1200. * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
  1201. * @phba: pointer to lpfc hba data structure.
  1202. *
  1203. * This routine is invoked to handle the following HBA hardware error
  1204. * conditions:
  1205. * 1 - HBA error attention interrupt
  1206. * 2 - DMA ring index out of range
  1207. * 3 - Mailbox command came back as unknown
  1208. **/
  1209. static void
  1210. lpfc_handle_eratt_s3(struct lpfc_hba *phba)
  1211. {
  1212. struct lpfc_vport *vport = phba->pport;
  1213. struct lpfc_sli *psli = &phba->sli;
  1214. struct lpfc_sli_ring *pring;
  1215. uint32_t event_data;
  1216. unsigned long temperature;
  1217. struct temp_event temp_event_data;
  1218. struct Scsi_Host *shost;
  1219. /* If the pci channel is offline, ignore possible errors,
  1220. * since we cannot communicate with the pci card anyway.
  1221. */
  1222. if (pci_channel_offline(phba->pcidev)) {
  1223. spin_lock_irq(&phba->hbalock);
  1224. phba->hba_flag &= ~DEFER_ERATT;
  1225. spin_unlock_irq(&phba->hbalock);
  1226. return;
  1227. }
  1228. /* If resets are disabled then leave the HBA alone and return */
  1229. if (!phba->cfg_enable_hba_reset)
  1230. return;
  1231. /* Send an internal error event to mgmt application */
  1232. lpfc_board_errevt_to_mgmt(phba);
  1233. if (phba->hba_flag & DEFER_ERATT)
  1234. lpfc_handle_deferred_eratt(phba);
  1235. if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
  1236. if (phba->work_hs & HS_FFER6)
  1237. /* Re-establishing Link */
  1238. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1239. "1301 Re-establishing Link "
  1240. "Data: x%x x%x x%x\n",
  1241. phba->work_hs, phba->work_status[0],
  1242. phba->work_status[1]);
  1243. if (phba->work_hs & HS_FFER8)
  1244. /* Device Zeroization */
  1245. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1246. "2861 Host Authentication device "
  1247. "zeroization Data:x%x x%x x%x\n",
  1248. phba->work_hs, phba->work_status[0],
  1249. phba->work_status[1]);
  1250. spin_lock_irq(&phba->hbalock);
  1251. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1252. spin_unlock_irq(&phba->hbalock);
  1253. /*
  1254. * Firmware stops when it triggled erratt with HS_FFER6.
  1255. * That could cause the I/Os dropped by the firmware.
  1256. * Error iocb (I/O) on txcmplq and let the SCSI layer
  1257. * retry it after re-establishing link.
  1258. */
  1259. pring = &psli->ring[psli->fcp_ring];
  1260. lpfc_sli_abort_iocb_ring(phba, pring);
  1261. /*
  1262. * There was a firmware error. Take the hba offline and then
  1263. * attempt to restart it.
  1264. */
  1265. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1266. lpfc_offline(phba);
  1267. lpfc_sli_brdrestart(phba);
  1268. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  1269. lpfc_unblock_mgmt_io(phba);
  1270. return;
  1271. }
  1272. lpfc_unblock_mgmt_io(phba);
  1273. } else if (phba->work_hs & HS_CRIT_TEMP) {
  1274. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  1275. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  1276. temp_event_data.event_code = LPFC_CRIT_TEMP;
  1277. temp_event_data.data = (uint32_t)temperature;
  1278. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1279. "0406 Adapter maximum temperature exceeded "
  1280. "(%ld), taking this port offline "
  1281. "Data: x%x x%x x%x\n",
  1282. temperature, phba->work_hs,
  1283. phba->work_status[0], phba->work_status[1]);
  1284. shost = lpfc_shost_from_vport(phba->pport);
  1285. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1286. sizeof(temp_event_data),
  1287. (char *) &temp_event_data,
  1288. SCSI_NL_VID_TYPE_PCI
  1289. | PCI_VENDOR_ID_EMULEX);
  1290. spin_lock_irq(&phba->hbalock);
  1291. phba->over_temp_state = HBA_OVER_TEMP;
  1292. spin_unlock_irq(&phba->hbalock);
  1293. lpfc_offline_eratt(phba);
  1294. } else {
  1295. /* The if clause above forces this code path when the status
  1296. * failure is a value other than FFER6. Do not call the offline
  1297. * twice. This is the adapter hardware error path.
  1298. */
  1299. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1300. "0457 Adapter Hardware Error "
  1301. "Data: x%x x%x x%x\n",
  1302. phba->work_hs,
  1303. phba->work_status[0], phba->work_status[1]);
  1304. event_data = FC_REG_DUMP_EVENT;
  1305. shost = lpfc_shost_from_vport(vport);
  1306. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1307. sizeof(event_data), (char *) &event_data,
  1308. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1309. lpfc_offline_eratt(phba);
  1310. }
  1311. return;
  1312. }
  1313. /**
  1314. * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
  1315. * @phba: pointer to lpfc hba data structure.
  1316. * @mbx_action: flag for mailbox shutdown action.
  1317. *
  1318. * This routine is invoked to perform an SLI4 port PCI function reset in
  1319. * response to port status register polling attention. It waits for port
  1320. * status register (ERR, RDY, RN) bits before proceeding with function reset.
  1321. * During this process, interrupt vectors are freed and later requested
  1322. * for handling possible port resource change.
  1323. **/
  1324. static int
  1325. lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action)
  1326. {
  1327. int rc;
  1328. uint32_t intr_mode;
  1329. /*
  1330. * On error status condition, driver need to wait for port
  1331. * ready before performing reset.
  1332. */
  1333. rc = lpfc_sli4_pdev_status_reg_wait(phba);
  1334. if (!rc) {
  1335. /* need reset: attempt for port recovery */
  1336. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1337. "2887 Reset Needed: Attempting Port "
  1338. "Recovery...\n");
  1339. lpfc_offline_prep(phba, mbx_action);
  1340. lpfc_offline(phba);
  1341. /* release interrupt for possible resource change */
  1342. lpfc_sli4_disable_intr(phba);
  1343. lpfc_sli_brdrestart(phba);
  1344. /* request and enable interrupt */
  1345. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  1346. if (intr_mode == LPFC_INTR_ERROR) {
  1347. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1348. "3175 Failed to enable interrupt\n");
  1349. return -EIO;
  1350. } else {
  1351. phba->intr_mode = intr_mode;
  1352. }
  1353. rc = lpfc_online(phba);
  1354. if (rc == 0)
  1355. lpfc_unblock_mgmt_io(phba);
  1356. }
  1357. return rc;
  1358. }
  1359. /**
  1360. * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
  1361. * @phba: pointer to lpfc hba data structure.
  1362. *
  1363. * This routine is invoked to handle the SLI4 HBA hardware error attention
  1364. * conditions.
  1365. **/
  1366. static void
  1367. lpfc_handle_eratt_s4(struct lpfc_hba *phba)
  1368. {
  1369. struct lpfc_vport *vport = phba->pport;
  1370. uint32_t event_data;
  1371. struct Scsi_Host *shost;
  1372. uint32_t if_type;
  1373. struct lpfc_register portstat_reg = {0};
  1374. uint32_t reg_err1, reg_err2;
  1375. uint32_t uerrlo_reg, uemasklo_reg;
  1376. uint32_t pci_rd_rc1, pci_rd_rc2;
  1377. int rc;
  1378. /* If the pci channel is offline, ignore possible errors, since
  1379. * we cannot communicate with the pci card anyway.
  1380. */
  1381. if (pci_channel_offline(phba->pcidev))
  1382. return;
  1383. /* If resets are disabled then leave the HBA alone and return */
  1384. if (!phba->cfg_enable_hba_reset)
  1385. return;
  1386. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  1387. switch (if_type) {
  1388. case LPFC_SLI_INTF_IF_TYPE_0:
  1389. pci_rd_rc1 = lpfc_readl(
  1390. phba->sli4_hba.u.if_type0.UERRLOregaddr,
  1391. &uerrlo_reg);
  1392. pci_rd_rc2 = lpfc_readl(
  1393. phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
  1394. &uemasklo_reg);
  1395. /* consider PCI bus read error as pci_channel_offline */
  1396. if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
  1397. return;
  1398. lpfc_sli4_offline_eratt(phba);
  1399. break;
  1400. case LPFC_SLI_INTF_IF_TYPE_2:
  1401. pci_rd_rc1 = lpfc_readl(
  1402. phba->sli4_hba.u.if_type2.STATUSregaddr,
  1403. &portstat_reg.word0);
  1404. /* consider PCI bus read error as pci_channel_offline */
  1405. if (pci_rd_rc1 == -EIO) {
  1406. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1407. "3151 PCI bus read access failure: x%x\n",
  1408. readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
  1409. return;
  1410. }
  1411. reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  1412. reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  1413. if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
  1414. /* TODO: Register for Overtemp async events. */
  1415. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1416. "2889 Port Overtemperature event, "
  1417. "taking port offline\n");
  1418. spin_lock_irq(&phba->hbalock);
  1419. phba->over_temp_state = HBA_OVER_TEMP;
  1420. spin_unlock_irq(&phba->hbalock);
  1421. lpfc_sli4_offline_eratt(phba);
  1422. break;
  1423. }
  1424. if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1425. reg_err2 == SLIPORT_ERR2_REG_FW_RESTART)
  1426. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1427. "3143 Port Down: Firmware Restarted\n");
  1428. else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1429. reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
  1430. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1431. "3144 Port Down: Debug Dump\n");
  1432. else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1433. reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
  1434. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1435. "3145 Port Down: Provisioning\n");
  1436. /* Check port status register for function reset */
  1437. rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT);
  1438. if (rc == 0) {
  1439. /* don't report event on forced debug dump */
  1440. if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
  1441. reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
  1442. return;
  1443. else
  1444. break;
  1445. }
  1446. /* fall through for not able to recover */
  1447. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1448. "3152 Unrecoverable error, bring the port "
  1449. "offline\n");
  1450. lpfc_sli4_offline_eratt(phba);
  1451. break;
  1452. case LPFC_SLI_INTF_IF_TYPE_1:
  1453. default:
  1454. break;
  1455. }
  1456. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1457. "3123 Report dump event to upper layer\n");
  1458. /* Send an internal error event to mgmt application */
  1459. lpfc_board_errevt_to_mgmt(phba);
  1460. event_data = FC_REG_DUMP_EVENT;
  1461. shost = lpfc_shost_from_vport(vport);
  1462. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1463. sizeof(event_data), (char *) &event_data,
  1464. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1465. }
  1466. /**
  1467. * lpfc_handle_eratt - Wrapper func for handling hba error attention
  1468. * @phba: pointer to lpfc HBA data structure.
  1469. *
  1470. * This routine wraps the actual SLI3 or SLI4 hba error attention handling
  1471. * routine from the API jump table function pointer from the lpfc_hba struct.
  1472. *
  1473. * Return codes
  1474. * 0 - success.
  1475. * Any other value - error.
  1476. **/
  1477. void
  1478. lpfc_handle_eratt(struct lpfc_hba *phba)
  1479. {
  1480. (*phba->lpfc_handle_eratt)(phba);
  1481. }
  1482. /**
  1483. * lpfc_handle_latt - The HBA link event handler
  1484. * @phba: pointer to lpfc hba data structure.
  1485. *
  1486. * This routine is invoked from the worker thread to handle a HBA host
  1487. * attention link event.
  1488. **/
  1489. void
  1490. lpfc_handle_latt(struct lpfc_hba *phba)
  1491. {
  1492. struct lpfc_vport *vport = phba->pport;
  1493. struct lpfc_sli *psli = &phba->sli;
  1494. LPFC_MBOXQ_t *pmb;
  1495. volatile uint32_t control;
  1496. struct lpfc_dmabuf *mp;
  1497. int rc = 0;
  1498. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1499. if (!pmb) {
  1500. rc = 1;
  1501. goto lpfc_handle_latt_err_exit;
  1502. }
  1503. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1504. if (!mp) {
  1505. rc = 2;
  1506. goto lpfc_handle_latt_free_pmb;
  1507. }
  1508. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  1509. if (!mp->virt) {
  1510. rc = 3;
  1511. goto lpfc_handle_latt_free_mp;
  1512. }
  1513. /* Cleanup any outstanding ELS commands */
  1514. lpfc_els_flush_all_cmd(phba);
  1515. psli->slistat.link_event++;
  1516. lpfc_read_topology(phba, pmb, mp);
  1517. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  1518. pmb->vport = vport;
  1519. /* Block ELS IOCBs until we have processed this mbox command */
  1520. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  1521. rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
  1522. if (rc == MBX_NOT_FINISHED) {
  1523. rc = 4;
  1524. goto lpfc_handle_latt_free_mbuf;
  1525. }
  1526. /* Clear Link Attention in HA REG */
  1527. spin_lock_irq(&phba->hbalock);
  1528. writel(HA_LATT, phba->HAregaddr);
  1529. readl(phba->HAregaddr); /* flush */
  1530. spin_unlock_irq(&phba->hbalock);
  1531. return;
  1532. lpfc_handle_latt_free_mbuf:
  1533. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  1534. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1535. lpfc_handle_latt_free_mp:
  1536. kfree(mp);
  1537. lpfc_handle_latt_free_pmb:
  1538. mempool_free(pmb, phba->mbox_mem_pool);
  1539. lpfc_handle_latt_err_exit:
  1540. /* Enable Link attention interrupts */
  1541. spin_lock_irq(&phba->hbalock);
  1542. psli->sli_flag |= LPFC_PROCESS_LA;
  1543. control = readl(phba->HCregaddr);
  1544. control |= HC_LAINT_ENA;
  1545. writel(control, phba->HCregaddr);
  1546. readl(phba->HCregaddr); /* flush */
  1547. /* Clear Link Attention in HA REG */
  1548. writel(HA_LATT, phba->HAregaddr);
  1549. readl(phba->HAregaddr); /* flush */
  1550. spin_unlock_irq(&phba->hbalock);
  1551. lpfc_linkdown(phba);
  1552. phba->link_state = LPFC_HBA_ERROR;
  1553. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1554. "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
  1555. return;
  1556. }
  1557. /**
  1558. * lpfc_parse_vpd - Parse VPD (Vital Product Data)
  1559. * @phba: pointer to lpfc hba data structure.
  1560. * @vpd: pointer to the vital product data.
  1561. * @len: length of the vital product data in bytes.
  1562. *
  1563. * This routine parses the Vital Product Data (VPD). The VPD is treated as
  1564. * an array of characters. In this routine, the ModelName, ProgramType, and
  1565. * ModelDesc, etc. fields of the phba data structure will be populated.
  1566. *
  1567. * Return codes
  1568. * 0 - pointer to the VPD passed in is NULL
  1569. * 1 - success
  1570. **/
  1571. int
  1572. lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
  1573. {
  1574. uint8_t lenlo, lenhi;
  1575. int Length;
  1576. int i, j;
  1577. int finished = 0;
  1578. int index = 0;
  1579. if (!vpd)
  1580. return 0;
  1581. /* Vital Product */
  1582. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1583. "0455 Vital Product Data: x%x x%x x%x x%x\n",
  1584. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  1585. (uint32_t) vpd[3]);
  1586. while (!finished && (index < (len - 4))) {
  1587. switch (vpd[index]) {
  1588. case 0x82:
  1589. case 0x91:
  1590. index += 1;
  1591. lenlo = vpd[index];
  1592. index += 1;
  1593. lenhi = vpd[index];
  1594. index += 1;
  1595. i = ((((unsigned short)lenhi) << 8) + lenlo);
  1596. index += i;
  1597. break;
  1598. case 0x90:
  1599. index += 1;
  1600. lenlo = vpd[index];
  1601. index += 1;
  1602. lenhi = vpd[index];
  1603. index += 1;
  1604. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  1605. if (Length > len - index)
  1606. Length = len - index;
  1607. while (Length > 0) {
  1608. /* Look for Serial Number */
  1609. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  1610. index += 2;
  1611. i = vpd[index];
  1612. index += 1;
  1613. j = 0;
  1614. Length -= (3+i);
  1615. while(i--) {
  1616. phba->SerialNumber[j++] = vpd[index++];
  1617. if (j == 31)
  1618. break;
  1619. }
  1620. phba->SerialNumber[j] = 0;
  1621. continue;
  1622. }
  1623. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  1624. phba->vpd_flag |= VPD_MODEL_DESC;
  1625. index += 2;
  1626. i = vpd[index];
  1627. index += 1;
  1628. j = 0;
  1629. Length -= (3+i);
  1630. while(i--) {
  1631. phba->ModelDesc[j++] = vpd[index++];
  1632. if (j == 255)
  1633. break;
  1634. }
  1635. phba->ModelDesc[j] = 0;
  1636. continue;
  1637. }
  1638. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  1639. phba->vpd_flag |= VPD_MODEL_NAME;
  1640. index += 2;
  1641. i = vpd[index];
  1642. index += 1;
  1643. j = 0;
  1644. Length -= (3+i);
  1645. while(i--) {
  1646. phba->ModelName[j++] = vpd[index++];
  1647. if (j == 79)
  1648. break;
  1649. }
  1650. phba->ModelName[j] = 0;
  1651. continue;
  1652. }
  1653. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  1654. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  1655. index += 2;
  1656. i = vpd[index];
  1657. index += 1;
  1658. j = 0;
  1659. Length -= (3+i);
  1660. while(i--) {
  1661. phba->ProgramType[j++] = vpd[index++];
  1662. if (j == 255)
  1663. break;
  1664. }
  1665. phba->ProgramType[j] = 0;
  1666. continue;
  1667. }
  1668. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  1669. phba->vpd_flag |= VPD_PORT;
  1670. index += 2;
  1671. i = vpd[index];
  1672. index += 1;
  1673. j = 0;
  1674. Length -= (3+i);
  1675. while(i--) {
  1676. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  1677. (phba->sli4_hba.pport_name_sta ==
  1678. LPFC_SLI4_PPNAME_GET)) {
  1679. j++;
  1680. index++;
  1681. } else
  1682. phba->Port[j++] = vpd[index++];
  1683. if (j == 19)
  1684. break;
  1685. }
  1686. if ((phba->sli_rev != LPFC_SLI_REV4) ||
  1687. (phba->sli4_hba.pport_name_sta ==
  1688. LPFC_SLI4_PPNAME_NON))
  1689. phba->Port[j] = 0;
  1690. continue;
  1691. }
  1692. else {
  1693. index += 2;
  1694. i = vpd[index];
  1695. index += 1;
  1696. index += i;
  1697. Length -= (3 + i);
  1698. }
  1699. }
  1700. finished = 0;
  1701. break;
  1702. case 0x78:
  1703. finished = 1;
  1704. break;
  1705. default:
  1706. index ++;
  1707. break;
  1708. }
  1709. }
  1710. return(1);
  1711. }
  1712. /**
  1713. * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
  1714. * @phba: pointer to lpfc hba data structure.
  1715. * @mdp: pointer to the data structure to hold the derived model name.
  1716. * @descp: pointer to the data structure to hold the derived description.
  1717. *
  1718. * This routine retrieves HBA's description based on its registered PCI device
  1719. * ID. The @descp passed into this function points to an array of 256 chars. It
  1720. * shall be returned with the model name, maximum speed, and the host bus type.
  1721. * The @mdp passed into this function points to an array of 80 chars. When the
  1722. * function returns, the @mdp will be filled with the model name.
  1723. **/
  1724. static void
  1725. lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  1726. {
  1727. lpfc_vpd_t *vp;
  1728. uint16_t dev_id = phba->pcidev->device;
  1729. int max_speed;
  1730. int GE = 0;
  1731. int oneConnect = 0; /* default is not a oneConnect */
  1732. struct {
  1733. char *name;
  1734. char *bus;
  1735. char *function;
  1736. } m = {"<Unknown>", "", ""};
  1737. if (mdp && mdp[0] != '\0'
  1738. && descp && descp[0] != '\0')
  1739. return;
  1740. if (phba->lmt & LMT_16Gb)
  1741. max_speed = 16;
  1742. else if (phba->lmt & LMT_10Gb)
  1743. max_speed = 10;
  1744. else if (phba->lmt & LMT_8Gb)
  1745. max_speed = 8;
  1746. else if (phba->lmt & LMT_4Gb)
  1747. max_speed = 4;
  1748. else if (phba->lmt & LMT_2Gb)
  1749. max_speed = 2;
  1750. else if (phba->lmt & LMT_1Gb)
  1751. max_speed = 1;
  1752. else
  1753. max_speed = 0;
  1754. vp = &phba->vpd;
  1755. switch (dev_id) {
  1756. case PCI_DEVICE_ID_FIREFLY:
  1757. m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"};
  1758. break;
  1759. case PCI_DEVICE_ID_SUPERFLY:
  1760. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  1761. m = (typeof(m)){"LP7000", "PCI",
  1762. "Fibre Channel Adapter"};
  1763. else
  1764. m = (typeof(m)){"LP7000E", "PCI",
  1765. "Fibre Channel Adapter"};
  1766. break;
  1767. case PCI_DEVICE_ID_DRAGONFLY:
  1768. m = (typeof(m)){"LP8000", "PCI",
  1769. "Fibre Channel Adapter"};
  1770. break;
  1771. case PCI_DEVICE_ID_CENTAUR:
  1772. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  1773. m = (typeof(m)){"LP9002", "PCI",
  1774. "Fibre Channel Adapter"};
  1775. else
  1776. m = (typeof(m)){"LP9000", "PCI",
  1777. "Fibre Channel Adapter"};
  1778. break;
  1779. case PCI_DEVICE_ID_RFLY:
  1780. m = (typeof(m)){"LP952", "PCI",
  1781. "Fibre Channel Adapter"};
  1782. break;
  1783. case PCI_DEVICE_ID_PEGASUS:
  1784. m = (typeof(m)){"LP9802", "PCI-X",
  1785. "Fibre Channel Adapter"};
  1786. break;
  1787. case PCI_DEVICE_ID_THOR:
  1788. m = (typeof(m)){"LP10000", "PCI-X",
  1789. "Fibre Channel Adapter"};
  1790. break;
  1791. case PCI_DEVICE_ID_VIPER:
  1792. m = (typeof(m)){"LPX1000", "PCI-X",
  1793. "Fibre Channel Adapter"};
  1794. break;
  1795. case PCI_DEVICE_ID_PFLY:
  1796. m = (typeof(m)){"LP982", "PCI-X",
  1797. "Fibre Channel Adapter"};
  1798. break;
  1799. case PCI_DEVICE_ID_TFLY:
  1800. m = (typeof(m)){"LP1050", "PCI-X",
  1801. "Fibre Channel Adapter"};
  1802. break;
  1803. case PCI_DEVICE_ID_HELIOS:
  1804. m = (typeof(m)){"LP11000", "PCI-X2",
  1805. "Fibre Channel Adapter"};
  1806. break;
  1807. case PCI_DEVICE_ID_HELIOS_SCSP:
  1808. m = (typeof(m)){"LP11000-SP", "PCI-X2",
  1809. "Fibre Channel Adapter"};
  1810. break;
  1811. case PCI_DEVICE_ID_HELIOS_DCSP:
  1812. m = (typeof(m)){"LP11002-SP", "PCI-X2",
  1813. "Fibre Channel Adapter"};
  1814. break;
  1815. case PCI_DEVICE_ID_NEPTUNE:
  1816. m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
  1817. break;
  1818. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  1819. m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
  1820. break;
  1821. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  1822. m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
  1823. break;
  1824. case PCI_DEVICE_ID_BMID:
  1825. m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
  1826. break;
  1827. case PCI_DEVICE_ID_BSMB:
  1828. m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
  1829. break;
  1830. case PCI_DEVICE_ID_ZEPHYR:
  1831. m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
  1832. break;
  1833. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  1834. m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
  1835. break;
  1836. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  1837. m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
  1838. GE = 1;
  1839. break;
  1840. case PCI_DEVICE_ID_ZMID:
  1841. m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
  1842. break;
  1843. case PCI_DEVICE_ID_ZSMB:
  1844. m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
  1845. break;
  1846. case PCI_DEVICE_ID_LP101:
  1847. m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"};
  1848. break;
  1849. case PCI_DEVICE_ID_LP10000S:
  1850. m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
  1851. break;
  1852. case PCI_DEVICE_ID_LP11000S:
  1853. m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
  1854. break;
  1855. case PCI_DEVICE_ID_LPE11000S:
  1856. m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
  1857. break;
  1858. case PCI_DEVICE_ID_SAT:
  1859. m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
  1860. break;
  1861. case PCI_DEVICE_ID_SAT_MID:
  1862. m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
  1863. break;
  1864. case PCI_DEVICE_ID_SAT_SMB:
  1865. m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
  1866. break;
  1867. case PCI_DEVICE_ID_SAT_DCSP:
  1868. m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
  1869. break;
  1870. case PCI_DEVICE_ID_SAT_SCSP:
  1871. m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
  1872. break;
  1873. case PCI_DEVICE_ID_SAT_S:
  1874. m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
  1875. break;
  1876. case PCI_DEVICE_ID_HORNET:
  1877. m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"};
  1878. GE = 1;
  1879. break;
  1880. case PCI_DEVICE_ID_PROTEUS_VF:
  1881. m = (typeof(m)){"LPev12000", "PCIe IOV",
  1882. "Fibre Channel Adapter"};
  1883. break;
  1884. case PCI_DEVICE_ID_PROTEUS_PF:
  1885. m = (typeof(m)){"LPev12000", "PCIe IOV",
  1886. "Fibre Channel Adapter"};
  1887. break;
  1888. case PCI_DEVICE_ID_PROTEUS_S:
  1889. m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
  1890. "Fibre Channel Adapter"};
  1891. break;
  1892. case PCI_DEVICE_ID_TIGERSHARK:
  1893. oneConnect = 1;
  1894. m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
  1895. break;
  1896. case PCI_DEVICE_ID_TOMCAT:
  1897. oneConnect = 1;
  1898. m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
  1899. break;
  1900. case PCI_DEVICE_ID_FALCON:
  1901. m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
  1902. "EmulexSecure Fibre"};
  1903. break;
  1904. case PCI_DEVICE_ID_BALIUS:
  1905. m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
  1906. "Fibre Channel Adapter"};
  1907. break;
  1908. case PCI_DEVICE_ID_LANCER_FC:
  1909. case PCI_DEVICE_ID_LANCER_FC_VF:
  1910. m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
  1911. break;
  1912. case PCI_DEVICE_ID_LANCER_FCOE:
  1913. case PCI_DEVICE_ID_LANCER_FCOE_VF:
  1914. oneConnect = 1;
  1915. m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
  1916. break;
  1917. case PCI_DEVICE_ID_SKYHAWK:
  1918. case PCI_DEVICE_ID_SKYHAWK_VF:
  1919. oneConnect = 1;
  1920. m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
  1921. break;
  1922. default:
  1923. m = (typeof(m)){"Unknown", "", ""};
  1924. break;
  1925. }
  1926. if (mdp && mdp[0] == '\0')
  1927. snprintf(mdp, 79,"%s", m.name);
  1928. /*
  1929. * oneConnect hba requires special processing, they are all initiators
  1930. * and we put the port number on the end
  1931. */
  1932. if (descp && descp[0] == '\0') {
  1933. if (oneConnect)
  1934. snprintf(descp, 255,
  1935. "Emulex OneConnect %s, %s Initiator %s",
  1936. m.name, m.function,
  1937. phba->Port);
  1938. else if (max_speed == 0)
  1939. snprintf(descp, 255,
  1940. "Emulex %s %s %s ",
  1941. m.name, m.bus, m.function);
  1942. else
  1943. snprintf(descp, 255,
  1944. "Emulex %s %d%s %s %s",
  1945. m.name, max_speed, (GE) ? "GE" : "Gb",
  1946. m.bus, m.function);
  1947. }
  1948. }
  1949. /**
  1950. * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
  1951. * @phba: pointer to lpfc hba data structure.
  1952. * @pring: pointer to a IOCB ring.
  1953. * @cnt: the number of IOCBs to be posted to the IOCB ring.
  1954. *
  1955. * This routine posts a given number of IOCBs with the associated DMA buffer
  1956. * descriptors specified by the cnt argument to the given IOCB ring.
  1957. *
  1958. * Return codes
  1959. * The number of IOCBs NOT able to be posted to the IOCB ring.
  1960. **/
  1961. int
  1962. lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
  1963. {
  1964. IOCB_t *icmd;
  1965. struct lpfc_iocbq *iocb;
  1966. struct lpfc_dmabuf *mp1, *mp2;
  1967. cnt += pring->missbufcnt;
  1968. /* While there are buffers to post */
  1969. while (cnt > 0) {
  1970. /* Allocate buffer for command iocb */
  1971. iocb = lpfc_sli_get_iocbq(phba);
  1972. if (iocb == NULL) {
  1973. pring->missbufcnt = cnt;
  1974. return cnt;
  1975. }
  1976. icmd = &iocb->iocb;
  1977. /* 2 buffers can be posted per command */
  1978. /* Allocate buffer to post */
  1979. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1980. if (mp1)
  1981. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
  1982. if (!mp1 || !mp1->virt) {
  1983. kfree(mp1);
  1984. lpfc_sli_release_iocbq(phba, iocb);
  1985. pring->missbufcnt = cnt;
  1986. return cnt;
  1987. }
  1988. INIT_LIST_HEAD(&mp1->list);
  1989. /* Allocate buffer to post */
  1990. if (cnt > 1) {
  1991. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1992. if (mp2)
  1993. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  1994. &mp2->phys);
  1995. if (!mp2 || !mp2->virt) {
  1996. kfree(mp2);
  1997. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1998. kfree(mp1);
  1999. lpfc_sli_release_iocbq(phba, iocb);
  2000. pring->missbufcnt = cnt;
  2001. return cnt;
  2002. }
  2003. INIT_LIST_HEAD(&mp2->list);
  2004. } else {
  2005. mp2 = NULL;
  2006. }
  2007. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  2008. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  2009. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  2010. icmd->ulpBdeCount = 1;
  2011. cnt--;
  2012. if (mp2) {
  2013. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  2014. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  2015. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  2016. cnt--;
  2017. icmd->ulpBdeCount = 2;
  2018. }
  2019. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  2020. icmd->ulpLe = 1;
  2021. if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
  2022. IOCB_ERROR) {
  2023. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  2024. kfree(mp1);
  2025. cnt++;
  2026. if (mp2) {
  2027. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  2028. kfree(mp2);
  2029. cnt++;
  2030. }
  2031. lpfc_sli_release_iocbq(phba, iocb);
  2032. pring->missbufcnt = cnt;
  2033. return cnt;
  2034. }
  2035. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  2036. if (mp2)
  2037. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  2038. }
  2039. pring->missbufcnt = 0;
  2040. return 0;
  2041. }
  2042. /**
  2043. * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
  2044. * @phba: pointer to lpfc hba data structure.
  2045. *
  2046. * This routine posts initial receive IOCB buffers to the ELS ring. The
  2047. * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
  2048. * set to 64 IOCBs.
  2049. *
  2050. * Return codes
  2051. * 0 - success (currently always success)
  2052. **/
  2053. static int
  2054. lpfc_post_rcv_buf(struct lpfc_hba *phba)
  2055. {
  2056. struct lpfc_sli *psli = &phba->sli;
  2057. /* Ring 0, ELS / CT buffers */
  2058. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
  2059. /* Ring 2 - FCP no buffers needed */
  2060. return 0;
  2061. }
  2062. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  2063. /**
  2064. * lpfc_sha_init - Set up initial array of hash table entries
  2065. * @HashResultPointer: pointer to an array as hash table.
  2066. *
  2067. * This routine sets up the initial values to the array of hash table entries
  2068. * for the LC HBAs.
  2069. **/
  2070. static void
  2071. lpfc_sha_init(uint32_t * HashResultPointer)
  2072. {
  2073. HashResultPointer[0] = 0x67452301;
  2074. HashResultPointer[1] = 0xEFCDAB89;
  2075. HashResultPointer[2] = 0x98BADCFE;
  2076. HashResultPointer[3] = 0x10325476;
  2077. HashResultPointer[4] = 0xC3D2E1F0;
  2078. }
  2079. /**
  2080. * lpfc_sha_iterate - Iterate initial hash table with the working hash table
  2081. * @HashResultPointer: pointer to an initial/result hash table.
  2082. * @HashWorkingPointer: pointer to an working hash table.
  2083. *
  2084. * This routine iterates an initial hash table pointed by @HashResultPointer
  2085. * with the values from the working hash table pointeed by @HashWorkingPointer.
  2086. * The results are putting back to the initial hash table, returned through
  2087. * the @HashResultPointer as the result hash table.
  2088. **/
  2089. static void
  2090. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  2091. {
  2092. int t;
  2093. uint32_t TEMP;
  2094. uint32_t A, B, C, D, E;
  2095. t = 16;
  2096. do {
  2097. HashWorkingPointer[t] =
  2098. S(1,
  2099. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  2100. 8] ^
  2101. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  2102. } while (++t <= 79);
  2103. t = 0;
  2104. A = HashResultPointer[0];
  2105. B = HashResultPointer[1];
  2106. C = HashResultPointer[2];
  2107. D = HashResultPointer[3];
  2108. E = HashResultPointer[4];
  2109. do {
  2110. if (t < 20) {
  2111. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  2112. } else if (t < 40) {
  2113. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  2114. } else if (t < 60) {
  2115. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  2116. } else {
  2117. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  2118. }
  2119. TEMP += S(5, A) + E + HashWorkingPointer[t];
  2120. E = D;
  2121. D = C;
  2122. C = S(30, B);
  2123. B = A;
  2124. A = TEMP;
  2125. } while (++t <= 79);
  2126. HashResultPointer[0] += A;
  2127. HashResultPointer[1] += B;
  2128. HashResultPointer[2] += C;
  2129. HashResultPointer[3] += D;
  2130. HashResultPointer[4] += E;
  2131. }
  2132. /**
  2133. * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
  2134. * @RandomChallenge: pointer to the entry of host challenge random number array.
  2135. * @HashWorking: pointer to the entry of the working hash array.
  2136. *
  2137. * This routine calculates the working hash array referred by @HashWorking
  2138. * from the challenge random numbers associated with the host, referred by
  2139. * @RandomChallenge. The result is put into the entry of the working hash
  2140. * array and returned by reference through @HashWorking.
  2141. **/
  2142. static void
  2143. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  2144. {
  2145. *HashWorking = (*RandomChallenge ^ *HashWorking);
  2146. }
  2147. /**
  2148. * lpfc_hba_init - Perform special handling for LC HBA initialization
  2149. * @phba: pointer to lpfc hba data structure.
  2150. * @hbainit: pointer to an array of unsigned 32-bit integers.
  2151. *
  2152. * This routine performs the special handling for LC HBA initialization.
  2153. **/
  2154. void
  2155. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  2156. {
  2157. int t;
  2158. uint32_t *HashWorking;
  2159. uint32_t *pwwnn = (uint32_t *) phba->wwnn;
  2160. HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
  2161. if (!HashWorking)
  2162. return;
  2163. HashWorking[0] = HashWorking[78] = *pwwnn++;
  2164. HashWorking[1] = HashWorking[79] = *pwwnn;
  2165. for (t = 0; t < 7; t++)
  2166. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  2167. lpfc_sha_init(hbainit);
  2168. lpfc_sha_iterate(hbainit, HashWorking);
  2169. kfree(HashWorking);
  2170. }
  2171. /**
  2172. * lpfc_cleanup - Performs vport cleanups before deleting a vport
  2173. * @vport: pointer to a virtual N_Port data structure.
  2174. *
  2175. * This routine performs the necessary cleanups before deleting the @vport.
  2176. * It invokes the discovery state machine to perform necessary state
  2177. * transitions and to release the ndlps associated with the @vport. Note,
  2178. * the physical port is treated as @vport 0.
  2179. **/
  2180. void
  2181. lpfc_cleanup(struct lpfc_vport *vport)
  2182. {
  2183. struct lpfc_hba *phba = vport->phba;
  2184. struct lpfc_nodelist *ndlp, *next_ndlp;
  2185. int i = 0;
  2186. if (phba->link_state > LPFC_LINK_DOWN)
  2187. lpfc_port_link_failure(vport);
  2188. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2189. if (!NLP_CHK_NODE_ACT(ndlp)) {
  2190. ndlp = lpfc_enable_node(vport, ndlp,
  2191. NLP_STE_UNUSED_NODE);
  2192. if (!ndlp)
  2193. continue;
  2194. spin_lock_irq(&phba->ndlp_lock);
  2195. NLP_SET_FREE_REQ(ndlp);
  2196. spin_unlock_irq(&phba->ndlp_lock);
  2197. /* Trigger the release of the ndlp memory */
  2198. lpfc_nlp_put(ndlp);
  2199. continue;
  2200. }
  2201. spin_lock_irq(&phba->ndlp_lock);
  2202. if (NLP_CHK_FREE_REQ(ndlp)) {
  2203. /* The ndlp should not be in memory free mode already */
  2204. spin_unlock_irq(&phba->ndlp_lock);
  2205. continue;
  2206. } else
  2207. /* Indicate request for freeing ndlp memory */
  2208. NLP_SET_FREE_REQ(ndlp);
  2209. spin_unlock_irq(&phba->ndlp_lock);
  2210. if (vport->port_type != LPFC_PHYSICAL_PORT &&
  2211. ndlp->nlp_DID == Fabric_DID) {
  2212. /* Just free up ndlp with Fabric_DID for vports */
  2213. lpfc_nlp_put(ndlp);
  2214. continue;
  2215. }
  2216. /* take care of nodes in unused state before the state
  2217. * machine taking action.
  2218. */
  2219. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  2220. lpfc_nlp_put(ndlp);
  2221. continue;
  2222. }
  2223. if (ndlp->nlp_type & NLP_FABRIC)
  2224. lpfc_disc_state_machine(vport, ndlp, NULL,
  2225. NLP_EVT_DEVICE_RECOVERY);
  2226. lpfc_disc_state_machine(vport, ndlp, NULL,
  2227. NLP_EVT_DEVICE_RM);
  2228. }
  2229. /* At this point, ALL ndlp's should be gone
  2230. * because of the previous NLP_EVT_DEVICE_RM.
  2231. * Lets wait for this to happen, if needed.
  2232. */
  2233. while (!list_empty(&vport->fc_nodes)) {
  2234. if (i++ > 3000) {
  2235. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2236. "0233 Nodelist not empty\n");
  2237. list_for_each_entry_safe(ndlp, next_ndlp,
  2238. &vport->fc_nodes, nlp_listp) {
  2239. lpfc_printf_vlog(ndlp->vport, KERN_ERR,
  2240. LOG_NODE,
  2241. "0282 did:x%x ndlp:x%p "
  2242. "usgmap:x%x refcnt:%d\n",
  2243. ndlp->nlp_DID, (void *)ndlp,
  2244. ndlp->nlp_usg_map,
  2245. atomic_read(
  2246. &ndlp->kref.refcount));
  2247. }
  2248. break;
  2249. }
  2250. /* Wait for any activity on ndlps to settle */
  2251. msleep(10);
  2252. }
  2253. lpfc_cleanup_vports_rrqs(vport, NULL);
  2254. }
  2255. /**
  2256. * lpfc_stop_vport_timers - Stop all the timers associated with a vport
  2257. * @vport: pointer to a virtual N_Port data structure.
  2258. *
  2259. * This routine stops all the timers associated with a @vport. This function
  2260. * is invoked before disabling or deleting a @vport. Note that the physical
  2261. * port is treated as @vport 0.
  2262. **/
  2263. void
  2264. lpfc_stop_vport_timers(struct lpfc_vport *vport)
  2265. {
  2266. del_timer_sync(&vport->els_tmofunc);
  2267. del_timer_sync(&vport->fc_fdmitmo);
  2268. del_timer_sync(&vport->delayed_disc_tmo);
  2269. lpfc_can_disctmo(vport);
  2270. return;
  2271. }
  2272. /**
  2273. * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
  2274. * @phba: pointer to lpfc hba data structure.
  2275. *
  2276. * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
  2277. * caller of this routine should already hold the host lock.
  2278. **/
  2279. void
  2280. __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
  2281. {
  2282. /* Clear pending FCF rediscovery wait flag */
  2283. phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
  2284. /* Now, try to stop the timer */
  2285. del_timer(&phba->fcf.redisc_wait);
  2286. }
  2287. /**
  2288. * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
  2289. * @phba: pointer to lpfc hba data structure.
  2290. *
  2291. * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
  2292. * checks whether the FCF rediscovery wait timer is pending with the host
  2293. * lock held before proceeding with disabling the timer and clearing the
  2294. * wait timer pendig flag.
  2295. **/
  2296. void
  2297. lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
  2298. {
  2299. spin_lock_irq(&phba->hbalock);
  2300. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
  2301. /* FCF rediscovery timer already fired or stopped */
  2302. spin_unlock_irq(&phba->hbalock);
  2303. return;
  2304. }
  2305. __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
  2306. /* Clear failover in progress flags */
  2307. phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
  2308. spin_unlock_irq(&phba->hbalock);
  2309. }
  2310. /**
  2311. * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
  2312. * @phba: pointer to lpfc hba data structure.
  2313. *
  2314. * This routine stops all the timers associated with a HBA. This function is
  2315. * invoked before either putting a HBA offline or unloading the driver.
  2316. **/
  2317. void
  2318. lpfc_stop_hba_timers(struct lpfc_hba *phba)
  2319. {
  2320. lpfc_stop_vport_timers(phba->pport);
  2321. del_timer_sync(&phba->sli.mbox_tmo);
  2322. del_timer_sync(&phba->fabric_block_timer);
  2323. del_timer_sync(&phba->eratt_poll);
  2324. del_timer_sync(&phba->hb_tmofunc);
  2325. if (phba->sli_rev == LPFC_SLI_REV4) {
  2326. del_timer_sync(&phba->rrq_tmr);
  2327. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  2328. }
  2329. phba->hb_outstanding = 0;
  2330. switch (phba->pci_dev_grp) {
  2331. case LPFC_PCI_DEV_LP:
  2332. /* Stop any LightPulse device specific driver timers */
  2333. del_timer_sync(&phba->fcp_poll_timer);
  2334. break;
  2335. case LPFC_PCI_DEV_OC:
  2336. /* Stop any OneConnect device sepcific driver timers */
  2337. lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
  2338. break;
  2339. default:
  2340. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2341. "0297 Invalid device group (x%x)\n",
  2342. phba->pci_dev_grp);
  2343. break;
  2344. }
  2345. return;
  2346. }
  2347. /**
  2348. * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
  2349. * @phba: pointer to lpfc hba data structure.
  2350. *
  2351. * This routine marks a HBA's management interface as blocked. Once the HBA's
  2352. * management interface is marked as blocked, all the user space access to
  2353. * the HBA, whether they are from sysfs interface or libdfc interface will
  2354. * all be blocked. The HBA is set to block the management interface when the
  2355. * driver prepares the HBA interface for online or offline.
  2356. **/
  2357. static void
  2358. lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
  2359. {
  2360. unsigned long iflag;
  2361. uint8_t actcmd = MBX_HEARTBEAT;
  2362. unsigned long timeout;
  2363. spin_lock_irqsave(&phba->hbalock, iflag);
  2364. phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
  2365. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2366. if (mbx_action == LPFC_MBX_NO_WAIT)
  2367. return;
  2368. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  2369. spin_lock_irqsave(&phba->hbalock, iflag);
  2370. if (phba->sli.mbox_active) {
  2371. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  2372. /* Determine how long we might wait for the active mailbox
  2373. * command to be gracefully completed by firmware.
  2374. */
  2375. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  2376. phba->sli.mbox_active) * 1000) + jiffies;
  2377. }
  2378. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2379. /* Wait for the outstnading mailbox command to complete */
  2380. while (phba->sli.mbox_active) {
  2381. /* Check active mailbox complete status every 2ms */
  2382. msleep(2);
  2383. if (time_after(jiffies, timeout)) {
  2384. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2385. "2813 Mgmt IO is Blocked %x "
  2386. "- mbox cmd %x still active\n",
  2387. phba->sli.sli_flag, actcmd);
  2388. break;
  2389. }
  2390. }
  2391. }
  2392. /**
  2393. * lpfc_sli4_node_prep - Assign RPIs for active nodes.
  2394. * @phba: pointer to lpfc hba data structure.
  2395. *
  2396. * Allocate RPIs for all active remote nodes. This is needed whenever
  2397. * an SLI4 adapter is reset and the driver is not unloading. Its purpose
  2398. * is to fixup the temporary rpi assignments.
  2399. **/
  2400. void
  2401. lpfc_sli4_node_prep(struct lpfc_hba *phba)
  2402. {
  2403. struct lpfc_nodelist *ndlp, *next_ndlp;
  2404. struct lpfc_vport **vports;
  2405. int i;
  2406. if (phba->sli_rev != LPFC_SLI_REV4)
  2407. return;
  2408. vports = lpfc_create_vport_work_array(phba);
  2409. if (vports != NULL) {
  2410. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2411. if (vports[i]->load_flag & FC_UNLOADING)
  2412. continue;
  2413. list_for_each_entry_safe(ndlp, next_ndlp,
  2414. &vports[i]->fc_nodes,
  2415. nlp_listp) {
  2416. if (NLP_CHK_NODE_ACT(ndlp))
  2417. ndlp->nlp_rpi =
  2418. lpfc_sli4_alloc_rpi(phba);
  2419. }
  2420. }
  2421. }
  2422. lpfc_destroy_vport_work_array(phba, vports);
  2423. }
  2424. /**
  2425. * lpfc_online - Initialize and bring a HBA online
  2426. * @phba: pointer to lpfc hba data structure.
  2427. *
  2428. * This routine initializes the HBA and brings a HBA online. During this
  2429. * process, the management interface is blocked to prevent user space access
  2430. * to the HBA interfering with the driver initialization.
  2431. *
  2432. * Return codes
  2433. * 0 - successful
  2434. * 1 - failed
  2435. **/
  2436. int
  2437. lpfc_online(struct lpfc_hba *phba)
  2438. {
  2439. struct lpfc_vport *vport;
  2440. struct lpfc_vport **vports;
  2441. int i;
  2442. bool vpis_cleared = false;
  2443. if (!phba)
  2444. return 0;
  2445. vport = phba->pport;
  2446. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  2447. return 0;
  2448. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2449. "0458 Bring Adapter online\n");
  2450. lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
  2451. if (!lpfc_sli_queue_setup(phba)) {
  2452. lpfc_unblock_mgmt_io(phba);
  2453. return 1;
  2454. }
  2455. if (phba->sli_rev == LPFC_SLI_REV4) {
  2456. if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
  2457. lpfc_unblock_mgmt_io(phba);
  2458. return 1;
  2459. }
  2460. spin_lock_irq(&phba->hbalock);
  2461. if (!phba->sli4_hba.max_cfg_param.vpi_used)
  2462. vpis_cleared = true;
  2463. spin_unlock_irq(&phba->hbalock);
  2464. } else {
  2465. if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
  2466. lpfc_unblock_mgmt_io(phba);
  2467. return 1;
  2468. }
  2469. }
  2470. vports = lpfc_create_vport_work_array(phba);
  2471. if (vports != NULL)
  2472. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2473. struct Scsi_Host *shost;
  2474. shost = lpfc_shost_from_vport(vports[i]);
  2475. spin_lock_irq(shost->host_lock);
  2476. vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
  2477. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  2478. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2479. if (phba->sli_rev == LPFC_SLI_REV4) {
  2480. vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  2481. if ((vpis_cleared) &&
  2482. (vports[i]->port_type !=
  2483. LPFC_PHYSICAL_PORT))
  2484. vports[i]->vpi = 0;
  2485. }
  2486. spin_unlock_irq(shost->host_lock);
  2487. }
  2488. lpfc_destroy_vport_work_array(phba, vports);
  2489. lpfc_unblock_mgmt_io(phba);
  2490. return 0;
  2491. }
  2492. /**
  2493. * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
  2494. * @phba: pointer to lpfc hba data structure.
  2495. *
  2496. * This routine marks a HBA's management interface as not blocked. Once the
  2497. * HBA's management interface is marked as not blocked, all the user space
  2498. * access to the HBA, whether they are from sysfs interface or libdfc
  2499. * interface will be allowed. The HBA is set to block the management interface
  2500. * when the driver prepares the HBA interface for online or offline and then
  2501. * set to unblock the management interface afterwards.
  2502. **/
  2503. void
  2504. lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
  2505. {
  2506. unsigned long iflag;
  2507. spin_lock_irqsave(&phba->hbalock, iflag);
  2508. phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
  2509. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2510. }
  2511. /**
  2512. * lpfc_offline_prep - Prepare a HBA to be brought offline
  2513. * @phba: pointer to lpfc hba data structure.
  2514. *
  2515. * This routine is invoked to prepare a HBA to be brought offline. It performs
  2516. * unregistration login to all the nodes on all vports and flushes the mailbox
  2517. * queue to make it ready to be brought offline.
  2518. **/
  2519. void
  2520. lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
  2521. {
  2522. struct lpfc_vport *vport = phba->pport;
  2523. struct lpfc_nodelist *ndlp, *next_ndlp;
  2524. struct lpfc_vport **vports;
  2525. struct Scsi_Host *shost;
  2526. int i;
  2527. if (vport->fc_flag & FC_OFFLINE_MODE)
  2528. return;
  2529. lpfc_block_mgmt_io(phba, mbx_action);
  2530. lpfc_linkdown(phba);
  2531. /* Issue an unreg_login to all nodes on all vports */
  2532. vports = lpfc_create_vport_work_array(phba);
  2533. if (vports != NULL) {
  2534. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2535. if (vports[i]->load_flag & FC_UNLOADING)
  2536. continue;
  2537. shost = lpfc_shost_from_vport(vports[i]);
  2538. spin_lock_irq(shost->host_lock);
  2539. vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
  2540. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2541. vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
  2542. spin_unlock_irq(shost->host_lock);
  2543. shost = lpfc_shost_from_vport(vports[i]);
  2544. list_for_each_entry_safe(ndlp, next_ndlp,
  2545. &vports[i]->fc_nodes,
  2546. nlp_listp) {
  2547. if (!NLP_CHK_NODE_ACT(ndlp))
  2548. continue;
  2549. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  2550. continue;
  2551. if (ndlp->nlp_type & NLP_FABRIC) {
  2552. lpfc_disc_state_machine(vports[i], ndlp,
  2553. NULL, NLP_EVT_DEVICE_RECOVERY);
  2554. lpfc_disc_state_machine(vports[i], ndlp,
  2555. NULL, NLP_EVT_DEVICE_RM);
  2556. }
  2557. spin_lock_irq(shost->host_lock);
  2558. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2559. spin_unlock_irq(shost->host_lock);
  2560. /*
  2561. * Whenever an SLI4 port goes offline, free the
  2562. * RPI. Get a new RPI when the adapter port
  2563. * comes back online.
  2564. */
  2565. if (phba->sli_rev == LPFC_SLI_REV4)
  2566. lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
  2567. lpfc_unreg_rpi(vports[i], ndlp);
  2568. }
  2569. }
  2570. }
  2571. lpfc_destroy_vport_work_array(phba, vports);
  2572. lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
  2573. }
  2574. /**
  2575. * lpfc_offline - Bring a HBA offline
  2576. * @phba: pointer to lpfc hba data structure.
  2577. *
  2578. * This routine actually brings a HBA offline. It stops all the timers
  2579. * associated with the HBA, brings down the SLI layer, and eventually
  2580. * marks the HBA as in offline state for the upper layer protocol.
  2581. **/
  2582. void
  2583. lpfc_offline(struct lpfc_hba *phba)
  2584. {
  2585. struct Scsi_Host *shost;
  2586. struct lpfc_vport **vports;
  2587. int i;
  2588. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  2589. return;
  2590. /* stop port and all timers associated with this hba */
  2591. lpfc_stop_port(phba);
  2592. vports = lpfc_create_vport_work_array(phba);
  2593. if (vports != NULL)
  2594. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  2595. lpfc_stop_vport_timers(vports[i]);
  2596. lpfc_destroy_vport_work_array(phba, vports);
  2597. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2598. "0460 Bring Adapter offline\n");
  2599. /* Bring down the SLI Layer and cleanup. The HBA is offline
  2600. now. */
  2601. lpfc_sli_hba_down(phba);
  2602. spin_lock_irq(&phba->hbalock);
  2603. phba->work_ha = 0;
  2604. spin_unlock_irq(&phba->hbalock);
  2605. vports = lpfc_create_vport_work_array(phba);
  2606. if (vports != NULL)
  2607. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2608. shost = lpfc_shost_from_vport(vports[i]);
  2609. spin_lock_irq(shost->host_lock);
  2610. vports[i]->work_port_events = 0;
  2611. vports[i]->fc_flag |= FC_OFFLINE_MODE;
  2612. spin_unlock_irq(shost->host_lock);
  2613. }
  2614. lpfc_destroy_vport_work_array(phba, vports);
  2615. }
  2616. /**
  2617. * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
  2618. * @phba: pointer to lpfc hba data structure.
  2619. *
  2620. * This routine is to free all the SCSI buffers and IOCBs from the driver
  2621. * list back to kernel. It is called from lpfc_pci_remove_one to free
  2622. * the internal resources before the device is removed from the system.
  2623. **/
  2624. static void
  2625. lpfc_scsi_free(struct lpfc_hba *phba)
  2626. {
  2627. struct lpfc_scsi_buf *sb, *sb_next;
  2628. struct lpfc_iocbq *io, *io_next;
  2629. spin_lock_irq(&phba->hbalock);
  2630. /* Release all the lpfc_scsi_bufs maintained by this host. */
  2631. spin_lock(&phba->scsi_buf_list_put_lock);
  2632. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
  2633. list) {
  2634. list_del(&sb->list);
  2635. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  2636. sb->dma_handle);
  2637. kfree(sb);
  2638. phba->total_scsi_bufs--;
  2639. }
  2640. spin_unlock(&phba->scsi_buf_list_put_lock);
  2641. spin_lock(&phba->scsi_buf_list_get_lock);
  2642. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
  2643. list) {
  2644. list_del(&sb->list);
  2645. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  2646. sb->dma_handle);
  2647. kfree(sb);
  2648. phba->total_scsi_bufs--;
  2649. }
  2650. spin_unlock(&phba->scsi_buf_list_get_lock);
  2651. /* Release all the lpfc_iocbq entries maintained by this host. */
  2652. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  2653. list_del(&io->list);
  2654. kfree(io);
  2655. phba->total_iocbq_bufs--;
  2656. }
  2657. spin_unlock_irq(&phba->hbalock);
  2658. }
  2659. /**
  2660. * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
  2661. * @phba: pointer to lpfc hba data structure.
  2662. *
  2663. * This routine first calculates the sizes of the current els and allocated
  2664. * scsi sgl lists, and then goes through all sgls to updates the physical
  2665. * XRIs assigned due to port function reset. During port initialization, the
  2666. * current els and allocated scsi sgl lists are 0s.
  2667. *
  2668. * Return codes
  2669. * 0 - successful (for now, it always returns 0)
  2670. **/
  2671. int
  2672. lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
  2673. {
  2674. struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
  2675. struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
  2676. uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
  2677. LIST_HEAD(els_sgl_list);
  2678. LIST_HEAD(scsi_sgl_list);
  2679. int rc;
  2680. /*
  2681. * update on pci function's els xri-sgl list
  2682. */
  2683. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  2684. if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
  2685. /* els xri-sgl expanded */
  2686. xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
  2687. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2688. "3157 ELS xri-sgl count increased from "
  2689. "%d to %d\n", phba->sli4_hba.els_xri_cnt,
  2690. els_xri_cnt);
  2691. /* allocate the additional els sgls */
  2692. for (i = 0; i < xri_cnt; i++) {
  2693. sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
  2694. GFP_KERNEL);
  2695. if (sglq_entry == NULL) {
  2696. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2697. "2562 Failure to allocate an "
  2698. "ELS sgl entry:%d\n", i);
  2699. rc = -ENOMEM;
  2700. goto out_free_mem;
  2701. }
  2702. sglq_entry->buff_type = GEN_BUFF_TYPE;
  2703. sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
  2704. &sglq_entry->phys);
  2705. if (sglq_entry->virt == NULL) {
  2706. kfree(sglq_entry);
  2707. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2708. "2563 Failure to allocate an "
  2709. "ELS mbuf:%d\n", i);
  2710. rc = -ENOMEM;
  2711. goto out_free_mem;
  2712. }
  2713. sglq_entry->sgl = sglq_entry->virt;
  2714. memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
  2715. sglq_entry->state = SGL_FREED;
  2716. list_add_tail(&sglq_entry->list, &els_sgl_list);
  2717. }
  2718. spin_lock_irq(&phba->hbalock);
  2719. list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
  2720. spin_unlock_irq(&phba->hbalock);
  2721. } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
  2722. /* els xri-sgl shrinked */
  2723. xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
  2724. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2725. "3158 ELS xri-sgl count decreased from "
  2726. "%d to %d\n", phba->sli4_hba.els_xri_cnt,
  2727. els_xri_cnt);
  2728. spin_lock_irq(&phba->hbalock);
  2729. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
  2730. spin_unlock_irq(&phba->hbalock);
  2731. /* release extra els sgls from list */
  2732. for (i = 0; i < xri_cnt; i++) {
  2733. list_remove_head(&els_sgl_list,
  2734. sglq_entry, struct lpfc_sglq, list);
  2735. if (sglq_entry) {
  2736. lpfc_mbuf_free(phba, sglq_entry->virt,
  2737. sglq_entry->phys);
  2738. kfree(sglq_entry);
  2739. }
  2740. }
  2741. spin_lock_irq(&phba->hbalock);
  2742. list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
  2743. spin_unlock_irq(&phba->hbalock);
  2744. } else
  2745. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2746. "3163 ELS xri-sgl count unchanged: %d\n",
  2747. els_xri_cnt);
  2748. phba->sli4_hba.els_xri_cnt = els_xri_cnt;
  2749. /* update xris to els sgls on the list */
  2750. sglq_entry = NULL;
  2751. sglq_entry_next = NULL;
  2752. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  2753. &phba->sli4_hba.lpfc_sgl_list, list) {
  2754. lxri = lpfc_sli4_next_xritag(phba);
  2755. if (lxri == NO_XRI) {
  2756. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2757. "2400 Failed to allocate xri for "
  2758. "ELS sgl\n");
  2759. rc = -ENOMEM;
  2760. goto out_free_mem;
  2761. }
  2762. sglq_entry->sli4_lxritag = lxri;
  2763. sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  2764. }
  2765. /*
  2766. * update on pci function's allocated scsi xri-sgl list
  2767. */
  2768. phba->total_scsi_bufs = 0;
  2769. /* maximum number of xris available for scsi buffers */
  2770. phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
  2771. els_xri_cnt;
  2772. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2773. "2401 Current allocated SCSI xri-sgl count:%d, "
  2774. "maximum SCSI xri count:%d\n",
  2775. phba->sli4_hba.scsi_xri_cnt,
  2776. phba->sli4_hba.scsi_xri_max);
  2777. spin_lock_irq(&phba->scsi_buf_list_get_lock);
  2778. spin_lock(&phba->scsi_buf_list_put_lock);
  2779. list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
  2780. list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
  2781. spin_unlock(&phba->scsi_buf_list_put_lock);
  2782. spin_unlock_irq(&phba->scsi_buf_list_get_lock);
  2783. if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
  2784. /* max scsi xri shrinked below the allocated scsi buffers */
  2785. scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
  2786. phba->sli4_hba.scsi_xri_max;
  2787. /* release the extra allocated scsi buffers */
  2788. for (i = 0; i < scsi_xri_cnt; i++) {
  2789. list_remove_head(&scsi_sgl_list, psb,
  2790. struct lpfc_scsi_buf, list);
  2791. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data,
  2792. psb->dma_handle);
  2793. kfree(psb);
  2794. }
  2795. spin_lock_irq(&phba->scsi_buf_list_get_lock);
  2796. phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
  2797. spin_unlock_irq(&phba->scsi_buf_list_get_lock);
  2798. }
  2799. /* update xris associated to remaining allocated scsi buffers */
  2800. psb = NULL;
  2801. psb_next = NULL;
  2802. list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
  2803. lxri = lpfc_sli4_next_xritag(phba);
  2804. if (lxri == NO_XRI) {
  2805. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2806. "2560 Failed to allocate xri for "
  2807. "scsi buffer\n");
  2808. rc = -ENOMEM;
  2809. goto out_free_mem;
  2810. }
  2811. psb->cur_iocbq.sli4_lxritag = lxri;
  2812. psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  2813. }
  2814. spin_lock_irq(&phba->scsi_buf_list_get_lock);
  2815. spin_lock(&phba->scsi_buf_list_put_lock);
  2816. list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
  2817. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
  2818. spin_unlock(&phba->scsi_buf_list_put_lock);
  2819. spin_unlock_irq(&phba->scsi_buf_list_get_lock);
  2820. return 0;
  2821. out_free_mem:
  2822. lpfc_free_els_sgl_list(phba);
  2823. lpfc_scsi_free(phba);
  2824. return rc;
  2825. }
  2826. /**
  2827. * lpfc_create_port - Create an FC port
  2828. * @phba: pointer to lpfc hba data structure.
  2829. * @instance: a unique integer ID to this FC port.
  2830. * @dev: pointer to the device data structure.
  2831. *
  2832. * This routine creates a FC port for the upper layer protocol. The FC port
  2833. * can be created on top of either a physical port or a virtual port provided
  2834. * by the HBA. This routine also allocates a SCSI host data structure (shost)
  2835. * and associates the FC port created before adding the shost into the SCSI
  2836. * layer.
  2837. *
  2838. * Return codes
  2839. * @vport - pointer to the virtual N_Port data structure.
  2840. * NULL - port create failed.
  2841. **/
  2842. struct lpfc_vport *
  2843. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  2844. {
  2845. struct lpfc_vport *vport;
  2846. struct Scsi_Host *shost;
  2847. int error = 0;
  2848. if (dev != &phba->pcidev->dev)
  2849. shost = scsi_host_alloc(&lpfc_vport_template,
  2850. sizeof(struct lpfc_vport));
  2851. else
  2852. shost = scsi_host_alloc(&lpfc_template,
  2853. sizeof(struct lpfc_vport));
  2854. if (!shost)
  2855. goto out;
  2856. vport = (struct lpfc_vport *) shost->hostdata;
  2857. vport->phba = phba;
  2858. vport->load_flag |= FC_LOADING;
  2859. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2860. vport->fc_rscn_flush = 0;
  2861. lpfc_get_vport_cfgparam(vport);
  2862. shost->unique_id = instance;
  2863. shost->max_id = LPFC_MAX_TARGET;
  2864. shost->max_lun = vport->cfg_max_luns;
  2865. shost->this_id = -1;
  2866. shost->max_cmd_len = 16;
  2867. if (phba->sli_rev == LPFC_SLI_REV4) {
  2868. shost->dma_boundary =
  2869. phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
  2870. shost->sg_tablesize = phba->cfg_sg_seg_cnt;
  2871. }
  2872. /*
  2873. * Set initial can_queue value since 0 is no longer supported and
  2874. * scsi_add_host will fail. This will be adjusted later based on the
  2875. * max xri value determined in hba setup.
  2876. */
  2877. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  2878. if (dev != &phba->pcidev->dev) {
  2879. shost->transportt = lpfc_vport_transport_template;
  2880. vport->port_type = LPFC_NPIV_PORT;
  2881. } else {
  2882. shost->transportt = lpfc_transport_template;
  2883. vport->port_type = LPFC_PHYSICAL_PORT;
  2884. }
  2885. /* Initialize all internally managed lists. */
  2886. INIT_LIST_HEAD(&vport->fc_nodes);
  2887. INIT_LIST_HEAD(&vport->rcv_buffer_list);
  2888. spin_lock_init(&vport->work_port_lock);
  2889. init_timer(&vport->fc_disctmo);
  2890. vport->fc_disctmo.function = lpfc_disc_timeout;
  2891. vport->fc_disctmo.data = (unsigned long)vport;
  2892. init_timer(&vport->fc_fdmitmo);
  2893. vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
  2894. vport->fc_fdmitmo.data = (unsigned long)vport;
  2895. init_timer(&vport->els_tmofunc);
  2896. vport->els_tmofunc.function = lpfc_els_timeout;
  2897. vport->els_tmofunc.data = (unsigned long)vport;
  2898. init_timer(&vport->delayed_disc_tmo);
  2899. vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
  2900. vport->delayed_disc_tmo.data = (unsigned long)vport;
  2901. error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
  2902. if (error)
  2903. goto out_put_shost;
  2904. spin_lock_irq(&phba->hbalock);
  2905. list_add_tail(&vport->listentry, &phba->port_list);
  2906. spin_unlock_irq(&phba->hbalock);
  2907. return vport;
  2908. out_put_shost:
  2909. scsi_host_put(shost);
  2910. out:
  2911. return NULL;
  2912. }
  2913. /**
  2914. * destroy_port - destroy an FC port
  2915. * @vport: pointer to an lpfc virtual N_Port data structure.
  2916. *
  2917. * This routine destroys a FC port from the upper layer protocol. All the
  2918. * resources associated with the port are released.
  2919. **/
  2920. void
  2921. destroy_port(struct lpfc_vport *vport)
  2922. {
  2923. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2924. struct lpfc_hba *phba = vport->phba;
  2925. lpfc_debugfs_terminate(vport);
  2926. fc_remove_host(shost);
  2927. scsi_remove_host(shost);
  2928. spin_lock_irq(&phba->hbalock);
  2929. list_del_init(&vport->listentry);
  2930. spin_unlock_irq(&phba->hbalock);
  2931. lpfc_cleanup(vport);
  2932. return;
  2933. }
  2934. /**
  2935. * lpfc_get_instance - Get a unique integer ID
  2936. *
  2937. * This routine allocates a unique integer ID from lpfc_hba_index pool. It
  2938. * uses the kernel idr facility to perform the task.
  2939. *
  2940. * Return codes:
  2941. * instance - a unique integer ID allocated as the new instance.
  2942. * -1 - lpfc get instance failed.
  2943. **/
  2944. int
  2945. lpfc_get_instance(void)
  2946. {
  2947. int ret;
  2948. ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
  2949. return ret < 0 ? -1 : ret;
  2950. }
  2951. /**
  2952. * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
  2953. * @shost: pointer to SCSI host data structure.
  2954. * @time: elapsed time of the scan in jiffies.
  2955. *
  2956. * This routine is called by the SCSI layer with a SCSI host to determine
  2957. * whether the scan host is finished.
  2958. *
  2959. * Note: there is no scan_start function as adapter initialization will have
  2960. * asynchronously kicked off the link initialization.
  2961. *
  2962. * Return codes
  2963. * 0 - SCSI host scan is not over yet.
  2964. * 1 - SCSI host scan is over.
  2965. **/
  2966. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  2967. {
  2968. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2969. struct lpfc_hba *phba = vport->phba;
  2970. int stat = 0;
  2971. spin_lock_irq(shost->host_lock);
  2972. if (vport->load_flag & FC_UNLOADING) {
  2973. stat = 1;
  2974. goto finished;
  2975. }
  2976. if (time >= msecs_to_jiffies(30 * 1000)) {
  2977. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2978. "0461 Scanning longer than 30 "
  2979. "seconds. Continuing initialization\n");
  2980. stat = 1;
  2981. goto finished;
  2982. }
  2983. if (time >= msecs_to_jiffies(15 * 1000) &&
  2984. phba->link_state <= LPFC_LINK_DOWN) {
  2985. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2986. "0465 Link down longer than 15 "
  2987. "seconds. Continuing initialization\n");
  2988. stat = 1;
  2989. goto finished;
  2990. }
  2991. if (vport->port_state != LPFC_VPORT_READY)
  2992. goto finished;
  2993. if (vport->num_disc_nodes || vport->fc_prli_sent)
  2994. goto finished;
  2995. if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
  2996. goto finished;
  2997. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  2998. goto finished;
  2999. stat = 1;
  3000. finished:
  3001. spin_unlock_irq(shost->host_lock);
  3002. return stat;
  3003. }
  3004. /**
  3005. * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
  3006. * @shost: pointer to SCSI host data structure.
  3007. *
  3008. * This routine initializes a given SCSI host attributes on a FC port. The
  3009. * SCSI host can be either on top of a physical port or a virtual port.
  3010. **/
  3011. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  3012. {
  3013. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3014. struct lpfc_hba *phba = vport->phba;
  3015. /*
  3016. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  3017. */
  3018. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  3019. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  3020. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  3021. memset(fc_host_supported_fc4s(shost), 0,
  3022. sizeof(fc_host_supported_fc4s(shost)));
  3023. fc_host_supported_fc4s(shost)[2] = 1;
  3024. fc_host_supported_fc4s(shost)[7] = 1;
  3025. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  3026. sizeof fc_host_symbolic_name(shost));
  3027. fc_host_supported_speeds(shost) = 0;
  3028. if (phba->lmt & LMT_16Gb)
  3029. fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
  3030. if (phba->lmt & LMT_10Gb)
  3031. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  3032. if (phba->lmt & LMT_8Gb)
  3033. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  3034. if (phba->lmt & LMT_4Gb)
  3035. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  3036. if (phba->lmt & LMT_2Gb)
  3037. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  3038. if (phba->lmt & LMT_1Gb)
  3039. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  3040. fc_host_maxframe_size(shost) =
  3041. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  3042. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  3043. fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
  3044. /* This value is also unchanging */
  3045. memset(fc_host_active_fc4s(shost), 0,
  3046. sizeof(fc_host_active_fc4s(shost)));
  3047. fc_host_active_fc4s(shost)[2] = 1;
  3048. fc_host_active_fc4s(shost)[7] = 1;
  3049. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  3050. spin_lock_irq(shost->host_lock);
  3051. vport->load_flag &= ~FC_LOADING;
  3052. spin_unlock_irq(shost->host_lock);
  3053. }
  3054. /**
  3055. * lpfc_stop_port_s3 - Stop SLI3 device port
  3056. * @phba: pointer to lpfc hba data structure.
  3057. *
  3058. * This routine is invoked to stop an SLI3 device port, it stops the device
  3059. * from generating interrupts and stops the device driver's timers for the
  3060. * device.
  3061. **/
  3062. static void
  3063. lpfc_stop_port_s3(struct lpfc_hba *phba)
  3064. {
  3065. /* Clear all interrupt enable conditions */
  3066. writel(0, phba->HCregaddr);
  3067. readl(phba->HCregaddr); /* flush */
  3068. /* Clear all pending interrupts */
  3069. writel(0xffffffff, phba->HAregaddr);
  3070. readl(phba->HAregaddr); /* flush */
  3071. /* Reset some HBA SLI setup states */
  3072. lpfc_stop_hba_timers(phba);
  3073. phba->pport->work_port_events = 0;
  3074. }
  3075. /**
  3076. * lpfc_stop_port_s4 - Stop SLI4 device port
  3077. * @phba: pointer to lpfc hba data structure.
  3078. *
  3079. * This routine is invoked to stop an SLI4 device port, it stops the device
  3080. * from generating interrupts and stops the device driver's timers for the
  3081. * device.
  3082. **/
  3083. static void
  3084. lpfc_stop_port_s4(struct lpfc_hba *phba)
  3085. {
  3086. /* Reset some HBA SLI4 setup states */
  3087. lpfc_stop_hba_timers(phba);
  3088. phba->pport->work_port_events = 0;
  3089. phba->sli4_hba.intr_enable = 0;
  3090. }
  3091. /**
  3092. * lpfc_stop_port - Wrapper function for stopping hba port
  3093. * @phba: Pointer to HBA context object.
  3094. *
  3095. * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
  3096. * the API jump table function pointer from the lpfc_hba struct.
  3097. **/
  3098. void
  3099. lpfc_stop_port(struct lpfc_hba *phba)
  3100. {
  3101. phba->lpfc_stop_port(phba);
  3102. }
  3103. /**
  3104. * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
  3105. * @phba: Pointer to hba for which this call is being executed.
  3106. *
  3107. * This routine starts the timer waiting for the FCF rediscovery to complete.
  3108. **/
  3109. void
  3110. lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
  3111. {
  3112. unsigned long fcf_redisc_wait_tmo =
  3113. (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
  3114. /* Start fcf rediscovery wait period timer */
  3115. mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
  3116. spin_lock_irq(&phba->hbalock);
  3117. /* Allow action to new fcf asynchronous event */
  3118. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
  3119. /* Mark the FCF rediscovery pending state */
  3120. phba->fcf.fcf_flag |= FCF_REDISC_PEND;
  3121. spin_unlock_irq(&phba->hbalock);
  3122. }
  3123. /**
  3124. * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
  3125. * @ptr: Map to lpfc_hba data structure pointer.
  3126. *
  3127. * This routine is invoked when waiting for FCF table rediscover has been
  3128. * timed out. If new FCF record(s) has (have) been discovered during the
  3129. * wait period, a new FCF event shall be added to the FCOE async event
  3130. * list, and then worker thread shall be waked up for processing from the
  3131. * worker thread context.
  3132. **/
  3133. void
  3134. lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
  3135. {
  3136. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  3137. /* Don't send FCF rediscovery event if timer cancelled */
  3138. spin_lock_irq(&phba->hbalock);
  3139. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
  3140. spin_unlock_irq(&phba->hbalock);
  3141. return;
  3142. }
  3143. /* Clear FCF rediscovery timer pending flag */
  3144. phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
  3145. /* FCF rediscovery event to worker thread */
  3146. phba->fcf.fcf_flag |= FCF_REDISC_EVT;
  3147. spin_unlock_irq(&phba->hbalock);
  3148. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  3149. "2776 FCF rediscover quiescent timer expired\n");
  3150. /* wake up worker thread */
  3151. lpfc_worker_wake_up(phba);
  3152. }
  3153. /**
  3154. * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
  3155. * @phba: pointer to lpfc hba data structure.
  3156. * @acqe_link: pointer to the async link completion queue entry.
  3157. *
  3158. * This routine is to parse the SLI4 link-attention link fault code and
  3159. * translate it into the base driver's read link attention mailbox command
  3160. * status.
  3161. *
  3162. * Return: Link-attention status in terms of base driver's coding.
  3163. **/
  3164. static uint16_t
  3165. lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
  3166. struct lpfc_acqe_link *acqe_link)
  3167. {
  3168. uint16_t latt_fault;
  3169. switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
  3170. case LPFC_ASYNC_LINK_FAULT_NONE:
  3171. case LPFC_ASYNC_LINK_FAULT_LOCAL:
  3172. case LPFC_ASYNC_LINK_FAULT_REMOTE:
  3173. latt_fault = 0;
  3174. break;
  3175. default:
  3176. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3177. "0398 Invalid link fault code: x%x\n",
  3178. bf_get(lpfc_acqe_link_fault, acqe_link));
  3179. latt_fault = MBXERR_ERROR;
  3180. break;
  3181. }
  3182. return latt_fault;
  3183. }
  3184. /**
  3185. * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
  3186. * @phba: pointer to lpfc hba data structure.
  3187. * @acqe_link: pointer to the async link completion queue entry.
  3188. *
  3189. * This routine is to parse the SLI4 link attention type and translate it
  3190. * into the base driver's link attention type coding.
  3191. *
  3192. * Return: Link attention type in terms of base driver's coding.
  3193. **/
  3194. static uint8_t
  3195. lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
  3196. struct lpfc_acqe_link *acqe_link)
  3197. {
  3198. uint8_t att_type;
  3199. switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
  3200. case LPFC_ASYNC_LINK_STATUS_DOWN:
  3201. case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
  3202. att_type = LPFC_ATT_LINK_DOWN;
  3203. break;
  3204. case LPFC_ASYNC_LINK_STATUS_UP:
  3205. /* Ignore physical link up events - wait for logical link up */
  3206. att_type = LPFC_ATT_RESERVED;
  3207. break;
  3208. case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
  3209. att_type = LPFC_ATT_LINK_UP;
  3210. break;
  3211. default:
  3212. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3213. "0399 Invalid link attention type: x%x\n",
  3214. bf_get(lpfc_acqe_link_status, acqe_link));
  3215. att_type = LPFC_ATT_RESERVED;
  3216. break;
  3217. }
  3218. return att_type;
  3219. }
  3220. /**
  3221. * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
  3222. * @phba: pointer to lpfc hba data structure.
  3223. * @acqe_link: pointer to the async link completion queue entry.
  3224. *
  3225. * This routine is to parse the SLI4 link-attention link speed and translate
  3226. * it into the base driver's link-attention link speed coding.
  3227. *
  3228. * Return: Link-attention link speed in terms of base driver's coding.
  3229. **/
  3230. static uint8_t
  3231. lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
  3232. struct lpfc_acqe_link *acqe_link)
  3233. {
  3234. uint8_t link_speed;
  3235. switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
  3236. case LPFC_ASYNC_LINK_SPEED_ZERO:
  3237. case LPFC_ASYNC_LINK_SPEED_10MBPS:
  3238. case LPFC_ASYNC_LINK_SPEED_100MBPS:
  3239. link_speed = LPFC_LINK_SPEED_UNKNOWN;
  3240. break;
  3241. case LPFC_ASYNC_LINK_SPEED_1GBPS:
  3242. link_speed = LPFC_LINK_SPEED_1GHZ;
  3243. break;
  3244. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  3245. link_speed = LPFC_LINK_SPEED_10GHZ;
  3246. break;
  3247. default:
  3248. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3249. "0483 Invalid link-attention link speed: x%x\n",
  3250. bf_get(lpfc_acqe_link_speed, acqe_link));
  3251. link_speed = LPFC_LINK_SPEED_UNKNOWN;
  3252. break;
  3253. }
  3254. return link_speed;
  3255. }
  3256. /**
  3257. * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
  3258. * @phba: pointer to lpfc hba data structure.
  3259. *
  3260. * This routine is to get an SLI3 FC port's link speed in Mbps.
  3261. *
  3262. * Return: link speed in terms of Mbps.
  3263. **/
  3264. uint32_t
  3265. lpfc_sli_port_speed_get(struct lpfc_hba *phba)
  3266. {
  3267. uint32_t link_speed;
  3268. if (!lpfc_is_link_up(phba))
  3269. return 0;
  3270. switch (phba->fc_linkspeed) {
  3271. case LPFC_LINK_SPEED_1GHZ:
  3272. link_speed = 1000;
  3273. break;
  3274. case LPFC_LINK_SPEED_2GHZ:
  3275. link_speed = 2000;
  3276. break;
  3277. case LPFC_LINK_SPEED_4GHZ:
  3278. link_speed = 4000;
  3279. break;
  3280. case LPFC_LINK_SPEED_8GHZ:
  3281. link_speed = 8000;
  3282. break;
  3283. case LPFC_LINK_SPEED_10GHZ:
  3284. link_speed = 10000;
  3285. break;
  3286. case LPFC_LINK_SPEED_16GHZ:
  3287. link_speed = 16000;
  3288. break;
  3289. default:
  3290. link_speed = 0;
  3291. }
  3292. return link_speed;
  3293. }
  3294. /**
  3295. * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
  3296. * @phba: pointer to lpfc hba data structure.
  3297. * @evt_code: asynchronous event code.
  3298. * @speed_code: asynchronous event link speed code.
  3299. *
  3300. * This routine is to parse the giving SLI4 async event link speed code into
  3301. * value of Mbps for the link speed.
  3302. *
  3303. * Return: link speed in terms of Mbps.
  3304. **/
  3305. static uint32_t
  3306. lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
  3307. uint8_t speed_code)
  3308. {
  3309. uint32_t port_speed;
  3310. switch (evt_code) {
  3311. case LPFC_TRAILER_CODE_LINK:
  3312. switch (speed_code) {
  3313. case LPFC_EVT_CODE_LINK_NO_LINK:
  3314. port_speed = 0;
  3315. break;
  3316. case LPFC_EVT_CODE_LINK_10_MBIT:
  3317. port_speed = 10;
  3318. break;
  3319. case LPFC_EVT_CODE_LINK_100_MBIT:
  3320. port_speed = 100;
  3321. break;
  3322. case LPFC_EVT_CODE_LINK_1_GBIT:
  3323. port_speed = 1000;
  3324. break;
  3325. case LPFC_EVT_CODE_LINK_10_GBIT:
  3326. port_speed = 10000;
  3327. break;
  3328. default:
  3329. port_speed = 0;
  3330. }
  3331. break;
  3332. case LPFC_TRAILER_CODE_FC:
  3333. switch (speed_code) {
  3334. case LPFC_EVT_CODE_FC_NO_LINK:
  3335. port_speed = 0;
  3336. break;
  3337. case LPFC_EVT_CODE_FC_1_GBAUD:
  3338. port_speed = 1000;
  3339. break;
  3340. case LPFC_EVT_CODE_FC_2_GBAUD:
  3341. port_speed = 2000;
  3342. break;
  3343. case LPFC_EVT_CODE_FC_4_GBAUD:
  3344. port_speed = 4000;
  3345. break;
  3346. case LPFC_EVT_CODE_FC_8_GBAUD:
  3347. port_speed = 8000;
  3348. break;
  3349. case LPFC_EVT_CODE_FC_10_GBAUD:
  3350. port_speed = 10000;
  3351. break;
  3352. case LPFC_EVT_CODE_FC_16_GBAUD:
  3353. port_speed = 16000;
  3354. break;
  3355. default:
  3356. port_speed = 0;
  3357. }
  3358. break;
  3359. default:
  3360. port_speed = 0;
  3361. }
  3362. return port_speed;
  3363. }
  3364. /**
  3365. * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
  3366. * @phba: pointer to lpfc hba data structure.
  3367. * @acqe_link: pointer to the async link completion queue entry.
  3368. *
  3369. * This routine is to handle the SLI4 asynchronous FCoE link event.
  3370. **/
  3371. static void
  3372. lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
  3373. struct lpfc_acqe_link *acqe_link)
  3374. {
  3375. struct lpfc_dmabuf *mp;
  3376. LPFC_MBOXQ_t *pmb;
  3377. MAILBOX_t *mb;
  3378. struct lpfc_mbx_read_top *la;
  3379. uint8_t att_type;
  3380. int rc;
  3381. att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
  3382. if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
  3383. return;
  3384. phba->fcoe_eventtag = acqe_link->event_tag;
  3385. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3386. if (!pmb) {
  3387. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3388. "0395 The mboxq allocation failed\n");
  3389. return;
  3390. }
  3391. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3392. if (!mp) {
  3393. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3394. "0396 The lpfc_dmabuf allocation failed\n");
  3395. goto out_free_pmb;
  3396. }
  3397. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  3398. if (!mp->virt) {
  3399. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3400. "0397 The mbuf allocation failed\n");
  3401. goto out_free_dmabuf;
  3402. }
  3403. /* Cleanup any outstanding ELS commands */
  3404. lpfc_els_flush_all_cmd(phba);
  3405. /* Block ELS IOCBs until we have done process link event */
  3406. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  3407. /* Update link event statistics */
  3408. phba->sli.slistat.link_event++;
  3409. /* Create lpfc_handle_latt mailbox command from link ACQE */
  3410. lpfc_read_topology(phba, pmb, mp);
  3411. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  3412. pmb->vport = phba->pport;
  3413. /* Keep the link status for extra SLI4 state machine reference */
  3414. phba->sli4_hba.link_state.speed =
  3415. lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
  3416. bf_get(lpfc_acqe_link_speed, acqe_link));
  3417. phba->sli4_hba.link_state.duplex =
  3418. bf_get(lpfc_acqe_link_duplex, acqe_link);
  3419. phba->sli4_hba.link_state.status =
  3420. bf_get(lpfc_acqe_link_status, acqe_link);
  3421. phba->sli4_hba.link_state.type =
  3422. bf_get(lpfc_acqe_link_type, acqe_link);
  3423. phba->sli4_hba.link_state.number =
  3424. bf_get(lpfc_acqe_link_number, acqe_link);
  3425. phba->sli4_hba.link_state.fault =
  3426. bf_get(lpfc_acqe_link_fault, acqe_link);
  3427. phba->sli4_hba.link_state.logical_speed =
  3428. bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
  3429. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3430. "2900 Async FC/FCoE Link event - Speed:%dGBit "
  3431. "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
  3432. "Logical speed:%dMbps Fault:%d\n",
  3433. phba->sli4_hba.link_state.speed,
  3434. phba->sli4_hba.link_state.topology,
  3435. phba->sli4_hba.link_state.status,
  3436. phba->sli4_hba.link_state.type,
  3437. phba->sli4_hba.link_state.number,
  3438. phba->sli4_hba.link_state.logical_speed,
  3439. phba->sli4_hba.link_state.fault);
  3440. /*
  3441. * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
  3442. * topology info. Note: Optional for non FC-AL ports.
  3443. */
  3444. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  3445. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3446. if (rc == MBX_NOT_FINISHED)
  3447. goto out_free_dmabuf;
  3448. return;
  3449. }
  3450. /*
  3451. * For FCoE Mode: fill in all the topology information we need and call
  3452. * the READ_TOPOLOGY completion routine to continue without actually
  3453. * sending the READ_TOPOLOGY mailbox command to the port.
  3454. */
  3455. /* Parse and translate status field */
  3456. mb = &pmb->u.mb;
  3457. mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
  3458. /* Parse and translate link attention fields */
  3459. la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
  3460. la->eventTag = acqe_link->event_tag;
  3461. bf_set(lpfc_mbx_read_top_att_type, la, att_type);
  3462. bf_set(lpfc_mbx_read_top_link_spd, la,
  3463. lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
  3464. /* Fake the the following irrelvant fields */
  3465. bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
  3466. bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
  3467. bf_set(lpfc_mbx_read_top_il, la, 0);
  3468. bf_set(lpfc_mbx_read_top_pb, la, 0);
  3469. bf_set(lpfc_mbx_read_top_fa, la, 0);
  3470. bf_set(lpfc_mbx_read_top_mm, la, 0);
  3471. /* Invoke the lpfc_handle_latt mailbox command callback function */
  3472. lpfc_mbx_cmpl_read_topology(phba, pmb);
  3473. return;
  3474. out_free_dmabuf:
  3475. kfree(mp);
  3476. out_free_pmb:
  3477. mempool_free(pmb, phba->mbox_mem_pool);
  3478. }
  3479. /**
  3480. * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
  3481. * @phba: pointer to lpfc hba data structure.
  3482. * @acqe_fc: pointer to the async fc completion queue entry.
  3483. *
  3484. * This routine is to handle the SLI4 asynchronous FC event. It will simply log
  3485. * that the event was received and then issue a read_topology mailbox command so
  3486. * that the rest of the driver will treat it the same as SLI3.
  3487. **/
  3488. static void
  3489. lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
  3490. {
  3491. struct lpfc_dmabuf *mp;
  3492. LPFC_MBOXQ_t *pmb;
  3493. int rc;
  3494. if (bf_get(lpfc_trailer_type, acqe_fc) !=
  3495. LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
  3496. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3497. "2895 Non FC link Event detected.(%d)\n",
  3498. bf_get(lpfc_trailer_type, acqe_fc));
  3499. return;
  3500. }
  3501. /* Keep the link status for extra SLI4 state machine reference */
  3502. phba->sli4_hba.link_state.speed =
  3503. lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
  3504. bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
  3505. phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
  3506. phba->sli4_hba.link_state.topology =
  3507. bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
  3508. phba->sli4_hba.link_state.status =
  3509. bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
  3510. phba->sli4_hba.link_state.type =
  3511. bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
  3512. phba->sli4_hba.link_state.number =
  3513. bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
  3514. phba->sli4_hba.link_state.fault =
  3515. bf_get(lpfc_acqe_link_fault, acqe_fc);
  3516. phba->sli4_hba.link_state.logical_speed =
  3517. bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
  3518. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3519. "2896 Async FC event - Speed:%dGBaud Topology:x%x "
  3520. "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
  3521. "%dMbps Fault:%d\n",
  3522. phba->sli4_hba.link_state.speed,
  3523. phba->sli4_hba.link_state.topology,
  3524. phba->sli4_hba.link_state.status,
  3525. phba->sli4_hba.link_state.type,
  3526. phba->sli4_hba.link_state.number,
  3527. phba->sli4_hba.link_state.logical_speed,
  3528. phba->sli4_hba.link_state.fault);
  3529. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3530. if (!pmb) {
  3531. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3532. "2897 The mboxq allocation failed\n");
  3533. return;
  3534. }
  3535. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3536. if (!mp) {
  3537. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3538. "2898 The lpfc_dmabuf allocation failed\n");
  3539. goto out_free_pmb;
  3540. }
  3541. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  3542. if (!mp->virt) {
  3543. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3544. "2899 The mbuf allocation failed\n");
  3545. goto out_free_dmabuf;
  3546. }
  3547. /* Cleanup any outstanding ELS commands */
  3548. lpfc_els_flush_all_cmd(phba);
  3549. /* Block ELS IOCBs until we have done process link event */
  3550. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  3551. /* Update link event statistics */
  3552. phba->sli.slistat.link_event++;
  3553. /* Create lpfc_handle_latt mailbox command from link ACQE */
  3554. lpfc_read_topology(phba, pmb, mp);
  3555. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  3556. pmb->vport = phba->pport;
  3557. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3558. if (rc == MBX_NOT_FINISHED)
  3559. goto out_free_dmabuf;
  3560. return;
  3561. out_free_dmabuf:
  3562. kfree(mp);
  3563. out_free_pmb:
  3564. mempool_free(pmb, phba->mbox_mem_pool);
  3565. }
  3566. /**
  3567. * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
  3568. * @phba: pointer to lpfc hba data structure.
  3569. * @acqe_fc: pointer to the async SLI completion queue entry.
  3570. *
  3571. * This routine is to handle the SLI4 asynchronous SLI events.
  3572. **/
  3573. static void
  3574. lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
  3575. {
  3576. char port_name;
  3577. char message[128];
  3578. uint8_t status;
  3579. struct lpfc_acqe_misconfigured_event *misconfigured;
  3580. /* special case misconfigured event as it contains data for all ports */
  3581. if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  3582. LPFC_SLI_INTF_IF_TYPE_2) ||
  3583. (bf_get(lpfc_trailer_type, acqe_sli) !=
  3584. LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) {
  3585. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3586. "2901 Async SLI event - Event Data1:x%08x Event Data2:"
  3587. "x%08x SLI Event Type:%d\n",
  3588. acqe_sli->event_data1, acqe_sli->event_data2,
  3589. bf_get(lpfc_trailer_type, acqe_sli));
  3590. return;
  3591. }
  3592. port_name = phba->Port[0];
  3593. if (port_name == 0x00)
  3594. port_name = '?'; /* get port name is empty */
  3595. misconfigured = (struct lpfc_acqe_misconfigured_event *)
  3596. &acqe_sli->event_data1;
  3597. /* fetch the status for this port */
  3598. switch (phba->sli4_hba.lnk_info.lnk_no) {
  3599. case LPFC_LINK_NUMBER_0:
  3600. status = bf_get(lpfc_sli_misconfigured_port0,
  3601. &misconfigured->theEvent);
  3602. break;
  3603. case LPFC_LINK_NUMBER_1:
  3604. status = bf_get(lpfc_sli_misconfigured_port1,
  3605. &misconfigured->theEvent);
  3606. break;
  3607. case LPFC_LINK_NUMBER_2:
  3608. status = bf_get(lpfc_sli_misconfigured_port2,
  3609. &misconfigured->theEvent);
  3610. break;
  3611. case LPFC_LINK_NUMBER_3:
  3612. status = bf_get(lpfc_sli_misconfigured_port3,
  3613. &misconfigured->theEvent);
  3614. break;
  3615. default:
  3616. status = ~LPFC_SLI_EVENT_STATUS_VALID;
  3617. break;
  3618. }
  3619. switch (status) {
  3620. case LPFC_SLI_EVENT_STATUS_VALID:
  3621. return; /* no message if the sfp is okay */
  3622. case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
  3623. sprintf(message, "Optics faulted/incorrectly installed/not " \
  3624. "installed - Reseat optics, if issue not "
  3625. "resolved, replace.");
  3626. break;
  3627. case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
  3628. sprintf(message,
  3629. "Optics of two types installed - Remove one optic or " \
  3630. "install matching pair of optics.");
  3631. break;
  3632. case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
  3633. sprintf(message, "Incompatible optics - Replace with " \
  3634. "compatible optics for card to function.");
  3635. break;
  3636. default:
  3637. /* firmware is reporting a status we don't know about */
  3638. sprintf(message, "Unknown event status x%02x", status);
  3639. break;
  3640. }
  3641. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3642. "3176 Misconfigured Physical Port - "
  3643. "Port Name %c %s\n", port_name, message);
  3644. }
  3645. /**
  3646. * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
  3647. * @vport: pointer to vport data structure.
  3648. *
  3649. * This routine is to perform Clear Virtual Link (CVL) on a vport in
  3650. * response to a CVL event.
  3651. *
  3652. * Return the pointer to the ndlp with the vport if successful, otherwise
  3653. * return NULL.
  3654. **/
  3655. static struct lpfc_nodelist *
  3656. lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
  3657. {
  3658. struct lpfc_nodelist *ndlp;
  3659. struct Scsi_Host *shost;
  3660. struct lpfc_hba *phba;
  3661. if (!vport)
  3662. return NULL;
  3663. phba = vport->phba;
  3664. if (!phba)
  3665. return NULL;
  3666. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  3667. if (!ndlp) {
  3668. /* Cannot find existing Fabric ndlp, so allocate a new one */
  3669. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3670. if (!ndlp)
  3671. return 0;
  3672. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  3673. /* Set the node type */
  3674. ndlp->nlp_type |= NLP_FABRIC;
  3675. /* Put ndlp onto node list */
  3676. lpfc_enqueue_node(vport, ndlp);
  3677. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3678. /* re-setup ndlp without removing from node list */
  3679. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  3680. if (!ndlp)
  3681. return 0;
  3682. }
  3683. if ((phba->pport->port_state < LPFC_FLOGI) &&
  3684. (phba->pport->port_state != LPFC_VPORT_FAILED))
  3685. return NULL;
  3686. /* If virtual link is not yet instantiated ignore CVL */
  3687. if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
  3688. && (vport->port_state != LPFC_VPORT_FAILED))
  3689. return NULL;
  3690. shost = lpfc_shost_from_vport(vport);
  3691. if (!shost)
  3692. return NULL;
  3693. lpfc_linkdown_port(vport);
  3694. lpfc_cleanup_pending_mbox(vport);
  3695. spin_lock_irq(shost->host_lock);
  3696. vport->fc_flag |= FC_VPORT_CVL_RCVD;
  3697. spin_unlock_irq(shost->host_lock);
  3698. return ndlp;
  3699. }
  3700. /**
  3701. * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
  3702. * @vport: pointer to lpfc hba data structure.
  3703. *
  3704. * This routine is to perform Clear Virtual Link (CVL) on all vports in
  3705. * response to a FCF dead event.
  3706. **/
  3707. static void
  3708. lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
  3709. {
  3710. struct lpfc_vport **vports;
  3711. int i;
  3712. vports = lpfc_create_vport_work_array(phba);
  3713. if (vports)
  3714. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  3715. lpfc_sli4_perform_vport_cvl(vports[i]);
  3716. lpfc_destroy_vport_work_array(phba, vports);
  3717. }
  3718. /**
  3719. * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
  3720. * @phba: pointer to lpfc hba data structure.
  3721. * @acqe_link: pointer to the async fcoe completion queue entry.
  3722. *
  3723. * This routine is to handle the SLI4 asynchronous fcoe event.
  3724. **/
  3725. static void
  3726. lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
  3727. struct lpfc_acqe_fip *acqe_fip)
  3728. {
  3729. uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
  3730. int rc;
  3731. struct lpfc_vport *vport;
  3732. struct lpfc_nodelist *ndlp;
  3733. struct Scsi_Host *shost;
  3734. int active_vlink_present;
  3735. struct lpfc_vport **vports;
  3736. int i;
  3737. phba->fc_eventTag = acqe_fip->event_tag;
  3738. phba->fcoe_eventtag = acqe_fip->event_tag;
  3739. switch (event_type) {
  3740. case LPFC_FIP_EVENT_TYPE_NEW_FCF:
  3741. case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
  3742. if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
  3743. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3744. LOG_DISCOVERY,
  3745. "2546 New FCF event, evt_tag:x%x, "
  3746. "index:x%x\n",
  3747. acqe_fip->event_tag,
  3748. acqe_fip->index);
  3749. else
  3750. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
  3751. LOG_DISCOVERY,
  3752. "2788 FCF param modified event, "
  3753. "evt_tag:x%x, index:x%x\n",
  3754. acqe_fip->event_tag,
  3755. acqe_fip->index);
  3756. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3757. /*
  3758. * During period of FCF discovery, read the FCF
  3759. * table record indexed by the event to update
  3760. * FCF roundrobin failover eligible FCF bmask.
  3761. */
  3762. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  3763. LOG_DISCOVERY,
  3764. "2779 Read FCF (x%x) for updating "
  3765. "roundrobin FCF failover bmask\n",
  3766. acqe_fip->index);
  3767. rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
  3768. }
  3769. /* If the FCF discovery is in progress, do nothing. */
  3770. spin_lock_irq(&phba->hbalock);
  3771. if (phba->hba_flag & FCF_TS_INPROG) {
  3772. spin_unlock_irq(&phba->hbalock);
  3773. break;
  3774. }
  3775. /* If fast FCF failover rescan event is pending, do nothing */
  3776. if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
  3777. spin_unlock_irq(&phba->hbalock);
  3778. break;
  3779. }
  3780. /* If the FCF has been in discovered state, do nothing. */
  3781. if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
  3782. spin_unlock_irq(&phba->hbalock);
  3783. break;
  3784. }
  3785. spin_unlock_irq(&phba->hbalock);
  3786. /* Otherwise, scan the entire FCF table and re-discover SAN */
  3787. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3788. "2770 Start FCF table scan per async FCF "
  3789. "event, evt_tag:x%x, index:x%x\n",
  3790. acqe_fip->event_tag, acqe_fip->index);
  3791. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  3792. LPFC_FCOE_FCF_GET_FIRST);
  3793. if (rc)
  3794. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3795. "2547 Issue FCF scan read FCF mailbox "
  3796. "command failed (x%x)\n", rc);
  3797. break;
  3798. case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
  3799. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3800. "2548 FCF Table full count 0x%x tag 0x%x\n",
  3801. bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
  3802. acqe_fip->event_tag);
  3803. break;
  3804. case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
  3805. phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
  3806. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3807. "2549 FCF (x%x) disconnected from network, "
  3808. "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
  3809. /*
  3810. * If we are in the middle of FCF failover process, clear
  3811. * the corresponding FCF bit in the roundrobin bitmap.
  3812. */
  3813. spin_lock_irq(&phba->hbalock);
  3814. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3815. spin_unlock_irq(&phba->hbalock);
  3816. /* Update FLOGI FCF failover eligible FCF bmask */
  3817. lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
  3818. break;
  3819. }
  3820. spin_unlock_irq(&phba->hbalock);
  3821. /* If the event is not for currently used fcf do nothing */
  3822. if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
  3823. break;
  3824. /*
  3825. * Otherwise, request the port to rediscover the entire FCF
  3826. * table for a fast recovery from case that the current FCF
  3827. * is no longer valid as we are not in the middle of FCF
  3828. * failover process already.
  3829. */
  3830. spin_lock_irq(&phba->hbalock);
  3831. /* Mark the fast failover process in progress */
  3832. phba->fcf.fcf_flag |= FCF_DEAD_DISC;
  3833. spin_unlock_irq(&phba->hbalock);
  3834. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3835. "2771 Start FCF fast failover process due to "
  3836. "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
  3837. "\n", acqe_fip->event_tag, acqe_fip->index);
  3838. rc = lpfc_sli4_redisc_fcf_table(phba);
  3839. if (rc) {
  3840. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3841. LOG_DISCOVERY,
  3842. "2772 Issue FCF rediscover mabilbox "
  3843. "command failed, fail through to FCF "
  3844. "dead event\n");
  3845. spin_lock_irq(&phba->hbalock);
  3846. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  3847. spin_unlock_irq(&phba->hbalock);
  3848. /*
  3849. * Last resort will fail over by treating this
  3850. * as a link down to FCF registration.
  3851. */
  3852. lpfc_sli4_fcf_dead_failthrough(phba);
  3853. } else {
  3854. /* Reset FCF roundrobin bmask for new discovery */
  3855. lpfc_sli4_clear_fcf_rr_bmask(phba);
  3856. /*
  3857. * Handling fast FCF failover to a DEAD FCF event is
  3858. * considered equalivant to receiving CVL to all vports.
  3859. */
  3860. lpfc_sli4_perform_all_vport_cvl(phba);
  3861. }
  3862. break;
  3863. case LPFC_FIP_EVENT_TYPE_CVL:
  3864. phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
  3865. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3866. "2718 Clear Virtual Link Received for VPI 0x%x"
  3867. " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
  3868. vport = lpfc_find_vport_by_vpid(phba,
  3869. acqe_fip->index);
  3870. ndlp = lpfc_sli4_perform_vport_cvl(vport);
  3871. if (!ndlp)
  3872. break;
  3873. active_vlink_present = 0;
  3874. vports = lpfc_create_vport_work_array(phba);
  3875. if (vports) {
  3876. for (i = 0; i <= phba->max_vports && vports[i] != NULL;
  3877. i++) {
  3878. if ((!(vports[i]->fc_flag &
  3879. FC_VPORT_CVL_RCVD)) &&
  3880. (vports[i]->port_state > LPFC_FDISC)) {
  3881. active_vlink_present = 1;
  3882. break;
  3883. }
  3884. }
  3885. lpfc_destroy_vport_work_array(phba, vports);
  3886. }
  3887. if (active_vlink_present) {
  3888. /*
  3889. * If there are other active VLinks present,
  3890. * re-instantiate the Vlink using FDISC.
  3891. */
  3892. mod_timer(&ndlp->nlp_delayfunc,
  3893. jiffies + msecs_to_jiffies(1000));
  3894. shost = lpfc_shost_from_vport(vport);
  3895. spin_lock_irq(shost->host_lock);
  3896. ndlp->nlp_flag |= NLP_DELAY_TMO;
  3897. spin_unlock_irq(shost->host_lock);
  3898. ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
  3899. vport->port_state = LPFC_FDISC;
  3900. } else {
  3901. /*
  3902. * Otherwise, we request port to rediscover
  3903. * the entire FCF table for a fast recovery
  3904. * from possible case that the current FCF
  3905. * is no longer valid if we are not already
  3906. * in the FCF failover process.
  3907. */
  3908. spin_lock_irq(&phba->hbalock);
  3909. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3910. spin_unlock_irq(&phba->hbalock);
  3911. break;
  3912. }
  3913. /* Mark the fast failover process in progress */
  3914. phba->fcf.fcf_flag |= FCF_ACVL_DISC;
  3915. spin_unlock_irq(&phba->hbalock);
  3916. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  3917. LOG_DISCOVERY,
  3918. "2773 Start FCF failover per CVL, "
  3919. "evt_tag:x%x\n", acqe_fip->event_tag);
  3920. rc = lpfc_sli4_redisc_fcf_table(phba);
  3921. if (rc) {
  3922. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3923. LOG_DISCOVERY,
  3924. "2774 Issue FCF rediscover "
  3925. "mabilbox command failed, "
  3926. "through to CVL event\n");
  3927. spin_lock_irq(&phba->hbalock);
  3928. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  3929. spin_unlock_irq(&phba->hbalock);
  3930. /*
  3931. * Last resort will be re-try on the
  3932. * the current registered FCF entry.
  3933. */
  3934. lpfc_retry_pport_discovery(phba);
  3935. } else
  3936. /*
  3937. * Reset FCF roundrobin bmask for new
  3938. * discovery.
  3939. */
  3940. lpfc_sli4_clear_fcf_rr_bmask(phba);
  3941. }
  3942. break;
  3943. default:
  3944. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3945. "0288 Unknown FCoE event type 0x%x event tag "
  3946. "0x%x\n", event_type, acqe_fip->event_tag);
  3947. break;
  3948. }
  3949. }
  3950. /**
  3951. * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
  3952. * @phba: pointer to lpfc hba data structure.
  3953. * @acqe_link: pointer to the async dcbx completion queue entry.
  3954. *
  3955. * This routine is to handle the SLI4 asynchronous dcbx event.
  3956. **/
  3957. static void
  3958. lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
  3959. struct lpfc_acqe_dcbx *acqe_dcbx)
  3960. {
  3961. phba->fc_eventTag = acqe_dcbx->event_tag;
  3962. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3963. "0290 The SLI4 DCBX asynchronous event is not "
  3964. "handled yet\n");
  3965. }
  3966. /**
  3967. * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
  3968. * @phba: pointer to lpfc hba data structure.
  3969. * @acqe_link: pointer to the async grp5 completion queue entry.
  3970. *
  3971. * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
  3972. * is an asynchronous notified of a logical link speed change. The Port
  3973. * reports the logical link speed in units of 10Mbps.
  3974. **/
  3975. static void
  3976. lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
  3977. struct lpfc_acqe_grp5 *acqe_grp5)
  3978. {
  3979. uint16_t prev_ll_spd;
  3980. phba->fc_eventTag = acqe_grp5->event_tag;
  3981. phba->fcoe_eventtag = acqe_grp5->event_tag;
  3982. prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
  3983. phba->sli4_hba.link_state.logical_speed =
  3984. (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
  3985. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3986. "2789 GRP5 Async Event: Updating logical link speed "
  3987. "from %dMbps to %dMbps\n", prev_ll_spd,
  3988. phba->sli4_hba.link_state.logical_speed);
  3989. }
  3990. /**
  3991. * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
  3992. * @phba: pointer to lpfc hba data structure.
  3993. *
  3994. * This routine is invoked by the worker thread to process all the pending
  3995. * SLI4 asynchronous events.
  3996. **/
  3997. void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
  3998. {
  3999. struct lpfc_cq_event *cq_event;
  4000. /* First, declare the async event has been handled */
  4001. spin_lock_irq(&phba->hbalock);
  4002. phba->hba_flag &= ~ASYNC_EVENT;
  4003. spin_unlock_irq(&phba->hbalock);
  4004. /* Now, handle all the async events */
  4005. while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
  4006. /* Get the first event from the head of the event queue */
  4007. spin_lock_irq(&phba->hbalock);
  4008. list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
  4009. cq_event, struct lpfc_cq_event, list);
  4010. spin_unlock_irq(&phba->hbalock);
  4011. /* Process the asynchronous event */
  4012. switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
  4013. case LPFC_TRAILER_CODE_LINK:
  4014. lpfc_sli4_async_link_evt(phba,
  4015. &cq_event->cqe.acqe_link);
  4016. break;
  4017. case LPFC_TRAILER_CODE_FCOE:
  4018. lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
  4019. break;
  4020. case LPFC_TRAILER_CODE_DCBX:
  4021. lpfc_sli4_async_dcbx_evt(phba,
  4022. &cq_event->cqe.acqe_dcbx);
  4023. break;
  4024. case LPFC_TRAILER_CODE_GRP5:
  4025. lpfc_sli4_async_grp5_evt(phba,
  4026. &cq_event->cqe.acqe_grp5);
  4027. break;
  4028. case LPFC_TRAILER_CODE_FC:
  4029. lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
  4030. break;
  4031. case LPFC_TRAILER_CODE_SLI:
  4032. lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
  4033. break;
  4034. default:
  4035. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4036. "1804 Invalid asynchrous event code: "
  4037. "x%x\n", bf_get(lpfc_trailer_code,
  4038. &cq_event->cqe.mcqe_cmpl));
  4039. break;
  4040. }
  4041. /* Free the completion event processed to the free pool */
  4042. lpfc_sli4_cq_event_release(phba, cq_event);
  4043. }
  4044. }
  4045. /**
  4046. * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
  4047. * @phba: pointer to lpfc hba data structure.
  4048. *
  4049. * This routine is invoked by the worker thread to process FCF table
  4050. * rediscovery pending completion event.
  4051. **/
  4052. void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
  4053. {
  4054. int rc;
  4055. spin_lock_irq(&phba->hbalock);
  4056. /* Clear FCF rediscovery timeout event */
  4057. phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
  4058. /* Clear driver fast failover FCF record flag */
  4059. phba->fcf.failover_rec.flag = 0;
  4060. /* Set state for FCF fast failover */
  4061. phba->fcf.fcf_flag |= FCF_REDISC_FOV;
  4062. spin_unlock_irq(&phba->hbalock);
  4063. /* Scan FCF table from the first entry to re-discover SAN */
  4064. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  4065. "2777 Start post-quiescent FCF table scan\n");
  4066. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
  4067. if (rc)
  4068. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  4069. "2747 Issue FCF scan read FCF mailbox "
  4070. "command failed 0x%x\n", rc);
  4071. }
  4072. /**
  4073. * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
  4074. * @phba: pointer to lpfc hba data structure.
  4075. * @dev_grp: The HBA PCI-Device group number.
  4076. *
  4077. * This routine is invoked to set up the per HBA PCI-Device group function
  4078. * API jump table entries.
  4079. *
  4080. * Return: 0 if success, otherwise -ENODEV
  4081. **/
  4082. int
  4083. lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4084. {
  4085. int rc;
  4086. /* Set up lpfc PCI-device group */
  4087. phba->pci_dev_grp = dev_grp;
  4088. /* The LPFC_PCI_DEV_OC uses SLI4 */
  4089. if (dev_grp == LPFC_PCI_DEV_OC)
  4090. phba->sli_rev = LPFC_SLI_REV4;
  4091. /* Set up device INIT API function jump table */
  4092. rc = lpfc_init_api_table_setup(phba, dev_grp);
  4093. if (rc)
  4094. return -ENODEV;
  4095. /* Set up SCSI API function jump table */
  4096. rc = lpfc_scsi_api_table_setup(phba, dev_grp);
  4097. if (rc)
  4098. return -ENODEV;
  4099. /* Set up SLI API function jump table */
  4100. rc = lpfc_sli_api_table_setup(phba, dev_grp);
  4101. if (rc)
  4102. return -ENODEV;
  4103. /* Set up MBOX API function jump table */
  4104. rc = lpfc_mbox_api_table_setup(phba, dev_grp);
  4105. if (rc)
  4106. return -ENODEV;
  4107. return 0;
  4108. }
  4109. /**
  4110. * lpfc_log_intr_mode - Log the active interrupt mode
  4111. * @phba: pointer to lpfc hba data structure.
  4112. * @intr_mode: active interrupt mode adopted.
  4113. *
  4114. * This routine it invoked to log the currently used active interrupt mode
  4115. * to the device.
  4116. **/
  4117. static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
  4118. {
  4119. switch (intr_mode) {
  4120. case 0:
  4121. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4122. "0470 Enable INTx interrupt mode.\n");
  4123. break;
  4124. case 1:
  4125. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4126. "0481 Enabled MSI interrupt mode.\n");
  4127. break;
  4128. case 2:
  4129. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4130. "0480 Enabled MSI-X interrupt mode.\n");
  4131. break;
  4132. default:
  4133. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4134. "0482 Illegal interrupt mode.\n");
  4135. break;
  4136. }
  4137. return;
  4138. }
  4139. /**
  4140. * lpfc_enable_pci_dev - Enable a generic PCI device.
  4141. * @phba: pointer to lpfc hba data structure.
  4142. *
  4143. * This routine is invoked to enable the PCI device that is common to all
  4144. * PCI devices.
  4145. *
  4146. * Return codes
  4147. * 0 - successful
  4148. * other values - error
  4149. **/
  4150. static int
  4151. lpfc_enable_pci_dev(struct lpfc_hba *phba)
  4152. {
  4153. struct pci_dev *pdev;
  4154. int bars = 0;
  4155. /* Obtain PCI device reference */
  4156. if (!phba->pcidev)
  4157. goto out_error;
  4158. else
  4159. pdev = phba->pcidev;
  4160. /* Select PCI BARs */
  4161. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  4162. /* Enable PCI device */
  4163. if (pci_enable_device_mem(pdev))
  4164. goto out_error;
  4165. /* Request PCI resource for the device */
  4166. if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
  4167. goto out_disable_device;
  4168. /* Set up device as PCI master and save state for EEH */
  4169. pci_set_master(pdev);
  4170. pci_try_set_mwi(pdev);
  4171. pci_save_state(pdev);
  4172. /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
  4173. if (pci_find_capability(pdev, PCI_CAP_ID_EXP))
  4174. pdev->needs_freset = 1;
  4175. return 0;
  4176. out_disable_device:
  4177. pci_disable_device(pdev);
  4178. out_error:
  4179. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4180. "1401 Failed to enable pci device, bars:x%x\n", bars);
  4181. return -ENODEV;
  4182. }
  4183. /**
  4184. * lpfc_disable_pci_dev - Disable a generic PCI device.
  4185. * @phba: pointer to lpfc hba data structure.
  4186. *
  4187. * This routine is invoked to disable the PCI device that is common to all
  4188. * PCI devices.
  4189. **/
  4190. static void
  4191. lpfc_disable_pci_dev(struct lpfc_hba *phba)
  4192. {
  4193. struct pci_dev *pdev;
  4194. int bars;
  4195. /* Obtain PCI device reference */
  4196. if (!phba->pcidev)
  4197. return;
  4198. else
  4199. pdev = phba->pcidev;
  4200. /* Select PCI BARs */
  4201. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  4202. /* Release PCI resource and disable PCI device */
  4203. pci_release_selected_regions(pdev, bars);
  4204. pci_disable_device(pdev);
  4205. /* Null out PCI private reference to driver */
  4206. pci_set_drvdata(pdev, NULL);
  4207. return;
  4208. }
  4209. /**
  4210. * lpfc_reset_hba - Reset a hba
  4211. * @phba: pointer to lpfc hba data structure.
  4212. *
  4213. * This routine is invoked to reset a hba device. It brings the HBA
  4214. * offline, performs a board restart, and then brings the board back
  4215. * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
  4216. * on outstanding mailbox commands.
  4217. **/
  4218. void
  4219. lpfc_reset_hba(struct lpfc_hba *phba)
  4220. {
  4221. /* If resets are disabled then set error state and return. */
  4222. if (!phba->cfg_enable_hba_reset) {
  4223. phba->link_state = LPFC_HBA_ERROR;
  4224. return;
  4225. }
  4226. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  4227. lpfc_offline(phba);
  4228. lpfc_sli_brdrestart(phba);
  4229. lpfc_online(phba);
  4230. lpfc_unblock_mgmt_io(phba);
  4231. }
  4232. /**
  4233. * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
  4234. * @phba: pointer to lpfc hba data structure.
  4235. *
  4236. * This function enables the PCI SR-IOV virtual functions to a physical
  4237. * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
  4238. * enable the number of virtual functions to the physical function. As
  4239. * not all devices support SR-IOV, the return code from the pci_enable_sriov()
  4240. * API call does not considered as an error condition for most of the device.
  4241. **/
  4242. uint16_t
  4243. lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
  4244. {
  4245. struct pci_dev *pdev = phba->pcidev;
  4246. uint16_t nr_virtfn;
  4247. int pos;
  4248. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
  4249. if (pos == 0)
  4250. return 0;
  4251. pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
  4252. return nr_virtfn;
  4253. }
  4254. /**
  4255. * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
  4256. * @phba: pointer to lpfc hba data structure.
  4257. * @nr_vfn: number of virtual functions to be enabled.
  4258. *
  4259. * This function enables the PCI SR-IOV virtual functions to a physical
  4260. * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
  4261. * enable the number of virtual functions to the physical function. As
  4262. * not all devices support SR-IOV, the return code from the pci_enable_sriov()
  4263. * API call does not considered as an error condition for most of the device.
  4264. **/
  4265. int
  4266. lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
  4267. {
  4268. struct pci_dev *pdev = phba->pcidev;
  4269. uint16_t max_nr_vfn;
  4270. int rc;
  4271. max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
  4272. if (nr_vfn > max_nr_vfn) {
  4273. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4274. "3057 Requested vfs (%d) greater than "
  4275. "supported vfs (%d)", nr_vfn, max_nr_vfn);
  4276. return -EINVAL;
  4277. }
  4278. rc = pci_enable_sriov(pdev, nr_vfn);
  4279. if (rc) {
  4280. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4281. "2806 Failed to enable sriov on this device "
  4282. "with vfn number nr_vf:%d, rc:%d\n",
  4283. nr_vfn, rc);
  4284. } else
  4285. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4286. "2807 Successful enable sriov on this device "
  4287. "with vfn number nr_vf:%d\n", nr_vfn);
  4288. return rc;
  4289. }
  4290. /**
  4291. * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
  4292. * @phba: pointer to lpfc hba data structure.
  4293. *
  4294. * This routine is invoked to set up the driver internal resources specific to
  4295. * support the SLI-3 HBA device it attached to.
  4296. *
  4297. * Return codes
  4298. * 0 - successful
  4299. * other values - error
  4300. **/
  4301. static int
  4302. lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
  4303. {
  4304. struct lpfc_sli *psli;
  4305. int rc;
  4306. /*
  4307. * Initialize timers used by driver
  4308. */
  4309. /* Heartbeat timer */
  4310. init_timer(&phba->hb_tmofunc);
  4311. phba->hb_tmofunc.function = lpfc_hb_timeout;
  4312. phba->hb_tmofunc.data = (unsigned long)phba;
  4313. psli = &phba->sli;
  4314. /* MBOX heartbeat timer */
  4315. init_timer(&psli->mbox_tmo);
  4316. psli->mbox_tmo.function = lpfc_mbox_timeout;
  4317. psli->mbox_tmo.data = (unsigned long) phba;
  4318. /* FCP polling mode timer */
  4319. init_timer(&phba->fcp_poll_timer);
  4320. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  4321. phba->fcp_poll_timer.data = (unsigned long) phba;
  4322. /* Fabric block timer */
  4323. init_timer(&phba->fabric_block_timer);
  4324. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  4325. phba->fabric_block_timer.data = (unsigned long) phba;
  4326. /* EA polling mode timer */
  4327. init_timer(&phba->eratt_poll);
  4328. phba->eratt_poll.function = lpfc_poll_eratt;
  4329. phba->eratt_poll.data = (unsigned long) phba;
  4330. /* Host attention work mask setup */
  4331. phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
  4332. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  4333. /* Get all the module params for configuring this host */
  4334. lpfc_get_cfgparam(phba);
  4335. if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
  4336. phba->menlo_flag |= HBA_MENLO_SUPPORT;
  4337. /* check for menlo minimum sg count */
  4338. if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
  4339. phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
  4340. }
  4341. if (!phba->sli.ring)
  4342. phba->sli.ring = (struct lpfc_sli_ring *)
  4343. kzalloc(LPFC_SLI3_MAX_RING *
  4344. sizeof(struct lpfc_sli_ring), GFP_KERNEL);
  4345. if (!phba->sli.ring)
  4346. return -ENOMEM;
  4347. /*
  4348. * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
  4349. * used to create the sg_dma_buf_pool must be dynamically calculated.
  4350. */
  4351. /* Initialize the host templates the configured values. */
  4352. lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  4353. lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  4354. /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
  4355. if (phba->cfg_enable_bg) {
  4356. /*
  4357. * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
  4358. * the FCP rsp, and a BDE for each. Sice we have no control
  4359. * over how many protection data segments the SCSI Layer
  4360. * will hand us (ie: there could be one for every block
  4361. * in the IO), we just allocate enough BDEs to accomidate
  4362. * our max amount and we need to limit lpfc_sg_seg_cnt to
  4363. * minimize the risk of running out.
  4364. */
  4365. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  4366. sizeof(struct fcp_rsp) +
  4367. (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
  4368. if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
  4369. phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
  4370. /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
  4371. phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
  4372. } else {
  4373. /*
  4374. * The scsi_buf for a regular I/O will hold the FCP cmnd,
  4375. * the FCP rsp, a BDE for each, and a BDE for up to
  4376. * cfg_sg_seg_cnt data segments.
  4377. */
  4378. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  4379. sizeof(struct fcp_rsp) +
  4380. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
  4381. /* Total BDEs in BPL for scsi_sg_list */
  4382. phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
  4383. }
  4384. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
  4385. "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
  4386. phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
  4387. phba->cfg_total_seg_cnt);
  4388. phba->max_vpi = LPFC_MAX_VPI;
  4389. /* This will be set to correct value after config_port mbox */
  4390. phba->max_vports = 0;
  4391. /*
  4392. * Initialize the SLI Layer to run with lpfc HBAs.
  4393. */
  4394. lpfc_sli_setup(phba);
  4395. lpfc_sli_queue_setup(phba);
  4396. /* Allocate device driver memory */
  4397. if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
  4398. return -ENOMEM;
  4399. /*
  4400. * Enable sr-iov virtual functions if supported and configured
  4401. * through the module parameter.
  4402. */
  4403. if (phba->cfg_sriov_nr_virtfn > 0) {
  4404. rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
  4405. phba->cfg_sriov_nr_virtfn);
  4406. if (rc) {
  4407. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4408. "2808 Requested number of SR-IOV "
  4409. "virtual functions (%d) is not "
  4410. "supported\n",
  4411. phba->cfg_sriov_nr_virtfn);
  4412. phba->cfg_sriov_nr_virtfn = 0;
  4413. }
  4414. }
  4415. return 0;
  4416. }
  4417. /**
  4418. * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
  4419. * @phba: pointer to lpfc hba data structure.
  4420. *
  4421. * This routine is invoked to unset the driver internal resources set up
  4422. * specific for supporting the SLI-3 HBA device it attached to.
  4423. **/
  4424. static void
  4425. lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
  4426. {
  4427. /* Free device driver memory allocated */
  4428. lpfc_mem_free_all(phba);
  4429. return;
  4430. }
  4431. /**
  4432. * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
  4433. * @phba: pointer to lpfc hba data structure.
  4434. *
  4435. * This routine is invoked to set up the driver internal resources specific to
  4436. * support the SLI-4 HBA device it attached to.
  4437. *
  4438. * Return codes
  4439. * 0 - successful
  4440. * other values - error
  4441. **/
  4442. static int
  4443. lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
  4444. {
  4445. struct lpfc_vector_map_info *cpup;
  4446. struct lpfc_sli *psli;
  4447. LPFC_MBOXQ_t *mboxq;
  4448. int rc, i, hbq_count, max_buf_size;
  4449. uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
  4450. struct lpfc_mqe *mqe;
  4451. int longs;
  4452. /* Get all the module params for configuring this host */
  4453. lpfc_get_cfgparam(phba);
  4454. /* Before proceed, wait for POST done and device ready */
  4455. rc = lpfc_sli4_post_status_check(phba);
  4456. if (rc)
  4457. return -ENODEV;
  4458. /*
  4459. * Initialize timers used by driver
  4460. */
  4461. /* Heartbeat timer */
  4462. init_timer(&phba->hb_tmofunc);
  4463. phba->hb_tmofunc.function = lpfc_hb_timeout;
  4464. phba->hb_tmofunc.data = (unsigned long)phba;
  4465. init_timer(&phba->rrq_tmr);
  4466. phba->rrq_tmr.function = lpfc_rrq_timeout;
  4467. phba->rrq_tmr.data = (unsigned long)phba;
  4468. psli = &phba->sli;
  4469. /* MBOX heartbeat timer */
  4470. init_timer(&psli->mbox_tmo);
  4471. psli->mbox_tmo.function = lpfc_mbox_timeout;
  4472. psli->mbox_tmo.data = (unsigned long) phba;
  4473. /* Fabric block timer */
  4474. init_timer(&phba->fabric_block_timer);
  4475. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  4476. phba->fabric_block_timer.data = (unsigned long) phba;
  4477. /* EA polling mode timer */
  4478. init_timer(&phba->eratt_poll);
  4479. phba->eratt_poll.function = lpfc_poll_eratt;
  4480. phba->eratt_poll.data = (unsigned long) phba;
  4481. /* FCF rediscover timer */
  4482. init_timer(&phba->fcf.redisc_wait);
  4483. phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
  4484. phba->fcf.redisc_wait.data = (unsigned long)phba;
  4485. /*
  4486. * Control structure for handling external multi-buffer mailbox
  4487. * command pass-through.
  4488. */
  4489. memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
  4490. sizeof(struct lpfc_mbox_ext_buf_ctx));
  4491. INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
  4492. phba->max_vpi = LPFC_MAX_VPI;
  4493. /* This will be set to correct value after the read_config mbox */
  4494. phba->max_vports = 0;
  4495. /* Program the default value of vlan_id and fc_map */
  4496. phba->valid_vlan = 0;
  4497. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4498. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4499. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4500. /*
  4501. * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
  4502. * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
  4503. */
  4504. if (!phba->sli.ring)
  4505. phba->sli.ring = kzalloc(
  4506. (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) *
  4507. sizeof(struct lpfc_sli_ring), GFP_KERNEL);
  4508. if (!phba->sli.ring)
  4509. return -ENOMEM;
  4510. /*
  4511. * It doesn't matter what family our adapter is in, we are
  4512. * limited to 2 Pages, 512 SGEs, for our SGL.
  4513. * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
  4514. */
  4515. max_buf_size = (2 * SLI4_PAGE_SIZE);
  4516. if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
  4517. phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
  4518. /*
  4519. * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
  4520. * used to create the sg_dma_buf_pool must be dynamically calculated.
  4521. */
  4522. if (phba->cfg_enable_bg) {
  4523. /*
  4524. * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
  4525. * the FCP rsp, and a SGE for each. Sice we have no control
  4526. * over how many protection data segments the SCSI Layer
  4527. * will hand us (ie: there could be one for every block
  4528. * in the IO), we just allocate enough SGEs to accomidate
  4529. * our max amount and we need to limit lpfc_sg_seg_cnt to
  4530. * minimize the risk of running out.
  4531. */
  4532. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  4533. sizeof(struct fcp_rsp) + max_buf_size;
  4534. /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
  4535. phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
  4536. if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
  4537. phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
  4538. } else {
  4539. /*
  4540. * The scsi_buf for a regular I/O will hold the FCP cmnd,
  4541. * the FCP rsp, a SGE for each, and a SGE for up to
  4542. * cfg_sg_seg_cnt data segments.
  4543. */
  4544. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  4545. sizeof(struct fcp_rsp) +
  4546. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
  4547. /* Total SGEs for scsi_sg_list */
  4548. phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
  4549. /*
  4550. * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need
  4551. * to post 1 page for the SGL.
  4552. */
  4553. }
  4554. /* Initialize the host templates with the updated values. */
  4555. lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  4556. lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  4557. if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
  4558. phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
  4559. else
  4560. phba->cfg_sg_dma_buf_size =
  4561. SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
  4562. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
  4563. "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
  4564. phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
  4565. phba->cfg_total_seg_cnt);
  4566. /* Initialize buffer queue management fields */
  4567. hbq_count = lpfc_sli_hbq_count();
  4568. for (i = 0; i < hbq_count; ++i)
  4569. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  4570. INIT_LIST_HEAD(&phba->rb_pend_list);
  4571. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
  4572. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
  4573. /*
  4574. * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
  4575. */
  4576. /* Initialize the Abort scsi buffer list used by driver */
  4577. spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
  4578. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  4579. /* This abort list used by worker thread */
  4580. spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
  4581. /*
  4582. * Initialize driver internal slow-path work queues
  4583. */
  4584. /* Driver internel slow-path CQ Event pool */
  4585. INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
  4586. /* Response IOCB work queue list */
  4587. INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
  4588. /* Asynchronous event CQ Event work queue list */
  4589. INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
  4590. /* Fast-path XRI aborted CQ Event work queue list */
  4591. INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  4592. /* Slow-path XRI aborted CQ Event work queue list */
  4593. INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
  4594. /* Receive queue CQ Event work queue list */
  4595. INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
  4596. /* Initialize extent block lists. */
  4597. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
  4598. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
  4599. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
  4600. INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
  4601. /* Initialize the driver internal SLI layer lists. */
  4602. lpfc_sli_setup(phba);
  4603. lpfc_sli_queue_setup(phba);
  4604. /* Allocate device driver memory */
  4605. rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
  4606. if (rc)
  4607. return -ENOMEM;
  4608. /* IF Type 2 ports get initialized now. */
  4609. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  4610. LPFC_SLI_INTF_IF_TYPE_2) {
  4611. rc = lpfc_pci_function_reset(phba);
  4612. if (unlikely(rc))
  4613. return -ENODEV;
  4614. }
  4615. /* Create the bootstrap mailbox command */
  4616. rc = lpfc_create_bootstrap_mbox(phba);
  4617. if (unlikely(rc))
  4618. goto out_free_mem;
  4619. /* Set up the host's endian order with the device. */
  4620. rc = lpfc_setup_endian_order(phba);
  4621. if (unlikely(rc))
  4622. goto out_free_bsmbx;
  4623. /* Set up the hba's configuration parameters. */
  4624. rc = lpfc_sli4_read_config(phba);
  4625. if (unlikely(rc))
  4626. goto out_free_bsmbx;
  4627. /* IF Type 0 ports get initialized now. */
  4628. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  4629. LPFC_SLI_INTF_IF_TYPE_0) {
  4630. rc = lpfc_pci_function_reset(phba);
  4631. if (unlikely(rc))
  4632. goto out_free_bsmbx;
  4633. }
  4634. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  4635. GFP_KERNEL);
  4636. if (!mboxq) {
  4637. rc = -ENOMEM;
  4638. goto out_free_bsmbx;
  4639. }
  4640. /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
  4641. lpfc_supported_pages(mboxq);
  4642. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4643. if (!rc) {
  4644. mqe = &mboxq->u.mqe;
  4645. memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
  4646. LPFC_MAX_SUPPORTED_PAGES);
  4647. for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
  4648. switch (pn_page[i]) {
  4649. case LPFC_SLI4_PARAMETERS:
  4650. phba->sli4_hba.pc_sli4_params.supported = 1;
  4651. break;
  4652. default:
  4653. break;
  4654. }
  4655. }
  4656. /* Read the port's SLI4 Parameters capabilities if supported. */
  4657. if (phba->sli4_hba.pc_sli4_params.supported)
  4658. rc = lpfc_pc_sli4_params_get(phba, mboxq);
  4659. if (rc) {
  4660. mempool_free(mboxq, phba->mbox_mem_pool);
  4661. rc = -EIO;
  4662. goto out_free_bsmbx;
  4663. }
  4664. }
  4665. /*
  4666. * Get sli4 parameters that override parameters from Port capabilities.
  4667. * If this call fails, it isn't critical unless the SLI4 parameters come
  4668. * back in conflict.
  4669. */
  4670. rc = lpfc_get_sli4_parameters(phba, mboxq);
  4671. if (rc) {
  4672. if (phba->sli4_hba.extents_in_use &&
  4673. phba->sli4_hba.rpi_hdrs_in_use) {
  4674. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4675. "2999 Unsupported SLI4 Parameters "
  4676. "Extents and RPI headers enabled.\n");
  4677. goto out_free_bsmbx;
  4678. }
  4679. }
  4680. mempool_free(mboxq, phba->mbox_mem_pool);
  4681. /* Verify all the SLI4 queues */
  4682. rc = lpfc_sli4_queue_verify(phba);
  4683. if (rc)
  4684. goto out_free_bsmbx;
  4685. /* Create driver internal CQE event pool */
  4686. rc = lpfc_sli4_cq_event_pool_create(phba);
  4687. if (rc)
  4688. goto out_free_bsmbx;
  4689. /* Initialize sgl lists per host */
  4690. lpfc_init_sgl_list(phba);
  4691. /* Allocate and initialize active sgl array */
  4692. rc = lpfc_init_active_sgl_array(phba);
  4693. if (rc) {
  4694. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4695. "1430 Failed to initialize sgl list.\n");
  4696. goto out_destroy_cq_event_pool;
  4697. }
  4698. rc = lpfc_sli4_init_rpi_hdrs(phba);
  4699. if (rc) {
  4700. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4701. "1432 Failed to initialize rpi headers.\n");
  4702. goto out_free_active_sgl;
  4703. }
  4704. /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
  4705. longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
  4706. phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
  4707. GFP_KERNEL);
  4708. if (!phba->fcf.fcf_rr_bmask) {
  4709. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4710. "2759 Failed allocate memory for FCF round "
  4711. "robin failover bmask\n");
  4712. rc = -ENOMEM;
  4713. goto out_remove_rpi_hdrs;
  4714. }
  4715. phba->sli4_hba.fcp_eq_hdl =
  4716. kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
  4717. phba->cfg_fcp_io_channel), GFP_KERNEL);
  4718. if (!phba->sli4_hba.fcp_eq_hdl) {
  4719. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4720. "2572 Failed allocate memory for "
  4721. "fast-path per-EQ handle array\n");
  4722. rc = -ENOMEM;
  4723. goto out_free_fcf_rr_bmask;
  4724. }
  4725. phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
  4726. phba->cfg_fcp_io_channel), GFP_KERNEL);
  4727. if (!phba->sli4_hba.msix_entries) {
  4728. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4729. "2573 Failed allocate memory for msi-x "
  4730. "interrupt vector entries\n");
  4731. rc = -ENOMEM;
  4732. goto out_free_fcp_eq_hdl;
  4733. }
  4734. phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) *
  4735. phba->sli4_hba.num_present_cpu),
  4736. GFP_KERNEL);
  4737. if (!phba->sli4_hba.cpu_map) {
  4738. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4739. "3327 Failed allocate memory for msi-x "
  4740. "interrupt vector mapping\n");
  4741. rc = -ENOMEM;
  4742. goto out_free_msix;
  4743. }
  4744. if (lpfc_used_cpu == NULL) {
  4745. lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu),
  4746. GFP_KERNEL);
  4747. if (!lpfc_used_cpu) {
  4748. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4749. "3335 Failed allocate memory for msi-x "
  4750. "interrupt vector mapping\n");
  4751. kfree(phba->sli4_hba.cpu_map);
  4752. rc = -ENOMEM;
  4753. goto out_free_msix;
  4754. }
  4755. for (i = 0; i < lpfc_present_cpu; i++)
  4756. lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
  4757. }
  4758. /* Initialize io channels for round robin */
  4759. cpup = phba->sli4_hba.cpu_map;
  4760. rc = 0;
  4761. for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
  4762. cpup->channel_id = rc;
  4763. rc++;
  4764. if (rc >= phba->cfg_fcp_io_channel)
  4765. rc = 0;
  4766. }
  4767. /*
  4768. * Enable sr-iov virtual functions if supported and configured
  4769. * through the module parameter.
  4770. */
  4771. if (phba->cfg_sriov_nr_virtfn > 0) {
  4772. rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
  4773. phba->cfg_sriov_nr_virtfn);
  4774. if (rc) {
  4775. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4776. "3020 Requested number of SR-IOV "
  4777. "virtual functions (%d) is not "
  4778. "supported\n",
  4779. phba->cfg_sriov_nr_virtfn);
  4780. phba->cfg_sriov_nr_virtfn = 0;
  4781. }
  4782. }
  4783. return 0;
  4784. out_free_msix:
  4785. kfree(phba->sli4_hba.msix_entries);
  4786. out_free_fcp_eq_hdl:
  4787. kfree(phba->sli4_hba.fcp_eq_hdl);
  4788. out_free_fcf_rr_bmask:
  4789. kfree(phba->fcf.fcf_rr_bmask);
  4790. out_remove_rpi_hdrs:
  4791. lpfc_sli4_remove_rpi_hdrs(phba);
  4792. out_free_active_sgl:
  4793. lpfc_free_active_sgl(phba);
  4794. out_destroy_cq_event_pool:
  4795. lpfc_sli4_cq_event_pool_destroy(phba);
  4796. out_free_bsmbx:
  4797. lpfc_destroy_bootstrap_mbox(phba);
  4798. out_free_mem:
  4799. lpfc_mem_free(phba);
  4800. return rc;
  4801. }
  4802. /**
  4803. * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
  4804. * @phba: pointer to lpfc hba data structure.
  4805. *
  4806. * This routine is invoked to unset the driver internal resources set up
  4807. * specific for supporting the SLI-4 HBA device it attached to.
  4808. **/
  4809. static void
  4810. lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
  4811. {
  4812. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  4813. /* Free memory allocated for msi-x interrupt vector to CPU mapping */
  4814. kfree(phba->sli4_hba.cpu_map);
  4815. phba->sli4_hba.num_present_cpu = 0;
  4816. phba->sli4_hba.num_online_cpu = 0;
  4817. /* Free memory allocated for msi-x interrupt vector entries */
  4818. kfree(phba->sli4_hba.msix_entries);
  4819. /* Free memory allocated for fast-path work queue handles */
  4820. kfree(phba->sli4_hba.fcp_eq_hdl);
  4821. /* Free the allocated rpi headers. */
  4822. lpfc_sli4_remove_rpi_hdrs(phba);
  4823. lpfc_sli4_remove_rpis(phba);
  4824. /* Free eligible FCF index bmask */
  4825. kfree(phba->fcf.fcf_rr_bmask);
  4826. /* Free the ELS sgl list */
  4827. lpfc_free_active_sgl(phba);
  4828. lpfc_free_els_sgl_list(phba);
  4829. /* Free the completion queue EQ event pool */
  4830. lpfc_sli4_cq_event_release_all(phba);
  4831. lpfc_sli4_cq_event_pool_destroy(phba);
  4832. /* Release resource identifiers. */
  4833. lpfc_sli4_dealloc_resource_identifiers(phba);
  4834. /* Free the bsmbx region. */
  4835. lpfc_destroy_bootstrap_mbox(phba);
  4836. /* Free the SLI Layer memory with SLI4 HBAs */
  4837. lpfc_mem_free_all(phba);
  4838. /* Free the current connect table */
  4839. list_for_each_entry_safe(conn_entry, next_conn_entry,
  4840. &phba->fcf_conn_rec_list, list) {
  4841. list_del_init(&conn_entry->list);
  4842. kfree(conn_entry);
  4843. }
  4844. return;
  4845. }
  4846. /**
  4847. * lpfc_init_api_table_setup - Set up init api function jump table
  4848. * @phba: The hba struct for which this call is being executed.
  4849. * @dev_grp: The HBA PCI-Device group number.
  4850. *
  4851. * This routine sets up the device INIT interface API function jump table
  4852. * in @phba struct.
  4853. *
  4854. * Returns: 0 - success, -ENODEV - failure.
  4855. **/
  4856. int
  4857. lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4858. {
  4859. phba->lpfc_hba_init_link = lpfc_hba_init_link;
  4860. phba->lpfc_hba_down_link = lpfc_hba_down_link;
  4861. phba->lpfc_selective_reset = lpfc_selective_reset;
  4862. switch (dev_grp) {
  4863. case LPFC_PCI_DEV_LP:
  4864. phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
  4865. phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
  4866. phba->lpfc_stop_port = lpfc_stop_port_s3;
  4867. break;
  4868. case LPFC_PCI_DEV_OC:
  4869. phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
  4870. phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
  4871. phba->lpfc_stop_port = lpfc_stop_port_s4;
  4872. break;
  4873. default:
  4874. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4875. "1431 Invalid HBA PCI-device group: 0x%x\n",
  4876. dev_grp);
  4877. return -ENODEV;
  4878. break;
  4879. }
  4880. return 0;
  4881. }
  4882. /**
  4883. * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
  4884. * @phba: pointer to lpfc hba data structure.
  4885. *
  4886. * This routine is invoked to set up the driver internal resources before the
  4887. * device specific resource setup to support the HBA device it attached to.
  4888. *
  4889. * Return codes
  4890. * 0 - successful
  4891. * other values - error
  4892. **/
  4893. static int
  4894. lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
  4895. {
  4896. /*
  4897. * Driver resources common to all SLI revisions
  4898. */
  4899. atomic_set(&phba->fast_event_count, 0);
  4900. spin_lock_init(&phba->hbalock);
  4901. /* Initialize ndlp management spinlock */
  4902. spin_lock_init(&phba->ndlp_lock);
  4903. INIT_LIST_HEAD(&phba->port_list);
  4904. INIT_LIST_HEAD(&phba->work_list);
  4905. init_waitqueue_head(&phba->wait_4_mlo_m_q);
  4906. /* Initialize the wait queue head for the kernel thread */
  4907. init_waitqueue_head(&phba->work_waitq);
  4908. /* Initialize the scsi buffer list used by driver for scsi IO */
  4909. spin_lock_init(&phba->scsi_buf_list_get_lock);
  4910. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
  4911. spin_lock_init(&phba->scsi_buf_list_put_lock);
  4912. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
  4913. /* Initialize the fabric iocb list */
  4914. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  4915. /* Initialize list to save ELS buffers */
  4916. INIT_LIST_HEAD(&phba->elsbuf);
  4917. /* Initialize FCF connection rec list */
  4918. INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
  4919. return 0;
  4920. }
  4921. /**
  4922. * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
  4923. * @phba: pointer to lpfc hba data structure.
  4924. *
  4925. * This routine is invoked to set up the driver internal resources after the
  4926. * device specific resource setup to support the HBA device it attached to.
  4927. *
  4928. * Return codes
  4929. * 0 - successful
  4930. * other values - error
  4931. **/
  4932. static int
  4933. lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
  4934. {
  4935. int error;
  4936. /* Startup the kernel thread for this host adapter. */
  4937. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  4938. "lpfc_worker_%d", phba->brd_no);
  4939. if (IS_ERR(phba->worker_thread)) {
  4940. error = PTR_ERR(phba->worker_thread);
  4941. return error;
  4942. }
  4943. return 0;
  4944. }
  4945. /**
  4946. * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
  4947. * @phba: pointer to lpfc hba data structure.
  4948. *
  4949. * This routine is invoked to unset the driver internal resources set up after
  4950. * the device specific resource setup for supporting the HBA device it
  4951. * attached to.
  4952. **/
  4953. static void
  4954. lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
  4955. {
  4956. /* Stop kernel worker thread */
  4957. kthread_stop(phba->worker_thread);
  4958. }
  4959. /**
  4960. * lpfc_free_iocb_list - Free iocb list.
  4961. * @phba: pointer to lpfc hba data structure.
  4962. *
  4963. * This routine is invoked to free the driver's IOCB list and memory.
  4964. **/
  4965. static void
  4966. lpfc_free_iocb_list(struct lpfc_hba *phba)
  4967. {
  4968. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  4969. spin_lock_irq(&phba->hbalock);
  4970. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  4971. &phba->lpfc_iocb_list, list) {
  4972. list_del(&iocbq_entry->list);
  4973. kfree(iocbq_entry);
  4974. phba->total_iocbq_bufs--;
  4975. }
  4976. spin_unlock_irq(&phba->hbalock);
  4977. return;
  4978. }
  4979. /**
  4980. * lpfc_init_iocb_list - Allocate and initialize iocb list.
  4981. * @phba: pointer to lpfc hba data structure.
  4982. *
  4983. * This routine is invoked to allocate and initizlize the driver's IOCB
  4984. * list and set up the IOCB tag array accordingly.
  4985. *
  4986. * Return codes
  4987. * 0 - successful
  4988. * other values - error
  4989. **/
  4990. static int
  4991. lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
  4992. {
  4993. struct lpfc_iocbq *iocbq_entry = NULL;
  4994. uint16_t iotag;
  4995. int i;
  4996. /* Initialize and populate the iocb list per host. */
  4997. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  4998. for (i = 0; i < iocb_count; i++) {
  4999. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  5000. if (iocbq_entry == NULL) {
  5001. printk(KERN_ERR "%s: only allocated %d iocbs of "
  5002. "expected %d count. Unloading driver.\n",
  5003. __func__, i, LPFC_IOCB_LIST_CNT);
  5004. goto out_free_iocbq;
  5005. }
  5006. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  5007. if (iotag == 0) {
  5008. kfree(iocbq_entry);
  5009. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  5010. "Unloading driver.\n", __func__);
  5011. goto out_free_iocbq;
  5012. }
  5013. iocbq_entry->sli4_lxritag = NO_XRI;
  5014. iocbq_entry->sli4_xritag = NO_XRI;
  5015. spin_lock_irq(&phba->hbalock);
  5016. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  5017. phba->total_iocbq_bufs++;
  5018. spin_unlock_irq(&phba->hbalock);
  5019. }
  5020. return 0;
  5021. out_free_iocbq:
  5022. lpfc_free_iocb_list(phba);
  5023. return -ENOMEM;
  5024. }
  5025. /**
  5026. * lpfc_free_sgl_list - Free a given sgl list.
  5027. * @phba: pointer to lpfc hba data structure.
  5028. * @sglq_list: pointer to the head of sgl list.
  5029. *
  5030. * This routine is invoked to free a give sgl list and memory.
  5031. **/
  5032. void
  5033. lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
  5034. {
  5035. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  5036. list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
  5037. list_del(&sglq_entry->list);
  5038. lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
  5039. kfree(sglq_entry);
  5040. }
  5041. }
  5042. /**
  5043. * lpfc_free_els_sgl_list - Free els sgl list.
  5044. * @phba: pointer to lpfc hba data structure.
  5045. *
  5046. * This routine is invoked to free the driver's els sgl list and memory.
  5047. **/
  5048. static void
  5049. lpfc_free_els_sgl_list(struct lpfc_hba *phba)
  5050. {
  5051. LIST_HEAD(sglq_list);
  5052. /* Retrieve all els sgls from driver list */
  5053. spin_lock_irq(&phba->hbalock);
  5054. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
  5055. spin_unlock_irq(&phba->hbalock);
  5056. /* Now free the sgl list */
  5057. lpfc_free_sgl_list(phba, &sglq_list);
  5058. }
  5059. /**
  5060. * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
  5061. * @phba: pointer to lpfc hba data structure.
  5062. *
  5063. * This routine is invoked to allocate the driver's active sgl memory.
  5064. * This array will hold the sglq_entry's for active IOs.
  5065. **/
  5066. static int
  5067. lpfc_init_active_sgl_array(struct lpfc_hba *phba)
  5068. {
  5069. int size;
  5070. size = sizeof(struct lpfc_sglq *);
  5071. size *= phba->sli4_hba.max_cfg_param.max_xri;
  5072. phba->sli4_hba.lpfc_sglq_active_list =
  5073. kzalloc(size, GFP_KERNEL);
  5074. if (!phba->sli4_hba.lpfc_sglq_active_list)
  5075. return -ENOMEM;
  5076. return 0;
  5077. }
  5078. /**
  5079. * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
  5080. * @phba: pointer to lpfc hba data structure.
  5081. *
  5082. * This routine is invoked to walk through the array of active sglq entries
  5083. * and free all of the resources.
  5084. * This is just a place holder for now.
  5085. **/
  5086. static void
  5087. lpfc_free_active_sgl(struct lpfc_hba *phba)
  5088. {
  5089. kfree(phba->sli4_hba.lpfc_sglq_active_list);
  5090. }
  5091. /**
  5092. * lpfc_init_sgl_list - Allocate and initialize sgl list.
  5093. * @phba: pointer to lpfc hba data structure.
  5094. *
  5095. * This routine is invoked to allocate and initizlize the driver's sgl
  5096. * list and set up the sgl xritag tag array accordingly.
  5097. *
  5098. **/
  5099. static void
  5100. lpfc_init_sgl_list(struct lpfc_hba *phba)
  5101. {
  5102. /* Initialize and populate the sglq list per host/VF. */
  5103. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
  5104. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  5105. /* els xri-sgl book keeping */
  5106. phba->sli4_hba.els_xri_cnt = 0;
  5107. /* scsi xri-buffer book keeping */
  5108. phba->sli4_hba.scsi_xri_cnt = 0;
  5109. }
  5110. /**
  5111. * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
  5112. * @phba: pointer to lpfc hba data structure.
  5113. *
  5114. * This routine is invoked to post rpi header templates to the
  5115. * port for those SLI4 ports that do not support extents. This routine
  5116. * posts a PAGE_SIZE memory region to the port to hold up to
  5117. * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
  5118. * and should be called only when interrupts are disabled.
  5119. *
  5120. * Return codes
  5121. * 0 - successful
  5122. * -ERROR - otherwise.
  5123. **/
  5124. int
  5125. lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
  5126. {
  5127. int rc = 0;
  5128. struct lpfc_rpi_hdr *rpi_hdr;
  5129. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
  5130. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5131. return rc;
  5132. if (phba->sli4_hba.extents_in_use)
  5133. return -EIO;
  5134. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  5135. if (!rpi_hdr) {
  5136. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5137. "0391 Error during rpi post operation\n");
  5138. lpfc_sli4_remove_rpis(phba);
  5139. rc = -ENODEV;
  5140. }
  5141. return rc;
  5142. }
  5143. /**
  5144. * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
  5145. * @phba: pointer to lpfc hba data structure.
  5146. *
  5147. * This routine is invoked to allocate a single 4KB memory region to
  5148. * support rpis and stores them in the phba. This single region
  5149. * provides support for up to 64 rpis. The region is used globally
  5150. * by the device.
  5151. *
  5152. * Returns:
  5153. * A valid rpi hdr on success.
  5154. * A NULL pointer on any failure.
  5155. **/
  5156. struct lpfc_rpi_hdr *
  5157. lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
  5158. {
  5159. uint16_t rpi_limit, curr_rpi_range;
  5160. struct lpfc_dmabuf *dmabuf;
  5161. struct lpfc_rpi_hdr *rpi_hdr;
  5162. uint32_t rpi_count;
  5163. /*
  5164. * If the SLI4 port supports extents, posting the rpi header isn't
  5165. * required. Set the expected maximum count and let the actual value
  5166. * get set when extents are fully allocated.
  5167. */
  5168. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5169. return NULL;
  5170. if (phba->sli4_hba.extents_in_use)
  5171. return NULL;
  5172. /* The limit on the logical index is just the max_rpi count. */
  5173. rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
  5174. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  5175. spin_lock_irq(&phba->hbalock);
  5176. /*
  5177. * Establish the starting RPI in this header block. The starting
  5178. * rpi is normalized to a zero base because the physical rpi is
  5179. * port based.
  5180. */
  5181. curr_rpi_range = phba->sli4_hba.next_rpi;
  5182. spin_unlock_irq(&phba->hbalock);
  5183. /*
  5184. * The port has a limited number of rpis. The increment here
  5185. * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
  5186. * and to allow the full max_rpi range per port.
  5187. */
  5188. if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
  5189. rpi_count = rpi_limit - curr_rpi_range;
  5190. else
  5191. rpi_count = LPFC_RPI_HDR_COUNT;
  5192. if (!rpi_count)
  5193. return NULL;
  5194. /*
  5195. * First allocate the protocol header region for the port. The
  5196. * port expects a 4KB DMA-mapped memory region that is 4K aligned.
  5197. */
  5198. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  5199. if (!dmabuf)
  5200. return NULL;
  5201. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  5202. LPFC_HDR_TEMPLATE_SIZE,
  5203. &dmabuf->phys,
  5204. GFP_KERNEL);
  5205. if (!dmabuf->virt) {
  5206. rpi_hdr = NULL;
  5207. goto err_free_dmabuf;
  5208. }
  5209. memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
  5210. if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
  5211. rpi_hdr = NULL;
  5212. goto err_free_coherent;
  5213. }
  5214. /* Save the rpi header data for cleanup later. */
  5215. rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
  5216. if (!rpi_hdr)
  5217. goto err_free_coherent;
  5218. rpi_hdr->dmabuf = dmabuf;
  5219. rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
  5220. rpi_hdr->page_count = 1;
  5221. spin_lock_irq(&phba->hbalock);
  5222. /* The rpi_hdr stores the logical index only. */
  5223. rpi_hdr->start_rpi = curr_rpi_range;
  5224. list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
  5225. /*
  5226. * The next_rpi stores the next logical module-64 rpi value used
  5227. * to post physical rpis in subsequent rpi postings.
  5228. */
  5229. phba->sli4_hba.next_rpi += rpi_count;
  5230. spin_unlock_irq(&phba->hbalock);
  5231. return rpi_hdr;
  5232. err_free_coherent:
  5233. dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
  5234. dmabuf->virt, dmabuf->phys);
  5235. err_free_dmabuf:
  5236. kfree(dmabuf);
  5237. return NULL;
  5238. }
  5239. /**
  5240. * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
  5241. * @phba: pointer to lpfc hba data structure.
  5242. *
  5243. * This routine is invoked to remove all memory resources allocated
  5244. * to support rpis for SLI4 ports not supporting extents. This routine
  5245. * presumes the caller has released all rpis consumed by fabric or port
  5246. * logins and is prepared to have the header pages removed.
  5247. **/
  5248. void
  5249. lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
  5250. {
  5251. struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
  5252. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5253. goto exit;
  5254. list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
  5255. &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  5256. list_del(&rpi_hdr->list);
  5257. dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
  5258. rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
  5259. kfree(rpi_hdr->dmabuf);
  5260. kfree(rpi_hdr);
  5261. }
  5262. exit:
  5263. /* There are no rpis available to the port now. */
  5264. phba->sli4_hba.next_rpi = 0;
  5265. }
  5266. /**
  5267. * lpfc_hba_alloc - Allocate driver hba data structure for a device.
  5268. * @pdev: pointer to pci device data structure.
  5269. *
  5270. * This routine is invoked to allocate the driver hba data structure for an
  5271. * HBA device. If the allocation is successful, the phba reference to the
  5272. * PCI device data structure is set.
  5273. *
  5274. * Return codes
  5275. * pointer to @phba - successful
  5276. * NULL - error
  5277. **/
  5278. static struct lpfc_hba *
  5279. lpfc_hba_alloc(struct pci_dev *pdev)
  5280. {
  5281. struct lpfc_hba *phba;
  5282. /* Allocate memory for HBA structure */
  5283. phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
  5284. if (!phba) {
  5285. dev_err(&pdev->dev, "failed to allocate hba struct\n");
  5286. return NULL;
  5287. }
  5288. /* Set reference to PCI device in HBA structure */
  5289. phba->pcidev = pdev;
  5290. /* Assign an unused board number */
  5291. phba->brd_no = lpfc_get_instance();
  5292. if (phba->brd_no < 0) {
  5293. kfree(phba);
  5294. return NULL;
  5295. }
  5296. spin_lock_init(&phba->ct_ev_lock);
  5297. INIT_LIST_HEAD(&phba->ct_ev_waiters);
  5298. return phba;
  5299. }
  5300. /**
  5301. * lpfc_hba_free - Free driver hba data structure with a device.
  5302. * @phba: pointer to lpfc hba data structure.
  5303. *
  5304. * This routine is invoked to free the driver hba data structure with an
  5305. * HBA device.
  5306. **/
  5307. static void
  5308. lpfc_hba_free(struct lpfc_hba *phba)
  5309. {
  5310. /* Release the driver assigned board number */
  5311. idr_remove(&lpfc_hba_index, phba->brd_no);
  5312. /* Free memory allocated with sli rings */
  5313. kfree(phba->sli.ring);
  5314. phba->sli.ring = NULL;
  5315. kfree(phba);
  5316. return;
  5317. }
  5318. /**
  5319. * lpfc_create_shost - Create hba physical port with associated scsi host.
  5320. * @phba: pointer to lpfc hba data structure.
  5321. *
  5322. * This routine is invoked to create HBA physical port and associate a SCSI
  5323. * host with it.
  5324. *
  5325. * Return codes
  5326. * 0 - successful
  5327. * other values - error
  5328. **/
  5329. static int
  5330. lpfc_create_shost(struct lpfc_hba *phba)
  5331. {
  5332. struct lpfc_vport *vport;
  5333. struct Scsi_Host *shost;
  5334. /* Initialize HBA FC structure */
  5335. phba->fc_edtov = FF_DEF_EDTOV;
  5336. phba->fc_ratov = FF_DEF_RATOV;
  5337. phba->fc_altov = FF_DEF_ALTOV;
  5338. phba->fc_arbtov = FF_DEF_ARBTOV;
  5339. atomic_set(&phba->sdev_cnt, 0);
  5340. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  5341. if (!vport)
  5342. return -ENODEV;
  5343. shost = lpfc_shost_from_vport(vport);
  5344. phba->pport = vport;
  5345. lpfc_debugfs_initialize(vport);
  5346. /* Put reference to SCSI host to driver's device private data */
  5347. pci_set_drvdata(phba->pcidev, shost);
  5348. return 0;
  5349. }
  5350. /**
  5351. * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
  5352. * @phba: pointer to lpfc hba data structure.
  5353. *
  5354. * This routine is invoked to destroy HBA physical port and the associated
  5355. * SCSI host.
  5356. **/
  5357. static void
  5358. lpfc_destroy_shost(struct lpfc_hba *phba)
  5359. {
  5360. struct lpfc_vport *vport = phba->pport;
  5361. /* Destroy physical port that associated with the SCSI host */
  5362. destroy_port(vport);
  5363. return;
  5364. }
  5365. /**
  5366. * lpfc_setup_bg - Setup Block guard structures and debug areas.
  5367. * @phba: pointer to lpfc hba data structure.
  5368. * @shost: the shost to be used to detect Block guard settings.
  5369. *
  5370. * This routine sets up the local Block guard protocol settings for @shost.
  5371. * This routine also allocates memory for debugging bg buffers.
  5372. **/
  5373. static void
  5374. lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
  5375. {
  5376. uint32_t old_mask;
  5377. uint32_t old_guard;
  5378. int pagecnt = 10;
  5379. if (lpfc_prot_mask && lpfc_prot_guard) {
  5380. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5381. "1478 Registering BlockGuard with the "
  5382. "SCSI layer\n");
  5383. old_mask = lpfc_prot_mask;
  5384. old_guard = lpfc_prot_guard;
  5385. /* Only allow supported values */
  5386. lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
  5387. SHOST_DIX_TYPE0_PROTECTION |
  5388. SHOST_DIX_TYPE1_PROTECTION);
  5389. lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
  5390. /* DIF Type 1 protection for profiles AST1/C1 is end to end */
  5391. if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
  5392. lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
  5393. if (lpfc_prot_mask && lpfc_prot_guard) {
  5394. if ((old_mask != lpfc_prot_mask) ||
  5395. (old_guard != lpfc_prot_guard))
  5396. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5397. "1475 Registering BlockGuard with the "
  5398. "SCSI layer: mask %d guard %d\n",
  5399. lpfc_prot_mask, lpfc_prot_guard);
  5400. scsi_host_set_prot(shost, lpfc_prot_mask);
  5401. scsi_host_set_guard(shost, lpfc_prot_guard);
  5402. } else
  5403. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5404. "1479 Not Registering BlockGuard with the SCSI "
  5405. "layer, Bad protection parameters: %d %d\n",
  5406. old_mask, old_guard);
  5407. }
  5408. if (!_dump_buf_data) {
  5409. while (pagecnt) {
  5410. spin_lock_init(&_dump_buf_lock);
  5411. _dump_buf_data =
  5412. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  5413. if (_dump_buf_data) {
  5414. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5415. "9043 BLKGRD: allocated %d pages for "
  5416. "_dump_buf_data at 0x%p\n",
  5417. (1 << pagecnt), _dump_buf_data);
  5418. _dump_buf_data_order = pagecnt;
  5419. memset(_dump_buf_data, 0,
  5420. ((1 << PAGE_SHIFT) << pagecnt));
  5421. break;
  5422. } else
  5423. --pagecnt;
  5424. }
  5425. if (!_dump_buf_data_order)
  5426. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5427. "9044 BLKGRD: ERROR unable to allocate "
  5428. "memory for hexdump\n");
  5429. } else
  5430. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5431. "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
  5432. "\n", _dump_buf_data);
  5433. if (!_dump_buf_dif) {
  5434. while (pagecnt) {
  5435. _dump_buf_dif =
  5436. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  5437. if (_dump_buf_dif) {
  5438. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5439. "9046 BLKGRD: allocated %d pages for "
  5440. "_dump_buf_dif at 0x%p\n",
  5441. (1 << pagecnt), _dump_buf_dif);
  5442. _dump_buf_dif_order = pagecnt;
  5443. memset(_dump_buf_dif, 0,
  5444. ((1 << PAGE_SHIFT) << pagecnt));
  5445. break;
  5446. } else
  5447. --pagecnt;
  5448. }
  5449. if (!_dump_buf_dif_order)
  5450. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5451. "9047 BLKGRD: ERROR unable to allocate "
  5452. "memory for hexdump\n");
  5453. } else
  5454. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  5455. "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
  5456. _dump_buf_dif);
  5457. }
  5458. /**
  5459. * lpfc_post_init_setup - Perform necessary device post initialization setup.
  5460. * @phba: pointer to lpfc hba data structure.
  5461. *
  5462. * This routine is invoked to perform all the necessary post initialization
  5463. * setup for the device.
  5464. **/
  5465. static void
  5466. lpfc_post_init_setup(struct lpfc_hba *phba)
  5467. {
  5468. struct Scsi_Host *shost;
  5469. struct lpfc_adapter_event_header adapter_event;
  5470. /* Get the default values for Model Name and Description */
  5471. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  5472. /*
  5473. * hba setup may have changed the hba_queue_depth so we need to
  5474. * adjust the value of can_queue.
  5475. */
  5476. shost = pci_get_drvdata(phba->pcidev);
  5477. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  5478. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
  5479. lpfc_setup_bg(phba, shost);
  5480. lpfc_host_attrib_init(shost);
  5481. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  5482. spin_lock_irq(shost->host_lock);
  5483. lpfc_poll_start_timer(phba);
  5484. spin_unlock_irq(shost->host_lock);
  5485. }
  5486. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5487. "0428 Perform SCSI scan\n");
  5488. /* Send board arrival event to upper layer */
  5489. adapter_event.event_type = FC_REG_ADAPTER_EVENT;
  5490. adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
  5491. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5492. sizeof(adapter_event),
  5493. (char *) &adapter_event,
  5494. LPFC_NL_VENDOR_ID);
  5495. return;
  5496. }
  5497. /**
  5498. * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
  5499. * @phba: pointer to lpfc hba data structure.
  5500. *
  5501. * This routine is invoked to set up the PCI device memory space for device
  5502. * with SLI-3 interface spec.
  5503. *
  5504. * Return codes
  5505. * 0 - successful
  5506. * other values - error
  5507. **/
  5508. static int
  5509. lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
  5510. {
  5511. struct pci_dev *pdev;
  5512. unsigned long bar0map_len, bar2map_len;
  5513. int i, hbq_count;
  5514. void *ptr;
  5515. int error = -ENODEV;
  5516. /* Obtain PCI device reference */
  5517. if (!phba->pcidev)
  5518. return error;
  5519. else
  5520. pdev = phba->pcidev;
  5521. /* Set the device DMA mask size */
  5522. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  5523. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  5524. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  5525. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  5526. return error;
  5527. }
  5528. }
  5529. /* Get the bus address of Bar0 and Bar2 and the number of bytes
  5530. * required by each mapping.
  5531. */
  5532. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  5533. bar0map_len = pci_resource_len(pdev, 0);
  5534. phba->pci_bar2_map = pci_resource_start(pdev, 2);
  5535. bar2map_len = pci_resource_len(pdev, 2);
  5536. /* Map HBA SLIM to a kernel virtual address. */
  5537. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  5538. if (!phba->slim_memmap_p) {
  5539. dev_printk(KERN_ERR, &pdev->dev,
  5540. "ioremap failed for SLIM memory.\n");
  5541. goto out;
  5542. }
  5543. /* Map HBA Control Registers to a kernel virtual address. */
  5544. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  5545. if (!phba->ctrl_regs_memmap_p) {
  5546. dev_printk(KERN_ERR, &pdev->dev,
  5547. "ioremap failed for HBA control registers.\n");
  5548. goto out_iounmap_slim;
  5549. }
  5550. /* Allocate memory for SLI-2 structures */
  5551. phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
  5552. SLI2_SLIM_SIZE,
  5553. &phba->slim2p.phys,
  5554. GFP_KERNEL);
  5555. if (!phba->slim2p.virt)
  5556. goto out_iounmap;
  5557. memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
  5558. phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
  5559. phba->mbox_ext = (phba->slim2p.virt +
  5560. offsetof(struct lpfc_sli2_slim, mbx_ext_words));
  5561. phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
  5562. phba->IOCBs = (phba->slim2p.virt +
  5563. offsetof(struct lpfc_sli2_slim, IOCBs));
  5564. phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
  5565. lpfc_sli_hbq_size(),
  5566. &phba->hbqslimp.phys,
  5567. GFP_KERNEL);
  5568. if (!phba->hbqslimp.virt)
  5569. goto out_free_slim;
  5570. hbq_count = lpfc_sli_hbq_count();
  5571. ptr = phba->hbqslimp.virt;
  5572. for (i = 0; i < hbq_count; ++i) {
  5573. phba->hbqs[i].hbq_virt = ptr;
  5574. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  5575. ptr += (lpfc_hbq_defs[i]->entry_count *
  5576. sizeof(struct lpfc_hbq_entry));
  5577. }
  5578. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  5579. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  5580. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  5581. INIT_LIST_HEAD(&phba->rb_pend_list);
  5582. phba->MBslimaddr = phba->slim_memmap_p;
  5583. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  5584. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  5585. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  5586. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  5587. return 0;
  5588. out_free_slim:
  5589. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  5590. phba->slim2p.virt, phba->slim2p.phys);
  5591. out_iounmap:
  5592. iounmap(phba->ctrl_regs_memmap_p);
  5593. out_iounmap_slim:
  5594. iounmap(phba->slim_memmap_p);
  5595. out:
  5596. return error;
  5597. }
  5598. /**
  5599. * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
  5600. * @phba: pointer to lpfc hba data structure.
  5601. *
  5602. * This routine is invoked to unset the PCI device memory space for device
  5603. * with SLI-3 interface spec.
  5604. **/
  5605. static void
  5606. lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
  5607. {
  5608. struct pci_dev *pdev;
  5609. /* Obtain PCI device reference */
  5610. if (!phba->pcidev)
  5611. return;
  5612. else
  5613. pdev = phba->pcidev;
  5614. /* Free coherent DMA memory allocated */
  5615. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  5616. phba->hbqslimp.virt, phba->hbqslimp.phys);
  5617. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  5618. phba->slim2p.virt, phba->slim2p.phys);
  5619. /* I/O memory unmap */
  5620. iounmap(phba->ctrl_regs_memmap_p);
  5621. iounmap(phba->slim_memmap_p);
  5622. return;
  5623. }
  5624. /**
  5625. * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
  5626. * @phba: pointer to lpfc hba data structure.
  5627. *
  5628. * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
  5629. * done and check status.
  5630. *
  5631. * Return 0 if successful, otherwise -ENODEV.
  5632. **/
  5633. int
  5634. lpfc_sli4_post_status_check(struct lpfc_hba *phba)
  5635. {
  5636. struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
  5637. struct lpfc_register reg_data;
  5638. int i, port_error = 0;
  5639. uint32_t if_type;
  5640. memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
  5641. memset(&reg_data, 0, sizeof(reg_data));
  5642. if (!phba->sli4_hba.PSMPHRregaddr)
  5643. return -ENODEV;
  5644. /* Wait up to 30 seconds for the SLI Port POST done and ready */
  5645. for (i = 0; i < 3000; i++) {
  5646. if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  5647. &portsmphr_reg.word0) ||
  5648. (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
  5649. /* Port has a fatal POST error, break out */
  5650. port_error = -ENODEV;
  5651. break;
  5652. }
  5653. if (LPFC_POST_STAGE_PORT_READY ==
  5654. bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
  5655. break;
  5656. msleep(10);
  5657. }
  5658. /*
  5659. * If there was a port error during POST, then don't proceed with
  5660. * other register reads as the data may not be valid. Just exit.
  5661. */
  5662. if (port_error) {
  5663. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5664. "1408 Port Failed POST - portsmphr=0x%x, "
  5665. "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
  5666. "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
  5667. portsmphr_reg.word0,
  5668. bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
  5669. bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
  5670. bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
  5671. bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
  5672. bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
  5673. bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
  5674. bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
  5675. bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
  5676. } else {
  5677. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5678. "2534 Device Info: SLIFamily=0x%x, "
  5679. "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
  5680. "SLIHint_2=0x%x, FT=0x%x\n",
  5681. bf_get(lpfc_sli_intf_sli_family,
  5682. &phba->sli4_hba.sli_intf),
  5683. bf_get(lpfc_sli_intf_slirev,
  5684. &phba->sli4_hba.sli_intf),
  5685. bf_get(lpfc_sli_intf_if_type,
  5686. &phba->sli4_hba.sli_intf),
  5687. bf_get(lpfc_sli_intf_sli_hint1,
  5688. &phba->sli4_hba.sli_intf),
  5689. bf_get(lpfc_sli_intf_sli_hint2,
  5690. &phba->sli4_hba.sli_intf),
  5691. bf_get(lpfc_sli_intf_func_type,
  5692. &phba->sli4_hba.sli_intf));
  5693. /*
  5694. * Check for other Port errors during the initialization
  5695. * process. Fail the load if the port did not come up
  5696. * correctly.
  5697. */
  5698. if_type = bf_get(lpfc_sli_intf_if_type,
  5699. &phba->sli4_hba.sli_intf);
  5700. switch (if_type) {
  5701. case LPFC_SLI_INTF_IF_TYPE_0:
  5702. phba->sli4_hba.ue_mask_lo =
  5703. readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
  5704. phba->sli4_hba.ue_mask_hi =
  5705. readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
  5706. uerrlo_reg.word0 =
  5707. readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
  5708. uerrhi_reg.word0 =
  5709. readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
  5710. if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
  5711. (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
  5712. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5713. "1422 Unrecoverable Error "
  5714. "Detected during POST "
  5715. "uerr_lo_reg=0x%x, "
  5716. "uerr_hi_reg=0x%x, "
  5717. "ue_mask_lo_reg=0x%x, "
  5718. "ue_mask_hi_reg=0x%x\n",
  5719. uerrlo_reg.word0,
  5720. uerrhi_reg.word0,
  5721. phba->sli4_hba.ue_mask_lo,
  5722. phba->sli4_hba.ue_mask_hi);
  5723. port_error = -ENODEV;
  5724. }
  5725. break;
  5726. case LPFC_SLI_INTF_IF_TYPE_2:
  5727. /* Final checks. The port status should be clean. */
  5728. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  5729. &reg_data.word0) ||
  5730. (bf_get(lpfc_sliport_status_err, &reg_data) &&
  5731. !bf_get(lpfc_sliport_status_rn, &reg_data))) {
  5732. phba->work_status[0] =
  5733. readl(phba->sli4_hba.u.if_type2.
  5734. ERR1regaddr);
  5735. phba->work_status[1] =
  5736. readl(phba->sli4_hba.u.if_type2.
  5737. ERR2regaddr);
  5738. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5739. "2888 Unrecoverable port error "
  5740. "following POST: port status reg "
  5741. "0x%x, port_smphr reg 0x%x, "
  5742. "error 1=0x%x, error 2=0x%x\n",
  5743. reg_data.word0,
  5744. portsmphr_reg.word0,
  5745. phba->work_status[0],
  5746. phba->work_status[1]);
  5747. port_error = -ENODEV;
  5748. }
  5749. break;
  5750. case LPFC_SLI_INTF_IF_TYPE_1:
  5751. default:
  5752. break;
  5753. }
  5754. }
  5755. return port_error;
  5756. }
  5757. /**
  5758. * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
  5759. * @phba: pointer to lpfc hba data structure.
  5760. * @if_type: The SLI4 interface type getting configured.
  5761. *
  5762. * This routine is invoked to set up SLI4 BAR0 PCI config space register
  5763. * memory map.
  5764. **/
  5765. static void
  5766. lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
  5767. {
  5768. switch (if_type) {
  5769. case LPFC_SLI_INTF_IF_TYPE_0:
  5770. phba->sli4_hba.u.if_type0.UERRLOregaddr =
  5771. phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
  5772. phba->sli4_hba.u.if_type0.UERRHIregaddr =
  5773. phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
  5774. phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
  5775. phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
  5776. phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
  5777. phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
  5778. phba->sli4_hba.SLIINTFregaddr =
  5779. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
  5780. break;
  5781. case LPFC_SLI_INTF_IF_TYPE_2:
  5782. phba->sli4_hba.u.if_type2.ERR1regaddr =
  5783. phba->sli4_hba.conf_regs_memmap_p +
  5784. LPFC_CTL_PORT_ER1_OFFSET;
  5785. phba->sli4_hba.u.if_type2.ERR2regaddr =
  5786. phba->sli4_hba.conf_regs_memmap_p +
  5787. LPFC_CTL_PORT_ER2_OFFSET;
  5788. phba->sli4_hba.u.if_type2.CTRLregaddr =
  5789. phba->sli4_hba.conf_regs_memmap_p +
  5790. LPFC_CTL_PORT_CTL_OFFSET;
  5791. phba->sli4_hba.u.if_type2.STATUSregaddr =
  5792. phba->sli4_hba.conf_regs_memmap_p +
  5793. LPFC_CTL_PORT_STA_OFFSET;
  5794. phba->sli4_hba.SLIINTFregaddr =
  5795. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
  5796. phba->sli4_hba.PSMPHRregaddr =
  5797. phba->sli4_hba.conf_regs_memmap_p +
  5798. LPFC_CTL_PORT_SEM_OFFSET;
  5799. phba->sli4_hba.RQDBregaddr =
  5800. phba->sli4_hba.conf_regs_memmap_p +
  5801. LPFC_ULP0_RQ_DOORBELL;
  5802. phba->sli4_hba.WQDBregaddr =
  5803. phba->sli4_hba.conf_regs_memmap_p +
  5804. LPFC_ULP0_WQ_DOORBELL;
  5805. phba->sli4_hba.EQCQDBregaddr =
  5806. phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
  5807. phba->sli4_hba.MQDBregaddr =
  5808. phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
  5809. phba->sli4_hba.BMBXregaddr =
  5810. phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
  5811. break;
  5812. case LPFC_SLI_INTF_IF_TYPE_1:
  5813. default:
  5814. dev_printk(KERN_ERR, &phba->pcidev->dev,
  5815. "FATAL - unsupported SLI4 interface type - %d\n",
  5816. if_type);
  5817. break;
  5818. }
  5819. }
  5820. /**
  5821. * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
  5822. * @phba: pointer to lpfc hba data structure.
  5823. *
  5824. * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
  5825. * memory map.
  5826. **/
  5827. static void
  5828. lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
  5829. {
  5830. phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5831. LPFC_SLIPORT_IF0_SMPHR;
  5832. phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5833. LPFC_HST_ISR0;
  5834. phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5835. LPFC_HST_IMR0;
  5836. phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5837. LPFC_HST_ISCR0;
  5838. }
  5839. /**
  5840. * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
  5841. * @phba: pointer to lpfc hba data structure.
  5842. * @vf: virtual function number
  5843. *
  5844. * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
  5845. * based on the given viftual function number, @vf.
  5846. *
  5847. * Return 0 if successful, otherwise -ENODEV.
  5848. **/
  5849. static int
  5850. lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
  5851. {
  5852. if (vf > LPFC_VIR_FUNC_MAX)
  5853. return -ENODEV;
  5854. phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5855. vf * LPFC_VFR_PAGE_SIZE +
  5856. LPFC_ULP0_RQ_DOORBELL);
  5857. phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5858. vf * LPFC_VFR_PAGE_SIZE +
  5859. LPFC_ULP0_WQ_DOORBELL);
  5860. phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5861. vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
  5862. phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5863. vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
  5864. phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5865. vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
  5866. return 0;
  5867. }
  5868. /**
  5869. * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
  5870. * @phba: pointer to lpfc hba data structure.
  5871. *
  5872. * This routine is invoked to create the bootstrap mailbox
  5873. * region consistent with the SLI-4 interface spec. This
  5874. * routine allocates all memory necessary to communicate
  5875. * mailbox commands to the port and sets up all alignment
  5876. * needs. No locks are expected to be held when calling
  5877. * this routine.
  5878. *
  5879. * Return codes
  5880. * 0 - successful
  5881. * -ENOMEM - could not allocated memory.
  5882. **/
  5883. static int
  5884. lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
  5885. {
  5886. uint32_t bmbx_size;
  5887. struct lpfc_dmabuf *dmabuf;
  5888. struct dma_address *dma_address;
  5889. uint32_t pa_addr;
  5890. uint64_t phys_addr;
  5891. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  5892. if (!dmabuf)
  5893. return -ENOMEM;
  5894. /*
  5895. * The bootstrap mailbox region is comprised of 2 parts
  5896. * plus an alignment restriction of 16 bytes.
  5897. */
  5898. bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
  5899. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  5900. bmbx_size,
  5901. &dmabuf->phys,
  5902. GFP_KERNEL);
  5903. if (!dmabuf->virt) {
  5904. kfree(dmabuf);
  5905. return -ENOMEM;
  5906. }
  5907. memset(dmabuf->virt, 0, bmbx_size);
  5908. /*
  5909. * Initialize the bootstrap mailbox pointers now so that the register
  5910. * operations are simple later. The mailbox dma address is required
  5911. * to be 16-byte aligned. Also align the virtual memory as each
  5912. * maibox is copied into the bmbx mailbox region before issuing the
  5913. * command to the port.
  5914. */
  5915. phba->sli4_hba.bmbx.dmabuf = dmabuf;
  5916. phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
  5917. phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
  5918. LPFC_ALIGN_16_BYTE);
  5919. phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
  5920. LPFC_ALIGN_16_BYTE);
  5921. /*
  5922. * Set the high and low physical addresses now. The SLI4 alignment
  5923. * requirement is 16 bytes and the mailbox is posted to the port
  5924. * as two 30-bit addresses. The other data is a bit marking whether
  5925. * the 30-bit address is the high or low address.
  5926. * Upcast bmbx aphys to 64bits so shift instruction compiles
  5927. * clean on 32 bit machines.
  5928. */
  5929. dma_address = &phba->sli4_hba.bmbx.dma_address;
  5930. phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
  5931. pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
  5932. dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
  5933. LPFC_BMBX_BIT1_ADDR_HI);
  5934. pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
  5935. dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
  5936. LPFC_BMBX_BIT1_ADDR_LO);
  5937. return 0;
  5938. }
  5939. /**
  5940. * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
  5941. * @phba: pointer to lpfc hba data structure.
  5942. *
  5943. * This routine is invoked to teardown the bootstrap mailbox
  5944. * region and release all host resources. This routine requires
  5945. * the caller to ensure all mailbox commands recovered, no
  5946. * additional mailbox comands are sent, and interrupts are disabled
  5947. * before calling this routine.
  5948. *
  5949. **/
  5950. static void
  5951. lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
  5952. {
  5953. dma_free_coherent(&phba->pcidev->dev,
  5954. phba->sli4_hba.bmbx.bmbx_size,
  5955. phba->sli4_hba.bmbx.dmabuf->virt,
  5956. phba->sli4_hba.bmbx.dmabuf->phys);
  5957. kfree(phba->sli4_hba.bmbx.dmabuf);
  5958. memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
  5959. }
  5960. /**
  5961. * lpfc_sli4_read_config - Get the config parameters.
  5962. * @phba: pointer to lpfc hba data structure.
  5963. *
  5964. * This routine is invoked to read the configuration parameters from the HBA.
  5965. * The configuration parameters are used to set the base and maximum values
  5966. * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
  5967. * allocation for the port.
  5968. *
  5969. * Return codes
  5970. * 0 - successful
  5971. * -ENOMEM - No available memory
  5972. * -EIO - The mailbox failed to complete successfully.
  5973. **/
  5974. int
  5975. lpfc_sli4_read_config(struct lpfc_hba *phba)
  5976. {
  5977. LPFC_MBOXQ_t *pmb;
  5978. struct lpfc_mbx_read_config *rd_config;
  5979. union lpfc_sli4_cfg_shdr *shdr;
  5980. uint32_t shdr_status, shdr_add_status;
  5981. struct lpfc_mbx_get_func_cfg *get_func_cfg;
  5982. struct lpfc_rsrc_desc_fcfcoe *desc;
  5983. char *pdesc_0;
  5984. uint32_t desc_count;
  5985. int length, i, rc = 0, rc2;
  5986. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5987. if (!pmb) {
  5988. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5989. "2011 Unable to allocate memory for issuing "
  5990. "SLI_CONFIG_SPECIAL mailbox command\n");
  5991. return -ENOMEM;
  5992. }
  5993. lpfc_read_config(phba, pmb);
  5994. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  5995. if (rc != MBX_SUCCESS) {
  5996. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5997. "2012 Mailbox failed , mbxCmd x%x "
  5998. "READ_CONFIG, mbxStatus x%x\n",
  5999. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  6000. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  6001. rc = -EIO;
  6002. } else {
  6003. rd_config = &pmb->u.mqe.un.rd_config;
  6004. if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
  6005. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  6006. phba->sli4_hba.lnk_info.lnk_tp =
  6007. bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
  6008. phba->sli4_hba.lnk_info.lnk_no =
  6009. bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
  6010. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6011. "3081 lnk_type:%d, lnk_numb:%d\n",
  6012. phba->sli4_hba.lnk_info.lnk_tp,
  6013. phba->sli4_hba.lnk_info.lnk_no);
  6014. } else
  6015. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  6016. "3082 Mailbox (x%x) returned ldv:x0\n",
  6017. bf_get(lpfc_mqe_command, &pmb->u.mqe));
  6018. phba->sli4_hba.extents_in_use =
  6019. bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
  6020. phba->sli4_hba.max_cfg_param.max_xri =
  6021. bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
  6022. phba->sli4_hba.max_cfg_param.xri_base =
  6023. bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
  6024. phba->sli4_hba.max_cfg_param.max_vpi =
  6025. bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
  6026. phba->sli4_hba.max_cfg_param.vpi_base =
  6027. bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
  6028. phba->sli4_hba.max_cfg_param.max_rpi =
  6029. bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
  6030. phba->sli4_hba.max_cfg_param.rpi_base =
  6031. bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
  6032. phba->sli4_hba.max_cfg_param.max_vfi =
  6033. bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
  6034. phba->sli4_hba.max_cfg_param.vfi_base =
  6035. bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
  6036. phba->sli4_hba.max_cfg_param.max_fcfi =
  6037. bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
  6038. phba->sli4_hba.max_cfg_param.max_eq =
  6039. bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
  6040. phba->sli4_hba.max_cfg_param.max_rq =
  6041. bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
  6042. phba->sli4_hba.max_cfg_param.max_wq =
  6043. bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
  6044. phba->sli4_hba.max_cfg_param.max_cq =
  6045. bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
  6046. phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
  6047. phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
  6048. phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
  6049. phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
  6050. phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
  6051. (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
  6052. phba->max_vports = phba->max_vpi;
  6053. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6054. "2003 cfg params Extents? %d "
  6055. "XRI(B:%d M:%d), "
  6056. "VPI(B:%d M:%d) "
  6057. "VFI(B:%d M:%d) "
  6058. "RPI(B:%d M:%d) "
  6059. "FCFI(Count:%d)\n",
  6060. phba->sli4_hba.extents_in_use,
  6061. phba->sli4_hba.max_cfg_param.xri_base,
  6062. phba->sli4_hba.max_cfg_param.max_xri,
  6063. phba->sli4_hba.max_cfg_param.vpi_base,
  6064. phba->sli4_hba.max_cfg_param.max_vpi,
  6065. phba->sli4_hba.max_cfg_param.vfi_base,
  6066. phba->sli4_hba.max_cfg_param.max_vfi,
  6067. phba->sli4_hba.max_cfg_param.rpi_base,
  6068. phba->sli4_hba.max_cfg_param.max_rpi,
  6069. phba->sli4_hba.max_cfg_param.max_fcfi);
  6070. }
  6071. if (rc)
  6072. goto read_cfg_out;
  6073. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  6074. length = phba->sli4_hba.max_cfg_param.max_xri -
  6075. lpfc_sli4_get_els_iocb_cnt(phba);
  6076. if (phba->cfg_hba_queue_depth > length) {
  6077. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6078. "3361 HBA queue depth changed from %d to %d\n",
  6079. phba->cfg_hba_queue_depth, length);
  6080. phba->cfg_hba_queue_depth = length;
  6081. }
  6082. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  6083. LPFC_SLI_INTF_IF_TYPE_2)
  6084. goto read_cfg_out;
  6085. /* get the pf# and vf# for SLI4 if_type 2 port */
  6086. length = (sizeof(struct lpfc_mbx_get_func_cfg) -
  6087. sizeof(struct lpfc_sli4_cfg_mhdr));
  6088. lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
  6089. LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
  6090. length, LPFC_SLI4_MBX_EMBED);
  6091. rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  6092. shdr = (union lpfc_sli4_cfg_shdr *)
  6093. &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
  6094. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  6095. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  6096. if (rc2 || shdr_status || shdr_add_status) {
  6097. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6098. "3026 Mailbox failed , mbxCmd x%x "
  6099. "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
  6100. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  6101. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  6102. goto read_cfg_out;
  6103. }
  6104. /* search for fc_fcoe resrouce descriptor */
  6105. get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
  6106. desc_count = get_func_cfg->func_cfg.rsrc_desc_count;
  6107. pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
  6108. desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
  6109. length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
  6110. if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
  6111. length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
  6112. else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
  6113. goto read_cfg_out;
  6114. for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
  6115. desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
  6116. if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
  6117. bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
  6118. phba->sli4_hba.iov.pf_number =
  6119. bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
  6120. phba->sli4_hba.iov.vf_number =
  6121. bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
  6122. break;
  6123. }
  6124. }
  6125. if (i < LPFC_RSRC_DESC_MAX_NUM)
  6126. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6127. "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
  6128. "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
  6129. phba->sli4_hba.iov.vf_number);
  6130. else
  6131. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6132. "3028 GET_FUNCTION_CONFIG: failed to find "
  6133. "Resrouce Descriptor:x%x\n",
  6134. LPFC_RSRC_DESC_TYPE_FCFCOE);
  6135. read_cfg_out:
  6136. mempool_free(pmb, phba->mbox_mem_pool);
  6137. return rc;
  6138. }
  6139. /**
  6140. * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
  6141. * @phba: pointer to lpfc hba data structure.
  6142. *
  6143. * This routine is invoked to setup the port-side endian order when
  6144. * the port if_type is 0. This routine has no function for other
  6145. * if_types.
  6146. *
  6147. * Return codes
  6148. * 0 - successful
  6149. * -ENOMEM - No available memory
  6150. * -EIO - The mailbox failed to complete successfully.
  6151. **/
  6152. static int
  6153. lpfc_setup_endian_order(struct lpfc_hba *phba)
  6154. {
  6155. LPFC_MBOXQ_t *mboxq;
  6156. uint32_t if_type, rc = 0;
  6157. uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
  6158. HOST_ENDIAN_HIGH_WORD1};
  6159. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  6160. switch (if_type) {
  6161. case LPFC_SLI_INTF_IF_TYPE_0:
  6162. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  6163. GFP_KERNEL);
  6164. if (!mboxq) {
  6165. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6166. "0492 Unable to allocate memory for "
  6167. "issuing SLI_CONFIG_SPECIAL mailbox "
  6168. "command\n");
  6169. return -ENOMEM;
  6170. }
  6171. /*
  6172. * The SLI4_CONFIG_SPECIAL mailbox command requires the first
  6173. * two words to contain special data values and no other data.
  6174. */
  6175. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  6176. memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
  6177. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6178. if (rc != MBX_SUCCESS) {
  6179. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6180. "0493 SLI_CONFIG_SPECIAL mailbox "
  6181. "failed with status x%x\n",
  6182. rc);
  6183. rc = -EIO;
  6184. }
  6185. mempool_free(mboxq, phba->mbox_mem_pool);
  6186. break;
  6187. case LPFC_SLI_INTF_IF_TYPE_2:
  6188. case LPFC_SLI_INTF_IF_TYPE_1:
  6189. default:
  6190. break;
  6191. }
  6192. return rc;
  6193. }
  6194. /**
  6195. * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
  6196. * @phba: pointer to lpfc hba data structure.
  6197. *
  6198. * This routine is invoked to check the user settable queue counts for EQs and
  6199. * CQs. after this routine is called the counts will be set to valid values that
  6200. * adhere to the constraints of the system's interrupt vectors and the port's
  6201. * queue resources.
  6202. *
  6203. * Return codes
  6204. * 0 - successful
  6205. * -ENOMEM - No available memory
  6206. **/
  6207. static int
  6208. lpfc_sli4_queue_verify(struct lpfc_hba *phba)
  6209. {
  6210. int cfg_fcp_io_channel;
  6211. uint32_t cpu;
  6212. uint32_t i = 0;
  6213. /*
  6214. * Sanity check for configured queue parameters against the run-time
  6215. * device parameters
  6216. */
  6217. /* Sanity check on HBA EQ parameters */
  6218. cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
  6219. /* It doesn't make sense to have more io channels then online CPUs */
  6220. for_each_present_cpu(cpu) {
  6221. if (cpu_online(cpu))
  6222. i++;
  6223. }
  6224. phba->sli4_hba.num_online_cpu = i;
  6225. phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
  6226. if (i < cfg_fcp_io_channel) {
  6227. lpfc_printf_log(phba,
  6228. KERN_ERR, LOG_INIT,
  6229. "3188 Reducing IO channels to match number of "
  6230. "online CPUs: from %d to %d\n",
  6231. cfg_fcp_io_channel, i);
  6232. cfg_fcp_io_channel = i;
  6233. }
  6234. if (cfg_fcp_io_channel >
  6235. phba->sli4_hba.max_cfg_param.max_eq) {
  6236. if (phba->sli4_hba.max_cfg_param.max_eq <
  6237. LPFC_FCP_IO_CHAN_MIN) {
  6238. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6239. "2574 Not enough EQs (%d) from the "
  6240. "pci function for supporting FCP "
  6241. "EQs (%d)\n",
  6242. phba->sli4_hba.max_cfg_param.max_eq,
  6243. phba->cfg_fcp_io_channel);
  6244. goto out_error;
  6245. }
  6246. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6247. "2575 Reducing IO channels to match number of "
  6248. "available EQs: from %d to %d\n",
  6249. cfg_fcp_io_channel,
  6250. phba->sli4_hba.max_cfg_param.max_eq);
  6251. cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq;
  6252. }
  6253. /* The actual number of FCP event queues adopted */
  6254. phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
  6255. /* Get EQ depth from module parameter, fake the default for now */
  6256. phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
  6257. phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
  6258. /* Get CQ depth from module parameter, fake the default for now */
  6259. phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
  6260. phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
  6261. return 0;
  6262. out_error:
  6263. return -ENOMEM;
  6264. }
  6265. /**
  6266. * lpfc_sli4_queue_create - Create all the SLI4 queues
  6267. * @phba: pointer to lpfc hba data structure.
  6268. *
  6269. * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
  6270. * operation. For each SLI4 queue type, the parameters such as queue entry
  6271. * count (queue depth) shall be taken from the module parameter. For now,
  6272. * we just use some constant number as place holder.
  6273. *
  6274. * Return codes
  6275. * 0 - successful
  6276. * -ENOMEM - No availble memory
  6277. * -EIO - The mailbox failed to complete successfully.
  6278. **/
  6279. int
  6280. lpfc_sli4_queue_create(struct lpfc_hba *phba)
  6281. {
  6282. struct lpfc_queue *qdesc;
  6283. int idx;
  6284. /*
  6285. * Create HBA Record arrays.
  6286. */
  6287. if (!phba->cfg_fcp_io_channel)
  6288. return -ERANGE;
  6289. phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
  6290. phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
  6291. phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
  6292. phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
  6293. phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
  6294. phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
  6295. phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
  6296. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6297. if (!phba->sli4_hba.hba_eq) {
  6298. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6299. "2576 Failed allocate memory for "
  6300. "fast-path EQ record array\n");
  6301. goto out_error;
  6302. }
  6303. phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
  6304. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6305. if (!phba->sli4_hba.fcp_cq) {
  6306. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6307. "2577 Failed allocate memory for fast-path "
  6308. "CQ record array\n");
  6309. goto out_error;
  6310. }
  6311. phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
  6312. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6313. if (!phba->sli4_hba.fcp_wq) {
  6314. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6315. "2578 Failed allocate memory for fast-path "
  6316. "WQ record array\n");
  6317. goto out_error;
  6318. }
  6319. /*
  6320. * Since the first EQ can have multiple CQs associated with it,
  6321. * this array is used to quickly see if we have a FCP fast-path
  6322. * CQ match.
  6323. */
  6324. phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
  6325. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6326. if (!phba->sli4_hba.fcp_cq_map) {
  6327. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6328. "2545 Failed allocate memory for fast-path "
  6329. "CQ map\n");
  6330. goto out_error;
  6331. }
  6332. /*
  6333. * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
  6334. * how many EQs to create.
  6335. */
  6336. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6337. /* Create EQs */
  6338. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  6339. phba->sli4_hba.eq_ecount);
  6340. if (!qdesc) {
  6341. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6342. "0497 Failed allocate EQ (%d)\n", idx);
  6343. goto out_error;
  6344. }
  6345. phba->sli4_hba.hba_eq[idx] = qdesc;
  6346. /* Create Fast Path FCP CQs */
  6347. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  6348. phba->sli4_hba.cq_ecount);
  6349. if (!qdesc) {
  6350. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6351. "0499 Failed allocate fast-path FCP "
  6352. "CQ (%d)\n", idx);
  6353. goto out_error;
  6354. }
  6355. phba->sli4_hba.fcp_cq[idx] = qdesc;
  6356. /* Create Fast Path FCP WQs */
  6357. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  6358. phba->sli4_hba.wq_ecount);
  6359. if (!qdesc) {
  6360. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6361. "0503 Failed allocate fast-path FCP "
  6362. "WQ (%d)\n", idx);
  6363. goto out_error;
  6364. }
  6365. phba->sli4_hba.fcp_wq[idx] = qdesc;
  6366. }
  6367. /*
  6368. * Create Slow Path Completion Queues (CQs)
  6369. */
  6370. /* Create slow-path Mailbox Command Complete Queue */
  6371. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  6372. phba->sli4_hba.cq_ecount);
  6373. if (!qdesc) {
  6374. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6375. "0500 Failed allocate slow-path mailbox CQ\n");
  6376. goto out_error;
  6377. }
  6378. phba->sli4_hba.mbx_cq = qdesc;
  6379. /* Create slow-path ELS Complete Queue */
  6380. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  6381. phba->sli4_hba.cq_ecount);
  6382. if (!qdesc) {
  6383. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6384. "0501 Failed allocate slow-path ELS CQ\n");
  6385. goto out_error;
  6386. }
  6387. phba->sli4_hba.els_cq = qdesc;
  6388. /*
  6389. * Create Slow Path Work Queues (WQs)
  6390. */
  6391. /* Create Mailbox Command Queue */
  6392. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
  6393. phba->sli4_hba.mq_ecount);
  6394. if (!qdesc) {
  6395. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6396. "0505 Failed allocate slow-path MQ\n");
  6397. goto out_error;
  6398. }
  6399. phba->sli4_hba.mbx_wq = qdesc;
  6400. /*
  6401. * Create ELS Work Queues
  6402. */
  6403. /* Create slow-path ELS Work Queue */
  6404. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  6405. phba->sli4_hba.wq_ecount);
  6406. if (!qdesc) {
  6407. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6408. "0504 Failed allocate slow-path ELS WQ\n");
  6409. goto out_error;
  6410. }
  6411. phba->sli4_hba.els_wq = qdesc;
  6412. /*
  6413. * Create Receive Queue (RQ)
  6414. */
  6415. /* Create Receive Queue for header */
  6416. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  6417. phba->sli4_hba.rq_ecount);
  6418. if (!qdesc) {
  6419. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6420. "0506 Failed allocate receive HRQ\n");
  6421. goto out_error;
  6422. }
  6423. phba->sli4_hba.hdr_rq = qdesc;
  6424. /* Create Receive Queue for data */
  6425. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  6426. phba->sli4_hba.rq_ecount);
  6427. if (!qdesc) {
  6428. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6429. "0507 Failed allocate receive DRQ\n");
  6430. goto out_error;
  6431. }
  6432. phba->sli4_hba.dat_rq = qdesc;
  6433. return 0;
  6434. out_error:
  6435. lpfc_sli4_queue_destroy(phba);
  6436. return -ENOMEM;
  6437. }
  6438. /**
  6439. * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
  6440. * @phba: pointer to lpfc hba data structure.
  6441. *
  6442. * This routine is invoked to release all the SLI4 queues with the FCoE HBA
  6443. * operation.
  6444. *
  6445. * Return codes
  6446. * 0 - successful
  6447. * -ENOMEM - No available memory
  6448. * -EIO - The mailbox failed to complete successfully.
  6449. **/
  6450. void
  6451. lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
  6452. {
  6453. int idx;
  6454. if (phba->sli4_hba.hba_eq != NULL) {
  6455. /* Release HBA event queue */
  6456. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6457. if (phba->sli4_hba.hba_eq[idx] != NULL) {
  6458. lpfc_sli4_queue_free(
  6459. phba->sli4_hba.hba_eq[idx]);
  6460. phba->sli4_hba.hba_eq[idx] = NULL;
  6461. }
  6462. }
  6463. kfree(phba->sli4_hba.hba_eq);
  6464. phba->sli4_hba.hba_eq = NULL;
  6465. }
  6466. if (phba->sli4_hba.fcp_cq != NULL) {
  6467. /* Release FCP completion queue */
  6468. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6469. if (phba->sli4_hba.fcp_cq[idx] != NULL) {
  6470. lpfc_sli4_queue_free(
  6471. phba->sli4_hba.fcp_cq[idx]);
  6472. phba->sli4_hba.fcp_cq[idx] = NULL;
  6473. }
  6474. }
  6475. kfree(phba->sli4_hba.fcp_cq);
  6476. phba->sli4_hba.fcp_cq = NULL;
  6477. }
  6478. if (phba->sli4_hba.fcp_wq != NULL) {
  6479. /* Release FCP work queue */
  6480. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6481. if (phba->sli4_hba.fcp_wq[idx] != NULL) {
  6482. lpfc_sli4_queue_free(
  6483. phba->sli4_hba.fcp_wq[idx]);
  6484. phba->sli4_hba.fcp_wq[idx] = NULL;
  6485. }
  6486. }
  6487. kfree(phba->sli4_hba.fcp_wq);
  6488. phba->sli4_hba.fcp_wq = NULL;
  6489. }
  6490. /* Release FCP CQ mapping array */
  6491. if (phba->sli4_hba.fcp_cq_map != NULL) {
  6492. kfree(phba->sli4_hba.fcp_cq_map);
  6493. phba->sli4_hba.fcp_cq_map = NULL;
  6494. }
  6495. /* Release mailbox command work queue */
  6496. if (phba->sli4_hba.mbx_wq != NULL) {
  6497. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  6498. phba->sli4_hba.mbx_wq = NULL;
  6499. }
  6500. /* Release ELS work queue */
  6501. if (phba->sli4_hba.els_wq != NULL) {
  6502. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  6503. phba->sli4_hba.els_wq = NULL;
  6504. }
  6505. /* Release unsolicited receive queue */
  6506. if (phba->sli4_hba.hdr_rq != NULL) {
  6507. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  6508. phba->sli4_hba.hdr_rq = NULL;
  6509. }
  6510. if (phba->sli4_hba.dat_rq != NULL) {
  6511. lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
  6512. phba->sli4_hba.dat_rq = NULL;
  6513. }
  6514. /* Release ELS complete queue */
  6515. if (phba->sli4_hba.els_cq != NULL) {
  6516. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  6517. phba->sli4_hba.els_cq = NULL;
  6518. }
  6519. /* Release mailbox command complete queue */
  6520. if (phba->sli4_hba.mbx_cq != NULL) {
  6521. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  6522. phba->sli4_hba.mbx_cq = NULL;
  6523. }
  6524. return;
  6525. }
  6526. /**
  6527. * lpfc_sli4_queue_setup - Set up all the SLI4 queues
  6528. * @phba: pointer to lpfc hba data structure.
  6529. *
  6530. * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
  6531. * operation.
  6532. *
  6533. * Return codes
  6534. * 0 - successful
  6535. * -ENOMEM - No available memory
  6536. * -EIO - The mailbox failed to complete successfully.
  6537. **/
  6538. int
  6539. lpfc_sli4_queue_setup(struct lpfc_hba *phba)
  6540. {
  6541. struct lpfc_sli *psli = &phba->sli;
  6542. struct lpfc_sli_ring *pring;
  6543. int rc = -ENOMEM;
  6544. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  6545. int fcp_cq_index = 0;
  6546. uint32_t shdr_status, shdr_add_status;
  6547. union lpfc_sli4_cfg_shdr *shdr;
  6548. LPFC_MBOXQ_t *mboxq;
  6549. uint32_t length;
  6550. /* Check for dual-ULP support */
  6551. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6552. if (!mboxq) {
  6553. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6554. "3249 Unable to allocate memory for "
  6555. "QUERY_FW_CFG mailbox command\n");
  6556. return -ENOMEM;
  6557. }
  6558. length = (sizeof(struct lpfc_mbx_query_fw_config) -
  6559. sizeof(struct lpfc_sli4_cfg_mhdr));
  6560. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  6561. LPFC_MBOX_OPCODE_QUERY_FW_CFG,
  6562. length, LPFC_SLI4_MBX_EMBED);
  6563. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6564. shdr = (union lpfc_sli4_cfg_shdr *)
  6565. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  6566. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  6567. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  6568. if (shdr_status || shdr_add_status || rc) {
  6569. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6570. "3250 QUERY_FW_CFG mailbox failed with status "
  6571. "x%x add_status x%x, mbx status x%x\n",
  6572. shdr_status, shdr_add_status, rc);
  6573. if (rc != MBX_TIMEOUT)
  6574. mempool_free(mboxq, phba->mbox_mem_pool);
  6575. rc = -ENXIO;
  6576. goto out_error;
  6577. }
  6578. phba->sli4_hba.fw_func_mode =
  6579. mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
  6580. phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
  6581. phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
  6582. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6583. "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
  6584. "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
  6585. phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
  6586. if (rc != MBX_TIMEOUT)
  6587. mempool_free(mboxq, phba->mbox_mem_pool);
  6588. /*
  6589. * Set up HBA Event Queues (EQs)
  6590. */
  6591. /* Set up HBA event queue */
  6592. if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
  6593. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6594. "3147 Fast-path EQs not allocated\n");
  6595. rc = -ENOMEM;
  6596. goto out_error;
  6597. }
  6598. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
  6599. if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
  6600. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6601. "0522 Fast-path EQ (%d) not "
  6602. "allocated\n", fcp_eqidx);
  6603. rc = -ENOMEM;
  6604. goto out_destroy_hba_eq;
  6605. }
  6606. rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
  6607. (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
  6608. if (rc) {
  6609. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6610. "0523 Failed setup of fast-path EQ "
  6611. "(%d), rc = 0x%x\n", fcp_eqidx, rc);
  6612. goto out_destroy_hba_eq;
  6613. }
  6614. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6615. "2584 HBA EQ setup: "
  6616. "queue[%d]-id=%d\n", fcp_eqidx,
  6617. phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
  6618. }
  6619. /* Set up fast-path FCP Response Complete Queue */
  6620. if (!phba->sli4_hba.fcp_cq) {
  6621. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6622. "3148 Fast-path FCP CQ array not "
  6623. "allocated\n");
  6624. rc = -ENOMEM;
  6625. goto out_destroy_hba_eq;
  6626. }
  6627. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
  6628. if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
  6629. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6630. "0526 Fast-path FCP CQ (%d) not "
  6631. "allocated\n", fcp_cqidx);
  6632. rc = -ENOMEM;
  6633. goto out_destroy_fcp_cq;
  6634. }
  6635. rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
  6636. phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
  6637. if (rc) {
  6638. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6639. "0527 Failed setup of fast-path FCP "
  6640. "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
  6641. goto out_destroy_fcp_cq;
  6642. }
  6643. /* Setup fcp_cq_map for fast lookup */
  6644. phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
  6645. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
  6646. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6647. "2588 FCP CQ setup: cq[%d]-id=%d, "
  6648. "parent seq[%d]-id=%d\n",
  6649. fcp_cqidx,
  6650. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
  6651. fcp_cqidx,
  6652. phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
  6653. }
  6654. /* Set up fast-path FCP Work Queue */
  6655. if (!phba->sli4_hba.fcp_wq) {
  6656. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6657. "3149 Fast-path FCP WQ array not "
  6658. "allocated\n");
  6659. rc = -ENOMEM;
  6660. goto out_destroy_fcp_cq;
  6661. }
  6662. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
  6663. if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
  6664. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6665. "0534 Fast-path FCP WQ (%d) not "
  6666. "allocated\n", fcp_wqidx);
  6667. rc = -ENOMEM;
  6668. goto out_destroy_fcp_wq;
  6669. }
  6670. rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
  6671. phba->sli4_hba.fcp_cq[fcp_wqidx],
  6672. LPFC_FCP);
  6673. if (rc) {
  6674. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6675. "0535 Failed setup of fast-path FCP "
  6676. "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
  6677. goto out_destroy_fcp_wq;
  6678. }
  6679. /* Bind this WQ to the next FCP ring */
  6680. pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
  6681. pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
  6682. phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
  6683. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6684. "2591 FCP WQ setup: wq[%d]-id=%d, "
  6685. "parent cq[%d]-id=%d\n",
  6686. fcp_wqidx,
  6687. phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
  6688. fcp_cq_index,
  6689. phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
  6690. }
  6691. /*
  6692. * Set up Complete Queues (CQs)
  6693. */
  6694. /* Set up slow-path MBOX Complete Queue as the first CQ */
  6695. if (!phba->sli4_hba.mbx_cq) {
  6696. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6697. "0528 Mailbox CQ not allocated\n");
  6698. rc = -ENOMEM;
  6699. goto out_destroy_fcp_wq;
  6700. }
  6701. rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
  6702. phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
  6703. if (rc) {
  6704. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6705. "0529 Failed setup of slow-path mailbox CQ: "
  6706. "rc = 0x%x\n", rc);
  6707. goto out_destroy_fcp_wq;
  6708. }
  6709. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6710. "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
  6711. phba->sli4_hba.mbx_cq->queue_id,
  6712. phba->sli4_hba.hba_eq[0]->queue_id);
  6713. /* Set up slow-path ELS Complete Queue */
  6714. if (!phba->sli4_hba.els_cq) {
  6715. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6716. "0530 ELS CQ not allocated\n");
  6717. rc = -ENOMEM;
  6718. goto out_destroy_mbx_cq;
  6719. }
  6720. rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
  6721. phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
  6722. if (rc) {
  6723. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6724. "0531 Failed setup of slow-path ELS CQ: "
  6725. "rc = 0x%x\n", rc);
  6726. goto out_destroy_mbx_cq;
  6727. }
  6728. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6729. "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
  6730. phba->sli4_hba.els_cq->queue_id,
  6731. phba->sli4_hba.hba_eq[0]->queue_id);
  6732. /*
  6733. * Set up all the Work Queues (WQs)
  6734. */
  6735. /* Set up Mailbox Command Queue */
  6736. if (!phba->sli4_hba.mbx_wq) {
  6737. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6738. "0538 Slow-path MQ not allocated\n");
  6739. rc = -ENOMEM;
  6740. goto out_destroy_els_cq;
  6741. }
  6742. rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
  6743. phba->sli4_hba.mbx_cq, LPFC_MBOX);
  6744. if (rc) {
  6745. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6746. "0539 Failed setup of slow-path MQ: "
  6747. "rc = 0x%x\n", rc);
  6748. goto out_destroy_els_cq;
  6749. }
  6750. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6751. "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
  6752. phba->sli4_hba.mbx_wq->queue_id,
  6753. phba->sli4_hba.mbx_cq->queue_id);
  6754. /* Set up slow-path ELS Work Queue */
  6755. if (!phba->sli4_hba.els_wq) {
  6756. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6757. "0536 Slow-path ELS WQ not allocated\n");
  6758. rc = -ENOMEM;
  6759. goto out_destroy_mbx_wq;
  6760. }
  6761. rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
  6762. phba->sli4_hba.els_cq, LPFC_ELS);
  6763. if (rc) {
  6764. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6765. "0537 Failed setup of slow-path ELS WQ: "
  6766. "rc = 0x%x\n", rc);
  6767. goto out_destroy_mbx_wq;
  6768. }
  6769. /* Bind this WQ to the ELS ring */
  6770. pring = &psli->ring[LPFC_ELS_RING];
  6771. pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
  6772. phba->sli4_hba.els_cq->pring = pring;
  6773. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6774. "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
  6775. phba->sli4_hba.els_wq->queue_id,
  6776. phba->sli4_hba.els_cq->queue_id);
  6777. /*
  6778. * Create Receive Queue (RQ)
  6779. */
  6780. if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
  6781. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6782. "0540 Receive Queue not allocated\n");
  6783. rc = -ENOMEM;
  6784. goto out_destroy_els_wq;
  6785. }
  6786. lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
  6787. lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
  6788. rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  6789. phba->sli4_hba.els_cq, LPFC_USOL);
  6790. if (rc) {
  6791. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6792. "0541 Failed setup of Receive Queue: "
  6793. "rc = 0x%x\n", rc);
  6794. goto out_destroy_fcp_wq;
  6795. }
  6796. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6797. "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
  6798. "parent cq-id=%d\n",
  6799. phba->sli4_hba.hdr_rq->queue_id,
  6800. phba->sli4_hba.dat_rq->queue_id,
  6801. phba->sli4_hba.els_cq->queue_id);
  6802. return 0;
  6803. out_destroy_els_wq:
  6804. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  6805. out_destroy_mbx_wq:
  6806. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  6807. out_destroy_els_cq:
  6808. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  6809. out_destroy_mbx_cq:
  6810. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  6811. out_destroy_fcp_wq:
  6812. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
  6813. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
  6814. out_destroy_fcp_cq:
  6815. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
  6816. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
  6817. out_destroy_hba_eq:
  6818. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
  6819. lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
  6820. out_error:
  6821. return rc;
  6822. }
  6823. /**
  6824. * lpfc_sli4_queue_unset - Unset all the SLI4 queues
  6825. * @phba: pointer to lpfc hba data structure.
  6826. *
  6827. * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
  6828. * operation.
  6829. *
  6830. * Return codes
  6831. * 0 - successful
  6832. * -ENOMEM - No available memory
  6833. * -EIO - The mailbox failed to complete successfully.
  6834. **/
  6835. void
  6836. lpfc_sli4_queue_unset(struct lpfc_hba *phba)
  6837. {
  6838. int fcp_qidx;
  6839. /* Unset mailbox command work queue */
  6840. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  6841. /* Unset ELS work queue */
  6842. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  6843. /* Unset unsolicited receive queue */
  6844. lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
  6845. /* Unset FCP work queue */
  6846. if (phba->sli4_hba.fcp_wq) {
  6847. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
  6848. fcp_qidx++)
  6849. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
  6850. }
  6851. /* Unset mailbox command complete queue */
  6852. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  6853. /* Unset ELS complete queue */
  6854. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  6855. /* Unset FCP response complete queue */
  6856. if (phba->sli4_hba.fcp_cq) {
  6857. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
  6858. fcp_qidx++)
  6859. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
  6860. }
  6861. /* Unset fast-path event queue */
  6862. if (phba->sli4_hba.hba_eq) {
  6863. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
  6864. fcp_qidx++)
  6865. lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
  6866. }
  6867. }
  6868. /**
  6869. * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
  6870. * @phba: pointer to lpfc hba data structure.
  6871. *
  6872. * This routine is invoked to allocate and set up a pool of completion queue
  6873. * events. The body of the completion queue event is a completion queue entry
  6874. * CQE. For now, this pool is used for the interrupt service routine to queue
  6875. * the following HBA completion queue events for the worker thread to process:
  6876. * - Mailbox asynchronous events
  6877. * - Receive queue completion unsolicited events
  6878. * Later, this can be used for all the slow-path events.
  6879. *
  6880. * Return codes
  6881. * 0 - successful
  6882. * -ENOMEM - No available memory
  6883. **/
  6884. static int
  6885. lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
  6886. {
  6887. struct lpfc_cq_event *cq_event;
  6888. int i;
  6889. for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
  6890. cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
  6891. if (!cq_event)
  6892. goto out_pool_create_fail;
  6893. list_add_tail(&cq_event->list,
  6894. &phba->sli4_hba.sp_cqe_event_pool);
  6895. }
  6896. return 0;
  6897. out_pool_create_fail:
  6898. lpfc_sli4_cq_event_pool_destroy(phba);
  6899. return -ENOMEM;
  6900. }
  6901. /**
  6902. * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
  6903. * @phba: pointer to lpfc hba data structure.
  6904. *
  6905. * This routine is invoked to free the pool of completion queue events at
  6906. * driver unload time. Note that, it is the responsibility of the driver
  6907. * cleanup routine to free all the outstanding completion-queue events
  6908. * allocated from this pool back into the pool before invoking this routine
  6909. * to destroy the pool.
  6910. **/
  6911. static void
  6912. lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
  6913. {
  6914. struct lpfc_cq_event *cq_event, *next_cq_event;
  6915. list_for_each_entry_safe(cq_event, next_cq_event,
  6916. &phba->sli4_hba.sp_cqe_event_pool, list) {
  6917. list_del(&cq_event->list);
  6918. kfree(cq_event);
  6919. }
  6920. }
  6921. /**
  6922. * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  6923. * @phba: pointer to lpfc hba data structure.
  6924. *
  6925. * This routine is the lock free version of the API invoked to allocate a
  6926. * completion-queue event from the free pool.
  6927. *
  6928. * Return: Pointer to the newly allocated completion-queue event if successful
  6929. * NULL otherwise.
  6930. **/
  6931. struct lpfc_cq_event *
  6932. __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  6933. {
  6934. struct lpfc_cq_event *cq_event = NULL;
  6935. list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
  6936. struct lpfc_cq_event, list);
  6937. return cq_event;
  6938. }
  6939. /**
  6940. * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  6941. * @phba: pointer to lpfc hba data structure.
  6942. *
  6943. * This routine is the lock version of the API invoked to allocate a
  6944. * completion-queue event from the free pool.
  6945. *
  6946. * Return: Pointer to the newly allocated completion-queue event if successful
  6947. * NULL otherwise.
  6948. **/
  6949. struct lpfc_cq_event *
  6950. lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  6951. {
  6952. struct lpfc_cq_event *cq_event;
  6953. unsigned long iflags;
  6954. spin_lock_irqsave(&phba->hbalock, iflags);
  6955. cq_event = __lpfc_sli4_cq_event_alloc(phba);
  6956. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6957. return cq_event;
  6958. }
  6959. /**
  6960. * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  6961. * @phba: pointer to lpfc hba data structure.
  6962. * @cq_event: pointer to the completion queue event to be freed.
  6963. *
  6964. * This routine is the lock free version of the API invoked to release a
  6965. * completion-queue event back into the free pool.
  6966. **/
  6967. void
  6968. __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  6969. struct lpfc_cq_event *cq_event)
  6970. {
  6971. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
  6972. }
  6973. /**
  6974. * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  6975. * @phba: pointer to lpfc hba data structure.
  6976. * @cq_event: pointer to the completion queue event to be freed.
  6977. *
  6978. * This routine is the lock version of the API invoked to release a
  6979. * completion-queue event back into the free pool.
  6980. **/
  6981. void
  6982. lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  6983. struct lpfc_cq_event *cq_event)
  6984. {
  6985. unsigned long iflags;
  6986. spin_lock_irqsave(&phba->hbalock, iflags);
  6987. __lpfc_sli4_cq_event_release(phba, cq_event);
  6988. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6989. }
  6990. /**
  6991. * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
  6992. * @phba: pointer to lpfc hba data structure.
  6993. *
  6994. * This routine is to free all the pending completion-queue events to the
  6995. * back into the free pool for device reset.
  6996. **/
  6997. static void
  6998. lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
  6999. {
  7000. LIST_HEAD(cqelist);
  7001. struct lpfc_cq_event *cqe;
  7002. unsigned long iflags;
  7003. /* Retrieve all the pending WCQEs from pending WCQE lists */
  7004. spin_lock_irqsave(&phba->hbalock, iflags);
  7005. /* Pending FCP XRI abort events */
  7006. list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7007. &cqelist);
  7008. /* Pending ELS XRI abort events */
  7009. list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7010. &cqelist);
  7011. /* Pending asynnc events */
  7012. list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
  7013. &cqelist);
  7014. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7015. while (!list_empty(&cqelist)) {
  7016. list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
  7017. lpfc_sli4_cq_event_release(phba, cqe);
  7018. }
  7019. }
  7020. /**
  7021. * lpfc_pci_function_reset - Reset pci function.
  7022. * @phba: pointer to lpfc hba data structure.
  7023. *
  7024. * This routine is invoked to request a PCI function reset. It will destroys
  7025. * all resources assigned to the PCI function which originates this request.
  7026. *
  7027. * Return codes
  7028. * 0 - successful
  7029. * -ENOMEM - No available memory
  7030. * -EIO - The mailbox failed to complete successfully.
  7031. **/
  7032. int
  7033. lpfc_pci_function_reset(struct lpfc_hba *phba)
  7034. {
  7035. LPFC_MBOXQ_t *mboxq;
  7036. uint32_t rc = 0, if_type;
  7037. uint32_t shdr_status, shdr_add_status;
  7038. uint32_t rdy_chk, num_resets = 0, reset_again = 0;
  7039. union lpfc_sli4_cfg_shdr *shdr;
  7040. struct lpfc_register reg_data;
  7041. uint16_t devid;
  7042. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7043. switch (if_type) {
  7044. case LPFC_SLI_INTF_IF_TYPE_0:
  7045. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  7046. GFP_KERNEL);
  7047. if (!mboxq) {
  7048. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7049. "0494 Unable to allocate memory for "
  7050. "issuing SLI_FUNCTION_RESET mailbox "
  7051. "command\n");
  7052. return -ENOMEM;
  7053. }
  7054. /* Setup PCI function reset mailbox-ioctl command */
  7055. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  7056. LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
  7057. LPFC_SLI4_MBX_EMBED);
  7058. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7059. shdr = (union lpfc_sli4_cfg_shdr *)
  7060. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  7061. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  7062. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  7063. &shdr->response);
  7064. if (rc != MBX_TIMEOUT)
  7065. mempool_free(mboxq, phba->mbox_mem_pool);
  7066. if (shdr_status || shdr_add_status || rc) {
  7067. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7068. "0495 SLI_FUNCTION_RESET mailbox "
  7069. "failed with status x%x add_status x%x,"
  7070. " mbx status x%x\n",
  7071. shdr_status, shdr_add_status, rc);
  7072. rc = -ENXIO;
  7073. }
  7074. break;
  7075. case LPFC_SLI_INTF_IF_TYPE_2:
  7076. for (num_resets = 0;
  7077. num_resets < MAX_IF_TYPE_2_RESETS;
  7078. num_resets++) {
  7079. reg_data.word0 = 0;
  7080. bf_set(lpfc_sliport_ctrl_end, &reg_data,
  7081. LPFC_SLIPORT_LITTLE_ENDIAN);
  7082. bf_set(lpfc_sliport_ctrl_ip, &reg_data,
  7083. LPFC_SLIPORT_INIT_PORT);
  7084. writel(reg_data.word0, phba->sli4_hba.u.if_type2.
  7085. CTRLregaddr);
  7086. /* flush */
  7087. pci_read_config_word(phba->pcidev,
  7088. PCI_DEVICE_ID, &devid);
  7089. /*
  7090. * Poll the Port Status Register and wait for RDY for
  7091. * up to 10 seconds. If the port doesn't respond, treat
  7092. * it as an error. If the port responds with RN, start
  7093. * the loop again.
  7094. */
  7095. for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) {
  7096. msleep(10);
  7097. if (lpfc_readl(phba->sli4_hba.u.if_type2.
  7098. STATUSregaddr, &reg_data.word0)) {
  7099. rc = -ENODEV;
  7100. goto out;
  7101. }
  7102. if (bf_get(lpfc_sliport_status_rn, &reg_data))
  7103. reset_again++;
  7104. if (bf_get(lpfc_sliport_status_rdy, &reg_data))
  7105. break;
  7106. }
  7107. /*
  7108. * If the port responds to the init request with
  7109. * reset needed, delay for a bit and restart the loop.
  7110. */
  7111. if (reset_again && (rdy_chk < 1000)) {
  7112. msleep(10);
  7113. reset_again = 0;
  7114. continue;
  7115. }
  7116. /* Detect any port errors. */
  7117. if ((bf_get(lpfc_sliport_status_err, &reg_data)) ||
  7118. (rdy_chk >= 1000)) {
  7119. phba->work_status[0] = readl(
  7120. phba->sli4_hba.u.if_type2.ERR1regaddr);
  7121. phba->work_status[1] = readl(
  7122. phba->sli4_hba.u.if_type2.ERR2regaddr);
  7123. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7124. "2890 Port error detected during port "
  7125. "reset(%d): wait_tmo:%d ms, "
  7126. "port status reg 0x%x, "
  7127. "error 1=0x%x, error 2=0x%x\n",
  7128. num_resets, rdy_chk*10,
  7129. reg_data.word0,
  7130. phba->work_status[0],
  7131. phba->work_status[1]);
  7132. rc = -ENODEV;
  7133. }
  7134. /*
  7135. * Terminate the outer loop provided the Port indicated
  7136. * ready within 10 seconds.
  7137. */
  7138. if (rdy_chk < 1000)
  7139. break;
  7140. }
  7141. /* delay driver action following IF_TYPE_2 function reset */
  7142. msleep(100);
  7143. break;
  7144. case LPFC_SLI_INTF_IF_TYPE_1:
  7145. default:
  7146. break;
  7147. }
  7148. out:
  7149. /* Catch the not-ready port failure after a port reset. */
  7150. if (num_resets >= MAX_IF_TYPE_2_RESETS) {
  7151. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7152. "3317 HBA not functional: IP Reset Failed "
  7153. "after (%d) retries, try: "
  7154. "echo fw_reset > board_mode\n", num_resets);
  7155. rc = -ENODEV;
  7156. }
  7157. return rc;
  7158. }
  7159. /**
  7160. * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
  7161. * @phba: pointer to lpfc hba data structure.
  7162. *
  7163. * This routine is invoked to set up the PCI device memory space for device
  7164. * with SLI-4 interface spec.
  7165. *
  7166. * Return codes
  7167. * 0 - successful
  7168. * other values - error
  7169. **/
  7170. static int
  7171. lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
  7172. {
  7173. struct pci_dev *pdev;
  7174. unsigned long bar0map_len, bar1map_len, bar2map_len;
  7175. int error = -ENODEV;
  7176. uint32_t if_type;
  7177. /* Obtain PCI device reference */
  7178. if (!phba->pcidev)
  7179. return error;
  7180. else
  7181. pdev = phba->pcidev;
  7182. /* Set the device DMA mask size */
  7183. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  7184. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  7185. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  7186. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  7187. return error;
  7188. }
  7189. }
  7190. /*
  7191. * The BARs and register set definitions and offset locations are
  7192. * dependent on the if_type.
  7193. */
  7194. if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
  7195. &phba->sli4_hba.sli_intf.word0)) {
  7196. return error;
  7197. }
  7198. /* There is no SLI3 failback for SLI4 devices. */
  7199. if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
  7200. LPFC_SLI_INTF_VALID) {
  7201. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7202. "2894 SLI_INTF reg contents invalid "
  7203. "sli_intf reg 0x%x\n",
  7204. phba->sli4_hba.sli_intf.word0);
  7205. return error;
  7206. }
  7207. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7208. /*
  7209. * Get the bus address of SLI4 device Bar regions and the
  7210. * number of bytes required by each mapping. The mapping of the
  7211. * particular PCI BARs regions is dependent on the type of
  7212. * SLI4 device.
  7213. */
  7214. if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
  7215. phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
  7216. bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
  7217. /*
  7218. * Map SLI4 PCI Config Space Register base to a kernel virtual
  7219. * addr
  7220. */
  7221. phba->sli4_hba.conf_regs_memmap_p =
  7222. ioremap(phba->pci_bar0_map, bar0map_len);
  7223. if (!phba->sli4_hba.conf_regs_memmap_p) {
  7224. dev_printk(KERN_ERR, &pdev->dev,
  7225. "ioremap failed for SLI4 PCI config "
  7226. "registers.\n");
  7227. goto out;
  7228. }
  7229. phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
  7230. /* Set up BAR0 PCI config space register memory map */
  7231. lpfc_sli4_bar0_register_memmap(phba, if_type);
  7232. } else {
  7233. phba->pci_bar0_map = pci_resource_start(pdev, 1);
  7234. bar0map_len = pci_resource_len(pdev, 1);
  7235. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7236. dev_printk(KERN_ERR, &pdev->dev,
  7237. "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
  7238. goto out;
  7239. }
  7240. phba->sli4_hba.conf_regs_memmap_p =
  7241. ioremap(phba->pci_bar0_map, bar0map_len);
  7242. if (!phba->sli4_hba.conf_regs_memmap_p) {
  7243. dev_printk(KERN_ERR, &pdev->dev,
  7244. "ioremap failed for SLI4 PCI config "
  7245. "registers.\n");
  7246. goto out;
  7247. }
  7248. lpfc_sli4_bar0_register_memmap(phba, if_type);
  7249. }
  7250. if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
  7251. (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
  7252. /*
  7253. * Map SLI4 if type 0 HBA Control Register base to a kernel
  7254. * virtual address and setup the registers.
  7255. */
  7256. phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
  7257. bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
  7258. phba->sli4_hba.ctrl_regs_memmap_p =
  7259. ioremap(phba->pci_bar1_map, bar1map_len);
  7260. if (!phba->sli4_hba.ctrl_regs_memmap_p) {
  7261. dev_printk(KERN_ERR, &pdev->dev,
  7262. "ioremap failed for SLI4 HBA control registers.\n");
  7263. goto out_iounmap_conf;
  7264. }
  7265. phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
  7266. lpfc_sli4_bar1_register_memmap(phba);
  7267. }
  7268. if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
  7269. (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
  7270. /*
  7271. * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
  7272. * virtual address and setup the registers.
  7273. */
  7274. phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
  7275. bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
  7276. phba->sli4_hba.drbl_regs_memmap_p =
  7277. ioremap(phba->pci_bar2_map, bar2map_len);
  7278. if (!phba->sli4_hba.drbl_regs_memmap_p) {
  7279. dev_printk(KERN_ERR, &pdev->dev,
  7280. "ioremap failed for SLI4 HBA doorbell registers.\n");
  7281. goto out_iounmap_ctrl;
  7282. }
  7283. phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
  7284. error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
  7285. if (error)
  7286. goto out_iounmap_all;
  7287. }
  7288. return 0;
  7289. out_iounmap_all:
  7290. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  7291. out_iounmap_ctrl:
  7292. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  7293. out_iounmap_conf:
  7294. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  7295. out:
  7296. return error;
  7297. }
  7298. /**
  7299. * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
  7300. * @phba: pointer to lpfc hba data structure.
  7301. *
  7302. * This routine is invoked to unset the PCI device memory space for device
  7303. * with SLI-4 interface spec.
  7304. **/
  7305. static void
  7306. lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
  7307. {
  7308. uint32_t if_type;
  7309. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7310. switch (if_type) {
  7311. case LPFC_SLI_INTF_IF_TYPE_0:
  7312. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  7313. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  7314. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  7315. break;
  7316. case LPFC_SLI_INTF_IF_TYPE_2:
  7317. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  7318. break;
  7319. case LPFC_SLI_INTF_IF_TYPE_1:
  7320. default:
  7321. dev_printk(KERN_ERR, &phba->pcidev->dev,
  7322. "FATAL - unsupported SLI4 interface type - %d\n",
  7323. if_type);
  7324. break;
  7325. }
  7326. }
  7327. /**
  7328. * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
  7329. * @phba: pointer to lpfc hba data structure.
  7330. *
  7331. * This routine is invoked to enable the MSI-X interrupt vectors to device
  7332. * with SLI-3 interface specs. The kernel function pci_enable_msix() is
  7333. * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
  7334. * invoked, enables either all or nothing, depending on the current
  7335. * availability of PCI vector resources. The device driver is responsible
  7336. * for calling the individual request_irq() to register each MSI-X vector
  7337. * with a interrupt handler, which is done in this function. Note that
  7338. * later when device is unloading, the driver should always call free_irq()
  7339. * on all MSI-X vectors it has done request_irq() on before calling
  7340. * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
  7341. * will be left with MSI-X enabled and leaks its vectors.
  7342. *
  7343. * Return codes
  7344. * 0 - successful
  7345. * other values - error
  7346. **/
  7347. static int
  7348. lpfc_sli_enable_msix(struct lpfc_hba *phba)
  7349. {
  7350. int rc, i;
  7351. LPFC_MBOXQ_t *pmb;
  7352. /* Set up MSI-X multi-message vectors */
  7353. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  7354. phba->msix_entries[i].entry = i;
  7355. /* Configure MSI-X capability structure */
  7356. rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
  7357. ARRAY_SIZE(phba->msix_entries));
  7358. if (rc) {
  7359. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7360. "0420 PCI enable MSI-X failed (%d)\n", rc);
  7361. goto msi_fail_out;
  7362. }
  7363. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  7364. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7365. "0477 MSI-X entry[%d]: vector=x%x "
  7366. "message=%d\n", i,
  7367. phba->msix_entries[i].vector,
  7368. phba->msix_entries[i].entry);
  7369. /*
  7370. * Assign MSI-X vectors to interrupt handlers
  7371. */
  7372. /* vector-0 is associated to slow-path handler */
  7373. rc = request_irq(phba->msix_entries[0].vector,
  7374. &lpfc_sli_sp_intr_handler, IRQF_SHARED,
  7375. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  7376. if (rc) {
  7377. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7378. "0421 MSI-X slow-path request_irq failed "
  7379. "(%d)\n", rc);
  7380. goto msi_fail_out;
  7381. }
  7382. /* vector-1 is associated to fast-path handler */
  7383. rc = request_irq(phba->msix_entries[1].vector,
  7384. &lpfc_sli_fp_intr_handler, IRQF_SHARED,
  7385. LPFC_FP_DRIVER_HANDLER_NAME, phba);
  7386. if (rc) {
  7387. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7388. "0429 MSI-X fast-path request_irq failed "
  7389. "(%d)\n", rc);
  7390. goto irq_fail_out;
  7391. }
  7392. /*
  7393. * Configure HBA MSI-X attention conditions to messages
  7394. */
  7395. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  7396. if (!pmb) {
  7397. rc = -ENOMEM;
  7398. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7399. "0474 Unable to allocate memory for issuing "
  7400. "MBOX_CONFIG_MSI command\n");
  7401. goto mem_fail_out;
  7402. }
  7403. rc = lpfc_config_msi(phba, pmb);
  7404. if (rc)
  7405. goto mbx_fail_out;
  7406. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  7407. if (rc != MBX_SUCCESS) {
  7408. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  7409. "0351 Config MSI mailbox command failed, "
  7410. "mbxCmd x%x, mbxStatus x%x\n",
  7411. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
  7412. goto mbx_fail_out;
  7413. }
  7414. /* Free memory allocated for mailbox command */
  7415. mempool_free(pmb, phba->mbox_mem_pool);
  7416. return rc;
  7417. mbx_fail_out:
  7418. /* Free memory allocated for mailbox command */
  7419. mempool_free(pmb, phba->mbox_mem_pool);
  7420. mem_fail_out:
  7421. /* free the irq already requested */
  7422. free_irq(phba->msix_entries[1].vector, phba);
  7423. irq_fail_out:
  7424. /* free the irq already requested */
  7425. free_irq(phba->msix_entries[0].vector, phba);
  7426. msi_fail_out:
  7427. /* Unconfigure MSI-X capability structure */
  7428. pci_disable_msix(phba->pcidev);
  7429. return rc;
  7430. }
  7431. /**
  7432. * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
  7433. * @phba: pointer to lpfc hba data structure.
  7434. *
  7435. * This routine is invoked to release the MSI-X vectors and then disable the
  7436. * MSI-X interrupt mode to device with SLI-3 interface spec.
  7437. **/
  7438. static void
  7439. lpfc_sli_disable_msix(struct lpfc_hba *phba)
  7440. {
  7441. int i;
  7442. /* Free up MSI-X multi-message vectors */
  7443. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  7444. free_irq(phba->msix_entries[i].vector, phba);
  7445. /* Disable MSI-X */
  7446. pci_disable_msix(phba->pcidev);
  7447. return;
  7448. }
  7449. /**
  7450. * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
  7451. * @phba: pointer to lpfc hba data structure.
  7452. *
  7453. * This routine is invoked to enable the MSI interrupt mode to device with
  7454. * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
  7455. * enable the MSI vector. The device driver is responsible for calling the
  7456. * request_irq() to register MSI vector with a interrupt the handler, which
  7457. * is done in this function.
  7458. *
  7459. * Return codes
  7460. * 0 - successful
  7461. * other values - error
  7462. */
  7463. static int
  7464. lpfc_sli_enable_msi(struct lpfc_hba *phba)
  7465. {
  7466. int rc;
  7467. rc = pci_enable_msi(phba->pcidev);
  7468. if (!rc)
  7469. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7470. "0462 PCI enable MSI mode success.\n");
  7471. else {
  7472. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7473. "0471 PCI enable MSI mode failed (%d)\n", rc);
  7474. return rc;
  7475. }
  7476. rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  7477. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7478. if (rc) {
  7479. pci_disable_msi(phba->pcidev);
  7480. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7481. "0478 MSI request_irq failed (%d)\n", rc);
  7482. }
  7483. return rc;
  7484. }
  7485. /**
  7486. * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
  7487. * @phba: pointer to lpfc hba data structure.
  7488. *
  7489. * This routine is invoked to disable the MSI interrupt mode to device with
  7490. * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
  7491. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  7492. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  7493. * its vector.
  7494. */
  7495. static void
  7496. lpfc_sli_disable_msi(struct lpfc_hba *phba)
  7497. {
  7498. free_irq(phba->pcidev->irq, phba);
  7499. pci_disable_msi(phba->pcidev);
  7500. return;
  7501. }
  7502. /**
  7503. * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
  7504. * @phba: pointer to lpfc hba data structure.
  7505. *
  7506. * This routine is invoked to enable device interrupt and associate driver's
  7507. * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
  7508. * spec. Depends on the interrupt mode configured to the driver, the driver
  7509. * will try to fallback from the configured interrupt mode to an interrupt
  7510. * mode which is supported by the platform, kernel, and device in the order
  7511. * of:
  7512. * MSI-X -> MSI -> IRQ.
  7513. *
  7514. * Return codes
  7515. * 0 - successful
  7516. * other values - error
  7517. **/
  7518. static uint32_t
  7519. lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  7520. {
  7521. uint32_t intr_mode = LPFC_INTR_ERROR;
  7522. int retval;
  7523. if (cfg_mode == 2) {
  7524. /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
  7525. retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
  7526. if (!retval) {
  7527. /* Now, try to enable MSI-X interrupt mode */
  7528. retval = lpfc_sli_enable_msix(phba);
  7529. if (!retval) {
  7530. /* Indicate initialization to MSI-X mode */
  7531. phba->intr_type = MSIX;
  7532. intr_mode = 2;
  7533. }
  7534. }
  7535. }
  7536. /* Fallback to MSI if MSI-X initialization failed */
  7537. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  7538. retval = lpfc_sli_enable_msi(phba);
  7539. if (!retval) {
  7540. /* Indicate initialization to MSI mode */
  7541. phba->intr_type = MSI;
  7542. intr_mode = 1;
  7543. }
  7544. }
  7545. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  7546. if (phba->intr_type == NONE) {
  7547. retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  7548. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7549. if (!retval) {
  7550. /* Indicate initialization to INTx mode */
  7551. phba->intr_type = INTx;
  7552. intr_mode = 0;
  7553. }
  7554. }
  7555. return intr_mode;
  7556. }
  7557. /**
  7558. * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
  7559. * @phba: pointer to lpfc hba data structure.
  7560. *
  7561. * This routine is invoked to disable device interrupt and disassociate the
  7562. * driver's interrupt handler(s) from interrupt vector(s) to device with
  7563. * SLI-3 interface spec. Depending on the interrupt mode, the driver will
  7564. * release the interrupt vector(s) for the message signaled interrupt.
  7565. **/
  7566. static void
  7567. lpfc_sli_disable_intr(struct lpfc_hba *phba)
  7568. {
  7569. /* Disable the currently initialized interrupt mode */
  7570. if (phba->intr_type == MSIX)
  7571. lpfc_sli_disable_msix(phba);
  7572. else if (phba->intr_type == MSI)
  7573. lpfc_sli_disable_msi(phba);
  7574. else if (phba->intr_type == INTx)
  7575. free_irq(phba->pcidev->irq, phba);
  7576. /* Reset interrupt management states */
  7577. phba->intr_type = NONE;
  7578. phba->sli.slistat.sli_intr = 0;
  7579. return;
  7580. }
  7581. /**
  7582. * lpfc_find_next_cpu - Find next available CPU that matches the phys_id
  7583. * @phba: pointer to lpfc hba data structure.
  7584. *
  7585. * Find next available CPU to use for IRQ to CPU affinity.
  7586. */
  7587. static int
  7588. lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id)
  7589. {
  7590. struct lpfc_vector_map_info *cpup;
  7591. int cpu;
  7592. cpup = phba->sli4_hba.cpu_map;
  7593. for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
  7594. /* CPU must be online */
  7595. if (cpu_online(cpu)) {
  7596. if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
  7597. (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) &&
  7598. (cpup->phys_id == phys_id)) {
  7599. return cpu;
  7600. }
  7601. }
  7602. cpup++;
  7603. }
  7604. /*
  7605. * If we get here, we have used ALL CPUs for the specific
  7606. * phys_id. Now we need to clear out lpfc_used_cpu and start
  7607. * reusing CPUs.
  7608. */
  7609. for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
  7610. if (lpfc_used_cpu[cpu] == phys_id)
  7611. lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY;
  7612. }
  7613. cpup = phba->sli4_hba.cpu_map;
  7614. for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
  7615. /* CPU must be online */
  7616. if (cpu_online(cpu)) {
  7617. if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
  7618. (cpup->phys_id == phys_id)) {
  7619. return cpu;
  7620. }
  7621. }
  7622. cpup++;
  7623. }
  7624. return LPFC_VECTOR_MAP_EMPTY;
  7625. }
  7626. /**
  7627. * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors
  7628. * @phba: pointer to lpfc hba data structure.
  7629. * @vectors: number of HBA vectors
  7630. *
  7631. * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector
  7632. * affinization across multple physical CPUs (numa nodes).
  7633. * In addition, this routine will assign an IO channel for each CPU
  7634. * to use when issuing I/Os.
  7635. */
  7636. static int
  7637. lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors)
  7638. {
  7639. int i, idx, saved_chann, used_chann, cpu, phys_id;
  7640. int max_phys_id, min_phys_id;
  7641. int num_io_channel, first_cpu, chan;
  7642. struct lpfc_vector_map_info *cpup;
  7643. #ifdef CONFIG_X86
  7644. struct cpuinfo_x86 *cpuinfo;
  7645. #endif
  7646. struct cpumask *mask;
  7647. uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1];
  7648. /* If there is no mapping, just return */
  7649. if (!phba->cfg_fcp_cpu_map)
  7650. return 1;
  7651. /* Init cpu_map array */
  7652. memset(phba->sli4_hba.cpu_map, 0xff,
  7653. (sizeof(struct lpfc_vector_map_info) *
  7654. phba->sli4_hba.num_present_cpu));
  7655. max_phys_id = 0;
  7656. min_phys_id = 0xff;
  7657. phys_id = 0;
  7658. num_io_channel = 0;
  7659. first_cpu = LPFC_VECTOR_MAP_EMPTY;
  7660. /* Update CPU map with physical id and core id of each CPU */
  7661. cpup = phba->sli4_hba.cpu_map;
  7662. for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
  7663. #ifdef CONFIG_X86
  7664. cpuinfo = &cpu_data(cpu);
  7665. cpup->phys_id = cpuinfo->phys_proc_id;
  7666. cpup->core_id = cpuinfo->cpu_core_id;
  7667. #else
  7668. /* No distinction between CPUs for other platforms */
  7669. cpup->phys_id = 0;
  7670. cpup->core_id = 0;
  7671. #endif
  7672. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7673. "3328 CPU physid %d coreid %d\n",
  7674. cpup->phys_id, cpup->core_id);
  7675. if (cpup->phys_id > max_phys_id)
  7676. max_phys_id = cpup->phys_id;
  7677. if (cpup->phys_id < min_phys_id)
  7678. min_phys_id = cpup->phys_id;
  7679. cpup++;
  7680. }
  7681. phys_id = min_phys_id;
  7682. /* Now associate the HBA vectors with specific CPUs */
  7683. for (idx = 0; idx < vectors; idx++) {
  7684. cpup = phba->sli4_hba.cpu_map;
  7685. cpu = lpfc_find_next_cpu(phba, phys_id);
  7686. if (cpu == LPFC_VECTOR_MAP_EMPTY) {
  7687. /* Try for all phys_id's */
  7688. for (i = 1; i < max_phys_id; i++) {
  7689. phys_id++;
  7690. if (phys_id > max_phys_id)
  7691. phys_id = min_phys_id;
  7692. cpu = lpfc_find_next_cpu(phba, phys_id);
  7693. if (cpu == LPFC_VECTOR_MAP_EMPTY)
  7694. continue;
  7695. goto found;
  7696. }
  7697. /* Use round robin for scheduling */
  7698. phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN;
  7699. chan = 0;
  7700. cpup = phba->sli4_hba.cpu_map;
  7701. for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
  7702. cpup->channel_id = chan;
  7703. cpup++;
  7704. chan++;
  7705. if (chan >= phba->cfg_fcp_io_channel)
  7706. chan = 0;
  7707. }
  7708. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7709. "3329 Cannot set affinity:"
  7710. "Error mapping vector %d (%d)\n",
  7711. idx, vectors);
  7712. return 0;
  7713. }
  7714. found:
  7715. cpup += cpu;
  7716. if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP)
  7717. lpfc_used_cpu[cpu] = phys_id;
  7718. /* Associate vector with selected CPU */
  7719. cpup->irq = phba->sli4_hba.msix_entries[idx].vector;
  7720. /* Associate IO channel with selected CPU */
  7721. cpup->channel_id = idx;
  7722. num_io_channel++;
  7723. if (first_cpu == LPFC_VECTOR_MAP_EMPTY)
  7724. first_cpu = cpu;
  7725. /* Now affinitize to the selected CPU */
  7726. mask = &cpup->maskbits;
  7727. cpumask_clear(mask);
  7728. cpumask_set_cpu(cpu, mask);
  7729. i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx].
  7730. vector, mask);
  7731. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7732. "3330 Set Affinity: CPU %d channel %d "
  7733. "irq %d (%x)\n",
  7734. cpu, cpup->channel_id,
  7735. phba->sli4_hba.msix_entries[idx].vector, i);
  7736. /* Spread vector mapping across multple physical CPU nodes */
  7737. phys_id++;
  7738. if (phys_id > max_phys_id)
  7739. phys_id = min_phys_id;
  7740. }
  7741. /*
  7742. * Finally fill in the IO channel for any remaining CPUs.
  7743. * At this point, all IO channels have been assigned to a specific
  7744. * MSIx vector, mapped to a specific CPU.
  7745. * Base the remaining IO channel assigned, to IO channels already
  7746. * assigned to other CPUs on the same phys_id.
  7747. */
  7748. for (i = min_phys_id; i <= max_phys_id; i++) {
  7749. /*
  7750. * If there are no io channels already mapped to
  7751. * this phys_id, just round robin thru the io_channels.
  7752. * Setup chann[] for round robin.
  7753. */
  7754. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
  7755. chann[idx] = idx;
  7756. saved_chann = 0;
  7757. used_chann = 0;
  7758. /*
  7759. * First build a list of IO channels already assigned
  7760. * to this phys_id before reassigning the same IO
  7761. * channels to the remaining CPUs.
  7762. */
  7763. cpup = phba->sli4_hba.cpu_map;
  7764. cpu = first_cpu;
  7765. cpup += cpu;
  7766. for (idx = 0; idx < phba->sli4_hba.num_present_cpu;
  7767. idx++) {
  7768. if (cpup->phys_id == i) {
  7769. /*
  7770. * Save any IO channels that are
  7771. * already mapped to this phys_id.
  7772. */
  7773. if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) {
  7774. chann[saved_chann] =
  7775. cpup->channel_id;
  7776. saved_chann++;
  7777. goto out;
  7778. }
  7779. /* See if we are using round-robin */
  7780. if (saved_chann == 0)
  7781. saved_chann =
  7782. phba->cfg_fcp_io_channel;
  7783. /* Associate next IO channel with CPU */
  7784. cpup->channel_id = chann[used_chann];
  7785. num_io_channel++;
  7786. used_chann++;
  7787. if (used_chann == saved_chann)
  7788. used_chann = 0;
  7789. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7790. "3331 Set IO_CHANN "
  7791. "CPU %d channel %d\n",
  7792. idx, cpup->channel_id);
  7793. }
  7794. out:
  7795. cpu++;
  7796. if (cpu >= phba->sli4_hba.num_present_cpu) {
  7797. cpup = phba->sli4_hba.cpu_map;
  7798. cpu = 0;
  7799. } else {
  7800. cpup++;
  7801. }
  7802. }
  7803. }
  7804. if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) {
  7805. cpup = phba->sli4_hba.cpu_map;
  7806. for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
  7807. if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) {
  7808. cpup->channel_id = 0;
  7809. num_io_channel++;
  7810. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7811. "3332 Assign IO_CHANN "
  7812. "CPU %d channel %d\n",
  7813. idx, cpup->channel_id);
  7814. }
  7815. cpup++;
  7816. }
  7817. }
  7818. /* Sanity check */
  7819. if (num_io_channel != phba->sli4_hba.num_present_cpu)
  7820. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7821. "3333 Set affinity mismatch:"
  7822. "%d chann != %d cpus: %d vectors\n",
  7823. num_io_channel, phba->sli4_hba.num_present_cpu,
  7824. vectors);
  7825. /* Enable using cpu affinity for scheduling */
  7826. phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU;
  7827. return 1;
  7828. }
  7829. /**
  7830. * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
  7831. * @phba: pointer to lpfc hba data structure.
  7832. *
  7833. * This routine is invoked to enable the MSI-X interrupt vectors to device
  7834. * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
  7835. * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
  7836. * enables either all or nothing, depending on the current availability of
  7837. * PCI vector resources. The device driver is responsible for calling the
  7838. * individual request_irq() to register each MSI-X vector with a interrupt
  7839. * handler, which is done in this function. Note that later when device is
  7840. * unloading, the driver should always call free_irq() on all MSI-X vectors
  7841. * it has done request_irq() on before calling pci_disable_msix(). Failure
  7842. * to do so results in a BUG_ON() and a device will be left with MSI-X
  7843. * enabled and leaks its vectors.
  7844. *
  7845. * Return codes
  7846. * 0 - successful
  7847. * other values - error
  7848. **/
  7849. static int
  7850. lpfc_sli4_enable_msix(struct lpfc_hba *phba)
  7851. {
  7852. int vectors, rc, index;
  7853. /* Set up MSI-X multi-message vectors */
  7854. for (index = 0; index < phba->cfg_fcp_io_channel; index++)
  7855. phba->sli4_hba.msix_entries[index].entry = index;
  7856. /* Configure MSI-X capability structure */
  7857. vectors = phba->cfg_fcp_io_channel;
  7858. enable_msix_vectors:
  7859. rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
  7860. vectors);
  7861. if (rc > 1) {
  7862. vectors = rc;
  7863. goto enable_msix_vectors;
  7864. } else if (rc) {
  7865. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7866. "0484 PCI enable MSI-X failed (%d)\n", rc);
  7867. goto msi_fail_out;
  7868. }
  7869. /* Log MSI-X vector assignment */
  7870. for (index = 0; index < vectors; index++)
  7871. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7872. "0489 MSI-X entry[%d]: vector=x%x "
  7873. "message=%d\n", index,
  7874. phba->sli4_hba.msix_entries[index].vector,
  7875. phba->sli4_hba.msix_entries[index].entry);
  7876. /* Assign MSI-X vectors to interrupt handlers */
  7877. for (index = 0; index < vectors; index++) {
  7878. memset(&phba->sli4_hba.handler_name[index], 0, 16);
  7879. sprintf((char *)&phba->sli4_hba.handler_name[index],
  7880. LPFC_DRIVER_HANDLER_NAME"%d", index);
  7881. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  7882. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  7883. atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
  7884. rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
  7885. &lpfc_sli4_hba_intr_handler, IRQF_SHARED,
  7886. (char *)&phba->sli4_hba.handler_name[index],
  7887. &phba->sli4_hba.fcp_eq_hdl[index]);
  7888. if (rc) {
  7889. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7890. "0486 MSI-X fast-path (%d) "
  7891. "request_irq failed (%d)\n", index, rc);
  7892. goto cfg_fail_out;
  7893. }
  7894. }
  7895. if (vectors != phba->cfg_fcp_io_channel) {
  7896. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7897. "3238 Reducing IO channels to match number of "
  7898. "MSI-X vectors, requested %d got %d\n",
  7899. phba->cfg_fcp_io_channel, vectors);
  7900. phba->cfg_fcp_io_channel = vectors;
  7901. }
  7902. lpfc_sli4_set_affinity(phba, vectors);
  7903. return rc;
  7904. cfg_fail_out:
  7905. /* free the irq already requested */
  7906. for (--index; index >= 0; index--) {
  7907. irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
  7908. vector, NULL);
  7909. free_irq(phba->sli4_hba.msix_entries[index].vector,
  7910. &phba->sli4_hba.fcp_eq_hdl[index]);
  7911. }
  7912. msi_fail_out:
  7913. /* Unconfigure MSI-X capability structure */
  7914. pci_disable_msix(phba->pcidev);
  7915. return rc;
  7916. }
  7917. /**
  7918. * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
  7919. * @phba: pointer to lpfc hba data structure.
  7920. *
  7921. * This routine is invoked to release the MSI-X vectors and then disable the
  7922. * MSI-X interrupt mode to device with SLI-4 interface spec.
  7923. **/
  7924. static void
  7925. lpfc_sli4_disable_msix(struct lpfc_hba *phba)
  7926. {
  7927. int index;
  7928. /* Free up MSI-X multi-message vectors */
  7929. for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
  7930. irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
  7931. vector, NULL);
  7932. free_irq(phba->sli4_hba.msix_entries[index].vector,
  7933. &phba->sli4_hba.fcp_eq_hdl[index]);
  7934. }
  7935. /* Disable MSI-X */
  7936. pci_disable_msix(phba->pcidev);
  7937. return;
  7938. }
  7939. /**
  7940. * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
  7941. * @phba: pointer to lpfc hba data structure.
  7942. *
  7943. * This routine is invoked to enable the MSI interrupt mode to device with
  7944. * SLI-4 interface spec. The kernel function pci_enable_msi() is called
  7945. * to enable the MSI vector. The device driver is responsible for calling
  7946. * the request_irq() to register MSI vector with a interrupt the handler,
  7947. * which is done in this function.
  7948. *
  7949. * Return codes
  7950. * 0 - successful
  7951. * other values - error
  7952. **/
  7953. static int
  7954. lpfc_sli4_enable_msi(struct lpfc_hba *phba)
  7955. {
  7956. int rc, index;
  7957. rc = pci_enable_msi(phba->pcidev);
  7958. if (!rc)
  7959. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7960. "0487 PCI enable MSI mode success.\n");
  7961. else {
  7962. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7963. "0488 PCI enable MSI mode failed (%d)\n", rc);
  7964. return rc;
  7965. }
  7966. rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  7967. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7968. if (rc) {
  7969. pci_disable_msi(phba->pcidev);
  7970. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7971. "0490 MSI request_irq failed (%d)\n", rc);
  7972. return rc;
  7973. }
  7974. for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
  7975. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  7976. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  7977. }
  7978. return 0;
  7979. }
  7980. /**
  7981. * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
  7982. * @phba: pointer to lpfc hba data structure.
  7983. *
  7984. * This routine is invoked to disable the MSI interrupt mode to device with
  7985. * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
  7986. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  7987. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  7988. * its vector.
  7989. **/
  7990. static void
  7991. lpfc_sli4_disable_msi(struct lpfc_hba *phba)
  7992. {
  7993. free_irq(phba->pcidev->irq, phba);
  7994. pci_disable_msi(phba->pcidev);
  7995. return;
  7996. }
  7997. /**
  7998. * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
  7999. * @phba: pointer to lpfc hba data structure.
  8000. *
  8001. * This routine is invoked to enable device interrupt and associate driver's
  8002. * interrupt handler(s) to interrupt vector(s) to device with SLI-4
  8003. * interface spec. Depends on the interrupt mode configured to the driver,
  8004. * the driver will try to fallback from the configured interrupt mode to an
  8005. * interrupt mode which is supported by the platform, kernel, and device in
  8006. * the order of:
  8007. * MSI-X -> MSI -> IRQ.
  8008. *
  8009. * Return codes
  8010. * 0 - successful
  8011. * other values - error
  8012. **/
  8013. static uint32_t
  8014. lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  8015. {
  8016. uint32_t intr_mode = LPFC_INTR_ERROR;
  8017. int retval, index;
  8018. if (cfg_mode == 2) {
  8019. /* Preparation before conf_msi mbox cmd */
  8020. retval = 0;
  8021. if (!retval) {
  8022. /* Now, try to enable MSI-X interrupt mode */
  8023. retval = lpfc_sli4_enable_msix(phba);
  8024. if (!retval) {
  8025. /* Indicate initialization to MSI-X mode */
  8026. phba->intr_type = MSIX;
  8027. intr_mode = 2;
  8028. }
  8029. }
  8030. }
  8031. /* Fallback to MSI if MSI-X initialization failed */
  8032. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  8033. retval = lpfc_sli4_enable_msi(phba);
  8034. if (!retval) {
  8035. /* Indicate initialization to MSI mode */
  8036. phba->intr_type = MSI;
  8037. intr_mode = 1;
  8038. }
  8039. }
  8040. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  8041. if (phba->intr_type == NONE) {
  8042. retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  8043. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  8044. if (!retval) {
  8045. /* Indicate initialization to INTx mode */
  8046. phba->intr_type = INTx;
  8047. intr_mode = 0;
  8048. for (index = 0; index < phba->cfg_fcp_io_channel;
  8049. index++) {
  8050. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  8051. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  8052. atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
  8053. fcp_eq_in_use, 1);
  8054. }
  8055. }
  8056. }
  8057. return intr_mode;
  8058. }
  8059. /**
  8060. * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
  8061. * @phba: pointer to lpfc hba data structure.
  8062. *
  8063. * This routine is invoked to disable device interrupt and disassociate
  8064. * the driver's interrupt handler(s) from interrupt vector(s) to device
  8065. * with SLI-4 interface spec. Depending on the interrupt mode, the driver
  8066. * will release the interrupt vector(s) for the message signaled interrupt.
  8067. **/
  8068. static void
  8069. lpfc_sli4_disable_intr(struct lpfc_hba *phba)
  8070. {
  8071. /* Disable the currently initialized interrupt mode */
  8072. if (phba->intr_type == MSIX)
  8073. lpfc_sli4_disable_msix(phba);
  8074. else if (phba->intr_type == MSI)
  8075. lpfc_sli4_disable_msi(phba);
  8076. else if (phba->intr_type == INTx)
  8077. free_irq(phba->pcidev->irq, phba);
  8078. /* Reset interrupt management states */
  8079. phba->intr_type = NONE;
  8080. phba->sli.slistat.sli_intr = 0;
  8081. return;
  8082. }
  8083. /**
  8084. * lpfc_unset_hba - Unset SLI3 hba device initialization
  8085. * @phba: pointer to lpfc hba data structure.
  8086. *
  8087. * This routine is invoked to unset the HBA device initialization steps to
  8088. * a device with SLI-3 interface spec.
  8089. **/
  8090. static void
  8091. lpfc_unset_hba(struct lpfc_hba *phba)
  8092. {
  8093. struct lpfc_vport *vport = phba->pport;
  8094. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  8095. spin_lock_irq(shost->host_lock);
  8096. vport->load_flag |= FC_UNLOADING;
  8097. spin_unlock_irq(shost->host_lock);
  8098. kfree(phba->vpi_bmask);
  8099. kfree(phba->vpi_ids);
  8100. lpfc_stop_hba_timers(phba);
  8101. phba->pport->work_port_events = 0;
  8102. lpfc_sli_hba_down(phba);
  8103. lpfc_sli_brdrestart(phba);
  8104. lpfc_sli_disable_intr(phba);
  8105. return;
  8106. }
  8107. /**
  8108. * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
  8109. * @phba: Pointer to HBA context object.
  8110. *
  8111. * This function is called in the SLI4 code path to wait for completion
  8112. * of device's XRIs exchange busy. It will check the XRI exchange busy
  8113. * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
  8114. * that, it will check the XRI exchange busy on outstanding FCP and ELS
  8115. * I/Os every 30 seconds, log error message, and wait forever. Only when
  8116. * all XRI exchange busy complete, the driver unload shall proceed with
  8117. * invoking the function reset ioctl mailbox command to the CNA and the
  8118. * the rest of the driver unload resource release.
  8119. **/
  8120. static void
  8121. lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
  8122. {
  8123. int wait_time = 0;
  8124. int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  8125. int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  8126. while (!fcp_xri_cmpl || !els_xri_cmpl) {
  8127. if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
  8128. if (!fcp_xri_cmpl)
  8129. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8130. "2877 FCP XRI exchange busy "
  8131. "wait time: %d seconds.\n",
  8132. wait_time/1000);
  8133. if (!els_xri_cmpl)
  8134. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8135. "2878 ELS XRI exchange busy "
  8136. "wait time: %d seconds.\n",
  8137. wait_time/1000);
  8138. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
  8139. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
  8140. } else {
  8141. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
  8142. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
  8143. }
  8144. fcp_xri_cmpl =
  8145. list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  8146. els_xri_cmpl =
  8147. list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  8148. }
  8149. }
  8150. /**
  8151. * lpfc_sli4_hba_unset - Unset the fcoe hba
  8152. * @phba: Pointer to HBA context object.
  8153. *
  8154. * This function is called in the SLI4 code path to reset the HBA's FCoE
  8155. * function. The caller is not required to hold any lock. This routine
  8156. * issues PCI function reset mailbox command to reset the FCoE function.
  8157. * At the end of the function, it calls lpfc_hba_down_post function to
  8158. * free any pending commands.
  8159. **/
  8160. static void
  8161. lpfc_sli4_hba_unset(struct lpfc_hba *phba)
  8162. {
  8163. int wait_cnt = 0;
  8164. LPFC_MBOXQ_t *mboxq;
  8165. struct pci_dev *pdev = phba->pcidev;
  8166. lpfc_stop_hba_timers(phba);
  8167. phba->sli4_hba.intr_enable = 0;
  8168. /*
  8169. * Gracefully wait out the potential current outstanding asynchronous
  8170. * mailbox command.
  8171. */
  8172. /* First, block any pending async mailbox command from posted */
  8173. spin_lock_irq(&phba->hbalock);
  8174. phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  8175. spin_unlock_irq(&phba->hbalock);
  8176. /* Now, trying to wait it out if we can */
  8177. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  8178. msleep(10);
  8179. if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
  8180. break;
  8181. }
  8182. /* Forcefully release the outstanding mailbox command if timed out */
  8183. if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  8184. spin_lock_irq(&phba->hbalock);
  8185. mboxq = phba->sli.mbox_active;
  8186. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8187. __lpfc_mbox_cmpl_put(phba, mboxq);
  8188. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8189. phba->sli.mbox_active = NULL;
  8190. spin_unlock_irq(&phba->hbalock);
  8191. }
  8192. /* Abort all iocbs associated with the hba */
  8193. lpfc_sli_hba_iocb_abort(phba);
  8194. /* Wait for completion of device XRI exchange busy */
  8195. lpfc_sli4_xri_exchange_busy_wait(phba);
  8196. /* Disable PCI subsystem interrupt */
  8197. lpfc_sli4_disable_intr(phba);
  8198. /* Disable SR-IOV if enabled */
  8199. if (phba->cfg_sriov_nr_virtfn)
  8200. pci_disable_sriov(pdev);
  8201. /* Stop kthread signal shall trigger work_done one more time */
  8202. kthread_stop(phba->worker_thread);
  8203. /* Reset SLI4 HBA FCoE function */
  8204. lpfc_pci_function_reset(phba);
  8205. lpfc_sli4_queue_destroy(phba);
  8206. /* Stop the SLI4 device port */
  8207. phba->pport->work_port_events = 0;
  8208. }
  8209. /**
  8210. * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
  8211. * @phba: Pointer to HBA context object.
  8212. * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
  8213. *
  8214. * This function is called in the SLI4 code path to read the port's
  8215. * sli4 capabilities.
  8216. *
  8217. * This function may be be called from any context that can block-wait
  8218. * for the completion. The expectation is that this routine is called
  8219. * typically from probe_one or from the online routine.
  8220. **/
  8221. int
  8222. lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  8223. {
  8224. int rc;
  8225. struct lpfc_mqe *mqe;
  8226. struct lpfc_pc_sli4_params *sli4_params;
  8227. uint32_t mbox_tmo;
  8228. rc = 0;
  8229. mqe = &mboxq->u.mqe;
  8230. /* Read the port's SLI4 Parameters port capabilities */
  8231. lpfc_pc_sli4_params(mboxq);
  8232. if (!phba->sli4_hba.intr_enable)
  8233. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  8234. else {
  8235. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  8236. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  8237. }
  8238. if (unlikely(rc))
  8239. return 1;
  8240. sli4_params = &phba->sli4_hba.pc_sli4_params;
  8241. sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
  8242. sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
  8243. sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
  8244. sli4_params->featurelevel_1 = bf_get(featurelevel_1,
  8245. &mqe->un.sli4_params);
  8246. sli4_params->featurelevel_2 = bf_get(featurelevel_2,
  8247. &mqe->un.sli4_params);
  8248. sli4_params->proto_types = mqe->un.sli4_params.word3;
  8249. sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
  8250. sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
  8251. sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
  8252. sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
  8253. sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
  8254. sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
  8255. sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
  8256. sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
  8257. sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
  8258. sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
  8259. sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
  8260. sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
  8261. sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
  8262. sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
  8263. sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
  8264. sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
  8265. sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
  8266. sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
  8267. sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
  8268. sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
  8269. /* Make sure that sge_supp_len can be handled by the driver */
  8270. if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
  8271. sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
  8272. return rc;
  8273. }
  8274. /**
  8275. * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
  8276. * @phba: Pointer to HBA context object.
  8277. * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
  8278. *
  8279. * This function is called in the SLI4 code path to read the port's
  8280. * sli4 capabilities.
  8281. *
  8282. * This function may be be called from any context that can block-wait
  8283. * for the completion. The expectation is that this routine is called
  8284. * typically from probe_one or from the online routine.
  8285. **/
  8286. int
  8287. lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  8288. {
  8289. int rc;
  8290. struct lpfc_mqe *mqe = &mboxq->u.mqe;
  8291. struct lpfc_pc_sli4_params *sli4_params;
  8292. uint32_t mbox_tmo;
  8293. int length;
  8294. struct lpfc_sli4_parameters *mbx_sli4_parameters;
  8295. /*
  8296. * By default, the driver assumes the SLI4 port requires RPI
  8297. * header postings. The SLI4_PARAM response will correct this
  8298. * assumption.
  8299. */
  8300. phba->sli4_hba.rpi_hdrs_in_use = 1;
  8301. /* Read the port's SLI4 Config Parameters */
  8302. length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
  8303. sizeof(struct lpfc_sli4_cfg_mhdr));
  8304. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  8305. LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
  8306. length, LPFC_SLI4_MBX_EMBED);
  8307. if (!phba->sli4_hba.intr_enable)
  8308. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  8309. else {
  8310. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  8311. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  8312. }
  8313. if (unlikely(rc))
  8314. return rc;
  8315. sli4_params = &phba->sli4_hba.pc_sli4_params;
  8316. mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
  8317. sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
  8318. sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
  8319. sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
  8320. sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
  8321. mbx_sli4_parameters);
  8322. sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
  8323. mbx_sli4_parameters);
  8324. if (bf_get(cfg_phwq, mbx_sli4_parameters))
  8325. phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
  8326. else
  8327. phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
  8328. sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
  8329. sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
  8330. sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
  8331. sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
  8332. sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
  8333. sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
  8334. sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
  8335. sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
  8336. mbx_sli4_parameters);
  8337. sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
  8338. mbx_sli4_parameters);
  8339. phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
  8340. phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
  8341. /* Make sure that sge_supp_len can be handled by the driver */
  8342. if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
  8343. sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
  8344. return 0;
  8345. }
  8346. /**
  8347. * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
  8348. * @pdev: pointer to PCI device
  8349. * @pid: pointer to PCI device identifier
  8350. *
  8351. * This routine is to be called to attach a device with SLI-3 interface spec
  8352. * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  8353. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  8354. * information of the device and driver to see if the driver state that it can
  8355. * support this kind of device. If the match is successful, the driver core
  8356. * invokes this routine. If this routine determines it can claim the HBA, it
  8357. * does all the initialization that it needs to do to handle the HBA properly.
  8358. *
  8359. * Return code
  8360. * 0 - driver can claim the device
  8361. * negative value - driver can not claim the device
  8362. **/
  8363. static int
  8364. lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
  8365. {
  8366. struct lpfc_hba *phba;
  8367. struct lpfc_vport *vport = NULL;
  8368. struct Scsi_Host *shost = NULL;
  8369. int error;
  8370. uint32_t cfg_mode, intr_mode;
  8371. /* Allocate memory for HBA structure */
  8372. phba = lpfc_hba_alloc(pdev);
  8373. if (!phba)
  8374. return -ENOMEM;
  8375. /* Perform generic PCI device enabling operation */
  8376. error = lpfc_enable_pci_dev(phba);
  8377. if (error)
  8378. goto out_free_phba;
  8379. /* Set up SLI API function jump table for PCI-device group-0 HBAs */
  8380. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
  8381. if (error)
  8382. goto out_disable_pci_dev;
  8383. /* Set up SLI-3 specific device PCI memory space */
  8384. error = lpfc_sli_pci_mem_setup(phba);
  8385. if (error) {
  8386. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8387. "1402 Failed to set up pci memory space.\n");
  8388. goto out_disable_pci_dev;
  8389. }
  8390. /* Set up phase-1 common device driver resources */
  8391. error = lpfc_setup_driver_resource_phase1(phba);
  8392. if (error) {
  8393. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8394. "1403 Failed to set up driver resource.\n");
  8395. goto out_unset_pci_mem_s3;
  8396. }
  8397. /* Set up SLI-3 specific device driver resources */
  8398. error = lpfc_sli_driver_resource_setup(phba);
  8399. if (error) {
  8400. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8401. "1404 Failed to set up driver resource.\n");
  8402. goto out_unset_pci_mem_s3;
  8403. }
  8404. /* Initialize and populate the iocb list per host */
  8405. error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
  8406. if (error) {
  8407. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8408. "1405 Failed to initialize iocb list.\n");
  8409. goto out_unset_driver_resource_s3;
  8410. }
  8411. /* Set up common device driver resources */
  8412. error = lpfc_setup_driver_resource_phase2(phba);
  8413. if (error) {
  8414. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8415. "1406 Failed to set up driver resource.\n");
  8416. goto out_free_iocb_list;
  8417. }
  8418. /* Get the default values for Model Name and Description */
  8419. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  8420. /* Create SCSI host to the physical port */
  8421. error = lpfc_create_shost(phba);
  8422. if (error) {
  8423. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8424. "1407 Failed to create scsi host.\n");
  8425. goto out_unset_driver_resource;
  8426. }
  8427. /* Configure sysfs attributes */
  8428. vport = phba->pport;
  8429. error = lpfc_alloc_sysfs_attr(vport);
  8430. if (error) {
  8431. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8432. "1476 Failed to allocate sysfs attr\n");
  8433. goto out_destroy_shost;
  8434. }
  8435. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  8436. /* Now, trying to enable interrupt and bring up the device */
  8437. cfg_mode = phba->cfg_use_msi;
  8438. while (true) {
  8439. /* Put device to a known state before enabling interrupt */
  8440. lpfc_stop_port(phba);
  8441. /* Configure and enable interrupt */
  8442. intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
  8443. if (intr_mode == LPFC_INTR_ERROR) {
  8444. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8445. "0431 Failed to enable interrupt.\n");
  8446. error = -ENODEV;
  8447. goto out_free_sysfs_attr;
  8448. }
  8449. /* SLI-3 HBA setup */
  8450. if (lpfc_sli_hba_setup(phba)) {
  8451. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8452. "1477 Failed to set up hba\n");
  8453. error = -ENODEV;
  8454. goto out_remove_device;
  8455. }
  8456. /* Wait 50ms for the interrupts of previous mailbox commands */
  8457. msleep(50);
  8458. /* Check active interrupts on message signaled interrupts */
  8459. if (intr_mode == 0 ||
  8460. phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
  8461. /* Log the current active interrupt mode */
  8462. phba->intr_mode = intr_mode;
  8463. lpfc_log_intr_mode(phba, intr_mode);
  8464. break;
  8465. } else {
  8466. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8467. "0447 Configure interrupt mode (%d) "
  8468. "failed active interrupt test.\n",
  8469. intr_mode);
  8470. /* Disable the current interrupt mode */
  8471. lpfc_sli_disable_intr(phba);
  8472. /* Try next level of interrupt mode */
  8473. cfg_mode = --intr_mode;
  8474. }
  8475. }
  8476. /* Perform post initialization setup */
  8477. lpfc_post_init_setup(phba);
  8478. /* Check if there are static vports to be created. */
  8479. lpfc_create_static_vport(phba);
  8480. return 0;
  8481. out_remove_device:
  8482. lpfc_unset_hba(phba);
  8483. out_free_sysfs_attr:
  8484. lpfc_free_sysfs_attr(vport);
  8485. out_destroy_shost:
  8486. lpfc_destroy_shost(phba);
  8487. out_unset_driver_resource:
  8488. lpfc_unset_driver_resource_phase2(phba);
  8489. out_free_iocb_list:
  8490. lpfc_free_iocb_list(phba);
  8491. out_unset_driver_resource_s3:
  8492. lpfc_sli_driver_resource_unset(phba);
  8493. out_unset_pci_mem_s3:
  8494. lpfc_sli_pci_mem_unset(phba);
  8495. out_disable_pci_dev:
  8496. lpfc_disable_pci_dev(phba);
  8497. if (shost)
  8498. scsi_host_put(shost);
  8499. out_free_phba:
  8500. lpfc_hba_free(phba);
  8501. return error;
  8502. }
  8503. /**
  8504. * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
  8505. * @pdev: pointer to PCI device
  8506. *
  8507. * This routine is to be called to disattach a device with SLI-3 interface
  8508. * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  8509. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  8510. * device to be removed from the PCI subsystem properly.
  8511. **/
  8512. static void
  8513. lpfc_pci_remove_one_s3(struct pci_dev *pdev)
  8514. {
  8515. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8516. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  8517. struct lpfc_vport **vports;
  8518. struct lpfc_hba *phba = vport->phba;
  8519. int i;
  8520. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  8521. spin_lock_irq(&phba->hbalock);
  8522. vport->load_flag |= FC_UNLOADING;
  8523. spin_unlock_irq(&phba->hbalock);
  8524. lpfc_free_sysfs_attr(vport);
  8525. /* Release all the vports against this physical port */
  8526. vports = lpfc_create_vport_work_array(phba);
  8527. if (vports != NULL)
  8528. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  8529. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  8530. continue;
  8531. fc_vport_terminate(vports[i]->fc_vport);
  8532. }
  8533. lpfc_destroy_vport_work_array(phba, vports);
  8534. /* Remove FC host and then SCSI host with the physical port */
  8535. fc_remove_host(shost);
  8536. scsi_remove_host(shost);
  8537. lpfc_cleanup(vport);
  8538. /*
  8539. * Bring down the SLI Layer. This step disable all interrupts,
  8540. * clears the rings, discards all mailbox commands, and resets
  8541. * the HBA.
  8542. */
  8543. /* HBA interrupt will be disabled after this call */
  8544. lpfc_sli_hba_down(phba);
  8545. /* Stop kthread signal shall trigger work_done one more time */
  8546. kthread_stop(phba->worker_thread);
  8547. /* Final cleanup of txcmplq and reset the HBA */
  8548. lpfc_sli_brdrestart(phba);
  8549. kfree(phba->vpi_bmask);
  8550. kfree(phba->vpi_ids);
  8551. lpfc_stop_hba_timers(phba);
  8552. spin_lock_irq(&phba->hbalock);
  8553. list_del_init(&vport->listentry);
  8554. spin_unlock_irq(&phba->hbalock);
  8555. lpfc_debugfs_terminate(vport);
  8556. /* Disable SR-IOV if enabled */
  8557. if (phba->cfg_sriov_nr_virtfn)
  8558. pci_disable_sriov(pdev);
  8559. /* Disable interrupt */
  8560. lpfc_sli_disable_intr(phba);
  8561. pci_set_drvdata(pdev, NULL);
  8562. scsi_host_put(shost);
  8563. /*
  8564. * Call scsi_free before mem_free since scsi bufs are released to their
  8565. * corresponding pools here.
  8566. */
  8567. lpfc_scsi_free(phba);
  8568. lpfc_mem_free_all(phba);
  8569. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  8570. phba->hbqslimp.virt, phba->hbqslimp.phys);
  8571. /* Free resources associated with SLI2 interface */
  8572. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  8573. phba->slim2p.virt, phba->slim2p.phys);
  8574. /* unmap adapter SLIM and Control Registers */
  8575. iounmap(phba->ctrl_regs_memmap_p);
  8576. iounmap(phba->slim_memmap_p);
  8577. lpfc_hba_free(phba);
  8578. pci_release_selected_regions(pdev, bars);
  8579. pci_disable_device(pdev);
  8580. }
  8581. /**
  8582. * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
  8583. * @pdev: pointer to PCI device
  8584. * @msg: power management message
  8585. *
  8586. * This routine is to be called from the kernel's PCI subsystem to support
  8587. * system Power Management (PM) to device with SLI-3 interface spec. When
  8588. * PM invokes this method, it quiesces the device by stopping the driver's
  8589. * worker thread for the device, turning off device's interrupt and DMA,
  8590. * and bring the device offline. Note that as the driver implements the
  8591. * minimum PM requirements to a power-aware driver's PM support for the
  8592. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  8593. * to the suspend() method call will be treated as SUSPEND and the driver will
  8594. * fully reinitialize its device during resume() method call, the driver will
  8595. * set device to PCI_D3hot state in PCI config space instead of setting it
  8596. * according to the @msg provided by the PM.
  8597. *
  8598. * Return code
  8599. * 0 - driver suspended the device
  8600. * Error otherwise
  8601. **/
  8602. static int
  8603. lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
  8604. {
  8605. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8606. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8607. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8608. "0473 PCI device Power Management suspend.\n");
  8609. /* Bring down the device */
  8610. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  8611. lpfc_offline(phba);
  8612. kthread_stop(phba->worker_thread);
  8613. /* Disable interrupt from device */
  8614. lpfc_sli_disable_intr(phba);
  8615. /* Save device state to PCI config space */
  8616. pci_save_state(pdev);
  8617. pci_set_power_state(pdev, PCI_D3hot);
  8618. return 0;
  8619. }
  8620. /**
  8621. * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
  8622. * @pdev: pointer to PCI device
  8623. *
  8624. * This routine is to be called from the kernel's PCI subsystem to support
  8625. * system Power Management (PM) to device with SLI-3 interface spec. When PM
  8626. * invokes this method, it restores the device's PCI config space state and
  8627. * fully reinitializes the device and brings it online. Note that as the
  8628. * driver implements the minimum PM requirements to a power-aware driver's
  8629. * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
  8630. * FREEZE) to the suspend() method call will be treated as SUSPEND and the
  8631. * driver will fully reinitialize its device during resume() method call,
  8632. * the device will be set to PCI_D0 directly in PCI config space before
  8633. * restoring the state.
  8634. *
  8635. * Return code
  8636. * 0 - driver suspended the device
  8637. * Error otherwise
  8638. **/
  8639. static int
  8640. lpfc_pci_resume_one_s3(struct pci_dev *pdev)
  8641. {
  8642. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8643. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8644. uint32_t intr_mode;
  8645. int error;
  8646. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8647. "0452 PCI device Power Management resume.\n");
  8648. /* Restore device state from PCI config space */
  8649. pci_set_power_state(pdev, PCI_D0);
  8650. pci_restore_state(pdev);
  8651. /*
  8652. * As the new kernel behavior of pci_restore_state() API call clears
  8653. * device saved_state flag, need to save the restored state again.
  8654. */
  8655. pci_save_state(pdev);
  8656. if (pdev->is_busmaster)
  8657. pci_set_master(pdev);
  8658. /* Startup the kernel thread for this host adapter. */
  8659. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  8660. "lpfc_worker_%d", phba->brd_no);
  8661. if (IS_ERR(phba->worker_thread)) {
  8662. error = PTR_ERR(phba->worker_thread);
  8663. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8664. "0434 PM resume failed to start worker "
  8665. "thread: error=x%x.\n", error);
  8666. return error;
  8667. }
  8668. /* Configure and enable interrupt */
  8669. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  8670. if (intr_mode == LPFC_INTR_ERROR) {
  8671. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8672. "0430 PM resume Failed to enable interrupt\n");
  8673. return -EIO;
  8674. } else
  8675. phba->intr_mode = intr_mode;
  8676. /* Restart HBA and bring it online */
  8677. lpfc_sli_brdrestart(phba);
  8678. lpfc_online(phba);
  8679. /* Log the current active interrupt mode */
  8680. lpfc_log_intr_mode(phba, phba->intr_mode);
  8681. return 0;
  8682. }
  8683. /**
  8684. * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
  8685. * @phba: pointer to lpfc hba data structure.
  8686. *
  8687. * This routine is called to prepare the SLI3 device for PCI slot recover. It
  8688. * aborts all the outstanding SCSI I/Os to the pci device.
  8689. **/
  8690. static void
  8691. lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
  8692. {
  8693. struct lpfc_sli *psli = &phba->sli;
  8694. struct lpfc_sli_ring *pring;
  8695. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8696. "2723 PCI channel I/O abort preparing for recovery\n");
  8697. /*
  8698. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  8699. * and let the SCSI mid-layer to retry them to recover.
  8700. */
  8701. pring = &psli->ring[psli->fcp_ring];
  8702. lpfc_sli_abort_iocb_ring(phba, pring);
  8703. }
  8704. /**
  8705. * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
  8706. * @phba: pointer to lpfc hba data structure.
  8707. *
  8708. * This routine is called to prepare the SLI3 device for PCI slot reset. It
  8709. * disables the device interrupt and pci device, and aborts the internal FCP
  8710. * pending I/Os.
  8711. **/
  8712. static void
  8713. lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
  8714. {
  8715. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8716. "2710 PCI channel disable preparing for reset\n");
  8717. /* Block any management I/Os to the device */
  8718. lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
  8719. /* Block all SCSI devices' I/Os on the host */
  8720. lpfc_scsi_dev_block(phba);
  8721. /* Flush all driver's outstanding SCSI I/Os as we are to reset */
  8722. lpfc_sli_flush_fcp_rings(phba);
  8723. /* stop all timers */
  8724. lpfc_stop_hba_timers(phba);
  8725. /* Disable interrupt and pci device */
  8726. lpfc_sli_disable_intr(phba);
  8727. pci_disable_device(phba->pcidev);
  8728. }
  8729. /**
  8730. * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
  8731. * @phba: pointer to lpfc hba data structure.
  8732. *
  8733. * This routine is called to prepare the SLI3 device for PCI slot permanently
  8734. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  8735. * pending I/Os.
  8736. **/
  8737. static void
  8738. lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  8739. {
  8740. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8741. "2711 PCI channel permanent disable for failure\n");
  8742. /* Block all SCSI devices' I/Os on the host */
  8743. lpfc_scsi_dev_block(phba);
  8744. /* stop all timers */
  8745. lpfc_stop_hba_timers(phba);
  8746. /* Clean up all driver's outstanding SCSI I/Os */
  8747. lpfc_sli_flush_fcp_rings(phba);
  8748. }
  8749. /**
  8750. * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
  8751. * @pdev: pointer to PCI device.
  8752. * @state: the current PCI connection state.
  8753. *
  8754. * This routine is called from the PCI subsystem for I/O error handling to
  8755. * device with SLI-3 interface spec. This function is called by the PCI
  8756. * subsystem after a PCI bus error affecting this device has been detected.
  8757. * When this function is invoked, it will need to stop all the I/Os and
  8758. * interrupt(s) to the device. Once that is done, it will return
  8759. * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
  8760. * as desired.
  8761. *
  8762. * Return codes
  8763. * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
  8764. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  8765. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8766. **/
  8767. static pci_ers_result_t
  8768. lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
  8769. {
  8770. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8771. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8772. switch (state) {
  8773. case pci_channel_io_normal:
  8774. /* Non-fatal error, prepare for recovery */
  8775. lpfc_sli_prep_dev_for_recover(phba);
  8776. return PCI_ERS_RESULT_CAN_RECOVER;
  8777. case pci_channel_io_frozen:
  8778. /* Fatal error, prepare for slot reset */
  8779. lpfc_sli_prep_dev_for_reset(phba);
  8780. return PCI_ERS_RESULT_NEED_RESET;
  8781. case pci_channel_io_perm_failure:
  8782. /* Permanent failure, prepare for device down */
  8783. lpfc_sli_prep_dev_for_perm_failure(phba);
  8784. return PCI_ERS_RESULT_DISCONNECT;
  8785. default:
  8786. /* Unknown state, prepare and request slot reset */
  8787. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8788. "0472 Unknown PCI error state: x%x\n", state);
  8789. lpfc_sli_prep_dev_for_reset(phba);
  8790. return PCI_ERS_RESULT_NEED_RESET;
  8791. }
  8792. }
  8793. /**
  8794. * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
  8795. * @pdev: pointer to PCI device.
  8796. *
  8797. * This routine is called from the PCI subsystem for error handling to
  8798. * device with SLI-3 interface spec. This is called after PCI bus has been
  8799. * reset to restart the PCI card from scratch, as if from a cold-boot.
  8800. * During the PCI subsystem error recovery, after driver returns
  8801. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  8802. * recovery and then call this routine before calling the .resume method
  8803. * to recover the device. This function will initialize the HBA device,
  8804. * enable the interrupt, but it will just put the HBA to offline state
  8805. * without passing any I/O traffic.
  8806. *
  8807. * Return codes
  8808. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  8809. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8810. */
  8811. static pci_ers_result_t
  8812. lpfc_io_slot_reset_s3(struct pci_dev *pdev)
  8813. {
  8814. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8815. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8816. struct lpfc_sli *psli = &phba->sli;
  8817. uint32_t intr_mode;
  8818. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  8819. if (pci_enable_device_mem(pdev)) {
  8820. printk(KERN_ERR "lpfc: Cannot re-enable "
  8821. "PCI device after reset.\n");
  8822. return PCI_ERS_RESULT_DISCONNECT;
  8823. }
  8824. pci_restore_state(pdev);
  8825. /*
  8826. * As the new kernel behavior of pci_restore_state() API call clears
  8827. * device saved_state flag, need to save the restored state again.
  8828. */
  8829. pci_save_state(pdev);
  8830. if (pdev->is_busmaster)
  8831. pci_set_master(pdev);
  8832. spin_lock_irq(&phba->hbalock);
  8833. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  8834. spin_unlock_irq(&phba->hbalock);
  8835. /* Configure and enable interrupt */
  8836. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  8837. if (intr_mode == LPFC_INTR_ERROR) {
  8838. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8839. "0427 Cannot re-enable interrupt after "
  8840. "slot reset.\n");
  8841. return PCI_ERS_RESULT_DISCONNECT;
  8842. } else
  8843. phba->intr_mode = intr_mode;
  8844. /* Take device offline, it will perform cleanup */
  8845. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  8846. lpfc_offline(phba);
  8847. lpfc_sli_brdrestart(phba);
  8848. /* Log the current active interrupt mode */
  8849. lpfc_log_intr_mode(phba, phba->intr_mode);
  8850. return PCI_ERS_RESULT_RECOVERED;
  8851. }
  8852. /**
  8853. * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
  8854. * @pdev: pointer to PCI device
  8855. *
  8856. * This routine is called from the PCI subsystem for error handling to device
  8857. * with SLI-3 interface spec. It is called when kernel error recovery tells
  8858. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  8859. * error recovery. After this call, traffic can start to flow from this device
  8860. * again.
  8861. */
  8862. static void
  8863. lpfc_io_resume_s3(struct pci_dev *pdev)
  8864. {
  8865. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8866. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8867. /* Bring device online, it will be no-op for non-fatal error resume */
  8868. lpfc_online(phba);
  8869. /* Clean up Advanced Error Reporting (AER) if needed */
  8870. if (phba->hba_flag & HBA_AER_ENABLED)
  8871. pci_cleanup_aer_uncorrect_error_status(pdev);
  8872. }
  8873. /**
  8874. * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
  8875. * @phba: pointer to lpfc hba data structure.
  8876. *
  8877. * returns the number of ELS/CT IOCBs to reserve
  8878. **/
  8879. int
  8880. lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
  8881. {
  8882. int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
  8883. if (phba->sli_rev == LPFC_SLI_REV4) {
  8884. if (max_xri <= 100)
  8885. return 10;
  8886. else if (max_xri <= 256)
  8887. return 25;
  8888. else if (max_xri <= 512)
  8889. return 50;
  8890. else if (max_xri <= 1024)
  8891. return 100;
  8892. else if (max_xri <= 1536)
  8893. return 150;
  8894. else if (max_xri <= 2048)
  8895. return 200;
  8896. else
  8897. return 250;
  8898. } else
  8899. return 0;
  8900. }
  8901. /**
  8902. * lpfc_write_firmware - attempt to write a firmware image to the port
  8903. * @fw: pointer to firmware image returned from request_firmware.
  8904. * @phba: pointer to lpfc hba data structure.
  8905. *
  8906. **/
  8907. static void
  8908. lpfc_write_firmware(const struct firmware *fw, void *context)
  8909. {
  8910. struct lpfc_hba *phba = (struct lpfc_hba *)context;
  8911. char fwrev[FW_REV_STR_SIZE];
  8912. struct lpfc_grp_hdr *image;
  8913. struct list_head dma_buffer_list;
  8914. int i, rc = 0;
  8915. struct lpfc_dmabuf *dmabuf, *next;
  8916. uint32_t offset = 0, temp_offset = 0;
  8917. /* It can be null in no-wait mode, sanity check */
  8918. if (!fw) {
  8919. rc = -ENXIO;
  8920. goto out;
  8921. }
  8922. image = (struct lpfc_grp_hdr *)fw->data;
  8923. INIT_LIST_HEAD(&dma_buffer_list);
  8924. if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
  8925. (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
  8926. LPFC_FILE_TYPE_GROUP) ||
  8927. (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
  8928. (be32_to_cpu(image->size) != fw->size)) {
  8929. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8930. "3022 Invalid FW image found. "
  8931. "Magic:%x Type:%x ID:%x\n",
  8932. be32_to_cpu(image->magic_number),
  8933. bf_get_be32(lpfc_grp_hdr_file_type, image),
  8934. bf_get_be32(lpfc_grp_hdr_id, image));
  8935. rc = -EINVAL;
  8936. goto release_out;
  8937. }
  8938. lpfc_decode_firmware_rev(phba, fwrev, 1);
  8939. if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
  8940. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8941. "3023 Updating Firmware, Current Version:%s "
  8942. "New Version:%s\n",
  8943. fwrev, image->revision);
  8944. for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
  8945. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
  8946. GFP_KERNEL);
  8947. if (!dmabuf) {
  8948. rc = -ENOMEM;
  8949. goto release_out;
  8950. }
  8951. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8952. SLI4_PAGE_SIZE,
  8953. &dmabuf->phys,
  8954. GFP_KERNEL);
  8955. if (!dmabuf->virt) {
  8956. kfree(dmabuf);
  8957. rc = -ENOMEM;
  8958. goto release_out;
  8959. }
  8960. list_add_tail(&dmabuf->list, &dma_buffer_list);
  8961. }
  8962. while (offset < fw->size) {
  8963. temp_offset = offset;
  8964. list_for_each_entry(dmabuf, &dma_buffer_list, list) {
  8965. if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
  8966. memcpy(dmabuf->virt,
  8967. fw->data + temp_offset,
  8968. fw->size - temp_offset);
  8969. temp_offset = fw->size;
  8970. break;
  8971. }
  8972. memcpy(dmabuf->virt, fw->data + temp_offset,
  8973. SLI4_PAGE_SIZE);
  8974. temp_offset += SLI4_PAGE_SIZE;
  8975. }
  8976. rc = lpfc_wr_object(phba, &dma_buffer_list,
  8977. (fw->size - offset), &offset);
  8978. if (rc)
  8979. goto release_out;
  8980. }
  8981. rc = offset;
  8982. }
  8983. release_out:
  8984. list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
  8985. list_del(&dmabuf->list);
  8986. dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
  8987. dmabuf->virt, dmabuf->phys);
  8988. kfree(dmabuf);
  8989. }
  8990. release_firmware(fw);
  8991. out:
  8992. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8993. "3024 Firmware update done: %d.\n", rc);
  8994. return;
  8995. }
  8996. /**
  8997. * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
  8998. * @phba: pointer to lpfc hba data structure.
  8999. *
  9000. * This routine is called to perform Linux generic firmware upgrade on device
  9001. * that supports such feature.
  9002. **/
  9003. int
  9004. lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
  9005. {
  9006. uint8_t file_name[ELX_MODEL_NAME_SIZE];
  9007. int ret;
  9008. const struct firmware *fw;
  9009. /* Only supported on SLI4 interface type 2 for now */
  9010. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  9011. LPFC_SLI_INTF_IF_TYPE_2)
  9012. return -EPERM;
  9013. snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
  9014. if (fw_upgrade == INT_FW_UPGRADE) {
  9015. ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
  9016. file_name, &phba->pcidev->dev,
  9017. GFP_KERNEL, (void *)phba,
  9018. lpfc_write_firmware);
  9019. } else if (fw_upgrade == RUN_FW_UPGRADE) {
  9020. ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
  9021. if (!ret)
  9022. lpfc_write_firmware(fw, (void *)phba);
  9023. } else {
  9024. ret = -EINVAL;
  9025. }
  9026. return ret;
  9027. }
  9028. /**
  9029. * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
  9030. * @pdev: pointer to PCI device
  9031. * @pid: pointer to PCI device identifier
  9032. *
  9033. * This routine is called from the kernel's PCI subsystem to device with
  9034. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  9035. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  9036. * information of the device and driver to see if the driver state that it
  9037. * can support this kind of device. If the match is successful, the driver
  9038. * core invokes this routine. If this routine determines it can claim the HBA,
  9039. * it does all the initialization that it needs to do to handle the HBA
  9040. * properly.
  9041. *
  9042. * Return code
  9043. * 0 - driver can claim the device
  9044. * negative value - driver can not claim the device
  9045. **/
  9046. static int
  9047. lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
  9048. {
  9049. struct lpfc_hba *phba;
  9050. struct lpfc_vport *vport = NULL;
  9051. struct Scsi_Host *shost = NULL;
  9052. int error, ret;
  9053. uint32_t cfg_mode, intr_mode;
  9054. int adjusted_fcp_io_channel;
  9055. /* Allocate memory for HBA structure */
  9056. phba = lpfc_hba_alloc(pdev);
  9057. if (!phba)
  9058. return -ENOMEM;
  9059. /* Perform generic PCI device enabling operation */
  9060. error = lpfc_enable_pci_dev(phba);
  9061. if (error)
  9062. goto out_free_phba;
  9063. /* Set up SLI API function jump table for PCI-device group-1 HBAs */
  9064. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
  9065. if (error)
  9066. goto out_disable_pci_dev;
  9067. /* Set up SLI-4 specific device PCI memory space */
  9068. error = lpfc_sli4_pci_mem_setup(phba);
  9069. if (error) {
  9070. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9071. "1410 Failed to set up pci memory space.\n");
  9072. goto out_disable_pci_dev;
  9073. }
  9074. /* Set up phase-1 common device driver resources */
  9075. error = lpfc_setup_driver_resource_phase1(phba);
  9076. if (error) {
  9077. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9078. "1411 Failed to set up driver resource.\n");
  9079. goto out_unset_pci_mem_s4;
  9080. }
  9081. /* Set up SLI-4 Specific device driver resources */
  9082. error = lpfc_sli4_driver_resource_setup(phba);
  9083. if (error) {
  9084. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9085. "1412 Failed to set up driver resource.\n");
  9086. goto out_unset_pci_mem_s4;
  9087. }
  9088. /* Initialize and populate the iocb list per host */
  9089. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9090. "2821 initialize iocb list %d.\n",
  9091. phba->cfg_iocb_cnt*1024);
  9092. error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
  9093. if (error) {
  9094. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9095. "1413 Failed to initialize iocb list.\n");
  9096. goto out_unset_driver_resource_s4;
  9097. }
  9098. INIT_LIST_HEAD(&phba->active_rrq_list);
  9099. INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
  9100. /* Set up common device driver resources */
  9101. error = lpfc_setup_driver_resource_phase2(phba);
  9102. if (error) {
  9103. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9104. "1414 Failed to set up driver resource.\n");
  9105. goto out_free_iocb_list;
  9106. }
  9107. /* Get the default values for Model Name and Description */
  9108. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  9109. /* Create SCSI host to the physical port */
  9110. error = lpfc_create_shost(phba);
  9111. if (error) {
  9112. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9113. "1415 Failed to create scsi host.\n");
  9114. goto out_unset_driver_resource;
  9115. }
  9116. /* Configure sysfs attributes */
  9117. vport = phba->pport;
  9118. error = lpfc_alloc_sysfs_attr(vport);
  9119. if (error) {
  9120. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9121. "1416 Failed to allocate sysfs attr\n");
  9122. goto out_destroy_shost;
  9123. }
  9124. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  9125. /* Now, trying to enable interrupt and bring up the device */
  9126. cfg_mode = phba->cfg_use_msi;
  9127. /* Put device to a known state before enabling interrupt */
  9128. lpfc_stop_port(phba);
  9129. /* Configure and enable interrupt */
  9130. intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
  9131. if (intr_mode == LPFC_INTR_ERROR) {
  9132. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9133. "0426 Failed to enable interrupt.\n");
  9134. error = -ENODEV;
  9135. goto out_free_sysfs_attr;
  9136. }
  9137. /* Default to single EQ for non-MSI-X */
  9138. if (phba->intr_type != MSIX)
  9139. adjusted_fcp_io_channel = 1;
  9140. else
  9141. adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
  9142. phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
  9143. /* Set up SLI-4 HBA */
  9144. if (lpfc_sli4_hba_setup(phba)) {
  9145. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9146. "1421 Failed to set up hba\n");
  9147. error = -ENODEV;
  9148. goto out_disable_intr;
  9149. }
  9150. /* Log the current active interrupt mode */
  9151. phba->intr_mode = intr_mode;
  9152. lpfc_log_intr_mode(phba, intr_mode);
  9153. /* Perform post initialization setup */
  9154. lpfc_post_init_setup(phba);
  9155. /* check for firmware upgrade or downgrade */
  9156. if (phba->cfg_request_firmware_upgrade)
  9157. ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
  9158. /* Check if there are static vports to be created. */
  9159. lpfc_create_static_vport(phba);
  9160. return 0;
  9161. out_disable_intr:
  9162. lpfc_sli4_disable_intr(phba);
  9163. out_free_sysfs_attr:
  9164. lpfc_free_sysfs_attr(vport);
  9165. out_destroy_shost:
  9166. lpfc_destroy_shost(phba);
  9167. out_unset_driver_resource:
  9168. lpfc_unset_driver_resource_phase2(phba);
  9169. out_free_iocb_list:
  9170. lpfc_free_iocb_list(phba);
  9171. out_unset_driver_resource_s4:
  9172. lpfc_sli4_driver_resource_unset(phba);
  9173. out_unset_pci_mem_s4:
  9174. lpfc_sli4_pci_mem_unset(phba);
  9175. out_disable_pci_dev:
  9176. lpfc_disable_pci_dev(phba);
  9177. if (shost)
  9178. scsi_host_put(shost);
  9179. out_free_phba:
  9180. lpfc_hba_free(phba);
  9181. return error;
  9182. }
  9183. /**
  9184. * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
  9185. * @pdev: pointer to PCI device
  9186. *
  9187. * This routine is called from the kernel's PCI subsystem to device with
  9188. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  9189. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  9190. * device to be removed from the PCI subsystem properly.
  9191. **/
  9192. static void
  9193. lpfc_pci_remove_one_s4(struct pci_dev *pdev)
  9194. {
  9195. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9196. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  9197. struct lpfc_vport **vports;
  9198. struct lpfc_hba *phba = vport->phba;
  9199. int i;
  9200. /* Mark the device unloading flag */
  9201. spin_lock_irq(&phba->hbalock);
  9202. vport->load_flag |= FC_UNLOADING;
  9203. spin_unlock_irq(&phba->hbalock);
  9204. /* Free the HBA sysfs attributes */
  9205. lpfc_free_sysfs_attr(vport);
  9206. /* Release all the vports against this physical port */
  9207. vports = lpfc_create_vport_work_array(phba);
  9208. if (vports != NULL)
  9209. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  9210. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  9211. continue;
  9212. fc_vport_terminate(vports[i]->fc_vport);
  9213. }
  9214. lpfc_destroy_vport_work_array(phba, vports);
  9215. /* Remove FC host and then SCSI host with the physical port */
  9216. fc_remove_host(shost);
  9217. scsi_remove_host(shost);
  9218. /* Perform cleanup on the physical port */
  9219. lpfc_cleanup(vport);
  9220. /*
  9221. * Bring down the SLI Layer. This step disables all interrupts,
  9222. * clears the rings, discards all mailbox commands, and resets
  9223. * the HBA FCoE function.
  9224. */
  9225. lpfc_debugfs_terminate(vport);
  9226. lpfc_sli4_hba_unset(phba);
  9227. spin_lock_irq(&phba->hbalock);
  9228. list_del_init(&vport->listentry);
  9229. spin_unlock_irq(&phba->hbalock);
  9230. /* Perform scsi free before driver resource_unset since scsi
  9231. * buffers are released to their corresponding pools here.
  9232. */
  9233. lpfc_scsi_free(phba);
  9234. lpfc_sli4_driver_resource_unset(phba);
  9235. /* Unmap adapter Control and Doorbell registers */
  9236. lpfc_sli4_pci_mem_unset(phba);
  9237. /* Release PCI resources and disable device's PCI function */
  9238. scsi_host_put(shost);
  9239. lpfc_disable_pci_dev(phba);
  9240. /* Finally, free the driver's device data structure */
  9241. lpfc_hba_free(phba);
  9242. return;
  9243. }
  9244. /**
  9245. * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
  9246. * @pdev: pointer to PCI device
  9247. * @msg: power management message
  9248. *
  9249. * This routine is called from the kernel's PCI subsystem to support system
  9250. * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
  9251. * this method, it quiesces the device by stopping the driver's worker
  9252. * thread for the device, turning off device's interrupt and DMA, and bring
  9253. * the device offline. Note that as the driver implements the minimum PM
  9254. * requirements to a power-aware driver's PM support for suspend/resume -- all
  9255. * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
  9256. * method call will be treated as SUSPEND and the driver will fully
  9257. * reinitialize its device during resume() method call, the driver will set
  9258. * device to PCI_D3hot state in PCI config space instead of setting it
  9259. * according to the @msg provided by the PM.
  9260. *
  9261. * Return code
  9262. * 0 - driver suspended the device
  9263. * Error otherwise
  9264. **/
  9265. static int
  9266. lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
  9267. {
  9268. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9269. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9270. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9271. "2843 PCI device Power Management suspend.\n");
  9272. /* Bring down the device */
  9273. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  9274. lpfc_offline(phba);
  9275. kthread_stop(phba->worker_thread);
  9276. /* Disable interrupt from device */
  9277. lpfc_sli4_disable_intr(phba);
  9278. lpfc_sli4_queue_destroy(phba);
  9279. /* Save device state to PCI config space */
  9280. pci_save_state(pdev);
  9281. pci_set_power_state(pdev, PCI_D3hot);
  9282. return 0;
  9283. }
  9284. /**
  9285. * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
  9286. * @pdev: pointer to PCI device
  9287. *
  9288. * This routine is called from the kernel's PCI subsystem to support system
  9289. * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
  9290. * this method, it restores the device's PCI config space state and fully
  9291. * reinitializes the device and brings it online. Note that as the driver
  9292. * implements the minimum PM requirements to a power-aware driver's PM for
  9293. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  9294. * to the suspend() method call will be treated as SUSPEND and the driver
  9295. * will fully reinitialize its device during resume() method call, the device
  9296. * will be set to PCI_D0 directly in PCI config space before restoring the
  9297. * state.
  9298. *
  9299. * Return code
  9300. * 0 - driver suspended the device
  9301. * Error otherwise
  9302. **/
  9303. static int
  9304. lpfc_pci_resume_one_s4(struct pci_dev *pdev)
  9305. {
  9306. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9307. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9308. uint32_t intr_mode;
  9309. int error;
  9310. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9311. "0292 PCI device Power Management resume.\n");
  9312. /* Restore device state from PCI config space */
  9313. pci_set_power_state(pdev, PCI_D0);
  9314. pci_restore_state(pdev);
  9315. /*
  9316. * As the new kernel behavior of pci_restore_state() API call clears
  9317. * device saved_state flag, need to save the restored state again.
  9318. */
  9319. pci_save_state(pdev);
  9320. if (pdev->is_busmaster)
  9321. pci_set_master(pdev);
  9322. /* Startup the kernel thread for this host adapter. */
  9323. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  9324. "lpfc_worker_%d", phba->brd_no);
  9325. if (IS_ERR(phba->worker_thread)) {
  9326. error = PTR_ERR(phba->worker_thread);
  9327. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9328. "0293 PM resume failed to start worker "
  9329. "thread: error=x%x.\n", error);
  9330. return error;
  9331. }
  9332. /* Configure and enable interrupt */
  9333. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  9334. if (intr_mode == LPFC_INTR_ERROR) {
  9335. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9336. "0294 PM resume Failed to enable interrupt\n");
  9337. return -EIO;
  9338. } else
  9339. phba->intr_mode = intr_mode;
  9340. /* Restart HBA and bring it online */
  9341. lpfc_sli_brdrestart(phba);
  9342. lpfc_online(phba);
  9343. /* Log the current active interrupt mode */
  9344. lpfc_log_intr_mode(phba, phba->intr_mode);
  9345. return 0;
  9346. }
  9347. /**
  9348. * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
  9349. * @phba: pointer to lpfc hba data structure.
  9350. *
  9351. * This routine is called to prepare the SLI4 device for PCI slot recover. It
  9352. * aborts all the outstanding SCSI I/Os to the pci device.
  9353. **/
  9354. static void
  9355. lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
  9356. {
  9357. struct lpfc_sli *psli = &phba->sli;
  9358. struct lpfc_sli_ring *pring;
  9359. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9360. "2828 PCI channel I/O abort preparing for recovery\n");
  9361. /*
  9362. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  9363. * and let the SCSI mid-layer to retry them to recover.
  9364. */
  9365. pring = &psli->ring[psli->fcp_ring];
  9366. lpfc_sli_abort_iocb_ring(phba, pring);
  9367. }
  9368. /**
  9369. * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
  9370. * @phba: pointer to lpfc hba data structure.
  9371. *
  9372. * This routine is called to prepare the SLI4 device for PCI slot reset. It
  9373. * disables the device interrupt and pci device, and aborts the internal FCP
  9374. * pending I/Os.
  9375. **/
  9376. static void
  9377. lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
  9378. {
  9379. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9380. "2826 PCI channel disable preparing for reset\n");
  9381. /* Block any management I/Os to the device */
  9382. lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
  9383. /* Block all SCSI devices' I/Os on the host */
  9384. lpfc_scsi_dev_block(phba);
  9385. /* Flush all driver's outstanding SCSI I/Os as we are to reset */
  9386. lpfc_sli_flush_fcp_rings(phba);
  9387. /* stop all timers */
  9388. lpfc_stop_hba_timers(phba);
  9389. /* Disable interrupt and pci device */
  9390. lpfc_sli4_disable_intr(phba);
  9391. lpfc_sli4_queue_destroy(phba);
  9392. pci_disable_device(phba->pcidev);
  9393. }
  9394. /**
  9395. * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
  9396. * @phba: pointer to lpfc hba data structure.
  9397. *
  9398. * This routine is called to prepare the SLI4 device for PCI slot permanently
  9399. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  9400. * pending I/Os.
  9401. **/
  9402. static void
  9403. lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  9404. {
  9405. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9406. "2827 PCI channel permanent disable for failure\n");
  9407. /* Block all SCSI devices' I/Os on the host */
  9408. lpfc_scsi_dev_block(phba);
  9409. /* stop all timers */
  9410. lpfc_stop_hba_timers(phba);
  9411. /* Clean up all driver's outstanding SCSI I/Os */
  9412. lpfc_sli_flush_fcp_rings(phba);
  9413. }
  9414. /**
  9415. * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
  9416. * @pdev: pointer to PCI device.
  9417. * @state: the current PCI connection state.
  9418. *
  9419. * This routine is called from the PCI subsystem for error handling to device
  9420. * with SLI-4 interface spec. This function is called by the PCI subsystem
  9421. * after a PCI bus error affecting this device has been detected. When this
  9422. * function is invoked, it will need to stop all the I/Os and interrupt(s)
  9423. * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
  9424. * for the PCI subsystem to perform proper recovery as desired.
  9425. *
  9426. * Return codes
  9427. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  9428. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9429. **/
  9430. static pci_ers_result_t
  9431. lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
  9432. {
  9433. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9434. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9435. switch (state) {
  9436. case pci_channel_io_normal:
  9437. /* Non-fatal error, prepare for recovery */
  9438. lpfc_sli4_prep_dev_for_recover(phba);
  9439. return PCI_ERS_RESULT_CAN_RECOVER;
  9440. case pci_channel_io_frozen:
  9441. /* Fatal error, prepare for slot reset */
  9442. lpfc_sli4_prep_dev_for_reset(phba);
  9443. return PCI_ERS_RESULT_NEED_RESET;
  9444. case pci_channel_io_perm_failure:
  9445. /* Permanent failure, prepare for device down */
  9446. lpfc_sli4_prep_dev_for_perm_failure(phba);
  9447. return PCI_ERS_RESULT_DISCONNECT;
  9448. default:
  9449. /* Unknown state, prepare and request slot reset */
  9450. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9451. "2825 Unknown PCI error state: x%x\n", state);
  9452. lpfc_sli4_prep_dev_for_reset(phba);
  9453. return PCI_ERS_RESULT_NEED_RESET;
  9454. }
  9455. }
  9456. /**
  9457. * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
  9458. * @pdev: pointer to PCI device.
  9459. *
  9460. * This routine is called from the PCI subsystem for error handling to device
  9461. * with SLI-4 interface spec. It is called after PCI bus has been reset to
  9462. * restart the PCI card from scratch, as if from a cold-boot. During the
  9463. * PCI subsystem error recovery, after the driver returns
  9464. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  9465. * recovery and then call this routine before calling the .resume method to
  9466. * recover the device. This function will initialize the HBA device, enable
  9467. * the interrupt, but it will just put the HBA to offline state without
  9468. * passing any I/O traffic.
  9469. *
  9470. * Return codes
  9471. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  9472. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9473. */
  9474. static pci_ers_result_t
  9475. lpfc_io_slot_reset_s4(struct pci_dev *pdev)
  9476. {
  9477. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9478. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9479. struct lpfc_sli *psli = &phba->sli;
  9480. uint32_t intr_mode;
  9481. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  9482. if (pci_enable_device_mem(pdev)) {
  9483. printk(KERN_ERR "lpfc: Cannot re-enable "
  9484. "PCI device after reset.\n");
  9485. return PCI_ERS_RESULT_DISCONNECT;
  9486. }
  9487. pci_restore_state(pdev);
  9488. /*
  9489. * As the new kernel behavior of pci_restore_state() API call clears
  9490. * device saved_state flag, need to save the restored state again.
  9491. */
  9492. pci_save_state(pdev);
  9493. if (pdev->is_busmaster)
  9494. pci_set_master(pdev);
  9495. spin_lock_irq(&phba->hbalock);
  9496. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  9497. spin_unlock_irq(&phba->hbalock);
  9498. /* Configure and enable interrupt */
  9499. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  9500. if (intr_mode == LPFC_INTR_ERROR) {
  9501. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9502. "2824 Cannot re-enable interrupt after "
  9503. "slot reset.\n");
  9504. return PCI_ERS_RESULT_DISCONNECT;
  9505. } else
  9506. phba->intr_mode = intr_mode;
  9507. /* Log the current active interrupt mode */
  9508. lpfc_log_intr_mode(phba, phba->intr_mode);
  9509. return PCI_ERS_RESULT_RECOVERED;
  9510. }
  9511. /**
  9512. * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
  9513. * @pdev: pointer to PCI device
  9514. *
  9515. * This routine is called from the PCI subsystem for error handling to device
  9516. * with SLI-4 interface spec. It is called when kernel error recovery tells
  9517. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  9518. * error recovery. After this call, traffic can start to flow from this device
  9519. * again.
  9520. **/
  9521. static void
  9522. lpfc_io_resume_s4(struct pci_dev *pdev)
  9523. {
  9524. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9525. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9526. /*
  9527. * In case of slot reset, as function reset is performed through
  9528. * mailbox command which needs DMA to be enabled, this operation
  9529. * has to be moved to the io resume phase. Taking device offline
  9530. * will perform the necessary cleanup.
  9531. */
  9532. if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
  9533. /* Perform device reset */
  9534. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  9535. lpfc_offline(phba);
  9536. lpfc_sli_brdrestart(phba);
  9537. /* Bring the device back online */
  9538. lpfc_online(phba);
  9539. }
  9540. /* Clean up Advanced Error Reporting (AER) if needed */
  9541. if (phba->hba_flag & HBA_AER_ENABLED)
  9542. pci_cleanup_aer_uncorrect_error_status(pdev);
  9543. }
  9544. /**
  9545. * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
  9546. * @pdev: pointer to PCI device
  9547. * @pid: pointer to PCI device identifier
  9548. *
  9549. * This routine is to be registered to the kernel's PCI subsystem. When an
  9550. * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
  9551. * at PCI device-specific information of the device and driver to see if the
  9552. * driver state that it can support this kind of device. If the match is
  9553. * successful, the driver core invokes this routine. This routine dispatches
  9554. * the action to the proper SLI-3 or SLI-4 device probing routine, which will
  9555. * do all the initialization that it needs to do to handle the HBA device
  9556. * properly.
  9557. *
  9558. * Return code
  9559. * 0 - driver can claim the device
  9560. * negative value - driver can not claim the device
  9561. **/
  9562. static int
  9563. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  9564. {
  9565. int rc;
  9566. struct lpfc_sli_intf intf;
  9567. if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
  9568. return -ENODEV;
  9569. if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
  9570. (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
  9571. rc = lpfc_pci_probe_one_s4(pdev, pid);
  9572. else
  9573. rc = lpfc_pci_probe_one_s3(pdev, pid);
  9574. return rc;
  9575. }
  9576. /**
  9577. * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
  9578. * @pdev: pointer to PCI device
  9579. *
  9580. * This routine is to be registered to the kernel's PCI subsystem. When an
  9581. * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
  9582. * This routine dispatches the action to the proper SLI-3 or SLI-4 device
  9583. * remove routine, which will perform all the necessary cleanup for the
  9584. * device to be removed from the PCI subsystem properly.
  9585. **/
  9586. static void
  9587. lpfc_pci_remove_one(struct pci_dev *pdev)
  9588. {
  9589. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9590. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9591. switch (phba->pci_dev_grp) {
  9592. case LPFC_PCI_DEV_LP:
  9593. lpfc_pci_remove_one_s3(pdev);
  9594. break;
  9595. case LPFC_PCI_DEV_OC:
  9596. lpfc_pci_remove_one_s4(pdev);
  9597. break;
  9598. default:
  9599. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9600. "1424 Invalid PCI device group: 0x%x\n",
  9601. phba->pci_dev_grp);
  9602. break;
  9603. }
  9604. return;
  9605. }
  9606. /**
  9607. * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
  9608. * @pdev: pointer to PCI device
  9609. * @msg: power management message
  9610. *
  9611. * This routine is to be registered to the kernel's PCI subsystem to support
  9612. * system Power Management (PM). When PM invokes this method, it dispatches
  9613. * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
  9614. * suspend the device.
  9615. *
  9616. * Return code
  9617. * 0 - driver suspended the device
  9618. * Error otherwise
  9619. **/
  9620. static int
  9621. lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
  9622. {
  9623. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9624. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9625. int rc = -ENODEV;
  9626. switch (phba->pci_dev_grp) {
  9627. case LPFC_PCI_DEV_LP:
  9628. rc = lpfc_pci_suspend_one_s3(pdev, msg);
  9629. break;
  9630. case LPFC_PCI_DEV_OC:
  9631. rc = lpfc_pci_suspend_one_s4(pdev, msg);
  9632. break;
  9633. default:
  9634. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9635. "1425 Invalid PCI device group: 0x%x\n",
  9636. phba->pci_dev_grp);
  9637. break;
  9638. }
  9639. return rc;
  9640. }
  9641. /**
  9642. * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
  9643. * @pdev: pointer to PCI device
  9644. *
  9645. * This routine is to be registered to the kernel's PCI subsystem to support
  9646. * system Power Management (PM). When PM invokes this method, it dispatches
  9647. * the action to the proper SLI-3 or SLI-4 device resume routine, which will
  9648. * resume the device.
  9649. *
  9650. * Return code
  9651. * 0 - driver suspended the device
  9652. * Error otherwise
  9653. **/
  9654. static int
  9655. lpfc_pci_resume_one(struct pci_dev *pdev)
  9656. {
  9657. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9658. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9659. int rc = -ENODEV;
  9660. switch (phba->pci_dev_grp) {
  9661. case LPFC_PCI_DEV_LP:
  9662. rc = lpfc_pci_resume_one_s3(pdev);
  9663. break;
  9664. case LPFC_PCI_DEV_OC:
  9665. rc = lpfc_pci_resume_one_s4(pdev);
  9666. break;
  9667. default:
  9668. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9669. "1426 Invalid PCI device group: 0x%x\n",
  9670. phba->pci_dev_grp);
  9671. break;
  9672. }
  9673. return rc;
  9674. }
  9675. /**
  9676. * lpfc_io_error_detected - lpfc method for handling PCI I/O error
  9677. * @pdev: pointer to PCI device.
  9678. * @state: the current PCI connection state.
  9679. *
  9680. * This routine is registered to the PCI subsystem for error handling. This
  9681. * function is called by the PCI subsystem after a PCI bus error affecting
  9682. * this device has been detected. When this routine is invoked, it dispatches
  9683. * the action to the proper SLI-3 or SLI-4 device error detected handling
  9684. * routine, which will perform the proper error detected operation.
  9685. *
  9686. * Return codes
  9687. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  9688. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9689. **/
  9690. static pci_ers_result_t
  9691. lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  9692. {
  9693. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9694. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9695. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  9696. switch (phba->pci_dev_grp) {
  9697. case LPFC_PCI_DEV_LP:
  9698. rc = lpfc_io_error_detected_s3(pdev, state);
  9699. break;
  9700. case LPFC_PCI_DEV_OC:
  9701. rc = lpfc_io_error_detected_s4(pdev, state);
  9702. break;
  9703. default:
  9704. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9705. "1427 Invalid PCI device group: 0x%x\n",
  9706. phba->pci_dev_grp);
  9707. break;
  9708. }
  9709. return rc;
  9710. }
  9711. /**
  9712. * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
  9713. * @pdev: pointer to PCI device.
  9714. *
  9715. * This routine is registered to the PCI subsystem for error handling. This
  9716. * function is called after PCI bus has been reset to restart the PCI card
  9717. * from scratch, as if from a cold-boot. When this routine is invoked, it
  9718. * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
  9719. * routine, which will perform the proper device reset.
  9720. *
  9721. * Return codes
  9722. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  9723. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9724. **/
  9725. static pci_ers_result_t
  9726. lpfc_io_slot_reset(struct pci_dev *pdev)
  9727. {
  9728. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9729. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9730. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  9731. switch (phba->pci_dev_grp) {
  9732. case LPFC_PCI_DEV_LP:
  9733. rc = lpfc_io_slot_reset_s3(pdev);
  9734. break;
  9735. case LPFC_PCI_DEV_OC:
  9736. rc = lpfc_io_slot_reset_s4(pdev);
  9737. break;
  9738. default:
  9739. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9740. "1428 Invalid PCI device group: 0x%x\n",
  9741. phba->pci_dev_grp);
  9742. break;
  9743. }
  9744. return rc;
  9745. }
  9746. /**
  9747. * lpfc_io_resume - lpfc method for resuming PCI I/O operation
  9748. * @pdev: pointer to PCI device
  9749. *
  9750. * This routine is registered to the PCI subsystem for error handling. It
  9751. * is called when kernel error recovery tells the lpfc driver that it is
  9752. * OK to resume normal PCI operation after PCI bus error recovery. When
  9753. * this routine is invoked, it dispatches the action to the proper SLI-3
  9754. * or SLI-4 device io_resume routine, which will resume the device operation.
  9755. **/
  9756. static void
  9757. lpfc_io_resume(struct pci_dev *pdev)
  9758. {
  9759. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9760. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9761. switch (phba->pci_dev_grp) {
  9762. case LPFC_PCI_DEV_LP:
  9763. lpfc_io_resume_s3(pdev);
  9764. break;
  9765. case LPFC_PCI_DEV_OC:
  9766. lpfc_io_resume_s4(pdev);
  9767. break;
  9768. default:
  9769. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9770. "1429 Invalid PCI device group: 0x%x\n",
  9771. phba->pci_dev_grp);
  9772. break;
  9773. }
  9774. return;
  9775. }
  9776. static struct pci_device_id lpfc_id_table[] = {
  9777. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  9778. PCI_ANY_ID, PCI_ANY_ID, },
  9779. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  9780. PCI_ANY_ID, PCI_ANY_ID, },
  9781. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  9782. PCI_ANY_ID, PCI_ANY_ID, },
  9783. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  9784. PCI_ANY_ID, PCI_ANY_ID, },
  9785. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  9786. PCI_ANY_ID, PCI_ANY_ID, },
  9787. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  9788. PCI_ANY_ID, PCI_ANY_ID, },
  9789. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  9790. PCI_ANY_ID, PCI_ANY_ID, },
  9791. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  9792. PCI_ANY_ID, PCI_ANY_ID, },
  9793. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  9794. PCI_ANY_ID, PCI_ANY_ID, },
  9795. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  9796. PCI_ANY_ID, PCI_ANY_ID, },
  9797. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  9798. PCI_ANY_ID, PCI_ANY_ID, },
  9799. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  9800. PCI_ANY_ID, PCI_ANY_ID, },
  9801. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  9802. PCI_ANY_ID, PCI_ANY_ID, },
  9803. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  9804. PCI_ANY_ID, PCI_ANY_ID, },
  9805. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  9806. PCI_ANY_ID, PCI_ANY_ID, },
  9807. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  9808. PCI_ANY_ID, PCI_ANY_ID, },
  9809. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  9810. PCI_ANY_ID, PCI_ANY_ID, },
  9811. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  9812. PCI_ANY_ID, PCI_ANY_ID, },
  9813. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
  9814. PCI_ANY_ID, PCI_ANY_ID, },
  9815. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  9816. PCI_ANY_ID, PCI_ANY_ID, },
  9817. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  9818. PCI_ANY_ID, PCI_ANY_ID, },
  9819. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  9820. PCI_ANY_ID, PCI_ANY_ID, },
  9821. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  9822. PCI_ANY_ID, PCI_ANY_ID, },
  9823. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  9824. PCI_ANY_ID, PCI_ANY_ID, },
  9825. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  9826. PCI_ANY_ID, PCI_ANY_ID, },
  9827. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  9828. PCI_ANY_ID, PCI_ANY_ID, },
  9829. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  9830. PCI_ANY_ID, PCI_ANY_ID, },
  9831. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  9832. PCI_ANY_ID, PCI_ANY_ID, },
  9833. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  9834. PCI_ANY_ID, PCI_ANY_ID, },
  9835. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  9836. PCI_ANY_ID, PCI_ANY_ID, },
  9837. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  9838. PCI_ANY_ID, PCI_ANY_ID, },
  9839. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  9840. PCI_ANY_ID, PCI_ANY_ID, },
  9841. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  9842. PCI_ANY_ID, PCI_ANY_ID, },
  9843. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  9844. PCI_ANY_ID, PCI_ANY_ID, },
  9845. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
  9846. PCI_ANY_ID, PCI_ANY_ID, },
  9847. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
  9848. PCI_ANY_ID, PCI_ANY_ID, },
  9849. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
  9850. PCI_ANY_ID, PCI_ANY_ID, },
  9851. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
  9852. PCI_ANY_ID, PCI_ANY_ID, },
  9853. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
  9854. PCI_ANY_ID, PCI_ANY_ID, },
  9855. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
  9856. PCI_ANY_ID, PCI_ANY_ID, },
  9857. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
  9858. PCI_ANY_ID, PCI_ANY_ID, },
  9859. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
  9860. PCI_ANY_ID, PCI_ANY_ID, },
  9861. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
  9862. PCI_ANY_ID, PCI_ANY_ID, },
  9863. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
  9864. PCI_ANY_ID, PCI_ANY_ID, },
  9865. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
  9866. PCI_ANY_ID, PCI_ANY_ID, },
  9867. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK,
  9868. PCI_ANY_ID, PCI_ANY_ID, },
  9869. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF,
  9870. PCI_ANY_ID, PCI_ANY_ID, },
  9871. { 0 }
  9872. };
  9873. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  9874. static const struct pci_error_handlers lpfc_err_handler = {
  9875. .error_detected = lpfc_io_error_detected,
  9876. .slot_reset = lpfc_io_slot_reset,
  9877. .resume = lpfc_io_resume,
  9878. };
  9879. static struct pci_driver lpfc_driver = {
  9880. .name = LPFC_DRIVER_NAME,
  9881. .id_table = lpfc_id_table,
  9882. .probe = lpfc_pci_probe_one,
  9883. .remove = lpfc_pci_remove_one,
  9884. .suspend = lpfc_pci_suspend_one,
  9885. .resume = lpfc_pci_resume_one,
  9886. .err_handler = &lpfc_err_handler,
  9887. };
  9888. static const struct file_operations lpfc_mgmt_fop = {
  9889. .owner = THIS_MODULE,
  9890. };
  9891. static struct miscdevice lpfc_mgmt_dev = {
  9892. .minor = MISC_DYNAMIC_MINOR,
  9893. .name = "lpfcmgmt",
  9894. .fops = &lpfc_mgmt_fop,
  9895. };
  9896. /**
  9897. * lpfc_init - lpfc module initialization routine
  9898. *
  9899. * This routine is to be invoked when the lpfc module is loaded into the
  9900. * kernel. The special kernel macro module_init() is used to indicate the
  9901. * role of this routine to the kernel as lpfc module entry point.
  9902. *
  9903. * Return codes
  9904. * 0 - successful
  9905. * -ENOMEM - FC attach transport failed
  9906. * all others - failed
  9907. */
  9908. static int __init
  9909. lpfc_init(void)
  9910. {
  9911. int cpu;
  9912. int error = 0;
  9913. printk(LPFC_MODULE_DESC "\n");
  9914. printk(LPFC_COPYRIGHT "\n");
  9915. error = misc_register(&lpfc_mgmt_dev);
  9916. if (error)
  9917. printk(KERN_ERR "Could not register lpfcmgmt device, "
  9918. "misc_register returned with status %d", error);
  9919. if (lpfc_enable_npiv) {
  9920. lpfc_transport_functions.vport_create = lpfc_vport_create;
  9921. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  9922. }
  9923. lpfc_transport_template =
  9924. fc_attach_transport(&lpfc_transport_functions);
  9925. if (lpfc_transport_template == NULL)
  9926. return -ENOMEM;
  9927. if (lpfc_enable_npiv) {
  9928. lpfc_vport_transport_template =
  9929. fc_attach_transport(&lpfc_vport_transport_functions);
  9930. if (lpfc_vport_transport_template == NULL) {
  9931. fc_release_transport(lpfc_transport_template);
  9932. return -ENOMEM;
  9933. }
  9934. }
  9935. /* Initialize in case vector mapping is needed */
  9936. lpfc_used_cpu = NULL;
  9937. lpfc_present_cpu = 0;
  9938. for_each_present_cpu(cpu)
  9939. lpfc_present_cpu++;
  9940. error = pci_register_driver(&lpfc_driver);
  9941. if (error) {
  9942. fc_release_transport(lpfc_transport_template);
  9943. if (lpfc_enable_npiv)
  9944. fc_release_transport(lpfc_vport_transport_template);
  9945. }
  9946. return error;
  9947. }
  9948. /**
  9949. * lpfc_exit - lpfc module removal routine
  9950. *
  9951. * This routine is invoked when the lpfc module is removed from the kernel.
  9952. * The special kernel macro module_exit() is used to indicate the role of
  9953. * this routine to the kernel as lpfc module exit point.
  9954. */
  9955. static void __exit
  9956. lpfc_exit(void)
  9957. {
  9958. misc_deregister(&lpfc_mgmt_dev);
  9959. pci_unregister_driver(&lpfc_driver);
  9960. fc_release_transport(lpfc_transport_template);
  9961. if (lpfc_enable_npiv)
  9962. fc_release_transport(lpfc_vport_transport_template);
  9963. if (_dump_buf_data) {
  9964. printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
  9965. "_dump_buf_data at 0x%p\n",
  9966. (1L << _dump_buf_data_order), _dump_buf_data);
  9967. free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
  9968. }
  9969. if (_dump_buf_dif) {
  9970. printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
  9971. "_dump_buf_dif at 0x%p\n",
  9972. (1L << _dump_buf_dif_order), _dump_buf_dif);
  9973. free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
  9974. }
  9975. kfree(lpfc_used_cpu);
  9976. }
  9977. module_init(lpfc_init);
  9978. module_exit(lpfc_exit);
  9979. MODULE_LICENSE("GPL");
  9980. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  9981. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  9982. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);