lpfc_init.c 249 KB

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