lpfc_init.c 263 KB

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