lpfc_init.c 241 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #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/kthread.h>
  27. #include <linux/pci.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/ctype.h>
  30. #include <linux/aer.h>
  31. #include <scsi/scsi.h>
  32. #include <scsi/scsi_device.h>
  33. #include <scsi/scsi_host.h>
  34. #include <scsi/scsi_transport_fc.h>
  35. #include "lpfc_hw4.h"
  36. #include "lpfc_hw.h"
  37. #include "lpfc_sli.h"
  38. #include "lpfc_sli4.h"
  39. #include "lpfc_nl.h"
  40. #include "lpfc_disc.h"
  41. #include "lpfc_scsi.h"
  42. #include "lpfc.h"
  43. #include "lpfc_logmsg.h"
  44. #include "lpfc_crtn.h"
  45. #include "lpfc_vport.h"
  46. #include "lpfc_version.h"
  47. char *_dump_buf_data;
  48. unsigned long _dump_buf_data_order;
  49. char *_dump_buf_dif;
  50. unsigned long _dump_buf_dif_order;
  51. spinlock_t _dump_buf_lock;
  52. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  53. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  54. static int lpfc_sli4_queue_create(struct lpfc_hba *);
  55. static void lpfc_sli4_queue_destroy(struct lpfc_hba *);
  56. static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
  57. static int lpfc_setup_endian_order(struct lpfc_hba *);
  58. static int lpfc_sli4_read_config(struct lpfc_hba *);
  59. static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
  60. static void lpfc_free_sgl_list(struct lpfc_hba *);
  61. static int lpfc_init_sgl_list(struct lpfc_hba *);
  62. static int lpfc_init_active_sgl_array(struct lpfc_hba *);
  63. static void lpfc_free_active_sgl(struct lpfc_hba *);
  64. static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
  65. static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
  66. static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
  67. static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
  68. static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
  69. static struct scsi_transport_template *lpfc_transport_template = NULL;
  70. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  71. static DEFINE_IDR(lpfc_hba_index);
  72. /**
  73. * lpfc_config_port_prep - Perform lpfc initialization prior to config port
  74. * @phba: pointer to lpfc hba data structure.
  75. *
  76. * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
  77. * mailbox command. It retrieves the revision information from the HBA and
  78. * collects the Vital Product Data (VPD) about the HBA for preparing the
  79. * configuration of the HBA.
  80. *
  81. * Return codes:
  82. * 0 - success.
  83. * -ERESTART - requests the SLI layer to reset the HBA and try again.
  84. * Any other value - indicates an error.
  85. **/
  86. int
  87. lpfc_config_port_prep(struct lpfc_hba *phba)
  88. {
  89. lpfc_vpd_t *vp = &phba->vpd;
  90. int i = 0, rc;
  91. LPFC_MBOXQ_t *pmb;
  92. MAILBOX_t *mb;
  93. char *lpfc_vpd_data = NULL;
  94. uint16_t offset = 0;
  95. static char licensed[56] =
  96. "key unlock for use with gnu public licensed code only\0";
  97. static int init_key = 1;
  98. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  99. if (!pmb) {
  100. phba->link_state = LPFC_HBA_ERROR;
  101. return -ENOMEM;
  102. }
  103. mb = &pmb->u.mb;
  104. phba->link_state = LPFC_INIT_MBX_CMDS;
  105. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  106. if (init_key) {
  107. uint32_t *ptext = (uint32_t *) licensed;
  108. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  109. *ptext = cpu_to_be32(*ptext);
  110. init_key = 0;
  111. }
  112. lpfc_read_nv(phba, pmb);
  113. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  114. sizeof (mb->un.varRDnvp.rsvd3));
  115. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  116. sizeof (licensed));
  117. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  118. if (rc != MBX_SUCCESS) {
  119. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  120. "0324 Config Port initialization "
  121. "error, mbxCmd x%x READ_NVPARM, "
  122. "mbxStatus x%x\n",
  123. mb->mbxCommand, mb->mbxStatus);
  124. mempool_free(pmb, phba->mbox_mem_pool);
  125. return -ERESTART;
  126. }
  127. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  128. sizeof(phba->wwnn));
  129. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  130. sizeof(phba->wwpn));
  131. }
  132. phba->sli3_options = 0x0;
  133. /* Setup and issue mailbox READ REV command */
  134. lpfc_read_rev(phba, pmb);
  135. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  136. if (rc != MBX_SUCCESS) {
  137. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  138. "0439 Adapter failed to init, mbxCmd x%x "
  139. "READ_REV, mbxStatus x%x\n",
  140. mb->mbxCommand, mb->mbxStatus);
  141. mempool_free( pmb, phba->mbox_mem_pool);
  142. return -ERESTART;
  143. }
  144. /*
  145. * The value of rr must be 1 since the driver set the cv field to 1.
  146. * This setting requires the FW to set all revision fields.
  147. */
  148. if (mb->un.varRdRev.rr == 0) {
  149. vp->rev.rBit = 0;
  150. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  151. "0440 Adapter failed to init, READ_REV has "
  152. "missing revision information.\n");
  153. mempool_free(pmb, phba->mbox_mem_pool);
  154. return -ERESTART;
  155. }
  156. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
  157. mempool_free(pmb, phba->mbox_mem_pool);
  158. return -EINVAL;
  159. }
  160. /* Save information as VPD data */
  161. vp->rev.rBit = 1;
  162. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  163. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  164. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  165. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  166. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  167. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  168. vp->rev.smRev = mb->un.varRdRev.smRev;
  169. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  170. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  171. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  172. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  173. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  174. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  175. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  176. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  177. /* If the sli feature level is less then 9, we must
  178. * tear down all RPIs and VPIs on link down if NPIV
  179. * is enabled.
  180. */
  181. if (vp->rev.feaLevelHigh < 9)
  182. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  183. if (lpfc_is_LC_HBA(phba->pcidev->device))
  184. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  185. sizeof (phba->RandomData));
  186. /* Get adapter VPD information */
  187. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  188. if (!lpfc_vpd_data)
  189. goto out_free_mbox;
  190. do {
  191. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
  192. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  193. if (rc != MBX_SUCCESS) {
  194. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  195. "0441 VPD not present on adapter, "
  196. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  197. mb->mbxCommand, mb->mbxStatus);
  198. mb->un.varDmp.word_cnt = 0;
  199. }
  200. /* dump mem may return a zero when finished or we got a
  201. * mailbox error, either way we are done.
  202. */
  203. if (mb->un.varDmp.word_cnt == 0)
  204. break;
  205. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  206. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  207. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  208. lpfc_vpd_data + offset,
  209. mb->un.varDmp.word_cnt);
  210. offset += mb->un.varDmp.word_cnt;
  211. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  212. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  213. kfree(lpfc_vpd_data);
  214. out_free_mbox:
  215. mempool_free(pmb, phba->mbox_mem_pool);
  216. return 0;
  217. }
  218. /**
  219. * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
  220. * @phba: pointer to lpfc hba data structure.
  221. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  222. *
  223. * This is the completion handler for driver's configuring asynchronous event
  224. * mailbox command to the device. If the mailbox command returns successfully,
  225. * it will set internal async event support flag to 1; otherwise, it will
  226. * set internal async event support flag to 0.
  227. **/
  228. static void
  229. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  230. {
  231. if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
  232. phba->temp_sensor_support = 1;
  233. else
  234. phba->temp_sensor_support = 0;
  235. mempool_free(pmboxq, phba->mbox_mem_pool);
  236. return;
  237. }
  238. /**
  239. * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
  240. * @phba: pointer to lpfc hba data structure.
  241. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  242. *
  243. * This is the completion handler for dump mailbox command for getting
  244. * wake up parameters. When this command complete, the response contain
  245. * Option rom version of the HBA. This function translate the version number
  246. * into a human readable string and store it in OptionROMVersion.
  247. **/
  248. static void
  249. lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  250. {
  251. struct prog_id *prg;
  252. uint32_t prog_id_word;
  253. char dist = ' ';
  254. /* character array used for decoding dist type. */
  255. char dist_char[] = "nabx";
  256. if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
  257. mempool_free(pmboxq, phba->mbox_mem_pool);
  258. return;
  259. }
  260. prg = (struct prog_id *) &prog_id_word;
  261. /* word 7 contain option rom version */
  262. prog_id_word = pmboxq->u.mb.un.varWords[7];
  263. /* Decode the Option rom version word to a readable string */
  264. if (prg->dist < 4)
  265. dist = dist_char[prg->dist];
  266. if ((prg->dist == 3) && (prg->num == 0))
  267. sprintf(phba->OptionROMVersion, "%d.%d%d",
  268. prg->ver, prg->rev, prg->lev);
  269. else
  270. sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
  271. prg->ver, prg->rev, prg->lev,
  272. dist, prg->num);
  273. mempool_free(pmboxq, phba->mbox_mem_pool);
  274. return;
  275. }
  276. /**
  277. * lpfc_config_port_post - Perform lpfc initialization after config port
  278. * @phba: pointer to lpfc hba data structure.
  279. *
  280. * This routine will do LPFC initialization after the CONFIG_PORT mailbox
  281. * command call. It performs all internal resource and state setups on the
  282. * port: post IOCB buffers, enable appropriate host interrupt attentions,
  283. * ELS ring timers, etc.
  284. *
  285. * Return codes
  286. * 0 - success.
  287. * Any other value - error.
  288. **/
  289. int
  290. lpfc_config_port_post(struct lpfc_hba *phba)
  291. {
  292. struct lpfc_vport *vport = phba->pport;
  293. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  294. LPFC_MBOXQ_t *pmb;
  295. MAILBOX_t *mb;
  296. struct lpfc_dmabuf *mp;
  297. struct lpfc_sli *psli = &phba->sli;
  298. uint32_t status, timeout;
  299. int i, j;
  300. int rc;
  301. spin_lock_irq(&phba->hbalock);
  302. /*
  303. * If the Config port completed correctly the HBA is not
  304. * over heated any more.
  305. */
  306. if (phba->over_temp_state == HBA_OVER_TEMP)
  307. phba->over_temp_state = HBA_NORMAL_TEMP;
  308. spin_unlock_irq(&phba->hbalock);
  309. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  310. if (!pmb) {
  311. phba->link_state = LPFC_HBA_ERROR;
  312. return -ENOMEM;
  313. }
  314. mb = &pmb->u.mb;
  315. /* Get login parameters for NID. */
  316. lpfc_read_sparam(phba, pmb, 0);
  317. pmb->vport = vport;
  318. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  319. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  320. "0448 Adapter failed init, mbxCmd x%x "
  321. "READ_SPARM mbxStatus x%x\n",
  322. mb->mbxCommand, mb->mbxStatus);
  323. phba->link_state = LPFC_HBA_ERROR;
  324. mp = (struct lpfc_dmabuf *) pmb->context1;
  325. mempool_free( pmb, phba->mbox_mem_pool);
  326. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  327. kfree(mp);
  328. return -EIO;
  329. }
  330. mp = (struct lpfc_dmabuf *) pmb->context1;
  331. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  332. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  333. kfree(mp);
  334. pmb->context1 = NULL;
  335. if (phba->cfg_soft_wwnn)
  336. u64_to_wwn(phba->cfg_soft_wwnn,
  337. vport->fc_sparam.nodeName.u.wwn);
  338. if (phba->cfg_soft_wwpn)
  339. u64_to_wwn(phba->cfg_soft_wwpn,
  340. vport->fc_sparam.portName.u.wwn);
  341. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  342. sizeof (struct lpfc_name));
  343. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  344. sizeof (struct lpfc_name));
  345. /* Update the fc_host data structures with new wwn. */
  346. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  347. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  348. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  349. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  350. /* This should be consolidated into parse_vpd ? - mr */
  351. if (phba->SerialNumber[0] == 0) {
  352. uint8_t *outptr;
  353. outptr = &vport->fc_nodename.u.s.IEEE[0];
  354. for (i = 0; i < 12; i++) {
  355. status = *outptr++;
  356. j = ((status & 0xf0) >> 4);
  357. if (j <= 9)
  358. phba->SerialNumber[i] =
  359. (char)((uint8_t) 0x30 + (uint8_t) j);
  360. else
  361. phba->SerialNumber[i] =
  362. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  363. i++;
  364. j = (status & 0xf);
  365. if (j <= 9)
  366. phba->SerialNumber[i] =
  367. (char)((uint8_t) 0x30 + (uint8_t) j);
  368. else
  369. phba->SerialNumber[i] =
  370. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  371. }
  372. }
  373. lpfc_read_config(phba, pmb);
  374. pmb->vport = vport;
  375. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  376. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  377. "0453 Adapter failed to init, mbxCmd x%x "
  378. "READ_CONFIG, mbxStatus x%x\n",
  379. mb->mbxCommand, mb->mbxStatus);
  380. phba->link_state = LPFC_HBA_ERROR;
  381. mempool_free( pmb, phba->mbox_mem_pool);
  382. return -EIO;
  383. }
  384. /* Check if the port is disabled */
  385. lpfc_sli_read_link_ste(phba);
  386. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  387. if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
  388. phba->cfg_hba_queue_depth =
  389. (mb->un.varRdConfig.max_xri + 1) -
  390. lpfc_sli4_get_els_iocb_cnt(phba);
  391. phba->lmt = mb->un.varRdConfig.lmt;
  392. /* Get the default values for Model Name and Description */
  393. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  394. if ((phba->cfg_link_speed > LINK_SPEED_10G)
  395. || ((phba->cfg_link_speed == LINK_SPEED_1G)
  396. && !(phba->lmt & LMT_1Gb))
  397. || ((phba->cfg_link_speed == LINK_SPEED_2G)
  398. && !(phba->lmt & LMT_2Gb))
  399. || ((phba->cfg_link_speed == LINK_SPEED_4G)
  400. && !(phba->lmt & LMT_4Gb))
  401. || ((phba->cfg_link_speed == LINK_SPEED_8G)
  402. && !(phba->lmt & LMT_8Gb))
  403. || ((phba->cfg_link_speed == LINK_SPEED_10G)
  404. && !(phba->lmt & LMT_10Gb))) {
  405. /* Reset link speed to auto */
  406. lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
  407. "1302 Invalid speed for this board: "
  408. "Reset link speed to auto: x%x\n",
  409. phba->cfg_link_speed);
  410. phba->cfg_link_speed = LINK_SPEED_AUTO;
  411. }
  412. phba->link_state = LPFC_LINK_DOWN;
  413. /* Only process IOCBs on ELS ring till hba_state is READY */
  414. if (psli->ring[psli->extra_ring].cmdringaddr)
  415. psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
  416. if (psli->ring[psli->fcp_ring].cmdringaddr)
  417. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  418. if (psli->ring[psli->next_ring].cmdringaddr)
  419. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  420. /* Post receive buffers for desired rings */
  421. if (phba->sli_rev != 3)
  422. lpfc_post_rcv_buf(phba);
  423. /*
  424. * Configure HBA MSI-X attention conditions to messages if MSI-X mode
  425. */
  426. if (phba->intr_type == MSIX) {
  427. rc = lpfc_config_msi(phba, pmb);
  428. if (rc) {
  429. mempool_free(pmb, phba->mbox_mem_pool);
  430. return -EIO;
  431. }
  432. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  433. if (rc != MBX_SUCCESS) {
  434. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  435. "0352 Config MSI mailbox command "
  436. "failed, mbxCmd x%x, mbxStatus x%x\n",
  437. pmb->u.mb.mbxCommand,
  438. pmb->u.mb.mbxStatus);
  439. mempool_free(pmb, phba->mbox_mem_pool);
  440. return -EIO;
  441. }
  442. }
  443. spin_lock_irq(&phba->hbalock);
  444. /* Initialize ERATT handling flag */
  445. phba->hba_flag &= ~HBA_ERATT_HANDLED;
  446. /* Enable appropriate host interrupts */
  447. status = readl(phba->HCregaddr);
  448. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  449. if (psli->num_rings > 0)
  450. status |= HC_R0INT_ENA;
  451. if (psli->num_rings > 1)
  452. status |= HC_R1INT_ENA;
  453. if (psli->num_rings > 2)
  454. status |= HC_R2INT_ENA;
  455. if (psli->num_rings > 3)
  456. status |= HC_R3INT_ENA;
  457. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  458. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  459. status &= ~(HC_R0INT_ENA);
  460. writel(status, phba->HCregaddr);
  461. readl(phba->HCregaddr); /* flush */
  462. spin_unlock_irq(&phba->hbalock);
  463. /* Set up ring-0 (ELS) timer */
  464. timeout = phba->fc_ratov * 2;
  465. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  466. /* Set up heart beat (HB) timer */
  467. mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  468. phba->hb_outstanding = 0;
  469. phba->last_completion_time = jiffies;
  470. /* Set up error attention (ERATT) polling timer */
  471. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  472. if (phba->hba_flag & LINK_DISABLED) {
  473. lpfc_printf_log(phba,
  474. KERN_ERR, LOG_INIT,
  475. "2598 Adapter Link is disabled.\n");
  476. lpfc_down_link(phba, pmb);
  477. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  478. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  479. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  480. lpfc_printf_log(phba,
  481. KERN_ERR, LOG_INIT,
  482. "2599 Adapter failed to issue DOWN_LINK"
  483. " mbox command rc 0x%x\n", rc);
  484. mempool_free(pmb, phba->mbox_mem_pool);
  485. return -EIO;
  486. }
  487. } else {
  488. lpfc_init_link(phba, pmb, phba->cfg_topology,
  489. phba->cfg_link_speed);
  490. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  491. lpfc_set_loopback_flag(phba);
  492. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  493. if (rc != MBX_SUCCESS) {
  494. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  495. "0454 Adapter failed to init, mbxCmd x%x "
  496. "INIT_LINK, mbxStatus x%x\n",
  497. mb->mbxCommand, mb->mbxStatus);
  498. /* Clear all interrupt enable conditions */
  499. writel(0, phba->HCregaddr);
  500. readl(phba->HCregaddr); /* flush */
  501. /* Clear all pending interrupts */
  502. writel(0xffffffff, phba->HAregaddr);
  503. readl(phba->HAregaddr); /* flush */
  504. phba->link_state = LPFC_HBA_ERROR;
  505. if (rc != MBX_BUSY)
  506. mempool_free(pmb, phba->mbox_mem_pool);
  507. return -EIO;
  508. }
  509. }
  510. /* MBOX buffer will be freed in mbox compl */
  511. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  512. lpfc_config_async(phba, pmb, LPFC_ELS_RING);
  513. pmb->mbox_cmpl = lpfc_config_async_cmpl;
  514. pmb->vport = phba->pport;
  515. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  516. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  517. lpfc_printf_log(phba,
  518. KERN_ERR,
  519. LOG_INIT,
  520. "0456 Adapter failed to issue "
  521. "ASYNCEVT_ENABLE mbox status x%x\n",
  522. rc);
  523. mempool_free(pmb, phba->mbox_mem_pool);
  524. }
  525. /* Get Option rom version */
  526. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  527. lpfc_dump_wakeup_param(phba, pmb);
  528. pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
  529. pmb->vport = phba->pport;
  530. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  531. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  532. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
  533. "to get Option ROM version status x%x\n", rc);
  534. mempool_free(pmb, phba->mbox_mem_pool);
  535. }
  536. return 0;
  537. }
  538. /**
  539. * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
  540. * @phba: pointer to lpfc HBA data structure.
  541. *
  542. * This routine will do LPFC uninitialization before the HBA is reset when
  543. * bringing down the SLI Layer.
  544. *
  545. * Return codes
  546. * 0 - success.
  547. * Any other value - error.
  548. **/
  549. int
  550. lpfc_hba_down_prep(struct lpfc_hba *phba)
  551. {
  552. struct lpfc_vport **vports;
  553. int i;
  554. if (phba->sli_rev <= LPFC_SLI_REV3) {
  555. /* Disable interrupts */
  556. writel(0, phba->HCregaddr);
  557. readl(phba->HCregaddr); /* flush */
  558. }
  559. if (phba->pport->load_flag & FC_UNLOADING)
  560. lpfc_cleanup_discovery_resources(phba->pport);
  561. else {
  562. vports = lpfc_create_vport_work_array(phba);
  563. if (vports != NULL)
  564. for (i = 0; i <= phba->max_vports &&
  565. vports[i] != NULL; i++)
  566. lpfc_cleanup_discovery_resources(vports[i]);
  567. lpfc_destroy_vport_work_array(phba, vports);
  568. }
  569. return 0;
  570. }
  571. /**
  572. * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
  573. * @phba: pointer to lpfc HBA data structure.
  574. *
  575. * This routine will do uninitialization after the HBA is reset when bring
  576. * down the SLI Layer.
  577. *
  578. * Return codes
  579. * 0 - sucess.
  580. * Any other value - error.
  581. **/
  582. static int
  583. lpfc_hba_down_post_s3(struct lpfc_hba *phba)
  584. {
  585. struct lpfc_sli *psli = &phba->sli;
  586. struct lpfc_sli_ring *pring;
  587. struct lpfc_dmabuf *mp, *next_mp;
  588. LIST_HEAD(completions);
  589. int i;
  590. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  591. lpfc_sli_hbqbuf_free_all(phba);
  592. else {
  593. /* Cleanup preposted buffers on the ELS ring */
  594. pring = &psli->ring[LPFC_ELS_RING];
  595. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  596. list_del(&mp->list);
  597. pring->postbufq_cnt--;
  598. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  599. kfree(mp);
  600. }
  601. }
  602. spin_lock_irq(&phba->hbalock);
  603. for (i = 0; i < psli->num_rings; i++) {
  604. pring = &psli->ring[i];
  605. /* At this point in time the HBA is either reset or DOA. Either
  606. * way, nothing should be on txcmplq as it will NEVER complete.
  607. */
  608. list_splice_init(&pring->txcmplq, &completions);
  609. pring->txcmplq_cnt = 0;
  610. spin_unlock_irq(&phba->hbalock);
  611. /* Cancel all the IOCBs from the completions list */
  612. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  613. IOERR_SLI_ABORTED);
  614. lpfc_sli_abort_iocb_ring(phba, pring);
  615. spin_lock_irq(&phba->hbalock);
  616. }
  617. spin_unlock_irq(&phba->hbalock);
  618. return 0;
  619. }
  620. /**
  621. * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
  622. * @phba: pointer to lpfc HBA data structure.
  623. *
  624. * This routine will do uninitialization after the HBA is reset when bring
  625. * down the SLI Layer.
  626. *
  627. * Return codes
  628. * 0 - sucess.
  629. * Any other value - error.
  630. **/
  631. static int
  632. lpfc_hba_down_post_s4(struct lpfc_hba *phba)
  633. {
  634. struct lpfc_scsi_buf *psb, *psb_next;
  635. LIST_HEAD(aborts);
  636. int ret;
  637. unsigned long iflag = 0;
  638. ret = lpfc_hba_down_post_s3(phba);
  639. if (ret)
  640. return ret;
  641. /* At this point in time the HBA is either reset or DOA. Either
  642. * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
  643. * on the lpfc_sgl_list so that it can either be freed if the
  644. * driver is unloading or reposted if the driver is restarting
  645. * the port.
  646. */
  647. spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
  648. /* scsl_buf_list */
  649. /* abts_sgl_list_lock required because worker thread uses this
  650. * list.
  651. */
  652. spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
  653. list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
  654. &phba->sli4_hba.lpfc_sgl_list);
  655. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  656. /* abts_scsi_buf_list_lock required because worker thread uses this
  657. * list.
  658. */
  659. spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  660. list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
  661. &aborts);
  662. spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  663. spin_unlock_irq(&phba->hbalock);
  664. list_for_each_entry_safe(psb, psb_next, &aborts, list) {
  665. psb->pCmd = NULL;
  666. psb->status = IOSTAT_SUCCESS;
  667. }
  668. spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
  669. list_splice(&aborts, &phba->lpfc_scsi_buf_list);
  670. spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
  671. return 0;
  672. }
  673. /**
  674. * lpfc_hba_down_post - Wrapper func for hba down post routine
  675. * @phba: pointer to lpfc HBA data structure.
  676. *
  677. * This routine wraps the actual SLI3 or SLI4 routine for performing
  678. * uninitialization after the HBA is reset when bring down the SLI Layer.
  679. *
  680. * Return codes
  681. * 0 - sucess.
  682. * Any other value - error.
  683. **/
  684. int
  685. lpfc_hba_down_post(struct lpfc_hba *phba)
  686. {
  687. return (*phba->lpfc_hba_down_post)(phba);
  688. }
  689. /**
  690. * lpfc_hb_timeout - The HBA-timer timeout handler
  691. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  692. *
  693. * This is the HBA-timer timeout handler registered to the lpfc driver. When
  694. * this timer fires, a HBA timeout event shall be posted to the lpfc driver
  695. * work-port-events bitmap and the worker thread is notified. This timeout
  696. * event will be used by the worker thread to invoke the actual timeout
  697. * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
  698. * be performed in the timeout handler and the HBA timeout event bit shall
  699. * be cleared by the worker thread after it has taken the event bitmap out.
  700. **/
  701. static void
  702. lpfc_hb_timeout(unsigned long ptr)
  703. {
  704. struct lpfc_hba *phba;
  705. uint32_t tmo_posted;
  706. unsigned long iflag;
  707. phba = (struct lpfc_hba *)ptr;
  708. /* Check for heart beat timeout conditions */
  709. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  710. tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
  711. if (!tmo_posted)
  712. phba->pport->work_port_events |= WORKER_HB_TMO;
  713. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  714. /* Tell the worker thread there is work to do */
  715. if (!tmo_posted)
  716. lpfc_worker_wake_up(phba);
  717. return;
  718. }
  719. /**
  720. * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
  721. * @phba: pointer to lpfc hba data structure.
  722. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  723. *
  724. * This is the callback function to the lpfc heart-beat mailbox command.
  725. * If configured, the lpfc driver issues the heart-beat mailbox command to
  726. * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
  727. * heart-beat mailbox command is issued, the driver shall set up heart-beat
  728. * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
  729. * heart-beat outstanding state. Once the mailbox command comes back and
  730. * no error conditions detected, the heart-beat mailbox command timer is
  731. * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
  732. * state is cleared for the next heart-beat. If the timer expired with the
  733. * heart-beat outstanding state set, the driver will put the HBA offline.
  734. **/
  735. static void
  736. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  737. {
  738. unsigned long drvr_flag;
  739. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  740. phba->hb_outstanding = 0;
  741. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  742. /* Check and reset heart-beat timer is necessary */
  743. mempool_free(pmboxq, phba->mbox_mem_pool);
  744. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  745. !(phba->link_state == LPFC_HBA_ERROR) &&
  746. !(phba->pport->load_flag & FC_UNLOADING))
  747. mod_timer(&phba->hb_tmofunc,
  748. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  749. return;
  750. }
  751. /**
  752. * lpfc_hb_timeout_handler - The HBA-timer timeout handler
  753. * @phba: pointer to lpfc hba data structure.
  754. *
  755. * This is the actual HBA-timer timeout handler to be invoked by the worker
  756. * thread whenever the HBA timer fired and HBA-timeout event posted. This
  757. * handler performs any periodic operations needed for the device. If such
  758. * periodic event has already been attended to either in the interrupt handler
  759. * or by processing slow-ring or fast-ring events within the HBA-timer
  760. * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
  761. * the timer for the next timeout period. If lpfc heart-beat mailbox command
  762. * is configured and there is no heart-beat mailbox command outstanding, a
  763. * heart-beat mailbox is issued and timer set properly. Otherwise, if there
  764. * has been a heart-beat mailbox command outstanding, the HBA shall be put
  765. * to offline.
  766. **/
  767. void
  768. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  769. {
  770. struct lpfc_vport **vports;
  771. LPFC_MBOXQ_t *pmboxq;
  772. struct lpfc_dmabuf *buf_ptr;
  773. int retval, i;
  774. struct lpfc_sli *psli = &phba->sli;
  775. LIST_HEAD(completions);
  776. vports = lpfc_create_vport_work_array(phba);
  777. if (vports != NULL)
  778. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  779. lpfc_rcv_seq_check_edtov(vports[i]);
  780. lpfc_destroy_vport_work_array(phba, vports);
  781. if ((phba->link_state == LPFC_HBA_ERROR) ||
  782. (phba->pport->load_flag & FC_UNLOADING) ||
  783. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  784. return;
  785. spin_lock_irq(&phba->pport->work_port_lock);
  786. if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
  787. jiffies)) {
  788. spin_unlock_irq(&phba->pport->work_port_lock);
  789. if (!phba->hb_outstanding)
  790. mod_timer(&phba->hb_tmofunc,
  791. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  792. else
  793. mod_timer(&phba->hb_tmofunc,
  794. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  795. return;
  796. }
  797. spin_unlock_irq(&phba->pport->work_port_lock);
  798. if (phba->elsbuf_cnt &&
  799. (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
  800. spin_lock_irq(&phba->hbalock);
  801. list_splice_init(&phba->elsbuf, &completions);
  802. phba->elsbuf_cnt = 0;
  803. phba->elsbuf_prev_cnt = 0;
  804. spin_unlock_irq(&phba->hbalock);
  805. while (!list_empty(&completions)) {
  806. list_remove_head(&completions, buf_ptr,
  807. struct lpfc_dmabuf, list);
  808. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  809. kfree(buf_ptr);
  810. }
  811. }
  812. phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
  813. /* If there is no heart beat outstanding, issue a heartbeat command */
  814. if (phba->cfg_enable_hba_heartbeat) {
  815. if (!phba->hb_outstanding) {
  816. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  817. if (!pmboxq) {
  818. mod_timer(&phba->hb_tmofunc,
  819. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  820. return;
  821. }
  822. lpfc_heart_beat(phba, pmboxq);
  823. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  824. pmboxq->vport = phba->pport;
  825. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  826. if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
  827. mempool_free(pmboxq, phba->mbox_mem_pool);
  828. mod_timer(&phba->hb_tmofunc,
  829. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  830. return;
  831. }
  832. mod_timer(&phba->hb_tmofunc,
  833. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  834. phba->hb_outstanding = 1;
  835. return;
  836. } else {
  837. /*
  838. * If heart beat timeout called with hb_outstanding set
  839. * we need to take the HBA offline.
  840. */
  841. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  842. "0459 Adapter heartbeat failure, "
  843. "taking this port offline.\n");
  844. spin_lock_irq(&phba->hbalock);
  845. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  846. spin_unlock_irq(&phba->hbalock);
  847. lpfc_offline_prep(phba);
  848. lpfc_offline(phba);
  849. lpfc_unblock_mgmt_io(phba);
  850. phba->link_state = LPFC_HBA_ERROR;
  851. lpfc_hba_down_post(phba);
  852. }
  853. }
  854. }
  855. /**
  856. * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
  857. * @phba: pointer to lpfc hba data structure.
  858. *
  859. * This routine is called to bring the HBA offline when HBA hardware error
  860. * other than Port Error 6 has been detected.
  861. **/
  862. static void
  863. lpfc_offline_eratt(struct lpfc_hba *phba)
  864. {
  865. struct lpfc_sli *psli = &phba->sli;
  866. spin_lock_irq(&phba->hbalock);
  867. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  868. spin_unlock_irq(&phba->hbalock);
  869. lpfc_offline_prep(phba);
  870. lpfc_offline(phba);
  871. lpfc_reset_barrier(phba);
  872. spin_lock_irq(&phba->hbalock);
  873. lpfc_sli_brdreset(phba);
  874. spin_unlock_irq(&phba->hbalock);
  875. lpfc_hba_down_post(phba);
  876. lpfc_sli_brdready(phba, HS_MBRDY);
  877. lpfc_unblock_mgmt_io(phba);
  878. phba->link_state = LPFC_HBA_ERROR;
  879. return;
  880. }
  881. /**
  882. * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
  883. * @phba: pointer to lpfc hba data structure.
  884. *
  885. * This routine is called to bring a SLI4 HBA offline when HBA hardware error
  886. * other than Port Error 6 has been detected.
  887. **/
  888. static void
  889. lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
  890. {
  891. lpfc_offline_prep(phba);
  892. lpfc_offline(phba);
  893. lpfc_sli4_brdreset(phba);
  894. lpfc_hba_down_post(phba);
  895. lpfc_sli4_post_status_check(phba);
  896. lpfc_unblock_mgmt_io(phba);
  897. phba->link_state = LPFC_HBA_ERROR;
  898. }
  899. /**
  900. * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
  901. * @phba: pointer to lpfc hba data structure.
  902. *
  903. * This routine is invoked to handle the deferred HBA hardware error
  904. * conditions. This type of error is indicated by HBA by setting ER1
  905. * and another ER bit in the host status register. The driver will
  906. * wait until the ER1 bit clears before handling the error condition.
  907. **/
  908. static void
  909. lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
  910. {
  911. uint32_t old_host_status = phba->work_hs;
  912. struct lpfc_sli_ring *pring;
  913. struct lpfc_sli *psli = &phba->sli;
  914. /* If the pci channel is offline, ignore possible errors,
  915. * since we cannot communicate with the pci card anyway.
  916. */
  917. if (pci_channel_offline(phba->pcidev)) {
  918. spin_lock_irq(&phba->hbalock);
  919. phba->hba_flag &= ~DEFER_ERATT;
  920. spin_unlock_irq(&phba->hbalock);
  921. return;
  922. }
  923. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  924. "0479 Deferred Adapter Hardware Error "
  925. "Data: x%x x%x x%x\n",
  926. phba->work_hs,
  927. phba->work_status[0], phba->work_status[1]);
  928. spin_lock_irq(&phba->hbalock);
  929. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  930. spin_unlock_irq(&phba->hbalock);
  931. /*
  932. * Firmware stops when it triggred erratt. That could cause the I/Os
  933. * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
  934. * SCSI layer retry it after re-establishing link.
  935. */
  936. pring = &psli->ring[psli->fcp_ring];
  937. lpfc_sli_abort_iocb_ring(phba, pring);
  938. /*
  939. * There was a firmware error. Take the hba offline and then
  940. * attempt to restart it.
  941. */
  942. lpfc_offline_prep(phba);
  943. lpfc_offline(phba);
  944. /* Wait for the ER1 bit to clear.*/
  945. while (phba->work_hs & HS_FFER1) {
  946. msleep(100);
  947. phba->work_hs = readl(phba->HSregaddr);
  948. /* If driver is unloading let the worker thread continue */
  949. if (phba->pport->load_flag & FC_UNLOADING) {
  950. phba->work_hs = 0;
  951. break;
  952. }
  953. }
  954. /*
  955. * This is to ptrotect against a race condition in which
  956. * first write to the host attention register clear the
  957. * host status register.
  958. */
  959. if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
  960. phba->work_hs = old_host_status & ~HS_FFER1;
  961. spin_lock_irq(&phba->hbalock);
  962. phba->hba_flag &= ~DEFER_ERATT;
  963. spin_unlock_irq(&phba->hbalock);
  964. phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
  965. phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
  966. }
  967. static void
  968. lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
  969. {
  970. struct lpfc_board_event_header board_event;
  971. struct Scsi_Host *shost;
  972. board_event.event_type = FC_REG_BOARD_EVENT;
  973. board_event.subcategory = LPFC_EVENT_PORTINTERR;
  974. shost = lpfc_shost_from_vport(phba->pport);
  975. fc_host_post_vendor_event(shost, fc_get_event_number(),
  976. sizeof(board_event),
  977. (char *) &board_event,
  978. LPFC_NL_VENDOR_ID);
  979. }
  980. /**
  981. * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
  982. * @phba: pointer to lpfc hba data structure.
  983. *
  984. * This routine is invoked to handle the following HBA hardware error
  985. * conditions:
  986. * 1 - HBA error attention interrupt
  987. * 2 - DMA ring index out of range
  988. * 3 - Mailbox command came back as unknown
  989. **/
  990. static void
  991. lpfc_handle_eratt_s3(struct lpfc_hba *phba)
  992. {
  993. struct lpfc_vport *vport = phba->pport;
  994. struct lpfc_sli *psli = &phba->sli;
  995. struct lpfc_sli_ring *pring;
  996. uint32_t event_data;
  997. unsigned long temperature;
  998. struct temp_event temp_event_data;
  999. struct Scsi_Host *shost;
  1000. /* If the pci channel is offline, ignore possible errors,
  1001. * since we cannot communicate with the pci card anyway.
  1002. */
  1003. if (pci_channel_offline(phba->pcidev)) {
  1004. spin_lock_irq(&phba->hbalock);
  1005. phba->hba_flag &= ~DEFER_ERATT;
  1006. spin_unlock_irq(&phba->hbalock);
  1007. return;
  1008. }
  1009. /* If resets are disabled then leave the HBA alone and return */
  1010. if (!phba->cfg_enable_hba_reset)
  1011. return;
  1012. /* Send an internal error event to mgmt application */
  1013. lpfc_board_errevt_to_mgmt(phba);
  1014. if (phba->hba_flag & DEFER_ERATT)
  1015. lpfc_handle_deferred_eratt(phba);
  1016. if (phba->work_hs & HS_FFER6) {
  1017. /* Re-establishing Link */
  1018. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1019. "1301 Re-establishing Link "
  1020. "Data: x%x x%x x%x\n",
  1021. phba->work_hs,
  1022. phba->work_status[0], phba->work_status[1]);
  1023. spin_lock_irq(&phba->hbalock);
  1024. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1025. spin_unlock_irq(&phba->hbalock);
  1026. /*
  1027. * Firmware stops when it triggled erratt with HS_FFER6.
  1028. * That could cause the I/Os dropped by the firmware.
  1029. * Error iocb (I/O) on txcmplq and let the SCSI layer
  1030. * retry it after re-establishing link.
  1031. */
  1032. pring = &psli->ring[psli->fcp_ring];
  1033. lpfc_sli_abort_iocb_ring(phba, pring);
  1034. /*
  1035. * There was a firmware error. Take the hba offline and then
  1036. * attempt to restart it.
  1037. */
  1038. lpfc_offline_prep(phba);
  1039. lpfc_offline(phba);
  1040. lpfc_sli_brdrestart(phba);
  1041. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  1042. lpfc_unblock_mgmt_io(phba);
  1043. return;
  1044. }
  1045. lpfc_unblock_mgmt_io(phba);
  1046. } else if (phba->work_hs & HS_CRIT_TEMP) {
  1047. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  1048. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  1049. temp_event_data.event_code = LPFC_CRIT_TEMP;
  1050. temp_event_data.data = (uint32_t)temperature;
  1051. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1052. "0406 Adapter maximum temperature exceeded "
  1053. "(%ld), taking this port offline "
  1054. "Data: x%x x%x x%x\n",
  1055. temperature, phba->work_hs,
  1056. phba->work_status[0], phba->work_status[1]);
  1057. shost = lpfc_shost_from_vport(phba->pport);
  1058. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1059. sizeof(temp_event_data),
  1060. (char *) &temp_event_data,
  1061. SCSI_NL_VID_TYPE_PCI
  1062. | PCI_VENDOR_ID_EMULEX);
  1063. spin_lock_irq(&phba->hbalock);
  1064. phba->over_temp_state = HBA_OVER_TEMP;
  1065. spin_unlock_irq(&phba->hbalock);
  1066. lpfc_offline_eratt(phba);
  1067. } else {
  1068. /* The if clause above forces this code path when the status
  1069. * failure is a value other than FFER6. Do not call the offline
  1070. * twice. This is the adapter hardware error path.
  1071. */
  1072. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1073. "0457 Adapter Hardware Error "
  1074. "Data: x%x x%x x%x\n",
  1075. phba->work_hs,
  1076. phba->work_status[0], phba->work_status[1]);
  1077. event_data = FC_REG_DUMP_EVENT;
  1078. shost = lpfc_shost_from_vport(vport);
  1079. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1080. sizeof(event_data), (char *) &event_data,
  1081. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1082. lpfc_offline_eratt(phba);
  1083. }
  1084. return;
  1085. }
  1086. /**
  1087. * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
  1088. * @phba: pointer to lpfc hba data structure.
  1089. *
  1090. * This routine is invoked to handle the SLI4 HBA hardware error attention
  1091. * conditions.
  1092. **/
  1093. static void
  1094. lpfc_handle_eratt_s4(struct lpfc_hba *phba)
  1095. {
  1096. struct lpfc_vport *vport = phba->pport;
  1097. uint32_t event_data;
  1098. struct Scsi_Host *shost;
  1099. /* If the pci channel is offline, ignore possible errors, since
  1100. * we cannot communicate with the pci card anyway.
  1101. */
  1102. if (pci_channel_offline(phba->pcidev))
  1103. return;
  1104. /* If resets are disabled then leave the HBA alone and return */
  1105. if (!phba->cfg_enable_hba_reset)
  1106. return;
  1107. /* Send an internal error event to mgmt application */
  1108. lpfc_board_errevt_to_mgmt(phba);
  1109. /* For now, the actual action for SLI4 device handling is not
  1110. * specified yet, just treated it as adaptor hardware failure
  1111. */
  1112. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1113. "0143 SLI4 Adapter Hardware Error Data: x%x x%x\n",
  1114. phba->work_status[0], phba->work_status[1]);
  1115. event_data = FC_REG_DUMP_EVENT;
  1116. shost = lpfc_shost_from_vport(vport);
  1117. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1118. sizeof(event_data), (char *) &event_data,
  1119. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1120. lpfc_sli4_offline_eratt(phba);
  1121. }
  1122. /**
  1123. * lpfc_handle_eratt - Wrapper func for handling hba error attention
  1124. * @phba: pointer to lpfc HBA data structure.
  1125. *
  1126. * This routine wraps the actual SLI3 or SLI4 hba error attention handling
  1127. * routine from the API jump table function pointer from the lpfc_hba struct.
  1128. *
  1129. * Return codes
  1130. * 0 - sucess.
  1131. * Any other value - error.
  1132. **/
  1133. void
  1134. lpfc_handle_eratt(struct lpfc_hba *phba)
  1135. {
  1136. (*phba->lpfc_handle_eratt)(phba);
  1137. }
  1138. /**
  1139. * lpfc_handle_latt - The HBA link event handler
  1140. * @phba: pointer to lpfc hba data structure.
  1141. *
  1142. * This routine is invoked from the worker thread to handle a HBA host
  1143. * attention link event.
  1144. **/
  1145. void
  1146. lpfc_handle_latt(struct lpfc_hba *phba)
  1147. {
  1148. struct lpfc_vport *vport = phba->pport;
  1149. struct lpfc_sli *psli = &phba->sli;
  1150. LPFC_MBOXQ_t *pmb;
  1151. volatile uint32_t control;
  1152. struct lpfc_dmabuf *mp;
  1153. int rc = 0;
  1154. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1155. if (!pmb) {
  1156. rc = 1;
  1157. goto lpfc_handle_latt_err_exit;
  1158. }
  1159. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1160. if (!mp) {
  1161. rc = 2;
  1162. goto lpfc_handle_latt_free_pmb;
  1163. }
  1164. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  1165. if (!mp->virt) {
  1166. rc = 3;
  1167. goto lpfc_handle_latt_free_mp;
  1168. }
  1169. /* Cleanup any outstanding ELS commands */
  1170. lpfc_els_flush_all_cmd(phba);
  1171. psli->slistat.link_event++;
  1172. lpfc_read_la(phba, pmb, mp);
  1173. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
  1174. pmb->vport = vport;
  1175. /* Block ELS IOCBs until we have processed this mbox command */
  1176. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  1177. rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
  1178. if (rc == MBX_NOT_FINISHED) {
  1179. rc = 4;
  1180. goto lpfc_handle_latt_free_mbuf;
  1181. }
  1182. /* Clear Link Attention in HA REG */
  1183. spin_lock_irq(&phba->hbalock);
  1184. writel(HA_LATT, phba->HAregaddr);
  1185. readl(phba->HAregaddr); /* flush */
  1186. spin_unlock_irq(&phba->hbalock);
  1187. return;
  1188. lpfc_handle_latt_free_mbuf:
  1189. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  1190. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1191. lpfc_handle_latt_free_mp:
  1192. kfree(mp);
  1193. lpfc_handle_latt_free_pmb:
  1194. mempool_free(pmb, phba->mbox_mem_pool);
  1195. lpfc_handle_latt_err_exit:
  1196. /* Enable Link attention interrupts */
  1197. spin_lock_irq(&phba->hbalock);
  1198. psli->sli_flag |= LPFC_PROCESS_LA;
  1199. control = readl(phba->HCregaddr);
  1200. control |= HC_LAINT_ENA;
  1201. writel(control, phba->HCregaddr);
  1202. readl(phba->HCregaddr); /* flush */
  1203. /* Clear Link Attention in HA REG */
  1204. writel(HA_LATT, phba->HAregaddr);
  1205. readl(phba->HAregaddr); /* flush */
  1206. spin_unlock_irq(&phba->hbalock);
  1207. lpfc_linkdown(phba);
  1208. phba->link_state = LPFC_HBA_ERROR;
  1209. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1210. "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
  1211. return;
  1212. }
  1213. /**
  1214. * lpfc_parse_vpd - Parse VPD (Vital Product Data)
  1215. * @phba: pointer to lpfc hba data structure.
  1216. * @vpd: pointer to the vital product data.
  1217. * @len: length of the vital product data in bytes.
  1218. *
  1219. * This routine parses the Vital Product Data (VPD). The VPD is treated as
  1220. * an array of characters. In this routine, the ModelName, ProgramType, and
  1221. * ModelDesc, etc. fields of the phba data structure will be populated.
  1222. *
  1223. * Return codes
  1224. * 0 - pointer to the VPD passed in is NULL
  1225. * 1 - success
  1226. **/
  1227. int
  1228. lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
  1229. {
  1230. uint8_t lenlo, lenhi;
  1231. int Length;
  1232. int i, j;
  1233. int finished = 0;
  1234. int index = 0;
  1235. if (!vpd)
  1236. return 0;
  1237. /* Vital Product */
  1238. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1239. "0455 Vital Product Data: x%x x%x x%x x%x\n",
  1240. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  1241. (uint32_t) vpd[3]);
  1242. while (!finished && (index < (len - 4))) {
  1243. switch (vpd[index]) {
  1244. case 0x82:
  1245. case 0x91:
  1246. index += 1;
  1247. lenlo = vpd[index];
  1248. index += 1;
  1249. lenhi = vpd[index];
  1250. index += 1;
  1251. i = ((((unsigned short)lenhi) << 8) + lenlo);
  1252. index += i;
  1253. break;
  1254. case 0x90:
  1255. index += 1;
  1256. lenlo = vpd[index];
  1257. index += 1;
  1258. lenhi = vpd[index];
  1259. index += 1;
  1260. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  1261. if (Length > len - index)
  1262. Length = len - index;
  1263. while (Length > 0) {
  1264. /* Look for Serial Number */
  1265. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  1266. index += 2;
  1267. i = vpd[index];
  1268. index += 1;
  1269. j = 0;
  1270. Length -= (3+i);
  1271. while(i--) {
  1272. phba->SerialNumber[j++] = vpd[index++];
  1273. if (j == 31)
  1274. break;
  1275. }
  1276. phba->SerialNumber[j] = 0;
  1277. continue;
  1278. }
  1279. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  1280. phba->vpd_flag |= VPD_MODEL_DESC;
  1281. index += 2;
  1282. i = vpd[index];
  1283. index += 1;
  1284. j = 0;
  1285. Length -= (3+i);
  1286. while(i--) {
  1287. phba->ModelDesc[j++] = vpd[index++];
  1288. if (j == 255)
  1289. break;
  1290. }
  1291. phba->ModelDesc[j] = 0;
  1292. continue;
  1293. }
  1294. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  1295. phba->vpd_flag |= VPD_MODEL_NAME;
  1296. index += 2;
  1297. i = vpd[index];
  1298. index += 1;
  1299. j = 0;
  1300. Length -= (3+i);
  1301. while(i--) {
  1302. phba->ModelName[j++] = vpd[index++];
  1303. if (j == 79)
  1304. break;
  1305. }
  1306. phba->ModelName[j] = 0;
  1307. continue;
  1308. }
  1309. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  1310. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  1311. index += 2;
  1312. i = vpd[index];
  1313. index += 1;
  1314. j = 0;
  1315. Length -= (3+i);
  1316. while(i--) {
  1317. phba->ProgramType[j++] = vpd[index++];
  1318. if (j == 255)
  1319. break;
  1320. }
  1321. phba->ProgramType[j] = 0;
  1322. continue;
  1323. }
  1324. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  1325. phba->vpd_flag |= VPD_PORT;
  1326. index += 2;
  1327. i = vpd[index];
  1328. index += 1;
  1329. j = 0;
  1330. Length -= (3+i);
  1331. while(i--) {
  1332. phba->Port[j++] = vpd[index++];
  1333. if (j == 19)
  1334. break;
  1335. }
  1336. phba->Port[j] = 0;
  1337. continue;
  1338. }
  1339. else {
  1340. index += 2;
  1341. i = vpd[index];
  1342. index += 1;
  1343. index += i;
  1344. Length -= (3 + i);
  1345. }
  1346. }
  1347. finished = 0;
  1348. break;
  1349. case 0x78:
  1350. finished = 1;
  1351. break;
  1352. default:
  1353. index ++;
  1354. break;
  1355. }
  1356. }
  1357. return(1);
  1358. }
  1359. /**
  1360. * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
  1361. * @phba: pointer to lpfc hba data structure.
  1362. * @mdp: pointer to the data structure to hold the derived model name.
  1363. * @descp: pointer to the data structure to hold the derived description.
  1364. *
  1365. * This routine retrieves HBA's description based on its registered PCI device
  1366. * ID. The @descp passed into this function points to an array of 256 chars. It
  1367. * shall be returned with the model name, maximum speed, and the host bus type.
  1368. * The @mdp passed into this function points to an array of 80 chars. When the
  1369. * function returns, the @mdp will be filled with the model name.
  1370. **/
  1371. static void
  1372. lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  1373. {
  1374. lpfc_vpd_t *vp;
  1375. uint16_t dev_id = phba->pcidev->device;
  1376. int max_speed;
  1377. int GE = 0;
  1378. int oneConnect = 0; /* default is not a oneConnect */
  1379. struct {
  1380. char * name;
  1381. int max_speed;
  1382. char * bus;
  1383. } m = {"<Unknown>", 0, ""};
  1384. if (mdp && mdp[0] != '\0'
  1385. && descp && descp[0] != '\0')
  1386. return;
  1387. if (phba->lmt & LMT_10Gb)
  1388. max_speed = 10;
  1389. else if (phba->lmt & LMT_8Gb)
  1390. max_speed = 8;
  1391. else if (phba->lmt & LMT_4Gb)
  1392. max_speed = 4;
  1393. else if (phba->lmt & LMT_2Gb)
  1394. max_speed = 2;
  1395. else
  1396. max_speed = 1;
  1397. vp = &phba->vpd;
  1398. switch (dev_id) {
  1399. case PCI_DEVICE_ID_FIREFLY:
  1400. m = (typeof(m)){"LP6000", max_speed, "PCI"};
  1401. break;
  1402. case PCI_DEVICE_ID_SUPERFLY:
  1403. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  1404. m = (typeof(m)){"LP7000", max_speed, "PCI"};
  1405. else
  1406. m = (typeof(m)){"LP7000E", max_speed, "PCI"};
  1407. break;
  1408. case PCI_DEVICE_ID_DRAGONFLY:
  1409. m = (typeof(m)){"LP8000", max_speed, "PCI"};
  1410. break;
  1411. case PCI_DEVICE_ID_CENTAUR:
  1412. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  1413. m = (typeof(m)){"LP9002", max_speed, "PCI"};
  1414. else
  1415. m = (typeof(m)){"LP9000", max_speed, "PCI"};
  1416. break;
  1417. case PCI_DEVICE_ID_RFLY:
  1418. m = (typeof(m)){"LP952", max_speed, "PCI"};
  1419. break;
  1420. case PCI_DEVICE_ID_PEGASUS:
  1421. m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
  1422. break;
  1423. case PCI_DEVICE_ID_THOR:
  1424. m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
  1425. break;
  1426. case PCI_DEVICE_ID_VIPER:
  1427. m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
  1428. break;
  1429. case PCI_DEVICE_ID_PFLY:
  1430. m = (typeof(m)){"LP982", max_speed, "PCI-X"};
  1431. break;
  1432. case PCI_DEVICE_ID_TFLY:
  1433. m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
  1434. break;
  1435. case PCI_DEVICE_ID_HELIOS:
  1436. m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
  1437. break;
  1438. case PCI_DEVICE_ID_HELIOS_SCSP:
  1439. m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
  1440. break;
  1441. case PCI_DEVICE_ID_HELIOS_DCSP:
  1442. m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
  1443. break;
  1444. case PCI_DEVICE_ID_NEPTUNE:
  1445. m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
  1446. break;
  1447. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  1448. m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
  1449. break;
  1450. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  1451. m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
  1452. break;
  1453. case PCI_DEVICE_ID_BMID:
  1454. m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
  1455. break;
  1456. case PCI_DEVICE_ID_BSMB:
  1457. m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
  1458. break;
  1459. case PCI_DEVICE_ID_ZEPHYR:
  1460. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  1461. break;
  1462. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  1463. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  1464. break;
  1465. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  1466. m = (typeof(m)){"LP2105", max_speed, "PCIe"};
  1467. GE = 1;
  1468. break;
  1469. case PCI_DEVICE_ID_ZMID:
  1470. m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
  1471. break;
  1472. case PCI_DEVICE_ID_ZSMB:
  1473. m = (typeof(m)){"LPe111", max_speed, "PCIe"};
  1474. break;
  1475. case PCI_DEVICE_ID_LP101:
  1476. m = (typeof(m)){"LP101", max_speed, "PCI-X"};
  1477. break;
  1478. case PCI_DEVICE_ID_LP10000S:
  1479. m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
  1480. break;
  1481. case PCI_DEVICE_ID_LP11000S:
  1482. m = (typeof(m)){"LP11000-S", max_speed,
  1483. "PCI-X2"};
  1484. break;
  1485. case PCI_DEVICE_ID_LPE11000S:
  1486. m = (typeof(m)){"LPe11000-S", max_speed,
  1487. "PCIe"};
  1488. break;
  1489. case PCI_DEVICE_ID_SAT:
  1490. m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
  1491. break;
  1492. case PCI_DEVICE_ID_SAT_MID:
  1493. m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
  1494. break;
  1495. case PCI_DEVICE_ID_SAT_SMB:
  1496. m = (typeof(m)){"LPe121", max_speed, "PCIe"};
  1497. break;
  1498. case PCI_DEVICE_ID_SAT_DCSP:
  1499. m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
  1500. break;
  1501. case PCI_DEVICE_ID_SAT_SCSP:
  1502. m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
  1503. break;
  1504. case PCI_DEVICE_ID_SAT_S:
  1505. m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
  1506. break;
  1507. case PCI_DEVICE_ID_HORNET:
  1508. m = (typeof(m)){"LP21000", max_speed, "PCIe"};
  1509. GE = 1;
  1510. break;
  1511. case PCI_DEVICE_ID_PROTEUS_VF:
  1512. m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
  1513. break;
  1514. case PCI_DEVICE_ID_PROTEUS_PF:
  1515. m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
  1516. break;
  1517. case PCI_DEVICE_ID_PROTEUS_S:
  1518. m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"};
  1519. break;
  1520. case PCI_DEVICE_ID_TIGERSHARK:
  1521. oneConnect = 1;
  1522. m = (typeof(m)) {"OCe10100-F", max_speed, "PCIe"};
  1523. break;
  1524. case PCI_DEVICE_ID_TS_BE3:
  1525. oneConnect = 1;
  1526. m = (typeof(m)) {"OCeXXXXX-F", max_speed, "PCIe"};
  1527. break;
  1528. default:
  1529. m = (typeof(m)){ NULL };
  1530. break;
  1531. }
  1532. if (mdp && mdp[0] == '\0')
  1533. snprintf(mdp, 79,"%s", m.name);
  1534. /* oneConnect hba requires special processing, they are all initiators
  1535. * and we put the port number on the end
  1536. */
  1537. if (descp && descp[0] == '\0') {
  1538. if (oneConnect)
  1539. snprintf(descp, 255,
  1540. "Emulex OneConnect %s, FCoE Initiator, Port %s",
  1541. m.name,
  1542. phba->Port);
  1543. else
  1544. snprintf(descp, 255,
  1545. "Emulex %s %d%s %s %s",
  1546. m.name, m.max_speed,
  1547. (GE) ? "GE" : "Gb",
  1548. m.bus,
  1549. (GE) ? "FCoE Adapter" :
  1550. "Fibre Channel Adapter");
  1551. }
  1552. }
  1553. /**
  1554. * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
  1555. * @phba: pointer to lpfc hba data structure.
  1556. * @pring: pointer to a IOCB ring.
  1557. * @cnt: the number of IOCBs to be posted to the IOCB ring.
  1558. *
  1559. * This routine posts a given number of IOCBs with the associated DMA buffer
  1560. * descriptors specified by the cnt argument to the given IOCB ring.
  1561. *
  1562. * Return codes
  1563. * The number of IOCBs NOT able to be posted to the IOCB ring.
  1564. **/
  1565. int
  1566. lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
  1567. {
  1568. IOCB_t *icmd;
  1569. struct lpfc_iocbq *iocb;
  1570. struct lpfc_dmabuf *mp1, *mp2;
  1571. cnt += pring->missbufcnt;
  1572. /* While there are buffers to post */
  1573. while (cnt > 0) {
  1574. /* Allocate buffer for command iocb */
  1575. iocb = lpfc_sli_get_iocbq(phba);
  1576. if (iocb == NULL) {
  1577. pring->missbufcnt = cnt;
  1578. return cnt;
  1579. }
  1580. icmd = &iocb->iocb;
  1581. /* 2 buffers can be posted per command */
  1582. /* Allocate buffer to post */
  1583. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1584. if (mp1)
  1585. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
  1586. if (!mp1 || !mp1->virt) {
  1587. kfree(mp1);
  1588. lpfc_sli_release_iocbq(phba, iocb);
  1589. pring->missbufcnt = cnt;
  1590. return cnt;
  1591. }
  1592. INIT_LIST_HEAD(&mp1->list);
  1593. /* Allocate buffer to post */
  1594. if (cnt > 1) {
  1595. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1596. if (mp2)
  1597. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  1598. &mp2->phys);
  1599. if (!mp2 || !mp2->virt) {
  1600. kfree(mp2);
  1601. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1602. kfree(mp1);
  1603. lpfc_sli_release_iocbq(phba, iocb);
  1604. pring->missbufcnt = cnt;
  1605. return cnt;
  1606. }
  1607. INIT_LIST_HEAD(&mp2->list);
  1608. } else {
  1609. mp2 = NULL;
  1610. }
  1611. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  1612. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  1613. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  1614. icmd->ulpBdeCount = 1;
  1615. cnt--;
  1616. if (mp2) {
  1617. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  1618. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  1619. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  1620. cnt--;
  1621. icmd->ulpBdeCount = 2;
  1622. }
  1623. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  1624. icmd->ulpLe = 1;
  1625. if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
  1626. IOCB_ERROR) {
  1627. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1628. kfree(mp1);
  1629. cnt++;
  1630. if (mp2) {
  1631. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  1632. kfree(mp2);
  1633. cnt++;
  1634. }
  1635. lpfc_sli_release_iocbq(phba, iocb);
  1636. pring->missbufcnt = cnt;
  1637. return cnt;
  1638. }
  1639. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  1640. if (mp2)
  1641. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  1642. }
  1643. pring->missbufcnt = 0;
  1644. return 0;
  1645. }
  1646. /**
  1647. * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
  1648. * @phba: pointer to lpfc hba data structure.
  1649. *
  1650. * This routine posts initial receive IOCB buffers to the ELS ring. The
  1651. * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
  1652. * set to 64 IOCBs.
  1653. *
  1654. * Return codes
  1655. * 0 - success (currently always success)
  1656. **/
  1657. static int
  1658. lpfc_post_rcv_buf(struct lpfc_hba *phba)
  1659. {
  1660. struct lpfc_sli *psli = &phba->sli;
  1661. /* Ring 0, ELS / CT buffers */
  1662. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
  1663. /* Ring 2 - FCP no buffers needed */
  1664. return 0;
  1665. }
  1666. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  1667. /**
  1668. * lpfc_sha_init - Set up initial array of hash table entries
  1669. * @HashResultPointer: pointer to an array as hash table.
  1670. *
  1671. * This routine sets up the initial values to the array of hash table entries
  1672. * for the LC HBAs.
  1673. **/
  1674. static void
  1675. lpfc_sha_init(uint32_t * HashResultPointer)
  1676. {
  1677. HashResultPointer[0] = 0x67452301;
  1678. HashResultPointer[1] = 0xEFCDAB89;
  1679. HashResultPointer[2] = 0x98BADCFE;
  1680. HashResultPointer[3] = 0x10325476;
  1681. HashResultPointer[4] = 0xC3D2E1F0;
  1682. }
  1683. /**
  1684. * lpfc_sha_iterate - Iterate initial hash table with the working hash table
  1685. * @HashResultPointer: pointer to an initial/result hash table.
  1686. * @HashWorkingPointer: pointer to an working hash table.
  1687. *
  1688. * This routine iterates an initial hash table pointed by @HashResultPointer
  1689. * with the values from the working hash table pointeed by @HashWorkingPointer.
  1690. * The results are putting back to the initial hash table, returned through
  1691. * the @HashResultPointer as the result hash table.
  1692. **/
  1693. static void
  1694. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  1695. {
  1696. int t;
  1697. uint32_t TEMP;
  1698. uint32_t A, B, C, D, E;
  1699. t = 16;
  1700. do {
  1701. HashWorkingPointer[t] =
  1702. S(1,
  1703. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  1704. 8] ^
  1705. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  1706. } while (++t <= 79);
  1707. t = 0;
  1708. A = HashResultPointer[0];
  1709. B = HashResultPointer[1];
  1710. C = HashResultPointer[2];
  1711. D = HashResultPointer[3];
  1712. E = HashResultPointer[4];
  1713. do {
  1714. if (t < 20) {
  1715. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  1716. } else if (t < 40) {
  1717. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  1718. } else if (t < 60) {
  1719. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  1720. } else {
  1721. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  1722. }
  1723. TEMP += S(5, A) + E + HashWorkingPointer[t];
  1724. E = D;
  1725. D = C;
  1726. C = S(30, B);
  1727. B = A;
  1728. A = TEMP;
  1729. } while (++t <= 79);
  1730. HashResultPointer[0] += A;
  1731. HashResultPointer[1] += B;
  1732. HashResultPointer[2] += C;
  1733. HashResultPointer[3] += D;
  1734. HashResultPointer[4] += E;
  1735. }
  1736. /**
  1737. * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
  1738. * @RandomChallenge: pointer to the entry of host challenge random number array.
  1739. * @HashWorking: pointer to the entry of the working hash array.
  1740. *
  1741. * This routine calculates the working hash array referred by @HashWorking
  1742. * from the challenge random numbers associated with the host, referred by
  1743. * @RandomChallenge. The result is put into the entry of the working hash
  1744. * array and returned by reference through @HashWorking.
  1745. **/
  1746. static void
  1747. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  1748. {
  1749. *HashWorking = (*RandomChallenge ^ *HashWorking);
  1750. }
  1751. /**
  1752. * lpfc_hba_init - Perform special handling for LC HBA initialization
  1753. * @phba: pointer to lpfc hba data structure.
  1754. * @hbainit: pointer to an array of unsigned 32-bit integers.
  1755. *
  1756. * This routine performs the special handling for LC HBA initialization.
  1757. **/
  1758. void
  1759. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  1760. {
  1761. int t;
  1762. uint32_t *HashWorking;
  1763. uint32_t *pwwnn = (uint32_t *) phba->wwnn;
  1764. HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
  1765. if (!HashWorking)
  1766. return;
  1767. HashWorking[0] = HashWorking[78] = *pwwnn++;
  1768. HashWorking[1] = HashWorking[79] = *pwwnn;
  1769. for (t = 0; t < 7; t++)
  1770. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  1771. lpfc_sha_init(hbainit);
  1772. lpfc_sha_iterate(hbainit, HashWorking);
  1773. kfree(HashWorking);
  1774. }
  1775. /**
  1776. * lpfc_cleanup - Performs vport cleanups before deleting a vport
  1777. * @vport: pointer to a virtual N_Port data structure.
  1778. *
  1779. * This routine performs the necessary cleanups before deleting the @vport.
  1780. * It invokes the discovery state machine to perform necessary state
  1781. * transitions and to release the ndlps associated with the @vport. Note,
  1782. * the physical port is treated as @vport 0.
  1783. **/
  1784. void
  1785. lpfc_cleanup(struct lpfc_vport *vport)
  1786. {
  1787. struct lpfc_hba *phba = vport->phba;
  1788. struct lpfc_nodelist *ndlp, *next_ndlp;
  1789. int i = 0;
  1790. if (phba->link_state > LPFC_LINK_DOWN)
  1791. lpfc_port_link_failure(vport);
  1792. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  1793. if (!NLP_CHK_NODE_ACT(ndlp)) {
  1794. ndlp = lpfc_enable_node(vport, ndlp,
  1795. NLP_STE_UNUSED_NODE);
  1796. if (!ndlp)
  1797. continue;
  1798. spin_lock_irq(&phba->ndlp_lock);
  1799. NLP_SET_FREE_REQ(ndlp);
  1800. spin_unlock_irq(&phba->ndlp_lock);
  1801. /* Trigger the release of the ndlp memory */
  1802. lpfc_nlp_put(ndlp);
  1803. continue;
  1804. }
  1805. spin_lock_irq(&phba->ndlp_lock);
  1806. if (NLP_CHK_FREE_REQ(ndlp)) {
  1807. /* The ndlp should not be in memory free mode already */
  1808. spin_unlock_irq(&phba->ndlp_lock);
  1809. continue;
  1810. } else
  1811. /* Indicate request for freeing ndlp memory */
  1812. NLP_SET_FREE_REQ(ndlp);
  1813. spin_unlock_irq(&phba->ndlp_lock);
  1814. if (vport->port_type != LPFC_PHYSICAL_PORT &&
  1815. ndlp->nlp_DID == Fabric_DID) {
  1816. /* Just free up ndlp with Fabric_DID for vports */
  1817. lpfc_nlp_put(ndlp);
  1818. continue;
  1819. }
  1820. if (ndlp->nlp_type & NLP_FABRIC)
  1821. lpfc_disc_state_machine(vport, ndlp, NULL,
  1822. NLP_EVT_DEVICE_RECOVERY);
  1823. lpfc_disc_state_machine(vport, ndlp, NULL,
  1824. NLP_EVT_DEVICE_RM);
  1825. }
  1826. /* At this point, ALL ndlp's should be gone
  1827. * because of the previous NLP_EVT_DEVICE_RM.
  1828. * Lets wait for this to happen, if needed.
  1829. */
  1830. while (!list_empty(&vport->fc_nodes)) {
  1831. if (i++ > 3000) {
  1832. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1833. "0233 Nodelist not empty\n");
  1834. list_for_each_entry_safe(ndlp, next_ndlp,
  1835. &vport->fc_nodes, nlp_listp) {
  1836. lpfc_printf_vlog(ndlp->vport, KERN_ERR,
  1837. LOG_NODE,
  1838. "0282 did:x%x ndlp:x%p "
  1839. "usgmap:x%x refcnt:%d\n",
  1840. ndlp->nlp_DID, (void *)ndlp,
  1841. ndlp->nlp_usg_map,
  1842. atomic_read(
  1843. &ndlp->kref.refcount));
  1844. }
  1845. break;
  1846. }
  1847. /* Wait for any activity on ndlps to settle */
  1848. msleep(10);
  1849. }
  1850. }
  1851. /**
  1852. * lpfc_stop_vport_timers - Stop all the timers associated with a vport
  1853. * @vport: pointer to a virtual N_Port data structure.
  1854. *
  1855. * This routine stops all the timers associated with a @vport. This function
  1856. * is invoked before disabling or deleting a @vport. Note that the physical
  1857. * port is treated as @vport 0.
  1858. **/
  1859. void
  1860. lpfc_stop_vport_timers(struct lpfc_vport *vport)
  1861. {
  1862. del_timer_sync(&vport->els_tmofunc);
  1863. del_timer_sync(&vport->fc_fdmitmo);
  1864. lpfc_can_disctmo(vport);
  1865. return;
  1866. }
  1867. /**
  1868. * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
  1869. * @phba: pointer to lpfc hba data structure.
  1870. *
  1871. * This routine stops all the timers associated with a HBA. This function is
  1872. * invoked before either putting a HBA offline or unloading the driver.
  1873. **/
  1874. void
  1875. lpfc_stop_hba_timers(struct lpfc_hba *phba)
  1876. {
  1877. lpfc_stop_vport_timers(phba->pport);
  1878. del_timer_sync(&phba->sli.mbox_tmo);
  1879. del_timer_sync(&phba->fabric_block_timer);
  1880. del_timer_sync(&phba->eratt_poll);
  1881. del_timer_sync(&phba->hb_tmofunc);
  1882. phba->hb_outstanding = 0;
  1883. switch (phba->pci_dev_grp) {
  1884. case LPFC_PCI_DEV_LP:
  1885. /* Stop any LightPulse device specific driver timers */
  1886. del_timer_sync(&phba->fcp_poll_timer);
  1887. break;
  1888. case LPFC_PCI_DEV_OC:
  1889. /* Stop any OneConnect device sepcific driver timers */
  1890. break;
  1891. default:
  1892. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1893. "0297 Invalid device group (x%x)\n",
  1894. phba->pci_dev_grp);
  1895. break;
  1896. }
  1897. return;
  1898. }
  1899. /**
  1900. * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
  1901. * @phba: pointer to lpfc hba data structure.
  1902. *
  1903. * This routine marks a HBA's management interface as blocked. Once the HBA's
  1904. * management interface is marked as blocked, all the user space access to
  1905. * the HBA, whether they are from sysfs interface or libdfc interface will
  1906. * all be blocked. The HBA is set to block the management interface when the
  1907. * driver prepares the HBA interface for online or offline.
  1908. **/
  1909. static void
  1910. lpfc_block_mgmt_io(struct lpfc_hba * phba)
  1911. {
  1912. unsigned long iflag;
  1913. spin_lock_irqsave(&phba->hbalock, iflag);
  1914. phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
  1915. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1916. }
  1917. /**
  1918. * lpfc_online - Initialize and bring a HBA online
  1919. * @phba: pointer to lpfc hba data structure.
  1920. *
  1921. * This routine initializes the HBA and brings a HBA online. During this
  1922. * process, the management interface is blocked to prevent user space access
  1923. * to the HBA interfering with the driver initialization.
  1924. *
  1925. * Return codes
  1926. * 0 - successful
  1927. * 1 - failed
  1928. **/
  1929. int
  1930. lpfc_online(struct lpfc_hba *phba)
  1931. {
  1932. struct lpfc_vport *vport;
  1933. struct lpfc_vport **vports;
  1934. int i;
  1935. if (!phba)
  1936. return 0;
  1937. vport = phba->pport;
  1938. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  1939. return 0;
  1940. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1941. "0458 Bring Adapter online\n");
  1942. lpfc_block_mgmt_io(phba);
  1943. if (!lpfc_sli_queue_setup(phba)) {
  1944. lpfc_unblock_mgmt_io(phba);
  1945. return 1;
  1946. }
  1947. if (phba->sli_rev == LPFC_SLI_REV4) {
  1948. if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
  1949. lpfc_unblock_mgmt_io(phba);
  1950. return 1;
  1951. }
  1952. } else {
  1953. if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
  1954. lpfc_unblock_mgmt_io(phba);
  1955. return 1;
  1956. }
  1957. }
  1958. vports = lpfc_create_vport_work_array(phba);
  1959. if (vports != NULL)
  1960. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  1961. struct Scsi_Host *shost;
  1962. shost = lpfc_shost_from_vport(vports[i]);
  1963. spin_lock_irq(shost->host_lock);
  1964. vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
  1965. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  1966. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  1967. if (phba->sli_rev == LPFC_SLI_REV4)
  1968. vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  1969. spin_unlock_irq(shost->host_lock);
  1970. }
  1971. lpfc_destroy_vport_work_array(phba, vports);
  1972. lpfc_unblock_mgmt_io(phba);
  1973. return 0;
  1974. }
  1975. /**
  1976. * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
  1977. * @phba: pointer to lpfc hba data structure.
  1978. *
  1979. * This routine marks a HBA's management interface as not blocked. Once the
  1980. * HBA's management interface is marked as not blocked, all the user space
  1981. * access to the HBA, whether they are from sysfs interface or libdfc
  1982. * interface will be allowed. The HBA is set to block the management interface
  1983. * when the driver prepares the HBA interface for online or offline and then
  1984. * set to unblock the management interface afterwards.
  1985. **/
  1986. void
  1987. lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
  1988. {
  1989. unsigned long iflag;
  1990. spin_lock_irqsave(&phba->hbalock, iflag);
  1991. phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
  1992. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1993. }
  1994. /**
  1995. * lpfc_offline_prep - Prepare a HBA to be brought offline
  1996. * @phba: pointer to lpfc hba data structure.
  1997. *
  1998. * This routine is invoked to prepare a HBA to be brought offline. It performs
  1999. * unregistration login to all the nodes on all vports and flushes the mailbox
  2000. * queue to make it ready to be brought offline.
  2001. **/
  2002. void
  2003. lpfc_offline_prep(struct lpfc_hba * phba)
  2004. {
  2005. struct lpfc_vport *vport = phba->pport;
  2006. struct lpfc_nodelist *ndlp, *next_ndlp;
  2007. struct lpfc_vport **vports;
  2008. int i;
  2009. if (vport->fc_flag & FC_OFFLINE_MODE)
  2010. return;
  2011. lpfc_block_mgmt_io(phba);
  2012. lpfc_linkdown(phba);
  2013. /* Issue an unreg_login to all nodes on all vports */
  2014. vports = lpfc_create_vport_work_array(phba);
  2015. if (vports != NULL) {
  2016. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2017. struct Scsi_Host *shost;
  2018. if (vports[i]->load_flag & FC_UNLOADING)
  2019. continue;
  2020. vports[i]->vfi_state &= ~LPFC_VFI_REGISTERED;
  2021. shost = lpfc_shost_from_vport(vports[i]);
  2022. list_for_each_entry_safe(ndlp, next_ndlp,
  2023. &vports[i]->fc_nodes,
  2024. nlp_listp) {
  2025. if (!NLP_CHK_NODE_ACT(ndlp))
  2026. continue;
  2027. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  2028. continue;
  2029. if (ndlp->nlp_type & NLP_FABRIC) {
  2030. lpfc_disc_state_machine(vports[i], ndlp,
  2031. NULL, NLP_EVT_DEVICE_RECOVERY);
  2032. lpfc_disc_state_machine(vports[i], ndlp,
  2033. NULL, NLP_EVT_DEVICE_RM);
  2034. }
  2035. spin_lock_irq(shost->host_lock);
  2036. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2037. spin_unlock_irq(shost->host_lock);
  2038. lpfc_unreg_rpi(vports[i], ndlp);
  2039. }
  2040. }
  2041. }
  2042. lpfc_destroy_vport_work_array(phba, vports);
  2043. lpfc_sli_mbox_sys_shutdown(phba);
  2044. }
  2045. /**
  2046. * lpfc_offline - Bring a HBA offline
  2047. * @phba: pointer to lpfc hba data structure.
  2048. *
  2049. * This routine actually brings a HBA offline. It stops all the timers
  2050. * associated with the HBA, brings down the SLI layer, and eventually
  2051. * marks the HBA as in offline state for the upper layer protocol.
  2052. **/
  2053. void
  2054. lpfc_offline(struct lpfc_hba *phba)
  2055. {
  2056. struct Scsi_Host *shost;
  2057. struct lpfc_vport **vports;
  2058. int i;
  2059. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  2060. return;
  2061. /* stop port and all timers associated with this hba */
  2062. lpfc_stop_port(phba);
  2063. vports = lpfc_create_vport_work_array(phba);
  2064. if (vports != NULL)
  2065. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  2066. lpfc_stop_vport_timers(vports[i]);
  2067. lpfc_destroy_vport_work_array(phba, vports);
  2068. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2069. "0460 Bring Adapter offline\n");
  2070. /* Bring down the SLI Layer and cleanup. The HBA is offline
  2071. now. */
  2072. lpfc_sli_hba_down(phba);
  2073. spin_lock_irq(&phba->hbalock);
  2074. phba->work_ha = 0;
  2075. spin_unlock_irq(&phba->hbalock);
  2076. vports = lpfc_create_vport_work_array(phba);
  2077. if (vports != NULL)
  2078. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2079. shost = lpfc_shost_from_vport(vports[i]);
  2080. spin_lock_irq(shost->host_lock);
  2081. vports[i]->work_port_events = 0;
  2082. vports[i]->fc_flag |= FC_OFFLINE_MODE;
  2083. spin_unlock_irq(shost->host_lock);
  2084. }
  2085. lpfc_destroy_vport_work_array(phba, vports);
  2086. }
  2087. /**
  2088. * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
  2089. * @phba: pointer to lpfc hba data structure.
  2090. *
  2091. * This routine is to free all the SCSI buffers and IOCBs from the driver
  2092. * list back to kernel. It is called from lpfc_pci_remove_one to free
  2093. * the internal resources before the device is removed from the system.
  2094. *
  2095. * Return codes
  2096. * 0 - successful (for now, it always returns 0)
  2097. **/
  2098. static int
  2099. lpfc_scsi_free(struct lpfc_hba *phba)
  2100. {
  2101. struct lpfc_scsi_buf *sb, *sb_next;
  2102. struct lpfc_iocbq *io, *io_next;
  2103. spin_lock_irq(&phba->hbalock);
  2104. /* Release all the lpfc_scsi_bufs maintained by this host. */
  2105. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
  2106. list_del(&sb->list);
  2107. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  2108. sb->dma_handle);
  2109. kfree(sb);
  2110. phba->total_scsi_bufs--;
  2111. }
  2112. /* Release all the lpfc_iocbq entries maintained by this host. */
  2113. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  2114. list_del(&io->list);
  2115. kfree(io);
  2116. phba->total_iocbq_bufs--;
  2117. }
  2118. spin_unlock_irq(&phba->hbalock);
  2119. return 0;
  2120. }
  2121. /**
  2122. * lpfc_create_port - Create an FC port
  2123. * @phba: pointer to lpfc hba data structure.
  2124. * @instance: a unique integer ID to this FC port.
  2125. * @dev: pointer to the device data structure.
  2126. *
  2127. * This routine creates a FC port for the upper layer protocol. The FC port
  2128. * can be created on top of either a physical port or a virtual port provided
  2129. * by the HBA. This routine also allocates a SCSI host data structure (shost)
  2130. * and associates the FC port created before adding the shost into the SCSI
  2131. * layer.
  2132. *
  2133. * Return codes
  2134. * @vport - pointer to the virtual N_Port data structure.
  2135. * NULL - port create failed.
  2136. **/
  2137. struct lpfc_vport *
  2138. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  2139. {
  2140. struct lpfc_vport *vport;
  2141. struct Scsi_Host *shost;
  2142. int error = 0;
  2143. if (dev != &phba->pcidev->dev)
  2144. shost = scsi_host_alloc(&lpfc_vport_template,
  2145. sizeof(struct lpfc_vport));
  2146. else
  2147. shost = scsi_host_alloc(&lpfc_template,
  2148. sizeof(struct lpfc_vport));
  2149. if (!shost)
  2150. goto out;
  2151. vport = (struct lpfc_vport *) shost->hostdata;
  2152. vport->phba = phba;
  2153. vport->load_flag |= FC_LOADING;
  2154. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2155. vport->fc_rscn_flush = 0;
  2156. lpfc_get_vport_cfgparam(vport);
  2157. shost->unique_id = instance;
  2158. shost->max_id = LPFC_MAX_TARGET;
  2159. shost->max_lun = vport->cfg_max_luns;
  2160. shost->this_id = -1;
  2161. shost->max_cmd_len = 16;
  2162. if (phba->sli_rev == LPFC_SLI_REV4) {
  2163. shost->dma_boundary = LPFC_SLI4_MAX_SEGMENT_SIZE;
  2164. shost->sg_tablesize = phba->cfg_sg_seg_cnt;
  2165. }
  2166. /*
  2167. * Set initial can_queue value since 0 is no longer supported and
  2168. * scsi_add_host will fail. This will be adjusted later based on the
  2169. * max xri value determined in hba setup.
  2170. */
  2171. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  2172. if (dev != &phba->pcidev->dev) {
  2173. shost->transportt = lpfc_vport_transport_template;
  2174. vport->port_type = LPFC_NPIV_PORT;
  2175. } else {
  2176. shost->transportt = lpfc_transport_template;
  2177. vport->port_type = LPFC_PHYSICAL_PORT;
  2178. }
  2179. /* Initialize all internally managed lists. */
  2180. INIT_LIST_HEAD(&vport->fc_nodes);
  2181. INIT_LIST_HEAD(&vport->rcv_buffer_list);
  2182. spin_lock_init(&vport->work_port_lock);
  2183. init_timer(&vport->fc_disctmo);
  2184. vport->fc_disctmo.function = lpfc_disc_timeout;
  2185. vport->fc_disctmo.data = (unsigned long)vport;
  2186. init_timer(&vport->fc_fdmitmo);
  2187. vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
  2188. vport->fc_fdmitmo.data = (unsigned long)vport;
  2189. init_timer(&vport->els_tmofunc);
  2190. vport->els_tmofunc.function = lpfc_els_timeout;
  2191. vport->els_tmofunc.data = (unsigned long)vport;
  2192. error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
  2193. if (error)
  2194. goto out_put_shost;
  2195. spin_lock_irq(&phba->hbalock);
  2196. list_add_tail(&vport->listentry, &phba->port_list);
  2197. spin_unlock_irq(&phba->hbalock);
  2198. return vport;
  2199. out_put_shost:
  2200. scsi_host_put(shost);
  2201. out:
  2202. return NULL;
  2203. }
  2204. /**
  2205. * destroy_port - destroy an FC port
  2206. * @vport: pointer to an lpfc virtual N_Port data structure.
  2207. *
  2208. * This routine destroys a FC port from the upper layer protocol. All the
  2209. * resources associated with the port are released.
  2210. **/
  2211. void
  2212. destroy_port(struct lpfc_vport *vport)
  2213. {
  2214. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2215. struct lpfc_hba *phba = vport->phba;
  2216. lpfc_debugfs_terminate(vport);
  2217. fc_remove_host(shost);
  2218. scsi_remove_host(shost);
  2219. spin_lock_irq(&phba->hbalock);
  2220. list_del_init(&vport->listentry);
  2221. spin_unlock_irq(&phba->hbalock);
  2222. lpfc_cleanup(vport);
  2223. return;
  2224. }
  2225. /**
  2226. * lpfc_get_instance - Get a unique integer ID
  2227. *
  2228. * This routine allocates a unique integer ID from lpfc_hba_index pool. It
  2229. * uses the kernel idr facility to perform the task.
  2230. *
  2231. * Return codes:
  2232. * instance - a unique integer ID allocated as the new instance.
  2233. * -1 - lpfc get instance failed.
  2234. **/
  2235. int
  2236. lpfc_get_instance(void)
  2237. {
  2238. int instance = 0;
  2239. /* Assign an unused number */
  2240. if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
  2241. return -1;
  2242. if (idr_get_new(&lpfc_hba_index, NULL, &instance))
  2243. return -1;
  2244. return instance;
  2245. }
  2246. /**
  2247. * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
  2248. * @shost: pointer to SCSI host data structure.
  2249. * @time: elapsed time of the scan in jiffies.
  2250. *
  2251. * This routine is called by the SCSI layer with a SCSI host to determine
  2252. * whether the scan host is finished.
  2253. *
  2254. * Note: there is no scan_start function as adapter initialization will have
  2255. * asynchronously kicked off the link initialization.
  2256. *
  2257. * Return codes
  2258. * 0 - SCSI host scan is not over yet.
  2259. * 1 - SCSI host scan is over.
  2260. **/
  2261. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  2262. {
  2263. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2264. struct lpfc_hba *phba = vport->phba;
  2265. int stat = 0;
  2266. spin_lock_irq(shost->host_lock);
  2267. if (vport->load_flag & FC_UNLOADING) {
  2268. stat = 1;
  2269. goto finished;
  2270. }
  2271. if (time >= 30 * HZ) {
  2272. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2273. "0461 Scanning longer than 30 "
  2274. "seconds. Continuing initialization\n");
  2275. stat = 1;
  2276. goto finished;
  2277. }
  2278. if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
  2279. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2280. "0465 Link down longer than 15 "
  2281. "seconds. Continuing initialization\n");
  2282. stat = 1;
  2283. goto finished;
  2284. }
  2285. if (vport->port_state != LPFC_VPORT_READY)
  2286. goto finished;
  2287. if (vport->num_disc_nodes || vport->fc_prli_sent)
  2288. goto finished;
  2289. if (vport->fc_map_cnt == 0 && time < 2 * HZ)
  2290. goto finished;
  2291. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  2292. goto finished;
  2293. stat = 1;
  2294. finished:
  2295. spin_unlock_irq(shost->host_lock);
  2296. return stat;
  2297. }
  2298. /**
  2299. * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
  2300. * @shost: pointer to SCSI host data structure.
  2301. *
  2302. * This routine initializes a given SCSI host attributes on a FC port. The
  2303. * SCSI host can be either on top of a physical port or a virtual port.
  2304. **/
  2305. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  2306. {
  2307. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2308. struct lpfc_hba *phba = vport->phba;
  2309. /*
  2310. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  2311. */
  2312. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  2313. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  2314. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  2315. memset(fc_host_supported_fc4s(shost), 0,
  2316. sizeof(fc_host_supported_fc4s(shost)));
  2317. fc_host_supported_fc4s(shost)[2] = 1;
  2318. fc_host_supported_fc4s(shost)[7] = 1;
  2319. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  2320. sizeof fc_host_symbolic_name(shost));
  2321. fc_host_supported_speeds(shost) = 0;
  2322. if (phba->lmt & LMT_10Gb)
  2323. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  2324. if (phba->lmt & LMT_8Gb)
  2325. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  2326. if (phba->lmt & LMT_4Gb)
  2327. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  2328. if (phba->lmt & LMT_2Gb)
  2329. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  2330. if (phba->lmt & LMT_1Gb)
  2331. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  2332. fc_host_maxframe_size(shost) =
  2333. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  2334. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  2335. /* This value is also unchanging */
  2336. memset(fc_host_active_fc4s(shost), 0,
  2337. sizeof(fc_host_active_fc4s(shost)));
  2338. fc_host_active_fc4s(shost)[2] = 1;
  2339. fc_host_active_fc4s(shost)[7] = 1;
  2340. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  2341. spin_lock_irq(shost->host_lock);
  2342. vport->load_flag &= ~FC_LOADING;
  2343. spin_unlock_irq(shost->host_lock);
  2344. }
  2345. /**
  2346. * lpfc_stop_port_s3 - Stop SLI3 device port
  2347. * @phba: pointer to lpfc hba data structure.
  2348. *
  2349. * This routine is invoked to stop an SLI3 device port, it stops the device
  2350. * from generating interrupts and stops the device driver's timers for the
  2351. * device.
  2352. **/
  2353. static void
  2354. lpfc_stop_port_s3(struct lpfc_hba *phba)
  2355. {
  2356. /* Clear all interrupt enable conditions */
  2357. writel(0, phba->HCregaddr);
  2358. readl(phba->HCregaddr); /* flush */
  2359. /* Clear all pending interrupts */
  2360. writel(0xffffffff, phba->HAregaddr);
  2361. readl(phba->HAregaddr); /* flush */
  2362. /* Reset some HBA SLI setup states */
  2363. lpfc_stop_hba_timers(phba);
  2364. phba->pport->work_port_events = 0;
  2365. }
  2366. /**
  2367. * lpfc_stop_port_s4 - Stop SLI4 device port
  2368. * @phba: pointer to lpfc hba data structure.
  2369. *
  2370. * This routine is invoked to stop an SLI4 device port, it stops the device
  2371. * from generating interrupts and stops the device driver's timers for the
  2372. * device.
  2373. **/
  2374. static void
  2375. lpfc_stop_port_s4(struct lpfc_hba *phba)
  2376. {
  2377. /* Reset some HBA SLI4 setup states */
  2378. lpfc_stop_hba_timers(phba);
  2379. phba->pport->work_port_events = 0;
  2380. phba->sli4_hba.intr_enable = 0;
  2381. /* Hard clear it for now, shall have more graceful way to wait later */
  2382. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2383. }
  2384. /**
  2385. * lpfc_stop_port - Wrapper function for stopping hba port
  2386. * @phba: Pointer to HBA context object.
  2387. *
  2388. * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
  2389. * the API jump table function pointer from the lpfc_hba struct.
  2390. **/
  2391. void
  2392. lpfc_stop_port(struct lpfc_hba *phba)
  2393. {
  2394. phba->lpfc_stop_port(phba);
  2395. }
  2396. /**
  2397. * lpfc_sli4_remove_dflt_fcf - Remove the driver default fcf record from the port.
  2398. * @phba: pointer to lpfc hba data structure.
  2399. *
  2400. * This routine is invoked to remove the driver default fcf record from
  2401. * the port. This routine currently acts on FCF Index 0.
  2402. *
  2403. **/
  2404. void
  2405. lpfc_sli_remove_dflt_fcf(struct lpfc_hba *phba)
  2406. {
  2407. int rc = 0;
  2408. LPFC_MBOXQ_t *mboxq;
  2409. struct lpfc_mbx_del_fcf_tbl_entry *del_fcf_record;
  2410. uint32_t mbox_tmo, req_len;
  2411. uint32_t shdr_status, shdr_add_status;
  2412. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2413. if (!mboxq) {
  2414. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2415. "2020 Failed to allocate mbox for ADD_FCF cmd\n");
  2416. return;
  2417. }
  2418. req_len = sizeof(struct lpfc_mbx_del_fcf_tbl_entry) -
  2419. sizeof(struct lpfc_sli4_cfg_mhdr);
  2420. rc = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  2421. LPFC_MBOX_OPCODE_FCOE_DELETE_FCF,
  2422. req_len, LPFC_SLI4_MBX_EMBED);
  2423. /*
  2424. * In phase 1, there is a single FCF index, 0. In phase2, the driver
  2425. * supports multiple FCF indices.
  2426. */
  2427. del_fcf_record = &mboxq->u.mqe.un.del_fcf_entry;
  2428. bf_set(lpfc_mbx_del_fcf_tbl_count, del_fcf_record, 1);
  2429. bf_set(lpfc_mbx_del_fcf_tbl_index, del_fcf_record,
  2430. phba->fcf.fcf_indx);
  2431. if (!phba->sli4_hba.intr_enable)
  2432. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  2433. else {
  2434. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  2435. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  2436. }
  2437. /* The IOCTL status is embedded in the mailbox subheader. */
  2438. shdr_status = bf_get(lpfc_mbox_hdr_status,
  2439. &del_fcf_record->header.cfg_shdr.response);
  2440. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  2441. &del_fcf_record->header.cfg_shdr.response);
  2442. if (shdr_status || shdr_add_status || rc != MBX_SUCCESS) {
  2443. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2444. "2516 DEL FCF of default FCF Index failed "
  2445. "mbx status x%x, status x%x add_status x%x\n",
  2446. rc, shdr_status, shdr_add_status);
  2447. }
  2448. if (rc != MBX_TIMEOUT)
  2449. mempool_free(mboxq, phba->mbox_mem_pool);
  2450. }
  2451. /**
  2452. * lpfc_sli4_fw_cfg_check - Read the firmware config and verify FCoE support
  2453. * @phba: pointer to lpfc hba data structure.
  2454. *
  2455. * This function uses the QUERY_FW_CFG mailbox command to determine if the
  2456. * firmware loaded supports FCoE. A return of zero indicates that the mailbox
  2457. * was successful and the firmware supports FCoE. Any other return indicates
  2458. * a error. It is assumed that this function will be called before interrupts
  2459. * are enabled.
  2460. **/
  2461. static int
  2462. lpfc_sli4_fw_cfg_check(struct lpfc_hba *phba)
  2463. {
  2464. int rc = 0;
  2465. LPFC_MBOXQ_t *mboxq;
  2466. struct lpfc_mbx_query_fw_cfg *query_fw_cfg;
  2467. uint32_t length;
  2468. uint32_t shdr_status, shdr_add_status;
  2469. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2470. if (!mboxq) {
  2471. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2472. "2621 Failed to allocate mbox for "
  2473. "query firmware config cmd\n");
  2474. return -ENOMEM;
  2475. }
  2476. query_fw_cfg = &mboxq->u.mqe.un.query_fw_cfg;
  2477. length = (sizeof(struct lpfc_mbx_query_fw_cfg) -
  2478. sizeof(struct lpfc_sli4_cfg_mhdr));
  2479. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  2480. LPFC_MBOX_OPCODE_QUERY_FW_CFG,
  2481. length, LPFC_SLI4_MBX_EMBED);
  2482. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  2483. /* The IOCTL status is embedded in the mailbox subheader. */
  2484. shdr_status = bf_get(lpfc_mbox_hdr_status,
  2485. &query_fw_cfg->header.cfg_shdr.response);
  2486. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  2487. &query_fw_cfg->header.cfg_shdr.response);
  2488. if (shdr_status || shdr_add_status || rc != MBX_SUCCESS) {
  2489. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2490. "2622 Query Firmware Config failed "
  2491. "mbx status x%x, status x%x add_status x%x\n",
  2492. rc, shdr_status, shdr_add_status);
  2493. return -EINVAL;
  2494. }
  2495. if (!bf_get(lpfc_function_mode_fcoe_i, query_fw_cfg)) {
  2496. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2497. "2623 FCoE Function not supported by firmware. "
  2498. "Function mode = %08x\n",
  2499. query_fw_cfg->function_mode);
  2500. return -EINVAL;
  2501. }
  2502. if (rc != MBX_TIMEOUT)
  2503. mempool_free(mboxq, phba->mbox_mem_pool);
  2504. return 0;
  2505. }
  2506. /**
  2507. * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
  2508. * @phba: pointer to lpfc hba data structure.
  2509. * @acqe_link: pointer to the async link completion queue entry.
  2510. *
  2511. * This routine is to parse the SLI4 link-attention link fault code and
  2512. * translate it into the base driver's read link attention mailbox command
  2513. * status.
  2514. *
  2515. * Return: Link-attention status in terms of base driver's coding.
  2516. **/
  2517. static uint16_t
  2518. lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
  2519. struct lpfc_acqe_link *acqe_link)
  2520. {
  2521. uint16_t latt_fault;
  2522. switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
  2523. case LPFC_ASYNC_LINK_FAULT_NONE:
  2524. case LPFC_ASYNC_LINK_FAULT_LOCAL:
  2525. case LPFC_ASYNC_LINK_FAULT_REMOTE:
  2526. latt_fault = 0;
  2527. break;
  2528. default:
  2529. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2530. "0398 Invalid link fault code: x%x\n",
  2531. bf_get(lpfc_acqe_link_fault, acqe_link));
  2532. latt_fault = MBXERR_ERROR;
  2533. break;
  2534. }
  2535. return latt_fault;
  2536. }
  2537. /**
  2538. * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
  2539. * @phba: pointer to lpfc hba data structure.
  2540. * @acqe_link: pointer to the async link completion queue entry.
  2541. *
  2542. * This routine is to parse the SLI4 link attention type and translate it
  2543. * into the base driver's link attention type coding.
  2544. *
  2545. * Return: Link attention type in terms of base driver's coding.
  2546. **/
  2547. static uint8_t
  2548. lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
  2549. struct lpfc_acqe_link *acqe_link)
  2550. {
  2551. uint8_t att_type;
  2552. switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
  2553. case LPFC_ASYNC_LINK_STATUS_DOWN:
  2554. case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
  2555. att_type = AT_LINK_DOWN;
  2556. break;
  2557. case LPFC_ASYNC_LINK_STATUS_UP:
  2558. /* Ignore physical link up events - wait for logical link up */
  2559. att_type = AT_RESERVED;
  2560. break;
  2561. case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
  2562. att_type = AT_LINK_UP;
  2563. break;
  2564. default:
  2565. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2566. "0399 Invalid link attention type: x%x\n",
  2567. bf_get(lpfc_acqe_link_status, acqe_link));
  2568. att_type = AT_RESERVED;
  2569. break;
  2570. }
  2571. return att_type;
  2572. }
  2573. /**
  2574. * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
  2575. * @phba: pointer to lpfc hba data structure.
  2576. * @acqe_link: pointer to the async link completion queue entry.
  2577. *
  2578. * This routine is to parse the SLI4 link-attention link speed and translate
  2579. * it into the base driver's link-attention link speed coding.
  2580. *
  2581. * Return: Link-attention link speed in terms of base driver's coding.
  2582. **/
  2583. static uint8_t
  2584. lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
  2585. struct lpfc_acqe_link *acqe_link)
  2586. {
  2587. uint8_t link_speed;
  2588. switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
  2589. case LPFC_ASYNC_LINK_SPEED_ZERO:
  2590. link_speed = LA_UNKNW_LINK;
  2591. break;
  2592. case LPFC_ASYNC_LINK_SPEED_10MBPS:
  2593. link_speed = LA_UNKNW_LINK;
  2594. break;
  2595. case LPFC_ASYNC_LINK_SPEED_100MBPS:
  2596. link_speed = LA_UNKNW_LINK;
  2597. break;
  2598. case LPFC_ASYNC_LINK_SPEED_1GBPS:
  2599. link_speed = LA_1GHZ_LINK;
  2600. break;
  2601. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  2602. link_speed = LA_10GHZ_LINK;
  2603. break;
  2604. default:
  2605. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2606. "0483 Invalid link-attention link speed: x%x\n",
  2607. bf_get(lpfc_acqe_link_speed, acqe_link));
  2608. link_speed = LA_UNKNW_LINK;
  2609. break;
  2610. }
  2611. return link_speed;
  2612. }
  2613. /**
  2614. * lpfc_sli4_async_link_evt - Process the asynchronous link event
  2615. * @phba: pointer to lpfc hba data structure.
  2616. * @acqe_link: pointer to the async link completion queue entry.
  2617. *
  2618. * This routine is to handle the SLI4 asynchronous link event.
  2619. **/
  2620. static void
  2621. lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
  2622. struct lpfc_acqe_link *acqe_link)
  2623. {
  2624. struct lpfc_dmabuf *mp;
  2625. LPFC_MBOXQ_t *pmb;
  2626. MAILBOX_t *mb;
  2627. READ_LA_VAR *la;
  2628. uint8_t att_type;
  2629. att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
  2630. if (att_type != AT_LINK_DOWN && att_type != AT_LINK_UP)
  2631. return;
  2632. phba->fcoe_eventtag = acqe_link->event_tag;
  2633. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2634. if (!pmb) {
  2635. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2636. "0395 The mboxq allocation failed\n");
  2637. return;
  2638. }
  2639. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  2640. if (!mp) {
  2641. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2642. "0396 The lpfc_dmabuf allocation failed\n");
  2643. goto out_free_pmb;
  2644. }
  2645. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  2646. if (!mp->virt) {
  2647. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2648. "0397 The mbuf allocation failed\n");
  2649. goto out_free_dmabuf;
  2650. }
  2651. /* Cleanup any outstanding ELS commands */
  2652. lpfc_els_flush_all_cmd(phba);
  2653. /* Block ELS IOCBs until we have done process link event */
  2654. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  2655. /* Update link event statistics */
  2656. phba->sli.slistat.link_event++;
  2657. /* Create pseudo lpfc_handle_latt mailbox command from link ACQE */
  2658. lpfc_read_la(phba, pmb, mp);
  2659. pmb->vport = phba->pport;
  2660. /* Parse and translate status field */
  2661. mb = &pmb->u.mb;
  2662. mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
  2663. /* Parse and translate link attention fields */
  2664. la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
  2665. la->eventTag = acqe_link->event_tag;
  2666. la->attType = att_type;
  2667. la->UlnkSpeed = lpfc_sli4_parse_latt_link_speed(phba, acqe_link);
  2668. /* Fake the the following irrelvant fields */
  2669. la->topology = TOPOLOGY_PT_PT;
  2670. la->granted_AL_PA = 0;
  2671. la->il = 0;
  2672. la->pb = 0;
  2673. la->fa = 0;
  2674. la->mm = 0;
  2675. /* Keep the link status for extra SLI4 state machine reference */
  2676. phba->sli4_hba.link_state.speed =
  2677. bf_get(lpfc_acqe_link_speed, acqe_link);
  2678. phba->sli4_hba.link_state.duplex =
  2679. bf_get(lpfc_acqe_link_duplex, acqe_link);
  2680. phba->sli4_hba.link_state.status =
  2681. bf_get(lpfc_acqe_link_status, acqe_link);
  2682. phba->sli4_hba.link_state.physical =
  2683. bf_get(lpfc_acqe_link_physical, acqe_link);
  2684. phba->sli4_hba.link_state.fault =
  2685. bf_get(lpfc_acqe_link_fault, acqe_link);
  2686. /* Invoke the lpfc_handle_latt mailbox command callback function */
  2687. lpfc_mbx_cmpl_read_la(phba, pmb);
  2688. return;
  2689. out_free_dmabuf:
  2690. kfree(mp);
  2691. out_free_pmb:
  2692. mempool_free(pmb, phba->mbox_mem_pool);
  2693. }
  2694. /**
  2695. * lpfc_sli4_async_fcoe_evt - Process the asynchronous fcoe event
  2696. * @phba: pointer to lpfc hba data structure.
  2697. * @acqe_link: pointer to the async fcoe completion queue entry.
  2698. *
  2699. * This routine is to handle the SLI4 asynchronous fcoe event.
  2700. **/
  2701. static void
  2702. lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
  2703. struct lpfc_acqe_fcoe *acqe_fcoe)
  2704. {
  2705. uint8_t event_type = bf_get(lpfc_acqe_fcoe_event_type, acqe_fcoe);
  2706. int rc;
  2707. struct lpfc_vport *vport;
  2708. struct lpfc_nodelist *ndlp;
  2709. struct Scsi_Host *shost;
  2710. phba->fc_eventTag = acqe_fcoe->event_tag;
  2711. phba->fcoe_eventtag = acqe_fcoe->event_tag;
  2712. switch (event_type) {
  2713. case LPFC_FCOE_EVENT_TYPE_NEW_FCF:
  2714. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2715. "2546 New FCF found index 0x%x tag 0x%x\n",
  2716. acqe_fcoe->index,
  2717. acqe_fcoe->event_tag);
  2718. /*
  2719. * If the current FCF is in discovered state, or
  2720. * FCF discovery is in progress do nothing.
  2721. */
  2722. spin_lock_irq(&phba->hbalock);
  2723. if ((phba->fcf.fcf_flag & FCF_DISCOVERED) ||
  2724. (phba->hba_flag & FCF_DISC_INPROGRESS)) {
  2725. spin_unlock_irq(&phba->hbalock);
  2726. break;
  2727. }
  2728. spin_unlock_irq(&phba->hbalock);
  2729. /* Read the FCF table and re-discover SAN. */
  2730. rc = lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
  2731. if (rc)
  2732. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2733. "2547 Read FCF record failed 0x%x\n",
  2734. rc);
  2735. break;
  2736. case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL:
  2737. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2738. "2548 FCF Table full count 0x%x tag 0x%x\n",
  2739. bf_get(lpfc_acqe_fcoe_fcf_count, acqe_fcoe),
  2740. acqe_fcoe->event_tag);
  2741. break;
  2742. case LPFC_FCOE_EVENT_TYPE_FCF_DEAD:
  2743. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2744. "2549 FCF disconnected from network index 0x%x"
  2745. " tag 0x%x\n", acqe_fcoe->index,
  2746. acqe_fcoe->event_tag);
  2747. /* If the event is not for currently used fcf do nothing */
  2748. if (phba->fcf.fcf_indx != acqe_fcoe->index)
  2749. break;
  2750. /*
  2751. * Currently, driver support only one FCF - so treat this as
  2752. * a link down.
  2753. */
  2754. lpfc_linkdown(phba);
  2755. /* Unregister FCF if no devices connected to it */
  2756. lpfc_unregister_unused_fcf(phba);
  2757. break;
  2758. case LPFC_FCOE_EVENT_TYPE_CVL:
  2759. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2760. "2718 Clear Virtual Link Received for VPI 0x%x"
  2761. " tag 0x%x\n", acqe_fcoe->index, acqe_fcoe->event_tag);
  2762. vport = lpfc_find_vport_by_vpid(phba,
  2763. acqe_fcoe->index /*- phba->vpi_base*/);
  2764. if (!vport)
  2765. break;
  2766. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  2767. if (!ndlp)
  2768. break;
  2769. shost = lpfc_shost_from_vport(vport);
  2770. lpfc_linkdown_port(vport);
  2771. if (vport->port_type != LPFC_NPIV_PORT) {
  2772. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  2773. spin_lock_irq(shost->host_lock);
  2774. ndlp->nlp_flag |= NLP_DELAY_TMO;
  2775. spin_unlock_irq(shost->host_lock);
  2776. ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
  2777. vport->port_state = LPFC_FLOGI;
  2778. }
  2779. break;
  2780. default:
  2781. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2782. "0288 Unknown FCoE event type 0x%x event tag "
  2783. "0x%x\n", event_type, acqe_fcoe->event_tag);
  2784. break;
  2785. }
  2786. }
  2787. /**
  2788. * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
  2789. * @phba: pointer to lpfc hba data structure.
  2790. * @acqe_link: pointer to the async dcbx completion queue entry.
  2791. *
  2792. * This routine is to handle the SLI4 asynchronous dcbx event.
  2793. **/
  2794. static void
  2795. lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
  2796. struct lpfc_acqe_dcbx *acqe_dcbx)
  2797. {
  2798. phba->fc_eventTag = acqe_dcbx->event_tag;
  2799. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2800. "0290 The SLI4 DCBX asynchronous event is not "
  2801. "handled yet\n");
  2802. }
  2803. /**
  2804. * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
  2805. * @phba: pointer to lpfc hba data structure.
  2806. *
  2807. * This routine is invoked by the worker thread to process all the pending
  2808. * SLI4 asynchronous events.
  2809. **/
  2810. void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
  2811. {
  2812. struct lpfc_cq_event *cq_event;
  2813. /* First, declare the async event has been handled */
  2814. spin_lock_irq(&phba->hbalock);
  2815. phba->hba_flag &= ~ASYNC_EVENT;
  2816. spin_unlock_irq(&phba->hbalock);
  2817. /* Now, handle all the async events */
  2818. while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
  2819. /* Get the first event from the head of the event queue */
  2820. spin_lock_irq(&phba->hbalock);
  2821. list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
  2822. cq_event, struct lpfc_cq_event, list);
  2823. spin_unlock_irq(&phba->hbalock);
  2824. /* Process the asynchronous event */
  2825. switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
  2826. case LPFC_TRAILER_CODE_LINK:
  2827. lpfc_sli4_async_link_evt(phba,
  2828. &cq_event->cqe.acqe_link);
  2829. break;
  2830. case LPFC_TRAILER_CODE_FCOE:
  2831. lpfc_sli4_async_fcoe_evt(phba,
  2832. &cq_event->cqe.acqe_fcoe);
  2833. break;
  2834. case LPFC_TRAILER_CODE_DCBX:
  2835. lpfc_sli4_async_dcbx_evt(phba,
  2836. &cq_event->cqe.acqe_dcbx);
  2837. break;
  2838. default:
  2839. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2840. "1804 Invalid asynchrous event code: "
  2841. "x%x\n", bf_get(lpfc_trailer_code,
  2842. &cq_event->cqe.mcqe_cmpl));
  2843. break;
  2844. }
  2845. /* Free the completion event processed to the free pool */
  2846. lpfc_sli4_cq_event_release(phba, cq_event);
  2847. }
  2848. }
  2849. /**
  2850. * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
  2851. * @phba: pointer to lpfc hba data structure.
  2852. * @dev_grp: The HBA PCI-Device group number.
  2853. *
  2854. * This routine is invoked to set up the per HBA PCI-Device group function
  2855. * API jump table entries.
  2856. *
  2857. * Return: 0 if success, otherwise -ENODEV
  2858. **/
  2859. int
  2860. lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  2861. {
  2862. int rc;
  2863. /* Set up lpfc PCI-device group */
  2864. phba->pci_dev_grp = dev_grp;
  2865. /* The LPFC_PCI_DEV_OC uses SLI4 */
  2866. if (dev_grp == LPFC_PCI_DEV_OC)
  2867. phba->sli_rev = LPFC_SLI_REV4;
  2868. /* Set up device INIT API function jump table */
  2869. rc = lpfc_init_api_table_setup(phba, dev_grp);
  2870. if (rc)
  2871. return -ENODEV;
  2872. /* Set up SCSI API function jump table */
  2873. rc = lpfc_scsi_api_table_setup(phba, dev_grp);
  2874. if (rc)
  2875. return -ENODEV;
  2876. /* Set up SLI API function jump table */
  2877. rc = lpfc_sli_api_table_setup(phba, dev_grp);
  2878. if (rc)
  2879. return -ENODEV;
  2880. /* Set up MBOX API function jump table */
  2881. rc = lpfc_mbox_api_table_setup(phba, dev_grp);
  2882. if (rc)
  2883. return -ENODEV;
  2884. return 0;
  2885. }
  2886. /**
  2887. * lpfc_log_intr_mode - Log the active interrupt mode
  2888. * @phba: pointer to lpfc hba data structure.
  2889. * @intr_mode: active interrupt mode adopted.
  2890. *
  2891. * This routine it invoked to log the currently used active interrupt mode
  2892. * to the device.
  2893. **/
  2894. static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
  2895. {
  2896. switch (intr_mode) {
  2897. case 0:
  2898. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2899. "0470 Enable INTx interrupt mode.\n");
  2900. break;
  2901. case 1:
  2902. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2903. "0481 Enabled MSI interrupt mode.\n");
  2904. break;
  2905. case 2:
  2906. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2907. "0480 Enabled MSI-X interrupt mode.\n");
  2908. break;
  2909. default:
  2910. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2911. "0482 Illegal interrupt mode.\n");
  2912. break;
  2913. }
  2914. return;
  2915. }
  2916. /**
  2917. * lpfc_enable_pci_dev - Enable a generic PCI device.
  2918. * @phba: pointer to lpfc hba data structure.
  2919. *
  2920. * This routine is invoked to enable the PCI device that is common to all
  2921. * PCI devices.
  2922. *
  2923. * Return codes
  2924. * 0 - sucessful
  2925. * other values - error
  2926. **/
  2927. static int
  2928. lpfc_enable_pci_dev(struct lpfc_hba *phba)
  2929. {
  2930. struct pci_dev *pdev;
  2931. int bars;
  2932. /* Obtain PCI device reference */
  2933. if (!phba->pcidev)
  2934. goto out_error;
  2935. else
  2936. pdev = phba->pcidev;
  2937. /* Select PCI BARs */
  2938. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2939. /* Enable PCI device */
  2940. if (pci_enable_device_mem(pdev))
  2941. goto out_error;
  2942. /* Request PCI resource for the device */
  2943. if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
  2944. goto out_disable_device;
  2945. /* Set up device as PCI master and save state for EEH */
  2946. pci_set_master(pdev);
  2947. pci_try_set_mwi(pdev);
  2948. pci_save_state(pdev);
  2949. return 0;
  2950. out_disable_device:
  2951. pci_disable_device(pdev);
  2952. out_error:
  2953. return -ENODEV;
  2954. }
  2955. /**
  2956. * lpfc_disable_pci_dev - Disable a generic PCI device.
  2957. * @phba: pointer to lpfc hba data structure.
  2958. *
  2959. * This routine is invoked to disable the PCI device that is common to all
  2960. * PCI devices.
  2961. **/
  2962. static void
  2963. lpfc_disable_pci_dev(struct lpfc_hba *phba)
  2964. {
  2965. struct pci_dev *pdev;
  2966. int bars;
  2967. /* Obtain PCI device reference */
  2968. if (!phba->pcidev)
  2969. return;
  2970. else
  2971. pdev = phba->pcidev;
  2972. /* Select PCI BARs */
  2973. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2974. /* Release PCI resource and disable PCI device */
  2975. pci_release_selected_regions(pdev, bars);
  2976. pci_disable_device(pdev);
  2977. /* Null out PCI private reference to driver */
  2978. pci_set_drvdata(pdev, NULL);
  2979. return;
  2980. }
  2981. /**
  2982. * lpfc_reset_hba - Reset a hba
  2983. * @phba: pointer to lpfc hba data structure.
  2984. *
  2985. * This routine is invoked to reset a hba device. It brings the HBA
  2986. * offline, performs a board restart, and then brings the board back
  2987. * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
  2988. * on outstanding mailbox commands.
  2989. **/
  2990. void
  2991. lpfc_reset_hba(struct lpfc_hba *phba)
  2992. {
  2993. /* If resets are disabled then set error state and return. */
  2994. if (!phba->cfg_enable_hba_reset) {
  2995. phba->link_state = LPFC_HBA_ERROR;
  2996. return;
  2997. }
  2998. lpfc_offline_prep(phba);
  2999. lpfc_offline(phba);
  3000. lpfc_sli_brdrestart(phba);
  3001. lpfc_online(phba);
  3002. lpfc_unblock_mgmt_io(phba);
  3003. }
  3004. /**
  3005. * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
  3006. * @phba: pointer to lpfc hba data structure.
  3007. *
  3008. * This routine is invoked to set up the driver internal resources specific to
  3009. * support the SLI-3 HBA device it attached to.
  3010. *
  3011. * Return codes
  3012. * 0 - sucessful
  3013. * other values - error
  3014. **/
  3015. static int
  3016. lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
  3017. {
  3018. struct lpfc_sli *psli;
  3019. /*
  3020. * Initialize timers used by driver
  3021. */
  3022. /* Heartbeat timer */
  3023. init_timer(&phba->hb_tmofunc);
  3024. phba->hb_tmofunc.function = lpfc_hb_timeout;
  3025. phba->hb_tmofunc.data = (unsigned long)phba;
  3026. psli = &phba->sli;
  3027. /* MBOX heartbeat timer */
  3028. init_timer(&psli->mbox_tmo);
  3029. psli->mbox_tmo.function = lpfc_mbox_timeout;
  3030. psli->mbox_tmo.data = (unsigned long) phba;
  3031. /* FCP polling mode timer */
  3032. init_timer(&phba->fcp_poll_timer);
  3033. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  3034. phba->fcp_poll_timer.data = (unsigned long) phba;
  3035. /* Fabric block timer */
  3036. init_timer(&phba->fabric_block_timer);
  3037. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  3038. phba->fabric_block_timer.data = (unsigned long) phba;
  3039. /* EA polling mode timer */
  3040. init_timer(&phba->eratt_poll);
  3041. phba->eratt_poll.function = lpfc_poll_eratt;
  3042. phba->eratt_poll.data = (unsigned long) phba;
  3043. /* Host attention work mask setup */
  3044. phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
  3045. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  3046. /* Get all the module params for configuring this host */
  3047. lpfc_get_cfgparam(phba);
  3048. /*
  3049. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  3050. * used to create the sg_dma_buf_pool must be dynamically calculated.
  3051. * 2 segments are added since the IOCB needs a command and response bde.
  3052. */
  3053. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  3054. sizeof(struct fcp_rsp) +
  3055. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
  3056. if (phba->cfg_enable_bg) {
  3057. phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
  3058. phba->cfg_sg_dma_buf_size +=
  3059. phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
  3060. }
  3061. /* Also reinitialize the host templates with new values. */
  3062. lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  3063. lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  3064. phba->max_vpi = LPFC_MAX_VPI;
  3065. /* This will be set to correct value after config_port mbox */
  3066. phba->max_vports = 0;
  3067. /*
  3068. * Initialize the SLI Layer to run with lpfc HBAs.
  3069. */
  3070. lpfc_sli_setup(phba);
  3071. lpfc_sli_queue_setup(phba);
  3072. /* Allocate device driver memory */
  3073. if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
  3074. return -ENOMEM;
  3075. return 0;
  3076. }
  3077. /**
  3078. * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
  3079. * @phba: pointer to lpfc hba data structure.
  3080. *
  3081. * This routine is invoked to unset the driver internal resources set up
  3082. * specific for supporting the SLI-3 HBA device it attached to.
  3083. **/
  3084. static void
  3085. lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
  3086. {
  3087. /* Free device driver memory allocated */
  3088. lpfc_mem_free_all(phba);
  3089. return;
  3090. }
  3091. /**
  3092. * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
  3093. * @phba: pointer to lpfc hba data structure.
  3094. *
  3095. * This routine is invoked to set up the driver internal resources specific to
  3096. * support the SLI-4 HBA device it attached to.
  3097. *
  3098. * Return codes
  3099. * 0 - sucessful
  3100. * other values - error
  3101. **/
  3102. static int
  3103. lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
  3104. {
  3105. struct lpfc_sli *psli;
  3106. int rc;
  3107. int i, hbq_count;
  3108. /* Before proceed, wait for POST done and device ready */
  3109. rc = lpfc_sli4_post_status_check(phba);
  3110. if (rc)
  3111. return -ENODEV;
  3112. /*
  3113. * Initialize timers used by driver
  3114. */
  3115. /* Heartbeat timer */
  3116. init_timer(&phba->hb_tmofunc);
  3117. phba->hb_tmofunc.function = lpfc_hb_timeout;
  3118. phba->hb_tmofunc.data = (unsigned long)phba;
  3119. psli = &phba->sli;
  3120. /* MBOX heartbeat timer */
  3121. init_timer(&psli->mbox_tmo);
  3122. psli->mbox_tmo.function = lpfc_mbox_timeout;
  3123. psli->mbox_tmo.data = (unsigned long) phba;
  3124. /* Fabric block timer */
  3125. init_timer(&phba->fabric_block_timer);
  3126. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  3127. phba->fabric_block_timer.data = (unsigned long) phba;
  3128. /* EA polling mode timer */
  3129. init_timer(&phba->eratt_poll);
  3130. phba->eratt_poll.function = lpfc_poll_eratt;
  3131. phba->eratt_poll.data = (unsigned long) phba;
  3132. /*
  3133. * We need to do a READ_CONFIG mailbox command here before
  3134. * calling lpfc_get_cfgparam. For VFs this will report the
  3135. * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
  3136. * All of the resources allocated
  3137. * for this Port are tied to these values.
  3138. */
  3139. /* Get all the module params for configuring this host */
  3140. lpfc_get_cfgparam(phba);
  3141. phba->max_vpi = LPFC_MAX_VPI;
  3142. /* This will be set to correct value after the read_config mbox */
  3143. phba->max_vports = 0;
  3144. /* Program the default value of vlan_id and fc_map */
  3145. phba->valid_vlan = 0;
  3146. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3147. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3148. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3149. /*
  3150. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  3151. * used to create the sg_dma_buf_pool must be dynamically calculated.
  3152. * 2 segments are added since the IOCB needs a command and response bde.
  3153. * To insure that the scsi sgl does not cross a 4k page boundary only
  3154. * sgl sizes of 1k, 2k, 4k, and 8k are supported.
  3155. * Table of sgl sizes and seg_cnt:
  3156. * sgl size, sg_seg_cnt total seg
  3157. * 1k 50 52
  3158. * 2k 114 116
  3159. * 4k 242 244
  3160. * 8k 498 500
  3161. * cmd(32) + rsp(160) + (52 * sizeof(sli4_sge)) = 1024
  3162. * cmd(32) + rsp(160) + (116 * sizeof(sli4_sge)) = 2048
  3163. * cmd(32) + rsp(160) + (244 * sizeof(sli4_sge)) = 4096
  3164. * cmd(32) + rsp(160) + (500 * sizeof(sli4_sge)) = 8192
  3165. */
  3166. if (phba->cfg_sg_seg_cnt <= LPFC_DEFAULT_SG_SEG_CNT)
  3167. phba->cfg_sg_seg_cnt = 50;
  3168. else if (phba->cfg_sg_seg_cnt <= 114)
  3169. phba->cfg_sg_seg_cnt = 114;
  3170. else if (phba->cfg_sg_seg_cnt <= 242)
  3171. phba->cfg_sg_seg_cnt = 242;
  3172. else
  3173. phba->cfg_sg_seg_cnt = 498;
  3174. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd)
  3175. + sizeof(struct fcp_rsp);
  3176. phba->cfg_sg_dma_buf_size +=
  3177. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
  3178. /* Initialize buffer queue management fields */
  3179. hbq_count = lpfc_sli_hbq_count();
  3180. for (i = 0; i < hbq_count; ++i)
  3181. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  3182. INIT_LIST_HEAD(&phba->rb_pend_list);
  3183. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
  3184. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
  3185. /*
  3186. * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
  3187. */
  3188. /* Initialize the Abort scsi buffer list used by driver */
  3189. spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
  3190. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  3191. /* This abort list used by worker thread */
  3192. spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
  3193. /*
  3194. * Initialize dirver internal slow-path work queues
  3195. */
  3196. /* Driver internel slow-path CQ Event pool */
  3197. INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
  3198. /* Response IOCB work queue list */
  3199. INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
  3200. /* Asynchronous event CQ Event work queue list */
  3201. INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
  3202. /* Fast-path XRI aborted CQ Event work queue list */
  3203. INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  3204. /* Slow-path XRI aborted CQ Event work queue list */
  3205. INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
  3206. /* Receive queue CQ Event work queue list */
  3207. INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
  3208. /* Initialize the driver internal SLI layer lists. */
  3209. lpfc_sli_setup(phba);
  3210. lpfc_sli_queue_setup(phba);
  3211. /* Allocate device driver memory */
  3212. rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
  3213. if (rc)
  3214. return -ENOMEM;
  3215. /* Create the bootstrap mailbox command */
  3216. rc = lpfc_create_bootstrap_mbox(phba);
  3217. if (unlikely(rc))
  3218. goto out_free_mem;
  3219. /* Set up the host's endian order with the device. */
  3220. rc = lpfc_setup_endian_order(phba);
  3221. if (unlikely(rc))
  3222. goto out_free_bsmbx;
  3223. rc = lpfc_sli4_fw_cfg_check(phba);
  3224. if (unlikely(rc))
  3225. goto out_free_bsmbx;
  3226. /* Set up the hba's configuration parameters. */
  3227. rc = lpfc_sli4_read_config(phba);
  3228. if (unlikely(rc))
  3229. goto out_free_bsmbx;
  3230. /* Perform a function reset */
  3231. rc = lpfc_pci_function_reset(phba);
  3232. if (unlikely(rc))
  3233. goto out_free_bsmbx;
  3234. /* Create all the SLI4 queues */
  3235. rc = lpfc_sli4_queue_create(phba);
  3236. if (rc)
  3237. goto out_free_bsmbx;
  3238. /* Create driver internal CQE event pool */
  3239. rc = lpfc_sli4_cq_event_pool_create(phba);
  3240. if (rc)
  3241. goto out_destroy_queue;
  3242. /* Initialize and populate the iocb list per host */
  3243. rc = lpfc_init_sgl_list(phba);
  3244. if (rc) {
  3245. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3246. "1400 Failed to initialize sgl list.\n");
  3247. goto out_destroy_cq_event_pool;
  3248. }
  3249. rc = lpfc_init_active_sgl_array(phba);
  3250. if (rc) {
  3251. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3252. "1430 Failed to initialize sgl list.\n");
  3253. goto out_free_sgl_list;
  3254. }
  3255. rc = lpfc_sli4_init_rpi_hdrs(phba);
  3256. if (rc) {
  3257. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3258. "1432 Failed to initialize rpi headers.\n");
  3259. goto out_free_active_sgl;
  3260. }
  3261. phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
  3262. phba->cfg_fcp_eq_count), GFP_KERNEL);
  3263. if (!phba->sli4_hba.fcp_eq_hdl) {
  3264. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3265. "2572 Failed allocate memory for fast-path "
  3266. "per-EQ handle array\n");
  3267. goto out_remove_rpi_hdrs;
  3268. }
  3269. phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
  3270. phba->sli4_hba.cfg_eqn), GFP_KERNEL);
  3271. if (!phba->sli4_hba.msix_entries) {
  3272. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3273. "2573 Failed allocate memory for msi-x "
  3274. "interrupt vector entries\n");
  3275. goto out_free_fcp_eq_hdl;
  3276. }
  3277. return rc;
  3278. out_free_fcp_eq_hdl:
  3279. kfree(phba->sli4_hba.fcp_eq_hdl);
  3280. out_remove_rpi_hdrs:
  3281. lpfc_sli4_remove_rpi_hdrs(phba);
  3282. out_free_active_sgl:
  3283. lpfc_free_active_sgl(phba);
  3284. out_free_sgl_list:
  3285. lpfc_free_sgl_list(phba);
  3286. out_destroy_cq_event_pool:
  3287. lpfc_sli4_cq_event_pool_destroy(phba);
  3288. out_destroy_queue:
  3289. lpfc_sli4_queue_destroy(phba);
  3290. out_free_bsmbx:
  3291. lpfc_destroy_bootstrap_mbox(phba);
  3292. out_free_mem:
  3293. lpfc_mem_free(phba);
  3294. return rc;
  3295. }
  3296. /**
  3297. * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
  3298. * @phba: pointer to lpfc hba data structure.
  3299. *
  3300. * This routine is invoked to unset the driver internal resources set up
  3301. * specific for supporting the SLI-4 HBA device it attached to.
  3302. **/
  3303. static void
  3304. lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
  3305. {
  3306. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  3307. /* unregister default FCFI from the HBA */
  3308. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  3309. /* Free the default FCR table */
  3310. lpfc_sli_remove_dflt_fcf(phba);
  3311. /* Free memory allocated for msi-x interrupt vector entries */
  3312. kfree(phba->sli4_hba.msix_entries);
  3313. /* Free memory allocated for fast-path work queue handles */
  3314. kfree(phba->sli4_hba.fcp_eq_hdl);
  3315. /* Free the allocated rpi headers. */
  3316. lpfc_sli4_remove_rpi_hdrs(phba);
  3317. lpfc_sli4_remove_rpis(phba);
  3318. /* Free the ELS sgl list */
  3319. lpfc_free_active_sgl(phba);
  3320. lpfc_free_sgl_list(phba);
  3321. /* Free the SCSI sgl management array */
  3322. kfree(phba->sli4_hba.lpfc_scsi_psb_array);
  3323. /* Free the SLI4 queues */
  3324. lpfc_sli4_queue_destroy(phba);
  3325. /* Free the completion queue EQ event pool */
  3326. lpfc_sli4_cq_event_release_all(phba);
  3327. lpfc_sli4_cq_event_pool_destroy(phba);
  3328. /* Reset SLI4 HBA FCoE function */
  3329. lpfc_pci_function_reset(phba);
  3330. /* Free the bsmbx region. */
  3331. lpfc_destroy_bootstrap_mbox(phba);
  3332. /* Free the SLI Layer memory with SLI4 HBAs */
  3333. lpfc_mem_free_all(phba);
  3334. /* Free the current connect table */
  3335. list_for_each_entry_safe(conn_entry, next_conn_entry,
  3336. &phba->fcf_conn_rec_list, list) {
  3337. list_del_init(&conn_entry->list);
  3338. kfree(conn_entry);
  3339. }
  3340. return;
  3341. }
  3342. /**
  3343. * lpfc_init_api_table_setup - Set up init api fucntion jump table
  3344. * @phba: The hba struct for which this call is being executed.
  3345. * @dev_grp: The HBA PCI-Device group number.
  3346. *
  3347. * This routine sets up the device INIT interface API function jump table
  3348. * in @phba struct.
  3349. *
  3350. * Returns: 0 - success, -ENODEV - failure.
  3351. **/
  3352. int
  3353. lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  3354. {
  3355. switch (dev_grp) {
  3356. case LPFC_PCI_DEV_LP:
  3357. phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
  3358. phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
  3359. phba->lpfc_stop_port = lpfc_stop_port_s3;
  3360. break;
  3361. case LPFC_PCI_DEV_OC:
  3362. phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
  3363. phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
  3364. phba->lpfc_stop_port = lpfc_stop_port_s4;
  3365. break;
  3366. default:
  3367. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3368. "1431 Invalid HBA PCI-device group: 0x%x\n",
  3369. dev_grp);
  3370. return -ENODEV;
  3371. break;
  3372. }
  3373. return 0;
  3374. }
  3375. /**
  3376. * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
  3377. * @phba: pointer to lpfc hba data structure.
  3378. *
  3379. * This routine is invoked to set up the driver internal resources before the
  3380. * device specific resource setup to support the HBA device it attached to.
  3381. *
  3382. * Return codes
  3383. * 0 - sucessful
  3384. * other values - error
  3385. **/
  3386. static int
  3387. lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
  3388. {
  3389. /*
  3390. * Driver resources common to all SLI revisions
  3391. */
  3392. atomic_set(&phba->fast_event_count, 0);
  3393. spin_lock_init(&phba->hbalock);
  3394. /* Initialize ndlp management spinlock */
  3395. spin_lock_init(&phba->ndlp_lock);
  3396. INIT_LIST_HEAD(&phba->port_list);
  3397. INIT_LIST_HEAD(&phba->work_list);
  3398. init_waitqueue_head(&phba->wait_4_mlo_m_q);
  3399. /* Initialize the wait queue head for the kernel thread */
  3400. init_waitqueue_head(&phba->work_waitq);
  3401. /* Initialize the scsi buffer list used by driver for scsi IO */
  3402. spin_lock_init(&phba->scsi_buf_list_lock);
  3403. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  3404. /* Initialize the fabric iocb list */
  3405. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  3406. /* Initialize list to save ELS buffers */
  3407. INIT_LIST_HEAD(&phba->elsbuf);
  3408. /* Initialize FCF connection rec list */
  3409. INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
  3410. return 0;
  3411. }
  3412. /**
  3413. * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
  3414. * @phba: pointer to lpfc hba data structure.
  3415. *
  3416. * This routine is invoked to set up the driver internal resources after the
  3417. * device specific resource setup to support the HBA device it attached to.
  3418. *
  3419. * Return codes
  3420. * 0 - sucessful
  3421. * other values - error
  3422. **/
  3423. static int
  3424. lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
  3425. {
  3426. int error;
  3427. /* Startup the kernel thread for this host adapter. */
  3428. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  3429. "lpfc_worker_%d", phba->brd_no);
  3430. if (IS_ERR(phba->worker_thread)) {
  3431. error = PTR_ERR(phba->worker_thread);
  3432. return error;
  3433. }
  3434. return 0;
  3435. }
  3436. /**
  3437. * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
  3438. * @phba: pointer to lpfc hba data structure.
  3439. *
  3440. * This routine is invoked to unset the driver internal resources set up after
  3441. * the device specific resource setup for supporting the HBA device it
  3442. * attached to.
  3443. **/
  3444. static void
  3445. lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
  3446. {
  3447. /* Stop kernel worker thread */
  3448. kthread_stop(phba->worker_thread);
  3449. }
  3450. /**
  3451. * lpfc_free_iocb_list - Free iocb list.
  3452. * @phba: pointer to lpfc hba data structure.
  3453. *
  3454. * This routine is invoked to free the driver's IOCB list and memory.
  3455. **/
  3456. static void
  3457. lpfc_free_iocb_list(struct lpfc_hba *phba)
  3458. {
  3459. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  3460. spin_lock_irq(&phba->hbalock);
  3461. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  3462. &phba->lpfc_iocb_list, list) {
  3463. list_del(&iocbq_entry->list);
  3464. kfree(iocbq_entry);
  3465. phba->total_iocbq_bufs--;
  3466. }
  3467. spin_unlock_irq(&phba->hbalock);
  3468. return;
  3469. }
  3470. /**
  3471. * lpfc_init_iocb_list - Allocate and initialize iocb list.
  3472. * @phba: pointer to lpfc hba data structure.
  3473. *
  3474. * This routine is invoked to allocate and initizlize the driver's IOCB
  3475. * list and set up the IOCB tag array accordingly.
  3476. *
  3477. * Return codes
  3478. * 0 - sucessful
  3479. * other values - error
  3480. **/
  3481. static int
  3482. lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
  3483. {
  3484. struct lpfc_iocbq *iocbq_entry = NULL;
  3485. uint16_t iotag;
  3486. int i;
  3487. /* Initialize and populate the iocb list per host. */
  3488. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  3489. for (i = 0; i < iocb_count; i++) {
  3490. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  3491. if (iocbq_entry == NULL) {
  3492. printk(KERN_ERR "%s: only allocated %d iocbs of "
  3493. "expected %d count. Unloading driver.\n",
  3494. __func__, i, LPFC_IOCB_LIST_CNT);
  3495. goto out_free_iocbq;
  3496. }
  3497. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  3498. if (iotag == 0) {
  3499. kfree(iocbq_entry);
  3500. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  3501. "Unloading driver.\n", __func__);
  3502. goto out_free_iocbq;
  3503. }
  3504. iocbq_entry->sli4_xritag = NO_XRI;
  3505. spin_lock_irq(&phba->hbalock);
  3506. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  3507. phba->total_iocbq_bufs++;
  3508. spin_unlock_irq(&phba->hbalock);
  3509. }
  3510. return 0;
  3511. out_free_iocbq:
  3512. lpfc_free_iocb_list(phba);
  3513. return -ENOMEM;
  3514. }
  3515. /**
  3516. * lpfc_free_sgl_list - Free sgl list.
  3517. * @phba: pointer to lpfc hba data structure.
  3518. *
  3519. * This routine is invoked to free the driver's sgl list and memory.
  3520. **/
  3521. static void
  3522. lpfc_free_sgl_list(struct lpfc_hba *phba)
  3523. {
  3524. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  3525. LIST_HEAD(sglq_list);
  3526. int rc = 0;
  3527. spin_lock_irq(&phba->hbalock);
  3528. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
  3529. spin_unlock_irq(&phba->hbalock);
  3530. list_for_each_entry_safe(sglq_entry, sglq_next,
  3531. &sglq_list, list) {
  3532. list_del(&sglq_entry->list);
  3533. lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
  3534. kfree(sglq_entry);
  3535. phba->sli4_hba.total_sglq_bufs--;
  3536. }
  3537. rc = lpfc_sli4_remove_all_sgl_pages(phba);
  3538. if (rc) {
  3539. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3540. "2005 Unable to deregister pages from HBA: %x\n", rc);
  3541. }
  3542. kfree(phba->sli4_hba.lpfc_els_sgl_array);
  3543. }
  3544. /**
  3545. * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
  3546. * @phba: pointer to lpfc hba data structure.
  3547. *
  3548. * This routine is invoked to allocate the driver's active sgl memory.
  3549. * This array will hold the sglq_entry's for active IOs.
  3550. **/
  3551. static int
  3552. lpfc_init_active_sgl_array(struct lpfc_hba *phba)
  3553. {
  3554. int size;
  3555. size = sizeof(struct lpfc_sglq *);
  3556. size *= phba->sli4_hba.max_cfg_param.max_xri;
  3557. phba->sli4_hba.lpfc_sglq_active_list =
  3558. kzalloc(size, GFP_KERNEL);
  3559. if (!phba->sli4_hba.lpfc_sglq_active_list)
  3560. return -ENOMEM;
  3561. return 0;
  3562. }
  3563. /**
  3564. * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
  3565. * @phba: pointer to lpfc hba data structure.
  3566. *
  3567. * This routine is invoked to walk through the array of active sglq entries
  3568. * and free all of the resources.
  3569. * This is just a place holder for now.
  3570. **/
  3571. static void
  3572. lpfc_free_active_sgl(struct lpfc_hba *phba)
  3573. {
  3574. kfree(phba->sli4_hba.lpfc_sglq_active_list);
  3575. }
  3576. /**
  3577. * lpfc_init_sgl_list - Allocate and initialize sgl list.
  3578. * @phba: pointer to lpfc hba data structure.
  3579. *
  3580. * This routine is invoked to allocate and initizlize the driver's sgl
  3581. * list and set up the sgl xritag tag array accordingly.
  3582. *
  3583. * Return codes
  3584. * 0 - sucessful
  3585. * other values - error
  3586. **/
  3587. static int
  3588. lpfc_init_sgl_list(struct lpfc_hba *phba)
  3589. {
  3590. struct lpfc_sglq *sglq_entry = NULL;
  3591. int i;
  3592. int els_xri_cnt;
  3593. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  3594. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3595. "2400 lpfc_init_sgl_list els %d.\n",
  3596. els_xri_cnt);
  3597. /* Initialize and populate the sglq list per host/VF. */
  3598. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
  3599. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  3600. /* Sanity check on XRI management */
  3601. if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) {
  3602. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3603. "2562 No room left for SCSI XRI allocation: "
  3604. "max_xri=%d, els_xri=%d\n",
  3605. phba->sli4_hba.max_cfg_param.max_xri,
  3606. els_xri_cnt);
  3607. return -ENOMEM;
  3608. }
  3609. /* Allocate memory for the ELS XRI management array */
  3610. phba->sli4_hba.lpfc_els_sgl_array =
  3611. kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt),
  3612. GFP_KERNEL);
  3613. if (!phba->sli4_hba.lpfc_els_sgl_array) {
  3614. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3615. "2401 Failed to allocate memory for ELS "
  3616. "XRI management array of size %d.\n",
  3617. els_xri_cnt);
  3618. return -ENOMEM;
  3619. }
  3620. /* Keep the SCSI XRI into the XRI management array */
  3621. phba->sli4_hba.scsi_xri_max =
  3622. phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
  3623. phba->sli4_hba.scsi_xri_cnt = 0;
  3624. phba->sli4_hba.lpfc_scsi_psb_array =
  3625. kzalloc((sizeof(struct lpfc_scsi_buf *) *
  3626. phba->sli4_hba.scsi_xri_max), GFP_KERNEL);
  3627. if (!phba->sli4_hba.lpfc_scsi_psb_array) {
  3628. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3629. "2563 Failed to allocate memory for SCSI "
  3630. "XRI management array of size %d.\n",
  3631. phba->sli4_hba.scsi_xri_max);
  3632. kfree(phba->sli4_hba.lpfc_els_sgl_array);
  3633. return -ENOMEM;
  3634. }
  3635. for (i = 0; i < els_xri_cnt; i++) {
  3636. sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL);
  3637. if (sglq_entry == NULL) {
  3638. printk(KERN_ERR "%s: only allocated %d sgls of "
  3639. "expected %d count. Unloading driver.\n",
  3640. __func__, i, els_xri_cnt);
  3641. goto out_free_mem;
  3642. }
  3643. sglq_entry->sli4_xritag = lpfc_sli4_next_xritag(phba);
  3644. if (sglq_entry->sli4_xritag == NO_XRI) {
  3645. kfree(sglq_entry);
  3646. printk(KERN_ERR "%s: failed to allocate XRI.\n"
  3647. "Unloading driver.\n", __func__);
  3648. goto out_free_mem;
  3649. }
  3650. sglq_entry->buff_type = GEN_BUFF_TYPE;
  3651. sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys);
  3652. if (sglq_entry->virt == NULL) {
  3653. kfree(sglq_entry);
  3654. printk(KERN_ERR "%s: failed to allocate mbuf.\n"
  3655. "Unloading driver.\n", __func__);
  3656. goto out_free_mem;
  3657. }
  3658. sglq_entry->sgl = sglq_entry->virt;
  3659. memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
  3660. /* The list order is used by later block SGL registraton */
  3661. spin_lock_irq(&phba->hbalock);
  3662. list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list);
  3663. phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry;
  3664. phba->sli4_hba.total_sglq_bufs++;
  3665. spin_unlock_irq(&phba->hbalock);
  3666. }
  3667. return 0;
  3668. out_free_mem:
  3669. kfree(phba->sli4_hba.lpfc_scsi_psb_array);
  3670. lpfc_free_sgl_list(phba);
  3671. return -ENOMEM;
  3672. }
  3673. /**
  3674. * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
  3675. * @phba: pointer to lpfc hba data structure.
  3676. *
  3677. * This routine is invoked to post rpi header templates to the
  3678. * HBA consistent with the SLI-4 interface spec. This routine
  3679. * posts a PAGE_SIZE memory region to the port to hold up to
  3680. * PAGE_SIZE modulo 64 rpi context headers.
  3681. * No locks are held here because this is an initialization routine
  3682. * called only from probe or lpfc_online when interrupts are not
  3683. * enabled and the driver is reinitializing the device.
  3684. *
  3685. * Return codes
  3686. * 0 - sucessful
  3687. * ENOMEM - No availble memory
  3688. * EIO - The mailbox failed to complete successfully.
  3689. **/
  3690. int
  3691. lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
  3692. {
  3693. int rc = 0;
  3694. int longs;
  3695. uint16_t rpi_count;
  3696. struct lpfc_rpi_hdr *rpi_hdr;
  3697. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
  3698. /*
  3699. * Provision an rpi bitmask range for discovery. The total count
  3700. * is the difference between max and base + 1.
  3701. */
  3702. rpi_count = phba->sli4_hba.max_cfg_param.rpi_base +
  3703. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  3704. longs = ((rpi_count) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  3705. phba->sli4_hba.rpi_bmask = kzalloc(longs * sizeof(unsigned long),
  3706. GFP_KERNEL);
  3707. if (!phba->sli4_hba.rpi_bmask)
  3708. return -ENOMEM;
  3709. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  3710. if (!rpi_hdr) {
  3711. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3712. "0391 Error during rpi post operation\n");
  3713. lpfc_sli4_remove_rpis(phba);
  3714. rc = -ENODEV;
  3715. }
  3716. return rc;
  3717. }
  3718. /**
  3719. * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
  3720. * @phba: pointer to lpfc hba data structure.
  3721. *
  3722. * This routine is invoked to allocate a single 4KB memory region to
  3723. * support rpis and stores them in the phba. This single region
  3724. * provides support for up to 64 rpis. The region is used globally
  3725. * by the device.
  3726. *
  3727. * Returns:
  3728. * A valid rpi hdr on success.
  3729. * A NULL pointer on any failure.
  3730. **/
  3731. struct lpfc_rpi_hdr *
  3732. lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
  3733. {
  3734. uint16_t rpi_limit, curr_rpi_range;
  3735. struct lpfc_dmabuf *dmabuf;
  3736. struct lpfc_rpi_hdr *rpi_hdr;
  3737. rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
  3738. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  3739. spin_lock_irq(&phba->hbalock);
  3740. curr_rpi_range = phba->sli4_hba.next_rpi;
  3741. spin_unlock_irq(&phba->hbalock);
  3742. /*
  3743. * The port has a limited number of rpis. The increment here
  3744. * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
  3745. * and to allow the full max_rpi range per port.
  3746. */
  3747. if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
  3748. return NULL;
  3749. /*
  3750. * First allocate the protocol header region for the port. The
  3751. * port expects a 4KB DMA-mapped memory region that is 4K aligned.
  3752. */
  3753. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3754. if (!dmabuf)
  3755. return NULL;
  3756. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3757. LPFC_HDR_TEMPLATE_SIZE,
  3758. &dmabuf->phys,
  3759. GFP_KERNEL);
  3760. if (!dmabuf->virt) {
  3761. rpi_hdr = NULL;
  3762. goto err_free_dmabuf;
  3763. }
  3764. memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
  3765. if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
  3766. rpi_hdr = NULL;
  3767. goto err_free_coherent;
  3768. }
  3769. /* Save the rpi header data for cleanup later. */
  3770. rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
  3771. if (!rpi_hdr)
  3772. goto err_free_coherent;
  3773. rpi_hdr->dmabuf = dmabuf;
  3774. rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
  3775. rpi_hdr->page_count = 1;
  3776. spin_lock_irq(&phba->hbalock);
  3777. rpi_hdr->start_rpi = phba->sli4_hba.next_rpi;
  3778. list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
  3779. /*
  3780. * The next_rpi stores the next module-64 rpi value to post
  3781. * in any subsequent rpi memory region postings.
  3782. */
  3783. phba->sli4_hba.next_rpi += LPFC_RPI_HDR_COUNT;
  3784. spin_unlock_irq(&phba->hbalock);
  3785. return rpi_hdr;
  3786. err_free_coherent:
  3787. dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
  3788. dmabuf->virt, dmabuf->phys);
  3789. err_free_dmabuf:
  3790. kfree(dmabuf);
  3791. return NULL;
  3792. }
  3793. /**
  3794. * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
  3795. * @phba: pointer to lpfc hba data structure.
  3796. *
  3797. * This routine is invoked to remove all memory resources allocated
  3798. * to support rpis. This routine presumes the caller has released all
  3799. * rpis consumed by fabric or port logins and is prepared to have
  3800. * the header pages removed.
  3801. **/
  3802. void
  3803. lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
  3804. {
  3805. struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
  3806. list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
  3807. &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  3808. list_del(&rpi_hdr->list);
  3809. dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
  3810. rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
  3811. kfree(rpi_hdr->dmabuf);
  3812. kfree(rpi_hdr);
  3813. }
  3814. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
  3815. memset(phba->sli4_hba.rpi_bmask, 0, sizeof(*phba->sli4_hba.rpi_bmask));
  3816. }
  3817. /**
  3818. * lpfc_hba_alloc - Allocate driver hba data structure for a device.
  3819. * @pdev: pointer to pci device data structure.
  3820. *
  3821. * This routine is invoked to allocate the driver hba data structure for an
  3822. * HBA device. If the allocation is successful, the phba reference to the
  3823. * PCI device data structure is set.
  3824. *
  3825. * Return codes
  3826. * pointer to @phba - sucessful
  3827. * NULL - error
  3828. **/
  3829. static struct lpfc_hba *
  3830. lpfc_hba_alloc(struct pci_dev *pdev)
  3831. {
  3832. struct lpfc_hba *phba;
  3833. /* Allocate memory for HBA structure */
  3834. phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
  3835. if (!phba) {
  3836. dev_err(&pdev->dev, "failed to allocate hba struct\n");
  3837. return NULL;
  3838. }
  3839. /* Set reference to PCI device in HBA structure */
  3840. phba->pcidev = pdev;
  3841. /* Assign an unused board number */
  3842. phba->brd_no = lpfc_get_instance();
  3843. if (phba->brd_no < 0) {
  3844. kfree(phba);
  3845. return NULL;
  3846. }
  3847. mutex_init(&phba->ct_event_mutex);
  3848. INIT_LIST_HEAD(&phba->ct_ev_waiters);
  3849. return phba;
  3850. }
  3851. /**
  3852. * lpfc_hba_free - Free driver hba data structure with a device.
  3853. * @phba: pointer to lpfc hba data structure.
  3854. *
  3855. * This routine is invoked to free the driver hba data structure with an
  3856. * HBA device.
  3857. **/
  3858. static void
  3859. lpfc_hba_free(struct lpfc_hba *phba)
  3860. {
  3861. /* Release the driver assigned board number */
  3862. idr_remove(&lpfc_hba_index, phba->brd_no);
  3863. kfree(phba);
  3864. return;
  3865. }
  3866. /**
  3867. * lpfc_create_shost - Create hba physical port with associated scsi host.
  3868. * @phba: pointer to lpfc hba data structure.
  3869. *
  3870. * This routine is invoked to create HBA physical port and associate a SCSI
  3871. * host with it.
  3872. *
  3873. * Return codes
  3874. * 0 - sucessful
  3875. * other values - error
  3876. **/
  3877. static int
  3878. lpfc_create_shost(struct lpfc_hba *phba)
  3879. {
  3880. struct lpfc_vport *vport;
  3881. struct Scsi_Host *shost;
  3882. /* Initialize HBA FC structure */
  3883. phba->fc_edtov = FF_DEF_EDTOV;
  3884. phba->fc_ratov = FF_DEF_RATOV;
  3885. phba->fc_altov = FF_DEF_ALTOV;
  3886. phba->fc_arbtov = FF_DEF_ARBTOV;
  3887. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  3888. if (!vport)
  3889. return -ENODEV;
  3890. shost = lpfc_shost_from_vport(vport);
  3891. phba->pport = vport;
  3892. lpfc_debugfs_initialize(vport);
  3893. /* Put reference to SCSI host to driver's device private data */
  3894. pci_set_drvdata(phba->pcidev, shost);
  3895. return 0;
  3896. }
  3897. /**
  3898. * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
  3899. * @phba: pointer to lpfc hba data structure.
  3900. *
  3901. * This routine is invoked to destroy HBA physical port and the associated
  3902. * SCSI host.
  3903. **/
  3904. static void
  3905. lpfc_destroy_shost(struct lpfc_hba *phba)
  3906. {
  3907. struct lpfc_vport *vport = phba->pport;
  3908. /* Destroy physical port that associated with the SCSI host */
  3909. destroy_port(vport);
  3910. return;
  3911. }
  3912. /**
  3913. * lpfc_setup_bg - Setup Block guard structures and debug areas.
  3914. * @phba: pointer to lpfc hba data structure.
  3915. * @shost: the shost to be used to detect Block guard settings.
  3916. *
  3917. * This routine sets up the local Block guard protocol settings for @shost.
  3918. * This routine also allocates memory for debugging bg buffers.
  3919. **/
  3920. static void
  3921. lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
  3922. {
  3923. int pagecnt = 10;
  3924. if (lpfc_prot_mask && lpfc_prot_guard) {
  3925. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3926. "1478 Registering BlockGuard with the "
  3927. "SCSI layer\n");
  3928. scsi_host_set_prot(shost, lpfc_prot_mask);
  3929. scsi_host_set_guard(shost, lpfc_prot_guard);
  3930. }
  3931. if (!_dump_buf_data) {
  3932. while (pagecnt) {
  3933. spin_lock_init(&_dump_buf_lock);
  3934. _dump_buf_data =
  3935. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  3936. if (_dump_buf_data) {
  3937. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  3938. "9043 BLKGRD: allocated %d pages for "
  3939. "_dump_buf_data at 0x%p\n",
  3940. (1 << pagecnt), _dump_buf_data);
  3941. _dump_buf_data_order = pagecnt;
  3942. memset(_dump_buf_data, 0,
  3943. ((1 << PAGE_SHIFT) << pagecnt));
  3944. break;
  3945. } else
  3946. --pagecnt;
  3947. }
  3948. if (!_dump_buf_data_order)
  3949. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  3950. "9044 BLKGRD: ERROR unable to allocate "
  3951. "memory for hexdump\n");
  3952. } else
  3953. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  3954. "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
  3955. "\n", _dump_buf_data);
  3956. if (!_dump_buf_dif) {
  3957. while (pagecnt) {
  3958. _dump_buf_dif =
  3959. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  3960. if (_dump_buf_dif) {
  3961. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  3962. "9046 BLKGRD: allocated %d pages for "
  3963. "_dump_buf_dif at 0x%p\n",
  3964. (1 << pagecnt), _dump_buf_dif);
  3965. _dump_buf_dif_order = pagecnt;
  3966. memset(_dump_buf_dif, 0,
  3967. ((1 << PAGE_SHIFT) << pagecnt));
  3968. break;
  3969. } else
  3970. --pagecnt;
  3971. }
  3972. if (!_dump_buf_dif_order)
  3973. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  3974. "9047 BLKGRD: ERROR unable to allocate "
  3975. "memory for hexdump\n");
  3976. } else
  3977. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  3978. "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
  3979. _dump_buf_dif);
  3980. }
  3981. /**
  3982. * lpfc_post_init_setup - Perform necessary device post initialization setup.
  3983. * @phba: pointer to lpfc hba data structure.
  3984. *
  3985. * This routine is invoked to perform all the necessary post initialization
  3986. * setup for the device.
  3987. **/
  3988. static void
  3989. lpfc_post_init_setup(struct lpfc_hba *phba)
  3990. {
  3991. struct Scsi_Host *shost;
  3992. struct lpfc_adapter_event_header adapter_event;
  3993. /* Get the default values for Model Name and Description */
  3994. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  3995. /*
  3996. * hba setup may have changed the hba_queue_depth so we need to
  3997. * adjust the value of can_queue.
  3998. */
  3999. shost = pci_get_drvdata(phba->pcidev);
  4000. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  4001. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
  4002. lpfc_setup_bg(phba, shost);
  4003. lpfc_host_attrib_init(shost);
  4004. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  4005. spin_lock_irq(shost->host_lock);
  4006. lpfc_poll_start_timer(phba);
  4007. spin_unlock_irq(shost->host_lock);
  4008. }
  4009. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4010. "0428 Perform SCSI scan\n");
  4011. /* Send board arrival event to upper layer */
  4012. adapter_event.event_type = FC_REG_ADAPTER_EVENT;
  4013. adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
  4014. fc_host_post_vendor_event(shost, fc_get_event_number(),
  4015. sizeof(adapter_event),
  4016. (char *) &adapter_event,
  4017. LPFC_NL_VENDOR_ID);
  4018. return;
  4019. }
  4020. /**
  4021. * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
  4022. * @phba: pointer to lpfc hba data structure.
  4023. *
  4024. * This routine is invoked to set up the PCI device memory space for device
  4025. * with SLI-3 interface spec.
  4026. *
  4027. * Return codes
  4028. * 0 - sucessful
  4029. * other values - error
  4030. **/
  4031. static int
  4032. lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
  4033. {
  4034. struct pci_dev *pdev;
  4035. unsigned long bar0map_len, bar2map_len;
  4036. int i, hbq_count;
  4037. void *ptr;
  4038. int error = -ENODEV;
  4039. /* Obtain PCI device reference */
  4040. if (!phba->pcidev)
  4041. return error;
  4042. else
  4043. pdev = phba->pcidev;
  4044. /* Set the device DMA mask size */
  4045. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)
  4046. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)
  4047. return error;
  4048. /* Get the bus address of Bar0 and Bar2 and the number of bytes
  4049. * required by each mapping.
  4050. */
  4051. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  4052. bar0map_len = pci_resource_len(pdev, 0);
  4053. phba->pci_bar2_map = pci_resource_start(pdev, 2);
  4054. bar2map_len = pci_resource_len(pdev, 2);
  4055. /* Map HBA SLIM to a kernel virtual address. */
  4056. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  4057. if (!phba->slim_memmap_p) {
  4058. dev_printk(KERN_ERR, &pdev->dev,
  4059. "ioremap failed for SLIM memory.\n");
  4060. goto out;
  4061. }
  4062. /* Map HBA Control Registers to a kernel virtual address. */
  4063. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  4064. if (!phba->ctrl_regs_memmap_p) {
  4065. dev_printk(KERN_ERR, &pdev->dev,
  4066. "ioremap failed for HBA control registers.\n");
  4067. goto out_iounmap_slim;
  4068. }
  4069. /* Allocate memory for SLI-2 structures */
  4070. phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
  4071. SLI2_SLIM_SIZE,
  4072. &phba->slim2p.phys,
  4073. GFP_KERNEL);
  4074. if (!phba->slim2p.virt)
  4075. goto out_iounmap;
  4076. memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
  4077. phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
  4078. phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
  4079. phba->IOCBs = (phba->slim2p.virt +
  4080. offsetof(struct lpfc_sli2_slim, IOCBs));
  4081. phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
  4082. lpfc_sli_hbq_size(),
  4083. &phba->hbqslimp.phys,
  4084. GFP_KERNEL);
  4085. if (!phba->hbqslimp.virt)
  4086. goto out_free_slim;
  4087. hbq_count = lpfc_sli_hbq_count();
  4088. ptr = phba->hbqslimp.virt;
  4089. for (i = 0; i < hbq_count; ++i) {
  4090. phba->hbqs[i].hbq_virt = ptr;
  4091. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  4092. ptr += (lpfc_hbq_defs[i]->entry_count *
  4093. sizeof(struct lpfc_hbq_entry));
  4094. }
  4095. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  4096. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  4097. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  4098. INIT_LIST_HEAD(&phba->rb_pend_list);
  4099. phba->MBslimaddr = phba->slim_memmap_p;
  4100. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  4101. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  4102. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  4103. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  4104. return 0;
  4105. out_free_slim:
  4106. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  4107. phba->slim2p.virt, phba->slim2p.phys);
  4108. out_iounmap:
  4109. iounmap(phba->ctrl_regs_memmap_p);
  4110. out_iounmap_slim:
  4111. iounmap(phba->slim_memmap_p);
  4112. out:
  4113. return error;
  4114. }
  4115. /**
  4116. * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
  4117. * @phba: pointer to lpfc hba data structure.
  4118. *
  4119. * This routine is invoked to unset the PCI device memory space for device
  4120. * with SLI-3 interface spec.
  4121. **/
  4122. static void
  4123. lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
  4124. {
  4125. struct pci_dev *pdev;
  4126. /* Obtain PCI device reference */
  4127. if (!phba->pcidev)
  4128. return;
  4129. else
  4130. pdev = phba->pcidev;
  4131. /* Free coherent DMA memory allocated */
  4132. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  4133. phba->hbqslimp.virt, phba->hbqslimp.phys);
  4134. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  4135. phba->slim2p.virt, phba->slim2p.phys);
  4136. /* I/O memory unmap */
  4137. iounmap(phba->ctrl_regs_memmap_p);
  4138. iounmap(phba->slim_memmap_p);
  4139. return;
  4140. }
  4141. /**
  4142. * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
  4143. * @phba: pointer to lpfc hba data structure.
  4144. *
  4145. * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
  4146. * done and check status.
  4147. *
  4148. * Return 0 if successful, otherwise -ENODEV.
  4149. **/
  4150. int
  4151. lpfc_sli4_post_status_check(struct lpfc_hba *phba)
  4152. {
  4153. struct lpfc_register sta_reg, uerrlo_reg, uerrhi_reg, scratchpad;
  4154. uint32_t onlnreg0, onlnreg1;
  4155. int i, port_error = -ENODEV;
  4156. if (!phba->sli4_hba.STAregaddr)
  4157. return -ENODEV;
  4158. /* Wait up to 30 seconds for the SLI Port POST done and ready */
  4159. for (i = 0; i < 3000; i++) {
  4160. sta_reg.word0 = readl(phba->sli4_hba.STAregaddr);
  4161. /* Encounter fatal POST error, break out */
  4162. if (bf_get(lpfc_hst_state_perr, &sta_reg)) {
  4163. port_error = -ENODEV;
  4164. break;
  4165. }
  4166. if (LPFC_POST_STAGE_ARMFW_READY ==
  4167. bf_get(lpfc_hst_state_port_status, &sta_reg)) {
  4168. port_error = 0;
  4169. break;
  4170. }
  4171. msleep(10);
  4172. }
  4173. if (port_error)
  4174. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4175. "1408 Failure HBA POST Status: sta_reg=0x%x, "
  4176. "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, xrom=x%x, "
  4177. "dl=x%x, pstatus=x%x\n", sta_reg.word0,
  4178. bf_get(lpfc_hst_state_perr, &sta_reg),
  4179. bf_get(lpfc_hst_state_sfi, &sta_reg),
  4180. bf_get(lpfc_hst_state_nip, &sta_reg),
  4181. bf_get(lpfc_hst_state_ipc, &sta_reg),
  4182. bf_get(lpfc_hst_state_xrom, &sta_reg),
  4183. bf_get(lpfc_hst_state_dl, &sta_reg),
  4184. bf_get(lpfc_hst_state_port_status, &sta_reg));
  4185. /* Log device information */
  4186. scratchpad.word0 = readl(phba->sli4_hba.SCRATCHPADregaddr);
  4187. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4188. "2534 Device Info: ChipType=0x%x, SliRev=0x%x, "
  4189. "FeatureL1=0x%x, FeatureL2=0x%x\n",
  4190. bf_get(lpfc_scratchpad_chiptype, &scratchpad),
  4191. bf_get(lpfc_scratchpad_slirev, &scratchpad),
  4192. bf_get(lpfc_scratchpad_featurelevel1, &scratchpad),
  4193. bf_get(lpfc_scratchpad_featurelevel2, &scratchpad));
  4194. /* With uncoverable error, log the error message and return error */
  4195. onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr);
  4196. onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr);
  4197. if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) {
  4198. uerrlo_reg.word0 = readl(phba->sli4_hba.UERRLOregaddr);
  4199. uerrhi_reg.word0 = readl(phba->sli4_hba.UERRHIregaddr);
  4200. if (uerrlo_reg.word0 || uerrhi_reg.word0) {
  4201. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4202. "1422 HBA Unrecoverable error: "
  4203. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  4204. "online0_reg=0x%x, online1_reg=0x%x\n",
  4205. uerrlo_reg.word0, uerrhi_reg.word0,
  4206. onlnreg0, onlnreg1);
  4207. }
  4208. return -ENODEV;
  4209. }
  4210. return port_error;
  4211. }
  4212. /**
  4213. * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
  4214. * @phba: pointer to lpfc hba data structure.
  4215. *
  4216. * This routine is invoked to set up SLI4 BAR0 PCI config space register
  4217. * memory map.
  4218. **/
  4219. static void
  4220. lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba)
  4221. {
  4222. phba->sli4_hba.UERRLOregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4223. LPFC_UERR_STATUS_LO;
  4224. phba->sli4_hba.UERRHIregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4225. LPFC_UERR_STATUS_HI;
  4226. phba->sli4_hba.ONLINE0regaddr = phba->sli4_hba.conf_regs_memmap_p +
  4227. LPFC_ONLINE0;
  4228. phba->sli4_hba.ONLINE1regaddr = phba->sli4_hba.conf_regs_memmap_p +
  4229. LPFC_ONLINE1;
  4230. phba->sli4_hba.SCRATCHPADregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4231. LPFC_SCRATCHPAD;
  4232. }
  4233. /**
  4234. * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
  4235. * @phba: pointer to lpfc hba data structure.
  4236. *
  4237. * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
  4238. * memory map.
  4239. **/
  4240. static void
  4241. lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
  4242. {
  4243. phba->sli4_hba.STAregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4244. LPFC_HST_STATE;
  4245. phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4246. LPFC_HST_ISR0;
  4247. phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4248. LPFC_HST_IMR0;
  4249. phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4250. LPFC_HST_ISCR0;
  4251. return;
  4252. }
  4253. /**
  4254. * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
  4255. * @phba: pointer to lpfc hba data structure.
  4256. * @vf: virtual function number
  4257. *
  4258. * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
  4259. * based on the given viftual function number, @vf.
  4260. *
  4261. * Return 0 if successful, otherwise -ENODEV.
  4262. **/
  4263. static int
  4264. lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
  4265. {
  4266. if (vf > LPFC_VIR_FUNC_MAX)
  4267. return -ENODEV;
  4268. phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4269. vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL);
  4270. phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4271. vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL);
  4272. phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4273. vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
  4274. phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4275. vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
  4276. phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4277. vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
  4278. return 0;
  4279. }
  4280. /**
  4281. * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
  4282. * @phba: pointer to lpfc hba data structure.
  4283. *
  4284. * This routine is invoked to create the bootstrap mailbox
  4285. * region consistent with the SLI-4 interface spec. This
  4286. * routine allocates all memory necessary to communicate
  4287. * mailbox commands to the port and sets up all alignment
  4288. * needs. No locks are expected to be held when calling
  4289. * this routine.
  4290. *
  4291. * Return codes
  4292. * 0 - sucessful
  4293. * ENOMEM - could not allocated memory.
  4294. **/
  4295. static int
  4296. lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
  4297. {
  4298. uint32_t bmbx_size;
  4299. struct lpfc_dmabuf *dmabuf;
  4300. struct dma_address *dma_address;
  4301. uint32_t pa_addr;
  4302. uint64_t phys_addr;
  4303. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4304. if (!dmabuf)
  4305. return -ENOMEM;
  4306. /*
  4307. * The bootstrap mailbox region is comprised of 2 parts
  4308. * plus an alignment restriction of 16 bytes.
  4309. */
  4310. bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
  4311. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4312. bmbx_size,
  4313. &dmabuf->phys,
  4314. GFP_KERNEL);
  4315. if (!dmabuf->virt) {
  4316. kfree(dmabuf);
  4317. return -ENOMEM;
  4318. }
  4319. memset(dmabuf->virt, 0, bmbx_size);
  4320. /*
  4321. * Initialize the bootstrap mailbox pointers now so that the register
  4322. * operations are simple later. The mailbox dma address is required
  4323. * to be 16-byte aligned. Also align the virtual memory as each
  4324. * maibox is copied into the bmbx mailbox region before issuing the
  4325. * command to the port.
  4326. */
  4327. phba->sli4_hba.bmbx.dmabuf = dmabuf;
  4328. phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
  4329. phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
  4330. LPFC_ALIGN_16_BYTE);
  4331. phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
  4332. LPFC_ALIGN_16_BYTE);
  4333. /*
  4334. * Set the high and low physical addresses now. The SLI4 alignment
  4335. * requirement is 16 bytes and the mailbox is posted to the port
  4336. * as two 30-bit addresses. The other data is a bit marking whether
  4337. * the 30-bit address is the high or low address.
  4338. * Upcast bmbx aphys to 64bits so shift instruction compiles
  4339. * clean on 32 bit machines.
  4340. */
  4341. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4342. phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
  4343. pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
  4344. dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
  4345. LPFC_BMBX_BIT1_ADDR_HI);
  4346. pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
  4347. dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
  4348. LPFC_BMBX_BIT1_ADDR_LO);
  4349. return 0;
  4350. }
  4351. /**
  4352. * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
  4353. * @phba: pointer to lpfc hba data structure.
  4354. *
  4355. * This routine is invoked to teardown the bootstrap mailbox
  4356. * region and release all host resources. This routine requires
  4357. * the caller to ensure all mailbox commands recovered, no
  4358. * additional mailbox comands are sent, and interrupts are disabled
  4359. * before calling this routine.
  4360. *
  4361. **/
  4362. static void
  4363. lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
  4364. {
  4365. dma_free_coherent(&phba->pcidev->dev,
  4366. phba->sli4_hba.bmbx.bmbx_size,
  4367. phba->sli4_hba.bmbx.dmabuf->virt,
  4368. phba->sli4_hba.bmbx.dmabuf->phys);
  4369. kfree(phba->sli4_hba.bmbx.dmabuf);
  4370. memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
  4371. }
  4372. /**
  4373. * lpfc_sli4_read_config - Get the config parameters.
  4374. * @phba: pointer to lpfc hba data structure.
  4375. *
  4376. * This routine is invoked to read the configuration parameters from the HBA.
  4377. * The configuration parameters are used to set the base and maximum values
  4378. * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
  4379. * allocation for the port.
  4380. *
  4381. * Return codes
  4382. * 0 - sucessful
  4383. * ENOMEM - No availble memory
  4384. * EIO - The mailbox failed to complete successfully.
  4385. **/
  4386. static int
  4387. lpfc_sli4_read_config(struct lpfc_hba *phba)
  4388. {
  4389. LPFC_MBOXQ_t *pmb;
  4390. struct lpfc_mbx_read_config *rd_config;
  4391. uint32_t rc = 0;
  4392. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4393. if (!pmb) {
  4394. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4395. "2011 Unable to allocate memory for issuing "
  4396. "SLI_CONFIG_SPECIAL mailbox command\n");
  4397. return -ENOMEM;
  4398. }
  4399. lpfc_read_config(phba, pmb);
  4400. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  4401. if (rc != MBX_SUCCESS) {
  4402. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4403. "2012 Mailbox failed , mbxCmd x%x "
  4404. "READ_CONFIG, mbxStatus x%x\n",
  4405. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  4406. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  4407. rc = -EIO;
  4408. } else {
  4409. rd_config = &pmb->u.mqe.un.rd_config;
  4410. phba->sli4_hba.max_cfg_param.max_xri =
  4411. bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
  4412. phba->sli4_hba.max_cfg_param.xri_base =
  4413. bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
  4414. phba->sli4_hba.max_cfg_param.max_vpi =
  4415. bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
  4416. phba->sli4_hba.max_cfg_param.vpi_base =
  4417. bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
  4418. phba->sli4_hba.max_cfg_param.max_rpi =
  4419. bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
  4420. phba->sli4_hba.max_cfg_param.rpi_base =
  4421. bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
  4422. phba->sli4_hba.max_cfg_param.max_vfi =
  4423. bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
  4424. phba->sli4_hba.max_cfg_param.vfi_base =
  4425. bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
  4426. phba->sli4_hba.max_cfg_param.max_fcfi =
  4427. bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
  4428. phba->sli4_hba.max_cfg_param.fcfi_base =
  4429. bf_get(lpfc_mbx_rd_conf_fcfi_base, rd_config);
  4430. phba->sli4_hba.max_cfg_param.max_eq =
  4431. bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
  4432. phba->sli4_hba.max_cfg_param.max_rq =
  4433. bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
  4434. phba->sli4_hba.max_cfg_param.max_wq =
  4435. bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
  4436. phba->sli4_hba.max_cfg_param.max_cq =
  4437. bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
  4438. phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
  4439. phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
  4440. phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
  4441. phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
  4442. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
  4443. phba->max_vpi = phba->sli4_hba.max_cfg_param.max_vpi;
  4444. phba->max_vports = phba->max_vpi;
  4445. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4446. "2003 cfg params XRI(B:%d M:%d), "
  4447. "VPI(B:%d M:%d) "
  4448. "VFI(B:%d M:%d) "
  4449. "RPI(B:%d M:%d) "
  4450. "FCFI(B:%d M:%d)\n",
  4451. phba->sli4_hba.max_cfg_param.xri_base,
  4452. phba->sli4_hba.max_cfg_param.max_xri,
  4453. phba->sli4_hba.max_cfg_param.vpi_base,
  4454. phba->sli4_hba.max_cfg_param.max_vpi,
  4455. phba->sli4_hba.max_cfg_param.vfi_base,
  4456. phba->sli4_hba.max_cfg_param.max_vfi,
  4457. phba->sli4_hba.max_cfg_param.rpi_base,
  4458. phba->sli4_hba.max_cfg_param.max_rpi,
  4459. phba->sli4_hba.max_cfg_param.fcfi_base,
  4460. phba->sli4_hba.max_cfg_param.max_fcfi);
  4461. }
  4462. mempool_free(pmb, phba->mbox_mem_pool);
  4463. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  4464. if (phba->cfg_hba_queue_depth > (phba->sli4_hba.max_cfg_param.max_xri))
  4465. phba->cfg_hba_queue_depth =
  4466. phba->sli4_hba.max_cfg_param.max_xri;
  4467. return rc;
  4468. }
  4469. /**
  4470. * lpfc_dev_endian_order_setup - Notify the port of the host's endian order.
  4471. * @phba: pointer to lpfc hba data structure.
  4472. *
  4473. * This routine is invoked to setup the host-side endian order to the
  4474. * HBA consistent with the SLI-4 interface spec.
  4475. *
  4476. * Return codes
  4477. * 0 - sucessful
  4478. * ENOMEM - No availble memory
  4479. * EIO - The mailbox failed to complete successfully.
  4480. **/
  4481. static int
  4482. lpfc_setup_endian_order(struct lpfc_hba *phba)
  4483. {
  4484. LPFC_MBOXQ_t *mboxq;
  4485. uint32_t rc = 0;
  4486. uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
  4487. HOST_ENDIAN_HIGH_WORD1};
  4488. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4489. if (!mboxq) {
  4490. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4491. "0492 Unable to allocate memory for issuing "
  4492. "SLI_CONFIG_SPECIAL mailbox command\n");
  4493. return -ENOMEM;
  4494. }
  4495. /*
  4496. * The SLI4_CONFIG_SPECIAL mailbox command requires the first two
  4497. * words to contain special data values and no other data.
  4498. */
  4499. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  4500. memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
  4501. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4502. if (rc != MBX_SUCCESS) {
  4503. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4504. "0493 SLI_CONFIG_SPECIAL mailbox failed with "
  4505. "status x%x\n",
  4506. rc);
  4507. rc = -EIO;
  4508. }
  4509. mempool_free(mboxq, phba->mbox_mem_pool);
  4510. return rc;
  4511. }
  4512. /**
  4513. * lpfc_sli4_queue_create - Create all the SLI4 queues
  4514. * @phba: pointer to lpfc hba data structure.
  4515. *
  4516. * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
  4517. * operation. For each SLI4 queue type, the parameters such as queue entry
  4518. * count (queue depth) shall be taken from the module parameter. For now,
  4519. * we just use some constant number as place holder.
  4520. *
  4521. * Return codes
  4522. * 0 - sucessful
  4523. * ENOMEM - No availble memory
  4524. * EIO - The mailbox failed to complete successfully.
  4525. **/
  4526. static int
  4527. lpfc_sli4_queue_create(struct lpfc_hba *phba)
  4528. {
  4529. struct lpfc_queue *qdesc;
  4530. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  4531. int cfg_fcp_wq_count;
  4532. int cfg_fcp_eq_count;
  4533. /*
  4534. * Sanity check for confiugred queue parameters against the run-time
  4535. * device parameters
  4536. */
  4537. /* Sanity check on FCP fast-path WQ parameters */
  4538. cfg_fcp_wq_count = phba->cfg_fcp_wq_count;
  4539. if (cfg_fcp_wq_count >
  4540. (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) {
  4541. cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq -
  4542. LPFC_SP_WQN_DEF;
  4543. if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) {
  4544. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4545. "2581 Not enough WQs (%d) from "
  4546. "the pci function for supporting "
  4547. "FCP WQs (%d)\n",
  4548. phba->sli4_hba.max_cfg_param.max_wq,
  4549. phba->cfg_fcp_wq_count);
  4550. goto out_error;
  4551. }
  4552. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4553. "2582 Not enough WQs (%d) from the pci "
  4554. "function for supporting the requested "
  4555. "FCP WQs (%d), the actual FCP WQs can "
  4556. "be supported: %d\n",
  4557. phba->sli4_hba.max_cfg_param.max_wq,
  4558. phba->cfg_fcp_wq_count, cfg_fcp_wq_count);
  4559. }
  4560. /* The actual number of FCP work queues adopted */
  4561. phba->cfg_fcp_wq_count = cfg_fcp_wq_count;
  4562. /* Sanity check on FCP fast-path EQ parameters */
  4563. cfg_fcp_eq_count = phba->cfg_fcp_eq_count;
  4564. if (cfg_fcp_eq_count >
  4565. (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) {
  4566. cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq -
  4567. LPFC_SP_EQN_DEF;
  4568. if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) {
  4569. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4570. "2574 Not enough EQs (%d) from the "
  4571. "pci function for supporting FCP "
  4572. "EQs (%d)\n",
  4573. phba->sli4_hba.max_cfg_param.max_eq,
  4574. phba->cfg_fcp_eq_count);
  4575. goto out_error;
  4576. }
  4577. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4578. "2575 Not enough EQs (%d) from the pci "
  4579. "function for supporting the requested "
  4580. "FCP EQs (%d), the actual FCP EQs can "
  4581. "be supported: %d\n",
  4582. phba->sli4_hba.max_cfg_param.max_eq,
  4583. phba->cfg_fcp_eq_count, cfg_fcp_eq_count);
  4584. }
  4585. /* It does not make sense to have more EQs than WQs */
  4586. if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) {
  4587. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4588. "2593 The FCP EQ count(%d) cannot be greater "
  4589. "than the FCP WQ count(%d), limiting the "
  4590. "FCP EQ count to %d\n", cfg_fcp_eq_count,
  4591. phba->cfg_fcp_wq_count,
  4592. phba->cfg_fcp_wq_count);
  4593. cfg_fcp_eq_count = phba->cfg_fcp_wq_count;
  4594. }
  4595. /* The actual number of FCP event queues adopted */
  4596. phba->cfg_fcp_eq_count = cfg_fcp_eq_count;
  4597. /* The overall number of event queues used */
  4598. phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF;
  4599. /*
  4600. * Create Event Queues (EQs)
  4601. */
  4602. /* Get EQ depth from module parameter, fake the default for now */
  4603. phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
  4604. phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
  4605. /* Create slow path event queue */
  4606. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  4607. phba->sli4_hba.eq_ecount);
  4608. if (!qdesc) {
  4609. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4610. "0496 Failed allocate slow-path EQ\n");
  4611. goto out_error;
  4612. }
  4613. phba->sli4_hba.sp_eq = qdesc;
  4614. /* Create fast-path FCP Event Queue(s) */
  4615. phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
  4616. phba->cfg_fcp_eq_count), GFP_KERNEL);
  4617. if (!phba->sli4_hba.fp_eq) {
  4618. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4619. "2576 Failed allocate memory for fast-path "
  4620. "EQ record array\n");
  4621. goto out_free_sp_eq;
  4622. }
  4623. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  4624. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  4625. phba->sli4_hba.eq_ecount);
  4626. if (!qdesc) {
  4627. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4628. "0497 Failed allocate fast-path EQ\n");
  4629. goto out_free_fp_eq;
  4630. }
  4631. phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc;
  4632. }
  4633. /*
  4634. * Create Complete Queues (CQs)
  4635. */
  4636. /* Get CQ depth from module parameter, fake the default for now */
  4637. phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
  4638. phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
  4639. /* Create slow-path Mailbox Command Complete Queue */
  4640. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  4641. phba->sli4_hba.cq_ecount);
  4642. if (!qdesc) {
  4643. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4644. "0500 Failed allocate slow-path mailbox CQ\n");
  4645. goto out_free_fp_eq;
  4646. }
  4647. phba->sli4_hba.mbx_cq = qdesc;
  4648. /* Create slow-path ELS Complete Queue */
  4649. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  4650. phba->sli4_hba.cq_ecount);
  4651. if (!qdesc) {
  4652. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4653. "0501 Failed allocate slow-path ELS CQ\n");
  4654. goto out_free_mbx_cq;
  4655. }
  4656. phba->sli4_hba.els_cq = qdesc;
  4657. /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
  4658. phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
  4659. phba->cfg_fcp_eq_count), GFP_KERNEL);
  4660. if (!phba->sli4_hba.fcp_cq) {
  4661. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4662. "2577 Failed allocate memory for fast-path "
  4663. "CQ record array\n");
  4664. goto out_free_els_cq;
  4665. }
  4666. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
  4667. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  4668. phba->sli4_hba.cq_ecount);
  4669. if (!qdesc) {
  4670. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4671. "0499 Failed allocate fast-path FCP "
  4672. "CQ (%d)\n", fcp_cqidx);
  4673. goto out_free_fcp_cq;
  4674. }
  4675. phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc;
  4676. }
  4677. /* Create Mailbox Command Queue */
  4678. phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
  4679. phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
  4680. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
  4681. phba->sli4_hba.mq_ecount);
  4682. if (!qdesc) {
  4683. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4684. "0505 Failed allocate slow-path MQ\n");
  4685. goto out_free_fcp_cq;
  4686. }
  4687. phba->sli4_hba.mbx_wq = qdesc;
  4688. /*
  4689. * Create all the Work Queues (WQs)
  4690. */
  4691. phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
  4692. phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
  4693. /* Create slow-path ELS Work Queue */
  4694. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  4695. phba->sli4_hba.wq_ecount);
  4696. if (!qdesc) {
  4697. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4698. "0504 Failed allocate slow-path ELS WQ\n");
  4699. goto out_free_mbx_wq;
  4700. }
  4701. phba->sli4_hba.els_wq = qdesc;
  4702. /* Create fast-path FCP Work Queue(s) */
  4703. phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
  4704. phba->cfg_fcp_wq_count), GFP_KERNEL);
  4705. if (!phba->sli4_hba.fcp_wq) {
  4706. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4707. "2578 Failed allocate memory for fast-path "
  4708. "WQ record array\n");
  4709. goto out_free_els_wq;
  4710. }
  4711. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
  4712. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  4713. phba->sli4_hba.wq_ecount);
  4714. if (!qdesc) {
  4715. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4716. "0503 Failed allocate fast-path FCP "
  4717. "WQ (%d)\n", fcp_wqidx);
  4718. goto out_free_fcp_wq;
  4719. }
  4720. phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc;
  4721. }
  4722. /*
  4723. * Create Receive Queue (RQ)
  4724. */
  4725. phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
  4726. phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
  4727. /* Create Receive Queue for header */
  4728. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  4729. phba->sli4_hba.rq_ecount);
  4730. if (!qdesc) {
  4731. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4732. "0506 Failed allocate receive HRQ\n");
  4733. goto out_free_fcp_wq;
  4734. }
  4735. phba->sli4_hba.hdr_rq = qdesc;
  4736. /* Create Receive Queue for data */
  4737. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  4738. phba->sli4_hba.rq_ecount);
  4739. if (!qdesc) {
  4740. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4741. "0507 Failed allocate receive DRQ\n");
  4742. goto out_free_hdr_rq;
  4743. }
  4744. phba->sli4_hba.dat_rq = qdesc;
  4745. return 0;
  4746. out_free_hdr_rq:
  4747. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  4748. phba->sli4_hba.hdr_rq = NULL;
  4749. out_free_fcp_wq:
  4750. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) {
  4751. lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]);
  4752. phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL;
  4753. }
  4754. kfree(phba->sli4_hba.fcp_wq);
  4755. out_free_els_wq:
  4756. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  4757. phba->sli4_hba.els_wq = NULL;
  4758. out_free_mbx_wq:
  4759. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  4760. phba->sli4_hba.mbx_wq = NULL;
  4761. out_free_fcp_cq:
  4762. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) {
  4763. lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]);
  4764. phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL;
  4765. }
  4766. kfree(phba->sli4_hba.fcp_cq);
  4767. out_free_els_cq:
  4768. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  4769. phba->sli4_hba.els_cq = NULL;
  4770. out_free_mbx_cq:
  4771. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  4772. phba->sli4_hba.mbx_cq = NULL;
  4773. out_free_fp_eq:
  4774. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) {
  4775. lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]);
  4776. phba->sli4_hba.fp_eq[fcp_eqidx] = NULL;
  4777. }
  4778. kfree(phba->sli4_hba.fp_eq);
  4779. out_free_sp_eq:
  4780. lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
  4781. phba->sli4_hba.sp_eq = NULL;
  4782. out_error:
  4783. return -ENOMEM;
  4784. }
  4785. /**
  4786. * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
  4787. * @phba: pointer to lpfc hba data structure.
  4788. *
  4789. * This routine is invoked to release all the SLI4 queues with the FCoE HBA
  4790. * operation.
  4791. *
  4792. * Return codes
  4793. * 0 - sucessful
  4794. * ENOMEM - No availble memory
  4795. * EIO - The mailbox failed to complete successfully.
  4796. **/
  4797. static void
  4798. lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
  4799. {
  4800. int fcp_qidx;
  4801. /* Release mailbox command work queue */
  4802. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  4803. phba->sli4_hba.mbx_wq = NULL;
  4804. /* Release ELS work queue */
  4805. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  4806. phba->sli4_hba.els_wq = NULL;
  4807. /* Release FCP work queue */
  4808. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
  4809. lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]);
  4810. kfree(phba->sli4_hba.fcp_wq);
  4811. phba->sli4_hba.fcp_wq = NULL;
  4812. /* Release unsolicited receive queue */
  4813. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  4814. phba->sli4_hba.hdr_rq = NULL;
  4815. lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
  4816. phba->sli4_hba.dat_rq = NULL;
  4817. /* Release ELS complete queue */
  4818. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  4819. phba->sli4_hba.els_cq = NULL;
  4820. /* Release mailbox command complete queue */
  4821. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  4822. phba->sli4_hba.mbx_cq = NULL;
  4823. /* Release FCP response complete queue */
  4824. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  4825. lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]);
  4826. kfree(phba->sli4_hba.fcp_cq);
  4827. phba->sli4_hba.fcp_cq = NULL;
  4828. /* Release fast-path event queue */
  4829. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  4830. lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
  4831. kfree(phba->sli4_hba.fp_eq);
  4832. phba->sli4_hba.fp_eq = NULL;
  4833. /* Release slow-path event queue */
  4834. lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
  4835. phba->sli4_hba.sp_eq = NULL;
  4836. return;
  4837. }
  4838. /**
  4839. * lpfc_sli4_queue_setup - Set up all the SLI4 queues
  4840. * @phba: pointer to lpfc hba data structure.
  4841. *
  4842. * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
  4843. * operation.
  4844. *
  4845. * Return codes
  4846. * 0 - sucessful
  4847. * ENOMEM - No availble memory
  4848. * EIO - The mailbox failed to complete successfully.
  4849. **/
  4850. int
  4851. lpfc_sli4_queue_setup(struct lpfc_hba *phba)
  4852. {
  4853. int rc = -ENOMEM;
  4854. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  4855. int fcp_cq_index = 0;
  4856. /*
  4857. * Set up Event Queues (EQs)
  4858. */
  4859. /* Set up slow-path event queue */
  4860. if (!phba->sli4_hba.sp_eq) {
  4861. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4862. "0520 Slow-path EQ not allocated\n");
  4863. goto out_error;
  4864. }
  4865. rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq,
  4866. LPFC_SP_DEF_IMAX);
  4867. if (rc) {
  4868. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4869. "0521 Failed setup of slow-path EQ: "
  4870. "rc = 0x%x\n", rc);
  4871. goto out_error;
  4872. }
  4873. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4874. "2583 Slow-path EQ setup: queue-id=%d\n",
  4875. phba->sli4_hba.sp_eq->queue_id);
  4876. /* Set up fast-path event queue */
  4877. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  4878. if (!phba->sli4_hba.fp_eq[fcp_eqidx]) {
  4879. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4880. "0522 Fast-path EQ (%d) not "
  4881. "allocated\n", fcp_eqidx);
  4882. goto out_destroy_fp_eq;
  4883. }
  4884. rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx],
  4885. phba->cfg_fcp_imax);
  4886. if (rc) {
  4887. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4888. "0523 Failed setup of fast-path EQ "
  4889. "(%d), rc = 0x%x\n", fcp_eqidx, rc);
  4890. goto out_destroy_fp_eq;
  4891. }
  4892. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4893. "2584 Fast-path EQ setup: "
  4894. "queue[%d]-id=%d\n", fcp_eqidx,
  4895. phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id);
  4896. }
  4897. /*
  4898. * Set up Complete Queues (CQs)
  4899. */
  4900. /* Set up slow-path MBOX Complete Queue as the first CQ */
  4901. if (!phba->sli4_hba.mbx_cq) {
  4902. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4903. "0528 Mailbox CQ not allocated\n");
  4904. goto out_destroy_fp_eq;
  4905. }
  4906. rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq,
  4907. LPFC_MCQ, LPFC_MBOX);
  4908. if (rc) {
  4909. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4910. "0529 Failed setup of slow-path mailbox CQ: "
  4911. "rc = 0x%x\n", rc);
  4912. goto out_destroy_fp_eq;
  4913. }
  4914. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4915. "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
  4916. phba->sli4_hba.mbx_cq->queue_id,
  4917. phba->sli4_hba.sp_eq->queue_id);
  4918. /* Set up slow-path ELS Complete Queue */
  4919. if (!phba->sli4_hba.els_cq) {
  4920. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4921. "0530 ELS CQ not allocated\n");
  4922. goto out_destroy_mbx_cq;
  4923. }
  4924. rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq,
  4925. LPFC_WCQ, LPFC_ELS);
  4926. if (rc) {
  4927. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4928. "0531 Failed setup of slow-path ELS CQ: "
  4929. "rc = 0x%x\n", rc);
  4930. goto out_destroy_mbx_cq;
  4931. }
  4932. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4933. "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
  4934. phba->sli4_hba.els_cq->queue_id,
  4935. phba->sli4_hba.sp_eq->queue_id);
  4936. /* Set up fast-path FCP Response Complete Queue */
  4937. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
  4938. if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
  4939. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4940. "0526 Fast-path FCP CQ (%d) not "
  4941. "allocated\n", fcp_cqidx);
  4942. goto out_destroy_fcp_cq;
  4943. }
  4944. rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
  4945. phba->sli4_hba.fp_eq[fcp_cqidx],
  4946. LPFC_WCQ, LPFC_FCP);
  4947. if (rc) {
  4948. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4949. "0527 Failed setup of fast-path FCP "
  4950. "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
  4951. goto out_destroy_fcp_cq;
  4952. }
  4953. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4954. "2588 FCP CQ setup: cq[%d]-id=%d, "
  4955. "parent eq[%d]-id=%d\n",
  4956. fcp_cqidx,
  4957. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
  4958. fcp_cqidx,
  4959. phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id);
  4960. }
  4961. /*
  4962. * Set up all the Work Queues (WQs)
  4963. */
  4964. /* Set up Mailbox Command Queue */
  4965. if (!phba->sli4_hba.mbx_wq) {
  4966. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4967. "0538 Slow-path MQ not allocated\n");
  4968. goto out_destroy_fcp_cq;
  4969. }
  4970. rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
  4971. phba->sli4_hba.mbx_cq, LPFC_MBOX);
  4972. if (rc) {
  4973. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4974. "0539 Failed setup of slow-path MQ: "
  4975. "rc = 0x%x\n", rc);
  4976. goto out_destroy_fcp_cq;
  4977. }
  4978. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4979. "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
  4980. phba->sli4_hba.mbx_wq->queue_id,
  4981. phba->sli4_hba.mbx_cq->queue_id);
  4982. /* Set up slow-path ELS Work Queue */
  4983. if (!phba->sli4_hba.els_wq) {
  4984. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4985. "0536 Slow-path ELS WQ not allocated\n");
  4986. goto out_destroy_mbx_wq;
  4987. }
  4988. rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
  4989. phba->sli4_hba.els_cq, LPFC_ELS);
  4990. if (rc) {
  4991. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4992. "0537 Failed setup of slow-path ELS WQ: "
  4993. "rc = 0x%x\n", rc);
  4994. goto out_destroy_mbx_wq;
  4995. }
  4996. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4997. "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
  4998. phba->sli4_hba.els_wq->queue_id,
  4999. phba->sli4_hba.els_cq->queue_id);
  5000. /* Set up fast-path FCP Work Queue */
  5001. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
  5002. if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
  5003. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5004. "0534 Fast-path FCP WQ (%d) not "
  5005. "allocated\n", fcp_wqidx);
  5006. goto out_destroy_fcp_wq;
  5007. }
  5008. rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
  5009. phba->sli4_hba.fcp_cq[fcp_cq_index],
  5010. LPFC_FCP);
  5011. if (rc) {
  5012. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5013. "0535 Failed setup of fast-path FCP "
  5014. "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
  5015. goto out_destroy_fcp_wq;
  5016. }
  5017. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5018. "2591 FCP WQ setup: wq[%d]-id=%d, "
  5019. "parent cq[%d]-id=%d\n",
  5020. fcp_wqidx,
  5021. phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
  5022. fcp_cq_index,
  5023. phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id);
  5024. /* Round robin FCP Work Queue's Completion Queue assignment */
  5025. fcp_cq_index = ((fcp_cq_index + 1) % phba->cfg_fcp_eq_count);
  5026. }
  5027. /*
  5028. * Create Receive Queue (RQ)
  5029. */
  5030. if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
  5031. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5032. "0540 Receive Queue not allocated\n");
  5033. goto out_destroy_fcp_wq;
  5034. }
  5035. rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  5036. phba->sli4_hba.els_cq, LPFC_USOL);
  5037. if (rc) {
  5038. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5039. "0541 Failed setup of Receive Queue: "
  5040. "rc = 0x%x\n", rc);
  5041. goto out_destroy_fcp_wq;
  5042. }
  5043. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5044. "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
  5045. "parent cq-id=%d\n",
  5046. phba->sli4_hba.hdr_rq->queue_id,
  5047. phba->sli4_hba.dat_rq->queue_id,
  5048. phba->sli4_hba.els_cq->queue_id);
  5049. return 0;
  5050. out_destroy_fcp_wq:
  5051. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
  5052. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
  5053. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  5054. out_destroy_mbx_wq:
  5055. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  5056. out_destroy_fcp_cq:
  5057. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
  5058. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
  5059. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  5060. out_destroy_mbx_cq:
  5061. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  5062. out_destroy_fp_eq:
  5063. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
  5064. lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]);
  5065. lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
  5066. out_error:
  5067. return rc;
  5068. }
  5069. /**
  5070. * lpfc_sli4_queue_unset - Unset all the SLI4 queues
  5071. * @phba: pointer to lpfc hba data structure.
  5072. *
  5073. * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
  5074. * operation.
  5075. *
  5076. * Return codes
  5077. * 0 - sucessful
  5078. * ENOMEM - No availble memory
  5079. * EIO - The mailbox failed to complete successfully.
  5080. **/
  5081. void
  5082. lpfc_sli4_queue_unset(struct lpfc_hba *phba)
  5083. {
  5084. int fcp_qidx;
  5085. /* Unset mailbox command work queue */
  5086. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  5087. /* Unset ELS work queue */
  5088. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  5089. /* Unset unsolicited receive queue */
  5090. lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
  5091. /* Unset FCP work queue */
  5092. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
  5093. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
  5094. /* Unset mailbox command complete queue */
  5095. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  5096. /* Unset ELS complete queue */
  5097. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  5098. /* Unset FCP response complete queue */
  5099. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5100. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
  5101. /* Unset fast-path event queue */
  5102. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5103. lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]);
  5104. /* Unset slow-path event queue */
  5105. lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
  5106. }
  5107. /**
  5108. * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
  5109. * @phba: pointer to lpfc hba data structure.
  5110. *
  5111. * This routine is invoked to allocate and set up a pool of completion queue
  5112. * events. The body of the completion queue event is a completion queue entry
  5113. * CQE. For now, this pool is used for the interrupt service routine to queue
  5114. * the following HBA completion queue events for the worker thread to process:
  5115. * - Mailbox asynchronous events
  5116. * - Receive queue completion unsolicited events
  5117. * Later, this can be used for all the slow-path events.
  5118. *
  5119. * Return codes
  5120. * 0 - sucessful
  5121. * -ENOMEM - No availble memory
  5122. **/
  5123. static int
  5124. lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
  5125. {
  5126. struct lpfc_cq_event *cq_event;
  5127. int i;
  5128. for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
  5129. cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
  5130. if (!cq_event)
  5131. goto out_pool_create_fail;
  5132. list_add_tail(&cq_event->list,
  5133. &phba->sli4_hba.sp_cqe_event_pool);
  5134. }
  5135. return 0;
  5136. out_pool_create_fail:
  5137. lpfc_sli4_cq_event_pool_destroy(phba);
  5138. return -ENOMEM;
  5139. }
  5140. /**
  5141. * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
  5142. * @phba: pointer to lpfc hba data structure.
  5143. *
  5144. * This routine is invoked to free the pool of completion queue events at
  5145. * driver unload time. Note that, it is the responsibility of the driver
  5146. * cleanup routine to free all the outstanding completion-queue events
  5147. * allocated from this pool back into the pool before invoking this routine
  5148. * to destroy the pool.
  5149. **/
  5150. static void
  5151. lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
  5152. {
  5153. struct lpfc_cq_event *cq_event, *next_cq_event;
  5154. list_for_each_entry_safe(cq_event, next_cq_event,
  5155. &phba->sli4_hba.sp_cqe_event_pool, list) {
  5156. list_del(&cq_event->list);
  5157. kfree(cq_event);
  5158. }
  5159. }
  5160. /**
  5161. * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  5162. * @phba: pointer to lpfc hba data structure.
  5163. *
  5164. * This routine is the lock free version of the API invoked to allocate a
  5165. * completion-queue event from the free pool.
  5166. *
  5167. * Return: Pointer to the newly allocated completion-queue event if successful
  5168. * NULL otherwise.
  5169. **/
  5170. struct lpfc_cq_event *
  5171. __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  5172. {
  5173. struct lpfc_cq_event *cq_event = NULL;
  5174. list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
  5175. struct lpfc_cq_event, list);
  5176. return cq_event;
  5177. }
  5178. /**
  5179. * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  5180. * @phba: pointer to lpfc hba data structure.
  5181. *
  5182. * This routine is the lock version of the API invoked to allocate a
  5183. * completion-queue event from the free pool.
  5184. *
  5185. * Return: Pointer to the newly allocated completion-queue event if successful
  5186. * NULL otherwise.
  5187. **/
  5188. struct lpfc_cq_event *
  5189. lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  5190. {
  5191. struct lpfc_cq_event *cq_event;
  5192. unsigned long iflags;
  5193. spin_lock_irqsave(&phba->hbalock, iflags);
  5194. cq_event = __lpfc_sli4_cq_event_alloc(phba);
  5195. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5196. return cq_event;
  5197. }
  5198. /**
  5199. * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  5200. * @phba: pointer to lpfc hba data structure.
  5201. * @cq_event: pointer to the completion queue event to be freed.
  5202. *
  5203. * This routine is the lock free version of the API invoked to release a
  5204. * completion-queue event back into the free pool.
  5205. **/
  5206. void
  5207. __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  5208. struct lpfc_cq_event *cq_event)
  5209. {
  5210. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
  5211. }
  5212. /**
  5213. * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  5214. * @phba: pointer to lpfc hba data structure.
  5215. * @cq_event: pointer to the completion queue event to be freed.
  5216. *
  5217. * This routine is the lock version of the API invoked to release a
  5218. * completion-queue event back into the free pool.
  5219. **/
  5220. void
  5221. lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  5222. struct lpfc_cq_event *cq_event)
  5223. {
  5224. unsigned long iflags;
  5225. spin_lock_irqsave(&phba->hbalock, iflags);
  5226. __lpfc_sli4_cq_event_release(phba, cq_event);
  5227. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5228. }
  5229. /**
  5230. * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
  5231. * @phba: pointer to lpfc hba data structure.
  5232. *
  5233. * This routine is to free all the pending completion-queue events to the
  5234. * back into the free pool for device reset.
  5235. **/
  5236. static void
  5237. lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
  5238. {
  5239. LIST_HEAD(cqelist);
  5240. struct lpfc_cq_event *cqe;
  5241. unsigned long iflags;
  5242. /* Retrieve all the pending WCQEs from pending WCQE lists */
  5243. spin_lock_irqsave(&phba->hbalock, iflags);
  5244. /* Pending FCP XRI abort events */
  5245. list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  5246. &cqelist);
  5247. /* Pending ELS XRI abort events */
  5248. list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  5249. &cqelist);
  5250. /* Pending asynnc events */
  5251. list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
  5252. &cqelist);
  5253. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5254. while (!list_empty(&cqelist)) {
  5255. list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
  5256. lpfc_sli4_cq_event_release(phba, cqe);
  5257. }
  5258. }
  5259. /**
  5260. * lpfc_pci_function_reset - Reset pci function.
  5261. * @phba: pointer to lpfc hba data structure.
  5262. *
  5263. * This routine is invoked to request a PCI function reset. It will destroys
  5264. * all resources assigned to the PCI function which originates this request.
  5265. *
  5266. * Return codes
  5267. * 0 - sucessful
  5268. * ENOMEM - No availble memory
  5269. * EIO - The mailbox failed to complete successfully.
  5270. **/
  5271. int
  5272. lpfc_pci_function_reset(struct lpfc_hba *phba)
  5273. {
  5274. LPFC_MBOXQ_t *mboxq;
  5275. uint32_t rc = 0;
  5276. uint32_t shdr_status, shdr_add_status;
  5277. union lpfc_sli4_cfg_shdr *shdr;
  5278. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5279. if (!mboxq) {
  5280. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5281. "0494 Unable to allocate memory for issuing "
  5282. "SLI_FUNCTION_RESET mailbox command\n");
  5283. return -ENOMEM;
  5284. }
  5285. /* Set up PCI function reset SLI4_CONFIG mailbox-ioctl command */
  5286. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  5287. LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
  5288. LPFC_SLI4_MBX_EMBED);
  5289. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5290. shdr = (union lpfc_sli4_cfg_shdr *)
  5291. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  5292. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  5293. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  5294. if (rc != MBX_TIMEOUT)
  5295. mempool_free(mboxq, phba->mbox_mem_pool);
  5296. if (shdr_status || shdr_add_status || rc) {
  5297. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5298. "0495 SLI_FUNCTION_RESET mailbox failed with "
  5299. "status x%x add_status x%x, mbx status x%x\n",
  5300. shdr_status, shdr_add_status, rc);
  5301. rc = -ENXIO;
  5302. }
  5303. return rc;
  5304. }
  5305. /**
  5306. * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
  5307. * @phba: pointer to lpfc hba data structure.
  5308. * @cnt: number of nop mailbox commands to send.
  5309. *
  5310. * This routine is invoked to send a number @cnt of NOP mailbox command and
  5311. * wait for each command to complete.
  5312. *
  5313. * Return: the number of NOP mailbox command completed.
  5314. **/
  5315. static int
  5316. lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
  5317. {
  5318. LPFC_MBOXQ_t *mboxq;
  5319. int length, cmdsent;
  5320. uint32_t mbox_tmo;
  5321. uint32_t rc = 0;
  5322. uint32_t shdr_status, shdr_add_status;
  5323. union lpfc_sli4_cfg_shdr *shdr;
  5324. if (cnt == 0) {
  5325. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5326. "2518 Requested to send 0 NOP mailbox cmd\n");
  5327. return cnt;
  5328. }
  5329. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5330. if (!mboxq) {
  5331. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5332. "2519 Unable to allocate memory for issuing "
  5333. "NOP mailbox command\n");
  5334. return 0;
  5335. }
  5336. /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
  5337. length = (sizeof(struct lpfc_mbx_nop) -
  5338. sizeof(struct lpfc_sli4_cfg_mhdr));
  5339. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  5340. LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED);
  5341. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  5342. for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
  5343. if (!phba->sli4_hba.intr_enable)
  5344. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5345. else
  5346. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  5347. if (rc == MBX_TIMEOUT)
  5348. break;
  5349. /* Check return status */
  5350. shdr = (union lpfc_sli4_cfg_shdr *)
  5351. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  5352. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  5353. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  5354. &shdr->response);
  5355. if (shdr_status || shdr_add_status || rc) {
  5356. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5357. "2520 NOP mailbox command failed "
  5358. "status x%x add_status x%x mbx "
  5359. "status x%x\n", shdr_status,
  5360. shdr_add_status, rc);
  5361. break;
  5362. }
  5363. }
  5364. if (rc != MBX_TIMEOUT)
  5365. mempool_free(mboxq, phba->mbox_mem_pool);
  5366. return cmdsent;
  5367. }
  5368. /**
  5369. * lpfc_sli4_fcfi_unreg - Unregister fcfi to device
  5370. * @phba: pointer to lpfc hba data structure.
  5371. * @fcfi: fcf index.
  5372. *
  5373. * This routine is invoked to unregister a FCFI from device.
  5374. **/
  5375. void
  5376. lpfc_sli4_fcfi_unreg(struct lpfc_hba *phba, uint16_t fcfi)
  5377. {
  5378. LPFC_MBOXQ_t *mbox;
  5379. uint32_t mbox_tmo;
  5380. int rc;
  5381. unsigned long flags;
  5382. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5383. if (!mbox)
  5384. return;
  5385. lpfc_unreg_fcfi(mbox, fcfi);
  5386. if (!phba->sli4_hba.intr_enable)
  5387. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5388. else {
  5389. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  5390. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5391. }
  5392. if (rc != MBX_TIMEOUT)
  5393. mempool_free(mbox, phba->mbox_mem_pool);
  5394. if (rc != MBX_SUCCESS)
  5395. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5396. "2517 Unregister FCFI command failed "
  5397. "status %d, mbxStatus x%x\n", rc,
  5398. bf_get(lpfc_mqe_status, &mbox->u.mqe));
  5399. else {
  5400. spin_lock_irqsave(&phba->hbalock, flags);
  5401. /* Mark the FCFI is no longer registered */
  5402. phba->fcf.fcf_flag &=
  5403. ~(FCF_AVAILABLE | FCF_REGISTERED | FCF_DISCOVERED);
  5404. spin_unlock_irqrestore(&phba->hbalock, flags);
  5405. }
  5406. }
  5407. /**
  5408. * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
  5409. * @phba: pointer to lpfc hba data structure.
  5410. *
  5411. * This routine is invoked to set up the PCI device memory space for device
  5412. * with SLI-4 interface spec.
  5413. *
  5414. * Return codes
  5415. * 0 - sucessful
  5416. * other values - error
  5417. **/
  5418. static int
  5419. lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
  5420. {
  5421. struct pci_dev *pdev;
  5422. unsigned long bar0map_len, bar1map_len, bar2map_len;
  5423. int error = -ENODEV;
  5424. /* Obtain PCI device reference */
  5425. if (!phba->pcidev)
  5426. return error;
  5427. else
  5428. pdev = phba->pcidev;
  5429. /* Set the device DMA mask size */
  5430. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)
  5431. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)
  5432. return error;
  5433. /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the
  5434. * number of bytes required by each mapping. They are actually
  5435. * mapping to the PCI BAR regions 1, 2, and 4 by the SLI4 device.
  5436. */
  5437. phba->pci_bar0_map = pci_resource_start(pdev, LPFC_SLI4_BAR0);
  5438. bar0map_len = pci_resource_len(pdev, LPFC_SLI4_BAR0);
  5439. phba->pci_bar1_map = pci_resource_start(pdev, LPFC_SLI4_BAR1);
  5440. bar1map_len = pci_resource_len(pdev, LPFC_SLI4_BAR1);
  5441. phba->pci_bar2_map = pci_resource_start(pdev, LPFC_SLI4_BAR2);
  5442. bar2map_len = pci_resource_len(pdev, LPFC_SLI4_BAR2);
  5443. /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */
  5444. phba->sli4_hba.conf_regs_memmap_p =
  5445. ioremap(phba->pci_bar0_map, bar0map_len);
  5446. if (!phba->sli4_hba.conf_regs_memmap_p) {
  5447. dev_printk(KERN_ERR, &pdev->dev,
  5448. "ioremap failed for SLI4 PCI config registers.\n");
  5449. goto out;
  5450. }
  5451. /* Map SLI4 HBA Control Register base to a kernel virtual address. */
  5452. phba->sli4_hba.ctrl_regs_memmap_p =
  5453. ioremap(phba->pci_bar1_map, bar1map_len);
  5454. if (!phba->sli4_hba.ctrl_regs_memmap_p) {
  5455. dev_printk(KERN_ERR, &pdev->dev,
  5456. "ioremap failed for SLI4 HBA control registers.\n");
  5457. goto out_iounmap_conf;
  5458. }
  5459. /* Map SLI4 HBA Doorbell Register base to a kernel virtual address. */
  5460. phba->sli4_hba.drbl_regs_memmap_p =
  5461. ioremap(phba->pci_bar2_map, bar2map_len);
  5462. if (!phba->sli4_hba.drbl_regs_memmap_p) {
  5463. dev_printk(KERN_ERR, &pdev->dev,
  5464. "ioremap failed for SLI4 HBA doorbell registers.\n");
  5465. goto out_iounmap_ctrl;
  5466. }
  5467. /* Set up BAR0 PCI config space register memory map */
  5468. lpfc_sli4_bar0_register_memmap(phba);
  5469. /* Set up BAR1 register memory map */
  5470. lpfc_sli4_bar1_register_memmap(phba);
  5471. /* Set up BAR2 register memory map */
  5472. error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
  5473. if (error)
  5474. goto out_iounmap_all;
  5475. return 0;
  5476. out_iounmap_all:
  5477. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  5478. out_iounmap_ctrl:
  5479. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  5480. out_iounmap_conf:
  5481. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  5482. out:
  5483. return error;
  5484. }
  5485. /**
  5486. * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
  5487. * @phba: pointer to lpfc hba data structure.
  5488. *
  5489. * This routine is invoked to unset the PCI device memory space for device
  5490. * with SLI-4 interface spec.
  5491. **/
  5492. static void
  5493. lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
  5494. {
  5495. struct pci_dev *pdev;
  5496. /* Obtain PCI device reference */
  5497. if (!phba->pcidev)
  5498. return;
  5499. else
  5500. pdev = phba->pcidev;
  5501. /* Free coherent DMA memory allocated */
  5502. /* Unmap I/O memory space */
  5503. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  5504. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  5505. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  5506. return;
  5507. }
  5508. /**
  5509. * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
  5510. * @phba: pointer to lpfc hba data structure.
  5511. *
  5512. * This routine is invoked to enable the MSI-X interrupt vectors to device
  5513. * with SLI-3 interface specs. The kernel function pci_enable_msix() is
  5514. * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
  5515. * invoked, enables either all or nothing, depending on the current
  5516. * availability of PCI vector resources. The device driver is responsible
  5517. * for calling the individual request_irq() to register each MSI-X vector
  5518. * with a interrupt handler, which is done in this function. Note that
  5519. * later when device is unloading, the driver should always call free_irq()
  5520. * on all MSI-X vectors it has done request_irq() on before calling
  5521. * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
  5522. * will be left with MSI-X enabled and leaks its vectors.
  5523. *
  5524. * Return codes
  5525. * 0 - sucessful
  5526. * other values - error
  5527. **/
  5528. static int
  5529. lpfc_sli_enable_msix(struct lpfc_hba *phba)
  5530. {
  5531. int rc, i;
  5532. LPFC_MBOXQ_t *pmb;
  5533. /* Set up MSI-X multi-message vectors */
  5534. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  5535. phba->msix_entries[i].entry = i;
  5536. /* Configure MSI-X capability structure */
  5537. rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
  5538. ARRAY_SIZE(phba->msix_entries));
  5539. if (rc) {
  5540. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5541. "0420 PCI enable MSI-X failed (%d)\n", rc);
  5542. goto msi_fail_out;
  5543. }
  5544. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  5545. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5546. "0477 MSI-X entry[%d]: vector=x%x "
  5547. "message=%d\n", i,
  5548. phba->msix_entries[i].vector,
  5549. phba->msix_entries[i].entry);
  5550. /*
  5551. * Assign MSI-X vectors to interrupt handlers
  5552. */
  5553. /* vector-0 is associated to slow-path handler */
  5554. rc = request_irq(phba->msix_entries[0].vector,
  5555. &lpfc_sli_sp_intr_handler, IRQF_SHARED,
  5556. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  5557. if (rc) {
  5558. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5559. "0421 MSI-X slow-path request_irq failed "
  5560. "(%d)\n", rc);
  5561. goto msi_fail_out;
  5562. }
  5563. /* vector-1 is associated to fast-path handler */
  5564. rc = request_irq(phba->msix_entries[1].vector,
  5565. &lpfc_sli_fp_intr_handler, IRQF_SHARED,
  5566. LPFC_FP_DRIVER_HANDLER_NAME, phba);
  5567. if (rc) {
  5568. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5569. "0429 MSI-X fast-path request_irq failed "
  5570. "(%d)\n", rc);
  5571. goto irq_fail_out;
  5572. }
  5573. /*
  5574. * Configure HBA MSI-X attention conditions to messages
  5575. */
  5576. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5577. if (!pmb) {
  5578. rc = -ENOMEM;
  5579. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5580. "0474 Unable to allocate memory for issuing "
  5581. "MBOX_CONFIG_MSI command\n");
  5582. goto mem_fail_out;
  5583. }
  5584. rc = lpfc_config_msi(phba, pmb);
  5585. if (rc)
  5586. goto mbx_fail_out;
  5587. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  5588. if (rc != MBX_SUCCESS) {
  5589. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  5590. "0351 Config MSI mailbox command failed, "
  5591. "mbxCmd x%x, mbxStatus x%x\n",
  5592. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
  5593. goto mbx_fail_out;
  5594. }
  5595. /* Free memory allocated for mailbox command */
  5596. mempool_free(pmb, phba->mbox_mem_pool);
  5597. return rc;
  5598. mbx_fail_out:
  5599. /* Free memory allocated for mailbox command */
  5600. mempool_free(pmb, phba->mbox_mem_pool);
  5601. mem_fail_out:
  5602. /* free the irq already requested */
  5603. free_irq(phba->msix_entries[1].vector, phba);
  5604. irq_fail_out:
  5605. /* free the irq already requested */
  5606. free_irq(phba->msix_entries[0].vector, phba);
  5607. msi_fail_out:
  5608. /* Unconfigure MSI-X capability structure */
  5609. pci_disable_msix(phba->pcidev);
  5610. return rc;
  5611. }
  5612. /**
  5613. * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
  5614. * @phba: pointer to lpfc hba data structure.
  5615. *
  5616. * This routine is invoked to release the MSI-X vectors and then disable the
  5617. * MSI-X interrupt mode to device with SLI-3 interface spec.
  5618. **/
  5619. static void
  5620. lpfc_sli_disable_msix(struct lpfc_hba *phba)
  5621. {
  5622. int i;
  5623. /* Free up MSI-X multi-message vectors */
  5624. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  5625. free_irq(phba->msix_entries[i].vector, phba);
  5626. /* Disable MSI-X */
  5627. pci_disable_msix(phba->pcidev);
  5628. return;
  5629. }
  5630. /**
  5631. * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
  5632. * @phba: pointer to lpfc hba data structure.
  5633. *
  5634. * This routine is invoked to enable the MSI interrupt mode to device with
  5635. * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
  5636. * enable the MSI vector. The device driver is responsible for calling the
  5637. * request_irq() to register MSI vector with a interrupt the handler, which
  5638. * is done in this function.
  5639. *
  5640. * Return codes
  5641. * 0 - sucessful
  5642. * other values - error
  5643. */
  5644. static int
  5645. lpfc_sli_enable_msi(struct lpfc_hba *phba)
  5646. {
  5647. int rc;
  5648. rc = pci_enable_msi(phba->pcidev);
  5649. if (!rc)
  5650. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5651. "0462 PCI enable MSI mode success.\n");
  5652. else {
  5653. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5654. "0471 PCI enable MSI mode failed (%d)\n", rc);
  5655. return rc;
  5656. }
  5657. rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  5658. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  5659. if (rc) {
  5660. pci_disable_msi(phba->pcidev);
  5661. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5662. "0478 MSI request_irq failed (%d)\n", rc);
  5663. }
  5664. return rc;
  5665. }
  5666. /**
  5667. * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
  5668. * @phba: pointer to lpfc hba data structure.
  5669. *
  5670. * This routine is invoked to disable the MSI interrupt mode to device with
  5671. * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
  5672. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  5673. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  5674. * its vector.
  5675. */
  5676. static void
  5677. lpfc_sli_disable_msi(struct lpfc_hba *phba)
  5678. {
  5679. free_irq(phba->pcidev->irq, phba);
  5680. pci_disable_msi(phba->pcidev);
  5681. return;
  5682. }
  5683. /**
  5684. * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
  5685. * @phba: pointer to lpfc hba data structure.
  5686. *
  5687. * This routine is invoked to enable device interrupt and associate driver's
  5688. * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
  5689. * spec. Depends on the interrupt mode configured to the driver, the driver
  5690. * will try to fallback from the configured interrupt mode to an interrupt
  5691. * mode which is supported by the platform, kernel, and device in the order
  5692. * of:
  5693. * MSI-X -> MSI -> IRQ.
  5694. *
  5695. * Return codes
  5696. * 0 - sucessful
  5697. * other values - error
  5698. **/
  5699. static uint32_t
  5700. lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  5701. {
  5702. uint32_t intr_mode = LPFC_INTR_ERROR;
  5703. int retval;
  5704. if (cfg_mode == 2) {
  5705. /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
  5706. retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
  5707. if (!retval) {
  5708. /* Now, try to enable MSI-X interrupt mode */
  5709. retval = lpfc_sli_enable_msix(phba);
  5710. if (!retval) {
  5711. /* Indicate initialization to MSI-X mode */
  5712. phba->intr_type = MSIX;
  5713. intr_mode = 2;
  5714. }
  5715. }
  5716. }
  5717. /* Fallback to MSI if MSI-X initialization failed */
  5718. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  5719. retval = lpfc_sli_enable_msi(phba);
  5720. if (!retval) {
  5721. /* Indicate initialization to MSI mode */
  5722. phba->intr_type = MSI;
  5723. intr_mode = 1;
  5724. }
  5725. }
  5726. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  5727. if (phba->intr_type == NONE) {
  5728. retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  5729. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  5730. if (!retval) {
  5731. /* Indicate initialization to INTx mode */
  5732. phba->intr_type = INTx;
  5733. intr_mode = 0;
  5734. }
  5735. }
  5736. return intr_mode;
  5737. }
  5738. /**
  5739. * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
  5740. * @phba: pointer to lpfc hba data structure.
  5741. *
  5742. * This routine is invoked to disable device interrupt and disassociate the
  5743. * driver's interrupt handler(s) from interrupt vector(s) to device with
  5744. * SLI-3 interface spec. Depending on the interrupt mode, the driver will
  5745. * release the interrupt vector(s) for the message signaled interrupt.
  5746. **/
  5747. static void
  5748. lpfc_sli_disable_intr(struct lpfc_hba *phba)
  5749. {
  5750. /* Disable the currently initialized interrupt mode */
  5751. if (phba->intr_type == MSIX)
  5752. lpfc_sli_disable_msix(phba);
  5753. else if (phba->intr_type == MSI)
  5754. lpfc_sli_disable_msi(phba);
  5755. else if (phba->intr_type == INTx)
  5756. free_irq(phba->pcidev->irq, phba);
  5757. /* Reset interrupt management states */
  5758. phba->intr_type = NONE;
  5759. phba->sli.slistat.sli_intr = 0;
  5760. return;
  5761. }
  5762. /**
  5763. * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
  5764. * @phba: pointer to lpfc hba data structure.
  5765. *
  5766. * This routine is invoked to enable the MSI-X interrupt vectors to device
  5767. * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
  5768. * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
  5769. * enables either all or nothing, depending on the current availability of
  5770. * PCI vector resources. The device driver is responsible for calling the
  5771. * individual request_irq() to register each MSI-X vector with a interrupt
  5772. * handler, which is done in this function. Note that later when device is
  5773. * unloading, the driver should always call free_irq() on all MSI-X vectors
  5774. * it has done request_irq() on before calling pci_disable_msix(). Failure
  5775. * to do so results in a BUG_ON() and a device will be left with MSI-X
  5776. * enabled and leaks its vectors.
  5777. *
  5778. * Return codes
  5779. * 0 - sucessful
  5780. * other values - error
  5781. **/
  5782. static int
  5783. lpfc_sli4_enable_msix(struct lpfc_hba *phba)
  5784. {
  5785. int rc, index;
  5786. /* Set up MSI-X multi-message vectors */
  5787. for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
  5788. phba->sli4_hba.msix_entries[index].entry = index;
  5789. /* Configure MSI-X capability structure */
  5790. rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
  5791. phba->sli4_hba.cfg_eqn);
  5792. if (rc) {
  5793. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5794. "0484 PCI enable MSI-X failed (%d)\n", rc);
  5795. goto msi_fail_out;
  5796. }
  5797. /* Log MSI-X vector assignment */
  5798. for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
  5799. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5800. "0489 MSI-X entry[%d]: vector=x%x "
  5801. "message=%d\n", index,
  5802. phba->sli4_hba.msix_entries[index].vector,
  5803. phba->sli4_hba.msix_entries[index].entry);
  5804. /*
  5805. * Assign MSI-X vectors to interrupt handlers
  5806. */
  5807. /* The first vector must associated to slow-path handler for MQ */
  5808. rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
  5809. &lpfc_sli4_sp_intr_handler, IRQF_SHARED,
  5810. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  5811. if (rc) {
  5812. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5813. "0485 MSI-X slow-path request_irq failed "
  5814. "(%d)\n", rc);
  5815. goto msi_fail_out;
  5816. }
  5817. /* The rest of the vector(s) are associated to fast-path handler(s) */
  5818. for (index = 1; index < phba->sli4_hba.cfg_eqn; index++) {
  5819. phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1;
  5820. phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba;
  5821. rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
  5822. &lpfc_sli4_fp_intr_handler, IRQF_SHARED,
  5823. LPFC_FP_DRIVER_HANDLER_NAME,
  5824. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  5825. if (rc) {
  5826. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5827. "0486 MSI-X fast-path (%d) "
  5828. "request_irq failed (%d)\n", index, rc);
  5829. goto cfg_fail_out;
  5830. }
  5831. }
  5832. return rc;
  5833. cfg_fail_out:
  5834. /* free the irq already requested */
  5835. for (--index; index >= 1; index--)
  5836. free_irq(phba->sli4_hba.msix_entries[index - 1].vector,
  5837. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  5838. /* free the irq already requested */
  5839. free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
  5840. msi_fail_out:
  5841. /* Unconfigure MSI-X capability structure */
  5842. pci_disable_msix(phba->pcidev);
  5843. return rc;
  5844. }
  5845. /**
  5846. * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
  5847. * @phba: pointer to lpfc hba data structure.
  5848. *
  5849. * This routine is invoked to release the MSI-X vectors and then disable the
  5850. * MSI-X interrupt mode to device with SLI-4 interface spec.
  5851. **/
  5852. static void
  5853. lpfc_sli4_disable_msix(struct lpfc_hba *phba)
  5854. {
  5855. int index;
  5856. /* Free up MSI-X multi-message vectors */
  5857. free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
  5858. for (index = 1; index < phba->sli4_hba.cfg_eqn; index++)
  5859. free_irq(phba->sli4_hba.msix_entries[index].vector,
  5860. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  5861. /* Disable MSI-X */
  5862. pci_disable_msix(phba->pcidev);
  5863. return;
  5864. }
  5865. /**
  5866. * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
  5867. * @phba: pointer to lpfc hba data structure.
  5868. *
  5869. * This routine is invoked to enable the MSI interrupt mode to device with
  5870. * SLI-4 interface spec. The kernel function pci_enable_msi() is called
  5871. * to enable the MSI vector. The device driver is responsible for calling
  5872. * the request_irq() to register MSI vector with a interrupt the handler,
  5873. * which is done in this function.
  5874. *
  5875. * Return codes
  5876. * 0 - sucessful
  5877. * other values - error
  5878. **/
  5879. static int
  5880. lpfc_sli4_enable_msi(struct lpfc_hba *phba)
  5881. {
  5882. int rc, index;
  5883. rc = pci_enable_msi(phba->pcidev);
  5884. if (!rc)
  5885. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5886. "0487 PCI enable MSI mode success.\n");
  5887. else {
  5888. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5889. "0488 PCI enable MSI mode failed (%d)\n", rc);
  5890. return rc;
  5891. }
  5892. rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  5893. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  5894. if (rc) {
  5895. pci_disable_msi(phba->pcidev);
  5896. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5897. "0490 MSI request_irq failed (%d)\n", rc);
  5898. }
  5899. for (index = 0; index < phba->cfg_fcp_eq_count; index++) {
  5900. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  5901. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  5902. }
  5903. return rc;
  5904. }
  5905. /**
  5906. * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
  5907. * @phba: pointer to lpfc hba data structure.
  5908. *
  5909. * This routine is invoked to disable the MSI interrupt mode to device with
  5910. * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
  5911. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  5912. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  5913. * its vector.
  5914. **/
  5915. static void
  5916. lpfc_sli4_disable_msi(struct lpfc_hba *phba)
  5917. {
  5918. free_irq(phba->pcidev->irq, phba);
  5919. pci_disable_msi(phba->pcidev);
  5920. return;
  5921. }
  5922. /**
  5923. * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
  5924. * @phba: pointer to lpfc hba data structure.
  5925. *
  5926. * This routine is invoked to enable device interrupt and associate driver's
  5927. * interrupt handler(s) to interrupt vector(s) to device with SLI-4
  5928. * interface spec. Depends on the interrupt mode configured to the driver,
  5929. * the driver will try to fallback from the configured interrupt mode to an
  5930. * interrupt mode which is supported by the platform, kernel, and device in
  5931. * the order of:
  5932. * MSI-X -> MSI -> IRQ.
  5933. *
  5934. * Return codes
  5935. * 0 - sucessful
  5936. * other values - error
  5937. **/
  5938. static uint32_t
  5939. lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  5940. {
  5941. uint32_t intr_mode = LPFC_INTR_ERROR;
  5942. int retval, index;
  5943. if (cfg_mode == 2) {
  5944. /* Preparation before conf_msi mbox cmd */
  5945. retval = 0;
  5946. if (!retval) {
  5947. /* Now, try to enable MSI-X interrupt mode */
  5948. retval = lpfc_sli4_enable_msix(phba);
  5949. if (!retval) {
  5950. /* Indicate initialization to MSI-X mode */
  5951. phba->intr_type = MSIX;
  5952. intr_mode = 2;
  5953. }
  5954. }
  5955. }
  5956. /* Fallback to MSI if MSI-X initialization failed */
  5957. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  5958. retval = lpfc_sli4_enable_msi(phba);
  5959. if (!retval) {
  5960. /* Indicate initialization to MSI mode */
  5961. phba->intr_type = MSI;
  5962. intr_mode = 1;
  5963. }
  5964. }
  5965. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  5966. if (phba->intr_type == NONE) {
  5967. retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  5968. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  5969. if (!retval) {
  5970. /* Indicate initialization to INTx mode */
  5971. phba->intr_type = INTx;
  5972. intr_mode = 0;
  5973. for (index = 0; index < phba->cfg_fcp_eq_count;
  5974. index++) {
  5975. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  5976. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  5977. }
  5978. }
  5979. }
  5980. return intr_mode;
  5981. }
  5982. /**
  5983. * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
  5984. * @phba: pointer to lpfc hba data structure.
  5985. *
  5986. * This routine is invoked to disable device interrupt and disassociate
  5987. * the driver's interrupt handler(s) from interrupt vector(s) to device
  5988. * with SLI-4 interface spec. Depending on the interrupt mode, the driver
  5989. * will release the interrupt vector(s) for the message signaled interrupt.
  5990. **/
  5991. static void
  5992. lpfc_sli4_disable_intr(struct lpfc_hba *phba)
  5993. {
  5994. /* Disable the currently initialized interrupt mode */
  5995. if (phba->intr_type == MSIX)
  5996. lpfc_sli4_disable_msix(phba);
  5997. else if (phba->intr_type == MSI)
  5998. lpfc_sli4_disable_msi(phba);
  5999. else if (phba->intr_type == INTx)
  6000. free_irq(phba->pcidev->irq, phba);
  6001. /* Reset interrupt management states */
  6002. phba->intr_type = NONE;
  6003. phba->sli.slistat.sli_intr = 0;
  6004. return;
  6005. }
  6006. /**
  6007. * lpfc_unset_hba - Unset SLI3 hba device initialization
  6008. * @phba: pointer to lpfc hba data structure.
  6009. *
  6010. * This routine is invoked to unset the HBA device initialization steps to
  6011. * a device with SLI-3 interface spec.
  6012. **/
  6013. static void
  6014. lpfc_unset_hba(struct lpfc_hba *phba)
  6015. {
  6016. struct lpfc_vport *vport = phba->pport;
  6017. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6018. spin_lock_irq(shost->host_lock);
  6019. vport->load_flag |= FC_UNLOADING;
  6020. spin_unlock_irq(shost->host_lock);
  6021. lpfc_stop_hba_timers(phba);
  6022. phba->pport->work_port_events = 0;
  6023. lpfc_sli_hba_down(phba);
  6024. lpfc_sli_brdrestart(phba);
  6025. lpfc_sli_disable_intr(phba);
  6026. return;
  6027. }
  6028. /**
  6029. * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
  6030. * @phba: pointer to lpfc hba data structure.
  6031. *
  6032. * This routine is invoked to unset the HBA device initialization steps to
  6033. * a device with SLI-4 interface spec.
  6034. **/
  6035. static void
  6036. lpfc_sli4_unset_hba(struct lpfc_hba *phba)
  6037. {
  6038. struct lpfc_vport *vport = phba->pport;
  6039. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6040. spin_lock_irq(shost->host_lock);
  6041. vport->load_flag |= FC_UNLOADING;
  6042. spin_unlock_irq(shost->host_lock);
  6043. phba->pport->work_port_events = 0;
  6044. lpfc_sli4_hba_down(phba);
  6045. lpfc_sli4_disable_intr(phba);
  6046. return;
  6047. }
  6048. /**
  6049. * lpfc_sli4_hba_unset - Unset the fcoe hba
  6050. * @phba: Pointer to HBA context object.
  6051. *
  6052. * This function is called in the SLI4 code path to reset the HBA's FCoE
  6053. * function. The caller is not required to hold any lock. This routine
  6054. * issues PCI function reset mailbox command to reset the FCoE function.
  6055. * At the end of the function, it calls lpfc_hba_down_post function to
  6056. * free any pending commands.
  6057. **/
  6058. static void
  6059. lpfc_sli4_hba_unset(struct lpfc_hba *phba)
  6060. {
  6061. int wait_cnt = 0;
  6062. LPFC_MBOXQ_t *mboxq;
  6063. lpfc_stop_hba_timers(phba);
  6064. phba->sli4_hba.intr_enable = 0;
  6065. /*
  6066. * Gracefully wait out the potential current outstanding asynchronous
  6067. * mailbox command.
  6068. */
  6069. /* First, block any pending async mailbox command from posted */
  6070. spin_lock_irq(&phba->hbalock);
  6071. phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6072. spin_unlock_irq(&phba->hbalock);
  6073. /* Now, trying to wait it out if we can */
  6074. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6075. msleep(10);
  6076. if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
  6077. break;
  6078. }
  6079. /* Forcefully release the outstanding mailbox command if timed out */
  6080. if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6081. spin_lock_irq(&phba->hbalock);
  6082. mboxq = phba->sli.mbox_active;
  6083. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6084. __lpfc_mbox_cmpl_put(phba, mboxq);
  6085. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6086. phba->sli.mbox_active = NULL;
  6087. spin_unlock_irq(&phba->hbalock);
  6088. }
  6089. /* Tear down the queues in the HBA */
  6090. lpfc_sli4_queue_unset(phba);
  6091. /* Disable PCI subsystem interrupt */
  6092. lpfc_sli4_disable_intr(phba);
  6093. /* Stop kthread signal shall trigger work_done one more time */
  6094. kthread_stop(phba->worker_thread);
  6095. /* Stop the SLI4 device port */
  6096. phba->pport->work_port_events = 0;
  6097. }
  6098. /**
  6099. * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
  6100. * @pdev: pointer to PCI device
  6101. * @pid: pointer to PCI device identifier
  6102. *
  6103. * This routine is to be called to attach a device with SLI-3 interface spec
  6104. * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  6105. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  6106. * information of the device and driver to see if the driver state that it can
  6107. * support this kind of device. If the match is successful, the driver core
  6108. * invokes this routine. If this routine determines it can claim the HBA, it
  6109. * does all the initialization that it needs to do to handle the HBA properly.
  6110. *
  6111. * Return code
  6112. * 0 - driver can claim the device
  6113. * negative value - driver can not claim the device
  6114. **/
  6115. static int __devinit
  6116. lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
  6117. {
  6118. struct lpfc_hba *phba;
  6119. struct lpfc_vport *vport = NULL;
  6120. struct Scsi_Host *shost = NULL;
  6121. int error;
  6122. uint32_t cfg_mode, intr_mode;
  6123. /* Allocate memory for HBA structure */
  6124. phba = lpfc_hba_alloc(pdev);
  6125. if (!phba)
  6126. return -ENOMEM;
  6127. /* Perform generic PCI device enabling operation */
  6128. error = lpfc_enable_pci_dev(phba);
  6129. if (error) {
  6130. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6131. "1401 Failed to enable pci device.\n");
  6132. goto out_free_phba;
  6133. }
  6134. /* Set up SLI API function jump table for PCI-device group-0 HBAs */
  6135. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
  6136. if (error)
  6137. goto out_disable_pci_dev;
  6138. /* Set up SLI-3 specific device PCI memory space */
  6139. error = lpfc_sli_pci_mem_setup(phba);
  6140. if (error) {
  6141. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6142. "1402 Failed to set up pci memory space.\n");
  6143. goto out_disable_pci_dev;
  6144. }
  6145. /* Set up phase-1 common device driver resources */
  6146. error = lpfc_setup_driver_resource_phase1(phba);
  6147. if (error) {
  6148. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6149. "1403 Failed to set up driver resource.\n");
  6150. goto out_unset_pci_mem_s3;
  6151. }
  6152. /* Set up SLI-3 specific device driver resources */
  6153. error = lpfc_sli_driver_resource_setup(phba);
  6154. if (error) {
  6155. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6156. "1404 Failed to set up driver resource.\n");
  6157. goto out_unset_pci_mem_s3;
  6158. }
  6159. /* Initialize and populate the iocb list per host */
  6160. error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
  6161. if (error) {
  6162. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6163. "1405 Failed to initialize iocb list.\n");
  6164. goto out_unset_driver_resource_s3;
  6165. }
  6166. /* Set up common device driver resources */
  6167. error = lpfc_setup_driver_resource_phase2(phba);
  6168. if (error) {
  6169. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6170. "1406 Failed to set up driver resource.\n");
  6171. goto out_free_iocb_list;
  6172. }
  6173. /* Create SCSI host to the physical port */
  6174. error = lpfc_create_shost(phba);
  6175. if (error) {
  6176. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6177. "1407 Failed to create scsi host.\n");
  6178. goto out_unset_driver_resource;
  6179. }
  6180. /* Configure sysfs attributes */
  6181. vport = phba->pport;
  6182. error = lpfc_alloc_sysfs_attr(vport);
  6183. if (error) {
  6184. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6185. "1476 Failed to allocate sysfs attr\n");
  6186. goto out_destroy_shost;
  6187. }
  6188. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  6189. /* Now, trying to enable interrupt and bring up the device */
  6190. cfg_mode = phba->cfg_use_msi;
  6191. while (true) {
  6192. /* Put device to a known state before enabling interrupt */
  6193. lpfc_stop_port(phba);
  6194. /* Configure and enable interrupt */
  6195. intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
  6196. if (intr_mode == LPFC_INTR_ERROR) {
  6197. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6198. "0431 Failed to enable interrupt.\n");
  6199. error = -ENODEV;
  6200. goto out_free_sysfs_attr;
  6201. }
  6202. /* SLI-3 HBA setup */
  6203. if (lpfc_sli_hba_setup(phba)) {
  6204. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6205. "1477 Failed to set up hba\n");
  6206. error = -ENODEV;
  6207. goto out_remove_device;
  6208. }
  6209. /* Wait 50ms for the interrupts of previous mailbox commands */
  6210. msleep(50);
  6211. /* Check active interrupts on message signaled interrupts */
  6212. if (intr_mode == 0 ||
  6213. phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
  6214. /* Log the current active interrupt mode */
  6215. phba->intr_mode = intr_mode;
  6216. lpfc_log_intr_mode(phba, intr_mode);
  6217. break;
  6218. } else {
  6219. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6220. "0447 Configure interrupt mode (%d) "
  6221. "failed active interrupt test.\n",
  6222. intr_mode);
  6223. /* Disable the current interrupt mode */
  6224. lpfc_sli_disable_intr(phba);
  6225. /* Try next level of interrupt mode */
  6226. cfg_mode = --intr_mode;
  6227. }
  6228. }
  6229. /* Perform post initialization setup */
  6230. lpfc_post_init_setup(phba);
  6231. /* Check if there are static vports to be created. */
  6232. lpfc_create_static_vport(phba);
  6233. return 0;
  6234. out_remove_device:
  6235. lpfc_unset_hba(phba);
  6236. out_free_sysfs_attr:
  6237. lpfc_free_sysfs_attr(vport);
  6238. out_destroy_shost:
  6239. lpfc_destroy_shost(phba);
  6240. out_unset_driver_resource:
  6241. lpfc_unset_driver_resource_phase2(phba);
  6242. out_free_iocb_list:
  6243. lpfc_free_iocb_list(phba);
  6244. out_unset_driver_resource_s3:
  6245. lpfc_sli_driver_resource_unset(phba);
  6246. out_unset_pci_mem_s3:
  6247. lpfc_sli_pci_mem_unset(phba);
  6248. out_disable_pci_dev:
  6249. lpfc_disable_pci_dev(phba);
  6250. if (shost)
  6251. scsi_host_put(shost);
  6252. out_free_phba:
  6253. lpfc_hba_free(phba);
  6254. return error;
  6255. }
  6256. /**
  6257. * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
  6258. * @pdev: pointer to PCI device
  6259. *
  6260. * This routine is to be called to disattach a device with SLI-3 interface
  6261. * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  6262. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  6263. * device to be removed from the PCI subsystem properly.
  6264. **/
  6265. static void __devexit
  6266. lpfc_pci_remove_one_s3(struct pci_dev *pdev)
  6267. {
  6268. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6269. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  6270. struct lpfc_vport **vports;
  6271. struct lpfc_hba *phba = vport->phba;
  6272. int i;
  6273. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  6274. spin_lock_irq(&phba->hbalock);
  6275. vport->load_flag |= FC_UNLOADING;
  6276. spin_unlock_irq(&phba->hbalock);
  6277. lpfc_free_sysfs_attr(vport);
  6278. /* Release all the vports against this physical port */
  6279. vports = lpfc_create_vport_work_array(phba);
  6280. if (vports != NULL)
  6281. for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
  6282. fc_vport_terminate(vports[i]->fc_vport);
  6283. lpfc_destroy_vport_work_array(phba, vports);
  6284. /* Remove FC host and then SCSI host with the physical port */
  6285. fc_remove_host(shost);
  6286. scsi_remove_host(shost);
  6287. lpfc_cleanup(vport);
  6288. /*
  6289. * Bring down the SLI Layer. This step disable all interrupts,
  6290. * clears the rings, discards all mailbox commands, and resets
  6291. * the HBA.
  6292. */
  6293. /* HBA interrupt will be diabled after this call */
  6294. lpfc_sli_hba_down(phba);
  6295. /* Stop kthread signal shall trigger work_done one more time */
  6296. kthread_stop(phba->worker_thread);
  6297. /* Final cleanup of txcmplq and reset the HBA */
  6298. lpfc_sli_brdrestart(phba);
  6299. lpfc_stop_hba_timers(phba);
  6300. spin_lock_irq(&phba->hbalock);
  6301. list_del_init(&vport->listentry);
  6302. spin_unlock_irq(&phba->hbalock);
  6303. lpfc_debugfs_terminate(vport);
  6304. /* Disable interrupt */
  6305. lpfc_sli_disable_intr(phba);
  6306. pci_set_drvdata(pdev, NULL);
  6307. scsi_host_put(shost);
  6308. /*
  6309. * Call scsi_free before mem_free since scsi bufs are released to their
  6310. * corresponding pools here.
  6311. */
  6312. lpfc_scsi_free(phba);
  6313. lpfc_mem_free_all(phba);
  6314. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  6315. phba->hbqslimp.virt, phba->hbqslimp.phys);
  6316. /* Free resources associated with SLI2 interface */
  6317. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  6318. phba->slim2p.virt, phba->slim2p.phys);
  6319. /* unmap adapter SLIM and Control Registers */
  6320. iounmap(phba->ctrl_regs_memmap_p);
  6321. iounmap(phba->slim_memmap_p);
  6322. lpfc_hba_free(phba);
  6323. pci_release_selected_regions(pdev, bars);
  6324. pci_disable_device(pdev);
  6325. }
  6326. /**
  6327. * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
  6328. * @pdev: pointer to PCI device
  6329. * @msg: power management message
  6330. *
  6331. * This routine is to be called from the kernel's PCI subsystem to support
  6332. * system Power Management (PM) to device with SLI-3 interface spec. When
  6333. * PM invokes this method, it quiesces the device by stopping the driver's
  6334. * worker thread for the device, turning off device's interrupt and DMA,
  6335. * and bring the device offline. Note that as the driver implements the
  6336. * minimum PM requirements to a power-aware driver's PM support for the
  6337. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  6338. * to the suspend() method call will be treated as SUSPEND and the driver will
  6339. * fully reinitialize its device during resume() method call, the driver will
  6340. * set device to PCI_D3hot state in PCI config space instead of setting it
  6341. * according to the @msg provided by the PM.
  6342. *
  6343. * Return code
  6344. * 0 - driver suspended the device
  6345. * Error otherwise
  6346. **/
  6347. static int
  6348. lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
  6349. {
  6350. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6351. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6352. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6353. "0473 PCI device Power Management suspend.\n");
  6354. /* Bring down the device */
  6355. lpfc_offline_prep(phba);
  6356. lpfc_offline(phba);
  6357. kthread_stop(phba->worker_thread);
  6358. /* Disable interrupt from device */
  6359. lpfc_sli_disable_intr(phba);
  6360. /* Save device state to PCI config space */
  6361. pci_save_state(pdev);
  6362. pci_set_power_state(pdev, PCI_D3hot);
  6363. return 0;
  6364. }
  6365. /**
  6366. * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
  6367. * @pdev: pointer to PCI device
  6368. *
  6369. * This routine is to be called from the kernel's PCI subsystem to support
  6370. * system Power Management (PM) to device with SLI-3 interface spec. When PM
  6371. * invokes this method, it restores the device's PCI config space state and
  6372. * fully reinitializes the device and brings it online. Note that as the
  6373. * driver implements the minimum PM requirements to a power-aware driver's
  6374. * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
  6375. * FREEZE) to the suspend() method call will be treated as SUSPEND and the
  6376. * driver will fully reinitialize its device during resume() method call,
  6377. * the device will be set to PCI_D0 directly in PCI config space before
  6378. * restoring the state.
  6379. *
  6380. * Return code
  6381. * 0 - driver suspended the device
  6382. * Error otherwise
  6383. **/
  6384. static int
  6385. lpfc_pci_resume_one_s3(struct pci_dev *pdev)
  6386. {
  6387. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6388. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6389. uint32_t intr_mode;
  6390. int error;
  6391. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6392. "0452 PCI device Power Management resume.\n");
  6393. /* Restore device state from PCI config space */
  6394. pci_set_power_state(pdev, PCI_D0);
  6395. pci_restore_state(pdev);
  6396. if (pdev->is_busmaster)
  6397. pci_set_master(pdev);
  6398. /* Startup the kernel thread for this host adapter. */
  6399. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  6400. "lpfc_worker_%d", phba->brd_no);
  6401. if (IS_ERR(phba->worker_thread)) {
  6402. error = PTR_ERR(phba->worker_thread);
  6403. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6404. "0434 PM resume failed to start worker "
  6405. "thread: error=x%x.\n", error);
  6406. return error;
  6407. }
  6408. /* Configure and enable interrupt */
  6409. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  6410. if (intr_mode == LPFC_INTR_ERROR) {
  6411. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6412. "0430 PM resume Failed to enable interrupt\n");
  6413. return -EIO;
  6414. } else
  6415. phba->intr_mode = intr_mode;
  6416. /* Restart HBA and bring it online */
  6417. lpfc_sli_brdrestart(phba);
  6418. lpfc_online(phba);
  6419. /* Log the current active interrupt mode */
  6420. lpfc_log_intr_mode(phba, phba->intr_mode);
  6421. return 0;
  6422. }
  6423. /**
  6424. * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
  6425. * @phba: pointer to lpfc hba data structure.
  6426. *
  6427. * This routine is called to prepare the SLI3 device for PCI slot reset. It
  6428. * disables the device interrupt and pci device, and aborts the internal FCP
  6429. * pending I/Os.
  6430. **/
  6431. static void
  6432. lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
  6433. {
  6434. struct lpfc_sli *psli = &phba->sli;
  6435. struct lpfc_sli_ring *pring;
  6436. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6437. "2710 PCI channel I/O frozen\n");
  6438. /* Disable interrupt and pci device */
  6439. lpfc_sli_disable_intr(phba);
  6440. pci_disable_device(phba->pcidev);
  6441. /*
  6442. * There may be I/Os dropped by the firmware.
  6443. * Error iocb (I/O) on txcmplq and let the SCSI layer
  6444. * retry it after re-establishing link.
  6445. */
  6446. pring = &psli->ring[psli->fcp_ring];
  6447. lpfc_sli_abort_iocb_ring(phba, pring);
  6448. }
  6449. /**
  6450. * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
  6451. * @phba: pointer to lpfc hba data structure.
  6452. *
  6453. * This routine is called to prepare the SLI3 device for PCI slot permanently
  6454. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  6455. * pending I/Os.
  6456. **/
  6457. static void
  6458. lpfc_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  6459. {
  6460. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6461. "2711 PCI channel I/O permanent failure\n");
  6462. /* Block all SCSI devices' I/Os on the host */
  6463. lpfc_scsi_dev_block(phba);
  6464. /* Clean up all driver's outstanding SCSI I/Os */
  6465. lpfc_sli_flush_fcp_rings(phba);
  6466. }
  6467. /**
  6468. * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
  6469. * @pdev: pointer to PCI device.
  6470. * @state: the current PCI connection state.
  6471. *
  6472. * This routine is called from the PCI subsystem for I/O error handling to
  6473. * device with SLI-3 interface spec. This function is called by the PCI
  6474. * subsystem after a PCI bus error affecting this device has been detected.
  6475. * When this function is invoked, it will need to stop all the I/Os and
  6476. * interrupt(s) to the device. Once that is done, it will return
  6477. * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
  6478. * as desired.
  6479. *
  6480. * Return codes
  6481. * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
  6482. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  6483. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  6484. **/
  6485. static pci_ers_result_t
  6486. lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
  6487. {
  6488. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6489. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6490. switch (state) {
  6491. case pci_channel_io_normal:
  6492. /* Non-fatal error, do nothing */
  6493. return PCI_ERS_RESULT_CAN_RECOVER;
  6494. case pci_channel_io_frozen:
  6495. /* Fatal error, prepare for slot reset */
  6496. lpfc_sli_prep_dev_for_reset(phba);
  6497. return PCI_ERS_RESULT_NEED_RESET;
  6498. case pci_channel_io_perm_failure:
  6499. /* Permanent failure, prepare for device down */
  6500. lpfc_prep_dev_for_perm_failure(phba);
  6501. return PCI_ERS_RESULT_DISCONNECT;
  6502. default:
  6503. /* Unknown state, prepare and request slot reset */
  6504. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6505. "0472 Unknown PCI error state: x%x\n", state);
  6506. lpfc_sli_prep_dev_for_reset(phba);
  6507. return PCI_ERS_RESULT_NEED_RESET;
  6508. }
  6509. }
  6510. /**
  6511. * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
  6512. * @pdev: pointer to PCI device.
  6513. *
  6514. * This routine is called from the PCI subsystem for error handling to
  6515. * device with SLI-3 interface spec. This is called after PCI bus has been
  6516. * reset to restart the PCI card from scratch, as if from a cold-boot.
  6517. * During the PCI subsystem error recovery, after driver returns
  6518. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  6519. * recovery and then call this routine before calling the .resume method
  6520. * to recover the device. This function will initialize the HBA device,
  6521. * enable the interrupt, but it will just put the HBA to offline state
  6522. * without passing any I/O traffic.
  6523. *
  6524. * Return codes
  6525. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  6526. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  6527. */
  6528. static pci_ers_result_t
  6529. lpfc_io_slot_reset_s3(struct pci_dev *pdev)
  6530. {
  6531. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6532. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6533. struct lpfc_sli *psli = &phba->sli;
  6534. uint32_t intr_mode;
  6535. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  6536. if (pci_enable_device_mem(pdev)) {
  6537. printk(KERN_ERR "lpfc: Cannot re-enable "
  6538. "PCI device after reset.\n");
  6539. return PCI_ERS_RESULT_DISCONNECT;
  6540. }
  6541. pci_restore_state(pdev);
  6542. if (pdev->is_busmaster)
  6543. pci_set_master(pdev);
  6544. spin_lock_irq(&phba->hbalock);
  6545. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  6546. spin_unlock_irq(&phba->hbalock);
  6547. /* Configure and enable interrupt */
  6548. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  6549. if (intr_mode == LPFC_INTR_ERROR) {
  6550. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6551. "0427 Cannot re-enable interrupt after "
  6552. "slot reset.\n");
  6553. return PCI_ERS_RESULT_DISCONNECT;
  6554. } else
  6555. phba->intr_mode = intr_mode;
  6556. /* Take device offline; this will perform cleanup */
  6557. lpfc_offline(phba);
  6558. lpfc_sli_brdrestart(phba);
  6559. /* Log the current active interrupt mode */
  6560. lpfc_log_intr_mode(phba, phba->intr_mode);
  6561. return PCI_ERS_RESULT_RECOVERED;
  6562. }
  6563. /**
  6564. * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
  6565. * @pdev: pointer to PCI device
  6566. *
  6567. * This routine is called from the PCI subsystem for error handling to device
  6568. * with SLI-3 interface spec. It is called when kernel error recovery tells
  6569. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  6570. * error recovery. After this call, traffic can start to flow from this device
  6571. * again.
  6572. */
  6573. static void
  6574. lpfc_io_resume_s3(struct pci_dev *pdev)
  6575. {
  6576. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6577. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6578. /* Bring the device online */
  6579. lpfc_online(phba);
  6580. /* Clean up Advanced Error Reporting (AER) if needed */
  6581. if (phba->hba_flag & HBA_AER_ENABLED)
  6582. pci_cleanup_aer_uncorrect_error_status(pdev);
  6583. }
  6584. /**
  6585. * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
  6586. * @phba: pointer to lpfc hba data structure.
  6587. *
  6588. * returns the number of ELS/CT IOCBs to reserve
  6589. **/
  6590. int
  6591. lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
  6592. {
  6593. int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
  6594. if (phba->sli_rev == LPFC_SLI_REV4) {
  6595. if (max_xri <= 100)
  6596. return 10;
  6597. else if (max_xri <= 256)
  6598. return 25;
  6599. else if (max_xri <= 512)
  6600. return 50;
  6601. else if (max_xri <= 1024)
  6602. return 100;
  6603. else
  6604. return 150;
  6605. } else
  6606. return 0;
  6607. }
  6608. /**
  6609. * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
  6610. * @pdev: pointer to PCI device
  6611. * @pid: pointer to PCI device identifier
  6612. *
  6613. * This routine is called from the kernel's PCI subsystem to device with
  6614. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  6615. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  6616. * information of the device and driver to see if the driver state that it
  6617. * can support this kind of device. If the match is successful, the driver
  6618. * core invokes this routine. If this routine determines it can claim the HBA,
  6619. * it does all the initialization that it needs to do to handle the HBA
  6620. * properly.
  6621. *
  6622. * Return code
  6623. * 0 - driver can claim the device
  6624. * negative value - driver can not claim the device
  6625. **/
  6626. static int __devinit
  6627. lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
  6628. {
  6629. struct lpfc_hba *phba;
  6630. struct lpfc_vport *vport = NULL;
  6631. struct Scsi_Host *shost = NULL;
  6632. int error;
  6633. uint32_t cfg_mode, intr_mode;
  6634. int mcnt;
  6635. /* Allocate memory for HBA structure */
  6636. phba = lpfc_hba_alloc(pdev);
  6637. if (!phba)
  6638. return -ENOMEM;
  6639. /* Perform generic PCI device enabling operation */
  6640. error = lpfc_enable_pci_dev(phba);
  6641. if (error) {
  6642. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6643. "1409 Failed to enable pci device.\n");
  6644. goto out_free_phba;
  6645. }
  6646. /* Set up SLI API function jump table for PCI-device group-1 HBAs */
  6647. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
  6648. if (error)
  6649. goto out_disable_pci_dev;
  6650. /* Set up SLI-4 specific device PCI memory space */
  6651. error = lpfc_sli4_pci_mem_setup(phba);
  6652. if (error) {
  6653. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6654. "1410 Failed to set up pci memory space.\n");
  6655. goto out_disable_pci_dev;
  6656. }
  6657. /* Set up phase-1 common device driver resources */
  6658. error = lpfc_setup_driver_resource_phase1(phba);
  6659. if (error) {
  6660. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6661. "1411 Failed to set up driver resource.\n");
  6662. goto out_unset_pci_mem_s4;
  6663. }
  6664. /* Set up SLI-4 Specific device driver resources */
  6665. error = lpfc_sli4_driver_resource_setup(phba);
  6666. if (error) {
  6667. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6668. "1412 Failed to set up driver resource.\n");
  6669. goto out_unset_pci_mem_s4;
  6670. }
  6671. /* Initialize and populate the iocb list per host */
  6672. error = lpfc_init_iocb_list(phba,
  6673. phba->sli4_hba.max_cfg_param.max_xri);
  6674. if (error) {
  6675. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6676. "1413 Failed to initialize iocb list.\n");
  6677. goto out_unset_driver_resource_s4;
  6678. }
  6679. /* Set up common device driver resources */
  6680. error = lpfc_setup_driver_resource_phase2(phba);
  6681. if (error) {
  6682. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6683. "1414 Failed to set up driver resource.\n");
  6684. goto out_free_iocb_list;
  6685. }
  6686. /* Create SCSI host to the physical port */
  6687. error = lpfc_create_shost(phba);
  6688. if (error) {
  6689. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6690. "1415 Failed to create scsi host.\n");
  6691. goto out_unset_driver_resource;
  6692. }
  6693. /* Configure sysfs attributes */
  6694. vport = phba->pport;
  6695. error = lpfc_alloc_sysfs_attr(vport);
  6696. if (error) {
  6697. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6698. "1416 Failed to allocate sysfs attr\n");
  6699. goto out_destroy_shost;
  6700. }
  6701. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  6702. /* Now, trying to enable interrupt and bring up the device */
  6703. cfg_mode = phba->cfg_use_msi;
  6704. while (true) {
  6705. /* Put device to a known state before enabling interrupt */
  6706. lpfc_stop_port(phba);
  6707. /* Configure and enable interrupt */
  6708. intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
  6709. if (intr_mode == LPFC_INTR_ERROR) {
  6710. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6711. "0426 Failed to enable interrupt.\n");
  6712. error = -ENODEV;
  6713. goto out_free_sysfs_attr;
  6714. }
  6715. /* Set up SLI-4 HBA */
  6716. if (lpfc_sli4_hba_setup(phba)) {
  6717. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6718. "1421 Failed to set up hba\n");
  6719. error = -ENODEV;
  6720. goto out_disable_intr;
  6721. }
  6722. /* Send NOP mbx cmds for non-INTx mode active interrupt test */
  6723. if (intr_mode != 0)
  6724. mcnt = lpfc_sli4_send_nop_mbox_cmds(phba,
  6725. LPFC_ACT_INTR_CNT);
  6726. /* Check active interrupts received only for MSI/MSI-X */
  6727. if (intr_mode == 0 ||
  6728. phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) {
  6729. /* Log the current active interrupt mode */
  6730. phba->intr_mode = intr_mode;
  6731. lpfc_log_intr_mode(phba, intr_mode);
  6732. break;
  6733. }
  6734. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6735. "0451 Configure interrupt mode (%d) "
  6736. "failed active interrupt test.\n",
  6737. intr_mode);
  6738. /* Unset the preivous SLI-4 HBA setup */
  6739. lpfc_sli4_unset_hba(phba);
  6740. /* Try next level of interrupt mode */
  6741. cfg_mode = --intr_mode;
  6742. }
  6743. /* Perform post initialization setup */
  6744. lpfc_post_init_setup(phba);
  6745. /* Check if there are static vports to be created. */
  6746. lpfc_create_static_vport(phba);
  6747. return 0;
  6748. out_disable_intr:
  6749. lpfc_sli4_disable_intr(phba);
  6750. out_free_sysfs_attr:
  6751. lpfc_free_sysfs_attr(vport);
  6752. out_destroy_shost:
  6753. lpfc_destroy_shost(phba);
  6754. out_unset_driver_resource:
  6755. lpfc_unset_driver_resource_phase2(phba);
  6756. out_free_iocb_list:
  6757. lpfc_free_iocb_list(phba);
  6758. out_unset_driver_resource_s4:
  6759. lpfc_sli4_driver_resource_unset(phba);
  6760. out_unset_pci_mem_s4:
  6761. lpfc_sli4_pci_mem_unset(phba);
  6762. out_disable_pci_dev:
  6763. lpfc_disable_pci_dev(phba);
  6764. if (shost)
  6765. scsi_host_put(shost);
  6766. out_free_phba:
  6767. lpfc_hba_free(phba);
  6768. return error;
  6769. }
  6770. /**
  6771. * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
  6772. * @pdev: pointer to PCI device
  6773. *
  6774. * This routine is called from the kernel's PCI subsystem to device with
  6775. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  6776. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  6777. * device to be removed from the PCI subsystem properly.
  6778. **/
  6779. static void __devexit
  6780. lpfc_pci_remove_one_s4(struct pci_dev *pdev)
  6781. {
  6782. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6783. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  6784. struct lpfc_vport **vports;
  6785. struct lpfc_hba *phba = vport->phba;
  6786. int i;
  6787. /* Mark the device unloading flag */
  6788. spin_lock_irq(&phba->hbalock);
  6789. vport->load_flag |= FC_UNLOADING;
  6790. spin_unlock_irq(&phba->hbalock);
  6791. /* Free the HBA sysfs attributes */
  6792. lpfc_free_sysfs_attr(vport);
  6793. /* Release all the vports against this physical port */
  6794. vports = lpfc_create_vport_work_array(phba);
  6795. if (vports != NULL)
  6796. for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
  6797. fc_vport_terminate(vports[i]->fc_vport);
  6798. lpfc_destroy_vport_work_array(phba, vports);
  6799. /* Remove FC host and then SCSI host with the physical port */
  6800. fc_remove_host(shost);
  6801. scsi_remove_host(shost);
  6802. /* Perform cleanup on the physical port */
  6803. lpfc_cleanup(vport);
  6804. /*
  6805. * Bring down the SLI Layer. This step disables all interrupts,
  6806. * clears the rings, discards all mailbox commands, and resets
  6807. * the HBA FCoE function.
  6808. */
  6809. lpfc_debugfs_terminate(vport);
  6810. lpfc_sli4_hba_unset(phba);
  6811. spin_lock_irq(&phba->hbalock);
  6812. list_del_init(&vport->listentry);
  6813. spin_unlock_irq(&phba->hbalock);
  6814. /* Call scsi_free before lpfc_sli4_driver_resource_unset since scsi
  6815. * buffers are released to their corresponding pools here.
  6816. */
  6817. lpfc_scsi_free(phba);
  6818. lpfc_sli4_driver_resource_unset(phba);
  6819. /* Unmap adapter Control and Doorbell registers */
  6820. lpfc_sli4_pci_mem_unset(phba);
  6821. /* Release PCI resources and disable device's PCI function */
  6822. scsi_host_put(shost);
  6823. lpfc_disable_pci_dev(phba);
  6824. /* Finally, free the driver's device data structure */
  6825. lpfc_hba_free(phba);
  6826. return;
  6827. }
  6828. /**
  6829. * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
  6830. * @pdev: pointer to PCI device
  6831. * @msg: power management message
  6832. *
  6833. * This routine is called from the kernel's PCI subsystem to support system
  6834. * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
  6835. * this method, it quiesces the device by stopping the driver's worker
  6836. * thread for the device, turning off device's interrupt and DMA, and bring
  6837. * the device offline. Note that as the driver implements the minimum PM
  6838. * requirements to a power-aware driver's PM support for suspend/resume -- all
  6839. * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
  6840. * method call will be treated as SUSPEND and the driver will fully
  6841. * reinitialize its device during resume() method call, the driver will set
  6842. * device to PCI_D3hot state in PCI config space instead of setting it
  6843. * according to the @msg provided by the PM.
  6844. *
  6845. * Return code
  6846. * 0 - driver suspended the device
  6847. * Error otherwise
  6848. **/
  6849. static int
  6850. lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
  6851. {
  6852. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6853. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6854. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6855. "0298 PCI device Power Management suspend.\n");
  6856. /* Bring down the device */
  6857. lpfc_offline_prep(phba);
  6858. lpfc_offline(phba);
  6859. kthread_stop(phba->worker_thread);
  6860. /* Disable interrupt from device */
  6861. lpfc_sli4_disable_intr(phba);
  6862. /* Save device state to PCI config space */
  6863. pci_save_state(pdev);
  6864. pci_set_power_state(pdev, PCI_D3hot);
  6865. return 0;
  6866. }
  6867. /**
  6868. * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
  6869. * @pdev: pointer to PCI device
  6870. *
  6871. * This routine is called from the kernel's PCI subsystem to support system
  6872. * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
  6873. * this method, it restores the device's PCI config space state and fully
  6874. * reinitializes the device and brings it online. Note that as the driver
  6875. * implements the minimum PM requirements to a power-aware driver's PM for
  6876. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  6877. * to the suspend() method call will be treated as SUSPEND and the driver
  6878. * will fully reinitialize its device during resume() method call, the device
  6879. * will be set to PCI_D0 directly in PCI config space before restoring the
  6880. * state.
  6881. *
  6882. * Return code
  6883. * 0 - driver suspended the device
  6884. * Error otherwise
  6885. **/
  6886. static int
  6887. lpfc_pci_resume_one_s4(struct pci_dev *pdev)
  6888. {
  6889. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6890. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6891. uint32_t intr_mode;
  6892. int error;
  6893. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6894. "0292 PCI device Power Management resume.\n");
  6895. /* Restore device state from PCI config space */
  6896. pci_set_power_state(pdev, PCI_D0);
  6897. pci_restore_state(pdev);
  6898. if (pdev->is_busmaster)
  6899. pci_set_master(pdev);
  6900. /* Startup the kernel thread for this host adapter. */
  6901. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  6902. "lpfc_worker_%d", phba->brd_no);
  6903. if (IS_ERR(phba->worker_thread)) {
  6904. error = PTR_ERR(phba->worker_thread);
  6905. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6906. "0293 PM resume failed to start worker "
  6907. "thread: error=x%x.\n", error);
  6908. return error;
  6909. }
  6910. /* Configure and enable interrupt */
  6911. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  6912. if (intr_mode == LPFC_INTR_ERROR) {
  6913. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6914. "0294 PM resume Failed to enable interrupt\n");
  6915. return -EIO;
  6916. } else
  6917. phba->intr_mode = intr_mode;
  6918. /* Restart HBA and bring it online */
  6919. lpfc_sli_brdrestart(phba);
  6920. lpfc_online(phba);
  6921. /* Log the current active interrupt mode */
  6922. lpfc_log_intr_mode(phba, phba->intr_mode);
  6923. return 0;
  6924. }
  6925. /**
  6926. * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
  6927. * @pdev: pointer to PCI device.
  6928. * @state: the current PCI connection state.
  6929. *
  6930. * This routine is called from the PCI subsystem for error handling to device
  6931. * with SLI-4 interface spec. This function is called by the PCI subsystem
  6932. * after a PCI bus error affecting this device has been detected. When this
  6933. * function is invoked, it will need to stop all the I/Os and interrupt(s)
  6934. * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
  6935. * for the PCI subsystem to perform proper recovery as desired.
  6936. *
  6937. * Return codes
  6938. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  6939. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  6940. **/
  6941. static pci_ers_result_t
  6942. lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
  6943. {
  6944. return PCI_ERS_RESULT_NEED_RESET;
  6945. }
  6946. /**
  6947. * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
  6948. * @pdev: pointer to PCI device.
  6949. *
  6950. * This routine is called from the PCI subsystem for error handling to device
  6951. * with SLI-4 interface spec. It is called after PCI bus has been reset to
  6952. * restart the PCI card from scratch, as if from a cold-boot. During the
  6953. * PCI subsystem error recovery, after the driver returns
  6954. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  6955. * recovery and then call this routine before calling the .resume method to
  6956. * recover the device. This function will initialize the HBA device, enable
  6957. * the interrupt, but it will just put the HBA to offline state without
  6958. * passing any I/O traffic.
  6959. *
  6960. * Return codes
  6961. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  6962. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  6963. */
  6964. static pci_ers_result_t
  6965. lpfc_io_slot_reset_s4(struct pci_dev *pdev)
  6966. {
  6967. return PCI_ERS_RESULT_RECOVERED;
  6968. }
  6969. /**
  6970. * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
  6971. * @pdev: pointer to PCI device
  6972. *
  6973. * This routine is called from the PCI subsystem for error handling to device
  6974. * with SLI-4 interface spec. It is called when kernel error recovery tells
  6975. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  6976. * error recovery. After this call, traffic can start to flow from this device
  6977. * again.
  6978. **/
  6979. static void
  6980. lpfc_io_resume_s4(struct pci_dev *pdev)
  6981. {
  6982. return;
  6983. }
  6984. /**
  6985. * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
  6986. * @pdev: pointer to PCI device
  6987. * @pid: pointer to PCI device identifier
  6988. *
  6989. * This routine is to be registered to the kernel's PCI subsystem. When an
  6990. * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
  6991. * at PCI device-specific information of the device and driver to see if the
  6992. * driver state that it can support this kind of device. If the match is
  6993. * successful, the driver core invokes this routine. This routine dispatches
  6994. * the action to the proper SLI-3 or SLI-4 device probing routine, which will
  6995. * do all the initialization that it needs to do to handle the HBA device
  6996. * properly.
  6997. *
  6998. * Return code
  6999. * 0 - driver can claim the device
  7000. * negative value - driver can not claim the device
  7001. **/
  7002. static int __devinit
  7003. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  7004. {
  7005. int rc;
  7006. struct lpfc_sli_intf intf;
  7007. if (pci_read_config_dword(pdev, LPFC_SLIREV_CONF_WORD, &intf.word0))
  7008. return -ENODEV;
  7009. if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
  7010. (bf_get(lpfc_sli_intf_rev, &intf) == LPFC_SLIREV_CONF_SLI4))
  7011. rc = lpfc_pci_probe_one_s4(pdev, pid);
  7012. else
  7013. rc = lpfc_pci_probe_one_s3(pdev, pid);
  7014. return rc;
  7015. }
  7016. /**
  7017. * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
  7018. * @pdev: pointer to PCI device
  7019. *
  7020. * This routine is to be registered to the kernel's PCI subsystem. When an
  7021. * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
  7022. * This routine dispatches the action to the proper SLI-3 or SLI-4 device
  7023. * remove routine, which will perform all the necessary cleanup for the
  7024. * device to be removed from the PCI subsystem properly.
  7025. **/
  7026. static void __devexit
  7027. lpfc_pci_remove_one(struct pci_dev *pdev)
  7028. {
  7029. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7030. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7031. switch (phba->pci_dev_grp) {
  7032. case LPFC_PCI_DEV_LP:
  7033. lpfc_pci_remove_one_s3(pdev);
  7034. break;
  7035. case LPFC_PCI_DEV_OC:
  7036. lpfc_pci_remove_one_s4(pdev);
  7037. break;
  7038. default:
  7039. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7040. "1424 Invalid PCI device group: 0x%x\n",
  7041. phba->pci_dev_grp);
  7042. break;
  7043. }
  7044. return;
  7045. }
  7046. /**
  7047. * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
  7048. * @pdev: pointer to PCI device
  7049. * @msg: power management message
  7050. *
  7051. * This routine is to be registered to the kernel's PCI subsystem to support
  7052. * system Power Management (PM). When PM invokes this method, it dispatches
  7053. * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
  7054. * suspend the device.
  7055. *
  7056. * Return code
  7057. * 0 - driver suspended the device
  7058. * Error otherwise
  7059. **/
  7060. static int
  7061. lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
  7062. {
  7063. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7064. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7065. int rc = -ENODEV;
  7066. switch (phba->pci_dev_grp) {
  7067. case LPFC_PCI_DEV_LP:
  7068. rc = lpfc_pci_suspend_one_s3(pdev, msg);
  7069. break;
  7070. case LPFC_PCI_DEV_OC:
  7071. rc = lpfc_pci_suspend_one_s4(pdev, msg);
  7072. break;
  7073. default:
  7074. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7075. "1425 Invalid PCI device group: 0x%x\n",
  7076. phba->pci_dev_grp);
  7077. break;
  7078. }
  7079. return rc;
  7080. }
  7081. /**
  7082. * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
  7083. * @pdev: pointer to PCI device
  7084. *
  7085. * This routine is to be registered to the kernel's PCI subsystem to support
  7086. * system Power Management (PM). When PM invokes this method, it dispatches
  7087. * the action to the proper SLI-3 or SLI-4 device resume routine, which will
  7088. * resume the device.
  7089. *
  7090. * Return code
  7091. * 0 - driver suspended the device
  7092. * Error otherwise
  7093. **/
  7094. static int
  7095. lpfc_pci_resume_one(struct pci_dev *pdev)
  7096. {
  7097. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7098. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7099. int rc = -ENODEV;
  7100. switch (phba->pci_dev_grp) {
  7101. case LPFC_PCI_DEV_LP:
  7102. rc = lpfc_pci_resume_one_s3(pdev);
  7103. break;
  7104. case LPFC_PCI_DEV_OC:
  7105. rc = lpfc_pci_resume_one_s4(pdev);
  7106. break;
  7107. default:
  7108. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7109. "1426 Invalid PCI device group: 0x%x\n",
  7110. phba->pci_dev_grp);
  7111. break;
  7112. }
  7113. return rc;
  7114. }
  7115. /**
  7116. * lpfc_io_error_detected - lpfc method for handling PCI I/O error
  7117. * @pdev: pointer to PCI device.
  7118. * @state: the current PCI connection state.
  7119. *
  7120. * This routine is registered to the PCI subsystem for error handling. This
  7121. * function is called by the PCI subsystem after a PCI bus error affecting
  7122. * this device has been detected. When this routine is invoked, it dispatches
  7123. * the action to the proper SLI-3 or SLI-4 device error detected handling
  7124. * routine, which will perform the proper error detected operation.
  7125. *
  7126. * Return codes
  7127. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  7128. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7129. **/
  7130. static pci_ers_result_t
  7131. lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  7132. {
  7133. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7134. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7135. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  7136. switch (phba->pci_dev_grp) {
  7137. case LPFC_PCI_DEV_LP:
  7138. rc = lpfc_io_error_detected_s3(pdev, state);
  7139. break;
  7140. case LPFC_PCI_DEV_OC:
  7141. rc = lpfc_io_error_detected_s4(pdev, state);
  7142. break;
  7143. default:
  7144. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7145. "1427 Invalid PCI device group: 0x%x\n",
  7146. phba->pci_dev_grp);
  7147. break;
  7148. }
  7149. return rc;
  7150. }
  7151. /**
  7152. * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
  7153. * @pdev: pointer to PCI device.
  7154. *
  7155. * This routine is registered to the PCI subsystem for error handling. This
  7156. * function is called after PCI bus has been reset to restart the PCI card
  7157. * from scratch, as if from a cold-boot. When this routine is invoked, it
  7158. * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
  7159. * routine, which will perform the proper device reset.
  7160. *
  7161. * Return codes
  7162. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  7163. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7164. **/
  7165. static pci_ers_result_t
  7166. lpfc_io_slot_reset(struct pci_dev *pdev)
  7167. {
  7168. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7169. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7170. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  7171. switch (phba->pci_dev_grp) {
  7172. case LPFC_PCI_DEV_LP:
  7173. rc = lpfc_io_slot_reset_s3(pdev);
  7174. break;
  7175. case LPFC_PCI_DEV_OC:
  7176. rc = lpfc_io_slot_reset_s4(pdev);
  7177. break;
  7178. default:
  7179. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7180. "1428 Invalid PCI device group: 0x%x\n",
  7181. phba->pci_dev_grp);
  7182. break;
  7183. }
  7184. return rc;
  7185. }
  7186. /**
  7187. * lpfc_io_resume - lpfc method for resuming PCI I/O operation
  7188. * @pdev: pointer to PCI device
  7189. *
  7190. * This routine is registered to the PCI subsystem for error handling. It
  7191. * is called when kernel error recovery tells the lpfc driver that it is
  7192. * OK to resume normal PCI operation after PCI bus error recovery. When
  7193. * this routine is invoked, it dispatches the action to the proper SLI-3
  7194. * or SLI-4 device io_resume routine, which will resume the device operation.
  7195. **/
  7196. static void
  7197. lpfc_io_resume(struct pci_dev *pdev)
  7198. {
  7199. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7200. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7201. switch (phba->pci_dev_grp) {
  7202. case LPFC_PCI_DEV_LP:
  7203. lpfc_io_resume_s3(pdev);
  7204. break;
  7205. case LPFC_PCI_DEV_OC:
  7206. lpfc_io_resume_s4(pdev);
  7207. break;
  7208. default:
  7209. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7210. "1429 Invalid PCI device group: 0x%x\n",
  7211. phba->pci_dev_grp);
  7212. break;
  7213. }
  7214. return;
  7215. }
  7216. static struct pci_device_id lpfc_id_table[] = {
  7217. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  7218. PCI_ANY_ID, PCI_ANY_ID, },
  7219. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  7220. PCI_ANY_ID, PCI_ANY_ID, },
  7221. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  7222. PCI_ANY_ID, PCI_ANY_ID, },
  7223. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  7224. PCI_ANY_ID, PCI_ANY_ID, },
  7225. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  7226. PCI_ANY_ID, PCI_ANY_ID, },
  7227. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  7228. PCI_ANY_ID, PCI_ANY_ID, },
  7229. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  7230. PCI_ANY_ID, PCI_ANY_ID, },
  7231. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  7232. PCI_ANY_ID, PCI_ANY_ID, },
  7233. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  7234. PCI_ANY_ID, PCI_ANY_ID, },
  7235. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  7236. PCI_ANY_ID, PCI_ANY_ID, },
  7237. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  7238. PCI_ANY_ID, PCI_ANY_ID, },
  7239. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  7240. PCI_ANY_ID, PCI_ANY_ID, },
  7241. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  7242. PCI_ANY_ID, PCI_ANY_ID, },
  7243. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  7244. PCI_ANY_ID, PCI_ANY_ID, },
  7245. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  7246. PCI_ANY_ID, PCI_ANY_ID, },
  7247. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  7248. PCI_ANY_ID, PCI_ANY_ID, },
  7249. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  7250. PCI_ANY_ID, PCI_ANY_ID, },
  7251. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  7252. PCI_ANY_ID, PCI_ANY_ID, },
  7253. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
  7254. PCI_ANY_ID, PCI_ANY_ID, },
  7255. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  7256. PCI_ANY_ID, PCI_ANY_ID, },
  7257. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  7258. PCI_ANY_ID, PCI_ANY_ID, },
  7259. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  7260. PCI_ANY_ID, PCI_ANY_ID, },
  7261. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  7262. PCI_ANY_ID, PCI_ANY_ID, },
  7263. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  7264. PCI_ANY_ID, PCI_ANY_ID, },
  7265. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  7266. PCI_ANY_ID, PCI_ANY_ID, },
  7267. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  7268. PCI_ANY_ID, PCI_ANY_ID, },
  7269. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  7270. PCI_ANY_ID, PCI_ANY_ID, },
  7271. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  7272. PCI_ANY_ID, PCI_ANY_ID, },
  7273. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  7274. PCI_ANY_ID, PCI_ANY_ID, },
  7275. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  7276. PCI_ANY_ID, PCI_ANY_ID, },
  7277. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  7278. PCI_ANY_ID, PCI_ANY_ID, },
  7279. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  7280. PCI_ANY_ID, PCI_ANY_ID, },
  7281. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  7282. PCI_ANY_ID, PCI_ANY_ID, },
  7283. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  7284. PCI_ANY_ID, PCI_ANY_ID, },
  7285. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
  7286. PCI_ANY_ID, PCI_ANY_ID, },
  7287. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
  7288. PCI_ANY_ID, PCI_ANY_ID, },
  7289. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
  7290. PCI_ANY_ID, PCI_ANY_ID, },
  7291. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
  7292. PCI_ANY_ID, PCI_ANY_ID, },
  7293. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TS_BE3,
  7294. PCI_ANY_ID, PCI_ANY_ID, },
  7295. { 0 }
  7296. };
  7297. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  7298. static struct pci_error_handlers lpfc_err_handler = {
  7299. .error_detected = lpfc_io_error_detected,
  7300. .slot_reset = lpfc_io_slot_reset,
  7301. .resume = lpfc_io_resume,
  7302. };
  7303. static struct pci_driver lpfc_driver = {
  7304. .name = LPFC_DRIVER_NAME,
  7305. .id_table = lpfc_id_table,
  7306. .probe = lpfc_pci_probe_one,
  7307. .remove = __devexit_p(lpfc_pci_remove_one),
  7308. .suspend = lpfc_pci_suspend_one,
  7309. .resume = lpfc_pci_resume_one,
  7310. .err_handler = &lpfc_err_handler,
  7311. };
  7312. /**
  7313. * lpfc_init - lpfc module initialization routine
  7314. *
  7315. * This routine is to be invoked when the lpfc module is loaded into the
  7316. * kernel. The special kernel macro module_init() is used to indicate the
  7317. * role of this routine to the kernel as lpfc module entry point.
  7318. *
  7319. * Return codes
  7320. * 0 - successful
  7321. * -ENOMEM - FC attach transport failed
  7322. * all others - failed
  7323. */
  7324. static int __init
  7325. lpfc_init(void)
  7326. {
  7327. int error = 0;
  7328. printk(LPFC_MODULE_DESC "\n");
  7329. printk(LPFC_COPYRIGHT "\n");
  7330. if (lpfc_enable_npiv) {
  7331. lpfc_transport_functions.vport_create = lpfc_vport_create;
  7332. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  7333. }
  7334. lpfc_transport_template =
  7335. fc_attach_transport(&lpfc_transport_functions);
  7336. if (lpfc_transport_template == NULL)
  7337. return -ENOMEM;
  7338. if (lpfc_enable_npiv) {
  7339. lpfc_vport_transport_template =
  7340. fc_attach_transport(&lpfc_vport_transport_functions);
  7341. if (lpfc_vport_transport_template == NULL) {
  7342. fc_release_transport(lpfc_transport_template);
  7343. return -ENOMEM;
  7344. }
  7345. }
  7346. error = pci_register_driver(&lpfc_driver);
  7347. if (error) {
  7348. fc_release_transport(lpfc_transport_template);
  7349. if (lpfc_enable_npiv)
  7350. fc_release_transport(lpfc_vport_transport_template);
  7351. }
  7352. return error;
  7353. }
  7354. /**
  7355. * lpfc_exit - lpfc module removal routine
  7356. *
  7357. * This routine is invoked when the lpfc module is removed from the kernel.
  7358. * The special kernel macro module_exit() is used to indicate the role of
  7359. * this routine to the kernel as lpfc module exit point.
  7360. */
  7361. static void __exit
  7362. lpfc_exit(void)
  7363. {
  7364. pci_unregister_driver(&lpfc_driver);
  7365. fc_release_transport(lpfc_transport_template);
  7366. if (lpfc_enable_npiv)
  7367. fc_release_transport(lpfc_vport_transport_template);
  7368. if (_dump_buf_data) {
  7369. printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
  7370. "_dump_buf_data at 0x%p\n",
  7371. (1L << _dump_buf_data_order), _dump_buf_data);
  7372. free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
  7373. }
  7374. if (_dump_buf_dif) {
  7375. printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
  7376. "_dump_buf_dif at 0x%p\n",
  7377. (1L << _dump_buf_dif_order), _dump_buf_dif);
  7378. free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
  7379. }
  7380. }
  7381. module_init(lpfc_init);
  7382. module_exit(lpfc_exit);
  7383. MODULE_LICENSE("GPL");
  7384. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  7385. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  7386. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);