lpfc_init.c 236 KB

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