lpfc_init.c 235 KB

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