lpfc_init.c 305 KB

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