t4_hw.c 227 KB

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