lpfc_init.c 261 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849
  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;
  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. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3003. "2546 New FCF found/FCF parameter modified event: "
  3004. "evt_tag:x%x, fcf_index:x%x\n",
  3005. acqe_fcoe->event_tag, acqe_fcoe->index);
  3006. spin_lock_irq(&phba->hbalock);
  3007. if ((phba->fcf.fcf_flag & FCF_SCAN_DONE) ||
  3008. (phba->hba_flag & FCF_DISC_INPROGRESS)) {
  3009. /*
  3010. * If the current FCF is in discovered state or
  3011. * FCF discovery is in progress, do nothing.
  3012. */
  3013. spin_unlock_irq(&phba->hbalock);
  3014. break;
  3015. }
  3016. if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
  3017. /*
  3018. * If fast FCF failover rescan event is pending,
  3019. * do nothing.
  3020. */
  3021. spin_unlock_irq(&phba->hbalock);
  3022. break;
  3023. }
  3024. spin_unlock_irq(&phba->hbalock);
  3025. if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
  3026. !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
  3027. /*
  3028. * During period of FCF discovery, read the FCF
  3029. * table record indexed by the event to update
  3030. * FCF round robin failover eligible FCF bmask.
  3031. */
  3032. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  3033. LOG_DISCOVERY,
  3034. "2779 Read new FCF record with "
  3035. "fcf_index:x%x for updating FCF "
  3036. "round robin failover bmask\n",
  3037. acqe_fcoe->index);
  3038. rc = lpfc_sli4_read_fcf_rec(phba, acqe_fcoe->index);
  3039. }
  3040. /* Otherwise, scan the entire FCF table and re-discover SAN */
  3041. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3042. "2770 Start FCF table scan due to new FCF "
  3043. "event: evt_tag:x%x, fcf_index:x%x\n",
  3044. acqe_fcoe->event_tag, acqe_fcoe->index);
  3045. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  3046. LPFC_FCOE_FCF_GET_FIRST);
  3047. if (rc)
  3048. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3049. "2547 Issue FCF scan read FCF mailbox "
  3050. "command failed 0x%x\n", rc);
  3051. break;
  3052. case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL:
  3053. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3054. "2548 FCF Table full count 0x%x tag 0x%x\n",
  3055. bf_get(lpfc_acqe_fcoe_fcf_count, acqe_fcoe),
  3056. acqe_fcoe->event_tag);
  3057. break;
  3058. case LPFC_FCOE_EVENT_TYPE_FCF_DEAD:
  3059. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3060. "2549 FCF disconnected from network index 0x%x"
  3061. " tag 0x%x\n", acqe_fcoe->index,
  3062. acqe_fcoe->event_tag);
  3063. /* If the event is not for currently used fcf do nothing */
  3064. if (phba->fcf.current_rec.fcf_indx != acqe_fcoe->index)
  3065. break;
  3066. /* We request port to rediscover the entire FCF table for
  3067. * a fast recovery from case that the current FCF record
  3068. * is no longer valid if we are not in the middle of FCF
  3069. * failover process already.
  3070. */
  3071. spin_lock_irq(&phba->hbalock);
  3072. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3073. spin_unlock_irq(&phba->hbalock);
  3074. /* Update FLOGI FCF failover eligible FCF bmask */
  3075. lpfc_sli4_fcf_rr_index_clear(phba, acqe_fcoe->index);
  3076. break;
  3077. }
  3078. /* Mark the fast failover process in progress */
  3079. phba->fcf.fcf_flag |= FCF_DEAD_DISC;
  3080. spin_unlock_irq(&phba->hbalock);
  3081. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3082. "2771 Start FCF fast failover process due to "
  3083. "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
  3084. "\n", acqe_fcoe->event_tag, acqe_fcoe->index);
  3085. rc = lpfc_sli4_redisc_fcf_table(phba);
  3086. if (rc) {
  3087. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3088. LOG_DISCOVERY,
  3089. "2772 Issue FCF rediscover mabilbox "
  3090. "command failed, fail through to FCF "
  3091. "dead event\n");
  3092. spin_lock_irq(&phba->hbalock);
  3093. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  3094. spin_unlock_irq(&phba->hbalock);
  3095. /*
  3096. * Last resort will fail over by treating this
  3097. * as a link down to FCF registration.
  3098. */
  3099. lpfc_sli4_fcf_dead_failthrough(phba);
  3100. } else
  3101. /* Handling fast FCF failover to a DEAD FCF event
  3102. * is considered equalivant to receiving CVL to all
  3103. * vports.
  3104. */
  3105. lpfc_sli4_perform_all_vport_cvl(phba);
  3106. break;
  3107. case LPFC_FCOE_EVENT_TYPE_CVL:
  3108. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3109. "2718 Clear Virtual Link Received for VPI 0x%x"
  3110. " tag 0x%x\n", acqe_fcoe->index, acqe_fcoe->event_tag);
  3111. vport = lpfc_find_vport_by_vpid(phba,
  3112. acqe_fcoe->index - phba->vpi_base);
  3113. ndlp = lpfc_sli4_perform_vport_cvl(vport);
  3114. if (!ndlp)
  3115. break;
  3116. active_vlink_present = 0;
  3117. vports = lpfc_create_vport_work_array(phba);
  3118. if (vports) {
  3119. for (i = 0; i <= phba->max_vports && vports[i] != NULL;
  3120. i++) {
  3121. if ((!(vports[i]->fc_flag &
  3122. FC_VPORT_CVL_RCVD)) &&
  3123. (vports[i]->port_state > LPFC_FDISC)) {
  3124. active_vlink_present = 1;
  3125. break;
  3126. }
  3127. }
  3128. lpfc_destroy_vport_work_array(phba, vports);
  3129. }
  3130. if (active_vlink_present) {
  3131. /*
  3132. * If there are other active VLinks present,
  3133. * re-instantiate the Vlink using FDISC.
  3134. */
  3135. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  3136. shost = lpfc_shost_from_vport(vport);
  3137. spin_lock_irq(shost->host_lock);
  3138. ndlp->nlp_flag |= NLP_DELAY_TMO;
  3139. spin_unlock_irq(shost->host_lock);
  3140. ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
  3141. vport->port_state = LPFC_FDISC;
  3142. } else {
  3143. /*
  3144. * Otherwise, we request port to rediscover
  3145. * the entire FCF table for a fast recovery
  3146. * from possible case that the current FCF
  3147. * is no longer valid if we are not already
  3148. * in the FCF failover process.
  3149. */
  3150. spin_lock_irq(&phba->hbalock);
  3151. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3152. spin_unlock_irq(&phba->hbalock);
  3153. break;
  3154. }
  3155. /* Mark the fast failover process in progress */
  3156. phba->fcf.fcf_flag |= FCF_ACVL_DISC;
  3157. spin_unlock_irq(&phba->hbalock);
  3158. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  3159. LOG_DISCOVERY,
  3160. "2773 Start FCF fast failover due "
  3161. "to CVL event: evt_tag:x%x\n",
  3162. acqe_fcoe->event_tag);
  3163. rc = lpfc_sli4_redisc_fcf_table(phba);
  3164. if (rc) {
  3165. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3166. LOG_DISCOVERY,
  3167. "2774 Issue FCF rediscover "
  3168. "mabilbox command failed, "
  3169. "through to CVL event\n");
  3170. spin_lock_irq(&phba->hbalock);
  3171. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  3172. spin_unlock_irq(&phba->hbalock);
  3173. /*
  3174. * Last resort will be re-try on the
  3175. * the current registered FCF entry.
  3176. */
  3177. lpfc_retry_pport_discovery(phba);
  3178. }
  3179. }
  3180. break;
  3181. default:
  3182. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3183. "0288 Unknown FCoE event type 0x%x event tag "
  3184. "0x%x\n", event_type, acqe_fcoe->event_tag);
  3185. break;
  3186. }
  3187. }
  3188. /**
  3189. * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
  3190. * @phba: pointer to lpfc hba data structure.
  3191. * @acqe_link: pointer to the async dcbx completion queue entry.
  3192. *
  3193. * This routine is to handle the SLI4 asynchronous dcbx event.
  3194. **/
  3195. static void
  3196. lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
  3197. struct lpfc_acqe_dcbx *acqe_dcbx)
  3198. {
  3199. phba->fc_eventTag = acqe_dcbx->event_tag;
  3200. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3201. "0290 The SLI4 DCBX asynchronous event is not "
  3202. "handled yet\n");
  3203. }
  3204. /**
  3205. * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
  3206. * @phba: pointer to lpfc hba data structure.
  3207. *
  3208. * This routine is invoked by the worker thread to process all the pending
  3209. * SLI4 asynchronous events.
  3210. **/
  3211. void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
  3212. {
  3213. struct lpfc_cq_event *cq_event;
  3214. /* First, declare the async event has been handled */
  3215. spin_lock_irq(&phba->hbalock);
  3216. phba->hba_flag &= ~ASYNC_EVENT;
  3217. spin_unlock_irq(&phba->hbalock);
  3218. /* Now, handle all the async events */
  3219. while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
  3220. /* Get the first event from the head of the event queue */
  3221. spin_lock_irq(&phba->hbalock);
  3222. list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
  3223. cq_event, struct lpfc_cq_event, list);
  3224. spin_unlock_irq(&phba->hbalock);
  3225. /* Process the asynchronous event */
  3226. switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
  3227. case LPFC_TRAILER_CODE_LINK:
  3228. lpfc_sli4_async_link_evt(phba,
  3229. &cq_event->cqe.acqe_link);
  3230. break;
  3231. case LPFC_TRAILER_CODE_FCOE:
  3232. lpfc_sli4_async_fcoe_evt(phba,
  3233. &cq_event->cqe.acqe_fcoe);
  3234. break;
  3235. case LPFC_TRAILER_CODE_DCBX:
  3236. lpfc_sli4_async_dcbx_evt(phba,
  3237. &cq_event->cqe.acqe_dcbx);
  3238. break;
  3239. default:
  3240. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3241. "1804 Invalid asynchrous event code: "
  3242. "x%x\n", bf_get(lpfc_trailer_code,
  3243. &cq_event->cqe.mcqe_cmpl));
  3244. break;
  3245. }
  3246. /* Free the completion event processed to the free pool */
  3247. lpfc_sli4_cq_event_release(phba, cq_event);
  3248. }
  3249. }
  3250. /**
  3251. * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
  3252. * @phba: pointer to lpfc hba data structure.
  3253. *
  3254. * This routine is invoked by the worker thread to process FCF table
  3255. * rediscovery pending completion event.
  3256. **/
  3257. void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
  3258. {
  3259. int rc;
  3260. spin_lock_irq(&phba->hbalock);
  3261. /* Clear FCF rediscovery timeout event */
  3262. phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
  3263. /* Clear driver fast failover FCF record flag */
  3264. phba->fcf.failover_rec.flag = 0;
  3265. /* Set state for FCF fast failover */
  3266. phba->fcf.fcf_flag |= FCF_REDISC_FOV;
  3267. spin_unlock_irq(&phba->hbalock);
  3268. /* Scan FCF table from the first entry to re-discover SAN */
  3269. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3270. "2777 Start FCF table scan after FCF "
  3271. "rediscovery quiescent period over\n");
  3272. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
  3273. if (rc)
  3274. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3275. "2747 Issue FCF scan read FCF mailbox "
  3276. "command failed 0x%x\n", rc);
  3277. }
  3278. /**
  3279. * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
  3280. * @phba: pointer to lpfc hba data structure.
  3281. * @dev_grp: The HBA PCI-Device group number.
  3282. *
  3283. * This routine is invoked to set up the per HBA PCI-Device group function
  3284. * API jump table entries.
  3285. *
  3286. * Return: 0 if success, otherwise -ENODEV
  3287. **/
  3288. int
  3289. lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  3290. {
  3291. int rc;
  3292. /* Set up lpfc PCI-device group */
  3293. phba->pci_dev_grp = dev_grp;
  3294. /* The LPFC_PCI_DEV_OC uses SLI4 */
  3295. if (dev_grp == LPFC_PCI_DEV_OC)
  3296. phba->sli_rev = LPFC_SLI_REV4;
  3297. /* Set up device INIT API function jump table */
  3298. rc = lpfc_init_api_table_setup(phba, dev_grp);
  3299. if (rc)
  3300. return -ENODEV;
  3301. /* Set up SCSI API function jump table */
  3302. rc = lpfc_scsi_api_table_setup(phba, dev_grp);
  3303. if (rc)
  3304. return -ENODEV;
  3305. /* Set up SLI API function jump table */
  3306. rc = lpfc_sli_api_table_setup(phba, dev_grp);
  3307. if (rc)
  3308. return -ENODEV;
  3309. /* Set up MBOX API function jump table */
  3310. rc = lpfc_mbox_api_table_setup(phba, dev_grp);
  3311. if (rc)
  3312. return -ENODEV;
  3313. return 0;
  3314. }
  3315. /**
  3316. * lpfc_log_intr_mode - Log the active interrupt mode
  3317. * @phba: pointer to lpfc hba data structure.
  3318. * @intr_mode: active interrupt mode adopted.
  3319. *
  3320. * This routine it invoked to log the currently used active interrupt mode
  3321. * to the device.
  3322. **/
  3323. static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
  3324. {
  3325. switch (intr_mode) {
  3326. case 0:
  3327. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3328. "0470 Enable INTx interrupt mode.\n");
  3329. break;
  3330. case 1:
  3331. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3332. "0481 Enabled MSI interrupt mode.\n");
  3333. break;
  3334. case 2:
  3335. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3336. "0480 Enabled MSI-X interrupt mode.\n");
  3337. break;
  3338. default:
  3339. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3340. "0482 Illegal interrupt mode.\n");
  3341. break;
  3342. }
  3343. return;
  3344. }
  3345. /**
  3346. * lpfc_enable_pci_dev - Enable a generic PCI device.
  3347. * @phba: pointer to lpfc hba data structure.
  3348. *
  3349. * This routine is invoked to enable the PCI device that is common to all
  3350. * PCI devices.
  3351. *
  3352. * Return codes
  3353. * 0 - successful
  3354. * other values - error
  3355. **/
  3356. static int
  3357. lpfc_enable_pci_dev(struct lpfc_hba *phba)
  3358. {
  3359. struct pci_dev *pdev;
  3360. int bars;
  3361. /* Obtain PCI device reference */
  3362. if (!phba->pcidev)
  3363. goto out_error;
  3364. else
  3365. pdev = phba->pcidev;
  3366. /* Select PCI BARs */
  3367. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  3368. /* Enable PCI device */
  3369. if (pci_enable_device_mem(pdev))
  3370. goto out_error;
  3371. /* Request PCI resource for the device */
  3372. if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
  3373. goto out_disable_device;
  3374. /* Set up device as PCI master and save state for EEH */
  3375. pci_set_master(pdev);
  3376. pci_try_set_mwi(pdev);
  3377. pci_save_state(pdev);
  3378. return 0;
  3379. out_disable_device:
  3380. pci_disable_device(pdev);
  3381. out_error:
  3382. return -ENODEV;
  3383. }
  3384. /**
  3385. * lpfc_disable_pci_dev - Disable a generic PCI device.
  3386. * @phba: pointer to lpfc hba data structure.
  3387. *
  3388. * This routine is invoked to disable the PCI device that is common to all
  3389. * PCI devices.
  3390. **/
  3391. static void
  3392. lpfc_disable_pci_dev(struct lpfc_hba *phba)
  3393. {
  3394. struct pci_dev *pdev;
  3395. int bars;
  3396. /* Obtain PCI device reference */
  3397. if (!phba->pcidev)
  3398. return;
  3399. else
  3400. pdev = phba->pcidev;
  3401. /* Select PCI BARs */
  3402. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  3403. /* Release PCI resource and disable PCI device */
  3404. pci_release_selected_regions(pdev, bars);
  3405. pci_disable_device(pdev);
  3406. /* Null out PCI private reference to driver */
  3407. pci_set_drvdata(pdev, NULL);
  3408. return;
  3409. }
  3410. /**
  3411. * lpfc_reset_hba - Reset a hba
  3412. * @phba: pointer to lpfc hba data structure.
  3413. *
  3414. * This routine is invoked to reset a hba device. It brings the HBA
  3415. * offline, performs a board restart, and then brings the board back
  3416. * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
  3417. * on outstanding mailbox commands.
  3418. **/
  3419. void
  3420. lpfc_reset_hba(struct lpfc_hba *phba)
  3421. {
  3422. /* If resets are disabled then set error state and return. */
  3423. if (!phba->cfg_enable_hba_reset) {
  3424. phba->link_state = LPFC_HBA_ERROR;
  3425. return;
  3426. }
  3427. lpfc_offline_prep(phba);
  3428. lpfc_offline(phba);
  3429. lpfc_sli_brdrestart(phba);
  3430. lpfc_online(phba);
  3431. lpfc_unblock_mgmt_io(phba);
  3432. }
  3433. /**
  3434. * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
  3435. * @phba: pointer to lpfc hba data structure.
  3436. *
  3437. * This routine is invoked to set up the driver internal resources specific to
  3438. * support the SLI-3 HBA device it attached to.
  3439. *
  3440. * Return codes
  3441. * 0 - successful
  3442. * other values - error
  3443. **/
  3444. static int
  3445. lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
  3446. {
  3447. struct lpfc_sli *psli;
  3448. /*
  3449. * Initialize timers used by driver
  3450. */
  3451. /* Heartbeat timer */
  3452. init_timer(&phba->hb_tmofunc);
  3453. phba->hb_tmofunc.function = lpfc_hb_timeout;
  3454. phba->hb_tmofunc.data = (unsigned long)phba;
  3455. psli = &phba->sli;
  3456. /* MBOX heartbeat timer */
  3457. init_timer(&psli->mbox_tmo);
  3458. psli->mbox_tmo.function = lpfc_mbox_timeout;
  3459. psli->mbox_tmo.data = (unsigned long) phba;
  3460. /* FCP polling mode timer */
  3461. init_timer(&phba->fcp_poll_timer);
  3462. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  3463. phba->fcp_poll_timer.data = (unsigned long) phba;
  3464. /* Fabric block timer */
  3465. init_timer(&phba->fabric_block_timer);
  3466. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  3467. phba->fabric_block_timer.data = (unsigned long) phba;
  3468. /* EA polling mode timer */
  3469. init_timer(&phba->eratt_poll);
  3470. phba->eratt_poll.function = lpfc_poll_eratt;
  3471. phba->eratt_poll.data = (unsigned long) phba;
  3472. /* Host attention work mask setup */
  3473. phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
  3474. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  3475. /* Get all the module params for configuring this host */
  3476. lpfc_get_cfgparam(phba);
  3477. /*
  3478. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  3479. * used to create the sg_dma_buf_pool must be dynamically calculated.
  3480. * 2 segments are added since the IOCB needs a command and response bde.
  3481. */
  3482. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  3483. sizeof(struct fcp_rsp) +
  3484. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
  3485. if (phba->cfg_enable_bg) {
  3486. phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
  3487. phba->cfg_sg_dma_buf_size +=
  3488. phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
  3489. }
  3490. /* Also reinitialize the host templates with new values. */
  3491. lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  3492. lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  3493. phba->max_vpi = LPFC_MAX_VPI;
  3494. /* This will be set to correct value after config_port mbox */
  3495. phba->max_vports = 0;
  3496. /*
  3497. * Initialize the SLI Layer to run with lpfc HBAs.
  3498. */
  3499. lpfc_sli_setup(phba);
  3500. lpfc_sli_queue_setup(phba);
  3501. /* Allocate device driver memory */
  3502. if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
  3503. return -ENOMEM;
  3504. return 0;
  3505. }
  3506. /**
  3507. * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
  3508. * @phba: pointer to lpfc hba data structure.
  3509. *
  3510. * This routine is invoked to unset the driver internal resources set up
  3511. * specific for supporting the SLI-3 HBA device it attached to.
  3512. **/
  3513. static void
  3514. lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
  3515. {
  3516. /* Free device driver memory allocated */
  3517. lpfc_mem_free_all(phba);
  3518. return;
  3519. }
  3520. /**
  3521. * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
  3522. * @phba: pointer to lpfc hba data structure.
  3523. *
  3524. * This routine is invoked to set up the driver internal resources specific to
  3525. * support the SLI-4 HBA device it attached to.
  3526. *
  3527. * Return codes
  3528. * 0 - successful
  3529. * other values - error
  3530. **/
  3531. static int
  3532. lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
  3533. {
  3534. struct lpfc_sli *psli;
  3535. LPFC_MBOXQ_t *mboxq;
  3536. int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size;
  3537. uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
  3538. struct lpfc_mqe *mqe;
  3539. int longs;
  3540. /* Before proceed, wait for POST done and device ready */
  3541. rc = lpfc_sli4_post_status_check(phba);
  3542. if (rc)
  3543. return -ENODEV;
  3544. /*
  3545. * Initialize timers used by driver
  3546. */
  3547. /* Heartbeat timer */
  3548. init_timer(&phba->hb_tmofunc);
  3549. phba->hb_tmofunc.function = lpfc_hb_timeout;
  3550. phba->hb_tmofunc.data = (unsigned long)phba;
  3551. psli = &phba->sli;
  3552. /* MBOX heartbeat timer */
  3553. init_timer(&psli->mbox_tmo);
  3554. psli->mbox_tmo.function = lpfc_mbox_timeout;
  3555. psli->mbox_tmo.data = (unsigned long) phba;
  3556. /* Fabric block timer */
  3557. init_timer(&phba->fabric_block_timer);
  3558. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  3559. phba->fabric_block_timer.data = (unsigned long) phba;
  3560. /* EA polling mode timer */
  3561. init_timer(&phba->eratt_poll);
  3562. phba->eratt_poll.function = lpfc_poll_eratt;
  3563. phba->eratt_poll.data = (unsigned long) phba;
  3564. /* FCF rediscover timer */
  3565. init_timer(&phba->fcf.redisc_wait);
  3566. phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
  3567. phba->fcf.redisc_wait.data = (unsigned long)phba;
  3568. /*
  3569. * We need to do a READ_CONFIG mailbox command here before
  3570. * calling lpfc_get_cfgparam. For VFs this will report the
  3571. * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
  3572. * All of the resources allocated
  3573. * for this Port are tied to these values.
  3574. */
  3575. /* Get all the module params for configuring this host */
  3576. lpfc_get_cfgparam(phba);
  3577. phba->max_vpi = LPFC_MAX_VPI;
  3578. /* This will be set to correct value after the read_config mbox */
  3579. phba->max_vports = 0;
  3580. /* Program the default value of vlan_id and fc_map */
  3581. phba->valid_vlan = 0;
  3582. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3583. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3584. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3585. /*
  3586. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  3587. * used to create the sg_dma_buf_pool must be dynamically calculated.
  3588. * 2 segments are added since the IOCB needs a command and response bde.
  3589. * To insure that the scsi sgl does not cross a 4k page boundary only
  3590. * sgl sizes of must be a power of 2.
  3591. */
  3592. buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) +
  3593. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge)));
  3594. /* Feature Level 1 hardware is limited to 2 pages */
  3595. if ((bf_get(lpfc_sli_intf_featurelevel1, &phba->sli4_hba.sli_intf) ==
  3596. LPFC_SLI_INTF_FEATURELEVEL1_1))
  3597. max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE;
  3598. else
  3599. max_buf_size = LPFC_SLI4_MAX_BUF_SIZE;
  3600. for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE;
  3601. dma_buf_size < max_buf_size && buf_size > dma_buf_size;
  3602. dma_buf_size = dma_buf_size << 1)
  3603. ;
  3604. if (dma_buf_size == max_buf_size)
  3605. phba->cfg_sg_seg_cnt = (dma_buf_size -
  3606. sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) -
  3607. (2 * sizeof(struct sli4_sge))) /
  3608. sizeof(struct sli4_sge);
  3609. phba->cfg_sg_dma_buf_size = dma_buf_size;
  3610. /* Initialize buffer queue management fields */
  3611. hbq_count = lpfc_sli_hbq_count();
  3612. for (i = 0; i < hbq_count; ++i)
  3613. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  3614. INIT_LIST_HEAD(&phba->rb_pend_list);
  3615. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
  3616. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
  3617. /*
  3618. * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
  3619. */
  3620. /* Initialize the Abort scsi buffer list used by driver */
  3621. spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
  3622. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  3623. /* This abort list used by worker thread */
  3624. spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
  3625. /*
  3626. * Initialize dirver internal slow-path work queues
  3627. */
  3628. /* Driver internel slow-path CQ Event pool */
  3629. INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
  3630. /* Response IOCB work queue list */
  3631. INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
  3632. /* Asynchronous event CQ Event work queue list */
  3633. INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
  3634. /* Fast-path XRI aborted CQ Event work queue list */
  3635. INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  3636. /* Slow-path XRI aborted CQ Event work queue list */
  3637. INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
  3638. /* Receive queue CQ Event work queue list */
  3639. INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
  3640. /* Initialize the driver internal SLI layer lists. */
  3641. lpfc_sli_setup(phba);
  3642. lpfc_sli_queue_setup(phba);
  3643. /* Allocate device driver memory */
  3644. rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
  3645. if (rc)
  3646. return -ENOMEM;
  3647. /* Create the bootstrap mailbox command */
  3648. rc = lpfc_create_bootstrap_mbox(phba);
  3649. if (unlikely(rc))
  3650. goto out_free_mem;
  3651. /* Set up the host's endian order with the device. */
  3652. rc = lpfc_setup_endian_order(phba);
  3653. if (unlikely(rc))
  3654. goto out_free_bsmbx;
  3655. rc = lpfc_sli4_fw_cfg_check(phba);
  3656. if (unlikely(rc))
  3657. goto out_free_bsmbx;
  3658. /* Set up the hba's configuration parameters. */
  3659. rc = lpfc_sli4_read_config(phba);
  3660. if (unlikely(rc))
  3661. goto out_free_bsmbx;
  3662. /* Perform a function reset */
  3663. rc = lpfc_pci_function_reset(phba);
  3664. if (unlikely(rc))
  3665. goto out_free_bsmbx;
  3666. /* Create all the SLI4 queues */
  3667. rc = lpfc_sli4_queue_create(phba);
  3668. if (rc)
  3669. goto out_free_bsmbx;
  3670. /* Create driver internal CQE event pool */
  3671. rc = lpfc_sli4_cq_event_pool_create(phba);
  3672. if (rc)
  3673. goto out_destroy_queue;
  3674. /* Initialize and populate the iocb list per host */
  3675. rc = lpfc_init_sgl_list(phba);
  3676. if (rc) {
  3677. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3678. "1400 Failed to initialize sgl list.\n");
  3679. goto out_destroy_cq_event_pool;
  3680. }
  3681. rc = lpfc_init_active_sgl_array(phba);
  3682. if (rc) {
  3683. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3684. "1430 Failed to initialize sgl list.\n");
  3685. goto out_free_sgl_list;
  3686. }
  3687. rc = lpfc_sli4_init_rpi_hdrs(phba);
  3688. if (rc) {
  3689. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3690. "1432 Failed to initialize rpi headers.\n");
  3691. goto out_free_active_sgl;
  3692. }
  3693. /* Allocate eligible FCF bmask memory for FCF round robin failover */
  3694. longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
  3695. phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
  3696. GFP_KERNEL);
  3697. if (!phba->fcf.fcf_rr_bmask) {
  3698. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3699. "2759 Failed allocate memory for FCF round "
  3700. "robin failover bmask\n");
  3701. goto out_remove_rpi_hdrs;
  3702. }
  3703. phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
  3704. phba->cfg_fcp_eq_count), GFP_KERNEL);
  3705. if (!phba->sli4_hba.fcp_eq_hdl) {
  3706. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3707. "2572 Failed allocate memory for fast-path "
  3708. "per-EQ handle array\n");
  3709. goto out_free_fcf_rr_bmask;
  3710. }
  3711. phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
  3712. phba->sli4_hba.cfg_eqn), GFP_KERNEL);
  3713. if (!phba->sli4_hba.msix_entries) {
  3714. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3715. "2573 Failed allocate memory for msi-x "
  3716. "interrupt vector entries\n");
  3717. goto out_free_fcp_eq_hdl;
  3718. }
  3719. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  3720. GFP_KERNEL);
  3721. if (!mboxq) {
  3722. rc = -ENOMEM;
  3723. goto out_free_fcp_eq_hdl;
  3724. }
  3725. /* Get the Supported Pages. It is always available. */
  3726. lpfc_supported_pages(mboxq);
  3727. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3728. if (unlikely(rc)) {
  3729. rc = -EIO;
  3730. mempool_free(mboxq, phba->mbox_mem_pool);
  3731. goto out_free_fcp_eq_hdl;
  3732. }
  3733. mqe = &mboxq->u.mqe;
  3734. memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
  3735. LPFC_MAX_SUPPORTED_PAGES);
  3736. for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
  3737. switch (pn_page[i]) {
  3738. case LPFC_SLI4_PARAMETERS:
  3739. phba->sli4_hba.pc_sli4_params.supported = 1;
  3740. break;
  3741. default:
  3742. break;
  3743. }
  3744. }
  3745. /* Read the port's SLI4 Parameters capabilities if supported. */
  3746. if (phba->sli4_hba.pc_sli4_params.supported)
  3747. rc = lpfc_pc_sli4_params_get(phba, mboxq);
  3748. mempool_free(mboxq, phba->mbox_mem_pool);
  3749. if (rc) {
  3750. rc = -EIO;
  3751. goto out_free_fcp_eq_hdl;
  3752. }
  3753. return rc;
  3754. out_free_fcp_eq_hdl:
  3755. kfree(phba->sli4_hba.fcp_eq_hdl);
  3756. out_free_fcf_rr_bmask:
  3757. kfree(phba->fcf.fcf_rr_bmask);
  3758. out_remove_rpi_hdrs:
  3759. lpfc_sli4_remove_rpi_hdrs(phba);
  3760. out_free_active_sgl:
  3761. lpfc_free_active_sgl(phba);
  3762. out_free_sgl_list:
  3763. lpfc_free_sgl_list(phba);
  3764. out_destroy_cq_event_pool:
  3765. lpfc_sli4_cq_event_pool_destroy(phba);
  3766. out_destroy_queue:
  3767. lpfc_sli4_queue_destroy(phba);
  3768. out_free_bsmbx:
  3769. lpfc_destroy_bootstrap_mbox(phba);
  3770. out_free_mem:
  3771. lpfc_mem_free(phba);
  3772. return rc;
  3773. }
  3774. /**
  3775. * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
  3776. * @phba: pointer to lpfc hba data structure.
  3777. *
  3778. * This routine is invoked to unset the driver internal resources set up
  3779. * specific for supporting the SLI-4 HBA device it attached to.
  3780. **/
  3781. static void
  3782. lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
  3783. {
  3784. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  3785. /* unregister default FCFI from the HBA */
  3786. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  3787. /* Free the default FCR table */
  3788. lpfc_sli_remove_dflt_fcf(phba);
  3789. /* Free memory allocated for msi-x interrupt vector entries */
  3790. kfree(phba->sli4_hba.msix_entries);
  3791. /* Free memory allocated for fast-path work queue handles */
  3792. kfree(phba->sli4_hba.fcp_eq_hdl);
  3793. /* Free the allocated rpi headers. */
  3794. lpfc_sli4_remove_rpi_hdrs(phba);
  3795. lpfc_sli4_remove_rpis(phba);
  3796. /* Free eligible FCF index bmask */
  3797. kfree(phba->fcf.fcf_rr_bmask);
  3798. /* Free the ELS sgl list */
  3799. lpfc_free_active_sgl(phba);
  3800. lpfc_free_sgl_list(phba);
  3801. /* Free the SCSI sgl management array */
  3802. kfree(phba->sli4_hba.lpfc_scsi_psb_array);
  3803. /* Free the SLI4 queues */
  3804. lpfc_sli4_queue_destroy(phba);
  3805. /* Free the completion queue EQ event pool */
  3806. lpfc_sli4_cq_event_release_all(phba);
  3807. lpfc_sli4_cq_event_pool_destroy(phba);
  3808. /* Reset SLI4 HBA FCoE function */
  3809. lpfc_pci_function_reset(phba);
  3810. /* Free the bsmbx region. */
  3811. lpfc_destroy_bootstrap_mbox(phba);
  3812. /* Free the SLI Layer memory with SLI4 HBAs */
  3813. lpfc_mem_free_all(phba);
  3814. /* Free the current connect table */
  3815. list_for_each_entry_safe(conn_entry, next_conn_entry,
  3816. &phba->fcf_conn_rec_list, list) {
  3817. list_del_init(&conn_entry->list);
  3818. kfree(conn_entry);
  3819. }
  3820. return;
  3821. }
  3822. /**
  3823. * lpfc_init_api_table_setup - Set up init api fucntion jump table
  3824. * @phba: The hba struct for which this call is being executed.
  3825. * @dev_grp: The HBA PCI-Device group number.
  3826. *
  3827. * This routine sets up the device INIT interface API function jump table
  3828. * in @phba struct.
  3829. *
  3830. * Returns: 0 - success, -ENODEV - failure.
  3831. **/
  3832. int
  3833. lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  3834. {
  3835. phba->lpfc_hba_init_link = lpfc_hba_init_link;
  3836. phba->lpfc_hba_down_link = lpfc_hba_down_link;
  3837. switch (dev_grp) {
  3838. case LPFC_PCI_DEV_LP:
  3839. phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
  3840. phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
  3841. phba->lpfc_stop_port = lpfc_stop_port_s3;
  3842. break;
  3843. case LPFC_PCI_DEV_OC:
  3844. phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
  3845. phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
  3846. phba->lpfc_stop_port = lpfc_stop_port_s4;
  3847. break;
  3848. default:
  3849. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3850. "1431 Invalid HBA PCI-device group: 0x%x\n",
  3851. dev_grp);
  3852. return -ENODEV;
  3853. break;
  3854. }
  3855. return 0;
  3856. }
  3857. /**
  3858. * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
  3859. * @phba: pointer to lpfc hba data structure.
  3860. *
  3861. * This routine is invoked to set up the driver internal resources before the
  3862. * device specific resource setup to support the HBA device it attached to.
  3863. *
  3864. * Return codes
  3865. * 0 - successful
  3866. * other values - error
  3867. **/
  3868. static int
  3869. lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
  3870. {
  3871. /*
  3872. * Driver resources common to all SLI revisions
  3873. */
  3874. atomic_set(&phba->fast_event_count, 0);
  3875. spin_lock_init(&phba->hbalock);
  3876. /* Initialize ndlp management spinlock */
  3877. spin_lock_init(&phba->ndlp_lock);
  3878. INIT_LIST_HEAD(&phba->port_list);
  3879. INIT_LIST_HEAD(&phba->work_list);
  3880. init_waitqueue_head(&phba->wait_4_mlo_m_q);
  3881. /* Initialize the wait queue head for the kernel thread */
  3882. init_waitqueue_head(&phba->work_waitq);
  3883. /* Initialize the scsi buffer list used by driver for scsi IO */
  3884. spin_lock_init(&phba->scsi_buf_list_lock);
  3885. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  3886. /* Initialize the fabric iocb list */
  3887. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  3888. /* Initialize list to save ELS buffers */
  3889. INIT_LIST_HEAD(&phba->elsbuf);
  3890. /* Initialize FCF connection rec list */
  3891. INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
  3892. return 0;
  3893. }
  3894. /**
  3895. * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
  3896. * @phba: pointer to lpfc hba data structure.
  3897. *
  3898. * This routine is invoked to set up the driver internal resources after the
  3899. * device specific resource setup to support the HBA device it attached to.
  3900. *
  3901. * Return codes
  3902. * 0 - successful
  3903. * other values - error
  3904. **/
  3905. static int
  3906. lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
  3907. {
  3908. int error;
  3909. /* Startup the kernel thread for this host adapter. */
  3910. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  3911. "lpfc_worker_%d", phba->brd_no);
  3912. if (IS_ERR(phba->worker_thread)) {
  3913. error = PTR_ERR(phba->worker_thread);
  3914. return error;
  3915. }
  3916. return 0;
  3917. }
  3918. /**
  3919. * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
  3920. * @phba: pointer to lpfc hba data structure.
  3921. *
  3922. * This routine is invoked to unset the driver internal resources set up after
  3923. * the device specific resource setup for supporting the HBA device it
  3924. * attached to.
  3925. **/
  3926. static void
  3927. lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
  3928. {
  3929. /* Stop kernel worker thread */
  3930. kthread_stop(phba->worker_thread);
  3931. }
  3932. /**
  3933. * lpfc_free_iocb_list - Free iocb list.
  3934. * @phba: pointer to lpfc hba data structure.
  3935. *
  3936. * This routine is invoked to free the driver's IOCB list and memory.
  3937. **/
  3938. static void
  3939. lpfc_free_iocb_list(struct lpfc_hba *phba)
  3940. {
  3941. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  3942. spin_lock_irq(&phba->hbalock);
  3943. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  3944. &phba->lpfc_iocb_list, list) {
  3945. list_del(&iocbq_entry->list);
  3946. kfree(iocbq_entry);
  3947. phba->total_iocbq_bufs--;
  3948. }
  3949. spin_unlock_irq(&phba->hbalock);
  3950. return;
  3951. }
  3952. /**
  3953. * lpfc_init_iocb_list - Allocate and initialize iocb list.
  3954. * @phba: pointer to lpfc hba data structure.
  3955. *
  3956. * This routine is invoked to allocate and initizlize the driver's IOCB
  3957. * list and set up the IOCB tag array accordingly.
  3958. *
  3959. * Return codes
  3960. * 0 - successful
  3961. * other values - error
  3962. **/
  3963. static int
  3964. lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
  3965. {
  3966. struct lpfc_iocbq *iocbq_entry = NULL;
  3967. uint16_t iotag;
  3968. int i;
  3969. /* Initialize and populate the iocb list per host. */
  3970. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  3971. for (i = 0; i < iocb_count; i++) {
  3972. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  3973. if (iocbq_entry == NULL) {
  3974. printk(KERN_ERR "%s: only allocated %d iocbs of "
  3975. "expected %d count. Unloading driver.\n",
  3976. __func__, i, LPFC_IOCB_LIST_CNT);
  3977. goto out_free_iocbq;
  3978. }
  3979. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  3980. if (iotag == 0) {
  3981. kfree(iocbq_entry);
  3982. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  3983. "Unloading driver.\n", __func__);
  3984. goto out_free_iocbq;
  3985. }
  3986. iocbq_entry->sli4_xritag = NO_XRI;
  3987. spin_lock_irq(&phba->hbalock);
  3988. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  3989. phba->total_iocbq_bufs++;
  3990. spin_unlock_irq(&phba->hbalock);
  3991. }
  3992. return 0;
  3993. out_free_iocbq:
  3994. lpfc_free_iocb_list(phba);
  3995. return -ENOMEM;
  3996. }
  3997. /**
  3998. * lpfc_free_sgl_list - Free sgl list.
  3999. * @phba: pointer to lpfc hba data structure.
  4000. *
  4001. * This routine is invoked to free the driver's sgl list and memory.
  4002. **/
  4003. static void
  4004. lpfc_free_sgl_list(struct lpfc_hba *phba)
  4005. {
  4006. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  4007. LIST_HEAD(sglq_list);
  4008. int rc = 0;
  4009. spin_lock_irq(&phba->hbalock);
  4010. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
  4011. spin_unlock_irq(&phba->hbalock);
  4012. list_for_each_entry_safe(sglq_entry, sglq_next,
  4013. &sglq_list, list) {
  4014. list_del(&sglq_entry->list);
  4015. lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
  4016. kfree(sglq_entry);
  4017. phba->sli4_hba.total_sglq_bufs--;
  4018. }
  4019. rc = lpfc_sli4_remove_all_sgl_pages(phba);
  4020. if (rc) {
  4021. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4022. "2005 Unable to deregister pages from HBA: %x\n", rc);
  4023. }
  4024. kfree(phba->sli4_hba.lpfc_els_sgl_array);
  4025. }
  4026. /**
  4027. * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
  4028. * @phba: pointer to lpfc hba data structure.
  4029. *
  4030. * This routine is invoked to allocate the driver's active sgl memory.
  4031. * This array will hold the sglq_entry's for active IOs.
  4032. **/
  4033. static int
  4034. lpfc_init_active_sgl_array(struct lpfc_hba *phba)
  4035. {
  4036. int size;
  4037. size = sizeof(struct lpfc_sglq *);
  4038. size *= phba->sli4_hba.max_cfg_param.max_xri;
  4039. phba->sli4_hba.lpfc_sglq_active_list =
  4040. kzalloc(size, GFP_KERNEL);
  4041. if (!phba->sli4_hba.lpfc_sglq_active_list)
  4042. return -ENOMEM;
  4043. return 0;
  4044. }
  4045. /**
  4046. * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
  4047. * @phba: pointer to lpfc hba data structure.
  4048. *
  4049. * This routine is invoked to walk through the array of active sglq entries
  4050. * and free all of the resources.
  4051. * This is just a place holder for now.
  4052. **/
  4053. static void
  4054. lpfc_free_active_sgl(struct lpfc_hba *phba)
  4055. {
  4056. kfree(phba->sli4_hba.lpfc_sglq_active_list);
  4057. }
  4058. /**
  4059. * lpfc_init_sgl_list - Allocate and initialize sgl list.
  4060. * @phba: pointer to lpfc hba data structure.
  4061. *
  4062. * This routine is invoked to allocate and initizlize the driver's sgl
  4063. * list and set up the sgl xritag tag array accordingly.
  4064. *
  4065. * Return codes
  4066. * 0 - successful
  4067. * other values - error
  4068. **/
  4069. static int
  4070. lpfc_init_sgl_list(struct lpfc_hba *phba)
  4071. {
  4072. struct lpfc_sglq *sglq_entry = NULL;
  4073. int i;
  4074. int els_xri_cnt;
  4075. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  4076. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4077. "2400 lpfc_init_sgl_list els %d.\n",
  4078. els_xri_cnt);
  4079. /* Initialize and populate the sglq list per host/VF. */
  4080. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
  4081. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  4082. /* Sanity check on XRI management */
  4083. if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) {
  4084. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4085. "2562 No room left for SCSI XRI allocation: "
  4086. "max_xri=%d, els_xri=%d\n",
  4087. phba->sli4_hba.max_cfg_param.max_xri,
  4088. els_xri_cnt);
  4089. return -ENOMEM;
  4090. }
  4091. /* Allocate memory for the ELS XRI management array */
  4092. phba->sli4_hba.lpfc_els_sgl_array =
  4093. kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt),
  4094. GFP_KERNEL);
  4095. if (!phba->sli4_hba.lpfc_els_sgl_array) {
  4096. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4097. "2401 Failed to allocate memory for ELS "
  4098. "XRI management array of size %d.\n",
  4099. els_xri_cnt);
  4100. return -ENOMEM;
  4101. }
  4102. /* Keep the SCSI XRI into the XRI management array */
  4103. phba->sli4_hba.scsi_xri_max =
  4104. phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
  4105. phba->sli4_hba.scsi_xri_cnt = 0;
  4106. phba->sli4_hba.lpfc_scsi_psb_array =
  4107. kzalloc((sizeof(struct lpfc_scsi_buf *) *
  4108. phba->sli4_hba.scsi_xri_max), GFP_KERNEL);
  4109. if (!phba->sli4_hba.lpfc_scsi_psb_array) {
  4110. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4111. "2563 Failed to allocate memory for SCSI "
  4112. "XRI management array of size %d.\n",
  4113. phba->sli4_hba.scsi_xri_max);
  4114. kfree(phba->sli4_hba.lpfc_els_sgl_array);
  4115. return -ENOMEM;
  4116. }
  4117. for (i = 0; i < els_xri_cnt; i++) {
  4118. sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL);
  4119. if (sglq_entry == NULL) {
  4120. printk(KERN_ERR "%s: only allocated %d sgls of "
  4121. "expected %d count. Unloading driver.\n",
  4122. __func__, i, els_xri_cnt);
  4123. goto out_free_mem;
  4124. }
  4125. sglq_entry->sli4_xritag = lpfc_sli4_next_xritag(phba);
  4126. if (sglq_entry->sli4_xritag == NO_XRI) {
  4127. kfree(sglq_entry);
  4128. printk(KERN_ERR "%s: failed to allocate XRI.\n"
  4129. "Unloading driver.\n", __func__);
  4130. goto out_free_mem;
  4131. }
  4132. sglq_entry->buff_type = GEN_BUFF_TYPE;
  4133. sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys);
  4134. if (sglq_entry->virt == NULL) {
  4135. kfree(sglq_entry);
  4136. printk(KERN_ERR "%s: failed to allocate mbuf.\n"
  4137. "Unloading driver.\n", __func__);
  4138. goto out_free_mem;
  4139. }
  4140. sglq_entry->sgl = sglq_entry->virt;
  4141. memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
  4142. /* The list order is used by later block SGL registraton */
  4143. spin_lock_irq(&phba->hbalock);
  4144. sglq_entry->state = SGL_FREED;
  4145. list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list);
  4146. phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry;
  4147. phba->sli4_hba.total_sglq_bufs++;
  4148. spin_unlock_irq(&phba->hbalock);
  4149. }
  4150. return 0;
  4151. out_free_mem:
  4152. kfree(phba->sli4_hba.lpfc_scsi_psb_array);
  4153. lpfc_free_sgl_list(phba);
  4154. return -ENOMEM;
  4155. }
  4156. /**
  4157. * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
  4158. * @phba: pointer to lpfc hba data structure.
  4159. *
  4160. * This routine is invoked to post rpi header templates to the
  4161. * HBA consistent with the SLI-4 interface spec. This routine
  4162. * posts a PAGE_SIZE memory region to the port to hold up to
  4163. * PAGE_SIZE modulo 64 rpi context headers.
  4164. * No locks are held here because this is an initialization routine
  4165. * called only from probe or lpfc_online when interrupts are not
  4166. * enabled and the driver is reinitializing the device.
  4167. *
  4168. * Return codes
  4169. * 0 - successful
  4170. * ENOMEM - No availble memory
  4171. * EIO - The mailbox failed to complete successfully.
  4172. **/
  4173. int
  4174. lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
  4175. {
  4176. int rc = 0;
  4177. int longs;
  4178. uint16_t rpi_count;
  4179. struct lpfc_rpi_hdr *rpi_hdr;
  4180. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
  4181. /*
  4182. * Provision an rpi bitmask range for discovery. The total count
  4183. * is the difference between max and base + 1.
  4184. */
  4185. rpi_count = phba->sli4_hba.max_cfg_param.rpi_base +
  4186. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  4187. longs = ((rpi_count) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4188. phba->sli4_hba.rpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4189. GFP_KERNEL);
  4190. if (!phba->sli4_hba.rpi_bmask)
  4191. return -ENOMEM;
  4192. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  4193. if (!rpi_hdr) {
  4194. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4195. "0391 Error during rpi post operation\n");
  4196. lpfc_sli4_remove_rpis(phba);
  4197. rc = -ENODEV;
  4198. }
  4199. return rc;
  4200. }
  4201. /**
  4202. * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
  4203. * @phba: pointer to lpfc hba data structure.
  4204. *
  4205. * This routine is invoked to allocate a single 4KB memory region to
  4206. * support rpis and stores them in the phba. This single region
  4207. * provides support for up to 64 rpis. The region is used globally
  4208. * by the device.
  4209. *
  4210. * Returns:
  4211. * A valid rpi hdr on success.
  4212. * A NULL pointer on any failure.
  4213. **/
  4214. struct lpfc_rpi_hdr *
  4215. lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
  4216. {
  4217. uint16_t rpi_limit, curr_rpi_range;
  4218. struct lpfc_dmabuf *dmabuf;
  4219. struct lpfc_rpi_hdr *rpi_hdr;
  4220. rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
  4221. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  4222. spin_lock_irq(&phba->hbalock);
  4223. curr_rpi_range = phba->sli4_hba.next_rpi;
  4224. spin_unlock_irq(&phba->hbalock);
  4225. /*
  4226. * The port has a limited number of rpis. The increment here
  4227. * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
  4228. * and to allow the full max_rpi range per port.
  4229. */
  4230. if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
  4231. return NULL;
  4232. /*
  4233. * First allocate the protocol header region for the port. The
  4234. * port expects a 4KB DMA-mapped memory region that is 4K aligned.
  4235. */
  4236. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4237. if (!dmabuf)
  4238. return NULL;
  4239. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4240. LPFC_HDR_TEMPLATE_SIZE,
  4241. &dmabuf->phys,
  4242. GFP_KERNEL);
  4243. if (!dmabuf->virt) {
  4244. rpi_hdr = NULL;
  4245. goto err_free_dmabuf;
  4246. }
  4247. memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
  4248. if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
  4249. rpi_hdr = NULL;
  4250. goto err_free_coherent;
  4251. }
  4252. /* Save the rpi header data for cleanup later. */
  4253. rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
  4254. if (!rpi_hdr)
  4255. goto err_free_coherent;
  4256. rpi_hdr->dmabuf = dmabuf;
  4257. rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
  4258. rpi_hdr->page_count = 1;
  4259. spin_lock_irq(&phba->hbalock);
  4260. rpi_hdr->start_rpi = phba->sli4_hba.next_rpi;
  4261. list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
  4262. /*
  4263. * The next_rpi stores the next module-64 rpi value to post
  4264. * in any subsequent rpi memory region postings.
  4265. */
  4266. phba->sli4_hba.next_rpi += LPFC_RPI_HDR_COUNT;
  4267. spin_unlock_irq(&phba->hbalock);
  4268. return rpi_hdr;
  4269. err_free_coherent:
  4270. dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
  4271. dmabuf->virt, dmabuf->phys);
  4272. err_free_dmabuf:
  4273. kfree(dmabuf);
  4274. return NULL;
  4275. }
  4276. /**
  4277. * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
  4278. * @phba: pointer to lpfc hba data structure.
  4279. *
  4280. * This routine is invoked to remove all memory resources allocated
  4281. * to support rpis. This routine presumes the caller has released all
  4282. * rpis consumed by fabric or port logins and is prepared to have
  4283. * the header pages removed.
  4284. **/
  4285. void
  4286. lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
  4287. {
  4288. struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
  4289. list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
  4290. &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  4291. list_del(&rpi_hdr->list);
  4292. dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
  4293. rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
  4294. kfree(rpi_hdr->dmabuf);
  4295. kfree(rpi_hdr);
  4296. }
  4297. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
  4298. memset(phba->sli4_hba.rpi_bmask, 0, sizeof(*phba->sli4_hba.rpi_bmask));
  4299. }
  4300. /**
  4301. * lpfc_hba_alloc - Allocate driver hba data structure for a device.
  4302. * @pdev: pointer to pci device data structure.
  4303. *
  4304. * This routine is invoked to allocate the driver hba data structure for an
  4305. * HBA device. If the allocation is successful, the phba reference to the
  4306. * PCI device data structure is set.
  4307. *
  4308. * Return codes
  4309. * pointer to @phba - successful
  4310. * NULL - error
  4311. **/
  4312. static struct lpfc_hba *
  4313. lpfc_hba_alloc(struct pci_dev *pdev)
  4314. {
  4315. struct lpfc_hba *phba;
  4316. /* Allocate memory for HBA structure */
  4317. phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
  4318. if (!phba) {
  4319. dev_err(&pdev->dev, "failed to allocate hba struct\n");
  4320. return NULL;
  4321. }
  4322. /* Set reference to PCI device in HBA structure */
  4323. phba->pcidev = pdev;
  4324. /* Assign an unused board number */
  4325. phba->brd_no = lpfc_get_instance();
  4326. if (phba->brd_no < 0) {
  4327. kfree(phba);
  4328. return NULL;
  4329. }
  4330. spin_lock_init(&phba->ct_ev_lock);
  4331. INIT_LIST_HEAD(&phba->ct_ev_waiters);
  4332. return phba;
  4333. }
  4334. /**
  4335. * lpfc_hba_free - Free driver hba data structure with a device.
  4336. * @phba: pointer to lpfc hba data structure.
  4337. *
  4338. * This routine is invoked to free the driver hba data structure with an
  4339. * HBA device.
  4340. **/
  4341. static void
  4342. lpfc_hba_free(struct lpfc_hba *phba)
  4343. {
  4344. /* Release the driver assigned board number */
  4345. idr_remove(&lpfc_hba_index, phba->brd_no);
  4346. kfree(phba);
  4347. return;
  4348. }
  4349. /**
  4350. * lpfc_create_shost - Create hba physical port with associated scsi host.
  4351. * @phba: pointer to lpfc hba data structure.
  4352. *
  4353. * This routine is invoked to create HBA physical port and associate a SCSI
  4354. * host with it.
  4355. *
  4356. * Return codes
  4357. * 0 - successful
  4358. * other values - error
  4359. **/
  4360. static int
  4361. lpfc_create_shost(struct lpfc_hba *phba)
  4362. {
  4363. struct lpfc_vport *vport;
  4364. struct Scsi_Host *shost;
  4365. /* Initialize HBA FC structure */
  4366. phba->fc_edtov = FF_DEF_EDTOV;
  4367. phba->fc_ratov = FF_DEF_RATOV;
  4368. phba->fc_altov = FF_DEF_ALTOV;
  4369. phba->fc_arbtov = FF_DEF_ARBTOV;
  4370. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  4371. if (!vport)
  4372. return -ENODEV;
  4373. shost = lpfc_shost_from_vport(vport);
  4374. phba->pport = vport;
  4375. lpfc_debugfs_initialize(vport);
  4376. /* Put reference to SCSI host to driver's device private data */
  4377. pci_set_drvdata(phba->pcidev, shost);
  4378. return 0;
  4379. }
  4380. /**
  4381. * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
  4382. * @phba: pointer to lpfc hba data structure.
  4383. *
  4384. * This routine is invoked to destroy HBA physical port and the associated
  4385. * SCSI host.
  4386. **/
  4387. static void
  4388. lpfc_destroy_shost(struct lpfc_hba *phba)
  4389. {
  4390. struct lpfc_vport *vport = phba->pport;
  4391. /* Destroy physical port that associated with the SCSI host */
  4392. destroy_port(vport);
  4393. return;
  4394. }
  4395. /**
  4396. * lpfc_setup_bg - Setup Block guard structures and debug areas.
  4397. * @phba: pointer to lpfc hba data structure.
  4398. * @shost: the shost to be used to detect Block guard settings.
  4399. *
  4400. * This routine sets up the local Block guard protocol settings for @shost.
  4401. * This routine also allocates memory for debugging bg buffers.
  4402. **/
  4403. static void
  4404. lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
  4405. {
  4406. int pagecnt = 10;
  4407. if (lpfc_prot_mask && lpfc_prot_guard) {
  4408. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4409. "1478 Registering BlockGuard with the "
  4410. "SCSI layer\n");
  4411. scsi_host_set_prot(shost, lpfc_prot_mask);
  4412. scsi_host_set_guard(shost, lpfc_prot_guard);
  4413. }
  4414. if (!_dump_buf_data) {
  4415. while (pagecnt) {
  4416. spin_lock_init(&_dump_buf_lock);
  4417. _dump_buf_data =
  4418. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  4419. if (_dump_buf_data) {
  4420. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4421. "9043 BLKGRD: allocated %d pages for "
  4422. "_dump_buf_data at 0x%p\n",
  4423. (1 << pagecnt), _dump_buf_data);
  4424. _dump_buf_data_order = pagecnt;
  4425. memset(_dump_buf_data, 0,
  4426. ((1 << PAGE_SHIFT) << pagecnt));
  4427. break;
  4428. } else
  4429. --pagecnt;
  4430. }
  4431. if (!_dump_buf_data_order)
  4432. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4433. "9044 BLKGRD: ERROR unable to allocate "
  4434. "memory for hexdump\n");
  4435. } else
  4436. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4437. "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
  4438. "\n", _dump_buf_data);
  4439. if (!_dump_buf_dif) {
  4440. while (pagecnt) {
  4441. _dump_buf_dif =
  4442. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  4443. if (_dump_buf_dif) {
  4444. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4445. "9046 BLKGRD: allocated %d pages for "
  4446. "_dump_buf_dif at 0x%p\n",
  4447. (1 << pagecnt), _dump_buf_dif);
  4448. _dump_buf_dif_order = pagecnt;
  4449. memset(_dump_buf_dif, 0,
  4450. ((1 << PAGE_SHIFT) << pagecnt));
  4451. break;
  4452. } else
  4453. --pagecnt;
  4454. }
  4455. if (!_dump_buf_dif_order)
  4456. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4457. "9047 BLKGRD: ERROR unable to allocate "
  4458. "memory for hexdump\n");
  4459. } else
  4460. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4461. "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
  4462. _dump_buf_dif);
  4463. }
  4464. /**
  4465. * lpfc_post_init_setup - Perform necessary device post initialization setup.
  4466. * @phba: pointer to lpfc hba data structure.
  4467. *
  4468. * This routine is invoked to perform all the necessary post initialization
  4469. * setup for the device.
  4470. **/
  4471. static void
  4472. lpfc_post_init_setup(struct lpfc_hba *phba)
  4473. {
  4474. struct Scsi_Host *shost;
  4475. struct lpfc_adapter_event_header adapter_event;
  4476. /* Get the default values for Model Name and Description */
  4477. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  4478. /*
  4479. * hba setup may have changed the hba_queue_depth so we need to
  4480. * adjust the value of can_queue.
  4481. */
  4482. shost = pci_get_drvdata(phba->pcidev);
  4483. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  4484. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
  4485. lpfc_setup_bg(phba, shost);
  4486. lpfc_host_attrib_init(shost);
  4487. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  4488. spin_lock_irq(shost->host_lock);
  4489. lpfc_poll_start_timer(phba);
  4490. spin_unlock_irq(shost->host_lock);
  4491. }
  4492. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4493. "0428 Perform SCSI scan\n");
  4494. /* Send board arrival event to upper layer */
  4495. adapter_event.event_type = FC_REG_ADAPTER_EVENT;
  4496. adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
  4497. fc_host_post_vendor_event(shost, fc_get_event_number(),
  4498. sizeof(adapter_event),
  4499. (char *) &adapter_event,
  4500. LPFC_NL_VENDOR_ID);
  4501. return;
  4502. }
  4503. /**
  4504. * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
  4505. * @phba: pointer to lpfc hba data structure.
  4506. *
  4507. * This routine is invoked to set up the PCI device memory space for device
  4508. * with SLI-3 interface spec.
  4509. *
  4510. * Return codes
  4511. * 0 - successful
  4512. * other values - error
  4513. **/
  4514. static int
  4515. lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
  4516. {
  4517. struct pci_dev *pdev;
  4518. unsigned long bar0map_len, bar2map_len;
  4519. int i, hbq_count;
  4520. void *ptr;
  4521. int error = -ENODEV;
  4522. /* Obtain PCI device reference */
  4523. if (!phba->pcidev)
  4524. return error;
  4525. else
  4526. pdev = phba->pcidev;
  4527. /* Set the device DMA mask size */
  4528. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  4529. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  4530. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  4531. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  4532. return error;
  4533. }
  4534. }
  4535. /* Get the bus address of Bar0 and Bar2 and the number of bytes
  4536. * required by each mapping.
  4537. */
  4538. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  4539. bar0map_len = pci_resource_len(pdev, 0);
  4540. phba->pci_bar2_map = pci_resource_start(pdev, 2);
  4541. bar2map_len = pci_resource_len(pdev, 2);
  4542. /* Map HBA SLIM to a kernel virtual address. */
  4543. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  4544. if (!phba->slim_memmap_p) {
  4545. dev_printk(KERN_ERR, &pdev->dev,
  4546. "ioremap failed for SLIM memory.\n");
  4547. goto out;
  4548. }
  4549. /* Map HBA Control Registers to a kernel virtual address. */
  4550. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  4551. if (!phba->ctrl_regs_memmap_p) {
  4552. dev_printk(KERN_ERR, &pdev->dev,
  4553. "ioremap failed for HBA control registers.\n");
  4554. goto out_iounmap_slim;
  4555. }
  4556. /* Allocate memory for SLI-2 structures */
  4557. phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
  4558. SLI2_SLIM_SIZE,
  4559. &phba->slim2p.phys,
  4560. GFP_KERNEL);
  4561. if (!phba->slim2p.virt)
  4562. goto out_iounmap;
  4563. memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
  4564. phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
  4565. phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
  4566. phba->IOCBs = (phba->slim2p.virt +
  4567. offsetof(struct lpfc_sli2_slim, IOCBs));
  4568. phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
  4569. lpfc_sli_hbq_size(),
  4570. &phba->hbqslimp.phys,
  4571. GFP_KERNEL);
  4572. if (!phba->hbqslimp.virt)
  4573. goto out_free_slim;
  4574. hbq_count = lpfc_sli_hbq_count();
  4575. ptr = phba->hbqslimp.virt;
  4576. for (i = 0; i < hbq_count; ++i) {
  4577. phba->hbqs[i].hbq_virt = ptr;
  4578. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  4579. ptr += (lpfc_hbq_defs[i]->entry_count *
  4580. sizeof(struct lpfc_hbq_entry));
  4581. }
  4582. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  4583. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  4584. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  4585. INIT_LIST_HEAD(&phba->rb_pend_list);
  4586. phba->MBslimaddr = phba->slim_memmap_p;
  4587. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  4588. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  4589. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  4590. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  4591. return 0;
  4592. out_free_slim:
  4593. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  4594. phba->slim2p.virt, phba->slim2p.phys);
  4595. out_iounmap:
  4596. iounmap(phba->ctrl_regs_memmap_p);
  4597. out_iounmap_slim:
  4598. iounmap(phba->slim_memmap_p);
  4599. out:
  4600. return error;
  4601. }
  4602. /**
  4603. * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
  4604. * @phba: pointer to lpfc hba data structure.
  4605. *
  4606. * This routine is invoked to unset the PCI device memory space for device
  4607. * with SLI-3 interface spec.
  4608. **/
  4609. static void
  4610. lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
  4611. {
  4612. struct pci_dev *pdev;
  4613. /* Obtain PCI device reference */
  4614. if (!phba->pcidev)
  4615. return;
  4616. else
  4617. pdev = phba->pcidev;
  4618. /* Free coherent DMA memory allocated */
  4619. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  4620. phba->hbqslimp.virt, phba->hbqslimp.phys);
  4621. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  4622. phba->slim2p.virt, phba->slim2p.phys);
  4623. /* I/O memory unmap */
  4624. iounmap(phba->ctrl_regs_memmap_p);
  4625. iounmap(phba->slim_memmap_p);
  4626. return;
  4627. }
  4628. /**
  4629. * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
  4630. * @phba: pointer to lpfc hba data structure.
  4631. *
  4632. * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
  4633. * done and check status.
  4634. *
  4635. * Return 0 if successful, otherwise -ENODEV.
  4636. **/
  4637. int
  4638. lpfc_sli4_post_status_check(struct lpfc_hba *phba)
  4639. {
  4640. struct lpfc_register sta_reg, uerrlo_reg, uerrhi_reg;
  4641. int i, port_error = -ENODEV;
  4642. if (!phba->sli4_hba.STAregaddr)
  4643. return -ENODEV;
  4644. /* Wait up to 30 seconds for the SLI Port POST done and ready */
  4645. for (i = 0; i < 3000; i++) {
  4646. sta_reg.word0 = readl(phba->sli4_hba.STAregaddr);
  4647. /* Encounter fatal POST error, break out */
  4648. if (bf_get(lpfc_hst_state_perr, &sta_reg)) {
  4649. port_error = -ENODEV;
  4650. break;
  4651. }
  4652. if (LPFC_POST_STAGE_ARMFW_READY ==
  4653. bf_get(lpfc_hst_state_port_status, &sta_reg)) {
  4654. port_error = 0;
  4655. break;
  4656. }
  4657. msleep(10);
  4658. }
  4659. if (port_error)
  4660. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4661. "1408 Failure HBA POST Status: sta_reg=0x%x, "
  4662. "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, xrom=x%x, "
  4663. "dl=x%x, pstatus=x%x\n", sta_reg.word0,
  4664. bf_get(lpfc_hst_state_perr, &sta_reg),
  4665. bf_get(lpfc_hst_state_sfi, &sta_reg),
  4666. bf_get(lpfc_hst_state_nip, &sta_reg),
  4667. bf_get(lpfc_hst_state_ipc, &sta_reg),
  4668. bf_get(lpfc_hst_state_xrom, &sta_reg),
  4669. bf_get(lpfc_hst_state_dl, &sta_reg),
  4670. bf_get(lpfc_hst_state_port_status, &sta_reg));
  4671. /* Log device information */
  4672. phba->sli4_hba.sli_intf.word0 = readl(phba->sli4_hba.SLIINTFregaddr);
  4673. if (bf_get(lpfc_sli_intf_valid,
  4674. &phba->sli4_hba.sli_intf) == LPFC_SLI_INTF_VALID) {
  4675. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4676. "2534 Device Info: ChipType=0x%x, SliRev=0x%x, "
  4677. "FeatureL1=0x%x, FeatureL2=0x%x\n",
  4678. bf_get(lpfc_sli_intf_sli_family,
  4679. &phba->sli4_hba.sli_intf),
  4680. bf_get(lpfc_sli_intf_slirev,
  4681. &phba->sli4_hba.sli_intf),
  4682. bf_get(lpfc_sli_intf_featurelevel1,
  4683. &phba->sli4_hba.sli_intf),
  4684. bf_get(lpfc_sli_intf_featurelevel2,
  4685. &phba->sli4_hba.sli_intf));
  4686. }
  4687. phba->sli4_hba.ue_mask_lo = readl(phba->sli4_hba.UEMASKLOregaddr);
  4688. phba->sli4_hba.ue_mask_hi = readl(phba->sli4_hba.UEMASKHIregaddr);
  4689. /* With uncoverable error, log the error message and return error */
  4690. uerrlo_reg.word0 = readl(phba->sli4_hba.UERRLOregaddr);
  4691. uerrhi_reg.word0 = readl(phba->sli4_hba.UERRHIregaddr);
  4692. if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
  4693. (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
  4694. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4695. "1422 HBA Unrecoverable error: "
  4696. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  4697. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  4698. uerrlo_reg.word0, uerrhi_reg.word0,
  4699. phba->sli4_hba.ue_mask_lo,
  4700. phba->sli4_hba.ue_mask_hi);
  4701. return -ENODEV;
  4702. }
  4703. return port_error;
  4704. }
  4705. /**
  4706. * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
  4707. * @phba: pointer to lpfc hba data structure.
  4708. *
  4709. * This routine is invoked to set up SLI4 BAR0 PCI config space register
  4710. * memory map.
  4711. **/
  4712. static void
  4713. lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba)
  4714. {
  4715. phba->sli4_hba.UERRLOregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4716. LPFC_UERR_STATUS_LO;
  4717. phba->sli4_hba.UERRHIregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4718. LPFC_UERR_STATUS_HI;
  4719. phba->sli4_hba.UEMASKLOregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4720. LPFC_UE_MASK_LO;
  4721. phba->sli4_hba.UEMASKHIregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4722. LPFC_UE_MASK_HI;
  4723. phba->sli4_hba.SLIINTFregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4724. LPFC_SLI_INTF;
  4725. }
  4726. /**
  4727. * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
  4728. * @phba: pointer to lpfc hba data structure.
  4729. *
  4730. * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
  4731. * memory map.
  4732. **/
  4733. static void
  4734. lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
  4735. {
  4736. phba->sli4_hba.STAregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4737. LPFC_HST_STATE;
  4738. phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4739. LPFC_HST_ISR0;
  4740. phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4741. LPFC_HST_IMR0;
  4742. phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4743. LPFC_HST_ISCR0;
  4744. return;
  4745. }
  4746. /**
  4747. * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
  4748. * @phba: pointer to lpfc hba data structure.
  4749. * @vf: virtual function number
  4750. *
  4751. * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
  4752. * based on the given viftual function number, @vf.
  4753. *
  4754. * Return 0 if successful, otherwise -ENODEV.
  4755. **/
  4756. static int
  4757. lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
  4758. {
  4759. if (vf > LPFC_VIR_FUNC_MAX)
  4760. return -ENODEV;
  4761. phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4762. vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL);
  4763. phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4764. vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL);
  4765. phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4766. vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
  4767. phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4768. vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
  4769. phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4770. vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
  4771. return 0;
  4772. }
  4773. /**
  4774. * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
  4775. * @phba: pointer to lpfc hba data structure.
  4776. *
  4777. * This routine is invoked to create the bootstrap mailbox
  4778. * region consistent with the SLI-4 interface spec. This
  4779. * routine allocates all memory necessary to communicate
  4780. * mailbox commands to the port and sets up all alignment
  4781. * needs. No locks are expected to be held when calling
  4782. * this routine.
  4783. *
  4784. * Return codes
  4785. * 0 - successful
  4786. * ENOMEM - could not allocated memory.
  4787. **/
  4788. static int
  4789. lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
  4790. {
  4791. uint32_t bmbx_size;
  4792. struct lpfc_dmabuf *dmabuf;
  4793. struct dma_address *dma_address;
  4794. uint32_t pa_addr;
  4795. uint64_t phys_addr;
  4796. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4797. if (!dmabuf)
  4798. return -ENOMEM;
  4799. /*
  4800. * The bootstrap mailbox region is comprised of 2 parts
  4801. * plus an alignment restriction of 16 bytes.
  4802. */
  4803. bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
  4804. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4805. bmbx_size,
  4806. &dmabuf->phys,
  4807. GFP_KERNEL);
  4808. if (!dmabuf->virt) {
  4809. kfree(dmabuf);
  4810. return -ENOMEM;
  4811. }
  4812. memset(dmabuf->virt, 0, bmbx_size);
  4813. /*
  4814. * Initialize the bootstrap mailbox pointers now so that the register
  4815. * operations are simple later. The mailbox dma address is required
  4816. * to be 16-byte aligned. Also align the virtual memory as each
  4817. * maibox is copied into the bmbx mailbox region before issuing the
  4818. * command to the port.
  4819. */
  4820. phba->sli4_hba.bmbx.dmabuf = dmabuf;
  4821. phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
  4822. phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
  4823. LPFC_ALIGN_16_BYTE);
  4824. phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
  4825. LPFC_ALIGN_16_BYTE);
  4826. /*
  4827. * Set the high and low physical addresses now. The SLI4 alignment
  4828. * requirement is 16 bytes and the mailbox is posted to the port
  4829. * as two 30-bit addresses. The other data is a bit marking whether
  4830. * the 30-bit address is the high or low address.
  4831. * Upcast bmbx aphys to 64bits so shift instruction compiles
  4832. * clean on 32 bit machines.
  4833. */
  4834. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4835. phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
  4836. pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
  4837. dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
  4838. LPFC_BMBX_BIT1_ADDR_HI);
  4839. pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
  4840. dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
  4841. LPFC_BMBX_BIT1_ADDR_LO);
  4842. return 0;
  4843. }
  4844. /**
  4845. * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
  4846. * @phba: pointer to lpfc hba data structure.
  4847. *
  4848. * This routine is invoked to teardown the bootstrap mailbox
  4849. * region and release all host resources. This routine requires
  4850. * the caller to ensure all mailbox commands recovered, no
  4851. * additional mailbox comands are sent, and interrupts are disabled
  4852. * before calling this routine.
  4853. *
  4854. **/
  4855. static void
  4856. lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
  4857. {
  4858. dma_free_coherent(&phba->pcidev->dev,
  4859. phba->sli4_hba.bmbx.bmbx_size,
  4860. phba->sli4_hba.bmbx.dmabuf->virt,
  4861. phba->sli4_hba.bmbx.dmabuf->phys);
  4862. kfree(phba->sli4_hba.bmbx.dmabuf);
  4863. memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
  4864. }
  4865. /**
  4866. * lpfc_sli4_read_config - Get the config parameters.
  4867. * @phba: pointer to lpfc hba data structure.
  4868. *
  4869. * This routine is invoked to read the configuration parameters from the HBA.
  4870. * The configuration parameters are used to set the base and maximum values
  4871. * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
  4872. * allocation for the port.
  4873. *
  4874. * Return codes
  4875. * 0 - successful
  4876. * ENOMEM - No availble memory
  4877. * EIO - The mailbox failed to complete successfully.
  4878. **/
  4879. static int
  4880. lpfc_sli4_read_config(struct lpfc_hba *phba)
  4881. {
  4882. LPFC_MBOXQ_t *pmb;
  4883. struct lpfc_mbx_read_config *rd_config;
  4884. uint32_t rc = 0;
  4885. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4886. if (!pmb) {
  4887. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4888. "2011 Unable to allocate memory for issuing "
  4889. "SLI_CONFIG_SPECIAL mailbox command\n");
  4890. return -ENOMEM;
  4891. }
  4892. lpfc_read_config(phba, pmb);
  4893. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  4894. if (rc != MBX_SUCCESS) {
  4895. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4896. "2012 Mailbox failed , mbxCmd x%x "
  4897. "READ_CONFIG, mbxStatus x%x\n",
  4898. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  4899. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  4900. rc = -EIO;
  4901. } else {
  4902. rd_config = &pmb->u.mqe.un.rd_config;
  4903. phba->sli4_hba.max_cfg_param.max_xri =
  4904. bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
  4905. phba->sli4_hba.max_cfg_param.xri_base =
  4906. bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
  4907. phba->sli4_hba.max_cfg_param.max_vpi =
  4908. bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
  4909. phba->sli4_hba.max_cfg_param.vpi_base =
  4910. bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
  4911. phba->sli4_hba.max_cfg_param.max_rpi =
  4912. bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
  4913. phba->sli4_hba.max_cfg_param.rpi_base =
  4914. bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
  4915. phba->sli4_hba.max_cfg_param.max_vfi =
  4916. bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
  4917. phba->sli4_hba.max_cfg_param.vfi_base =
  4918. bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
  4919. phba->sli4_hba.max_cfg_param.max_fcfi =
  4920. bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
  4921. phba->sli4_hba.max_cfg_param.fcfi_base =
  4922. bf_get(lpfc_mbx_rd_conf_fcfi_base, rd_config);
  4923. phba->sli4_hba.max_cfg_param.max_eq =
  4924. bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
  4925. phba->sli4_hba.max_cfg_param.max_rq =
  4926. bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
  4927. phba->sli4_hba.max_cfg_param.max_wq =
  4928. bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
  4929. phba->sli4_hba.max_cfg_param.max_cq =
  4930. bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
  4931. phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
  4932. phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
  4933. phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
  4934. phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
  4935. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
  4936. phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
  4937. (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
  4938. phba->max_vports = phba->max_vpi;
  4939. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4940. "2003 cfg params XRI(B:%d M:%d), "
  4941. "VPI(B:%d M:%d) "
  4942. "VFI(B:%d M:%d) "
  4943. "RPI(B:%d M:%d) "
  4944. "FCFI(B:%d M:%d)\n",
  4945. phba->sli4_hba.max_cfg_param.xri_base,
  4946. phba->sli4_hba.max_cfg_param.max_xri,
  4947. phba->sli4_hba.max_cfg_param.vpi_base,
  4948. phba->sli4_hba.max_cfg_param.max_vpi,
  4949. phba->sli4_hba.max_cfg_param.vfi_base,
  4950. phba->sli4_hba.max_cfg_param.max_vfi,
  4951. phba->sli4_hba.max_cfg_param.rpi_base,
  4952. phba->sli4_hba.max_cfg_param.max_rpi,
  4953. phba->sli4_hba.max_cfg_param.fcfi_base,
  4954. phba->sli4_hba.max_cfg_param.max_fcfi);
  4955. }
  4956. mempool_free(pmb, phba->mbox_mem_pool);
  4957. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  4958. if (phba->cfg_hba_queue_depth > (phba->sli4_hba.max_cfg_param.max_xri))
  4959. phba->cfg_hba_queue_depth =
  4960. phba->sli4_hba.max_cfg_param.max_xri;
  4961. return rc;
  4962. }
  4963. /**
  4964. * lpfc_dev_endian_order_setup - Notify the port of the host's endian order.
  4965. * @phba: pointer to lpfc hba data structure.
  4966. *
  4967. * This routine is invoked to setup the host-side endian order to the
  4968. * HBA consistent with the SLI-4 interface spec.
  4969. *
  4970. * Return codes
  4971. * 0 - successful
  4972. * ENOMEM - No availble memory
  4973. * EIO - The mailbox failed to complete successfully.
  4974. **/
  4975. static int
  4976. lpfc_setup_endian_order(struct lpfc_hba *phba)
  4977. {
  4978. LPFC_MBOXQ_t *mboxq;
  4979. uint32_t rc = 0;
  4980. uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
  4981. HOST_ENDIAN_HIGH_WORD1};
  4982. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4983. if (!mboxq) {
  4984. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4985. "0492 Unable to allocate memory for issuing "
  4986. "SLI_CONFIG_SPECIAL mailbox command\n");
  4987. return -ENOMEM;
  4988. }
  4989. /*
  4990. * The SLI4_CONFIG_SPECIAL mailbox command requires the first two
  4991. * words to contain special data values and no other data.
  4992. */
  4993. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  4994. memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
  4995. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4996. if (rc != MBX_SUCCESS) {
  4997. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4998. "0493 SLI_CONFIG_SPECIAL mailbox failed with "
  4999. "status x%x\n",
  5000. rc);
  5001. rc = -EIO;
  5002. }
  5003. mempool_free(mboxq, phba->mbox_mem_pool);
  5004. return rc;
  5005. }
  5006. /**
  5007. * lpfc_sli4_queue_create - Create all the SLI4 queues
  5008. * @phba: pointer to lpfc hba data structure.
  5009. *
  5010. * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
  5011. * operation. For each SLI4 queue type, the parameters such as queue entry
  5012. * count (queue depth) shall be taken from the module parameter. For now,
  5013. * we just use some constant number as place holder.
  5014. *
  5015. * Return codes
  5016. * 0 - successful
  5017. * ENOMEM - No availble memory
  5018. * EIO - The mailbox failed to complete successfully.
  5019. **/
  5020. static int
  5021. lpfc_sli4_queue_create(struct lpfc_hba *phba)
  5022. {
  5023. struct lpfc_queue *qdesc;
  5024. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  5025. int cfg_fcp_wq_count;
  5026. int cfg_fcp_eq_count;
  5027. /*
  5028. * Sanity check for confiugred queue parameters against the run-time
  5029. * device parameters
  5030. */
  5031. /* Sanity check on FCP fast-path WQ parameters */
  5032. cfg_fcp_wq_count = phba->cfg_fcp_wq_count;
  5033. if (cfg_fcp_wq_count >
  5034. (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) {
  5035. cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq -
  5036. LPFC_SP_WQN_DEF;
  5037. if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) {
  5038. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5039. "2581 Not enough WQs (%d) from "
  5040. "the pci function for supporting "
  5041. "FCP WQs (%d)\n",
  5042. phba->sli4_hba.max_cfg_param.max_wq,
  5043. phba->cfg_fcp_wq_count);
  5044. goto out_error;
  5045. }
  5046. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5047. "2582 Not enough WQs (%d) from the pci "
  5048. "function for supporting the requested "
  5049. "FCP WQs (%d), the actual FCP WQs can "
  5050. "be supported: %d\n",
  5051. phba->sli4_hba.max_cfg_param.max_wq,
  5052. phba->cfg_fcp_wq_count, cfg_fcp_wq_count);
  5053. }
  5054. /* The actual number of FCP work queues adopted */
  5055. phba->cfg_fcp_wq_count = cfg_fcp_wq_count;
  5056. /* Sanity check on FCP fast-path EQ parameters */
  5057. cfg_fcp_eq_count = phba->cfg_fcp_eq_count;
  5058. if (cfg_fcp_eq_count >
  5059. (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) {
  5060. cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq -
  5061. LPFC_SP_EQN_DEF;
  5062. if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) {
  5063. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5064. "2574 Not enough EQs (%d) from the "
  5065. "pci function for supporting FCP "
  5066. "EQs (%d)\n",
  5067. phba->sli4_hba.max_cfg_param.max_eq,
  5068. phba->cfg_fcp_eq_count);
  5069. goto out_error;
  5070. }
  5071. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5072. "2575 Not enough EQs (%d) from the pci "
  5073. "function for supporting the requested "
  5074. "FCP EQs (%d), the actual FCP EQs can "
  5075. "be supported: %d\n",
  5076. phba->sli4_hba.max_cfg_param.max_eq,
  5077. phba->cfg_fcp_eq_count, cfg_fcp_eq_count);
  5078. }
  5079. /* It does not make sense to have more EQs than WQs */
  5080. if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) {
  5081. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5082. "2593 The FCP EQ count(%d) cannot be greater "
  5083. "than the FCP WQ count(%d), limiting the "
  5084. "FCP EQ count to %d\n", cfg_fcp_eq_count,
  5085. phba->cfg_fcp_wq_count,
  5086. phba->cfg_fcp_wq_count);
  5087. cfg_fcp_eq_count = phba->cfg_fcp_wq_count;
  5088. }
  5089. /* The actual number of FCP event queues adopted */
  5090. phba->cfg_fcp_eq_count = cfg_fcp_eq_count;
  5091. /* The overall number of event queues used */
  5092. phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF;
  5093. /*
  5094. * Create Event Queues (EQs)
  5095. */
  5096. /* Get EQ depth from module parameter, fake the default for now */
  5097. phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
  5098. phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
  5099. /* Create slow path event queue */
  5100. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  5101. phba->sli4_hba.eq_ecount);
  5102. if (!qdesc) {
  5103. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5104. "0496 Failed allocate slow-path EQ\n");
  5105. goto out_error;
  5106. }
  5107. phba->sli4_hba.sp_eq = qdesc;
  5108. /* Create fast-path FCP Event Queue(s) */
  5109. phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
  5110. phba->cfg_fcp_eq_count), GFP_KERNEL);
  5111. if (!phba->sli4_hba.fp_eq) {
  5112. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5113. "2576 Failed allocate memory for fast-path "
  5114. "EQ record array\n");
  5115. goto out_free_sp_eq;
  5116. }
  5117. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  5118. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  5119. phba->sli4_hba.eq_ecount);
  5120. if (!qdesc) {
  5121. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5122. "0497 Failed allocate fast-path EQ\n");
  5123. goto out_free_fp_eq;
  5124. }
  5125. phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc;
  5126. }
  5127. /*
  5128. * Create Complete Queues (CQs)
  5129. */
  5130. /* Get CQ depth from module parameter, fake the default for now */
  5131. phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
  5132. phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
  5133. /* Create slow-path Mailbox Command Complete Queue */
  5134. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  5135. phba->sli4_hba.cq_ecount);
  5136. if (!qdesc) {
  5137. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5138. "0500 Failed allocate slow-path mailbox CQ\n");
  5139. goto out_free_fp_eq;
  5140. }
  5141. phba->sli4_hba.mbx_cq = qdesc;
  5142. /* Create slow-path ELS Complete Queue */
  5143. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  5144. phba->sli4_hba.cq_ecount);
  5145. if (!qdesc) {
  5146. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5147. "0501 Failed allocate slow-path ELS CQ\n");
  5148. goto out_free_mbx_cq;
  5149. }
  5150. phba->sli4_hba.els_cq = qdesc;
  5151. /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
  5152. phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
  5153. phba->cfg_fcp_eq_count), GFP_KERNEL);
  5154. if (!phba->sli4_hba.fcp_cq) {
  5155. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5156. "2577 Failed allocate memory for fast-path "
  5157. "CQ record array\n");
  5158. goto out_free_els_cq;
  5159. }
  5160. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
  5161. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  5162. phba->sli4_hba.cq_ecount);
  5163. if (!qdesc) {
  5164. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5165. "0499 Failed allocate fast-path FCP "
  5166. "CQ (%d)\n", fcp_cqidx);
  5167. goto out_free_fcp_cq;
  5168. }
  5169. phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc;
  5170. }
  5171. /* Create Mailbox Command Queue */
  5172. phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
  5173. phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
  5174. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
  5175. phba->sli4_hba.mq_ecount);
  5176. if (!qdesc) {
  5177. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5178. "0505 Failed allocate slow-path MQ\n");
  5179. goto out_free_fcp_cq;
  5180. }
  5181. phba->sli4_hba.mbx_wq = qdesc;
  5182. /*
  5183. * Create all the Work Queues (WQs)
  5184. */
  5185. phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
  5186. phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
  5187. /* Create slow-path ELS Work Queue */
  5188. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  5189. phba->sli4_hba.wq_ecount);
  5190. if (!qdesc) {
  5191. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5192. "0504 Failed allocate slow-path ELS WQ\n");
  5193. goto out_free_mbx_wq;
  5194. }
  5195. phba->sli4_hba.els_wq = qdesc;
  5196. /* Create fast-path FCP Work Queue(s) */
  5197. phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
  5198. phba->cfg_fcp_wq_count), GFP_KERNEL);
  5199. if (!phba->sli4_hba.fcp_wq) {
  5200. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5201. "2578 Failed allocate memory for fast-path "
  5202. "WQ record array\n");
  5203. goto out_free_els_wq;
  5204. }
  5205. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
  5206. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  5207. phba->sli4_hba.wq_ecount);
  5208. if (!qdesc) {
  5209. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5210. "0503 Failed allocate fast-path FCP "
  5211. "WQ (%d)\n", fcp_wqidx);
  5212. goto out_free_fcp_wq;
  5213. }
  5214. phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc;
  5215. }
  5216. /*
  5217. * Create Receive Queue (RQ)
  5218. */
  5219. phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
  5220. phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
  5221. /* Create Receive Queue for header */
  5222. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  5223. phba->sli4_hba.rq_ecount);
  5224. if (!qdesc) {
  5225. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5226. "0506 Failed allocate receive HRQ\n");
  5227. goto out_free_fcp_wq;
  5228. }
  5229. phba->sli4_hba.hdr_rq = qdesc;
  5230. /* Create Receive Queue for data */
  5231. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  5232. phba->sli4_hba.rq_ecount);
  5233. if (!qdesc) {
  5234. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5235. "0507 Failed allocate receive DRQ\n");
  5236. goto out_free_hdr_rq;
  5237. }
  5238. phba->sli4_hba.dat_rq = qdesc;
  5239. return 0;
  5240. out_free_hdr_rq:
  5241. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  5242. phba->sli4_hba.hdr_rq = NULL;
  5243. out_free_fcp_wq:
  5244. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) {
  5245. lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]);
  5246. phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL;
  5247. }
  5248. kfree(phba->sli4_hba.fcp_wq);
  5249. out_free_els_wq:
  5250. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  5251. phba->sli4_hba.els_wq = NULL;
  5252. out_free_mbx_wq:
  5253. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  5254. phba->sli4_hba.mbx_wq = NULL;
  5255. out_free_fcp_cq:
  5256. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) {
  5257. lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]);
  5258. phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL;
  5259. }
  5260. kfree(phba->sli4_hba.fcp_cq);
  5261. out_free_els_cq:
  5262. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  5263. phba->sli4_hba.els_cq = NULL;
  5264. out_free_mbx_cq:
  5265. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  5266. phba->sli4_hba.mbx_cq = NULL;
  5267. out_free_fp_eq:
  5268. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) {
  5269. lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]);
  5270. phba->sli4_hba.fp_eq[fcp_eqidx] = NULL;
  5271. }
  5272. kfree(phba->sli4_hba.fp_eq);
  5273. out_free_sp_eq:
  5274. lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
  5275. phba->sli4_hba.sp_eq = NULL;
  5276. out_error:
  5277. return -ENOMEM;
  5278. }
  5279. /**
  5280. * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
  5281. * @phba: pointer to lpfc hba data structure.
  5282. *
  5283. * This routine is invoked to release all the SLI4 queues with the FCoE HBA
  5284. * operation.
  5285. *
  5286. * Return codes
  5287. * 0 - successful
  5288. * ENOMEM - No availble memory
  5289. * EIO - The mailbox failed to complete successfully.
  5290. **/
  5291. static void
  5292. lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
  5293. {
  5294. int fcp_qidx;
  5295. /* Release mailbox command work queue */
  5296. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  5297. phba->sli4_hba.mbx_wq = NULL;
  5298. /* Release ELS work queue */
  5299. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  5300. phba->sli4_hba.els_wq = NULL;
  5301. /* Release FCP work queue */
  5302. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
  5303. lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]);
  5304. kfree(phba->sli4_hba.fcp_wq);
  5305. phba->sli4_hba.fcp_wq = NULL;
  5306. /* Release unsolicited receive queue */
  5307. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  5308. phba->sli4_hba.hdr_rq = NULL;
  5309. lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
  5310. phba->sli4_hba.dat_rq = NULL;
  5311. /* Release ELS complete queue */
  5312. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  5313. phba->sli4_hba.els_cq = NULL;
  5314. /* Release mailbox command complete queue */
  5315. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  5316. phba->sli4_hba.mbx_cq = NULL;
  5317. /* Release FCP response complete queue */
  5318. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5319. lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]);
  5320. kfree(phba->sli4_hba.fcp_cq);
  5321. phba->sli4_hba.fcp_cq = NULL;
  5322. /* Release fast-path event queue */
  5323. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5324. lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
  5325. kfree(phba->sli4_hba.fp_eq);
  5326. phba->sli4_hba.fp_eq = NULL;
  5327. /* Release slow-path event queue */
  5328. lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
  5329. phba->sli4_hba.sp_eq = NULL;
  5330. return;
  5331. }
  5332. /**
  5333. * lpfc_sli4_queue_setup - Set up all the SLI4 queues
  5334. * @phba: pointer to lpfc hba data structure.
  5335. *
  5336. * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
  5337. * operation.
  5338. *
  5339. * Return codes
  5340. * 0 - successful
  5341. * ENOMEM - No availble memory
  5342. * EIO - The mailbox failed to complete successfully.
  5343. **/
  5344. int
  5345. lpfc_sli4_queue_setup(struct lpfc_hba *phba)
  5346. {
  5347. int rc = -ENOMEM;
  5348. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  5349. int fcp_cq_index = 0;
  5350. /*
  5351. * Set up Event Queues (EQs)
  5352. */
  5353. /* Set up slow-path event queue */
  5354. if (!phba->sli4_hba.sp_eq) {
  5355. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5356. "0520 Slow-path EQ not allocated\n");
  5357. goto out_error;
  5358. }
  5359. rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq,
  5360. LPFC_SP_DEF_IMAX);
  5361. if (rc) {
  5362. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5363. "0521 Failed setup of slow-path EQ: "
  5364. "rc = 0x%x\n", rc);
  5365. goto out_error;
  5366. }
  5367. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5368. "2583 Slow-path EQ setup: queue-id=%d\n",
  5369. phba->sli4_hba.sp_eq->queue_id);
  5370. /* Set up fast-path event queue */
  5371. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  5372. if (!phba->sli4_hba.fp_eq[fcp_eqidx]) {
  5373. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5374. "0522 Fast-path EQ (%d) not "
  5375. "allocated\n", fcp_eqidx);
  5376. goto out_destroy_fp_eq;
  5377. }
  5378. rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx],
  5379. phba->cfg_fcp_imax);
  5380. if (rc) {
  5381. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5382. "0523 Failed setup of fast-path EQ "
  5383. "(%d), rc = 0x%x\n", fcp_eqidx, rc);
  5384. goto out_destroy_fp_eq;
  5385. }
  5386. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5387. "2584 Fast-path EQ setup: "
  5388. "queue[%d]-id=%d\n", fcp_eqidx,
  5389. phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id);
  5390. }
  5391. /*
  5392. * Set up Complete Queues (CQs)
  5393. */
  5394. /* Set up slow-path MBOX Complete Queue as the first CQ */
  5395. if (!phba->sli4_hba.mbx_cq) {
  5396. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5397. "0528 Mailbox CQ not allocated\n");
  5398. goto out_destroy_fp_eq;
  5399. }
  5400. rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq,
  5401. LPFC_MCQ, LPFC_MBOX);
  5402. if (rc) {
  5403. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5404. "0529 Failed setup of slow-path mailbox CQ: "
  5405. "rc = 0x%x\n", rc);
  5406. goto out_destroy_fp_eq;
  5407. }
  5408. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5409. "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
  5410. phba->sli4_hba.mbx_cq->queue_id,
  5411. phba->sli4_hba.sp_eq->queue_id);
  5412. /* Set up slow-path ELS Complete Queue */
  5413. if (!phba->sli4_hba.els_cq) {
  5414. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5415. "0530 ELS CQ not allocated\n");
  5416. goto out_destroy_mbx_cq;
  5417. }
  5418. rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq,
  5419. LPFC_WCQ, LPFC_ELS);
  5420. if (rc) {
  5421. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5422. "0531 Failed setup of slow-path ELS CQ: "
  5423. "rc = 0x%x\n", rc);
  5424. goto out_destroy_mbx_cq;
  5425. }
  5426. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5427. "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
  5428. phba->sli4_hba.els_cq->queue_id,
  5429. phba->sli4_hba.sp_eq->queue_id);
  5430. /* Set up fast-path FCP Response Complete Queue */
  5431. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
  5432. if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
  5433. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5434. "0526 Fast-path FCP CQ (%d) not "
  5435. "allocated\n", fcp_cqidx);
  5436. goto out_destroy_fcp_cq;
  5437. }
  5438. rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
  5439. phba->sli4_hba.fp_eq[fcp_cqidx],
  5440. LPFC_WCQ, LPFC_FCP);
  5441. if (rc) {
  5442. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5443. "0527 Failed setup of fast-path FCP "
  5444. "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
  5445. goto out_destroy_fcp_cq;
  5446. }
  5447. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5448. "2588 FCP CQ setup: cq[%d]-id=%d, "
  5449. "parent eq[%d]-id=%d\n",
  5450. fcp_cqidx,
  5451. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
  5452. fcp_cqidx,
  5453. phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id);
  5454. }
  5455. /*
  5456. * Set up all the Work Queues (WQs)
  5457. */
  5458. /* Set up Mailbox Command Queue */
  5459. if (!phba->sli4_hba.mbx_wq) {
  5460. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5461. "0538 Slow-path MQ not allocated\n");
  5462. goto out_destroy_fcp_cq;
  5463. }
  5464. rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
  5465. phba->sli4_hba.mbx_cq, LPFC_MBOX);
  5466. if (rc) {
  5467. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5468. "0539 Failed setup of slow-path MQ: "
  5469. "rc = 0x%x\n", rc);
  5470. goto out_destroy_fcp_cq;
  5471. }
  5472. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5473. "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
  5474. phba->sli4_hba.mbx_wq->queue_id,
  5475. phba->sli4_hba.mbx_cq->queue_id);
  5476. /* Set up slow-path ELS Work Queue */
  5477. if (!phba->sli4_hba.els_wq) {
  5478. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5479. "0536 Slow-path ELS WQ not allocated\n");
  5480. goto out_destroy_mbx_wq;
  5481. }
  5482. rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
  5483. phba->sli4_hba.els_cq, LPFC_ELS);
  5484. if (rc) {
  5485. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5486. "0537 Failed setup of slow-path ELS WQ: "
  5487. "rc = 0x%x\n", rc);
  5488. goto out_destroy_mbx_wq;
  5489. }
  5490. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5491. "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
  5492. phba->sli4_hba.els_wq->queue_id,
  5493. phba->sli4_hba.els_cq->queue_id);
  5494. /* Set up fast-path FCP Work Queue */
  5495. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
  5496. if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
  5497. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5498. "0534 Fast-path FCP WQ (%d) not "
  5499. "allocated\n", fcp_wqidx);
  5500. goto out_destroy_fcp_wq;
  5501. }
  5502. rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
  5503. phba->sli4_hba.fcp_cq[fcp_cq_index],
  5504. LPFC_FCP);
  5505. if (rc) {
  5506. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5507. "0535 Failed setup of fast-path FCP "
  5508. "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
  5509. goto out_destroy_fcp_wq;
  5510. }
  5511. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5512. "2591 FCP WQ setup: wq[%d]-id=%d, "
  5513. "parent cq[%d]-id=%d\n",
  5514. fcp_wqidx,
  5515. phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
  5516. fcp_cq_index,
  5517. phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id);
  5518. /* Round robin FCP Work Queue's Completion Queue assignment */
  5519. fcp_cq_index = ((fcp_cq_index + 1) % phba->cfg_fcp_eq_count);
  5520. }
  5521. /*
  5522. * Create Receive Queue (RQ)
  5523. */
  5524. if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
  5525. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5526. "0540 Receive Queue not allocated\n");
  5527. goto out_destroy_fcp_wq;
  5528. }
  5529. rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  5530. phba->sli4_hba.els_cq, LPFC_USOL);
  5531. if (rc) {
  5532. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5533. "0541 Failed setup of Receive Queue: "
  5534. "rc = 0x%x\n", rc);
  5535. goto out_destroy_fcp_wq;
  5536. }
  5537. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5538. "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
  5539. "parent cq-id=%d\n",
  5540. phba->sli4_hba.hdr_rq->queue_id,
  5541. phba->sli4_hba.dat_rq->queue_id,
  5542. phba->sli4_hba.els_cq->queue_id);
  5543. return 0;
  5544. out_destroy_fcp_wq:
  5545. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
  5546. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
  5547. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  5548. out_destroy_mbx_wq:
  5549. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  5550. out_destroy_fcp_cq:
  5551. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
  5552. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
  5553. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  5554. out_destroy_mbx_cq:
  5555. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  5556. out_destroy_fp_eq:
  5557. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
  5558. lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]);
  5559. lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
  5560. out_error:
  5561. return rc;
  5562. }
  5563. /**
  5564. * lpfc_sli4_queue_unset - Unset all the SLI4 queues
  5565. * @phba: pointer to lpfc hba data structure.
  5566. *
  5567. * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
  5568. * operation.
  5569. *
  5570. * Return codes
  5571. * 0 - successful
  5572. * ENOMEM - No availble memory
  5573. * EIO - The mailbox failed to complete successfully.
  5574. **/
  5575. void
  5576. lpfc_sli4_queue_unset(struct lpfc_hba *phba)
  5577. {
  5578. int fcp_qidx;
  5579. /* Unset mailbox command work queue */
  5580. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  5581. /* Unset ELS work queue */
  5582. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  5583. /* Unset unsolicited receive queue */
  5584. lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
  5585. /* Unset FCP work queue */
  5586. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
  5587. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
  5588. /* Unset mailbox command complete queue */
  5589. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  5590. /* Unset ELS complete queue */
  5591. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  5592. /* Unset FCP response complete queue */
  5593. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5594. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
  5595. /* Unset fast-path event queue */
  5596. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5597. lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]);
  5598. /* Unset slow-path event queue */
  5599. lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
  5600. }
  5601. /**
  5602. * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
  5603. * @phba: pointer to lpfc hba data structure.
  5604. *
  5605. * This routine is invoked to allocate and set up a pool of completion queue
  5606. * events. The body of the completion queue event is a completion queue entry
  5607. * CQE. For now, this pool is used for the interrupt service routine to queue
  5608. * the following HBA completion queue events for the worker thread to process:
  5609. * - Mailbox asynchronous events
  5610. * - Receive queue completion unsolicited events
  5611. * Later, this can be used for all the slow-path events.
  5612. *
  5613. * Return codes
  5614. * 0 - successful
  5615. * -ENOMEM - No availble memory
  5616. **/
  5617. static int
  5618. lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
  5619. {
  5620. struct lpfc_cq_event *cq_event;
  5621. int i;
  5622. for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
  5623. cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
  5624. if (!cq_event)
  5625. goto out_pool_create_fail;
  5626. list_add_tail(&cq_event->list,
  5627. &phba->sli4_hba.sp_cqe_event_pool);
  5628. }
  5629. return 0;
  5630. out_pool_create_fail:
  5631. lpfc_sli4_cq_event_pool_destroy(phba);
  5632. return -ENOMEM;
  5633. }
  5634. /**
  5635. * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
  5636. * @phba: pointer to lpfc hba data structure.
  5637. *
  5638. * This routine is invoked to free the pool of completion queue events at
  5639. * driver unload time. Note that, it is the responsibility of the driver
  5640. * cleanup routine to free all the outstanding completion-queue events
  5641. * allocated from this pool back into the pool before invoking this routine
  5642. * to destroy the pool.
  5643. **/
  5644. static void
  5645. lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
  5646. {
  5647. struct lpfc_cq_event *cq_event, *next_cq_event;
  5648. list_for_each_entry_safe(cq_event, next_cq_event,
  5649. &phba->sli4_hba.sp_cqe_event_pool, list) {
  5650. list_del(&cq_event->list);
  5651. kfree(cq_event);
  5652. }
  5653. }
  5654. /**
  5655. * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  5656. * @phba: pointer to lpfc hba data structure.
  5657. *
  5658. * This routine is the lock free version of the API invoked to allocate a
  5659. * completion-queue event from the free pool.
  5660. *
  5661. * Return: Pointer to the newly allocated completion-queue event if successful
  5662. * NULL otherwise.
  5663. **/
  5664. struct lpfc_cq_event *
  5665. __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  5666. {
  5667. struct lpfc_cq_event *cq_event = NULL;
  5668. list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
  5669. struct lpfc_cq_event, list);
  5670. return cq_event;
  5671. }
  5672. /**
  5673. * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  5674. * @phba: pointer to lpfc hba data structure.
  5675. *
  5676. * This routine is the lock version of the API invoked to allocate a
  5677. * completion-queue event from the free pool.
  5678. *
  5679. * Return: Pointer to the newly allocated completion-queue event if successful
  5680. * NULL otherwise.
  5681. **/
  5682. struct lpfc_cq_event *
  5683. lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  5684. {
  5685. struct lpfc_cq_event *cq_event;
  5686. unsigned long iflags;
  5687. spin_lock_irqsave(&phba->hbalock, iflags);
  5688. cq_event = __lpfc_sli4_cq_event_alloc(phba);
  5689. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5690. return cq_event;
  5691. }
  5692. /**
  5693. * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  5694. * @phba: pointer to lpfc hba data structure.
  5695. * @cq_event: pointer to the completion queue event to be freed.
  5696. *
  5697. * This routine is the lock free version of the API invoked to release a
  5698. * completion-queue event back into the free pool.
  5699. **/
  5700. void
  5701. __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  5702. struct lpfc_cq_event *cq_event)
  5703. {
  5704. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
  5705. }
  5706. /**
  5707. * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  5708. * @phba: pointer to lpfc hba data structure.
  5709. * @cq_event: pointer to the completion queue event to be freed.
  5710. *
  5711. * This routine is the lock version of the API invoked to release a
  5712. * completion-queue event back into the free pool.
  5713. **/
  5714. void
  5715. lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  5716. struct lpfc_cq_event *cq_event)
  5717. {
  5718. unsigned long iflags;
  5719. spin_lock_irqsave(&phba->hbalock, iflags);
  5720. __lpfc_sli4_cq_event_release(phba, cq_event);
  5721. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5722. }
  5723. /**
  5724. * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
  5725. * @phba: pointer to lpfc hba data structure.
  5726. *
  5727. * This routine is to free all the pending completion-queue events to the
  5728. * back into the free pool for device reset.
  5729. **/
  5730. static void
  5731. lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
  5732. {
  5733. LIST_HEAD(cqelist);
  5734. struct lpfc_cq_event *cqe;
  5735. unsigned long iflags;
  5736. /* Retrieve all the pending WCQEs from pending WCQE lists */
  5737. spin_lock_irqsave(&phba->hbalock, iflags);
  5738. /* Pending FCP XRI abort events */
  5739. list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  5740. &cqelist);
  5741. /* Pending ELS XRI abort events */
  5742. list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  5743. &cqelist);
  5744. /* Pending asynnc events */
  5745. list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
  5746. &cqelist);
  5747. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5748. while (!list_empty(&cqelist)) {
  5749. list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
  5750. lpfc_sli4_cq_event_release(phba, cqe);
  5751. }
  5752. }
  5753. /**
  5754. * lpfc_pci_function_reset - Reset pci function.
  5755. * @phba: pointer to lpfc hba data structure.
  5756. *
  5757. * This routine is invoked to request a PCI function reset. It will destroys
  5758. * all resources assigned to the PCI function which originates this request.
  5759. *
  5760. * Return codes
  5761. * 0 - successful
  5762. * ENOMEM - No availble memory
  5763. * EIO - The mailbox failed to complete successfully.
  5764. **/
  5765. int
  5766. lpfc_pci_function_reset(struct lpfc_hba *phba)
  5767. {
  5768. LPFC_MBOXQ_t *mboxq;
  5769. uint32_t rc = 0;
  5770. uint32_t shdr_status, shdr_add_status;
  5771. union lpfc_sli4_cfg_shdr *shdr;
  5772. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5773. if (!mboxq) {
  5774. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5775. "0494 Unable to allocate memory for issuing "
  5776. "SLI_FUNCTION_RESET mailbox command\n");
  5777. return -ENOMEM;
  5778. }
  5779. /* Set up PCI function reset SLI4_CONFIG mailbox-ioctl command */
  5780. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  5781. LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
  5782. LPFC_SLI4_MBX_EMBED);
  5783. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5784. shdr = (union lpfc_sli4_cfg_shdr *)
  5785. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  5786. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  5787. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  5788. if (rc != MBX_TIMEOUT)
  5789. mempool_free(mboxq, phba->mbox_mem_pool);
  5790. if (shdr_status || shdr_add_status || rc) {
  5791. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5792. "0495 SLI_FUNCTION_RESET mailbox failed with "
  5793. "status x%x add_status x%x, mbx status x%x\n",
  5794. shdr_status, shdr_add_status, rc);
  5795. rc = -ENXIO;
  5796. }
  5797. return rc;
  5798. }
  5799. /**
  5800. * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
  5801. * @phba: pointer to lpfc hba data structure.
  5802. * @cnt: number of nop mailbox commands to send.
  5803. *
  5804. * This routine is invoked to send a number @cnt of NOP mailbox command and
  5805. * wait for each command to complete.
  5806. *
  5807. * Return: the number of NOP mailbox command completed.
  5808. **/
  5809. static int
  5810. lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
  5811. {
  5812. LPFC_MBOXQ_t *mboxq;
  5813. int length, cmdsent;
  5814. uint32_t mbox_tmo;
  5815. uint32_t rc = 0;
  5816. uint32_t shdr_status, shdr_add_status;
  5817. union lpfc_sli4_cfg_shdr *shdr;
  5818. if (cnt == 0) {
  5819. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5820. "2518 Requested to send 0 NOP mailbox cmd\n");
  5821. return cnt;
  5822. }
  5823. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5824. if (!mboxq) {
  5825. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5826. "2519 Unable to allocate memory for issuing "
  5827. "NOP mailbox command\n");
  5828. return 0;
  5829. }
  5830. /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
  5831. length = (sizeof(struct lpfc_mbx_nop) -
  5832. sizeof(struct lpfc_sli4_cfg_mhdr));
  5833. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  5834. LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED);
  5835. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  5836. for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
  5837. if (!phba->sli4_hba.intr_enable)
  5838. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5839. else
  5840. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  5841. if (rc == MBX_TIMEOUT)
  5842. break;
  5843. /* Check return status */
  5844. shdr = (union lpfc_sli4_cfg_shdr *)
  5845. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  5846. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  5847. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  5848. &shdr->response);
  5849. if (shdr_status || shdr_add_status || rc) {
  5850. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5851. "2520 NOP mailbox command failed "
  5852. "status x%x add_status x%x mbx "
  5853. "status x%x\n", shdr_status,
  5854. shdr_add_status, rc);
  5855. break;
  5856. }
  5857. }
  5858. if (rc != MBX_TIMEOUT)
  5859. mempool_free(mboxq, phba->mbox_mem_pool);
  5860. return cmdsent;
  5861. }
  5862. /**
  5863. * lpfc_sli4_fcfi_unreg - Unregister fcfi to device
  5864. * @phba: pointer to lpfc hba data structure.
  5865. * @fcfi: fcf index.
  5866. *
  5867. * This routine is invoked to unregister a FCFI from device.
  5868. **/
  5869. void
  5870. lpfc_sli4_fcfi_unreg(struct lpfc_hba *phba, uint16_t fcfi)
  5871. {
  5872. LPFC_MBOXQ_t *mbox;
  5873. uint32_t mbox_tmo;
  5874. int rc;
  5875. unsigned long flags;
  5876. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5877. if (!mbox)
  5878. return;
  5879. lpfc_unreg_fcfi(mbox, fcfi);
  5880. if (!phba->sli4_hba.intr_enable)
  5881. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5882. else {
  5883. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  5884. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5885. }
  5886. if (rc != MBX_TIMEOUT)
  5887. mempool_free(mbox, phba->mbox_mem_pool);
  5888. if (rc != MBX_SUCCESS)
  5889. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5890. "2517 Unregister FCFI command failed "
  5891. "status %d, mbxStatus x%x\n", rc,
  5892. bf_get(lpfc_mqe_status, &mbox->u.mqe));
  5893. else {
  5894. spin_lock_irqsave(&phba->hbalock, flags);
  5895. /* Mark the FCFI is no longer registered */
  5896. phba->fcf.fcf_flag &=
  5897. ~(FCF_AVAILABLE | FCF_REGISTERED | FCF_SCAN_DONE);
  5898. spin_unlock_irqrestore(&phba->hbalock, flags);
  5899. }
  5900. }
  5901. /**
  5902. * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
  5903. * @phba: pointer to lpfc hba data structure.
  5904. *
  5905. * This routine is invoked to set up the PCI device memory space for device
  5906. * with SLI-4 interface spec.
  5907. *
  5908. * Return codes
  5909. * 0 - successful
  5910. * other values - error
  5911. **/
  5912. static int
  5913. lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
  5914. {
  5915. struct pci_dev *pdev;
  5916. unsigned long bar0map_len, bar1map_len, bar2map_len;
  5917. int error = -ENODEV;
  5918. /* Obtain PCI device reference */
  5919. if (!phba->pcidev)
  5920. return error;
  5921. else
  5922. pdev = phba->pcidev;
  5923. /* Set the device DMA mask size */
  5924. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  5925. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  5926. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  5927. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  5928. return error;
  5929. }
  5930. }
  5931. /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the
  5932. * number of bytes required by each mapping. They are actually
  5933. * mapping to the PCI BAR regions 0 or 1, 2, and 4 by the SLI4 device.
  5934. */
  5935. if (pci_resource_start(pdev, 0)) {
  5936. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  5937. bar0map_len = pci_resource_len(pdev, 0);
  5938. } else {
  5939. phba->pci_bar0_map = pci_resource_start(pdev, 1);
  5940. bar0map_len = pci_resource_len(pdev, 1);
  5941. }
  5942. phba->pci_bar1_map = pci_resource_start(pdev, 2);
  5943. bar1map_len = pci_resource_len(pdev, 2);
  5944. phba->pci_bar2_map = pci_resource_start(pdev, 4);
  5945. bar2map_len = pci_resource_len(pdev, 4);
  5946. /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */
  5947. phba->sli4_hba.conf_regs_memmap_p =
  5948. ioremap(phba->pci_bar0_map, bar0map_len);
  5949. if (!phba->sli4_hba.conf_regs_memmap_p) {
  5950. dev_printk(KERN_ERR, &pdev->dev,
  5951. "ioremap failed for SLI4 PCI config registers.\n");
  5952. goto out;
  5953. }
  5954. /* Map SLI4 HBA Control Register base to a kernel virtual address. */
  5955. phba->sli4_hba.ctrl_regs_memmap_p =
  5956. ioremap(phba->pci_bar1_map, bar1map_len);
  5957. if (!phba->sli4_hba.ctrl_regs_memmap_p) {
  5958. dev_printk(KERN_ERR, &pdev->dev,
  5959. "ioremap failed for SLI4 HBA control registers.\n");
  5960. goto out_iounmap_conf;
  5961. }
  5962. /* Map SLI4 HBA Doorbell Register base to a kernel virtual address. */
  5963. phba->sli4_hba.drbl_regs_memmap_p =
  5964. ioremap(phba->pci_bar2_map, bar2map_len);
  5965. if (!phba->sli4_hba.drbl_regs_memmap_p) {
  5966. dev_printk(KERN_ERR, &pdev->dev,
  5967. "ioremap failed for SLI4 HBA doorbell registers.\n");
  5968. goto out_iounmap_ctrl;
  5969. }
  5970. /* Set up BAR0 PCI config space register memory map */
  5971. lpfc_sli4_bar0_register_memmap(phba);
  5972. /* Set up BAR1 register memory map */
  5973. lpfc_sli4_bar1_register_memmap(phba);
  5974. /* Set up BAR2 register memory map */
  5975. error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
  5976. if (error)
  5977. goto out_iounmap_all;
  5978. return 0;
  5979. out_iounmap_all:
  5980. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  5981. out_iounmap_ctrl:
  5982. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  5983. out_iounmap_conf:
  5984. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  5985. out:
  5986. return error;
  5987. }
  5988. /**
  5989. * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
  5990. * @phba: pointer to lpfc hba data structure.
  5991. *
  5992. * This routine is invoked to unset the PCI device memory space for device
  5993. * with SLI-4 interface spec.
  5994. **/
  5995. static void
  5996. lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
  5997. {
  5998. struct pci_dev *pdev;
  5999. /* Obtain PCI device reference */
  6000. if (!phba->pcidev)
  6001. return;
  6002. else
  6003. pdev = phba->pcidev;
  6004. /* Free coherent DMA memory allocated */
  6005. /* Unmap I/O memory space */
  6006. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  6007. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  6008. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  6009. return;
  6010. }
  6011. /**
  6012. * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
  6013. * @phba: pointer to lpfc hba data structure.
  6014. *
  6015. * This routine is invoked to enable the MSI-X interrupt vectors to device
  6016. * with SLI-3 interface specs. The kernel function pci_enable_msix() is
  6017. * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
  6018. * invoked, enables either all or nothing, depending on the current
  6019. * availability of PCI vector resources. The device driver is responsible
  6020. * for calling the individual request_irq() to register each MSI-X vector
  6021. * with a interrupt handler, which is done in this function. Note that
  6022. * later when device is unloading, the driver should always call free_irq()
  6023. * on all MSI-X vectors it has done request_irq() on before calling
  6024. * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
  6025. * will be left with MSI-X enabled and leaks its vectors.
  6026. *
  6027. * Return codes
  6028. * 0 - successful
  6029. * other values - error
  6030. **/
  6031. static int
  6032. lpfc_sli_enable_msix(struct lpfc_hba *phba)
  6033. {
  6034. int rc, i;
  6035. LPFC_MBOXQ_t *pmb;
  6036. /* Set up MSI-X multi-message vectors */
  6037. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  6038. phba->msix_entries[i].entry = i;
  6039. /* Configure MSI-X capability structure */
  6040. rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
  6041. ARRAY_SIZE(phba->msix_entries));
  6042. if (rc) {
  6043. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6044. "0420 PCI enable MSI-X failed (%d)\n", rc);
  6045. goto msi_fail_out;
  6046. }
  6047. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  6048. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6049. "0477 MSI-X entry[%d]: vector=x%x "
  6050. "message=%d\n", i,
  6051. phba->msix_entries[i].vector,
  6052. phba->msix_entries[i].entry);
  6053. /*
  6054. * Assign MSI-X vectors to interrupt handlers
  6055. */
  6056. /* vector-0 is associated to slow-path handler */
  6057. rc = request_irq(phba->msix_entries[0].vector,
  6058. &lpfc_sli_sp_intr_handler, IRQF_SHARED,
  6059. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  6060. if (rc) {
  6061. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6062. "0421 MSI-X slow-path request_irq failed "
  6063. "(%d)\n", rc);
  6064. goto msi_fail_out;
  6065. }
  6066. /* vector-1 is associated to fast-path handler */
  6067. rc = request_irq(phba->msix_entries[1].vector,
  6068. &lpfc_sli_fp_intr_handler, IRQF_SHARED,
  6069. LPFC_FP_DRIVER_HANDLER_NAME, phba);
  6070. if (rc) {
  6071. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6072. "0429 MSI-X fast-path request_irq failed "
  6073. "(%d)\n", rc);
  6074. goto irq_fail_out;
  6075. }
  6076. /*
  6077. * Configure HBA MSI-X attention conditions to messages
  6078. */
  6079. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6080. if (!pmb) {
  6081. rc = -ENOMEM;
  6082. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6083. "0474 Unable to allocate memory for issuing "
  6084. "MBOX_CONFIG_MSI command\n");
  6085. goto mem_fail_out;
  6086. }
  6087. rc = lpfc_config_msi(phba, pmb);
  6088. if (rc)
  6089. goto mbx_fail_out;
  6090. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  6091. if (rc != MBX_SUCCESS) {
  6092. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  6093. "0351 Config MSI mailbox command failed, "
  6094. "mbxCmd x%x, mbxStatus x%x\n",
  6095. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
  6096. goto mbx_fail_out;
  6097. }
  6098. /* Free memory allocated for mailbox command */
  6099. mempool_free(pmb, phba->mbox_mem_pool);
  6100. return rc;
  6101. mbx_fail_out:
  6102. /* Free memory allocated for mailbox command */
  6103. mempool_free(pmb, phba->mbox_mem_pool);
  6104. mem_fail_out:
  6105. /* free the irq already requested */
  6106. free_irq(phba->msix_entries[1].vector, phba);
  6107. irq_fail_out:
  6108. /* free the irq already requested */
  6109. free_irq(phba->msix_entries[0].vector, phba);
  6110. msi_fail_out:
  6111. /* Unconfigure MSI-X capability structure */
  6112. pci_disable_msix(phba->pcidev);
  6113. return rc;
  6114. }
  6115. /**
  6116. * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
  6117. * @phba: pointer to lpfc hba data structure.
  6118. *
  6119. * This routine is invoked to release the MSI-X vectors and then disable the
  6120. * MSI-X interrupt mode to device with SLI-3 interface spec.
  6121. **/
  6122. static void
  6123. lpfc_sli_disable_msix(struct lpfc_hba *phba)
  6124. {
  6125. int i;
  6126. /* Free up MSI-X multi-message vectors */
  6127. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  6128. free_irq(phba->msix_entries[i].vector, phba);
  6129. /* Disable MSI-X */
  6130. pci_disable_msix(phba->pcidev);
  6131. return;
  6132. }
  6133. /**
  6134. * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
  6135. * @phba: pointer to lpfc hba data structure.
  6136. *
  6137. * This routine is invoked to enable the MSI interrupt mode to device with
  6138. * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
  6139. * enable the MSI vector. The device driver is responsible for calling the
  6140. * request_irq() to register MSI vector with a interrupt the handler, which
  6141. * is done in this function.
  6142. *
  6143. * Return codes
  6144. * 0 - successful
  6145. * other values - error
  6146. */
  6147. static int
  6148. lpfc_sli_enable_msi(struct lpfc_hba *phba)
  6149. {
  6150. int rc;
  6151. rc = pci_enable_msi(phba->pcidev);
  6152. if (!rc)
  6153. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6154. "0462 PCI enable MSI mode success.\n");
  6155. else {
  6156. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6157. "0471 PCI enable MSI mode failed (%d)\n", rc);
  6158. return rc;
  6159. }
  6160. rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  6161. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  6162. if (rc) {
  6163. pci_disable_msi(phba->pcidev);
  6164. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6165. "0478 MSI request_irq failed (%d)\n", rc);
  6166. }
  6167. return rc;
  6168. }
  6169. /**
  6170. * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
  6171. * @phba: pointer to lpfc hba data structure.
  6172. *
  6173. * This routine is invoked to disable the MSI interrupt mode to device with
  6174. * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
  6175. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  6176. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  6177. * its vector.
  6178. */
  6179. static void
  6180. lpfc_sli_disable_msi(struct lpfc_hba *phba)
  6181. {
  6182. free_irq(phba->pcidev->irq, phba);
  6183. pci_disable_msi(phba->pcidev);
  6184. return;
  6185. }
  6186. /**
  6187. * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
  6188. * @phba: pointer to lpfc hba data structure.
  6189. *
  6190. * This routine is invoked to enable device interrupt and associate driver's
  6191. * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
  6192. * spec. Depends on the interrupt mode configured to the driver, the driver
  6193. * will try to fallback from the configured interrupt mode to an interrupt
  6194. * mode which is supported by the platform, kernel, and device in the order
  6195. * of:
  6196. * MSI-X -> MSI -> IRQ.
  6197. *
  6198. * Return codes
  6199. * 0 - successful
  6200. * other values - error
  6201. **/
  6202. static uint32_t
  6203. lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  6204. {
  6205. uint32_t intr_mode = LPFC_INTR_ERROR;
  6206. int retval;
  6207. if (cfg_mode == 2) {
  6208. /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
  6209. retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
  6210. if (!retval) {
  6211. /* Now, try to enable MSI-X interrupt mode */
  6212. retval = lpfc_sli_enable_msix(phba);
  6213. if (!retval) {
  6214. /* Indicate initialization to MSI-X mode */
  6215. phba->intr_type = MSIX;
  6216. intr_mode = 2;
  6217. }
  6218. }
  6219. }
  6220. /* Fallback to MSI if MSI-X initialization failed */
  6221. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  6222. retval = lpfc_sli_enable_msi(phba);
  6223. if (!retval) {
  6224. /* Indicate initialization to MSI mode */
  6225. phba->intr_type = MSI;
  6226. intr_mode = 1;
  6227. }
  6228. }
  6229. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  6230. if (phba->intr_type == NONE) {
  6231. retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  6232. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  6233. if (!retval) {
  6234. /* Indicate initialization to INTx mode */
  6235. phba->intr_type = INTx;
  6236. intr_mode = 0;
  6237. }
  6238. }
  6239. return intr_mode;
  6240. }
  6241. /**
  6242. * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
  6243. * @phba: pointer to lpfc hba data structure.
  6244. *
  6245. * This routine is invoked to disable device interrupt and disassociate the
  6246. * driver's interrupt handler(s) from interrupt vector(s) to device with
  6247. * SLI-3 interface spec. Depending on the interrupt mode, the driver will
  6248. * release the interrupt vector(s) for the message signaled interrupt.
  6249. **/
  6250. static void
  6251. lpfc_sli_disable_intr(struct lpfc_hba *phba)
  6252. {
  6253. /* Disable the currently initialized interrupt mode */
  6254. if (phba->intr_type == MSIX)
  6255. lpfc_sli_disable_msix(phba);
  6256. else if (phba->intr_type == MSI)
  6257. lpfc_sli_disable_msi(phba);
  6258. else if (phba->intr_type == INTx)
  6259. free_irq(phba->pcidev->irq, phba);
  6260. /* Reset interrupt management states */
  6261. phba->intr_type = NONE;
  6262. phba->sli.slistat.sli_intr = 0;
  6263. return;
  6264. }
  6265. /**
  6266. * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
  6267. * @phba: pointer to lpfc hba data structure.
  6268. *
  6269. * This routine is invoked to enable the MSI-X interrupt vectors to device
  6270. * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
  6271. * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
  6272. * enables either all or nothing, depending on the current availability of
  6273. * PCI vector resources. The device driver is responsible for calling the
  6274. * individual request_irq() to register each MSI-X vector with a interrupt
  6275. * handler, which is done in this function. Note that later when device is
  6276. * unloading, the driver should always call free_irq() on all MSI-X vectors
  6277. * it has done request_irq() on before calling pci_disable_msix(). Failure
  6278. * to do so results in a BUG_ON() and a device will be left with MSI-X
  6279. * enabled and leaks its vectors.
  6280. *
  6281. * Return codes
  6282. * 0 - successful
  6283. * other values - error
  6284. **/
  6285. static int
  6286. lpfc_sli4_enable_msix(struct lpfc_hba *phba)
  6287. {
  6288. int rc, index;
  6289. /* Set up MSI-X multi-message vectors */
  6290. for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
  6291. phba->sli4_hba.msix_entries[index].entry = index;
  6292. /* Configure MSI-X capability structure */
  6293. rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
  6294. phba->sli4_hba.cfg_eqn);
  6295. if (rc) {
  6296. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6297. "0484 PCI enable MSI-X failed (%d)\n", rc);
  6298. goto msi_fail_out;
  6299. }
  6300. /* Log MSI-X vector assignment */
  6301. for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
  6302. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6303. "0489 MSI-X entry[%d]: vector=x%x "
  6304. "message=%d\n", index,
  6305. phba->sli4_hba.msix_entries[index].vector,
  6306. phba->sli4_hba.msix_entries[index].entry);
  6307. /*
  6308. * Assign MSI-X vectors to interrupt handlers
  6309. */
  6310. /* The first vector must associated to slow-path handler for MQ */
  6311. rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
  6312. &lpfc_sli4_sp_intr_handler, IRQF_SHARED,
  6313. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  6314. if (rc) {
  6315. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6316. "0485 MSI-X slow-path request_irq failed "
  6317. "(%d)\n", rc);
  6318. goto msi_fail_out;
  6319. }
  6320. /* The rest of the vector(s) are associated to fast-path handler(s) */
  6321. for (index = 1; index < phba->sli4_hba.cfg_eqn; index++) {
  6322. phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1;
  6323. phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba;
  6324. rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
  6325. &lpfc_sli4_fp_intr_handler, IRQF_SHARED,
  6326. LPFC_FP_DRIVER_HANDLER_NAME,
  6327. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  6328. if (rc) {
  6329. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6330. "0486 MSI-X fast-path (%d) "
  6331. "request_irq failed (%d)\n", index, rc);
  6332. goto cfg_fail_out;
  6333. }
  6334. }
  6335. return rc;
  6336. cfg_fail_out:
  6337. /* free the irq already requested */
  6338. for (--index; index >= 1; index--)
  6339. free_irq(phba->sli4_hba.msix_entries[index - 1].vector,
  6340. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  6341. /* free the irq already requested */
  6342. free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
  6343. msi_fail_out:
  6344. /* Unconfigure MSI-X capability structure */
  6345. pci_disable_msix(phba->pcidev);
  6346. return rc;
  6347. }
  6348. /**
  6349. * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
  6350. * @phba: pointer to lpfc hba data structure.
  6351. *
  6352. * This routine is invoked to release the MSI-X vectors and then disable the
  6353. * MSI-X interrupt mode to device with SLI-4 interface spec.
  6354. **/
  6355. static void
  6356. lpfc_sli4_disable_msix(struct lpfc_hba *phba)
  6357. {
  6358. int index;
  6359. /* Free up MSI-X multi-message vectors */
  6360. free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
  6361. for (index = 1; index < phba->sli4_hba.cfg_eqn; index++)
  6362. free_irq(phba->sli4_hba.msix_entries[index].vector,
  6363. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  6364. /* Disable MSI-X */
  6365. pci_disable_msix(phba->pcidev);
  6366. return;
  6367. }
  6368. /**
  6369. * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
  6370. * @phba: pointer to lpfc hba data structure.
  6371. *
  6372. * This routine is invoked to enable the MSI interrupt mode to device with
  6373. * SLI-4 interface spec. The kernel function pci_enable_msi() is called
  6374. * to enable the MSI vector. The device driver is responsible for calling
  6375. * the request_irq() to register MSI vector with a interrupt the handler,
  6376. * which is done in this function.
  6377. *
  6378. * Return codes
  6379. * 0 - successful
  6380. * other values - error
  6381. **/
  6382. static int
  6383. lpfc_sli4_enable_msi(struct lpfc_hba *phba)
  6384. {
  6385. int rc, index;
  6386. rc = pci_enable_msi(phba->pcidev);
  6387. if (!rc)
  6388. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6389. "0487 PCI enable MSI mode success.\n");
  6390. else {
  6391. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6392. "0488 PCI enable MSI mode failed (%d)\n", rc);
  6393. return rc;
  6394. }
  6395. rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  6396. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  6397. if (rc) {
  6398. pci_disable_msi(phba->pcidev);
  6399. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6400. "0490 MSI request_irq failed (%d)\n", rc);
  6401. }
  6402. for (index = 0; index < phba->cfg_fcp_eq_count; index++) {
  6403. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  6404. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  6405. }
  6406. return rc;
  6407. }
  6408. /**
  6409. * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
  6410. * @phba: pointer to lpfc hba data structure.
  6411. *
  6412. * This routine is invoked to disable the MSI interrupt mode to device with
  6413. * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
  6414. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  6415. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  6416. * its vector.
  6417. **/
  6418. static void
  6419. lpfc_sli4_disable_msi(struct lpfc_hba *phba)
  6420. {
  6421. free_irq(phba->pcidev->irq, phba);
  6422. pci_disable_msi(phba->pcidev);
  6423. return;
  6424. }
  6425. /**
  6426. * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
  6427. * @phba: pointer to lpfc hba data structure.
  6428. *
  6429. * This routine is invoked to enable device interrupt and associate driver's
  6430. * interrupt handler(s) to interrupt vector(s) to device with SLI-4
  6431. * interface spec. Depends on the interrupt mode configured to the driver,
  6432. * the driver will try to fallback from the configured interrupt mode to an
  6433. * interrupt mode which is supported by the platform, kernel, and device in
  6434. * the order of:
  6435. * MSI-X -> MSI -> IRQ.
  6436. *
  6437. * Return codes
  6438. * 0 - successful
  6439. * other values - error
  6440. **/
  6441. static uint32_t
  6442. lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  6443. {
  6444. uint32_t intr_mode = LPFC_INTR_ERROR;
  6445. int retval, index;
  6446. if (cfg_mode == 2) {
  6447. /* Preparation before conf_msi mbox cmd */
  6448. retval = 0;
  6449. if (!retval) {
  6450. /* Now, try to enable MSI-X interrupt mode */
  6451. retval = lpfc_sli4_enable_msix(phba);
  6452. if (!retval) {
  6453. /* Indicate initialization to MSI-X mode */
  6454. phba->intr_type = MSIX;
  6455. intr_mode = 2;
  6456. }
  6457. }
  6458. }
  6459. /* Fallback to MSI if MSI-X initialization failed */
  6460. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  6461. retval = lpfc_sli4_enable_msi(phba);
  6462. if (!retval) {
  6463. /* Indicate initialization to MSI mode */
  6464. phba->intr_type = MSI;
  6465. intr_mode = 1;
  6466. }
  6467. }
  6468. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  6469. if (phba->intr_type == NONE) {
  6470. retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  6471. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  6472. if (!retval) {
  6473. /* Indicate initialization to INTx mode */
  6474. phba->intr_type = INTx;
  6475. intr_mode = 0;
  6476. for (index = 0; index < phba->cfg_fcp_eq_count;
  6477. index++) {
  6478. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  6479. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  6480. }
  6481. }
  6482. }
  6483. return intr_mode;
  6484. }
  6485. /**
  6486. * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
  6487. * @phba: pointer to lpfc hba data structure.
  6488. *
  6489. * This routine is invoked to disable device interrupt and disassociate
  6490. * the driver's interrupt handler(s) from interrupt vector(s) to device
  6491. * with SLI-4 interface spec. Depending on the interrupt mode, the driver
  6492. * will release the interrupt vector(s) for the message signaled interrupt.
  6493. **/
  6494. static void
  6495. lpfc_sli4_disable_intr(struct lpfc_hba *phba)
  6496. {
  6497. /* Disable the currently initialized interrupt mode */
  6498. if (phba->intr_type == MSIX)
  6499. lpfc_sli4_disable_msix(phba);
  6500. else if (phba->intr_type == MSI)
  6501. lpfc_sli4_disable_msi(phba);
  6502. else if (phba->intr_type == INTx)
  6503. free_irq(phba->pcidev->irq, phba);
  6504. /* Reset interrupt management states */
  6505. phba->intr_type = NONE;
  6506. phba->sli.slistat.sli_intr = 0;
  6507. return;
  6508. }
  6509. /**
  6510. * lpfc_unset_hba - Unset SLI3 hba device initialization
  6511. * @phba: pointer to lpfc hba data structure.
  6512. *
  6513. * This routine is invoked to unset the HBA device initialization steps to
  6514. * a device with SLI-3 interface spec.
  6515. **/
  6516. static void
  6517. lpfc_unset_hba(struct lpfc_hba *phba)
  6518. {
  6519. struct lpfc_vport *vport = phba->pport;
  6520. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6521. spin_lock_irq(shost->host_lock);
  6522. vport->load_flag |= FC_UNLOADING;
  6523. spin_unlock_irq(shost->host_lock);
  6524. lpfc_stop_hba_timers(phba);
  6525. phba->pport->work_port_events = 0;
  6526. lpfc_sli_hba_down(phba);
  6527. lpfc_sli_brdrestart(phba);
  6528. lpfc_sli_disable_intr(phba);
  6529. return;
  6530. }
  6531. /**
  6532. * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
  6533. * @phba: pointer to lpfc hba data structure.
  6534. *
  6535. * This routine is invoked to unset the HBA device initialization steps to
  6536. * a device with SLI-4 interface spec.
  6537. **/
  6538. static void
  6539. lpfc_sli4_unset_hba(struct lpfc_hba *phba)
  6540. {
  6541. struct lpfc_vport *vport = phba->pport;
  6542. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6543. spin_lock_irq(shost->host_lock);
  6544. vport->load_flag |= FC_UNLOADING;
  6545. spin_unlock_irq(shost->host_lock);
  6546. phba->pport->work_port_events = 0;
  6547. lpfc_sli4_hba_down(phba);
  6548. lpfc_sli4_disable_intr(phba);
  6549. return;
  6550. }
  6551. /**
  6552. * lpfc_sli4_hba_unset - Unset the fcoe hba
  6553. * @phba: Pointer to HBA context object.
  6554. *
  6555. * This function is called in the SLI4 code path to reset the HBA's FCoE
  6556. * function. The caller is not required to hold any lock. This routine
  6557. * issues PCI function reset mailbox command to reset the FCoE function.
  6558. * At the end of the function, it calls lpfc_hba_down_post function to
  6559. * free any pending commands.
  6560. **/
  6561. static void
  6562. lpfc_sli4_hba_unset(struct lpfc_hba *phba)
  6563. {
  6564. int wait_cnt = 0;
  6565. LPFC_MBOXQ_t *mboxq;
  6566. lpfc_stop_hba_timers(phba);
  6567. phba->sli4_hba.intr_enable = 0;
  6568. /*
  6569. * Gracefully wait out the potential current outstanding asynchronous
  6570. * mailbox command.
  6571. */
  6572. /* First, block any pending async mailbox command from posted */
  6573. spin_lock_irq(&phba->hbalock);
  6574. phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6575. spin_unlock_irq(&phba->hbalock);
  6576. /* Now, trying to wait it out if we can */
  6577. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6578. msleep(10);
  6579. if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
  6580. break;
  6581. }
  6582. /* Forcefully release the outstanding mailbox command if timed out */
  6583. if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6584. spin_lock_irq(&phba->hbalock);
  6585. mboxq = phba->sli.mbox_active;
  6586. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6587. __lpfc_mbox_cmpl_put(phba, mboxq);
  6588. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6589. phba->sli.mbox_active = NULL;
  6590. spin_unlock_irq(&phba->hbalock);
  6591. }
  6592. /* Tear down the queues in the HBA */
  6593. lpfc_sli4_queue_unset(phba);
  6594. /* Disable PCI subsystem interrupt */
  6595. lpfc_sli4_disable_intr(phba);
  6596. /* Stop kthread signal shall trigger work_done one more time */
  6597. kthread_stop(phba->worker_thread);
  6598. /* Stop the SLI4 device port */
  6599. phba->pport->work_port_events = 0;
  6600. }
  6601. /**
  6602. * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
  6603. * @phba: Pointer to HBA context object.
  6604. * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
  6605. *
  6606. * This function is called in the SLI4 code path to read the port's
  6607. * sli4 capabilities.
  6608. *
  6609. * This function may be be called from any context that can block-wait
  6610. * for the completion. The expectation is that this routine is called
  6611. * typically from probe_one or from the online routine.
  6612. **/
  6613. int
  6614. lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6615. {
  6616. int rc;
  6617. struct lpfc_mqe *mqe;
  6618. struct lpfc_pc_sli4_params *sli4_params;
  6619. uint32_t mbox_tmo;
  6620. rc = 0;
  6621. mqe = &mboxq->u.mqe;
  6622. /* Read the port's SLI4 Parameters port capabilities */
  6623. lpfc_sli4_params(mboxq);
  6624. if (!phba->sli4_hba.intr_enable)
  6625. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6626. else {
  6627. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_PORT_CAPABILITIES);
  6628. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  6629. }
  6630. if (unlikely(rc))
  6631. return 1;
  6632. sli4_params = &phba->sli4_hba.pc_sli4_params;
  6633. sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
  6634. sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
  6635. sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
  6636. sli4_params->featurelevel_1 = bf_get(featurelevel_1,
  6637. &mqe->un.sli4_params);
  6638. sli4_params->featurelevel_2 = bf_get(featurelevel_2,
  6639. &mqe->un.sli4_params);
  6640. sli4_params->proto_types = mqe->un.sli4_params.word3;
  6641. sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
  6642. sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
  6643. sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
  6644. sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
  6645. sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
  6646. sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
  6647. sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
  6648. sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
  6649. sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
  6650. sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
  6651. sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
  6652. sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
  6653. sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
  6654. sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
  6655. sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
  6656. sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
  6657. sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
  6658. sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
  6659. sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
  6660. sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
  6661. return rc;
  6662. }
  6663. /**
  6664. * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
  6665. * @pdev: pointer to PCI device
  6666. * @pid: pointer to PCI device identifier
  6667. *
  6668. * This routine is to be called to attach a device with SLI-3 interface spec
  6669. * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  6670. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  6671. * information of the device and driver to see if the driver state that it can
  6672. * support this kind of device. If the match is successful, the driver core
  6673. * invokes this routine. If this routine determines it can claim the HBA, it
  6674. * does all the initialization that it needs to do to handle the HBA properly.
  6675. *
  6676. * Return code
  6677. * 0 - driver can claim the device
  6678. * negative value - driver can not claim the device
  6679. **/
  6680. static int __devinit
  6681. lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
  6682. {
  6683. struct lpfc_hba *phba;
  6684. struct lpfc_vport *vport = NULL;
  6685. struct Scsi_Host *shost = NULL;
  6686. int error;
  6687. uint32_t cfg_mode, intr_mode;
  6688. /* Allocate memory for HBA structure */
  6689. phba = lpfc_hba_alloc(pdev);
  6690. if (!phba)
  6691. return -ENOMEM;
  6692. /* Perform generic PCI device enabling operation */
  6693. error = lpfc_enable_pci_dev(phba);
  6694. if (error) {
  6695. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6696. "1401 Failed to enable pci device.\n");
  6697. goto out_free_phba;
  6698. }
  6699. /* Set up SLI API function jump table for PCI-device group-0 HBAs */
  6700. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
  6701. if (error)
  6702. goto out_disable_pci_dev;
  6703. /* Set up SLI-3 specific device PCI memory space */
  6704. error = lpfc_sli_pci_mem_setup(phba);
  6705. if (error) {
  6706. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6707. "1402 Failed to set up pci memory space.\n");
  6708. goto out_disable_pci_dev;
  6709. }
  6710. /* Set up phase-1 common device driver resources */
  6711. error = lpfc_setup_driver_resource_phase1(phba);
  6712. if (error) {
  6713. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6714. "1403 Failed to set up driver resource.\n");
  6715. goto out_unset_pci_mem_s3;
  6716. }
  6717. /* Set up SLI-3 specific device driver resources */
  6718. error = lpfc_sli_driver_resource_setup(phba);
  6719. if (error) {
  6720. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6721. "1404 Failed to set up driver resource.\n");
  6722. goto out_unset_pci_mem_s3;
  6723. }
  6724. /* Initialize and populate the iocb list per host */
  6725. error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
  6726. if (error) {
  6727. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6728. "1405 Failed to initialize iocb list.\n");
  6729. goto out_unset_driver_resource_s3;
  6730. }
  6731. /* Set up common device driver resources */
  6732. error = lpfc_setup_driver_resource_phase2(phba);
  6733. if (error) {
  6734. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6735. "1406 Failed to set up driver resource.\n");
  6736. goto out_free_iocb_list;
  6737. }
  6738. /* Create SCSI host to the physical port */
  6739. error = lpfc_create_shost(phba);
  6740. if (error) {
  6741. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6742. "1407 Failed to create scsi host.\n");
  6743. goto out_unset_driver_resource;
  6744. }
  6745. /* Configure sysfs attributes */
  6746. vport = phba->pport;
  6747. error = lpfc_alloc_sysfs_attr(vport);
  6748. if (error) {
  6749. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6750. "1476 Failed to allocate sysfs attr\n");
  6751. goto out_destroy_shost;
  6752. }
  6753. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  6754. /* Now, trying to enable interrupt and bring up the device */
  6755. cfg_mode = phba->cfg_use_msi;
  6756. while (true) {
  6757. /* Put device to a known state before enabling interrupt */
  6758. lpfc_stop_port(phba);
  6759. /* Configure and enable interrupt */
  6760. intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
  6761. if (intr_mode == LPFC_INTR_ERROR) {
  6762. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6763. "0431 Failed to enable interrupt.\n");
  6764. error = -ENODEV;
  6765. goto out_free_sysfs_attr;
  6766. }
  6767. /* SLI-3 HBA setup */
  6768. if (lpfc_sli_hba_setup(phba)) {
  6769. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6770. "1477 Failed to set up hba\n");
  6771. error = -ENODEV;
  6772. goto out_remove_device;
  6773. }
  6774. /* Wait 50ms for the interrupts of previous mailbox commands */
  6775. msleep(50);
  6776. /* Check active interrupts on message signaled interrupts */
  6777. if (intr_mode == 0 ||
  6778. phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
  6779. /* Log the current active interrupt mode */
  6780. phba->intr_mode = intr_mode;
  6781. lpfc_log_intr_mode(phba, intr_mode);
  6782. break;
  6783. } else {
  6784. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6785. "0447 Configure interrupt mode (%d) "
  6786. "failed active interrupt test.\n",
  6787. intr_mode);
  6788. /* Disable the current interrupt mode */
  6789. lpfc_sli_disable_intr(phba);
  6790. /* Try next level of interrupt mode */
  6791. cfg_mode = --intr_mode;
  6792. }
  6793. }
  6794. /* Perform post initialization setup */
  6795. lpfc_post_init_setup(phba);
  6796. /* Check if there are static vports to be created. */
  6797. lpfc_create_static_vport(phba);
  6798. return 0;
  6799. out_remove_device:
  6800. lpfc_unset_hba(phba);
  6801. out_free_sysfs_attr:
  6802. lpfc_free_sysfs_attr(vport);
  6803. out_destroy_shost:
  6804. lpfc_destroy_shost(phba);
  6805. out_unset_driver_resource:
  6806. lpfc_unset_driver_resource_phase2(phba);
  6807. out_free_iocb_list:
  6808. lpfc_free_iocb_list(phba);
  6809. out_unset_driver_resource_s3:
  6810. lpfc_sli_driver_resource_unset(phba);
  6811. out_unset_pci_mem_s3:
  6812. lpfc_sli_pci_mem_unset(phba);
  6813. out_disable_pci_dev:
  6814. lpfc_disable_pci_dev(phba);
  6815. if (shost)
  6816. scsi_host_put(shost);
  6817. out_free_phba:
  6818. lpfc_hba_free(phba);
  6819. return error;
  6820. }
  6821. /**
  6822. * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
  6823. * @pdev: pointer to PCI device
  6824. *
  6825. * This routine is to be called to disattach a device with SLI-3 interface
  6826. * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  6827. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  6828. * device to be removed from the PCI subsystem properly.
  6829. **/
  6830. static void __devexit
  6831. lpfc_pci_remove_one_s3(struct pci_dev *pdev)
  6832. {
  6833. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6834. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  6835. struct lpfc_vport **vports;
  6836. struct lpfc_hba *phba = vport->phba;
  6837. int i;
  6838. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  6839. spin_lock_irq(&phba->hbalock);
  6840. vport->load_flag |= FC_UNLOADING;
  6841. spin_unlock_irq(&phba->hbalock);
  6842. lpfc_free_sysfs_attr(vport);
  6843. /* Release all the vports against this physical port */
  6844. vports = lpfc_create_vport_work_array(phba);
  6845. if (vports != NULL)
  6846. for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
  6847. fc_vport_terminate(vports[i]->fc_vport);
  6848. lpfc_destroy_vport_work_array(phba, vports);
  6849. /* Remove FC host and then SCSI host with the physical port */
  6850. fc_remove_host(shost);
  6851. scsi_remove_host(shost);
  6852. lpfc_cleanup(vport);
  6853. /*
  6854. * Bring down the SLI Layer. This step disable all interrupts,
  6855. * clears the rings, discards all mailbox commands, and resets
  6856. * the HBA.
  6857. */
  6858. /* HBA interrupt will be diabled after this call */
  6859. lpfc_sli_hba_down(phba);
  6860. /* Stop kthread signal shall trigger work_done one more time */
  6861. kthread_stop(phba->worker_thread);
  6862. /* Final cleanup of txcmplq and reset the HBA */
  6863. lpfc_sli_brdrestart(phba);
  6864. lpfc_stop_hba_timers(phba);
  6865. spin_lock_irq(&phba->hbalock);
  6866. list_del_init(&vport->listentry);
  6867. spin_unlock_irq(&phba->hbalock);
  6868. lpfc_debugfs_terminate(vport);
  6869. /* Disable interrupt */
  6870. lpfc_sli_disable_intr(phba);
  6871. pci_set_drvdata(pdev, NULL);
  6872. scsi_host_put(shost);
  6873. /*
  6874. * Call scsi_free before mem_free since scsi bufs are released to their
  6875. * corresponding pools here.
  6876. */
  6877. lpfc_scsi_free(phba);
  6878. lpfc_mem_free_all(phba);
  6879. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  6880. phba->hbqslimp.virt, phba->hbqslimp.phys);
  6881. /* Free resources associated with SLI2 interface */
  6882. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  6883. phba->slim2p.virt, phba->slim2p.phys);
  6884. /* unmap adapter SLIM and Control Registers */
  6885. iounmap(phba->ctrl_regs_memmap_p);
  6886. iounmap(phba->slim_memmap_p);
  6887. lpfc_hba_free(phba);
  6888. pci_release_selected_regions(pdev, bars);
  6889. pci_disable_device(pdev);
  6890. }
  6891. /**
  6892. * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
  6893. * @pdev: pointer to PCI device
  6894. * @msg: power management message
  6895. *
  6896. * This routine is to be called from the kernel's PCI subsystem to support
  6897. * system Power Management (PM) to device with SLI-3 interface spec. When
  6898. * PM invokes this method, it quiesces the device by stopping the driver's
  6899. * worker thread for the device, turning off device's interrupt and DMA,
  6900. * and bring the device offline. Note that as the driver implements the
  6901. * minimum PM requirements to a power-aware driver's PM support for the
  6902. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  6903. * to the suspend() method call will be treated as SUSPEND and the driver will
  6904. * fully reinitialize its device during resume() method call, the driver will
  6905. * set device to PCI_D3hot state in PCI config space instead of setting it
  6906. * according to the @msg provided by the PM.
  6907. *
  6908. * Return code
  6909. * 0 - driver suspended the device
  6910. * Error otherwise
  6911. **/
  6912. static int
  6913. lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
  6914. {
  6915. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6916. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6917. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6918. "0473 PCI device Power Management suspend.\n");
  6919. /* Bring down the device */
  6920. lpfc_offline_prep(phba);
  6921. lpfc_offline(phba);
  6922. kthread_stop(phba->worker_thread);
  6923. /* Disable interrupt from device */
  6924. lpfc_sli_disable_intr(phba);
  6925. /* Save device state to PCI config space */
  6926. pci_save_state(pdev);
  6927. pci_set_power_state(pdev, PCI_D3hot);
  6928. return 0;
  6929. }
  6930. /**
  6931. * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
  6932. * @pdev: pointer to PCI device
  6933. *
  6934. * This routine is to be called from the kernel's PCI subsystem to support
  6935. * system Power Management (PM) to device with SLI-3 interface spec. When PM
  6936. * invokes this method, it restores the device's PCI config space state and
  6937. * fully reinitializes the device and brings it online. Note that as the
  6938. * driver implements the minimum PM requirements to a power-aware driver's
  6939. * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
  6940. * FREEZE) to the suspend() method call will be treated as SUSPEND and the
  6941. * driver will fully reinitialize its device during resume() method call,
  6942. * the device will be set to PCI_D0 directly in PCI config space before
  6943. * restoring the state.
  6944. *
  6945. * Return code
  6946. * 0 - driver suspended the device
  6947. * Error otherwise
  6948. **/
  6949. static int
  6950. lpfc_pci_resume_one_s3(struct pci_dev *pdev)
  6951. {
  6952. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6953. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6954. uint32_t intr_mode;
  6955. int error;
  6956. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6957. "0452 PCI device Power Management resume.\n");
  6958. /* Restore device state from PCI config space */
  6959. pci_set_power_state(pdev, PCI_D0);
  6960. pci_restore_state(pdev);
  6961. /*
  6962. * As the new kernel behavior of pci_restore_state() API call clears
  6963. * device saved_state flag, need to save the restored state again.
  6964. */
  6965. pci_save_state(pdev);
  6966. if (pdev->is_busmaster)
  6967. pci_set_master(pdev);
  6968. /* Startup the kernel thread for this host adapter. */
  6969. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  6970. "lpfc_worker_%d", phba->brd_no);
  6971. if (IS_ERR(phba->worker_thread)) {
  6972. error = PTR_ERR(phba->worker_thread);
  6973. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6974. "0434 PM resume failed to start worker "
  6975. "thread: error=x%x.\n", error);
  6976. return error;
  6977. }
  6978. /* Configure and enable interrupt */
  6979. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  6980. if (intr_mode == LPFC_INTR_ERROR) {
  6981. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6982. "0430 PM resume Failed to enable interrupt\n");
  6983. return -EIO;
  6984. } else
  6985. phba->intr_mode = intr_mode;
  6986. /* Restart HBA and bring it online */
  6987. lpfc_sli_brdrestart(phba);
  6988. lpfc_online(phba);
  6989. /* Log the current active interrupt mode */
  6990. lpfc_log_intr_mode(phba, phba->intr_mode);
  6991. return 0;
  6992. }
  6993. /**
  6994. * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
  6995. * @phba: pointer to lpfc hba data structure.
  6996. *
  6997. * This routine is called to prepare the SLI3 device for PCI slot recover. It
  6998. * aborts and stops all the on-going I/Os on the pci device.
  6999. **/
  7000. static void
  7001. lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
  7002. {
  7003. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7004. "2723 PCI channel I/O abort preparing for recovery\n");
  7005. /* Prepare for bringing HBA offline */
  7006. lpfc_offline_prep(phba);
  7007. /* Clear sli active flag to prevent sysfs access to HBA */
  7008. spin_lock_irq(&phba->hbalock);
  7009. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  7010. spin_unlock_irq(&phba->hbalock);
  7011. /* Stop and flush all I/Os and bring HBA offline */
  7012. lpfc_offline(phba);
  7013. }
  7014. /**
  7015. * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
  7016. * @phba: pointer to lpfc hba data structure.
  7017. *
  7018. * This routine is called to prepare the SLI3 device for PCI slot reset. It
  7019. * disables the device interrupt and pci device, and aborts the internal FCP
  7020. * pending I/Os.
  7021. **/
  7022. static void
  7023. lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
  7024. {
  7025. struct lpfc_sli *psli = &phba->sli;
  7026. struct lpfc_sli_ring *pring;
  7027. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7028. "2710 PCI channel disable preparing for reset\n");
  7029. /* Disable interrupt and pci device */
  7030. lpfc_sli_disable_intr(phba);
  7031. pci_disable_device(phba->pcidev);
  7032. /*
  7033. * There may be I/Os dropped by the firmware.
  7034. * Error iocb (I/O) on txcmplq and let the SCSI layer
  7035. * retry it after re-establishing link.
  7036. */
  7037. pring = &psli->ring[psli->fcp_ring];
  7038. lpfc_sli_abort_iocb_ring(phba, pring);
  7039. }
  7040. /**
  7041. * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
  7042. * @phba: pointer to lpfc hba data structure.
  7043. *
  7044. * This routine is called to prepare the SLI3 device for PCI slot permanently
  7045. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  7046. * pending I/Os.
  7047. **/
  7048. static void
  7049. lpfc_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  7050. {
  7051. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7052. "2711 PCI channel permanent disable for failure\n");
  7053. /* Clean up all driver's outstanding SCSI I/Os */
  7054. lpfc_sli_flush_fcp_rings(phba);
  7055. }
  7056. /**
  7057. * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
  7058. * @pdev: pointer to PCI device.
  7059. * @state: the current PCI connection state.
  7060. *
  7061. * This routine is called from the PCI subsystem for I/O error handling to
  7062. * device with SLI-3 interface spec. This function is called by the PCI
  7063. * subsystem after a PCI bus error affecting this device has been detected.
  7064. * When this function is invoked, it will need to stop all the I/Os and
  7065. * interrupt(s) to the device. Once that is done, it will return
  7066. * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
  7067. * as desired.
  7068. *
  7069. * Return codes
  7070. * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
  7071. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  7072. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7073. **/
  7074. static pci_ers_result_t
  7075. lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
  7076. {
  7077. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7078. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7079. /* Block all SCSI devices' I/Os on the host */
  7080. lpfc_scsi_dev_block(phba);
  7081. switch (state) {
  7082. case pci_channel_io_normal:
  7083. /* Non-fatal error, prepare for recovery */
  7084. lpfc_sli_prep_dev_for_recover(phba);
  7085. return PCI_ERS_RESULT_CAN_RECOVER;
  7086. case pci_channel_io_frozen:
  7087. /* Fatal error, prepare for slot reset */
  7088. lpfc_sli_prep_dev_for_reset(phba);
  7089. return PCI_ERS_RESULT_NEED_RESET;
  7090. case pci_channel_io_perm_failure:
  7091. /* Permanent failure, prepare for device down */
  7092. lpfc_prep_dev_for_perm_failure(phba);
  7093. return PCI_ERS_RESULT_DISCONNECT;
  7094. default:
  7095. /* Unknown state, prepare and request slot reset */
  7096. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7097. "0472 Unknown PCI error state: x%x\n", state);
  7098. lpfc_sli_prep_dev_for_reset(phba);
  7099. return PCI_ERS_RESULT_NEED_RESET;
  7100. }
  7101. }
  7102. /**
  7103. * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
  7104. * @pdev: pointer to PCI device.
  7105. *
  7106. * This routine is called from the PCI subsystem for error handling to
  7107. * device with SLI-3 interface spec. This is called after PCI bus has been
  7108. * reset to restart the PCI card from scratch, as if from a cold-boot.
  7109. * During the PCI subsystem error recovery, after driver returns
  7110. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  7111. * recovery and then call this routine before calling the .resume method
  7112. * to recover the device. This function will initialize the HBA device,
  7113. * enable the interrupt, but it will just put the HBA to offline state
  7114. * without passing any I/O traffic.
  7115. *
  7116. * Return codes
  7117. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  7118. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7119. */
  7120. static pci_ers_result_t
  7121. lpfc_io_slot_reset_s3(struct pci_dev *pdev)
  7122. {
  7123. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7124. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7125. struct lpfc_sli *psli = &phba->sli;
  7126. uint32_t intr_mode;
  7127. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  7128. if (pci_enable_device_mem(pdev)) {
  7129. printk(KERN_ERR "lpfc: Cannot re-enable "
  7130. "PCI device after reset.\n");
  7131. return PCI_ERS_RESULT_DISCONNECT;
  7132. }
  7133. pci_restore_state(pdev);
  7134. /*
  7135. * As the new kernel behavior of pci_restore_state() API call clears
  7136. * device saved_state flag, need to save the restored state again.
  7137. */
  7138. pci_save_state(pdev);
  7139. if (pdev->is_busmaster)
  7140. pci_set_master(pdev);
  7141. spin_lock_irq(&phba->hbalock);
  7142. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  7143. spin_unlock_irq(&phba->hbalock);
  7144. /* Configure and enable interrupt */
  7145. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  7146. if (intr_mode == LPFC_INTR_ERROR) {
  7147. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7148. "0427 Cannot re-enable interrupt after "
  7149. "slot reset.\n");
  7150. return PCI_ERS_RESULT_DISCONNECT;
  7151. } else
  7152. phba->intr_mode = intr_mode;
  7153. /* Take device offline; this will perform cleanup */
  7154. lpfc_offline(phba);
  7155. lpfc_sli_brdrestart(phba);
  7156. /* Log the current active interrupt mode */
  7157. lpfc_log_intr_mode(phba, phba->intr_mode);
  7158. return PCI_ERS_RESULT_RECOVERED;
  7159. }
  7160. /**
  7161. * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
  7162. * @pdev: pointer to PCI device
  7163. *
  7164. * This routine is called from the PCI subsystem for error handling to device
  7165. * with SLI-3 interface spec. It is called when kernel error recovery tells
  7166. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  7167. * error recovery. After this call, traffic can start to flow from this device
  7168. * again.
  7169. */
  7170. static void
  7171. lpfc_io_resume_s3(struct pci_dev *pdev)
  7172. {
  7173. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7174. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7175. /* Bring the device online */
  7176. lpfc_online(phba);
  7177. /* Clean up Advanced Error Reporting (AER) if needed */
  7178. if (phba->hba_flag & HBA_AER_ENABLED)
  7179. pci_cleanup_aer_uncorrect_error_status(pdev);
  7180. }
  7181. /**
  7182. * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
  7183. * @phba: pointer to lpfc hba data structure.
  7184. *
  7185. * returns the number of ELS/CT IOCBs to reserve
  7186. **/
  7187. int
  7188. lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
  7189. {
  7190. int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
  7191. if (phba->sli_rev == LPFC_SLI_REV4) {
  7192. if (max_xri <= 100)
  7193. return 10;
  7194. else if (max_xri <= 256)
  7195. return 25;
  7196. else if (max_xri <= 512)
  7197. return 50;
  7198. else if (max_xri <= 1024)
  7199. return 100;
  7200. else
  7201. return 150;
  7202. } else
  7203. return 0;
  7204. }
  7205. /**
  7206. * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
  7207. * @pdev: pointer to PCI device
  7208. * @pid: pointer to PCI device identifier
  7209. *
  7210. * This routine is called from the kernel's PCI subsystem to device with
  7211. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  7212. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  7213. * information of the device and driver to see if the driver state that it
  7214. * can support this kind of device. If the match is successful, the driver
  7215. * core invokes this routine. If this routine determines it can claim the HBA,
  7216. * it does all the initialization that it needs to do to handle the HBA
  7217. * properly.
  7218. *
  7219. * Return code
  7220. * 0 - driver can claim the device
  7221. * negative value - driver can not claim the device
  7222. **/
  7223. static int __devinit
  7224. lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
  7225. {
  7226. struct lpfc_hba *phba;
  7227. struct lpfc_vport *vport = NULL;
  7228. struct Scsi_Host *shost = NULL;
  7229. int error;
  7230. uint32_t cfg_mode, intr_mode;
  7231. int mcnt;
  7232. /* Allocate memory for HBA structure */
  7233. phba = lpfc_hba_alloc(pdev);
  7234. if (!phba)
  7235. return -ENOMEM;
  7236. /* Perform generic PCI device enabling operation */
  7237. error = lpfc_enable_pci_dev(phba);
  7238. if (error) {
  7239. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7240. "1409 Failed to enable pci device.\n");
  7241. goto out_free_phba;
  7242. }
  7243. /* Set up SLI API function jump table for PCI-device group-1 HBAs */
  7244. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
  7245. if (error)
  7246. goto out_disable_pci_dev;
  7247. /* Set up SLI-4 specific device PCI memory space */
  7248. error = lpfc_sli4_pci_mem_setup(phba);
  7249. if (error) {
  7250. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7251. "1410 Failed to set up pci memory space.\n");
  7252. goto out_disable_pci_dev;
  7253. }
  7254. /* Set up phase-1 common device driver resources */
  7255. error = lpfc_setup_driver_resource_phase1(phba);
  7256. if (error) {
  7257. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7258. "1411 Failed to set up driver resource.\n");
  7259. goto out_unset_pci_mem_s4;
  7260. }
  7261. /* Set up SLI-4 Specific device driver resources */
  7262. error = lpfc_sli4_driver_resource_setup(phba);
  7263. if (error) {
  7264. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7265. "1412 Failed to set up driver resource.\n");
  7266. goto out_unset_pci_mem_s4;
  7267. }
  7268. /* Initialize and populate the iocb list per host */
  7269. error = lpfc_init_iocb_list(phba,
  7270. phba->sli4_hba.max_cfg_param.max_xri);
  7271. if (error) {
  7272. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7273. "1413 Failed to initialize iocb list.\n");
  7274. goto out_unset_driver_resource_s4;
  7275. }
  7276. /* Set up common device driver resources */
  7277. error = lpfc_setup_driver_resource_phase2(phba);
  7278. if (error) {
  7279. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7280. "1414 Failed to set up driver resource.\n");
  7281. goto out_free_iocb_list;
  7282. }
  7283. /* Create SCSI host to the physical port */
  7284. error = lpfc_create_shost(phba);
  7285. if (error) {
  7286. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7287. "1415 Failed to create scsi host.\n");
  7288. goto out_unset_driver_resource;
  7289. }
  7290. /* Configure sysfs attributes */
  7291. vport = phba->pport;
  7292. error = lpfc_alloc_sysfs_attr(vport);
  7293. if (error) {
  7294. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7295. "1416 Failed to allocate sysfs attr\n");
  7296. goto out_destroy_shost;
  7297. }
  7298. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  7299. /* Now, trying to enable interrupt and bring up the device */
  7300. cfg_mode = phba->cfg_use_msi;
  7301. while (true) {
  7302. /* Put device to a known state before enabling interrupt */
  7303. lpfc_stop_port(phba);
  7304. /* Configure and enable interrupt */
  7305. intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
  7306. if (intr_mode == LPFC_INTR_ERROR) {
  7307. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7308. "0426 Failed to enable interrupt.\n");
  7309. error = -ENODEV;
  7310. goto out_free_sysfs_attr;
  7311. }
  7312. /* Default to single FCP EQ for non-MSI-X */
  7313. if (phba->intr_type != MSIX)
  7314. phba->cfg_fcp_eq_count = 1;
  7315. /* Set up SLI-4 HBA */
  7316. if (lpfc_sli4_hba_setup(phba)) {
  7317. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7318. "1421 Failed to set up hba\n");
  7319. error = -ENODEV;
  7320. goto out_disable_intr;
  7321. }
  7322. /* Send NOP mbx cmds for non-INTx mode active interrupt test */
  7323. if (intr_mode != 0)
  7324. mcnt = lpfc_sli4_send_nop_mbox_cmds(phba,
  7325. LPFC_ACT_INTR_CNT);
  7326. /* Check active interrupts received only for MSI/MSI-X */
  7327. if (intr_mode == 0 ||
  7328. phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) {
  7329. /* Log the current active interrupt mode */
  7330. phba->intr_mode = intr_mode;
  7331. lpfc_log_intr_mode(phba, intr_mode);
  7332. break;
  7333. }
  7334. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7335. "0451 Configure interrupt mode (%d) "
  7336. "failed active interrupt test.\n",
  7337. intr_mode);
  7338. /* Unset the preivous SLI-4 HBA setup */
  7339. lpfc_sli4_unset_hba(phba);
  7340. /* Try next level of interrupt mode */
  7341. cfg_mode = --intr_mode;
  7342. }
  7343. /* Perform post initialization setup */
  7344. lpfc_post_init_setup(phba);
  7345. /* Check if there are static vports to be created. */
  7346. lpfc_create_static_vport(phba);
  7347. return 0;
  7348. out_disable_intr:
  7349. lpfc_sli4_disable_intr(phba);
  7350. out_free_sysfs_attr:
  7351. lpfc_free_sysfs_attr(vport);
  7352. out_destroy_shost:
  7353. lpfc_destroy_shost(phba);
  7354. out_unset_driver_resource:
  7355. lpfc_unset_driver_resource_phase2(phba);
  7356. out_free_iocb_list:
  7357. lpfc_free_iocb_list(phba);
  7358. out_unset_driver_resource_s4:
  7359. lpfc_sli4_driver_resource_unset(phba);
  7360. out_unset_pci_mem_s4:
  7361. lpfc_sli4_pci_mem_unset(phba);
  7362. out_disable_pci_dev:
  7363. lpfc_disable_pci_dev(phba);
  7364. if (shost)
  7365. scsi_host_put(shost);
  7366. out_free_phba:
  7367. lpfc_hba_free(phba);
  7368. return error;
  7369. }
  7370. /**
  7371. * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
  7372. * @pdev: pointer to PCI device
  7373. *
  7374. * This routine is called from the kernel's PCI subsystem to device with
  7375. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  7376. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  7377. * device to be removed from the PCI subsystem properly.
  7378. **/
  7379. static void __devexit
  7380. lpfc_pci_remove_one_s4(struct pci_dev *pdev)
  7381. {
  7382. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7383. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  7384. struct lpfc_vport **vports;
  7385. struct lpfc_hba *phba = vport->phba;
  7386. int i;
  7387. /* Mark the device unloading flag */
  7388. spin_lock_irq(&phba->hbalock);
  7389. vport->load_flag |= FC_UNLOADING;
  7390. spin_unlock_irq(&phba->hbalock);
  7391. /* Free the HBA sysfs attributes */
  7392. lpfc_free_sysfs_attr(vport);
  7393. /* Release all the vports against this physical port */
  7394. vports = lpfc_create_vport_work_array(phba);
  7395. if (vports != NULL)
  7396. for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
  7397. fc_vport_terminate(vports[i]->fc_vport);
  7398. lpfc_destroy_vport_work_array(phba, vports);
  7399. /* Remove FC host and then SCSI host with the physical port */
  7400. fc_remove_host(shost);
  7401. scsi_remove_host(shost);
  7402. /* Perform cleanup on the physical port */
  7403. lpfc_cleanup(vport);
  7404. /*
  7405. * Bring down the SLI Layer. This step disables all interrupts,
  7406. * clears the rings, discards all mailbox commands, and resets
  7407. * the HBA FCoE function.
  7408. */
  7409. lpfc_debugfs_terminate(vport);
  7410. lpfc_sli4_hba_unset(phba);
  7411. spin_lock_irq(&phba->hbalock);
  7412. list_del_init(&vport->listentry);
  7413. spin_unlock_irq(&phba->hbalock);
  7414. /* Call scsi_free before lpfc_sli4_driver_resource_unset since scsi
  7415. * buffers are released to their corresponding pools here.
  7416. */
  7417. lpfc_scsi_free(phba);
  7418. lpfc_sli4_driver_resource_unset(phba);
  7419. /* Unmap adapter Control and Doorbell registers */
  7420. lpfc_sli4_pci_mem_unset(phba);
  7421. /* Release PCI resources and disable device's PCI function */
  7422. scsi_host_put(shost);
  7423. lpfc_disable_pci_dev(phba);
  7424. /* Finally, free the driver's device data structure */
  7425. lpfc_hba_free(phba);
  7426. return;
  7427. }
  7428. /**
  7429. * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
  7430. * @pdev: pointer to PCI device
  7431. * @msg: power management message
  7432. *
  7433. * This routine is called from the kernel's PCI subsystem to support system
  7434. * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
  7435. * this method, it quiesces the device by stopping the driver's worker
  7436. * thread for the device, turning off device's interrupt and DMA, and bring
  7437. * the device offline. Note that as the driver implements the minimum PM
  7438. * requirements to a power-aware driver's PM support for suspend/resume -- all
  7439. * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
  7440. * method call will be treated as SUSPEND and the driver will fully
  7441. * reinitialize its device during resume() method call, the driver will set
  7442. * device to PCI_D3hot state in PCI config space instead of setting it
  7443. * according to the @msg provided by the PM.
  7444. *
  7445. * Return code
  7446. * 0 - driver suspended the device
  7447. * Error otherwise
  7448. **/
  7449. static int
  7450. lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
  7451. {
  7452. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7453. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7454. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7455. "0298 PCI device Power Management suspend.\n");
  7456. /* Bring down the device */
  7457. lpfc_offline_prep(phba);
  7458. lpfc_offline(phba);
  7459. kthread_stop(phba->worker_thread);
  7460. /* Disable interrupt from device */
  7461. lpfc_sli4_disable_intr(phba);
  7462. /* Save device state to PCI config space */
  7463. pci_save_state(pdev);
  7464. pci_set_power_state(pdev, PCI_D3hot);
  7465. return 0;
  7466. }
  7467. /**
  7468. * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
  7469. * @pdev: pointer to PCI device
  7470. *
  7471. * This routine is called from the kernel's PCI subsystem to support system
  7472. * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
  7473. * this method, it restores the device's PCI config space state and fully
  7474. * reinitializes the device and brings it online. Note that as the driver
  7475. * implements the minimum PM requirements to a power-aware driver's PM for
  7476. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  7477. * to the suspend() method call will be treated as SUSPEND and the driver
  7478. * will fully reinitialize its device during resume() method call, the device
  7479. * will be set to PCI_D0 directly in PCI config space before restoring the
  7480. * state.
  7481. *
  7482. * Return code
  7483. * 0 - driver suspended the device
  7484. * Error otherwise
  7485. **/
  7486. static int
  7487. lpfc_pci_resume_one_s4(struct pci_dev *pdev)
  7488. {
  7489. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7490. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7491. uint32_t intr_mode;
  7492. int error;
  7493. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7494. "0292 PCI device Power Management resume.\n");
  7495. /* Restore device state from PCI config space */
  7496. pci_set_power_state(pdev, PCI_D0);
  7497. pci_restore_state(pdev);
  7498. /*
  7499. * As the new kernel behavior of pci_restore_state() API call clears
  7500. * device saved_state flag, need to save the restored state again.
  7501. */
  7502. pci_save_state(pdev);
  7503. if (pdev->is_busmaster)
  7504. pci_set_master(pdev);
  7505. /* Startup the kernel thread for this host adapter. */
  7506. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  7507. "lpfc_worker_%d", phba->brd_no);
  7508. if (IS_ERR(phba->worker_thread)) {
  7509. error = PTR_ERR(phba->worker_thread);
  7510. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7511. "0293 PM resume failed to start worker "
  7512. "thread: error=x%x.\n", error);
  7513. return error;
  7514. }
  7515. /* Configure and enable interrupt */
  7516. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  7517. if (intr_mode == LPFC_INTR_ERROR) {
  7518. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7519. "0294 PM resume Failed to enable interrupt\n");
  7520. return -EIO;
  7521. } else
  7522. phba->intr_mode = intr_mode;
  7523. /* Restart HBA and bring it online */
  7524. lpfc_sli_brdrestart(phba);
  7525. lpfc_online(phba);
  7526. /* Log the current active interrupt mode */
  7527. lpfc_log_intr_mode(phba, phba->intr_mode);
  7528. return 0;
  7529. }
  7530. /**
  7531. * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
  7532. * @pdev: pointer to PCI device.
  7533. * @state: the current PCI connection state.
  7534. *
  7535. * This routine is called from the PCI subsystem for error handling to device
  7536. * with SLI-4 interface spec. This function is called by the PCI subsystem
  7537. * after a PCI bus error affecting this device has been detected. When this
  7538. * function is invoked, it will need to stop all the I/Os and interrupt(s)
  7539. * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
  7540. * for the PCI subsystem to perform proper recovery as desired.
  7541. *
  7542. * Return codes
  7543. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  7544. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7545. **/
  7546. static pci_ers_result_t
  7547. lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
  7548. {
  7549. return PCI_ERS_RESULT_NEED_RESET;
  7550. }
  7551. /**
  7552. * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
  7553. * @pdev: pointer to PCI device.
  7554. *
  7555. * This routine is called from the PCI subsystem for error handling to device
  7556. * with SLI-4 interface spec. It is called after PCI bus has been reset to
  7557. * restart the PCI card from scratch, as if from a cold-boot. During the
  7558. * PCI subsystem error recovery, after the driver returns
  7559. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  7560. * recovery and then call this routine before calling the .resume method to
  7561. * recover the device. This function will initialize the HBA device, enable
  7562. * the interrupt, but it will just put the HBA to offline state without
  7563. * passing any I/O traffic.
  7564. *
  7565. * Return codes
  7566. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  7567. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7568. */
  7569. static pci_ers_result_t
  7570. lpfc_io_slot_reset_s4(struct pci_dev *pdev)
  7571. {
  7572. return PCI_ERS_RESULT_RECOVERED;
  7573. }
  7574. /**
  7575. * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
  7576. * @pdev: pointer to PCI device
  7577. *
  7578. * This routine is called from the PCI subsystem for error handling to device
  7579. * with SLI-4 interface spec. It is called when kernel error recovery tells
  7580. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  7581. * error recovery. After this call, traffic can start to flow from this device
  7582. * again.
  7583. **/
  7584. static void
  7585. lpfc_io_resume_s4(struct pci_dev *pdev)
  7586. {
  7587. return;
  7588. }
  7589. /**
  7590. * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
  7591. * @pdev: pointer to PCI device
  7592. * @pid: pointer to PCI device identifier
  7593. *
  7594. * This routine is to be registered to the kernel's PCI subsystem. When an
  7595. * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
  7596. * at PCI device-specific information of the device and driver to see if the
  7597. * driver state that it can support this kind of device. If the match is
  7598. * successful, the driver core invokes this routine. This routine dispatches
  7599. * the action to the proper SLI-3 or SLI-4 device probing routine, which will
  7600. * do all the initialization that it needs to do to handle the HBA device
  7601. * properly.
  7602. *
  7603. * Return code
  7604. * 0 - driver can claim the device
  7605. * negative value - driver can not claim the device
  7606. **/
  7607. static int __devinit
  7608. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  7609. {
  7610. int rc;
  7611. struct lpfc_sli_intf intf;
  7612. if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
  7613. return -ENODEV;
  7614. if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
  7615. (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
  7616. rc = lpfc_pci_probe_one_s4(pdev, pid);
  7617. else
  7618. rc = lpfc_pci_probe_one_s3(pdev, pid);
  7619. return rc;
  7620. }
  7621. /**
  7622. * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
  7623. * @pdev: pointer to PCI device
  7624. *
  7625. * This routine is to be registered to the kernel's PCI subsystem. When an
  7626. * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
  7627. * This routine dispatches the action to the proper SLI-3 or SLI-4 device
  7628. * remove routine, which will perform all the necessary cleanup for the
  7629. * device to be removed from the PCI subsystem properly.
  7630. **/
  7631. static void __devexit
  7632. lpfc_pci_remove_one(struct pci_dev *pdev)
  7633. {
  7634. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7635. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7636. switch (phba->pci_dev_grp) {
  7637. case LPFC_PCI_DEV_LP:
  7638. lpfc_pci_remove_one_s3(pdev);
  7639. break;
  7640. case LPFC_PCI_DEV_OC:
  7641. lpfc_pci_remove_one_s4(pdev);
  7642. break;
  7643. default:
  7644. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7645. "1424 Invalid PCI device group: 0x%x\n",
  7646. phba->pci_dev_grp);
  7647. break;
  7648. }
  7649. return;
  7650. }
  7651. /**
  7652. * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
  7653. * @pdev: pointer to PCI device
  7654. * @msg: power management message
  7655. *
  7656. * This routine is to be registered to the kernel's PCI subsystem to support
  7657. * system Power Management (PM). When PM invokes this method, it dispatches
  7658. * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
  7659. * suspend the device.
  7660. *
  7661. * Return code
  7662. * 0 - driver suspended the device
  7663. * Error otherwise
  7664. **/
  7665. static int
  7666. lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
  7667. {
  7668. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7669. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7670. int rc = -ENODEV;
  7671. switch (phba->pci_dev_grp) {
  7672. case LPFC_PCI_DEV_LP:
  7673. rc = lpfc_pci_suspend_one_s3(pdev, msg);
  7674. break;
  7675. case LPFC_PCI_DEV_OC:
  7676. rc = lpfc_pci_suspend_one_s4(pdev, msg);
  7677. break;
  7678. default:
  7679. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7680. "1425 Invalid PCI device group: 0x%x\n",
  7681. phba->pci_dev_grp);
  7682. break;
  7683. }
  7684. return rc;
  7685. }
  7686. /**
  7687. * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
  7688. * @pdev: pointer to PCI device
  7689. *
  7690. * This routine is to be registered to the kernel's PCI subsystem to support
  7691. * system Power Management (PM). When PM invokes this method, it dispatches
  7692. * the action to the proper SLI-3 or SLI-4 device resume routine, which will
  7693. * resume the device.
  7694. *
  7695. * Return code
  7696. * 0 - driver suspended the device
  7697. * Error otherwise
  7698. **/
  7699. static int
  7700. lpfc_pci_resume_one(struct pci_dev *pdev)
  7701. {
  7702. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7703. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7704. int rc = -ENODEV;
  7705. switch (phba->pci_dev_grp) {
  7706. case LPFC_PCI_DEV_LP:
  7707. rc = lpfc_pci_resume_one_s3(pdev);
  7708. break;
  7709. case LPFC_PCI_DEV_OC:
  7710. rc = lpfc_pci_resume_one_s4(pdev);
  7711. break;
  7712. default:
  7713. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7714. "1426 Invalid PCI device group: 0x%x\n",
  7715. phba->pci_dev_grp);
  7716. break;
  7717. }
  7718. return rc;
  7719. }
  7720. /**
  7721. * lpfc_io_error_detected - lpfc method for handling PCI I/O error
  7722. * @pdev: pointer to PCI device.
  7723. * @state: the current PCI connection state.
  7724. *
  7725. * This routine is registered to the PCI subsystem for error handling. This
  7726. * function is called by the PCI subsystem after a PCI bus error affecting
  7727. * this device has been detected. When this routine is invoked, it dispatches
  7728. * the action to the proper SLI-3 or SLI-4 device error detected handling
  7729. * routine, which will perform the proper error detected operation.
  7730. *
  7731. * Return codes
  7732. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  7733. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7734. **/
  7735. static pci_ers_result_t
  7736. lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  7737. {
  7738. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7739. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7740. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  7741. switch (phba->pci_dev_grp) {
  7742. case LPFC_PCI_DEV_LP:
  7743. rc = lpfc_io_error_detected_s3(pdev, state);
  7744. break;
  7745. case LPFC_PCI_DEV_OC:
  7746. rc = lpfc_io_error_detected_s4(pdev, state);
  7747. break;
  7748. default:
  7749. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7750. "1427 Invalid PCI device group: 0x%x\n",
  7751. phba->pci_dev_grp);
  7752. break;
  7753. }
  7754. return rc;
  7755. }
  7756. /**
  7757. * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
  7758. * @pdev: pointer to PCI device.
  7759. *
  7760. * This routine is registered to the PCI subsystem for error handling. This
  7761. * function is called after PCI bus has been reset to restart the PCI card
  7762. * from scratch, as if from a cold-boot. When this routine is invoked, it
  7763. * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
  7764. * routine, which will perform the proper device reset.
  7765. *
  7766. * Return codes
  7767. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  7768. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7769. **/
  7770. static pci_ers_result_t
  7771. lpfc_io_slot_reset(struct pci_dev *pdev)
  7772. {
  7773. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7774. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7775. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  7776. switch (phba->pci_dev_grp) {
  7777. case LPFC_PCI_DEV_LP:
  7778. rc = lpfc_io_slot_reset_s3(pdev);
  7779. break;
  7780. case LPFC_PCI_DEV_OC:
  7781. rc = lpfc_io_slot_reset_s4(pdev);
  7782. break;
  7783. default:
  7784. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7785. "1428 Invalid PCI device group: 0x%x\n",
  7786. phba->pci_dev_grp);
  7787. break;
  7788. }
  7789. return rc;
  7790. }
  7791. /**
  7792. * lpfc_io_resume - lpfc method for resuming PCI I/O operation
  7793. * @pdev: pointer to PCI device
  7794. *
  7795. * This routine is registered to the PCI subsystem for error handling. It
  7796. * is called when kernel error recovery tells the lpfc driver that it is
  7797. * OK to resume normal PCI operation after PCI bus error recovery. When
  7798. * this routine is invoked, it dispatches the action to the proper SLI-3
  7799. * or SLI-4 device io_resume routine, which will resume the device operation.
  7800. **/
  7801. static void
  7802. lpfc_io_resume(struct pci_dev *pdev)
  7803. {
  7804. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7805. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7806. switch (phba->pci_dev_grp) {
  7807. case LPFC_PCI_DEV_LP:
  7808. lpfc_io_resume_s3(pdev);
  7809. break;
  7810. case LPFC_PCI_DEV_OC:
  7811. lpfc_io_resume_s4(pdev);
  7812. break;
  7813. default:
  7814. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7815. "1429 Invalid PCI device group: 0x%x\n",
  7816. phba->pci_dev_grp);
  7817. break;
  7818. }
  7819. return;
  7820. }
  7821. static struct pci_device_id lpfc_id_table[] = {
  7822. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  7823. PCI_ANY_ID, PCI_ANY_ID, },
  7824. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  7825. PCI_ANY_ID, PCI_ANY_ID, },
  7826. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  7827. PCI_ANY_ID, PCI_ANY_ID, },
  7828. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  7829. PCI_ANY_ID, PCI_ANY_ID, },
  7830. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  7831. PCI_ANY_ID, PCI_ANY_ID, },
  7832. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  7833. PCI_ANY_ID, PCI_ANY_ID, },
  7834. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  7835. PCI_ANY_ID, PCI_ANY_ID, },
  7836. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  7837. PCI_ANY_ID, PCI_ANY_ID, },
  7838. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  7839. PCI_ANY_ID, PCI_ANY_ID, },
  7840. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  7841. PCI_ANY_ID, PCI_ANY_ID, },
  7842. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  7843. PCI_ANY_ID, PCI_ANY_ID, },
  7844. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  7845. PCI_ANY_ID, PCI_ANY_ID, },
  7846. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  7847. PCI_ANY_ID, PCI_ANY_ID, },
  7848. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  7849. PCI_ANY_ID, PCI_ANY_ID, },
  7850. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  7851. PCI_ANY_ID, PCI_ANY_ID, },
  7852. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  7853. PCI_ANY_ID, PCI_ANY_ID, },
  7854. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  7855. PCI_ANY_ID, PCI_ANY_ID, },
  7856. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  7857. PCI_ANY_ID, PCI_ANY_ID, },
  7858. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
  7859. PCI_ANY_ID, PCI_ANY_ID, },
  7860. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  7861. PCI_ANY_ID, PCI_ANY_ID, },
  7862. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  7863. PCI_ANY_ID, PCI_ANY_ID, },
  7864. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  7865. PCI_ANY_ID, PCI_ANY_ID, },
  7866. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  7867. PCI_ANY_ID, PCI_ANY_ID, },
  7868. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  7869. PCI_ANY_ID, PCI_ANY_ID, },
  7870. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  7871. PCI_ANY_ID, PCI_ANY_ID, },
  7872. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  7873. PCI_ANY_ID, PCI_ANY_ID, },
  7874. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  7875. PCI_ANY_ID, PCI_ANY_ID, },
  7876. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  7877. PCI_ANY_ID, PCI_ANY_ID, },
  7878. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  7879. PCI_ANY_ID, PCI_ANY_ID, },
  7880. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  7881. PCI_ANY_ID, PCI_ANY_ID, },
  7882. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  7883. PCI_ANY_ID, PCI_ANY_ID, },
  7884. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  7885. PCI_ANY_ID, PCI_ANY_ID, },
  7886. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  7887. PCI_ANY_ID, PCI_ANY_ID, },
  7888. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  7889. PCI_ANY_ID, PCI_ANY_ID, },
  7890. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
  7891. PCI_ANY_ID, PCI_ANY_ID, },
  7892. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
  7893. PCI_ANY_ID, PCI_ANY_ID, },
  7894. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
  7895. PCI_ANY_ID, PCI_ANY_ID, },
  7896. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
  7897. PCI_ANY_ID, PCI_ANY_ID, },
  7898. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
  7899. PCI_ANY_ID, PCI_ANY_ID, },
  7900. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
  7901. PCI_ANY_ID, PCI_ANY_ID, },
  7902. { 0 }
  7903. };
  7904. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  7905. static struct pci_error_handlers lpfc_err_handler = {
  7906. .error_detected = lpfc_io_error_detected,
  7907. .slot_reset = lpfc_io_slot_reset,
  7908. .resume = lpfc_io_resume,
  7909. };
  7910. static struct pci_driver lpfc_driver = {
  7911. .name = LPFC_DRIVER_NAME,
  7912. .id_table = lpfc_id_table,
  7913. .probe = lpfc_pci_probe_one,
  7914. .remove = __devexit_p(lpfc_pci_remove_one),
  7915. .suspend = lpfc_pci_suspend_one,
  7916. .resume = lpfc_pci_resume_one,
  7917. .err_handler = &lpfc_err_handler,
  7918. };
  7919. /**
  7920. * lpfc_init - lpfc module initialization routine
  7921. *
  7922. * This routine is to be invoked when the lpfc module is loaded into the
  7923. * kernel. The special kernel macro module_init() is used to indicate the
  7924. * role of this routine to the kernel as lpfc module entry point.
  7925. *
  7926. * Return codes
  7927. * 0 - successful
  7928. * -ENOMEM - FC attach transport failed
  7929. * all others - failed
  7930. */
  7931. static int __init
  7932. lpfc_init(void)
  7933. {
  7934. int error = 0;
  7935. printk(LPFC_MODULE_DESC "\n");
  7936. printk(LPFC_COPYRIGHT "\n");
  7937. if (lpfc_enable_npiv) {
  7938. lpfc_transport_functions.vport_create = lpfc_vport_create;
  7939. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  7940. }
  7941. lpfc_transport_template =
  7942. fc_attach_transport(&lpfc_transport_functions);
  7943. if (lpfc_transport_template == NULL)
  7944. return -ENOMEM;
  7945. if (lpfc_enable_npiv) {
  7946. lpfc_vport_transport_template =
  7947. fc_attach_transport(&lpfc_vport_transport_functions);
  7948. if (lpfc_vport_transport_template == NULL) {
  7949. fc_release_transport(lpfc_transport_template);
  7950. return -ENOMEM;
  7951. }
  7952. }
  7953. error = pci_register_driver(&lpfc_driver);
  7954. if (error) {
  7955. fc_release_transport(lpfc_transport_template);
  7956. if (lpfc_enable_npiv)
  7957. fc_release_transport(lpfc_vport_transport_template);
  7958. }
  7959. return error;
  7960. }
  7961. /**
  7962. * lpfc_exit - lpfc module removal routine
  7963. *
  7964. * This routine is invoked when the lpfc module is removed from the kernel.
  7965. * The special kernel macro module_exit() is used to indicate the role of
  7966. * this routine to the kernel as lpfc module exit point.
  7967. */
  7968. static void __exit
  7969. lpfc_exit(void)
  7970. {
  7971. pci_unregister_driver(&lpfc_driver);
  7972. fc_release_transport(lpfc_transport_template);
  7973. if (lpfc_enable_npiv)
  7974. fc_release_transport(lpfc_vport_transport_template);
  7975. if (_dump_buf_data) {
  7976. printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
  7977. "_dump_buf_data at 0x%p\n",
  7978. (1L << _dump_buf_data_order), _dump_buf_data);
  7979. free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
  7980. }
  7981. if (_dump_buf_dif) {
  7982. printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
  7983. "_dump_buf_dif at 0x%p\n",
  7984. (1L << _dump_buf_dif_order), _dump_buf_dif);
  7985. free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
  7986. }
  7987. }
  7988. module_init(lpfc_init);
  7989. module_exit(lpfc_exit);
  7990. MODULE_LICENSE("GPL");
  7991. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  7992. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  7993. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);