lpfc_init.c 337 KB

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