t4_hw.c 290 KB

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