lpfc_init.c 315 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681
  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 + LPFC_RQ_DOORBELL;
  5677. phba->sli4_hba.WQDBregaddr =
  5678. phba->sli4_hba.conf_regs_memmap_p + LPFC_WQ_DOORBELL;
  5679. phba->sli4_hba.EQCQDBregaddr =
  5680. phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
  5681. phba->sli4_hba.MQDBregaddr =
  5682. phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
  5683. phba->sli4_hba.BMBXregaddr =
  5684. phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
  5685. break;
  5686. case LPFC_SLI_INTF_IF_TYPE_1:
  5687. default:
  5688. dev_printk(KERN_ERR, &phba->pcidev->dev,
  5689. "FATAL - unsupported SLI4 interface type - %d\n",
  5690. if_type);
  5691. break;
  5692. }
  5693. }
  5694. /**
  5695. * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
  5696. * @phba: pointer to lpfc hba data structure.
  5697. *
  5698. * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
  5699. * memory map.
  5700. **/
  5701. static void
  5702. lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
  5703. {
  5704. phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5705. LPFC_SLIPORT_IF0_SMPHR;
  5706. phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5707. LPFC_HST_ISR0;
  5708. phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5709. LPFC_HST_IMR0;
  5710. phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5711. LPFC_HST_ISCR0;
  5712. }
  5713. /**
  5714. * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
  5715. * @phba: pointer to lpfc hba data structure.
  5716. * @vf: virtual function number
  5717. *
  5718. * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
  5719. * based on the given viftual function number, @vf.
  5720. *
  5721. * Return 0 if successful, otherwise -ENODEV.
  5722. **/
  5723. static int
  5724. lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
  5725. {
  5726. if (vf > LPFC_VIR_FUNC_MAX)
  5727. return -ENODEV;
  5728. phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5729. vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL);
  5730. phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5731. vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL);
  5732. phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5733. vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
  5734. phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5735. vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
  5736. phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5737. vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
  5738. return 0;
  5739. }
  5740. /**
  5741. * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
  5742. * @phba: pointer to lpfc hba data structure.
  5743. *
  5744. * This routine is invoked to create the bootstrap mailbox
  5745. * region consistent with the SLI-4 interface spec. This
  5746. * routine allocates all memory necessary to communicate
  5747. * mailbox commands to the port and sets up all alignment
  5748. * needs. No locks are expected to be held when calling
  5749. * this routine.
  5750. *
  5751. * Return codes
  5752. * 0 - successful
  5753. * -ENOMEM - could not allocated memory.
  5754. **/
  5755. static int
  5756. lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
  5757. {
  5758. uint32_t bmbx_size;
  5759. struct lpfc_dmabuf *dmabuf;
  5760. struct dma_address *dma_address;
  5761. uint32_t pa_addr;
  5762. uint64_t phys_addr;
  5763. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  5764. if (!dmabuf)
  5765. return -ENOMEM;
  5766. /*
  5767. * The bootstrap mailbox region is comprised of 2 parts
  5768. * plus an alignment restriction of 16 bytes.
  5769. */
  5770. bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
  5771. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  5772. bmbx_size,
  5773. &dmabuf->phys,
  5774. GFP_KERNEL);
  5775. if (!dmabuf->virt) {
  5776. kfree(dmabuf);
  5777. return -ENOMEM;
  5778. }
  5779. memset(dmabuf->virt, 0, bmbx_size);
  5780. /*
  5781. * Initialize the bootstrap mailbox pointers now so that the register
  5782. * operations are simple later. The mailbox dma address is required
  5783. * to be 16-byte aligned. Also align the virtual memory as each
  5784. * maibox is copied into the bmbx mailbox region before issuing the
  5785. * command to the port.
  5786. */
  5787. phba->sli4_hba.bmbx.dmabuf = dmabuf;
  5788. phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
  5789. phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
  5790. LPFC_ALIGN_16_BYTE);
  5791. phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
  5792. LPFC_ALIGN_16_BYTE);
  5793. /*
  5794. * Set the high and low physical addresses now. The SLI4 alignment
  5795. * requirement is 16 bytes and the mailbox is posted to the port
  5796. * as two 30-bit addresses. The other data is a bit marking whether
  5797. * the 30-bit address is the high or low address.
  5798. * Upcast bmbx aphys to 64bits so shift instruction compiles
  5799. * clean on 32 bit machines.
  5800. */
  5801. dma_address = &phba->sli4_hba.bmbx.dma_address;
  5802. phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
  5803. pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
  5804. dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
  5805. LPFC_BMBX_BIT1_ADDR_HI);
  5806. pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
  5807. dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
  5808. LPFC_BMBX_BIT1_ADDR_LO);
  5809. return 0;
  5810. }
  5811. /**
  5812. * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
  5813. * @phba: pointer to lpfc hba data structure.
  5814. *
  5815. * This routine is invoked to teardown the bootstrap mailbox
  5816. * region and release all host resources. This routine requires
  5817. * the caller to ensure all mailbox commands recovered, no
  5818. * additional mailbox comands are sent, and interrupts are disabled
  5819. * before calling this routine.
  5820. *
  5821. **/
  5822. static void
  5823. lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
  5824. {
  5825. dma_free_coherent(&phba->pcidev->dev,
  5826. phba->sli4_hba.bmbx.bmbx_size,
  5827. phba->sli4_hba.bmbx.dmabuf->virt,
  5828. phba->sli4_hba.bmbx.dmabuf->phys);
  5829. kfree(phba->sli4_hba.bmbx.dmabuf);
  5830. memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
  5831. }
  5832. /**
  5833. * lpfc_sli4_read_config - Get the config parameters.
  5834. * @phba: pointer to lpfc hba data structure.
  5835. *
  5836. * This routine is invoked to read the configuration parameters from the HBA.
  5837. * The configuration parameters are used to set the base and maximum values
  5838. * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
  5839. * allocation for the port.
  5840. *
  5841. * Return codes
  5842. * 0 - successful
  5843. * -ENOMEM - No available memory
  5844. * -EIO - The mailbox failed to complete successfully.
  5845. **/
  5846. int
  5847. lpfc_sli4_read_config(struct lpfc_hba *phba)
  5848. {
  5849. LPFC_MBOXQ_t *pmb;
  5850. struct lpfc_mbx_read_config *rd_config;
  5851. union lpfc_sli4_cfg_shdr *shdr;
  5852. uint32_t shdr_status, shdr_add_status;
  5853. struct lpfc_mbx_get_func_cfg *get_func_cfg;
  5854. struct lpfc_rsrc_desc_fcfcoe *desc;
  5855. char *pdesc_0;
  5856. uint32_t desc_count;
  5857. int length, i, rc = 0, rc2;
  5858. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5859. if (!pmb) {
  5860. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5861. "2011 Unable to allocate memory for issuing "
  5862. "SLI_CONFIG_SPECIAL mailbox command\n");
  5863. return -ENOMEM;
  5864. }
  5865. lpfc_read_config(phba, pmb);
  5866. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  5867. if (rc != MBX_SUCCESS) {
  5868. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5869. "2012 Mailbox failed , mbxCmd x%x "
  5870. "READ_CONFIG, mbxStatus x%x\n",
  5871. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  5872. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  5873. rc = -EIO;
  5874. } else {
  5875. rd_config = &pmb->u.mqe.un.rd_config;
  5876. if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
  5877. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  5878. phba->sli4_hba.lnk_info.lnk_tp =
  5879. bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
  5880. phba->sli4_hba.lnk_info.lnk_no =
  5881. bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
  5882. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  5883. "3081 lnk_type:%d, lnk_numb:%d\n",
  5884. phba->sli4_hba.lnk_info.lnk_tp,
  5885. phba->sli4_hba.lnk_info.lnk_no);
  5886. } else
  5887. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5888. "3082 Mailbox (x%x) returned ldv:x0\n",
  5889. bf_get(lpfc_mqe_command, &pmb->u.mqe));
  5890. phba->sli4_hba.extents_in_use =
  5891. bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
  5892. phba->sli4_hba.max_cfg_param.max_xri =
  5893. bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
  5894. phba->sli4_hba.max_cfg_param.xri_base =
  5895. bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
  5896. phba->sli4_hba.max_cfg_param.max_vpi =
  5897. bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
  5898. phba->sli4_hba.max_cfg_param.vpi_base =
  5899. bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
  5900. phba->sli4_hba.max_cfg_param.max_rpi =
  5901. bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
  5902. phba->sli4_hba.max_cfg_param.rpi_base =
  5903. bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
  5904. phba->sli4_hba.max_cfg_param.max_vfi =
  5905. bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
  5906. phba->sli4_hba.max_cfg_param.vfi_base =
  5907. bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
  5908. phba->sli4_hba.max_cfg_param.max_fcfi =
  5909. bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
  5910. phba->sli4_hba.max_cfg_param.max_eq =
  5911. bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
  5912. phba->sli4_hba.max_cfg_param.max_rq =
  5913. bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
  5914. phba->sli4_hba.max_cfg_param.max_wq =
  5915. bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
  5916. phba->sli4_hba.max_cfg_param.max_cq =
  5917. bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
  5918. phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
  5919. phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
  5920. phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
  5921. phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
  5922. phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
  5923. (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
  5924. phba->max_vports = phba->max_vpi;
  5925. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  5926. "2003 cfg params Extents? %d "
  5927. "XRI(B:%d M:%d), "
  5928. "VPI(B:%d M:%d) "
  5929. "VFI(B:%d M:%d) "
  5930. "RPI(B:%d M:%d) "
  5931. "FCFI(Count:%d)\n",
  5932. phba->sli4_hba.extents_in_use,
  5933. phba->sli4_hba.max_cfg_param.xri_base,
  5934. phba->sli4_hba.max_cfg_param.max_xri,
  5935. phba->sli4_hba.max_cfg_param.vpi_base,
  5936. phba->sli4_hba.max_cfg_param.max_vpi,
  5937. phba->sli4_hba.max_cfg_param.vfi_base,
  5938. phba->sli4_hba.max_cfg_param.max_vfi,
  5939. phba->sli4_hba.max_cfg_param.rpi_base,
  5940. phba->sli4_hba.max_cfg_param.max_rpi,
  5941. phba->sli4_hba.max_cfg_param.max_fcfi);
  5942. }
  5943. if (rc)
  5944. goto read_cfg_out;
  5945. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  5946. if (phba->cfg_hba_queue_depth >
  5947. (phba->sli4_hba.max_cfg_param.max_xri -
  5948. lpfc_sli4_get_els_iocb_cnt(phba)))
  5949. phba->cfg_hba_queue_depth =
  5950. phba->sli4_hba.max_cfg_param.max_xri -
  5951. lpfc_sli4_get_els_iocb_cnt(phba);
  5952. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  5953. LPFC_SLI_INTF_IF_TYPE_2)
  5954. goto read_cfg_out;
  5955. /* get the pf# and vf# for SLI4 if_type 2 port */
  5956. length = (sizeof(struct lpfc_mbx_get_func_cfg) -
  5957. sizeof(struct lpfc_sli4_cfg_mhdr));
  5958. lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
  5959. LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
  5960. length, LPFC_SLI4_MBX_EMBED);
  5961. rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  5962. shdr = (union lpfc_sli4_cfg_shdr *)
  5963. &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
  5964. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  5965. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  5966. if (rc2 || shdr_status || shdr_add_status) {
  5967. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5968. "3026 Mailbox failed , mbxCmd x%x "
  5969. "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
  5970. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  5971. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  5972. goto read_cfg_out;
  5973. }
  5974. /* search for fc_fcoe resrouce descriptor */
  5975. get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
  5976. desc_count = get_func_cfg->func_cfg.rsrc_desc_count;
  5977. pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
  5978. desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
  5979. length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
  5980. if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
  5981. length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
  5982. else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
  5983. goto read_cfg_out;
  5984. for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
  5985. desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
  5986. if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
  5987. bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
  5988. phba->sli4_hba.iov.pf_number =
  5989. bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
  5990. phba->sli4_hba.iov.vf_number =
  5991. bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
  5992. break;
  5993. }
  5994. }
  5995. if (i < LPFC_RSRC_DESC_MAX_NUM)
  5996. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  5997. "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
  5998. "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
  5999. phba->sli4_hba.iov.vf_number);
  6000. else
  6001. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6002. "3028 GET_FUNCTION_CONFIG: failed to find "
  6003. "Resrouce Descriptor:x%x\n",
  6004. LPFC_RSRC_DESC_TYPE_FCFCOE);
  6005. read_cfg_out:
  6006. mempool_free(pmb, phba->mbox_mem_pool);
  6007. return rc;
  6008. }
  6009. /**
  6010. * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
  6011. * @phba: pointer to lpfc hba data structure.
  6012. *
  6013. * This routine is invoked to setup the port-side endian order when
  6014. * the port if_type is 0. This routine has no function for other
  6015. * if_types.
  6016. *
  6017. * Return codes
  6018. * 0 - successful
  6019. * -ENOMEM - No available memory
  6020. * -EIO - The mailbox failed to complete successfully.
  6021. **/
  6022. static int
  6023. lpfc_setup_endian_order(struct lpfc_hba *phba)
  6024. {
  6025. LPFC_MBOXQ_t *mboxq;
  6026. uint32_t if_type, rc = 0;
  6027. uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
  6028. HOST_ENDIAN_HIGH_WORD1};
  6029. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  6030. switch (if_type) {
  6031. case LPFC_SLI_INTF_IF_TYPE_0:
  6032. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  6033. GFP_KERNEL);
  6034. if (!mboxq) {
  6035. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6036. "0492 Unable to allocate memory for "
  6037. "issuing SLI_CONFIG_SPECIAL mailbox "
  6038. "command\n");
  6039. return -ENOMEM;
  6040. }
  6041. /*
  6042. * The SLI4_CONFIG_SPECIAL mailbox command requires the first
  6043. * two words to contain special data values and no other data.
  6044. */
  6045. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  6046. memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
  6047. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6048. if (rc != MBX_SUCCESS) {
  6049. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6050. "0493 SLI_CONFIG_SPECIAL mailbox "
  6051. "failed with status x%x\n",
  6052. rc);
  6053. rc = -EIO;
  6054. }
  6055. mempool_free(mboxq, phba->mbox_mem_pool);
  6056. break;
  6057. case LPFC_SLI_INTF_IF_TYPE_2:
  6058. case LPFC_SLI_INTF_IF_TYPE_1:
  6059. default:
  6060. break;
  6061. }
  6062. return rc;
  6063. }
  6064. /**
  6065. * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
  6066. * @phba: pointer to lpfc hba data structure.
  6067. *
  6068. * This routine is invoked to check the user settable queue counts for EQs and
  6069. * CQs. after this routine is called the counts will be set to valid values that
  6070. * adhere to the constraints of the system's interrupt vectors and the port's
  6071. * queue resources.
  6072. *
  6073. * Return codes
  6074. * 0 - successful
  6075. * -ENOMEM - No available memory
  6076. **/
  6077. static int
  6078. lpfc_sli4_queue_verify(struct lpfc_hba *phba)
  6079. {
  6080. int cfg_fcp_io_channel;
  6081. uint32_t cpu;
  6082. uint32_t i = 0;
  6083. /*
  6084. * Sanity check for configured queue parameters against the run-time
  6085. * device parameters
  6086. */
  6087. /* Sanity check on HBA EQ parameters */
  6088. cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
  6089. /* It doesn't make sense to have more io channels then CPUs */
  6090. for_each_online_cpu(cpu) {
  6091. i++;
  6092. }
  6093. if (i < cfg_fcp_io_channel) {
  6094. lpfc_printf_log(phba,
  6095. KERN_ERR, LOG_INIT,
  6096. "3188 Reducing IO channels to match number of "
  6097. "CPUs: from %d to %d\n", cfg_fcp_io_channel, i);
  6098. cfg_fcp_io_channel = i;
  6099. }
  6100. if (cfg_fcp_io_channel >
  6101. phba->sli4_hba.max_cfg_param.max_eq) {
  6102. if (phba->sli4_hba.max_cfg_param.max_eq <
  6103. LPFC_FCP_IO_CHAN_MIN) {
  6104. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6105. "2574 Not enough EQs (%d) from the "
  6106. "pci function for supporting FCP "
  6107. "EQs (%d)\n",
  6108. phba->sli4_hba.max_cfg_param.max_eq,
  6109. phba->cfg_fcp_io_channel);
  6110. goto out_error;
  6111. }
  6112. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6113. "2575 Reducing IO channels to match number of "
  6114. "available EQs: from %d to %d\n",
  6115. cfg_fcp_io_channel,
  6116. phba->sli4_hba.max_cfg_param.max_eq);
  6117. cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq;
  6118. }
  6119. /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */
  6120. /* The actual number of FCP event queues adopted */
  6121. phba->cfg_fcp_eq_count = cfg_fcp_io_channel;
  6122. phba->cfg_fcp_wq_count = cfg_fcp_io_channel;
  6123. phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
  6124. /* Get EQ depth from module parameter, fake the default for now */
  6125. phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
  6126. phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
  6127. /* Get CQ depth from module parameter, fake the default for now */
  6128. phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
  6129. phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
  6130. return 0;
  6131. out_error:
  6132. return -ENOMEM;
  6133. }
  6134. /**
  6135. * lpfc_sli4_queue_create - Create all the SLI4 queues
  6136. * @phba: pointer to lpfc hba data structure.
  6137. *
  6138. * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
  6139. * operation. For each SLI4 queue type, the parameters such as queue entry
  6140. * count (queue depth) shall be taken from the module parameter. For now,
  6141. * we just use some constant number as place holder.
  6142. *
  6143. * Return codes
  6144. * 0 - successful
  6145. * -ENOMEM - No availble memory
  6146. * -EIO - The mailbox failed to complete successfully.
  6147. **/
  6148. int
  6149. lpfc_sli4_queue_create(struct lpfc_hba *phba)
  6150. {
  6151. struct lpfc_queue *qdesc;
  6152. int idx;
  6153. /*
  6154. * Create HBA Record arrays.
  6155. */
  6156. if (!phba->cfg_fcp_io_channel)
  6157. return -ERANGE;
  6158. phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
  6159. phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
  6160. phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
  6161. phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
  6162. phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
  6163. phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
  6164. phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
  6165. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6166. if (!phba->sli4_hba.hba_eq) {
  6167. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6168. "2576 Failed allocate memory for "
  6169. "fast-path EQ record array\n");
  6170. goto out_error;
  6171. }
  6172. phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
  6173. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6174. if (!phba->sli4_hba.fcp_cq) {
  6175. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6176. "2577 Failed allocate memory for fast-path "
  6177. "CQ record array\n");
  6178. goto out_error;
  6179. }
  6180. phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
  6181. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6182. if (!phba->sli4_hba.fcp_wq) {
  6183. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6184. "2578 Failed allocate memory for fast-path "
  6185. "WQ record array\n");
  6186. goto out_error;
  6187. }
  6188. /*
  6189. * Since the first EQ can have multiple CQs associated with it,
  6190. * this array is used to quickly see if we have a FCP fast-path
  6191. * CQ match.
  6192. */
  6193. phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
  6194. phba->cfg_fcp_io_channel), GFP_KERNEL);
  6195. if (!phba->sli4_hba.fcp_cq_map) {
  6196. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6197. "2545 Failed allocate memory for fast-path "
  6198. "CQ map\n");
  6199. goto out_error;
  6200. }
  6201. /*
  6202. * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
  6203. * how many EQs to create.
  6204. */
  6205. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6206. /* Create EQs */
  6207. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  6208. phba->sli4_hba.eq_ecount);
  6209. if (!qdesc) {
  6210. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6211. "0497 Failed allocate EQ (%d)\n", idx);
  6212. goto out_error;
  6213. }
  6214. phba->sli4_hba.hba_eq[idx] = qdesc;
  6215. /* Create Fast Path FCP CQs */
  6216. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  6217. phba->sli4_hba.cq_ecount);
  6218. if (!qdesc) {
  6219. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6220. "0499 Failed allocate fast-path FCP "
  6221. "CQ (%d)\n", idx);
  6222. goto out_error;
  6223. }
  6224. phba->sli4_hba.fcp_cq[idx] = qdesc;
  6225. /* Create Fast Path FCP WQs */
  6226. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  6227. phba->sli4_hba.wq_ecount);
  6228. if (!qdesc) {
  6229. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6230. "0503 Failed allocate fast-path FCP "
  6231. "WQ (%d)\n", idx);
  6232. goto out_error;
  6233. }
  6234. phba->sli4_hba.fcp_wq[idx] = qdesc;
  6235. }
  6236. /*
  6237. * Create Slow Path Completion Queues (CQs)
  6238. */
  6239. /* Create slow-path Mailbox Command Complete Queue */
  6240. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  6241. phba->sli4_hba.cq_ecount);
  6242. if (!qdesc) {
  6243. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6244. "0500 Failed allocate slow-path mailbox CQ\n");
  6245. goto out_error;
  6246. }
  6247. phba->sli4_hba.mbx_cq = qdesc;
  6248. /* Create slow-path ELS Complete Queue */
  6249. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  6250. phba->sli4_hba.cq_ecount);
  6251. if (!qdesc) {
  6252. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6253. "0501 Failed allocate slow-path ELS CQ\n");
  6254. goto out_error;
  6255. }
  6256. phba->sli4_hba.els_cq = qdesc;
  6257. /*
  6258. * Create Slow Path Work Queues (WQs)
  6259. */
  6260. /* Create Mailbox Command Queue */
  6261. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
  6262. phba->sli4_hba.mq_ecount);
  6263. if (!qdesc) {
  6264. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6265. "0505 Failed allocate slow-path MQ\n");
  6266. goto out_error;
  6267. }
  6268. phba->sli4_hba.mbx_wq = qdesc;
  6269. /*
  6270. * Create ELS Work Queues
  6271. */
  6272. /* Create slow-path ELS Work Queue */
  6273. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  6274. phba->sli4_hba.wq_ecount);
  6275. if (!qdesc) {
  6276. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6277. "0504 Failed allocate slow-path ELS WQ\n");
  6278. goto out_error;
  6279. }
  6280. phba->sli4_hba.els_wq = qdesc;
  6281. /*
  6282. * Create Receive Queue (RQ)
  6283. */
  6284. /* Create Receive Queue for header */
  6285. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  6286. phba->sli4_hba.rq_ecount);
  6287. if (!qdesc) {
  6288. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6289. "0506 Failed allocate receive HRQ\n");
  6290. goto out_error;
  6291. }
  6292. phba->sli4_hba.hdr_rq = qdesc;
  6293. /* Create Receive Queue for data */
  6294. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  6295. phba->sli4_hba.rq_ecount);
  6296. if (!qdesc) {
  6297. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6298. "0507 Failed allocate receive DRQ\n");
  6299. goto out_error;
  6300. }
  6301. phba->sli4_hba.dat_rq = qdesc;
  6302. return 0;
  6303. out_error:
  6304. lpfc_sli4_queue_destroy(phba);
  6305. return -ENOMEM;
  6306. }
  6307. /**
  6308. * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
  6309. * @phba: pointer to lpfc hba data structure.
  6310. *
  6311. * This routine is invoked to release all the SLI4 queues with the FCoE HBA
  6312. * operation.
  6313. *
  6314. * Return codes
  6315. * 0 - successful
  6316. * -ENOMEM - No available memory
  6317. * -EIO - The mailbox failed to complete successfully.
  6318. **/
  6319. void
  6320. lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
  6321. {
  6322. int idx;
  6323. if (phba->sli4_hba.hba_eq != NULL) {
  6324. /* Release HBA event queue */
  6325. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6326. if (phba->sli4_hba.hba_eq[idx] != NULL) {
  6327. lpfc_sli4_queue_free(
  6328. phba->sli4_hba.hba_eq[idx]);
  6329. phba->sli4_hba.hba_eq[idx] = NULL;
  6330. }
  6331. }
  6332. kfree(phba->sli4_hba.hba_eq);
  6333. phba->sli4_hba.hba_eq = NULL;
  6334. }
  6335. if (phba->sli4_hba.fcp_cq != NULL) {
  6336. /* Release FCP completion queue */
  6337. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6338. if (phba->sli4_hba.fcp_cq[idx] != NULL) {
  6339. lpfc_sli4_queue_free(
  6340. phba->sli4_hba.fcp_cq[idx]);
  6341. phba->sli4_hba.fcp_cq[idx] = NULL;
  6342. }
  6343. }
  6344. kfree(phba->sli4_hba.fcp_cq);
  6345. phba->sli4_hba.fcp_cq = NULL;
  6346. }
  6347. if (phba->sli4_hba.fcp_wq != NULL) {
  6348. /* Release FCP work queue */
  6349. for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
  6350. if (phba->sli4_hba.fcp_wq[idx] != NULL) {
  6351. lpfc_sli4_queue_free(
  6352. phba->sli4_hba.fcp_wq[idx]);
  6353. phba->sli4_hba.fcp_wq[idx] = NULL;
  6354. }
  6355. }
  6356. kfree(phba->sli4_hba.fcp_wq);
  6357. phba->sli4_hba.fcp_wq = NULL;
  6358. }
  6359. /* Release FCP CQ mapping array */
  6360. if (phba->sli4_hba.fcp_cq_map != NULL) {
  6361. kfree(phba->sli4_hba.fcp_cq_map);
  6362. phba->sli4_hba.fcp_cq_map = NULL;
  6363. }
  6364. /* Release mailbox command work queue */
  6365. if (phba->sli4_hba.mbx_wq != NULL) {
  6366. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  6367. phba->sli4_hba.mbx_wq = NULL;
  6368. }
  6369. /* Release ELS work queue */
  6370. if (phba->sli4_hba.els_wq != NULL) {
  6371. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  6372. phba->sli4_hba.els_wq = NULL;
  6373. }
  6374. /* Release unsolicited receive queue */
  6375. if (phba->sli4_hba.hdr_rq != NULL) {
  6376. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  6377. phba->sli4_hba.hdr_rq = NULL;
  6378. }
  6379. if (phba->sli4_hba.dat_rq != NULL) {
  6380. lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
  6381. phba->sli4_hba.dat_rq = NULL;
  6382. }
  6383. /* Release ELS complete queue */
  6384. if (phba->sli4_hba.els_cq != NULL) {
  6385. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  6386. phba->sli4_hba.els_cq = NULL;
  6387. }
  6388. /* Release mailbox command complete queue */
  6389. if (phba->sli4_hba.mbx_cq != NULL) {
  6390. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  6391. phba->sli4_hba.mbx_cq = NULL;
  6392. }
  6393. return;
  6394. }
  6395. /**
  6396. * lpfc_sli4_queue_setup - Set up all the SLI4 queues
  6397. * @phba: pointer to lpfc hba data structure.
  6398. *
  6399. * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
  6400. * operation.
  6401. *
  6402. * Return codes
  6403. * 0 - successful
  6404. * -ENOMEM - No available memory
  6405. * -EIO - The mailbox failed to complete successfully.
  6406. **/
  6407. int
  6408. lpfc_sli4_queue_setup(struct lpfc_hba *phba)
  6409. {
  6410. struct lpfc_sli *psli = &phba->sli;
  6411. struct lpfc_sli_ring *pring;
  6412. int rc = -ENOMEM;
  6413. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  6414. int fcp_cq_index = 0;
  6415. /*
  6416. * Set up HBA Event Queues (EQs)
  6417. */
  6418. /* Set up HBA event queue */
  6419. if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
  6420. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6421. "3147 Fast-path EQs not allocated\n");
  6422. rc = -ENOMEM;
  6423. goto out_error;
  6424. }
  6425. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
  6426. if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
  6427. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6428. "0522 Fast-path EQ (%d) not "
  6429. "allocated\n", fcp_eqidx);
  6430. rc = -ENOMEM;
  6431. goto out_destroy_hba_eq;
  6432. }
  6433. rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
  6434. (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
  6435. if (rc) {
  6436. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6437. "0523 Failed setup of fast-path EQ "
  6438. "(%d), rc = 0x%x\n", fcp_eqidx, rc);
  6439. goto out_destroy_hba_eq;
  6440. }
  6441. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6442. "2584 HBA EQ setup: "
  6443. "queue[%d]-id=%d\n", fcp_eqidx,
  6444. phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
  6445. }
  6446. /* Set up fast-path FCP Response Complete Queue */
  6447. if (!phba->sli4_hba.fcp_cq) {
  6448. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6449. "3148 Fast-path FCP CQ array not "
  6450. "allocated\n");
  6451. rc = -ENOMEM;
  6452. goto out_destroy_hba_eq;
  6453. }
  6454. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
  6455. if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
  6456. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6457. "0526 Fast-path FCP CQ (%d) not "
  6458. "allocated\n", fcp_cqidx);
  6459. rc = -ENOMEM;
  6460. goto out_destroy_fcp_cq;
  6461. }
  6462. rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
  6463. phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
  6464. if (rc) {
  6465. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6466. "0527 Failed setup of fast-path FCP "
  6467. "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
  6468. goto out_destroy_fcp_cq;
  6469. }
  6470. /* Setup fcp_cq_map for fast lookup */
  6471. phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
  6472. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
  6473. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6474. "2588 FCP CQ setup: cq[%d]-id=%d, "
  6475. "parent seq[%d]-id=%d\n",
  6476. fcp_cqidx,
  6477. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
  6478. fcp_cqidx,
  6479. phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
  6480. }
  6481. /* Set up fast-path FCP Work Queue */
  6482. if (!phba->sli4_hba.fcp_wq) {
  6483. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6484. "3149 Fast-path FCP WQ array not "
  6485. "allocated\n");
  6486. rc = -ENOMEM;
  6487. goto out_destroy_fcp_cq;
  6488. }
  6489. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
  6490. if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
  6491. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6492. "0534 Fast-path FCP WQ (%d) not "
  6493. "allocated\n", fcp_wqidx);
  6494. rc = -ENOMEM;
  6495. goto out_destroy_fcp_wq;
  6496. }
  6497. rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
  6498. phba->sli4_hba.fcp_cq[fcp_wqidx],
  6499. LPFC_FCP);
  6500. if (rc) {
  6501. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6502. "0535 Failed setup of fast-path FCP "
  6503. "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
  6504. goto out_destroy_fcp_wq;
  6505. }
  6506. /* Bind this WQ to the next FCP ring */
  6507. pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
  6508. pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
  6509. phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
  6510. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6511. "2591 FCP WQ setup: wq[%d]-id=%d, "
  6512. "parent cq[%d]-id=%d\n",
  6513. fcp_wqidx,
  6514. phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
  6515. fcp_cq_index,
  6516. phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
  6517. }
  6518. /*
  6519. * Set up Complete Queues (CQs)
  6520. */
  6521. /* Set up slow-path MBOX Complete Queue as the first CQ */
  6522. if (!phba->sli4_hba.mbx_cq) {
  6523. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6524. "0528 Mailbox CQ not allocated\n");
  6525. rc = -ENOMEM;
  6526. goto out_destroy_fcp_wq;
  6527. }
  6528. rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
  6529. phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
  6530. if (rc) {
  6531. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6532. "0529 Failed setup of slow-path mailbox CQ: "
  6533. "rc = 0x%x\n", rc);
  6534. goto out_destroy_fcp_wq;
  6535. }
  6536. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6537. "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
  6538. phba->sli4_hba.mbx_cq->queue_id,
  6539. phba->sli4_hba.hba_eq[0]->queue_id);
  6540. /* Set up slow-path ELS Complete Queue */
  6541. if (!phba->sli4_hba.els_cq) {
  6542. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6543. "0530 ELS CQ not allocated\n");
  6544. rc = -ENOMEM;
  6545. goto out_destroy_mbx_cq;
  6546. }
  6547. rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
  6548. phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
  6549. if (rc) {
  6550. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6551. "0531 Failed setup of slow-path ELS CQ: "
  6552. "rc = 0x%x\n", rc);
  6553. goto out_destroy_mbx_cq;
  6554. }
  6555. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6556. "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
  6557. phba->sli4_hba.els_cq->queue_id,
  6558. phba->sli4_hba.hba_eq[0]->queue_id);
  6559. /*
  6560. * Set up all the Work Queues (WQs)
  6561. */
  6562. /* Set up Mailbox Command Queue */
  6563. if (!phba->sli4_hba.mbx_wq) {
  6564. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6565. "0538 Slow-path MQ not allocated\n");
  6566. rc = -ENOMEM;
  6567. goto out_destroy_els_cq;
  6568. }
  6569. rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
  6570. phba->sli4_hba.mbx_cq, LPFC_MBOX);
  6571. if (rc) {
  6572. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6573. "0539 Failed setup of slow-path MQ: "
  6574. "rc = 0x%x\n", rc);
  6575. goto out_destroy_els_cq;
  6576. }
  6577. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6578. "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
  6579. phba->sli4_hba.mbx_wq->queue_id,
  6580. phba->sli4_hba.mbx_cq->queue_id);
  6581. /* Set up slow-path ELS Work Queue */
  6582. if (!phba->sli4_hba.els_wq) {
  6583. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6584. "0536 Slow-path ELS WQ not allocated\n");
  6585. rc = -ENOMEM;
  6586. goto out_destroy_mbx_wq;
  6587. }
  6588. rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
  6589. phba->sli4_hba.els_cq, LPFC_ELS);
  6590. if (rc) {
  6591. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6592. "0537 Failed setup of slow-path ELS WQ: "
  6593. "rc = 0x%x\n", rc);
  6594. goto out_destroy_mbx_wq;
  6595. }
  6596. /* Bind this WQ to the ELS ring */
  6597. pring = &psli->ring[LPFC_ELS_RING];
  6598. pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
  6599. phba->sli4_hba.els_cq->pring = pring;
  6600. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6601. "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
  6602. phba->sli4_hba.els_wq->queue_id,
  6603. phba->sli4_hba.els_cq->queue_id);
  6604. /*
  6605. * Create Receive Queue (RQ)
  6606. */
  6607. if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
  6608. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6609. "0540 Receive Queue not allocated\n");
  6610. rc = -ENOMEM;
  6611. goto out_destroy_els_wq;
  6612. }
  6613. lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
  6614. lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
  6615. rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  6616. phba->sli4_hba.els_cq, LPFC_USOL);
  6617. if (rc) {
  6618. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6619. "0541 Failed setup of Receive Queue: "
  6620. "rc = 0x%x\n", rc);
  6621. goto out_destroy_fcp_wq;
  6622. }
  6623. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6624. "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
  6625. "parent cq-id=%d\n",
  6626. phba->sli4_hba.hdr_rq->queue_id,
  6627. phba->sli4_hba.dat_rq->queue_id,
  6628. phba->sli4_hba.els_cq->queue_id);
  6629. return 0;
  6630. out_destroy_els_wq:
  6631. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  6632. out_destroy_mbx_wq:
  6633. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  6634. out_destroy_els_cq:
  6635. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  6636. out_destroy_mbx_cq:
  6637. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  6638. out_destroy_fcp_wq:
  6639. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
  6640. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
  6641. out_destroy_fcp_cq:
  6642. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
  6643. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
  6644. out_destroy_hba_eq:
  6645. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
  6646. lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
  6647. out_error:
  6648. return rc;
  6649. }
  6650. /**
  6651. * lpfc_sli4_queue_unset - Unset all the SLI4 queues
  6652. * @phba: pointer to lpfc hba data structure.
  6653. *
  6654. * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
  6655. * operation.
  6656. *
  6657. * Return codes
  6658. * 0 - successful
  6659. * -ENOMEM - No available memory
  6660. * -EIO - The mailbox failed to complete successfully.
  6661. **/
  6662. void
  6663. lpfc_sli4_queue_unset(struct lpfc_hba *phba)
  6664. {
  6665. int fcp_qidx;
  6666. /* Unset mailbox command work queue */
  6667. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  6668. /* Unset ELS work queue */
  6669. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  6670. /* Unset unsolicited receive queue */
  6671. lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
  6672. /* Unset FCP work queue */
  6673. if (phba->sli4_hba.fcp_wq) {
  6674. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
  6675. fcp_qidx++)
  6676. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
  6677. }
  6678. /* Unset mailbox command complete queue */
  6679. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  6680. /* Unset ELS complete queue */
  6681. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  6682. /* Unset FCP response complete queue */
  6683. if (phba->sli4_hba.fcp_cq) {
  6684. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
  6685. fcp_qidx++)
  6686. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
  6687. }
  6688. /* Unset fast-path event queue */
  6689. if (phba->sli4_hba.hba_eq) {
  6690. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
  6691. fcp_qidx++)
  6692. lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
  6693. }
  6694. }
  6695. /**
  6696. * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
  6697. * @phba: pointer to lpfc hba data structure.
  6698. *
  6699. * This routine is invoked to allocate and set up a pool of completion queue
  6700. * events. The body of the completion queue event is a completion queue entry
  6701. * CQE. For now, this pool is used for the interrupt service routine to queue
  6702. * the following HBA completion queue events for the worker thread to process:
  6703. * - Mailbox asynchronous events
  6704. * - Receive queue completion unsolicited events
  6705. * Later, this can be used for all the slow-path events.
  6706. *
  6707. * Return codes
  6708. * 0 - successful
  6709. * -ENOMEM - No available memory
  6710. **/
  6711. static int
  6712. lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
  6713. {
  6714. struct lpfc_cq_event *cq_event;
  6715. int i;
  6716. for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
  6717. cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
  6718. if (!cq_event)
  6719. goto out_pool_create_fail;
  6720. list_add_tail(&cq_event->list,
  6721. &phba->sli4_hba.sp_cqe_event_pool);
  6722. }
  6723. return 0;
  6724. out_pool_create_fail:
  6725. lpfc_sli4_cq_event_pool_destroy(phba);
  6726. return -ENOMEM;
  6727. }
  6728. /**
  6729. * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
  6730. * @phba: pointer to lpfc hba data structure.
  6731. *
  6732. * This routine is invoked to free the pool of completion queue events at
  6733. * driver unload time. Note that, it is the responsibility of the driver
  6734. * cleanup routine to free all the outstanding completion-queue events
  6735. * allocated from this pool back into the pool before invoking this routine
  6736. * to destroy the pool.
  6737. **/
  6738. static void
  6739. lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
  6740. {
  6741. struct lpfc_cq_event *cq_event, *next_cq_event;
  6742. list_for_each_entry_safe(cq_event, next_cq_event,
  6743. &phba->sli4_hba.sp_cqe_event_pool, list) {
  6744. list_del(&cq_event->list);
  6745. kfree(cq_event);
  6746. }
  6747. }
  6748. /**
  6749. * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  6750. * @phba: pointer to lpfc hba data structure.
  6751. *
  6752. * This routine is the lock free version of the API invoked to allocate a
  6753. * completion-queue event from the free pool.
  6754. *
  6755. * Return: Pointer to the newly allocated completion-queue event if successful
  6756. * NULL otherwise.
  6757. **/
  6758. struct lpfc_cq_event *
  6759. __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  6760. {
  6761. struct lpfc_cq_event *cq_event = NULL;
  6762. list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
  6763. struct lpfc_cq_event, list);
  6764. return cq_event;
  6765. }
  6766. /**
  6767. * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  6768. * @phba: pointer to lpfc hba data structure.
  6769. *
  6770. * This routine is the lock version of the API invoked to allocate a
  6771. * completion-queue event from the free pool.
  6772. *
  6773. * Return: Pointer to the newly allocated completion-queue event if successful
  6774. * NULL otherwise.
  6775. **/
  6776. struct lpfc_cq_event *
  6777. lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  6778. {
  6779. struct lpfc_cq_event *cq_event;
  6780. unsigned long iflags;
  6781. spin_lock_irqsave(&phba->hbalock, iflags);
  6782. cq_event = __lpfc_sli4_cq_event_alloc(phba);
  6783. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6784. return cq_event;
  6785. }
  6786. /**
  6787. * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  6788. * @phba: pointer to lpfc hba data structure.
  6789. * @cq_event: pointer to the completion queue event to be freed.
  6790. *
  6791. * This routine is the lock free version of the API invoked to release a
  6792. * completion-queue event back into the free pool.
  6793. **/
  6794. void
  6795. __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  6796. struct lpfc_cq_event *cq_event)
  6797. {
  6798. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
  6799. }
  6800. /**
  6801. * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  6802. * @phba: pointer to lpfc hba data structure.
  6803. * @cq_event: pointer to the completion queue event to be freed.
  6804. *
  6805. * This routine is the lock version of the API invoked to release a
  6806. * completion-queue event back into the free pool.
  6807. **/
  6808. void
  6809. lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  6810. struct lpfc_cq_event *cq_event)
  6811. {
  6812. unsigned long iflags;
  6813. spin_lock_irqsave(&phba->hbalock, iflags);
  6814. __lpfc_sli4_cq_event_release(phba, cq_event);
  6815. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6816. }
  6817. /**
  6818. * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
  6819. * @phba: pointer to lpfc hba data structure.
  6820. *
  6821. * This routine is to free all the pending completion-queue events to the
  6822. * back into the free pool for device reset.
  6823. **/
  6824. static void
  6825. lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
  6826. {
  6827. LIST_HEAD(cqelist);
  6828. struct lpfc_cq_event *cqe;
  6829. unsigned long iflags;
  6830. /* Retrieve all the pending WCQEs from pending WCQE lists */
  6831. spin_lock_irqsave(&phba->hbalock, iflags);
  6832. /* Pending FCP XRI abort events */
  6833. list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  6834. &cqelist);
  6835. /* Pending ELS XRI abort events */
  6836. list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  6837. &cqelist);
  6838. /* Pending asynnc events */
  6839. list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
  6840. &cqelist);
  6841. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6842. while (!list_empty(&cqelist)) {
  6843. list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
  6844. lpfc_sli4_cq_event_release(phba, cqe);
  6845. }
  6846. }
  6847. /**
  6848. * lpfc_pci_function_reset - Reset pci function.
  6849. * @phba: pointer to lpfc hba data structure.
  6850. *
  6851. * This routine is invoked to request a PCI function reset. It will destroys
  6852. * all resources assigned to the PCI function which originates this request.
  6853. *
  6854. * Return codes
  6855. * 0 - successful
  6856. * -ENOMEM - No available memory
  6857. * -EIO - The mailbox failed to complete successfully.
  6858. **/
  6859. int
  6860. lpfc_pci_function_reset(struct lpfc_hba *phba)
  6861. {
  6862. LPFC_MBOXQ_t *mboxq;
  6863. uint32_t rc = 0, if_type;
  6864. uint32_t shdr_status, shdr_add_status;
  6865. uint32_t rdy_chk, num_resets = 0, reset_again = 0;
  6866. union lpfc_sli4_cfg_shdr *shdr;
  6867. struct lpfc_register reg_data;
  6868. uint16_t devid;
  6869. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  6870. switch (if_type) {
  6871. case LPFC_SLI_INTF_IF_TYPE_0:
  6872. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  6873. GFP_KERNEL);
  6874. if (!mboxq) {
  6875. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6876. "0494 Unable to allocate memory for "
  6877. "issuing SLI_FUNCTION_RESET mailbox "
  6878. "command\n");
  6879. return -ENOMEM;
  6880. }
  6881. /* Setup PCI function reset mailbox-ioctl command */
  6882. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  6883. LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
  6884. LPFC_SLI4_MBX_EMBED);
  6885. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6886. shdr = (union lpfc_sli4_cfg_shdr *)
  6887. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  6888. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  6889. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  6890. &shdr->response);
  6891. if (rc != MBX_TIMEOUT)
  6892. mempool_free(mboxq, phba->mbox_mem_pool);
  6893. if (shdr_status || shdr_add_status || rc) {
  6894. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6895. "0495 SLI_FUNCTION_RESET mailbox "
  6896. "failed with status x%x add_status x%x,"
  6897. " mbx status x%x\n",
  6898. shdr_status, shdr_add_status, rc);
  6899. rc = -ENXIO;
  6900. }
  6901. break;
  6902. case LPFC_SLI_INTF_IF_TYPE_2:
  6903. for (num_resets = 0;
  6904. num_resets < MAX_IF_TYPE_2_RESETS;
  6905. num_resets++) {
  6906. reg_data.word0 = 0;
  6907. bf_set(lpfc_sliport_ctrl_end, &reg_data,
  6908. LPFC_SLIPORT_LITTLE_ENDIAN);
  6909. bf_set(lpfc_sliport_ctrl_ip, &reg_data,
  6910. LPFC_SLIPORT_INIT_PORT);
  6911. writel(reg_data.word0, phba->sli4_hba.u.if_type2.
  6912. CTRLregaddr);
  6913. /* flush */
  6914. pci_read_config_word(phba->pcidev,
  6915. PCI_DEVICE_ID, &devid);
  6916. /*
  6917. * Poll the Port Status Register and wait for RDY for
  6918. * up to 10 seconds. If the port doesn't respond, treat
  6919. * it as an error. If the port responds with RN, start
  6920. * the loop again.
  6921. */
  6922. for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) {
  6923. msleep(10);
  6924. if (lpfc_readl(phba->sli4_hba.u.if_type2.
  6925. STATUSregaddr, &reg_data.word0)) {
  6926. rc = -ENODEV;
  6927. goto out;
  6928. }
  6929. if (bf_get(lpfc_sliport_status_rn, &reg_data))
  6930. reset_again++;
  6931. if (bf_get(lpfc_sliport_status_rdy, &reg_data))
  6932. break;
  6933. }
  6934. /*
  6935. * If the port responds to the init request with
  6936. * reset needed, delay for a bit and restart the loop.
  6937. */
  6938. if (reset_again && (rdy_chk < 1000)) {
  6939. msleep(10);
  6940. reset_again = 0;
  6941. continue;
  6942. }
  6943. /* Detect any port errors. */
  6944. if ((bf_get(lpfc_sliport_status_err, &reg_data)) ||
  6945. (rdy_chk >= 1000)) {
  6946. phba->work_status[0] = readl(
  6947. phba->sli4_hba.u.if_type2.ERR1regaddr);
  6948. phba->work_status[1] = readl(
  6949. phba->sli4_hba.u.if_type2.ERR2regaddr);
  6950. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6951. "2890 Port error detected during port "
  6952. "reset(%d): wait_tmo:%d ms, "
  6953. "port status reg 0x%x, "
  6954. "error 1=0x%x, error 2=0x%x\n",
  6955. num_resets, rdy_chk*10,
  6956. reg_data.word0,
  6957. phba->work_status[0],
  6958. phba->work_status[1]);
  6959. rc = -ENODEV;
  6960. }
  6961. /*
  6962. * Terminate the outer loop provided the Port indicated
  6963. * ready within 10 seconds.
  6964. */
  6965. if (rdy_chk < 1000)
  6966. break;
  6967. }
  6968. /* delay driver action following IF_TYPE_2 function reset */
  6969. msleep(100);
  6970. break;
  6971. case LPFC_SLI_INTF_IF_TYPE_1:
  6972. default:
  6973. break;
  6974. }
  6975. out:
  6976. /* Catch the not-ready port failure after a port reset. */
  6977. if (num_resets >= MAX_IF_TYPE_2_RESETS)
  6978. rc = -ENODEV;
  6979. return rc;
  6980. }
  6981. /**
  6982. * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
  6983. * @phba: pointer to lpfc hba data structure.
  6984. * @cnt: number of nop mailbox commands to send.
  6985. *
  6986. * This routine is invoked to send a number @cnt of NOP mailbox command and
  6987. * wait for each command to complete.
  6988. *
  6989. * Return: the number of NOP mailbox command completed.
  6990. **/
  6991. static int
  6992. lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
  6993. {
  6994. LPFC_MBOXQ_t *mboxq;
  6995. int length, cmdsent;
  6996. uint32_t mbox_tmo;
  6997. uint32_t rc = 0;
  6998. uint32_t shdr_status, shdr_add_status;
  6999. union lpfc_sli4_cfg_shdr *shdr;
  7000. if (cnt == 0) {
  7001. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7002. "2518 Requested to send 0 NOP mailbox cmd\n");
  7003. return cnt;
  7004. }
  7005. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  7006. if (!mboxq) {
  7007. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7008. "2519 Unable to allocate memory for issuing "
  7009. "NOP mailbox command\n");
  7010. return 0;
  7011. }
  7012. /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
  7013. length = (sizeof(struct lpfc_mbx_nop) -
  7014. sizeof(struct lpfc_sli4_cfg_mhdr));
  7015. for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
  7016. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  7017. LPFC_MBOX_OPCODE_NOP, length,
  7018. LPFC_SLI4_MBX_EMBED);
  7019. if (!phba->sli4_hba.intr_enable)
  7020. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7021. else {
  7022. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  7023. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  7024. }
  7025. if (rc == MBX_TIMEOUT)
  7026. break;
  7027. /* Check return status */
  7028. shdr = (union lpfc_sli4_cfg_shdr *)
  7029. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  7030. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  7031. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  7032. &shdr->response);
  7033. if (shdr_status || shdr_add_status || rc) {
  7034. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7035. "2520 NOP mailbox command failed "
  7036. "status x%x add_status x%x mbx "
  7037. "status x%x\n", shdr_status,
  7038. shdr_add_status, rc);
  7039. break;
  7040. }
  7041. }
  7042. if (rc != MBX_TIMEOUT)
  7043. mempool_free(mboxq, phba->mbox_mem_pool);
  7044. return cmdsent;
  7045. }
  7046. /**
  7047. * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
  7048. * @phba: pointer to lpfc hba data structure.
  7049. *
  7050. * This routine is invoked to set up the PCI device memory space for device
  7051. * with SLI-4 interface spec.
  7052. *
  7053. * Return codes
  7054. * 0 - successful
  7055. * other values - error
  7056. **/
  7057. static int
  7058. lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
  7059. {
  7060. struct pci_dev *pdev;
  7061. unsigned long bar0map_len, bar1map_len, bar2map_len;
  7062. int error = -ENODEV;
  7063. uint32_t if_type;
  7064. /* Obtain PCI device reference */
  7065. if (!phba->pcidev)
  7066. return error;
  7067. else
  7068. pdev = phba->pcidev;
  7069. /* Set the device DMA mask size */
  7070. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  7071. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  7072. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  7073. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  7074. return error;
  7075. }
  7076. }
  7077. /*
  7078. * The BARs and register set definitions and offset locations are
  7079. * dependent on the if_type.
  7080. */
  7081. if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
  7082. &phba->sli4_hba.sli_intf.word0)) {
  7083. return error;
  7084. }
  7085. /* There is no SLI3 failback for SLI4 devices. */
  7086. if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
  7087. LPFC_SLI_INTF_VALID) {
  7088. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7089. "2894 SLI_INTF reg contents invalid "
  7090. "sli_intf reg 0x%x\n",
  7091. phba->sli4_hba.sli_intf.word0);
  7092. return error;
  7093. }
  7094. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7095. /*
  7096. * Get the bus address of SLI4 device Bar regions and the
  7097. * number of bytes required by each mapping. The mapping of the
  7098. * particular PCI BARs regions is dependent on the type of
  7099. * SLI4 device.
  7100. */
  7101. if (pci_resource_start(pdev, 0)) {
  7102. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  7103. bar0map_len = pci_resource_len(pdev, 0);
  7104. /*
  7105. * Map SLI4 PCI Config Space Register base to a kernel virtual
  7106. * addr
  7107. */
  7108. phba->sli4_hba.conf_regs_memmap_p =
  7109. ioremap(phba->pci_bar0_map, bar0map_len);
  7110. if (!phba->sli4_hba.conf_regs_memmap_p) {
  7111. dev_printk(KERN_ERR, &pdev->dev,
  7112. "ioremap failed for SLI4 PCI config "
  7113. "registers.\n");
  7114. goto out;
  7115. }
  7116. /* Set up BAR0 PCI config space register memory map */
  7117. lpfc_sli4_bar0_register_memmap(phba, if_type);
  7118. } else {
  7119. phba->pci_bar0_map = pci_resource_start(pdev, 1);
  7120. bar0map_len = pci_resource_len(pdev, 1);
  7121. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7122. dev_printk(KERN_ERR, &pdev->dev,
  7123. "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
  7124. goto out;
  7125. }
  7126. phba->sli4_hba.conf_regs_memmap_p =
  7127. ioremap(phba->pci_bar0_map, bar0map_len);
  7128. if (!phba->sli4_hba.conf_regs_memmap_p) {
  7129. dev_printk(KERN_ERR, &pdev->dev,
  7130. "ioremap failed for SLI4 PCI config "
  7131. "registers.\n");
  7132. goto out;
  7133. }
  7134. lpfc_sli4_bar0_register_memmap(phba, if_type);
  7135. }
  7136. if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
  7137. (pci_resource_start(pdev, 2))) {
  7138. /*
  7139. * Map SLI4 if type 0 HBA Control Register base to a kernel
  7140. * virtual address and setup the registers.
  7141. */
  7142. phba->pci_bar1_map = pci_resource_start(pdev, 2);
  7143. bar1map_len = pci_resource_len(pdev, 2);
  7144. phba->sli4_hba.ctrl_regs_memmap_p =
  7145. ioremap(phba->pci_bar1_map, bar1map_len);
  7146. if (!phba->sli4_hba.ctrl_regs_memmap_p) {
  7147. dev_printk(KERN_ERR, &pdev->dev,
  7148. "ioremap failed for SLI4 HBA control registers.\n");
  7149. goto out_iounmap_conf;
  7150. }
  7151. lpfc_sli4_bar1_register_memmap(phba);
  7152. }
  7153. if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
  7154. (pci_resource_start(pdev, 4))) {
  7155. /*
  7156. * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
  7157. * virtual address and setup the registers.
  7158. */
  7159. phba->pci_bar2_map = pci_resource_start(pdev, 4);
  7160. bar2map_len = pci_resource_len(pdev, 4);
  7161. phba->sli4_hba.drbl_regs_memmap_p =
  7162. ioremap(phba->pci_bar2_map, bar2map_len);
  7163. if (!phba->sli4_hba.drbl_regs_memmap_p) {
  7164. dev_printk(KERN_ERR, &pdev->dev,
  7165. "ioremap failed for SLI4 HBA doorbell registers.\n");
  7166. goto out_iounmap_ctrl;
  7167. }
  7168. error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
  7169. if (error)
  7170. goto out_iounmap_all;
  7171. }
  7172. return 0;
  7173. out_iounmap_all:
  7174. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  7175. out_iounmap_ctrl:
  7176. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  7177. out_iounmap_conf:
  7178. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  7179. out:
  7180. return error;
  7181. }
  7182. /**
  7183. * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
  7184. * @phba: pointer to lpfc hba data structure.
  7185. *
  7186. * This routine is invoked to unset the PCI device memory space for device
  7187. * with SLI-4 interface spec.
  7188. **/
  7189. static void
  7190. lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
  7191. {
  7192. uint32_t if_type;
  7193. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7194. switch (if_type) {
  7195. case LPFC_SLI_INTF_IF_TYPE_0:
  7196. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  7197. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  7198. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  7199. break;
  7200. case LPFC_SLI_INTF_IF_TYPE_2:
  7201. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  7202. break;
  7203. case LPFC_SLI_INTF_IF_TYPE_1:
  7204. default:
  7205. dev_printk(KERN_ERR, &phba->pcidev->dev,
  7206. "FATAL - unsupported SLI4 interface type - %d\n",
  7207. if_type);
  7208. break;
  7209. }
  7210. }
  7211. /**
  7212. * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
  7213. * @phba: pointer to lpfc hba data structure.
  7214. *
  7215. * This routine is invoked to enable the MSI-X interrupt vectors to device
  7216. * with SLI-3 interface specs. The kernel function pci_enable_msix() is
  7217. * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
  7218. * invoked, enables either all or nothing, depending on the current
  7219. * availability of PCI vector resources. The device driver is responsible
  7220. * for calling the individual request_irq() to register each MSI-X vector
  7221. * with a interrupt handler, which is done in this function. Note that
  7222. * later when device is unloading, the driver should always call free_irq()
  7223. * on all MSI-X vectors it has done request_irq() on before calling
  7224. * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
  7225. * will be left with MSI-X enabled and leaks its vectors.
  7226. *
  7227. * Return codes
  7228. * 0 - successful
  7229. * other values - error
  7230. **/
  7231. static int
  7232. lpfc_sli_enable_msix(struct lpfc_hba *phba)
  7233. {
  7234. int rc, i;
  7235. LPFC_MBOXQ_t *pmb;
  7236. /* Set up MSI-X multi-message vectors */
  7237. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  7238. phba->msix_entries[i].entry = i;
  7239. /* Configure MSI-X capability structure */
  7240. rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
  7241. ARRAY_SIZE(phba->msix_entries));
  7242. if (rc) {
  7243. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7244. "0420 PCI enable MSI-X failed (%d)\n", rc);
  7245. goto msi_fail_out;
  7246. }
  7247. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  7248. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7249. "0477 MSI-X entry[%d]: vector=x%x "
  7250. "message=%d\n", i,
  7251. phba->msix_entries[i].vector,
  7252. phba->msix_entries[i].entry);
  7253. /*
  7254. * Assign MSI-X vectors to interrupt handlers
  7255. */
  7256. /* vector-0 is associated to slow-path handler */
  7257. rc = request_irq(phba->msix_entries[0].vector,
  7258. &lpfc_sli_sp_intr_handler, IRQF_SHARED,
  7259. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  7260. if (rc) {
  7261. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7262. "0421 MSI-X slow-path request_irq failed "
  7263. "(%d)\n", rc);
  7264. goto msi_fail_out;
  7265. }
  7266. /* vector-1 is associated to fast-path handler */
  7267. rc = request_irq(phba->msix_entries[1].vector,
  7268. &lpfc_sli_fp_intr_handler, IRQF_SHARED,
  7269. LPFC_FP_DRIVER_HANDLER_NAME, phba);
  7270. if (rc) {
  7271. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7272. "0429 MSI-X fast-path request_irq failed "
  7273. "(%d)\n", rc);
  7274. goto irq_fail_out;
  7275. }
  7276. /*
  7277. * Configure HBA MSI-X attention conditions to messages
  7278. */
  7279. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  7280. if (!pmb) {
  7281. rc = -ENOMEM;
  7282. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7283. "0474 Unable to allocate memory for issuing "
  7284. "MBOX_CONFIG_MSI command\n");
  7285. goto mem_fail_out;
  7286. }
  7287. rc = lpfc_config_msi(phba, pmb);
  7288. if (rc)
  7289. goto mbx_fail_out;
  7290. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  7291. if (rc != MBX_SUCCESS) {
  7292. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  7293. "0351 Config MSI mailbox command failed, "
  7294. "mbxCmd x%x, mbxStatus x%x\n",
  7295. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
  7296. goto mbx_fail_out;
  7297. }
  7298. /* Free memory allocated for mailbox command */
  7299. mempool_free(pmb, phba->mbox_mem_pool);
  7300. return rc;
  7301. mbx_fail_out:
  7302. /* Free memory allocated for mailbox command */
  7303. mempool_free(pmb, phba->mbox_mem_pool);
  7304. mem_fail_out:
  7305. /* free the irq already requested */
  7306. free_irq(phba->msix_entries[1].vector, phba);
  7307. irq_fail_out:
  7308. /* free the irq already requested */
  7309. free_irq(phba->msix_entries[0].vector, phba);
  7310. msi_fail_out:
  7311. /* Unconfigure MSI-X capability structure */
  7312. pci_disable_msix(phba->pcidev);
  7313. return rc;
  7314. }
  7315. /**
  7316. * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
  7317. * @phba: pointer to lpfc hba data structure.
  7318. *
  7319. * This routine is invoked to release the MSI-X vectors and then disable the
  7320. * MSI-X interrupt mode to device with SLI-3 interface spec.
  7321. **/
  7322. static void
  7323. lpfc_sli_disable_msix(struct lpfc_hba *phba)
  7324. {
  7325. int i;
  7326. /* Free up MSI-X multi-message vectors */
  7327. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  7328. free_irq(phba->msix_entries[i].vector, phba);
  7329. /* Disable MSI-X */
  7330. pci_disable_msix(phba->pcidev);
  7331. return;
  7332. }
  7333. /**
  7334. * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
  7335. * @phba: pointer to lpfc hba data structure.
  7336. *
  7337. * This routine is invoked to enable the MSI interrupt mode to device with
  7338. * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
  7339. * enable the MSI vector. The device driver is responsible for calling the
  7340. * request_irq() to register MSI vector with a interrupt the handler, which
  7341. * is done in this function.
  7342. *
  7343. * Return codes
  7344. * 0 - successful
  7345. * other values - error
  7346. */
  7347. static int
  7348. lpfc_sli_enable_msi(struct lpfc_hba *phba)
  7349. {
  7350. int rc;
  7351. rc = pci_enable_msi(phba->pcidev);
  7352. if (!rc)
  7353. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7354. "0462 PCI enable MSI mode success.\n");
  7355. else {
  7356. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7357. "0471 PCI enable MSI mode failed (%d)\n", rc);
  7358. return rc;
  7359. }
  7360. rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  7361. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7362. if (rc) {
  7363. pci_disable_msi(phba->pcidev);
  7364. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7365. "0478 MSI request_irq failed (%d)\n", rc);
  7366. }
  7367. return rc;
  7368. }
  7369. /**
  7370. * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
  7371. * @phba: pointer to lpfc hba data structure.
  7372. *
  7373. * This routine is invoked to disable the MSI interrupt mode to device with
  7374. * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
  7375. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  7376. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  7377. * its vector.
  7378. */
  7379. static void
  7380. lpfc_sli_disable_msi(struct lpfc_hba *phba)
  7381. {
  7382. free_irq(phba->pcidev->irq, phba);
  7383. pci_disable_msi(phba->pcidev);
  7384. return;
  7385. }
  7386. /**
  7387. * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
  7388. * @phba: pointer to lpfc hba data structure.
  7389. *
  7390. * This routine is invoked to enable device interrupt and associate driver's
  7391. * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
  7392. * spec. Depends on the interrupt mode configured to the driver, the driver
  7393. * will try to fallback from the configured interrupt mode to an interrupt
  7394. * mode which is supported by the platform, kernel, and device in the order
  7395. * of:
  7396. * MSI-X -> MSI -> IRQ.
  7397. *
  7398. * Return codes
  7399. * 0 - successful
  7400. * other values - error
  7401. **/
  7402. static uint32_t
  7403. lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  7404. {
  7405. uint32_t intr_mode = LPFC_INTR_ERROR;
  7406. int retval;
  7407. if (cfg_mode == 2) {
  7408. /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
  7409. retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
  7410. if (!retval) {
  7411. /* Now, try to enable MSI-X interrupt mode */
  7412. retval = lpfc_sli_enable_msix(phba);
  7413. if (!retval) {
  7414. /* Indicate initialization to MSI-X mode */
  7415. phba->intr_type = MSIX;
  7416. intr_mode = 2;
  7417. }
  7418. }
  7419. }
  7420. /* Fallback to MSI if MSI-X initialization failed */
  7421. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  7422. retval = lpfc_sli_enable_msi(phba);
  7423. if (!retval) {
  7424. /* Indicate initialization to MSI mode */
  7425. phba->intr_type = MSI;
  7426. intr_mode = 1;
  7427. }
  7428. }
  7429. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  7430. if (phba->intr_type == NONE) {
  7431. retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  7432. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7433. if (!retval) {
  7434. /* Indicate initialization to INTx mode */
  7435. phba->intr_type = INTx;
  7436. intr_mode = 0;
  7437. }
  7438. }
  7439. return intr_mode;
  7440. }
  7441. /**
  7442. * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
  7443. * @phba: pointer to lpfc hba data structure.
  7444. *
  7445. * This routine is invoked to disable device interrupt and disassociate the
  7446. * driver's interrupt handler(s) from interrupt vector(s) to device with
  7447. * SLI-3 interface spec. Depending on the interrupt mode, the driver will
  7448. * release the interrupt vector(s) for the message signaled interrupt.
  7449. **/
  7450. static void
  7451. lpfc_sli_disable_intr(struct lpfc_hba *phba)
  7452. {
  7453. /* Disable the currently initialized interrupt mode */
  7454. if (phba->intr_type == MSIX)
  7455. lpfc_sli_disable_msix(phba);
  7456. else if (phba->intr_type == MSI)
  7457. lpfc_sli_disable_msi(phba);
  7458. else if (phba->intr_type == INTx)
  7459. free_irq(phba->pcidev->irq, phba);
  7460. /* Reset interrupt management states */
  7461. phba->intr_type = NONE;
  7462. phba->sli.slistat.sli_intr = 0;
  7463. return;
  7464. }
  7465. /**
  7466. * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
  7467. * @phba: pointer to lpfc hba data structure.
  7468. *
  7469. * This routine is invoked to enable the MSI-X interrupt vectors to device
  7470. * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
  7471. * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
  7472. * enables either all or nothing, depending on the current availability of
  7473. * PCI vector resources. The device driver is responsible for calling the
  7474. * individual request_irq() to register each MSI-X vector with a interrupt
  7475. * handler, which is done in this function. Note that later when device is
  7476. * unloading, the driver should always call free_irq() on all MSI-X vectors
  7477. * it has done request_irq() on before calling pci_disable_msix(). Failure
  7478. * to do so results in a BUG_ON() and a device will be left with MSI-X
  7479. * enabled and leaks its vectors.
  7480. *
  7481. * Return codes
  7482. * 0 - successful
  7483. * other values - error
  7484. **/
  7485. static int
  7486. lpfc_sli4_enable_msix(struct lpfc_hba *phba)
  7487. {
  7488. int vectors, rc, index;
  7489. /* Set up MSI-X multi-message vectors */
  7490. for (index = 0; index < phba->cfg_fcp_io_channel; index++)
  7491. phba->sli4_hba.msix_entries[index].entry = index;
  7492. /* Configure MSI-X capability structure */
  7493. vectors = phba->cfg_fcp_io_channel;
  7494. enable_msix_vectors:
  7495. rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
  7496. vectors);
  7497. if (rc > 1) {
  7498. vectors = rc;
  7499. goto enable_msix_vectors;
  7500. } else if (rc) {
  7501. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7502. "0484 PCI enable MSI-X failed (%d)\n", rc);
  7503. goto msi_fail_out;
  7504. }
  7505. /* Log MSI-X vector assignment */
  7506. for (index = 0; index < vectors; index++)
  7507. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7508. "0489 MSI-X entry[%d]: vector=x%x "
  7509. "message=%d\n", index,
  7510. phba->sli4_hba.msix_entries[index].vector,
  7511. phba->sli4_hba.msix_entries[index].entry);
  7512. /*
  7513. * Assign MSI-X vectors to interrupt handlers
  7514. */
  7515. for (index = 0; index < vectors; index++) {
  7516. memset(&phba->sli4_hba.handler_name[index], 0, 16);
  7517. sprintf((char *)&phba->sli4_hba.handler_name[index],
  7518. LPFC_DRIVER_HANDLER_NAME"%d", index);
  7519. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  7520. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  7521. atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
  7522. rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
  7523. &lpfc_sli4_hba_intr_handler, IRQF_SHARED,
  7524. (char *)&phba->sli4_hba.handler_name[index],
  7525. &phba->sli4_hba.fcp_eq_hdl[index]);
  7526. if (rc) {
  7527. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7528. "0486 MSI-X fast-path (%d) "
  7529. "request_irq failed (%d)\n", index, rc);
  7530. goto cfg_fail_out;
  7531. }
  7532. }
  7533. if (vectors != phba->cfg_fcp_io_channel) {
  7534. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7535. "3238 Reducing IO channels to match number of "
  7536. "MSI-X vectors, requested %d got %d\n",
  7537. phba->cfg_fcp_io_channel, vectors);
  7538. phba->cfg_fcp_io_channel = vectors;
  7539. }
  7540. return rc;
  7541. cfg_fail_out:
  7542. /* free the irq already requested */
  7543. for (--index; index >= 0; index--)
  7544. free_irq(phba->sli4_hba.msix_entries[index].vector,
  7545. &phba->sli4_hba.fcp_eq_hdl[index]);
  7546. msi_fail_out:
  7547. /* Unconfigure MSI-X capability structure */
  7548. pci_disable_msix(phba->pcidev);
  7549. return rc;
  7550. }
  7551. /**
  7552. * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
  7553. * @phba: pointer to lpfc hba data structure.
  7554. *
  7555. * This routine is invoked to release the MSI-X vectors and then disable the
  7556. * MSI-X interrupt mode to device with SLI-4 interface spec.
  7557. **/
  7558. static void
  7559. lpfc_sli4_disable_msix(struct lpfc_hba *phba)
  7560. {
  7561. int index;
  7562. /* Free up MSI-X multi-message vectors */
  7563. for (index = 0; index < phba->cfg_fcp_io_channel; index++)
  7564. free_irq(phba->sli4_hba.msix_entries[index].vector,
  7565. &phba->sli4_hba.fcp_eq_hdl[index]);
  7566. /* Disable MSI-X */
  7567. pci_disable_msix(phba->pcidev);
  7568. return;
  7569. }
  7570. /**
  7571. * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
  7572. * @phba: pointer to lpfc hba data structure.
  7573. *
  7574. * This routine is invoked to enable the MSI interrupt mode to device with
  7575. * SLI-4 interface spec. The kernel function pci_enable_msi() is called
  7576. * to enable the MSI vector. The device driver is responsible for calling
  7577. * the request_irq() to register MSI vector with a interrupt the handler,
  7578. * which is done in this function.
  7579. *
  7580. * Return codes
  7581. * 0 - successful
  7582. * other values - error
  7583. **/
  7584. static int
  7585. lpfc_sli4_enable_msi(struct lpfc_hba *phba)
  7586. {
  7587. int rc, index;
  7588. rc = pci_enable_msi(phba->pcidev);
  7589. if (!rc)
  7590. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7591. "0487 PCI enable MSI mode success.\n");
  7592. else {
  7593. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7594. "0488 PCI enable MSI mode failed (%d)\n", rc);
  7595. return rc;
  7596. }
  7597. rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  7598. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7599. if (rc) {
  7600. pci_disable_msi(phba->pcidev);
  7601. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  7602. "0490 MSI request_irq failed (%d)\n", rc);
  7603. return rc;
  7604. }
  7605. for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
  7606. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  7607. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  7608. }
  7609. return 0;
  7610. }
  7611. /**
  7612. * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
  7613. * @phba: pointer to lpfc hba data structure.
  7614. *
  7615. * This routine is invoked to disable the MSI interrupt mode to device with
  7616. * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
  7617. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  7618. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  7619. * its vector.
  7620. **/
  7621. static void
  7622. lpfc_sli4_disable_msi(struct lpfc_hba *phba)
  7623. {
  7624. free_irq(phba->pcidev->irq, phba);
  7625. pci_disable_msi(phba->pcidev);
  7626. return;
  7627. }
  7628. /**
  7629. * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
  7630. * @phba: pointer to lpfc hba data structure.
  7631. *
  7632. * This routine is invoked to enable device interrupt and associate driver's
  7633. * interrupt handler(s) to interrupt vector(s) to device with SLI-4
  7634. * interface spec. Depends on the interrupt mode configured to the driver,
  7635. * the driver will try to fallback from the configured interrupt mode to an
  7636. * interrupt mode which is supported by the platform, kernel, and device in
  7637. * the order of:
  7638. * MSI-X -> MSI -> IRQ.
  7639. *
  7640. * Return codes
  7641. * 0 - successful
  7642. * other values - error
  7643. **/
  7644. static uint32_t
  7645. lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  7646. {
  7647. uint32_t intr_mode = LPFC_INTR_ERROR;
  7648. int retval, index;
  7649. if (cfg_mode == 2) {
  7650. /* Preparation before conf_msi mbox cmd */
  7651. retval = 0;
  7652. if (!retval) {
  7653. /* Now, try to enable MSI-X interrupt mode */
  7654. retval = lpfc_sli4_enable_msix(phba);
  7655. if (!retval) {
  7656. /* Indicate initialization to MSI-X mode */
  7657. phba->intr_type = MSIX;
  7658. intr_mode = 2;
  7659. }
  7660. }
  7661. }
  7662. /* Fallback to MSI if MSI-X initialization failed */
  7663. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  7664. retval = lpfc_sli4_enable_msi(phba);
  7665. if (!retval) {
  7666. /* Indicate initialization to MSI mode */
  7667. phba->intr_type = MSI;
  7668. intr_mode = 1;
  7669. }
  7670. }
  7671. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  7672. if (phba->intr_type == NONE) {
  7673. retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  7674. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  7675. if (!retval) {
  7676. /* Indicate initialization to INTx mode */
  7677. phba->intr_type = INTx;
  7678. intr_mode = 0;
  7679. for (index = 0; index < phba->cfg_fcp_io_channel;
  7680. index++) {
  7681. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  7682. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  7683. atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
  7684. fcp_eq_in_use, 1);
  7685. }
  7686. }
  7687. }
  7688. return intr_mode;
  7689. }
  7690. /**
  7691. * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
  7692. * @phba: pointer to lpfc hba data structure.
  7693. *
  7694. * This routine is invoked to disable device interrupt and disassociate
  7695. * the driver's interrupt handler(s) from interrupt vector(s) to device
  7696. * with SLI-4 interface spec. Depending on the interrupt mode, the driver
  7697. * will release the interrupt vector(s) for the message signaled interrupt.
  7698. **/
  7699. static void
  7700. lpfc_sli4_disable_intr(struct lpfc_hba *phba)
  7701. {
  7702. /* Disable the currently initialized interrupt mode */
  7703. if (phba->intr_type == MSIX)
  7704. lpfc_sli4_disable_msix(phba);
  7705. else if (phba->intr_type == MSI)
  7706. lpfc_sli4_disable_msi(phba);
  7707. else if (phba->intr_type == INTx)
  7708. free_irq(phba->pcidev->irq, phba);
  7709. /* Reset interrupt management states */
  7710. phba->intr_type = NONE;
  7711. phba->sli.slistat.sli_intr = 0;
  7712. return;
  7713. }
  7714. /**
  7715. * lpfc_unset_hba - Unset SLI3 hba device initialization
  7716. * @phba: pointer to lpfc hba data structure.
  7717. *
  7718. * This routine is invoked to unset the HBA device initialization steps to
  7719. * a device with SLI-3 interface spec.
  7720. **/
  7721. static void
  7722. lpfc_unset_hba(struct lpfc_hba *phba)
  7723. {
  7724. struct lpfc_vport *vport = phba->pport;
  7725. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  7726. spin_lock_irq(shost->host_lock);
  7727. vport->load_flag |= FC_UNLOADING;
  7728. spin_unlock_irq(shost->host_lock);
  7729. kfree(phba->vpi_bmask);
  7730. kfree(phba->vpi_ids);
  7731. lpfc_stop_hba_timers(phba);
  7732. phba->pport->work_port_events = 0;
  7733. lpfc_sli_hba_down(phba);
  7734. lpfc_sli_brdrestart(phba);
  7735. lpfc_sli_disable_intr(phba);
  7736. return;
  7737. }
  7738. /**
  7739. * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
  7740. * @phba: pointer to lpfc hba data structure.
  7741. *
  7742. * This routine is invoked to unset the HBA device initialization steps to
  7743. * a device with SLI-4 interface spec.
  7744. **/
  7745. static void
  7746. lpfc_sli4_unset_hba(struct lpfc_hba *phba)
  7747. {
  7748. struct lpfc_vport *vport = phba->pport;
  7749. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  7750. spin_lock_irq(shost->host_lock);
  7751. vport->load_flag |= FC_UNLOADING;
  7752. spin_unlock_irq(shost->host_lock);
  7753. phba->pport->work_port_events = 0;
  7754. /* Stop the SLI4 device port */
  7755. lpfc_stop_port(phba);
  7756. lpfc_sli4_disable_intr(phba);
  7757. /* Reset SLI4 HBA FCoE function */
  7758. lpfc_pci_function_reset(phba);
  7759. lpfc_sli4_queue_destroy(phba);
  7760. return;
  7761. }
  7762. /**
  7763. * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
  7764. * @phba: Pointer to HBA context object.
  7765. *
  7766. * This function is called in the SLI4 code path to wait for completion
  7767. * of device's XRIs exchange busy. It will check the XRI exchange busy
  7768. * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
  7769. * that, it will check the XRI exchange busy on outstanding FCP and ELS
  7770. * I/Os every 30 seconds, log error message, and wait forever. Only when
  7771. * all XRI exchange busy complete, the driver unload shall proceed with
  7772. * invoking the function reset ioctl mailbox command to the CNA and the
  7773. * the rest of the driver unload resource release.
  7774. **/
  7775. static void
  7776. lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
  7777. {
  7778. int wait_time = 0;
  7779. int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  7780. int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  7781. while (!fcp_xri_cmpl || !els_xri_cmpl) {
  7782. if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
  7783. if (!fcp_xri_cmpl)
  7784. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7785. "2877 FCP XRI exchange busy "
  7786. "wait time: %d seconds.\n",
  7787. wait_time/1000);
  7788. if (!els_xri_cmpl)
  7789. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7790. "2878 ELS XRI exchange busy "
  7791. "wait time: %d seconds.\n",
  7792. wait_time/1000);
  7793. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
  7794. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
  7795. } else {
  7796. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
  7797. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
  7798. }
  7799. fcp_xri_cmpl =
  7800. list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  7801. els_xri_cmpl =
  7802. list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  7803. }
  7804. }
  7805. /**
  7806. * lpfc_sli4_hba_unset - Unset the fcoe hba
  7807. * @phba: Pointer to HBA context object.
  7808. *
  7809. * This function is called in the SLI4 code path to reset the HBA's FCoE
  7810. * function. The caller is not required to hold any lock. This routine
  7811. * issues PCI function reset mailbox command to reset the FCoE function.
  7812. * At the end of the function, it calls lpfc_hba_down_post function to
  7813. * free any pending commands.
  7814. **/
  7815. static void
  7816. lpfc_sli4_hba_unset(struct lpfc_hba *phba)
  7817. {
  7818. int wait_cnt = 0;
  7819. LPFC_MBOXQ_t *mboxq;
  7820. struct pci_dev *pdev = phba->pcidev;
  7821. lpfc_stop_hba_timers(phba);
  7822. phba->sli4_hba.intr_enable = 0;
  7823. /*
  7824. * Gracefully wait out the potential current outstanding asynchronous
  7825. * mailbox command.
  7826. */
  7827. /* First, block any pending async mailbox command from posted */
  7828. spin_lock_irq(&phba->hbalock);
  7829. phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7830. spin_unlock_irq(&phba->hbalock);
  7831. /* Now, trying to wait it out if we can */
  7832. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  7833. msleep(10);
  7834. if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
  7835. break;
  7836. }
  7837. /* Forcefully release the outstanding mailbox command if timed out */
  7838. if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  7839. spin_lock_irq(&phba->hbalock);
  7840. mboxq = phba->sli.mbox_active;
  7841. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  7842. __lpfc_mbox_cmpl_put(phba, mboxq);
  7843. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7844. phba->sli.mbox_active = NULL;
  7845. spin_unlock_irq(&phba->hbalock);
  7846. }
  7847. /* Abort all iocbs associated with the hba */
  7848. lpfc_sli_hba_iocb_abort(phba);
  7849. /* Wait for completion of device XRI exchange busy */
  7850. lpfc_sli4_xri_exchange_busy_wait(phba);
  7851. /* Disable PCI subsystem interrupt */
  7852. lpfc_sli4_disable_intr(phba);
  7853. /* Disable SR-IOV if enabled */
  7854. if (phba->cfg_sriov_nr_virtfn)
  7855. pci_disable_sriov(pdev);
  7856. /* Stop kthread signal shall trigger work_done one more time */
  7857. kthread_stop(phba->worker_thread);
  7858. /* Reset SLI4 HBA FCoE function */
  7859. lpfc_pci_function_reset(phba);
  7860. lpfc_sli4_queue_destroy(phba);
  7861. /* Stop the SLI4 device port */
  7862. phba->pport->work_port_events = 0;
  7863. }
  7864. /**
  7865. * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
  7866. * @phba: Pointer to HBA context object.
  7867. * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
  7868. *
  7869. * This function is called in the SLI4 code path to read the port's
  7870. * sli4 capabilities.
  7871. *
  7872. * This function may be be called from any context that can block-wait
  7873. * for the completion. The expectation is that this routine is called
  7874. * typically from probe_one or from the online routine.
  7875. **/
  7876. int
  7877. lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  7878. {
  7879. int rc;
  7880. struct lpfc_mqe *mqe;
  7881. struct lpfc_pc_sli4_params *sli4_params;
  7882. uint32_t mbox_tmo;
  7883. rc = 0;
  7884. mqe = &mboxq->u.mqe;
  7885. /* Read the port's SLI4 Parameters port capabilities */
  7886. lpfc_pc_sli4_params(mboxq);
  7887. if (!phba->sli4_hba.intr_enable)
  7888. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7889. else {
  7890. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  7891. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  7892. }
  7893. if (unlikely(rc))
  7894. return 1;
  7895. sli4_params = &phba->sli4_hba.pc_sli4_params;
  7896. sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
  7897. sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
  7898. sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
  7899. sli4_params->featurelevel_1 = bf_get(featurelevel_1,
  7900. &mqe->un.sli4_params);
  7901. sli4_params->featurelevel_2 = bf_get(featurelevel_2,
  7902. &mqe->un.sli4_params);
  7903. sli4_params->proto_types = mqe->un.sli4_params.word3;
  7904. sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
  7905. sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
  7906. sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
  7907. sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
  7908. sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
  7909. sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
  7910. sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
  7911. sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
  7912. sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
  7913. sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
  7914. sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
  7915. sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
  7916. sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
  7917. sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
  7918. sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
  7919. sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
  7920. sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
  7921. sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
  7922. sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
  7923. sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
  7924. /* Make sure that sge_supp_len can be handled by the driver */
  7925. if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
  7926. sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
  7927. return rc;
  7928. }
  7929. /**
  7930. * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
  7931. * @phba: Pointer to HBA context object.
  7932. * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
  7933. *
  7934. * This function is called in the SLI4 code path to read the port's
  7935. * sli4 capabilities.
  7936. *
  7937. * This function may be be called from any context that can block-wait
  7938. * for the completion. The expectation is that this routine is called
  7939. * typically from probe_one or from the online routine.
  7940. **/
  7941. int
  7942. lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  7943. {
  7944. int rc;
  7945. struct lpfc_mqe *mqe = &mboxq->u.mqe;
  7946. struct lpfc_pc_sli4_params *sli4_params;
  7947. uint32_t mbox_tmo;
  7948. int length;
  7949. struct lpfc_sli4_parameters *mbx_sli4_parameters;
  7950. /*
  7951. * By default, the driver assumes the SLI4 port requires RPI
  7952. * header postings. The SLI4_PARAM response will correct this
  7953. * assumption.
  7954. */
  7955. phba->sli4_hba.rpi_hdrs_in_use = 1;
  7956. /* Read the port's SLI4 Config Parameters */
  7957. length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
  7958. sizeof(struct lpfc_sli4_cfg_mhdr));
  7959. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  7960. LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
  7961. length, LPFC_SLI4_MBX_EMBED);
  7962. if (!phba->sli4_hba.intr_enable)
  7963. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7964. else {
  7965. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  7966. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  7967. }
  7968. if (unlikely(rc))
  7969. return rc;
  7970. sli4_params = &phba->sli4_hba.pc_sli4_params;
  7971. mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
  7972. sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
  7973. sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
  7974. sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
  7975. sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
  7976. mbx_sli4_parameters);
  7977. sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
  7978. mbx_sli4_parameters);
  7979. if (bf_get(cfg_phwq, mbx_sli4_parameters))
  7980. phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
  7981. else
  7982. phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
  7983. sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
  7984. sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
  7985. sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
  7986. sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
  7987. sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
  7988. sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
  7989. sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
  7990. mbx_sli4_parameters);
  7991. sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
  7992. mbx_sli4_parameters);
  7993. phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
  7994. phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
  7995. /* Make sure that sge_supp_len can be handled by the driver */
  7996. if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
  7997. sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
  7998. return 0;
  7999. }
  8000. /**
  8001. * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
  8002. * @pdev: pointer to PCI device
  8003. * @pid: pointer to PCI device identifier
  8004. *
  8005. * This routine is to be called to attach a device with SLI-3 interface spec
  8006. * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  8007. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  8008. * information of the device and driver to see if the driver state that it can
  8009. * support this kind of device. If the match is successful, the driver core
  8010. * invokes this routine. If this routine determines it can claim the HBA, it
  8011. * does all the initialization that it needs to do to handle the HBA properly.
  8012. *
  8013. * Return code
  8014. * 0 - driver can claim the device
  8015. * negative value - driver can not claim the device
  8016. **/
  8017. static int
  8018. lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
  8019. {
  8020. struct lpfc_hba *phba;
  8021. struct lpfc_vport *vport = NULL;
  8022. struct Scsi_Host *shost = NULL;
  8023. int error;
  8024. uint32_t cfg_mode, intr_mode;
  8025. /* Allocate memory for HBA structure */
  8026. phba = lpfc_hba_alloc(pdev);
  8027. if (!phba)
  8028. return -ENOMEM;
  8029. /* Perform generic PCI device enabling operation */
  8030. error = lpfc_enable_pci_dev(phba);
  8031. if (error)
  8032. goto out_free_phba;
  8033. /* Set up SLI API function jump table for PCI-device group-0 HBAs */
  8034. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
  8035. if (error)
  8036. goto out_disable_pci_dev;
  8037. /* Set up SLI-3 specific device PCI memory space */
  8038. error = lpfc_sli_pci_mem_setup(phba);
  8039. if (error) {
  8040. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8041. "1402 Failed to set up pci memory space.\n");
  8042. goto out_disable_pci_dev;
  8043. }
  8044. /* Set up phase-1 common device driver resources */
  8045. error = lpfc_setup_driver_resource_phase1(phba);
  8046. if (error) {
  8047. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8048. "1403 Failed to set up driver resource.\n");
  8049. goto out_unset_pci_mem_s3;
  8050. }
  8051. /* Set up SLI-3 specific device driver resources */
  8052. error = lpfc_sli_driver_resource_setup(phba);
  8053. if (error) {
  8054. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8055. "1404 Failed to set up driver resource.\n");
  8056. goto out_unset_pci_mem_s3;
  8057. }
  8058. /* Initialize and populate the iocb list per host */
  8059. error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
  8060. if (error) {
  8061. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8062. "1405 Failed to initialize iocb list.\n");
  8063. goto out_unset_driver_resource_s3;
  8064. }
  8065. /* Set up common device driver resources */
  8066. error = lpfc_setup_driver_resource_phase2(phba);
  8067. if (error) {
  8068. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8069. "1406 Failed to set up driver resource.\n");
  8070. goto out_free_iocb_list;
  8071. }
  8072. /* Get the default values for Model Name and Description */
  8073. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  8074. /* Create SCSI host to the physical port */
  8075. error = lpfc_create_shost(phba);
  8076. if (error) {
  8077. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8078. "1407 Failed to create scsi host.\n");
  8079. goto out_unset_driver_resource;
  8080. }
  8081. /* Configure sysfs attributes */
  8082. vport = phba->pport;
  8083. error = lpfc_alloc_sysfs_attr(vport);
  8084. if (error) {
  8085. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8086. "1476 Failed to allocate sysfs attr\n");
  8087. goto out_destroy_shost;
  8088. }
  8089. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  8090. /* Now, trying to enable interrupt and bring up the device */
  8091. cfg_mode = phba->cfg_use_msi;
  8092. while (true) {
  8093. /* Put device to a known state before enabling interrupt */
  8094. lpfc_stop_port(phba);
  8095. /* Configure and enable interrupt */
  8096. intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
  8097. if (intr_mode == LPFC_INTR_ERROR) {
  8098. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8099. "0431 Failed to enable interrupt.\n");
  8100. error = -ENODEV;
  8101. goto out_free_sysfs_attr;
  8102. }
  8103. /* SLI-3 HBA setup */
  8104. if (lpfc_sli_hba_setup(phba)) {
  8105. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8106. "1477 Failed to set up hba\n");
  8107. error = -ENODEV;
  8108. goto out_remove_device;
  8109. }
  8110. /* Wait 50ms for the interrupts of previous mailbox commands */
  8111. msleep(50);
  8112. /* Check active interrupts on message signaled interrupts */
  8113. if (intr_mode == 0 ||
  8114. phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
  8115. /* Log the current active interrupt mode */
  8116. phba->intr_mode = intr_mode;
  8117. lpfc_log_intr_mode(phba, intr_mode);
  8118. break;
  8119. } else {
  8120. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8121. "0447 Configure interrupt mode (%d) "
  8122. "failed active interrupt test.\n",
  8123. intr_mode);
  8124. /* Disable the current interrupt mode */
  8125. lpfc_sli_disable_intr(phba);
  8126. /* Try next level of interrupt mode */
  8127. cfg_mode = --intr_mode;
  8128. }
  8129. }
  8130. /* Perform post initialization setup */
  8131. lpfc_post_init_setup(phba);
  8132. /* Check if there are static vports to be created. */
  8133. lpfc_create_static_vport(phba);
  8134. return 0;
  8135. out_remove_device:
  8136. lpfc_unset_hba(phba);
  8137. out_free_sysfs_attr:
  8138. lpfc_free_sysfs_attr(vport);
  8139. out_destroy_shost:
  8140. lpfc_destroy_shost(phba);
  8141. out_unset_driver_resource:
  8142. lpfc_unset_driver_resource_phase2(phba);
  8143. out_free_iocb_list:
  8144. lpfc_free_iocb_list(phba);
  8145. out_unset_driver_resource_s3:
  8146. lpfc_sli_driver_resource_unset(phba);
  8147. out_unset_pci_mem_s3:
  8148. lpfc_sli_pci_mem_unset(phba);
  8149. out_disable_pci_dev:
  8150. lpfc_disable_pci_dev(phba);
  8151. if (shost)
  8152. scsi_host_put(shost);
  8153. out_free_phba:
  8154. lpfc_hba_free(phba);
  8155. return error;
  8156. }
  8157. /**
  8158. * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
  8159. * @pdev: pointer to PCI device
  8160. *
  8161. * This routine is to be called to disattach a device with SLI-3 interface
  8162. * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  8163. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  8164. * device to be removed from the PCI subsystem properly.
  8165. **/
  8166. static void
  8167. lpfc_pci_remove_one_s3(struct pci_dev *pdev)
  8168. {
  8169. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8170. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  8171. struct lpfc_vport **vports;
  8172. struct lpfc_hba *phba = vport->phba;
  8173. int i;
  8174. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  8175. spin_lock_irq(&phba->hbalock);
  8176. vport->load_flag |= FC_UNLOADING;
  8177. spin_unlock_irq(&phba->hbalock);
  8178. lpfc_free_sysfs_attr(vport);
  8179. /* Release all the vports against this physical port */
  8180. vports = lpfc_create_vport_work_array(phba);
  8181. if (vports != NULL)
  8182. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  8183. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  8184. continue;
  8185. fc_vport_terminate(vports[i]->fc_vport);
  8186. }
  8187. lpfc_destroy_vport_work_array(phba, vports);
  8188. /* Remove FC host and then SCSI host with the physical port */
  8189. fc_remove_host(shost);
  8190. scsi_remove_host(shost);
  8191. lpfc_cleanup(vport);
  8192. /*
  8193. * Bring down the SLI Layer. This step disable all interrupts,
  8194. * clears the rings, discards all mailbox commands, and resets
  8195. * the HBA.
  8196. */
  8197. /* HBA interrupt will be disabled after this call */
  8198. lpfc_sli_hba_down(phba);
  8199. /* Stop kthread signal shall trigger work_done one more time */
  8200. kthread_stop(phba->worker_thread);
  8201. /* Final cleanup of txcmplq and reset the HBA */
  8202. lpfc_sli_brdrestart(phba);
  8203. kfree(phba->vpi_bmask);
  8204. kfree(phba->vpi_ids);
  8205. lpfc_stop_hba_timers(phba);
  8206. spin_lock_irq(&phba->hbalock);
  8207. list_del_init(&vport->listentry);
  8208. spin_unlock_irq(&phba->hbalock);
  8209. lpfc_debugfs_terminate(vport);
  8210. /* Disable SR-IOV if enabled */
  8211. if (phba->cfg_sriov_nr_virtfn)
  8212. pci_disable_sriov(pdev);
  8213. /* Disable interrupt */
  8214. lpfc_sli_disable_intr(phba);
  8215. pci_set_drvdata(pdev, NULL);
  8216. scsi_host_put(shost);
  8217. /*
  8218. * Call scsi_free before mem_free since scsi bufs are released to their
  8219. * corresponding pools here.
  8220. */
  8221. lpfc_scsi_free(phba);
  8222. lpfc_mem_free_all(phba);
  8223. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  8224. phba->hbqslimp.virt, phba->hbqslimp.phys);
  8225. /* Free resources associated with SLI2 interface */
  8226. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  8227. phba->slim2p.virt, phba->slim2p.phys);
  8228. /* unmap adapter SLIM and Control Registers */
  8229. iounmap(phba->ctrl_regs_memmap_p);
  8230. iounmap(phba->slim_memmap_p);
  8231. lpfc_hba_free(phba);
  8232. pci_release_selected_regions(pdev, bars);
  8233. pci_disable_device(pdev);
  8234. }
  8235. /**
  8236. * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
  8237. * @pdev: pointer to PCI device
  8238. * @msg: power management message
  8239. *
  8240. * This routine is to be called from the kernel's PCI subsystem to support
  8241. * system Power Management (PM) to device with SLI-3 interface spec. When
  8242. * PM invokes this method, it quiesces the device by stopping the driver's
  8243. * worker thread for the device, turning off device's interrupt and DMA,
  8244. * and bring the device offline. Note that as the driver implements the
  8245. * minimum PM requirements to a power-aware driver's PM support for the
  8246. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  8247. * to the suspend() method call will be treated as SUSPEND and the driver will
  8248. * fully reinitialize its device during resume() method call, the driver will
  8249. * set device to PCI_D3hot state in PCI config space instead of setting it
  8250. * according to the @msg provided by the PM.
  8251. *
  8252. * Return code
  8253. * 0 - driver suspended the device
  8254. * Error otherwise
  8255. **/
  8256. static int
  8257. lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
  8258. {
  8259. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8260. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8261. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8262. "0473 PCI device Power Management suspend.\n");
  8263. /* Bring down the device */
  8264. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  8265. lpfc_offline(phba);
  8266. kthread_stop(phba->worker_thread);
  8267. /* Disable interrupt from device */
  8268. lpfc_sli_disable_intr(phba);
  8269. /* Save device state to PCI config space */
  8270. pci_save_state(pdev);
  8271. pci_set_power_state(pdev, PCI_D3hot);
  8272. return 0;
  8273. }
  8274. /**
  8275. * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
  8276. * @pdev: pointer to PCI device
  8277. *
  8278. * This routine is to be called from the kernel's PCI subsystem to support
  8279. * system Power Management (PM) to device with SLI-3 interface spec. When PM
  8280. * invokes this method, it restores the device's PCI config space state and
  8281. * fully reinitializes the device and brings it online. Note that as the
  8282. * driver implements the minimum PM requirements to a power-aware driver's
  8283. * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
  8284. * FREEZE) to the suspend() method call will be treated as SUSPEND and the
  8285. * driver will fully reinitialize its device during resume() method call,
  8286. * the device will be set to PCI_D0 directly in PCI config space before
  8287. * restoring the state.
  8288. *
  8289. * Return code
  8290. * 0 - driver suspended the device
  8291. * Error otherwise
  8292. **/
  8293. static int
  8294. lpfc_pci_resume_one_s3(struct pci_dev *pdev)
  8295. {
  8296. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8297. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8298. uint32_t intr_mode;
  8299. int error;
  8300. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8301. "0452 PCI device Power Management resume.\n");
  8302. /* Restore device state from PCI config space */
  8303. pci_set_power_state(pdev, PCI_D0);
  8304. pci_restore_state(pdev);
  8305. /*
  8306. * As the new kernel behavior of pci_restore_state() API call clears
  8307. * device saved_state flag, need to save the restored state again.
  8308. */
  8309. pci_save_state(pdev);
  8310. if (pdev->is_busmaster)
  8311. pci_set_master(pdev);
  8312. /* Startup the kernel thread for this host adapter. */
  8313. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  8314. "lpfc_worker_%d", phba->brd_no);
  8315. if (IS_ERR(phba->worker_thread)) {
  8316. error = PTR_ERR(phba->worker_thread);
  8317. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8318. "0434 PM resume failed to start worker "
  8319. "thread: error=x%x.\n", error);
  8320. return error;
  8321. }
  8322. /* Configure and enable interrupt */
  8323. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  8324. if (intr_mode == LPFC_INTR_ERROR) {
  8325. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8326. "0430 PM resume Failed to enable interrupt\n");
  8327. return -EIO;
  8328. } else
  8329. phba->intr_mode = intr_mode;
  8330. /* Restart HBA and bring it online */
  8331. lpfc_sli_brdrestart(phba);
  8332. lpfc_online(phba);
  8333. /* Log the current active interrupt mode */
  8334. lpfc_log_intr_mode(phba, phba->intr_mode);
  8335. return 0;
  8336. }
  8337. /**
  8338. * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
  8339. * @phba: pointer to lpfc hba data structure.
  8340. *
  8341. * This routine is called to prepare the SLI3 device for PCI slot recover. It
  8342. * aborts all the outstanding SCSI I/Os to the pci device.
  8343. **/
  8344. static void
  8345. lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
  8346. {
  8347. struct lpfc_sli *psli = &phba->sli;
  8348. struct lpfc_sli_ring *pring;
  8349. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8350. "2723 PCI channel I/O abort preparing for recovery\n");
  8351. /*
  8352. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  8353. * and let the SCSI mid-layer to retry them to recover.
  8354. */
  8355. pring = &psli->ring[psli->fcp_ring];
  8356. lpfc_sli_abort_iocb_ring(phba, pring);
  8357. }
  8358. /**
  8359. * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
  8360. * @phba: pointer to lpfc hba data structure.
  8361. *
  8362. * This routine is called to prepare the SLI3 device for PCI slot reset. It
  8363. * disables the device interrupt and pci device, and aborts the internal FCP
  8364. * pending I/Os.
  8365. **/
  8366. static void
  8367. lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
  8368. {
  8369. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8370. "2710 PCI channel disable preparing for reset\n");
  8371. /* Block any management I/Os to the device */
  8372. lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
  8373. /* Block all SCSI devices' I/Os on the host */
  8374. lpfc_scsi_dev_block(phba);
  8375. /* stop all timers */
  8376. lpfc_stop_hba_timers(phba);
  8377. /* Disable interrupt and pci device */
  8378. lpfc_sli_disable_intr(phba);
  8379. pci_disable_device(phba->pcidev);
  8380. /* Flush all driver's outstanding SCSI I/Os as we are to reset */
  8381. lpfc_sli_flush_fcp_rings(phba);
  8382. }
  8383. /**
  8384. * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
  8385. * @phba: pointer to lpfc hba data structure.
  8386. *
  8387. * This routine is called to prepare the SLI3 device for PCI slot permanently
  8388. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  8389. * pending I/Os.
  8390. **/
  8391. static void
  8392. lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  8393. {
  8394. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8395. "2711 PCI channel permanent disable for failure\n");
  8396. /* Block all SCSI devices' I/Os on the host */
  8397. lpfc_scsi_dev_block(phba);
  8398. /* stop all timers */
  8399. lpfc_stop_hba_timers(phba);
  8400. /* Clean up all driver's outstanding SCSI I/Os */
  8401. lpfc_sli_flush_fcp_rings(phba);
  8402. }
  8403. /**
  8404. * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
  8405. * @pdev: pointer to PCI device.
  8406. * @state: the current PCI connection state.
  8407. *
  8408. * This routine is called from the PCI subsystem for I/O error handling to
  8409. * device with SLI-3 interface spec. This function is called by the PCI
  8410. * subsystem after a PCI bus error affecting this device has been detected.
  8411. * When this function is invoked, it will need to stop all the I/Os and
  8412. * interrupt(s) to the device. Once that is done, it will return
  8413. * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
  8414. * as desired.
  8415. *
  8416. * Return codes
  8417. * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
  8418. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  8419. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8420. **/
  8421. static pci_ers_result_t
  8422. lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
  8423. {
  8424. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8425. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8426. switch (state) {
  8427. case pci_channel_io_normal:
  8428. /* Non-fatal error, prepare for recovery */
  8429. lpfc_sli_prep_dev_for_recover(phba);
  8430. return PCI_ERS_RESULT_CAN_RECOVER;
  8431. case pci_channel_io_frozen:
  8432. /* Fatal error, prepare for slot reset */
  8433. lpfc_sli_prep_dev_for_reset(phba);
  8434. return PCI_ERS_RESULT_NEED_RESET;
  8435. case pci_channel_io_perm_failure:
  8436. /* Permanent failure, prepare for device down */
  8437. lpfc_sli_prep_dev_for_perm_failure(phba);
  8438. return PCI_ERS_RESULT_DISCONNECT;
  8439. default:
  8440. /* Unknown state, prepare and request slot reset */
  8441. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8442. "0472 Unknown PCI error state: x%x\n", state);
  8443. lpfc_sli_prep_dev_for_reset(phba);
  8444. return PCI_ERS_RESULT_NEED_RESET;
  8445. }
  8446. }
  8447. /**
  8448. * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
  8449. * @pdev: pointer to PCI device.
  8450. *
  8451. * This routine is called from the PCI subsystem for error handling to
  8452. * device with SLI-3 interface spec. This is called after PCI bus has been
  8453. * reset to restart the PCI card from scratch, as if from a cold-boot.
  8454. * During the PCI subsystem error recovery, after driver returns
  8455. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  8456. * recovery and then call this routine before calling the .resume method
  8457. * to recover the device. This function will initialize the HBA device,
  8458. * enable the interrupt, but it will just put the HBA to offline state
  8459. * without passing any I/O traffic.
  8460. *
  8461. * Return codes
  8462. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  8463. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8464. */
  8465. static pci_ers_result_t
  8466. lpfc_io_slot_reset_s3(struct pci_dev *pdev)
  8467. {
  8468. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8469. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8470. struct lpfc_sli *psli = &phba->sli;
  8471. uint32_t intr_mode;
  8472. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  8473. if (pci_enable_device_mem(pdev)) {
  8474. printk(KERN_ERR "lpfc: Cannot re-enable "
  8475. "PCI device after reset.\n");
  8476. return PCI_ERS_RESULT_DISCONNECT;
  8477. }
  8478. pci_restore_state(pdev);
  8479. /*
  8480. * As the new kernel behavior of pci_restore_state() API call clears
  8481. * device saved_state flag, need to save the restored state again.
  8482. */
  8483. pci_save_state(pdev);
  8484. if (pdev->is_busmaster)
  8485. pci_set_master(pdev);
  8486. spin_lock_irq(&phba->hbalock);
  8487. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  8488. spin_unlock_irq(&phba->hbalock);
  8489. /* Configure and enable interrupt */
  8490. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  8491. if (intr_mode == LPFC_INTR_ERROR) {
  8492. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8493. "0427 Cannot re-enable interrupt after "
  8494. "slot reset.\n");
  8495. return PCI_ERS_RESULT_DISCONNECT;
  8496. } else
  8497. phba->intr_mode = intr_mode;
  8498. /* Take device offline, it will perform cleanup */
  8499. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  8500. lpfc_offline(phba);
  8501. lpfc_sli_brdrestart(phba);
  8502. /* Log the current active interrupt mode */
  8503. lpfc_log_intr_mode(phba, phba->intr_mode);
  8504. return PCI_ERS_RESULT_RECOVERED;
  8505. }
  8506. /**
  8507. * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
  8508. * @pdev: pointer to PCI device
  8509. *
  8510. * This routine is called from the PCI subsystem for error handling to device
  8511. * with SLI-3 interface spec. It is called when kernel error recovery tells
  8512. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  8513. * error recovery. After this call, traffic can start to flow from this device
  8514. * again.
  8515. */
  8516. static void
  8517. lpfc_io_resume_s3(struct pci_dev *pdev)
  8518. {
  8519. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8520. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8521. /* Bring device online, it will be no-op for non-fatal error resume */
  8522. lpfc_online(phba);
  8523. /* Clean up Advanced Error Reporting (AER) if needed */
  8524. if (phba->hba_flag & HBA_AER_ENABLED)
  8525. pci_cleanup_aer_uncorrect_error_status(pdev);
  8526. }
  8527. /**
  8528. * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
  8529. * @phba: pointer to lpfc hba data structure.
  8530. *
  8531. * returns the number of ELS/CT IOCBs to reserve
  8532. **/
  8533. int
  8534. lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
  8535. {
  8536. int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
  8537. if (phba->sli_rev == LPFC_SLI_REV4) {
  8538. if (max_xri <= 100)
  8539. return 10;
  8540. else if (max_xri <= 256)
  8541. return 25;
  8542. else if (max_xri <= 512)
  8543. return 50;
  8544. else if (max_xri <= 1024)
  8545. return 100;
  8546. else if (max_xri <= 1536)
  8547. return 150;
  8548. else if (max_xri <= 2048)
  8549. return 200;
  8550. else
  8551. return 250;
  8552. } else
  8553. return 0;
  8554. }
  8555. /**
  8556. * lpfc_write_firmware - attempt to write a firmware image to the port
  8557. * @fw: pointer to firmware image returned from request_firmware.
  8558. * @phba: pointer to lpfc hba data structure.
  8559. *
  8560. **/
  8561. static void
  8562. lpfc_write_firmware(const struct firmware *fw, void *context)
  8563. {
  8564. struct lpfc_hba *phba = (struct lpfc_hba *)context;
  8565. char fwrev[FW_REV_STR_SIZE];
  8566. struct lpfc_grp_hdr *image;
  8567. struct list_head dma_buffer_list;
  8568. int i, rc = 0;
  8569. struct lpfc_dmabuf *dmabuf, *next;
  8570. uint32_t offset = 0, temp_offset = 0;
  8571. /* It can be null in no-wait mode, sanity check */
  8572. if (!fw) {
  8573. rc = -ENXIO;
  8574. goto out;
  8575. }
  8576. image = (struct lpfc_grp_hdr *)fw->data;
  8577. INIT_LIST_HEAD(&dma_buffer_list);
  8578. if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
  8579. (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
  8580. LPFC_FILE_TYPE_GROUP) ||
  8581. (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
  8582. (be32_to_cpu(image->size) != fw->size)) {
  8583. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8584. "3022 Invalid FW image found. "
  8585. "Magic:%x Type:%x ID:%x\n",
  8586. be32_to_cpu(image->magic_number),
  8587. bf_get_be32(lpfc_grp_hdr_file_type, image),
  8588. bf_get_be32(lpfc_grp_hdr_id, image));
  8589. rc = -EINVAL;
  8590. goto release_out;
  8591. }
  8592. lpfc_decode_firmware_rev(phba, fwrev, 1);
  8593. if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
  8594. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8595. "3023 Updating Firmware, Current Version:%s "
  8596. "New Version:%s\n",
  8597. fwrev, image->revision);
  8598. for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
  8599. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
  8600. GFP_KERNEL);
  8601. if (!dmabuf) {
  8602. rc = -ENOMEM;
  8603. goto release_out;
  8604. }
  8605. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8606. SLI4_PAGE_SIZE,
  8607. &dmabuf->phys,
  8608. GFP_KERNEL);
  8609. if (!dmabuf->virt) {
  8610. kfree(dmabuf);
  8611. rc = -ENOMEM;
  8612. goto release_out;
  8613. }
  8614. list_add_tail(&dmabuf->list, &dma_buffer_list);
  8615. }
  8616. while (offset < fw->size) {
  8617. temp_offset = offset;
  8618. list_for_each_entry(dmabuf, &dma_buffer_list, list) {
  8619. if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
  8620. memcpy(dmabuf->virt,
  8621. fw->data + temp_offset,
  8622. fw->size - temp_offset);
  8623. temp_offset = fw->size;
  8624. break;
  8625. }
  8626. memcpy(dmabuf->virt, fw->data + temp_offset,
  8627. SLI4_PAGE_SIZE);
  8628. temp_offset += SLI4_PAGE_SIZE;
  8629. }
  8630. rc = lpfc_wr_object(phba, &dma_buffer_list,
  8631. (fw->size - offset), &offset);
  8632. if (rc)
  8633. goto release_out;
  8634. }
  8635. rc = offset;
  8636. }
  8637. release_out:
  8638. list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
  8639. list_del(&dmabuf->list);
  8640. dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
  8641. dmabuf->virt, dmabuf->phys);
  8642. kfree(dmabuf);
  8643. }
  8644. release_firmware(fw);
  8645. out:
  8646. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8647. "3024 Firmware update done: %d.\n", rc);
  8648. return;
  8649. }
  8650. /**
  8651. * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
  8652. * @phba: pointer to lpfc hba data structure.
  8653. *
  8654. * This routine is called to perform Linux generic firmware upgrade on device
  8655. * that supports such feature.
  8656. **/
  8657. int
  8658. lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
  8659. {
  8660. uint8_t file_name[ELX_MODEL_NAME_SIZE];
  8661. int ret;
  8662. const struct firmware *fw;
  8663. /* Only supported on SLI4 interface type 2 for now */
  8664. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  8665. LPFC_SLI_INTF_IF_TYPE_2)
  8666. return -EPERM;
  8667. snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
  8668. if (fw_upgrade == INT_FW_UPGRADE) {
  8669. ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
  8670. file_name, &phba->pcidev->dev,
  8671. GFP_KERNEL, (void *)phba,
  8672. lpfc_write_firmware);
  8673. } else if (fw_upgrade == RUN_FW_UPGRADE) {
  8674. ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
  8675. if (!ret)
  8676. lpfc_write_firmware(fw, (void *)phba);
  8677. } else {
  8678. ret = -EINVAL;
  8679. }
  8680. return ret;
  8681. }
  8682. /**
  8683. * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
  8684. * @pdev: pointer to PCI device
  8685. * @pid: pointer to PCI device identifier
  8686. *
  8687. * This routine is called from the kernel's PCI subsystem to device with
  8688. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  8689. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  8690. * information of the device and driver to see if the driver state that it
  8691. * can support this kind of device. If the match is successful, the driver
  8692. * core invokes this routine. If this routine determines it can claim the HBA,
  8693. * it does all the initialization that it needs to do to handle the HBA
  8694. * properly.
  8695. *
  8696. * Return code
  8697. * 0 - driver can claim the device
  8698. * negative value - driver can not claim the device
  8699. **/
  8700. static int
  8701. lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
  8702. {
  8703. struct lpfc_hba *phba;
  8704. struct lpfc_vport *vport = NULL;
  8705. struct Scsi_Host *shost = NULL;
  8706. int error, ret;
  8707. uint32_t cfg_mode, intr_mode;
  8708. int mcnt;
  8709. int adjusted_fcp_io_channel;
  8710. /* Allocate memory for HBA structure */
  8711. phba = lpfc_hba_alloc(pdev);
  8712. if (!phba)
  8713. return -ENOMEM;
  8714. /* Perform generic PCI device enabling operation */
  8715. error = lpfc_enable_pci_dev(phba);
  8716. if (error)
  8717. goto out_free_phba;
  8718. /* Set up SLI API function jump table for PCI-device group-1 HBAs */
  8719. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
  8720. if (error)
  8721. goto out_disable_pci_dev;
  8722. /* Set up SLI-4 specific device PCI memory space */
  8723. error = lpfc_sli4_pci_mem_setup(phba);
  8724. if (error) {
  8725. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8726. "1410 Failed to set up pci memory space.\n");
  8727. goto out_disable_pci_dev;
  8728. }
  8729. /* Set up phase-1 common device driver resources */
  8730. error = lpfc_setup_driver_resource_phase1(phba);
  8731. if (error) {
  8732. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8733. "1411 Failed to set up driver resource.\n");
  8734. goto out_unset_pci_mem_s4;
  8735. }
  8736. /* Set up SLI-4 Specific device driver resources */
  8737. error = lpfc_sli4_driver_resource_setup(phba);
  8738. if (error) {
  8739. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8740. "1412 Failed to set up driver resource.\n");
  8741. goto out_unset_pci_mem_s4;
  8742. }
  8743. /* Initialize and populate the iocb list per host */
  8744. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8745. "2821 initialize iocb list %d.\n",
  8746. phba->cfg_iocb_cnt*1024);
  8747. error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
  8748. if (error) {
  8749. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8750. "1413 Failed to initialize iocb list.\n");
  8751. goto out_unset_driver_resource_s4;
  8752. }
  8753. INIT_LIST_HEAD(&phba->active_rrq_list);
  8754. INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
  8755. /* Set up common device driver resources */
  8756. error = lpfc_setup_driver_resource_phase2(phba);
  8757. if (error) {
  8758. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8759. "1414 Failed to set up driver resource.\n");
  8760. goto out_free_iocb_list;
  8761. }
  8762. /* Get the default values for Model Name and Description */
  8763. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  8764. /* Create SCSI host to the physical port */
  8765. error = lpfc_create_shost(phba);
  8766. if (error) {
  8767. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8768. "1415 Failed to create scsi host.\n");
  8769. goto out_unset_driver_resource;
  8770. }
  8771. /* Configure sysfs attributes */
  8772. vport = phba->pport;
  8773. error = lpfc_alloc_sysfs_attr(vport);
  8774. if (error) {
  8775. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8776. "1416 Failed to allocate sysfs attr\n");
  8777. goto out_destroy_shost;
  8778. }
  8779. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  8780. /* Now, trying to enable interrupt and bring up the device */
  8781. cfg_mode = phba->cfg_use_msi;
  8782. while (true) {
  8783. /* Put device to a known state before enabling interrupt */
  8784. lpfc_stop_port(phba);
  8785. /* Configure and enable interrupt */
  8786. intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
  8787. if (intr_mode == LPFC_INTR_ERROR) {
  8788. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8789. "0426 Failed to enable interrupt.\n");
  8790. error = -ENODEV;
  8791. goto out_free_sysfs_attr;
  8792. }
  8793. /* Default to single EQ for non-MSI-X */
  8794. if (phba->intr_type != MSIX)
  8795. adjusted_fcp_io_channel = 1;
  8796. else
  8797. adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
  8798. phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
  8799. /* Set up SLI-4 HBA */
  8800. if (lpfc_sli4_hba_setup(phba)) {
  8801. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8802. "1421 Failed to set up hba\n");
  8803. error = -ENODEV;
  8804. goto out_disable_intr;
  8805. }
  8806. /* Send NOP mbx cmds for non-INTx mode active interrupt test */
  8807. if (intr_mode != 0)
  8808. mcnt = lpfc_sli4_send_nop_mbox_cmds(phba,
  8809. LPFC_ACT_INTR_CNT);
  8810. /* Check active interrupts received only for MSI/MSI-X */
  8811. if (intr_mode == 0 ||
  8812. phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) {
  8813. /* Log the current active interrupt mode */
  8814. phba->intr_mode = intr_mode;
  8815. lpfc_log_intr_mode(phba, intr_mode);
  8816. break;
  8817. }
  8818. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8819. "0451 Configure interrupt mode (%d) "
  8820. "failed active interrupt test.\n",
  8821. intr_mode);
  8822. /* Unset the previous SLI-4 HBA setup. */
  8823. /*
  8824. * TODO: Is this operation compatible with IF TYPE 2
  8825. * devices? All port state is deleted and cleared.
  8826. */
  8827. lpfc_sli4_unset_hba(phba);
  8828. /* Try next level of interrupt mode */
  8829. cfg_mode = --intr_mode;
  8830. }
  8831. /* Perform post initialization setup */
  8832. lpfc_post_init_setup(phba);
  8833. /* check for firmware upgrade or downgrade */
  8834. if (phba->cfg_request_firmware_upgrade)
  8835. ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
  8836. /* Check if there are static vports to be created. */
  8837. lpfc_create_static_vport(phba);
  8838. return 0;
  8839. out_disable_intr:
  8840. lpfc_sli4_disable_intr(phba);
  8841. out_free_sysfs_attr:
  8842. lpfc_free_sysfs_attr(vport);
  8843. out_destroy_shost:
  8844. lpfc_destroy_shost(phba);
  8845. out_unset_driver_resource:
  8846. lpfc_unset_driver_resource_phase2(phba);
  8847. out_free_iocb_list:
  8848. lpfc_free_iocb_list(phba);
  8849. out_unset_driver_resource_s4:
  8850. lpfc_sli4_driver_resource_unset(phba);
  8851. out_unset_pci_mem_s4:
  8852. lpfc_sli4_pci_mem_unset(phba);
  8853. out_disable_pci_dev:
  8854. lpfc_disable_pci_dev(phba);
  8855. if (shost)
  8856. scsi_host_put(shost);
  8857. out_free_phba:
  8858. lpfc_hba_free(phba);
  8859. return error;
  8860. }
  8861. /**
  8862. * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
  8863. * @pdev: pointer to PCI device
  8864. *
  8865. * This routine is called from the kernel's PCI subsystem to device with
  8866. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  8867. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  8868. * device to be removed from the PCI subsystem properly.
  8869. **/
  8870. static void
  8871. lpfc_pci_remove_one_s4(struct pci_dev *pdev)
  8872. {
  8873. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8874. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  8875. struct lpfc_vport **vports;
  8876. struct lpfc_hba *phba = vport->phba;
  8877. int i;
  8878. /* Mark the device unloading flag */
  8879. spin_lock_irq(&phba->hbalock);
  8880. vport->load_flag |= FC_UNLOADING;
  8881. spin_unlock_irq(&phba->hbalock);
  8882. /* Free the HBA sysfs attributes */
  8883. lpfc_free_sysfs_attr(vport);
  8884. /* Release all the vports against this physical port */
  8885. vports = lpfc_create_vport_work_array(phba);
  8886. if (vports != NULL)
  8887. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  8888. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  8889. continue;
  8890. fc_vport_terminate(vports[i]->fc_vport);
  8891. }
  8892. lpfc_destroy_vport_work_array(phba, vports);
  8893. /* Remove FC host and then SCSI host with the physical port */
  8894. fc_remove_host(shost);
  8895. scsi_remove_host(shost);
  8896. /* Perform cleanup on the physical port */
  8897. lpfc_cleanup(vport);
  8898. /*
  8899. * Bring down the SLI Layer. This step disables all interrupts,
  8900. * clears the rings, discards all mailbox commands, and resets
  8901. * the HBA FCoE function.
  8902. */
  8903. lpfc_debugfs_terminate(vport);
  8904. lpfc_sli4_hba_unset(phba);
  8905. spin_lock_irq(&phba->hbalock);
  8906. list_del_init(&vport->listentry);
  8907. spin_unlock_irq(&phba->hbalock);
  8908. /* Perform scsi free before driver resource_unset since scsi
  8909. * buffers are released to their corresponding pools here.
  8910. */
  8911. lpfc_scsi_free(phba);
  8912. lpfc_sli4_driver_resource_unset(phba);
  8913. /* Unmap adapter Control and Doorbell registers */
  8914. lpfc_sli4_pci_mem_unset(phba);
  8915. /* Release PCI resources and disable device's PCI function */
  8916. scsi_host_put(shost);
  8917. lpfc_disable_pci_dev(phba);
  8918. /* Finally, free the driver's device data structure */
  8919. lpfc_hba_free(phba);
  8920. return;
  8921. }
  8922. /**
  8923. * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
  8924. * @pdev: pointer to PCI device
  8925. * @msg: power management message
  8926. *
  8927. * This routine is called from the kernel's PCI subsystem to support system
  8928. * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
  8929. * this method, it quiesces the device by stopping the driver's worker
  8930. * thread for the device, turning off device's interrupt and DMA, and bring
  8931. * the device offline. Note that as the driver implements the minimum PM
  8932. * requirements to a power-aware driver's PM support for suspend/resume -- all
  8933. * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
  8934. * method call will be treated as SUSPEND and the driver will fully
  8935. * reinitialize its device during resume() method call, the driver will set
  8936. * device to PCI_D3hot state in PCI config space instead of setting it
  8937. * according to the @msg provided by the PM.
  8938. *
  8939. * Return code
  8940. * 0 - driver suspended the device
  8941. * Error otherwise
  8942. **/
  8943. static int
  8944. lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
  8945. {
  8946. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8947. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8948. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8949. "2843 PCI device Power Management suspend.\n");
  8950. /* Bring down the device */
  8951. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  8952. lpfc_offline(phba);
  8953. kthread_stop(phba->worker_thread);
  8954. /* Disable interrupt from device */
  8955. lpfc_sli4_disable_intr(phba);
  8956. lpfc_sli4_queue_destroy(phba);
  8957. /* Save device state to PCI config space */
  8958. pci_save_state(pdev);
  8959. pci_set_power_state(pdev, PCI_D3hot);
  8960. return 0;
  8961. }
  8962. /**
  8963. * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
  8964. * @pdev: pointer to PCI device
  8965. *
  8966. * This routine is called from the kernel's PCI subsystem to support system
  8967. * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
  8968. * this method, it restores the device's PCI config space state and fully
  8969. * reinitializes the device and brings it online. Note that as the driver
  8970. * implements the minimum PM requirements to a power-aware driver's PM for
  8971. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  8972. * to the suspend() method call will be treated as SUSPEND and the driver
  8973. * will fully reinitialize its device during resume() method call, the device
  8974. * will be set to PCI_D0 directly in PCI config space before restoring the
  8975. * state.
  8976. *
  8977. * Return code
  8978. * 0 - driver suspended the device
  8979. * Error otherwise
  8980. **/
  8981. static int
  8982. lpfc_pci_resume_one_s4(struct pci_dev *pdev)
  8983. {
  8984. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8985. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8986. uint32_t intr_mode;
  8987. int error;
  8988. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8989. "0292 PCI device Power Management resume.\n");
  8990. /* Restore device state from PCI config space */
  8991. pci_set_power_state(pdev, PCI_D0);
  8992. pci_restore_state(pdev);
  8993. /*
  8994. * As the new kernel behavior of pci_restore_state() API call clears
  8995. * device saved_state flag, need to save the restored state again.
  8996. */
  8997. pci_save_state(pdev);
  8998. if (pdev->is_busmaster)
  8999. pci_set_master(pdev);
  9000. /* Startup the kernel thread for this host adapter. */
  9001. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  9002. "lpfc_worker_%d", phba->brd_no);
  9003. if (IS_ERR(phba->worker_thread)) {
  9004. error = PTR_ERR(phba->worker_thread);
  9005. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9006. "0293 PM resume failed to start worker "
  9007. "thread: error=x%x.\n", error);
  9008. return error;
  9009. }
  9010. /* Configure and enable interrupt */
  9011. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  9012. if (intr_mode == LPFC_INTR_ERROR) {
  9013. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9014. "0294 PM resume Failed to enable interrupt\n");
  9015. return -EIO;
  9016. } else
  9017. phba->intr_mode = intr_mode;
  9018. /* Restart HBA and bring it online */
  9019. lpfc_sli_brdrestart(phba);
  9020. lpfc_online(phba);
  9021. /* Log the current active interrupt mode */
  9022. lpfc_log_intr_mode(phba, phba->intr_mode);
  9023. return 0;
  9024. }
  9025. /**
  9026. * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
  9027. * @phba: pointer to lpfc hba data structure.
  9028. *
  9029. * This routine is called to prepare the SLI4 device for PCI slot recover. It
  9030. * aborts all the outstanding SCSI I/Os to the pci device.
  9031. **/
  9032. static void
  9033. lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
  9034. {
  9035. struct lpfc_sli *psli = &phba->sli;
  9036. struct lpfc_sli_ring *pring;
  9037. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9038. "2828 PCI channel I/O abort preparing for recovery\n");
  9039. /*
  9040. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  9041. * and let the SCSI mid-layer to retry them to recover.
  9042. */
  9043. pring = &psli->ring[psli->fcp_ring];
  9044. lpfc_sli_abort_iocb_ring(phba, pring);
  9045. }
  9046. /**
  9047. * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
  9048. * @phba: pointer to lpfc hba data structure.
  9049. *
  9050. * This routine is called to prepare the SLI4 device for PCI slot reset. It
  9051. * disables the device interrupt and pci device, and aborts the internal FCP
  9052. * pending I/Os.
  9053. **/
  9054. static void
  9055. lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
  9056. {
  9057. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9058. "2826 PCI channel disable preparing for reset\n");
  9059. /* Block any management I/Os to the device */
  9060. lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
  9061. /* Block all SCSI devices' I/Os on the host */
  9062. lpfc_scsi_dev_block(phba);
  9063. /* stop all timers */
  9064. lpfc_stop_hba_timers(phba);
  9065. /* Disable interrupt and pci device */
  9066. lpfc_sli4_disable_intr(phba);
  9067. lpfc_sli4_queue_destroy(phba);
  9068. pci_disable_device(phba->pcidev);
  9069. /* Flush all driver's outstanding SCSI I/Os as we are to reset */
  9070. lpfc_sli_flush_fcp_rings(phba);
  9071. }
  9072. /**
  9073. * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
  9074. * @phba: pointer to lpfc hba data structure.
  9075. *
  9076. * This routine is called to prepare the SLI4 device for PCI slot permanently
  9077. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  9078. * pending I/Os.
  9079. **/
  9080. static void
  9081. lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  9082. {
  9083. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9084. "2827 PCI channel permanent disable for failure\n");
  9085. /* Block all SCSI devices' I/Os on the host */
  9086. lpfc_scsi_dev_block(phba);
  9087. /* stop all timers */
  9088. lpfc_stop_hba_timers(phba);
  9089. /* Clean up all driver's outstanding SCSI I/Os */
  9090. lpfc_sli_flush_fcp_rings(phba);
  9091. }
  9092. /**
  9093. * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
  9094. * @pdev: pointer to PCI device.
  9095. * @state: the current PCI connection state.
  9096. *
  9097. * This routine is called from the PCI subsystem for error handling to device
  9098. * with SLI-4 interface spec. This function is called by the PCI subsystem
  9099. * after a PCI bus error affecting this device has been detected. When this
  9100. * function is invoked, it will need to stop all the I/Os and interrupt(s)
  9101. * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
  9102. * for the PCI subsystem to perform proper recovery as desired.
  9103. *
  9104. * Return codes
  9105. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  9106. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9107. **/
  9108. static pci_ers_result_t
  9109. lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
  9110. {
  9111. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9112. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9113. switch (state) {
  9114. case pci_channel_io_normal:
  9115. /* Non-fatal error, prepare for recovery */
  9116. lpfc_sli4_prep_dev_for_recover(phba);
  9117. return PCI_ERS_RESULT_CAN_RECOVER;
  9118. case pci_channel_io_frozen:
  9119. /* Fatal error, prepare for slot reset */
  9120. lpfc_sli4_prep_dev_for_reset(phba);
  9121. return PCI_ERS_RESULT_NEED_RESET;
  9122. case pci_channel_io_perm_failure:
  9123. /* Permanent failure, prepare for device down */
  9124. lpfc_sli4_prep_dev_for_perm_failure(phba);
  9125. return PCI_ERS_RESULT_DISCONNECT;
  9126. default:
  9127. /* Unknown state, prepare and request slot reset */
  9128. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9129. "2825 Unknown PCI error state: x%x\n", state);
  9130. lpfc_sli4_prep_dev_for_reset(phba);
  9131. return PCI_ERS_RESULT_NEED_RESET;
  9132. }
  9133. }
  9134. /**
  9135. * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
  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 after PCI bus has been reset to
  9140. * restart the PCI card from scratch, as if from a cold-boot. During the
  9141. * PCI subsystem error recovery, after the driver returns
  9142. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  9143. * recovery and then call this routine before calling the .resume method to
  9144. * recover the device. This function will initialize the HBA device, enable
  9145. * the interrupt, but it will just put the HBA to offline state without
  9146. * passing any I/O traffic.
  9147. *
  9148. * Return codes
  9149. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  9150. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9151. */
  9152. static pci_ers_result_t
  9153. lpfc_io_slot_reset_s4(struct pci_dev *pdev)
  9154. {
  9155. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9156. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9157. struct lpfc_sli *psli = &phba->sli;
  9158. uint32_t intr_mode;
  9159. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  9160. if (pci_enable_device_mem(pdev)) {
  9161. printk(KERN_ERR "lpfc: Cannot re-enable "
  9162. "PCI device after reset.\n");
  9163. return PCI_ERS_RESULT_DISCONNECT;
  9164. }
  9165. pci_restore_state(pdev);
  9166. /*
  9167. * As the new kernel behavior of pci_restore_state() API call clears
  9168. * device saved_state flag, need to save the restored state again.
  9169. */
  9170. pci_save_state(pdev);
  9171. if (pdev->is_busmaster)
  9172. pci_set_master(pdev);
  9173. spin_lock_irq(&phba->hbalock);
  9174. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  9175. spin_unlock_irq(&phba->hbalock);
  9176. /* Configure and enable interrupt */
  9177. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  9178. if (intr_mode == LPFC_INTR_ERROR) {
  9179. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9180. "2824 Cannot re-enable interrupt after "
  9181. "slot reset.\n");
  9182. return PCI_ERS_RESULT_DISCONNECT;
  9183. } else
  9184. phba->intr_mode = intr_mode;
  9185. /* Log the current active interrupt mode */
  9186. lpfc_log_intr_mode(phba, phba->intr_mode);
  9187. return PCI_ERS_RESULT_RECOVERED;
  9188. }
  9189. /**
  9190. * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
  9191. * @pdev: pointer to PCI device
  9192. *
  9193. * This routine is called from the PCI subsystem for error handling to device
  9194. * with SLI-4 interface spec. It is called when kernel error recovery tells
  9195. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  9196. * error recovery. After this call, traffic can start to flow from this device
  9197. * again.
  9198. **/
  9199. static void
  9200. lpfc_io_resume_s4(struct pci_dev *pdev)
  9201. {
  9202. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9203. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9204. /*
  9205. * In case of slot reset, as function reset is performed through
  9206. * mailbox command which needs DMA to be enabled, this operation
  9207. * has to be moved to the io resume phase. Taking device offline
  9208. * will perform the necessary cleanup.
  9209. */
  9210. if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
  9211. /* Perform device reset */
  9212. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  9213. lpfc_offline(phba);
  9214. lpfc_sli_brdrestart(phba);
  9215. /* Bring the device back online */
  9216. lpfc_online(phba);
  9217. }
  9218. /* Clean up Advanced Error Reporting (AER) if needed */
  9219. if (phba->hba_flag & HBA_AER_ENABLED)
  9220. pci_cleanup_aer_uncorrect_error_status(pdev);
  9221. }
  9222. /**
  9223. * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
  9224. * @pdev: pointer to PCI device
  9225. * @pid: pointer to PCI device identifier
  9226. *
  9227. * This routine is to be registered to the kernel's PCI subsystem. When an
  9228. * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
  9229. * at PCI device-specific information of the device and driver to see if the
  9230. * driver state that it can support this kind of device. If the match is
  9231. * successful, the driver core invokes this routine. This routine dispatches
  9232. * the action to the proper SLI-3 or SLI-4 device probing routine, which will
  9233. * do all the initialization that it needs to do to handle the HBA device
  9234. * properly.
  9235. *
  9236. * Return code
  9237. * 0 - driver can claim the device
  9238. * negative value - driver can not claim the device
  9239. **/
  9240. static int
  9241. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  9242. {
  9243. int rc;
  9244. struct lpfc_sli_intf intf;
  9245. if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
  9246. return -ENODEV;
  9247. if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
  9248. (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
  9249. rc = lpfc_pci_probe_one_s4(pdev, pid);
  9250. else
  9251. rc = lpfc_pci_probe_one_s3(pdev, pid);
  9252. return rc;
  9253. }
  9254. /**
  9255. * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
  9256. * @pdev: pointer to PCI device
  9257. *
  9258. * This routine is to be registered to the kernel's PCI subsystem. When an
  9259. * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
  9260. * This routine dispatches the action to the proper SLI-3 or SLI-4 device
  9261. * remove routine, which will perform all the necessary cleanup for the
  9262. * device to be removed from the PCI subsystem properly.
  9263. **/
  9264. static void
  9265. lpfc_pci_remove_one(struct pci_dev *pdev)
  9266. {
  9267. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9268. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9269. switch (phba->pci_dev_grp) {
  9270. case LPFC_PCI_DEV_LP:
  9271. lpfc_pci_remove_one_s3(pdev);
  9272. break;
  9273. case LPFC_PCI_DEV_OC:
  9274. lpfc_pci_remove_one_s4(pdev);
  9275. break;
  9276. default:
  9277. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9278. "1424 Invalid PCI device group: 0x%x\n",
  9279. phba->pci_dev_grp);
  9280. break;
  9281. }
  9282. return;
  9283. }
  9284. /**
  9285. * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
  9286. * @pdev: pointer to PCI device
  9287. * @msg: power management message
  9288. *
  9289. * This routine is to be registered to the kernel's PCI subsystem to support
  9290. * system Power Management (PM). When PM invokes this method, it dispatches
  9291. * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
  9292. * suspend the device.
  9293. *
  9294. * Return code
  9295. * 0 - driver suspended the device
  9296. * Error otherwise
  9297. **/
  9298. static int
  9299. lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
  9300. {
  9301. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9302. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9303. int rc = -ENODEV;
  9304. switch (phba->pci_dev_grp) {
  9305. case LPFC_PCI_DEV_LP:
  9306. rc = lpfc_pci_suspend_one_s3(pdev, msg);
  9307. break;
  9308. case LPFC_PCI_DEV_OC:
  9309. rc = lpfc_pci_suspend_one_s4(pdev, msg);
  9310. break;
  9311. default:
  9312. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9313. "1425 Invalid PCI device group: 0x%x\n",
  9314. phba->pci_dev_grp);
  9315. break;
  9316. }
  9317. return rc;
  9318. }
  9319. /**
  9320. * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
  9321. * @pdev: pointer to PCI device
  9322. *
  9323. * This routine is to be registered to the kernel's PCI subsystem to support
  9324. * system Power Management (PM). When PM invokes this method, it dispatches
  9325. * the action to the proper SLI-3 or SLI-4 device resume routine, which will
  9326. * resume the device.
  9327. *
  9328. * Return code
  9329. * 0 - driver suspended the device
  9330. * Error otherwise
  9331. **/
  9332. static int
  9333. lpfc_pci_resume_one(struct pci_dev *pdev)
  9334. {
  9335. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9336. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9337. int rc = -ENODEV;
  9338. switch (phba->pci_dev_grp) {
  9339. case LPFC_PCI_DEV_LP:
  9340. rc = lpfc_pci_resume_one_s3(pdev);
  9341. break;
  9342. case LPFC_PCI_DEV_OC:
  9343. rc = lpfc_pci_resume_one_s4(pdev);
  9344. break;
  9345. default:
  9346. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9347. "1426 Invalid PCI device group: 0x%x\n",
  9348. phba->pci_dev_grp);
  9349. break;
  9350. }
  9351. return rc;
  9352. }
  9353. /**
  9354. * lpfc_io_error_detected - lpfc method for handling PCI I/O error
  9355. * @pdev: pointer to PCI device.
  9356. * @state: the current PCI connection state.
  9357. *
  9358. * This routine is registered to the PCI subsystem for error handling. This
  9359. * function is called by the PCI subsystem after a PCI bus error affecting
  9360. * this device has been detected. When this routine is invoked, it dispatches
  9361. * the action to the proper SLI-3 or SLI-4 device error detected handling
  9362. * routine, which will perform the proper error detected operation.
  9363. *
  9364. * Return codes
  9365. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  9366. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9367. **/
  9368. static pci_ers_result_t
  9369. lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  9370. {
  9371. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9372. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9373. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  9374. switch (phba->pci_dev_grp) {
  9375. case LPFC_PCI_DEV_LP:
  9376. rc = lpfc_io_error_detected_s3(pdev, state);
  9377. break;
  9378. case LPFC_PCI_DEV_OC:
  9379. rc = lpfc_io_error_detected_s4(pdev, state);
  9380. break;
  9381. default:
  9382. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9383. "1427 Invalid PCI device group: 0x%x\n",
  9384. phba->pci_dev_grp);
  9385. break;
  9386. }
  9387. return rc;
  9388. }
  9389. /**
  9390. * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
  9391. * @pdev: pointer to PCI device.
  9392. *
  9393. * This routine is registered to the PCI subsystem for error handling. This
  9394. * function is called after PCI bus has been reset to restart the PCI card
  9395. * from scratch, as if from a cold-boot. When this routine is invoked, it
  9396. * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
  9397. * routine, which will perform the proper device reset.
  9398. *
  9399. * Return codes
  9400. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  9401. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  9402. **/
  9403. static pci_ers_result_t
  9404. lpfc_io_slot_reset(struct pci_dev *pdev)
  9405. {
  9406. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9407. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9408. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  9409. switch (phba->pci_dev_grp) {
  9410. case LPFC_PCI_DEV_LP:
  9411. rc = lpfc_io_slot_reset_s3(pdev);
  9412. break;
  9413. case LPFC_PCI_DEV_OC:
  9414. rc = lpfc_io_slot_reset_s4(pdev);
  9415. break;
  9416. default:
  9417. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9418. "1428 Invalid PCI device group: 0x%x\n",
  9419. phba->pci_dev_grp);
  9420. break;
  9421. }
  9422. return rc;
  9423. }
  9424. /**
  9425. * lpfc_io_resume - lpfc method for resuming PCI I/O operation
  9426. * @pdev: pointer to PCI device
  9427. *
  9428. * This routine is registered to the PCI subsystem for error handling. It
  9429. * is called when kernel error recovery tells the lpfc driver that it is
  9430. * OK to resume normal PCI operation after PCI bus error recovery. When
  9431. * this routine is invoked, it dispatches the action to the proper SLI-3
  9432. * or SLI-4 device io_resume routine, which will resume the device operation.
  9433. **/
  9434. static void
  9435. lpfc_io_resume(struct pci_dev *pdev)
  9436. {
  9437. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9438. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  9439. switch (phba->pci_dev_grp) {
  9440. case LPFC_PCI_DEV_LP:
  9441. lpfc_io_resume_s3(pdev);
  9442. break;
  9443. case LPFC_PCI_DEV_OC:
  9444. lpfc_io_resume_s4(pdev);
  9445. break;
  9446. default:
  9447. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9448. "1429 Invalid PCI device group: 0x%x\n",
  9449. phba->pci_dev_grp);
  9450. break;
  9451. }
  9452. return;
  9453. }
  9454. /**
  9455. * lpfc_mgmt_open - method called when 'lpfcmgmt' is opened from userspace
  9456. * @inode: pointer to the inode representing the lpfcmgmt device
  9457. * @filep: pointer to the file representing the open lpfcmgmt device
  9458. *
  9459. * This routine puts a reference count on the lpfc module whenever the
  9460. * character device is opened
  9461. **/
  9462. static int
  9463. lpfc_mgmt_open(struct inode *inode, struct file *filep)
  9464. {
  9465. try_module_get(THIS_MODULE);
  9466. return 0;
  9467. }
  9468. /**
  9469. * lpfc_mgmt_release - method called when 'lpfcmgmt' is closed in userspace
  9470. * @inode: pointer to the inode representing the lpfcmgmt device
  9471. * @filep: pointer to the file representing the open lpfcmgmt device
  9472. *
  9473. * This routine removes a reference count from the lpfc module when the
  9474. * character device is closed
  9475. **/
  9476. static int
  9477. lpfc_mgmt_release(struct inode *inode, struct file *filep)
  9478. {
  9479. module_put(THIS_MODULE);
  9480. return 0;
  9481. }
  9482. static struct pci_device_id lpfc_id_table[] = {
  9483. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  9484. PCI_ANY_ID, PCI_ANY_ID, },
  9485. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  9486. PCI_ANY_ID, PCI_ANY_ID, },
  9487. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  9488. PCI_ANY_ID, PCI_ANY_ID, },
  9489. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  9490. PCI_ANY_ID, PCI_ANY_ID, },
  9491. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  9492. PCI_ANY_ID, PCI_ANY_ID, },
  9493. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  9494. PCI_ANY_ID, PCI_ANY_ID, },
  9495. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  9496. PCI_ANY_ID, PCI_ANY_ID, },
  9497. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  9498. PCI_ANY_ID, PCI_ANY_ID, },
  9499. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  9500. PCI_ANY_ID, PCI_ANY_ID, },
  9501. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  9502. PCI_ANY_ID, PCI_ANY_ID, },
  9503. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  9504. PCI_ANY_ID, PCI_ANY_ID, },
  9505. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  9506. PCI_ANY_ID, PCI_ANY_ID, },
  9507. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  9508. PCI_ANY_ID, PCI_ANY_ID, },
  9509. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  9510. PCI_ANY_ID, PCI_ANY_ID, },
  9511. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  9512. PCI_ANY_ID, PCI_ANY_ID, },
  9513. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  9514. PCI_ANY_ID, PCI_ANY_ID, },
  9515. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  9516. PCI_ANY_ID, PCI_ANY_ID, },
  9517. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  9518. PCI_ANY_ID, PCI_ANY_ID, },
  9519. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
  9520. PCI_ANY_ID, PCI_ANY_ID, },
  9521. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  9522. PCI_ANY_ID, PCI_ANY_ID, },
  9523. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  9524. PCI_ANY_ID, PCI_ANY_ID, },
  9525. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  9526. PCI_ANY_ID, PCI_ANY_ID, },
  9527. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  9528. PCI_ANY_ID, PCI_ANY_ID, },
  9529. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  9530. PCI_ANY_ID, PCI_ANY_ID, },
  9531. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  9532. PCI_ANY_ID, PCI_ANY_ID, },
  9533. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  9534. PCI_ANY_ID, PCI_ANY_ID, },
  9535. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  9536. PCI_ANY_ID, PCI_ANY_ID, },
  9537. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  9538. PCI_ANY_ID, PCI_ANY_ID, },
  9539. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  9540. PCI_ANY_ID, PCI_ANY_ID, },
  9541. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  9542. PCI_ANY_ID, PCI_ANY_ID, },
  9543. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  9544. PCI_ANY_ID, PCI_ANY_ID, },
  9545. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  9546. PCI_ANY_ID, PCI_ANY_ID, },
  9547. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  9548. PCI_ANY_ID, PCI_ANY_ID, },
  9549. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  9550. PCI_ANY_ID, PCI_ANY_ID, },
  9551. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
  9552. PCI_ANY_ID, PCI_ANY_ID, },
  9553. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
  9554. PCI_ANY_ID, PCI_ANY_ID, },
  9555. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
  9556. PCI_ANY_ID, PCI_ANY_ID, },
  9557. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
  9558. PCI_ANY_ID, PCI_ANY_ID, },
  9559. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
  9560. PCI_ANY_ID, PCI_ANY_ID, },
  9561. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
  9562. PCI_ANY_ID, PCI_ANY_ID, },
  9563. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
  9564. PCI_ANY_ID, PCI_ANY_ID, },
  9565. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
  9566. PCI_ANY_ID, PCI_ANY_ID, },
  9567. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
  9568. PCI_ANY_ID, PCI_ANY_ID, },
  9569. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
  9570. PCI_ANY_ID, PCI_ANY_ID, },
  9571. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
  9572. PCI_ANY_ID, PCI_ANY_ID, },
  9573. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK,
  9574. PCI_ANY_ID, PCI_ANY_ID, },
  9575. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF,
  9576. PCI_ANY_ID, PCI_ANY_ID, },
  9577. { 0 }
  9578. };
  9579. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  9580. static const struct pci_error_handlers lpfc_err_handler = {
  9581. .error_detected = lpfc_io_error_detected,
  9582. .slot_reset = lpfc_io_slot_reset,
  9583. .resume = lpfc_io_resume,
  9584. };
  9585. static struct pci_driver lpfc_driver = {
  9586. .name = LPFC_DRIVER_NAME,
  9587. .id_table = lpfc_id_table,
  9588. .probe = lpfc_pci_probe_one,
  9589. .remove = lpfc_pci_remove_one,
  9590. .suspend = lpfc_pci_suspend_one,
  9591. .resume = lpfc_pci_resume_one,
  9592. .err_handler = &lpfc_err_handler,
  9593. };
  9594. static const struct file_operations lpfc_mgmt_fop = {
  9595. .open = lpfc_mgmt_open,
  9596. .release = lpfc_mgmt_release,
  9597. };
  9598. static struct miscdevice lpfc_mgmt_dev = {
  9599. .minor = MISC_DYNAMIC_MINOR,
  9600. .name = "lpfcmgmt",
  9601. .fops = &lpfc_mgmt_fop,
  9602. };
  9603. /**
  9604. * lpfc_init - lpfc module initialization routine
  9605. *
  9606. * This routine is to be invoked when the lpfc module is loaded into the
  9607. * kernel. The special kernel macro module_init() is used to indicate the
  9608. * role of this routine to the kernel as lpfc module entry point.
  9609. *
  9610. * Return codes
  9611. * 0 - successful
  9612. * -ENOMEM - FC attach transport failed
  9613. * all others - failed
  9614. */
  9615. static int __init
  9616. lpfc_init(void)
  9617. {
  9618. int error = 0;
  9619. printk(LPFC_MODULE_DESC "\n");
  9620. printk(LPFC_COPYRIGHT "\n");
  9621. error = misc_register(&lpfc_mgmt_dev);
  9622. if (error)
  9623. printk(KERN_ERR "Could not register lpfcmgmt device, "
  9624. "misc_register returned with status %d", error);
  9625. if (lpfc_enable_npiv) {
  9626. lpfc_transport_functions.vport_create = lpfc_vport_create;
  9627. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  9628. }
  9629. lpfc_transport_template =
  9630. fc_attach_transport(&lpfc_transport_functions);
  9631. if (lpfc_transport_template == NULL)
  9632. return -ENOMEM;
  9633. if (lpfc_enable_npiv) {
  9634. lpfc_vport_transport_template =
  9635. fc_attach_transport(&lpfc_vport_transport_functions);
  9636. if (lpfc_vport_transport_template == NULL) {
  9637. fc_release_transport(lpfc_transport_template);
  9638. return -ENOMEM;
  9639. }
  9640. }
  9641. error = pci_register_driver(&lpfc_driver);
  9642. if (error) {
  9643. fc_release_transport(lpfc_transport_template);
  9644. if (lpfc_enable_npiv)
  9645. fc_release_transport(lpfc_vport_transport_template);
  9646. }
  9647. return error;
  9648. }
  9649. /**
  9650. * lpfc_exit - lpfc module removal routine
  9651. *
  9652. * This routine is invoked when the lpfc module is removed from the kernel.
  9653. * The special kernel macro module_exit() is used to indicate the role of
  9654. * this routine to the kernel as lpfc module exit point.
  9655. */
  9656. static void __exit
  9657. lpfc_exit(void)
  9658. {
  9659. misc_deregister(&lpfc_mgmt_dev);
  9660. pci_unregister_driver(&lpfc_driver);
  9661. fc_release_transport(lpfc_transport_template);
  9662. if (lpfc_enable_npiv)
  9663. fc_release_transport(lpfc_vport_transport_template);
  9664. if (_dump_buf_data) {
  9665. printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
  9666. "_dump_buf_data at 0x%p\n",
  9667. (1L << _dump_buf_data_order), _dump_buf_data);
  9668. free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
  9669. }
  9670. if (_dump_buf_dif) {
  9671. printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
  9672. "_dump_buf_dif at 0x%p\n",
  9673. (1L << _dump_buf_dif_order), _dump_buf_dif);
  9674. free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
  9675. }
  9676. }
  9677. module_init(lpfc_init);
  9678. module_exit(lpfc_exit);
  9679. MODULE_LICENSE("GPL");
  9680. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  9681. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  9682. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);