lpfc_init.c 256 KB

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