t4_hw.c 222 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/delay.h>
  35. #include "cxgb4.h"
  36. #include "t4_regs.h"
  37. #include "t4_values.h"
  38. #include "t4fw_api.h"
  39. #include "t4fw_version.h"
  40. /**
  41. * t4_wait_op_done_val - wait until an operation is completed
  42. * @adapter: the adapter performing the operation
  43. * @reg: the register to check for completion
  44. * @mask: a single-bit field within @reg that indicates completion
  45. * @polarity: the value of the field when the operation is completed
  46. * @attempts: number of check iterations
  47. * @delay: delay in usecs between iterations
  48. * @valp: where to store the value of the register at completion time
  49. *
  50. * Wait until an operation is completed by checking a bit in a register
  51. * up to @attempts times. If @valp is not NULL the value of the register
  52. * at the time it indicated completion is stored there. Returns 0 if the
  53. * operation completes and -EAGAIN otherwise.
  54. */
  55. static int t4_wait_op_done_val(struct adapter *adapter, int reg, u32 mask,
  56. int polarity, int attempts, int delay, u32 *valp)
  57. {
  58. while (1) {
  59. u32 val = t4_read_reg(adapter, reg);
  60. if (!!(val & mask) == polarity) {
  61. if (valp)
  62. *valp = val;
  63. return 0;
  64. }
  65. if (--attempts == 0)
  66. return -EAGAIN;
  67. if (delay)
  68. udelay(delay);
  69. }
  70. }
  71. static inline int t4_wait_op_done(struct adapter *adapter, int reg, u32 mask,
  72. int polarity, int attempts, int delay)
  73. {
  74. return t4_wait_op_done_val(adapter, reg, mask, polarity, attempts,
  75. delay, NULL);
  76. }
  77. /**
  78. * t4_set_reg_field - set a register field to a value
  79. * @adapter: the adapter to program
  80. * @addr: the register address
  81. * @mask: specifies the portion of the register to modify
  82. * @val: the new value for the register field
  83. *
  84. * Sets a register field specified by the supplied mask to the
  85. * given value.
  86. */
  87. void t4_set_reg_field(struct adapter *adapter, unsigned int addr, u32 mask,
  88. u32 val)
  89. {
  90. u32 v = t4_read_reg(adapter, addr) & ~mask;
  91. t4_write_reg(adapter, addr, v | val);
  92. (void) t4_read_reg(adapter, addr); /* flush */
  93. }
  94. /**
  95. * t4_read_indirect - read indirectly addressed registers
  96. * @adap: the adapter
  97. * @addr_reg: register holding the indirect address
  98. * @data_reg: register holding the value of the indirect register
  99. * @vals: where the read register values are stored
  100. * @nregs: how many indirect registers to read
  101. * @start_idx: index of first indirect register to read
  102. *
  103. * Reads registers that are accessed indirectly through an address/data
  104. * register pair.
  105. */
  106. void t4_read_indirect(struct adapter *adap, unsigned int addr_reg,
  107. unsigned int data_reg, u32 *vals,
  108. unsigned int nregs, unsigned int start_idx)
  109. {
  110. while (nregs--) {
  111. t4_write_reg(adap, addr_reg, start_idx);
  112. *vals++ = t4_read_reg(adap, data_reg);
  113. start_idx++;
  114. }
  115. }
  116. /**
  117. * t4_write_indirect - write indirectly addressed registers
  118. * @adap: the adapter
  119. * @addr_reg: register holding the indirect addresses
  120. * @data_reg: register holding the value for the indirect registers
  121. * @vals: values to write
  122. * @nregs: how many indirect registers to write
  123. * @start_idx: address of first indirect register to write
  124. *
  125. * Writes a sequential block of registers that are accessed indirectly
  126. * through an address/data register pair.
  127. */
  128. void t4_write_indirect(struct adapter *adap, unsigned int addr_reg,
  129. unsigned int data_reg, const u32 *vals,
  130. unsigned int nregs, unsigned int start_idx)
  131. {
  132. while (nregs--) {
  133. t4_write_reg(adap, addr_reg, start_idx++);
  134. t4_write_reg(adap, data_reg, *vals++);
  135. }
  136. }
  137. /*
  138. * Read a 32-bit PCI Configuration Space register via the PCI-E backdoor
  139. * mechanism. This guarantees that we get the real value even if we're
  140. * operating within a Virtual Machine and the Hypervisor is trapping our
  141. * Configuration Space accesses.
  142. */
  143. void t4_hw_pci_read_cfg4(struct adapter *adap, int reg, u32 *val)
  144. {
  145. u32 req = FUNCTION_V(adap->pf) | REGISTER_V(reg);
  146. if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  147. req |= ENABLE_F;
  148. else
  149. req |= T6_ENABLE_F;
  150. if (is_t4(adap->params.chip))
  151. req |= LOCALCFG_F;
  152. t4_write_reg(adap, PCIE_CFG_SPACE_REQ_A, req);
  153. *val = t4_read_reg(adap, PCIE_CFG_SPACE_DATA_A);
  154. /* Reset ENABLE to 0 so reads of PCIE_CFG_SPACE_DATA won't cause a
  155. * Configuration Space read. (None of the other fields matter when
  156. * ENABLE is 0 so a simple register write is easier than a
  157. * read-modify-write via t4_set_reg_field().)
  158. */
  159. t4_write_reg(adap, PCIE_CFG_SPACE_REQ_A, 0);
  160. }
  161. /*
  162. * t4_report_fw_error - report firmware error
  163. * @adap: the adapter
  164. *
  165. * The adapter firmware can indicate error conditions to the host.
  166. * If the firmware has indicated an error, print out the reason for
  167. * the firmware error.
  168. */
  169. static void t4_report_fw_error(struct adapter *adap)
  170. {
  171. static const char *const reason[] = {
  172. "Crash", /* PCIE_FW_EVAL_CRASH */
  173. "During Device Preparation", /* PCIE_FW_EVAL_PREP */
  174. "During Device Configuration", /* PCIE_FW_EVAL_CONF */
  175. "During Device Initialization", /* PCIE_FW_EVAL_INIT */
  176. "Unexpected Event", /* PCIE_FW_EVAL_UNEXPECTEDEVENT */
  177. "Insufficient Airflow", /* PCIE_FW_EVAL_OVERHEAT */
  178. "Device Shutdown", /* PCIE_FW_EVAL_DEVICESHUTDOWN */
  179. "Reserved", /* reserved */
  180. };
  181. u32 pcie_fw;
  182. pcie_fw = t4_read_reg(adap, PCIE_FW_A);
  183. if (pcie_fw & PCIE_FW_ERR_F)
  184. dev_err(adap->pdev_dev, "Firmware reports adapter error: %s\n",
  185. reason[PCIE_FW_EVAL_G(pcie_fw)]);
  186. }
  187. /*
  188. * Get the reply to a mailbox command and store it in @rpl in big-endian order.
  189. */
  190. static void get_mbox_rpl(struct adapter *adap, __be64 *rpl, int nflit,
  191. u32 mbox_addr)
  192. {
  193. for ( ; nflit; nflit--, mbox_addr += 8)
  194. *rpl++ = cpu_to_be64(t4_read_reg64(adap, mbox_addr));
  195. }
  196. /*
  197. * Handle a FW assertion reported in a mailbox.
  198. */
  199. static void fw_asrt(struct adapter *adap, u32 mbox_addr)
  200. {
  201. struct fw_debug_cmd asrt;
  202. get_mbox_rpl(adap, (__be64 *)&asrt, sizeof(asrt) / 8, mbox_addr);
  203. dev_alert(adap->pdev_dev,
  204. "FW assertion at %.16s:%u, val0 %#x, val1 %#x\n",
  205. asrt.u.assert.filename_0_7, be32_to_cpu(asrt.u.assert.line),
  206. be32_to_cpu(asrt.u.assert.x), be32_to_cpu(asrt.u.assert.y));
  207. }
  208. static void dump_mbox(struct adapter *adap, int mbox, u32 data_reg)
  209. {
  210. dev_err(adap->pdev_dev,
  211. "mbox %d: %llx %llx %llx %llx %llx %llx %llx %llx\n", mbox,
  212. (unsigned long long)t4_read_reg64(adap, data_reg),
  213. (unsigned long long)t4_read_reg64(adap, data_reg + 8),
  214. (unsigned long long)t4_read_reg64(adap, data_reg + 16),
  215. (unsigned long long)t4_read_reg64(adap, data_reg + 24),
  216. (unsigned long long)t4_read_reg64(adap, data_reg + 32),
  217. (unsigned long long)t4_read_reg64(adap, data_reg + 40),
  218. (unsigned long long)t4_read_reg64(adap, data_reg + 48),
  219. (unsigned long long)t4_read_reg64(adap, data_reg + 56));
  220. }
  221. /**
  222. * t4_wr_mbox_meat_timeout - send a command to FW through the given mailbox
  223. * @adap: the adapter
  224. * @mbox: index of the mailbox to use
  225. * @cmd: the command to write
  226. * @size: command length in bytes
  227. * @rpl: where to optionally store the reply
  228. * @sleep_ok: if true we may sleep while awaiting command completion
  229. * @timeout: time to wait for command to finish before timing out
  230. *
  231. * Sends the given command to FW through the selected mailbox and waits
  232. * for the FW to execute the command. If @rpl is not %NULL it is used to
  233. * store the FW's reply to the command. The command and its optional
  234. * reply are of the same length. FW can take up to %FW_CMD_MAX_TIMEOUT ms
  235. * to respond. @sleep_ok determines whether we may sleep while awaiting
  236. * the response. If sleeping is allowed we use progressive backoff
  237. * otherwise we spin.
  238. *
  239. * The return value is 0 on success or a negative errno on failure. A
  240. * failure can happen either because we are not able to execute the
  241. * command or FW executes it but signals an error. In the latter case
  242. * the return value is the error code indicated by FW (negated).
  243. */
  244. int t4_wr_mbox_meat_timeout(struct adapter *adap, int mbox, const void *cmd,
  245. int size, void *rpl, bool sleep_ok, int timeout)
  246. {
  247. static const int delay[] = {
  248. 1, 1, 3, 5, 10, 10, 20, 50, 100, 200
  249. };
  250. u32 v;
  251. u64 res;
  252. int i, ms, delay_idx;
  253. const __be64 *p = cmd;
  254. u32 data_reg = PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
  255. u32 ctl_reg = PF_REG(mbox, CIM_PF_MAILBOX_CTRL_A);
  256. if ((size & 15) || size > MBOX_LEN)
  257. return -EINVAL;
  258. /*
  259. * If the device is off-line, as in EEH, commands will time out.
  260. * Fail them early so we don't waste time waiting.
  261. */
  262. if (adap->pdev->error_state != pci_channel_io_normal)
  263. return -EIO;
  264. v = MBOWNER_G(t4_read_reg(adap, ctl_reg));
  265. for (i = 0; v == MBOX_OWNER_NONE && i < 3; i++)
  266. v = MBOWNER_G(t4_read_reg(adap, ctl_reg));
  267. if (v != MBOX_OWNER_DRV)
  268. return v ? -EBUSY : -ETIMEDOUT;
  269. for (i = 0; i < size; i += 8)
  270. t4_write_reg64(adap, data_reg + i, be64_to_cpu(*p++));
  271. t4_write_reg(adap, ctl_reg, MBMSGVALID_F | MBOWNER_V(MBOX_OWNER_FW));
  272. t4_read_reg(adap, ctl_reg); /* flush write */
  273. delay_idx = 0;
  274. ms = delay[0];
  275. for (i = 0; i < timeout; i += ms) {
  276. if (sleep_ok) {
  277. ms = delay[delay_idx]; /* last element may repeat */
  278. if (delay_idx < ARRAY_SIZE(delay) - 1)
  279. delay_idx++;
  280. msleep(ms);
  281. } else
  282. mdelay(ms);
  283. v = t4_read_reg(adap, ctl_reg);
  284. if (MBOWNER_G(v) == MBOX_OWNER_DRV) {
  285. if (!(v & MBMSGVALID_F)) {
  286. t4_write_reg(adap, ctl_reg, 0);
  287. continue;
  288. }
  289. res = t4_read_reg64(adap, data_reg);
  290. if (FW_CMD_OP_G(res >> 32) == FW_DEBUG_CMD) {
  291. fw_asrt(adap, data_reg);
  292. res = FW_CMD_RETVAL_V(EIO);
  293. } else if (rpl) {
  294. get_mbox_rpl(adap, rpl, size / 8, data_reg);
  295. }
  296. if (FW_CMD_RETVAL_G((int)res))
  297. dump_mbox(adap, mbox, data_reg);
  298. t4_write_reg(adap, ctl_reg, 0);
  299. return -FW_CMD_RETVAL_G((int)res);
  300. }
  301. }
  302. dump_mbox(adap, mbox, data_reg);
  303. dev_err(adap->pdev_dev, "command %#x in mailbox %d timed out\n",
  304. *(const u8 *)cmd, mbox);
  305. t4_report_fw_error(adap);
  306. return -ETIMEDOUT;
  307. }
  308. int t4_wr_mbox_meat(struct adapter *adap, int mbox, const void *cmd, int size,
  309. void *rpl, bool sleep_ok)
  310. {
  311. return t4_wr_mbox_meat_timeout(adap, mbox, cmd, size, rpl, sleep_ok,
  312. FW_CMD_MAX_TIMEOUT);
  313. }
  314. static int t4_edc_err_read(struct adapter *adap, int idx)
  315. {
  316. u32 edc_ecc_err_addr_reg;
  317. u32 rdata_reg;
  318. if (is_t4(adap->params.chip)) {
  319. CH_WARN(adap, "%s: T4 NOT supported.\n", __func__);
  320. return 0;
  321. }
  322. if (idx != 0 && idx != 1) {
  323. CH_WARN(adap, "%s: idx %d NOT supported.\n", __func__, idx);
  324. return 0;
  325. }
  326. edc_ecc_err_addr_reg = EDC_T5_REG(EDC_H_ECC_ERR_ADDR_A, idx);
  327. rdata_reg = EDC_T5_REG(EDC_H_BIST_STATUS_RDATA_A, idx);
  328. CH_WARN(adap,
  329. "edc%d err addr 0x%x: 0x%x.\n",
  330. idx, edc_ecc_err_addr_reg,
  331. t4_read_reg(adap, edc_ecc_err_addr_reg));
  332. CH_WARN(adap,
  333. "bist: 0x%x, status %llx %llx %llx %llx %llx %llx %llx %llx %llx.\n",
  334. rdata_reg,
  335. (unsigned long long)t4_read_reg64(adap, rdata_reg),
  336. (unsigned long long)t4_read_reg64(adap, rdata_reg + 8),
  337. (unsigned long long)t4_read_reg64(adap, rdata_reg + 16),
  338. (unsigned long long)t4_read_reg64(adap, rdata_reg + 24),
  339. (unsigned long long)t4_read_reg64(adap, rdata_reg + 32),
  340. (unsigned long long)t4_read_reg64(adap, rdata_reg + 40),
  341. (unsigned long long)t4_read_reg64(adap, rdata_reg + 48),
  342. (unsigned long long)t4_read_reg64(adap, rdata_reg + 56),
  343. (unsigned long long)t4_read_reg64(adap, rdata_reg + 64));
  344. return 0;
  345. }
  346. /**
  347. * t4_memory_rw - read/write EDC 0, EDC 1 or MC via PCIE memory window
  348. * @adap: the adapter
  349. * @win: PCI-E Memory Window to use
  350. * @mtype: memory type: MEM_EDC0, MEM_EDC1 or MEM_MC
  351. * @addr: address within indicated memory type
  352. * @len: amount of memory to transfer
  353. * @hbuf: host memory buffer
  354. * @dir: direction of transfer T4_MEMORY_READ (1) or T4_MEMORY_WRITE (0)
  355. *
  356. * Reads/writes an [almost] arbitrary memory region in the firmware: the
  357. * firmware memory address and host buffer must be aligned on 32-bit
  358. * boudaries; the length may be arbitrary. The memory is transferred as
  359. * a raw byte sequence from/to the firmware's memory. If this memory
  360. * contains data structures which contain multi-byte integers, it's the
  361. * caller's responsibility to perform appropriate byte order conversions.
  362. */
  363. int t4_memory_rw(struct adapter *adap, int win, int mtype, u32 addr,
  364. u32 len, void *hbuf, int dir)
  365. {
  366. u32 pos, offset, resid, memoffset;
  367. u32 edc_size, mc_size, win_pf, mem_reg, mem_aperture, mem_base;
  368. u32 *buf;
  369. /* Argument sanity checks ...
  370. */
  371. if (addr & 0x3 || (uintptr_t)hbuf & 0x3)
  372. return -EINVAL;
  373. buf = (u32 *)hbuf;
  374. /* It's convenient to be able to handle lengths which aren't a
  375. * multiple of 32-bits because we often end up transferring files to
  376. * the firmware. So we'll handle that by normalizing the length here
  377. * and then handling any residual transfer at the end.
  378. */
  379. resid = len & 0x3;
  380. len -= resid;
  381. /* Offset into the region of memory which is being accessed
  382. * MEM_EDC0 = 0
  383. * MEM_EDC1 = 1
  384. * MEM_MC = 2 -- MEM_MC for chips with only 1 memory controller
  385. * MEM_MC1 = 3 -- for chips with 2 memory controllers (e.g. T5)
  386. */
  387. edc_size = EDRAM0_SIZE_G(t4_read_reg(adap, MA_EDRAM0_BAR_A));
  388. if (mtype != MEM_MC1)
  389. memoffset = (mtype * (edc_size * 1024 * 1024));
  390. else {
  391. mc_size = EXT_MEM0_SIZE_G(t4_read_reg(adap,
  392. MA_EXT_MEMORY0_BAR_A));
  393. memoffset = (MEM_MC0 * edc_size + mc_size) * 1024 * 1024;
  394. }
  395. /* Determine the PCIE_MEM_ACCESS_OFFSET */
  396. addr = addr + memoffset;
  397. /* Each PCI-E Memory Window is programmed with a window size -- or
  398. * "aperture" -- which controls the granularity of its mapping onto
  399. * adapter memory. We need to grab that aperture in order to know
  400. * how to use the specified window. The window is also programmed
  401. * with the base address of the Memory Window in BAR0's address
  402. * space. For T4 this is an absolute PCI-E Bus Address. For T5
  403. * the address is relative to BAR0.
  404. */
  405. mem_reg = t4_read_reg(adap,
  406. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A,
  407. win));
  408. mem_aperture = 1 << (WINDOW_G(mem_reg) + WINDOW_SHIFT_X);
  409. mem_base = PCIEOFST_G(mem_reg) << PCIEOFST_SHIFT_X;
  410. if (is_t4(adap->params.chip))
  411. mem_base -= adap->t4_bar0;
  412. win_pf = is_t4(adap->params.chip) ? 0 : PFNUM_V(adap->pf);
  413. /* Calculate our initial PCI-E Memory Window Position and Offset into
  414. * that Window.
  415. */
  416. pos = addr & ~(mem_aperture-1);
  417. offset = addr - pos;
  418. /* Set up initial PCI-E Memory Window to cover the start of our
  419. * transfer. (Read it back to ensure that changes propagate before we
  420. * attempt to use the new value.)
  421. */
  422. t4_write_reg(adap,
  423. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win),
  424. pos | win_pf);
  425. t4_read_reg(adap,
  426. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win));
  427. /* Transfer data to/from the adapter as long as there's an integral
  428. * number of 32-bit transfers to complete.
  429. *
  430. * A note on Endianness issues:
  431. *
  432. * The "register" reads and writes below from/to the PCI-E Memory
  433. * Window invoke the standard adapter Big-Endian to PCI-E Link
  434. * Little-Endian "swizzel." As a result, if we have the following
  435. * data in adapter memory:
  436. *
  437. * Memory: ... | b0 | b1 | b2 | b3 | ...
  438. * Address: i+0 i+1 i+2 i+3
  439. *
  440. * Then a read of the adapter memory via the PCI-E Memory Window
  441. * will yield:
  442. *
  443. * x = readl(i)
  444. * 31 0
  445. * [ b3 | b2 | b1 | b0 ]
  446. *
  447. * If this value is stored into local memory on a Little-Endian system
  448. * it will show up correctly in local memory as:
  449. *
  450. * ( ..., b0, b1, b2, b3, ... )
  451. *
  452. * But on a Big-Endian system, the store will show up in memory
  453. * incorrectly swizzled as:
  454. *
  455. * ( ..., b3, b2, b1, b0, ... )
  456. *
  457. * So we need to account for this in the reads and writes to the
  458. * PCI-E Memory Window below by undoing the register read/write
  459. * swizzels.
  460. */
  461. while (len > 0) {
  462. if (dir == T4_MEMORY_READ)
  463. *buf++ = le32_to_cpu((__force __le32)t4_read_reg(adap,
  464. mem_base + offset));
  465. else
  466. t4_write_reg(adap, mem_base + offset,
  467. (__force u32)cpu_to_le32(*buf++));
  468. offset += sizeof(__be32);
  469. len -= sizeof(__be32);
  470. /* If we've reached the end of our current window aperture,
  471. * move the PCI-E Memory Window on to the next. Note that
  472. * doing this here after "len" may be 0 allows us to set up
  473. * the PCI-E Memory Window for a possible final residual
  474. * transfer below ...
  475. */
  476. if (offset == mem_aperture) {
  477. pos += mem_aperture;
  478. offset = 0;
  479. t4_write_reg(adap,
  480. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A,
  481. win), pos | win_pf);
  482. t4_read_reg(adap,
  483. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A,
  484. win));
  485. }
  486. }
  487. /* If the original transfer had a length which wasn't a multiple of
  488. * 32-bits, now's where we need to finish off the transfer of the
  489. * residual amount. The PCI-E Memory Window has already been moved
  490. * above (if necessary) to cover this final transfer.
  491. */
  492. if (resid) {
  493. union {
  494. u32 word;
  495. char byte[4];
  496. } last;
  497. unsigned char *bp;
  498. int i;
  499. if (dir == T4_MEMORY_READ) {
  500. last.word = le32_to_cpu(
  501. (__force __le32)t4_read_reg(adap,
  502. mem_base + offset));
  503. for (bp = (unsigned char *)buf, i = resid; i < 4; i++)
  504. bp[i] = last.byte[i];
  505. } else {
  506. last.word = *buf;
  507. for (i = resid; i < 4; i++)
  508. last.byte[i] = 0;
  509. t4_write_reg(adap, mem_base + offset,
  510. (__force u32)cpu_to_le32(last.word));
  511. }
  512. }
  513. return 0;
  514. }
  515. /* Return the specified PCI-E Configuration Space register from our Physical
  516. * Function. We try first via a Firmware LDST Command since we prefer to let
  517. * the firmware own all of these registers, but if that fails we go for it
  518. * directly ourselves.
  519. */
  520. u32 t4_read_pcie_cfg4(struct adapter *adap, int reg)
  521. {
  522. u32 val, ldst_addrspace;
  523. /* If fw_attach != 0, construct and send the Firmware LDST Command to
  524. * retrieve the specified PCI-E Configuration Space register.
  525. */
  526. struct fw_ldst_cmd ldst_cmd;
  527. int ret;
  528. memset(&ldst_cmd, 0, sizeof(ldst_cmd));
  529. ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_FUNC_PCIE);
  530. ldst_cmd.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
  531. FW_CMD_REQUEST_F |
  532. FW_CMD_READ_F |
  533. ldst_addrspace);
  534. ldst_cmd.cycles_to_len16 = cpu_to_be32(FW_LEN16(ldst_cmd));
  535. ldst_cmd.u.pcie.select_naccess = FW_LDST_CMD_NACCESS_V(1);
  536. ldst_cmd.u.pcie.ctrl_to_fn =
  537. (FW_LDST_CMD_LC_F | FW_LDST_CMD_FN_V(adap->pf));
  538. ldst_cmd.u.pcie.r = reg;
  539. /* If the LDST Command succeeds, return the result, otherwise
  540. * fall through to reading it directly ourselves ...
  541. */
  542. ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd, sizeof(ldst_cmd),
  543. &ldst_cmd);
  544. if (ret == 0)
  545. val = be32_to_cpu(ldst_cmd.u.pcie.data[0]);
  546. else
  547. /* Read the desired Configuration Space register via the PCI-E
  548. * Backdoor mechanism.
  549. */
  550. t4_hw_pci_read_cfg4(adap, reg, &val);
  551. return val;
  552. }
  553. /* Get the window based on base passed to it.
  554. * Window aperture is currently unhandled, but there is no use case for it
  555. * right now
  556. */
  557. static u32 t4_get_window(struct adapter *adap, u32 pci_base, u64 pci_mask,
  558. u32 memwin_base)
  559. {
  560. u32 ret;
  561. if (is_t4(adap->params.chip)) {
  562. u32 bar0;
  563. /* Truncation intentional: we only read the bottom 32-bits of
  564. * the 64-bit BAR0/BAR1 ... We use the hardware backdoor
  565. * mechanism to read BAR0 instead of using
  566. * pci_resource_start() because we could be operating from
  567. * within a Virtual Machine which is trapping our accesses to
  568. * our Configuration Space and we need to set up the PCI-E
  569. * Memory Window decoders with the actual addresses which will
  570. * be coming across the PCI-E link.
  571. */
  572. bar0 = t4_read_pcie_cfg4(adap, pci_base);
  573. bar0 &= pci_mask;
  574. adap->t4_bar0 = bar0;
  575. ret = bar0 + memwin_base;
  576. } else {
  577. /* For T5, only relative offset inside the PCIe BAR is passed */
  578. ret = memwin_base;
  579. }
  580. return ret;
  581. }
  582. /* Get the default utility window (win0) used by everyone */
  583. u32 t4_get_util_window(struct adapter *adap)
  584. {
  585. return t4_get_window(adap, PCI_BASE_ADDRESS_0,
  586. PCI_BASE_ADDRESS_MEM_MASK, MEMWIN0_BASE);
  587. }
  588. /* Set up memory window for accessing adapter memory ranges. (Read
  589. * back MA register to ensure that changes propagate before we attempt
  590. * to use the new values.)
  591. */
  592. void t4_setup_memwin(struct adapter *adap, u32 memwin_base, u32 window)
  593. {
  594. t4_write_reg(adap,
  595. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, window),
  596. memwin_base | BIR_V(0) |
  597. WINDOW_V(ilog2(MEMWIN0_APERTURE) - WINDOW_SHIFT_X));
  598. t4_read_reg(adap,
  599. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, window));
  600. }
  601. /**
  602. * t4_get_regs_len - return the size of the chips register set
  603. * @adapter: the adapter
  604. *
  605. * Returns the size of the chip's BAR0 register space.
  606. */
  607. unsigned int t4_get_regs_len(struct adapter *adapter)
  608. {
  609. unsigned int chip_version = CHELSIO_CHIP_VERSION(adapter->params.chip);
  610. switch (chip_version) {
  611. case CHELSIO_T4:
  612. return T4_REGMAP_SIZE;
  613. case CHELSIO_T5:
  614. case CHELSIO_T6:
  615. return T5_REGMAP_SIZE;
  616. }
  617. dev_err(adapter->pdev_dev,
  618. "Unsupported chip version %d\n", chip_version);
  619. return 0;
  620. }
  621. /**
  622. * t4_get_regs - read chip registers into provided buffer
  623. * @adap: the adapter
  624. * @buf: register buffer
  625. * @buf_size: size (in bytes) of register buffer
  626. *
  627. * If the provided register buffer isn't large enough for the chip's
  628. * full register range, the register dump will be truncated to the
  629. * register buffer's size.
  630. */
  631. void t4_get_regs(struct adapter *adap, void *buf, size_t buf_size)
  632. {
  633. static const unsigned int t4_reg_ranges[] = {
  634. 0x1008, 0x1108,
  635. 0x1180, 0x1184,
  636. 0x1190, 0x1194,
  637. 0x11a0, 0x11a4,
  638. 0x11b0, 0x11b4,
  639. 0x11fc, 0x123c,
  640. 0x1300, 0x173c,
  641. 0x1800, 0x18fc,
  642. 0x3000, 0x30d8,
  643. 0x30e0, 0x30e4,
  644. 0x30ec, 0x5910,
  645. 0x5920, 0x5924,
  646. 0x5960, 0x5960,
  647. 0x5968, 0x5968,
  648. 0x5970, 0x5970,
  649. 0x5978, 0x5978,
  650. 0x5980, 0x5980,
  651. 0x5988, 0x5988,
  652. 0x5990, 0x5990,
  653. 0x5998, 0x5998,
  654. 0x59a0, 0x59d4,
  655. 0x5a00, 0x5ae0,
  656. 0x5ae8, 0x5ae8,
  657. 0x5af0, 0x5af0,
  658. 0x5af8, 0x5af8,
  659. 0x6000, 0x6098,
  660. 0x6100, 0x6150,
  661. 0x6200, 0x6208,
  662. 0x6240, 0x6248,
  663. 0x6280, 0x62b0,
  664. 0x62c0, 0x6338,
  665. 0x6370, 0x638c,
  666. 0x6400, 0x643c,
  667. 0x6500, 0x6524,
  668. 0x6a00, 0x6a04,
  669. 0x6a14, 0x6a38,
  670. 0x6a60, 0x6a70,
  671. 0x6a78, 0x6a78,
  672. 0x6b00, 0x6b0c,
  673. 0x6b1c, 0x6b84,
  674. 0x6bf0, 0x6bf8,
  675. 0x6c00, 0x6c0c,
  676. 0x6c1c, 0x6c84,
  677. 0x6cf0, 0x6cf8,
  678. 0x6d00, 0x6d0c,
  679. 0x6d1c, 0x6d84,
  680. 0x6df0, 0x6df8,
  681. 0x6e00, 0x6e0c,
  682. 0x6e1c, 0x6e84,
  683. 0x6ef0, 0x6ef8,
  684. 0x6f00, 0x6f0c,
  685. 0x6f1c, 0x6f84,
  686. 0x6ff0, 0x6ff8,
  687. 0x7000, 0x700c,
  688. 0x701c, 0x7084,
  689. 0x70f0, 0x70f8,
  690. 0x7100, 0x710c,
  691. 0x711c, 0x7184,
  692. 0x71f0, 0x71f8,
  693. 0x7200, 0x720c,
  694. 0x721c, 0x7284,
  695. 0x72f0, 0x72f8,
  696. 0x7300, 0x730c,
  697. 0x731c, 0x7384,
  698. 0x73f0, 0x73f8,
  699. 0x7400, 0x7450,
  700. 0x7500, 0x7530,
  701. 0x7600, 0x760c,
  702. 0x7614, 0x761c,
  703. 0x7680, 0x76cc,
  704. 0x7700, 0x7798,
  705. 0x77c0, 0x77fc,
  706. 0x7900, 0x79fc,
  707. 0x7b00, 0x7b58,
  708. 0x7b60, 0x7b84,
  709. 0x7b8c, 0x7c38,
  710. 0x7d00, 0x7d38,
  711. 0x7d40, 0x7d80,
  712. 0x7d8c, 0x7ddc,
  713. 0x7de4, 0x7e04,
  714. 0x7e10, 0x7e1c,
  715. 0x7e24, 0x7e38,
  716. 0x7e40, 0x7e44,
  717. 0x7e4c, 0x7e78,
  718. 0x7e80, 0x7ea4,
  719. 0x7eac, 0x7edc,
  720. 0x7ee8, 0x7efc,
  721. 0x8dc0, 0x8e04,
  722. 0x8e10, 0x8e1c,
  723. 0x8e30, 0x8e78,
  724. 0x8ea0, 0x8eb8,
  725. 0x8ec0, 0x8f6c,
  726. 0x8fc0, 0x9008,
  727. 0x9010, 0x9058,
  728. 0x9060, 0x9060,
  729. 0x9068, 0x9074,
  730. 0x90fc, 0x90fc,
  731. 0x9400, 0x9408,
  732. 0x9410, 0x9458,
  733. 0x9600, 0x9600,
  734. 0x9608, 0x9638,
  735. 0x9640, 0x96bc,
  736. 0x9800, 0x9808,
  737. 0x9820, 0x983c,
  738. 0x9850, 0x9864,
  739. 0x9c00, 0x9c6c,
  740. 0x9c80, 0x9cec,
  741. 0x9d00, 0x9d6c,
  742. 0x9d80, 0x9dec,
  743. 0x9e00, 0x9e6c,
  744. 0x9e80, 0x9eec,
  745. 0x9f00, 0x9f6c,
  746. 0x9f80, 0x9fec,
  747. 0xd004, 0xd004,
  748. 0xd010, 0xd03c,
  749. 0xdfc0, 0xdfe0,
  750. 0xe000, 0xea7c,
  751. 0xf000, 0x11190,
  752. 0x19040, 0x1906c,
  753. 0x19078, 0x19080,
  754. 0x1908c, 0x190e4,
  755. 0x190f0, 0x190f8,
  756. 0x19100, 0x19110,
  757. 0x19120, 0x19124,
  758. 0x19150, 0x19194,
  759. 0x1919c, 0x191b0,
  760. 0x191d0, 0x191e8,
  761. 0x19238, 0x1924c,
  762. 0x193f8, 0x1943c,
  763. 0x1944c, 0x19474,
  764. 0x19490, 0x194e0,
  765. 0x194f0, 0x194f8,
  766. 0x19800, 0x19c08,
  767. 0x19c10, 0x19c90,
  768. 0x19ca0, 0x19ce4,
  769. 0x19cf0, 0x19d40,
  770. 0x19d50, 0x19d94,
  771. 0x19da0, 0x19de8,
  772. 0x19df0, 0x19e40,
  773. 0x19e50, 0x19e90,
  774. 0x19ea0, 0x19f4c,
  775. 0x1a000, 0x1a004,
  776. 0x1a010, 0x1a06c,
  777. 0x1a0b0, 0x1a0e4,
  778. 0x1a0ec, 0x1a0f4,
  779. 0x1a100, 0x1a108,
  780. 0x1a114, 0x1a120,
  781. 0x1a128, 0x1a130,
  782. 0x1a138, 0x1a138,
  783. 0x1a190, 0x1a1c4,
  784. 0x1a1fc, 0x1a1fc,
  785. 0x1e040, 0x1e04c,
  786. 0x1e284, 0x1e28c,
  787. 0x1e2c0, 0x1e2c0,
  788. 0x1e2e0, 0x1e2e0,
  789. 0x1e300, 0x1e384,
  790. 0x1e3c0, 0x1e3c8,
  791. 0x1e440, 0x1e44c,
  792. 0x1e684, 0x1e68c,
  793. 0x1e6c0, 0x1e6c0,
  794. 0x1e6e0, 0x1e6e0,
  795. 0x1e700, 0x1e784,
  796. 0x1e7c0, 0x1e7c8,
  797. 0x1e840, 0x1e84c,
  798. 0x1ea84, 0x1ea8c,
  799. 0x1eac0, 0x1eac0,
  800. 0x1eae0, 0x1eae0,
  801. 0x1eb00, 0x1eb84,
  802. 0x1ebc0, 0x1ebc8,
  803. 0x1ec40, 0x1ec4c,
  804. 0x1ee84, 0x1ee8c,
  805. 0x1eec0, 0x1eec0,
  806. 0x1eee0, 0x1eee0,
  807. 0x1ef00, 0x1ef84,
  808. 0x1efc0, 0x1efc8,
  809. 0x1f040, 0x1f04c,
  810. 0x1f284, 0x1f28c,
  811. 0x1f2c0, 0x1f2c0,
  812. 0x1f2e0, 0x1f2e0,
  813. 0x1f300, 0x1f384,
  814. 0x1f3c0, 0x1f3c8,
  815. 0x1f440, 0x1f44c,
  816. 0x1f684, 0x1f68c,
  817. 0x1f6c0, 0x1f6c0,
  818. 0x1f6e0, 0x1f6e0,
  819. 0x1f700, 0x1f784,
  820. 0x1f7c0, 0x1f7c8,
  821. 0x1f840, 0x1f84c,
  822. 0x1fa84, 0x1fa8c,
  823. 0x1fac0, 0x1fac0,
  824. 0x1fae0, 0x1fae0,
  825. 0x1fb00, 0x1fb84,
  826. 0x1fbc0, 0x1fbc8,
  827. 0x1fc40, 0x1fc4c,
  828. 0x1fe84, 0x1fe8c,
  829. 0x1fec0, 0x1fec0,
  830. 0x1fee0, 0x1fee0,
  831. 0x1ff00, 0x1ff84,
  832. 0x1ffc0, 0x1ffc8,
  833. 0x20000, 0x2002c,
  834. 0x20100, 0x2013c,
  835. 0x20190, 0x201a0,
  836. 0x201a8, 0x201b8,
  837. 0x201c4, 0x201c8,
  838. 0x20200, 0x20318,
  839. 0x20400, 0x204b4,
  840. 0x204c0, 0x20528,
  841. 0x20540, 0x20614,
  842. 0x21000, 0x21040,
  843. 0x2104c, 0x21060,
  844. 0x210c0, 0x210ec,
  845. 0x21200, 0x21268,
  846. 0x21270, 0x21284,
  847. 0x212fc, 0x21388,
  848. 0x21400, 0x21404,
  849. 0x21500, 0x21500,
  850. 0x21510, 0x21518,
  851. 0x2152c, 0x21530,
  852. 0x2153c, 0x2153c,
  853. 0x21550, 0x21554,
  854. 0x21600, 0x21600,
  855. 0x21608, 0x2161c,
  856. 0x21624, 0x21628,
  857. 0x21630, 0x21634,
  858. 0x2163c, 0x2163c,
  859. 0x21700, 0x2171c,
  860. 0x21780, 0x2178c,
  861. 0x21800, 0x21818,
  862. 0x21820, 0x21828,
  863. 0x21830, 0x21848,
  864. 0x21850, 0x21854,
  865. 0x21860, 0x21868,
  866. 0x21870, 0x21870,
  867. 0x21878, 0x21898,
  868. 0x218a0, 0x218a8,
  869. 0x218b0, 0x218c8,
  870. 0x218d0, 0x218d4,
  871. 0x218e0, 0x218e8,
  872. 0x218f0, 0x218f0,
  873. 0x218f8, 0x21a18,
  874. 0x21a20, 0x21a28,
  875. 0x21a30, 0x21a48,
  876. 0x21a50, 0x21a54,
  877. 0x21a60, 0x21a68,
  878. 0x21a70, 0x21a70,
  879. 0x21a78, 0x21a98,
  880. 0x21aa0, 0x21aa8,
  881. 0x21ab0, 0x21ac8,
  882. 0x21ad0, 0x21ad4,
  883. 0x21ae0, 0x21ae8,
  884. 0x21af0, 0x21af0,
  885. 0x21af8, 0x21c18,
  886. 0x21c20, 0x21c20,
  887. 0x21c28, 0x21c30,
  888. 0x21c38, 0x21c38,
  889. 0x21c80, 0x21c98,
  890. 0x21ca0, 0x21ca8,
  891. 0x21cb0, 0x21cc8,
  892. 0x21cd0, 0x21cd4,
  893. 0x21ce0, 0x21ce8,
  894. 0x21cf0, 0x21cf0,
  895. 0x21cf8, 0x21d7c,
  896. 0x21e00, 0x21e04,
  897. 0x22000, 0x2202c,
  898. 0x22100, 0x2213c,
  899. 0x22190, 0x221a0,
  900. 0x221a8, 0x221b8,
  901. 0x221c4, 0x221c8,
  902. 0x22200, 0x22318,
  903. 0x22400, 0x224b4,
  904. 0x224c0, 0x22528,
  905. 0x22540, 0x22614,
  906. 0x23000, 0x23040,
  907. 0x2304c, 0x23060,
  908. 0x230c0, 0x230ec,
  909. 0x23200, 0x23268,
  910. 0x23270, 0x23284,
  911. 0x232fc, 0x23388,
  912. 0x23400, 0x23404,
  913. 0x23500, 0x23500,
  914. 0x23510, 0x23518,
  915. 0x2352c, 0x23530,
  916. 0x2353c, 0x2353c,
  917. 0x23550, 0x23554,
  918. 0x23600, 0x23600,
  919. 0x23608, 0x2361c,
  920. 0x23624, 0x23628,
  921. 0x23630, 0x23634,
  922. 0x2363c, 0x2363c,
  923. 0x23700, 0x2371c,
  924. 0x23780, 0x2378c,
  925. 0x23800, 0x23818,
  926. 0x23820, 0x23828,
  927. 0x23830, 0x23848,
  928. 0x23850, 0x23854,
  929. 0x23860, 0x23868,
  930. 0x23870, 0x23870,
  931. 0x23878, 0x23898,
  932. 0x238a0, 0x238a8,
  933. 0x238b0, 0x238c8,
  934. 0x238d0, 0x238d4,
  935. 0x238e0, 0x238e8,
  936. 0x238f0, 0x238f0,
  937. 0x238f8, 0x23a18,
  938. 0x23a20, 0x23a28,
  939. 0x23a30, 0x23a48,
  940. 0x23a50, 0x23a54,
  941. 0x23a60, 0x23a68,
  942. 0x23a70, 0x23a70,
  943. 0x23a78, 0x23a98,
  944. 0x23aa0, 0x23aa8,
  945. 0x23ab0, 0x23ac8,
  946. 0x23ad0, 0x23ad4,
  947. 0x23ae0, 0x23ae8,
  948. 0x23af0, 0x23af0,
  949. 0x23af8, 0x23c18,
  950. 0x23c20, 0x23c20,
  951. 0x23c28, 0x23c30,
  952. 0x23c38, 0x23c38,
  953. 0x23c80, 0x23c98,
  954. 0x23ca0, 0x23ca8,
  955. 0x23cb0, 0x23cc8,
  956. 0x23cd0, 0x23cd4,
  957. 0x23ce0, 0x23ce8,
  958. 0x23cf0, 0x23cf0,
  959. 0x23cf8, 0x23d7c,
  960. 0x23e00, 0x23e04,
  961. 0x24000, 0x2402c,
  962. 0x24100, 0x2413c,
  963. 0x24190, 0x241a0,
  964. 0x241a8, 0x241b8,
  965. 0x241c4, 0x241c8,
  966. 0x24200, 0x24318,
  967. 0x24400, 0x244b4,
  968. 0x244c0, 0x24528,
  969. 0x24540, 0x24614,
  970. 0x25000, 0x25040,
  971. 0x2504c, 0x25060,
  972. 0x250c0, 0x250ec,
  973. 0x25200, 0x25268,
  974. 0x25270, 0x25284,
  975. 0x252fc, 0x25388,
  976. 0x25400, 0x25404,
  977. 0x25500, 0x25500,
  978. 0x25510, 0x25518,
  979. 0x2552c, 0x25530,
  980. 0x2553c, 0x2553c,
  981. 0x25550, 0x25554,
  982. 0x25600, 0x25600,
  983. 0x25608, 0x2561c,
  984. 0x25624, 0x25628,
  985. 0x25630, 0x25634,
  986. 0x2563c, 0x2563c,
  987. 0x25700, 0x2571c,
  988. 0x25780, 0x2578c,
  989. 0x25800, 0x25818,
  990. 0x25820, 0x25828,
  991. 0x25830, 0x25848,
  992. 0x25850, 0x25854,
  993. 0x25860, 0x25868,
  994. 0x25870, 0x25870,
  995. 0x25878, 0x25898,
  996. 0x258a0, 0x258a8,
  997. 0x258b0, 0x258c8,
  998. 0x258d0, 0x258d4,
  999. 0x258e0, 0x258e8,
  1000. 0x258f0, 0x258f0,
  1001. 0x258f8, 0x25a18,
  1002. 0x25a20, 0x25a28,
  1003. 0x25a30, 0x25a48,
  1004. 0x25a50, 0x25a54,
  1005. 0x25a60, 0x25a68,
  1006. 0x25a70, 0x25a70,
  1007. 0x25a78, 0x25a98,
  1008. 0x25aa0, 0x25aa8,
  1009. 0x25ab0, 0x25ac8,
  1010. 0x25ad0, 0x25ad4,
  1011. 0x25ae0, 0x25ae8,
  1012. 0x25af0, 0x25af0,
  1013. 0x25af8, 0x25c18,
  1014. 0x25c20, 0x25c20,
  1015. 0x25c28, 0x25c30,
  1016. 0x25c38, 0x25c38,
  1017. 0x25c80, 0x25c98,
  1018. 0x25ca0, 0x25ca8,
  1019. 0x25cb0, 0x25cc8,
  1020. 0x25cd0, 0x25cd4,
  1021. 0x25ce0, 0x25ce8,
  1022. 0x25cf0, 0x25cf0,
  1023. 0x25cf8, 0x25d7c,
  1024. 0x25e00, 0x25e04,
  1025. 0x26000, 0x2602c,
  1026. 0x26100, 0x2613c,
  1027. 0x26190, 0x261a0,
  1028. 0x261a8, 0x261b8,
  1029. 0x261c4, 0x261c8,
  1030. 0x26200, 0x26318,
  1031. 0x26400, 0x264b4,
  1032. 0x264c0, 0x26528,
  1033. 0x26540, 0x26614,
  1034. 0x27000, 0x27040,
  1035. 0x2704c, 0x27060,
  1036. 0x270c0, 0x270ec,
  1037. 0x27200, 0x27268,
  1038. 0x27270, 0x27284,
  1039. 0x272fc, 0x27388,
  1040. 0x27400, 0x27404,
  1041. 0x27500, 0x27500,
  1042. 0x27510, 0x27518,
  1043. 0x2752c, 0x27530,
  1044. 0x2753c, 0x2753c,
  1045. 0x27550, 0x27554,
  1046. 0x27600, 0x27600,
  1047. 0x27608, 0x2761c,
  1048. 0x27624, 0x27628,
  1049. 0x27630, 0x27634,
  1050. 0x2763c, 0x2763c,
  1051. 0x27700, 0x2771c,
  1052. 0x27780, 0x2778c,
  1053. 0x27800, 0x27818,
  1054. 0x27820, 0x27828,
  1055. 0x27830, 0x27848,
  1056. 0x27850, 0x27854,
  1057. 0x27860, 0x27868,
  1058. 0x27870, 0x27870,
  1059. 0x27878, 0x27898,
  1060. 0x278a0, 0x278a8,
  1061. 0x278b0, 0x278c8,
  1062. 0x278d0, 0x278d4,
  1063. 0x278e0, 0x278e8,
  1064. 0x278f0, 0x278f0,
  1065. 0x278f8, 0x27a18,
  1066. 0x27a20, 0x27a28,
  1067. 0x27a30, 0x27a48,
  1068. 0x27a50, 0x27a54,
  1069. 0x27a60, 0x27a68,
  1070. 0x27a70, 0x27a70,
  1071. 0x27a78, 0x27a98,
  1072. 0x27aa0, 0x27aa8,
  1073. 0x27ab0, 0x27ac8,
  1074. 0x27ad0, 0x27ad4,
  1075. 0x27ae0, 0x27ae8,
  1076. 0x27af0, 0x27af0,
  1077. 0x27af8, 0x27c18,
  1078. 0x27c20, 0x27c20,
  1079. 0x27c28, 0x27c30,
  1080. 0x27c38, 0x27c38,
  1081. 0x27c80, 0x27c98,
  1082. 0x27ca0, 0x27ca8,
  1083. 0x27cb0, 0x27cc8,
  1084. 0x27cd0, 0x27cd4,
  1085. 0x27ce0, 0x27ce8,
  1086. 0x27cf0, 0x27cf0,
  1087. 0x27cf8, 0x27d7c,
  1088. 0x27e00, 0x27e04,
  1089. };
  1090. static const unsigned int t5_reg_ranges[] = {
  1091. 0x1008, 0x10c0,
  1092. 0x10cc, 0x10f8,
  1093. 0x1100, 0x1100,
  1094. 0x110c, 0x1148,
  1095. 0x1180, 0x1184,
  1096. 0x1190, 0x1194,
  1097. 0x11a0, 0x11a4,
  1098. 0x11b0, 0x11b4,
  1099. 0x11fc, 0x123c,
  1100. 0x1280, 0x173c,
  1101. 0x1800, 0x18fc,
  1102. 0x3000, 0x3028,
  1103. 0x3060, 0x30b0,
  1104. 0x30b8, 0x30d8,
  1105. 0x30e0, 0x30fc,
  1106. 0x3140, 0x357c,
  1107. 0x35a8, 0x35cc,
  1108. 0x35ec, 0x35ec,
  1109. 0x3600, 0x5624,
  1110. 0x56cc, 0x56ec,
  1111. 0x56f4, 0x5720,
  1112. 0x5728, 0x575c,
  1113. 0x580c, 0x5814,
  1114. 0x5890, 0x589c,
  1115. 0x58a4, 0x58ac,
  1116. 0x58b8, 0x58bc,
  1117. 0x5940, 0x59c8,
  1118. 0x59d0, 0x59dc,
  1119. 0x59fc, 0x5a18,
  1120. 0x5a60, 0x5a70,
  1121. 0x5a80, 0x5a9c,
  1122. 0x5b94, 0x5bfc,
  1123. 0x6000, 0x6020,
  1124. 0x6028, 0x6040,
  1125. 0x6058, 0x609c,
  1126. 0x60a8, 0x614c,
  1127. 0x7700, 0x7798,
  1128. 0x77c0, 0x78fc,
  1129. 0x7b00, 0x7b58,
  1130. 0x7b60, 0x7b84,
  1131. 0x7b8c, 0x7c54,
  1132. 0x7d00, 0x7d38,
  1133. 0x7d40, 0x7d80,
  1134. 0x7d8c, 0x7ddc,
  1135. 0x7de4, 0x7e04,
  1136. 0x7e10, 0x7e1c,
  1137. 0x7e24, 0x7e38,
  1138. 0x7e40, 0x7e44,
  1139. 0x7e4c, 0x7e78,
  1140. 0x7e80, 0x7edc,
  1141. 0x7ee8, 0x7efc,
  1142. 0x8dc0, 0x8de0,
  1143. 0x8df8, 0x8e04,
  1144. 0x8e10, 0x8e84,
  1145. 0x8ea0, 0x8f84,
  1146. 0x8fc0, 0x9058,
  1147. 0x9060, 0x9060,
  1148. 0x9068, 0x90f8,
  1149. 0x9400, 0x9408,
  1150. 0x9410, 0x9470,
  1151. 0x9600, 0x9600,
  1152. 0x9608, 0x9638,
  1153. 0x9640, 0x96f4,
  1154. 0x9800, 0x9808,
  1155. 0x9820, 0x983c,
  1156. 0x9850, 0x9864,
  1157. 0x9c00, 0x9c6c,
  1158. 0x9c80, 0x9cec,
  1159. 0x9d00, 0x9d6c,
  1160. 0x9d80, 0x9dec,
  1161. 0x9e00, 0x9e6c,
  1162. 0x9e80, 0x9eec,
  1163. 0x9f00, 0x9f6c,
  1164. 0x9f80, 0xa020,
  1165. 0xd004, 0xd004,
  1166. 0xd010, 0xd03c,
  1167. 0xdfc0, 0xdfe0,
  1168. 0xe000, 0x1106c,
  1169. 0x11074, 0x11088,
  1170. 0x1109c, 0x1117c,
  1171. 0x11190, 0x11204,
  1172. 0x19040, 0x1906c,
  1173. 0x19078, 0x19080,
  1174. 0x1908c, 0x190e8,
  1175. 0x190f0, 0x190f8,
  1176. 0x19100, 0x19110,
  1177. 0x19120, 0x19124,
  1178. 0x19150, 0x19194,
  1179. 0x1919c, 0x191b0,
  1180. 0x191d0, 0x191e8,
  1181. 0x19238, 0x19290,
  1182. 0x193f8, 0x19428,
  1183. 0x19430, 0x19444,
  1184. 0x1944c, 0x1946c,
  1185. 0x19474, 0x19474,
  1186. 0x19490, 0x194cc,
  1187. 0x194f0, 0x194f8,
  1188. 0x19c00, 0x19c08,
  1189. 0x19c10, 0x19c60,
  1190. 0x19c94, 0x19ce4,
  1191. 0x19cf0, 0x19d40,
  1192. 0x19d50, 0x19d94,
  1193. 0x19da0, 0x19de8,
  1194. 0x19df0, 0x19e10,
  1195. 0x19e50, 0x19e90,
  1196. 0x19ea0, 0x19f24,
  1197. 0x19f34, 0x19f34,
  1198. 0x19f40, 0x19f50,
  1199. 0x19f90, 0x19fb4,
  1200. 0x19fc4, 0x19fe4,
  1201. 0x1a000, 0x1a004,
  1202. 0x1a010, 0x1a06c,
  1203. 0x1a0b0, 0x1a0e4,
  1204. 0x1a0ec, 0x1a0f8,
  1205. 0x1a100, 0x1a108,
  1206. 0x1a114, 0x1a120,
  1207. 0x1a128, 0x1a130,
  1208. 0x1a138, 0x1a138,
  1209. 0x1a190, 0x1a1c4,
  1210. 0x1a1fc, 0x1a1fc,
  1211. 0x1e008, 0x1e00c,
  1212. 0x1e040, 0x1e044,
  1213. 0x1e04c, 0x1e04c,
  1214. 0x1e284, 0x1e290,
  1215. 0x1e2c0, 0x1e2c0,
  1216. 0x1e2e0, 0x1e2e0,
  1217. 0x1e300, 0x1e384,
  1218. 0x1e3c0, 0x1e3c8,
  1219. 0x1e408, 0x1e40c,
  1220. 0x1e440, 0x1e444,
  1221. 0x1e44c, 0x1e44c,
  1222. 0x1e684, 0x1e690,
  1223. 0x1e6c0, 0x1e6c0,
  1224. 0x1e6e0, 0x1e6e0,
  1225. 0x1e700, 0x1e784,
  1226. 0x1e7c0, 0x1e7c8,
  1227. 0x1e808, 0x1e80c,
  1228. 0x1e840, 0x1e844,
  1229. 0x1e84c, 0x1e84c,
  1230. 0x1ea84, 0x1ea90,
  1231. 0x1eac0, 0x1eac0,
  1232. 0x1eae0, 0x1eae0,
  1233. 0x1eb00, 0x1eb84,
  1234. 0x1ebc0, 0x1ebc8,
  1235. 0x1ec08, 0x1ec0c,
  1236. 0x1ec40, 0x1ec44,
  1237. 0x1ec4c, 0x1ec4c,
  1238. 0x1ee84, 0x1ee90,
  1239. 0x1eec0, 0x1eec0,
  1240. 0x1eee0, 0x1eee0,
  1241. 0x1ef00, 0x1ef84,
  1242. 0x1efc0, 0x1efc8,
  1243. 0x1f008, 0x1f00c,
  1244. 0x1f040, 0x1f044,
  1245. 0x1f04c, 0x1f04c,
  1246. 0x1f284, 0x1f290,
  1247. 0x1f2c0, 0x1f2c0,
  1248. 0x1f2e0, 0x1f2e0,
  1249. 0x1f300, 0x1f384,
  1250. 0x1f3c0, 0x1f3c8,
  1251. 0x1f408, 0x1f40c,
  1252. 0x1f440, 0x1f444,
  1253. 0x1f44c, 0x1f44c,
  1254. 0x1f684, 0x1f690,
  1255. 0x1f6c0, 0x1f6c0,
  1256. 0x1f6e0, 0x1f6e0,
  1257. 0x1f700, 0x1f784,
  1258. 0x1f7c0, 0x1f7c8,
  1259. 0x1f808, 0x1f80c,
  1260. 0x1f840, 0x1f844,
  1261. 0x1f84c, 0x1f84c,
  1262. 0x1fa84, 0x1fa90,
  1263. 0x1fac0, 0x1fac0,
  1264. 0x1fae0, 0x1fae0,
  1265. 0x1fb00, 0x1fb84,
  1266. 0x1fbc0, 0x1fbc8,
  1267. 0x1fc08, 0x1fc0c,
  1268. 0x1fc40, 0x1fc44,
  1269. 0x1fc4c, 0x1fc4c,
  1270. 0x1fe84, 0x1fe90,
  1271. 0x1fec0, 0x1fec0,
  1272. 0x1fee0, 0x1fee0,
  1273. 0x1ff00, 0x1ff84,
  1274. 0x1ffc0, 0x1ffc8,
  1275. 0x30000, 0x30030,
  1276. 0x30038, 0x30038,
  1277. 0x30040, 0x30040,
  1278. 0x30100, 0x30144,
  1279. 0x30190, 0x301a0,
  1280. 0x301a8, 0x301b8,
  1281. 0x301c4, 0x301c8,
  1282. 0x301d0, 0x301d0,
  1283. 0x30200, 0x30318,
  1284. 0x30400, 0x304b4,
  1285. 0x304c0, 0x3052c,
  1286. 0x30540, 0x3061c,
  1287. 0x30800, 0x30828,
  1288. 0x30834, 0x30834,
  1289. 0x308c0, 0x30908,
  1290. 0x30910, 0x309ac,
  1291. 0x30a00, 0x30a14,
  1292. 0x30a1c, 0x30a2c,
  1293. 0x30a44, 0x30a50,
  1294. 0x30a74, 0x30a74,
  1295. 0x30a7c, 0x30afc,
  1296. 0x30b08, 0x30c24,
  1297. 0x30d00, 0x30d00,
  1298. 0x30d08, 0x30d14,
  1299. 0x30d1c, 0x30d20,
  1300. 0x30d3c, 0x30d3c,
  1301. 0x30d48, 0x30d50,
  1302. 0x31200, 0x3120c,
  1303. 0x31220, 0x31220,
  1304. 0x31240, 0x31240,
  1305. 0x31600, 0x3160c,
  1306. 0x31a00, 0x31a1c,
  1307. 0x31e00, 0x31e20,
  1308. 0x31e38, 0x31e3c,
  1309. 0x31e80, 0x31e80,
  1310. 0x31e88, 0x31ea8,
  1311. 0x31eb0, 0x31eb4,
  1312. 0x31ec8, 0x31ed4,
  1313. 0x31fb8, 0x32004,
  1314. 0x32200, 0x32200,
  1315. 0x32208, 0x32240,
  1316. 0x32248, 0x32280,
  1317. 0x32288, 0x322c0,
  1318. 0x322c8, 0x322fc,
  1319. 0x32600, 0x32630,
  1320. 0x32a00, 0x32abc,
  1321. 0x32b00, 0x32b10,
  1322. 0x32b20, 0x32b30,
  1323. 0x32b40, 0x32b50,
  1324. 0x32b60, 0x32b70,
  1325. 0x33000, 0x33028,
  1326. 0x33030, 0x33048,
  1327. 0x33060, 0x33068,
  1328. 0x33070, 0x3309c,
  1329. 0x330f0, 0x33128,
  1330. 0x33130, 0x33148,
  1331. 0x33160, 0x33168,
  1332. 0x33170, 0x3319c,
  1333. 0x331f0, 0x33238,
  1334. 0x33240, 0x33240,
  1335. 0x33248, 0x33250,
  1336. 0x3325c, 0x33264,
  1337. 0x33270, 0x332b8,
  1338. 0x332c0, 0x332e4,
  1339. 0x332f8, 0x33338,
  1340. 0x33340, 0x33340,
  1341. 0x33348, 0x33350,
  1342. 0x3335c, 0x33364,
  1343. 0x33370, 0x333b8,
  1344. 0x333c0, 0x333e4,
  1345. 0x333f8, 0x33428,
  1346. 0x33430, 0x33448,
  1347. 0x33460, 0x33468,
  1348. 0x33470, 0x3349c,
  1349. 0x334f0, 0x33528,
  1350. 0x33530, 0x33548,
  1351. 0x33560, 0x33568,
  1352. 0x33570, 0x3359c,
  1353. 0x335f0, 0x33638,
  1354. 0x33640, 0x33640,
  1355. 0x33648, 0x33650,
  1356. 0x3365c, 0x33664,
  1357. 0x33670, 0x336b8,
  1358. 0x336c0, 0x336e4,
  1359. 0x336f8, 0x33738,
  1360. 0x33740, 0x33740,
  1361. 0x33748, 0x33750,
  1362. 0x3375c, 0x33764,
  1363. 0x33770, 0x337b8,
  1364. 0x337c0, 0x337e4,
  1365. 0x337f8, 0x337fc,
  1366. 0x33814, 0x33814,
  1367. 0x3382c, 0x3382c,
  1368. 0x33880, 0x3388c,
  1369. 0x338e8, 0x338ec,
  1370. 0x33900, 0x33928,
  1371. 0x33930, 0x33948,
  1372. 0x33960, 0x33968,
  1373. 0x33970, 0x3399c,
  1374. 0x339f0, 0x33a38,
  1375. 0x33a40, 0x33a40,
  1376. 0x33a48, 0x33a50,
  1377. 0x33a5c, 0x33a64,
  1378. 0x33a70, 0x33ab8,
  1379. 0x33ac0, 0x33ae4,
  1380. 0x33af8, 0x33b10,
  1381. 0x33b28, 0x33b28,
  1382. 0x33b3c, 0x33b50,
  1383. 0x33bf0, 0x33c10,
  1384. 0x33c28, 0x33c28,
  1385. 0x33c3c, 0x33c50,
  1386. 0x33cf0, 0x33cfc,
  1387. 0x34000, 0x34030,
  1388. 0x34038, 0x34038,
  1389. 0x34040, 0x34040,
  1390. 0x34100, 0x34144,
  1391. 0x34190, 0x341a0,
  1392. 0x341a8, 0x341b8,
  1393. 0x341c4, 0x341c8,
  1394. 0x341d0, 0x341d0,
  1395. 0x34200, 0x34318,
  1396. 0x34400, 0x344b4,
  1397. 0x344c0, 0x3452c,
  1398. 0x34540, 0x3461c,
  1399. 0x34800, 0x34828,
  1400. 0x34834, 0x34834,
  1401. 0x348c0, 0x34908,
  1402. 0x34910, 0x349ac,
  1403. 0x34a00, 0x34a14,
  1404. 0x34a1c, 0x34a2c,
  1405. 0x34a44, 0x34a50,
  1406. 0x34a74, 0x34a74,
  1407. 0x34a7c, 0x34afc,
  1408. 0x34b08, 0x34c24,
  1409. 0x34d00, 0x34d00,
  1410. 0x34d08, 0x34d14,
  1411. 0x34d1c, 0x34d20,
  1412. 0x34d3c, 0x34d3c,
  1413. 0x34d48, 0x34d50,
  1414. 0x35200, 0x3520c,
  1415. 0x35220, 0x35220,
  1416. 0x35240, 0x35240,
  1417. 0x35600, 0x3560c,
  1418. 0x35a00, 0x35a1c,
  1419. 0x35e00, 0x35e20,
  1420. 0x35e38, 0x35e3c,
  1421. 0x35e80, 0x35e80,
  1422. 0x35e88, 0x35ea8,
  1423. 0x35eb0, 0x35eb4,
  1424. 0x35ec8, 0x35ed4,
  1425. 0x35fb8, 0x36004,
  1426. 0x36200, 0x36200,
  1427. 0x36208, 0x36240,
  1428. 0x36248, 0x36280,
  1429. 0x36288, 0x362c0,
  1430. 0x362c8, 0x362fc,
  1431. 0x36600, 0x36630,
  1432. 0x36a00, 0x36abc,
  1433. 0x36b00, 0x36b10,
  1434. 0x36b20, 0x36b30,
  1435. 0x36b40, 0x36b50,
  1436. 0x36b60, 0x36b70,
  1437. 0x37000, 0x37028,
  1438. 0x37030, 0x37048,
  1439. 0x37060, 0x37068,
  1440. 0x37070, 0x3709c,
  1441. 0x370f0, 0x37128,
  1442. 0x37130, 0x37148,
  1443. 0x37160, 0x37168,
  1444. 0x37170, 0x3719c,
  1445. 0x371f0, 0x37238,
  1446. 0x37240, 0x37240,
  1447. 0x37248, 0x37250,
  1448. 0x3725c, 0x37264,
  1449. 0x37270, 0x372b8,
  1450. 0x372c0, 0x372e4,
  1451. 0x372f8, 0x37338,
  1452. 0x37340, 0x37340,
  1453. 0x37348, 0x37350,
  1454. 0x3735c, 0x37364,
  1455. 0x37370, 0x373b8,
  1456. 0x373c0, 0x373e4,
  1457. 0x373f8, 0x37428,
  1458. 0x37430, 0x37448,
  1459. 0x37460, 0x37468,
  1460. 0x37470, 0x3749c,
  1461. 0x374f0, 0x37528,
  1462. 0x37530, 0x37548,
  1463. 0x37560, 0x37568,
  1464. 0x37570, 0x3759c,
  1465. 0x375f0, 0x37638,
  1466. 0x37640, 0x37640,
  1467. 0x37648, 0x37650,
  1468. 0x3765c, 0x37664,
  1469. 0x37670, 0x376b8,
  1470. 0x376c0, 0x376e4,
  1471. 0x376f8, 0x37738,
  1472. 0x37740, 0x37740,
  1473. 0x37748, 0x37750,
  1474. 0x3775c, 0x37764,
  1475. 0x37770, 0x377b8,
  1476. 0x377c0, 0x377e4,
  1477. 0x377f8, 0x377fc,
  1478. 0x37814, 0x37814,
  1479. 0x3782c, 0x3782c,
  1480. 0x37880, 0x3788c,
  1481. 0x378e8, 0x378ec,
  1482. 0x37900, 0x37928,
  1483. 0x37930, 0x37948,
  1484. 0x37960, 0x37968,
  1485. 0x37970, 0x3799c,
  1486. 0x379f0, 0x37a38,
  1487. 0x37a40, 0x37a40,
  1488. 0x37a48, 0x37a50,
  1489. 0x37a5c, 0x37a64,
  1490. 0x37a70, 0x37ab8,
  1491. 0x37ac0, 0x37ae4,
  1492. 0x37af8, 0x37b10,
  1493. 0x37b28, 0x37b28,
  1494. 0x37b3c, 0x37b50,
  1495. 0x37bf0, 0x37c10,
  1496. 0x37c28, 0x37c28,
  1497. 0x37c3c, 0x37c50,
  1498. 0x37cf0, 0x37cfc,
  1499. 0x38000, 0x38030,
  1500. 0x38038, 0x38038,
  1501. 0x38040, 0x38040,
  1502. 0x38100, 0x38144,
  1503. 0x38190, 0x381a0,
  1504. 0x381a8, 0x381b8,
  1505. 0x381c4, 0x381c8,
  1506. 0x381d0, 0x381d0,
  1507. 0x38200, 0x38318,
  1508. 0x38400, 0x384b4,
  1509. 0x384c0, 0x3852c,
  1510. 0x38540, 0x3861c,
  1511. 0x38800, 0x38828,
  1512. 0x38834, 0x38834,
  1513. 0x388c0, 0x38908,
  1514. 0x38910, 0x389ac,
  1515. 0x38a00, 0x38a14,
  1516. 0x38a1c, 0x38a2c,
  1517. 0x38a44, 0x38a50,
  1518. 0x38a74, 0x38a74,
  1519. 0x38a7c, 0x38afc,
  1520. 0x38b08, 0x38c24,
  1521. 0x38d00, 0x38d00,
  1522. 0x38d08, 0x38d14,
  1523. 0x38d1c, 0x38d20,
  1524. 0x38d3c, 0x38d3c,
  1525. 0x38d48, 0x38d50,
  1526. 0x39200, 0x3920c,
  1527. 0x39220, 0x39220,
  1528. 0x39240, 0x39240,
  1529. 0x39600, 0x3960c,
  1530. 0x39a00, 0x39a1c,
  1531. 0x39e00, 0x39e20,
  1532. 0x39e38, 0x39e3c,
  1533. 0x39e80, 0x39e80,
  1534. 0x39e88, 0x39ea8,
  1535. 0x39eb0, 0x39eb4,
  1536. 0x39ec8, 0x39ed4,
  1537. 0x39fb8, 0x3a004,
  1538. 0x3a200, 0x3a200,
  1539. 0x3a208, 0x3a240,
  1540. 0x3a248, 0x3a280,
  1541. 0x3a288, 0x3a2c0,
  1542. 0x3a2c8, 0x3a2fc,
  1543. 0x3a600, 0x3a630,
  1544. 0x3aa00, 0x3aabc,
  1545. 0x3ab00, 0x3ab10,
  1546. 0x3ab20, 0x3ab30,
  1547. 0x3ab40, 0x3ab50,
  1548. 0x3ab60, 0x3ab70,
  1549. 0x3b000, 0x3b028,
  1550. 0x3b030, 0x3b048,
  1551. 0x3b060, 0x3b068,
  1552. 0x3b070, 0x3b09c,
  1553. 0x3b0f0, 0x3b128,
  1554. 0x3b130, 0x3b148,
  1555. 0x3b160, 0x3b168,
  1556. 0x3b170, 0x3b19c,
  1557. 0x3b1f0, 0x3b238,
  1558. 0x3b240, 0x3b240,
  1559. 0x3b248, 0x3b250,
  1560. 0x3b25c, 0x3b264,
  1561. 0x3b270, 0x3b2b8,
  1562. 0x3b2c0, 0x3b2e4,
  1563. 0x3b2f8, 0x3b338,
  1564. 0x3b340, 0x3b340,
  1565. 0x3b348, 0x3b350,
  1566. 0x3b35c, 0x3b364,
  1567. 0x3b370, 0x3b3b8,
  1568. 0x3b3c0, 0x3b3e4,
  1569. 0x3b3f8, 0x3b428,
  1570. 0x3b430, 0x3b448,
  1571. 0x3b460, 0x3b468,
  1572. 0x3b470, 0x3b49c,
  1573. 0x3b4f0, 0x3b528,
  1574. 0x3b530, 0x3b548,
  1575. 0x3b560, 0x3b568,
  1576. 0x3b570, 0x3b59c,
  1577. 0x3b5f0, 0x3b638,
  1578. 0x3b640, 0x3b640,
  1579. 0x3b648, 0x3b650,
  1580. 0x3b65c, 0x3b664,
  1581. 0x3b670, 0x3b6b8,
  1582. 0x3b6c0, 0x3b6e4,
  1583. 0x3b6f8, 0x3b738,
  1584. 0x3b740, 0x3b740,
  1585. 0x3b748, 0x3b750,
  1586. 0x3b75c, 0x3b764,
  1587. 0x3b770, 0x3b7b8,
  1588. 0x3b7c0, 0x3b7e4,
  1589. 0x3b7f8, 0x3b7fc,
  1590. 0x3b814, 0x3b814,
  1591. 0x3b82c, 0x3b82c,
  1592. 0x3b880, 0x3b88c,
  1593. 0x3b8e8, 0x3b8ec,
  1594. 0x3b900, 0x3b928,
  1595. 0x3b930, 0x3b948,
  1596. 0x3b960, 0x3b968,
  1597. 0x3b970, 0x3b99c,
  1598. 0x3b9f0, 0x3ba38,
  1599. 0x3ba40, 0x3ba40,
  1600. 0x3ba48, 0x3ba50,
  1601. 0x3ba5c, 0x3ba64,
  1602. 0x3ba70, 0x3bab8,
  1603. 0x3bac0, 0x3bae4,
  1604. 0x3baf8, 0x3bb10,
  1605. 0x3bb28, 0x3bb28,
  1606. 0x3bb3c, 0x3bb50,
  1607. 0x3bbf0, 0x3bc10,
  1608. 0x3bc28, 0x3bc28,
  1609. 0x3bc3c, 0x3bc50,
  1610. 0x3bcf0, 0x3bcfc,
  1611. 0x3c000, 0x3c030,
  1612. 0x3c038, 0x3c038,
  1613. 0x3c040, 0x3c040,
  1614. 0x3c100, 0x3c144,
  1615. 0x3c190, 0x3c1a0,
  1616. 0x3c1a8, 0x3c1b8,
  1617. 0x3c1c4, 0x3c1c8,
  1618. 0x3c1d0, 0x3c1d0,
  1619. 0x3c200, 0x3c318,
  1620. 0x3c400, 0x3c4b4,
  1621. 0x3c4c0, 0x3c52c,
  1622. 0x3c540, 0x3c61c,
  1623. 0x3c800, 0x3c828,
  1624. 0x3c834, 0x3c834,
  1625. 0x3c8c0, 0x3c908,
  1626. 0x3c910, 0x3c9ac,
  1627. 0x3ca00, 0x3ca14,
  1628. 0x3ca1c, 0x3ca2c,
  1629. 0x3ca44, 0x3ca50,
  1630. 0x3ca74, 0x3ca74,
  1631. 0x3ca7c, 0x3cafc,
  1632. 0x3cb08, 0x3cc24,
  1633. 0x3cd00, 0x3cd00,
  1634. 0x3cd08, 0x3cd14,
  1635. 0x3cd1c, 0x3cd20,
  1636. 0x3cd3c, 0x3cd3c,
  1637. 0x3cd48, 0x3cd50,
  1638. 0x3d200, 0x3d20c,
  1639. 0x3d220, 0x3d220,
  1640. 0x3d240, 0x3d240,
  1641. 0x3d600, 0x3d60c,
  1642. 0x3da00, 0x3da1c,
  1643. 0x3de00, 0x3de20,
  1644. 0x3de38, 0x3de3c,
  1645. 0x3de80, 0x3de80,
  1646. 0x3de88, 0x3dea8,
  1647. 0x3deb0, 0x3deb4,
  1648. 0x3dec8, 0x3ded4,
  1649. 0x3dfb8, 0x3e004,
  1650. 0x3e200, 0x3e200,
  1651. 0x3e208, 0x3e240,
  1652. 0x3e248, 0x3e280,
  1653. 0x3e288, 0x3e2c0,
  1654. 0x3e2c8, 0x3e2fc,
  1655. 0x3e600, 0x3e630,
  1656. 0x3ea00, 0x3eabc,
  1657. 0x3eb00, 0x3eb10,
  1658. 0x3eb20, 0x3eb30,
  1659. 0x3eb40, 0x3eb50,
  1660. 0x3eb60, 0x3eb70,
  1661. 0x3f000, 0x3f028,
  1662. 0x3f030, 0x3f048,
  1663. 0x3f060, 0x3f068,
  1664. 0x3f070, 0x3f09c,
  1665. 0x3f0f0, 0x3f128,
  1666. 0x3f130, 0x3f148,
  1667. 0x3f160, 0x3f168,
  1668. 0x3f170, 0x3f19c,
  1669. 0x3f1f0, 0x3f238,
  1670. 0x3f240, 0x3f240,
  1671. 0x3f248, 0x3f250,
  1672. 0x3f25c, 0x3f264,
  1673. 0x3f270, 0x3f2b8,
  1674. 0x3f2c0, 0x3f2e4,
  1675. 0x3f2f8, 0x3f338,
  1676. 0x3f340, 0x3f340,
  1677. 0x3f348, 0x3f350,
  1678. 0x3f35c, 0x3f364,
  1679. 0x3f370, 0x3f3b8,
  1680. 0x3f3c0, 0x3f3e4,
  1681. 0x3f3f8, 0x3f428,
  1682. 0x3f430, 0x3f448,
  1683. 0x3f460, 0x3f468,
  1684. 0x3f470, 0x3f49c,
  1685. 0x3f4f0, 0x3f528,
  1686. 0x3f530, 0x3f548,
  1687. 0x3f560, 0x3f568,
  1688. 0x3f570, 0x3f59c,
  1689. 0x3f5f0, 0x3f638,
  1690. 0x3f640, 0x3f640,
  1691. 0x3f648, 0x3f650,
  1692. 0x3f65c, 0x3f664,
  1693. 0x3f670, 0x3f6b8,
  1694. 0x3f6c0, 0x3f6e4,
  1695. 0x3f6f8, 0x3f738,
  1696. 0x3f740, 0x3f740,
  1697. 0x3f748, 0x3f750,
  1698. 0x3f75c, 0x3f764,
  1699. 0x3f770, 0x3f7b8,
  1700. 0x3f7c0, 0x3f7e4,
  1701. 0x3f7f8, 0x3f7fc,
  1702. 0x3f814, 0x3f814,
  1703. 0x3f82c, 0x3f82c,
  1704. 0x3f880, 0x3f88c,
  1705. 0x3f8e8, 0x3f8ec,
  1706. 0x3f900, 0x3f928,
  1707. 0x3f930, 0x3f948,
  1708. 0x3f960, 0x3f968,
  1709. 0x3f970, 0x3f99c,
  1710. 0x3f9f0, 0x3fa38,
  1711. 0x3fa40, 0x3fa40,
  1712. 0x3fa48, 0x3fa50,
  1713. 0x3fa5c, 0x3fa64,
  1714. 0x3fa70, 0x3fab8,
  1715. 0x3fac0, 0x3fae4,
  1716. 0x3faf8, 0x3fb10,
  1717. 0x3fb28, 0x3fb28,
  1718. 0x3fb3c, 0x3fb50,
  1719. 0x3fbf0, 0x3fc10,
  1720. 0x3fc28, 0x3fc28,
  1721. 0x3fc3c, 0x3fc50,
  1722. 0x3fcf0, 0x3fcfc,
  1723. 0x40000, 0x4000c,
  1724. 0x40040, 0x40050,
  1725. 0x40060, 0x40068,
  1726. 0x4007c, 0x4008c,
  1727. 0x40094, 0x400b0,
  1728. 0x400c0, 0x40144,
  1729. 0x40180, 0x4018c,
  1730. 0x40200, 0x40254,
  1731. 0x40260, 0x40264,
  1732. 0x40270, 0x40288,
  1733. 0x40290, 0x40298,
  1734. 0x402ac, 0x402c8,
  1735. 0x402d0, 0x402e0,
  1736. 0x402f0, 0x402f0,
  1737. 0x40300, 0x4033c,
  1738. 0x403f8, 0x403fc,
  1739. 0x41304, 0x413c4,
  1740. 0x41400, 0x4140c,
  1741. 0x41414, 0x4141c,
  1742. 0x41480, 0x414d0,
  1743. 0x44000, 0x44054,
  1744. 0x4405c, 0x44078,
  1745. 0x440c0, 0x44174,
  1746. 0x44180, 0x441ac,
  1747. 0x441b4, 0x441b8,
  1748. 0x441c0, 0x44254,
  1749. 0x4425c, 0x44278,
  1750. 0x442c0, 0x44374,
  1751. 0x44380, 0x443ac,
  1752. 0x443b4, 0x443b8,
  1753. 0x443c0, 0x44454,
  1754. 0x4445c, 0x44478,
  1755. 0x444c0, 0x44574,
  1756. 0x44580, 0x445ac,
  1757. 0x445b4, 0x445b8,
  1758. 0x445c0, 0x44654,
  1759. 0x4465c, 0x44678,
  1760. 0x446c0, 0x44774,
  1761. 0x44780, 0x447ac,
  1762. 0x447b4, 0x447b8,
  1763. 0x447c0, 0x44854,
  1764. 0x4485c, 0x44878,
  1765. 0x448c0, 0x44974,
  1766. 0x44980, 0x449ac,
  1767. 0x449b4, 0x449b8,
  1768. 0x449c0, 0x449fc,
  1769. 0x45000, 0x45004,
  1770. 0x45010, 0x45030,
  1771. 0x45040, 0x45060,
  1772. 0x45068, 0x45068,
  1773. 0x45080, 0x45084,
  1774. 0x450a0, 0x450b0,
  1775. 0x45200, 0x45204,
  1776. 0x45210, 0x45230,
  1777. 0x45240, 0x45260,
  1778. 0x45268, 0x45268,
  1779. 0x45280, 0x45284,
  1780. 0x452a0, 0x452b0,
  1781. 0x460c0, 0x460e4,
  1782. 0x47000, 0x4703c,
  1783. 0x47044, 0x4708c,
  1784. 0x47200, 0x47250,
  1785. 0x47400, 0x47408,
  1786. 0x47414, 0x47420,
  1787. 0x47600, 0x47618,
  1788. 0x47800, 0x47814,
  1789. 0x48000, 0x4800c,
  1790. 0x48040, 0x48050,
  1791. 0x48060, 0x48068,
  1792. 0x4807c, 0x4808c,
  1793. 0x48094, 0x480b0,
  1794. 0x480c0, 0x48144,
  1795. 0x48180, 0x4818c,
  1796. 0x48200, 0x48254,
  1797. 0x48260, 0x48264,
  1798. 0x48270, 0x48288,
  1799. 0x48290, 0x48298,
  1800. 0x482ac, 0x482c8,
  1801. 0x482d0, 0x482e0,
  1802. 0x482f0, 0x482f0,
  1803. 0x48300, 0x4833c,
  1804. 0x483f8, 0x483fc,
  1805. 0x49304, 0x493c4,
  1806. 0x49400, 0x4940c,
  1807. 0x49414, 0x4941c,
  1808. 0x49480, 0x494d0,
  1809. 0x4c000, 0x4c054,
  1810. 0x4c05c, 0x4c078,
  1811. 0x4c0c0, 0x4c174,
  1812. 0x4c180, 0x4c1ac,
  1813. 0x4c1b4, 0x4c1b8,
  1814. 0x4c1c0, 0x4c254,
  1815. 0x4c25c, 0x4c278,
  1816. 0x4c2c0, 0x4c374,
  1817. 0x4c380, 0x4c3ac,
  1818. 0x4c3b4, 0x4c3b8,
  1819. 0x4c3c0, 0x4c454,
  1820. 0x4c45c, 0x4c478,
  1821. 0x4c4c0, 0x4c574,
  1822. 0x4c580, 0x4c5ac,
  1823. 0x4c5b4, 0x4c5b8,
  1824. 0x4c5c0, 0x4c654,
  1825. 0x4c65c, 0x4c678,
  1826. 0x4c6c0, 0x4c774,
  1827. 0x4c780, 0x4c7ac,
  1828. 0x4c7b4, 0x4c7b8,
  1829. 0x4c7c0, 0x4c854,
  1830. 0x4c85c, 0x4c878,
  1831. 0x4c8c0, 0x4c974,
  1832. 0x4c980, 0x4c9ac,
  1833. 0x4c9b4, 0x4c9b8,
  1834. 0x4c9c0, 0x4c9fc,
  1835. 0x4d000, 0x4d004,
  1836. 0x4d010, 0x4d030,
  1837. 0x4d040, 0x4d060,
  1838. 0x4d068, 0x4d068,
  1839. 0x4d080, 0x4d084,
  1840. 0x4d0a0, 0x4d0b0,
  1841. 0x4d200, 0x4d204,
  1842. 0x4d210, 0x4d230,
  1843. 0x4d240, 0x4d260,
  1844. 0x4d268, 0x4d268,
  1845. 0x4d280, 0x4d284,
  1846. 0x4d2a0, 0x4d2b0,
  1847. 0x4e0c0, 0x4e0e4,
  1848. 0x4f000, 0x4f03c,
  1849. 0x4f044, 0x4f08c,
  1850. 0x4f200, 0x4f250,
  1851. 0x4f400, 0x4f408,
  1852. 0x4f414, 0x4f420,
  1853. 0x4f600, 0x4f618,
  1854. 0x4f800, 0x4f814,
  1855. 0x50000, 0x50084,
  1856. 0x50090, 0x500cc,
  1857. 0x50400, 0x50400,
  1858. 0x50800, 0x50884,
  1859. 0x50890, 0x508cc,
  1860. 0x50c00, 0x50c00,
  1861. 0x51000, 0x5101c,
  1862. 0x51300, 0x51308,
  1863. };
  1864. static const unsigned int t6_reg_ranges[] = {
  1865. 0x1008, 0x101c,
  1866. 0x1024, 0x10a8,
  1867. 0x10b4, 0x10f8,
  1868. 0x1100, 0x1114,
  1869. 0x111c, 0x112c,
  1870. 0x1138, 0x113c,
  1871. 0x1144, 0x114c,
  1872. 0x1180, 0x1184,
  1873. 0x1190, 0x1194,
  1874. 0x11a0, 0x11a4,
  1875. 0x11b0, 0x11b4,
  1876. 0x11fc, 0x1254,
  1877. 0x1280, 0x133c,
  1878. 0x1800, 0x18fc,
  1879. 0x3000, 0x302c,
  1880. 0x3060, 0x30b0,
  1881. 0x30b8, 0x30d8,
  1882. 0x30e0, 0x30fc,
  1883. 0x3140, 0x357c,
  1884. 0x35a8, 0x35cc,
  1885. 0x35ec, 0x35ec,
  1886. 0x3600, 0x5624,
  1887. 0x56cc, 0x56ec,
  1888. 0x56f4, 0x5720,
  1889. 0x5728, 0x575c,
  1890. 0x580c, 0x5814,
  1891. 0x5890, 0x589c,
  1892. 0x58a4, 0x58ac,
  1893. 0x58b8, 0x58bc,
  1894. 0x5940, 0x595c,
  1895. 0x5980, 0x598c,
  1896. 0x59b0, 0x59c8,
  1897. 0x59d0, 0x59dc,
  1898. 0x59fc, 0x5a18,
  1899. 0x5a60, 0x5a6c,
  1900. 0x5a80, 0x5a8c,
  1901. 0x5a94, 0x5a9c,
  1902. 0x5b94, 0x5bfc,
  1903. 0x5c10, 0x5e48,
  1904. 0x5e50, 0x5e94,
  1905. 0x5ea0, 0x5eb0,
  1906. 0x5ec0, 0x5ec0,
  1907. 0x5ec8, 0x5ecc,
  1908. 0x6000, 0x6020,
  1909. 0x6028, 0x6040,
  1910. 0x6058, 0x609c,
  1911. 0x60a8, 0x619c,
  1912. 0x7700, 0x7798,
  1913. 0x77c0, 0x7880,
  1914. 0x78cc, 0x78fc,
  1915. 0x7b00, 0x7b58,
  1916. 0x7b60, 0x7b84,
  1917. 0x7b8c, 0x7c54,
  1918. 0x7d00, 0x7d38,
  1919. 0x7d40, 0x7d84,
  1920. 0x7d8c, 0x7ddc,
  1921. 0x7de4, 0x7e04,
  1922. 0x7e10, 0x7e1c,
  1923. 0x7e24, 0x7e38,
  1924. 0x7e40, 0x7e44,
  1925. 0x7e4c, 0x7e78,
  1926. 0x7e80, 0x7edc,
  1927. 0x7ee8, 0x7efc,
  1928. 0x8dc0, 0x8de4,
  1929. 0x8df8, 0x8e04,
  1930. 0x8e10, 0x8e84,
  1931. 0x8ea0, 0x8f88,
  1932. 0x8fb8, 0x9058,
  1933. 0x9060, 0x9060,
  1934. 0x9068, 0x90f8,
  1935. 0x9100, 0x9124,
  1936. 0x9400, 0x9470,
  1937. 0x9600, 0x9600,
  1938. 0x9608, 0x9638,
  1939. 0x9640, 0x9704,
  1940. 0x9710, 0x971c,
  1941. 0x9800, 0x9808,
  1942. 0x9820, 0x983c,
  1943. 0x9850, 0x9864,
  1944. 0x9c00, 0x9c6c,
  1945. 0x9c80, 0x9cec,
  1946. 0x9d00, 0x9d6c,
  1947. 0x9d80, 0x9dec,
  1948. 0x9e00, 0x9e6c,
  1949. 0x9e80, 0x9eec,
  1950. 0x9f00, 0x9f6c,
  1951. 0x9f80, 0xa020,
  1952. 0xd004, 0xd03c,
  1953. 0xd100, 0xd118,
  1954. 0xd200, 0xd214,
  1955. 0xd220, 0xd234,
  1956. 0xd240, 0xd254,
  1957. 0xd260, 0xd274,
  1958. 0xd280, 0xd294,
  1959. 0xd2a0, 0xd2b4,
  1960. 0xd2c0, 0xd2d4,
  1961. 0xd2e0, 0xd2f4,
  1962. 0xd300, 0xd31c,
  1963. 0xdfc0, 0xdfe0,
  1964. 0xe000, 0xf008,
  1965. 0x11000, 0x11014,
  1966. 0x11048, 0x1106c,
  1967. 0x11074, 0x11088,
  1968. 0x11098, 0x11120,
  1969. 0x1112c, 0x1117c,
  1970. 0x11190, 0x112e0,
  1971. 0x11300, 0x1130c,
  1972. 0x12000, 0x1206c,
  1973. 0x19040, 0x1906c,
  1974. 0x19078, 0x19080,
  1975. 0x1908c, 0x190e8,
  1976. 0x190f0, 0x190f8,
  1977. 0x19100, 0x19110,
  1978. 0x19120, 0x19124,
  1979. 0x19150, 0x19194,
  1980. 0x1919c, 0x191b0,
  1981. 0x191d0, 0x191e8,
  1982. 0x19238, 0x192b0,
  1983. 0x192bc, 0x192bc,
  1984. 0x19348, 0x1934c,
  1985. 0x193f8, 0x19418,
  1986. 0x19420, 0x19428,
  1987. 0x19430, 0x19444,
  1988. 0x1944c, 0x1946c,
  1989. 0x19474, 0x19474,
  1990. 0x19490, 0x194cc,
  1991. 0x194f0, 0x194f8,
  1992. 0x19c00, 0x19c48,
  1993. 0x19c50, 0x19c80,
  1994. 0x19c94, 0x19c98,
  1995. 0x19ca0, 0x19cbc,
  1996. 0x19ce4, 0x19ce4,
  1997. 0x19cf0, 0x19cf8,
  1998. 0x19d00, 0x19d28,
  1999. 0x19d50, 0x19d78,
  2000. 0x19d94, 0x19d98,
  2001. 0x19da0, 0x19dc8,
  2002. 0x19df0, 0x19e10,
  2003. 0x19e50, 0x19e6c,
  2004. 0x19ea0, 0x19ebc,
  2005. 0x19ec4, 0x19ef4,
  2006. 0x19f04, 0x19f2c,
  2007. 0x19f34, 0x19f34,
  2008. 0x19f40, 0x19f50,
  2009. 0x19f90, 0x19fac,
  2010. 0x19fc4, 0x19fc8,
  2011. 0x19fd0, 0x19fe4,
  2012. 0x1a000, 0x1a004,
  2013. 0x1a010, 0x1a06c,
  2014. 0x1a0b0, 0x1a0e4,
  2015. 0x1a0ec, 0x1a0f8,
  2016. 0x1a100, 0x1a108,
  2017. 0x1a114, 0x1a120,
  2018. 0x1a128, 0x1a130,
  2019. 0x1a138, 0x1a138,
  2020. 0x1a190, 0x1a1c4,
  2021. 0x1a1fc, 0x1a1fc,
  2022. 0x1e008, 0x1e00c,
  2023. 0x1e040, 0x1e044,
  2024. 0x1e04c, 0x1e04c,
  2025. 0x1e284, 0x1e290,
  2026. 0x1e2c0, 0x1e2c0,
  2027. 0x1e2e0, 0x1e2e0,
  2028. 0x1e300, 0x1e384,
  2029. 0x1e3c0, 0x1e3c8,
  2030. 0x1e408, 0x1e40c,
  2031. 0x1e440, 0x1e444,
  2032. 0x1e44c, 0x1e44c,
  2033. 0x1e684, 0x1e690,
  2034. 0x1e6c0, 0x1e6c0,
  2035. 0x1e6e0, 0x1e6e0,
  2036. 0x1e700, 0x1e784,
  2037. 0x1e7c0, 0x1e7c8,
  2038. 0x1e808, 0x1e80c,
  2039. 0x1e840, 0x1e844,
  2040. 0x1e84c, 0x1e84c,
  2041. 0x1ea84, 0x1ea90,
  2042. 0x1eac0, 0x1eac0,
  2043. 0x1eae0, 0x1eae0,
  2044. 0x1eb00, 0x1eb84,
  2045. 0x1ebc0, 0x1ebc8,
  2046. 0x1ec08, 0x1ec0c,
  2047. 0x1ec40, 0x1ec44,
  2048. 0x1ec4c, 0x1ec4c,
  2049. 0x1ee84, 0x1ee90,
  2050. 0x1eec0, 0x1eec0,
  2051. 0x1eee0, 0x1eee0,
  2052. 0x1ef00, 0x1ef84,
  2053. 0x1efc0, 0x1efc8,
  2054. 0x1f008, 0x1f00c,
  2055. 0x1f040, 0x1f044,
  2056. 0x1f04c, 0x1f04c,
  2057. 0x1f284, 0x1f290,
  2058. 0x1f2c0, 0x1f2c0,
  2059. 0x1f2e0, 0x1f2e0,
  2060. 0x1f300, 0x1f384,
  2061. 0x1f3c0, 0x1f3c8,
  2062. 0x1f408, 0x1f40c,
  2063. 0x1f440, 0x1f444,
  2064. 0x1f44c, 0x1f44c,
  2065. 0x1f684, 0x1f690,
  2066. 0x1f6c0, 0x1f6c0,
  2067. 0x1f6e0, 0x1f6e0,
  2068. 0x1f700, 0x1f784,
  2069. 0x1f7c0, 0x1f7c8,
  2070. 0x1f808, 0x1f80c,
  2071. 0x1f840, 0x1f844,
  2072. 0x1f84c, 0x1f84c,
  2073. 0x1fa84, 0x1fa90,
  2074. 0x1fac0, 0x1fac0,
  2075. 0x1fae0, 0x1fae0,
  2076. 0x1fb00, 0x1fb84,
  2077. 0x1fbc0, 0x1fbc8,
  2078. 0x1fc08, 0x1fc0c,
  2079. 0x1fc40, 0x1fc44,
  2080. 0x1fc4c, 0x1fc4c,
  2081. 0x1fe84, 0x1fe90,
  2082. 0x1fec0, 0x1fec0,
  2083. 0x1fee0, 0x1fee0,
  2084. 0x1ff00, 0x1ff84,
  2085. 0x1ffc0, 0x1ffc8,
  2086. 0x30000, 0x30030,
  2087. 0x30038, 0x30038,
  2088. 0x30040, 0x30040,
  2089. 0x30048, 0x30048,
  2090. 0x30050, 0x30050,
  2091. 0x3005c, 0x30060,
  2092. 0x30068, 0x30068,
  2093. 0x30070, 0x30070,
  2094. 0x30100, 0x30168,
  2095. 0x30190, 0x301a0,
  2096. 0x301a8, 0x301b8,
  2097. 0x301c4, 0x301c8,
  2098. 0x301d0, 0x301d0,
  2099. 0x30200, 0x30320,
  2100. 0x30400, 0x304b4,
  2101. 0x304c0, 0x3052c,
  2102. 0x30540, 0x3061c,
  2103. 0x30800, 0x308a0,
  2104. 0x308c0, 0x30908,
  2105. 0x30910, 0x309b8,
  2106. 0x30a00, 0x30a04,
  2107. 0x30a0c, 0x30a14,
  2108. 0x30a1c, 0x30a2c,
  2109. 0x30a44, 0x30a50,
  2110. 0x30a74, 0x30a74,
  2111. 0x30a7c, 0x30afc,
  2112. 0x30b08, 0x30c24,
  2113. 0x30d00, 0x30d14,
  2114. 0x30d1c, 0x30d3c,
  2115. 0x30d44, 0x30d4c,
  2116. 0x30d54, 0x30d74,
  2117. 0x30d7c, 0x30d7c,
  2118. 0x30de0, 0x30de0,
  2119. 0x30e00, 0x30ed4,
  2120. 0x30f00, 0x30fa4,
  2121. 0x30fc0, 0x30fc4,
  2122. 0x31000, 0x31004,
  2123. 0x31080, 0x310fc,
  2124. 0x31208, 0x31220,
  2125. 0x3123c, 0x31254,
  2126. 0x31300, 0x31300,
  2127. 0x31308, 0x3131c,
  2128. 0x31338, 0x3133c,
  2129. 0x31380, 0x31380,
  2130. 0x31388, 0x313a8,
  2131. 0x313b4, 0x313b4,
  2132. 0x31400, 0x31420,
  2133. 0x31438, 0x3143c,
  2134. 0x31480, 0x31480,
  2135. 0x314a8, 0x314a8,
  2136. 0x314b0, 0x314b4,
  2137. 0x314c8, 0x314d4,
  2138. 0x31a40, 0x31a4c,
  2139. 0x31af0, 0x31b20,
  2140. 0x31b38, 0x31b3c,
  2141. 0x31b80, 0x31b80,
  2142. 0x31ba8, 0x31ba8,
  2143. 0x31bb0, 0x31bb4,
  2144. 0x31bc8, 0x31bd4,
  2145. 0x32140, 0x3218c,
  2146. 0x321f0, 0x321f4,
  2147. 0x32200, 0x32200,
  2148. 0x32218, 0x32218,
  2149. 0x32400, 0x32400,
  2150. 0x32408, 0x3241c,
  2151. 0x32618, 0x32620,
  2152. 0x32664, 0x32664,
  2153. 0x326a8, 0x326a8,
  2154. 0x326ec, 0x326ec,
  2155. 0x32a00, 0x32abc,
  2156. 0x32b00, 0x32b38,
  2157. 0x32b40, 0x32b58,
  2158. 0x32b60, 0x32b78,
  2159. 0x32c00, 0x32c00,
  2160. 0x32c08, 0x32c3c,
  2161. 0x32e00, 0x32e2c,
  2162. 0x32f00, 0x32f2c,
  2163. 0x33000, 0x3302c,
  2164. 0x33034, 0x33050,
  2165. 0x33058, 0x33058,
  2166. 0x33060, 0x3308c,
  2167. 0x3309c, 0x330ac,
  2168. 0x330c0, 0x330c0,
  2169. 0x330c8, 0x330d0,
  2170. 0x330d8, 0x330e0,
  2171. 0x330ec, 0x3312c,
  2172. 0x33134, 0x33150,
  2173. 0x33158, 0x33158,
  2174. 0x33160, 0x3318c,
  2175. 0x3319c, 0x331ac,
  2176. 0x331c0, 0x331c0,
  2177. 0x331c8, 0x331d0,
  2178. 0x331d8, 0x331e0,
  2179. 0x331ec, 0x33290,
  2180. 0x33298, 0x332c4,
  2181. 0x332e4, 0x33390,
  2182. 0x33398, 0x333c4,
  2183. 0x333e4, 0x3342c,
  2184. 0x33434, 0x33450,
  2185. 0x33458, 0x33458,
  2186. 0x33460, 0x3348c,
  2187. 0x3349c, 0x334ac,
  2188. 0x334c0, 0x334c0,
  2189. 0x334c8, 0x334d0,
  2190. 0x334d8, 0x334e0,
  2191. 0x334ec, 0x3352c,
  2192. 0x33534, 0x33550,
  2193. 0x33558, 0x33558,
  2194. 0x33560, 0x3358c,
  2195. 0x3359c, 0x335ac,
  2196. 0x335c0, 0x335c0,
  2197. 0x335c8, 0x335d0,
  2198. 0x335d8, 0x335e0,
  2199. 0x335ec, 0x33690,
  2200. 0x33698, 0x336c4,
  2201. 0x336e4, 0x33790,
  2202. 0x33798, 0x337c4,
  2203. 0x337e4, 0x337fc,
  2204. 0x33814, 0x33814,
  2205. 0x33854, 0x33868,
  2206. 0x33880, 0x3388c,
  2207. 0x338c0, 0x338d0,
  2208. 0x338e8, 0x338ec,
  2209. 0x33900, 0x3392c,
  2210. 0x33934, 0x33950,
  2211. 0x33958, 0x33958,
  2212. 0x33960, 0x3398c,
  2213. 0x3399c, 0x339ac,
  2214. 0x339c0, 0x339c0,
  2215. 0x339c8, 0x339d0,
  2216. 0x339d8, 0x339e0,
  2217. 0x339ec, 0x33a90,
  2218. 0x33a98, 0x33ac4,
  2219. 0x33ae4, 0x33b10,
  2220. 0x33b24, 0x33b28,
  2221. 0x33b38, 0x33b50,
  2222. 0x33bf0, 0x33c10,
  2223. 0x33c24, 0x33c28,
  2224. 0x33c38, 0x33c50,
  2225. 0x33cf0, 0x33cfc,
  2226. 0x34000, 0x34030,
  2227. 0x34038, 0x34038,
  2228. 0x34040, 0x34040,
  2229. 0x34048, 0x34048,
  2230. 0x34050, 0x34050,
  2231. 0x3405c, 0x34060,
  2232. 0x34068, 0x34068,
  2233. 0x34070, 0x34070,
  2234. 0x34100, 0x34168,
  2235. 0x34190, 0x341a0,
  2236. 0x341a8, 0x341b8,
  2237. 0x341c4, 0x341c8,
  2238. 0x341d0, 0x341d0,
  2239. 0x34200, 0x34320,
  2240. 0x34400, 0x344b4,
  2241. 0x344c0, 0x3452c,
  2242. 0x34540, 0x3461c,
  2243. 0x34800, 0x348a0,
  2244. 0x348c0, 0x34908,
  2245. 0x34910, 0x349b8,
  2246. 0x34a00, 0x34a04,
  2247. 0x34a0c, 0x34a14,
  2248. 0x34a1c, 0x34a2c,
  2249. 0x34a44, 0x34a50,
  2250. 0x34a74, 0x34a74,
  2251. 0x34a7c, 0x34afc,
  2252. 0x34b08, 0x34c24,
  2253. 0x34d00, 0x34d14,
  2254. 0x34d1c, 0x34d3c,
  2255. 0x34d44, 0x34d4c,
  2256. 0x34d54, 0x34d74,
  2257. 0x34d7c, 0x34d7c,
  2258. 0x34de0, 0x34de0,
  2259. 0x34e00, 0x34ed4,
  2260. 0x34f00, 0x34fa4,
  2261. 0x34fc0, 0x34fc4,
  2262. 0x35000, 0x35004,
  2263. 0x35080, 0x350fc,
  2264. 0x35208, 0x35220,
  2265. 0x3523c, 0x35254,
  2266. 0x35300, 0x35300,
  2267. 0x35308, 0x3531c,
  2268. 0x35338, 0x3533c,
  2269. 0x35380, 0x35380,
  2270. 0x35388, 0x353a8,
  2271. 0x353b4, 0x353b4,
  2272. 0x35400, 0x35420,
  2273. 0x35438, 0x3543c,
  2274. 0x35480, 0x35480,
  2275. 0x354a8, 0x354a8,
  2276. 0x354b0, 0x354b4,
  2277. 0x354c8, 0x354d4,
  2278. 0x35a40, 0x35a4c,
  2279. 0x35af0, 0x35b20,
  2280. 0x35b38, 0x35b3c,
  2281. 0x35b80, 0x35b80,
  2282. 0x35ba8, 0x35ba8,
  2283. 0x35bb0, 0x35bb4,
  2284. 0x35bc8, 0x35bd4,
  2285. 0x36140, 0x3618c,
  2286. 0x361f0, 0x361f4,
  2287. 0x36200, 0x36200,
  2288. 0x36218, 0x36218,
  2289. 0x36400, 0x36400,
  2290. 0x36408, 0x3641c,
  2291. 0x36618, 0x36620,
  2292. 0x36664, 0x36664,
  2293. 0x366a8, 0x366a8,
  2294. 0x366ec, 0x366ec,
  2295. 0x36a00, 0x36abc,
  2296. 0x36b00, 0x36b38,
  2297. 0x36b40, 0x36b58,
  2298. 0x36b60, 0x36b78,
  2299. 0x36c00, 0x36c00,
  2300. 0x36c08, 0x36c3c,
  2301. 0x36e00, 0x36e2c,
  2302. 0x36f00, 0x36f2c,
  2303. 0x37000, 0x3702c,
  2304. 0x37034, 0x37050,
  2305. 0x37058, 0x37058,
  2306. 0x37060, 0x3708c,
  2307. 0x3709c, 0x370ac,
  2308. 0x370c0, 0x370c0,
  2309. 0x370c8, 0x370d0,
  2310. 0x370d8, 0x370e0,
  2311. 0x370ec, 0x3712c,
  2312. 0x37134, 0x37150,
  2313. 0x37158, 0x37158,
  2314. 0x37160, 0x3718c,
  2315. 0x3719c, 0x371ac,
  2316. 0x371c0, 0x371c0,
  2317. 0x371c8, 0x371d0,
  2318. 0x371d8, 0x371e0,
  2319. 0x371ec, 0x37290,
  2320. 0x37298, 0x372c4,
  2321. 0x372e4, 0x37390,
  2322. 0x37398, 0x373c4,
  2323. 0x373e4, 0x3742c,
  2324. 0x37434, 0x37450,
  2325. 0x37458, 0x37458,
  2326. 0x37460, 0x3748c,
  2327. 0x3749c, 0x374ac,
  2328. 0x374c0, 0x374c0,
  2329. 0x374c8, 0x374d0,
  2330. 0x374d8, 0x374e0,
  2331. 0x374ec, 0x3752c,
  2332. 0x37534, 0x37550,
  2333. 0x37558, 0x37558,
  2334. 0x37560, 0x3758c,
  2335. 0x3759c, 0x375ac,
  2336. 0x375c0, 0x375c0,
  2337. 0x375c8, 0x375d0,
  2338. 0x375d8, 0x375e0,
  2339. 0x375ec, 0x37690,
  2340. 0x37698, 0x376c4,
  2341. 0x376e4, 0x37790,
  2342. 0x37798, 0x377c4,
  2343. 0x377e4, 0x377fc,
  2344. 0x37814, 0x37814,
  2345. 0x37854, 0x37868,
  2346. 0x37880, 0x3788c,
  2347. 0x378c0, 0x378d0,
  2348. 0x378e8, 0x378ec,
  2349. 0x37900, 0x3792c,
  2350. 0x37934, 0x37950,
  2351. 0x37958, 0x37958,
  2352. 0x37960, 0x3798c,
  2353. 0x3799c, 0x379ac,
  2354. 0x379c0, 0x379c0,
  2355. 0x379c8, 0x379d0,
  2356. 0x379d8, 0x379e0,
  2357. 0x379ec, 0x37a90,
  2358. 0x37a98, 0x37ac4,
  2359. 0x37ae4, 0x37b10,
  2360. 0x37b24, 0x37b28,
  2361. 0x37b38, 0x37b50,
  2362. 0x37bf0, 0x37c10,
  2363. 0x37c24, 0x37c28,
  2364. 0x37c38, 0x37c50,
  2365. 0x37cf0, 0x37cfc,
  2366. 0x40040, 0x40040,
  2367. 0x40080, 0x40084,
  2368. 0x40100, 0x40100,
  2369. 0x40140, 0x401bc,
  2370. 0x40200, 0x40214,
  2371. 0x40228, 0x40228,
  2372. 0x40240, 0x40258,
  2373. 0x40280, 0x40280,
  2374. 0x40304, 0x40304,
  2375. 0x40330, 0x4033c,
  2376. 0x41304, 0x413c8,
  2377. 0x413d0, 0x413dc,
  2378. 0x413f0, 0x413f0,
  2379. 0x41400, 0x4140c,
  2380. 0x41414, 0x4141c,
  2381. 0x41480, 0x414d0,
  2382. 0x44000, 0x4407c,
  2383. 0x440c0, 0x441ac,
  2384. 0x441b4, 0x4427c,
  2385. 0x442c0, 0x443ac,
  2386. 0x443b4, 0x4447c,
  2387. 0x444c0, 0x445ac,
  2388. 0x445b4, 0x4467c,
  2389. 0x446c0, 0x447ac,
  2390. 0x447b4, 0x4487c,
  2391. 0x448c0, 0x449ac,
  2392. 0x449b4, 0x44a7c,
  2393. 0x44ac0, 0x44bac,
  2394. 0x44bb4, 0x44c7c,
  2395. 0x44cc0, 0x44dac,
  2396. 0x44db4, 0x44e7c,
  2397. 0x44ec0, 0x44fac,
  2398. 0x44fb4, 0x4507c,
  2399. 0x450c0, 0x451ac,
  2400. 0x451b4, 0x451fc,
  2401. 0x45800, 0x45804,
  2402. 0x45810, 0x45830,
  2403. 0x45840, 0x45860,
  2404. 0x45868, 0x45868,
  2405. 0x45880, 0x45884,
  2406. 0x458a0, 0x458b0,
  2407. 0x45a00, 0x45a04,
  2408. 0x45a10, 0x45a30,
  2409. 0x45a40, 0x45a60,
  2410. 0x45a68, 0x45a68,
  2411. 0x45a80, 0x45a84,
  2412. 0x45aa0, 0x45ab0,
  2413. 0x460c0, 0x460e4,
  2414. 0x47000, 0x4703c,
  2415. 0x47044, 0x4708c,
  2416. 0x47200, 0x47250,
  2417. 0x47400, 0x47408,
  2418. 0x47414, 0x47420,
  2419. 0x47600, 0x47618,
  2420. 0x47800, 0x47814,
  2421. 0x47820, 0x4782c,
  2422. 0x50000, 0x50084,
  2423. 0x50090, 0x500cc,
  2424. 0x50300, 0x50384,
  2425. 0x50400, 0x50400,
  2426. 0x50800, 0x50884,
  2427. 0x50890, 0x508cc,
  2428. 0x50b00, 0x50b84,
  2429. 0x50c00, 0x50c00,
  2430. 0x51000, 0x51020,
  2431. 0x51028, 0x510b0,
  2432. 0x51300, 0x51324,
  2433. };
  2434. u32 *buf_end = (u32 *)((char *)buf + buf_size);
  2435. const unsigned int *reg_ranges;
  2436. int reg_ranges_size, range;
  2437. unsigned int chip_version = CHELSIO_CHIP_VERSION(adap->params.chip);
  2438. /* Select the right set of register ranges to dump depending on the
  2439. * adapter chip type.
  2440. */
  2441. switch (chip_version) {
  2442. case CHELSIO_T4:
  2443. reg_ranges = t4_reg_ranges;
  2444. reg_ranges_size = ARRAY_SIZE(t4_reg_ranges);
  2445. break;
  2446. case CHELSIO_T5:
  2447. reg_ranges = t5_reg_ranges;
  2448. reg_ranges_size = ARRAY_SIZE(t5_reg_ranges);
  2449. break;
  2450. case CHELSIO_T6:
  2451. reg_ranges = t6_reg_ranges;
  2452. reg_ranges_size = ARRAY_SIZE(t6_reg_ranges);
  2453. break;
  2454. default:
  2455. dev_err(adap->pdev_dev,
  2456. "Unsupported chip version %d\n", chip_version);
  2457. return;
  2458. }
  2459. /* Clear the register buffer and insert the appropriate register
  2460. * values selected by the above register ranges.
  2461. */
  2462. memset(buf, 0, buf_size);
  2463. for (range = 0; range < reg_ranges_size; range += 2) {
  2464. unsigned int reg = reg_ranges[range];
  2465. unsigned int last_reg = reg_ranges[range + 1];
  2466. u32 *bufp = (u32 *)((char *)buf + reg);
  2467. /* Iterate across the register range filling in the register
  2468. * buffer but don't write past the end of the register buffer.
  2469. */
  2470. while (reg <= last_reg && bufp < buf_end) {
  2471. *bufp++ = t4_read_reg(adap, reg);
  2472. reg += sizeof(u32);
  2473. }
  2474. }
  2475. }
  2476. #define EEPROM_STAT_ADDR 0x7bfc
  2477. #define VPD_BASE 0x400
  2478. #define VPD_BASE_OLD 0
  2479. #define VPD_LEN 1024
  2480. #define CHELSIO_VPD_UNIQUE_ID 0x82
  2481. /**
  2482. * t4_seeprom_wp - enable/disable EEPROM write protection
  2483. * @adapter: the adapter
  2484. * @enable: whether to enable or disable write protection
  2485. *
  2486. * Enables or disables write protection on the serial EEPROM.
  2487. */
  2488. int t4_seeprom_wp(struct adapter *adapter, bool enable)
  2489. {
  2490. unsigned int v = enable ? 0xc : 0;
  2491. int ret = pci_write_vpd(adapter->pdev, EEPROM_STAT_ADDR, 4, &v);
  2492. return ret < 0 ? ret : 0;
  2493. }
  2494. /**
  2495. * t4_get_raw_vpd_params - read VPD parameters from VPD EEPROM
  2496. * @adapter: adapter to read
  2497. * @p: where to store the parameters
  2498. *
  2499. * Reads card parameters stored in VPD EEPROM.
  2500. */
  2501. int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p)
  2502. {
  2503. int i, ret = 0, addr;
  2504. int ec, sn, pn, na;
  2505. u8 *vpd, csum;
  2506. unsigned int vpdr_len, kw_offset, id_len;
  2507. vpd = vmalloc(VPD_LEN);
  2508. if (!vpd)
  2509. return -ENOMEM;
  2510. /* Card information normally starts at VPD_BASE but early cards had
  2511. * it at 0.
  2512. */
  2513. ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(u32), vpd);
  2514. if (ret < 0)
  2515. goto out;
  2516. /* The VPD shall have a unique identifier specified by the PCI SIG.
  2517. * For chelsio adapters, the identifier is 0x82. The first byte of a VPD
  2518. * shall be CHELSIO_VPD_UNIQUE_ID (0x82). The VPD programming software
  2519. * is expected to automatically put this entry at the
  2520. * beginning of the VPD.
  2521. */
  2522. addr = *vpd == CHELSIO_VPD_UNIQUE_ID ? VPD_BASE : VPD_BASE_OLD;
  2523. ret = pci_read_vpd(adapter->pdev, addr, VPD_LEN, vpd);
  2524. if (ret < 0)
  2525. goto out;
  2526. if (vpd[0] != PCI_VPD_LRDT_ID_STRING) {
  2527. dev_err(adapter->pdev_dev, "missing VPD ID string\n");
  2528. ret = -EINVAL;
  2529. goto out;
  2530. }
  2531. id_len = pci_vpd_lrdt_size(vpd);
  2532. if (id_len > ID_LEN)
  2533. id_len = ID_LEN;
  2534. i = pci_vpd_find_tag(vpd, 0, VPD_LEN, PCI_VPD_LRDT_RO_DATA);
  2535. if (i < 0) {
  2536. dev_err(adapter->pdev_dev, "missing VPD-R section\n");
  2537. ret = -EINVAL;
  2538. goto out;
  2539. }
  2540. vpdr_len = pci_vpd_lrdt_size(&vpd[i]);
  2541. kw_offset = i + PCI_VPD_LRDT_TAG_SIZE;
  2542. if (vpdr_len + kw_offset > VPD_LEN) {
  2543. dev_err(adapter->pdev_dev, "bad VPD-R length %u\n", vpdr_len);
  2544. ret = -EINVAL;
  2545. goto out;
  2546. }
  2547. #define FIND_VPD_KW(var, name) do { \
  2548. var = pci_vpd_find_info_keyword(vpd, kw_offset, vpdr_len, name); \
  2549. if (var < 0) { \
  2550. dev_err(adapter->pdev_dev, "missing VPD keyword " name "\n"); \
  2551. ret = -EINVAL; \
  2552. goto out; \
  2553. } \
  2554. var += PCI_VPD_INFO_FLD_HDR_SIZE; \
  2555. } while (0)
  2556. FIND_VPD_KW(i, "RV");
  2557. for (csum = 0; i >= 0; i--)
  2558. csum += vpd[i];
  2559. if (csum) {
  2560. dev_err(adapter->pdev_dev,
  2561. "corrupted VPD EEPROM, actual csum %u\n", csum);
  2562. ret = -EINVAL;
  2563. goto out;
  2564. }
  2565. FIND_VPD_KW(ec, "EC");
  2566. FIND_VPD_KW(sn, "SN");
  2567. FIND_VPD_KW(pn, "PN");
  2568. FIND_VPD_KW(na, "NA");
  2569. #undef FIND_VPD_KW
  2570. memcpy(p->id, vpd + PCI_VPD_LRDT_TAG_SIZE, id_len);
  2571. strim(p->id);
  2572. memcpy(p->ec, vpd + ec, EC_LEN);
  2573. strim(p->ec);
  2574. i = pci_vpd_info_field_size(vpd + sn - PCI_VPD_INFO_FLD_HDR_SIZE);
  2575. memcpy(p->sn, vpd + sn, min(i, SERNUM_LEN));
  2576. strim(p->sn);
  2577. i = pci_vpd_info_field_size(vpd + pn - PCI_VPD_INFO_FLD_HDR_SIZE);
  2578. memcpy(p->pn, vpd + pn, min(i, PN_LEN));
  2579. strim(p->pn);
  2580. memcpy(p->na, vpd + na, min(i, MACADDR_LEN));
  2581. strim((char *)p->na);
  2582. out:
  2583. vfree(vpd);
  2584. return ret;
  2585. }
  2586. /**
  2587. * t4_get_vpd_params - read VPD parameters & retrieve Core Clock
  2588. * @adapter: adapter to read
  2589. * @p: where to store the parameters
  2590. *
  2591. * Reads card parameters stored in VPD EEPROM and retrieves the Core
  2592. * Clock. This can only be called after a connection to the firmware
  2593. * is established.
  2594. */
  2595. int t4_get_vpd_params(struct adapter *adapter, struct vpd_params *p)
  2596. {
  2597. u32 cclk_param, cclk_val;
  2598. int ret;
  2599. /* Grab the raw VPD parameters.
  2600. */
  2601. ret = t4_get_raw_vpd_params(adapter, p);
  2602. if (ret)
  2603. return ret;
  2604. /* Ask firmware for the Core Clock since it knows how to translate the
  2605. * Reference Clock ('V2') VPD field into a Core Clock value ...
  2606. */
  2607. cclk_param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  2608. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CCLK));
  2609. ret = t4_query_params(adapter, adapter->mbox, adapter->pf, 0,
  2610. 1, &cclk_param, &cclk_val);
  2611. if (ret)
  2612. return ret;
  2613. p->cclk = cclk_val;
  2614. return 0;
  2615. }
  2616. /* serial flash and firmware constants */
  2617. enum {
  2618. SF_ATTEMPTS = 10, /* max retries for SF operations */
  2619. /* flash command opcodes */
  2620. SF_PROG_PAGE = 2, /* program page */
  2621. SF_WR_DISABLE = 4, /* disable writes */
  2622. SF_RD_STATUS = 5, /* read status register */
  2623. SF_WR_ENABLE = 6, /* enable writes */
  2624. SF_RD_DATA_FAST = 0xb, /* read flash */
  2625. SF_RD_ID = 0x9f, /* read ID */
  2626. SF_ERASE_SECTOR = 0xd8, /* erase sector */
  2627. FW_MAX_SIZE = 16 * SF_SEC_SIZE,
  2628. };
  2629. /**
  2630. * sf1_read - read data from the serial flash
  2631. * @adapter: the adapter
  2632. * @byte_cnt: number of bytes to read
  2633. * @cont: whether another operation will be chained
  2634. * @lock: whether to lock SF for PL access only
  2635. * @valp: where to store the read data
  2636. *
  2637. * Reads up to 4 bytes of data from the serial flash. The location of
  2638. * the read needs to be specified prior to calling this by issuing the
  2639. * appropriate commands to the serial flash.
  2640. */
  2641. static int sf1_read(struct adapter *adapter, unsigned int byte_cnt, int cont,
  2642. int lock, u32 *valp)
  2643. {
  2644. int ret;
  2645. if (!byte_cnt || byte_cnt > 4)
  2646. return -EINVAL;
  2647. if (t4_read_reg(adapter, SF_OP_A) & SF_BUSY_F)
  2648. return -EBUSY;
  2649. t4_write_reg(adapter, SF_OP_A, SF_LOCK_V(lock) |
  2650. SF_CONT_V(cont) | BYTECNT_V(byte_cnt - 1));
  2651. ret = t4_wait_op_done(adapter, SF_OP_A, SF_BUSY_F, 0, SF_ATTEMPTS, 5);
  2652. if (!ret)
  2653. *valp = t4_read_reg(adapter, SF_DATA_A);
  2654. return ret;
  2655. }
  2656. /**
  2657. * sf1_write - write data to the serial flash
  2658. * @adapter: the adapter
  2659. * @byte_cnt: number of bytes to write
  2660. * @cont: whether another operation will be chained
  2661. * @lock: whether to lock SF for PL access only
  2662. * @val: value to write
  2663. *
  2664. * Writes up to 4 bytes of data to the serial flash. The location of
  2665. * the write needs to be specified prior to calling this by issuing the
  2666. * appropriate commands to the serial flash.
  2667. */
  2668. static int sf1_write(struct adapter *adapter, unsigned int byte_cnt, int cont,
  2669. int lock, u32 val)
  2670. {
  2671. if (!byte_cnt || byte_cnt > 4)
  2672. return -EINVAL;
  2673. if (t4_read_reg(adapter, SF_OP_A) & SF_BUSY_F)
  2674. return -EBUSY;
  2675. t4_write_reg(adapter, SF_DATA_A, val);
  2676. t4_write_reg(adapter, SF_OP_A, SF_LOCK_V(lock) |
  2677. SF_CONT_V(cont) | BYTECNT_V(byte_cnt - 1) | OP_V(1));
  2678. return t4_wait_op_done(adapter, SF_OP_A, SF_BUSY_F, 0, SF_ATTEMPTS, 5);
  2679. }
  2680. /**
  2681. * flash_wait_op - wait for a flash operation to complete
  2682. * @adapter: the adapter
  2683. * @attempts: max number of polls of the status register
  2684. * @delay: delay between polls in ms
  2685. *
  2686. * Wait for a flash operation to complete by polling the status register.
  2687. */
  2688. static int flash_wait_op(struct adapter *adapter, int attempts, int delay)
  2689. {
  2690. int ret;
  2691. u32 status;
  2692. while (1) {
  2693. if ((ret = sf1_write(adapter, 1, 1, 1, SF_RD_STATUS)) != 0 ||
  2694. (ret = sf1_read(adapter, 1, 0, 1, &status)) != 0)
  2695. return ret;
  2696. if (!(status & 1))
  2697. return 0;
  2698. if (--attempts == 0)
  2699. return -EAGAIN;
  2700. if (delay)
  2701. msleep(delay);
  2702. }
  2703. }
  2704. /**
  2705. * t4_read_flash - read words from serial flash
  2706. * @adapter: the adapter
  2707. * @addr: the start address for the read
  2708. * @nwords: how many 32-bit words to read
  2709. * @data: where to store the read data
  2710. * @byte_oriented: whether to store data as bytes or as words
  2711. *
  2712. * Read the specified number of 32-bit words from the serial flash.
  2713. * If @byte_oriented is set the read data is stored as a byte array
  2714. * (i.e., big-endian), otherwise as 32-bit words in the platform's
  2715. * natural endianness.
  2716. */
  2717. int t4_read_flash(struct adapter *adapter, unsigned int addr,
  2718. unsigned int nwords, u32 *data, int byte_oriented)
  2719. {
  2720. int ret;
  2721. if (addr + nwords * sizeof(u32) > adapter->params.sf_size || (addr & 3))
  2722. return -EINVAL;
  2723. addr = swab32(addr) | SF_RD_DATA_FAST;
  2724. if ((ret = sf1_write(adapter, 4, 1, 0, addr)) != 0 ||
  2725. (ret = sf1_read(adapter, 1, 1, 0, data)) != 0)
  2726. return ret;
  2727. for ( ; nwords; nwords--, data++) {
  2728. ret = sf1_read(adapter, 4, nwords > 1, nwords == 1, data);
  2729. if (nwords == 1)
  2730. t4_write_reg(adapter, SF_OP_A, 0); /* unlock SF */
  2731. if (ret)
  2732. return ret;
  2733. if (byte_oriented)
  2734. *data = (__force __u32)(cpu_to_be32(*data));
  2735. }
  2736. return 0;
  2737. }
  2738. /**
  2739. * t4_write_flash - write up to a page of data to the serial flash
  2740. * @adapter: the adapter
  2741. * @addr: the start address to write
  2742. * @n: length of data to write in bytes
  2743. * @data: the data to write
  2744. *
  2745. * Writes up to a page of data (256 bytes) to the serial flash starting
  2746. * at the given address. All the data must be written to the same page.
  2747. */
  2748. static int t4_write_flash(struct adapter *adapter, unsigned int addr,
  2749. unsigned int n, const u8 *data)
  2750. {
  2751. int ret;
  2752. u32 buf[64];
  2753. unsigned int i, c, left, val, offset = addr & 0xff;
  2754. if (addr >= adapter->params.sf_size || offset + n > SF_PAGE_SIZE)
  2755. return -EINVAL;
  2756. val = swab32(addr) | SF_PROG_PAGE;
  2757. if ((ret = sf1_write(adapter, 1, 0, 1, SF_WR_ENABLE)) != 0 ||
  2758. (ret = sf1_write(adapter, 4, 1, 1, val)) != 0)
  2759. goto unlock;
  2760. for (left = n; left; left -= c) {
  2761. c = min(left, 4U);
  2762. for (val = 0, i = 0; i < c; ++i)
  2763. val = (val << 8) + *data++;
  2764. ret = sf1_write(adapter, c, c != left, 1, val);
  2765. if (ret)
  2766. goto unlock;
  2767. }
  2768. ret = flash_wait_op(adapter, 8, 1);
  2769. if (ret)
  2770. goto unlock;
  2771. t4_write_reg(adapter, SF_OP_A, 0); /* unlock SF */
  2772. /* Read the page to verify the write succeeded */
  2773. ret = t4_read_flash(adapter, addr & ~0xff, ARRAY_SIZE(buf), buf, 1);
  2774. if (ret)
  2775. return ret;
  2776. if (memcmp(data - n, (u8 *)buf + offset, n)) {
  2777. dev_err(adapter->pdev_dev,
  2778. "failed to correctly write the flash page at %#x\n",
  2779. addr);
  2780. return -EIO;
  2781. }
  2782. return 0;
  2783. unlock:
  2784. t4_write_reg(adapter, SF_OP_A, 0); /* unlock SF */
  2785. return ret;
  2786. }
  2787. /**
  2788. * t4_get_fw_version - read the firmware version
  2789. * @adapter: the adapter
  2790. * @vers: where to place the version
  2791. *
  2792. * Reads the FW version from flash.
  2793. */
  2794. int t4_get_fw_version(struct adapter *adapter, u32 *vers)
  2795. {
  2796. return t4_read_flash(adapter, FLASH_FW_START +
  2797. offsetof(struct fw_hdr, fw_ver), 1,
  2798. vers, 0);
  2799. }
  2800. /**
  2801. * t4_get_tp_version - read the TP microcode version
  2802. * @adapter: the adapter
  2803. * @vers: where to place the version
  2804. *
  2805. * Reads the TP microcode version from flash.
  2806. */
  2807. int t4_get_tp_version(struct adapter *adapter, u32 *vers)
  2808. {
  2809. return t4_read_flash(adapter, FLASH_FW_START +
  2810. offsetof(struct fw_hdr, tp_microcode_ver),
  2811. 1, vers, 0);
  2812. }
  2813. /**
  2814. * t4_get_exprom_version - return the Expansion ROM version (if any)
  2815. * @adapter: the adapter
  2816. * @vers: where to place the version
  2817. *
  2818. * Reads the Expansion ROM header from FLASH and returns the version
  2819. * number (if present) through the @vers return value pointer. We return
  2820. * this in the Firmware Version Format since it's convenient. Return
  2821. * 0 on success, -ENOENT if no Expansion ROM is present.
  2822. */
  2823. int t4_get_exprom_version(struct adapter *adap, u32 *vers)
  2824. {
  2825. struct exprom_header {
  2826. unsigned char hdr_arr[16]; /* must start with 0x55aa */
  2827. unsigned char hdr_ver[4]; /* Expansion ROM version */
  2828. } *hdr;
  2829. u32 exprom_header_buf[DIV_ROUND_UP(sizeof(struct exprom_header),
  2830. sizeof(u32))];
  2831. int ret;
  2832. ret = t4_read_flash(adap, FLASH_EXP_ROM_START,
  2833. ARRAY_SIZE(exprom_header_buf), exprom_header_buf,
  2834. 0);
  2835. if (ret)
  2836. return ret;
  2837. hdr = (struct exprom_header *)exprom_header_buf;
  2838. if (hdr->hdr_arr[0] != 0x55 || hdr->hdr_arr[1] != 0xaa)
  2839. return -ENOENT;
  2840. *vers = (FW_HDR_FW_VER_MAJOR_V(hdr->hdr_ver[0]) |
  2841. FW_HDR_FW_VER_MINOR_V(hdr->hdr_ver[1]) |
  2842. FW_HDR_FW_VER_MICRO_V(hdr->hdr_ver[2]) |
  2843. FW_HDR_FW_VER_BUILD_V(hdr->hdr_ver[3]));
  2844. return 0;
  2845. }
  2846. /**
  2847. * t4_check_fw_version - check if the FW is supported with this driver
  2848. * @adap: the adapter
  2849. *
  2850. * Checks if an adapter's FW is compatible with the driver. Returns 0
  2851. * if there's exact match, a negative error if the version could not be
  2852. * read or there's a major version mismatch
  2853. */
  2854. int t4_check_fw_version(struct adapter *adap)
  2855. {
  2856. int i, ret, major, minor, micro;
  2857. int exp_major, exp_minor, exp_micro;
  2858. unsigned int chip_version = CHELSIO_CHIP_VERSION(adap->params.chip);
  2859. ret = t4_get_fw_version(adap, &adap->params.fw_vers);
  2860. /* Try multiple times before returning error */
  2861. for (i = 0; (ret == -EBUSY || ret == -EAGAIN) && i < 3; i++)
  2862. ret = t4_get_fw_version(adap, &adap->params.fw_vers);
  2863. if (ret)
  2864. return ret;
  2865. major = FW_HDR_FW_VER_MAJOR_G(adap->params.fw_vers);
  2866. minor = FW_HDR_FW_VER_MINOR_G(adap->params.fw_vers);
  2867. micro = FW_HDR_FW_VER_MICRO_G(adap->params.fw_vers);
  2868. switch (chip_version) {
  2869. case CHELSIO_T4:
  2870. exp_major = T4FW_MIN_VERSION_MAJOR;
  2871. exp_minor = T4FW_MIN_VERSION_MINOR;
  2872. exp_micro = T4FW_MIN_VERSION_MICRO;
  2873. break;
  2874. case CHELSIO_T5:
  2875. exp_major = T5FW_MIN_VERSION_MAJOR;
  2876. exp_minor = T5FW_MIN_VERSION_MINOR;
  2877. exp_micro = T5FW_MIN_VERSION_MICRO;
  2878. break;
  2879. case CHELSIO_T6:
  2880. exp_major = T6FW_MIN_VERSION_MAJOR;
  2881. exp_minor = T6FW_MIN_VERSION_MINOR;
  2882. exp_micro = T6FW_MIN_VERSION_MICRO;
  2883. break;
  2884. default:
  2885. dev_err(adap->pdev_dev, "Unsupported chip type, %x\n",
  2886. adap->chip);
  2887. return -EINVAL;
  2888. }
  2889. if (major < exp_major || (major == exp_major && minor < exp_minor) ||
  2890. (major == exp_major && minor == exp_minor && micro < exp_micro)) {
  2891. dev_err(adap->pdev_dev,
  2892. "Card has firmware version %u.%u.%u, minimum "
  2893. "supported firmware is %u.%u.%u.\n", major, minor,
  2894. micro, exp_major, exp_minor, exp_micro);
  2895. return -EFAULT;
  2896. }
  2897. return 0;
  2898. }
  2899. /* Is the given firmware API compatible with the one the driver was compiled
  2900. * with?
  2901. */
  2902. static int fw_compatible(const struct fw_hdr *hdr1, const struct fw_hdr *hdr2)
  2903. {
  2904. /* short circuit if it's the exact same firmware version */
  2905. if (hdr1->chip == hdr2->chip && hdr1->fw_ver == hdr2->fw_ver)
  2906. return 1;
  2907. #define SAME_INTF(x) (hdr1->intfver_##x == hdr2->intfver_##x)
  2908. if (hdr1->chip == hdr2->chip && SAME_INTF(nic) && SAME_INTF(vnic) &&
  2909. SAME_INTF(ri) && SAME_INTF(iscsi) && SAME_INTF(fcoe))
  2910. return 1;
  2911. #undef SAME_INTF
  2912. return 0;
  2913. }
  2914. /* The firmware in the filesystem is usable, but should it be installed?
  2915. * This routine explains itself in detail if it indicates the filesystem
  2916. * firmware should be installed.
  2917. */
  2918. static int should_install_fs_fw(struct adapter *adap, int card_fw_usable,
  2919. int k, int c)
  2920. {
  2921. const char *reason;
  2922. if (!card_fw_usable) {
  2923. reason = "incompatible or unusable";
  2924. goto install;
  2925. }
  2926. if (k > c) {
  2927. reason = "older than the version supported with this driver";
  2928. goto install;
  2929. }
  2930. return 0;
  2931. install:
  2932. dev_err(adap->pdev_dev, "firmware on card (%u.%u.%u.%u) is %s, "
  2933. "installing firmware %u.%u.%u.%u on card.\n",
  2934. FW_HDR_FW_VER_MAJOR_G(c), FW_HDR_FW_VER_MINOR_G(c),
  2935. FW_HDR_FW_VER_MICRO_G(c), FW_HDR_FW_VER_BUILD_G(c), reason,
  2936. FW_HDR_FW_VER_MAJOR_G(k), FW_HDR_FW_VER_MINOR_G(k),
  2937. FW_HDR_FW_VER_MICRO_G(k), FW_HDR_FW_VER_BUILD_G(k));
  2938. return 1;
  2939. }
  2940. int t4_prep_fw(struct adapter *adap, struct fw_info *fw_info,
  2941. const u8 *fw_data, unsigned int fw_size,
  2942. struct fw_hdr *card_fw, enum dev_state state,
  2943. int *reset)
  2944. {
  2945. int ret, card_fw_usable, fs_fw_usable;
  2946. const struct fw_hdr *fs_fw;
  2947. const struct fw_hdr *drv_fw;
  2948. drv_fw = &fw_info->fw_hdr;
  2949. /* Read the header of the firmware on the card */
  2950. ret = -t4_read_flash(adap, FLASH_FW_START,
  2951. sizeof(*card_fw) / sizeof(uint32_t),
  2952. (uint32_t *)card_fw, 1);
  2953. if (ret == 0) {
  2954. card_fw_usable = fw_compatible(drv_fw, (const void *)card_fw);
  2955. } else {
  2956. dev_err(adap->pdev_dev,
  2957. "Unable to read card's firmware header: %d\n", ret);
  2958. card_fw_usable = 0;
  2959. }
  2960. if (fw_data != NULL) {
  2961. fs_fw = (const void *)fw_data;
  2962. fs_fw_usable = fw_compatible(drv_fw, fs_fw);
  2963. } else {
  2964. fs_fw = NULL;
  2965. fs_fw_usable = 0;
  2966. }
  2967. if (card_fw_usable && card_fw->fw_ver == drv_fw->fw_ver &&
  2968. (!fs_fw_usable || fs_fw->fw_ver == drv_fw->fw_ver)) {
  2969. /* Common case: the firmware on the card is an exact match and
  2970. * the filesystem one is an exact match too, or the filesystem
  2971. * one is absent/incompatible.
  2972. */
  2973. } else if (fs_fw_usable && state == DEV_STATE_UNINIT &&
  2974. should_install_fs_fw(adap, card_fw_usable,
  2975. be32_to_cpu(fs_fw->fw_ver),
  2976. be32_to_cpu(card_fw->fw_ver))) {
  2977. ret = -t4_fw_upgrade(adap, adap->mbox, fw_data,
  2978. fw_size, 0);
  2979. if (ret != 0) {
  2980. dev_err(adap->pdev_dev,
  2981. "failed to install firmware: %d\n", ret);
  2982. goto bye;
  2983. }
  2984. /* Installed successfully, update the cached header too. */
  2985. *card_fw = *fs_fw;
  2986. card_fw_usable = 1;
  2987. *reset = 0; /* already reset as part of load_fw */
  2988. }
  2989. if (!card_fw_usable) {
  2990. uint32_t d, c, k;
  2991. d = be32_to_cpu(drv_fw->fw_ver);
  2992. c = be32_to_cpu(card_fw->fw_ver);
  2993. k = fs_fw ? be32_to_cpu(fs_fw->fw_ver) : 0;
  2994. dev_err(adap->pdev_dev, "Cannot find a usable firmware: "
  2995. "chip state %d, "
  2996. "driver compiled with %d.%d.%d.%d, "
  2997. "card has %d.%d.%d.%d, filesystem has %d.%d.%d.%d\n",
  2998. state,
  2999. FW_HDR_FW_VER_MAJOR_G(d), FW_HDR_FW_VER_MINOR_G(d),
  3000. FW_HDR_FW_VER_MICRO_G(d), FW_HDR_FW_VER_BUILD_G(d),
  3001. FW_HDR_FW_VER_MAJOR_G(c), FW_HDR_FW_VER_MINOR_G(c),
  3002. FW_HDR_FW_VER_MICRO_G(c), FW_HDR_FW_VER_BUILD_G(c),
  3003. FW_HDR_FW_VER_MAJOR_G(k), FW_HDR_FW_VER_MINOR_G(k),
  3004. FW_HDR_FW_VER_MICRO_G(k), FW_HDR_FW_VER_BUILD_G(k));
  3005. ret = EINVAL;
  3006. goto bye;
  3007. }
  3008. /* We're using whatever's on the card and it's known to be good. */
  3009. adap->params.fw_vers = be32_to_cpu(card_fw->fw_ver);
  3010. adap->params.tp_vers = be32_to_cpu(card_fw->tp_microcode_ver);
  3011. bye:
  3012. return ret;
  3013. }
  3014. /**
  3015. * t4_flash_erase_sectors - erase a range of flash sectors
  3016. * @adapter: the adapter
  3017. * @start: the first sector to erase
  3018. * @end: the last sector to erase
  3019. *
  3020. * Erases the sectors in the given inclusive range.
  3021. */
  3022. static int t4_flash_erase_sectors(struct adapter *adapter, int start, int end)
  3023. {
  3024. int ret = 0;
  3025. if (end >= adapter->params.sf_nsec)
  3026. return -EINVAL;
  3027. while (start <= end) {
  3028. if ((ret = sf1_write(adapter, 1, 0, 1, SF_WR_ENABLE)) != 0 ||
  3029. (ret = sf1_write(adapter, 4, 0, 1,
  3030. SF_ERASE_SECTOR | (start << 8))) != 0 ||
  3031. (ret = flash_wait_op(adapter, 14, 500)) != 0) {
  3032. dev_err(adapter->pdev_dev,
  3033. "erase of flash sector %d failed, error %d\n",
  3034. start, ret);
  3035. break;
  3036. }
  3037. start++;
  3038. }
  3039. t4_write_reg(adapter, SF_OP_A, 0); /* unlock SF */
  3040. return ret;
  3041. }
  3042. /**
  3043. * t4_flash_cfg_addr - return the address of the flash configuration file
  3044. * @adapter: the adapter
  3045. *
  3046. * Return the address within the flash where the Firmware Configuration
  3047. * File is stored.
  3048. */
  3049. unsigned int t4_flash_cfg_addr(struct adapter *adapter)
  3050. {
  3051. if (adapter->params.sf_size == 0x100000)
  3052. return FLASH_FPGA_CFG_START;
  3053. else
  3054. return FLASH_CFG_START;
  3055. }
  3056. /* Return TRUE if the specified firmware matches the adapter. I.e. T4
  3057. * firmware for T4 adapters, T5 firmware for T5 adapters, etc. We go ahead
  3058. * and emit an error message for mismatched firmware to save our caller the
  3059. * effort ...
  3060. */
  3061. static bool t4_fw_matches_chip(const struct adapter *adap,
  3062. const struct fw_hdr *hdr)
  3063. {
  3064. /* The expression below will return FALSE for any unsupported adapter
  3065. * which will keep us "honest" in the future ...
  3066. */
  3067. if ((is_t4(adap->params.chip) && hdr->chip == FW_HDR_CHIP_T4) ||
  3068. (is_t5(adap->params.chip) && hdr->chip == FW_HDR_CHIP_T5) ||
  3069. (is_t6(adap->params.chip) && hdr->chip == FW_HDR_CHIP_T6))
  3070. return true;
  3071. dev_err(adap->pdev_dev,
  3072. "FW image (%d) is not suitable for this adapter (%d)\n",
  3073. hdr->chip, CHELSIO_CHIP_VERSION(adap->params.chip));
  3074. return false;
  3075. }
  3076. /**
  3077. * t4_load_fw - download firmware
  3078. * @adap: the adapter
  3079. * @fw_data: the firmware image to write
  3080. * @size: image size
  3081. *
  3082. * Write the supplied firmware image to the card's serial flash.
  3083. */
  3084. int t4_load_fw(struct adapter *adap, const u8 *fw_data, unsigned int size)
  3085. {
  3086. u32 csum;
  3087. int ret, addr;
  3088. unsigned int i;
  3089. u8 first_page[SF_PAGE_SIZE];
  3090. const __be32 *p = (const __be32 *)fw_data;
  3091. const struct fw_hdr *hdr = (const struct fw_hdr *)fw_data;
  3092. unsigned int sf_sec_size = adap->params.sf_size / adap->params.sf_nsec;
  3093. unsigned int fw_img_start = adap->params.sf_fw_start;
  3094. unsigned int fw_start_sec = fw_img_start / sf_sec_size;
  3095. if (!size) {
  3096. dev_err(adap->pdev_dev, "FW image has no data\n");
  3097. return -EINVAL;
  3098. }
  3099. if (size & 511) {
  3100. dev_err(adap->pdev_dev,
  3101. "FW image size not multiple of 512 bytes\n");
  3102. return -EINVAL;
  3103. }
  3104. if ((unsigned int)be16_to_cpu(hdr->len512) * 512 != size) {
  3105. dev_err(adap->pdev_dev,
  3106. "FW image size differs from size in FW header\n");
  3107. return -EINVAL;
  3108. }
  3109. if (size > FW_MAX_SIZE) {
  3110. dev_err(adap->pdev_dev, "FW image too large, max is %u bytes\n",
  3111. FW_MAX_SIZE);
  3112. return -EFBIG;
  3113. }
  3114. if (!t4_fw_matches_chip(adap, hdr))
  3115. return -EINVAL;
  3116. for (csum = 0, i = 0; i < size / sizeof(csum); i++)
  3117. csum += be32_to_cpu(p[i]);
  3118. if (csum != 0xffffffff) {
  3119. dev_err(adap->pdev_dev,
  3120. "corrupted firmware image, checksum %#x\n", csum);
  3121. return -EINVAL;
  3122. }
  3123. i = DIV_ROUND_UP(size, sf_sec_size); /* # of sectors spanned */
  3124. ret = t4_flash_erase_sectors(adap, fw_start_sec, fw_start_sec + i - 1);
  3125. if (ret)
  3126. goto out;
  3127. /*
  3128. * We write the correct version at the end so the driver can see a bad
  3129. * version if the FW write fails. Start by writing a copy of the
  3130. * first page with a bad version.
  3131. */
  3132. memcpy(first_page, fw_data, SF_PAGE_SIZE);
  3133. ((struct fw_hdr *)first_page)->fw_ver = cpu_to_be32(0xffffffff);
  3134. ret = t4_write_flash(adap, fw_img_start, SF_PAGE_SIZE, first_page);
  3135. if (ret)
  3136. goto out;
  3137. addr = fw_img_start;
  3138. for (size -= SF_PAGE_SIZE; size; size -= SF_PAGE_SIZE) {
  3139. addr += SF_PAGE_SIZE;
  3140. fw_data += SF_PAGE_SIZE;
  3141. ret = t4_write_flash(adap, addr, SF_PAGE_SIZE, fw_data);
  3142. if (ret)
  3143. goto out;
  3144. }
  3145. ret = t4_write_flash(adap,
  3146. fw_img_start + offsetof(struct fw_hdr, fw_ver),
  3147. sizeof(hdr->fw_ver), (const u8 *)&hdr->fw_ver);
  3148. out:
  3149. if (ret)
  3150. dev_err(adap->pdev_dev, "firmware download failed, error %d\n",
  3151. ret);
  3152. else
  3153. ret = t4_get_fw_version(adap, &adap->params.fw_vers);
  3154. return ret;
  3155. }
  3156. /**
  3157. * t4_phy_fw_ver - return current PHY firmware version
  3158. * @adap: the adapter
  3159. * @phy_fw_ver: return value buffer for PHY firmware version
  3160. *
  3161. * Returns the current version of external PHY firmware on the
  3162. * adapter.
  3163. */
  3164. int t4_phy_fw_ver(struct adapter *adap, int *phy_fw_ver)
  3165. {
  3166. u32 param, val;
  3167. int ret;
  3168. param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3169. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PHYFW) |
  3170. FW_PARAMS_PARAM_Y_V(adap->params.portvec) |
  3171. FW_PARAMS_PARAM_Z_V(FW_PARAMS_PARAM_DEV_PHYFW_VERSION));
  3172. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
  3173. &param, &val);
  3174. if (ret < 0)
  3175. return ret;
  3176. *phy_fw_ver = val;
  3177. return 0;
  3178. }
  3179. /**
  3180. * t4_load_phy_fw - download port PHY firmware
  3181. * @adap: the adapter
  3182. * @win: the PCI-E Memory Window index to use for t4_memory_rw()
  3183. * @win_lock: the lock to use to guard the memory copy
  3184. * @phy_fw_version: function to check PHY firmware versions
  3185. * @phy_fw_data: the PHY firmware image to write
  3186. * @phy_fw_size: image size
  3187. *
  3188. * Transfer the specified PHY firmware to the adapter. If a non-NULL
  3189. * @phy_fw_version is supplied, then it will be used to determine if
  3190. * it's necessary to perform the transfer by comparing the version
  3191. * of any existing adapter PHY firmware with that of the passed in
  3192. * PHY firmware image. If @win_lock is non-NULL then it will be used
  3193. * around the call to t4_memory_rw() which transfers the PHY firmware
  3194. * to the adapter.
  3195. *
  3196. * A negative error number will be returned if an error occurs. If
  3197. * version number support is available and there's no need to upgrade
  3198. * the firmware, 0 will be returned. If firmware is successfully
  3199. * transferred to the adapter, 1 will be retured.
  3200. *
  3201. * NOTE: some adapters only have local RAM to store the PHY firmware. As
  3202. * a result, a RESET of the adapter would cause that RAM to lose its
  3203. * contents. Thus, loading PHY firmware on such adapters must happen
  3204. * after any FW_RESET_CMDs ...
  3205. */
  3206. int t4_load_phy_fw(struct adapter *adap,
  3207. int win, spinlock_t *win_lock,
  3208. int (*phy_fw_version)(const u8 *, size_t),
  3209. const u8 *phy_fw_data, size_t phy_fw_size)
  3210. {
  3211. unsigned long mtype = 0, maddr = 0;
  3212. u32 param, val;
  3213. int cur_phy_fw_ver = 0, new_phy_fw_vers = 0;
  3214. int ret;
  3215. /* If we have version number support, then check to see if the adapter
  3216. * already has up-to-date PHY firmware loaded.
  3217. */
  3218. if (phy_fw_version) {
  3219. new_phy_fw_vers = phy_fw_version(phy_fw_data, phy_fw_size);
  3220. ret = t4_phy_fw_ver(adap, &cur_phy_fw_ver);
  3221. if (ret < 0)
  3222. return ret;
  3223. if (cur_phy_fw_ver >= new_phy_fw_vers) {
  3224. CH_WARN(adap, "PHY Firmware already up-to-date, "
  3225. "version %#x\n", cur_phy_fw_ver);
  3226. return 0;
  3227. }
  3228. }
  3229. /* Ask the firmware where it wants us to copy the PHY firmware image.
  3230. * The size of the file requires a special version of the READ coommand
  3231. * which will pass the file size via the values field in PARAMS_CMD and
  3232. * retrieve the return value from firmware and place it in the same
  3233. * buffer values
  3234. */
  3235. param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3236. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PHYFW) |
  3237. FW_PARAMS_PARAM_Y_V(adap->params.portvec) |
  3238. FW_PARAMS_PARAM_Z_V(FW_PARAMS_PARAM_DEV_PHYFW_DOWNLOAD));
  3239. val = phy_fw_size;
  3240. ret = t4_query_params_rw(adap, adap->mbox, adap->pf, 0, 1,
  3241. &param, &val, 1);
  3242. if (ret < 0)
  3243. return ret;
  3244. mtype = val >> 8;
  3245. maddr = (val & 0xff) << 16;
  3246. /* Copy the supplied PHY Firmware image to the adapter memory location
  3247. * allocated by the adapter firmware.
  3248. */
  3249. if (win_lock)
  3250. spin_lock_bh(win_lock);
  3251. ret = t4_memory_rw(adap, win, mtype, maddr,
  3252. phy_fw_size, (__be32 *)phy_fw_data,
  3253. T4_MEMORY_WRITE);
  3254. if (win_lock)
  3255. spin_unlock_bh(win_lock);
  3256. if (ret)
  3257. return ret;
  3258. /* Tell the firmware that the PHY firmware image has been written to
  3259. * RAM and it can now start copying it over to the PHYs. The chip
  3260. * firmware will RESET the affected PHYs as part of this operation
  3261. * leaving them running the new PHY firmware image.
  3262. */
  3263. param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3264. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PHYFW) |
  3265. FW_PARAMS_PARAM_Y_V(adap->params.portvec) |
  3266. FW_PARAMS_PARAM_Z_V(FW_PARAMS_PARAM_DEV_PHYFW_DOWNLOAD));
  3267. ret = t4_set_params_timeout(adap, adap->mbox, adap->pf, 0, 1,
  3268. &param, &val, 30000);
  3269. /* If we have version number support, then check to see that the new
  3270. * firmware got loaded properly.
  3271. */
  3272. if (phy_fw_version) {
  3273. ret = t4_phy_fw_ver(adap, &cur_phy_fw_ver);
  3274. if (ret < 0)
  3275. return ret;
  3276. if (cur_phy_fw_ver != new_phy_fw_vers) {
  3277. CH_WARN(adap, "PHY Firmware did not update: "
  3278. "version on adapter %#x, "
  3279. "version flashed %#x\n",
  3280. cur_phy_fw_ver, new_phy_fw_vers);
  3281. return -ENXIO;
  3282. }
  3283. }
  3284. return 1;
  3285. }
  3286. /**
  3287. * t4_fwcache - firmware cache operation
  3288. * @adap: the adapter
  3289. * @op : the operation (flush or flush and invalidate)
  3290. */
  3291. int t4_fwcache(struct adapter *adap, enum fw_params_param_dev_fwcache op)
  3292. {
  3293. struct fw_params_cmd c;
  3294. memset(&c, 0, sizeof(c));
  3295. c.op_to_vfn =
  3296. cpu_to_be32(FW_CMD_OP_V(FW_PARAMS_CMD) |
  3297. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  3298. FW_PARAMS_CMD_PFN_V(adap->pf) |
  3299. FW_PARAMS_CMD_VFN_V(0));
  3300. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  3301. c.param[0].mnem =
  3302. cpu_to_be32(FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3303. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_FWCACHE));
  3304. c.param[0].val = (__force __be32)op;
  3305. return t4_wr_mbox(adap, adap->mbox, &c, sizeof(c), NULL);
  3306. }
  3307. void t4_cim_read_pif_la(struct adapter *adap, u32 *pif_req, u32 *pif_rsp,
  3308. unsigned int *pif_req_wrptr,
  3309. unsigned int *pif_rsp_wrptr)
  3310. {
  3311. int i, j;
  3312. u32 cfg, val, req, rsp;
  3313. cfg = t4_read_reg(adap, CIM_DEBUGCFG_A);
  3314. if (cfg & LADBGEN_F)
  3315. t4_write_reg(adap, CIM_DEBUGCFG_A, cfg ^ LADBGEN_F);
  3316. val = t4_read_reg(adap, CIM_DEBUGSTS_A);
  3317. req = POLADBGWRPTR_G(val);
  3318. rsp = PILADBGWRPTR_G(val);
  3319. if (pif_req_wrptr)
  3320. *pif_req_wrptr = req;
  3321. if (pif_rsp_wrptr)
  3322. *pif_rsp_wrptr = rsp;
  3323. for (i = 0; i < CIM_PIFLA_SIZE; i++) {
  3324. for (j = 0; j < 6; j++) {
  3325. t4_write_reg(adap, CIM_DEBUGCFG_A, POLADBGRDPTR_V(req) |
  3326. PILADBGRDPTR_V(rsp));
  3327. *pif_req++ = t4_read_reg(adap, CIM_PO_LA_DEBUGDATA_A);
  3328. *pif_rsp++ = t4_read_reg(adap, CIM_PI_LA_DEBUGDATA_A);
  3329. req++;
  3330. rsp++;
  3331. }
  3332. req = (req + 2) & POLADBGRDPTR_M;
  3333. rsp = (rsp + 2) & PILADBGRDPTR_M;
  3334. }
  3335. t4_write_reg(adap, CIM_DEBUGCFG_A, cfg);
  3336. }
  3337. void t4_cim_read_ma_la(struct adapter *adap, u32 *ma_req, u32 *ma_rsp)
  3338. {
  3339. u32 cfg;
  3340. int i, j, idx;
  3341. cfg = t4_read_reg(adap, CIM_DEBUGCFG_A);
  3342. if (cfg & LADBGEN_F)
  3343. t4_write_reg(adap, CIM_DEBUGCFG_A, cfg ^ LADBGEN_F);
  3344. for (i = 0; i < CIM_MALA_SIZE; i++) {
  3345. for (j = 0; j < 5; j++) {
  3346. idx = 8 * i + j;
  3347. t4_write_reg(adap, CIM_DEBUGCFG_A, POLADBGRDPTR_V(idx) |
  3348. PILADBGRDPTR_V(idx));
  3349. *ma_req++ = t4_read_reg(adap, CIM_PO_LA_MADEBUGDATA_A);
  3350. *ma_rsp++ = t4_read_reg(adap, CIM_PI_LA_MADEBUGDATA_A);
  3351. }
  3352. }
  3353. t4_write_reg(adap, CIM_DEBUGCFG_A, cfg);
  3354. }
  3355. void t4_ulprx_read_la(struct adapter *adap, u32 *la_buf)
  3356. {
  3357. unsigned int i, j;
  3358. for (i = 0; i < 8; i++) {
  3359. u32 *p = la_buf + i;
  3360. t4_write_reg(adap, ULP_RX_LA_CTL_A, i);
  3361. j = t4_read_reg(adap, ULP_RX_LA_WRPTR_A);
  3362. t4_write_reg(adap, ULP_RX_LA_RDPTR_A, j);
  3363. for (j = 0; j < ULPRX_LA_SIZE; j++, p += 8)
  3364. *p = t4_read_reg(adap, ULP_RX_LA_RDDATA_A);
  3365. }
  3366. }
  3367. #define ADVERT_MASK (FW_PORT_CAP_SPEED_100M | FW_PORT_CAP_SPEED_1G |\
  3368. FW_PORT_CAP_SPEED_10G | FW_PORT_CAP_SPEED_40G | \
  3369. FW_PORT_CAP_ANEG)
  3370. /**
  3371. * t4_link_l1cfg - apply link configuration to MAC/PHY
  3372. * @phy: the PHY to setup
  3373. * @mac: the MAC to setup
  3374. * @lc: the requested link configuration
  3375. *
  3376. * Set up a port's MAC and PHY according to a desired link configuration.
  3377. * - If the PHY can auto-negotiate first decide what to advertise, then
  3378. * enable/disable auto-negotiation as desired, and reset.
  3379. * - If the PHY does not auto-negotiate just reset it.
  3380. * - If auto-negotiation is off set the MAC to the proper speed/duplex/FC,
  3381. * otherwise do it later based on the outcome of auto-negotiation.
  3382. */
  3383. int t4_link_l1cfg(struct adapter *adap, unsigned int mbox, unsigned int port,
  3384. struct link_config *lc)
  3385. {
  3386. struct fw_port_cmd c;
  3387. unsigned int fc = 0, mdi = FW_PORT_CAP_MDI_V(FW_PORT_CAP_MDI_AUTO);
  3388. lc->link_ok = 0;
  3389. if (lc->requested_fc & PAUSE_RX)
  3390. fc |= FW_PORT_CAP_FC_RX;
  3391. if (lc->requested_fc & PAUSE_TX)
  3392. fc |= FW_PORT_CAP_FC_TX;
  3393. memset(&c, 0, sizeof(c));
  3394. c.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
  3395. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  3396. FW_PORT_CMD_PORTID_V(port));
  3397. c.action_to_len16 =
  3398. cpu_to_be32(FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_L1_CFG) |
  3399. FW_LEN16(c));
  3400. if (!(lc->supported & FW_PORT_CAP_ANEG)) {
  3401. c.u.l1cfg.rcap = cpu_to_be32((lc->supported & ADVERT_MASK) |
  3402. fc);
  3403. lc->fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
  3404. } else if (lc->autoneg == AUTONEG_DISABLE) {
  3405. c.u.l1cfg.rcap = cpu_to_be32(lc->requested_speed | fc | mdi);
  3406. lc->fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
  3407. } else
  3408. c.u.l1cfg.rcap = cpu_to_be32(lc->advertising | fc | mdi);
  3409. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  3410. }
  3411. /**
  3412. * t4_restart_aneg - restart autonegotiation
  3413. * @adap: the adapter
  3414. * @mbox: mbox to use for the FW command
  3415. * @port: the port id
  3416. *
  3417. * Restarts autonegotiation for the selected port.
  3418. */
  3419. int t4_restart_aneg(struct adapter *adap, unsigned int mbox, unsigned int port)
  3420. {
  3421. struct fw_port_cmd c;
  3422. memset(&c, 0, sizeof(c));
  3423. c.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
  3424. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  3425. FW_PORT_CMD_PORTID_V(port));
  3426. c.action_to_len16 =
  3427. cpu_to_be32(FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_L1_CFG) |
  3428. FW_LEN16(c));
  3429. c.u.l1cfg.rcap = cpu_to_be32(FW_PORT_CAP_ANEG);
  3430. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  3431. }
  3432. typedef void (*int_handler_t)(struct adapter *adap);
  3433. struct intr_info {
  3434. unsigned int mask; /* bits to check in interrupt status */
  3435. const char *msg; /* message to print or NULL */
  3436. short stat_idx; /* stat counter to increment or -1 */
  3437. unsigned short fatal; /* whether the condition reported is fatal */
  3438. int_handler_t int_handler; /* platform-specific int handler */
  3439. };
  3440. /**
  3441. * t4_handle_intr_status - table driven interrupt handler
  3442. * @adapter: the adapter that generated the interrupt
  3443. * @reg: the interrupt status register to process
  3444. * @acts: table of interrupt actions
  3445. *
  3446. * A table driven interrupt handler that applies a set of masks to an
  3447. * interrupt status word and performs the corresponding actions if the
  3448. * interrupts described by the mask have occurred. The actions include
  3449. * optionally emitting a warning or alert message. The table is terminated
  3450. * by an entry specifying mask 0. Returns the number of fatal interrupt
  3451. * conditions.
  3452. */
  3453. static int t4_handle_intr_status(struct adapter *adapter, unsigned int reg,
  3454. const struct intr_info *acts)
  3455. {
  3456. int fatal = 0;
  3457. unsigned int mask = 0;
  3458. unsigned int status = t4_read_reg(adapter, reg);
  3459. for ( ; acts->mask; ++acts) {
  3460. if (!(status & acts->mask))
  3461. continue;
  3462. if (acts->fatal) {
  3463. fatal++;
  3464. dev_alert(adapter->pdev_dev, "%s (0x%x)\n", acts->msg,
  3465. status & acts->mask);
  3466. } else if (acts->msg && printk_ratelimit())
  3467. dev_warn(adapter->pdev_dev, "%s (0x%x)\n", acts->msg,
  3468. status & acts->mask);
  3469. if (acts->int_handler)
  3470. acts->int_handler(adapter);
  3471. mask |= acts->mask;
  3472. }
  3473. status &= mask;
  3474. if (status) /* clear processed interrupts */
  3475. t4_write_reg(adapter, reg, status);
  3476. return fatal;
  3477. }
  3478. /*
  3479. * Interrupt handler for the PCIE module.
  3480. */
  3481. static void pcie_intr_handler(struct adapter *adapter)
  3482. {
  3483. static const struct intr_info sysbus_intr_info[] = {
  3484. { RNPP_F, "RXNP array parity error", -1, 1 },
  3485. { RPCP_F, "RXPC array parity error", -1, 1 },
  3486. { RCIP_F, "RXCIF array parity error", -1, 1 },
  3487. { RCCP_F, "Rx completions control array parity error", -1, 1 },
  3488. { RFTP_F, "RXFT array parity error", -1, 1 },
  3489. { 0 }
  3490. };
  3491. static const struct intr_info pcie_port_intr_info[] = {
  3492. { TPCP_F, "TXPC array parity error", -1, 1 },
  3493. { TNPP_F, "TXNP array parity error", -1, 1 },
  3494. { TFTP_F, "TXFT array parity error", -1, 1 },
  3495. { TCAP_F, "TXCA array parity error", -1, 1 },
  3496. { TCIP_F, "TXCIF array parity error", -1, 1 },
  3497. { RCAP_F, "RXCA array parity error", -1, 1 },
  3498. { OTDD_F, "outbound request TLP discarded", -1, 1 },
  3499. { RDPE_F, "Rx data parity error", -1, 1 },
  3500. { TDUE_F, "Tx uncorrectable data error", -1, 1 },
  3501. { 0 }
  3502. };
  3503. static const struct intr_info pcie_intr_info[] = {
  3504. { MSIADDRLPERR_F, "MSI AddrL parity error", -1, 1 },
  3505. { MSIADDRHPERR_F, "MSI AddrH parity error", -1, 1 },
  3506. { MSIDATAPERR_F, "MSI data parity error", -1, 1 },
  3507. { MSIXADDRLPERR_F, "MSI-X AddrL parity error", -1, 1 },
  3508. { MSIXADDRHPERR_F, "MSI-X AddrH parity error", -1, 1 },
  3509. { MSIXDATAPERR_F, "MSI-X data parity error", -1, 1 },
  3510. { MSIXDIPERR_F, "MSI-X DI parity error", -1, 1 },
  3511. { PIOCPLPERR_F, "PCI PIO completion FIFO parity error", -1, 1 },
  3512. { PIOREQPERR_F, "PCI PIO request FIFO parity error", -1, 1 },
  3513. { TARTAGPERR_F, "PCI PCI target tag FIFO parity error", -1, 1 },
  3514. { CCNTPERR_F, "PCI CMD channel count parity error", -1, 1 },
  3515. { CREQPERR_F, "PCI CMD channel request parity error", -1, 1 },
  3516. { CRSPPERR_F, "PCI CMD channel response parity error", -1, 1 },
  3517. { DCNTPERR_F, "PCI DMA channel count parity error", -1, 1 },
  3518. { DREQPERR_F, "PCI DMA channel request parity error", -1, 1 },
  3519. { DRSPPERR_F, "PCI DMA channel response parity error", -1, 1 },
  3520. { HCNTPERR_F, "PCI HMA channel count parity error", -1, 1 },
  3521. { HREQPERR_F, "PCI HMA channel request parity error", -1, 1 },
  3522. { HRSPPERR_F, "PCI HMA channel response parity error", -1, 1 },
  3523. { CFGSNPPERR_F, "PCI config snoop FIFO parity error", -1, 1 },
  3524. { FIDPERR_F, "PCI FID parity error", -1, 1 },
  3525. { INTXCLRPERR_F, "PCI INTx clear parity error", -1, 1 },
  3526. { MATAGPERR_F, "PCI MA tag parity error", -1, 1 },
  3527. { PIOTAGPERR_F, "PCI PIO tag parity error", -1, 1 },
  3528. { RXCPLPERR_F, "PCI Rx completion parity error", -1, 1 },
  3529. { RXWRPERR_F, "PCI Rx write parity error", -1, 1 },
  3530. { RPLPERR_F, "PCI replay buffer parity error", -1, 1 },
  3531. { PCIESINT_F, "PCI core secondary fault", -1, 1 },
  3532. { PCIEPINT_F, "PCI core primary fault", -1, 1 },
  3533. { UNXSPLCPLERR_F, "PCI unexpected split completion error",
  3534. -1, 0 },
  3535. { 0 }
  3536. };
  3537. static struct intr_info t5_pcie_intr_info[] = {
  3538. { MSTGRPPERR_F, "Master Response Read Queue parity error",
  3539. -1, 1 },
  3540. { MSTTIMEOUTPERR_F, "Master Timeout FIFO parity error", -1, 1 },
  3541. { MSIXSTIPERR_F, "MSI-X STI SRAM parity error", -1, 1 },
  3542. { MSIXADDRLPERR_F, "MSI-X AddrL parity error", -1, 1 },
  3543. { MSIXADDRHPERR_F, "MSI-X AddrH parity error", -1, 1 },
  3544. { MSIXDATAPERR_F, "MSI-X data parity error", -1, 1 },
  3545. { MSIXDIPERR_F, "MSI-X DI parity error", -1, 1 },
  3546. { PIOCPLGRPPERR_F, "PCI PIO completion Group FIFO parity error",
  3547. -1, 1 },
  3548. { PIOREQGRPPERR_F, "PCI PIO request Group FIFO parity error",
  3549. -1, 1 },
  3550. { TARTAGPERR_F, "PCI PCI target tag FIFO parity error", -1, 1 },
  3551. { MSTTAGQPERR_F, "PCI master tag queue parity error", -1, 1 },
  3552. { CREQPERR_F, "PCI CMD channel request parity error", -1, 1 },
  3553. { CRSPPERR_F, "PCI CMD channel response parity error", -1, 1 },
  3554. { DREQWRPERR_F, "PCI DMA channel write request parity error",
  3555. -1, 1 },
  3556. { DREQPERR_F, "PCI DMA channel request parity error", -1, 1 },
  3557. { DRSPPERR_F, "PCI DMA channel response parity error", -1, 1 },
  3558. { HREQWRPERR_F, "PCI HMA channel count parity error", -1, 1 },
  3559. { HREQPERR_F, "PCI HMA channel request parity error", -1, 1 },
  3560. { HRSPPERR_F, "PCI HMA channel response parity error", -1, 1 },
  3561. { CFGSNPPERR_F, "PCI config snoop FIFO parity error", -1, 1 },
  3562. { FIDPERR_F, "PCI FID parity error", -1, 1 },
  3563. { VFIDPERR_F, "PCI INTx clear parity error", -1, 1 },
  3564. { MAGRPPERR_F, "PCI MA group FIFO parity error", -1, 1 },
  3565. { PIOTAGPERR_F, "PCI PIO tag parity error", -1, 1 },
  3566. { IPRXHDRGRPPERR_F, "PCI IP Rx header group parity error",
  3567. -1, 1 },
  3568. { IPRXDATAGRPPERR_F, "PCI IP Rx data group parity error",
  3569. -1, 1 },
  3570. { RPLPERR_F, "PCI IP replay buffer parity error", -1, 1 },
  3571. { IPSOTPERR_F, "PCI IP SOT buffer parity error", -1, 1 },
  3572. { TRGT1GRPPERR_F, "PCI TRGT1 group FIFOs parity error", -1, 1 },
  3573. { READRSPERR_F, "Outbound read error", -1, 0 },
  3574. { 0 }
  3575. };
  3576. int fat;
  3577. if (is_t4(adapter->params.chip))
  3578. fat = t4_handle_intr_status(adapter,
  3579. PCIE_CORE_UTL_SYSTEM_BUS_AGENT_STATUS_A,
  3580. sysbus_intr_info) +
  3581. t4_handle_intr_status(adapter,
  3582. PCIE_CORE_UTL_PCI_EXPRESS_PORT_STATUS_A,
  3583. pcie_port_intr_info) +
  3584. t4_handle_intr_status(adapter, PCIE_INT_CAUSE_A,
  3585. pcie_intr_info);
  3586. else
  3587. fat = t4_handle_intr_status(adapter, PCIE_INT_CAUSE_A,
  3588. t5_pcie_intr_info);
  3589. if (fat)
  3590. t4_fatal_err(adapter);
  3591. }
  3592. /*
  3593. * TP interrupt handler.
  3594. */
  3595. static void tp_intr_handler(struct adapter *adapter)
  3596. {
  3597. static const struct intr_info tp_intr_info[] = {
  3598. { 0x3fffffff, "TP parity error", -1, 1 },
  3599. { FLMTXFLSTEMPTY_F, "TP out of Tx pages", -1, 1 },
  3600. { 0 }
  3601. };
  3602. if (t4_handle_intr_status(adapter, TP_INT_CAUSE_A, tp_intr_info))
  3603. t4_fatal_err(adapter);
  3604. }
  3605. /*
  3606. * SGE interrupt handler.
  3607. */
  3608. static void sge_intr_handler(struct adapter *adapter)
  3609. {
  3610. u64 v;
  3611. u32 err;
  3612. static const struct intr_info sge_intr_info[] = {
  3613. { ERR_CPL_EXCEED_IQE_SIZE_F,
  3614. "SGE received CPL exceeding IQE size", -1, 1 },
  3615. { ERR_INVALID_CIDX_INC_F,
  3616. "SGE GTS CIDX increment too large", -1, 0 },
  3617. { ERR_CPL_OPCODE_0_F, "SGE received 0-length CPL", -1, 0 },
  3618. { DBFIFO_LP_INT_F, NULL, -1, 0, t4_db_full },
  3619. { ERR_DATA_CPL_ON_HIGH_QID1_F | ERR_DATA_CPL_ON_HIGH_QID0_F,
  3620. "SGE IQID > 1023 received CPL for FL", -1, 0 },
  3621. { ERR_BAD_DB_PIDX3_F, "SGE DBP 3 pidx increment too large", -1,
  3622. 0 },
  3623. { ERR_BAD_DB_PIDX2_F, "SGE DBP 2 pidx increment too large", -1,
  3624. 0 },
  3625. { ERR_BAD_DB_PIDX1_F, "SGE DBP 1 pidx increment too large", -1,
  3626. 0 },
  3627. { ERR_BAD_DB_PIDX0_F, "SGE DBP 0 pidx increment too large", -1,
  3628. 0 },
  3629. { ERR_ING_CTXT_PRIO_F,
  3630. "SGE too many priority ingress contexts", -1, 0 },
  3631. { INGRESS_SIZE_ERR_F, "SGE illegal ingress QID", -1, 0 },
  3632. { EGRESS_SIZE_ERR_F, "SGE illegal egress QID", -1, 0 },
  3633. { 0 }
  3634. };
  3635. static struct intr_info t4t5_sge_intr_info[] = {
  3636. { ERR_DROPPED_DB_F, NULL, -1, 0, t4_db_dropped },
  3637. { DBFIFO_HP_INT_F, NULL, -1, 0, t4_db_full },
  3638. { ERR_EGR_CTXT_PRIO_F,
  3639. "SGE too many priority egress contexts", -1, 0 },
  3640. { 0 }
  3641. };
  3642. v = (u64)t4_read_reg(adapter, SGE_INT_CAUSE1_A) |
  3643. ((u64)t4_read_reg(adapter, SGE_INT_CAUSE2_A) << 32);
  3644. if (v) {
  3645. dev_alert(adapter->pdev_dev, "SGE parity error (%#llx)\n",
  3646. (unsigned long long)v);
  3647. t4_write_reg(adapter, SGE_INT_CAUSE1_A, v);
  3648. t4_write_reg(adapter, SGE_INT_CAUSE2_A, v >> 32);
  3649. }
  3650. v |= t4_handle_intr_status(adapter, SGE_INT_CAUSE3_A, sge_intr_info);
  3651. if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
  3652. v |= t4_handle_intr_status(adapter, SGE_INT_CAUSE3_A,
  3653. t4t5_sge_intr_info);
  3654. err = t4_read_reg(adapter, SGE_ERROR_STATS_A);
  3655. if (err & ERROR_QID_VALID_F) {
  3656. dev_err(adapter->pdev_dev, "SGE error for queue %u\n",
  3657. ERROR_QID_G(err));
  3658. if (err & UNCAPTURED_ERROR_F)
  3659. dev_err(adapter->pdev_dev,
  3660. "SGE UNCAPTURED_ERROR set (clearing)\n");
  3661. t4_write_reg(adapter, SGE_ERROR_STATS_A, ERROR_QID_VALID_F |
  3662. UNCAPTURED_ERROR_F);
  3663. }
  3664. if (v != 0)
  3665. t4_fatal_err(adapter);
  3666. }
  3667. #define CIM_OBQ_INTR (OBQULP0PARERR_F | OBQULP1PARERR_F | OBQULP2PARERR_F |\
  3668. OBQULP3PARERR_F | OBQSGEPARERR_F | OBQNCSIPARERR_F)
  3669. #define CIM_IBQ_INTR (IBQTP0PARERR_F | IBQTP1PARERR_F | IBQULPPARERR_F |\
  3670. IBQSGEHIPARERR_F | IBQSGELOPARERR_F | IBQNCSIPARERR_F)
  3671. /*
  3672. * CIM interrupt handler.
  3673. */
  3674. static void cim_intr_handler(struct adapter *adapter)
  3675. {
  3676. static const struct intr_info cim_intr_info[] = {
  3677. { PREFDROPINT_F, "CIM control register prefetch drop", -1, 1 },
  3678. { CIM_OBQ_INTR, "CIM OBQ parity error", -1, 1 },
  3679. { CIM_IBQ_INTR, "CIM IBQ parity error", -1, 1 },
  3680. { MBUPPARERR_F, "CIM mailbox uP parity error", -1, 1 },
  3681. { MBHOSTPARERR_F, "CIM mailbox host parity error", -1, 1 },
  3682. { TIEQINPARERRINT_F, "CIM TIEQ outgoing parity error", -1, 1 },
  3683. { TIEQOUTPARERRINT_F, "CIM TIEQ incoming parity error", -1, 1 },
  3684. { 0 }
  3685. };
  3686. static const struct intr_info cim_upintr_info[] = {
  3687. { RSVDSPACEINT_F, "CIM reserved space access", -1, 1 },
  3688. { ILLTRANSINT_F, "CIM illegal transaction", -1, 1 },
  3689. { ILLWRINT_F, "CIM illegal write", -1, 1 },
  3690. { ILLRDINT_F, "CIM illegal read", -1, 1 },
  3691. { ILLRDBEINT_F, "CIM illegal read BE", -1, 1 },
  3692. { ILLWRBEINT_F, "CIM illegal write BE", -1, 1 },
  3693. { SGLRDBOOTINT_F, "CIM single read from boot space", -1, 1 },
  3694. { SGLWRBOOTINT_F, "CIM single write to boot space", -1, 1 },
  3695. { BLKWRBOOTINT_F, "CIM block write to boot space", -1, 1 },
  3696. { SGLRDFLASHINT_F, "CIM single read from flash space", -1, 1 },
  3697. { SGLWRFLASHINT_F, "CIM single write to flash space", -1, 1 },
  3698. { BLKWRFLASHINT_F, "CIM block write to flash space", -1, 1 },
  3699. { SGLRDEEPROMINT_F, "CIM single EEPROM read", -1, 1 },
  3700. { SGLWREEPROMINT_F, "CIM single EEPROM write", -1, 1 },
  3701. { BLKRDEEPROMINT_F, "CIM block EEPROM read", -1, 1 },
  3702. { BLKWREEPROMINT_F, "CIM block EEPROM write", -1, 1 },
  3703. { SGLRDCTLINT_F, "CIM single read from CTL space", -1, 1 },
  3704. { SGLWRCTLINT_F, "CIM single write to CTL space", -1, 1 },
  3705. { BLKRDCTLINT_F, "CIM block read from CTL space", -1, 1 },
  3706. { BLKWRCTLINT_F, "CIM block write to CTL space", -1, 1 },
  3707. { SGLRDPLINT_F, "CIM single read from PL space", -1, 1 },
  3708. { SGLWRPLINT_F, "CIM single write to PL space", -1, 1 },
  3709. { BLKRDPLINT_F, "CIM block read from PL space", -1, 1 },
  3710. { BLKWRPLINT_F, "CIM block write to PL space", -1, 1 },
  3711. { REQOVRLOOKUPINT_F, "CIM request FIFO overwrite", -1, 1 },
  3712. { RSPOVRLOOKUPINT_F, "CIM response FIFO overwrite", -1, 1 },
  3713. { TIMEOUTINT_F, "CIM PIF timeout", -1, 1 },
  3714. { TIMEOUTMAINT_F, "CIM PIF MA timeout", -1, 1 },
  3715. { 0 }
  3716. };
  3717. int fat;
  3718. if (t4_read_reg(adapter, PCIE_FW_A) & PCIE_FW_ERR_F)
  3719. t4_report_fw_error(adapter);
  3720. fat = t4_handle_intr_status(adapter, CIM_HOST_INT_CAUSE_A,
  3721. cim_intr_info) +
  3722. t4_handle_intr_status(adapter, CIM_HOST_UPACC_INT_CAUSE_A,
  3723. cim_upintr_info);
  3724. if (fat)
  3725. t4_fatal_err(adapter);
  3726. }
  3727. /*
  3728. * ULP RX interrupt handler.
  3729. */
  3730. static void ulprx_intr_handler(struct adapter *adapter)
  3731. {
  3732. static const struct intr_info ulprx_intr_info[] = {
  3733. { 0x1800000, "ULPRX context error", -1, 1 },
  3734. { 0x7fffff, "ULPRX parity error", -1, 1 },
  3735. { 0 }
  3736. };
  3737. if (t4_handle_intr_status(adapter, ULP_RX_INT_CAUSE_A, ulprx_intr_info))
  3738. t4_fatal_err(adapter);
  3739. }
  3740. /*
  3741. * ULP TX interrupt handler.
  3742. */
  3743. static void ulptx_intr_handler(struct adapter *adapter)
  3744. {
  3745. static const struct intr_info ulptx_intr_info[] = {
  3746. { PBL_BOUND_ERR_CH3_F, "ULPTX channel 3 PBL out of bounds", -1,
  3747. 0 },
  3748. { PBL_BOUND_ERR_CH2_F, "ULPTX channel 2 PBL out of bounds", -1,
  3749. 0 },
  3750. { PBL_BOUND_ERR_CH1_F, "ULPTX channel 1 PBL out of bounds", -1,
  3751. 0 },
  3752. { PBL_BOUND_ERR_CH0_F, "ULPTX channel 0 PBL out of bounds", -1,
  3753. 0 },
  3754. { 0xfffffff, "ULPTX parity error", -1, 1 },
  3755. { 0 }
  3756. };
  3757. if (t4_handle_intr_status(adapter, ULP_TX_INT_CAUSE_A, ulptx_intr_info))
  3758. t4_fatal_err(adapter);
  3759. }
  3760. /*
  3761. * PM TX interrupt handler.
  3762. */
  3763. static void pmtx_intr_handler(struct adapter *adapter)
  3764. {
  3765. static const struct intr_info pmtx_intr_info[] = {
  3766. { PCMD_LEN_OVFL0_F, "PMTX channel 0 pcmd too large", -1, 1 },
  3767. { PCMD_LEN_OVFL1_F, "PMTX channel 1 pcmd too large", -1, 1 },
  3768. { PCMD_LEN_OVFL2_F, "PMTX channel 2 pcmd too large", -1, 1 },
  3769. { ZERO_C_CMD_ERROR_F, "PMTX 0-length pcmd", -1, 1 },
  3770. { PMTX_FRAMING_ERROR_F, "PMTX framing error", -1, 1 },
  3771. { OESPI_PAR_ERROR_F, "PMTX oespi parity error", -1, 1 },
  3772. { DB_OPTIONS_PAR_ERROR_F, "PMTX db_options parity error",
  3773. -1, 1 },
  3774. { ICSPI_PAR_ERROR_F, "PMTX icspi parity error", -1, 1 },
  3775. { PMTX_C_PCMD_PAR_ERROR_F, "PMTX c_pcmd parity error", -1, 1},
  3776. { 0 }
  3777. };
  3778. if (t4_handle_intr_status(adapter, PM_TX_INT_CAUSE_A, pmtx_intr_info))
  3779. t4_fatal_err(adapter);
  3780. }
  3781. /*
  3782. * PM RX interrupt handler.
  3783. */
  3784. static void pmrx_intr_handler(struct adapter *adapter)
  3785. {
  3786. static const struct intr_info pmrx_intr_info[] = {
  3787. { ZERO_E_CMD_ERROR_F, "PMRX 0-length pcmd", -1, 1 },
  3788. { PMRX_FRAMING_ERROR_F, "PMRX framing error", -1, 1 },
  3789. { OCSPI_PAR_ERROR_F, "PMRX ocspi parity error", -1, 1 },
  3790. { DB_OPTIONS_PAR_ERROR_F, "PMRX db_options parity error",
  3791. -1, 1 },
  3792. { IESPI_PAR_ERROR_F, "PMRX iespi parity error", -1, 1 },
  3793. { PMRX_E_PCMD_PAR_ERROR_F, "PMRX e_pcmd parity error", -1, 1},
  3794. { 0 }
  3795. };
  3796. if (t4_handle_intr_status(adapter, PM_RX_INT_CAUSE_A, pmrx_intr_info))
  3797. t4_fatal_err(adapter);
  3798. }
  3799. /*
  3800. * CPL switch interrupt handler.
  3801. */
  3802. static void cplsw_intr_handler(struct adapter *adapter)
  3803. {
  3804. static const struct intr_info cplsw_intr_info[] = {
  3805. { CIM_OP_MAP_PERR_F, "CPLSW CIM op_map parity error", -1, 1 },
  3806. { CIM_OVFL_ERROR_F, "CPLSW CIM overflow", -1, 1 },
  3807. { TP_FRAMING_ERROR_F, "CPLSW TP framing error", -1, 1 },
  3808. { SGE_FRAMING_ERROR_F, "CPLSW SGE framing error", -1, 1 },
  3809. { CIM_FRAMING_ERROR_F, "CPLSW CIM framing error", -1, 1 },
  3810. { ZERO_SWITCH_ERROR_F, "CPLSW no-switch error", -1, 1 },
  3811. { 0 }
  3812. };
  3813. if (t4_handle_intr_status(adapter, CPL_INTR_CAUSE_A, cplsw_intr_info))
  3814. t4_fatal_err(adapter);
  3815. }
  3816. /*
  3817. * LE interrupt handler.
  3818. */
  3819. static void le_intr_handler(struct adapter *adap)
  3820. {
  3821. enum chip_type chip = CHELSIO_CHIP_VERSION(adap->params.chip);
  3822. static const struct intr_info le_intr_info[] = {
  3823. { LIPMISS_F, "LE LIP miss", -1, 0 },
  3824. { LIP0_F, "LE 0 LIP error", -1, 0 },
  3825. { PARITYERR_F, "LE parity error", -1, 1 },
  3826. { UNKNOWNCMD_F, "LE unknown command", -1, 1 },
  3827. { REQQPARERR_F, "LE request queue parity error", -1, 1 },
  3828. { 0 }
  3829. };
  3830. static struct intr_info t6_le_intr_info[] = {
  3831. { T6_LIPMISS_F, "LE LIP miss", -1, 0 },
  3832. { T6_LIP0_F, "LE 0 LIP error", -1, 0 },
  3833. { TCAMINTPERR_F, "LE parity error", -1, 1 },
  3834. { T6_UNKNOWNCMD_F, "LE unknown command", -1, 1 },
  3835. { SSRAMINTPERR_F, "LE request queue parity error", -1, 1 },
  3836. { 0 }
  3837. };
  3838. if (t4_handle_intr_status(adap, LE_DB_INT_CAUSE_A,
  3839. (chip <= CHELSIO_T5) ?
  3840. le_intr_info : t6_le_intr_info))
  3841. t4_fatal_err(adap);
  3842. }
  3843. /*
  3844. * MPS interrupt handler.
  3845. */
  3846. static void mps_intr_handler(struct adapter *adapter)
  3847. {
  3848. static const struct intr_info mps_rx_intr_info[] = {
  3849. { 0xffffff, "MPS Rx parity error", -1, 1 },
  3850. { 0 }
  3851. };
  3852. static const struct intr_info mps_tx_intr_info[] = {
  3853. { TPFIFO_V(TPFIFO_M), "MPS Tx TP FIFO parity error", -1, 1 },
  3854. { NCSIFIFO_F, "MPS Tx NC-SI FIFO parity error", -1, 1 },
  3855. { TXDATAFIFO_V(TXDATAFIFO_M), "MPS Tx data FIFO parity error",
  3856. -1, 1 },
  3857. { TXDESCFIFO_V(TXDESCFIFO_M), "MPS Tx desc FIFO parity error",
  3858. -1, 1 },
  3859. { BUBBLE_F, "MPS Tx underflow", -1, 1 },
  3860. { SECNTERR_F, "MPS Tx SOP/EOP error", -1, 1 },
  3861. { FRMERR_F, "MPS Tx framing error", -1, 1 },
  3862. { 0 }
  3863. };
  3864. static const struct intr_info mps_trc_intr_info[] = {
  3865. { FILTMEM_V(FILTMEM_M), "MPS TRC filter parity error", -1, 1 },
  3866. { PKTFIFO_V(PKTFIFO_M), "MPS TRC packet FIFO parity error",
  3867. -1, 1 },
  3868. { MISCPERR_F, "MPS TRC misc parity error", -1, 1 },
  3869. { 0 }
  3870. };
  3871. static const struct intr_info mps_stat_sram_intr_info[] = {
  3872. { 0x1fffff, "MPS statistics SRAM parity error", -1, 1 },
  3873. { 0 }
  3874. };
  3875. static const struct intr_info mps_stat_tx_intr_info[] = {
  3876. { 0xfffff, "MPS statistics Tx FIFO parity error", -1, 1 },
  3877. { 0 }
  3878. };
  3879. static const struct intr_info mps_stat_rx_intr_info[] = {
  3880. { 0xffffff, "MPS statistics Rx FIFO parity error", -1, 1 },
  3881. { 0 }
  3882. };
  3883. static const struct intr_info mps_cls_intr_info[] = {
  3884. { MATCHSRAM_F, "MPS match SRAM parity error", -1, 1 },
  3885. { MATCHTCAM_F, "MPS match TCAM parity error", -1, 1 },
  3886. { HASHSRAM_F, "MPS hash SRAM parity error", -1, 1 },
  3887. { 0 }
  3888. };
  3889. int fat;
  3890. fat = t4_handle_intr_status(adapter, MPS_RX_PERR_INT_CAUSE_A,
  3891. mps_rx_intr_info) +
  3892. t4_handle_intr_status(adapter, MPS_TX_INT_CAUSE_A,
  3893. mps_tx_intr_info) +
  3894. t4_handle_intr_status(adapter, MPS_TRC_INT_CAUSE_A,
  3895. mps_trc_intr_info) +
  3896. t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_SRAM_A,
  3897. mps_stat_sram_intr_info) +
  3898. t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_TX_FIFO_A,
  3899. mps_stat_tx_intr_info) +
  3900. t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_RX_FIFO_A,
  3901. mps_stat_rx_intr_info) +
  3902. t4_handle_intr_status(adapter, MPS_CLS_INT_CAUSE_A,
  3903. mps_cls_intr_info);
  3904. t4_write_reg(adapter, MPS_INT_CAUSE_A, 0);
  3905. t4_read_reg(adapter, MPS_INT_CAUSE_A); /* flush */
  3906. if (fat)
  3907. t4_fatal_err(adapter);
  3908. }
  3909. #define MEM_INT_MASK (PERR_INT_CAUSE_F | ECC_CE_INT_CAUSE_F | \
  3910. ECC_UE_INT_CAUSE_F)
  3911. /*
  3912. * EDC/MC interrupt handler.
  3913. */
  3914. static void mem_intr_handler(struct adapter *adapter, int idx)
  3915. {
  3916. static const char name[4][7] = { "EDC0", "EDC1", "MC/MC0", "MC1" };
  3917. unsigned int addr, cnt_addr, v;
  3918. if (idx <= MEM_EDC1) {
  3919. addr = EDC_REG(EDC_INT_CAUSE_A, idx);
  3920. cnt_addr = EDC_REG(EDC_ECC_STATUS_A, idx);
  3921. } else if (idx == MEM_MC) {
  3922. if (is_t4(adapter->params.chip)) {
  3923. addr = MC_INT_CAUSE_A;
  3924. cnt_addr = MC_ECC_STATUS_A;
  3925. } else {
  3926. addr = MC_P_INT_CAUSE_A;
  3927. cnt_addr = MC_P_ECC_STATUS_A;
  3928. }
  3929. } else {
  3930. addr = MC_REG(MC_P_INT_CAUSE_A, 1);
  3931. cnt_addr = MC_REG(MC_P_ECC_STATUS_A, 1);
  3932. }
  3933. v = t4_read_reg(adapter, addr) & MEM_INT_MASK;
  3934. if (v & PERR_INT_CAUSE_F)
  3935. dev_alert(adapter->pdev_dev, "%s FIFO parity error\n",
  3936. name[idx]);
  3937. if (v & ECC_CE_INT_CAUSE_F) {
  3938. u32 cnt = ECC_CECNT_G(t4_read_reg(adapter, cnt_addr));
  3939. t4_edc_err_read(adapter, idx);
  3940. t4_write_reg(adapter, cnt_addr, ECC_CECNT_V(ECC_CECNT_M));
  3941. if (printk_ratelimit())
  3942. dev_warn(adapter->pdev_dev,
  3943. "%u %s correctable ECC data error%s\n",
  3944. cnt, name[idx], cnt > 1 ? "s" : "");
  3945. }
  3946. if (v & ECC_UE_INT_CAUSE_F)
  3947. dev_alert(adapter->pdev_dev,
  3948. "%s uncorrectable ECC data error\n", name[idx]);
  3949. t4_write_reg(adapter, addr, v);
  3950. if (v & (PERR_INT_CAUSE_F | ECC_UE_INT_CAUSE_F))
  3951. t4_fatal_err(adapter);
  3952. }
  3953. /*
  3954. * MA interrupt handler.
  3955. */
  3956. static void ma_intr_handler(struct adapter *adap)
  3957. {
  3958. u32 v, status = t4_read_reg(adap, MA_INT_CAUSE_A);
  3959. if (status & MEM_PERR_INT_CAUSE_F) {
  3960. dev_alert(adap->pdev_dev,
  3961. "MA parity error, parity status %#x\n",
  3962. t4_read_reg(adap, MA_PARITY_ERROR_STATUS1_A));
  3963. if (is_t5(adap->params.chip))
  3964. dev_alert(adap->pdev_dev,
  3965. "MA parity error, parity status %#x\n",
  3966. t4_read_reg(adap,
  3967. MA_PARITY_ERROR_STATUS2_A));
  3968. }
  3969. if (status & MEM_WRAP_INT_CAUSE_F) {
  3970. v = t4_read_reg(adap, MA_INT_WRAP_STATUS_A);
  3971. dev_alert(adap->pdev_dev, "MA address wrap-around error by "
  3972. "client %u to address %#x\n",
  3973. MEM_WRAP_CLIENT_NUM_G(v),
  3974. MEM_WRAP_ADDRESS_G(v) << 4);
  3975. }
  3976. t4_write_reg(adap, MA_INT_CAUSE_A, status);
  3977. t4_fatal_err(adap);
  3978. }
  3979. /*
  3980. * SMB interrupt handler.
  3981. */
  3982. static void smb_intr_handler(struct adapter *adap)
  3983. {
  3984. static const struct intr_info smb_intr_info[] = {
  3985. { MSTTXFIFOPARINT_F, "SMB master Tx FIFO parity error", -1, 1 },
  3986. { MSTRXFIFOPARINT_F, "SMB master Rx FIFO parity error", -1, 1 },
  3987. { SLVFIFOPARINT_F, "SMB slave FIFO parity error", -1, 1 },
  3988. { 0 }
  3989. };
  3990. if (t4_handle_intr_status(adap, SMB_INT_CAUSE_A, smb_intr_info))
  3991. t4_fatal_err(adap);
  3992. }
  3993. /*
  3994. * NC-SI interrupt handler.
  3995. */
  3996. static void ncsi_intr_handler(struct adapter *adap)
  3997. {
  3998. static const struct intr_info ncsi_intr_info[] = {
  3999. { CIM_DM_PRTY_ERR_F, "NC-SI CIM parity error", -1, 1 },
  4000. { MPS_DM_PRTY_ERR_F, "NC-SI MPS parity error", -1, 1 },
  4001. { TXFIFO_PRTY_ERR_F, "NC-SI Tx FIFO parity error", -1, 1 },
  4002. { RXFIFO_PRTY_ERR_F, "NC-SI Rx FIFO parity error", -1, 1 },
  4003. { 0 }
  4004. };
  4005. if (t4_handle_intr_status(adap, NCSI_INT_CAUSE_A, ncsi_intr_info))
  4006. t4_fatal_err(adap);
  4007. }
  4008. /*
  4009. * XGMAC interrupt handler.
  4010. */
  4011. static void xgmac_intr_handler(struct adapter *adap, int port)
  4012. {
  4013. u32 v, int_cause_reg;
  4014. if (is_t4(adap->params.chip))
  4015. int_cause_reg = PORT_REG(port, XGMAC_PORT_INT_CAUSE_A);
  4016. else
  4017. int_cause_reg = T5_PORT_REG(port, MAC_PORT_INT_CAUSE_A);
  4018. v = t4_read_reg(adap, int_cause_reg);
  4019. v &= TXFIFO_PRTY_ERR_F | RXFIFO_PRTY_ERR_F;
  4020. if (!v)
  4021. return;
  4022. if (v & TXFIFO_PRTY_ERR_F)
  4023. dev_alert(adap->pdev_dev, "XGMAC %d Tx FIFO parity error\n",
  4024. port);
  4025. if (v & RXFIFO_PRTY_ERR_F)
  4026. dev_alert(adap->pdev_dev, "XGMAC %d Rx FIFO parity error\n",
  4027. port);
  4028. t4_write_reg(adap, PORT_REG(port, XGMAC_PORT_INT_CAUSE_A), v);
  4029. t4_fatal_err(adap);
  4030. }
  4031. /*
  4032. * PL interrupt handler.
  4033. */
  4034. static void pl_intr_handler(struct adapter *adap)
  4035. {
  4036. static const struct intr_info pl_intr_info[] = {
  4037. { FATALPERR_F, "T4 fatal parity error", -1, 1 },
  4038. { PERRVFID_F, "PL VFID_MAP parity error", -1, 1 },
  4039. { 0 }
  4040. };
  4041. if (t4_handle_intr_status(adap, PL_PL_INT_CAUSE_A, pl_intr_info))
  4042. t4_fatal_err(adap);
  4043. }
  4044. #define PF_INTR_MASK (PFSW_F)
  4045. #define GLBL_INTR_MASK (CIM_F | MPS_F | PL_F | PCIE_F | MC_F | EDC0_F | \
  4046. EDC1_F | LE_F | TP_F | MA_F | PM_TX_F | PM_RX_F | ULP_RX_F | \
  4047. CPL_SWITCH_F | SGE_F | ULP_TX_F)
  4048. /**
  4049. * t4_slow_intr_handler - control path interrupt handler
  4050. * @adapter: the adapter
  4051. *
  4052. * T4 interrupt handler for non-data global interrupt events, e.g., errors.
  4053. * The designation 'slow' is because it involves register reads, while
  4054. * data interrupts typically don't involve any MMIOs.
  4055. */
  4056. int t4_slow_intr_handler(struct adapter *adapter)
  4057. {
  4058. u32 cause = t4_read_reg(adapter, PL_INT_CAUSE_A);
  4059. if (!(cause & GLBL_INTR_MASK))
  4060. return 0;
  4061. if (cause & CIM_F)
  4062. cim_intr_handler(adapter);
  4063. if (cause & MPS_F)
  4064. mps_intr_handler(adapter);
  4065. if (cause & NCSI_F)
  4066. ncsi_intr_handler(adapter);
  4067. if (cause & PL_F)
  4068. pl_intr_handler(adapter);
  4069. if (cause & SMB_F)
  4070. smb_intr_handler(adapter);
  4071. if (cause & XGMAC0_F)
  4072. xgmac_intr_handler(adapter, 0);
  4073. if (cause & XGMAC1_F)
  4074. xgmac_intr_handler(adapter, 1);
  4075. if (cause & XGMAC_KR0_F)
  4076. xgmac_intr_handler(adapter, 2);
  4077. if (cause & XGMAC_KR1_F)
  4078. xgmac_intr_handler(adapter, 3);
  4079. if (cause & PCIE_F)
  4080. pcie_intr_handler(adapter);
  4081. if (cause & MC_F)
  4082. mem_intr_handler(adapter, MEM_MC);
  4083. if (is_t5(adapter->params.chip) && (cause & MC1_F))
  4084. mem_intr_handler(adapter, MEM_MC1);
  4085. if (cause & EDC0_F)
  4086. mem_intr_handler(adapter, MEM_EDC0);
  4087. if (cause & EDC1_F)
  4088. mem_intr_handler(adapter, MEM_EDC1);
  4089. if (cause & LE_F)
  4090. le_intr_handler(adapter);
  4091. if (cause & TP_F)
  4092. tp_intr_handler(adapter);
  4093. if (cause & MA_F)
  4094. ma_intr_handler(adapter);
  4095. if (cause & PM_TX_F)
  4096. pmtx_intr_handler(adapter);
  4097. if (cause & PM_RX_F)
  4098. pmrx_intr_handler(adapter);
  4099. if (cause & ULP_RX_F)
  4100. ulprx_intr_handler(adapter);
  4101. if (cause & CPL_SWITCH_F)
  4102. cplsw_intr_handler(adapter);
  4103. if (cause & SGE_F)
  4104. sge_intr_handler(adapter);
  4105. if (cause & ULP_TX_F)
  4106. ulptx_intr_handler(adapter);
  4107. /* Clear the interrupts just processed for which we are the master. */
  4108. t4_write_reg(adapter, PL_INT_CAUSE_A, cause & GLBL_INTR_MASK);
  4109. (void)t4_read_reg(adapter, PL_INT_CAUSE_A); /* flush */
  4110. return 1;
  4111. }
  4112. /**
  4113. * t4_intr_enable - enable interrupts
  4114. * @adapter: the adapter whose interrupts should be enabled
  4115. *
  4116. * Enable PF-specific interrupts for the calling function and the top-level
  4117. * interrupt concentrator for global interrupts. Interrupts are already
  4118. * enabled at each module, here we just enable the roots of the interrupt
  4119. * hierarchies.
  4120. *
  4121. * Note: this function should be called only when the driver manages
  4122. * non PF-specific interrupts from the various HW modules. Only one PCI
  4123. * function at a time should be doing this.
  4124. */
  4125. void t4_intr_enable(struct adapter *adapter)
  4126. {
  4127. u32 val = 0;
  4128. u32 whoami = t4_read_reg(adapter, PL_WHOAMI_A);
  4129. u32 pf = CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5 ?
  4130. SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
  4131. if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
  4132. val = ERR_DROPPED_DB_F | ERR_EGR_CTXT_PRIO_F | DBFIFO_HP_INT_F;
  4133. t4_write_reg(adapter, SGE_INT_ENABLE3_A, ERR_CPL_EXCEED_IQE_SIZE_F |
  4134. ERR_INVALID_CIDX_INC_F | ERR_CPL_OPCODE_0_F |
  4135. ERR_DATA_CPL_ON_HIGH_QID1_F | INGRESS_SIZE_ERR_F |
  4136. ERR_DATA_CPL_ON_HIGH_QID0_F | ERR_BAD_DB_PIDX3_F |
  4137. ERR_BAD_DB_PIDX2_F | ERR_BAD_DB_PIDX1_F |
  4138. ERR_BAD_DB_PIDX0_F | ERR_ING_CTXT_PRIO_F |
  4139. DBFIFO_LP_INT_F | EGRESS_SIZE_ERR_F | val);
  4140. t4_write_reg(adapter, MYPF_REG(PL_PF_INT_ENABLE_A), PF_INTR_MASK);
  4141. t4_set_reg_field(adapter, PL_INT_MAP0_A, 0, 1 << pf);
  4142. }
  4143. /**
  4144. * t4_intr_disable - disable interrupts
  4145. * @adapter: the adapter whose interrupts should be disabled
  4146. *
  4147. * Disable interrupts. We only disable the top-level interrupt
  4148. * concentrators. The caller must be a PCI function managing global
  4149. * interrupts.
  4150. */
  4151. void t4_intr_disable(struct adapter *adapter)
  4152. {
  4153. u32 whoami = t4_read_reg(adapter, PL_WHOAMI_A);
  4154. u32 pf = CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5 ?
  4155. SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
  4156. t4_write_reg(adapter, MYPF_REG(PL_PF_INT_ENABLE_A), 0);
  4157. t4_set_reg_field(adapter, PL_INT_MAP0_A, 1 << pf, 0);
  4158. }
  4159. /**
  4160. * hash_mac_addr - return the hash value of a MAC address
  4161. * @addr: the 48-bit Ethernet MAC address
  4162. *
  4163. * Hashes a MAC address according to the hash function used by HW inexact
  4164. * (hash) address matching.
  4165. */
  4166. static int hash_mac_addr(const u8 *addr)
  4167. {
  4168. u32 a = ((u32)addr[0] << 16) | ((u32)addr[1] << 8) | addr[2];
  4169. u32 b = ((u32)addr[3] << 16) | ((u32)addr[4] << 8) | addr[5];
  4170. a ^= b;
  4171. a ^= (a >> 12);
  4172. a ^= (a >> 6);
  4173. return a & 0x3f;
  4174. }
  4175. /**
  4176. * t4_config_rss_range - configure a portion of the RSS mapping table
  4177. * @adapter: the adapter
  4178. * @mbox: mbox to use for the FW command
  4179. * @viid: virtual interface whose RSS subtable is to be written
  4180. * @start: start entry in the table to write
  4181. * @n: how many table entries to write
  4182. * @rspq: values for the response queue lookup table
  4183. * @nrspq: number of values in @rspq
  4184. *
  4185. * Programs the selected part of the VI's RSS mapping table with the
  4186. * provided values. If @nrspq < @n the supplied values are used repeatedly
  4187. * until the full table range is populated.
  4188. *
  4189. * The caller must ensure the values in @rspq are in the range allowed for
  4190. * @viid.
  4191. */
  4192. int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
  4193. int start, int n, const u16 *rspq, unsigned int nrspq)
  4194. {
  4195. int ret;
  4196. const u16 *rsp = rspq;
  4197. const u16 *rsp_end = rspq + nrspq;
  4198. struct fw_rss_ind_tbl_cmd cmd;
  4199. memset(&cmd, 0, sizeof(cmd));
  4200. cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_RSS_IND_TBL_CMD) |
  4201. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  4202. FW_RSS_IND_TBL_CMD_VIID_V(viid));
  4203. cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
  4204. /* each fw_rss_ind_tbl_cmd takes up to 32 entries */
  4205. while (n > 0) {
  4206. int nq = min(n, 32);
  4207. __be32 *qp = &cmd.iq0_to_iq2;
  4208. cmd.niqid = cpu_to_be16(nq);
  4209. cmd.startidx = cpu_to_be16(start);
  4210. start += nq;
  4211. n -= nq;
  4212. while (nq > 0) {
  4213. unsigned int v;
  4214. v = FW_RSS_IND_TBL_CMD_IQ0_V(*rsp);
  4215. if (++rsp >= rsp_end)
  4216. rsp = rspq;
  4217. v |= FW_RSS_IND_TBL_CMD_IQ1_V(*rsp);
  4218. if (++rsp >= rsp_end)
  4219. rsp = rspq;
  4220. v |= FW_RSS_IND_TBL_CMD_IQ2_V(*rsp);
  4221. if (++rsp >= rsp_end)
  4222. rsp = rspq;
  4223. *qp++ = cpu_to_be32(v);
  4224. nq -= 3;
  4225. }
  4226. ret = t4_wr_mbox(adapter, mbox, &cmd, sizeof(cmd), NULL);
  4227. if (ret)
  4228. return ret;
  4229. }
  4230. return 0;
  4231. }
  4232. /**
  4233. * t4_config_glbl_rss - configure the global RSS mode
  4234. * @adapter: the adapter
  4235. * @mbox: mbox to use for the FW command
  4236. * @mode: global RSS mode
  4237. * @flags: mode-specific flags
  4238. *
  4239. * Sets the global RSS mode.
  4240. */
  4241. int t4_config_glbl_rss(struct adapter *adapter, int mbox, unsigned int mode,
  4242. unsigned int flags)
  4243. {
  4244. struct fw_rss_glb_config_cmd c;
  4245. memset(&c, 0, sizeof(c));
  4246. c.op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_RSS_GLB_CONFIG_CMD) |
  4247. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  4248. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  4249. if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_MANUAL) {
  4250. c.u.manual.mode_pkd =
  4251. cpu_to_be32(FW_RSS_GLB_CONFIG_CMD_MODE_V(mode));
  4252. } else if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL) {
  4253. c.u.basicvirtual.mode_pkd =
  4254. cpu_to_be32(FW_RSS_GLB_CONFIG_CMD_MODE_V(mode));
  4255. c.u.basicvirtual.synmapen_to_hashtoeplitz = cpu_to_be32(flags);
  4256. } else
  4257. return -EINVAL;
  4258. return t4_wr_mbox(adapter, mbox, &c, sizeof(c), NULL);
  4259. }
  4260. /**
  4261. * t4_config_vi_rss - configure per VI RSS settings
  4262. * @adapter: the adapter
  4263. * @mbox: mbox to use for the FW command
  4264. * @viid: the VI id
  4265. * @flags: RSS flags
  4266. * @defq: id of the default RSS queue for the VI.
  4267. *
  4268. * Configures VI-specific RSS properties.
  4269. */
  4270. int t4_config_vi_rss(struct adapter *adapter, int mbox, unsigned int viid,
  4271. unsigned int flags, unsigned int defq)
  4272. {
  4273. struct fw_rss_vi_config_cmd c;
  4274. memset(&c, 0, sizeof(c));
  4275. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_RSS_VI_CONFIG_CMD) |
  4276. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  4277. FW_RSS_VI_CONFIG_CMD_VIID_V(viid));
  4278. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  4279. c.u.basicvirtual.defaultq_to_udpen = cpu_to_be32(flags |
  4280. FW_RSS_VI_CONFIG_CMD_DEFAULTQ_V(defq));
  4281. return t4_wr_mbox(adapter, mbox, &c, sizeof(c), NULL);
  4282. }
  4283. /* Read an RSS table row */
  4284. static int rd_rss_row(struct adapter *adap, int row, u32 *val)
  4285. {
  4286. t4_write_reg(adap, TP_RSS_LKP_TABLE_A, 0xfff00000 | row);
  4287. return t4_wait_op_done_val(adap, TP_RSS_LKP_TABLE_A, LKPTBLROWVLD_F, 1,
  4288. 5, 0, val);
  4289. }
  4290. /**
  4291. * t4_read_rss - read the contents of the RSS mapping table
  4292. * @adapter: the adapter
  4293. * @map: holds the contents of the RSS mapping table
  4294. *
  4295. * Reads the contents of the RSS hash->queue mapping table.
  4296. */
  4297. int t4_read_rss(struct adapter *adapter, u16 *map)
  4298. {
  4299. u32 val;
  4300. int i, ret;
  4301. for (i = 0; i < RSS_NENTRIES / 2; ++i) {
  4302. ret = rd_rss_row(adapter, i, &val);
  4303. if (ret)
  4304. return ret;
  4305. *map++ = LKPTBLQUEUE0_G(val);
  4306. *map++ = LKPTBLQUEUE1_G(val);
  4307. }
  4308. return 0;
  4309. }
  4310. static unsigned int t4_use_ldst(struct adapter *adap)
  4311. {
  4312. return (adap->flags & FW_OK) || !adap->use_bd;
  4313. }
  4314. /**
  4315. * t4_fw_tp_pio_rw - Access TP PIO through LDST
  4316. * @adap: the adapter
  4317. * @vals: where the indirect register values are stored/written
  4318. * @nregs: how many indirect registers to read/write
  4319. * @start_idx: index of first indirect register to read/write
  4320. * @rw: Read (1) or Write (0)
  4321. *
  4322. * Access TP PIO registers through LDST
  4323. */
  4324. static void t4_fw_tp_pio_rw(struct adapter *adap, u32 *vals, unsigned int nregs,
  4325. unsigned int start_index, unsigned int rw)
  4326. {
  4327. int ret, i;
  4328. int cmd = FW_LDST_ADDRSPC_TP_PIO;
  4329. struct fw_ldst_cmd c;
  4330. for (i = 0 ; i < nregs; i++) {
  4331. memset(&c, 0, sizeof(c));
  4332. c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
  4333. FW_CMD_REQUEST_F |
  4334. (rw ? FW_CMD_READ_F :
  4335. FW_CMD_WRITE_F) |
  4336. FW_LDST_CMD_ADDRSPACE_V(cmd));
  4337. c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
  4338. c.u.addrval.addr = cpu_to_be32(start_index + i);
  4339. c.u.addrval.val = rw ? 0 : cpu_to_be32(vals[i]);
  4340. ret = t4_wr_mbox(adap, adap->mbox, &c, sizeof(c), &c);
  4341. if (!ret && rw)
  4342. vals[i] = be32_to_cpu(c.u.addrval.val);
  4343. }
  4344. }
  4345. /**
  4346. * t4_read_rss_key - read the global RSS key
  4347. * @adap: the adapter
  4348. * @key: 10-entry array holding the 320-bit RSS key
  4349. *
  4350. * Reads the global 320-bit RSS key.
  4351. */
  4352. void t4_read_rss_key(struct adapter *adap, u32 *key)
  4353. {
  4354. if (t4_use_ldst(adap))
  4355. t4_fw_tp_pio_rw(adap, key, 10, TP_RSS_SECRET_KEY0_A, 1);
  4356. else
  4357. t4_read_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A, key, 10,
  4358. TP_RSS_SECRET_KEY0_A);
  4359. }
  4360. /**
  4361. * t4_write_rss_key - program one of the RSS keys
  4362. * @adap: the adapter
  4363. * @key: 10-entry array holding the 320-bit RSS key
  4364. * @idx: which RSS key to write
  4365. *
  4366. * Writes one of the RSS keys with the given 320-bit value. If @idx is
  4367. * 0..15 the corresponding entry in the RSS key table is written,
  4368. * otherwise the global RSS key is written.
  4369. */
  4370. void t4_write_rss_key(struct adapter *adap, const u32 *key, int idx)
  4371. {
  4372. u8 rss_key_addr_cnt = 16;
  4373. u32 vrt = t4_read_reg(adap, TP_RSS_CONFIG_VRT_A);
  4374. /* T6 and later: for KeyMode 3 (per-vf and per-vf scramble),
  4375. * allows access to key addresses 16-63 by using KeyWrAddrX
  4376. * as index[5:4](upper 2) into key table
  4377. */
  4378. if ((CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) &&
  4379. (vrt & KEYEXTEND_F) && (KEYMODE_G(vrt) == 3))
  4380. rss_key_addr_cnt = 32;
  4381. if (t4_use_ldst(adap))
  4382. t4_fw_tp_pio_rw(adap, (void *)key, 10, TP_RSS_SECRET_KEY0_A, 0);
  4383. else
  4384. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A, key, 10,
  4385. TP_RSS_SECRET_KEY0_A);
  4386. if (idx >= 0 && idx < rss_key_addr_cnt) {
  4387. if (rss_key_addr_cnt > 16)
  4388. t4_write_reg(adap, TP_RSS_CONFIG_VRT_A,
  4389. KEYWRADDRX_V(idx >> 4) |
  4390. T6_VFWRADDR_V(idx) | KEYWREN_F);
  4391. else
  4392. t4_write_reg(adap, TP_RSS_CONFIG_VRT_A,
  4393. KEYWRADDR_V(idx) | KEYWREN_F);
  4394. }
  4395. }
  4396. /**
  4397. * t4_read_rss_pf_config - read PF RSS Configuration Table
  4398. * @adapter: the adapter
  4399. * @index: the entry in the PF RSS table to read
  4400. * @valp: where to store the returned value
  4401. *
  4402. * Reads the PF RSS Configuration Table at the specified index and returns
  4403. * the value found there.
  4404. */
  4405. void t4_read_rss_pf_config(struct adapter *adapter, unsigned int index,
  4406. u32 *valp)
  4407. {
  4408. if (t4_use_ldst(adapter))
  4409. t4_fw_tp_pio_rw(adapter, valp, 1,
  4410. TP_RSS_PF0_CONFIG_A + index, 1);
  4411. else
  4412. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4413. valp, 1, TP_RSS_PF0_CONFIG_A + index);
  4414. }
  4415. /**
  4416. * t4_read_rss_vf_config - read VF RSS Configuration Table
  4417. * @adapter: the adapter
  4418. * @index: the entry in the VF RSS table to read
  4419. * @vfl: where to store the returned VFL
  4420. * @vfh: where to store the returned VFH
  4421. *
  4422. * Reads the VF RSS Configuration Table at the specified index and returns
  4423. * the (VFL, VFH) values found there.
  4424. */
  4425. void t4_read_rss_vf_config(struct adapter *adapter, unsigned int index,
  4426. u32 *vfl, u32 *vfh)
  4427. {
  4428. u32 vrt, mask, data;
  4429. if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5) {
  4430. mask = VFWRADDR_V(VFWRADDR_M);
  4431. data = VFWRADDR_V(index);
  4432. } else {
  4433. mask = T6_VFWRADDR_V(T6_VFWRADDR_M);
  4434. data = T6_VFWRADDR_V(index);
  4435. }
  4436. /* Request that the index'th VF Table values be read into VFL/VFH.
  4437. */
  4438. vrt = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
  4439. vrt &= ~(VFRDRG_F | VFWREN_F | KEYWREN_F | mask);
  4440. vrt |= data | VFRDEN_F;
  4441. t4_write_reg(adapter, TP_RSS_CONFIG_VRT_A, vrt);
  4442. /* Grab the VFL/VFH values ...
  4443. */
  4444. if (t4_use_ldst(adapter)) {
  4445. t4_fw_tp_pio_rw(adapter, vfl, 1, TP_RSS_VFL_CONFIG_A, 1);
  4446. t4_fw_tp_pio_rw(adapter, vfh, 1, TP_RSS_VFH_CONFIG_A, 1);
  4447. } else {
  4448. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4449. vfl, 1, TP_RSS_VFL_CONFIG_A);
  4450. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4451. vfh, 1, TP_RSS_VFH_CONFIG_A);
  4452. }
  4453. }
  4454. /**
  4455. * t4_read_rss_pf_map - read PF RSS Map
  4456. * @adapter: the adapter
  4457. *
  4458. * Reads the PF RSS Map register and returns its value.
  4459. */
  4460. u32 t4_read_rss_pf_map(struct adapter *adapter)
  4461. {
  4462. u32 pfmap;
  4463. if (t4_use_ldst(adapter))
  4464. t4_fw_tp_pio_rw(adapter, &pfmap, 1, TP_RSS_PF_MAP_A, 1);
  4465. else
  4466. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4467. &pfmap, 1, TP_RSS_PF_MAP_A);
  4468. return pfmap;
  4469. }
  4470. /**
  4471. * t4_read_rss_pf_mask - read PF RSS Mask
  4472. * @adapter: the adapter
  4473. *
  4474. * Reads the PF RSS Mask register and returns its value.
  4475. */
  4476. u32 t4_read_rss_pf_mask(struct adapter *adapter)
  4477. {
  4478. u32 pfmask;
  4479. if (t4_use_ldst(adapter))
  4480. t4_fw_tp_pio_rw(adapter, &pfmask, 1, TP_RSS_PF_MSK_A, 1);
  4481. else
  4482. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4483. &pfmask, 1, TP_RSS_PF_MSK_A);
  4484. return pfmask;
  4485. }
  4486. /**
  4487. * t4_tp_get_tcp_stats - read TP's TCP MIB counters
  4488. * @adap: the adapter
  4489. * @v4: holds the TCP/IP counter values
  4490. * @v6: holds the TCP/IPv6 counter values
  4491. *
  4492. * Returns the values of TP's TCP/IP and TCP/IPv6 MIB counters.
  4493. * Either @v4 or @v6 may be %NULL to skip the corresponding stats.
  4494. */
  4495. void t4_tp_get_tcp_stats(struct adapter *adap, struct tp_tcp_stats *v4,
  4496. struct tp_tcp_stats *v6)
  4497. {
  4498. u32 val[TP_MIB_TCP_RXT_SEG_LO_A - TP_MIB_TCP_OUT_RST_A + 1];
  4499. #define STAT_IDX(x) ((TP_MIB_TCP_##x##_A) - TP_MIB_TCP_OUT_RST_A)
  4500. #define STAT(x) val[STAT_IDX(x)]
  4501. #define STAT64(x) (((u64)STAT(x##_HI) << 32) | STAT(x##_LO))
  4502. if (v4) {
  4503. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val,
  4504. ARRAY_SIZE(val), TP_MIB_TCP_OUT_RST_A);
  4505. v4->tcp_out_rsts = STAT(OUT_RST);
  4506. v4->tcp_in_segs = STAT64(IN_SEG);
  4507. v4->tcp_out_segs = STAT64(OUT_SEG);
  4508. v4->tcp_retrans_segs = STAT64(RXT_SEG);
  4509. }
  4510. if (v6) {
  4511. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val,
  4512. ARRAY_SIZE(val), TP_MIB_TCP_V6OUT_RST_A);
  4513. v6->tcp_out_rsts = STAT(OUT_RST);
  4514. v6->tcp_in_segs = STAT64(IN_SEG);
  4515. v6->tcp_out_segs = STAT64(OUT_SEG);
  4516. v6->tcp_retrans_segs = STAT64(RXT_SEG);
  4517. }
  4518. #undef STAT64
  4519. #undef STAT
  4520. #undef STAT_IDX
  4521. }
  4522. /**
  4523. * t4_tp_get_err_stats - read TP's error MIB counters
  4524. * @adap: the adapter
  4525. * @st: holds the counter values
  4526. *
  4527. * Returns the values of TP's error counters.
  4528. */
  4529. void t4_tp_get_err_stats(struct adapter *adap, struct tp_err_stats *st)
  4530. {
  4531. int nchan = adap->params.arch.nchan;
  4532. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4533. st->mac_in_errs, nchan, TP_MIB_MAC_IN_ERR_0_A);
  4534. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4535. st->hdr_in_errs, nchan, TP_MIB_HDR_IN_ERR_0_A);
  4536. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4537. st->tcp_in_errs, nchan, TP_MIB_TCP_IN_ERR_0_A);
  4538. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4539. st->tnl_cong_drops, nchan, TP_MIB_TNL_CNG_DROP_0_A);
  4540. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4541. st->ofld_chan_drops, nchan, TP_MIB_OFD_CHN_DROP_0_A);
  4542. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4543. st->tnl_tx_drops, nchan, TP_MIB_TNL_DROP_0_A);
  4544. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4545. st->ofld_vlan_drops, nchan, TP_MIB_OFD_VLN_DROP_0_A);
  4546. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4547. st->tcp6_in_errs, nchan, TP_MIB_TCP_V6IN_ERR_0_A);
  4548. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4549. &st->ofld_no_neigh, 2, TP_MIB_OFD_ARP_DROP_A);
  4550. }
  4551. /**
  4552. * t4_tp_get_cpl_stats - read TP's CPL MIB counters
  4553. * @adap: the adapter
  4554. * @st: holds the counter values
  4555. *
  4556. * Returns the values of TP's CPL counters.
  4557. */
  4558. void t4_tp_get_cpl_stats(struct adapter *adap, struct tp_cpl_stats *st)
  4559. {
  4560. int nchan = adap->params.arch.nchan;
  4561. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, st->req,
  4562. nchan, TP_MIB_CPL_IN_REQ_0_A);
  4563. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, st->rsp,
  4564. nchan, TP_MIB_CPL_OUT_RSP_0_A);
  4565. }
  4566. /**
  4567. * t4_tp_get_rdma_stats - read TP's RDMA MIB counters
  4568. * @adap: the adapter
  4569. * @st: holds the counter values
  4570. *
  4571. * Returns the values of TP's RDMA counters.
  4572. */
  4573. void t4_tp_get_rdma_stats(struct adapter *adap, struct tp_rdma_stats *st)
  4574. {
  4575. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, &st->rqe_dfr_pkt,
  4576. 2, TP_MIB_RQE_DFR_PKT_A);
  4577. }
  4578. /**
  4579. * t4_get_fcoe_stats - read TP's FCoE MIB counters for a port
  4580. * @adap: the adapter
  4581. * @idx: the port index
  4582. * @st: holds the counter values
  4583. *
  4584. * Returns the values of TP's FCoE counters for the selected port.
  4585. */
  4586. void t4_get_fcoe_stats(struct adapter *adap, unsigned int idx,
  4587. struct tp_fcoe_stats *st)
  4588. {
  4589. u32 val[2];
  4590. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, &st->frames_ddp,
  4591. 1, TP_MIB_FCOE_DDP_0_A + idx);
  4592. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, &st->frames_drop,
  4593. 1, TP_MIB_FCOE_DROP_0_A + idx);
  4594. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val,
  4595. 2, TP_MIB_FCOE_BYTE_0_HI_A + 2 * idx);
  4596. st->octets_ddp = ((u64)val[0] << 32) | val[1];
  4597. }
  4598. /**
  4599. * t4_get_usm_stats - read TP's non-TCP DDP MIB counters
  4600. * @adap: the adapter
  4601. * @st: holds the counter values
  4602. *
  4603. * Returns the values of TP's counters for non-TCP directly-placed packets.
  4604. */
  4605. void t4_get_usm_stats(struct adapter *adap, struct tp_usm_stats *st)
  4606. {
  4607. u32 val[4];
  4608. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val, 4,
  4609. TP_MIB_USM_PKTS_A);
  4610. st->frames = val[0];
  4611. st->drops = val[1];
  4612. st->octets = ((u64)val[2] << 32) | val[3];
  4613. }
  4614. /**
  4615. * t4_read_mtu_tbl - returns the values in the HW path MTU table
  4616. * @adap: the adapter
  4617. * @mtus: where to store the MTU values
  4618. * @mtu_log: where to store the MTU base-2 log (may be %NULL)
  4619. *
  4620. * Reads the HW path MTU table.
  4621. */
  4622. void t4_read_mtu_tbl(struct adapter *adap, u16 *mtus, u8 *mtu_log)
  4623. {
  4624. u32 v;
  4625. int i;
  4626. for (i = 0; i < NMTUS; ++i) {
  4627. t4_write_reg(adap, TP_MTU_TABLE_A,
  4628. MTUINDEX_V(0xff) | MTUVALUE_V(i));
  4629. v = t4_read_reg(adap, TP_MTU_TABLE_A);
  4630. mtus[i] = MTUVALUE_G(v);
  4631. if (mtu_log)
  4632. mtu_log[i] = MTUWIDTH_G(v);
  4633. }
  4634. }
  4635. /**
  4636. * t4_read_cong_tbl - reads the congestion control table
  4637. * @adap: the adapter
  4638. * @incr: where to store the alpha values
  4639. *
  4640. * Reads the additive increments programmed into the HW congestion
  4641. * control table.
  4642. */
  4643. void t4_read_cong_tbl(struct adapter *adap, u16 incr[NMTUS][NCCTRL_WIN])
  4644. {
  4645. unsigned int mtu, w;
  4646. for (mtu = 0; mtu < NMTUS; ++mtu)
  4647. for (w = 0; w < NCCTRL_WIN; ++w) {
  4648. t4_write_reg(adap, TP_CCTRL_TABLE_A,
  4649. ROWINDEX_V(0xffff) | (mtu << 5) | w);
  4650. incr[mtu][w] = (u16)t4_read_reg(adap,
  4651. TP_CCTRL_TABLE_A) & 0x1fff;
  4652. }
  4653. }
  4654. /**
  4655. * t4_tp_wr_bits_indirect - set/clear bits in an indirect TP register
  4656. * @adap: the adapter
  4657. * @addr: the indirect TP register address
  4658. * @mask: specifies the field within the register to modify
  4659. * @val: new value for the field
  4660. *
  4661. * Sets a field of an indirect TP register to the given value.
  4662. */
  4663. void t4_tp_wr_bits_indirect(struct adapter *adap, unsigned int addr,
  4664. unsigned int mask, unsigned int val)
  4665. {
  4666. t4_write_reg(adap, TP_PIO_ADDR_A, addr);
  4667. val |= t4_read_reg(adap, TP_PIO_DATA_A) & ~mask;
  4668. t4_write_reg(adap, TP_PIO_DATA_A, val);
  4669. }
  4670. /**
  4671. * init_cong_ctrl - initialize congestion control parameters
  4672. * @a: the alpha values for congestion control
  4673. * @b: the beta values for congestion control
  4674. *
  4675. * Initialize the congestion control parameters.
  4676. */
  4677. static void init_cong_ctrl(unsigned short *a, unsigned short *b)
  4678. {
  4679. a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = a[6] = a[7] = a[8] = 1;
  4680. a[9] = 2;
  4681. a[10] = 3;
  4682. a[11] = 4;
  4683. a[12] = 5;
  4684. a[13] = 6;
  4685. a[14] = 7;
  4686. a[15] = 8;
  4687. a[16] = 9;
  4688. a[17] = 10;
  4689. a[18] = 14;
  4690. a[19] = 17;
  4691. a[20] = 21;
  4692. a[21] = 25;
  4693. a[22] = 30;
  4694. a[23] = 35;
  4695. a[24] = 45;
  4696. a[25] = 60;
  4697. a[26] = 80;
  4698. a[27] = 100;
  4699. a[28] = 200;
  4700. a[29] = 300;
  4701. a[30] = 400;
  4702. a[31] = 500;
  4703. b[0] = b[1] = b[2] = b[3] = b[4] = b[5] = b[6] = b[7] = b[8] = 0;
  4704. b[9] = b[10] = 1;
  4705. b[11] = b[12] = 2;
  4706. b[13] = b[14] = b[15] = b[16] = 3;
  4707. b[17] = b[18] = b[19] = b[20] = b[21] = 4;
  4708. b[22] = b[23] = b[24] = b[25] = b[26] = b[27] = 5;
  4709. b[28] = b[29] = 6;
  4710. b[30] = b[31] = 7;
  4711. }
  4712. /* The minimum additive increment value for the congestion control table */
  4713. #define CC_MIN_INCR 2U
  4714. /**
  4715. * t4_load_mtus - write the MTU and congestion control HW tables
  4716. * @adap: the adapter
  4717. * @mtus: the values for the MTU table
  4718. * @alpha: the values for the congestion control alpha parameter
  4719. * @beta: the values for the congestion control beta parameter
  4720. *
  4721. * Write the HW MTU table with the supplied MTUs and the high-speed
  4722. * congestion control table with the supplied alpha, beta, and MTUs.
  4723. * We write the two tables together because the additive increments
  4724. * depend on the MTUs.
  4725. */
  4726. void t4_load_mtus(struct adapter *adap, const unsigned short *mtus,
  4727. const unsigned short *alpha, const unsigned short *beta)
  4728. {
  4729. static const unsigned int avg_pkts[NCCTRL_WIN] = {
  4730. 2, 6, 10, 14, 20, 28, 40, 56, 80, 112, 160, 224, 320, 448, 640,
  4731. 896, 1281, 1792, 2560, 3584, 5120, 7168, 10240, 14336, 20480,
  4732. 28672, 40960, 57344, 81920, 114688, 163840, 229376
  4733. };
  4734. unsigned int i, w;
  4735. for (i = 0; i < NMTUS; ++i) {
  4736. unsigned int mtu = mtus[i];
  4737. unsigned int log2 = fls(mtu);
  4738. if (!(mtu & ((1 << log2) >> 2))) /* round */
  4739. log2--;
  4740. t4_write_reg(adap, TP_MTU_TABLE_A, MTUINDEX_V(i) |
  4741. MTUWIDTH_V(log2) | MTUVALUE_V(mtu));
  4742. for (w = 0; w < NCCTRL_WIN; ++w) {
  4743. unsigned int inc;
  4744. inc = max(((mtu - 40) * alpha[w]) / avg_pkts[w],
  4745. CC_MIN_INCR);
  4746. t4_write_reg(adap, TP_CCTRL_TABLE_A, (i << 21) |
  4747. (w << 16) | (beta[w] << 13) | inc);
  4748. }
  4749. }
  4750. }
  4751. /* Calculates a rate in bytes/s given the number of 256-byte units per 4K core
  4752. * clocks. The formula is
  4753. *
  4754. * bytes/s = bytes256 * 256 * ClkFreq / 4096
  4755. *
  4756. * which is equivalent to
  4757. *
  4758. * bytes/s = 62.5 * bytes256 * ClkFreq_ms
  4759. */
  4760. static u64 chan_rate(struct adapter *adap, unsigned int bytes256)
  4761. {
  4762. u64 v = bytes256 * adap->params.vpd.cclk;
  4763. return v * 62 + v / 2;
  4764. }
  4765. /**
  4766. * t4_get_chan_txrate - get the current per channel Tx rates
  4767. * @adap: the adapter
  4768. * @nic_rate: rates for NIC traffic
  4769. * @ofld_rate: rates for offloaded traffic
  4770. *
  4771. * Return the current Tx rates in bytes/s for NIC and offloaded traffic
  4772. * for each channel.
  4773. */
  4774. void t4_get_chan_txrate(struct adapter *adap, u64 *nic_rate, u64 *ofld_rate)
  4775. {
  4776. u32 v;
  4777. v = t4_read_reg(adap, TP_TX_TRATE_A);
  4778. nic_rate[0] = chan_rate(adap, TNLRATE0_G(v));
  4779. nic_rate[1] = chan_rate(adap, TNLRATE1_G(v));
  4780. if (adap->params.arch.nchan == NCHAN) {
  4781. nic_rate[2] = chan_rate(adap, TNLRATE2_G(v));
  4782. nic_rate[3] = chan_rate(adap, TNLRATE3_G(v));
  4783. }
  4784. v = t4_read_reg(adap, TP_TX_ORATE_A);
  4785. ofld_rate[0] = chan_rate(adap, OFDRATE0_G(v));
  4786. ofld_rate[1] = chan_rate(adap, OFDRATE1_G(v));
  4787. if (adap->params.arch.nchan == NCHAN) {
  4788. ofld_rate[2] = chan_rate(adap, OFDRATE2_G(v));
  4789. ofld_rate[3] = chan_rate(adap, OFDRATE3_G(v));
  4790. }
  4791. }
  4792. /**
  4793. * t4_set_trace_filter - configure one of the tracing filters
  4794. * @adap: the adapter
  4795. * @tp: the desired trace filter parameters
  4796. * @idx: which filter to configure
  4797. * @enable: whether to enable or disable the filter
  4798. *
  4799. * Configures one of the tracing filters available in HW. If @enable is
  4800. * %0 @tp is not examined and may be %NULL. The user is responsible to
  4801. * set the single/multiple trace mode by writing to MPS_TRC_CFG_A register
  4802. */
  4803. int t4_set_trace_filter(struct adapter *adap, const struct trace_params *tp,
  4804. int idx, int enable)
  4805. {
  4806. int i, ofst = idx * 4;
  4807. u32 data_reg, mask_reg, cfg;
  4808. u32 multitrc = TRCMULTIFILTER_F;
  4809. if (!enable) {
  4810. t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A_A + ofst, 0);
  4811. return 0;
  4812. }
  4813. cfg = t4_read_reg(adap, MPS_TRC_CFG_A);
  4814. if (cfg & TRCMULTIFILTER_F) {
  4815. /* If multiple tracers are enabled, then maximum
  4816. * capture size is 2.5KB (FIFO size of a single channel)
  4817. * minus 2 flits for CPL_TRACE_PKT header.
  4818. */
  4819. if (tp->snap_len > ((10 * 1024 / 4) - (2 * 8)))
  4820. return -EINVAL;
  4821. } else {
  4822. /* If multiple tracers are disabled, to avoid deadlocks
  4823. * maximum packet capture size of 9600 bytes is recommended.
  4824. * Also in this mode, only trace0 can be enabled and running.
  4825. */
  4826. multitrc = 0;
  4827. if (tp->snap_len > 9600 || idx)
  4828. return -EINVAL;
  4829. }
  4830. if (tp->port > (is_t4(adap->params.chip) ? 11 : 19) || tp->invert > 1 ||
  4831. tp->skip_len > TFLENGTH_M || tp->skip_ofst > TFOFFSET_M ||
  4832. tp->min_len > TFMINPKTSIZE_M)
  4833. return -EINVAL;
  4834. /* stop the tracer we'll be changing */
  4835. t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A_A + ofst, 0);
  4836. idx *= (MPS_TRC_FILTER1_MATCH_A - MPS_TRC_FILTER0_MATCH_A);
  4837. data_reg = MPS_TRC_FILTER0_MATCH_A + idx;
  4838. mask_reg = MPS_TRC_FILTER0_DONT_CARE_A + idx;
  4839. for (i = 0; i < TRACE_LEN / 4; i++, data_reg += 4, mask_reg += 4) {
  4840. t4_write_reg(adap, data_reg, tp->data[i]);
  4841. t4_write_reg(adap, mask_reg, ~tp->mask[i]);
  4842. }
  4843. t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_B_A + ofst,
  4844. TFCAPTUREMAX_V(tp->snap_len) |
  4845. TFMINPKTSIZE_V(tp->min_len));
  4846. t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A_A + ofst,
  4847. TFOFFSET_V(tp->skip_ofst) | TFLENGTH_V(tp->skip_len) |
  4848. (is_t4(adap->params.chip) ?
  4849. TFPORT_V(tp->port) | TFEN_F | TFINVERTMATCH_V(tp->invert) :
  4850. T5_TFPORT_V(tp->port) | T5_TFEN_F |
  4851. T5_TFINVERTMATCH_V(tp->invert)));
  4852. return 0;
  4853. }
  4854. /**
  4855. * t4_get_trace_filter - query one of the tracing filters
  4856. * @adap: the adapter
  4857. * @tp: the current trace filter parameters
  4858. * @idx: which trace filter to query
  4859. * @enabled: non-zero if the filter is enabled
  4860. *
  4861. * Returns the current settings of one of the HW tracing filters.
  4862. */
  4863. void t4_get_trace_filter(struct adapter *adap, struct trace_params *tp, int idx,
  4864. int *enabled)
  4865. {
  4866. u32 ctla, ctlb;
  4867. int i, ofst = idx * 4;
  4868. u32 data_reg, mask_reg;
  4869. ctla = t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A_A + ofst);
  4870. ctlb = t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_B_A + ofst);
  4871. if (is_t4(adap->params.chip)) {
  4872. *enabled = !!(ctla & TFEN_F);
  4873. tp->port = TFPORT_G(ctla);
  4874. tp->invert = !!(ctla & TFINVERTMATCH_F);
  4875. } else {
  4876. *enabled = !!(ctla & T5_TFEN_F);
  4877. tp->port = T5_TFPORT_G(ctla);
  4878. tp->invert = !!(ctla & T5_TFINVERTMATCH_F);
  4879. }
  4880. tp->snap_len = TFCAPTUREMAX_G(ctlb);
  4881. tp->min_len = TFMINPKTSIZE_G(ctlb);
  4882. tp->skip_ofst = TFOFFSET_G(ctla);
  4883. tp->skip_len = TFLENGTH_G(ctla);
  4884. ofst = (MPS_TRC_FILTER1_MATCH_A - MPS_TRC_FILTER0_MATCH_A) * idx;
  4885. data_reg = MPS_TRC_FILTER0_MATCH_A + ofst;
  4886. mask_reg = MPS_TRC_FILTER0_DONT_CARE_A + ofst;
  4887. for (i = 0; i < TRACE_LEN / 4; i++, data_reg += 4, mask_reg += 4) {
  4888. tp->mask[i] = ~t4_read_reg(adap, mask_reg);
  4889. tp->data[i] = t4_read_reg(adap, data_reg) & tp->mask[i];
  4890. }
  4891. }
  4892. /**
  4893. * t4_pmtx_get_stats - returns the HW stats from PMTX
  4894. * @adap: the adapter
  4895. * @cnt: where to store the count statistics
  4896. * @cycles: where to store the cycle statistics
  4897. *
  4898. * Returns performance statistics from PMTX.
  4899. */
  4900. void t4_pmtx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[])
  4901. {
  4902. int i;
  4903. u32 data[2];
  4904. for (i = 0; i < PM_NSTATS; i++) {
  4905. t4_write_reg(adap, PM_TX_STAT_CONFIG_A, i + 1);
  4906. cnt[i] = t4_read_reg(adap, PM_TX_STAT_COUNT_A);
  4907. if (is_t4(adap->params.chip)) {
  4908. cycles[i] = t4_read_reg64(adap, PM_TX_STAT_LSB_A);
  4909. } else {
  4910. t4_read_indirect(adap, PM_TX_DBG_CTRL_A,
  4911. PM_TX_DBG_DATA_A, data, 2,
  4912. PM_TX_DBG_STAT_MSB_A);
  4913. cycles[i] = (((u64)data[0] << 32) | data[1]);
  4914. }
  4915. }
  4916. }
  4917. /**
  4918. * t4_pmrx_get_stats - returns the HW stats from PMRX
  4919. * @adap: the adapter
  4920. * @cnt: where to store the count statistics
  4921. * @cycles: where to store the cycle statistics
  4922. *
  4923. * Returns performance statistics from PMRX.
  4924. */
  4925. void t4_pmrx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[])
  4926. {
  4927. int i;
  4928. u32 data[2];
  4929. for (i = 0; i < PM_NSTATS; i++) {
  4930. t4_write_reg(adap, PM_RX_STAT_CONFIG_A, i + 1);
  4931. cnt[i] = t4_read_reg(adap, PM_RX_STAT_COUNT_A);
  4932. if (is_t4(adap->params.chip)) {
  4933. cycles[i] = t4_read_reg64(adap, PM_RX_STAT_LSB_A);
  4934. } else {
  4935. t4_read_indirect(adap, PM_RX_DBG_CTRL_A,
  4936. PM_RX_DBG_DATA_A, data, 2,
  4937. PM_RX_DBG_STAT_MSB_A);
  4938. cycles[i] = (((u64)data[0] << 32) | data[1]);
  4939. }
  4940. }
  4941. }
  4942. /**
  4943. * t4_get_mps_bg_map - return the buffer groups associated with a port
  4944. * @adap: the adapter
  4945. * @idx: the port index
  4946. *
  4947. * Returns a bitmap indicating which MPS buffer groups are associated
  4948. * with the given port. Bit i is set if buffer group i is used by the
  4949. * port.
  4950. */
  4951. unsigned int t4_get_mps_bg_map(struct adapter *adap, int idx)
  4952. {
  4953. u32 n = NUMPORTS_G(t4_read_reg(adap, MPS_CMN_CTL_A));
  4954. if (n == 0)
  4955. return idx == 0 ? 0xf : 0;
  4956. if (n == 1)
  4957. return idx < 2 ? (3 << (2 * idx)) : 0;
  4958. return 1 << idx;
  4959. }
  4960. /**
  4961. * t4_get_port_type_description - return Port Type string description
  4962. * @port_type: firmware Port Type enumeration
  4963. */
  4964. const char *t4_get_port_type_description(enum fw_port_type port_type)
  4965. {
  4966. static const char *const port_type_description[] = {
  4967. "R XFI",
  4968. "R XAUI",
  4969. "T SGMII",
  4970. "T XFI",
  4971. "T XAUI",
  4972. "KX4",
  4973. "CX4",
  4974. "KX",
  4975. "KR",
  4976. "R SFP+",
  4977. "KR/KX",
  4978. "KR/KX/KX4",
  4979. "R QSFP_10G",
  4980. "R QSA",
  4981. "R QSFP",
  4982. "R BP40_BA",
  4983. };
  4984. if (port_type < ARRAY_SIZE(port_type_description))
  4985. return port_type_description[port_type];
  4986. return "UNKNOWN";
  4987. }
  4988. /**
  4989. * t4_get_port_stats_offset - collect port stats relative to a previous
  4990. * snapshot
  4991. * @adap: The adapter
  4992. * @idx: The port
  4993. * @stats: Current stats to fill
  4994. * @offset: Previous stats snapshot
  4995. */
  4996. void t4_get_port_stats_offset(struct adapter *adap, int idx,
  4997. struct port_stats *stats,
  4998. struct port_stats *offset)
  4999. {
  5000. u64 *s, *o;
  5001. int i;
  5002. t4_get_port_stats(adap, idx, stats);
  5003. for (i = 0, s = (u64 *)stats, o = (u64 *)offset;
  5004. i < (sizeof(struct port_stats) / sizeof(u64));
  5005. i++, s++, o++)
  5006. *s -= *o;
  5007. }
  5008. /**
  5009. * t4_get_port_stats - collect port statistics
  5010. * @adap: the adapter
  5011. * @idx: the port index
  5012. * @p: the stats structure to fill
  5013. *
  5014. * Collect statistics related to the given port from HW.
  5015. */
  5016. void t4_get_port_stats(struct adapter *adap, int idx, struct port_stats *p)
  5017. {
  5018. u32 bgmap = t4_get_mps_bg_map(adap, idx);
  5019. #define GET_STAT(name) \
  5020. t4_read_reg64(adap, \
  5021. (is_t4(adap->params.chip) ? PORT_REG(idx, MPS_PORT_STAT_##name##_L) : \
  5022. T5_PORT_REG(idx, MPS_PORT_STAT_##name##_L)))
  5023. #define GET_STAT_COM(name) t4_read_reg64(adap, MPS_STAT_##name##_L)
  5024. p->tx_octets = GET_STAT(TX_PORT_BYTES);
  5025. p->tx_frames = GET_STAT(TX_PORT_FRAMES);
  5026. p->tx_bcast_frames = GET_STAT(TX_PORT_BCAST);
  5027. p->tx_mcast_frames = GET_STAT(TX_PORT_MCAST);
  5028. p->tx_ucast_frames = GET_STAT(TX_PORT_UCAST);
  5029. p->tx_error_frames = GET_STAT(TX_PORT_ERROR);
  5030. p->tx_frames_64 = GET_STAT(TX_PORT_64B);
  5031. p->tx_frames_65_127 = GET_STAT(TX_PORT_65B_127B);
  5032. p->tx_frames_128_255 = GET_STAT(TX_PORT_128B_255B);
  5033. p->tx_frames_256_511 = GET_STAT(TX_PORT_256B_511B);
  5034. p->tx_frames_512_1023 = GET_STAT(TX_PORT_512B_1023B);
  5035. p->tx_frames_1024_1518 = GET_STAT(TX_PORT_1024B_1518B);
  5036. p->tx_frames_1519_max = GET_STAT(TX_PORT_1519B_MAX);
  5037. p->tx_drop = GET_STAT(TX_PORT_DROP);
  5038. p->tx_pause = GET_STAT(TX_PORT_PAUSE);
  5039. p->tx_ppp0 = GET_STAT(TX_PORT_PPP0);
  5040. p->tx_ppp1 = GET_STAT(TX_PORT_PPP1);
  5041. p->tx_ppp2 = GET_STAT(TX_PORT_PPP2);
  5042. p->tx_ppp3 = GET_STAT(TX_PORT_PPP3);
  5043. p->tx_ppp4 = GET_STAT(TX_PORT_PPP4);
  5044. p->tx_ppp5 = GET_STAT(TX_PORT_PPP5);
  5045. p->tx_ppp6 = GET_STAT(TX_PORT_PPP6);
  5046. p->tx_ppp7 = GET_STAT(TX_PORT_PPP7);
  5047. p->rx_octets = GET_STAT(RX_PORT_BYTES);
  5048. p->rx_frames = GET_STAT(RX_PORT_FRAMES);
  5049. p->rx_bcast_frames = GET_STAT(RX_PORT_BCAST);
  5050. p->rx_mcast_frames = GET_STAT(RX_PORT_MCAST);
  5051. p->rx_ucast_frames = GET_STAT(RX_PORT_UCAST);
  5052. p->rx_too_long = GET_STAT(RX_PORT_MTU_ERROR);
  5053. p->rx_jabber = GET_STAT(RX_PORT_MTU_CRC_ERROR);
  5054. p->rx_fcs_err = GET_STAT(RX_PORT_CRC_ERROR);
  5055. p->rx_len_err = GET_STAT(RX_PORT_LEN_ERROR);
  5056. p->rx_symbol_err = GET_STAT(RX_PORT_SYM_ERROR);
  5057. p->rx_runt = GET_STAT(RX_PORT_LESS_64B);
  5058. p->rx_frames_64 = GET_STAT(RX_PORT_64B);
  5059. p->rx_frames_65_127 = GET_STAT(RX_PORT_65B_127B);
  5060. p->rx_frames_128_255 = GET_STAT(RX_PORT_128B_255B);
  5061. p->rx_frames_256_511 = GET_STAT(RX_PORT_256B_511B);
  5062. p->rx_frames_512_1023 = GET_STAT(RX_PORT_512B_1023B);
  5063. p->rx_frames_1024_1518 = GET_STAT(RX_PORT_1024B_1518B);
  5064. p->rx_frames_1519_max = GET_STAT(RX_PORT_1519B_MAX);
  5065. p->rx_pause = GET_STAT(RX_PORT_PAUSE);
  5066. p->rx_ppp0 = GET_STAT(RX_PORT_PPP0);
  5067. p->rx_ppp1 = GET_STAT(RX_PORT_PPP1);
  5068. p->rx_ppp2 = GET_STAT(RX_PORT_PPP2);
  5069. p->rx_ppp3 = GET_STAT(RX_PORT_PPP3);
  5070. p->rx_ppp4 = GET_STAT(RX_PORT_PPP4);
  5071. p->rx_ppp5 = GET_STAT(RX_PORT_PPP5);
  5072. p->rx_ppp6 = GET_STAT(RX_PORT_PPP6);
  5073. p->rx_ppp7 = GET_STAT(RX_PORT_PPP7);
  5074. p->rx_ovflow0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_DROP_FRAME) : 0;
  5075. p->rx_ovflow1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_DROP_FRAME) : 0;
  5076. p->rx_ovflow2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_DROP_FRAME) : 0;
  5077. p->rx_ovflow3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_DROP_FRAME) : 0;
  5078. p->rx_trunc0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_TRUNC_FRAME) : 0;
  5079. p->rx_trunc1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_TRUNC_FRAME) : 0;
  5080. p->rx_trunc2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_TRUNC_FRAME) : 0;
  5081. p->rx_trunc3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_TRUNC_FRAME) : 0;
  5082. #undef GET_STAT
  5083. #undef GET_STAT_COM
  5084. }
  5085. /**
  5086. * t4_get_lb_stats - collect loopback port statistics
  5087. * @adap: the adapter
  5088. * @idx: the loopback port index
  5089. * @p: the stats structure to fill
  5090. *
  5091. * Return HW statistics for the given loopback port.
  5092. */
  5093. void t4_get_lb_stats(struct adapter *adap, int idx, struct lb_port_stats *p)
  5094. {
  5095. u32 bgmap = t4_get_mps_bg_map(adap, idx);
  5096. #define GET_STAT(name) \
  5097. t4_read_reg64(adap, \
  5098. (is_t4(adap->params.chip) ? \
  5099. PORT_REG(idx, MPS_PORT_STAT_LB_PORT_##name##_L) : \
  5100. T5_PORT_REG(idx, MPS_PORT_STAT_LB_PORT_##name##_L)))
  5101. #define GET_STAT_COM(name) t4_read_reg64(adap, MPS_STAT_##name##_L)
  5102. p->octets = GET_STAT(BYTES);
  5103. p->frames = GET_STAT(FRAMES);
  5104. p->bcast_frames = GET_STAT(BCAST);
  5105. p->mcast_frames = GET_STAT(MCAST);
  5106. p->ucast_frames = GET_STAT(UCAST);
  5107. p->error_frames = GET_STAT(ERROR);
  5108. p->frames_64 = GET_STAT(64B);
  5109. p->frames_65_127 = GET_STAT(65B_127B);
  5110. p->frames_128_255 = GET_STAT(128B_255B);
  5111. p->frames_256_511 = GET_STAT(256B_511B);
  5112. p->frames_512_1023 = GET_STAT(512B_1023B);
  5113. p->frames_1024_1518 = GET_STAT(1024B_1518B);
  5114. p->frames_1519_max = GET_STAT(1519B_MAX);
  5115. p->drop = GET_STAT(DROP_FRAMES);
  5116. p->ovflow0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_LB_DROP_FRAME) : 0;
  5117. p->ovflow1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_LB_DROP_FRAME) : 0;
  5118. p->ovflow2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_LB_DROP_FRAME) : 0;
  5119. p->ovflow3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_LB_DROP_FRAME) : 0;
  5120. p->trunc0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_LB_TRUNC_FRAME) : 0;
  5121. p->trunc1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_LB_TRUNC_FRAME) : 0;
  5122. p->trunc2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_LB_TRUNC_FRAME) : 0;
  5123. p->trunc3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_LB_TRUNC_FRAME) : 0;
  5124. #undef GET_STAT
  5125. #undef GET_STAT_COM
  5126. }
  5127. /* t4_mk_filtdelwr - create a delete filter WR
  5128. * @ftid: the filter ID
  5129. * @wr: the filter work request to populate
  5130. * @qid: ingress queue to receive the delete notification
  5131. *
  5132. * Creates a filter work request to delete the supplied filter. If @qid is
  5133. * negative the delete notification is suppressed.
  5134. */
  5135. void t4_mk_filtdelwr(unsigned int ftid, struct fw_filter_wr *wr, int qid)
  5136. {
  5137. memset(wr, 0, sizeof(*wr));
  5138. wr->op_pkd = cpu_to_be32(FW_WR_OP_V(FW_FILTER_WR));
  5139. wr->len16_pkd = cpu_to_be32(FW_WR_LEN16_V(sizeof(*wr) / 16));
  5140. wr->tid_to_iq = cpu_to_be32(FW_FILTER_WR_TID_V(ftid) |
  5141. FW_FILTER_WR_NOREPLY_V(qid < 0));
  5142. wr->del_filter_to_l2tix = cpu_to_be32(FW_FILTER_WR_DEL_FILTER_F);
  5143. if (qid >= 0)
  5144. wr->rx_chan_rx_rpl_iq =
  5145. cpu_to_be16(FW_FILTER_WR_RX_RPL_IQ_V(qid));
  5146. }
  5147. #define INIT_CMD(var, cmd, rd_wr) do { \
  5148. (var).op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_##cmd##_CMD) | \
  5149. FW_CMD_REQUEST_F | \
  5150. FW_CMD_##rd_wr##_F); \
  5151. (var).retval_len16 = cpu_to_be32(FW_LEN16(var)); \
  5152. } while (0)
  5153. int t4_fwaddrspace_write(struct adapter *adap, unsigned int mbox,
  5154. u32 addr, u32 val)
  5155. {
  5156. u32 ldst_addrspace;
  5157. struct fw_ldst_cmd c;
  5158. memset(&c, 0, sizeof(c));
  5159. ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_FIRMWARE);
  5160. c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
  5161. FW_CMD_REQUEST_F |
  5162. FW_CMD_WRITE_F |
  5163. ldst_addrspace);
  5164. c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
  5165. c.u.addrval.addr = cpu_to_be32(addr);
  5166. c.u.addrval.val = cpu_to_be32(val);
  5167. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5168. }
  5169. /**
  5170. * t4_mdio_rd - read a PHY register through MDIO
  5171. * @adap: the adapter
  5172. * @mbox: mailbox to use for the FW command
  5173. * @phy_addr: the PHY address
  5174. * @mmd: the PHY MMD to access (0 for clause 22 PHYs)
  5175. * @reg: the register to read
  5176. * @valp: where to store the value
  5177. *
  5178. * Issues a FW command through the given mailbox to read a PHY register.
  5179. */
  5180. int t4_mdio_rd(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
  5181. unsigned int mmd, unsigned int reg, u16 *valp)
  5182. {
  5183. int ret;
  5184. u32 ldst_addrspace;
  5185. struct fw_ldst_cmd c;
  5186. memset(&c, 0, sizeof(c));
  5187. ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MDIO);
  5188. c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
  5189. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  5190. ldst_addrspace);
  5191. c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
  5192. c.u.mdio.paddr_mmd = cpu_to_be16(FW_LDST_CMD_PADDR_V(phy_addr) |
  5193. FW_LDST_CMD_MMD_V(mmd));
  5194. c.u.mdio.raddr = cpu_to_be16(reg);
  5195. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  5196. if (ret == 0)
  5197. *valp = be16_to_cpu(c.u.mdio.rval);
  5198. return ret;
  5199. }
  5200. /**
  5201. * t4_mdio_wr - write a PHY register through MDIO
  5202. * @adap: the adapter
  5203. * @mbox: mailbox to use for the FW command
  5204. * @phy_addr: the PHY address
  5205. * @mmd: the PHY MMD to access (0 for clause 22 PHYs)
  5206. * @reg: the register to write
  5207. * @valp: value to write
  5208. *
  5209. * Issues a FW command through the given mailbox to write a PHY register.
  5210. */
  5211. int t4_mdio_wr(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
  5212. unsigned int mmd, unsigned int reg, u16 val)
  5213. {
  5214. u32 ldst_addrspace;
  5215. struct fw_ldst_cmd c;
  5216. memset(&c, 0, sizeof(c));
  5217. ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MDIO);
  5218. c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
  5219. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  5220. ldst_addrspace);
  5221. c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
  5222. c.u.mdio.paddr_mmd = cpu_to_be16(FW_LDST_CMD_PADDR_V(phy_addr) |
  5223. FW_LDST_CMD_MMD_V(mmd));
  5224. c.u.mdio.raddr = cpu_to_be16(reg);
  5225. c.u.mdio.rval = cpu_to_be16(val);
  5226. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5227. }
  5228. /**
  5229. * t4_sge_decode_idma_state - decode the idma state
  5230. * @adap: the adapter
  5231. * @state: the state idma is stuck in
  5232. */
  5233. void t4_sge_decode_idma_state(struct adapter *adapter, int state)
  5234. {
  5235. static const char * const t4_decode[] = {
  5236. "IDMA_IDLE",
  5237. "IDMA_PUSH_MORE_CPL_FIFO",
  5238. "IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
  5239. "Not used",
  5240. "IDMA_PHYSADDR_SEND_PCIEHDR",
  5241. "IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
  5242. "IDMA_PHYSADDR_SEND_PAYLOAD",
  5243. "IDMA_SEND_FIFO_TO_IMSG",
  5244. "IDMA_FL_REQ_DATA_FL_PREP",
  5245. "IDMA_FL_REQ_DATA_FL",
  5246. "IDMA_FL_DROP",
  5247. "IDMA_FL_H_REQ_HEADER_FL",
  5248. "IDMA_FL_H_SEND_PCIEHDR",
  5249. "IDMA_FL_H_PUSH_CPL_FIFO",
  5250. "IDMA_FL_H_SEND_CPL",
  5251. "IDMA_FL_H_SEND_IP_HDR_FIRST",
  5252. "IDMA_FL_H_SEND_IP_HDR",
  5253. "IDMA_FL_H_REQ_NEXT_HEADER_FL",
  5254. "IDMA_FL_H_SEND_NEXT_PCIEHDR",
  5255. "IDMA_FL_H_SEND_IP_HDR_PADDING",
  5256. "IDMA_FL_D_SEND_PCIEHDR",
  5257. "IDMA_FL_D_SEND_CPL_AND_IP_HDR",
  5258. "IDMA_FL_D_REQ_NEXT_DATA_FL",
  5259. "IDMA_FL_SEND_PCIEHDR",
  5260. "IDMA_FL_PUSH_CPL_FIFO",
  5261. "IDMA_FL_SEND_CPL",
  5262. "IDMA_FL_SEND_PAYLOAD_FIRST",
  5263. "IDMA_FL_SEND_PAYLOAD",
  5264. "IDMA_FL_REQ_NEXT_DATA_FL",
  5265. "IDMA_FL_SEND_NEXT_PCIEHDR",
  5266. "IDMA_FL_SEND_PADDING",
  5267. "IDMA_FL_SEND_COMPLETION_TO_IMSG",
  5268. "IDMA_FL_SEND_FIFO_TO_IMSG",
  5269. "IDMA_FL_REQ_DATAFL_DONE",
  5270. "IDMA_FL_REQ_HEADERFL_DONE",
  5271. };
  5272. static const char * const t5_decode[] = {
  5273. "IDMA_IDLE",
  5274. "IDMA_ALMOST_IDLE",
  5275. "IDMA_PUSH_MORE_CPL_FIFO",
  5276. "IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
  5277. "IDMA_SGEFLRFLUSH_SEND_PCIEHDR",
  5278. "IDMA_PHYSADDR_SEND_PCIEHDR",
  5279. "IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
  5280. "IDMA_PHYSADDR_SEND_PAYLOAD",
  5281. "IDMA_SEND_FIFO_TO_IMSG",
  5282. "IDMA_FL_REQ_DATA_FL",
  5283. "IDMA_FL_DROP",
  5284. "IDMA_FL_DROP_SEND_INC",
  5285. "IDMA_FL_H_REQ_HEADER_FL",
  5286. "IDMA_FL_H_SEND_PCIEHDR",
  5287. "IDMA_FL_H_PUSH_CPL_FIFO",
  5288. "IDMA_FL_H_SEND_CPL",
  5289. "IDMA_FL_H_SEND_IP_HDR_FIRST",
  5290. "IDMA_FL_H_SEND_IP_HDR",
  5291. "IDMA_FL_H_REQ_NEXT_HEADER_FL",
  5292. "IDMA_FL_H_SEND_NEXT_PCIEHDR",
  5293. "IDMA_FL_H_SEND_IP_HDR_PADDING",
  5294. "IDMA_FL_D_SEND_PCIEHDR",
  5295. "IDMA_FL_D_SEND_CPL_AND_IP_HDR",
  5296. "IDMA_FL_D_REQ_NEXT_DATA_FL",
  5297. "IDMA_FL_SEND_PCIEHDR",
  5298. "IDMA_FL_PUSH_CPL_FIFO",
  5299. "IDMA_FL_SEND_CPL",
  5300. "IDMA_FL_SEND_PAYLOAD_FIRST",
  5301. "IDMA_FL_SEND_PAYLOAD",
  5302. "IDMA_FL_REQ_NEXT_DATA_FL",
  5303. "IDMA_FL_SEND_NEXT_PCIEHDR",
  5304. "IDMA_FL_SEND_PADDING",
  5305. "IDMA_FL_SEND_COMPLETION_TO_IMSG",
  5306. };
  5307. static const u32 sge_regs[] = {
  5308. SGE_DEBUG_DATA_LOW_INDEX_2_A,
  5309. SGE_DEBUG_DATA_LOW_INDEX_3_A,
  5310. SGE_DEBUG_DATA_HIGH_INDEX_10_A,
  5311. };
  5312. const char **sge_idma_decode;
  5313. int sge_idma_decode_nstates;
  5314. int i;
  5315. if (is_t4(adapter->params.chip)) {
  5316. sge_idma_decode = (const char **)t4_decode;
  5317. sge_idma_decode_nstates = ARRAY_SIZE(t4_decode);
  5318. } else {
  5319. sge_idma_decode = (const char **)t5_decode;
  5320. sge_idma_decode_nstates = ARRAY_SIZE(t5_decode);
  5321. }
  5322. if (state < sge_idma_decode_nstates)
  5323. CH_WARN(adapter, "idma state %s\n", sge_idma_decode[state]);
  5324. else
  5325. CH_WARN(adapter, "idma state %d unknown\n", state);
  5326. for (i = 0; i < ARRAY_SIZE(sge_regs); i++)
  5327. CH_WARN(adapter, "SGE register %#x value %#x\n",
  5328. sge_regs[i], t4_read_reg(adapter, sge_regs[i]));
  5329. }
  5330. /**
  5331. * t4_sge_ctxt_flush - flush the SGE context cache
  5332. * @adap: the adapter
  5333. * @mbox: mailbox to use for the FW command
  5334. *
  5335. * Issues a FW command through the given mailbox to flush the
  5336. * SGE context cache.
  5337. */
  5338. int t4_sge_ctxt_flush(struct adapter *adap, unsigned int mbox)
  5339. {
  5340. int ret;
  5341. u32 ldst_addrspace;
  5342. struct fw_ldst_cmd c;
  5343. memset(&c, 0, sizeof(c));
  5344. ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_SGE_EGRC);
  5345. c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
  5346. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  5347. ldst_addrspace);
  5348. c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
  5349. c.u.idctxt.msg_ctxtflush = cpu_to_be32(FW_LDST_CMD_CTXTFLUSH_F);
  5350. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  5351. return ret;
  5352. }
  5353. /**
  5354. * t4_fw_hello - establish communication with FW
  5355. * @adap: the adapter
  5356. * @mbox: mailbox to use for the FW command
  5357. * @evt_mbox: mailbox to receive async FW events
  5358. * @master: specifies the caller's willingness to be the device master
  5359. * @state: returns the current device state (if non-NULL)
  5360. *
  5361. * Issues a command to establish communication with FW. Returns either
  5362. * an error (negative integer) or the mailbox of the Master PF.
  5363. */
  5364. int t4_fw_hello(struct adapter *adap, unsigned int mbox, unsigned int evt_mbox,
  5365. enum dev_master master, enum dev_state *state)
  5366. {
  5367. int ret;
  5368. struct fw_hello_cmd c;
  5369. u32 v;
  5370. unsigned int master_mbox;
  5371. int retries = FW_CMD_HELLO_RETRIES;
  5372. retry:
  5373. memset(&c, 0, sizeof(c));
  5374. INIT_CMD(c, HELLO, WRITE);
  5375. c.err_to_clearinit = cpu_to_be32(
  5376. FW_HELLO_CMD_MASTERDIS_V(master == MASTER_CANT) |
  5377. FW_HELLO_CMD_MASTERFORCE_V(master == MASTER_MUST) |
  5378. FW_HELLO_CMD_MBMASTER_V(master == MASTER_MUST ?
  5379. mbox : FW_HELLO_CMD_MBMASTER_M) |
  5380. FW_HELLO_CMD_MBASYNCNOT_V(evt_mbox) |
  5381. FW_HELLO_CMD_STAGE_V(fw_hello_cmd_stage_os) |
  5382. FW_HELLO_CMD_CLEARINIT_F);
  5383. /*
  5384. * Issue the HELLO command to the firmware. If it's not successful
  5385. * but indicates that we got a "busy" or "timeout" condition, retry
  5386. * the HELLO until we exhaust our retry limit. If we do exceed our
  5387. * retry limit, check to see if the firmware left us any error
  5388. * information and report that if so.
  5389. */
  5390. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  5391. if (ret < 0) {
  5392. if ((ret == -EBUSY || ret == -ETIMEDOUT) && retries-- > 0)
  5393. goto retry;
  5394. if (t4_read_reg(adap, PCIE_FW_A) & PCIE_FW_ERR_F)
  5395. t4_report_fw_error(adap);
  5396. return ret;
  5397. }
  5398. v = be32_to_cpu(c.err_to_clearinit);
  5399. master_mbox = FW_HELLO_CMD_MBMASTER_G(v);
  5400. if (state) {
  5401. if (v & FW_HELLO_CMD_ERR_F)
  5402. *state = DEV_STATE_ERR;
  5403. else if (v & FW_HELLO_CMD_INIT_F)
  5404. *state = DEV_STATE_INIT;
  5405. else
  5406. *state = DEV_STATE_UNINIT;
  5407. }
  5408. /*
  5409. * If we're not the Master PF then we need to wait around for the
  5410. * Master PF Driver to finish setting up the adapter.
  5411. *
  5412. * Note that we also do this wait if we're a non-Master-capable PF and
  5413. * there is no current Master PF; a Master PF may show up momentarily
  5414. * and we wouldn't want to fail pointlessly. (This can happen when an
  5415. * OS loads lots of different drivers rapidly at the same time). In
  5416. * this case, the Master PF returned by the firmware will be
  5417. * PCIE_FW_MASTER_M so the test below will work ...
  5418. */
  5419. if ((v & (FW_HELLO_CMD_ERR_F|FW_HELLO_CMD_INIT_F)) == 0 &&
  5420. master_mbox != mbox) {
  5421. int waiting = FW_CMD_HELLO_TIMEOUT;
  5422. /*
  5423. * Wait for the firmware to either indicate an error or
  5424. * initialized state. If we see either of these we bail out
  5425. * and report the issue to the caller. If we exhaust the
  5426. * "hello timeout" and we haven't exhausted our retries, try
  5427. * again. Otherwise bail with a timeout error.
  5428. */
  5429. for (;;) {
  5430. u32 pcie_fw;
  5431. msleep(50);
  5432. waiting -= 50;
  5433. /*
  5434. * If neither Error nor Initialialized are indicated
  5435. * by the firmware keep waiting till we exaust our
  5436. * timeout ... and then retry if we haven't exhausted
  5437. * our retries ...
  5438. */
  5439. pcie_fw = t4_read_reg(adap, PCIE_FW_A);
  5440. if (!(pcie_fw & (PCIE_FW_ERR_F|PCIE_FW_INIT_F))) {
  5441. if (waiting <= 0) {
  5442. if (retries-- > 0)
  5443. goto retry;
  5444. return -ETIMEDOUT;
  5445. }
  5446. continue;
  5447. }
  5448. /*
  5449. * We either have an Error or Initialized condition
  5450. * report errors preferentially.
  5451. */
  5452. if (state) {
  5453. if (pcie_fw & PCIE_FW_ERR_F)
  5454. *state = DEV_STATE_ERR;
  5455. else if (pcie_fw & PCIE_FW_INIT_F)
  5456. *state = DEV_STATE_INIT;
  5457. }
  5458. /*
  5459. * If we arrived before a Master PF was selected and
  5460. * there's not a valid Master PF, grab its identity
  5461. * for our caller.
  5462. */
  5463. if (master_mbox == PCIE_FW_MASTER_M &&
  5464. (pcie_fw & PCIE_FW_MASTER_VLD_F))
  5465. master_mbox = PCIE_FW_MASTER_G(pcie_fw);
  5466. break;
  5467. }
  5468. }
  5469. return master_mbox;
  5470. }
  5471. /**
  5472. * t4_fw_bye - end communication with FW
  5473. * @adap: the adapter
  5474. * @mbox: mailbox to use for the FW command
  5475. *
  5476. * Issues a command to terminate communication with FW.
  5477. */
  5478. int t4_fw_bye(struct adapter *adap, unsigned int mbox)
  5479. {
  5480. struct fw_bye_cmd c;
  5481. memset(&c, 0, sizeof(c));
  5482. INIT_CMD(c, BYE, WRITE);
  5483. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5484. }
  5485. /**
  5486. * t4_init_cmd - ask FW to initialize the device
  5487. * @adap: the adapter
  5488. * @mbox: mailbox to use for the FW command
  5489. *
  5490. * Issues a command to FW to partially initialize the device. This
  5491. * performs initialization that generally doesn't depend on user input.
  5492. */
  5493. int t4_early_init(struct adapter *adap, unsigned int mbox)
  5494. {
  5495. struct fw_initialize_cmd c;
  5496. memset(&c, 0, sizeof(c));
  5497. INIT_CMD(c, INITIALIZE, WRITE);
  5498. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5499. }
  5500. /**
  5501. * t4_fw_reset - issue a reset to FW
  5502. * @adap: the adapter
  5503. * @mbox: mailbox to use for the FW command
  5504. * @reset: specifies the type of reset to perform
  5505. *
  5506. * Issues a reset command of the specified type to FW.
  5507. */
  5508. int t4_fw_reset(struct adapter *adap, unsigned int mbox, int reset)
  5509. {
  5510. struct fw_reset_cmd c;
  5511. memset(&c, 0, sizeof(c));
  5512. INIT_CMD(c, RESET, WRITE);
  5513. c.val = cpu_to_be32(reset);
  5514. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5515. }
  5516. /**
  5517. * t4_fw_halt - issue a reset/halt to FW and put uP into RESET
  5518. * @adap: the adapter
  5519. * @mbox: mailbox to use for the FW RESET command (if desired)
  5520. * @force: force uP into RESET even if FW RESET command fails
  5521. *
  5522. * Issues a RESET command to firmware (if desired) with a HALT indication
  5523. * and then puts the microprocessor into RESET state. The RESET command
  5524. * will only be issued if a legitimate mailbox is provided (mbox <=
  5525. * PCIE_FW_MASTER_M).
  5526. *
  5527. * This is generally used in order for the host to safely manipulate the
  5528. * adapter without fear of conflicting with whatever the firmware might
  5529. * be doing. The only way out of this state is to RESTART the firmware
  5530. * ...
  5531. */
  5532. static int t4_fw_halt(struct adapter *adap, unsigned int mbox, int force)
  5533. {
  5534. int ret = 0;
  5535. /*
  5536. * If a legitimate mailbox is provided, issue a RESET command
  5537. * with a HALT indication.
  5538. */
  5539. if (mbox <= PCIE_FW_MASTER_M) {
  5540. struct fw_reset_cmd c;
  5541. memset(&c, 0, sizeof(c));
  5542. INIT_CMD(c, RESET, WRITE);
  5543. c.val = cpu_to_be32(PIORST_F | PIORSTMODE_F);
  5544. c.halt_pkd = cpu_to_be32(FW_RESET_CMD_HALT_F);
  5545. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5546. }
  5547. /*
  5548. * Normally we won't complete the operation if the firmware RESET
  5549. * command fails but if our caller insists we'll go ahead and put the
  5550. * uP into RESET. This can be useful if the firmware is hung or even
  5551. * missing ... We'll have to take the risk of putting the uP into
  5552. * RESET without the cooperation of firmware in that case.
  5553. *
  5554. * We also force the firmware's HALT flag to be on in case we bypassed
  5555. * the firmware RESET command above or we're dealing with old firmware
  5556. * which doesn't have the HALT capability. This will serve as a flag
  5557. * for the incoming firmware to know that it's coming out of a HALT
  5558. * rather than a RESET ... if it's new enough to understand that ...
  5559. */
  5560. if (ret == 0 || force) {
  5561. t4_set_reg_field(adap, CIM_BOOT_CFG_A, UPCRST_F, UPCRST_F);
  5562. t4_set_reg_field(adap, PCIE_FW_A, PCIE_FW_HALT_F,
  5563. PCIE_FW_HALT_F);
  5564. }
  5565. /*
  5566. * And we always return the result of the firmware RESET command
  5567. * even when we force the uP into RESET ...
  5568. */
  5569. return ret;
  5570. }
  5571. /**
  5572. * t4_fw_restart - restart the firmware by taking the uP out of RESET
  5573. * @adap: the adapter
  5574. * @reset: if we want to do a RESET to restart things
  5575. *
  5576. * Restart firmware previously halted by t4_fw_halt(). On successful
  5577. * return the previous PF Master remains as the new PF Master and there
  5578. * is no need to issue a new HELLO command, etc.
  5579. *
  5580. * We do this in two ways:
  5581. *
  5582. * 1. If we're dealing with newer firmware we'll simply want to take
  5583. * the chip's microprocessor out of RESET. This will cause the
  5584. * firmware to start up from its start vector. And then we'll loop
  5585. * until the firmware indicates it's started again (PCIE_FW.HALT
  5586. * reset to 0) or we timeout.
  5587. *
  5588. * 2. If we're dealing with older firmware then we'll need to RESET
  5589. * the chip since older firmware won't recognize the PCIE_FW.HALT
  5590. * flag and automatically RESET itself on startup.
  5591. */
  5592. static int t4_fw_restart(struct adapter *adap, unsigned int mbox, int reset)
  5593. {
  5594. if (reset) {
  5595. /*
  5596. * Since we're directing the RESET instead of the firmware
  5597. * doing it automatically, we need to clear the PCIE_FW.HALT
  5598. * bit.
  5599. */
  5600. t4_set_reg_field(adap, PCIE_FW_A, PCIE_FW_HALT_F, 0);
  5601. /*
  5602. * If we've been given a valid mailbox, first try to get the
  5603. * firmware to do the RESET. If that works, great and we can
  5604. * return success. Otherwise, if we haven't been given a
  5605. * valid mailbox or the RESET command failed, fall back to
  5606. * hitting the chip with a hammer.
  5607. */
  5608. if (mbox <= PCIE_FW_MASTER_M) {
  5609. t4_set_reg_field(adap, CIM_BOOT_CFG_A, UPCRST_F, 0);
  5610. msleep(100);
  5611. if (t4_fw_reset(adap, mbox,
  5612. PIORST_F | PIORSTMODE_F) == 0)
  5613. return 0;
  5614. }
  5615. t4_write_reg(adap, PL_RST_A, PIORST_F | PIORSTMODE_F);
  5616. msleep(2000);
  5617. } else {
  5618. int ms;
  5619. t4_set_reg_field(adap, CIM_BOOT_CFG_A, UPCRST_F, 0);
  5620. for (ms = 0; ms < FW_CMD_MAX_TIMEOUT; ) {
  5621. if (!(t4_read_reg(adap, PCIE_FW_A) & PCIE_FW_HALT_F))
  5622. return 0;
  5623. msleep(100);
  5624. ms += 100;
  5625. }
  5626. return -ETIMEDOUT;
  5627. }
  5628. return 0;
  5629. }
  5630. /**
  5631. * t4_fw_upgrade - perform all of the steps necessary to upgrade FW
  5632. * @adap: the adapter
  5633. * @mbox: mailbox to use for the FW RESET command (if desired)
  5634. * @fw_data: the firmware image to write
  5635. * @size: image size
  5636. * @force: force upgrade even if firmware doesn't cooperate
  5637. *
  5638. * Perform all of the steps necessary for upgrading an adapter's
  5639. * firmware image. Normally this requires the cooperation of the
  5640. * existing firmware in order to halt all existing activities
  5641. * but if an invalid mailbox token is passed in we skip that step
  5642. * (though we'll still put the adapter microprocessor into RESET in
  5643. * that case).
  5644. *
  5645. * On successful return the new firmware will have been loaded and
  5646. * the adapter will have been fully RESET losing all previous setup
  5647. * state. On unsuccessful return the adapter may be completely hosed ...
  5648. * positive errno indicates that the adapter is ~probably~ intact, a
  5649. * negative errno indicates that things are looking bad ...
  5650. */
  5651. int t4_fw_upgrade(struct adapter *adap, unsigned int mbox,
  5652. const u8 *fw_data, unsigned int size, int force)
  5653. {
  5654. const struct fw_hdr *fw_hdr = (const struct fw_hdr *)fw_data;
  5655. int reset, ret;
  5656. if (!t4_fw_matches_chip(adap, fw_hdr))
  5657. return -EINVAL;
  5658. /* Disable FW_OK flag so that mbox commands with FW_OK flag set
  5659. * wont be sent when we are flashing FW.
  5660. */
  5661. adap->flags &= ~FW_OK;
  5662. ret = t4_fw_halt(adap, mbox, force);
  5663. if (ret < 0 && !force)
  5664. goto out;
  5665. ret = t4_load_fw(adap, fw_data, size);
  5666. if (ret < 0)
  5667. goto out;
  5668. /*
  5669. * Older versions of the firmware don't understand the new
  5670. * PCIE_FW.HALT flag and so won't know to perform a RESET when they
  5671. * restart. So for newly loaded older firmware we'll have to do the
  5672. * RESET for it so it starts up on a clean slate. We can tell if
  5673. * the newly loaded firmware will handle this right by checking
  5674. * its header flags to see if it advertises the capability.
  5675. */
  5676. reset = ((be32_to_cpu(fw_hdr->flags) & FW_HDR_FLAGS_RESET_HALT) == 0);
  5677. ret = t4_fw_restart(adap, mbox, reset);
  5678. /* Grab potentially new Firmware Device Log parameters so we can see
  5679. * how healthy the new Firmware is. It's okay to contact the new
  5680. * Firmware for these parameters even though, as far as it's
  5681. * concerned, we've never said "HELLO" to it ...
  5682. */
  5683. (void)t4_init_devlog_params(adap);
  5684. out:
  5685. adap->flags |= FW_OK;
  5686. return ret;
  5687. }
  5688. /**
  5689. * t4_fixup_host_params - fix up host-dependent parameters
  5690. * @adap: the adapter
  5691. * @page_size: the host's Base Page Size
  5692. * @cache_line_size: the host's Cache Line Size
  5693. *
  5694. * Various registers in T4 contain values which are dependent on the
  5695. * host's Base Page and Cache Line Sizes. This function will fix all of
  5696. * those registers with the appropriate values as passed in ...
  5697. */
  5698. int t4_fixup_host_params(struct adapter *adap, unsigned int page_size,
  5699. unsigned int cache_line_size)
  5700. {
  5701. unsigned int page_shift = fls(page_size) - 1;
  5702. unsigned int sge_hps = page_shift - 10;
  5703. unsigned int stat_len = cache_line_size > 64 ? 128 : 64;
  5704. unsigned int fl_align = cache_line_size < 32 ? 32 : cache_line_size;
  5705. unsigned int fl_align_log = fls(fl_align) - 1;
  5706. t4_write_reg(adap, SGE_HOST_PAGE_SIZE_A,
  5707. HOSTPAGESIZEPF0_V(sge_hps) |
  5708. HOSTPAGESIZEPF1_V(sge_hps) |
  5709. HOSTPAGESIZEPF2_V(sge_hps) |
  5710. HOSTPAGESIZEPF3_V(sge_hps) |
  5711. HOSTPAGESIZEPF4_V(sge_hps) |
  5712. HOSTPAGESIZEPF5_V(sge_hps) |
  5713. HOSTPAGESIZEPF6_V(sge_hps) |
  5714. HOSTPAGESIZEPF7_V(sge_hps));
  5715. if (is_t4(adap->params.chip)) {
  5716. t4_set_reg_field(adap, SGE_CONTROL_A,
  5717. INGPADBOUNDARY_V(INGPADBOUNDARY_M) |
  5718. EGRSTATUSPAGESIZE_F,
  5719. INGPADBOUNDARY_V(fl_align_log -
  5720. INGPADBOUNDARY_SHIFT_X) |
  5721. EGRSTATUSPAGESIZE_V(stat_len != 64));
  5722. } else {
  5723. /* T5 introduced the separation of the Free List Padding and
  5724. * Packing Boundaries. Thus, we can select a smaller Padding
  5725. * Boundary to avoid uselessly chewing up PCIe Link and Memory
  5726. * Bandwidth, and use a Packing Boundary which is large enough
  5727. * to avoid false sharing between CPUs, etc.
  5728. *
  5729. * For the PCI Link, the smaller the Padding Boundary the
  5730. * better. For the Memory Controller, a smaller Padding
  5731. * Boundary is better until we cross under the Memory Line
  5732. * Size (the minimum unit of transfer to/from Memory). If we
  5733. * have a Padding Boundary which is smaller than the Memory
  5734. * Line Size, that'll involve a Read-Modify-Write cycle on the
  5735. * Memory Controller which is never good. For T5 the smallest
  5736. * Padding Boundary which we can select is 32 bytes which is
  5737. * larger than any known Memory Controller Line Size so we'll
  5738. * use that.
  5739. *
  5740. * T5 has a different interpretation of the "0" value for the
  5741. * Packing Boundary. This corresponds to 16 bytes instead of
  5742. * the expected 32 bytes. We never have a Packing Boundary
  5743. * less than 32 bytes so we can't use that special value but
  5744. * on the other hand, if we wanted 32 bytes, the best we can
  5745. * really do is 64 bytes.
  5746. */
  5747. if (fl_align <= 32) {
  5748. fl_align = 64;
  5749. fl_align_log = 6;
  5750. }
  5751. t4_set_reg_field(adap, SGE_CONTROL_A,
  5752. INGPADBOUNDARY_V(INGPADBOUNDARY_M) |
  5753. EGRSTATUSPAGESIZE_F,
  5754. INGPADBOUNDARY_V(INGPCIEBOUNDARY_32B_X) |
  5755. EGRSTATUSPAGESIZE_V(stat_len != 64));
  5756. t4_set_reg_field(adap, SGE_CONTROL2_A,
  5757. INGPACKBOUNDARY_V(INGPACKBOUNDARY_M),
  5758. INGPACKBOUNDARY_V(fl_align_log -
  5759. INGPACKBOUNDARY_SHIFT_X));
  5760. }
  5761. /*
  5762. * Adjust various SGE Free List Host Buffer Sizes.
  5763. *
  5764. * This is something of a crock since we're using fixed indices into
  5765. * the array which are also known by the sge.c code and the T4
  5766. * Firmware Configuration File. We need to come up with a much better
  5767. * approach to managing this array. For now, the first four entries
  5768. * are:
  5769. *
  5770. * 0: Host Page Size
  5771. * 1: 64KB
  5772. * 2: Buffer size corresponding to 1500 byte MTU (unpacked mode)
  5773. * 3: Buffer size corresponding to 9000 byte MTU (unpacked mode)
  5774. *
  5775. * For the single-MTU buffers in unpacked mode we need to include
  5776. * space for the SGE Control Packet Shift, 14 byte Ethernet header,
  5777. * possible 4 byte VLAN tag, all rounded up to the next Ingress Packet
  5778. * Padding boundary. All of these are accommodated in the Factory
  5779. * Default Firmware Configuration File but we need to adjust it for
  5780. * this host's cache line size.
  5781. */
  5782. t4_write_reg(adap, SGE_FL_BUFFER_SIZE0_A, page_size);
  5783. t4_write_reg(adap, SGE_FL_BUFFER_SIZE2_A,
  5784. (t4_read_reg(adap, SGE_FL_BUFFER_SIZE2_A) + fl_align-1)
  5785. & ~(fl_align-1));
  5786. t4_write_reg(adap, SGE_FL_BUFFER_SIZE3_A,
  5787. (t4_read_reg(adap, SGE_FL_BUFFER_SIZE3_A) + fl_align-1)
  5788. & ~(fl_align-1));
  5789. t4_write_reg(adap, ULP_RX_TDDP_PSZ_A, HPZ0_V(page_shift - 12));
  5790. return 0;
  5791. }
  5792. /**
  5793. * t4_fw_initialize - ask FW to initialize the device
  5794. * @adap: the adapter
  5795. * @mbox: mailbox to use for the FW command
  5796. *
  5797. * Issues a command to FW to partially initialize the device. This
  5798. * performs initialization that generally doesn't depend on user input.
  5799. */
  5800. int t4_fw_initialize(struct adapter *adap, unsigned int mbox)
  5801. {
  5802. struct fw_initialize_cmd c;
  5803. memset(&c, 0, sizeof(c));
  5804. INIT_CMD(c, INITIALIZE, WRITE);
  5805. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5806. }
  5807. /**
  5808. * t4_query_params_rw - query FW or device parameters
  5809. * @adap: the adapter
  5810. * @mbox: mailbox to use for the FW command
  5811. * @pf: the PF
  5812. * @vf: the VF
  5813. * @nparams: the number of parameters
  5814. * @params: the parameter names
  5815. * @val: the parameter values
  5816. * @rw: Write and read flag
  5817. *
  5818. * Reads the value of FW or device parameters. Up to 7 parameters can be
  5819. * queried at once.
  5820. */
  5821. int t4_query_params_rw(struct adapter *adap, unsigned int mbox, unsigned int pf,
  5822. unsigned int vf, unsigned int nparams, const u32 *params,
  5823. u32 *val, int rw)
  5824. {
  5825. int i, ret;
  5826. struct fw_params_cmd c;
  5827. __be32 *p = &c.param[0].mnem;
  5828. if (nparams > 7)
  5829. return -EINVAL;
  5830. memset(&c, 0, sizeof(c));
  5831. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PARAMS_CMD) |
  5832. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  5833. FW_PARAMS_CMD_PFN_V(pf) |
  5834. FW_PARAMS_CMD_VFN_V(vf));
  5835. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  5836. for (i = 0; i < nparams; i++) {
  5837. *p++ = cpu_to_be32(*params++);
  5838. if (rw)
  5839. *p = cpu_to_be32(*(val + i));
  5840. p++;
  5841. }
  5842. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  5843. if (ret == 0)
  5844. for (i = 0, p = &c.param[0].val; i < nparams; i++, p += 2)
  5845. *val++ = be32_to_cpu(*p);
  5846. return ret;
  5847. }
  5848. int t4_query_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
  5849. unsigned int vf, unsigned int nparams, const u32 *params,
  5850. u32 *val)
  5851. {
  5852. return t4_query_params_rw(adap, mbox, pf, vf, nparams, params, val, 0);
  5853. }
  5854. /**
  5855. * t4_set_params_timeout - sets FW or device parameters
  5856. * @adap: the adapter
  5857. * @mbox: mailbox to use for the FW command
  5858. * @pf: the PF
  5859. * @vf: the VF
  5860. * @nparams: the number of parameters
  5861. * @params: the parameter names
  5862. * @val: the parameter values
  5863. * @timeout: the timeout time
  5864. *
  5865. * Sets the value of FW or device parameters. Up to 7 parameters can be
  5866. * specified at once.
  5867. */
  5868. int t4_set_params_timeout(struct adapter *adap, unsigned int mbox,
  5869. unsigned int pf, unsigned int vf,
  5870. unsigned int nparams, const u32 *params,
  5871. const u32 *val, int timeout)
  5872. {
  5873. struct fw_params_cmd c;
  5874. __be32 *p = &c.param[0].mnem;
  5875. if (nparams > 7)
  5876. return -EINVAL;
  5877. memset(&c, 0, sizeof(c));
  5878. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PARAMS_CMD) |
  5879. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  5880. FW_PARAMS_CMD_PFN_V(pf) |
  5881. FW_PARAMS_CMD_VFN_V(vf));
  5882. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  5883. while (nparams--) {
  5884. *p++ = cpu_to_be32(*params++);
  5885. *p++ = cpu_to_be32(*val++);
  5886. }
  5887. return t4_wr_mbox_timeout(adap, mbox, &c, sizeof(c), NULL, timeout);
  5888. }
  5889. /**
  5890. * t4_set_params - sets FW or device parameters
  5891. * @adap: the adapter
  5892. * @mbox: mailbox to use for the FW command
  5893. * @pf: the PF
  5894. * @vf: the VF
  5895. * @nparams: the number of parameters
  5896. * @params: the parameter names
  5897. * @val: the parameter values
  5898. *
  5899. * Sets the value of FW or device parameters. Up to 7 parameters can be
  5900. * specified at once.
  5901. */
  5902. int t4_set_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
  5903. unsigned int vf, unsigned int nparams, const u32 *params,
  5904. const u32 *val)
  5905. {
  5906. return t4_set_params_timeout(adap, mbox, pf, vf, nparams, params, val,
  5907. FW_CMD_MAX_TIMEOUT);
  5908. }
  5909. /**
  5910. * t4_cfg_pfvf - configure PF/VF resource limits
  5911. * @adap: the adapter
  5912. * @mbox: mailbox to use for the FW command
  5913. * @pf: the PF being configured
  5914. * @vf: the VF being configured
  5915. * @txq: the max number of egress queues
  5916. * @txq_eth_ctrl: the max number of egress Ethernet or control queues
  5917. * @rxqi: the max number of interrupt-capable ingress queues
  5918. * @rxq: the max number of interruptless ingress queues
  5919. * @tc: the PCI traffic class
  5920. * @vi: the max number of virtual interfaces
  5921. * @cmask: the channel access rights mask for the PF/VF
  5922. * @pmask: the port access rights mask for the PF/VF
  5923. * @nexact: the maximum number of exact MPS filters
  5924. * @rcaps: read capabilities
  5925. * @wxcaps: write/execute capabilities
  5926. *
  5927. * Configures resource limits and capabilities for a physical or virtual
  5928. * function.
  5929. */
  5930. int t4_cfg_pfvf(struct adapter *adap, unsigned int mbox, unsigned int pf,
  5931. unsigned int vf, unsigned int txq, unsigned int txq_eth_ctrl,
  5932. unsigned int rxqi, unsigned int rxq, unsigned int tc,
  5933. unsigned int vi, unsigned int cmask, unsigned int pmask,
  5934. unsigned int nexact, unsigned int rcaps, unsigned int wxcaps)
  5935. {
  5936. struct fw_pfvf_cmd c;
  5937. memset(&c, 0, sizeof(c));
  5938. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PFVF_CMD) | FW_CMD_REQUEST_F |
  5939. FW_CMD_WRITE_F | FW_PFVF_CMD_PFN_V(pf) |
  5940. FW_PFVF_CMD_VFN_V(vf));
  5941. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  5942. c.niqflint_niq = cpu_to_be32(FW_PFVF_CMD_NIQFLINT_V(rxqi) |
  5943. FW_PFVF_CMD_NIQ_V(rxq));
  5944. c.type_to_neq = cpu_to_be32(FW_PFVF_CMD_CMASK_V(cmask) |
  5945. FW_PFVF_CMD_PMASK_V(pmask) |
  5946. FW_PFVF_CMD_NEQ_V(txq));
  5947. c.tc_to_nexactf = cpu_to_be32(FW_PFVF_CMD_TC_V(tc) |
  5948. FW_PFVF_CMD_NVI_V(vi) |
  5949. FW_PFVF_CMD_NEXACTF_V(nexact));
  5950. c.r_caps_to_nethctrl = cpu_to_be32(FW_PFVF_CMD_R_CAPS_V(rcaps) |
  5951. FW_PFVF_CMD_WX_CAPS_V(wxcaps) |
  5952. FW_PFVF_CMD_NETHCTRL_V(txq_eth_ctrl));
  5953. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5954. }
  5955. /**
  5956. * t4_alloc_vi - allocate a virtual interface
  5957. * @adap: the adapter
  5958. * @mbox: mailbox to use for the FW command
  5959. * @port: physical port associated with the VI
  5960. * @pf: the PF owning the VI
  5961. * @vf: the VF owning the VI
  5962. * @nmac: number of MAC addresses needed (1 to 5)
  5963. * @mac: the MAC addresses of the VI
  5964. * @rss_size: size of RSS table slice associated with this VI
  5965. *
  5966. * Allocates a virtual interface for the given physical port. If @mac is
  5967. * not %NULL it contains the MAC addresses of the VI as assigned by FW.
  5968. * @mac should be large enough to hold @nmac Ethernet addresses, they are
  5969. * stored consecutively so the space needed is @nmac * 6 bytes.
  5970. * Returns a negative error number or the non-negative VI id.
  5971. */
  5972. int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
  5973. unsigned int pf, unsigned int vf, unsigned int nmac, u8 *mac,
  5974. unsigned int *rss_size)
  5975. {
  5976. int ret;
  5977. struct fw_vi_cmd c;
  5978. memset(&c, 0, sizeof(c));
  5979. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_VI_CMD) | FW_CMD_REQUEST_F |
  5980. FW_CMD_WRITE_F | FW_CMD_EXEC_F |
  5981. FW_VI_CMD_PFN_V(pf) | FW_VI_CMD_VFN_V(vf));
  5982. c.alloc_to_len16 = cpu_to_be32(FW_VI_CMD_ALLOC_F | FW_LEN16(c));
  5983. c.portid_pkd = FW_VI_CMD_PORTID_V(port);
  5984. c.nmac = nmac - 1;
  5985. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  5986. if (ret)
  5987. return ret;
  5988. if (mac) {
  5989. memcpy(mac, c.mac, sizeof(c.mac));
  5990. switch (nmac) {
  5991. case 5:
  5992. memcpy(mac + 24, c.nmac3, sizeof(c.nmac3));
  5993. case 4:
  5994. memcpy(mac + 18, c.nmac2, sizeof(c.nmac2));
  5995. case 3:
  5996. memcpy(mac + 12, c.nmac1, sizeof(c.nmac1));
  5997. case 2:
  5998. memcpy(mac + 6, c.nmac0, sizeof(c.nmac0));
  5999. }
  6000. }
  6001. if (rss_size)
  6002. *rss_size = FW_VI_CMD_RSSSIZE_G(be16_to_cpu(c.rsssize_pkd));
  6003. return FW_VI_CMD_VIID_G(be16_to_cpu(c.type_viid));
  6004. }
  6005. /**
  6006. * t4_free_vi - free a virtual interface
  6007. * @adap: the adapter
  6008. * @mbox: mailbox to use for the FW command
  6009. * @pf: the PF owning the VI
  6010. * @vf: the VF owning the VI
  6011. * @viid: virtual interface identifiler
  6012. *
  6013. * Free a previously allocated virtual interface.
  6014. */
  6015. int t4_free_vi(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6016. unsigned int vf, unsigned int viid)
  6017. {
  6018. struct fw_vi_cmd c;
  6019. memset(&c, 0, sizeof(c));
  6020. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_VI_CMD) |
  6021. FW_CMD_REQUEST_F |
  6022. FW_CMD_EXEC_F |
  6023. FW_VI_CMD_PFN_V(pf) |
  6024. FW_VI_CMD_VFN_V(vf));
  6025. c.alloc_to_len16 = cpu_to_be32(FW_VI_CMD_FREE_F | FW_LEN16(c));
  6026. c.type_viid = cpu_to_be16(FW_VI_CMD_VIID_V(viid));
  6027. return t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  6028. }
  6029. /**
  6030. * t4_set_rxmode - set Rx properties of a virtual interface
  6031. * @adap: the adapter
  6032. * @mbox: mailbox to use for the FW command
  6033. * @viid: the VI id
  6034. * @mtu: the new MTU or -1
  6035. * @promisc: 1 to enable promiscuous mode, 0 to disable it, -1 no change
  6036. * @all_multi: 1 to enable all-multi mode, 0 to disable it, -1 no change
  6037. * @bcast: 1 to enable broadcast Rx, 0 to disable it, -1 no change
  6038. * @vlanex: 1 to enable HW VLAN extraction, 0 to disable it, -1 no change
  6039. * @sleep_ok: if true we may sleep while awaiting command completion
  6040. *
  6041. * Sets Rx properties of a virtual interface.
  6042. */
  6043. int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
  6044. int mtu, int promisc, int all_multi, int bcast, int vlanex,
  6045. bool sleep_ok)
  6046. {
  6047. struct fw_vi_rxmode_cmd c;
  6048. /* convert to FW values */
  6049. if (mtu < 0)
  6050. mtu = FW_RXMODE_MTU_NO_CHG;
  6051. if (promisc < 0)
  6052. promisc = FW_VI_RXMODE_CMD_PROMISCEN_M;
  6053. if (all_multi < 0)
  6054. all_multi = FW_VI_RXMODE_CMD_ALLMULTIEN_M;
  6055. if (bcast < 0)
  6056. bcast = FW_VI_RXMODE_CMD_BROADCASTEN_M;
  6057. if (vlanex < 0)
  6058. vlanex = FW_VI_RXMODE_CMD_VLANEXEN_M;
  6059. memset(&c, 0, sizeof(c));
  6060. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_RXMODE_CMD) |
  6061. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  6062. FW_VI_RXMODE_CMD_VIID_V(viid));
  6063. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  6064. c.mtu_to_vlanexen =
  6065. cpu_to_be32(FW_VI_RXMODE_CMD_MTU_V(mtu) |
  6066. FW_VI_RXMODE_CMD_PROMISCEN_V(promisc) |
  6067. FW_VI_RXMODE_CMD_ALLMULTIEN_V(all_multi) |
  6068. FW_VI_RXMODE_CMD_BROADCASTEN_V(bcast) |
  6069. FW_VI_RXMODE_CMD_VLANEXEN_V(vlanex));
  6070. return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
  6071. }
  6072. /**
  6073. * t4_alloc_mac_filt - allocates exact-match filters for MAC addresses
  6074. * @adap: the adapter
  6075. * @mbox: mailbox to use for the FW command
  6076. * @viid: the VI id
  6077. * @free: if true any existing filters for this VI id are first removed
  6078. * @naddr: the number of MAC addresses to allocate filters for (up to 7)
  6079. * @addr: the MAC address(es)
  6080. * @idx: where to store the index of each allocated filter
  6081. * @hash: pointer to hash address filter bitmap
  6082. * @sleep_ok: call is allowed to sleep
  6083. *
  6084. * Allocates an exact-match filter for each of the supplied addresses and
  6085. * sets it to the corresponding address. If @idx is not %NULL it should
  6086. * have at least @naddr entries, each of which will be set to the index of
  6087. * the filter allocated for the corresponding MAC address. If a filter
  6088. * could not be allocated for an address its index is set to 0xffff.
  6089. * If @hash is not %NULL addresses that fail to allocate an exact filter
  6090. * are hashed and update the hash filter bitmap pointed at by @hash.
  6091. *
  6092. * Returns a negative error number or the number of filters allocated.
  6093. */
  6094. int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox,
  6095. unsigned int viid, bool free, unsigned int naddr,
  6096. const u8 **addr, u16 *idx, u64 *hash, bool sleep_ok)
  6097. {
  6098. int offset, ret = 0;
  6099. struct fw_vi_mac_cmd c;
  6100. unsigned int nfilters = 0;
  6101. unsigned int max_naddr = adap->params.arch.mps_tcam_size;
  6102. unsigned int rem = naddr;
  6103. if (naddr > max_naddr)
  6104. return -EINVAL;
  6105. for (offset = 0; offset < naddr ; /**/) {
  6106. unsigned int fw_naddr = (rem < ARRAY_SIZE(c.u.exact) ?
  6107. rem : ARRAY_SIZE(c.u.exact));
  6108. size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
  6109. u.exact[fw_naddr]), 16);
  6110. struct fw_vi_mac_exact *p;
  6111. int i;
  6112. memset(&c, 0, sizeof(c));
  6113. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
  6114. FW_CMD_REQUEST_F |
  6115. FW_CMD_WRITE_F |
  6116. FW_CMD_EXEC_V(free) |
  6117. FW_VI_MAC_CMD_VIID_V(viid));
  6118. c.freemacs_to_len16 =
  6119. cpu_to_be32(FW_VI_MAC_CMD_FREEMACS_V(free) |
  6120. FW_CMD_LEN16_V(len16));
  6121. for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
  6122. p->valid_to_idx =
  6123. cpu_to_be16(FW_VI_MAC_CMD_VALID_F |
  6124. FW_VI_MAC_CMD_IDX_V(
  6125. FW_VI_MAC_ADD_MAC));
  6126. memcpy(p->macaddr, addr[offset + i],
  6127. sizeof(p->macaddr));
  6128. }
  6129. /* It's okay if we run out of space in our MAC address arena.
  6130. * Some of the addresses we submit may get stored so we need
  6131. * to run through the reply to see what the results were ...
  6132. */
  6133. ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), &c, sleep_ok);
  6134. if (ret && ret != -FW_ENOMEM)
  6135. break;
  6136. for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
  6137. u16 index = FW_VI_MAC_CMD_IDX_G(
  6138. be16_to_cpu(p->valid_to_idx));
  6139. if (idx)
  6140. idx[offset + i] = (index >= max_naddr ?
  6141. 0xffff : index);
  6142. if (index < max_naddr)
  6143. nfilters++;
  6144. else if (hash)
  6145. *hash |= (1ULL <<
  6146. hash_mac_addr(addr[offset + i]));
  6147. }
  6148. free = false;
  6149. offset += fw_naddr;
  6150. rem -= fw_naddr;
  6151. }
  6152. if (ret == 0 || ret == -FW_ENOMEM)
  6153. ret = nfilters;
  6154. return ret;
  6155. }
  6156. /**
  6157. * t4_change_mac - modifies the exact-match filter for a MAC address
  6158. * @adap: the adapter
  6159. * @mbox: mailbox to use for the FW command
  6160. * @viid: the VI id
  6161. * @idx: index of existing filter for old value of MAC address, or -1
  6162. * @addr: the new MAC address value
  6163. * @persist: whether a new MAC allocation should be persistent
  6164. * @add_smt: if true also add the address to the HW SMT
  6165. *
  6166. * Modifies an exact-match filter and sets it to the new MAC address.
  6167. * Note that in general it is not possible to modify the value of a given
  6168. * filter so the generic way to modify an address filter is to free the one
  6169. * being used by the old address value and allocate a new filter for the
  6170. * new address value. @idx can be -1 if the address is a new addition.
  6171. *
  6172. * Returns a negative error number or the index of the filter with the new
  6173. * MAC value.
  6174. */
  6175. int t4_change_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
  6176. int idx, const u8 *addr, bool persist, bool add_smt)
  6177. {
  6178. int ret, mode;
  6179. struct fw_vi_mac_cmd c;
  6180. struct fw_vi_mac_exact *p = c.u.exact;
  6181. unsigned int max_mac_addr = adap->params.arch.mps_tcam_size;
  6182. if (idx < 0) /* new allocation */
  6183. idx = persist ? FW_VI_MAC_ADD_PERSIST_MAC : FW_VI_MAC_ADD_MAC;
  6184. mode = add_smt ? FW_VI_MAC_SMT_AND_MPSTCAM : FW_VI_MAC_MPS_TCAM_ENTRY;
  6185. memset(&c, 0, sizeof(c));
  6186. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
  6187. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  6188. FW_VI_MAC_CMD_VIID_V(viid));
  6189. c.freemacs_to_len16 = cpu_to_be32(FW_CMD_LEN16_V(1));
  6190. p->valid_to_idx = cpu_to_be16(FW_VI_MAC_CMD_VALID_F |
  6191. FW_VI_MAC_CMD_SMAC_RESULT_V(mode) |
  6192. FW_VI_MAC_CMD_IDX_V(idx));
  6193. memcpy(p->macaddr, addr, sizeof(p->macaddr));
  6194. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  6195. if (ret == 0) {
  6196. ret = FW_VI_MAC_CMD_IDX_G(be16_to_cpu(p->valid_to_idx));
  6197. if (ret >= max_mac_addr)
  6198. ret = -ENOMEM;
  6199. }
  6200. return ret;
  6201. }
  6202. /**
  6203. * t4_set_addr_hash - program the MAC inexact-match hash filter
  6204. * @adap: the adapter
  6205. * @mbox: mailbox to use for the FW command
  6206. * @viid: the VI id
  6207. * @ucast: whether the hash filter should also match unicast addresses
  6208. * @vec: the value to be written to the hash filter
  6209. * @sleep_ok: call is allowed to sleep
  6210. *
  6211. * Sets the 64-bit inexact-match hash filter for a virtual interface.
  6212. */
  6213. int t4_set_addr_hash(struct adapter *adap, unsigned int mbox, unsigned int viid,
  6214. bool ucast, u64 vec, bool sleep_ok)
  6215. {
  6216. struct fw_vi_mac_cmd c;
  6217. memset(&c, 0, sizeof(c));
  6218. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
  6219. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  6220. FW_VI_ENABLE_CMD_VIID_V(viid));
  6221. c.freemacs_to_len16 = cpu_to_be32(FW_VI_MAC_CMD_HASHVECEN_F |
  6222. FW_VI_MAC_CMD_HASHUNIEN_V(ucast) |
  6223. FW_CMD_LEN16_V(1));
  6224. c.u.hash.hashvec = cpu_to_be64(vec);
  6225. return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
  6226. }
  6227. /**
  6228. * t4_enable_vi_params - enable/disable a virtual interface
  6229. * @adap: the adapter
  6230. * @mbox: mailbox to use for the FW command
  6231. * @viid: the VI id
  6232. * @rx_en: 1=enable Rx, 0=disable Rx
  6233. * @tx_en: 1=enable Tx, 0=disable Tx
  6234. * @dcb_en: 1=enable delivery of Data Center Bridging messages.
  6235. *
  6236. * Enables/disables a virtual interface. Note that setting DCB Enable
  6237. * only makes sense when enabling a Virtual Interface ...
  6238. */
  6239. int t4_enable_vi_params(struct adapter *adap, unsigned int mbox,
  6240. unsigned int viid, bool rx_en, bool tx_en, bool dcb_en)
  6241. {
  6242. struct fw_vi_enable_cmd c;
  6243. memset(&c, 0, sizeof(c));
  6244. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_ENABLE_CMD) |
  6245. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  6246. FW_VI_ENABLE_CMD_VIID_V(viid));
  6247. c.ien_to_len16 = cpu_to_be32(FW_VI_ENABLE_CMD_IEN_V(rx_en) |
  6248. FW_VI_ENABLE_CMD_EEN_V(tx_en) |
  6249. FW_VI_ENABLE_CMD_DCB_INFO_V(dcb_en) |
  6250. FW_LEN16(c));
  6251. return t4_wr_mbox_ns(adap, mbox, &c, sizeof(c), NULL);
  6252. }
  6253. /**
  6254. * t4_enable_vi - enable/disable a virtual interface
  6255. * @adap: the adapter
  6256. * @mbox: mailbox to use for the FW command
  6257. * @viid: the VI id
  6258. * @rx_en: 1=enable Rx, 0=disable Rx
  6259. * @tx_en: 1=enable Tx, 0=disable Tx
  6260. *
  6261. * Enables/disables a virtual interface.
  6262. */
  6263. int t4_enable_vi(struct adapter *adap, unsigned int mbox, unsigned int viid,
  6264. bool rx_en, bool tx_en)
  6265. {
  6266. return t4_enable_vi_params(adap, mbox, viid, rx_en, tx_en, 0);
  6267. }
  6268. /**
  6269. * t4_identify_port - identify a VI's port by blinking its LED
  6270. * @adap: the adapter
  6271. * @mbox: mailbox to use for the FW command
  6272. * @viid: the VI id
  6273. * @nblinks: how many times to blink LED at 2.5 Hz
  6274. *
  6275. * Identifies a VI's port by blinking its LED.
  6276. */
  6277. int t4_identify_port(struct adapter *adap, unsigned int mbox, unsigned int viid,
  6278. unsigned int nblinks)
  6279. {
  6280. struct fw_vi_enable_cmd c;
  6281. memset(&c, 0, sizeof(c));
  6282. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_ENABLE_CMD) |
  6283. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  6284. FW_VI_ENABLE_CMD_VIID_V(viid));
  6285. c.ien_to_len16 = cpu_to_be32(FW_VI_ENABLE_CMD_LED_F | FW_LEN16(c));
  6286. c.blinkdur = cpu_to_be16(nblinks);
  6287. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  6288. }
  6289. /**
  6290. * t4_iq_free - free an ingress queue and its FLs
  6291. * @adap: the adapter
  6292. * @mbox: mailbox to use for the FW command
  6293. * @pf: the PF owning the queues
  6294. * @vf: the VF owning the queues
  6295. * @iqtype: the ingress queue type
  6296. * @iqid: ingress queue id
  6297. * @fl0id: FL0 queue id or 0xffff if no attached FL0
  6298. * @fl1id: FL1 queue id or 0xffff if no attached FL1
  6299. *
  6300. * Frees an ingress queue and its associated FLs, if any.
  6301. */
  6302. int t4_iq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6303. unsigned int vf, unsigned int iqtype, unsigned int iqid,
  6304. unsigned int fl0id, unsigned int fl1id)
  6305. {
  6306. struct fw_iq_cmd c;
  6307. memset(&c, 0, sizeof(c));
  6308. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_IQ_CMD) | FW_CMD_REQUEST_F |
  6309. FW_CMD_EXEC_F | FW_IQ_CMD_PFN_V(pf) |
  6310. FW_IQ_CMD_VFN_V(vf));
  6311. c.alloc_to_len16 = cpu_to_be32(FW_IQ_CMD_FREE_F | FW_LEN16(c));
  6312. c.type_to_iqandstindex = cpu_to_be32(FW_IQ_CMD_TYPE_V(iqtype));
  6313. c.iqid = cpu_to_be16(iqid);
  6314. c.fl0id = cpu_to_be16(fl0id);
  6315. c.fl1id = cpu_to_be16(fl1id);
  6316. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  6317. }
  6318. /**
  6319. * t4_eth_eq_free - free an Ethernet egress queue
  6320. * @adap: the adapter
  6321. * @mbox: mailbox to use for the FW command
  6322. * @pf: the PF owning the queue
  6323. * @vf: the VF owning the queue
  6324. * @eqid: egress queue id
  6325. *
  6326. * Frees an Ethernet egress queue.
  6327. */
  6328. int t4_eth_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6329. unsigned int vf, unsigned int eqid)
  6330. {
  6331. struct fw_eq_eth_cmd c;
  6332. memset(&c, 0, sizeof(c));
  6333. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_EQ_ETH_CMD) |
  6334. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  6335. FW_EQ_ETH_CMD_PFN_V(pf) |
  6336. FW_EQ_ETH_CMD_VFN_V(vf));
  6337. c.alloc_to_len16 = cpu_to_be32(FW_EQ_ETH_CMD_FREE_F | FW_LEN16(c));
  6338. c.eqid_pkd = cpu_to_be32(FW_EQ_ETH_CMD_EQID_V(eqid));
  6339. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  6340. }
  6341. /**
  6342. * t4_ctrl_eq_free - free a control egress queue
  6343. * @adap: the adapter
  6344. * @mbox: mailbox to use for the FW command
  6345. * @pf: the PF owning the queue
  6346. * @vf: the VF owning the queue
  6347. * @eqid: egress queue id
  6348. *
  6349. * Frees a control egress queue.
  6350. */
  6351. int t4_ctrl_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6352. unsigned int vf, unsigned int eqid)
  6353. {
  6354. struct fw_eq_ctrl_cmd c;
  6355. memset(&c, 0, sizeof(c));
  6356. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_EQ_CTRL_CMD) |
  6357. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  6358. FW_EQ_CTRL_CMD_PFN_V(pf) |
  6359. FW_EQ_CTRL_CMD_VFN_V(vf));
  6360. c.alloc_to_len16 = cpu_to_be32(FW_EQ_CTRL_CMD_FREE_F | FW_LEN16(c));
  6361. c.cmpliqid_eqid = cpu_to_be32(FW_EQ_CTRL_CMD_EQID_V(eqid));
  6362. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  6363. }
  6364. /**
  6365. * t4_ofld_eq_free - free an offload egress queue
  6366. * @adap: the adapter
  6367. * @mbox: mailbox to use for the FW command
  6368. * @pf: the PF owning the queue
  6369. * @vf: the VF owning the queue
  6370. * @eqid: egress queue id
  6371. *
  6372. * Frees a control egress queue.
  6373. */
  6374. int t4_ofld_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6375. unsigned int vf, unsigned int eqid)
  6376. {
  6377. struct fw_eq_ofld_cmd c;
  6378. memset(&c, 0, sizeof(c));
  6379. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_EQ_OFLD_CMD) |
  6380. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  6381. FW_EQ_OFLD_CMD_PFN_V(pf) |
  6382. FW_EQ_OFLD_CMD_VFN_V(vf));
  6383. c.alloc_to_len16 = cpu_to_be32(FW_EQ_OFLD_CMD_FREE_F | FW_LEN16(c));
  6384. c.eqid_pkd = cpu_to_be32(FW_EQ_OFLD_CMD_EQID_V(eqid));
  6385. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  6386. }
  6387. /**
  6388. * t4_handle_fw_rpl - process a FW reply message
  6389. * @adap: the adapter
  6390. * @rpl: start of the FW message
  6391. *
  6392. * Processes a FW message, such as link state change messages.
  6393. */
  6394. int t4_handle_fw_rpl(struct adapter *adap, const __be64 *rpl)
  6395. {
  6396. u8 opcode = *(const u8 *)rpl;
  6397. if (opcode == FW_PORT_CMD) { /* link/module state change message */
  6398. int speed = 0, fc = 0;
  6399. const struct fw_port_cmd *p = (void *)rpl;
  6400. int chan = FW_PORT_CMD_PORTID_G(be32_to_cpu(p->op_to_portid));
  6401. int port = adap->chan_map[chan];
  6402. struct port_info *pi = adap2pinfo(adap, port);
  6403. struct link_config *lc = &pi->link_cfg;
  6404. u32 stat = be32_to_cpu(p->u.info.lstatus_to_modtype);
  6405. int link_ok = (stat & FW_PORT_CMD_LSTATUS_F) != 0;
  6406. u32 mod = FW_PORT_CMD_MODTYPE_G(stat);
  6407. if (stat & FW_PORT_CMD_RXPAUSE_F)
  6408. fc |= PAUSE_RX;
  6409. if (stat & FW_PORT_CMD_TXPAUSE_F)
  6410. fc |= PAUSE_TX;
  6411. if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_100M))
  6412. speed = 100;
  6413. else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_1G))
  6414. speed = 1000;
  6415. else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_10G))
  6416. speed = 10000;
  6417. else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_40G))
  6418. speed = 40000;
  6419. if (link_ok != lc->link_ok || speed != lc->speed ||
  6420. fc != lc->fc) { /* something changed */
  6421. lc->link_ok = link_ok;
  6422. lc->speed = speed;
  6423. lc->fc = fc;
  6424. lc->supported = be16_to_cpu(p->u.info.pcap);
  6425. t4_os_link_changed(adap, port, link_ok);
  6426. }
  6427. if (mod != pi->mod_type) {
  6428. pi->mod_type = mod;
  6429. t4_os_portmod_changed(adap, port);
  6430. }
  6431. }
  6432. return 0;
  6433. }
  6434. static void get_pci_mode(struct adapter *adapter, struct pci_params *p)
  6435. {
  6436. u16 val;
  6437. if (pci_is_pcie(adapter->pdev)) {
  6438. pcie_capability_read_word(adapter->pdev, PCI_EXP_LNKSTA, &val);
  6439. p->speed = val & PCI_EXP_LNKSTA_CLS;
  6440. p->width = (val & PCI_EXP_LNKSTA_NLW) >> 4;
  6441. }
  6442. }
  6443. /**
  6444. * init_link_config - initialize a link's SW state
  6445. * @lc: structure holding the link state
  6446. * @caps: link capabilities
  6447. *
  6448. * Initializes the SW state maintained for each link, including the link's
  6449. * capabilities and default speed/flow-control/autonegotiation settings.
  6450. */
  6451. static void init_link_config(struct link_config *lc, unsigned int caps)
  6452. {
  6453. lc->supported = caps;
  6454. lc->requested_speed = 0;
  6455. lc->speed = 0;
  6456. lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX;
  6457. if (lc->supported & FW_PORT_CAP_ANEG) {
  6458. lc->advertising = lc->supported & ADVERT_MASK;
  6459. lc->autoneg = AUTONEG_ENABLE;
  6460. lc->requested_fc |= PAUSE_AUTONEG;
  6461. } else {
  6462. lc->advertising = 0;
  6463. lc->autoneg = AUTONEG_DISABLE;
  6464. }
  6465. }
  6466. #define CIM_PF_NOACCESS 0xeeeeeeee
  6467. int t4_wait_dev_ready(void __iomem *regs)
  6468. {
  6469. u32 whoami;
  6470. whoami = readl(regs + PL_WHOAMI_A);
  6471. if (whoami != 0xffffffff && whoami != CIM_PF_NOACCESS)
  6472. return 0;
  6473. msleep(500);
  6474. whoami = readl(regs + PL_WHOAMI_A);
  6475. return (whoami != 0xffffffff && whoami != CIM_PF_NOACCESS ? 0 : -EIO);
  6476. }
  6477. struct flash_desc {
  6478. u32 vendor_and_model_id;
  6479. u32 size_mb;
  6480. };
  6481. static int get_flash_params(struct adapter *adap)
  6482. {
  6483. /* Table for non-Numonix supported flash parts. Numonix parts are left
  6484. * to the preexisting code. All flash parts have 64KB sectors.
  6485. */
  6486. static struct flash_desc supported_flash[] = {
  6487. { 0x150201, 4 << 20 }, /* Spansion 4MB S25FL032P */
  6488. };
  6489. int ret;
  6490. u32 info;
  6491. ret = sf1_write(adap, 1, 1, 0, SF_RD_ID);
  6492. if (!ret)
  6493. ret = sf1_read(adap, 3, 0, 1, &info);
  6494. t4_write_reg(adap, SF_OP_A, 0); /* unlock SF */
  6495. if (ret)
  6496. return ret;
  6497. for (ret = 0; ret < ARRAY_SIZE(supported_flash); ++ret)
  6498. if (supported_flash[ret].vendor_and_model_id == info) {
  6499. adap->params.sf_size = supported_flash[ret].size_mb;
  6500. adap->params.sf_nsec =
  6501. adap->params.sf_size / SF_SEC_SIZE;
  6502. return 0;
  6503. }
  6504. if ((info & 0xff) != 0x20) /* not a Numonix flash */
  6505. return -EINVAL;
  6506. info >>= 16; /* log2 of size */
  6507. if (info >= 0x14 && info < 0x18)
  6508. adap->params.sf_nsec = 1 << (info - 16);
  6509. else if (info == 0x18)
  6510. adap->params.sf_nsec = 64;
  6511. else
  6512. return -EINVAL;
  6513. adap->params.sf_size = 1 << info;
  6514. adap->params.sf_fw_start =
  6515. t4_read_reg(adap, CIM_BOOT_CFG_A) & BOOTADDR_M;
  6516. if (adap->params.sf_size < FLASH_MIN_SIZE)
  6517. dev_warn(adap->pdev_dev, "WARNING!!! FLASH size %#x < %#x!!!\n",
  6518. adap->params.sf_size, FLASH_MIN_SIZE);
  6519. return 0;
  6520. }
  6521. static void set_pcie_completion_timeout(struct adapter *adapter, u8 range)
  6522. {
  6523. u16 val;
  6524. u32 pcie_cap;
  6525. pcie_cap = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
  6526. if (pcie_cap) {
  6527. pci_read_config_word(adapter->pdev,
  6528. pcie_cap + PCI_EXP_DEVCTL2, &val);
  6529. val &= ~PCI_EXP_DEVCTL2_COMP_TIMEOUT;
  6530. val |= range;
  6531. pci_write_config_word(adapter->pdev,
  6532. pcie_cap + PCI_EXP_DEVCTL2, val);
  6533. }
  6534. }
  6535. /**
  6536. * t4_prep_adapter - prepare SW and HW for operation
  6537. * @adapter: the adapter
  6538. * @reset: if true perform a HW reset
  6539. *
  6540. * Initialize adapter SW state for the various HW modules, set initial
  6541. * values for some adapter tunables, take PHYs out of reset, and
  6542. * initialize the MDIO interface.
  6543. */
  6544. int t4_prep_adapter(struct adapter *adapter)
  6545. {
  6546. int ret, ver;
  6547. uint16_t device_id;
  6548. u32 pl_rev;
  6549. get_pci_mode(adapter, &adapter->params.pci);
  6550. pl_rev = REV_G(t4_read_reg(adapter, PL_REV_A));
  6551. ret = get_flash_params(adapter);
  6552. if (ret < 0) {
  6553. dev_err(adapter->pdev_dev, "error %d identifying flash\n", ret);
  6554. return ret;
  6555. }
  6556. /* Retrieve adapter's device ID
  6557. */
  6558. pci_read_config_word(adapter->pdev, PCI_DEVICE_ID, &device_id);
  6559. ver = device_id >> 12;
  6560. adapter->params.chip = 0;
  6561. switch (ver) {
  6562. case CHELSIO_T4:
  6563. adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T4, pl_rev);
  6564. adapter->params.arch.sge_fl_db = DBPRIO_F;
  6565. adapter->params.arch.mps_tcam_size =
  6566. NUM_MPS_CLS_SRAM_L_INSTANCES;
  6567. adapter->params.arch.mps_rplc_size = 128;
  6568. adapter->params.arch.nchan = NCHAN;
  6569. adapter->params.arch.vfcount = 128;
  6570. break;
  6571. case CHELSIO_T5:
  6572. adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T5, pl_rev);
  6573. adapter->params.arch.sge_fl_db = DBPRIO_F | DBTYPE_F;
  6574. adapter->params.arch.mps_tcam_size =
  6575. NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
  6576. adapter->params.arch.mps_rplc_size = 128;
  6577. adapter->params.arch.nchan = NCHAN;
  6578. adapter->params.arch.vfcount = 128;
  6579. break;
  6580. case CHELSIO_T6:
  6581. adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T6, pl_rev);
  6582. adapter->params.arch.sge_fl_db = 0;
  6583. adapter->params.arch.mps_tcam_size =
  6584. NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
  6585. adapter->params.arch.mps_rplc_size = 256;
  6586. adapter->params.arch.nchan = 2;
  6587. adapter->params.arch.vfcount = 256;
  6588. break;
  6589. default:
  6590. dev_err(adapter->pdev_dev, "Device %d is not supported\n",
  6591. device_id);
  6592. return -EINVAL;
  6593. }
  6594. adapter->params.cim_la_size = CIMLA_SIZE;
  6595. init_cong_ctrl(adapter->params.a_wnd, adapter->params.b_wnd);
  6596. /*
  6597. * Default port for debugging in case we can't reach FW.
  6598. */
  6599. adapter->params.nports = 1;
  6600. adapter->params.portvec = 1;
  6601. adapter->params.vpd.cclk = 50000;
  6602. /* Set pci completion timeout value to 4 seconds. */
  6603. set_pcie_completion_timeout(adapter, 0xd);
  6604. return 0;
  6605. }
  6606. /**
  6607. * t4_bar2_sge_qregs - return BAR2 SGE Queue register information
  6608. * @adapter: the adapter
  6609. * @qid: the Queue ID
  6610. * @qtype: the Ingress or Egress type for @qid
  6611. * @user: true if this request is for a user mode queue
  6612. * @pbar2_qoffset: BAR2 Queue Offset
  6613. * @pbar2_qid: BAR2 Queue ID or 0 for Queue ID inferred SGE Queues
  6614. *
  6615. * Returns the BAR2 SGE Queue Registers information associated with the
  6616. * indicated Absolute Queue ID. These are passed back in return value
  6617. * pointers. @qtype should be T4_BAR2_QTYPE_EGRESS for Egress Queue
  6618. * and T4_BAR2_QTYPE_INGRESS for Ingress Queues.
  6619. *
  6620. * This may return an error which indicates that BAR2 SGE Queue
  6621. * registers aren't available. If an error is not returned, then the
  6622. * following values are returned:
  6623. *
  6624. * *@pbar2_qoffset: the BAR2 Offset of the @qid Registers
  6625. * *@pbar2_qid: the BAR2 SGE Queue ID or 0 of @qid
  6626. *
  6627. * If the returned BAR2 Queue ID is 0, then BAR2 SGE registers which
  6628. * require the "Inferred Queue ID" ability may be used. E.g. the
  6629. * Write Combining Doorbell Buffer. If the BAR2 Queue ID is not 0,
  6630. * then these "Inferred Queue ID" register may not be used.
  6631. */
  6632. int t4_bar2_sge_qregs(struct adapter *adapter,
  6633. unsigned int qid,
  6634. enum t4_bar2_qtype qtype,
  6635. int user,
  6636. u64 *pbar2_qoffset,
  6637. unsigned int *pbar2_qid)
  6638. {
  6639. unsigned int page_shift, page_size, qpp_shift, qpp_mask;
  6640. u64 bar2_page_offset, bar2_qoffset;
  6641. unsigned int bar2_qid, bar2_qid_offset, bar2_qinferred;
  6642. /* T4 doesn't support BAR2 SGE Queue registers for kernel mode queues */
  6643. if (!user && is_t4(adapter->params.chip))
  6644. return -EINVAL;
  6645. /* Get our SGE Page Size parameters.
  6646. */
  6647. page_shift = adapter->params.sge.hps + 10;
  6648. page_size = 1 << page_shift;
  6649. /* Get the right Queues per Page parameters for our Queue.
  6650. */
  6651. qpp_shift = (qtype == T4_BAR2_QTYPE_EGRESS
  6652. ? adapter->params.sge.eq_qpp
  6653. : adapter->params.sge.iq_qpp);
  6654. qpp_mask = (1 << qpp_shift) - 1;
  6655. /* Calculate the basics of the BAR2 SGE Queue register area:
  6656. * o The BAR2 page the Queue registers will be in.
  6657. * o The BAR2 Queue ID.
  6658. * o The BAR2 Queue ID Offset into the BAR2 page.
  6659. */
  6660. bar2_page_offset = ((u64)(qid >> qpp_shift) << page_shift);
  6661. bar2_qid = qid & qpp_mask;
  6662. bar2_qid_offset = bar2_qid * SGE_UDB_SIZE;
  6663. /* If the BAR2 Queue ID Offset is less than the Page Size, then the
  6664. * hardware will infer the Absolute Queue ID simply from the writes to
  6665. * the BAR2 Queue ID Offset within the BAR2 Page (and we need to use a
  6666. * BAR2 Queue ID of 0 for those writes). Otherwise, we'll simply
  6667. * write to the first BAR2 SGE Queue Area within the BAR2 Page with
  6668. * the BAR2 Queue ID and the hardware will infer the Absolute Queue ID
  6669. * from the BAR2 Page and BAR2 Queue ID.
  6670. *
  6671. * One important censequence of this is that some BAR2 SGE registers
  6672. * have a "Queue ID" field and we can write the BAR2 SGE Queue ID
  6673. * there. But other registers synthesize the SGE Queue ID purely
  6674. * from the writes to the registers -- the Write Combined Doorbell
  6675. * Buffer is a good example. These BAR2 SGE Registers are only
  6676. * available for those BAR2 SGE Register areas where the SGE Absolute
  6677. * Queue ID can be inferred from simple writes.
  6678. */
  6679. bar2_qoffset = bar2_page_offset;
  6680. bar2_qinferred = (bar2_qid_offset < page_size);
  6681. if (bar2_qinferred) {
  6682. bar2_qoffset += bar2_qid_offset;
  6683. bar2_qid = 0;
  6684. }
  6685. *pbar2_qoffset = bar2_qoffset;
  6686. *pbar2_qid = bar2_qid;
  6687. return 0;
  6688. }
  6689. /**
  6690. * t4_init_devlog_params - initialize adapter->params.devlog
  6691. * @adap: the adapter
  6692. *
  6693. * Initialize various fields of the adapter's Firmware Device Log
  6694. * Parameters structure.
  6695. */
  6696. int t4_init_devlog_params(struct adapter *adap)
  6697. {
  6698. struct devlog_params *dparams = &adap->params.devlog;
  6699. u32 pf_dparams;
  6700. unsigned int devlog_meminfo;
  6701. struct fw_devlog_cmd devlog_cmd;
  6702. int ret;
  6703. /* If we're dealing with newer firmware, the Device Log Paramerters
  6704. * are stored in a designated register which allows us to access the
  6705. * Device Log even if we can't talk to the firmware.
  6706. */
  6707. pf_dparams =
  6708. t4_read_reg(adap, PCIE_FW_REG(PCIE_FW_PF_A, PCIE_FW_PF_DEVLOG));
  6709. if (pf_dparams) {
  6710. unsigned int nentries, nentries128;
  6711. dparams->memtype = PCIE_FW_PF_DEVLOG_MEMTYPE_G(pf_dparams);
  6712. dparams->start = PCIE_FW_PF_DEVLOG_ADDR16_G(pf_dparams) << 4;
  6713. nentries128 = PCIE_FW_PF_DEVLOG_NENTRIES128_G(pf_dparams);
  6714. nentries = (nentries128 + 1) * 128;
  6715. dparams->size = nentries * sizeof(struct fw_devlog_e);
  6716. return 0;
  6717. }
  6718. /* Otherwise, ask the firmware for it's Device Log Parameters.
  6719. */
  6720. memset(&devlog_cmd, 0, sizeof(devlog_cmd));
  6721. devlog_cmd.op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_DEVLOG_CMD) |
  6722. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  6723. devlog_cmd.retval_len16 = cpu_to_be32(FW_LEN16(devlog_cmd));
  6724. ret = t4_wr_mbox(adap, adap->mbox, &devlog_cmd, sizeof(devlog_cmd),
  6725. &devlog_cmd);
  6726. if (ret)
  6727. return ret;
  6728. devlog_meminfo =
  6729. be32_to_cpu(devlog_cmd.memtype_devlog_memaddr16_devlog);
  6730. dparams->memtype = FW_DEVLOG_CMD_MEMTYPE_DEVLOG_G(devlog_meminfo);
  6731. dparams->start = FW_DEVLOG_CMD_MEMADDR16_DEVLOG_G(devlog_meminfo) << 4;
  6732. dparams->size = be32_to_cpu(devlog_cmd.memsize_devlog);
  6733. return 0;
  6734. }
  6735. /**
  6736. * t4_init_sge_params - initialize adap->params.sge
  6737. * @adapter: the adapter
  6738. *
  6739. * Initialize various fields of the adapter's SGE Parameters structure.
  6740. */
  6741. int t4_init_sge_params(struct adapter *adapter)
  6742. {
  6743. struct sge_params *sge_params = &adapter->params.sge;
  6744. u32 hps, qpp;
  6745. unsigned int s_hps, s_qpp;
  6746. /* Extract the SGE Page Size for our PF.
  6747. */
  6748. hps = t4_read_reg(adapter, SGE_HOST_PAGE_SIZE_A);
  6749. s_hps = (HOSTPAGESIZEPF0_S +
  6750. (HOSTPAGESIZEPF1_S - HOSTPAGESIZEPF0_S) * adapter->pf);
  6751. sge_params->hps = ((hps >> s_hps) & HOSTPAGESIZEPF0_M);
  6752. /* Extract the SGE Egress and Ingess Queues Per Page for our PF.
  6753. */
  6754. s_qpp = (QUEUESPERPAGEPF0_S +
  6755. (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) * adapter->pf);
  6756. qpp = t4_read_reg(adapter, SGE_EGRESS_QUEUES_PER_PAGE_PF_A);
  6757. sge_params->eq_qpp = ((qpp >> s_qpp) & QUEUESPERPAGEPF0_M);
  6758. qpp = t4_read_reg(adapter, SGE_INGRESS_QUEUES_PER_PAGE_PF_A);
  6759. sge_params->iq_qpp = ((qpp >> s_qpp) & QUEUESPERPAGEPF0_M);
  6760. return 0;
  6761. }
  6762. /**
  6763. * t4_init_tp_params - initialize adap->params.tp
  6764. * @adap: the adapter
  6765. *
  6766. * Initialize various fields of the adapter's TP Parameters structure.
  6767. */
  6768. int t4_init_tp_params(struct adapter *adap)
  6769. {
  6770. int chan;
  6771. u32 v;
  6772. v = t4_read_reg(adap, TP_TIMER_RESOLUTION_A);
  6773. adap->params.tp.tre = TIMERRESOLUTION_G(v);
  6774. adap->params.tp.dack_re = DELAYEDACKRESOLUTION_G(v);
  6775. /* MODQ_REQ_MAP defaults to setting queues 0-3 to chan 0-3 */
  6776. for (chan = 0; chan < NCHAN; chan++)
  6777. adap->params.tp.tx_modq[chan] = chan;
  6778. /* Cache the adapter's Compressed Filter Mode and global Incress
  6779. * Configuration.
  6780. */
  6781. if (t4_use_ldst(adap)) {
  6782. t4_fw_tp_pio_rw(adap, &adap->params.tp.vlan_pri_map, 1,
  6783. TP_VLAN_PRI_MAP_A, 1);
  6784. t4_fw_tp_pio_rw(adap, &adap->params.tp.ingress_config, 1,
  6785. TP_INGRESS_CONFIG_A, 1);
  6786. } else {
  6787. t4_read_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  6788. &adap->params.tp.vlan_pri_map, 1,
  6789. TP_VLAN_PRI_MAP_A);
  6790. t4_read_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  6791. &adap->params.tp.ingress_config, 1,
  6792. TP_INGRESS_CONFIG_A);
  6793. }
  6794. /* Now that we have TP_VLAN_PRI_MAP cached, we can calculate the field
  6795. * shift positions of several elements of the Compressed Filter Tuple
  6796. * for this adapter which we need frequently ...
  6797. */
  6798. adap->params.tp.vlan_shift = t4_filter_field_shift(adap, VLAN_F);
  6799. adap->params.tp.vnic_shift = t4_filter_field_shift(adap, VNIC_ID_F);
  6800. adap->params.tp.port_shift = t4_filter_field_shift(adap, PORT_F);
  6801. adap->params.tp.protocol_shift = t4_filter_field_shift(adap,
  6802. PROTOCOL_F);
  6803. /* If TP_INGRESS_CONFIG.VNID == 0, then TP_VLAN_PRI_MAP.VNIC_ID
  6804. * represents the presence of an Outer VLAN instead of a VNIC ID.
  6805. */
  6806. if ((adap->params.tp.ingress_config & VNIC_F) == 0)
  6807. adap->params.tp.vnic_shift = -1;
  6808. return 0;
  6809. }
  6810. /**
  6811. * t4_filter_field_shift - calculate filter field shift
  6812. * @adap: the adapter
  6813. * @filter_sel: the desired field (from TP_VLAN_PRI_MAP bits)
  6814. *
  6815. * Return the shift position of a filter field within the Compressed
  6816. * Filter Tuple. The filter field is specified via its selection bit
  6817. * within TP_VLAN_PRI_MAL (filter mode). E.g. F_VLAN.
  6818. */
  6819. int t4_filter_field_shift(const struct adapter *adap, int filter_sel)
  6820. {
  6821. unsigned int filter_mode = adap->params.tp.vlan_pri_map;
  6822. unsigned int sel;
  6823. int field_shift;
  6824. if ((filter_mode & filter_sel) == 0)
  6825. return -1;
  6826. for (sel = 1, field_shift = 0; sel < filter_sel; sel <<= 1) {
  6827. switch (filter_mode & sel) {
  6828. case FCOE_F:
  6829. field_shift += FT_FCOE_W;
  6830. break;
  6831. case PORT_F:
  6832. field_shift += FT_PORT_W;
  6833. break;
  6834. case VNIC_ID_F:
  6835. field_shift += FT_VNIC_ID_W;
  6836. break;
  6837. case VLAN_F:
  6838. field_shift += FT_VLAN_W;
  6839. break;
  6840. case TOS_F:
  6841. field_shift += FT_TOS_W;
  6842. break;
  6843. case PROTOCOL_F:
  6844. field_shift += FT_PROTOCOL_W;
  6845. break;
  6846. case ETHERTYPE_F:
  6847. field_shift += FT_ETHERTYPE_W;
  6848. break;
  6849. case MACMATCH_F:
  6850. field_shift += FT_MACMATCH_W;
  6851. break;
  6852. case MPSHITTYPE_F:
  6853. field_shift += FT_MPSHITTYPE_W;
  6854. break;
  6855. case FRAGMENTATION_F:
  6856. field_shift += FT_FRAGMENTATION_W;
  6857. break;
  6858. }
  6859. }
  6860. return field_shift;
  6861. }
  6862. int t4_init_rss_mode(struct adapter *adap, int mbox)
  6863. {
  6864. int i, ret;
  6865. struct fw_rss_vi_config_cmd rvc;
  6866. memset(&rvc, 0, sizeof(rvc));
  6867. for_each_port(adap, i) {
  6868. struct port_info *p = adap2pinfo(adap, i);
  6869. rvc.op_to_viid =
  6870. cpu_to_be32(FW_CMD_OP_V(FW_RSS_VI_CONFIG_CMD) |
  6871. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  6872. FW_RSS_VI_CONFIG_CMD_VIID_V(p->viid));
  6873. rvc.retval_len16 = cpu_to_be32(FW_LEN16(rvc));
  6874. ret = t4_wr_mbox(adap, mbox, &rvc, sizeof(rvc), &rvc);
  6875. if (ret)
  6876. return ret;
  6877. p->rss_mode = be32_to_cpu(rvc.u.basicvirtual.defaultq_to_udpen);
  6878. }
  6879. return 0;
  6880. }
  6881. int t4_port_init(struct adapter *adap, int mbox, int pf, int vf)
  6882. {
  6883. u8 addr[6];
  6884. int ret, i, j = 0;
  6885. struct fw_port_cmd c;
  6886. struct fw_rss_vi_config_cmd rvc;
  6887. memset(&c, 0, sizeof(c));
  6888. memset(&rvc, 0, sizeof(rvc));
  6889. for_each_port(adap, i) {
  6890. unsigned int rss_size;
  6891. struct port_info *p = adap2pinfo(adap, i);
  6892. while ((adap->params.portvec & (1 << j)) == 0)
  6893. j++;
  6894. c.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
  6895. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  6896. FW_PORT_CMD_PORTID_V(j));
  6897. c.action_to_len16 = cpu_to_be32(
  6898. FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_GET_PORT_INFO) |
  6899. FW_LEN16(c));
  6900. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  6901. if (ret)
  6902. return ret;
  6903. ret = t4_alloc_vi(adap, mbox, j, pf, vf, 1, addr, &rss_size);
  6904. if (ret < 0)
  6905. return ret;
  6906. p->viid = ret;
  6907. p->tx_chan = j;
  6908. p->lport = j;
  6909. p->rss_size = rss_size;
  6910. memcpy(adap->port[i]->dev_addr, addr, ETH_ALEN);
  6911. adap->port[i]->dev_port = j;
  6912. ret = be32_to_cpu(c.u.info.lstatus_to_modtype);
  6913. p->mdio_addr = (ret & FW_PORT_CMD_MDIOCAP_F) ?
  6914. FW_PORT_CMD_MDIOADDR_G(ret) : -1;
  6915. p->port_type = FW_PORT_CMD_PTYPE_G(ret);
  6916. p->mod_type = FW_PORT_MOD_TYPE_NA;
  6917. rvc.op_to_viid =
  6918. cpu_to_be32(FW_CMD_OP_V(FW_RSS_VI_CONFIG_CMD) |
  6919. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  6920. FW_RSS_VI_CONFIG_CMD_VIID(p->viid));
  6921. rvc.retval_len16 = cpu_to_be32(FW_LEN16(rvc));
  6922. ret = t4_wr_mbox(adap, mbox, &rvc, sizeof(rvc), &rvc);
  6923. if (ret)
  6924. return ret;
  6925. p->rss_mode = be32_to_cpu(rvc.u.basicvirtual.defaultq_to_udpen);
  6926. init_link_config(&p->link_cfg, be16_to_cpu(c.u.info.pcap));
  6927. j++;
  6928. }
  6929. return 0;
  6930. }
  6931. /**
  6932. * t4_read_cimq_cfg - read CIM queue configuration
  6933. * @adap: the adapter
  6934. * @base: holds the queue base addresses in bytes
  6935. * @size: holds the queue sizes in bytes
  6936. * @thres: holds the queue full thresholds in bytes
  6937. *
  6938. * Returns the current configuration of the CIM queues, starting with
  6939. * the IBQs, then the OBQs.
  6940. */
  6941. void t4_read_cimq_cfg(struct adapter *adap, u16 *base, u16 *size, u16 *thres)
  6942. {
  6943. unsigned int i, v;
  6944. int cim_num_obq = is_t4(adap->params.chip) ?
  6945. CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
  6946. for (i = 0; i < CIM_NUM_IBQ; i++) {
  6947. t4_write_reg(adap, CIM_QUEUE_CONFIG_REF_A, IBQSELECT_F |
  6948. QUENUMSELECT_V(i));
  6949. v = t4_read_reg(adap, CIM_QUEUE_CONFIG_CTRL_A);
  6950. /* value is in 256-byte units */
  6951. *base++ = CIMQBASE_G(v) * 256;
  6952. *size++ = CIMQSIZE_G(v) * 256;
  6953. *thres++ = QUEFULLTHRSH_G(v) * 8; /* 8-byte unit */
  6954. }
  6955. for (i = 0; i < cim_num_obq; i++) {
  6956. t4_write_reg(adap, CIM_QUEUE_CONFIG_REF_A, OBQSELECT_F |
  6957. QUENUMSELECT_V(i));
  6958. v = t4_read_reg(adap, CIM_QUEUE_CONFIG_CTRL_A);
  6959. /* value is in 256-byte units */
  6960. *base++ = CIMQBASE_G(v) * 256;
  6961. *size++ = CIMQSIZE_G(v) * 256;
  6962. }
  6963. }
  6964. /**
  6965. * t4_read_cim_ibq - read the contents of a CIM inbound queue
  6966. * @adap: the adapter
  6967. * @qid: the queue index
  6968. * @data: where to store the queue contents
  6969. * @n: capacity of @data in 32-bit words
  6970. *
  6971. * Reads the contents of the selected CIM queue starting at address 0 up
  6972. * to the capacity of @data. @n must be a multiple of 4. Returns < 0 on
  6973. * error and the number of 32-bit words actually read on success.
  6974. */
  6975. int t4_read_cim_ibq(struct adapter *adap, unsigned int qid, u32 *data, size_t n)
  6976. {
  6977. int i, err, attempts;
  6978. unsigned int addr;
  6979. const unsigned int nwords = CIM_IBQ_SIZE * 4;
  6980. if (qid > 5 || (n & 3))
  6981. return -EINVAL;
  6982. addr = qid * nwords;
  6983. if (n > nwords)
  6984. n = nwords;
  6985. /* It might take 3-10ms before the IBQ debug read access is allowed.
  6986. * Wait for 1 Sec with a delay of 1 usec.
  6987. */
  6988. attempts = 1000000;
  6989. for (i = 0; i < n; i++, addr++) {
  6990. t4_write_reg(adap, CIM_IBQ_DBG_CFG_A, IBQDBGADDR_V(addr) |
  6991. IBQDBGEN_F);
  6992. err = t4_wait_op_done(adap, CIM_IBQ_DBG_CFG_A, IBQDBGBUSY_F, 0,
  6993. attempts, 1);
  6994. if (err)
  6995. return err;
  6996. *data++ = t4_read_reg(adap, CIM_IBQ_DBG_DATA_A);
  6997. }
  6998. t4_write_reg(adap, CIM_IBQ_DBG_CFG_A, 0);
  6999. return i;
  7000. }
  7001. /**
  7002. * t4_read_cim_obq - read the contents of a CIM outbound queue
  7003. * @adap: the adapter
  7004. * @qid: the queue index
  7005. * @data: where to store the queue contents
  7006. * @n: capacity of @data in 32-bit words
  7007. *
  7008. * Reads the contents of the selected CIM queue starting at address 0 up
  7009. * to the capacity of @data. @n must be a multiple of 4. Returns < 0 on
  7010. * error and the number of 32-bit words actually read on success.
  7011. */
  7012. int t4_read_cim_obq(struct adapter *adap, unsigned int qid, u32 *data, size_t n)
  7013. {
  7014. int i, err;
  7015. unsigned int addr, v, nwords;
  7016. int cim_num_obq = is_t4(adap->params.chip) ?
  7017. CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
  7018. if ((qid > (cim_num_obq - 1)) || (n & 3))
  7019. return -EINVAL;
  7020. t4_write_reg(adap, CIM_QUEUE_CONFIG_REF_A, OBQSELECT_F |
  7021. QUENUMSELECT_V(qid));
  7022. v = t4_read_reg(adap, CIM_QUEUE_CONFIG_CTRL_A);
  7023. addr = CIMQBASE_G(v) * 64; /* muliple of 256 -> muliple of 4 */
  7024. nwords = CIMQSIZE_G(v) * 64; /* same */
  7025. if (n > nwords)
  7026. n = nwords;
  7027. for (i = 0; i < n; i++, addr++) {
  7028. t4_write_reg(adap, CIM_OBQ_DBG_CFG_A, OBQDBGADDR_V(addr) |
  7029. OBQDBGEN_F);
  7030. err = t4_wait_op_done(adap, CIM_OBQ_DBG_CFG_A, OBQDBGBUSY_F, 0,
  7031. 2, 1);
  7032. if (err)
  7033. return err;
  7034. *data++ = t4_read_reg(adap, CIM_OBQ_DBG_DATA_A);
  7035. }
  7036. t4_write_reg(adap, CIM_OBQ_DBG_CFG_A, 0);
  7037. return i;
  7038. }
  7039. /**
  7040. * t4_cim_read - read a block from CIM internal address space
  7041. * @adap: the adapter
  7042. * @addr: the start address within the CIM address space
  7043. * @n: number of words to read
  7044. * @valp: where to store the result
  7045. *
  7046. * Reads a block of 4-byte words from the CIM intenal address space.
  7047. */
  7048. int t4_cim_read(struct adapter *adap, unsigned int addr, unsigned int n,
  7049. unsigned int *valp)
  7050. {
  7051. int ret = 0;
  7052. if (t4_read_reg(adap, CIM_HOST_ACC_CTRL_A) & HOSTBUSY_F)
  7053. return -EBUSY;
  7054. for ( ; !ret && n--; addr += 4) {
  7055. t4_write_reg(adap, CIM_HOST_ACC_CTRL_A, addr);
  7056. ret = t4_wait_op_done(adap, CIM_HOST_ACC_CTRL_A, HOSTBUSY_F,
  7057. 0, 5, 2);
  7058. if (!ret)
  7059. *valp++ = t4_read_reg(adap, CIM_HOST_ACC_DATA_A);
  7060. }
  7061. return ret;
  7062. }
  7063. /**
  7064. * t4_cim_write - write a block into CIM internal address space
  7065. * @adap: the adapter
  7066. * @addr: the start address within the CIM address space
  7067. * @n: number of words to write
  7068. * @valp: set of values to write
  7069. *
  7070. * Writes a block of 4-byte words into the CIM intenal address space.
  7071. */
  7072. int t4_cim_write(struct adapter *adap, unsigned int addr, unsigned int n,
  7073. const unsigned int *valp)
  7074. {
  7075. int ret = 0;
  7076. if (t4_read_reg(adap, CIM_HOST_ACC_CTRL_A) & HOSTBUSY_F)
  7077. return -EBUSY;
  7078. for ( ; !ret && n--; addr += 4) {
  7079. t4_write_reg(adap, CIM_HOST_ACC_DATA_A, *valp++);
  7080. t4_write_reg(adap, CIM_HOST_ACC_CTRL_A, addr | HOSTWRITE_F);
  7081. ret = t4_wait_op_done(adap, CIM_HOST_ACC_CTRL_A, HOSTBUSY_F,
  7082. 0, 5, 2);
  7083. }
  7084. return ret;
  7085. }
  7086. static int t4_cim_write1(struct adapter *adap, unsigned int addr,
  7087. unsigned int val)
  7088. {
  7089. return t4_cim_write(adap, addr, 1, &val);
  7090. }
  7091. /**
  7092. * t4_cim_read_la - read CIM LA capture buffer
  7093. * @adap: the adapter
  7094. * @la_buf: where to store the LA data
  7095. * @wrptr: the HW write pointer within the capture buffer
  7096. *
  7097. * Reads the contents of the CIM LA buffer with the most recent entry at
  7098. * the end of the returned data and with the entry at @wrptr first.
  7099. * We try to leave the LA in the running state we find it in.
  7100. */
  7101. int t4_cim_read_la(struct adapter *adap, u32 *la_buf, unsigned int *wrptr)
  7102. {
  7103. int i, ret;
  7104. unsigned int cfg, val, idx;
  7105. ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
  7106. if (ret)
  7107. return ret;
  7108. if (cfg & UPDBGLAEN_F) { /* LA is running, freeze it */
  7109. ret = t4_cim_write1(adap, UP_UP_DBG_LA_CFG_A, 0);
  7110. if (ret)
  7111. return ret;
  7112. }
  7113. ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &val);
  7114. if (ret)
  7115. goto restart;
  7116. idx = UPDBGLAWRPTR_G(val);
  7117. if (wrptr)
  7118. *wrptr = idx;
  7119. for (i = 0; i < adap->params.cim_la_size; i++) {
  7120. ret = t4_cim_write1(adap, UP_UP_DBG_LA_CFG_A,
  7121. UPDBGLARDPTR_V(idx) | UPDBGLARDEN_F);
  7122. if (ret)
  7123. break;
  7124. ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &val);
  7125. if (ret)
  7126. break;
  7127. if (val & UPDBGLARDEN_F) {
  7128. ret = -ETIMEDOUT;
  7129. break;
  7130. }
  7131. ret = t4_cim_read(adap, UP_UP_DBG_LA_DATA_A, 1, &la_buf[i]);
  7132. if (ret)
  7133. break;
  7134. /* Bits 0-3 of UpDbgLaRdPtr can be between 0000 to 1001 to
  7135. * identify the 32-bit portion of the full 312-bit data
  7136. */
  7137. if (is_t6(adap->params.chip) && (idx & 0xf) >= 9)
  7138. idx = (idx & 0xff0) + 0x10;
  7139. else
  7140. idx++;
  7141. /* address can't exceed 0xfff */
  7142. idx &= UPDBGLARDPTR_M;
  7143. }
  7144. restart:
  7145. if (cfg & UPDBGLAEN_F) {
  7146. int r = t4_cim_write1(adap, UP_UP_DBG_LA_CFG_A,
  7147. cfg & ~UPDBGLARDEN_F);
  7148. if (!ret)
  7149. ret = r;
  7150. }
  7151. return ret;
  7152. }
  7153. /**
  7154. * t4_tp_read_la - read TP LA capture buffer
  7155. * @adap: the adapter
  7156. * @la_buf: where to store the LA data
  7157. * @wrptr: the HW write pointer within the capture buffer
  7158. *
  7159. * Reads the contents of the TP LA buffer with the most recent entry at
  7160. * the end of the returned data and with the entry at @wrptr first.
  7161. * We leave the LA in the running state we find it in.
  7162. */
  7163. void t4_tp_read_la(struct adapter *adap, u64 *la_buf, unsigned int *wrptr)
  7164. {
  7165. bool last_incomplete;
  7166. unsigned int i, cfg, val, idx;
  7167. cfg = t4_read_reg(adap, TP_DBG_LA_CONFIG_A) & 0xffff;
  7168. if (cfg & DBGLAENABLE_F) /* freeze LA */
  7169. t4_write_reg(adap, TP_DBG_LA_CONFIG_A,
  7170. adap->params.tp.la_mask | (cfg ^ DBGLAENABLE_F));
  7171. val = t4_read_reg(adap, TP_DBG_LA_CONFIG_A);
  7172. idx = DBGLAWPTR_G(val);
  7173. last_incomplete = DBGLAMODE_G(val) >= 2 && (val & DBGLAWHLF_F) == 0;
  7174. if (last_incomplete)
  7175. idx = (idx + 1) & DBGLARPTR_M;
  7176. if (wrptr)
  7177. *wrptr = idx;
  7178. val &= 0xffff;
  7179. val &= ~DBGLARPTR_V(DBGLARPTR_M);
  7180. val |= adap->params.tp.la_mask;
  7181. for (i = 0; i < TPLA_SIZE; i++) {
  7182. t4_write_reg(adap, TP_DBG_LA_CONFIG_A, DBGLARPTR_V(idx) | val);
  7183. la_buf[i] = t4_read_reg64(adap, TP_DBG_LA_DATAL_A);
  7184. idx = (idx + 1) & DBGLARPTR_M;
  7185. }
  7186. /* Wipe out last entry if it isn't valid */
  7187. if (last_incomplete)
  7188. la_buf[TPLA_SIZE - 1] = ~0ULL;
  7189. if (cfg & DBGLAENABLE_F) /* restore running state */
  7190. t4_write_reg(adap, TP_DBG_LA_CONFIG_A,
  7191. cfg | adap->params.tp.la_mask);
  7192. }
  7193. /* SGE Hung Ingress DMA Warning Threshold time and Warning Repeat Rate (in
  7194. * seconds). If we find one of the SGE Ingress DMA State Machines in the same
  7195. * state for more than the Warning Threshold then we'll issue a warning about
  7196. * a potential hang. We'll repeat the warning as the SGE Ingress DMA Channel
  7197. * appears to be hung every Warning Repeat second till the situation clears.
  7198. * If the situation clears, we'll note that as well.
  7199. */
  7200. #define SGE_IDMA_WARN_THRESH 1
  7201. #define SGE_IDMA_WARN_REPEAT 300
  7202. /**
  7203. * t4_idma_monitor_init - initialize SGE Ingress DMA Monitor
  7204. * @adapter: the adapter
  7205. * @idma: the adapter IDMA Monitor state
  7206. *
  7207. * Initialize the state of an SGE Ingress DMA Monitor.
  7208. */
  7209. void t4_idma_monitor_init(struct adapter *adapter,
  7210. struct sge_idma_monitor_state *idma)
  7211. {
  7212. /* Initialize the state variables for detecting an SGE Ingress DMA
  7213. * hang. The SGE has internal counters which count up on each clock
  7214. * tick whenever the SGE finds its Ingress DMA State Engines in the
  7215. * same state they were on the previous clock tick. The clock used is
  7216. * the Core Clock so we have a limit on the maximum "time" they can
  7217. * record; typically a very small number of seconds. For instance,
  7218. * with a 600MHz Core Clock, we can only count up to a bit more than
  7219. * 7s. So we'll synthesize a larger counter in order to not run the
  7220. * risk of having the "timers" overflow and give us the flexibility to
  7221. * maintain a Hung SGE State Machine of our own which operates across
  7222. * a longer time frame.
  7223. */
  7224. idma->idma_1s_thresh = core_ticks_per_usec(adapter) * 1000000; /* 1s */
  7225. idma->idma_stalled[0] = 0;
  7226. idma->idma_stalled[1] = 0;
  7227. }
  7228. /**
  7229. * t4_idma_monitor - monitor SGE Ingress DMA state
  7230. * @adapter: the adapter
  7231. * @idma: the adapter IDMA Monitor state
  7232. * @hz: number of ticks/second
  7233. * @ticks: number of ticks since the last IDMA Monitor call
  7234. */
  7235. void t4_idma_monitor(struct adapter *adapter,
  7236. struct sge_idma_monitor_state *idma,
  7237. int hz, int ticks)
  7238. {
  7239. int i, idma_same_state_cnt[2];
  7240. /* Read the SGE Debug Ingress DMA Same State Count registers. These
  7241. * are counters inside the SGE which count up on each clock when the
  7242. * SGE finds its Ingress DMA State Engines in the same states they
  7243. * were in the previous clock. The counters will peg out at
  7244. * 0xffffffff without wrapping around so once they pass the 1s
  7245. * threshold they'll stay above that till the IDMA state changes.
  7246. */
  7247. t4_write_reg(adapter, SGE_DEBUG_INDEX_A, 13);
  7248. idma_same_state_cnt[0] = t4_read_reg(adapter, SGE_DEBUG_DATA_HIGH_A);
  7249. idma_same_state_cnt[1] = t4_read_reg(adapter, SGE_DEBUG_DATA_LOW_A);
  7250. for (i = 0; i < 2; i++) {
  7251. u32 debug0, debug11;
  7252. /* If the Ingress DMA Same State Counter ("timer") is less
  7253. * than 1s, then we can reset our synthesized Stall Timer and
  7254. * continue. If we have previously emitted warnings about a
  7255. * potential stalled Ingress Queue, issue a note indicating
  7256. * that the Ingress Queue has resumed forward progress.
  7257. */
  7258. if (idma_same_state_cnt[i] < idma->idma_1s_thresh) {
  7259. if (idma->idma_stalled[i] >= SGE_IDMA_WARN_THRESH * hz)
  7260. dev_warn(adapter->pdev_dev, "SGE idma%d, queue %u, "
  7261. "resumed after %d seconds\n",
  7262. i, idma->idma_qid[i],
  7263. idma->idma_stalled[i] / hz);
  7264. idma->idma_stalled[i] = 0;
  7265. continue;
  7266. }
  7267. /* Synthesize an SGE Ingress DMA Same State Timer in the Hz
  7268. * domain. The first time we get here it'll be because we
  7269. * passed the 1s Threshold; each additional time it'll be
  7270. * because the RX Timer Callback is being fired on its regular
  7271. * schedule.
  7272. *
  7273. * If the stall is below our Potential Hung Ingress Queue
  7274. * Warning Threshold, continue.
  7275. */
  7276. if (idma->idma_stalled[i] == 0) {
  7277. idma->idma_stalled[i] = hz;
  7278. idma->idma_warn[i] = 0;
  7279. } else {
  7280. idma->idma_stalled[i] += ticks;
  7281. idma->idma_warn[i] -= ticks;
  7282. }
  7283. if (idma->idma_stalled[i] < SGE_IDMA_WARN_THRESH * hz)
  7284. continue;
  7285. /* We'll issue a warning every SGE_IDMA_WARN_REPEAT seconds.
  7286. */
  7287. if (idma->idma_warn[i] > 0)
  7288. continue;
  7289. idma->idma_warn[i] = SGE_IDMA_WARN_REPEAT * hz;
  7290. /* Read and save the SGE IDMA State and Queue ID information.
  7291. * We do this every time in case it changes across time ...
  7292. * can't be too careful ...
  7293. */
  7294. t4_write_reg(adapter, SGE_DEBUG_INDEX_A, 0);
  7295. debug0 = t4_read_reg(adapter, SGE_DEBUG_DATA_LOW_A);
  7296. idma->idma_state[i] = (debug0 >> (i * 9)) & 0x3f;
  7297. t4_write_reg(adapter, SGE_DEBUG_INDEX_A, 11);
  7298. debug11 = t4_read_reg(adapter, SGE_DEBUG_DATA_LOW_A);
  7299. idma->idma_qid[i] = (debug11 >> (i * 16)) & 0xffff;
  7300. dev_warn(adapter->pdev_dev, "SGE idma%u, queue %u, potentially stuck in "
  7301. "state %u for %d seconds (debug0=%#x, debug11=%#x)\n",
  7302. i, idma->idma_qid[i], idma->idma_state[i],
  7303. idma->idma_stalled[i] / hz,
  7304. debug0, debug11);
  7305. t4_sge_decode_idma_state(adapter, idma->idma_state[i]);
  7306. }
  7307. }