lpfc_init.c 303 KB

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