lpfc_init.c 270 KB

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