lpfc_init.c 314 KB

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