lpfc_init.c 325 KB

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