lpfc_init.c 307 KB

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