lpfc_init.c 261 KB

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