lpfc_init.c 300 KB

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