t4_hw.c 234 KB

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