chip.c 435 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874
  1. /*
  2. * Copyright(c) 2015, 2016 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. /*
  48. * This file contains all of the code that is specific to the HFI chip
  49. */
  50. #include <linux/pci.h>
  51. #include <linux/delay.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/module.h>
  54. #include "hfi.h"
  55. #include "trace.h"
  56. #include "mad.h"
  57. #include "pio.h"
  58. #include "sdma.h"
  59. #include "eprom.h"
  60. #include "efivar.h"
  61. #include "platform.h"
  62. #include "aspm.h"
  63. #include "affinity.h"
  64. #define NUM_IB_PORTS 1
  65. uint kdeth_qp;
  66. module_param_named(kdeth_qp, kdeth_qp, uint, S_IRUGO);
  67. MODULE_PARM_DESC(kdeth_qp, "Set the KDETH queue pair prefix");
  68. uint num_vls = HFI1_MAX_VLS_SUPPORTED;
  69. module_param(num_vls, uint, S_IRUGO);
  70. MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
  71. /*
  72. * Default time to aggregate two 10K packets from the idle state
  73. * (timer not running). The timer starts at the end of the first packet,
  74. * so only the time for one 10K packet and header plus a bit extra is needed.
  75. * 10 * 1024 + 64 header byte = 10304 byte
  76. * 10304 byte / 12.5 GB/s = 824.32ns
  77. */
  78. uint rcv_intr_timeout = (824 + 16); /* 16 is for coalescing interrupt */
  79. module_param(rcv_intr_timeout, uint, S_IRUGO);
  80. MODULE_PARM_DESC(rcv_intr_timeout, "Receive interrupt mitigation timeout in ns");
  81. uint rcv_intr_count = 16; /* same as qib */
  82. module_param(rcv_intr_count, uint, S_IRUGO);
  83. MODULE_PARM_DESC(rcv_intr_count, "Receive interrupt mitigation count");
  84. ushort link_crc_mask = SUPPORTED_CRCS;
  85. module_param(link_crc_mask, ushort, S_IRUGO);
  86. MODULE_PARM_DESC(link_crc_mask, "CRCs to use on the link");
  87. uint loopback;
  88. module_param_named(loopback, loopback, uint, S_IRUGO);
  89. MODULE_PARM_DESC(loopback, "Put into loopback mode (1 = serdes, 3 = external cable");
  90. /* Other driver tunables */
  91. uint rcv_intr_dynamic = 1; /* enable dynamic mode for rcv int mitigation*/
  92. static ushort crc_14b_sideband = 1;
  93. static uint use_flr = 1;
  94. uint quick_linkup; /* skip LNI */
  95. struct flag_table {
  96. u64 flag; /* the flag */
  97. char *str; /* description string */
  98. u16 extra; /* extra information */
  99. u16 unused0;
  100. u32 unused1;
  101. };
  102. /* str must be a string constant */
  103. #define FLAG_ENTRY(str, extra, flag) {flag, str, extra}
  104. #define FLAG_ENTRY0(str, flag) {flag, str, 0}
  105. /* Send Error Consequences */
  106. #define SEC_WRITE_DROPPED 0x1
  107. #define SEC_PACKET_DROPPED 0x2
  108. #define SEC_SC_HALTED 0x4 /* per-context only */
  109. #define SEC_SPC_FREEZE 0x8 /* per-HFI only */
  110. #define DEFAULT_KRCVQS 2
  111. #define MIN_KERNEL_KCTXTS 2
  112. #define FIRST_KERNEL_KCTXT 1
  113. /* sizes for both the QP and RSM map tables */
  114. #define NUM_MAP_ENTRIES 256
  115. #define NUM_MAP_REGS 32
  116. /* Bit offset into the GUID which carries HFI id information */
  117. #define GUID_HFI_INDEX_SHIFT 39
  118. /* extract the emulation revision */
  119. #define emulator_rev(dd) ((dd)->irev >> 8)
  120. /* parallel and serial emulation versions are 3 and 4 respectively */
  121. #define is_emulator_p(dd) ((((dd)->irev) & 0xf) == 3)
  122. #define is_emulator_s(dd) ((((dd)->irev) & 0xf) == 4)
  123. /* RSM fields */
  124. /* packet type */
  125. #define IB_PACKET_TYPE 2ull
  126. #define QW_SHIFT 6ull
  127. /* QPN[7..1] */
  128. #define QPN_WIDTH 7ull
  129. /* LRH.BTH: QW 0, OFFSET 48 - for match */
  130. #define LRH_BTH_QW 0ull
  131. #define LRH_BTH_BIT_OFFSET 48ull
  132. #define LRH_BTH_OFFSET(off) ((LRH_BTH_QW << QW_SHIFT) | (off))
  133. #define LRH_BTH_MATCH_OFFSET LRH_BTH_OFFSET(LRH_BTH_BIT_OFFSET)
  134. #define LRH_BTH_SELECT
  135. #define LRH_BTH_MASK 3ull
  136. #define LRH_BTH_VALUE 2ull
  137. /* LRH.SC[3..0] QW 0, OFFSET 56 - for match */
  138. #define LRH_SC_QW 0ull
  139. #define LRH_SC_BIT_OFFSET 56ull
  140. #define LRH_SC_OFFSET(off) ((LRH_SC_QW << QW_SHIFT) | (off))
  141. #define LRH_SC_MATCH_OFFSET LRH_SC_OFFSET(LRH_SC_BIT_OFFSET)
  142. #define LRH_SC_MASK 128ull
  143. #define LRH_SC_VALUE 0ull
  144. /* SC[n..0] QW 0, OFFSET 60 - for select */
  145. #define LRH_SC_SELECT_OFFSET ((LRH_SC_QW << QW_SHIFT) | (60ull))
  146. /* QPN[m+n:1] QW 1, OFFSET 1 */
  147. #define QPN_SELECT_OFFSET ((1ull << QW_SHIFT) | (1ull))
  148. /* defines to build power on SC2VL table */
  149. #define SC2VL_VAL( \
  150. num, \
  151. sc0, sc0val, \
  152. sc1, sc1val, \
  153. sc2, sc2val, \
  154. sc3, sc3val, \
  155. sc4, sc4val, \
  156. sc5, sc5val, \
  157. sc6, sc6val, \
  158. sc7, sc7val) \
  159. ( \
  160. ((u64)(sc0val) << SEND_SC2VLT##num##_SC##sc0##_SHIFT) | \
  161. ((u64)(sc1val) << SEND_SC2VLT##num##_SC##sc1##_SHIFT) | \
  162. ((u64)(sc2val) << SEND_SC2VLT##num##_SC##sc2##_SHIFT) | \
  163. ((u64)(sc3val) << SEND_SC2VLT##num##_SC##sc3##_SHIFT) | \
  164. ((u64)(sc4val) << SEND_SC2VLT##num##_SC##sc4##_SHIFT) | \
  165. ((u64)(sc5val) << SEND_SC2VLT##num##_SC##sc5##_SHIFT) | \
  166. ((u64)(sc6val) << SEND_SC2VLT##num##_SC##sc6##_SHIFT) | \
  167. ((u64)(sc7val) << SEND_SC2VLT##num##_SC##sc7##_SHIFT) \
  168. )
  169. #define DC_SC_VL_VAL( \
  170. range, \
  171. e0, e0val, \
  172. e1, e1val, \
  173. e2, e2val, \
  174. e3, e3val, \
  175. e4, e4val, \
  176. e5, e5val, \
  177. e6, e6val, \
  178. e7, e7val, \
  179. e8, e8val, \
  180. e9, e9val, \
  181. e10, e10val, \
  182. e11, e11val, \
  183. e12, e12val, \
  184. e13, e13val, \
  185. e14, e14val, \
  186. e15, e15val) \
  187. ( \
  188. ((u64)(e0val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e0##_SHIFT) | \
  189. ((u64)(e1val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e1##_SHIFT) | \
  190. ((u64)(e2val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e2##_SHIFT) | \
  191. ((u64)(e3val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e3##_SHIFT) | \
  192. ((u64)(e4val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e4##_SHIFT) | \
  193. ((u64)(e5val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e5##_SHIFT) | \
  194. ((u64)(e6val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e6##_SHIFT) | \
  195. ((u64)(e7val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e7##_SHIFT) | \
  196. ((u64)(e8val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e8##_SHIFT) | \
  197. ((u64)(e9val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e9##_SHIFT) | \
  198. ((u64)(e10val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e10##_SHIFT) | \
  199. ((u64)(e11val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e11##_SHIFT) | \
  200. ((u64)(e12val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e12##_SHIFT) | \
  201. ((u64)(e13val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e13##_SHIFT) | \
  202. ((u64)(e14val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e14##_SHIFT) | \
  203. ((u64)(e15val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e15##_SHIFT) \
  204. )
  205. /* all CceStatus sub-block freeze bits */
  206. #define ALL_FROZE (CCE_STATUS_SDMA_FROZE_SMASK \
  207. | CCE_STATUS_RXE_FROZE_SMASK \
  208. | CCE_STATUS_TXE_FROZE_SMASK \
  209. | CCE_STATUS_TXE_PIO_FROZE_SMASK)
  210. /* all CceStatus sub-block TXE pause bits */
  211. #define ALL_TXE_PAUSE (CCE_STATUS_TXE_PIO_PAUSED_SMASK \
  212. | CCE_STATUS_TXE_PAUSED_SMASK \
  213. | CCE_STATUS_SDMA_PAUSED_SMASK)
  214. /* all CceStatus sub-block RXE pause bits */
  215. #define ALL_RXE_PAUSE CCE_STATUS_RXE_PAUSED_SMASK
  216. #define CNTR_MAX 0xFFFFFFFFFFFFFFFFULL
  217. #define CNTR_32BIT_MAX 0x00000000FFFFFFFF
  218. /*
  219. * CCE Error flags.
  220. */
  221. static struct flag_table cce_err_status_flags[] = {
  222. /* 0*/ FLAG_ENTRY0("CceCsrParityErr",
  223. CCE_ERR_STATUS_CCE_CSR_PARITY_ERR_SMASK),
  224. /* 1*/ FLAG_ENTRY0("CceCsrReadBadAddrErr",
  225. CCE_ERR_STATUS_CCE_CSR_READ_BAD_ADDR_ERR_SMASK),
  226. /* 2*/ FLAG_ENTRY0("CceCsrWriteBadAddrErr",
  227. CCE_ERR_STATUS_CCE_CSR_WRITE_BAD_ADDR_ERR_SMASK),
  228. /* 3*/ FLAG_ENTRY0("CceTrgtAsyncFifoParityErr",
  229. CCE_ERR_STATUS_CCE_TRGT_ASYNC_FIFO_PARITY_ERR_SMASK),
  230. /* 4*/ FLAG_ENTRY0("CceTrgtAccessErr",
  231. CCE_ERR_STATUS_CCE_TRGT_ACCESS_ERR_SMASK),
  232. /* 5*/ FLAG_ENTRY0("CceRspdDataParityErr",
  233. CCE_ERR_STATUS_CCE_RSPD_DATA_PARITY_ERR_SMASK),
  234. /* 6*/ FLAG_ENTRY0("CceCli0AsyncFifoParityErr",
  235. CCE_ERR_STATUS_CCE_CLI0_ASYNC_FIFO_PARITY_ERR_SMASK),
  236. /* 7*/ FLAG_ENTRY0("CceCsrCfgBusParityErr",
  237. CCE_ERR_STATUS_CCE_CSR_CFG_BUS_PARITY_ERR_SMASK),
  238. /* 8*/ FLAG_ENTRY0("CceCli2AsyncFifoParityErr",
  239. CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK),
  240. /* 9*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
  241. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR_SMASK),
  242. /*10*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
  243. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR_SMASK),
  244. /*11*/ FLAG_ENTRY0("CceCli1AsyncFifoRxdmaParityError",
  245. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERROR_SMASK),
  246. /*12*/ FLAG_ENTRY0("CceCli1AsyncFifoDbgParityError",
  247. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERROR_SMASK),
  248. /*13*/ FLAG_ENTRY0("PcicRetryMemCorErr",
  249. CCE_ERR_STATUS_PCIC_RETRY_MEM_COR_ERR_SMASK),
  250. /*14*/ FLAG_ENTRY0("PcicRetryMemCorErr",
  251. CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_COR_ERR_SMASK),
  252. /*15*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  253. CCE_ERR_STATUS_PCIC_POST_HD_QCOR_ERR_SMASK),
  254. /*16*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  255. CCE_ERR_STATUS_PCIC_POST_DAT_QCOR_ERR_SMASK),
  256. /*17*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  257. CCE_ERR_STATUS_PCIC_CPL_HD_QCOR_ERR_SMASK),
  258. /*18*/ FLAG_ENTRY0("PcicCplDatQCorErr",
  259. CCE_ERR_STATUS_PCIC_CPL_DAT_QCOR_ERR_SMASK),
  260. /*19*/ FLAG_ENTRY0("PcicNPostHQParityErr",
  261. CCE_ERR_STATUS_PCIC_NPOST_HQ_PARITY_ERR_SMASK),
  262. /*20*/ FLAG_ENTRY0("PcicNPostDatQParityErr",
  263. CCE_ERR_STATUS_PCIC_NPOST_DAT_QPARITY_ERR_SMASK),
  264. /*21*/ FLAG_ENTRY0("PcicRetryMemUncErr",
  265. CCE_ERR_STATUS_PCIC_RETRY_MEM_UNC_ERR_SMASK),
  266. /*22*/ FLAG_ENTRY0("PcicRetrySotMemUncErr",
  267. CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_UNC_ERR_SMASK),
  268. /*23*/ FLAG_ENTRY0("PcicPostHdQUncErr",
  269. CCE_ERR_STATUS_PCIC_POST_HD_QUNC_ERR_SMASK),
  270. /*24*/ FLAG_ENTRY0("PcicPostDatQUncErr",
  271. CCE_ERR_STATUS_PCIC_POST_DAT_QUNC_ERR_SMASK),
  272. /*25*/ FLAG_ENTRY0("PcicCplHdQUncErr",
  273. CCE_ERR_STATUS_PCIC_CPL_HD_QUNC_ERR_SMASK),
  274. /*26*/ FLAG_ENTRY0("PcicCplDatQUncErr",
  275. CCE_ERR_STATUS_PCIC_CPL_DAT_QUNC_ERR_SMASK),
  276. /*27*/ FLAG_ENTRY0("PcicTransmitFrontParityErr",
  277. CCE_ERR_STATUS_PCIC_TRANSMIT_FRONT_PARITY_ERR_SMASK),
  278. /*28*/ FLAG_ENTRY0("PcicTransmitBackParityErr",
  279. CCE_ERR_STATUS_PCIC_TRANSMIT_BACK_PARITY_ERR_SMASK),
  280. /*29*/ FLAG_ENTRY0("PcicReceiveParityErr",
  281. CCE_ERR_STATUS_PCIC_RECEIVE_PARITY_ERR_SMASK),
  282. /*30*/ FLAG_ENTRY0("CceTrgtCplTimeoutErr",
  283. CCE_ERR_STATUS_CCE_TRGT_CPL_TIMEOUT_ERR_SMASK),
  284. /*31*/ FLAG_ENTRY0("LATriggered",
  285. CCE_ERR_STATUS_LA_TRIGGERED_SMASK),
  286. /*32*/ FLAG_ENTRY0("CceSegReadBadAddrErr",
  287. CCE_ERR_STATUS_CCE_SEG_READ_BAD_ADDR_ERR_SMASK),
  288. /*33*/ FLAG_ENTRY0("CceSegWriteBadAddrErr",
  289. CCE_ERR_STATUS_CCE_SEG_WRITE_BAD_ADDR_ERR_SMASK),
  290. /*34*/ FLAG_ENTRY0("CceRcplAsyncFifoParityErr",
  291. CCE_ERR_STATUS_CCE_RCPL_ASYNC_FIFO_PARITY_ERR_SMASK),
  292. /*35*/ FLAG_ENTRY0("CceRxdmaConvFifoParityErr",
  293. CCE_ERR_STATUS_CCE_RXDMA_CONV_FIFO_PARITY_ERR_SMASK),
  294. /*36*/ FLAG_ENTRY0("CceMsixTableCorErr",
  295. CCE_ERR_STATUS_CCE_MSIX_TABLE_COR_ERR_SMASK),
  296. /*37*/ FLAG_ENTRY0("CceMsixTableUncErr",
  297. CCE_ERR_STATUS_CCE_MSIX_TABLE_UNC_ERR_SMASK),
  298. /*38*/ FLAG_ENTRY0("CceIntMapCorErr",
  299. CCE_ERR_STATUS_CCE_INT_MAP_COR_ERR_SMASK),
  300. /*39*/ FLAG_ENTRY0("CceIntMapUncErr",
  301. CCE_ERR_STATUS_CCE_INT_MAP_UNC_ERR_SMASK),
  302. /*40*/ FLAG_ENTRY0("CceMsixCsrParityErr",
  303. CCE_ERR_STATUS_CCE_MSIX_CSR_PARITY_ERR_SMASK),
  304. /*41-63 reserved*/
  305. };
  306. /*
  307. * Misc Error flags
  308. */
  309. #define MES(text) MISC_ERR_STATUS_MISC_##text##_ERR_SMASK
  310. static struct flag_table misc_err_status_flags[] = {
  311. /* 0*/ FLAG_ENTRY0("CSR_PARITY", MES(CSR_PARITY)),
  312. /* 1*/ FLAG_ENTRY0("CSR_READ_BAD_ADDR", MES(CSR_READ_BAD_ADDR)),
  313. /* 2*/ FLAG_ENTRY0("CSR_WRITE_BAD_ADDR", MES(CSR_WRITE_BAD_ADDR)),
  314. /* 3*/ FLAG_ENTRY0("SBUS_WRITE_FAILED", MES(SBUS_WRITE_FAILED)),
  315. /* 4*/ FLAG_ENTRY0("KEY_MISMATCH", MES(KEY_MISMATCH)),
  316. /* 5*/ FLAG_ENTRY0("FW_AUTH_FAILED", MES(FW_AUTH_FAILED)),
  317. /* 6*/ FLAG_ENTRY0("EFUSE_CSR_PARITY", MES(EFUSE_CSR_PARITY)),
  318. /* 7*/ FLAG_ENTRY0("EFUSE_READ_BAD_ADDR", MES(EFUSE_READ_BAD_ADDR)),
  319. /* 8*/ FLAG_ENTRY0("EFUSE_WRITE", MES(EFUSE_WRITE)),
  320. /* 9*/ FLAG_ENTRY0("EFUSE_DONE_PARITY", MES(EFUSE_DONE_PARITY)),
  321. /*10*/ FLAG_ENTRY0("INVALID_EEP_CMD", MES(INVALID_EEP_CMD)),
  322. /*11*/ FLAG_ENTRY0("MBIST_FAIL", MES(MBIST_FAIL)),
  323. /*12*/ FLAG_ENTRY0("PLL_LOCK_FAIL", MES(PLL_LOCK_FAIL))
  324. };
  325. /*
  326. * TXE PIO Error flags and consequences
  327. */
  328. static struct flag_table pio_err_status_flags[] = {
  329. /* 0*/ FLAG_ENTRY("PioWriteBadCtxt",
  330. SEC_WRITE_DROPPED,
  331. SEND_PIO_ERR_STATUS_PIO_WRITE_BAD_CTXT_ERR_SMASK),
  332. /* 1*/ FLAG_ENTRY("PioWriteAddrParity",
  333. SEC_SPC_FREEZE,
  334. SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK),
  335. /* 2*/ FLAG_ENTRY("PioCsrParity",
  336. SEC_SPC_FREEZE,
  337. SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK),
  338. /* 3*/ FLAG_ENTRY("PioSbMemFifo0",
  339. SEC_SPC_FREEZE,
  340. SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK),
  341. /* 4*/ FLAG_ENTRY("PioSbMemFifo1",
  342. SEC_SPC_FREEZE,
  343. SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK),
  344. /* 5*/ FLAG_ENTRY("PioPccFifoParity",
  345. SEC_SPC_FREEZE,
  346. SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK),
  347. /* 6*/ FLAG_ENTRY("PioPecFifoParity",
  348. SEC_SPC_FREEZE,
  349. SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK),
  350. /* 7*/ FLAG_ENTRY("PioSbrdctlCrrelParity",
  351. SEC_SPC_FREEZE,
  352. SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK),
  353. /* 8*/ FLAG_ENTRY("PioSbrdctrlCrrelFifoParity",
  354. SEC_SPC_FREEZE,
  355. SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK),
  356. /* 9*/ FLAG_ENTRY("PioPktEvictFifoParityErr",
  357. SEC_SPC_FREEZE,
  358. SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK),
  359. /*10*/ FLAG_ENTRY("PioSmPktResetParity",
  360. SEC_SPC_FREEZE,
  361. SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK),
  362. /*11*/ FLAG_ENTRY("PioVlLenMemBank0Unc",
  363. SEC_SPC_FREEZE,
  364. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK),
  365. /*12*/ FLAG_ENTRY("PioVlLenMemBank1Unc",
  366. SEC_SPC_FREEZE,
  367. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK),
  368. /*13*/ FLAG_ENTRY("PioVlLenMemBank0Cor",
  369. 0,
  370. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_COR_ERR_SMASK),
  371. /*14*/ FLAG_ENTRY("PioVlLenMemBank1Cor",
  372. 0,
  373. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_COR_ERR_SMASK),
  374. /*15*/ FLAG_ENTRY("PioCreditRetFifoParity",
  375. SEC_SPC_FREEZE,
  376. SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK),
  377. /*16*/ FLAG_ENTRY("PioPpmcPblFifo",
  378. SEC_SPC_FREEZE,
  379. SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK),
  380. /*17*/ FLAG_ENTRY("PioInitSmIn",
  381. 0,
  382. SEND_PIO_ERR_STATUS_PIO_INIT_SM_IN_ERR_SMASK),
  383. /*18*/ FLAG_ENTRY("PioPktEvictSmOrArbSm",
  384. SEC_SPC_FREEZE,
  385. SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK),
  386. /*19*/ FLAG_ENTRY("PioHostAddrMemUnc",
  387. SEC_SPC_FREEZE,
  388. SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK),
  389. /*20*/ FLAG_ENTRY("PioHostAddrMemCor",
  390. 0,
  391. SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_COR_ERR_SMASK),
  392. /*21*/ FLAG_ENTRY("PioWriteDataParity",
  393. SEC_SPC_FREEZE,
  394. SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK),
  395. /*22*/ FLAG_ENTRY("PioStateMachine",
  396. SEC_SPC_FREEZE,
  397. SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK),
  398. /*23*/ FLAG_ENTRY("PioWriteQwValidParity",
  399. SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
  400. SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK),
  401. /*24*/ FLAG_ENTRY("PioBlockQwCountParity",
  402. SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
  403. SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK),
  404. /*25*/ FLAG_ENTRY("PioVlfVlLenParity",
  405. SEC_SPC_FREEZE,
  406. SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK),
  407. /*26*/ FLAG_ENTRY("PioVlfSopParity",
  408. SEC_SPC_FREEZE,
  409. SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK),
  410. /*27*/ FLAG_ENTRY("PioVlFifoParity",
  411. SEC_SPC_FREEZE,
  412. SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK),
  413. /*28*/ FLAG_ENTRY("PioPpmcBqcMemParity",
  414. SEC_SPC_FREEZE,
  415. SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK),
  416. /*29*/ FLAG_ENTRY("PioPpmcSopLen",
  417. SEC_SPC_FREEZE,
  418. SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK),
  419. /*30-31 reserved*/
  420. /*32*/ FLAG_ENTRY("PioCurrentFreeCntParity",
  421. SEC_SPC_FREEZE,
  422. SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK),
  423. /*33*/ FLAG_ENTRY("PioLastReturnedCntParity",
  424. SEC_SPC_FREEZE,
  425. SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK),
  426. /*34*/ FLAG_ENTRY("PioPccSopHeadParity",
  427. SEC_SPC_FREEZE,
  428. SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK),
  429. /*35*/ FLAG_ENTRY("PioPecSopHeadParityErr",
  430. SEC_SPC_FREEZE,
  431. SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK),
  432. /*36-63 reserved*/
  433. };
  434. /* TXE PIO errors that cause an SPC freeze */
  435. #define ALL_PIO_FREEZE_ERR \
  436. (SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK \
  437. | SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK \
  438. | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK \
  439. | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK \
  440. | SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK \
  441. | SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK \
  442. | SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK \
  443. | SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK \
  444. | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK \
  445. | SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK \
  446. | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK \
  447. | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK \
  448. | SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK \
  449. | SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK \
  450. | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK \
  451. | SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK \
  452. | SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK \
  453. | SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK \
  454. | SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK \
  455. | SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK \
  456. | SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK \
  457. | SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK \
  458. | SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK \
  459. | SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK \
  460. | SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK \
  461. | SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK \
  462. | SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK \
  463. | SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK \
  464. | SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK)
  465. /*
  466. * TXE SDMA Error flags
  467. */
  468. static struct flag_table sdma_err_status_flags[] = {
  469. /* 0*/ FLAG_ENTRY0("SDmaRpyTagErr",
  470. SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK),
  471. /* 1*/ FLAG_ENTRY0("SDmaCsrParityErr",
  472. SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK),
  473. /* 2*/ FLAG_ENTRY0("SDmaPcieReqTrackingUncErr",
  474. SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK),
  475. /* 3*/ FLAG_ENTRY0("SDmaPcieReqTrackingCorErr",
  476. SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_COR_ERR_SMASK),
  477. /*04-63 reserved*/
  478. };
  479. /* TXE SDMA errors that cause an SPC freeze */
  480. #define ALL_SDMA_FREEZE_ERR \
  481. (SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK \
  482. | SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK \
  483. | SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK)
  484. /* SendEgressErrInfo bits that correspond to a PortXmitDiscard counter */
  485. #define PORT_DISCARD_EGRESS_ERRS \
  486. (SEND_EGRESS_ERR_INFO_TOO_LONG_IB_PACKET_ERR_SMASK \
  487. | SEND_EGRESS_ERR_INFO_VL_MAPPING_ERR_SMASK \
  488. | SEND_EGRESS_ERR_INFO_VL_ERR_SMASK)
  489. /*
  490. * TXE Egress Error flags
  491. */
  492. #define SEES(text) SEND_EGRESS_ERR_STATUS_##text##_ERR_SMASK
  493. static struct flag_table egress_err_status_flags[] = {
  494. /* 0*/ FLAG_ENTRY0("TxPktIntegrityMemCorErr", SEES(TX_PKT_INTEGRITY_MEM_COR)),
  495. /* 1*/ FLAG_ENTRY0("TxPktIntegrityMemUncErr", SEES(TX_PKT_INTEGRITY_MEM_UNC)),
  496. /* 2 reserved */
  497. /* 3*/ FLAG_ENTRY0("TxEgressFifoUnderrunOrParityErr",
  498. SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY)),
  499. /* 4*/ FLAG_ENTRY0("TxLinkdownErr", SEES(TX_LINKDOWN)),
  500. /* 5*/ FLAG_ENTRY0("TxIncorrectLinkStateErr", SEES(TX_INCORRECT_LINK_STATE)),
  501. /* 6 reserved */
  502. /* 7*/ FLAG_ENTRY0("TxPioLaunchIntfParityErr",
  503. SEES(TX_PIO_LAUNCH_INTF_PARITY)),
  504. /* 8*/ FLAG_ENTRY0("TxSdmaLaunchIntfParityErr",
  505. SEES(TX_SDMA_LAUNCH_INTF_PARITY)),
  506. /* 9-10 reserved */
  507. /*11*/ FLAG_ENTRY0("TxSbrdCtlStateMachineParityErr",
  508. SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY)),
  509. /*12*/ FLAG_ENTRY0("TxIllegalVLErr", SEES(TX_ILLEGAL_VL)),
  510. /*13*/ FLAG_ENTRY0("TxLaunchCsrParityErr", SEES(TX_LAUNCH_CSR_PARITY)),
  511. /*14*/ FLAG_ENTRY0("TxSbrdCtlCsrParityErr", SEES(TX_SBRD_CTL_CSR_PARITY)),
  512. /*15*/ FLAG_ENTRY0("TxConfigParityErr", SEES(TX_CONFIG_PARITY)),
  513. /*16*/ FLAG_ENTRY0("TxSdma0DisallowedPacketErr",
  514. SEES(TX_SDMA0_DISALLOWED_PACKET)),
  515. /*17*/ FLAG_ENTRY0("TxSdma1DisallowedPacketErr",
  516. SEES(TX_SDMA1_DISALLOWED_PACKET)),
  517. /*18*/ FLAG_ENTRY0("TxSdma2DisallowedPacketErr",
  518. SEES(TX_SDMA2_DISALLOWED_PACKET)),
  519. /*19*/ FLAG_ENTRY0("TxSdma3DisallowedPacketErr",
  520. SEES(TX_SDMA3_DISALLOWED_PACKET)),
  521. /*20*/ FLAG_ENTRY0("TxSdma4DisallowedPacketErr",
  522. SEES(TX_SDMA4_DISALLOWED_PACKET)),
  523. /*21*/ FLAG_ENTRY0("TxSdma5DisallowedPacketErr",
  524. SEES(TX_SDMA5_DISALLOWED_PACKET)),
  525. /*22*/ FLAG_ENTRY0("TxSdma6DisallowedPacketErr",
  526. SEES(TX_SDMA6_DISALLOWED_PACKET)),
  527. /*23*/ FLAG_ENTRY0("TxSdma7DisallowedPacketErr",
  528. SEES(TX_SDMA7_DISALLOWED_PACKET)),
  529. /*24*/ FLAG_ENTRY0("TxSdma8DisallowedPacketErr",
  530. SEES(TX_SDMA8_DISALLOWED_PACKET)),
  531. /*25*/ FLAG_ENTRY0("TxSdma9DisallowedPacketErr",
  532. SEES(TX_SDMA9_DISALLOWED_PACKET)),
  533. /*26*/ FLAG_ENTRY0("TxSdma10DisallowedPacketErr",
  534. SEES(TX_SDMA10_DISALLOWED_PACKET)),
  535. /*27*/ FLAG_ENTRY0("TxSdma11DisallowedPacketErr",
  536. SEES(TX_SDMA11_DISALLOWED_PACKET)),
  537. /*28*/ FLAG_ENTRY0("TxSdma12DisallowedPacketErr",
  538. SEES(TX_SDMA12_DISALLOWED_PACKET)),
  539. /*29*/ FLAG_ENTRY0("TxSdma13DisallowedPacketErr",
  540. SEES(TX_SDMA13_DISALLOWED_PACKET)),
  541. /*30*/ FLAG_ENTRY0("TxSdma14DisallowedPacketErr",
  542. SEES(TX_SDMA14_DISALLOWED_PACKET)),
  543. /*31*/ FLAG_ENTRY0("TxSdma15DisallowedPacketErr",
  544. SEES(TX_SDMA15_DISALLOWED_PACKET)),
  545. /*32*/ FLAG_ENTRY0("TxLaunchFifo0UncOrParityErr",
  546. SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY)),
  547. /*33*/ FLAG_ENTRY0("TxLaunchFifo1UncOrParityErr",
  548. SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY)),
  549. /*34*/ FLAG_ENTRY0("TxLaunchFifo2UncOrParityErr",
  550. SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY)),
  551. /*35*/ FLAG_ENTRY0("TxLaunchFifo3UncOrParityErr",
  552. SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY)),
  553. /*36*/ FLAG_ENTRY0("TxLaunchFifo4UncOrParityErr",
  554. SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY)),
  555. /*37*/ FLAG_ENTRY0("TxLaunchFifo5UncOrParityErr",
  556. SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY)),
  557. /*38*/ FLAG_ENTRY0("TxLaunchFifo6UncOrParityErr",
  558. SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY)),
  559. /*39*/ FLAG_ENTRY0("TxLaunchFifo7UncOrParityErr",
  560. SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY)),
  561. /*40*/ FLAG_ENTRY0("TxLaunchFifo8UncOrParityErr",
  562. SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY)),
  563. /*41*/ FLAG_ENTRY0("TxCreditReturnParityErr", SEES(TX_CREDIT_RETURN_PARITY)),
  564. /*42*/ FLAG_ENTRY0("TxSbHdrUncErr", SEES(TX_SB_HDR_UNC)),
  565. /*43*/ FLAG_ENTRY0("TxReadSdmaMemoryUncErr", SEES(TX_READ_SDMA_MEMORY_UNC)),
  566. /*44*/ FLAG_ENTRY0("TxReadPioMemoryUncErr", SEES(TX_READ_PIO_MEMORY_UNC)),
  567. /*45*/ FLAG_ENTRY0("TxEgressFifoUncErr", SEES(TX_EGRESS_FIFO_UNC)),
  568. /*46*/ FLAG_ENTRY0("TxHcrcInsertionErr", SEES(TX_HCRC_INSERTION)),
  569. /*47*/ FLAG_ENTRY0("TxCreditReturnVLErr", SEES(TX_CREDIT_RETURN_VL)),
  570. /*48*/ FLAG_ENTRY0("TxLaunchFifo0CorErr", SEES(TX_LAUNCH_FIFO0_COR)),
  571. /*49*/ FLAG_ENTRY0("TxLaunchFifo1CorErr", SEES(TX_LAUNCH_FIFO1_COR)),
  572. /*50*/ FLAG_ENTRY0("TxLaunchFifo2CorErr", SEES(TX_LAUNCH_FIFO2_COR)),
  573. /*51*/ FLAG_ENTRY0("TxLaunchFifo3CorErr", SEES(TX_LAUNCH_FIFO3_COR)),
  574. /*52*/ FLAG_ENTRY0("TxLaunchFifo4CorErr", SEES(TX_LAUNCH_FIFO4_COR)),
  575. /*53*/ FLAG_ENTRY0("TxLaunchFifo5CorErr", SEES(TX_LAUNCH_FIFO5_COR)),
  576. /*54*/ FLAG_ENTRY0("TxLaunchFifo6CorErr", SEES(TX_LAUNCH_FIFO6_COR)),
  577. /*55*/ FLAG_ENTRY0("TxLaunchFifo7CorErr", SEES(TX_LAUNCH_FIFO7_COR)),
  578. /*56*/ FLAG_ENTRY0("TxLaunchFifo8CorErr", SEES(TX_LAUNCH_FIFO8_COR)),
  579. /*57*/ FLAG_ENTRY0("TxCreditOverrunErr", SEES(TX_CREDIT_OVERRUN)),
  580. /*58*/ FLAG_ENTRY0("TxSbHdrCorErr", SEES(TX_SB_HDR_COR)),
  581. /*59*/ FLAG_ENTRY0("TxReadSdmaMemoryCorErr", SEES(TX_READ_SDMA_MEMORY_COR)),
  582. /*60*/ FLAG_ENTRY0("TxReadPioMemoryCorErr", SEES(TX_READ_PIO_MEMORY_COR)),
  583. /*61*/ FLAG_ENTRY0("TxEgressFifoCorErr", SEES(TX_EGRESS_FIFO_COR)),
  584. /*62*/ FLAG_ENTRY0("TxReadSdmaMemoryCsrUncErr",
  585. SEES(TX_READ_SDMA_MEMORY_CSR_UNC)),
  586. /*63*/ FLAG_ENTRY0("TxReadPioMemoryCsrUncErr",
  587. SEES(TX_READ_PIO_MEMORY_CSR_UNC)),
  588. };
  589. /*
  590. * TXE Egress Error Info flags
  591. */
  592. #define SEEI(text) SEND_EGRESS_ERR_INFO_##text##_ERR_SMASK
  593. static struct flag_table egress_err_info_flags[] = {
  594. /* 0*/ FLAG_ENTRY0("Reserved", 0ull),
  595. /* 1*/ FLAG_ENTRY0("VLErr", SEEI(VL)),
  596. /* 2*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
  597. /* 3*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
  598. /* 4*/ FLAG_ENTRY0("PartitionKeyErr", SEEI(PARTITION_KEY)),
  599. /* 5*/ FLAG_ENTRY0("SLIDErr", SEEI(SLID)),
  600. /* 6*/ FLAG_ENTRY0("OpcodeErr", SEEI(OPCODE)),
  601. /* 7*/ FLAG_ENTRY0("VLMappingErr", SEEI(VL_MAPPING)),
  602. /* 8*/ FLAG_ENTRY0("RawErr", SEEI(RAW)),
  603. /* 9*/ FLAG_ENTRY0("RawIPv6Err", SEEI(RAW_IPV6)),
  604. /*10*/ FLAG_ENTRY0("GRHErr", SEEI(GRH)),
  605. /*11*/ FLAG_ENTRY0("BypassErr", SEEI(BYPASS)),
  606. /*12*/ FLAG_ENTRY0("KDETHPacketsErr", SEEI(KDETH_PACKETS)),
  607. /*13*/ FLAG_ENTRY0("NonKDETHPacketsErr", SEEI(NON_KDETH_PACKETS)),
  608. /*14*/ FLAG_ENTRY0("TooSmallIBPacketsErr", SEEI(TOO_SMALL_IB_PACKETS)),
  609. /*15*/ FLAG_ENTRY0("TooSmallBypassPacketsErr", SEEI(TOO_SMALL_BYPASS_PACKETS)),
  610. /*16*/ FLAG_ENTRY0("PbcTestErr", SEEI(PBC_TEST)),
  611. /*17*/ FLAG_ENTRY0("BadPktLenErr", SEEI(BAD_PKT_LEN)),
  612. /*18*/ FLAG_ENTRY0("TooLongIBPacketErr", SEEI(TOO_LONG_IB_PACKET)),
  613. /*19*/ FLAG_ENTRY0("TooLongBypassPacketsErr", SEEI(TOO_LONG_BYPASS_PACKETS)),
  614. /*20*/ FLAG_ENTRY0("PbcStaticRateControlErr", SEEI(PBC_STATIC_RATE_CONTROL)),
  615. /*21*/ FLAG_ENTRY0("BypassBadPktLenErr", SEEI(BAD_PKT_LEN)),
  616. };
  617. /* TXE Egress errors that cause an SPC freeze */
  618. #define ALL_TXE_EGRESS_FREEZE_ERR \
  619. (SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY) \
  620. | SEES(TX_PIO_LAUNCH_INTF_PARITY) \
  621. | SEES(TX_SDMA_LAUNCH_INTF_PARITY) \
  622. | SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY) \
  623. | SEES(TX_LAUNCH_CSR_PARITY) \
  624. | SEES(TX_SBRD_CTL_CSR_PARITY) \
  625. | SEES(TX_CONFIG_PARITY) \
  626. | SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY) \
  627. | SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY) \
  628. | SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY) \
  629. | SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY) \
  630. | SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY) \
  631. | SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY) \
  632. | SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY) \
  633. | SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY) \
  634. | SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY) \
  635. | SEES(TX_CREDIT_RETURN_PARITY))
  636. /*
  637. * TXE Send error flags
  638. */
  639. #define SES(name) SEND_ERR_STATUS_SEND_##name##_ERR_SMASK
  640. static struct flag_table send_err_status_flags[] = {
  641. /* 0*/ FLAG_ENTRY0("SendCsrParityErr", SES(CSR_PARITY)),
  642. /* 1*/ FLAG_ENTRY0("SendCsrReadBadAddrErr", SES(CSR_READ_BAD_ADDR)),
  643. /* 2*/ FLAG_ENTRY0("SendCsrWriteBadAddrErr", SES(CSR_WRITE_BAD_ADDR))
  644. };
  645. /*
  646. * TXE Send Context Error flags and consequences
  647. */
  648. static struct flag_table sc_err_status_flags[] = {
  649. /* 0*/ FLAG_ENTRY("InconsistentSop",
  650. SEC_PACKET_DROPPED | SEC_SC_HALTED,
  651. SEND_CTXT_ERR_STATUS_PIO_INCONSISTENT_SOP_ERR_SMASK),
  652. /* 1*/ FLAG_ENTRY("DisallowedPacket",
  653. SEC_PACKET_DROPPED | SEC_SC_HALTED,
  654. SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK),
  655. /* 2*/ FLAG_ENTRY("WriteCrossesBoundary",
  656. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  657. SEND_CTXT_ERR_STATUS_PIO_WRITE_CROSSES_BOUNDARY_ERR_SMASK),
  658. /* 3*/ FLAG_ENTRY("WriteOverflow",
  659. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  660. SEND_CTXT_ERR_STATUS_PIO_WRITE_OVERFLOW_ERR_SMASK),
  661. /* 4*/ FLAG_ENTRY("WriteOutOfBounds",
  662. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  663. SEND_CTXT_ERR_STATUS_PIO_WRITE_OUT_OF_BOUNDS_ERR_SMASK),
  664. /* 5-63 reserved*/
  665. };
  666. /*
  667. * RXE Receive Error flags
  668. */
  669. #define RXES(name) RCV_ERR_STATUS_RX_##name##_ERR_SMASK
  670. static struct flag_table rxe_err_status_flags[] = {
  671. /* 0*/ FLAG_ENTRY0("RxDmaCsrCorErr", RXES(DMA_CSR_COR)),
  672. /* 1*/ FLAG_ENTRY0("RxDcIntfParityErr", RXES(DC_INTF_PARITY)),
  673. /* 2*/ FLAG_ENTRY0("RxRcvHdrUncErr", RXES(RCV_HDR_UNC)),
  674. /* 3*/ FLAG_ENTRY0("RxRcvHdrCorErr", RXES(RCV_HDR_COR)),
  675. /* 4*/ FLAG_ENTRY0("RxRcvDataUncErr", RXES(RCV_DATA_UNC)),
  676. /* 5*/ FLAG_ENTRY0("RxRcvDataCorErr", RXES(RCV_DATA_COR)),
  677. /* 6*/ FLAG_ENTRY0("RxRcvQpMapTableUncErr", RXES(RCV_QP_MAP_TABLE_UNC)),
  678. /* 7*/ FLAG_ENTRY0("RxRcvQpMapTableCorErr", RXES(RCV_QP_MAP_TABLE_COR)),
  679. /* 8*/ FLAG_ENTRY0("RxRcvCsrParityErr", RXES(RCV_CSR_PARITY)),
  680. /* 9*/ FLAG_ENTRY0("RxDcSopEopParityErr", RXES(DC_SOP_EOP_PARITY)),
  681. /*10*/ FLAG_ENTRY0("RxDmaFlagUncErr", RXES(DMA_FLAG_UNC)),
  682. /*11*/ FLAG_ENTRY0("RxDmaFlagCorErr", RXES(DMA_FLAG_COR)),
  683. /*12*/ FLAG_ENTRY0("RxRcvFsmEncodingErr", RXES(RCV_FSM_ENCODING)),
  684. /*13*/ FLAG_ENTRY0("RxRbufFreeListUncErr", RXES(RBUF_FREE_LIST_UNC)),
  685. /*14*/ FLAG_ENTRY0("RxRbufFreeListCorErr", RXES(RBUF_FREE_LIST_COR)),
  686. /*15*/ FLAG_ENTRY0("RxRbufLookupDesRegUncErr", RXES(RBUF_LOOKUP_DES_REG_UNC)),
  687. /*16*/ FLAG_ENTRY0("RxRbufLookupDesRegUncCorErr",
  688. RXES(RBUF_LOOKUP_DES_REG_UNC_COR)),
  689. /*17*/ FLAG_ENTRY0("RxRbufLookupDesUncErr", RXES(RBUF_LOOKUP_DES_UNC)),
  690. /*18*/ FLAG_ENTRY0("RxRbufLookupDesCorErr", RXES(RBUF_LOOKUP_DES_COR)),
  691. /*19*/ FLAG_ENTRY0("RxRbufBlockListReadUncErr",
  692. RXES(RBUF_BLOCK_LIST_READ_UNC)),
  693. /*20*/ FLAG_ENTRY0("RxRbufBlockListReadCorErr",
  694. RXES(RBUF_BLOCK_LIST_READ_COR)),
  695. /*21*/ FLAG_ENTRY0("RxRbufCsrQHeadBufNumParityErr",
  696. RXES(RBUF_CSR_QHEAD_BUF_NUM_PARITY)),
  697. /*22*/ FLAG_ENTRY0("RxRbufCsrQEntCntParityErr",
  698. RXES(RBUF_CSR_QENT_CNT_PARITY)),
  699. /*23*/ FLAG_ENTRY0("RxRbufCsrQNextBufParityErr",
  700. RXES(RBUF_CSR_QNEXT_BUF_PARITY)),
  701. /*24*/ FLAG_ENTRY0("RxRbufCsrQVldBitParityErr",
  702. RXES(RBUF_CSR_QVLD_BIT_PARITY)),
  703. /*25*/ FLAG_ENTRY0("RxRbufCsrQHdPtrParityErr", RXES(RBUF_CSR_QHD_PTR_PARITY)),
  704. /*26*/ FLAG_ENTRY0("RxRbufCsrQTlPtrParityErr", RXES(RBUF_CSR_QTL_PTR_PARITY)),
  705. /*27*/ FLAG_ENTRY0("RxRbufCsrQNumOfPktParityErr",
  706. RXES(RBUF_CSR_QNUM_OF_PKT_PARITY)),
  707. /*28*/ FLAG_ENTRY0("RxRbufCsrQEOPDWParityErr", RXES(RBUF_CSR_QEOPDW_PARITY)),
  708. /*29*/ FLAG_ENTRY0("RxRbufCtxIdParityErr", RXES(RBUF_CTX_ID_PARITY)),
  709. /*30*/ FLAG_ENTRY0("RxRBufBadLookupErr", RXES(RBUF_BAD_LOOKUP)),
  710. /*31*/ FLAG_ENTRY0("RxRbufFullErr", RXES(RBUF_FULL)),
  711. /*32*/ FLAG_ENTRY0("RxRbufEmptyErr", RXES(RBUF_EMPTY)),
  712. /*33*/ FLAG_ENTRY0("RxRbufFlRdAddrParityErr", RXES(RBUF_FL_RD_ADDR_PARITY)),
  713. /*34*/ FLAG_ENTRY0("RxRbufFlWrAddrParityErr", RXES(RBUF_FL_WR_ADDR_PARITY)),
  714. /*35*/ FLAG_ENTRY0("RxRbufFlInitdoneParityErr",
  715. RXES(RBUF_FL_INITDONE_PARITY)),
  716. /*36*/ FLAG_ENTRY0("RxRbufFlInitWrAddrParityErr",
  717. RXES(RBUF_FL_INIT_WR_ADDR_PARITY)),
  718. /*37*/ FLAG_ENTRY0("RxRbufNextFreeBufUncErr", RXES(RBUF_NEXT_FREE_BUF_UNC)),
  719. /*38*/ FLAG_ENTRY0("RxRbufNextFreeBufCorErr", RXES(RBUF_NEXT_FREE_BUF_COR)),
  720. /*39*/ FLAG_ENTRY0("RxLookupDesPart1UncErr", RXES(LOOKUP_DES_PART1_UNC)),
  721. /*40*/ FLAG_ENTRY0("RxLookupDesPart1UncCorErr",
  722. RXES(LOOKUP_DES_PART1_UNC_COR)),
  723. /*41*/ FLAG_ENTRY0("RxLookupDesPart2ParityErr",
  724. RXES(LOOKUP_DES_PART2_PARITY)),
  725. /*42*/ FLAG_ENTRY0("RxLookupRcvArrayUncErr", RXES(LOOKUP_RCV_ARRAY_UNC)),
  726. /*43*/ FLAG_ENTRY0("RxLookupRcvArrayCorErr", RXES(LOOKUP_RCV_ARRAY_COR)),
  727. /*44*/ FLAG_ENTRY0("RxLookupCsrParityErr", RXES(LOOKUP_CSR_PARITY)),
  728. /*45*/ FLAG_ENTRY0("RxHqIntrCsrParityErr", RXES(HQ_INTR_CSR_PARITY)),
  729. /*46*/ FLAG_ENTRY0("RxHqIntrFsmErr", RXES(HQ_INTR_FSM)),
  730. /*47*/ FLAG_ENTRY0("RxRbufDescPart1UncErr", RXES(RBUF_DESC_PART1_UNC)),
  731. /*48*/ FLAG_ENTRY0("RxRbufDescPart1CorErr", RXES(RBUF_DESC_PART1_COR)),
  732. /*49*/ FLAG_ENTRY0("RxRbufDescPart2UncErr", RXES(RBUF_DESC_PART2_UNC)),
  733. /*50*/ FLAG_ENTRY0("RxRbufDescPart2CorErr", RXES(RBUF_DESC_PART2_COR)),
  734. /*51*/ FLAG_ENTRY0("RxDmaHdrFifoRdUncErr", RXES(DMA_HDR_FIFO_RD_UNC)),
  735. /*52*/ FLAG_ENTRY0("RxDmaHdrFifoRdCorErr", RXES(DMA_HDR_FIFO_RD_COR)),
  736. /*53*/ FLAG_ENTRY0("RxDmaDataFifoRdUncErr", RXES(DMA_DATA_FIFO_RD_UNC)),
  737. /*54*/ FLAG_ENTRY0("RxDmaDataFifoRdCorErr", RXES(DMA_DATA_FIFO_RD_COR)),
  738. /*55*/ FLAG_ENTRY0("RxRbufDataUncErr", RXES(RBUF_DATA_UNC)),
  739. /*56*/ FLAG_ENTRY0("RxRbufDataCorErr", RXES(RBUF_DATA_COR)),
  740. /*57*/ FLAG_ENTRY0("RxDmaCsrParityErr", RXES(DMA_CSR_PARITY)),
  741. /*58*/ FLAG_ENTRY0("RxDmaEqFsmEncodingErr", RXES(DMA_EQ_FSM_ENCODING)),
  742. /*59*/ FLAG_ENTRY0("RxDmaDqFsmEncodingErr", RXES(DMA_DQ_FSM_ENCODING)),
  743. /*60*/ FLAG_ENTRY0("RxDmaCsrUncErr", RXES(DMA_CSR_UNC)),
  744. /*61*/ FLAG_ENTRY0("RxCsrReadBadAddrErr", RXES(CSR_READ_BAD_ADDR)),
  745. /*62*/ FLAG_ENTRY0("RxCsrWriteBadAddrErr", RXES(CSR_WRITE_BAD_ADDR)),
  746. /*63*/ FLAG_ENTRY0("RxCsrParityErr", RXES(CSR_PARITY))
  747. };
  748. /* RXE errors that will trigger an SPC freeze */
  749. #define ALL_RXE_FREEZE_ERR \
  750. (RCV_ERR_STATUS_RX_RCV_QP_MAP_TABLE_UNC_ERR_SMASK \
  751. | RCV_ERR_STATUS_RX_RCV_CSR_PARITY_ERR_SMASK \
  752. | RCV_ERR_STATUS_RX_DMA_FLAG_UNC_ERR_SMASK \
  753. | RCV_ERR_STATUS_RX_RCV_FSM_ENCODING_ERR_SMASK \
  754. | RCV_ERR_STATUS_RX_RBUF_FREE_LIST_UNC_ERR_SMASK \
  755. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_ERR_SMASK \
  756. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR_SMASK \
  757. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_UNC_ERR_SMASK \
  758. | RCV_ERR_STATUS_RX_RBUF_BLOCK_LIST_READ_UNC_ERR_SMASK \
  759. | RCV_ERR_STATUS_RX_RBUF_CSR_QHEAD_BUF_NUM_PARITY_ERR_SMASK \
  760. | RCV_ERR_STATUS_RX_RBUF_CSR_QENT_CNT_PARITY_ERR_SMASK \
  761. | RCV_ERR_STATUS_RX_RBUF_CSR_QNEXT_BUF_PARITY_ERR_SMASK \
  762. | RCV_ERR_STATUS_RX_RBUF_CSR_QVLD_BIT_PARITY_ERR_SMASK \
  763. | RCV_ERR_STATUS_RX_RBUF_CSR_QHD_PTR_PARITY_ERR_SMASK \
  764. | RCV_ERR_STATUS_RX_RBUF_CSR_QTL_PTR_PARITY_ERR_SMASK \
  765. | RCV_ERR_STATUS_RX_RBUF_CSR_QNUM_OF_PKT_PARITY_ERR_SMASK \
  766. | RCV_ERR_STATUS_RX_RBUF_CSR_QEOPDW_PARITY_ERR_SMASK \
  767. | RCV_ERR_STATUS_RX_RBUF_CTX_ID_PARITY_ERR_SMASK \
  768. | RCV_ERR_STATUS_RX_RBUF_BAD_LOOKUP_ERR_SMASK \
  769. | RCV_ERR_STATUS_RX_RBUF_FULL_ERR_SMASK \
  770. | RCV_ERR_STATUS_RX_RBUF_EMPTY_ERR_SMASK \
  771. | RCV_ERR_STATUS_RX_RBUF_FL_RD_ADDR_PARITY_ERR_SMASK \
  772. | RCV_ERR_STATUS_RX_RBUF_FL_WR_ADDR_PARITY_ERR_SMASK \
  773. | RCV_ERR_STATUS_RX_RBUF_FL_INITDONE_PARITY_ERR_SMASK \
  774. | RCV_ERR_STATUS_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR_SMASK \
  775. | RCV_ERR_STATUS_RX_RBUF_NEXT_FREE_BUF_UNC_ERR_SMASK \
  776. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_ERR_SMASK \
  777. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_COR_ERR_SMASK \
  778. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART2_PARITY_ERR_SMASK \
  779. | RCV_ERR_STATUS_RX_LOOKUP_RCV_ARRAY_UNC_ERR_SMASK \
  780. | RCV_ERR_STATUS_RX_LOOKUP_CSR_PARITY_ERR_SMASK \
  781. | RCV_ERR_STATUS_RX_HQ_INTR_CSR_PARITY_ERR_SMASK \
  782. | RCV_ERR_STATUS_RX_HQ_INTR_FSM_ERR_SMASK \
  783. | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_UNC_ERR_SMASK \
  784. | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_COR_ERR_SMASK \
  785. | RCV_ERR_STATUS_RX_RBUF_DESC_PART2_UNC_ERR_SMASK \
  786. | RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK \
  787. | RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK \
  788. | RCV_ERR_STATUS_RX_RBUF_DATA_UNC_ERR_SMASK \
  789. | RCV_ERR_STATUS_RX_DMA_CSR_PARITY_ERR_SMASK \
  790. | RCV_ERR_STATUS_RX_DMA_EQ_FSM_ENCODING_ERR_SMASK \
  791. | RCV_ERR_STATUS_RX_DMA_DQ_FSM_ENCODING_ERR_SMASK \
  792. | RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK \
  793. | RCV_ERR_STATUS_RX_CSR_PARITY_ERR_SMASK)
  794. #define RXE_FREEZE_ABORT_MASK \
  795. (RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK | \
  796. RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK | \
  797. RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK)
  798. /*
  799. * DCC Error Flags
  800. */
  801. #define DCCE(name) DCC_ERR_FLG_##name##_SMASK
  802. static struct flag_table dcc_err_flags[] = {
  803. FLAG_ENTRY0("bad_l2_err", DCCE(BAD_L2_ERR)),
  804. FLAG_ENTRY0("bad_sc_err", DCCE(BAD_SC_ERR)),
  805. FLAG_ENTRY0("bad_mid_tail_err", DCCE(BAD_MID_TAIL_ERR)),
  806. FLAG_ENTRY0("bad_preemption_err", DCCE(BAD_PREEMPTION_ERR)),
  807. FLAG_ENTRY0("preemption_err", DCCE(PREEMPTION_ERR)),
  808. FLAG_ENTRY0("preemptionvl15_err", DCCE(PREEMPTIONVL15_ERR)),
  809. FLAG_ENTRY0("bad_vl_marker_err", DCCE(BAD_VL_MARKER_ERR)),
  810. FLAG_ENTRY0("bad_dlid_target_err", DCCE(BAD_DLID_TARGET_ERR)),
  811. FLAG_ENTRY0("bad_lver_err", DCCE(BAD_LVER_ERR)),
  812. FLAG_ENTRY0("uncorrectable_err", DCCE(UNCORRECTABLE_ERR)),
  813. FLAG_ENTRY0("bad_crdt_ack_err", DCCE(BAD_CRDT_ACK_ERR)),
  814. FLAG_ENTRY0("unsup_pkt_type", DCCE(UNSUP_PKT_TYPE)),
  815. FLAG_ENTRY0("bad_ctrl_flit_err", DCCE(BAD_CTRL_FLIT_ERR)),
  816. FLAG_ENTRY0("event_cntr_parity_err", DCCE(EVENT_CNTR_PARITY_ERR)),
  817. FLAG_ENTRY0("event_cntr_rollover_err", DCCE(EVENT_CNTR_ROLLOVER_ERR)),
  818. FLAG_ENTRY0("link_err", DCCE(LINK_ERR)),
  819. FLAG_ENTRY0("misc_cntr_rollover_err", DCCE(MISC_CNTR_ROLLOVER_ERR)),
  820. FLAG_ENTRY0("bad_ctrl_dist_err", DCCE(BAD_CTRL_DIST_ERR)),
  821. FLAG_ENTRY0("bad_tail_dist_err", DCCE(BAD_TAIL_DIST_ERR)),
  822. FLAG_ENTRY0("bad_head_dist_err", DCCE(BAD_HEAD_DIST_ERR)),
  823. FLAG_ENTRY0("nonvl15_state_err", DCCE(NONVL15_STATE_ERR)),
  824. FLAG_ENTRY0("vl15_multi_err", DCCE(VL15_MULTI_ERR)),
  825. FLAG_ENTRY0("bad_pkt_length_err", DCCE(BAD_PKT_LENGTH_ERR)),
  826. FLAG_ENTRY0("unsup_vl_err", DCCE(UNSUP_VL_ERR)),
  827. FLAG_ENTRY0("perm_nvl15_err", DCCE(PERM_NVL15_ERR)),
  828. FLAG_ENTRY0("slid_zero_err", DCCE(SLID_ZERO_ERR)),
  829. FLAG_ENTRY0("dlid_zero_err", DCCE(DLID_ZERO_ERR)),
  830. FLAG_ENTRY0("length_mtu_err", DCCE(LENGTH_MTU_ERR)),
  831. FLAG_ENTRY0("rx_early_drop_err", DCCE(RX_EARLY_DROP_ERR)),
  832. FLAG_ENTRY0("late_short_err", DCCE(LATE_SHORT_ERR)),
  833. FLAG_ENTRY0("late_long_err", DCCE(LATE_LONG_ERR)),
  834. FLAG_ENTRY0("late_ebp_err", DCCE(LATE_EBP_ERR)),
  835. FLAG_ENTRY0("fpe_tx_fifo_ovflw_err", DCCE(FPE_TX_FIFO_OVFLW_ERR)),
  836. FLAG_ENTRY0("fpe_tx_fifo_unflw_err", DCCE(FPE_TX_FIFO_UNFLW_ERR)),
  837. FLAG_ENTRY0("csr_access_blocked_host", DCCE(CSR_ACCESS_BLOCKED_HOST)),
  838. FLAG_ENTRY0("csr_access_blocked_uc", DCCE(CSR_ACCESS_BLOCKED_UC)),
  839. FLAG_ENTRY0("tx_ctrl_parity_err", DCCE(TX_CTRL_PARITY_ERR)),
  840. FLAG_ENTRY0("tx_ctrl_parity_mbe_err", DCCE(TX_CTRL_PARITY_MBE_ERR)),
  841. FLAG_ENTRY0("tx_sc_parity_err", DCCE(TX_SC_PARITY_ERR)),
  842. FLAG_ENTRY0("rx_ctrl_parity_mbe_err", DCCE(RX_CTRL_PARITY_MBE_ERR)),
  843. FLAG_ENTRY0("csr_parity_err", DCCE(CSR_PARITY_ERR)),
  844. FLAG_ENTRY0("csr_inval_addr", DCCE(CSR_INVAL_ADDR)),
  845. FLAG_ENTRY0("tx_byte_shft_parity_err", DCCE(TX_BYTE_SHFT_PARITY_ERR)),
  846. FLAG_ENTRY0("rx_byte_shft_parity_err", DCCE(RX_BYTE_SHFT_PARITY_ERR)),
  847. FLAG_ENTRY0("fmconfig_err", DCCE(FMCONFIG_ERR)),
  848. FLAG_ENTRY0("rcvport_err", DCCE(RCVPORT_ERR)),
  849. };
  850. /*
  851. * LCB error flags
  852. */
  853. #define LCBE(name) DC_LCB_ERR_FLG_##name##_SMASK
  854. static struct flag_table lcb_err_flags[] = {
  855. /* 0*/ FLAG_ENTRY0("CSR_PARITY_ERR", LCBE(CSR_PARITY_ERR)),
  856. /* 1*/ FLAG_ENTRY0("INVALID_CSR_ADDR", LCBE(INVALID_CSR_ADDR)),
  857. /* 2*/ FLAG_ENTRY0("RST_FOR_FAILED_DESKEW", LCBE(RST_FOR_FAILED_DESKEW)),
  858. /* 3*/ FLAG_ENTRY0("ALL_LNS_FAILED_REINIT_TEST",
  859. LCBE(ALL_LNS_FAILED_REINIT_TEST)),
  860. /* 4*/ FLAG_ENTRY0("LOST_REINIT_STALL_OR_TOS", LCBE(LOST_REINIT_STALL_OR_TOS)),
  861. /* 5*/ FLAG_ENTRY0("TX_LESS_THAN_FOUR_LNS", LCBE(TX_LESS_THAN_FOUR_LNS)),
  862. /* 6*/ FLAG_ENTRY0("RX_LESS_THAN_FOUR_LNS", LCBE(RX_LESS_THAN_FOUR_LNS)),
  863. /* 7*/ FLAG_ENTRY0("SEQ_CRC_ERR", LCBE(SEQ_CRC_ERR)),
  864. /* 8*/ FLAG_ENTRY0("REINIT_FROM_PEER", LCBE(REINIT_FROM_PEER)),
  865. /* 9*/ FLAG_ENTRY0("REINIT_FOR_LN_DEGRADE", LCBE(REINIT_FOR_LN_DEGRADE)),
  866. /*10*/ FLAG_ENTRY0("CRC_ERR_CNT_HIT_LIMIT", LCBE(CRC_ERR_CNT_HIT_LIMIT)),
  867. /*11*/ FLAG_ENTRY0("RCLK_STOPPED", LCBE(RCLK_STOPPED)),
  868. /*12*/ FLAG_ENTRY0("UNEXPECTED_REPLAY_MARKER", LCBE(UNEXPECTED_REPLAY_MARKER)),
  869. /*13*/ FLAG_ENTRY0("UNEXPECTED_ROUND_TRIP_MARKER",
  870. LCBE(UNEXPECTED_ROUND_TRIP_MARKER)),
  871. /*14*/ FLAG_ENTRY0("ILLEGAL_NULL_LTP", LCBE(ILLEGAL_NULL_LTP)),
  872. /*15*/ FLAG_ENTRY0("ILLEGAL_FLIT_ENCODING", LCBE(ILLEGAL_FLIT_ENCODING)),
  873. /*16*/ FLAG_ENTRY0("FLIT_INPUT_BUF_OFLW", LCBE(FLIT_INPUT_BUF_OFLW)),
  874. /*17*/ FLAG_ENTRY0("VL_ACK_INPUT_BUF_OFLW", LCBE(VL_ACK_INPUT_BUF_OFLW)),
  875. /*18*/ FLAG_ENTRY0("VL_ACK_INPUT_PARITY_ERR", LCBE(VL_ACK_INPUT_PARITY_ERR)),
  876. /*19*/ FLAG_ENTRY0("VL_ACK_INPUT_WRONG_CRC_MODE",
  877. LCBE(VL_ACK_INPUT_WRONG_CRC_MODE)),
  878. /*20*/ FLAG_ENTRY0("FLIT_INPUT_BUF_MBE", LCBE(FLIT_INPUT_BUF_MBE)),
  879. /*21*/ FLAG_ENTRY0("FLIT_INPUT_BUF_SBE", LCBE(FLIT_INPUT_BUF_SBE)),
  880. /*22*/ FLAG_ENTRY0("REPLAY_BUF_MBE", LCBE(REPLAY_BUF_MBE)),
  881. /*23*/ FLAG_ENTRY0("REPLAY_BUF_SBE", LCBE(REPLAY_BUF_SBE)),
  882. /*24*/ FLAG_ENTRY0("CREDIT_RETURN_FLIT_MBE", LCBE(CREDIT_RETURN_FLIT_MBE)),
  883. /*25*/ FLAG_ENTRY0("RST_FOR_LINK_TIMEOUT", LCBE(RST_FOR_LINK_TIMEOUT)),
  884. /*26*/ FLAG_ENTRY0("RST_FOR_INCOMPLT_RND_TRIP",
  885. LCBE(RST_FOR_INCOMPLT_RND_TRIP)),
  886. /*27*/ FLAG_ENTRY0("HOLD_REINIT", LCBE(HOLD_REINIT)),
  887. /*28*/ FLAG_ENTRY0("NEG_EDGE_LINK_TRANSFER_ACTIVE",
  888. LCBE(NEG_EDGE_LINK_TRANSFER_ACTIVE)),
  889. /*29*/ FLAG_ENTRY0("REDUNDANT_FLIT_PARITY_ERR",
  890. LCBE(REDUNDANT_FLIT_PARITY_ERR))
  891. };
  892. /*
  893. * DC8051 Error Flags
  894. */
  895. #define D8E(name) DC_DC8051_ERR_FLG_##name##_SMASK
  896. static struct flag_table dc8051_err_flags[] = {
  897. FLAG_ENTRY0("SET_BY_8051", D8E(SET_BY_8051)),
  898. FLAG_ENTRY0("LOST_8051_HEART_BEAT", D8E(LOST_8051_HEART_BEAT)),
  899. FLAG_ENTRY0("CRAM_MBE", D8E(CRAM_MBE)),
  900. FLAG_ENTRY0("CRAM_SBE", D8E(CRAM_SBE)),
  901. FLAG_ENTRY0("DRAM_MBE", D8E(DRAM_MBE)),
  902. FLAG_ENTRY0("DRAM_SBE", D8E(DRAM_SBE)),
  903. FLAG_ENTRY0("IRAM_MBE", D8E(IRAM_MBE)),
  904. FLAG_ENTRY0("IRAM_SBE", D8E(IRAM_SBE)),
  905. FLAG_ENTRY0("UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES",
  906. D8E(UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES)),
  907. FLAG_ENTRY0("INVALID_CSR_ADDR", D8E(INVALID_CSR_ADDR)),
  908. };
  909. /*
  910. * DC8051 Information Error flags
  911. *
  912. * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.ERROR field.
  913. */
  914. static struct flag_table dc8051_info_err_flags[] = {
  915. FLAG_ENTRY0("Spico ROM check failed", SPICO_ROM_FAILED),
  916. FLAG_ENTRY0("Unknown frame received", UNKNOWN_FRAME),
  917. FLAG_ENTRY0("Target BER not met", TARGET_BER_NOT_MET),
  918. FLAG_ENTRY0("Serdes internal loopback failure",
  919. FAILED_SERDES_INTERNAL_LOOPBACK),
  920. FLAG_ENTRY0("Failed SerDes init", FAILED_SERDES_INIT),
  921. FLAG_ENTRY0("Failed LNI(Polling)", FAILED_LNI_POLLING),
  922. FLAG_ENTRY0("Failed LNI(Debounce)", FAILED_LNI_DEBOUNCE),
  923. FLAG_ENTRY0("Failed LNI(EstbComm)", FAILED_LNI_ESTBCOMM),
  924. FLAG_ENTRY0("Failed LNI(OptEq)", FAILED_LNI_OPTEQ),
  925. FLAG_ENTRY0("Failed LNI(VerifyCap_1)", FAILED_LNI_VERIFY_CAP1),
  926. FLAG_ENTRY0("Failed LNI(VerifyCap_2)", FAILED_LNI_VERIFY_CAP2),
  927. FLAG_ENTRY0("Failed LNI(ConfigLT)", FAILED_LNI_CONFIGLT),
  928. FLAG_ENTRY0("Host Handshake Timeout", HOST_HANDSHAKE_TIMEOUT),
  929. FLAG_ENTRY0("External Device Request Timeout",
  930. EXTERNAL_DEVICE_REQ_TIMEOUT),
  931. };
  932. /*
  933. * DC8051 Information Host Information flags
  934. *
  935. * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.HOST_MSG field.
  936. */
  937. static struct flag_table dc8051_info_host_msg_flags[] = {
  938. FLAG_ENTRY0("Host request done", 0x0001),
  939. FLAG_ENTRY0("BC SMA message", 0x0002),
  940. FLAG_ENTRY0("BC PWR_MGM message", 0x0004),
  941. FLAG_ENTRY0("BC Unknown message (BCC)", 0x0008),
  942. FLAG_ENTRY0("BC Unknown message (LCB)", 0x0010),
  943. FLAG_ENTRY0("External device config request", 0x0020),
  944. FLAG_ENTRY0("VerifyCap all frames received", 0x0040),
  945. FLAG_ENTRY0("LinkUp achieved", 0x0080),
  946. FLAG_ENTRY0("Link going down", 0x0100),
  947. };
  948. static u32 encoded_size(u32 size);
  949. static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate);
  950. static int set_physical_link_state(struct hfi1_devdata *dd, u64 state);
  951. static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
  952. u8 *continuous);
  953. static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
  954. u8 *vcu, u16 *vl15buf, u8 *crc_sizes);
  955. static void read_vc_remote_link_width(struct hfi1_devdata *dd,
  956. u8 *remote_tx_rate, u16 *link_widths);
  957. static void read_vc_local_link_width(struct hfi1_devdata *dd, u8 *misc_bits,
  958. u8 *flag_bits, u16 *link_widths);
  959. static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
  960. u8 *device_rev);
  961. static void read_mgmt_allowed(struct hfi1_devdata *dd, u8 *mgmt_allowed);
  962. static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx);
  963. static int read_tx_settings(struct hfi1_devdata *dd, u8 *enable_lane_tx,
  964. u8 *tx_polarity_inversion,
  965. u8 *rx_polarity_inversion, u8 *max_rate);
  966. static void handle_sdma_eng_err(struct hfi1_devdata *dd,
  967. unsigned int context, u64 err_status);
  968. static void handle_qsfp_int(struct hfi1_devdata *dd, u32 source, u64 reg);
  969. static void handle_dcc_err(struct hfi1_devdata *dd,
  970. unsigned int context, u64 err_status);
  971. static void handle_lcb_err(struct hfi1_devdata *dd,
  972. unsigned int context, u64 err_status);
  973. static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg);
  974. static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  975. static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  976. static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  977. static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  978. static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  979. static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  980. static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  981. static void set_partition_keys(struct hfi1_pportdata *);
  982. static const char *link_state_name(u32 state);
  983. static const char *link_state_reason_name(struct hfi1_pportdata *ppd,
  984. u32 state);
  985. static int do_8051_command(struct hfi1_devdata *dd, u32 type, u64 in_data,
  986. u64 *out_data);
  987. static int read_idle_sma(struct hfi1_devdata *dd, u64 *data);
  988. static int thermal_init(struct hfi1_devdata *dd);
  989. static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  990. int msecs);
  991. static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc);
  992. static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr);
  993. static void handle_temp_err(struct hfi1_devdata *);
  994. static void dc_shutdown(struct hfi1_devdata *);
  995. static void dc_start(struct hfi1_devdata *);
  996. static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp,
  997. unsigned int *np);
  998. static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd);
  999. /*
  1000. * Error interrupt table entry. This is used as input to the interrupt
  1001. * "clear down" routine used for all second tier error interrupt register.
  1002. * Second tier interrupt registers have a single bit representing them
  1003. * in the top-level CceIntStatus.
  1004. */
  1005. struct err_reg_info {
  1006. u32 status; /* status CSR offset */
  1007. u32 clear; /* clear CSR offset */
  1008. u32 mask; /* mask CSR offset */
  1009. void (*handler)(struct hfi1_devdata *dd, u32 source, u64 reg);
  1010. const char *desc;
  1011. };
  1012. #define NUM_MISC_ERRS (IS_GENERAL_ERR_END - IS_GENERAL_ERR_START)
  1013. #define NUM_DC_ERRS (IS_DC_END - IS_DC_START)
  1014. #define NUM_VARIOUS (IS_VARIOUS_END - IS_VARIOUS_START)
  1015. /*
  1016. * Helpers for building HFI and DC error interrupt table entries. Different
  1017. * helpers are needed because of inconsistent register names.
  1018. */
  1019. #define EE(reg, handler, desc) \
  1020. { reg##_STATUS, reg##_CLEAR, reg##_MASK, \
  1021. handler, desc }
  1022. #define DC_EE1(reg, handler, desc) \
  1023. { reg##_FLG, reg##_FLG_CLR, reg##_FLG_EN, handler, desc }
  1024. #define DC_EE2(reg, handler, desc) \
  1025. { reg##_FLG, reg##_CLR, reg##_EN, handler, desc }
  1026. /*
  1027. * Table of the "misc" grouping of error interrupts. Each entry refers to
  1028. * another register containing more information.
  1029. */
  1030. static const struct err_reg_info misc_errs[NUM_MISC_ERRS] = {
  1031. /* 0*/ EE(CCE_ERR, handle_cce_err, "CceErr"),
  1032. /* 1*/ EE(RCV_ERR, handle_rxe_err, "RxeErr"),
  1033. /* 2*/ EE(MISC_ERR, handle_misc_err, "MiscErr"),
  1034. /* 3*/ { 0, 0, 0, NULL }, /* reserved */
  1035. /* 4*/ EE(SEND_PIO_ERR, handle_pio_err, "PioErr"),
  1036. /* 5*/ EE(SEND_DMA_ERR, handle_sdma_err, "SDmaErr"),
  1037. /* 6*/ EE(SEND_EGRESS_ERR, handle_egress_err, "EgressErr"),
  1038. /* 7*/ EE(SEND_ERR, handle_txe_err, "TxeErr")
  1039. /* the rest are reserved */
  1040. };
  1041. /*
  1042. * Index into the Various section of the interrupt sources
  1043. * corresponding to the Critical Temperature interrupt.
  1044. */
  1045. #define TCRIT_INT_SOURCE 4
  1046. /*
  1047. * SDMA error interrupt entry - refers to another register containing more
  1048. * information.
  1049. */
  1050. static const struct err_reg_info sdma_eng_err =
  1051. EE(SEND_DMA_ENG_ERR, handle_sdma_eng_err, "SDmaEngErr");
  1052. static const struct err_reg_info various_err[NUM_VARIOUS] = {
  1053. /* 0*/ { 0, 0, 0, NULL }, /* PbcInt */
  1054. /* 1*/ { 0, 0, 0, NULL }, /* GpioAssertInt */
  1055. /* 2*/ EE(ASIC_QSFP1, handle_qsfp_int, "QSFP1"),
  1056. /* 3*/ EE(ASIC_QSFP2, handle_qsfp_int, "QSFP2"),
  1057. /* 4*/ { 0, 0, 0, NULL }, /* TCritInt */
  1058. /* rest are reserved */
  1059. };
  1060. /*
  1061. * The DC encoding of mtu_cap for 10K MTU in the DCC_CFG_PORT_CONFIG
  1062. * register can not be derived from the MTU value because 10K is not
  1063. * a power of 2. Therefore, we need a constant. Everything else can
  1064. * be calculated.
  1065. */
  1066. #define DCC_CFG_PORT_MTU_CAP_10240 7
  1067. /*
  1068. * Table of the DC grouping of error interrupts. Each entry refers to
  1069. * another register containing more information.
  1070. */
  1071. static const struct err_reg_info dc_errs[NUM_DC_ERRS] = {
  1072. /* 0*/ DC_EE1(DCC_ERR, handle_dcc_err, "DCC Err"),
  1073. /* 1*/ DC_EE2(DC_LCB_ERR, handle_lcb_err, "LCB Err"),
  1074. /* 2*/ DC_EE2(DC_DC8051_ERR, handle_8051_interrupt, "DC8051 Interrupt"),
  1075. /* 3*/ /* dc_lbm_int - special, see is_dc_int() */
  1076. /* the rest are reserved */
  1077. };
  1078. struct cntr_entry {
  1079. /*
  1080. * counter name
  1081. */
  1082. char *name;
  1083. /*
  1084. * csr to read for name (if applicable)
  1085. */
  1086. u64 csr;
  1087. /*
  1088. * offset into dd or ppd to store the counter's value
  1089. */
  1090. int offset;
  1091. /*
  1092. * flags
  1093. */
  1094. u8 flags;
  1095. /*
  1096. * accessor for stat element, context either dd or ppd
  1097. */
  1098. u64 (*rw_cntr)(const struct cntr_entry *, void *context, int vl,
  1099. int mode, u64 data);
  1100. };
  1101. #define C_RCV_HDR_OVF_FIRST C_RCV_HDR_OVF_0
  1102. #define C_RCV_HDR_OVF_LAST C_RCV_HDR_OVF_159
  1103. #define CNTR_ELEM(name, csr, offset, flags, accessor) \
  1104. { \
  1105. name, \
  1106. csr, \
  1107. offset, \
  1108. flags, \
  1109. accessor \
  1110. }
  1111. /* 32bit RXE */
  1112. #define RXE32_PORT_CNTR_ELEM(name, counter, flags) \
  1113. CNTR_ELEM(#name, \
  1114. (counter * 8 + RCV_COUNTER_ARRAY32), \
  1115. 0, flags | CNTR_32BIT, \
  1116. port_access_u32_csr)
  1117. #define RXE32_DEV_CNTR_ELEM(name, counter, flags) \
  1118. CNTR_ELEM(#name, \
  1119. (counter * 8 + RCV_COUNTER_ARRAY32), \
  1120. 0, flags | CNTR_32BIT, \
  1121. dev_access_u32_csr)
  1122. /* 64bit RXE */
  1123. #define RXE64_PORT_CNTR_ELEM(name, counter, flags) \
  1124. CNTR_ELEM(#name, \
  1125. (counter * 8 + RCV_COUNTER_ARRAY64), \
  1126. 0, flags, \
  1127. port_access_u64_csr)
  1128. #define RXE64_DEV_CNTR_ELEM(name, counter, flags) \
  1129. CNTR_ELEM(#name, \
  1130. (counter * 8 + RCV_COUNTER_ARRAY64), \
  1131. 0, flags, \
  1132. dev_access_u64_csr)
  1133. #define OVR_LBL(ctx) C_RCV_HDR_OVF_ ## ctx
  1134. #define OVR_ELM(ctx) \
  1135. CNTR_ELEM("RcvHdrOvr" #ctx, \
  1136. (RCV_HDR_OVFL_CNT + ctx * 0x100), \
  1137. 0, CNTR_NORMAL, port_access_u64_csr)
  1138. /* 32bit TXE */
  1139. #define TXE32_PORT_CNTR_ELEM(name, counter, flags) \
  1140. CNTR_ELEM(#name, \
  1141. (counter * 8 + SEND_COUNTER_ARRAY32), \
  1142. 0, flags | CNTR_32BIT, \
  1143. port_access_u32_csr)
  1144. /* 64bit TXE */
  1145. #define TXE64_PORT_CNTR_ELEM(name, counter, flags) \
  1146. CNTR_ELEM(#name, \
  1147. (counter * 8 + SEND_COUNTER_ARRAY64), \
  1148. 0, flags, \
  1149. port_access_u64_csr)
  1150. # define TX64_DEV_CNTR_ELEM(name, counter, flags) \
  1151. CNTR_ELEM(#name,\
  1152. counter * 8 + SEND_COUNTER_ARRAY64, \
  1153. 0, \
  1154. flags, \
  1155. dev_access_u64_csr)
  1156. /* CCE */
  1157. #define CCE_PERF_DEV_CNTR_ELEM(name, counter, flags) \
  1158. CNTR_ELEM(#name, \
  1159. (counter * 8 + CCE_COUNTER_ARRAY32), \
  1160. 0, flags | CNTR_32BIT, \
  1161. dev_access_u32_csr)
  1162. #define CCE_INT_DEV_CNTR_ELEM(name, counter, flags) \
  1163. CNTR_ELEM(#name, \
  1164. (counter * 8 + CCE_INT_COUNTER_ARRAY32), \
  1165. 0, flags | CNTR_32BIT, \
  1166. dev_access_u32_csr)
  1167. /* DC */
  1168. #define DC_PERF_CNTR(name, counter, flags) \
  1169. CNTR_ELEM(#name, \
  1170. counter, \
  1171. 0, \
  1172. flags, \
  1173. dev_access_u64_csr)
  1174. #define DC_PERF_CNTR_LCB(name, counter, flags) \
  1175. CNTR_ELEM(#name, \
  1176. counter, \
  1177. 0, \
  1178. flags, \
  1179. dc_access_lcb_cntr)
  1180. /* ibp counters */
  1181. #define SW_IBP_CNTR(name, cntr) \
  1182. CNTR_ELEM(#name, \
  1183. 0, \
  1184. 0, \
  1185. CNTR_SYNTH, \
  1186. access_ibp_##cntr)
  1187. u64 read_csr(const struct hfi1_devdata *dd, u32 offset)
  1188. {
  1189. if (dd->flags & HFI1_PRESENT) {
  1190. return readq((void __iomem *)dd->kregbase + offset);
  1191. }
  1192. return -1;
  1193. }
  1194. void write_csr(const struct hfi1_devdata *dd, u32 offset, u64 value)
  1195. {
  1196. if (dd->flags & HFI1_PRESENT)
  1197. writeq(value, (void __iomem *)dd->kregbase + offset);
  1198. }
  1199. void __iomem *get_csr_addr(
  1200. struct hfi1_devdata *dd,
  1201. u32 offset)
  1202. {
  1203. return (void __iomem *)dd->kregbase + offset;
  1204. }
  1205. static inline u64 read_write_csr(const struct hfi1_devdata *dd, u32 csr,
  1206. int mode, u64 value)
  1207. {
  1208. u64 ret;
  1209. if (mode == CNTR_MODE_R) {
  1210. ret = read_csr(dd, csr);
  1211. } else if (mode == CNTR_MODE_W) {
  1212. write_csr(dd, csr, value);
  1213. ret = value;
  1214. } else {
  1215. dd_dev_err(dd, "Invalid cntr register access mode");
  1216. return 0;
  1217. }
  1218. hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, ret, mode);
  1219. return ret;
  1220. }
  1221. /* Dev Access */
  1222. static u64 dev_access_u32_csr(const struct cntr_entry *entry,
  1223. void *context, int vl, int mode, u64 data)
  1224. {
  1225. struct hfi1_devdata *dd = context;
  1226. u64 csr = entry->csr;
  1227. if (entry->flags & CNTR_SDMA) {
  1228. if (vl == CNTR_INVALID_VL)
  1229. return 0;
  1230. csr += 0x100 * vl;
  1231. } else {
  1232. if (vl != CNTR_INVALID_VL)
  1233. return 0;
  1234. }
  1235. return read_write_csr(dd, csr, mode, data);
  1236. }
  1237. static u64 access_sde_err_cnt(const struct cntr_entry *entry,
  1238. void *context, int idx, int mode, u64 data)
  1239. {
  1240. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1241. if (dd->per_sdma && idx < dd->num_sdma)
  1242. return dd->per_sdma[idx].err_cnt;
  1243. return 0;
  1244. }
  1245. static u64 access_sde_int_cnt(const struct cntr_entry *entry,
  1246. void *context, int idx, int mode, u64 data)
  1247. {
  1248. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1249. if (dd->per_sdma && idx < dd->num_sdma)
  1250. return dd->per_sdma[idx].sdma_int_cnt;
  1251. return 0;
  1252. }
  1253. static u64 access_sde_idle_int_cnt(const struct cntr_entry *entry,
  1254. void *context, int idx, int mode, u64 data)
  1255. {
  1256. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1257. if (dd->per_sdma && idx < dd->num_sdma)
  1258. return dd->per_sdma[idx].idle_int_cnt;
  1259. return 0;
  1260. }
  1261. static u64 access_sde_progress_int_cnt(const struct cntr_entry *entry,
  1262. void *context, int idx, int mode,
  1263. u64 data)
  1264. {
  1265. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1266. if (dd->per_sdma && idx < dd->num_sdma)
  1267. return dd->per_sdma[idx].progress_int_cnt;
  1268. return 0;
  1269. }
  1270. static u64 dev_access_u64_csr(const struct cntr_entry *entry, void *context,
  1271. int vl, int mode, u64 data)
  1272. {
  1273. struct hfi1_devdata *dd = context;
  1274. u64 val = 0;
  1275. u64 csr = entry->csr;
  1276. if (entry->flags & CNTR_VL) {
  1277. if (vl == CNTR_INVALID_VL)
  1278. return 0;
  1279. csr += 8 * vl;
  1280. } else {
  1281. if (vl != CNTR_INVALID_VL)
  1282. return 0;
  1283. }
  1284. val = read_write_csr(dd, csr, mode, data);
  1285. return val;
  1286. }
  1287. static u64 dc_access_lcb_cntr(const struct cntr_entry *entry, void *context,
  1288. int vl, int mode, u64 data)
  1289. {
  1290. struct hfi1_devdata *dd = context;
  1291. u32 csr = entry->csr;
  1292. int ret = 0;
  1293. if (vl != CNTR_INVALID_VL)
  1294. return 0;
  1295. if (mode == CNTR_MODE_R)
  1296. ret = read_lcb_csr(dd, csr, &data);
  1297. else if (mode == CNTR_MODE_W)
  1298. ret = write_lcb_csr(dd, csr, data);
  1299. if (ret) {
  1300. dd_dev_err(dd, "Could not acquire LCB for counter 0x%x", csr);
  1301. return 0;
  1302. }
  1303. hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, data, mode);
  1304. return data;
  1305. }
  1306. /* Port Access */
  1307. static u64 port_access_u32_csr(const struct cntr_entry *entry, void *context,
  1308. int vl, int mode, u64 data)
  1309. {
  1310. struct hfi1_pportdata *ppd = context;
  1311. if (vl != CNTR_INVALID_VL)
  1312. return 0;
  1313. return read_write_csr(ppd->dd, entry->csr, mode, data);
  1314. }
  1315. static u64 port_access_u64_csr(const struct cntr_entry *entry,
  1316. void *context, int vl, int mode, u64 data)
  1317. {
  1318. struct hfi1_pportdata *ppd = context;
  1319. u64 val;
  1320. u64 csr = entry->csr;
  1321. if (entry->flags & CNTR_VL) {
  1322. if (vl == CNTR_INVALID_VL)
  1323. return 0;
  1324. csr += 8 * vl;
  1325. } else {
  1326. if (vl != CNTR_INVALID_VL)
  1327. return 0;
  1328. }
  1329. val = read_write_csr(ppd->dd, csr, mode, data);
  1330. return val;
  1331. }
  1332. /* Software defined */
  1333. static inline u64 read_write_sw(struct hfi1_devdata *dd, u64 *cntr, int mode,
  1334. u64 data)
  1335. {
  1336. u64 ret;
  1337. if (mode == CNTR_MODE_R) {
  1338. ret = *cntr;
  1339. } else if (mode == CNTR_MODE_W) {
  1340. *cntr = data;
  1341. ret = data;
  1342. } else {
  1343. dd_dev_err(dd, "Invalid cntr sw access mode");
  1344. return 0;
  1345. }
  1346. hfi1_cdbg(CNTR, "val 0x%llx mode %d", ret, mode);
  1347. return ret;
  1348. }
  1349. static u64 access_sw_link_dn_cnt(const struct cntr_entry *entry, void *context,
  1350. int vl, int mode, u64 data)
  1351. {
  1352. struct hfi1_pportdata *ppd = context;
  1353. if (vl != CNTR_INVALID_VL)
  1354. return 0;
  1355. return read_write_sw(ppd->dd, &ppd->link_downed, mode, data);
  1356. }
  1357. static u64 access_sw_link_up_cnt(const struct cntr_entry *entry, void *context,
  1358. int vl, int mode, u64 data)
  1359. {
  1360. struct hfi1_pportdata *ppd = context;
  1361. if (vl != CNTR_INVALID_VL)
  1362. return 0;
  1363. return read_write_sw(ppd->dd, &ppd->link_up, mode, data);
  1364. }
  1365. static u64 access_sw_unknown_frame_cnt(const struct cntr_entry *entry,
  1366. void *context, int vl, int mode,
  1367. u64 data)
  1368. {
  1369. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
  1370. if (vl != CNTR_INVALID_VL)
  1371. return 0;
  1372. return read_write_sw(ppd->dd, &ppd->unknown_frame_count, mode, data);
  1373. }
  1374. static u64 access_sw_xmit_discards(const struct cntr_entry *entry,
  1375. void *context, int vl, int mode, u64 data)
  1376. {
  1377. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
  1378. u64 zero = 0;
  1379. u64 *counter;
  1380. if (vl == CNTR_INVALID_VL)
  1381. counter = &ppd->port_xmit_discards;
  1382. else if (vl >= 0 && vl < C_VL_COUNT)
  1383. counter = &ppd->port_xmit_discards_vl[vl];
  1384. else
  1385. counter = &zero;
  1386. return read_write_sw(ppd->dd, counter, mode, data);
  1387. }
  1388. static u64 access_xmit_constraint_errs(const struct cntr_entry *entry,
  1389. void *context, int vl, int mode,
  1390. u64 data)
  1391. {
  1392. struct hfi1_pportdata *ppd = context;
  1393. if (vl != CNTR_INVALID_VL)
  1394. return 0;
  1395. return read_write_sw(ppd->dd, &ppd->port_xmit_constraint_errors,
  1396. mode, data);
  1397. }
  1398. static u64 access_rcv_constraint_errs(const struct cntr_entry *entry,
  1399. void *context, int vl, int mode, u64 data)
  1400. {
  1401. struct hfi1_pportdata *ppd = context;
  1402. if (vl != CNTR_INVALID_VL)
  1403. return 0;
  1404. return read_write_sw(ppd->dd, &ppd->port_rcv_constraint_errors,
  1405. mode, data);
  1406. }
  1407. u64 get_all_cpu_total(u64 __percpu *cntr)
  1408. {
  1409. int cpu;
  1410. u64 counter = 0;
  1411. for_each_possible_cpu(cpu)
  1412. counter += *per_cpu_ptr(cntr, cpu);
  1413. return counter;
  1414. }
  1415. static u64 read_write_cpu(struct hfi1_devdata *dd, u64 *z_val,
  1416. u64 __percpu *cntr,
  1417. int vl, int mode, u64 data)
  1418. {
  1419. u64 ret = 0;
  1420. if (vl != CNTR_INVALID_VL)
  1421. return 0;
  1422. if (mode == CNTR_MODE_R) {
  1423. ret = get_all_cpu_total(cntr) - *z_val;
  1424. } else if (mode == CNTR_MODE_W) {
  1425. /* A write can only zero the counter */
  1426. if (data == 0)
  1427. *z_val = get_all_cpu_total(cntr);
  1428. else
  1429. dd_dev_err(dd, "Per CPU cntrs can only be zeroed");
  1430. } else {
  1431. dd_dev_err(dd, "Invalid cntr sw cpu access mode");
  1432. return 0;
  1433. }
  1434. return ret;
  1435. }
  1436. static u64 access_sw_cpu_intr(const struct cntr_entry *entry,
  1437. void *context, int vl, int mode, u64 data)
  1438. {
  1439. struct hfi1_devdata *dd = context;
  1440. return read_write_cpu(dd, &dd->z_int_counter, dd->int_counter, vl,
  1441. mode, data);
  1442. }
  1443. static u64 access_sw_cpu_rcv_limit(const struct cntr_entry *entry,
  1444. void *context, int vl, int mode, u64 data)
  1445. {
  1446. struct hfi1_devdata *dd = context;
  1447. return read_write_cpu(dd, &dd->z_rcv_limit, dd->rcv_limit, vl,
  1448. mode, data);
  1449. }
  1450. static u64 access_sw_pio_wait(const struct cntr_entry *entry,
  1451. void *context, int vl, int mode, u64 data)
  1452. {
  1453. struct hfi1_devdata *dd = context;
  1454. return dd->verbs_dev.n_piowait;
  1455. }
  1456. static u64 access_sw_pio_drain(const struct cntr_entry *entry,
  1457. void *context, int vl, int mode, u64 data)
  1458. {
  1459. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1460. return dd->verbs_dev.n_piodrain;
  1461. }
  1462. static u64 access_sw_vtx_wait(const struct cntr_entry *entry,
  1463. void *context, int vl, int mode, u64 data)
  1464. {
  1465. struct hfi1_devdata *dd = context;
  1466. return dd->verbs_dev.n_txwait;
  1467. }
  1468. static u64 access_sw_kmem_wait(const struct cntr_entry *entry,
  1469. void *context, int vl, int mode, u64 data)
  1470. {
  1471. struct hfi1_devdata *dd = context;
  1472. return dd->verbs_dev.n_kmem_wait;
  1473. }
  1474. static u64 access_sw_send_schedule(const struct cntr_entry *entry,
  1475. void *context, int vl, int mode, u64 data)
  1476. {
  1477. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1478. return read_write_cpu(dd, &dd->z_send_schedule, dd->send_schedule, vl,
  1479. mode, data);
  1480. }
  1481. /* Software counters for the error status bits within MISC_ERR_STATUS */
  1482. static u64 access_misc_pll_lock_fail_err_cnt(const struct cntr_entry *entry,
  1483. void *context, int vl, int mode,
  1484. u64 data)
  1485. {
  1486. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1487. return dd->misc_err_status_cnt[12];
  1488. }
  1489. static u64 access_misc_mbist_fail_err_cnt(const struct cntr_entry *entry,
  1490. void *context, int vl, int mode,
  1491. u64 data)
  1492. {
  1493. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1494. return dd->misc_err_status_cnt[11];
  1495. }
  1496. static u64 access_misc_invalid_eep_cmd_err_cnt(const struct cntr_entry *entry,
  1497. void *context, int vl, int mode,
  1498. u64 data)
  1499. {
  1500. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1501. return dd->misc_err_status_cnt[10];
  1502. }
  1503. static u64 access_misc_efuse_done_parity_err_cnt(const struct cntr_entry *entry,
  1504. void *context, int vl,
  1505. int mode, u64 data)
  1506. {
  1507. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1508. return dd->misc_err_status_cnt[9];
  1509. }
  1510. static u64 access_misc_efuse_write_err_cnt(const struct cntr_entry *entry,
  1511. void *context, int vl, int mode,
  1512. u64 data)
  1513. {
  1514. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1515. return dd->misc_err_status_cnt[8];
  1516. }
  1517. static u64 access_misc_efuse_read_bad_addr_err_cnt(
  1518. const struct cntr_entry *entry,
  1519. void *context, int vl, int mode, u64 data)
  1520. {
  1521. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1522. return dd->misc_err_status_cnt[7];
  1523. }
  1524. static u64 access_misc_efuse_csr_parity_err_cnt(const struct cntr_entry *entry,
  1525. void *context, int vl,
  1526. int mode, u64 data)
  1527. {
  1528. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1529. return dd->misc_err_status_cnt[6];
  1530. }
  1531. static u64 access_misc_fw_auth_failed_err_cnt(const struct cntr_entry *entry,
  1532. void *context, int vl, int mode,
  1533. u64 data)
  1534. {
  1535. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1536. return dd->misc_err_status_cnt[5];
  1537. }
  1538. static u64 access_misc_key_mismatch_err_cnt(const struct cntr_entry *entry,
  1539. void *context, int vl, int mode,
  1540. u64 data)
  1541. {
  1542. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1543. return dd->misc_err_status_cnt[4];
  1544. }
  1545. static u64 access_misc_sbus_write_failed_err_cnt(const struct cntr_entry *entry,
  1546. void *context, int vl,
  1547. int mode, u64 data)
  1548. {
  1549. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1550. return dd->misc_err_status_cnt[3];
  1551. }
  1552. static u64 access_misc_csr_write_bad_addr_err_cnt(
  1553. const struct cntr_entry *entry,
  1554. void *context, int vl, int mode, u64 data)
  1555. {
  1556. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1557. return dd->misc_err_status_cnt[2];
  1558. }
  1559. static u64 access_misc_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1560. void *context, int vl,
  1561. int mode, u64 data)
  1562. {
  1563. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1564. return dd->misc_err_status_cnt[1];
  1565. }
  1566. static u64 access_misc_csr_parity_err_cnt(const struct cntr_entry *entry,
  1567. void *context, int vl, int mode,
  1568. u64 data)
  1569. {
  1570. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1571. return dd->misc_err_status_cnt[0];
  1572. }
  1573. /*
  1574. * Software counter for the aggregate of
  1575. * individual CceErrStatus counters
  1576. */
  1577. static u64 access_sw_cce_err_status_aggregated_cnt(
  1578. const struct cntr_entry *entry,
  1579. void *context, int vl, int mode, u64 data)
  1580. {
  1581. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1582. return dd->sw_cce_err_status_aggregate;
  1583. }
  1584. /*
  1585. * Software counters corresponding to each of the
  1586. * error status bits within CceErrStatus
  1587. */
  1588. static u64 access_cce_msix_csr_parity_err_cnt(const struct cntr_entry *entry,
  1589. void *context, int vl, int mode,
  1590. u64 data)
  1591. {
  1592. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1593. return dd->cce_err_status_cnt[40];
  1594. }
  1595. static u64 access_cce_int_map_unc_err_cnt(const struct cntr_entry *entry,
  1596. void *context, int vl, int mode,
  1597. u64 data)
  1598. {
  1599. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1600. return dd->cce_err_status_cnt[39];
  1601. }
  1602. static u64 access_cce_int_map_cor_err_cnt(const struct cntr_entry *entry,
  1603. void *context, int vl, int mode,
  1604. u64 data)
  1605. {
  1606. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1607. return dd->cce_err_status_cnt[38];
  1608. }
  1609. static u64 access_cce_msix_table_unc_err_cnt(const struct cntr_entry *entry,
  1610. void *context, int vl, int mode,
  1611. u64 data)
  1612. {
  1613. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1614. return dd->cce_err_status_cnt[37];
  1615. }
  1616. static u64 access_cce_msix_table_cor_err_cnt(const struct cntr_entry *entry,
  1617. void *context, int vl, int mode,
  1618. u64 data)
  1619. {
  1620. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1621. return dd->cce_err_status_cnt[36];
  1622. }
  1623. static u64 access_cce_rxdma_conv_fifo_parity_err_cnt(
  1624. const struct cntr_entry *entry,
  1625. void *context, int vl, int mode, u64 data)
  1626. {
  1627. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1628. return dd->cce_err_status_cnt[35];
  1629. }
  1630. static u64 access_cce_rcpl_async_fifo_parity_err_cnt(
  1631. const struct cntr_entry *entry,
  1632. void *context, int vl, int mode, u64 data)
  1633. {
  1634. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1635. return dd->cce_err_status_cnt[34];
  1636. }
  1637. static u64 access_cce_seg_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1638. void *context, int vl,
  1639. int mode, u64 data)
  1640. {
  1641. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1642. return dd->cce_err_status_cnt[33];
  1643. }
  1644. static u64 access_cce_seg_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1645. void *context, int vl, int mode,
  1646. u64 data)
  1647. {
  1648. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1649. return dd->cce_err_status_cnt[32];
  1650. }
  1651. static u64 access_la_triggered_cnt(const struct cntr_entry *entry,
  1652. void *context, int vl, int mode, u64 data)
  1653. {
  1654. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1655. return dd->cce_err_status_cnt[31];
  1656. }
  1657. static u64 access_cce_trgt_cpl_timeout_err_cnt(const struct cntr_entry *entry,
  1658. void *context, int vl, int mode,
  1659. u64 data)
  1660. {
  1661. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1662. return dd->cce_err_status_cnt[30];
  1663. }
  1664. static u64 access_pcic_receive_parity_err_cnt(const struct cntr_entry *entry,
  1665. void *context, int vl, int mode,
  1666. u64 data)
  1667. {
  1668. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1669. return dd->cce_err_status_cnt[29];
  1670. }
  1671. static u64 access_pcic_transmit_back_parity_err_cnt(
  1672. const struct cntr_entry *entry,
  1673. void *context, int vl, int mode, u64 data)
  1674. {
  1675. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1676. return dd->cce_err_status_cnt[28];
  1677. }
  1678. static u64 access_pcic_transmit_front_parity_err_cnt(
  1679. const struct cntr_entry *entry,
  1680. void *context, int vl, int mode, u64 data)
  1681. {
  1682. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1683. return dd->cce_err_status_cnt[27];
  1684. }
  1685. static u64 access_pcic_cpl_dat_q_unc_err_cnt(const struct cntr_entry *entry,
  1686. void *context, int vl, int mode,
  1687. u64 data)
  1688. {
  1689. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1690. return dd->cce_err_status_cnt[26];
  1691. }
  1692. static u64 access_pcic_cpl_hd_q_unc_err_cnt(const struct cntr_entry *entry,
  1693. void *context, int vl, int mode,
  1694. u64 data)
  1695. {
  1696. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1697. return dd->cce_err_status_cnt[25];
  1698. }
  1699. static u64 access_pcic_post_dat_q_unc_err_cnt(const struct cntr_entry *entry,
  1700. void *context, int vl, int mode,
  1701. u64 data)
  1702. {
  1703. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1704. return dd->cce_err_status_cnt[24];
  1705. }
  1706. static u64 access_pcic_post_hd_q_unc_err_cnt(const struct cntr_entry *entry,
  1707. void *context, int vl, int mode,
  1708. u64 data)
  1709. {
  1710. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1711. return dd->cce_err_status_cnt[23];
  1712. }
  1713. static u64 access_pcic_retry_sot_mem_unc_err_cnt(const struct cntr_entry *entry,
  1714. void *context, int vl,
  1715. int mode, u64 data)
  1716. {
  1717. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1718. return dd->cce_err_status_cnt[22];
  1719. }
  1720. static u64 access_pcic_retry_mem_unc_err(const struct cntr_entry *entry,
  1721. void *context, int vl, int mode,
  1722. u64 data)
  1723. {
  1724. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1725. return dd->cce_err_status_cnt[21];
  1726. }
  1727. static u64 access_pcic_n_post_dat_q_parity_err_cnt(
  1728. const struct cntr_entry *entry,
  1729. void *context, int vl, int mode, u64 data)
  1730. {
  1731. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1732. return dd->cce_err_status_cnt[20];
  1733. }
  1734. static u64 access_pcic_n_post_h_q_parity_err_cnt(const struct cntr_entry *entry,
  1735. void *context, int vl,
  1736. int mode, u64 data)
  1737. {
  1738. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1739. return dd->cce_err_status_cnt[19];
  1740. }
  1741. static u64 access_pcic_cpl_dat_q_cor_err_cnt(const struct cntr_entry *entry,
  1742. void *context, int vl, int mode,
  1743. u64 data)
  1744. {
  1745. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1746. return dd->cce_err_status_cnt[18];
  1747. }
  1748. static u64 access_pcic_cpl_hd_q_cor_err_cnt(const struct cntr_entry *entry,
  1749. void *context, int vl, int mode,
  1750. u64 data)
  1751. {
  1752. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1753. return dd->cce_err_status_cnt[17];
  1754. }
  1755. static u64 access_pcic_post_dat_q_cor_err_cnt(const struct cntr_entry *entry,
  1756. void *context, int vl, int mode,
  1757. u64 data)
  1758. {
  1759. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1760. return dd->cce_err_status_cnt[16];
  1761. }
  1762. static u64 access_pcic_post_hd_q_cor_err_cnt(const struct cntr_entry *entry,
  1763. void *context, int vl, int mode,
  1764. u64 data)
  1765. {
  1766. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1767. return dd->cce_err_status_cnt[15];
  1768. }
  1769. static u64 access_pcic_retry_sot_mem_cor_err_cnt(const struct cntr_entry *entry,
  1770. void *context, int vl,
  1771. int mode, u64 data)
  1772. {
  1773. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1774. return dd->cce_err_status_cnt[14];
  1775. }
  1776. static u64 access_pcic_retry_mem_cor_err_cnt(const struct cntr_entry *entry,
  1777. void *context, int vl, int mode,
  1778. u64 data)
  1779. {
  1780. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1781. return dd->cce_err_status_cnt[13];
  1782. }
  1783. static u64 access_cce_cli1_async_fifo_dbg_parity_err_cnt(
  1784. const struct cntr_entry *entry,
  1785. void *context, int vl, int mode, u64 data)
  1786. {
  1787. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1788. return dd->cce_err_status_cnt[12];
  1789. }
  1790. static u64 access_cce_cli1_async_fifo_rxdma_parity_err_cnt(
  1791. const struct cntr_entry *entry,
  1792. void *context, int vl, int mode, u64 data)
  1793. {
  1794. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1795. return dd->cce_err_status_cnt[11];
  1796. }
  1797. static u64 access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt(
  1798. const struct cntr_entry *entry,
  1799. void *context, int vl, int mode, u64 data)
  1800. {
  1801. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1802. return dd->cce_err_status_cnt[10];
  1803. }
  1804. static u64 access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt(
  1805. const struct cntr_entry *entry,
  1806. void *context, int vl, int mode, u64 data)
  1807. {
  1808. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1809. return dd->cce_err_status_cnt[9];
  1810. }
  1811. static u64 access_cce_cli2_async_fifo_parity_err_cnt(
  1812. const struct cntr_entry *entry,
  1813. void *context, int vl, int mode, u64 data)
  1814. {
  1815. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1816. return dd->cce_err_status_cnt[8];
  1817. }
  1818. static u64 access_cce_csr_cfg_bus_parity_err_cnt(const struct cntr_entry *entry,
  1819. void *context, int vl,
  1820. int mode, u64 data)
  1821. {
  1822. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1823. return dd->cce_err_status_cnt[7];
  1824. }
  1825. static u64 access_cce_cli0_async_fifo_parity_err_cnt(
  1826. const struct cntr_entry *entry,
  1827. void *context, int vl, int mode, u64 data)
  1828. {
  1829. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1830. return dd->cce_err_status_cnt[6];
  1831. }
  1832. static u64 access_cce_rspd_data_parity_err_cnt(const struct cntr_entry *entry,
  1833. void *context, int vl, int mode,
  1834. u64 data)
  1835. {
  1836. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1837. return dd->cce_err_status_cnt[5];
  1838. }
  1839. static u64 access_cce_trgt_access_err_cnt(const struct cntr_entry *entry,
  1840. void *context, int vl, int mode,
  1841. u64 data)
  1842. {
  1843. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1844. return dd->cce_err_status_cnt[4];
  1845. }
  1846. static u64 access_cce_trgt_async_fifo_parity_err_cnt(
  1847. const struct cntr_entry *entry,
  1848. void *context, int vl, int mode, u64 data)
  1849. {
  1850. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1851. return dd->cce_err_status_cnt[3];
  1852. }
  1853. static u64 access_cce_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1854. void *context, int vl,
  1855. int mode, u64 data)
  1856. {
  1857. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1858. return dd->cce_err_status_cnt[2];
  1859. }
  1860. static u64 access_cce_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1861. void *context, int vl,
  1862. int mode, u64 data)
  1863. {
  1864. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1865. return dd->cce_err_status_cnt[1];
  1866. }
  1867. static u64 access_ccs_csr_parity_err_cnt(const struct cntr_entry *entry,
  1868. void *context, int vl, int mode,
  1869. u64 data)
  1870. {
  1871. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1872. return dd->cce_err_status_cnt[0];
  1873. }
  1874. /*
  1875. * Software counters corresponding to each of the
  1876. * error status bits within RcvErrStatus
  1877. */
  1878. static u64 access_rx_csr_parity_err_cnt(const struct cntr_entry *entry,
  1879. void *context, int vl, int mode,
  1880. u64 data)
  1881. {
  1882. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1883. return dd->rcv_err_status_cnt[63];
  1884. }
  1885. static u64 access_rx_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1886. void *context, int vl,
  1887. int mode, u64 data)
  1888. {
  1889. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1890. return dd->rcv_err_status_cnt[62];
  1891. }
  1892. static u64 access_rx_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1893. void *context, int vl, int mode,
  1894. u64 data)
  1895. {
  1896. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1897. return dd->rcv_err_status_cnt[61];
  1898. }
  1899. static u64 access_rx_dma_csr_unc_err_cnt(const struct cntr_entry *entry,
  1900. void *context, int vl, int mode,
  1901. u64 data)
  1902. {
  1903. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1904. return dd->rcv_err_status_cnt[60];
  1905. }
  1906. static u64 access_rx_dma_dq_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  1907. void *context, int vl,
  1908. int mode, u64 data)
  1909. {
  1910. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1911. return dd->rcv_err_status_cnt[59];
  1912. }
  1913. static u64 access_rx_dma_eq_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  1914. void *context, int vl,
  1915. int mode, u64 data)
  1916. {
  1917. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1918. return dd->rcv_err_status_cnt[58];
  1919. }
  1920. static u64 access_rx_dma_csr_parity_err_cnt(const struct cntr_entry *entry,
  1921. void *context, int vl, int mode,
  1922. u64 data)
  1923. {
  1924. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1925. return dd->rcv_err_status_cnt[57];
  1926. }
  1927. static u64 access_rx_rbuf_data_cor_err_cnt(const struct cntr_entry *entry,
  1928. void *context, int vl, int mode,
  1929. u64 data)
  1930. {
  1931. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1932. return dd->rcv_err_status_cnt[56];
  1933. }
  1934. static u64 access_rx_rbuf_data_unc_err_cnt(const struct cntr_entry *entry,
  1935. void *context, int vl, int mode,
  1936. u64 data)
  1937. {
  1938. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1939. return dd->rcv_err_status_cnt[55];
  1940. }
  1941. static u64 access_rx_dma_data_fifo_rd_cor_err_cnt(
  1942. const struct cntr_entry *entry,
  1943. void *context, int vl, int mode, u64 data)
  1944. {
  1945. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1946. return dd->rcv_err_status_cnt[54];
  1947. }
  1948. static u64 access_rx_dma_data_fifo_rd_unc_err_cnt(
  1949. const struct cntr_entry *entry,
  1950. void *context, int vl, int mode, u64 data)
  1951. {
  1952. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1953. return dd->rcv_err_status_cnt[53];
  1954. }
  1955. static u64 access_rx_dma_hdr_fifo_rd_cor_err_cnt(const struct cntr_entry *entry,
  1956. void *context, int vl,
  1957. int mode, u64 data)
  1958. {
  1959. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1960. return dd->rcv_err_status_cnt[52];
  1961. }
  1962. static u64 access_rx_dma_hdr_fifo_rd_unc_err_cnt(const struct cntr_entry *entry,
  1963. void *context, int vl,
  1964. int mode, u64 data)
  1965. {
  1966. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1967. return dd->rcv_err_status_cnt[51];
  1968. }
  1969. static u64 access_rx_rbuf_desc_part2_cor_err_cnt(const struct cntr_entry *entry,
  1970. void *context, int vl,
  1971. int mode, u64 data)
  1972. {
  1973. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1974. return dd->rcv_err_status_cnt[50];
  1975. }
  1976. static u64 access_rx_rbuf_desc_part2_unc_err_cnt(const struct cntr_entry *entry,
  1977. void *context, int vl,
  1978. int mode, u64 data)
  1979. {
  1980. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1981. return dd->rcv_err_status_cnt[49];
  1982. }
  1983. static u64 access_rx_rbuf_desc_part1_cor_err_cnt(const struct cntr_entry *entry,
  1984. void *context, int vl,
  1985. int mode, u64 data)
  1986. {
  1987. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1988. return dd->rcv_err_status_cnt[48];
  1989. }
  1990. static u64 access_rx_rbuf_desc_part1_unc_err_cnt(const struct cntr_entry *entry,
  1991. void *context, int vl,
  1992. int mode, u64 data)
  1993. {
  1994. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1995. return dd->rcv_err_status_cnt[47];
  1996. }
  1997. static u64 access_rx_hq_intr_fsm_err_cnt(const struct cntr_entry *entry,
  1998. void *context, int vl, int mode,
  1999. u64 data)
  2000. {
  2001. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2002. return dd->rcv_err_status_cnt[46];
  2003. }
  2004. static u64 access_rx_hq_intr_csr_parity_err_cnt(
  2005. const struct cntr_entry *entry,
  2006. void *context, int vl, int mode, u64 data)
  2007. {
  2008. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2009. return dd->rcv_err_status_cnt[45];
  2010. }
  2011. static u64 access_rx_lookup_csr_parity_err_cnt(
  2012. const struct cntr_entry *entry,
  2013. void *context, int vl, int mode, u64 data)
  2014. {
  2015. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2016. return dd->rcv_err_status_cnt[44];
  2017. }
  2018. static u64 access_rx_lookup_rcv_array_cor_err_cnt(
  2019. const struct cntr_entry *entry,
  2020. void *context, int vl, int mode, u64 data)
  2021. {
  2022. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2023. return dd->rcv_err_status_cnt[43];
  2024. }
  2025. static u64 access_rx_lookup_rcv_array_unc_err_cnt(
  2026. const struct cntr_entry *entry,
  2027. void *context, int vl, int mode, u64 data)
  2028. {
  2029. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2030. return dd->rcv_err_status_cnt[42];
  2031. }
  2032. static u64 access_rx_lookup_des_part2_parity_err_cnt(
  2033. const struct cntr_entry *entry,
  2034. void *context, int vl, int mode, u64 data)
  2035. {
  2036. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2037. return dd->rcv_err_status_cnt[41];
  2038. }
  2039. static u64 access_rx_lookup_des_part1_unc_cor_err_cnt(
  2040. const struct cntr_entry *entry,
  2041. void *context, int vl, int mode, u64 data)
  2042. {
  2043. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2044. return dd->rcv_err_status_cnt[40];
  2045. }
  2046. static u64 access_rx_lookup_des_part1_unc_err_cnt(
  2047. const struct cntr_entry *entry,
  2048. void *context, int vl, int mode, u64 data)
  2049. {
  2050. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2051. return dd->rcv_err_status_cnt[39];
  2052. }
  2053. static u64 access_rx_rbuf_next_free_buf_cor_err_cnt(
  2054. const struct cntr_entry *entry,
  2055. void *context, int vl, int mode, u64 data)
  2056. {
  2057. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2058. return dd->rcv_err_status_cnt[38];
  2059. }
  2060. static u64 access_rx_rbuf_next_free_buf_unc_err_cnt(
  2061. const struct cntr_entry *entry,
  2062. void *context, int vl, int mode, u64 data)
  2063. {
  2064. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2065. return dd->rcv_err_status_cnt[37];
  2066. }
  2067. static u64 access_rbuf_fl_init_wr_addr_parity_err_cnt(
  2068. const struct cntr_entry *entry,
  2069. void *context, int vl, int mode, u64 data)
  2070. {
  2071. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2072. return dd->rcv_err_status_cnt[36];
  2073. }
  2074. static u64 access_rx_rbuf_fl_initdone_parity_err_cnt(
  2075. const struct cntr_entry *entry,
  2076. void *context, int vl, int mode, u64 data)
  2077. {
  2078. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2079. return dd->rcv_err_status_cnt[35];
  2080. }
  2081. static u64 access_rx_rbuf_fl_write_addr_parity_err_cnt(
  2082. const struct cntr_entry *entry,
  2083. void *context, int vl, int mode, u64 data)
  2084. {
  2085. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2086. return dd->rcv_err_status_cnt[34];
  2087. }
  2088. static u64 access_rx_rbuf_fl_rd_addr_parity_err_cnt(
  2089. const struct cntr_entry *entry,
  2090. void *context, int vl, int mode, u64 data)
  2091. {
  2092. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2093. return dd->rcv_err_status_cnt[33];
  2094. }
  2095. static u64 access_rx_rbuf_empty_err_cnt(const struct cntr_entry *entry,
  2096. void *context, int vl, int mode,
  2097. u64 data)
  2098. {
  2099. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2100. return dd->rcv_err_status_cnt[32];
  2101. }
  2102. static u64 access_rx_rbuf_full_err_cnt(const struct cntr_entry *entry,
  2103. void *context, int vl, int mode,
  2104. u64 data)
  2105. {
  2106. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2107. return dd->rcv_err_status_cnt[31];
  2108. }
  2109. static u64 access_rbuf_bad_lookup_err_cnt(const struct cntr_entry *entry,
  2110. void *context, int vl, int mode,
  2111. u64 data)
  2112. {
  2113. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2114. return dd->rcv_err_status_cnt[30];
  2115. }
  2116. static u64 access_rbuf_ctx_id_parity_err_cnt(const struct cntr_entry *entry,
  2117. void *context, int vl, int mode,
  2118. u64 data)
  2119. {
  2120. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2121. return dd->rcv_err_status_cnt[29];
  2122. }
  2123. static u64 access_rbuf_csr_qeopdw_parity_err_cnt(const struct cntr_entry *entry,
  2124. void *context, int vl,
  2125. int mode, u64 data)
  2126. {
  2127. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2128. return dd->rcv_err_status_cnt[28];
  2129. }
  2130. static u64 access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt(
  2131. const struct cntr_entry *entry,
  2132. void *context, int vl, int mode, u64 data)
  2133. {
  2134. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2135. return dd->rcv_err_status_cnt[27];
  2136. }
  2137. static u64 access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt(
  2138. const struct cntr_entry *entry,
  2139. void *context, int vl, int mode, u64 data)
  2140. {
  2141. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2142. return dd->rcv_err_status_cnt[26];
  2143. }
  2144. static u64 access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt(
  2145. const struct cntr_entry *entry,
  2146. void *context, int vl, int mode, u64 data)
  2147. {
  2148. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2149. return dd->rcv_err_status_cnt[25];
  2150. }
  2151. static u64 access_rx_rbuf_csr_q_vld_bit_parity_err_cnt(
  2152. const struct cntr_entry *entry,
  2153. void *context, int vl, int mode, u64 data)
  2154. {
  2155. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2156. return dd->rcv_err_status_cnt[24];
  2157. }
  2158. static u64 access_rx_rbuf_csr_q_next_buf_parity_err_cnt(
  2159. const struct cntr_entry *entry,
  2160. void *context, int vl, int mode, u64 data)
  2161. {
  2162. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2163. return dd->rcv_err_status_cnt[23];
  2164. }
  2165. static u64 access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt(
  2166. const struct cntr_entry *entry,
  2167. void *context, int vl, int mode, u64 data)
  2168. {
  2169. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2170. return dd->rcv_err_status_cnt[22];
  2171. }
  2172. static u64 access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt(
  2173. const struct cntr_entry *entry,
  2174. void *context, int vl, int mode, u64 data)
  2175. {
  2176. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2177. return dd->rcv_err_status_cnt[21];
  2178. }
  2179. static u64 access_rx_rbuf_block_list_read_cor_err_cnt(
  2180. const struct cntr_entry *entry,
  2181. void *context, int vl, int mode, u64 data)
  2182. {
  2183. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2184. return dd->rcv_err_status_cnt[20];
  2185. }
  2186. static u64 access_rx_rbuf_block_list_read_unc_err_cnt(
  2187. const struct cntr_entry *entry,
  2188. void *context, int vl, int mode, u64 data)
  2189. {
  2190. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2191. return dd->rcv_err_status_cnt[19];
  2192. }
  2193. static u64 access_rx_rbuf_lookup_des_cor_err_cnt(const struct cntr_entry *entry,
  2194. void *context, int vl,
  2195. int mode, u64 data)
  2196. {
  2197. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2198. return dd->rcv_err_status_cnt[18];
  2199. }
  2200. static u64 access_rx_rbuf_lookup_des_unc_err_cnt(const struct cntr_entry *entry,
  2201. void *context, int vl,
  2202. int mode, u64 data)
  2203. {
  2204. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2205. return dd->rcv_err_status_cnt[17];
  2206. }
  2207. static u64 access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt(
  2208. const struct cntr_entry *entry,
  2209. void *context, int vl, int mode, u64 data)
  2210. {
  2211. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2212. return dd->rcv_err_status_cnt[16];
  2213. }
  2214. static u64 access_rx_rbuf_lookup_des_reg_unc_err_cnt(
  2215. const struct cntr_entry *entry,
  2216. void *context, int vl, int mode, u64 data)
  2217. {
  2218. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2219. return dd->rcv_err_status_cnt[15];
  2220. }
  2221. static u64 access_rx_rbuf_free_list_cor_err_cnt(const struct cntr_entry *entry,
  2222. void *context, int vl,
  2223. int mode, u64 data)
  2224. {
  2225. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2226. return dd->rcv_err_status_cnt[14];
  2227. }
  2228. static u64 access_rx_rbuf_free_list_unc_err_cnt(const struct cntr_entry *entry,
  2229. void *context, int vl,
  2230. int mode, u64 data)
  2231. {
  2232. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2233. return dd->rcv_err_status_cnt[13];
  2234. }
  2235. static u64 access_rx_rcv_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  2236. void *context, int vl, int mode,
  2237. u64 data)
  2238. {
  2239. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2240. return dd->rcv_err_status_cnt[12];
  2241. }
  2242. static u64 access_rx_dma_flag_cor_err_cnt(const struct cntr_entry *entry,
  2243. void *context, int vl, int mode,
  2244. u64 data)
  2245. {
  2246. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2247. return dd->rcv_err_status_cnt[11];
  2248. }
  2249. static u64 access_rx_dma_flag_unc_err_cnt(const struct cntr_entry *entry,
  2250. void *context, int vl, int mode,
  2251. u64 data)
  2252. {
  2253. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2254. return dd->rcv_err_status_cnt[10];
  2255. }
  2256. static u64 access_rx_dc_sop_eop_parity_err_cnt(const struct cntr_entry *entry,
  2257. void *context, int vl, int mode,
  2258. u64 data)
  2259. {
  2260. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2261. return dd->rcv_err_status_cnt[9];
  2262. }
  2263. static u64 access_rx_rcv_csr_parity_err_cnt(const struct cntr_entry *entry,
  2264. void *context, int vl, int mode,
  2265. u64 data)
  2266. {
  2267. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2268. return dd->rcv_err_status_cnt[8];
  2269. }
  2270. static u64 access_rx_rcv_qp_map_table_cor_err_cnt(
  2271. const struct cntr_entry *entry,
  2272. void *context, int vl, int mode, u64 data)
  2273. {
  2274. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2275. return dd->rcv_err_status_cnt[7];
  2276. }
  2277. static u64 access_rx_rcv_qp_map_table_unc_err_cnt(
  2278. const struct cntr_entry *entry,
  2279. void *context, int vl, int mode, u64 data)
  2280. {
  2281. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2282. return dd->rcv_err_status_cnt[6];
  2283. }
  2284. static u64 access_rx_rcv_data_cor_err_cnt(const struct cntr_entry *entry,
  2285. void *context, int vl, int mode,
  2286. u64 data)
  2287. {
  2288. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2289. return dd->rcv_err_status_cnt[5];
  2290. }
  2291. static u64 access_rx_rcv_data_unc_err_cnt(const struct cntr_entry *entry,
  2292. void *context, int vl, int mode,
  2293. u64 data)
  2294. {
  2295. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2296. return dd->rcv_err_status_cnt[4];
  2297. }
  2298. static u64 access_rx_rcv_hdr_cor_err_cnt(const struct cntr_entry *entry,
  2299. void *context, int vl, int mode,
  2300. u64 data)
  2301. {
  2302. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2303. return dd->rcv_err_status_cnt[3];
  2304. }
  2305. static u64 access_rx_rcv_hdr_unc_err_cnt(const struct cntr_entry *entry,
  2306. void *context, int vl, int mode,
  2307. u64 data)
  2308. {
  2309. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2310. return dd->rcv_err_status_cnt[2];
  2311. }
  2312. static u64 access_rx_dc_intf_parity_err_cnt(const struct cntr_entry *entry,
  2313. void *context, int vl, int mode,
  2314. u64 data)
  2315. {
  2316. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2317. return dd->rcv_err_status_cnt[1];
  2318. }
  2319. static u64 access_rx_dma_csr_cor_err_cnt(const struct cntr_entry *entry,
  2320. void *context, int vl, int mode,
  2321. u64 data)
  2322. {
  2323. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2324. return dd->rcv_err_status_cnt[0];
  2325. }
  2326. /*
  2327. * Software counters corresponding to each of the
  2328. * error status bits within SendPioErrStatus
  2329. */
  2330. static u64 access_pio_pec_sop_head_parity_err_cnt(
  2331. const struct cntr_entry *entry,
  2332. void *context, int vl, int mode, u64 data)
  2333. {
  2334. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2335. return dd->send_pio_err_status_cnt[35];
  2336. }
  2337. static u64 access_pio_pcc_sop_head_parity_err_cnt(
  2338. const struct cntr_entry *entry,
  2339. void *context, int vl, int mode, u64 data)
  2340. {
  2341. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2342. return dd->send_pio_err_status_cnt[34];
  2343. }
  2344. static u64 access_pio_last_returned_cnt_parity_err_cnt(
  2345. const struct cntr_entry *entry,
  2346. void *context, int vl, int mode, u64 data)
  2347. {
  2348. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2349. return dd->send_pio_err_status_cnt[33];
  2350. }
  2351. static u64 access_pio_current_free_cnt_parity_err_cnt(
  2352. const struct cntr_entry *entry,
  2353. void *context, int vl, int mode, u64 data)
  2354. {
  2355. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2356. return dd->send_pio_err_status_cnt[32];
  2357. }
  2358. static u64 access_pio_reserved_31_err_cnt(const struct cntr_entry *entry,
  2359. void *context, int vl, int mode,
  2360. u64 data)
  2361. {
  2362. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2363. return dd->send_pio_err_status_cnt[31];
  2364. }
  2365. static u64 access_pio_reserved_30_err_cnt(const struct cntr_entry *entry,
  2366. void *context, int vl, int mode,
  2367. u64 data)
  2368. {
  2369. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2370. return dd->send_pio_err_status_cnt[30];
  2371. }
  2372. static u64 access_pio_ppmc_sop_len_err_cnt(const struct cntr_entry *entry,
  2373. void *context, int vl, int mode,
  2374. u64 data)
  2375. {
  2376. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2377. return dd->send_pio_err_status_cnt[29];
  2378. }
  2379. static u64 access_pio_ppmc_bqc_mem_parity_err_cnt(
  2380. const struct cntr_entry *entry,
  2381. void *context, int vl, int mode, u64 data)
  2382. {
  2383. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2384. return dd->send_pio_err_status_cnt[28];
  2385. }
  2386. static u64 access_pio_vl_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2387. void *context, int vl, int mode,
  2388. u64 data)
  2389. {
  2390. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2391. return dd->send_pio_err_status_cnt[27];
  2392. }
  2393. static u64 access_pio_vlf_sop_parity_err_cnt(const struct cntr_entry *entry,
  2394. void *context, int vl, int mode,
  2395. u64 data)
  2396. {
  2397. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2398. return dd->send_pio_err_status_cnt[26];
  2399. }
  2400. static u64 access_pio_vlf_v1_len_parity_err_cnt(const struct cntr_entry *entry,
  2401. void *context, int vl,
  2402. int mode, u64 data)
  2403. {
  2404. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2405. return dd->send_pio_err_status_cnt[25];
  2406. }
  2407. static u64 access_pio_block_qw_count_parity_err_cnt(
  2408. const struct cntr_entry *entry,
  2409. void *context, int vl, int mode, u64 data)
  2410. {
  2411. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2412. return dd->send_pio_err_status_cnt[24];
  2413. }
  2414. static u64 access_pio_write_qw_valid_parity_err_cnt(
  2415. const struct cntr_entry *entry,
  2416. void *context, int vl, int mode, u64 data)
  2417. {
  2418. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2419. return dd->send_pio_err_status_cnt[23];
  2420. }
  2421. static u64 access_pio_state_machine_err_cnt(const struct cntr_entry *entry,
  2422. void *context, int vl, int mode,
  2423. u64 data)
  2424. {
  2425. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2426. return dd->send_pio_err_status_cnt[22];
  2427. }
  2428. static u64 access_pio_write_data_parity_err_cnt(const struct cntr_entry *entry,
  2429. void *context, int vl,
  2430. int mode, u64 data)
  2431. {
  2432. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2433. return dd->send_pio_err_status_cnt[21];
  2434. }
  2435. static u64 access_pio_host_addr_mem_cor_err_cnt(const struct cntr_entry *entry,
  2436. void *context, int vl,
  2437. int mode, u64 data)
  2438. {
  2439. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2440. return dd->send_pio_err_status_cnt[20];
  2441. }
  2442. static u64 access_pio_host_addr_mem_unc_err_cnt(const struct cntr_entry *entry,
  2443. void *context, int vl,
  2444. int mode, u64 data)
  2445. {
  2446. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2447. return dd->send_pio_err_status_cnt[19];
  2448. }
  2449. static u64 access_pio_pkt_evict_sm_or_arb_sm_err_cnt(
  2450. const struct cntr_entry *entry,
  2451. void *context, int vl, int mode, u64 data)
  2452. {
  2453. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2454. return dd->send_pio_err_status_cnt[18];
  2455. }
  2456. static u64 access_pio_init_sm_in_err_cnt(const struct cntr_entry *entry,
  2457. void *context, int vl, int mode,
  2458. u64 data)
  2459. {
  2460. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2461. return dd->send_pio_err_status_cnt[17];
  2462. }
  2463. static u64 access_pio_ppmc_pbl_fifo_err_cnt(const struct cntr_entry *entry,
  2464. void *context, int vl, int mode,
  2465. u64 data)
  2466. {
  2467. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2468. return dd->send_pio_err_status_cnt[16];
  2469. }
  2470. static u64 access_pio_credit_ret_fifo_parity_err_cnt(
  2471. const struct cntr_entry *entry,
  2472. void *context, int vl, int mode, u64 data)
  2473. {
  2474. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2475. return dd->send_pio_err_status_cnt[15];
  2476. }
  2477. static u64 access_pio_v1_len_mem_bank1_cor_err_cnt(
  2478. const struct cntr_entry *entry,
  2479. void *context, int vl, int mode, u64 data)
  2480. {
  2481. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2482. return dd->send_pio_err_status_cnt[14];
  2483. }
  2484. static u64 access_pio_v1_len_mem_bank0_cor_err_cnt(
  2485. const struct cntr_entry *entry,
  2486. void *context, int vl, int mode, u64 data)
  2487. {
  2488. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2489. return dd->send_pio_err_status_cnt[13];
  2490. }
  2491. static u64 access_pio_v1_len_mem_bank1_unc_err_cnt(
  2492. const struct cntr_entry *entry,
  2493. void *context, int vl, int mode, u64 data)
  2494. {
  2495. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2496. return dd->send_pio_err_status_cnt[12];
  2497. }
  2498. static u64 access_pio_v1_len_mem_bank0_unc_err_cnt(
  2499. const struct cntr_entry *entry,
  2500. void *context, int vl, int mode, u64 data)
  2501. {
  2502. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2503. return dd->send_pio_err_status_cnt[11];
  2504. }
  2505. static u64 access_pio_sm_pkt_reset_parity_err_cnt(
  2506. const struct cntr_entry *entry,
  2507. void *context, int vl, int mode, u64 data)
  2508. {
  2509. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2510. return dd->send_pio_err_status_cnt[10];
  2511. }
  2512. static u64 access_pio_pkt_evict_fifo_parity_err_cnt(
  2513. const struct cntr_entry *entry,
  2514. void *context, int vl, int mode, u64 data)
  2515. {
  2516. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2517. return dd->send_pio_err_status_cnt[9];
  2518. }
  2519. static u64 access_pio_sbrdctrl_crrel_fifo_parity_err_cnt(
  2520. const struct cntr_entry *entry,
  2521. void *context, int vl, int mode, u64 data)
  2522. {
  2523. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2524. return dd->send_pio_err_status_cnt[8];
  2525. }
  2526. static u64 access_pio_sbrdctl_crrel_parity_err_cnt(
  2527. const struct cntr_entry *entry,
  2528. void *context, int vl, int mode, u64 data)
  2529. {
  2530. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2531. return dd->send_pio_err_status_cnt[7];
  2532. }
  2533. static u64 access_pio_pec_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2534. void *context, int vl, int mode,
  2535. u64 data)
  2536. {
  2537. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2538. return dd->send_pio_err_status_cnt[6];
  2539. }
  2540. static u64 access_pio_pcc_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2541. void *context, int vl, int mode,
  2542. u64 data)
  2543. {
  2544. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2545. return dd->send_pio_err_status_cnt[5];
  2546. }
  2547. static u64 access_pio_sb_mem_fifo1_err_cnt(const struct cntr_entry *entry,
  2548. void *context, int vl, int mode,
  2549. u64 data)
  2550. {
  2551. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2552. return dd->send_pio_err_status_cnt[4];
  2553. }
  2554. static u64 access_pio_sb_mem_fifo0_err_cnt(const struct cntr_entry *entry,
  2555. void *context, int vl, int mode,
  2556. u64 data)
  2557. {
  2558. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2559. return dd->send_pio_err_status_cnt[3];
  2560. }
  2561. static u64 access_pio_csr_parity_err_cnt(const struct cntr_entry *entry,
  2562. void *context, int vl, int mode,
  2563. u64 data)
  2564. {
  2565. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2566. return dd->send_pio_err_status_cnt[2];
  2567. }
  2568. static u64 access_pio_write_addr_parity_err_cnt(const struct cntr_entry *entry,
  2569. void *context, int vl,
  2570. int mode, u64 data)
  2571. {
  2572. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2573. return dd->send_pio_err_status_cnt[1];
  2574. }
  2575. static u64 access_pio_write_bad_ctxt_err_cnt(const struct cntr_entry *entry,
  2576. void *context, int vl, int mode,
  2577. u64 data)
  2578. {
  2579. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2580. return dd->send_pio_err_status_cnt[0];
  2581. }
  2582. /*
  2583. * Software counters corresponding to each of the
  2584. * error status bits within SendDmaErrStatus
  2585. */
  2586. static u64 access_sdma_pcie_req_tracking_cor_err_cnt(
  2587. const struct cntr_entry *entry,
  2588. void *context, int vl, int mode, u64 data)
  2589. {
  2590. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2591. return dd->send_dma_err_status_cnt[3];
  2592. }
  2593. static u64 access_sdma_pcie_req_tracking_unc_err_cnt(
  2594. const struct cntr_entry *entry,
  2595. void *context, int vl, int mode, u64 data)
  2596. {
  2597. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2598. return dd->send_dma_err_status_cnt[2];
  2599. }
  2600. static u64 access_sdma_csr_parity_err_cnt(const struct cntr_entry *entry,
  2601. void *context, int vl, int mode,
  2602. u64 data)
  2603. {
  2604. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2605. return dd->send_dma_err_status_cnt[1];
  2606. }
  2607. static u64 access_sdma_rpy_tag_err_cnt(const struct cntr_entry *entry,
  2608. void *context, int vl, int mode,
  2609. u64 data)
  2610. {
  2611. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2612. return dd->send_dma_err_status_cnt[0];
  2613. }
  2614. /*
  2615. * Software counters corresponding to each of the
  2616. * error status bits within SendEgressErrStatus
  2617. */
  2618. static u64 access_tx_read_pio_memory_csr_unc_err_cnt(
  2619. const struct cntr_entry *entry,
  2620. void *context, int vl, int mode, u64 data)
  2621. {
  2622. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2623. return dd->send_egress_err_status_cnt[63];
  2624. }
  2625. static u64 access_tx_read_sdma_memory_csr_err_cnt(
  2626. const struct cntr_entry *entry,
  2627. void *context, int vl, int mode, u64 data)
  2628. {
  2629. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2630. return dd->send_egress_err_status_cnt[62];
  2631. }
  2632. static u64 access_tx_egress_fifo_cor_err_cnt(const struct cntr_entry *entry,
  2633. void *context, int vl, int mode,
  2634. u64 data)
  2635. {
  2636. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2637. return dd->send_egress_err_status_cnt[61];
  2638. }
  2639. static u64 access_tx_read_pio_memory_cor_err_cnt(const struct cntr_entry *entry,
  2640. void *context, int vl,
  2641. int mode, u64 data)
  2642. {
  2643. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2644. return dd->send_egress_err_status_cnt[60];
  2645. }
  2646. static u64 access_tx_read_sdma_memory_cor_err_cnt(
  2647. const struct cntr_entry *entry,
  2648. void *context, int vl, int mode, u64 data)
  2649. {
  2650. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2651. return dd->send_egress_err_status_cnt[59];
  2652. }
  2653. static u64 access_tx_sb_hdr_cor_err_cnt(const struct cntr_entry *entry,
  2654. void *context, int vl, int mode,
  2655. u64 data)
  2656. {
  2657. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2658. return dd->send_egress_err_status_cnt[58];
  2659. }
  2660. static u64 access_tx_credit_overrun_err_cnt(const struct cntr_entry *entry,
  2661. void *context, int vl, int mode,
  2662. u64 data)
  2663. {
  2664. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2665. return dd->send_egress_err_status_cnt[57];
  2666. }
  2667. static u64 access_tx_launch_fifo8_cor_err_cnt(const struct cntr_entry *entry,
  2668. void *context, int vl, int mode,
  2669. u64 data)
  2670. {
  2671. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2672. return dd->send_egress_err_status_cnt[56];
  2673. }
  2674. static u64 access_tx_launch_fifo7_cor_err_cnt(const struct cntr_entry *entry,
  2675. void *context, int vl, int mode,
  2676. u64 data)
  2677. {
  2678. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2679. return dd->send_egress_err_status_cnt[55];
  2680. }
  2681. static u64 access_tx_launch_fifo6_cor_err_cnt(const struct cntr_entry *entry,
  2682. void *context, int vl, int mode,
  2683. u64 data)
  2684. {
  2685. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2686. return dd->send_egress_err_status_cnt[54];
  2687. }
  2688. static u64 access_tx_launch_fifo5_cor_err_cnt(const struct cntr_entry *entry,
  2689. void *context, int vl, int mode,
  2690. u64 data)
  2691. {
  2692. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2693. return dd->send_egress_err_status_cnt[53];
  2694. }
  2695. static u64 access_tx_launch_fifo4_cor_err_cnt(const struct cntr_entry *entry,
  2696. void *context, int vl, int mode,
  2697. u64 data)
  2698. {
  2699. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2700. return dd->send_egress_err_status_cnt[52];
  2701. }
  2702. static u64 access_tx_launch_fifo3_cor_err_cnt(const struct cntr_entry *entry,
  2703. void *context, int vl, int mode,
  2704. u64 data)
  2705. {
  2706. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2707. return dd->send_egress_err_status_cnt[51];
  2708. }
  2709. static u64 access_tx_launch_fifo2_cor_err_cnt(const struct cntr_entry *entry,
  2710. void *context, int vl, int mode,
  2711. u64 data)
  2712. {
  2713. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2714. return dd->send_egress_err_status_cnt[50];
  2715. }
  2716. static u64 access_tx_launch_fifo1_cor_err_cnt(const struct cntr_entry *entry,
  2717. void *context, int vl, int mode,
  2718. u64 data)
  2719. {
  2720. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2721. return dd->send_egress_err_status_cnt[49];
  2722. }
  2723. static u64 access_tx_launch_fifo0_cor_err_cnt(const struct cntr_entry *entry,
  2724. void *context, int vl, int mode,
  2725. u64 data)
  2726. {
  2727. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2728. return dd->send_egress_err_status_cnt[48];
  2729. }
  2730. static u64 access_tx_credit_return_vl_err_cnt(const struct cntr_entry *entry,
  2731. void *context, int vl, int mode,
  2732. u64 data)
  2733. {
  2734. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2735. return dd->send_egress_err_status_cnt[47];
  2736. }
  2737. static u64 access_tx_hcrc_insertion_err_cnt(const struct cntr_entry *entry,
  2738. void *context, int vl, int mode,
  2739. u64 data)
  2740. {
  2741. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2742. return dd->send_egress_err_status_cnt[46];
  2743. }
  2744. static u64 access_tx_egress_fifo_unc_err_cnt(const struct cntr_entry *entry,
  2745. void *context, int vl, int mode,
  2746. u64 data)
  2747. {
  2748. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2749. return dd->send_egress_err_status_cnt[45];
  2750. }
  2751. static u64 access_tx_read_pio_memory_unc_err_cnt(const struct cntr_entry *entry,
  2752. void *context, int vl,
  2753. int mode, u64 data)
  2754. {
  2755. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2756. return dd->send_egress_err_status_cnt[44];
  2757. }
  2758. static u64 access_tx_read_sdma_memory_unc_err_cnt(
  2759. const struct cntr_entry *entry,
  2760. void *context, int vl, int mode, u64 data)
  2761. {
  2762. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2763. return dd->send_egress_err_status_cnt[43];
  2764. }
  2765. static u64 access_tx_sb_hdr_unc_err_cnt(const struct cntr_entry *entry,
  2766. void *context, int vl, int mode,
  2767. u64 data)
  2768. {
  2769. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2770. return dd->send_egress_err_status_cnt[42];
  2771. }
  2772. static u64 access_tx_credit_return_partiy_err_cnt(
  2773. const struct cntr_entry *entry,
  2774. void *context, int vl, int mode, u64 data)
  2775. {
  2776. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2777. return dd->send_egress_err_status_cnt[41];
  2778. }
  2779. static u64 access_tx_launch_fifo8_unc_or_parity_err_cnt(
  2780. const struct cntr_entry *entry,
  2781. void *context, int vl, int mode, u64 data)
  2782. {
  2783. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2784. return dd->send_egress_err_status_cnt[40];
  2785. }
  2786. static u64 access_tx_launch_fifo7_unc_or_parity_err_cnt(
  2787. const struct cntr_entry *entry,
  2788. void *context, int vl, int mode, u64 data)
  2789. {
  2790. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2791. return dd->send_egress_err_status_cnt[39];
  2792. }
  2793. static u64 access_tx_launch_fifo6_unc_or_parity_err_cnt(
  2794. const struct cntr_entry *entry,
  2795. void *context, int vl, int mode, u64 data)
  2796. {
  2797. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2798. return dd->send_egress_err_status_cnt[38];
  2799. }
  2800. static u64 access_tx_launch_fifo5_unc_or_parity_err_cnt(
  2801. const struct cntr_entry *entry,
  2802. void *context, int vl, int mode, u64 data)
  2803. {
  2804. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2805. return dd->send_egress_err_status_cnt[37];
  2806. }
  2807. static u64 access_tx_launch_fifo4_unc_or_parity_err_cnt(
  2808. const struct cntr_entry *entry,
  2809. void *context, int vl, int mode, u64 data)
  2810. {
  2811. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2812. return dd->send_egress_err_status_cnt[36];
  2813. }
  2814. static u64 access_tx_launch_fifo3_unc_or_parity_err_cnt(
  2815. const struct cntr_entry *entry,
  2816. void *context, int vl, int mode, u64 data)
  2817. {
  2818. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2819. return dd->send_egress_err_status_cnt[35];
  2820. }
  2821. static u64 access_tx_launch_fifo2_unc_or_parity_err_cnt(
  2822. const struct cntr_entry *entry,
  2823. void *context, int vl, int mode, u64 data)
  2824. {
  2825. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2826. return dd->send_egress_err_status_cnt[34];
  2827. }
  2828. static u64 access_tx_launch_fifo1_unc_or_parity_err_cnt(
  2829. const struct cntr_entry *entry,
  2830. void *context, int vl, int mode, u64 data)
  2831. {
  2832. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2833. return dd->send_egress_err_status_cnt[33];
  2834. }
  2835. static u64 access_tx_launch_fifo0_unc_or_parity_err_cnt(
  2836. const struct cntr_entry *entry,
  2837. void *context, int vl, int mode, u64 data)
  2838. {
  2839. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2840. return dd->send_egress_err_status_cnt[32];
  2841. }
  2842. static u64 access_tx_sdma15_disallowed_packet_err_cnt(
  2843. const struct cntr_entry *entry,
  2844. void *context, int vl, int mode, u64 data)
  2845. {
  2846. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2847. return dd->send_egress_err_status_cnt[31];
  2848. }
  2849. static u64 access_tx_sdma14_disallowed_packet_err_cnt(
  2850. const struct cntr_entry *entry,
  2851. void *context, int vl, int mode, u64 data)
  2852. {
  2853. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2854. return dd->send_egress_err_status_cnt[30];
  2855. }
  2856. static u64 access_tx_sdma13_disallowed_packet_err_cnt(
  2857. const struct cntr_entry *entry,
  2858. void *context, int vl, int mode, u64 data)
  2859. {
  2860. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2861. return dd->send_egress_err_status_cnt[29];
  2862. }
  2863. static u64 access_tx_sdma12_disallowed_packet_err_cnt(
  2864. const struct cntr_entry *entry,
  2865. void *context, int vl, int mode, u64 data)
  2866. {
  2867. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2868. return dd->send_egress_err_status_cnt[28];
  2869. }
  2870. static u64 access_tx_sdma11_disallowed_packet_err_cnt(
  2871. const struct cntr_entry *entry,
  2872. void *context, int vl, int mode, u64 data)
  2873. {
  2874. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2875. return dd->send_egress_err_status_cnt[27];
  2876. }
  2877. static u64 access_tx_sdma10_disallowed_packet_err_cnt(
  2878. const struct cntr_entry *entry,
  2879. void *context, int vl, int mode, u64 data)
  2880. {
  2881. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2882. return dd->send_egress_err_status_cnt[26];
  2883. }
  2884. static u64 access_tx_sdma9_disallowed_packet_err_cnt(
  2885. const struct cntr_entry *entry,
  2886. void *context, int vl, int mode, u64 data)
  2887. {
  2888. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2889. return dd->send_egress_err_status_cnt[25];
  2890. }
  2891. static u64 access_tx_sdma8_disallowed_packet_err_cnt(
  2892. const struct cntr_entry *entry,
  2893. void *context, int vl, int mode, u64 data)
  2894. {
  2895. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2896. return dd->send_egress_err_status_cnt[24];
  2897. }
  2898. static u64 access_tx_sdma7_disallowed_packet_err_cnt(
  2899. const struct cntr_entry *entry,
  2900. void *context, int vl, int mode, u64 data)
  2901. {
  2902. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2903. return dd->send_egress_err_status_cnt[23];
  2904. }
  2905. static u64 access_tx_sdma6_disallowed_packet_err_cnt(
  2906. const struct cntr_entry *entry,
  2907. void *context, int vl, int mode, u64 data)
  2908. {
  2909. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2910. return dd->send_egress_err_status_cnt[22];
  2911. }
  2912. static u64 access_tx_sdma5_disallowed_packet_err_cnt(
  2913. const struct cntr_entry *entry,
  2914. void *context, int vl, int mode, u64 data)
  2915. {
  2916. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2917. return dd->send_egress_err_status_cnt[21];
  2918. }
  2919. static u64 access_tx_sdma4_disallowed_packet_err_cnt(
  2920. const struct cntr_entry *entry,
  2921. void *context, int vl, int mode, u64 data)
  2922. {
  2923. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2924. return dd->send_egress_err_status_cnt[20];
  2925. }
  2926. static u64 access_tx_sdma3_disallowed_packet_err_cnt(
  2927. const struct cntr_entry *entry,
  2928. void *context, int vl, int mode, u64 data)
  2929. {
  2930. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2931. return dd->send_egress_err_status_cnt[19];
  2932. }
  2933. static u64 access_tx_sdma2_disallowed_packet_err_cnt(
  2934. const struct cntr_entry *entry,
  2935. void *context, int vl, int mode, u64 data)
  2936. {
  2937. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2938. return dd->send_egress_err_status_cnt[18];
  2939. }
  2940. static u64 access_tx_sdma1_disallowed_packet_err_cnt(
  2941. const struct cntr_entry *entry,
  2942. void *context, int vl, int mode, u64 data)
  2943. {
  2944. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2945. return dd->send_egress_err_status_cnt[17];
  2946. }
  2947. static u64 access_tx_sdma0_disallowed_packet_err_cnt(
  2948. const struct cntr_entry *entry,
  2949. void *context, int vl, int mode, u64 data)
  2950. {
  2951. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2952. return dd->send_egress_err_status_cnt[16];
  2953. }
  2954. static u64 access_tx_config_parity_err_cnt(const struct cntr_entry *entry,
  2955. void *context, int vl, int mode,
  2956. u64 data)
  2957. {
  2958. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2959. return dd->send_egress_err_status_cnt[15];
  2960. }
  2961. static u64 access_tx_sbrd_ctl_csr_parity_err_cnt(const struct cntr_entry *entry,
  2962. void *context, int vl,
  2963. int mode, u64 data)
  2964. {
  2965. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2966. return dd->send_egress_err_status_cnt[14];
  2967. }
  2968. static u64 access_tx_launch_csr_parity_err_cnt(const struct cntr_entry *entry,
  2969. void *context, int vl, int mode,
  2970. u64 data)
  2971. {
  2972. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2973. return dd->send_egress_err_status_cnt[13];
  2974. }
  2975. static u64 access_tx_illegal_vl_err_cnt(const struct cntr_entry *entry,
  2976. void *context, int vl, int mode,
  2977. u64 data)
  2978. {
  2979. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2980. return dd->send_egress_err_status_cnt[12];
  2981. }
  2982. static u64 access_tx_sbrd_ctl_state_machine_parity_err_cnt(
  2983. const struct cntr_entry *entry,
  2984. void *context, int vl, int mode, u64 data)
  2985. {
  2986. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2987. return dd->send_egress_err_status_cnt[11];
  2988. }
  2989. static u64 access_egress_reserved_10_err_cnt(const struct cntr_entry *entry,
  2990. void *context, int vl, int mode,
  2991. u64 data)
  2992. {
  2993. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2994. return dd->send_egress_err_status_cnt[10];
  2995. }
  2996. static u64 access_egress_reserved_9_err_cnt(const struct cntr_entry *entry,
  2997. void *context, int vl, int mode,
  2998. u64 data)
  2999. {
  3000. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3001. return dd->send_egress_err_status_cnt[9];
  3002. }
  3003. static u64 access_tx_sdma_launch_intf_parity_err_cnt(
  3004. const struct cntr_entry *entry,
  3005. void *context, int vl, int mode, u64 data)
  3006. {
  3007. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3008. return dd->send_egress_err_status_cnt[8];
  3009. }
  3010. static u64 access_tx_pio_launch_intf_parity_err_cnt(
  3011. const struct cntr_entry *entry,
  3012. void *context, int vl, int mode, u64 data)
  3013. {
  3014. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3015. return dd->send_egress_err_status_cnt[7];
  3016. }
  3017. static u64 access_egress_reserved_6_err_cnt(const struct cntr_entry *entry,
  3018. void *context, int vl, int mode,
  3019. u64 data)
  3020. {
  3021. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3022. return dd->send_egress_err_status_cnt[6];
  3023. }
  3024. static u64 access_tx_incorrect_link_state_err_cnt(
  3025. const struct cntr_entry *entry,
  3026. void *context, int vl, int mode, u64 data)
  3027. {
  3028. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3029. return dd->send_egress_err_status_cnt[5];
  3030. }
  3031. static u64 access_tx_linkdown_err_cnt(const struct cntr_entry *entry,
  3032. void *context, int vl, int mode,
  3033. u64 data)
  3034. {
  3035. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3036. return dd->send_egress_err_status_cnt[4];
  3037. }
  3038. static u64 access_tx_egress_fifi_underrun_or_parity_err_cnt(
  3039. const struct cntr_entry *entry,
  3040. void *context, int vl, int mode, u64 data)
  3041. {
  3042. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3043. return dd->send_egress_err_status_cnt[3];
  3044. }
  3045. static u64 access_egress_reserved_2_err_cnt(const struct cntr_entry *entry,
  3046. void *context, int vl, int mode,
  3047. u64 data)
  3048. {
  3049. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3050. return dd->send_egress_err_status_cnt[2];
  3051. }
  3052. static u64 access_tx_pkt_integrity_mem_unc_err_cnt(
  3053. const struct cntr_entry *entry,
  3054. void *context, int vl, int mode, u64 data)
  3055. {
  3056. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3057. return dd->send_egress_err_status_cnt[1];
  3058. }
  3059. static u64 access_tx_pkt_integrity_mem_cor_err_cnt(
  3060. const struct cntr_entry *entry,
  3061. void *context, int vl, int mode, u64 data)
  3062. {
  3063. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3064. return dd->send_egress_err_status_cnt[0];
  3065. }
  3066. /*
  3067. * Software counters corresponding to each of the
  3068. * error status bits within SendErrStatus
  3069. */
  3070. static u64 access_send_csr_write_bad_addr_err_cnt(
  3071. const struct cntr_entry *entry,
  3072. void *context, int vl, int mode, u64 data)
  3073. {
  3074. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3075. return dd->send_err_status_cnt[2];
  3076. }
  3077. static u64 access_send_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  3078. void *context, int vl,
  3079. int mode, u64 data)
  3080. {
  3081. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3082. return dd->send_err_status_cnt[1];
  3083. }
  3084. static u64 access_send_csr_parity_cnt(const struct cntr_entry *entry,
  3085. void *context, int vl, int mode,
  3086. u64 data)
  3087. {
  3088. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3089. return dd->send_err_status_cnt[0];
  3090. }
  3091. /*
  3092. * Software counters corresponding to each of the
  3093. * error status bits within SendCtxtErrStatus
  3094. */
  3095. static u64 access_pio_write_out_of_bounds_err_cnt(
  3096. const struct cntr_entry *entry,
  3097. void *context, int vl, int mode, u64 data)
  3098. {
  3099. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3100. return dd->sw_ctxt_err_status_cnt[4];
  3101. }
  3102. static u64 access_pio_write_overflow_err_cnt(const struct cntr_entry *entry,
  3103. void *context, int vl, int mode,
  3104. u64 data)
  3105. {
  3106. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3107. return dd->sw_ctxt_err_status_cnt[3];
  3108. }
  3109. static u64 access_pio_write_crosses_boundary_err_cnt(
  3110. const struct cntr_entry *entry,
  3111. void *context, int vl, int mode, u64 data)
  3112. {
  3113. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3114. return dd->sw_ctxt_err_status_cnt[2];
  3115. }
  3116. static u64 access_pio_disallowed_packet_err_cnt(const struct cntr_entry *entry,
  3117. void *context, int vl,
  3118. int mode, u64 data)
  3119. {
  3120. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3121. return dd->sw_ctxt_err_status_cnt[1];
  3122. }
  3123. static u64 access_pio_inconsistent_sop_err_cnt(const struct cntr_entry *entry,
  3124. void *context, int vl, int mode,
  3125. u64 data)
  3126. {
  3127. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3128. return dd->sw_ctxt_err_status_cnt[0];
  3129. }
  3130. /*
  3131. * Software counters corresponding to each of the
  3132. * error status bits within SendDmaEngErrStatus
  3133. */
  3134. static u64 access_sdma_header_request_fifo_cor_err_cnt(
  3135. const struct cntr_entry *entry,
  3136. void *context, int vl, int mode, u64 data)
  3137. {
  3138. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3139. return dd->sw_send_dma_eng_err_status_cnt[23];
  3140. }
  3141. static u64 access_sdma_header_storage_cor_err_cnt(
  3142. const struct cntr_entry *entry,
  3143. void *context, int vl, int mode, u64 data)
  3144. {
  3145. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3146. return dd->sw_send_dma_eng_err_status_cnt[22];
  3147. }
  3148. static u64 access_sdma_packet_tracking_cor_err_cnt(
  3149. const struct cntr_entry *entry,
  3150. void *context, int vl, int mode, u64 data)
  3151. {
  3152. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3153. return dd->sw_send_dma_eng_err_status_cnt[21];
  3154. }
  3155. static u64 access_sdma_assembly_cor_err_cnt(const struct cntr_entry *entry,
  3156. void *context, int vl, int mode,
  3157. u64 data)
  3158. {
  3159. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3160. return dd->sw_send_dma_eng_err_status_cnt[20];
  3161. }
  3162. static u64 access_sdma_desc_table_cor_err_cnt(const struct cntr_entry *entry,
  3163. void *context, int vl, int mode,
  3164. u64 data)
  3165. {
  3166. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3167. return dd->sw_send_dma_eng_err_status_cnt[19];
  3168. }
  3169. static u64 access_sdma_header_request_fifo_unc_err_cnt(
  3170. const struct cntr_entry *entry,
  3171. void *context, int vl, int mode, u64 data)
  3172. {
  3173. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3174. return dd->sw_send_dma_eng_err_status_cnt[18];
  3175. }
  3176. static u64 access_sdma_header_storage_unc_err_cnt(
  3177. const struct cntr_entry *entry,
  3178. void *context, int vl, int mode, u64 data)
  3179. {
  3180. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3181. return dd->sw_send_dma_eng_err_status_cnt[17];
  3182. }
  3183. static u64 access_sdma_packet_tracking_unc_err_cnt(
  3184. const struct cntr_entry *entry,
  3185. void *context, int vl, int mode, u64 data)
  3186. {
  3187. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3188. return dd->sw_send_dma_eng_err_status_cnt[16];
  3189. }
  3190. static u64 access_sdma_assembly_unc_err_cnt(const struct cntr_entry *entry,
  3191. void *context, int vl, int mode,
  3192. u64 data)
  3193. {
  3194. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3195. return dd->sw_send_dma_eng_err_status_cnt[15];
  3196. }
  3197. static u64 access_sdma_desc_table_unc_err_cnt(const struct cntr_entry *entry,
  3198. void *context, int vl, int mode,
  3199. u64 data)
  3200. {
  3201. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3202. return dd->sw_send_dma_eng_err_status_cnt[14];
  3203. }
  3204. static u64 access_sdma_timeout_err_cnt(const struct cntr_entry *entry,
  3205. void *context, int vl, int mode,
  3206. u64 data)
  3207. {
  3208. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3209. return dd->sw_send_dma_eng_err_status_cnt[13];
  3210. }
  3211. static u64 access_sdma_header_length_err_cnt(const struct cntr_entry *entry,
  3212. void *context, int vl, int mode,
  3213. u64 data)
  3214. {
  3215. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3216. return dd->sw_send_dma_eng_err_status_cnt[12];
  3217. }
  3218. static u64 access_sdma_header_address_err_cnt(const struct cntr_entry *entry,
  3219. void *context, int vl, int mode,
  3220. u64 data)
  3221. {
  3222. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3223. return dd->sw_send_dma_eng_err_status_cnt[11];
  3224. }
  3225. static u64 access_sdma_header_select_err_cnt(const struct cntr_entry *entry,
  3226. void *context, int vl, int mode,
  3227. u64 data)
  3228. {
  3229. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3230. return dd->sw_send_dma_eng_err_status_cnt[10];
  3231. }
  3232. static u64 access_sdma_reserved_9_err_cnt(const struct cntr_entry *entry,
  3233. void *context, int vl, int mode,
  3234. u64 data)
  3235. {
  3236. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3237. return dd->sw_send_dma_eng_err_status_cnt[9];
  3238. }
  3239. static u64 access_sdma_packet_desc_overflow_err_cnt(
  3240. const struct cntr_entry *entry,
  3241. void *context, int vl, int mode, u64 data)
  3242. {
  3243. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3244. return dd->sw_send_dma_eng_err_status_cnt[8];
  3245. }
  3246. static u64 access_sdma_length_mismatch_err_cnt(const struct cntr_entry *entry,
  3247. void *context, int vl,
  3248. int mode, u64 data)
  3249. {
  3250. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3251. return dd->sw_send_dma_eng_err_status_cnt[7];
  3252. }
  3253. static u64 access_sdma_halt_err_cnt(const struct cntr_entry *entry,
  3254. void *context, int vl, int mode, u64 data)
  3255. {
  3256. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3257. return dd->sw_send_dma_eng_err_status_cnt[6];
  3258. }
  3259. static u64 access_sdma_mem_read_err_cnt(const struct cntr_entry *entry,
  3260. void *context, int vl, int mode,
  3261. u64 data)
  3262. {
  3263. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3264. return dd->sw_send_dma_eng_err_status_cnt[5];
  3265. }
  3266. static u64 access_sdma_first_desc_err_cnt(const struct cntr_entry *entry,
  3267. void *context, int vl, int mode,
  3268. u64 data)
  3269. {
  3270. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3271. return dd->sw_send_dma_eng_err_status_cnt[4];
  3272. }
  3273. static u64 access_sdma_tail_out_of_bounds_err_cnt(
  3274. const struct cntr_entry *entry,
  3275. void *context, int vl, int mode, u64 data)
  3276. {
  3277. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3278. return dd->sw_send_dma_eng_err_status_cnt[3];
  3279. }
  3280. static u64 access_sdma_too_long_err_cnt(const struct cntr_entry *entry,
  3281. void *context, int vl, int mode,
  3282. u64 data)
  3283. {
  3284. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3285. return dd->sw_send_dma_eng_err_status_cnt[2];
  3286. }
  3287. static u64 access_sdma_gen_mismatch_err_cnt(const struct cntr_entry *entry,
  3288. void *context, int vl, int mode,
  3289. u64 data)
  3290. {
  3291. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3292. return dd->sw_send_dma_eng_err_status_cnt[1];
  3293. }
  3294. static u64 access_sdma_wrong_dw_err_cnt(const struct cntr_entry *entry,
  3295. void *context, int vl, int mode,
  3296. u64 data)
  3297. {
  3298. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3299. return dd->sw_send_dma_eng_err_status_cnt[0];
  3300. }
  3301. static u64 access_dc_rcv_err_cnt(const struct cntr_entry *entry,
  3302. void *context, int vl, int mode,
  3303. u64 data)
  3304. {
  3305. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3306. u64 val = 0;
  3307. u64 csr = entry->csr;
  3308. val = read_write_csr(dd, csr, mode, data);
  3309. if (mode == CNTR_MODE_R) {
  3310. val = val > CNTR_MAX - dd->sw_rcv_bypass_packet_errors ?
  3311. CNTR_MAX : val + dd->sw_rcv_bypass_packet_errors;
  3312. } else if (mode == CNTR_MODE_W) {
  3313. dd->sw_rcv_bypass_packet_errors = 0;
  3314. } else {
  3315. dd_dev_err(dd, "Invalid cntr register access mode");
  3316. return 0;
  3317. }
  3318. return val;
  3319. }
  3320. #define def_access_sw_cpu(cntr) \
  3321. static u64 access_sw_cpu_##cntr(const struct cntr_entry *entry, \
  3322. void *context, int vl, int mode, u64 data) \
  3323. { \
  3324. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
  3325. return read_write_cpu(ppd->dd, &ppd->ibport_data.rvp.z_ ##cntr, \
  3326. ppd->ibport_data.rvp.cntr, vl, \
  3327. mode, data); \
  3328. }
  3329. def_access_sw_cpu(rc_acks);
  3330. def_access_sw_cpu(rc_qacks);
  3331. def_access_sw_cpu(rc_delayed_comp);
  3332. #define def_access_ibp_counter(cntr) \
  3333. static u64 access_ibp_##cntr(const struct cntr_entry *entry, \
  3334. void *context, int vl, int mode, u64 data) \
  3335. { \
  3336. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
  3337. \
  3338. if (vl != CNTR_INVALID_VL) \
  3339. return 0; \
  3340. \
  3341. return read_write_sw(ppd->dd, &ppd->ibport_data.rvp.n_ ##cntr, \
  3342. mode, data); \
  3343. }
  3344. def_access_ibp_counter(loop_pkts);
  3345. def_access_ibp_counter(rc_resends);
  3346. def_access_ibp_counter(rnr_naks);
  3347. def_access_ibp_counter(other_naks);
  3348. def_access_ibp_counter(rc_timeouts);
  3349. def_access_ibp_counter(pkt_drops);
  3350. def_access_ibp_counter(dmawait);
  3351. def_access_ibp_counter(rc_seqnak);
  3352. def_access_ibp_counter(rc_dupreq);
  3353. def_access_ibp_counter(rdma_seq);
  3354. def_access_ibp_counter(unaligned);
  3355. def_access_ibp_counter(seq_naks);
  3356. static struct cntr_entry dev_cntrs[DEV_CNTR_LAST] = {
  3357. [C_RCV_OVF] = RXE32_DEV_CNTR_ELEM(RcvOverflow, RCV_BUF_OVFL_CNT, CNTR_SYNTH),
  3358. [C_RX_TID_FULL] = RXE32_DEV_CNTR_ELEM(RxTIDFullEr, RCV_TID_FULL_ERR_CNT,
  3359. CNTR_NORMAL),
  3360. [C_RX_TID_INVALID] = RXE32_DEV_CNTR_ELEM(RxTIDInvalid, RCV_TID_VALID_ERR_CNT,
  3361. CNTR_NORMAL),
  3362. [C_RX_TID_FLGMS] = RXE32_DEV_CNTR_ELEM(RxTidFLGMs,
  3363. RCV_TID_FLOW_GEN_MISMATCH_CNT,
  3364. CNTR_NORMAL),
  3365. [C_RX_CTX_EGRS] = RXE32_DEV_CNTR_ELEM(RxCtxEgrS, RCV_CONTEXT_EGR_STALL,
  3366. CNTR_NORMAL),
  3367. [C_RCV_TID_FLSMS] = RXE32_DEV_CNTR_ELEM(RxTidFLSMs,
  3368. RCV_TID_FLOW_SEQ_MISMATCH_CNT, CNTR_NORMAL),
  3369. [C_CCE_PCI_CR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciCrSt,
  3370. CCE_PCIE_POSTED_CRDT_STALL_CNT, CNTR_NORMAL),
  3371. [C_CCE_PCI_TR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciTrSt, CCE_PCIE_TRGT_STALL_CNT,
  3372. CNTR_NORMAL),
  3373. [C_CCE_PIO_WR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePioWrSt, CCE_PIO_WR_STALL_CNT,
  3374. CNTR_NORMAL),
  3375. [C_CCE_ERR_INT] = CCE_INT_DEV_CNTR_ELEM(CceErrInt, CCE_ERR_INT_CNT,
  3376. CNTR_NORMAL),
  3377. [C_CCE_SDMA_INT] = CCE_INT_DEV_CNTR_ELEM(CceSdmaInt, CCE_SDMA_INT_CNT,
  3378. CNTR_NORMAL),
  3379. [C_CCE_MISC_INT] = CCE_INT_DEV_CNTR_ELEM(CceMiscInt, CCE_MISC_INT_CNT,
  3380. CNTR_NORMAL),
  3381. [C_CCE_RCV_AV_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvAvInt, CCE_RCV_AVAIL_INT_CNT,
  3382. CNTR_NORMAL),
  3383. [C_CCE_RCV_URG_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvUrgInt,
  3384. CCE_RCV_URGENT_INT_CNT, CNTR_NORMAL),
  3385. [C_CCE_SEND_CR_INT] = CCE_INT_DEV_CNTR_ELEM(CceSndCrInt,
  3386. CCE_SEND_CREDIT_INT_CNT, CNTR_NORMAL),
  3387. [C_DC_UNC_ERR] = DC_PERF_CNTR(DcUnctblErr, DCC_ERR_UNCORRECTABLE_CNT,
  3388. CNTR_SYNTH),
  3389. [C_DC_RCV_ERR] = CNTR_ELEM("DcRecvErr", DCC_ERR_PORTRCV_ERR_CNT, 0, CNTR_SYNTH,
  3390. access_dc_rcv_err_cnt),
  3391. [C_DC_FM_CFG_ERR] = DC_PERF_CNTR(DcFmCfgErr, DCC_ERR_FMCONFIG_ERR_CNT,
  3392. CNTR_SYNTH),
  3393. [C_DC_RMT_PHY_ERR] = DC_PERF_CNTR(DcRmtPhyErr, DCC_ERR_RCVREMOTE_PHY_ERR_CNT,
  3394. CNTR_SYNTH),
  3395. [C_DC_DROPPED_PKT] = DC_PERF_CNTR(DcDroppedPkt, DCC_ERR_DROPPED_PKT_CNT,
  3396. CNTR_SYNTH),
  3397. [C_DC_MC_XMIT_PKTS] = DC_PERF_CNTR(DcMcXmitPkts,
  3398. DCC_PRF_PORT_XMIT_MULTICAST_CNT, CNTR_SYNTH),
  3399. [C_DC_MC_RCV_PKTS] = DC_PERF_CNTR(DcMcRcvPkts,
  3400. DCC_PRF_PORT_RCV_MULTICAST_PKT_CNT,
  3401. CNTR_SYNTH),
  3402. [C_DC_XMIT_CERR] = DC_PERF_CNTR(DcXmitCorr,
  3403. DCC_PRF_PORT_XMIT_CORRECTABLE_CNT, CNTR_SYNTH),
  3404. [C_DC_RCV_CERR] = DC_PERF_CNTR(DcRcvCorrCnt, DCC_PRF_PORT_RCV_CORRECTABLE_CNT,
  3405. CNTR_SYNTH),
  3406. [C_DC_RCV_FCC] = DC_PERF_CNTR(DcRxFCntl, DCC_PRF_RX_FLOW_CRTL_CNT,
  3407. CNTR_SYNTH),
  3408. [C_DC_XMIT_FCC] = DC_PERF_CNTR(DcXmitFCntl, DCC_PRF_TX_FLOW_CRTL_CNT,
  3409. CNTR_SYNTH),
  3410. [C_DC_XMIT_FLITS] = DC_PERF_CNTR(DcXmitFlits, DCC_PRF_PORT_XMIT_DATA_CNT,
  3411. CNTR_SYNTH),
  3412. [C_DC_RCV_FLITS] = DC_PERF_CNTR(DcRcvFlits, DCC_PRF_PORT_RCV_DATA_CNT,
  3413. CNTR_SYNTH),
  3414. [C_DC_XMIT_PKTS] = DC_PERF_CNTR(DcXmitPkts, DCC_PRF_PORT_XMIT_PKTS_CNT,
  3415. CNTR_SYNTH),
  3416. [C_DC_RCV_PKTS] = DC_PERF_CNTR(DcRcvPkts, DCC_PRF_PORT_RCV_PKTS_CNT,
  3417. CNTR_SYNTH),
  3418. [C_DC_RX_FLIT_VL] = DC_PERF_CNTR(DcRxFlitVl, DCC_PRF_PORT_VL_RCV_DATA_CNT,
  3419. CNTR_SYNTH | CNTR_VL),
  3420. [C_DC_RX_PKT_VL] = DC_PERF_CNTR(DcRxPktVl, DCC_PRF_PORT_VL_RCV_PKTS_CNT,
  3421. CNTR_SYNTH | CNTR_VL),
  3422. [C_DC_RCV_FCN] = DC_PERF_CNTR(DcRcvFcn, DCC_PRF_PORT_RCV_FECN_CNT, CNTR_SYNTH),
  3423. [C_DC_RCV_FCN_VL] = DC_PERF_CNTR(DcRcvFcnVl, DCC_PRF_PORT_VL_RCV_FECN_CNT,
  3424. CNTR_SYNTH | CNTR_VL),
  3425. [C_DC_RCV_BCN] = DC_PERF_CNTR(DcRcvBcn, DCC_PRF_PORT_RCV_BECN_CNT, CNTR_SYNTH),
  3426. [C_DC_RCV_BCN_VL] = DC_PERF_CNTR(DcRcvBcnVl, DCC_PRF_PORT_VL_RCV_BECN_CNT,
  3427. CNTR_SYNTH | CNTR_VL),
  3428. [C_DC_RCV_BBL] = DC_PERF_CNTR(DcRcvBbl, DCC_PRF_PORT_RCV_BUBBLE_CNT,
  3429. CNTR_SYNTH),
  3430. [C_DC_RCV_BBL_VL] = DC_PERF_CNTR(DcRcvBblVl, DCC_PRF_PORT_VL_RCV_BUBBLE_CNT,
  3431. CNTR_SYNTH | CNTR_VL),
  3432. [C_DC_MARK_FECN] = DC_PERF_CNTR(DcMarkFcn, DCC_PRF_PORT_MARK_FECN_CNT,
  3433. CNTR_SYNTH),
  3434. [C_DC_MARK_FECN_VL] = DC_PERF_CNTR(DcMarkFcnVl, DCC_PRF_PORT_VL_MARK_FECN_CNT,
  3435. CNTR_SYNTH | CNTR_VL),
  3436. [C_DC_TOTAL_CRC] =
  3437. DC_PERF_CNTR_LCB(DcTotCrc, DC_LCB_ERR_INFO_TOTAL_CRC_ERR,
  3438. CNTR_SYNTH),
  3439. [C_DC_CRC_LN0] = DC_PERF_CNTR_LCB(DcCrcLn0, DC_LCB_ERR_INFO_CRC_ERR_LN0,
  3440. CNTR_SYNTH),
  3441. [C_DC_CRC_LN1] = DC_PERF_CNTR_LCB(DcCrcLn1, DC_LCB_ERR_INFO_CRC_ERR_LN1,
  3442. CNTR_SYNTH),
  3443. [C_DC_CRC_LN2] = DC_PERF_CNTR_LCB(DcCrcLn2, DC_LCB_ERR_INFO_CRC_ERR_LN2,
  3444. CNTR_SYNTH),
  3445. [C_DC_CRC_LN3] = DC_PERF_CNTR_LCB(DcCrcLn3, DC_LCB_ERR_INFO_CRC_ERR_LN3,
  3446. CNTR_SYNTH),
  3447. [C_DC_CRC_MULT_LN] =
  3448. DC_PERF_CNTR_LCB(DcMultLn, DC_LCB_ERR_INFO_CRC_ERR_MULTI_LN,
  3449. CNTR_SYNTH),
  3450. [C_DC_TX_REPLAY] = DC_PERF_CNTR_LCB(DcTxReplay, DC_LCB_ERR_INFO_TX_REPLAY_CNT,
  3451. CNTR_SYNTH),
  3452. [C_DC_RX_REPLAY] = DC_PERF_CNTR_LCB(DcRxReplay, DC_LCB_ERR_INFO_RX_REPLAY_CNT,
  3453. CNTR_SYNTH),
  3454. [C_DC_SEQ_CRC_CNT] =
  3455. DC_PERF_CNTR_LCB(DcLinkSeqCrc, DC_LCB_ERR_INFO_SEQ_CRC_CNT,
  3456. CNTR_SYNTH),
  3457. [C_DC_ESC0_ONLY_CNT] =
  3458. DC_PERF_CNTR_LCB(DcEsc0, DC_LCB_ERR_INFO_ESCAPE_0_ONLY_CNT,
  3459. CNTR_SYNTH),
  3460. [C_DC_ESC0_PLUS1_CNT] =
  3461. DC_PERF_CNTR_LCB(DcEsc1, DC_LCB_ERR_INFO_ESCAPE_0_PLUS1_CNT,
  3462. CNTR_SYNTH),
  3463. [C_DC_ESC0_PLUS2_CNT] =
  3464. DC_PERF_CNTR_LCB(DcEsc0Plus2, DC_LCB_ERR_INFO_ESCAPE_0_PLUS2_CNT,
  3465. CNTR_SYNTH),
  3466. [C_DC_REINIT_FROM_PEER_CNT] =
  3467. DC_PERF_CNTR_LCB(DcReinitPeer, DC_LCB_ERR_INFO_REINIT_FROM_PEER_CNT,
  3468. CNTR_SYNTH),
  3469. [C_DC_SBE_CNT] = DC_PERF_CNTR_LCB(DcSbe, DC_LCB_ERR_INFO_SBE_CNT,
  3470. CNTR_SYNTH),
  3471. [C_DC_MISC_FLG_CNT] =
  3472. DC_PERF_CNTR_LCB(DcMiscFlg, DC_LCB_ERR_INFO_MISC_FLG_CNT,
  3473. CNTR_SYNTH),
  3474. [C_DC_PRF_GOOD_LTP_CNT] =
  3475. DC_PERF_CNTR_LCB(DcGoodLTP, DC_LCB_PRF_GOOD_LTP_CNT, CNTR_SYNTH),
  3476. [C_DC_PRF_ACCEPTED_LTP_CNT] =
  3477. DC_PERF_CNTR_LCB(DcAccLTP, DC_LCB_PRF_ACCEPTED_LTP_CNT,
  3478. CNTR_SYNTH),
  3479. [C_DC_PRF_RX_FLIT_CNT] =
  3480. DC_PERF_CNTR_LCB(DcPrfRxFlit, DC_LCB_PRF_RX_FLIT_CNT, CNTR_SYNTH),
  3481. [C_DC_PRF_TX_FLIT_CNT] =
  3482. DC_PERF_CNTR_LCB(DcPrfTxFlit, DC_LCB_PRF_TX_FLIT_CNT, CNTR_SYNTH),
  3483. [C_DC_PRF_CLK_CNTR] =
  3484. DC_PERF_CNTR_LCB(DcPrfClk, DC_LCB_PRF_CLK_CNTR, CNTR_SYNTH),
  3485. [C_DC_PG_DBG_FLIT_CRDTS_CNT] =
  3486. DC_PERF_CNTR_LCB(DcFltCrdts, DC_LCB_PG_DBG_FLIT_CRDTS_CNT, CNTR_SYNTH),
  3487. [C_DC_PG_STS_PAUSE_COMPLETE_CNT] =
  3488. DC_PERF_CNTR_LCB(DcPauseComp, DC_LCB_PG_STS_PAUSE_COMPLETE_CNT,
  3489. CNTR_SYNTH),
  3490. [C_DC_PG_STS_TX_SBE_CNT] =
  3491. DC_PERF_CNTR_LCB(DcStsTxSbe, DC_LCB_PG_STS_TX_SBE_CNT, CNTR_SYNTH),
  3492. [C_DC_PG_STS_TX_MBE_CNT] =
  3493. DC_PERF_CNTR_LCB(DcStsTxMbe, DC_LCB_PG_STS_TX_MBE_CNT,
  3494. CNTR_SYNTH),
  3495. [C_SW_CPU_INTR] = CNTR_ELEM("Intr", 0, 0, CNTR_NORMAL,
  3496. access_sw_cpu_intr),
  3497. [C_SW_CPU_RCV_LIM] = CNTR_ELEM("RcvLimit", 0, 0, CNTR_NORMAL,
  3498. access_sw_cpu_rcv_limit),
  3499. [C_SW_VTX_WAIT] = CNTR_ELEM("vTxWait", 0, 0, CNTR_NORMAL,
  3500. access_sw_vtx_wait),
  3501. [C_SW_PIO_WAIT] = CNTR_ELEM("PioWait", 0, 0, CNTR_NORMAL,
  3502. access_sw_pio_wait),
  3503. [C_SW_PIO_DRAIN] = CNTR_ELEM("PioDrain", 0, 0, CNTR_NORMAL,
  3504. access_sw_pio_drain),
  3505. [C_SW_KMEM_WAIT] = CNTR_ELEM("KmemWait", 0, 0, CNTR_NORMAL,
  3506. access_sw_kmem_wait),
  3507. [C_SW_SEND_SCHED] = CNTR_ELEM("SendSched", 0, 0, CNTR_NORMAL,
  3508. access_sw_send_schedule),
  3509. [C_SDMA_DESC_FETCHED_CNT] = CNTR_ELEM("SDEDscFdCn",
  3510. SEND_DMA_DESC_FETCHED_CNT, 0,
  3511. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3512. dev_access_u32_csr),
  3513. [C_SDMA_INT_CNT] = CNTR_ELEM("SDMAInt", 0, 0,
  3514. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3515. access_sde_int_cnt),
  3516. [C_SDMA_ERR_CNT] = CNTR_ELEM("SDMAErrCt", 0, 0,
  3517. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3518. access_sde_err_cnt),
  3519. [C_SDMA_IDLE_INT_CNT] = CNTR_ELEM("SDMAIdInt", 0, 0,
  3520. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3521. access_sde_idle_int_cnt),
  3522. [C_SDMA_PROGRESS_INT_CNT] = CNTR_ELEM("SDMAPrIntCn", 0, 0,
  3523. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3524. access_sde_progress_int_cnt),
  3525. /* MISC_ERR_STATUS */
  3526. [C_MISC_PLL_LOCK_FAIL_ERR] = CNTR_ELEM("MISC_PLL_LOCK_FAIL_ERR", 0, 0,
  3527. CNTR_NORMAL,
  3528. access_misc_pll_lock_fail_err_cnt),
  3529. [C_MISC_MBIST_FAIL_ERR] = CNTR_ELEM("MISC_MBIST_FAIL_ERR", 0, 0,
  3530. CNTR_NORMAL,
  3531. access_misc_mbist_fail_err_cnt),
  3532. [C_MISC_INVALID_EEP_CMD_ERR] = CNTR_ELEM("MISC_INVALID_EEP_CMD_ERR", 0, 0,
  3533. CNTR_NORMAL,
  3534. access_misc_invalid_eep_cmd_err_cnt),
  3535. [C_MISC_EFUSE_DONE_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_DONE_PARITY_ERR", 0, 0,
  3536. CNTR_NORMAL,
  3537. access_misc_efuse_done_parity_err_cnt),
  3538. [C_MISC_EFUSE_WRITE_ERR] = CNTR_ELEM("MISC_EFUSE_WRITE_ERR", 0, 0,
  3539. CNTR_NORMAL,
  3540. access_misc_efuse_write_err_cnt),
  3541. [C_MISC_EFUSE_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_EFUSE_READ_BAD_ADDR_ERR", 0,
  3542. 0, CNTR_NORMAL,
  3543. access_misc_efuse_read_bad_addr_err_cnt),
  3544. [C_MISC_EFUSE_CSR_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_CSR_PARITY_ERR", 0, 0,
  3545. CNTR_NORMAL,
  3546. access_misc_efuse_csr_parity_err_cnt),
  3547. [C_MISC_FW_AUTH_FAILED_ERR] = CNTR_ELEM("MISC_FW_AUTH_FAILED_ERR", 0, 0,
  3548. CNTR_NORMAL,
  3549. access_misc_fw_auth_failed_err_cnt),
  3550. [C_MISC_KEY_MISMATCH_ERR] = CNTR_ELEM("MISC_KEY_MISMATCH_ERR", 0, 0,
  3551. CNTR_NORMAL,
  3552. access_misc_key_mismatch_err_cnt),
  3553. [C_MISC_SBUS_WRITE_FAILED_ERR] = CNTR_ELEM("MISC_SBUS_WRITE_FAILED_ERR", 0, 0,
  3554. CNTR_NORMAL,
  3555. access_misc_sbus_write_failed_err_cnt),
  3556. [C_MISC_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_WRITE_BAD_ADDR_ERR", 0, 0,
  3557. CNTR_NORMAL,
  3558. access_misc_csr_write_bad_addr_err_cnt),
  3559. [C_MISC_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_READ_BAD_ADDR_ERR", 0, 0,
  3560. CNTR_NORMAL,
  3561. access_misc_csr_read_bad_addr_err_cnt),
  3562. [C_MISC_CSR_PARITY_ERR] = CNTR_ELEM("MISC_CSR_PARITY_ERR", 0, 0,
  3563. CNTR_NORMAL,
  3564. access_misc_csr_parity_err_cnt),
  3565. /* CceErrStatus */
  3566. [C_CCE_ERR_STATUS_AGGREGATED_CNT] = CNTR_ELEM("CceErrStatusAggregatedCnt", 0, 0,
  3567. CNTR_NORMAL,
  3568. access_sw_cce_err_status_aggregated_cnt),
  3569. [C_CCE_MSIX_CSR_PARITY_ERR] = CNTR_ELEM("CceMsixCsrParityErr", 0, 0,
  3570. CNTR_NORMAL,
  3571. access_cce_msix_csr_parity_err_cnt),
  3572. [C_CCE_INT_MAP_UNC_ERR] = CNTR_ELEM("CceIntMapUncErr", 0, 0,
  3573. CNTR_NORMAL,
  3574. access_cce_int_map_unc_err_cnt),
  3575. [C_CCE_INT_MAP_COR_ERR] = CNTR_ELEM("CceIntMapCorErr", 0, 0,
  3576. CNTR_NORMAL,
  3577. access_cce_int_map_cor_err_cnt),
  3578. [C_CCE_MSIX_TABLE_UNC_ERR] = CNTR_ELEM("CceMsixTableUncErr", 0, 0,
  3579. CNTR_NORMAL,
  3580. access_cce_msix_table_unc_err_cnt),
  3581. [C_CCE_MSIX_TABLE_COR_ERR] = CNTR_ELEM("CceMsixTableCorErr", 0, 0,
  3582. CNTR_NORMAL,
  3583. access_cce_msix_table_cor_err_cnt),
  3584. [C_CCE_RXDMA_CONV_FIFO_PARITY_ERR] = CNTR_ELEM("CceRxdmaConvFifoParityErr", 0,
  3585. 0, CNTR_NORMAL,
  3586. access_cce_rxdma_conv_fifo_parity_err_cnt),
  3587. [C_CCE_RCPL_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceRcplAsyncFifoParityErr", 0,
  3588. 0, CNTR_NORMAL,
  3589. access_cce_rcpl_async_fifo_parity_err_cnt),
  3590. [C_CCE_SEG_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceSegWriteBadAddrErr", 0, 0,
  3591. CNTR_NORMAL,
  3592. access_cce_seg_write_bad_addr_err_cnt),
  3593. [C_CCE_SEG_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceSegReadBadAddrErr", 0, 0,
  3594. CNTR_NORMAL,
  3595. access_cce_seg_read_bad_addr_err_cnt),
  3596. [C_LA_TRIGGERED] = CNTR_ELEM("Cce LATriggered", 0, 0,
  3597. CNTR_NORMAL,
  3598. access_la_triggered_cnt),
  3599. [C_CCE_TRGT_CPL_TIMEOUT_ERR] = CNTR_ELEM("CceTrgtCplTimeoutErr", 0, 0,
  3600. CNTR_NORMAL,
  3601. access_cce_trgt_cpl_timeout_err_cnt),
  3602. [C_PCIC_RECEIVE_PARITY_ERR] = CNTR_ELEM("PcicReceiveParityErr", 0, 0,
  3603. CNTR_NORMAL,
  3604. access_pcic_receive_parity_err_cnt),
  3605. [C_PCIC_TRANSMIT_BACK_PARITY_ERR] = CNTR_ELEM("PcicTransmitBackParityErr", 0, 0,
  3606. CNTR_NORMAL,
  3607. access_pcic_transmit_back_parity_err_cnt),
  3608. [C_PCIC_TRANSMIT_FRONT_PARITY_ERR] = CNTR_ELEM("PcicTransmitFrontParityErr", 0,
  3609. 0, CNTR_NORMAL,
  3610. access_pcic_transmit_front_parity_err_cnt),
  3611. [C_PCIC_CPL_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicCplDatQUncErr", 0, 0,
  3612. CNTR_NORMAL,
  3613. access_pcic_cpl_dat_q_unc_err_cnt),
  3614. [C_PCIC_CPL_HD_Q_UNC_ERR] = CNTR_ELEM("PcicCplHdQUncErr", 0, 0,
  3615. CNTR_NORMAL,
  3616. access_pcic_cpl_hd_q_unc_err_cnt),
  3617. [C_PCIC_POST_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicPostDatQUncErr", 0, 0,
  3618. CNTR_NORMAL,
  3619. access_pcic_post_dat_q_unc_err_cnt),
  3620. [C_PCIC_POST_HD_Q_UNC_ERR] = CNTR_ELEM("PcicPostHdQUncErr", 0, 0,
  3621. CNTR_NORMAL,
  3622. access_pcic_post_hd_q_unc_err_cnt),
  3623. [C_PCIC_RETRY_SOT_MEM_UNC_ERR] = CNTR_ELEM("PcicRetrySotMemUncErr", 0, 0,
  3624. CNTR_NORMAL,
  3625. access_pcic_retry_sot_mem_unc_err_cnt),
  3626. [C_PCIC_RETRY_MEM_UNC_ERR] = CNTR_ELEM("PcicRetryMemUncErr", 0, 0,
  3627. CNTR_NORMAL,
  3628. access_pcic_retry_mem_unc_err),
  3629. [C_PCIC_N_POST_DAT_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostDatQParityErr", 0, 0,
  3630. CNTR_NORMAL,
  3631. access_pcic_n_post_dat_q_parity_err_cnt),
  3632. [C_PCIC_N_POST_H_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostHQParityErr", 0, 0,
  3633. CNTR_NORMAL,
  3634. access_pcic_n_post_h_q_parity_err_cnt),
  3635. [C_PCIC_CPL_DAT_Q_COR_ERR] = CNTR_ELEM("PcicCplDatQCorErr", 0, 0,
  3636. CNTR_NORMAL,
  3637. access_pcic_cpl_dat_q_cor_err_cnt),
  3638. [C_PCIC_CPL_HD_Q_COR_ERR] = CNTR_ELEM("PcicCplHdQCorErr", 0, 0,
  3639. CNTR_NORMAL,
  3640. access_pcic_cpl_hd_q_cor_err_cnt),
  3641. [C_PCIC_POST_DAT_Q_COR_ERR] = CNTR_ELEM("PcicPostDatQCorErr", 0, 0,
  3642. CNTR_NORMAL,
  3643. access_pcic_post_dat_q_cor_err_cnt),
  3644. [C_PCIC_POST_HD_Q_COR_ERR] = CNTR_ELEM("PcicPostHdQCorErr", 0, 0,
  3645. CNTR_NORMAL,
  3646. access_pcic_post_hd_q_cor_err_cnt),
  3647. [C_PCIC_RETRY_SOT_MEM_COR_ERR] = CNTR_ELEM("PcicRetrySotMemCorErr", 0, 0,
  3648. CNTR_NORMAL,
  3649. access_pcic_retry_sot_mem_cor_err_cnt),
  3650. [C_PCIC_RETRY_MEM_COR_ERR] = CNTR_ELEM("PcicRetryMemCorErr", 0, 0,
  3651. CNTR_NORMAL,
  3652. access_pcic_retry_mem_cor_err_cnt),
  3653. [C_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERR] = CNTR_ELEM(
  3654. "CceCli1AsyncFifoDbgParityError", 0, 0,
  3655. CNTR_NORMAL,
  3656. access_cce_cli1_async_fifo_dbg_parity_err_cnt),
  3657. [C_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERR] = CNTR_ELEM(
  3658. "CceCli1AsyncFifoRxdmaParityError", 0, 0,
  3659. CNTR_NORMAL,
  3660. access_cce_cli1_async_fifo_rxdma_parity_err_cnt
  3661. ),
  3662. [C_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR] = CNTR_ELEM(
  3663. "CceCli1AsyncFifoSdmaHdParityErr", 0, 0,
  3664. CNTR_NORMAL,
  3665. access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt),
  3666. [C_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR] = CNTR_ELEM(
  3667. "CceCli1AsyncFifoPioCrdtParityErr", 0, 0,
  3668. CNTR_NORMAL,
  3669. access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt),
  3670. [C_CCE_CLI2_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceCli2AsyncFifoParityErr", 0,
  3671. 0, CNTR_NORMAL,
  3672. access_cce_cli2_async_fifo_parity_err_cnt),
  3673. [C_CCE_CSR_CFG_BUS_PARITY_ERR] = CNTR_ELEM("CceCsrCfgBusParityErr", 0, 0,
  3674. CNTR_NORMAL,
  3675. access_cce_csr_cfg_bus_parity_err_cnt),
  3676. [C_CCE_CLI0_ASYNC_FIFO_PARTIY_ERR] = CNTR_ELEM("CceCli0AsyncFifoParityErr", 0,
  3677. 0, CNTR_NORMAL,
  3678. access_cce_cli0_async_fifo_parity_err_cnt),
  3679. [C_CCE_RSPD_DATA_PARITY_ERR] = CNTR_ELEM("CceRspdDataParityErr", 0, 0,
  3680. CNTR_NORMAL,
  3681. access_cce_rspd_data_parity_err_cnt),
  3682. [C_CCE_TRGT_ACCESS_ERR] = CNTR_ELEM("CceTrgtAccessErr", 0, 0,
  3683. CNTR_NORMAL,
  3684. access_cce_trgt_access_err_cnt),
  3685. [C_CCE_TRGT_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceTrgtAsyncFifoParityErr", 0,
  3686. 0, CNTR_NORMAL,
  3687. access_cce_trgt_async_fifo_parity_err_cnt),
  3688. [C_CCE_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrWriteBadAddrErr", 0, 0,
  3689. CNTR_NORMAL,
  3690. access_cce_csr_write_bad_addr_err_cnt),
  3691. [C_CCE_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrReadBadAddrErr", 0, 0,
  3692. CNTR_NORMAL,
  3693. access_cce_csr_read_bad_addr_err_cnt),
  3694. [C_CCE_CSR_PARITY_ERR] = CNTR_ELEM("CceCsrParityErr", 0, 0,
  3695. CNTR_NORMAL,
  3696. access_ccs_csr_parity_err_cnt),
  3697. /* RcvErrStatus */
  3698. [C_RX_CSR_PARITY_ERR] = CNTR_ELEM("RxCsrParityErr", 0, 0,
  3699. CNTR_NORMAL,
  3700. access_rx_csr_parity_err_cnt),
  3701. [C_RX_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrWriteBadAddrErr", 0, 0,
  3702. CNTR_NORMAL,
  3703. access_rx_csr_write_bad_addr_err_cnt),
  3704. [C_RX_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrReadBadAddrErr", 0, 0,
  3705. CNTR_NORMAL,
  3706. access_rx_csr_read_bad_addr_err_cnt),
  3707. [C_RX_DMA_CSR_UNC_ERR] = CNTR_ELEM("RxDmaCsrUncErr", 0, 0,
  3708. CNTR_NORMAL,
  3709. access_rx_dma_csr_unc_err_cnt),
  3710. [C_RX_DMA_DQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaDqFsmEncodingErr", 0, 0,
  3711. CNTR_NORMAL,
  3712. access_rx_dma_dq_fsm_encoding_err_cnt),
  3713. [C_RX_DMA_EQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaEqFsmEncodingErr", 0, 0,
  3714. CNTR_NORMAL,
  3715. access_rx_dma_eq_fsm_encoding_err_cnt),
  3716. [C_RX_DMA_CSR_PARITY_ERR] = CNTR_ELEM("RxDmaCsrParityErr", 0, 0,
  3717. CNTR_NORMAL,
  3718. access_rx_dma_csr_parity_err_cnt),
  3719. [C_RX_RBUF_DATA_COR_ERR] = CNTR_ELEM("RxRbufDataCorErr", 0, 0,
  3720. CNTR_NORMAL,
  3721. access_rx_rbuf_data_cor_err_cnt),
  3722. [C_RX_RBUF_DATA_UNC_ERR] = CNTR_ELEM("RxRbufDataUncErr", 0, 0,
  3723. CNTR_NORMAL,
  3724. access_rx_rbuf_data_unc_err_cnt),
  3725. [C_RX_DMA_DATA_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaDataFifoRdCorErr", 0, 0,
  3726. CNTR_NORMAL,
  3727. access_rx_dma_data_fifo_rd_cor_err_cnt),
  3728. [C_RX_DMA_DATA_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaDataFifoRdUncErr", 0, 0,
  3729. CNTR_NORMAL,
  3730. access_rx_dma_data_fifo_rd_unc_err_cnt),
  3731. [C_RX_DMA_HDR_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaHdrFifoRdCorErr", 0, 0,
  3732. CNTR_NORMAL,
  3733. access_rx_dma_hdr_fifo_rd_cor_err_cnt),
  3734. [C_RX_DMA_HDR_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaHdrFifoRdUncErr", 0, 0,
  3735. CNTR_NORMAL,
  3736. access_rx_dma_hdr_fifo_rd_unc_err_cnt),
  3737. [C_RX_RBUF_DESC_PART2_COR_ERR] = CNTR_ELEM("RxRbufDescPart2CorErr", 0, 0,
  3738. CNTR_NORMAL,
  3739. access_rx_rbuf_desc_part2_cor_err_cnt),
  3740. [C_RX_RBUF_DESC_PART2_UNC_ERR] = CNTR_ELEM("RxRbufDescPart2UncErr", 0, 0,
  3741. CNTR_NORMAL,
  3742. access_rx_rbuf_desc_part2_unc_err_cnt),
  3743. [C_RX_RBUF_DESC_PART1_COR_ERR] = CNTR_ELEM("RxRbufDescPart1CorErr", 0, 0,
  3744. CNTR_NORMAL,
  3745. access_rx_rbuf_desc_part1_cor_err_cnt),
  3746. [C_RX_RBUF_DESC_PART1_UNC_ERR] = CNTR_ELEM("RxRbufDescPart1UncErr", 0, 0,
  3747. CNTR_NORMAL,
  3748. access_rx_rbuf_desc_part1_unc_err_cnt),
  3749. [C_RX_HQ_INTR_FSM_ERR] = CNTR_ELEM("RxHqIntrFsmErr", 0, 0,
  3750. CNTR_NORMAL,
  3751. access_rx_hq_intr_fsm_err_cnt),
  3752. [C_RX_HQ_INTR_CSR_PARITY_ERR] = CNTR_ELEM("RxHqIntrCsrParityErr", 0, 0,
  3753. CNTR_NORMAL,
  3754. access_rx_hq_intr_csr_parity_err_cnt),
  3755. [C_RX_LOOKUP_CSR_PARITY_ERR] = CNTR_ELEM("RxLookupCsrParityErr", 0, 0,
  3756. CNTR_NORMAL,
  3757. access_rx_lookup_csr_parity_err_cnt),
  3758. [C_RX_LOOKUP_RCV_ARRAY_COR_ERR] = CNTR_ELEM("RxLookupRcvArrayCorErr", 0, 0,
  3759. CNTR_NORMAL,
  3760. access_rx_lookup_rcv_array_cor_err_cnt),
  3761. [C_RX_LOOKUP_RCV_ARRAY_UNC_ERR] = CNTR_ELEM("RxLookupRcvArrayUncErr", 0, 0,
  3762. CNTR_NORMAL,
  3763. access_rx_lookup_rcv_array_unc_err_cnt),
  3764. [C_RX_LOOKUP_DES_PART2_PARITY_ERR] = CNTR_ELEM("RxLookupDesPart2ParityErr", 0,
  3765. 0, CNTR_NORMAL,
  3766. access_rx_lookup_des_part2_parity_err_cnt),
  3767. [C_RX_LOOKUP_DES_PART1_UNC_COR_ERR] = CNTR_ELEM("RxLookupDesPart1UncCorErr", 0,
  3768. 0, CNTR_NORMAL,
  3769. access_rx_lookup_des_part1_unc_cor_err_cnt),
  3770. [C_RX_LOOKUP_DES_PART1_UNC_ERR] = CNTR_ELEM("RxLookupDesPart1UncErr", 0, 0,
  3771. CNTR_NORMAL,
  3772. access_rx_lookup_des_part1_unc_err_cnt),
  3773. [C_RX_RBUF_NEXT_FREE_BUF_COR_ERR] = CNTR_ELEM("RxRbufNextFreeBufCorErr", 0, 0,
  3774. CNTR_NORMAL,
  3775. access_rx_rbuf_next_free_buf_cor_err_cnt),
  3776. [C_RX_RBUF_NEXT_FREE_BUF_UNC_ERR] = CNTR_ELEM("RxRbufNextFreeBufUncErr", 0, 0,
  3777. CNTR_NORMAL,
  3778. access_rx_rbuf_next_free_buf_unc_err_cnt),
  3779. [C_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR] = CNTR_ELEM(
  3780. "RxRbufFlInitWrAddrParityErr", 0, 0,
  3781. CNTR_NORMAL,
  3782. access_rbuf_fl_init_wr_addr_parity_err_cnt),
  3783. [C_RX_RBUF_FL_INITDONE_PARITY_ERR] = CNTR_ELEM("RxRbufFlInitdoneParityErr", 0,
  3784. 0, CNTR_NORMAL,
  3785. access_rx_rbuf_fl_initdone_parity_err_cnt),
  3786. [C_RX_RBUF_FL_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlWrAddrParityErr", 0,
  3787. 0, CNTR_NORMAL,
  3788. access_rx_rbuf_fl_write_addr_parity_err_cnt),
  3789. [C_RX_RBUF_FL_RD_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlRdAddrParityErr", 0, 0,
  3790. CNTR_NORMAL,
  3791. access_rx_rbuf_fl_rd_addr_parity_err_cnt),
  3792. [C_RX_RBUF_EMPTY_ERR] = CNTR_ELEM("RxRbufEmptyErr", 0, 0,
  3793. CNTR_NORMAL,
  3794. access_rx_rbuf_empty_err_cnt),
  3795. [C_RX_RBUF_FULL_ERR] = CNTR_ELEM("RxRbufFullErr", 0, 0,
  3796. CNTR_NORMAL,
  3797. access_rx_rbuf_full_err_cnt),
  3798. [C_RX_RBUF_BAD_LOOKUP_ERR] = CNTR_ELEM("RxRBufBadLookupErr", 0, 0,
  3799. CNTR_NORMAL,
  3800. access_rbuf_bad_lookup_err_cnt),
  3801. [C_RX_RBUF_CTX_ID_PARITY_ERR] = CNTR_ELEM("RxRbufCtxIdParityErr", 0, 0,
  3802. CNTR_NORMAL,
  3803. access_rbuf_ctx_id_parity_err_cnt),
  3804. [C_RX_RBUF_CSR_QEOPDW_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEOPDWParityErr", 0, 0,
  3805. CNTR_NORMAL,
  3806. access_rbuf_csr_qeopdw_parity_err_cnt),
  3807. [C_RX_RBUF_CSR_Q_NUM_OF_PKT_PARITY_ERR] = CNTR_ELEM(
  3808. "RxRbufCsrQNumOfPktParityErr", 0, 0,
  3809. CNTR_NORMAL,
  3810. access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt),
  3811. [C_RX_RBUF_CSR_Q_T1_PTR_PARITY_ERR] = CNTR_ELEM(
  3812. "RxRbufCsrQTlPtrParityErr", 0, 0,
  3813. CNTR_NORMAL,
  3814. access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt),
  3815. [C_RX_RBUF_CSR_Q_HD_PTR_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQHdPtrParityErr", 0,
  3816. 0, CNTR_NORMAL,
  3817. access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt),
  3818. [C_RX_RBUF_CSR_Q_VLD_BIT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQVldBitParityErr", 0,
  3819. 0, CNTR_NORMAL,
  3820. access_rx_rbuf_csr_q_vld_bit_parity_err_cnt),
  3821. [C_RX_RBUF_CSR_Q_NEXT_BUF_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQNextBufParityErr",
  3822. 0, 0, CNTR_NORMAL,
  3823. access_rx_rbuf_csr_q_next_buf_parity_err_cnt),
  3824. [C_RX_RBUF_CSR_Q_ENT_CNT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEntCntParityErr", 0,
  3825. 0, CNTR_NORMAL,
  3826. access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt),
  3827. [C_RX_RBUF_CSR_Q_HEAD_BUF_NUM_PARITY_ERR] = CNTR_ELEM(
  3828. "RxRbufCsrQHeadBufNumParityErr", 0, 0,
  3829. CNTR_NORMAL,
  3830. access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt),
  3831. [C_RX_RBUF_BLOCK_LIST_READ_COR_ERR] = CNTR_ELEM("RxRbufBlockListReadCorErr", 0,
  3832. 0, CNTR_NORMAL,
  3833. access_rx_rbuf_block_list_read_cor_err_cnt),
  3834. [C_RX_RBUF_BLOCK_LIST_READ_UNC_ERR] = CNTR_ELEM("RxRbufBlockListReadUncErr", 0,
  3835. 0, CNTR_NORMAL,
  3836. access_rx_rbuf_block_list_read_unc_err_cnt),
  3837. [C_RX_RBUF_LOOKUP_DES_COR_ERR] = CNTR_ELEM("RxRbufLookupDesCorErr", 0, 0,
  3838. CNTR_NORMAL,
  3839. access_rx_rbuf_lookup_des_cor_err_cnt),
  3840. [C_RX_RBUF_LOOKUP_DES_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesUncErr", 0, 0,
  3841. CNTR_NORMAL,
  3842. access_rx_rbuf_lookup_des_unc_err_cnt),
  3843. [C_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR] = CNTR_ELEM(
  3844. "RxRbufLookupDesRegUncCorErr", 0, 0,
  3845. CNTR_NORMAL,
  3846. access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt),
  3847. [C_RX_RBUF_LOOKUP_DES_REG_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesRegUncErr", 0, 0,
  3848. CNTR_NORMAL,
  3849. access_rx_rbuf_lookup_des_reg_unc_err_cnt),
  3850. [C_RX_RBUF_FREE_LIST_COR_ERR] = CNTR_ELEM("RxRbufFreeListCorErr", 0, 0,
  3851. CNTR_NORMAL,
  3852. access_rx_rbuf_free_list_cor_err_cnt),
  3853. [C_RX_RBUF_FREE_LIST_UNC_ERR] = CNTR_ELEM("RxRbufFreeListUncErr", 0, 0,
  3854. CNTR_NORMAL,
  3855. access_rx_rbuf_free_list_unc_err_cnt),
  3856. [C_RX_RCV_FSM_ENCODING_ERR] = CNTR_ELEM("RxRcvFsmEncodingErr", 0, 0,
  3857. CNTR_NORMAL,
  3858. access_rx_rcv_fsm_encoding_err_cnt),
  3859. [C_RX_DMA_FLAG_COR_ERR] = CNTR_ELEM("RxDmaFlagCorErr", 0, 0,
  3860. CNTR_NORMAL,
  3861. access_rx_dma_flag_cor_err_cnt),
  3862. [C_RX_DMA_FLAG_UNC_ERR] = CNTR_ELEM("RxDmaFlagUncErr", 0, 0,
  3863. CNTR_NORMAL,
  3864. access_rx_dma_flag_unc_err_cnt),
  3865. [C_RX_DC_SOP_EOP_PARITY_ERR] = CNTR_ELEM("RxDcSopEopParityErr", 0, 0,
  3866. CNTR_NORMAL,
  3867. access_rx_dc_sop_eop_parity_err_cnt),
  3868. [C_RX_RCV_CSR_PARITY_ERR] = CNTR_ELEM("RxRcvCsrParityErr", 0, 0,
  3869. CNTR_NORMAL,
  3870. access_rx_rcv_csr_parity_err_cnt),
  3871. [C_RX_RCV_QP_MAP_TABLE_COR_ERR] = CNTR_ELEM("RxRcvQpMapTableCorErr", 0, 0,
  3872. CNTR_NORMAL,
  3873. access_rx_rcv_qp_map_table_cor_err_cnt),
  3874. [C_RX_RCV_QP_MAP_TABLE_UNC_ERR] = CNTR_ELEM("RxRcvQpMapTableUncErr", 0, 0,
  3875. CNTR_NORMAL,
  3876. access_rx_rcv_qp_map_table_unc_err_cnt),
  3877. [C_RX_RCV_DATA_COR_ERR] = CNTR_ELEM("RxRcvDataCorErr", 0, 0,
  3878. CNTR_NORMAL,
  3879. access_rx_rcv_data_cor_err_cnt),
  3880. [C_RX_RCV_DATA_UNC_ERR] = CNTR_ELEM("RxRcvDataUncErr", 0, 0,
  3881. CNTR_NORMAL,
  3882. access_rx_rcv_data_unc_err_cnt),
  3883. [C_RX_RCV_HDR_COR_ERR] = CNTR_ELEM("RxRcvHdrCorErr", 0, 0,
  3884. CNTR_NORMAL,
  3885. access_rx_rcv_hdr_cor_err_cnt),
  3886. [C_RX_RCV_HDR_UNC_ERR] = CNTR_ELEM("RxRcvHdrUncErr", 0, 0,
  3887. CNTR_NORMAL,
  3888. access_rx_rcv_hdr_unc_err_cnt),
  3889. [C_RX_DC_INTF_PARITY_ERR] = CNTR_ELEM("RxDcIntfParityErr", 0, 0,
  3890. CNTR_NORMAL,
  3891. access_rx_dc_intf_parity_err_cnt),
  3892. [C_RX_DMA_CSR_COR_ERR] = CNTR_ELEM("RxDmaCsrCorErr", 0, 0,
  3893. CNTR_NORMAL,
  3894. access_rx_dma_csr_cor_err_cnt),
  3895. /* SendPioErrStatus */
  3896. [C_PIO_PEC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPecSopHeadParityErr", 0, 0,
  3897. CNTR_NORMAL,
  3898. access_pio_pec_sop_head_parity_err_cnt),
  3899. [C_PIO_PCC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPccSopHeadParityErr", 0, 0,
  3900. CNTR_NORMAL,
  3901. access_pio_pcc_sop_head_parity_err_cnt),
  3902. [C_PIO_LAST_RETURNED_CNT_PARITY_ERR] = CNTR_ELEM("PioLastReturnedCntParityErr",
  3903. 0, 0, CNTR_NORMAL,
  3904. access_pio_last_returned_cnt_parity_err_cnt),
  3905. [C_PIO_CURRENT_FREE_CNT_PARITY_ERR] = CNTR_ELEM("PioCurrentFreeCntParityErr", 0,
  3906. 0, CNTR_NORMAL,
  3907. access_pio_current_free_cnt_parity_err_cnt),
  3908. [C_PIO_RSVD_31_ERR] = CNTR_ELEM("Pio Reserved 31", 0, 0,
  3909. CNTR_NORMAL,
  3910. access_pio_reserved_31_err_cnt),
  3911. [C_PIO_RSVD_30_ERR] = CNTR_ELEM("Pio Reserved 30", 0, 0,
  3912. CNTR_NORMAL,
  3913. access_pio_reserved_30_err_cnt),
  3914. [C_PIO_PPMC_SOP_LEN_ERR] = CNTR_ELEM("PioPpmcSopLenErr", 0, 0,
  3915. CNTR_NORMAL,
  3916. access_pio_ppmc_sop_len_err_cnt),
  3917. [C_PIO_PPMC_BQC_MEM_PARITY_ERR] = CNTR_ELEM("PioPpmcBqcMemParityErr", 0, 0,
  3918. CNTR_NORMAL,
  3919. access_pio_ppmc_bqc_mem_parity_err_cnt),
  3920. [C_PIO_VL_FIFO_PARITY_ERR] = CNTR_ELEM("PioVlFifoParityErr", 0, 0,
  3921. CNTR_NORMAL,
  3922. access_pio_vl_fifo_parity_err_cnt),
  3923. [C_PIO_VLF_SOP_PARITY_ERR] = CNTR_ELEM("PioVlfSopParityErr", 0, 0,
  3924. CNTR_NORMAL,
  3925. access_pio_vlf_sop_parity_err_cnt),
  3926. [C_PIO_VLF_V1_LEN_PARITY_ERR] = CNTR_ELEM("PioVlfVlLenParityErr", 0, 0,
  3927. CNTR_NORMAL,
  3928. access_pio_vlf_v1_len_parity_err_cnt),
  3929. [C_PIO_BLOCK_QW_COUNT_PARITY_ERR] = CNTR_ELEM("PioBlockQwCountParityErr", 0, 0,
  3930. CNTR_NORMAL,
  3931. access_pio_block_qw_count_parity_err_cnt),
  3932. [C_PIO_WRITE_QW_VALID_PARITY_ERR] = CNTR_ELEM("PioWriteQwValidParityErr", 0, 0,
  3933. CNTR_NORMAL,
  3934. access_pio_write_qw_valid_parity_err_cnt),
  3935. [C_PIO_STATE_MACHINE_ERR] = CNTR_ELEM("PioStateMachineErr", 0, 0,
  3936. CNTR_NORMAL,
  3937. access_pio_state_machine_err_cnt),
  3938. [C_PIO_WRITE_DATA_PARITY_ERR] = CNTR_ELEM("PioWriteDataParityErr", 0, 0,
  3939. CNTR_NORMAL,
  3940. access_pio_write_data_parity_err_cnt),
  3941. [C_PIO_HOST_ADDR_MEM_COR_ERR] = CNTR_ELEM("PioHostAddrMemCorErr", 0, 0,
  3942. CNTR_NORMAL,
  3943. access_pio_host_addr_mem_cor_err_cnt),
  3944. [C_PIO_HOST_ADDR_MEM_UNC_ERR] = CNTR_ELEM("PioHostAddrMemUncErr", 0, 0,
  3945. CNTR_NORMAL,
  3946. access_pio_host_addr_mem_unc_err_cnt),
  3947. [C_PIO_PKT_EVICT_SM_OR_ARM_SM_ERR] = CNTR_ELEM("PioPktEvictSmOrArbSmErr", 0, 0,
  3948. CNTR_NORMAL,
  3949. access_pio_pkt_evict_sm_or_arb_sm_err_cnt),
  3950. [C_PIO_INIT_SM_IN_ERR] = CNTR_ELEM("PioInitSmInErr", 0, 0,
  3951. CNTR_NORMAL,
  3952. access_pio_init_sm_in_err_cnt),
  3953. [C_PIO_PPMC_PBL_FIFO_ERR] = CNTR_ELEM("PioPpmcPblFifoErr", 0, 0,
  3954. CNTR_NORMAL,
  3955. access_pio_ppmc_pbl_fifo_err_cnt),
  3956. [C_PIO_CREDIT_RET_FIFO_PARITY_ERR] = CNTR_ELEM("PioCreditRetFifoParityErr", 0,
  3957. 0, CNTR_NORMAL,
  3958. access_pio_credit_ret_fifo_parity_err_cnt),
  3959. [C_PIO_V1_LEN_MEM_BANK1_COR_ERR] = CNTR_ELEM("PioVlLenMemBank1CorErr", 0, 0,
  3960. CNTR_NORMAL,
  3961. access_pio_v1_len_mem_bank1_cor_err_cnt),
  3962. [C_PIO_V1_LEN_MEM_BANK0_COR_ERR] = CNTR_ELEM("PioVlLenMemBank0CorErr", 0, 0,
  3963. CNTR_NORMAL,
  3964. access_pio_v1_len_mem_bank0_cor_err_cnt),
  3965. [C_PIO_V1_LEN_MEM_BANK1_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank1UncErr", 0, 0,
  3966. CNTR_NORMAL,
  3967. access_pio_v1_len_mem_bank1_unc_err_cnt),
  3968. [C_PIO_V1_LEN_MEM_BANK0_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank0UncErr", 0, 0,
  3969. CNTR_NORMAL,
  3970. access_pio_v1_len_mem_bank0_unc_err_cnt),
  3971. [C_PIO_SM_PKT_RESET_PARITY_ERR] = CNTR_ELEM("PioSmPktResetParityErr", 0, 0,
  3972. CNTR_NORMAL,
  3973. access_pio_sm_pkt_reset_parity_err_cnt),
  3974. [C_PIO_PKT_EVICT_FIFO_PARITY_ERR] = CNTR_ELEM("PioPktEvictFifoParityErr", 0, 0,
  3975. CNTR_NORMAL,
  3976. access_pio_pkt_evict_fifo_parity_err_cnt),
  3977. [C_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR] = CNTR_ELEM(
  3978. "PioSbrdctrlCrrelFifoParityErr", 0, 0,
  3979. CNTR_NORMAL,
  3980. access_pio_sbrdctrl_crrel_fifo_parity_err_cnt),
  3981. [C_PIO_SBRDCTL_CRREL_PARITY_ERR] = CNTR_ELEM("PioSbrdctlCrrelParityErr", 0, 0,
  3982. CNTR_NORMAL,
  3983. access_pio_sbrdctl_crrel_parity_err_cnt),
  3984. [C_PIO_PEC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPecFifoParityErr", 0, 0,
  3985. CNTR_NORMAL,
  3986. access_pio_pec_fifo_parity_err_cnt),
  3987. [C_PIO_PCC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPccFifoParityErr", 0, 0,
  3988. CNTR_NORMAL,
  3989. access_pio_pcc_fifo_parity_err_cnt),
  3990. [C_PIO_SB_MEM_FIFO1_ERR] = CNTR_ELEM("PioSbMemFifo1Err", 0, 0,
  3991. CNTR_NORMAL,
  3992. access_pio_sb_mem_fifo1_err_cnt),
  3993. [C_PIO_SB_MEM_FIFO0_ERR] = CNTR_ELEM("PioSbMemFifo0Err", 0, 0,
  3994. CNTR_NORMAL,
  3995. access_pio_sb_mem_fifo0_err_cnt),
  3996. [C_PIO_CSR_PARITY_ERR] = CNTR_ELEM("PioCsrParityErr", 0, 0,
  3997. CNTR_NORMAL,
  3998. access_pio_csr_parity_err_cnt),
  3999. [C_PIO_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("PioWriteAddrParityErr", 0, 0,
  4000. CNTR_NORMAL,
  4001. access_pio_write_addr_parity_err_cnt),
  4002. [C_PIO_WRITE_BAD_CTXT_ERR] = CNTR_ELEM("PioWriteBadCtxtErr", 0, 0,
  4003. CNTR_NORMAL,
  4004. access_pio_write_bad_ctxt_err_cnt),
  4005. /* SendDmaErrStatus */
  4006. [C_SDMA_PCIE_REQ_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPcieReqTrackingCorErr", 0,
  4007. 0, CNTR_NORMAL,
  4008. access_sdma_pcie_req_tracking_cor_err_cnt),
  4009. [C_SDMA_PCIE_REQ_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPcieReqTrackingUncErr", 0,
  4010. 0, CNTR_NORMAL,
  4011. access_sdma_pcie_req_tracking_unc_err_cnt),
  4012. [C_SDMA_CSR_PARITY_ERR] = CNTR_ELEM("SDmaCsrParityErr", 0, 0,
  4013. CNTR_NORMAL,
  4014. access_sdma_csr_parity_err_cnt),
  4015. [C_SDMA_RPY_TAG_ERR] = CNTR_ELEM("SDmaRpyTagErr", 0, 0,
  4016. CNTR_NORMAL,
  4017. access_sdma_rpy_tag_err_cnt),
  4018. /* SendEgressErrStatus */
  4019. [C_TX_READ_PIO_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryCsrUncErr", 0, 0,
  4020. CNTR_NORMAL,
  4021. access_tx_read_pio_memory_csr_unc_err_cnt),
  4022. [C_TX_READ_SDMA_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryCsrUncErr", 0,
  4023. 0, CNTR_NORMAL,
  4024. access_tx_read_sdma_memory_csr_err_cnt),
  4025. [C_TX_EGRESS_FIFO_COR_ERR] = CNTR_ELEM("TxEgressFifoCorErr", 0, 0,
  4026. CNTR_NORMAL,
  4027. access_tx_egress_fifo_cor_err_cnt),
  4028. [C_TX_READ_PIO_MEMORY_COR_ERR] = CNTR_ELEM("TxReadPioMemoryCorErr", 0, 0,
  4029. CNTR_NORMAL,
  4030. access_tx_read_pio_memory_cor_err_cnt),
  4031. [C_TX_READ_SDMA_MEMORY_COR_ERR] = CNTR_ELEM("TxReadSdmaMemoryCorErr", 0, 0,
  4032. CNTR_NORMAL,
  4033. access_tx_read_sdma_memory_cor_err_cnt),
  4034. [C_TX_SB_HDR_COR_ERR] = CNTR_ELEM("TxSbHdrCorErr", 0, 0,
  4035. CNTR_NORMAL,
  4036. access_tx_sb_hdr_cor_err_cnt),
  4037. [C_TX_CREDIT_OVERRUN_ERR] = CNTR_ELEM("TxCreditOverrunErr", 0, 0,
  4038. CNTR_NORMAL,
  4039. access_tx_credit_overrun_err_cnt),
  4040. [C_TX_LAUNCH_FIFO8_COR_ERR] = CNTR_ELEM("TxLaunchFifo8CorErr", 0, 0,
  4041. CNTR_NORMAL,
  4042. access_tx_launch_fifo8_cor_err_cnt),
  4043. [C_TX_LAUNCH_FIFO7_COR_ERR] = CNTR_ELEM("TxLaunchFifo7CorErr", 0, 0,
  4044. CNTR_NORMAL,
  4045. access_tx_launch_fifo7_cor_err_cnt),
  4046. [C_TX_LAUNCH_FIFO6_COR_ERR] = CNTR_ELEM("TxLaunchFifo6CorErr", 0, 0,
  4047. CNTR_NORMAL,
  4048. access_tx_launch_fifo6_cor_err_cnt),
  4049. [C_TX_LAUNCH_FIFO5_COR_ERR] = CNTR_ELEM("TxLaunchFifo5CorErr", 0, 0,
  4050. CNTR_NORMAL,
  4051. access_tx_launch_fifo5_cor_err_cnt),
  4052. [C_TX_LAUNCH_FIFO4_COR_ERR] = CNTR_ELEM("TxLaunchFifo4CorErr", 0, 0,
  4053. CNTR_NORMAL,
  4054. access_tx_launch_fifo4_cor_err_cnt),
  4055. [C_TX_LAUNCH_FIFO3_COR_ERR] = CNTR_ELEM("TxLaunchFifo3CorErr", 0, 0,
  4056. CNTR_NORMAL,
  4057. access_tx_launch_fifo3_cor_err_cnt),
  4058. [C_TX_LAUNCH_FIFO2_COR_ERR] = CNTR_ELEM("TxLaunchFifo2CorErr", 0, 0,
  4059. CNTR_NORMAL,
  4060. access_tx_launch_fifo2_cor_err_cnt),
  4061. [C_TX_LAUNCH_FIFO1_COR_ERR] = CNTR_ELEM("TxLaunchFifo1CorErr", 0, 0,
  4062. CNTR_NORMAL,
  4063. access_tx_launch_fifo1_cor_err_cnt),
  4064. [C_TX_LAUNCH_FIFO0_COR_ERR] = CNTR_ELEM("TxLaunchFifo0CorErr", 0, 0,
  4065. CNTR_NORMAL,
  4066. access_tx_launch_fifo0_cor_err_cnt),
  4067. [C_TX_CREDIT_RETURN_VL_ERR] = CNTR_ELEM("TxCreditReturnVLErr", 0, 0,
  4068. CNTR_NORMAL,
  4069. access_tx_credit_return_vl_err_cnt),
  4070. [C_TX_HCRC_INSERTION_ERR] = CNTR_ELEM("TxHcrcInsertionErr", 0, 0,
  4071. CNTR_NORMAL,
  4072. access_tx_hcrc_insertion_err_cnt),
  4073. [C_TX_EGRESS_FIFI_UNC_ERR] = CNTR_ELEM("TxEgressFifoUncErr", 0, 0,
  4074. CNTR_NORMAL,
  4075. access_tx_egress_fifo_unc_err_cnt),
  4076. [C_TX_READ_PIO_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryUncErr", 0, 0,
  4077. CNTR_NORMAL,
  4078. access_tx_read_pio_memory_unc_err_cnt),
  4079. [C_TX_READ_SDMA_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryUncErr", 0, 0,
  4080. CNTR_NORMAL,
  4081. access_tx_read_sdma_memory_unc_err_cnt),
  4082. [C_TX_SB_HDR_UNC_ERR] = CNTR_ELEM("TxSbHdrUncErr", 0, 0,
  4083. CNTR_NORMAL,
  4084. access_tx_sb_hdr_unc_err_cnt),
  4085. [C_TX_CREDIT_RETURN_PARITY_ERR] = CNTR_ELEM("TxCreditReturnParityErr", 0, 0,
  4086. CNTR_NORMAL,
  4087. access_tx_credit_return_partiy_err_cnt),
  4088. [C_TX_LAUNCH_FIFO8_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo8UncOrParityErr",
  4089. 0, 0, CNTR_NORMAL,
  4090. access_tx_launch_fifo8_unc_or_parity_err_cnt),
  4091. [C_TX_LAUNCH_FIFO7_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo7UncOrParityErr",
  4092. 0, 0, CNTR_NORMAL,
  4093. access_tx_launch_fifo7_unc_or_parity_err_cnt),
  4094. [C_TX_LAUNCH_FIFO6_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo6UncOrParityErr",
  4095. 0, 0, CNTR_NORMAL,
  4096. access_tx_launch_fifo6_unc_or_parity_err_cnt),
  4097. [C_TX_LAUNCH_FIFO5_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo5UncOrParityErr",
  4098. 0, 0, CNTR_NORMAL,
  4099. access_tx_launch_fifo5_unc_or_parity_err_cnt),
  4100. [C_TX_LAUNCH_FIFO4_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo4UncOrParityErr",
  4101. 0, 0, CNTR_NORMAL,
  4102. access_tx_launch_fifo4_unc_or_parity_err_cnt),
  4103. [C_TX_LAUNCH_FIFO3_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo3UncOrParityErr",
  4104. 0, 0, CNTR_NORMAL,
  4105. access_tx_launch_fifo3_unc_or_parity_err_cnt),
  4106. [C_TX_LAUNCH_FIFO2_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo2UncOrParityErr",
  4107. 0, 0, CNTR_NORMAL,
  4108. access_tx_launch_fifo2_unc_or_parity_err_cnt),
  4109. [C_TX_LAUNCH_FIFO1_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo1UncOrParityErr",
  4110. 0, 0, CNTR_NORMAL,
  4111. access_tx_launch_fifo1_unc_or_parity_err_cnt),
  4112. [C_TX_LAUNCH_FIFO0_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo0UncOrParityErr",
  4113. 0, 0, CNTR_NORMAL,
  4114. access_tx_launch_fifo0_unc_or_parity_err_cnt),
  4115. [C_TX_SDMA15_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma15DisallowedPacketErr",
  4116. 0, 0, CNTR_NORMAL,
  4117. access_tx_sdma15_disallowed_packet_err_cnt),
  4118. [C_TX_SDMA14_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma14DisallowedPacketErr",
  4119. 0, 0, CNTR_NORMAL,
  4120. access_tx_sdma14_disallowed_packet_err_cnt),
  4121. [C_TX_SDMA13_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma13DisallowedPacketErr",
  4122. 0, 0, CNTR_NORMAL,
  4123. access_tx_sdma13_disallowed_packet_err_cnt),
  4124. [C_TX_SDMA12_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma12DisallowedPacketErr",
  4125. 0, 0, CNTR_NORMAL,
  4126. access_tx_sdma12_disallowed_packet_err_cnt),
  4127. [C_TX_SDMA11_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma11DisallowedPacketErr",
  4128. 0, 0, CNTR_NORMAL,
  4129. access_tx_sdma11_disallowed_packet_err_cnt),
  4130. [C_TX_SDMA10_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma10DisallowedPacketErr",
  4131. 0, 0, CNTR_NORMAL,
  4132. access_tx_sdma10_disallowed_packet_err_cnt),
  4133. [C_TX_SDMA9_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma9DisallowedPacketErr",
  4134. 0, 0, CNTR_NORMAL,
  4135. access_tx_sdma9_disallowed_packet_err_cnt),
  4136. [C_TX_SDMA8_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma8DisallowedPacketErr",
  4137. 0, 0, CNTR_NORMAL,
  4138. access_tx_sdma8_disallowed_packet_err_cnt),
  4139. [C_TX_SDMA7_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma7DisallowedPacketErr",
  4140. 0, 0, CNTR_NORMAL,
  4141. access_tx_sdma7_disallowed_packet_err_cnt),
  4142. [C_TX_SDMA6_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma6DisallowedPacketErr",
  4143. 0, 0, CNTR_NORMAL,
  4144. access_tx_sdma6_disallowed_packet_err_cnt),
  4145. [C_TX_SDMA5_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma5DisallowedPacketErr",
  4146. 0, 0, CNTR_NORMAL,
  4147. access_tx_sdma5_disallowed_packet_err_cnt),
  4148. [C_TX_SDMA4_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma4DisallowedPacketErr",
  4149. 0, 0, CNTR_NORMAL,
  4150. access_tx_sdma4_disallowed_packet_err_cnt),
  4151. [C_TX_SDMA3_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma3DisallowedPacketErr",
  4152. 0, 0, CNTR_NORMAL,
  4153. access_tx_sdma3_disallowed_packet_err_cnt),
  4154. [C_TX_SDMA2_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma2DisallowedPacketErr",
  4155. 0, 0, CNTR_NORMAL,
  4156. access_tx_sdma2_disallowed_packet_err_cnt),
  4157. [C_TX_SDMA1_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma1DisallowedPacketErr",
  4158. 0, 0, CNTR_NORMAL,
  4159. access_tx_sdma1_disallowed_packet_err_cnt),
  4160. [C_TX_SDMA0_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma0DisallowedPacketErr",
  4161. 0, 0, CNTR_NORMAL,
  4162. access_tx_sdma0_disallowed_packet_err_cnt),
  4163. [C_TX_CONFIG_PARITY_ERR] = CNTR_ELEM("TxConfigParityErr", 0, 0,
  4164. CNTR_NORMAL,
  4165. access_tx_config_parity_err_cnt),
  4166. [C_TX_SBRD_CTL_CSR_PARITY_ERR] = CNTR_ELEM("TxSbrdCtlCsrParityErr", 0, 0,
  4167. CNTR_NORMAL,
  4168. access_tx_sbrd_ctl_csr_parity_err_cnt),
  4169. [C_TX_LAUNCH_CSR_PARITY_ERR] = CNTR_ELEM("TxLaunchCsrParityErr", 0, 0,
  4170. CNTR_NORMAL,
  4171. access_tx_launch_csr_parity_err_cnt),
  4172. [C_TX_ILLEGAL_CL_ERR] = CNTR_ELEM("TxIllegalVLErr", 0, 0,
  4173. CNTR_NORMAL,
  4174. access_tx_illegal_vl_err_cnt),
  4175. [C_TX_SBRD_CTL_STATE_MACHINE_PARITY_ERR] = CNTR_ELEM(
  4176. "TxSbrdCtlStateMachineParityErr", 0, 0,
  4177. CNTR_NORMAL,
  4178. access_tx_sbrd_ctl_state_machine_parity_err_cnt),
  4179. [C_TX_RESERVED_10] = CNTR_ELEM("Tx Egress Reserved 10", 0, 0,
  4180. CNTR_NORMAL,
  4181. access_egress_reserved_10_err_cnt),
  4182. [C_TX_RESERVED_9] = CNTR_ELEM("Tx Egress Reserved 9", 0, 0,
  4183. CNTR_NORMAL,
  4184. access_egress_reserved_9_err_cnt),
  4185. [C_TX_SDMA_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxSdmaLaunchIntfParityErr",
  4186. 0, 0, CNTR_NORMAL,
  4187. access_tx_sdma_launch_intf_parity_err_cnt),
  4188. [C_TX_PIO_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxPioLaunchIntfParityErr", 0, 0,
  4189. CNTR_NORMAL,
  4190. access_tx_pio_launch_intf_parity_err_cnt),
  4191. [C_TX_RESERVED_6] = CNTR_ELEM("Tx Egress Reserved 6", 0, 0,
  4192. CNTR_NORMAL,
  4193. access_egress_reserved_6_err_cnt),
  4194. [C_TX_INCORRECT_LINK_STATE_ERR] = CNTR_ELEM("TxIncorrectLinkStateErr", 0, 0,
  4195. CNTR_NORMAL,
  4196. access_tx_incorrect_link_state_err_cnt),
  4197. [C_TX_LINK_DOWN_ERR] = CNTR_ELEM("TxLinkdownErr", 0, 0,
  4198. CNTR_NORMAL,
  4199. access_tx_linkdown_err_cnt),
  4200. [C_TX_EGRESS_FIFO_UNDERRUN_OR_PARITY_ERR] = CNTR_ELEM(
  4201. "EgressFifoUnderrunOrParityErr", 0, 0,
  4202. CNTR_NORMAL,
  4203. access_tx_egress_fifi_underrun_or_parity_err_cnt),
  4204. [C_TX_RESERVED_2] = CNTR_ELEM("Tx Egress Reserved 2", 0, 0,
  4205. CNTR_NORMAL,
  4206. access_egress_reserved_2_err_cnt),
  4207. [C_TX_PKT_INTEGRITY_MEM_UNC_ERR] = CNTR_ELEM("TxPktIntegrityMemUncErr", 0, 0,
  4208. CNTR_NORMAL,
  4209. access_tx_pkt_integrity_mem_unc_err_cnt),
  4210. [C_TX_PKT_INTEGRITY_MEM_COR_ERR] = CNTR_ELEM("TxPktIntegrityMemCorErr", 0, 0,
  4211. CNTR_NORMAL,
  4212. access_tx_pkt_integrity_mem_cor_err_cnt),
  4213. /* SendErrStatus */
  4214. [C_SEND_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("SendCsrWriteBadAddrErr", 0, 0,
  4215. CNTR_NORMAL,
  4216. access_send_csr_write_bad_addr_err_cnt),
  4217. [C_SEND_CSR_READ_BAD_ADD_ERR] = CNTR_ELEM("SendCsrReadBadAddrErr", 0, 0,
  4218. CNTR_NORMAL,
  4219. access_send_csr_read_bad_addr_err_cnt),
  4220. [C_SEND_CSR_PARITY_ERR] = CNTR_ELEM("SendCsrParityErr", 0, 0,
  4221. CNTR_NORMAL,
  4222. access_send_csr_parity_cnt),
  4223. /* SendCtxtErrStatus */
  4224. [C_PIO_WRITE_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("PioWriteOutOfBoundsErr", 0, 0,
  4225. CNTR_NORMAL,
  4226. access_pio_write_out_of_bounds_err_cnt),
  4227. [C_PIO_WRITE_OVERFLOW_ERR] = CNTR_ELEM("PioWriteOverflowErr", 0, 0,
  4228. CNTR_NORMAL,
  4229. access_pio_write_overflow_err_cnt),
  4230. [C_PIO_WRITE_CROSSES_BOUNDARY_ERR] = CNTR_ELEM("PioWriteCrossesBoundaryErr",
  4231. 0, 0, CNTR_NORMAL,
  4232. access_pio_write_crosses_boundary_err_cnt),
  4233. [C_PIO_DISALLOWED_PACKET_ERR] = CNTR_ELEM("PioDisallowedPacketErr", 0, 0,
  4234. CNTR_NORMAL,
  4235. access_pio_disallowed_packet_err_cnt),
  4236. [C_PIO_INCONSISTENT_SOP_ERR] = CNTR_ELEM("PioInconsistentSopErr", 0, 0,
  4237. CNTR_NORMAL,
  4238. access_pio_inconsistent_sop_err_cnt),
  4239. /* SendDmaEngErrStatus */
  4240. [C_SDMA_HEADER_REQUEST_FIFO_COR_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoCorErr",
  4241. 0, 0, CNTR_NORMAL,
  4242. access_sdma_header_request_fifo_cor_err_cnt),
  4243. [C_SDMA_HEADER_STORAGE_COR_ERR] = CNTR_ELEM("SDmaHeaderStorageCorErr", 0, 0,
  4244. CNTR_NORMAL,
  4245. access_sdma_header_storage_cor_err_cnt),
  4246. [C_SDMA_PACKET_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPacketTrackingCorErr", 0, 0,
  4247. CNTR_NORMAL,
  4248. access_sdma_packet_tracking_cor_err_cnt),
  4249. [C_SDMA_ASSEMBLY_COR_ERR] = CNTR_ELEM("SDmaAssemblyCorErr", 0, 0,
  4250. CNTR_NORMAL,
  4251. access_sdma_assembly_cor_err_cnt),
  4252. [C_SDMA_DESC_TABLE_COR_ERR] = CNTR_ELEM("SDmaDescTableCorErr", 0, 0,
  4253. CNTR_NORMAL,
  4254. access_sdma_desc_table_cor_err_cnt),
  4255. [C_SDMA_HEADER_REQUEST_FIFO_UNC_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoUncErr",
  4256. 0, 0, CNTR_NORMAL,
  4257. access_sdma_header_request_fifo_unc_err_cnt),
  4258. [C_SDMA_HEADER_STORAGE_UNC_ERR] = CNTR_ELEM("SDmaHeaderStorageUncErr", 0, 0,
  4259. CNTR_NORMAL,
  4260. access_sdma_header_storage_unc_err_cnt),
  4261. [C_SDMA_PACKET_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPacketTrackingUncErr", 0, 0,
  4262. CNTR_NORMAL,
  4263. access_sdma_packet_tracking_unc_err_cnt),
  4264. [C_SDMA_ASSEMBLY_UNC_ERR] = CNTR_ELEM("SDmaAssemblyUncErr", 0, 0,
  4265. CNTR_NORMAL,
  4266. access_sdma_assembly_unc_err_cnt),
  4267. [C_SDMA_DESC_TABLE_UNC_ERR] = CNTR_ELEM("SDmaDescTableUncErr", 0, 0,
  4268. CNTR_NORMAL,
  4269. access_sdma_desc_table_unc_err_cnt),
  4270. [C_SDMA_TIMEOUT_ERR] = CNTR_ELEM("SDmaTimeoutErr", 0, 0,
  4271. CNTR_NORMAL,
  4272. access_sdma_timeout_err_cnt),
  4273. [C_SDMA_HEADER_LENGTH_ERR] = CNTR_ELEM("SDmaHeaderLengthErr", 0, 0,
  4274. CNTR_NORMAL,
  4275. access_sdma_header_length_err_cnt),
  4276. [C_SDMA_HEADER_ADDRESS_ERR] = CNTR_ELEM("SDmaHeaderAddressErr", 0, 0,
  4277. CNTR_NORMAL,
  4278. access_sdma_header_address_err_cnt),
  4279. [C_SDMA_HEADER_SELECT_ERR] = CNTR_ELEM("SDmaHeaderSelectErr", 0, 0,
  4280. CNTR_NORMAL,
  4281. access_sdma_header_select_err_cnt),
  4282. [C_SMDA_RESERVED_9] = CNTR_ELEM("SDma Reserved 9", 0, 0,
  4283. CNTR_NORMAL,
  4284. access_sdma_reserved_9_err_cnt),
  4285. [C_SDMA_PACKET_DESC_OVERFLOW_ERR] = CNTR_ELEM("SDmaPacketDescOverflowErr", 0, 0,
  4286. CNTR_NORMAL,
  4287. access_sdma_packet_desc_overflow_err_cnt),
  4288. [C_SDMA_LENGTH_MISMATCH_ERR] = CNTR_ELEM("SDmaLengthMismatchErr", 0, 0,
  4289. CNTR_NORMAL,
  4290. access_sdma_length_mismatch_err_cnt),
  4291. [C_SDMA_HALT_ERR] = CNTR_ELEM("SDmaHaltErr", 0, 0,
  4292. CNTR_NORMAL,
  4293. access_sdma_halt_err_cnt),
  4294. [C_SDMA_MEM_READ_ERR] = CNTR_ELEM("SDmaMemReadErr", 0, 0,
  4295. CNTR_NORMAL,
  4296. access_sdma_mem_read_err_cnt),
  4297. [C_SDMA_FIRST_DESC_ERR] = CNTR_ELEM("SDmaFirstDescErr", 0, 0,
  4298. CNTR_NORMAL,
  4299. access_sdma_first_desc_err_cnt),
  4300. [C_SDMA_TAIL_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("SDmaTailOutOfBoundsErr", 0, 0,
  4301. CNTR_NORMAL,
  4302. access_sdma_tail_out_of_bounds_err_cnt),
  4303. [C_SDMA_TOO_LONG_ERR] = CNTR_ELEM("SDmaTooLongErr", 0, 0,
  4304. CNTR_NORMAL,
  4305. access_sdma_too_long_err_cnt),
  4306. [C_SDMA_GEN_MISMATCH_ERR] = CNTR_ELEM("SDmaGenMismatchErr", 0, 0,
  4307. CNTR_NORMAL,
  4308. access_sdma_gen_mismatch_err_cnt),
  4309. [C_SDMA_WRONG_DW_ERR] = CNTR_ELEM("SDmaWrongDwErr", 0, 0,
  4310. CNTR_NORMAL,
  4311. access_sdma_wrong_dw_err_cnt),
  4312. };
  4313. static struct cntr_entry port_cntrs[PORT_CNTR_LAST] = {
  4314. [C_TX_UNSUP_VL] = TXE32_PORT_CNTR_ELEM(TxUnVLErr, SEND_UNSUP_VL_ERR_CNT,
  4315. CNTR_NORMAL),
  4316. [C_TX_INVAL_LEN] = TXE32_PORT_CNTR_ELEM(TxInvalLen, SEND_LEN_ERR_CNT,
  4317. CNTR_NORMAL),
  4318. [C_TX_MM_LEN_ERR] = TXE32_PORT_CNTR_ELEM(TxMMLenErr, SEND_MAX_MIN_LEN_ERR_CNT,
  4319. CNTR_NORMAL),
  4320. [C_TX_UNDERRUN] = TXE32_PORT_CNTR_ELEM(TxUnderrun, SEND_UNDERRUN_CNT,
  4321. CNTR_NORMAL),
  4322. [C_TX_FLOW_STALL] = TXE32_PORT_CNTR_ELEM(TxFlowStall, SEND_FLOW_STALL_CNT,
  4323. CNTR_NORMAL),
  4324. [C_TX_DROPPED] = TXE32_PORT_CNTR_ELEM(TxDropped, SEND_DROPPED_PKT_CNT,
  4325. CNTR_NORMAL),
  4326. [C_TX_HDR_ERR] = TXE32_PORT_CNTR_ELEM(TxHdrErr, SEND_HEADERS_ERR_CNT,
  4327. CNTR_NORMAL),
  4328. [C_TX_PKT] = TXE64_PORT_CNTR_ELEM(TxPkt, SEND_DATA_PKT_CNT, CNTR_NORMAL),
  4329. [C_TX_WORDS] = TXE64_PORT_CNTR_ELEM(TxWords, SEND_DWORD_CNT, CNTR_NORMAL),
  4330. [C_TX_WAIT] = TXE64_PORT_CNTR_ELEM(TxWait, SEND_WAIT_CNT, CNTR_SYNTH),
  4331. [C_TX_FLIT_VL] = TXE64_PORT_CNTR_ELEM(TxFlitVL, SEND_DATA_VL0_CNT,
  4332. CNTR_SYNTH | CNTR_VL),
  4333. [C_TX_PKT_VL] = TXE64_PORT_CNTR_ELEM(TxPktVL, SEND_DATA_PKT_VL0_CNT,
  4334. CNTR_SYNTH | CNTR_VL),
  4335. [C_TX_WAIT_VL] = TXE64_PORT_CNTR_ELEM(TxWaitVL, SEND_WAIT_VL0_CNT,
  4336. CNTR_SYNTH | CNTR_VL),
  4337. [C_RX_PKT] = RXE64_PORT_CNTR_ELEM(RxPkt, RCV_DATA_PKT_CNT, CNTR_NORMAL),
  4338. [C_RX_WORDS] = RXE64_PORT_CNTR_ELEM(RxWords, RCV_DWORD_CNT, CNTR_NORMAL),
  4339. [C_SW_LINK_DOWN] = CNTR_ELEM("SwLinkDown", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4340. access_sw_link_dn_cnt),
  4341. [C_SW_LINK_UP] = CNTR_ELEM("SwLinkUp", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4342. access_sw_link_up_cnt),
  4343. [C_SW_UNKNOWN_FRAME] = CNTR_ELEM("UnknownFrame", 0, 0, CNTR_NORMAL,
  4344. access_sw_unknown_frame_cnt),
  4345. [C_SW_XMIT_DSCD] = CNTR_ELEM("XmitDscd", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4346. access_sw_xmit_discards),
  4347. [C_SW_XMIT_DSCD_VL] = CNTR_ELEM("XmitDscdVl", 0, 0,
  4348. CNTR_SYNTH | CNTR_32BIT | CNTR_VL,
  4349. access_sw_xmit_discards),
  4350. [C_SW_XMIT_CSTR_ERR] = CNTR_ELEM("XmitCstrErr", 0, 0, CNTR_SYNTH,
  4351. access_xmit_constraint_errs),
  4352. [C_SW_RCV_CSTR_ERR] = CNTR_ELEM("RcvCstrErr", 0, 0, CNTR_SYNTH,
  4353. access_rcv_constraint_errs),
  4354. [C_SW_IBP_LOOP_PKTS] = SW_IBP_CNTR(LoopPkts, loop_pkts),
  4355. [C_SW_IBP_RC_RESENDS] = SW_IBP_CNTR(RcResend, rc_resends),
  4356. [C_SW_IBP_RNR_NAKS] = SW_IBP_CNTR(RnrNak, rnr_naks),
  4357. [C_SW_IBP_OTHER_NAKS] = SW_IBP_CNTR(OtherNak, other_naks),
  4358. [C_SW_IBP_RC_TIMEOUTS] = SW_IBP_CNTR(RcTimeOut, rc_timeouts),
  4359. [C_SW_IBP_PKT_DROPS] = SW_IBP_CNTR(PktDrop, pkt_drops),
  4360. [C_SW_IBP_DMA_WAIT] = SW_IBP_CNTR(DmaWait, dmawait),
  4361. [C_SW_IBP_RC_SEQNAK] = SW_IBP_CNTR(RcSeqNak, rc_seqnak),
  4362. [C_SW_IBP_RC_DUPREQ] = SW_IBP_CNTR(RcDupRew, rc_dupreq),
  4363. [C_SW_IBP_RDMA_SEQ] = SW_IBP_CNTR(RdmaSeq, rdma_seq),
  4364. [C_SW_IBP_UNALIGNED] = SW_IBP_CNTR(Unaligned, unaligned),
  4365. [C_SW_IBP_SEQ_NAK] = SW_IBP_CNTR(SeqNak, seq_naks),
  4366. [C_SW_CPU_RC_ACKS] = CNTR_ELEM("RcAcks", 0, 0, CNTR_NORMAL,
  4367. access_sw_cpu_rc_acks),
  4368. [C_SW_CPU_RC_QACKS] = CNTR_ELEM("RcQacks", 0, 0, CNTR_NORMAL,
  4369. access_sw_cpu_rc_qacks),
  4370. [C_SW_CPU_RC_DELAYED_COMP] = CNTR_ELEM("RcDelayComp", 0, 0, CNTR_NORMAL,
  4371. access_sw_cpu_rc_delayed_comp),
  4372. [OVR_LBL(0)] = OVR_ELM(0), [OVR_LBL(1)] = OVR_ELM(1),
  4373. [OVR_LBL(2)] = OVR_ELM(2), [OVR_LBL(3)] = OVR_ELM(3),
  4374. [OVR_LBL(4)] = OVR_ELM(4), [OVR_LBL(5)] = OVR_ELM(5),
  4375. [OVR_LBL(6)] = OVR_ELM(6), [OVR_LBL(7)] = OVR_ELM(7),
  4376. [OVR_LBL(8)] = OVR_ELM(8), [OVR_LBL(9)] = OVR_ELM(9),
  4377. [OVR_LBL(10)] = OVR_ELM(10), [OVR_LBL(11)] = OVR_ELM(11),
  4378. [OVR_LBL(12)] = OVR_ELM(12), [OVR_LBL(13)] = OVR_ELM(13),
  4379. [OVR_LBL(14)] = OVR_ELM(14), [OVR_LBL(15)] = OVR_ELM(15),
  4380. [OVR_LBL(16)] = OVR_ELM(16), [OVR_LBL(17)] = OVR_ELM(17),
  4381. [OVR_LBL(18)] = OVR_ELM(18), [OVR_LBL(19)] = OVR_ELM(19),
  4382. [OVR_LBL(20)] = OVR_ELM(20), [OVR_LBL(21)] = OVR_ELM(21),
  4383. [OVR_LBL(22)] = OVR_ELM(22), [OVR_LBL(23)] = OVR_ELM(23),
  4384. [OVR_LBL(24)] = OVR_ELM(24), [OVR_LBL(25)] = OVR_ELM(25),
  4385. [OVR_LBL(26)] = OVR_ELM(26), [OVR_LBL(27)] = OVR_ELM(27),
  4386. [OVR_LBL(28)] = OVR_ELM(28), [OVR_LBL(29)] = OVR_ELM(29),
  4387. [OVR_LBL(30)] = OVR_ELM(30), [OVR_LBL(31)] = OVR_ELM(31),
  4388. [OVR_LBL(32)] = OVR_ELM(32), [OVR_LBL(33)] = OVR_ELM(33),
  4389. [OVR_LBL(34)] = OVR_ELM(34), [OVR_LBL(35)] = OVR_ELM(35),
  4390. [OVR_LBL(36)] = OVR_ELM(36), [OVR_LBL(37)] = OVR_ELM(37),
  4391. [OVR_LBL(38)] = OVR_ELM(38), [OVR_LBL(39)] = OVR_ELM(39),
  4392. [OVR_LBL(40)] = OVR_ELM(40), [OVR_LBL(41)] = OVR_ELM(41),
  4393. [OVR_LBL(42)] = OVR_ELM(42), [OVR_LBL(43)] = OVR_ELM(43),
  4394. [OVR_LBL(44)] = OVR_ELM(44), [OVR_LBL(45)] = OVR_ELM(45),
  4395. [OVR_LBL(46)] = OVR_ELM(46), [OVR_LBL(47)] = OVR_ELM(47),
  4396. [OVR_LBL(48)] = OVR_ELM(48), [OVR_LBL(49)] = OVR_ELM(49),
  4397. [OVR_LBL(50)] = OVR_ELM(50), [OVR_LBL(51)] = OVR_ELM(51),
  4398. [OVR_LBL(52)] = OVR_ELM(52), [OVR_LBL(53)] = OVR_ELM(53),
  4399. [OVR_LBL(54)] = OVR_ELM(54), [OVR_LBL(55)] = OVR_ELM(55),
  4400. [OVR_LBL(56)] = OVR_ELM(56), [OVR_LBL(57)] = OVR_ELM(57),
  4401. [OVR_LBL(58)] = OVR_ELM(58), [OVR_LBL(59)] = OVR_ELM(59),
  4402. [OVR_LBL(60)] = OVR_ELM(60), [OVR_LBL(61)] = OVR_ELM(61),
  4403. [OVR_LBL(62)] = OVR_ELM(62), [OVR_LBL(63)] = OVR_ELM(63),
  4404. [OVR_LBL(64)] = OVR_ELM(64), [OVR_LBL(65)] = OVR_ELM(65),
  4405. [OVR_LBL(66)] = OVR_ELM(66), [OVR_LBL(67)] = OVR_ELM(67),
  4406. [OVR_LBL(68)] = OVR_ELM(68), [OVR_LBL(69)] = OVR_ELM(69),
  4407. [OVR_LBL(70)] = OVR_ELM(70), [OVR_LBL(71)] = OVR_ELM(71),
  4408. [OVR_LBL(72)] = OVR_ELM(72), [OVR_LBL(73)] = OVR_ELM(73),
  4409. [OVR_LBL(74)] = OVR_ELM(74), [OVR_LBL(75)] = OVR_ELM(75),
  4410. [OVR_LBL(76)] = OVR_ELM(76), [OVR_LBL(77)] = OVR_ELM(77),
  4411. [OVR_LBL(78)] = OVR_ELM(78), [OVR_LBL(79)] = OVR_ELM(79),
  4412. [OVR_LBL(80)] = OVR_ELM(80), [OVR_LBL(81)] = OVR_ELM(81),
  4413. [OVR_LBL(82)] = OVR_ELM(82), [OVR_LBL(83)] = OVR_ELM(83),
  4414. [OVR_LBL(84)] = OVR_ELM(84), [OVR_LBL(85)] = OVR_ELM(85),
  4415. [OVR_LBL(86)] = OVR_ELM(86), [OVR_LBL(87)] = OVR_ELM(87),
  4416. [OVR_LBL(88)] = OVR_ELM(88), [OVR_LBL(89)] = OVR_ELM(89),
  4417. [OVR_LBL(90)] = OVR_ELM(90), [OVR_LBL(91)] = OVR_ELM(91),
  4418. [OVR_LBL(92)] = OVR_ELM(92), [OVR_LBL(93)] = OVR_ELM(93),
  4419. [OVR_LBL(94)] = OVR_ELM(94), [OVR_LBL(95)] = OVR_ELM(95),
  4420. [OVR_LBL(96)] = OVR_ELM(96), [OVR_LBL(97)] = OVR_ELM(97),
  4421. [OVR_LBL(98)] = OVR_ELM(98), [OVR_LBL(99)] = OVR_ELM(99),
  4422. [OVR_LBL(100)] = OVR_ELM(100), [OVR_LBL(101)] = OVR_ELM(101),
  4423. [OVR_LBL(102)] = OVR_ELM(102), [OVR_LBL(103)] = OVR_ELM(103),
  4424. [OVR_LBL(104)] = OVR_ELM(104), [OVR_LBL(105)] = OVR_ELM(105),
  4425. [OVR_LBL(106)] = OVR_ELM(106), [OVR_LBL(107)] = OVR_ELM(107),
  4426. [OVR_LBL(108)] = OVR_ELM(108), [OVR_LBL(109)] = OVR_ELM(109),
  4427. [OVR_LBL(110)] = OVR_ELM(110), [OVR_LBL(111)] = OVR_ELM(111),
  4428. [OVR_LBL(112)] = OVR_ELM(112), [OVR_LBL(113)] = OVR_ELM(113),
  4429. [OVR_LBL(114)] = OVR_ELM(114), [OVR_LBL(115)] = OVR_ELM(115),
  4430. [OVR_LBL(116)] = OVR_ELM(116), [OVR_LBL(117)] = OVR_ELM(117),
  4431. [OVR_LBL(118)] = OVR_ELM(118), [OVR_LBL(119)] = OVR_ELM(119),
  4432. [OVR_LBL(120)] = OVR_ELM(120), [OVR_LBL(121)] = OVR_ELM(121),
  4433. [OVR_LBL(122)] = OVR_ELM(122), [OVR_LBL(123)] = OVR_ELM(123),
  4434. [OVR_LBL(124)] = OVR_ELM(124), [OVR_LBL(125)] = OVR_ELM(125),
  4435. [OVR_LBL(126)] = OVR_ELM(126), [OVR_LBL(127)] = OVR_ELM(127),
  4436. [OVR_LBL(128)] = OVR_ELM(128), [OVR_LBL(129)] = OVR_ELM(129),
  4437. [OVR_LBL(130)] = OVR_ELM(130), [OVR_LBL(131)] = OVR_ELM(131),
  4438. [OVR_LBL(132)] = OVR_ELM(132), [OVR_LBL(133)] = OVR_ELM(133),
  4439. [OVR_LBL(134)] = OVR_ELM(134), [OVR_LBL(135)] = OVR_ELM(135),
  4440. [OVR_LBL(136)] = OVR_ELM(136), [OVR_LBL(137)] = OVR_ELM(137),
  4441. [OVR_LBL(138)] = OVR_ELM(138), [OVR_LBL(139)] = OVR_ELM(139),
  4442. [OVR_LBL(140)] = OVR_ELM(140), [OVR_LBL(141)] = OVR_ELM(141),
  4443. [OVR_LBL(142)] = OVR_ELM(142), [OVR_LBL(143)] = OVR_ELM(143),
  4444. [OVR_LBL(144)] = OVR_ELM(144), [OVR_LBL(145)] = OVR_ELM(145),
  4445. [OVR_LBL(146)] = OVR_ELM(146), [OVR_LBL(147)] = OVR_ELM(147),
  4446. [OVR_LBL(148)] = OVR_ELM(148), [OVR_LBL(149)] = OVR_ELM(149),
  4447. [OVR_LBL(150)] = OVR_ELM(150), [OVR_LBL(151)] = OVR_ELM(151),
  4448. [OVR_LBL(152)] = OVR_ELM(152), [OVR_LBL(153)] = OVR_ELM(153),
  4449. [OVR_LBL(154)] = OVR_ELM(154), [OVR_LBL(155)] = OVR_ELM(155),
  4450. [OVR_LBL(156)] = OVR_ELM(156), [OVR_LBL(157)] = OVR_ELM(157),
  4451. [OVR_LBL(158)] = OVR_ELM(158), [OVR_LBL(159)] = OVR_ELM(159),
  4452. };
  4453. /* ======================================================================== */
  4454. /* return true if this is chip revision revision a */
  4455. int is_ax(struct hfi1_devdata *dd)
  4456. {
  4457. u8 chip_rev_minor =
  4458. dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
  4459. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  4460. return (chip_rev_minor & 0xf0) == 0;
  4461. }
  4462. /* return true if this is chip revision revision b */
  4463. int is_bx(struct hfi1_devdata *dd)
  4464. {
  4465. u8 chip_rev_minor =
  4466. dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
  4467. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  4468. return (chip_rev_minor & 0xF0) == 0x10;
  4469. }
  4470. /*
  4471. * Append string s to buffer buf. Arguments curp and len are the current
  4472. * position and remaining length, respectively.
  4473. *
  4474. * return 0 on success, 1 on out of room
  4475. */
  4476. static int append_str(char *buf, char **curp, int *lenp, const char *s)
  4477. {
  4478. char *p = *curp;
  4479. int len = *lenp;
  4480. int result = 0; /* success */
  4481. char c;
  4482. /* add a comma, if first in the buffer */
  4483. if (p != buf) {
  4484. if (len == 0) {
  4485. result = 1; /* out of room */
  4486. goto done;
  4487. }
  4488. *p++ = ',';
  4489. len--;
  4490. }
  4491. /* copy the string */
  4492. while ((c = *s++) != 0) {
  4493. if (len == 0) {
  4494. result = 1; /* out of room */
  4495. goto done;
  4496. }
  4497. *p++ = c;
  4498. len--;
  4499. }
  4500. done:
  4501. /* write return values */
  4502. *curp = p;
  4503. *lenp = len;
  4504. return result;
  4505. }
  4506. /*
  4507. * Using the given flag table, print a comma separated string into
  4508. * the buffer. End in '*' if the buffer is too short.
  4509. */
  4510. static char *flag_string(char *buf, int buf_len, u64 flags,
  4511. struct flag_table *table, int table_size)
  4512. {
  4513. char extra[32];
  4514. char *p = buf;
  4515. int len = buf_len;
  4516. int no_room = 0;
  4517. int i;
  4518. /* make sure there is at least 2 so we can form "*" */
  4519. if (len < 2)
  4520. return "";
  4521. len--; /* leave room for a nul */
  4522. for (i = 0; i < table_size; i++) {
  4523. if (flags & table[i].flag) {
  4524. no_room = append_str(buf, &p, &len, table[i].str);
  4525. if (no_room)
  4526. break;
  4527. flags &= ~table[i].flag;
  4528. }
  4529. }
  4530. /* any undocumented bits left? */
  4531. if (!no_room && flags) {
  4532. snprintf(extra, sizeof(extra), "bits 0x%llx", flags);
  4533. no_room = append_str(buf, &p, &len, extra);
  4534. }
  4535. /* add * if ran out of room */
  4536. if (no_room) {
  4537. /* may need to back up to add space for a '*' */
  4538. if (len == 0)
  4539. --p;
  4540. *p++ = '*';
  4541. }
  4542. /* add final nul - space already allocated above */
  4543. *p = 0;
  4544. return buf;
  4545. }
  4546. /* first 8 CCE error interrupt source names */
  4547. static const char * const cce_misc_names[] = {
  4548. "CceErrInt", /* 0 */
  4549. "RxeErrInt", /* 1 */
  4550. "MiscErrInt", /* 2 */
  4551. "Reserved3", /* 3 */
  4552. "PioErrInt", /* 4 */
  4553. "SDmaErrInt", /* 5 */
  4554. "EgressErrInt", /* 6 */
  4555. "TxeErrInt" /* 7 */
  4556. };
  4557. /*
  4558. * Return the miscellaneous error interrupt name.
  4559. */
  4560. static char *is_misc_err_name(char *buf, size_t bsize, unsigned int source)
  4561. {
  4562. if (source < ARRAY_SIZE(cce_misc_names))
  4563. strncpy(buf, cce_misc_names[source], bsize);
  4564. else
  4565. snprintf(buf, bsize, "Reserved%u",
  4566. source + IS_GENERAL_ERR_START);
  4567. return buf;
  4568. }
  4569. /*
  4570. * Return the SDMA engine error interrupt name.
  4571. */
  4572. static char *is_sdma_eng_err_name(char *buf, size_t bsize, unsigned int source)
  4573. {
  4574. snprintf(buf, bsize, "SDmaEngErrInt%u", source);
  4575. return buf;
  4576. }
  4577. /*
  4578. * Return the send context error interrupt name.
  4579. */
  4580. static char *is_sendctxt_err_name(char *buf, size_t bsize, unsigned int source)
  4581. {
  4582. snprintf(buf, bsize, "SendCtxtErrInt%u", source);
  4583. return buf;
  4584. }
  4585. static const char * const various_names[] = {
  4586. "PbcInt",
  4587. "GpioAssertInt",
  4588. "Qsfp1Int",
  4589. "Qsfp2Int",
  4590. "TCritInt"
  4591. };
  4592. /*
  4593. * Return the various interrupt name.
  4594. */
  4595. static char *is_various_name(char *buf, size_t bsize, unsigned int source)
  4596. {
  4597. if (source < ARRAY_SIZE(various_names))
  4598. strncpy(buf, various_names[source], bsize);
  4599. else
  4600. snprintf(buf, bsize, "Reserved%u", source + IS_VARIOUS_START);
  4601. return buf;
  4602. }
  4603. /*
  4604. * Return the DC interrupt name.
  4605. */
  4606. static char *is_dc_name(char *buf, size_t bsize, unsigned int source)
  4607. {
  4608. static const char * const dc_int_names[] = {
  4609. "common",
  4610. "lcb",
  4611. "8051",
  4612. "lbm" /* local block merge */
  4613. };
  4614. if (source < ARRAY_SIZE(dc_int_names))
  4615. snprintf(buf, bsize, "dc_%s_int", dc_int_names[source]);
  4616. else
  4617. snprintf(buf, bsize, "DCInt%u", source);
  4618. return buf;
  4619. }
  4620. static const char * const sdma_int_names[] = {
  4621. "SDmaInt",
  4622. "SdmaIdleInt",
  4623. "SdmaProgressInt",
  4624. };
  4625. /*
  4626. * Return the SDMA engine interrupt name.
  4627. */
  4628. static char *is_sdma_eng_name(char *buf, size_t bsize, unsigned int source)
  4629. {
  4630. /* what interrupt */
  4631. unsigned int what = source / TXE_NUM_SDMA_ENGINES;
  4632. /* which engine */
  4633. unsigned int which = source % TXE_NUM_SDMA_ENGINES;
  4634. if (likely(what < 3))
  4635. snprintf(buf, bsize, "%s%u", sdma_int_names[what], which);
  4636. else
  4637. snprintf(buf, bsize, "Invalid SDMA interrupt %u", source);
  4638. return buf;
  4639. }
  4640. /*
  4641. * Return the receive available interrupt name.
  4642. */
  4643. static char *is_rcv_avail_name(char *buf, size_t bsize, unsigned int source)
  4644. {
  4645. snprintf(buf, bsize, "RcvAvailInt%u", source);
  4646. return buf;
  4647. }
  4648. /*
  4649. * Return the receive urgent interrupt name.
  4650. */
  4651. static char *is_rcv_urgent_name(char *buf, size_t bsize, unsigned int source)
  4652. {
  4653. snprintf(buf, bsize, "RcvUrgentInt%u", source);
  4654. return buf;
  4655. }
  4656. /*
  4657. * Return the send credit interrupt name.
  4658. */
  4659. static char *is_send_credit_name(char *buf, size_t bsize, unsigned int source)
  4660. {
  4661. snprintf(buf, bsize, "SendCreditInt%u", source);
  4662. return buf;
  4663. }
  4664. /*
  4665. * Return the reserved interrupt name.
  4666. */
  4667. static char *is_reserved_name(char *buf, size_t bsize, unsigned int source)
  4668. {
  4669. snprintf(buf, bsize, "Reserved%u", source + IS_RESERVED_START);
  4670. return buf;
  4671. }
  4672. static char *cce_err_status_string(char *buf, int buf_len, u64 flags)
  4673. {
  4674. return flag_string(buf, buf_len, flags,
  4675. cce_err_status_flags,
  4676. ARRAY_SIZE(cce_err_status_flags));
  4677. }
  4678. static char *rxe_err_status_string(char *buf, int buf_len, u64 flags)
  4679. {
  4680. return flag_string(buf, buf_len, flags,
  4681. rxe_err_status_flags,
  4682. ARRAY_SIZE(rxe_err_status_flags));
  4683. }
  4684. static char *misc_err_status_string(char *buf, int buf_len, u64 flags)
  4685. {
  4686. return flag_string(buf, buf_len, flags, misc_err_status_flags,
  4687. ARRAY_SIZE(misc_err_status_flags));
  4688. }
  4689. static char *pio_err_status_string(char *buf, int buf_len, u64 flags)
  4690. {
  4691. return flag_string(buf, buf_len, flags,
  4692. pio_err_status_flags,
  4693. ARRAY_SIZE(pio_err_status_flags));
  4694. }
  4695. static char *sdma_err_status_string(char *buf, int buf_len, u64 flags)
  4696. {
  4697. return flag_string(buf, buf_len, flags,
  4698. sdma_err_status_flags,
  4699. ARRAY_SIZE(sdma_err_status_flags));
  4700. }
  4701. static char *egress_err_status_string(char *buf, int buf_len, u64 flags)
  4702. {
  4703. return flag_string(buf, buf_len, flags,
  4704. egress_err_status_flags,
  4705. ARRAY_SIZE(egress_err_status_flags));
  4706. }
  4707. static char *egress_err_info_string(char *buf, int buf_len, u64 flags)
  4708. {
  4709. return flag_string(buf, buf_len, flags,
  4710. egress_err_info_flags,
  4711. ARRAY_SIZE(egress_err_info_flags));
  4712. }
  4713. static char *send_err_status_string(char *buf, int buf_len, u64 flags)
  4714. {
  4715. return flag_string(buf, buf_len, flags,
  4716. send_err_status_flags,
  4717. ARRAY_SIZE(send_err_status_flags));
  4718. }
  4719. static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4720. {
  4721. char buf[96];
  4722. int i = 0;
  4723. /*
  4724. * For most these errors, there is nothing that can be done except
  4725. * report or record it.
  4726. */
  4727. dd_dev_info(dd, "CCE Error: %s\n",
  4728. cce_err_status_string(buf, sizeof(buf), reg));
  4729. if ((reg & CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK) &&
  4730. is_ax(dd) && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)) {
  4731. /* this error requires a manual drop into SPC freeze mode */
  4732. /* then a fix up */
  4733. start_freeze_handling(dd->pport, FREEZE_SELF);
  4734. }
  4735. for (i = 0; i < NUM_CCE_ERR_STATUS_COUNTERS; i++) {
  4736. if (reg & (1ull << i)) {
  4737. incr_cntr64(&dd->cce_err_status_cnt[i]);
  4738. /* maintain a counter over all cce_err_status errors */
  4739. incr_cntr64(&dd->sw_cce_err_status_aggregate);
  4740. }
  4741. }
  4742. }
  4743. /*
  4744. * Check counters for receive errors that do not have an interrupt
  4745. * associated with them.
  4746. */
  4747. #define RCVERR_CHECK_TIME 10
  4748. static void update_rcverr_timer(unsigned long opaque)
  4749. {
  4750. struct hfi1_devdata *dd = (struct hfi1_devdata *)opaque;
  4751. struct hfi1_pportdata *ppd = dd->pport;
  4752. u32 cur_ovfl_cnt = read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL);
  4753. if (dd->rcv_ovfl_cnt < cur_ovfl_cnt &&
  4754. ppd->port_error_action & OPA_PI_MASK_EX_BUFFER_OVERRUN) {
  4755. dd_dev_info(dd, "%s: PortErrorAction bounce\n", __func__);
  4756. set_link_down_reason(
  4757. ppd, OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN, 0,
  4758. OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN);
  4759. queue_work(ppd->hfi1_wq, &ppd->link_bounce_work);
  4760. }
  4761. dd->rcv_ovfl_cnt = (u32)cur_ovfl_cnt;
  4762. mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
  4763. }
  4764. static int init_rcverr(struct hfi1_devdata *dd)
  4765. {
  4766. setup_timer(&dd->rcverr_timer, update_rcverr_timer, (unsigned long)dd);
  4767. /* Assume the hardware counter has been reset */
  4768. dd->rcv_ovfl_cnt = 0;
  4769. return mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
  4770. }
  4771. static void free_rcverr(struct hfi1_devdata *dd)
  4772. {
  4773. if (dd->rcverr_timer.data)
  4774. del_timer_sync(&dd->rcverr_timer);
  4775. dd->rcverr_timer.data = 0;
  4776. }
  4777. static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4778. {
  4779. char buf[96];
  4780. int i = 0;
  4781. dd_dev_info(dd, "Receive Error: %s\n",
  4782. rxe_err_status_string(buf, sizeof(buf), reg));
  4783. if (reg & ALL_RXE_FREEZE_ERR) {
  4784. int flags = 0;
  4785. /*
  4786. * Freeze mode recovery is disabled for the errors
  4787. * in RXE_FREEZE_ABORT_MASK
  4788. */
  4789. if (is_ax(dd) && (reg & RXE_FREEZE_ABORT_MASK))
  4790. flags = FREEZE_ABORT;
  4791. start_freeze_handling(dd->pport, flags);
  4792. }
  4793. for (i = 0; i < NUM_RCV_ERR_STATUS_COUNTERS; i++) {
  4794. if (reg & (1ull << i))
  4795. incr_cntr64(&dd->rcv_err_status_cnt[i]);
  4796. }
  4797. }
  4798. static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4799. {
  4800. char buf[96];
  4801. int i = 0;
  4802. dd_dev_info(dd, "Misc Error: %s",
  4803. misc_err_status_string(buf, sizeof(buf), reg));
  4804. for (i = 0; i < NUM_MISC_ERR_STATUS_COUNTERS; i++) {
  4805. if (reg & (1ull << i))
  4806. incr_cntr64(&dd->misc_err_status_cnt[i]);
  4807. }
  4808. }
  4809. static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4810. {
  4811. char buf[96];
  4812. int i = 0;
  4813. dd_dev_info(dd, "PIO Error: %s\n",
  4814. pio_err_status_string(buf, sizeof(buf), reg));
  4815. if (reg & ALL_PIO_FREEZE_ERR)
  4816. start_freeze_handling(dd->pport, 0);
  4817. for (i = 0; i < NUM_SEND_PIO_ERR_STATUS_COUNTERS; i++) {
  4818. if (reg & (1ull << i))
  4819. incr_cntr64(&dd->send_pio_err_status_cnt[i]);
  4820. }
  4821. }
  4822. static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4823. {
  4824. char buf[96];
  4825. int i = 0;
  4826. dd_dev_info(dd, "SDMA Error: %s\n",
  4827. sdma_err_status_string(buf, sizeof(buf), reg));
  4828. if (reg & ALL_SDMA_FREEZE_ERR)
  4829. start_freeze_handling(dd->pport, 0);
  4830. for (i = 0; i < NUM_SEND_DMA_ERR_STATUS_COUNTERS; i++) {
  4831. if (reg & (1ull << i))
  4832. incr_cntr64(&dd->send_dma_err_status_cnt[i]);
  4833. }
  4834. }
  4835. static inline void __count_port_discards(struct hfi1_pportdata *ppd)
  4836. {
  4837. incr_cntr64(&ppd->port_xmit_discards);
  4838. }
  4839. static void count_port_inactive(struct hfi1_devdata *dd)
  4840. {
  4841. __count_port_discards(dd->pport);
  4842. }
  4843. /*
  4844. * We have had a "disallowed packet" error during egress. Determine the
  4845. * integrity check which failed, and update relevant error counter, etc.
  4846. *
  4847. * Note that the SEND_EGRESS_ERR_INFO register has only a single
  4848. * bit of state per integrity check, and so we can miss the reason for an
  4849. * egress error if more than one packet fails the same integrity check
  4850. * since we cleared the corresponding bit in SEND_EGRESS_ERR_INFO.
  4851. */
  4852. static void handle_send_egress_err_info(struct hfi1_devdata *dd,
  4853. int vl)
  4854. {
  4855. struct hfi1_pportdata *ppd = dd->pport;
  4856. u64 src = read_csr(dd, SEND_EGRESS_ERR_SOURCE); /* read first */
  4857. u64 info = read_csr(dd, SEND_EGRESS_ERR_INFO);
  4858. char buf[96];
  4859. /* clear down all observed info as quickly as possible after read */
  4860. write_csr(dd, SEND_EGRESS_ERR_INFO, info);
  4861. dd_dev_info(dd,
  4862. "Egress Error Info: 0x%llx, %s Egress Error Src 0x%llx\n",
  4863. info, egress_err_info_string(buf, sizeof(buf), info), src);
  4864. /* Eventually add other counters for each bit */
  4865. if (info & PORT_DISCARD_EGRESS_ERRS) {
  4866. int weight, i;
  4867. /*
  4868. * Count all applicable bits as individual errors and
  4869. * attribute them to the packet that triggered this handler.
  4870. * This may not be completely accurate due to limitations
  4871. * on the available hardware error information. There is
  4872. * a single information register and any number of error
  4873. * packets may have occurred and contributed to it before
  4874. * this routine is called. This means that:
  4875. * a) If multiple packets with the same error occur before
  4876. * this routine is called, earlier packets are missed.
  4877. * There is only a single bit for each error type.
  4878. * b) Errors may not be attributed to the correct VL.
  4879. * The driver is attributing all bits in the info register
  4880. * to the packet that triggered this call, but bits
  4881. * could be an accumulation of different packets with
  4882. * different VLs.
  4883. * c) A single error packet may have multiple counts attached
  4884. * to it. There is no way for the driver to know if
  4885. * multiple bits set in the info register are due to a
  4886. * single packet or multiple packets. The driver assumes
  4887. * multiple packets.
  4888. */
  4889. weight = hweight64(info & PORT_DISCARD_EGRESS_ERRS);
  4890. for (i = 0; i < weight; i++) {
  4891. __count_port_discards(ppd);
  4892. if (vl >= 0 && vl < TXE_NUM_DATA_VL)
  4893. incr_cntr64(&ppd->port_xmit_discards_vl[vl]);
  4894. else if (vl == 15)
  4895. incr_cntr64(&ppd->port_xmit_discards_vl
  4896. [C_VL_15]);
  4897. }
  4898. }
  4899. }
  4900. /*
  4901. * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
  4902. * register. Does it represent a 'port inactive' error?
  4903. */
  4904. static inline int port_inactive_err(u64 posn)
  4905. {
  4906. return (posn >= SEES(TX_LINKDOWN) &&
  4907. posn <= SEES(TX_INCORRECT_LINK_STATE));
  4908. }
  4909. /*
  4910. * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
  4911. * register. Does it represent a 'disallowed packet' error?
  4912. */
  4913. static inline int disallowed_pkt_err(int posn)
  4914. {
  4915. return (posn >= SEES(TX_SDMA0_DISALLOWED_PACKET) &&
  4916. posn <= SEES(TX_SDMA15_DISALLOWED_PACKET));
  4917. }
  4918. /*
  4919. * Input value is a bit position of one of the SDMA engine disallowed
  4920. * packet errors. Return which engine. Use of this must be guarded by
  4921. * disallowed_pkt_err().
  4922. */
  4923. static inline int disallowed_pkt_engine(int posn)
  4924. {
  4925. return posn - SEES(TX_SDMA0_DISALLOWED_PACKET);
  4926. }
  4927. /*
  4928. * Translate an SDMA engine to a VL. Return -1 if the tranlation cannot
  4929. * be done.
  4930. */
  4931. static int engine_to_vl(struct hfi1_devdata *dd, int engine)
  4932. {
  4933. struct sdma_vl_map *m;
  4934. int vl;
  4935. /* range check */
  4936. if (engine < 0 || engine >= TXE_NUM_SDMA_ENGINES)
  4937. return -1;
  4938. rcu_read_lock();
  4939. m = rcu_dereference(dd->sdma_map);
  4940. vl = m->engine_to_vl[engine];
  4941. rcu_read_unlock();
  4942. return vl;
  4943. }
  4944. /*
  4945. * Translate the send context (sofware index) into a VL. Return -1 if the
  4946. * translation cannot be done.
  4947. */
  4948. static int sc_to_vl(struct hfi1_devdata *dd, int sw_index)
  4949. {
  4950. struct send_context_info *sci;
  4951. struct send_context *sc;
  4952. int i;
  4953. sci = &dd->send_contexts[sw_index];
  4954. /* there is no information for user (PSM) and ack contexts */
  4955. if ((sci->type != SC_KERNEL) && (sci->type != SC_VL15))
  4956. return -1;
  4957. sc = sci->sc;
  4958. if (!sc)
  4959. return -1;
  4960. if (dd->vld[15].sc == sc)
  4961. return 15;
  4962. for (i = 0; i < num_vls; i++)
  4963. if (dd->vld[i].sc == sc)
  4964. return i;
  4965. return -1;
  4966. }
  4967. static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4968. {
  4969. u64 reg_copy = reg, handled = 0;
  4970. char buf[96];
  4971. int i = 0;
  4972. if (reg & ALL_TXE_EGRESS_FREEZE_ERR)
  4973. start_freeze_handling(dd->pport, 0);
  4974. else if (is_ax(dd) &&
  4975. (reg & SEND_EGRESS_ERR_STATUS_TX_CREDIT_RETURN_VL_ERR_SMASK) &&
  4976. (dd->icode != ICODE_FUNCTIONAL_SIMULATOR))
  4977. start_freeze_handling(dd->pport, 0);
  4978. while (reg_copy) {
  4979. int posn = fls64(reg_copy);
  4980. /* fls64() returns a 1-based offset, we want it zero based */
  4981. int shift = posn - 1;
  4982. u64 mask = 1ULL << shift;
  4983. if (port_inactive_err(shift)) {
  4984. count_port_inactive(dd);
  4985. handled |= mask;
  4986. } else if (disallowed_pkt_err(shift)) {
  4987. int vl = engine_to_vl(dd, disallowed_pkt_engine(shift));
  4988. handle_send_egress_err_info(dd, vl);
  4989. handled |= mask;
  4990. }
  4991. reg_copy &= ~mask;
  4992. }
  4993. reg &= ~handled;
  4994. if (reg)
  4995. dd_dev_info(dd, "Egress Error: %s\n",
  4996. egress_err_status_string(buf, sizeof(buf), reg));
  4997. for (i = 0; i < NUM_SEND_EGRESS_ERR_STATUS_COUNTERS; i++) {
  4998. if (reg & (1ull << i))
  4999. incr_cntr64(&dd->send_egress_err_status_cnt[i]);
  5000. }
  5001. }
  5002. static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  5003. {
  5004. char buf[96];
  5005. int i = 0;
  5006. dd_dev_info(dd, "Send Error: %s\n",
  5007. send_err_status_string(buf, sizeof(buf), reg));
  5008. for (i = 0; i < NUM_SEND_ERR_STATUS_COUNTERS; i++) {
  5009. if (reg & (1ull << i))
  5010. incr_cntr64(&dd->send_err_status_cnt[i]);
  5011. }
  5012. }
  5013. /*
  5014. * The maximum number of times the error clear down will loop before
  5015. * blocking a repeating error. This value is arbitrary.
  5016. */
  5017. #define MAX_CLEAR_COUNT 20
  5018. /*
  5019. * Clear and handle an error register. All error interrupts are funneled
  5020. * through here to have a central location to correctly handle single-
  5021. * or multi-shot errors.
  5022. *
  5023. * For non per-context registers, call this routine with a context value
  5024. * of 0 so the per-context offset is zero.
  5025. *
  5026. * If the handler loops too many times, assume that something is wrong
  5027. * and can't be fixed, so mask the error bits.
  5028. */
  5029. static void interrupt_clear_down(struct hfi1_devdata *dd,
  5030. u32 context,
  5031. const struct err_reg_info *eri)
  5032. {
  5033. u64 reg;
  5034. u32 count;
  5035. /* read in a loop until no more errors are seen */
  5036. count = 0;
  5037. while (1) {
  5038. reg = read_kctxt_csr(dd, context, eri->status);
  5039. if (reg == 0)
  5040. break;
  5041. write_kctxt_csr(dd, context, eri->clear, reg);
  5042. if (likely(eri->handler))
  5043. eri->handler(dd, context, reg);
  5044. count++;
  5045. if (count > MAX_CLEAR_COUNT) {
  5046. u64 mask;
  5047. dd_dev_err(dd, "Repeating %s bits 0x%llx - masking\n",
  5048. eri->desc, reg);
  5049. /*
  5050. * Read-modify-write so any other masked bits
  5051. * remain masked.
  5052. */
  5053. mask = read_kctxt_csr(dd, context, eri->mask);
  5054. mask &= ~reg;
  5055. write_kctxt_csr(dd, context, eri->mask, mask);
  5056. break;
  5057. }
  5058. }
  5059. }
  5060. /*
  5061. * CCE block "misc" interrupt. Source is < 16.
  5062. */
  5063. static void is_misc_err_int(struct hfi1_devdata *dd, unsigned int source)
  5064. {
  5065. const struct err_reg_info *eri = &misc_errs[source];
  5066. if (eri->handler) {
  5067. interrupt_clear_down(dd, 0, eri);
  5068. } else {
  5069. dd_dev_err(dd, "Unexpected misc interrupt (%u) - reserved\n",
  5070. source);
  5071. }
  5072. }
  5073. static char *send_context_err_status_string(char *buf, int buf_len, u64 flags)
  5074. {
  5075. return flag_string(buf, buf_len, flags,
  5076. sc_err_status_flags,
  5077. ARRAY_SIZE(sc_err_status_flags));
  5078. }
  5079. /*
  5080. * Send context error interrupt. Source (hw_context) is < 160.
  5081. *
  5082. * All send context errors cause the send context to halt. The normal
  5083. * clear-down mechanism cannot be used because we cannot clear the
  5084. * error bits until several other long-running items are done first.
  5085. * This is OK because with the context halted, nothing else is going
  5086. * to happen on it anyway.
  5087. */
  5088. static void is_sendctxt_err_int(struct hfi1_devdata *dd,
  5089. unsigned int hw_context)
  5090. {
  5091. struct send_context_info *sci;
  5092. struct send_context *sc;
  5093. char flags[96];
  5094. u64 status;
  5095. u32 sw_index;
  5096. int i = 0;
  5097. sw_index = dd->hw_to_sw[hw_context];
  5098. if (sw_index >= dd->num_send_contexts) {
  5099. dd_dev_err(dd,
  5100. "out of range sw index %u for send context %u\n",
  5101. sw_index, hw_context);
  5102. return;
  5103. }
  5104. sci = &dd->send_contexts[sw_index];
  5105. sc = sci->sc;
  5106. if (!sc) {
  5107. dd_dev_err(dd, "%s: context %u(%u): no sc?\n", __func__,
  5108. sw_index, hw_context);
  5109. return;
  5110. }
  5111. /* tell the software that a halt has begun */
  5112. sc_stop(sc, SCF_HALTED);
  5113. status = read_kctxt_csr(dd, hw_context, SEND_CTXT_ERR_STATUS);
  5114. dd_dev_info(dd, "Send Context %u(%u) Error: %s\n", sw_index, hw_context,
  5115. send_context_err_status_string(flags, sizeof(flags),
  5116. status));
  5117. if (status & SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK)
  5118. handle_send_egress_err_info(dd, sc_to_vl(dd, sw_index));
  5119. /*
  5120. * Automatically restart halted kernel contexts out of interrupt
  5121. * context. User contexts must ask the driver to restart the context.
  5122. */
  5123. if (sc->type != SC_USER)
  5124. queue_work(dd->pport->hfi1_wq, &sc->halt_work);
  5125. /*
  5126. * Update the counters for the corresponding status bits.
  5127. * Note that these particular counters are aggregated over all
  5128. * 160 contexts.
  5129. */
  5130. for (i = 0; i < NUM_SEND_CTXT_ERR_STATUS_COUNTERS; i++) {
  5131. if (status & (1ull << i))
  5132. incr_cntr64(&dd->sw_ctxt_err_status_cnt[i]);
  5133. }
  5134. }
  5135. static void handle_sdma_eng_err(struct hfi1_devdata *dd,
  5136. unsigned int source, u64 status)
  5137. {
  5138. struct sdma_engine *sde;
  5139. int i = 0;
  5140. sde = &dd->per_sdma[source];
  5141. #ifdef CONFIG_SDMA_VERBOSITY
  5142. dd_dev_err(sde->dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  5143. slashstrip(__FILE__), __LINE__, __func__);
  5144. dd_dev_err(sde->dd, "CONFIG SDMA(%u) source: %u status 0x%llx\n",
  5145. sde->this_idx, source, (unsigned long long)status);
  5146. #endif
  5147. sde->err_cnt++;
  5148. sdma_engine_error(sde, status);
  5149. /*
  5150. * Update the counters for the corresponding status bits.
  5151. * Note that these particular counters are aggregated over
  5152. * all 16 DMA engines.
  5153. */
  5154. for (i = 0; i < NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS; i++) {
  5155. if (status & (1ull << i))
  5156. incr_cntr64(&dd->sw_send_dma_eng_err_status_cnt[i]);
  5157. }
  5158. }
  5159. /*
  5160. * CCE block SDMA error interrupt. Source is < 16.
  5161. */
  5162. static void is_sdma_eng_err_int(struct hfi1_devdata *dd, unsigned int source)
  5163. {
  5164. #ifdef CONFIG_SDMA_VERBOSITY
  5165. struct sdma_engine *sde = &dd->per_sdma[source];
  5166. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  5167. slashstrip(__FILE__), __LINE__, __func__);
  5168. dd_dev_err(dd, "CONFIG SDMA(%u) source: %u\n", sde->this_idx,
  5169. source);
  5170. sdma_dumpstate(sde);
  5171. #endif
  5172. interrupt_clear_down(dd, source, &sdma_eng_err);
  5173. }
  5174. /*
  5175. * CCE block "various" interrupt. Source is < 8.
  5176. */
  5177. static void is_various_int(struct hfi1_devdata *dd, unsigned int source)
  5178. {
  5179. const struct err_reg_info *eri = &various_err[source];
  5180. /*
  5181. * TCritInt cannot go through interrupt_clear_down()
  5182. * because it is not a second tier interrupt. The handler
  5183. * should be called directly.
  5184. */
  5185. if (source == TCRIT_INT_SOURCE)
  5186. handle_temp_err(dd);
  5187. else if (eri->handler)
  5188. interrupt_clear_down(dd, 0, eri);
  5189. else
  5190. dd_dev_info(dd,
  5191. "%s: Unimplemented/reserved interrupt %d\n",
  5192. __func__, source);
  5193. }
  5194. static void handle_qsfp_int(struct hfi1_devdata *dd, u32 src_ctx, u64 reg)
  5195. {
  5196. /* src_ctx is always zero */
  5197. struct hfi1_pportdata *ppd = dd->pport;
  5198. unsigned long flags;
  5199. u64 qsfp_int_mgmt = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
  5200. if (reg & QSFP_HFI0_MODPRST_N) {
  5201. if (!qsfp_mod_present(ppd)) {
  5202. dd_dev_info(dd, "%s: QSFP module removed\n",
  5203. __func__);
  5204. ppd->driver_link_ready = 0;
  5205. /*
  5206. * Cable removed, reset all our information about the
  5207. * cache and cable capabilities
  5208. */
  5209. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5210. /*
  5211. * We don't set cache_refresh_required here as we expect
  5212. * an interrupt when a cable is inserted
  5213. */
  5214. ppd->qsfp_info.cache_valid = 0;
  5215. ppd->qsfp_info.reset_needed = 0;
  5216. ppd->qsfp_info.limiting_active = 0;
  5217. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  5218. flags);
  5219. /* Invert the ModPresent pin now to detect plug-in */
  5220. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
  5221. ASIC_QSFP1_INVERT, qsfp_int_mgmt);
  5222. if ((ppd->offline_disabled_reason >
  5223. HFI1_ODR_MASK(
  5224. OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED)) ||
  5225. (ppd->offline_disabled_reason ==
  5226. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE)))
  5227. ppd->offline_disabled_reason =
  5228. HFI1_ODR_MASK(
  5229. OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED);
  5230. if (ppd->host_link_state == HLS_DN_POLL) {
  5231. /*
  5232. * The link is still in POLL. This means
  5233. * that the normal link down processing
  5234. * will not happen. We have to do it here
  5235. * before turning the DC off.
  5236. */
  5237. queue_work(ppd->hfi1_wq, &ppd->link_down_work);
  5238. }
  5239. } else {
  5240. dd_dev_info(dd, "%s: QSFP module inserted\n",
  5241. __func__);
  5242. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5243. ppd->qsfp_info.cache_valid = 0;
  5244. ppd->qsfp_info.cache_refresh_required = 1;
  5245. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  5246. flags);
  5247. /*
  5248. * Stop inversion of ModPresent pin to detect
  5249. * removal of the cable
  5250. */
  5251. qsfp_int_mgmt &= ~(u64)QSFP_HFI0_MODPRST_N;
  5252. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
  5253. ASIC_QSFP1_INVERT, qsfp_int_mgmt);
  5254. ppd->offline_disabled_reason =
  5255. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
  5256. }
  5257. }
  5258. if (reg & QSFP_HFI0_INT_N) {
  5259. dd_dev_info(dd, "%s: Interrupt received from QSFP module\n",
  5260. __func__);
  5261. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5262. ppd->qsfp_info.check_interrupt_flags = 1;
  5263. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, flags);
  5264. }
  5265. /* Schedule the QSFP work only if there is a cable attached. */
  5266. if (qsfp_mod_present(ppd))
  5267. queue_work(ppd->hfi1_wq, &ppd->qsfp_info.qsfp_work);
  5268. }
  5269. static int request_host_lcb_access(struct hfi1_devdata *dd)
  5270. {
  5271. int ret;
  5272. ret = do_8051_command(dd, HCMD_MISC,
  5273. (u64)HCMD_MISC_REQUEST_LCB_ACCESS <<
  5274. LOAD_DATA_FIELD_ID_SHIFT, NULL);
  5275. if (ret != HCMD_SUCCESS) {
  5276. dd_dev_err(dd, "%s: command failed with error %d\n",
  5277. __func__, ret);
  5278. }
  5279. return ret == HCMD_SUCCESS ? 0 : -EBUSY;
  5280. }
  5281. static int request_8051_lcb_access(struct hfi1_devdata *dd)
  5282. {
  5283. int ret;
  5284. ret = do_8051_command(dd, HCMD_MISC,
  5285. (u64)HCMD_MISC_GRANT_LCB_ACCESS <<
  5286. LOAD_DATA_FIELD_ID_SHIFT, NULL);
  5287. if (ret != HCMD_SUCCESS) {
  5288. dd_dev_err(dd, "%s: command failed with error %d\n",
  5289. __func__, ret);
  5290. }
  5291. return ret == HCMD_SUCCESS ? 0 : -EBUSY;
  5292. }
  5293. /*
  5294. * Set the LCB selector - allow host access. The DCC selector always
  5295. * points to the host.
  5296. */
  5297. static inline void set_host_lcb_access(struct hfi1_devdata *dd)
  5298. {
  5299. write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
  5300. DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK |
  5301. DC_DC8051_CFG_CSR_ACCESS_SEL_LCB_SMASK);
  5302. }
  5303. /*
  5304. * Clear the LCB selector - allow 8051 access. The DCC selector always
  5305. * points to the host.
  5306. */
  5307. static inline void set_8051_lcb_access(struct hfi1_devdata *dd)
  5308. {
  5309. write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
  5310. DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK);
  5311. }
  5312. /*
  5313. * Acquire LCB access from the 8051. If the host already has access,
  5314. * just increment a counter. Otherwise, inform the 8051 that the
  5315. * host is taking access.
  5316. *
  5317. * Returns:
  5318. * 0 on success
  5319. * -EBUSY if the 8051 has control and cannot be disturbed
  5320. * -errno if unable to acquire access from the 8051
  5321. */
  5322. int acquire_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
  5323. {
  5324. struct hfi1_pportdata *ppd = dd->pport;
  5325. int ret = 0;
  5326. /*
  5327. * Use the host link state lock so the operation of this routine
  5328. * { link state check, selector change, count increment } can occur
  5329. * as a unit against a link state change. Otherwise there is a
  5330. * race between the state change and the count increment.
  5331. */
  5332. if (sleep_ok) {
  5333. mutex_lock(&ppd->hls_lock);
  5334. } else {
  5335. while (!mutex_trylock(&ppd->hls_lock))
  5336. udelay(1);
  5337. }
  5338. /* this access is valid only when the link is up */
  5339. if (ppd->host_link_state & HLS_DOWN) {
  5340. dd_dev_info(dd, "%s: link state %s not up\n",
  5341. __func__, link_state_name(ppd->host_link_state));
  5342. ret = -EBUSY;
  5343. goto done;
  5344. }
  5345. if (dd->lcb_access_count == 0) {
  5346. ret = request_host_lcb_access(dd);
  5347. if (ret) {
  5348. dd_dev_err(dd,
  5349. "%s: unable to acquire LCB access, err %d\n",
  5350. __func__, ret);
  5351. goto done;
  5352. }
  5353. set_host_lcb_access(dd);
  5354. }
  5355. dd->lcb_access_count++;
  5356. done:
  5357. mutex_unlock(&ppd->hls_lock);
  5358. return ret;
  5359. }
  5360. /*
  5361. * Release LCB access by decrementing the use count. If the count is moving
  5362. * from 1 to 0, inform 8051 that it has control back.
  5363. *
  5364. * Returns:
  5365. * 0 on success
  5366. * -errno if unable to release access to the 8051
  5367. */
  5368. int release_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
  5369. {
  5370. int ret = 0;
  5371. /*
  5372. * Use the host link state lock because the acquire needed it.
  5373. * Here, we only need to keep { selector change, count decrement }
  5374. * as a unit.
  5375. */
  5376. if (sleep_ok) {
  5377. mutex_lock(&dd->pport->hls_lock);
  5378. } else {
  5379. while (!mutex_trylock(&dd->pport->hls_lock))
  5380. udelay(1);
  5381. }
  5382. if (dd->lcb_access_count == 0) {
  5383. dd_dev_err(dd, "%s: LCB access count is zero. Skipping.\n",
  5384. __func__);
  5385. goto done;
  5386. }
  5387. if (dd->lcb_access_count == 1) {
  5388. set_8051_lcb_access(dd);
  5389. ret = request_8051_lcb_access(dd);
  5390. if (ret) {
  5391. dd_dev_err(dd,
  5392. "%s: unable to release LCB access, err %d\n",
  5393. __func__, ret);
  5394. /* restore host access if the grant didn't work */
  5395. set_host_lcb_access(dd);
  5396. goto done;
  5397. }
  5398. }
  5399. dd->lcb_access_count--;
  5400. done:
  5401. mutex_unlock(&dd->pport->hls_lock);
  5402. return ret;
  5403. }
  5404. /*
  5405. * Initialize LCB access variables and state. Called during driver load,
  5406. * after most of the initialization is finished.
  5407. *
  5408. * The DC default is LCB access on for the host. The driver defaults to
  5409. * leaving access to the 8051. Assign access now - this constrains the call
  5410. * to this routine to be after all LCB set-up is done. In particular, after
  5411. * hf1_init_dd() -> set_up_interrupts() -> clear_all_interrupts()
  5412. */
  5413. static void init_lcb_access(struct hfi1_devdata *dd)
  5414. {
  5415. dd->lcb_access_count = 0;
  5416. }
  5417. /*
  5418. * Write a response back to a 8051 request.
  5419. */
  5420. static void hreq_response(struct hfi1_devdata *dd, u8 return_code, u16 rsp_data)
  5421. {
  5422. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0,
  5423. DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK |
  5424. (u64)return_code <<
  5425. DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT |
  5426. (u64)rsp_data << DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
  5427. }
  5428. /*
  5429. * Handle host requests from the 8051.
  5430. */
  5431. static void handle_8051_request(struct hfi1_pportdata *ppd)
  5432. {
  5433. struct hfi1_devdata *dd = ppd->dd;
  5434. u64 reg;
  5435. u16 data = 0;
  5436. u8 type;
  5437. reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_1);
  5438. if ((reg & DC_DC8051_CFG_EXT_DEV_1_REQ_NEW_SMASK) == 0)
  5439. return; /* no request */
  5440. /* zero out COMPLETED so the response is seen */
  5441. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, 0);
  5442. /* extract request details */
  5443. type = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_SHIFT)
  5444. & DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_MASK;
  5445. data = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT)
  5446. & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_MASK;
  5447. switch (type) {
  5448. case HREQ_LOAD_CONFIG:
  5449. case HREQ_SAVE_CONFIG:
  5450. case HREQ_READ_CONFIG:
  5451. case HREQ_SET_TX_EQ_ABS:
  5452. case HREQ_SET_TX_EQ_REL:
  5453. case HREQ_ENABLE:
  5454. dd_dev_info(dd, "8051 request: request 0x%x not supported\n",
  5455. type);
  5456. hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
  5457. break;
  5458. case HREQ_CONFIG_DONE:
  5459. hreq_response(dd, HREQ_SUCCESS, 0);
  5460. break;
  5461. case HREQ_INTERFACE_TEST:
  5462. hreq_response(dd, HREQ_SUCCESS, data);
  5463. break;
  5464. default:
  5465. dd_dev_err(dd, "8051 request: unknown request 0x%x\n", type);
  5466. hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
  5467. break;
  5468. }
  5469. }
  5470. static void write_global_credit(struct hfi1_devdata *dd,
  5471. u8 vau, u16 total, u16 shared)
  5472. {
  5473. write_csr(dd, SEND_CM_GLOBAL_CREDIT,
  5474. ((u64)total <<
  5475. SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT) |
  5476. ((u64)shared <<
  5477. SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT) |
  5478. ((u64)vau << SEND_CM_GLOBAL_CREDIT_AU_SHIFT));
  5479. }
  5480. /*
  5481. * Set up initial VL15 credits of the remote. Assumes the rest of
  5482. * the CM credit registers are zero from a previous global or credit reset .
  5483. */
  5484. void set_up_vl15(struct hfi1_devdata *dd, u8 vau, u16 vl15buf)
  5485. {
  5486. /* leave shared count at zero for both global and VL15 */
  5487. write_global_credit(dd, vau, vl15buf, 0);
  5488. write_csr(dd, SEND_CM_CREDIT_VL15, (u64)vl15buf
  5489. << SEND_CM_CREDIT_VL15_DEDICATED_LIMIT_VL_SHIFT);
  5490. }
  5491. /*
  5492. * Zero all credit details from the previous connection and
  5493. * reset the CM manager's internal counters.
  5494. */
  5495. void reset_link_credits(struct hfi1_devdata *dd)
  5496. {
  5497. int i;
  5498. /* remove all previous VL credit limits */
  5499. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  5500. write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
  5501. write_csr(dd, SEND_CM_CREDIT_VL15, 0);
  5502. write_global_credit(dd, 0, 0, 0);
  5503. /* reset the CM block */
  5504. pio_send_control(dd, PSC_CM_RESET);
  5505. }
  5506. /* convert a vCU to a CU */
  5507. static u32 vcu_to_cu(u8 vcu)
  5508. {
  5509. return 1 << vcu;
  5510. }
  5511. /* convert a CU to a vCU */
  5512. static u8 cu_to_vcu(u32 cu)
  5513. {
  5514. return ilog2(cu);
  5515. }
  5516. /* convert a vAU to an AU */
  5517. static u32 vau_to_au(u8 vau)
  5518. {
  5519. return 8 * (1 << vau);
  5520. }
  5521. static void set_linkup_defaults(struct hfi1_pportdata *ppd)
  5522. {
  5523. ppd->sm_trap_qp = 0x0;
  5524. ppd->sa_qp = 0x1;
  5525. }
  5526. /*
  5527. * Graceful LCB shutdown. This leaves the LCB FIFOs in reset.
  5528. */
  5529. static void lcb_shutdown(struct hfi1_devdata *dd, int abort)
  5530. {
  5531. u64 reg;
  5532. /* clear lcb run: LCB_CFG_RUN.EN = 0 */
  5533. write_csr(dd, DC_LCB_CFG_RUN, 0);
  5534. /* set tx fifo reset: LCB_CFG_TX_FIFOS_RESET.VAL = 1 */
  5535. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET,
  5536. 1ull << DC_LCB_CFG_TX_FIFOS_RESET_VAL_SHIFT);
  5537. /* set dcc reset csr: DCC_CFG_RESET.{reset_lcb,reset_rx_fpe} = 1 */
  5538. dd->lcb_err_en = read_csr(dd, DC_LCB_ERR_EN);
  5539. reg = read_csr(dd, DCC_CFG_RESET);
  5540. write_csr(dd, DCC_CFG_RESET, reg |
  5541. (1ull << DCC_CFG_RESET_RESET_LCB_SHIFT) |
  5542. (1ull << DCC_CFG_RESET_RESET_RX_FPE_SHIFT));
  5543. (void)read_csr(dd, DCC_CFG_RESET); /* make sure the write completed */
  5544. if (!abort) {
  5545. udelay(1); /* must hold for the longer of 16cclks or 20ns */
  5546. write_csr(dd, DCC_CFG_RESET, reg);
  5547. write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
  5548. }
  5549. }
  5550. /*
  5551. * This routine should be called after the link has been transitioned to
  5552. * OFFLINE (OFFLINE state has the side effect of putting the SerDes into
  5553. * reset).
  5554. *
  5555. * The expectation is that the caller of this routine would have taken
  5556. * care of properly transitioning the link into the correct state.
  5557. */
  5558. static void dc_shutdown(struct hfi1_devdata *dd)
  5559. {
  5560. unsigned long flags;
  5561. spin_lock_irqsave(&dd->dc8051_lock, flags);
  5562. if (dd->dc_shutdown) {
  5563. spin_unlock_irqrestore(&dd->dc8051_lock, flags);
  5564. return;
  5565. }
  5566. dd->dc_shutdown = 1;
  5567. spin_unlock_irqrestore(&dd->dc8051_lock, flags);
  5568. /* Shutdown the LCB */
  5569. lcb_shutdown(dd, 1);
  5570. /*
  5571. * Going to OFFLINE would have causes the 8051 to put the
  5572. * SerDes into reset already. Just need to shut down the 8051,
  5573. * itself.
  5574. */
  5575. write_csr(dd, DC_DC8051_CFG_RST, 0x1);
  5576. }
  5577. /*
  5578. * Calling this after the DC has been brought out of reset should not
  5579. * do any damage.
  5580. */
  5581. static void dc_start(struct hfi1_devdata *dd)
  5582. {
  5583. unsigned long flags;
  5584. int ret;
  5585. spin_lock_irqsave(&dd->dc8051_lock, flags);
  5586. if (!dd->dc_shutdown)
  5587. goto done;
  5588. spin_unlock_irqrestore(&dd->dc8051_lock, flags);
  5589. /* Take the 8051 out of reset */
  5590. write_csr(dd, DC_DC8051_CFG_RST, 0ull);
  5591. /* Wait until 8051 is ready */
  5592. ret = wait_fm_ready(dd, TIMEOUT_8051_START);
  5593. if (ret) {
  5594. dd_dev_err(dd, "%s: timeout starting 8051 firmware\n",
  5595. __func__);
  5596. }
  5597. /* Take away reset for LCB and RX FPE (set in lcb_shutdown). */
  5598. write_csr(dd, DCC_CFG_RESET, 0x10);
  5599. /* lcb_shutdown() with abort=1 does not restore these */
  5600. write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
  5601. spin_lock_irqsave(&dd->dc8051_lock, flags);
  5602. dd->dc_shutdown = 0;
  5603. done:
  5604. spin_unlock_irqrestore(&dd->dc8051_lock, flags);
  5605. }
  5606. /*
  5607. * These LCB adjustments are for the Aurora SerDes core in the FPGA.
  5608. */
  5609. static void adjust_lcb_for_fpga_serdes(struct hfi1_devdata *dd)
  5610. {
  5611. u64 rx_radr, tx_radr;
  5612. u32 version;
  5613. if (dd->icode != ICODE_FPGA_EMULATION)
  5614. return;
  5615. /*
  5616. * These LCB defaults on emulator _s are good, nothing to do here:
  5617. * LCB_CFG_TX_FIFOS_RADR
  5618. * LCB_CFG_RX_FIFOS_RADR
  5619. * LCB_CFG_LN_DCLK
  5620. * LCB_CFG_IGNORE_LOST_RCLK
  5621. */
  5622. if (is_emulator_s(dd))
  5623. return;
  5624. /* else this is _p */
  5625. version = emulator_rev(dd);
  5626. if (!is_ax(dd))
  5627. version = 0x2d; /* all B0 use 0x2d or higher settings */
  5628. if (version <= 0x12) {
  5629. /* release 0x12 and below */
  5630. /*
  5631. * LCB_CFG_RX_FIFOS_RADR.RST_VAL = 0x9
  5632. * LCB_CFG_RX_FIFOS_RADR.OK_TO_JUMP_VAL = 0x9
  5633. * LCB_CFG_RX_FIFOS_RADR.DO_NOT_JUMP_VAL = 0xa
  5634. */
  5635. rx_radr =
  5636. 0xaull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5637. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5638. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5639. /*
  5640. * LCB_CFG_TX_FIFOS_RADR.ON_REINIT = 0 (default)
  5641. * LCB_CFG_TX_FIFOS_RADR.RST_VAL = 6
  5642. */
  5643. tx_radr = 6ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5644. } else if (version <= 0x18) {
  5645. /* release 0x13 up to 0x18 */
  5646. /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
  5647. rx_radr =
  5648. 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5649. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5650. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5651. tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5652. } else if (version == 0x19) {
  5653. /* release 0x19 */
  5654. /* LCB_CFG_RX_FIFOS_RADR = 0xa99 */
  5655. rx_radr =
  5656. 0xAull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5657. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5658. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5659. tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5660. } else if (version == 0x1a) {
  5661. /* release 0x1a */
  5662. /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
  5663. rx_radr =
  5664. 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5665. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5666. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5667. tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5668. write_csr(dd, DC_LCB_CFG_LN_DCLK, 1ull);
  5669. } else {
  5670. /* release 0x1b and higher */
  5671. /* LCB_CFG_RX_FIFOS_RADR = 0x877 */
  5672. rx_radr =
  5673. 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5674. | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5675. | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5676. tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5677. }
  5678. write_csr(dd, DC_LCB_CFG_RX_FIFOS_RADR, rx_radr);
  5679. /* LCB_CFG_IGNORE_LOST_RCLK.EN = 1 */
  5680. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
  5681. DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
  5682. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RADR, tx_radr);
  5683. }
  5684. /*
  5685. * Handle a SMA idle message
  5686. *
  5687. * This is a work-queue function outside of the interrupt.
  5688. */
  5689. void handle_sma_message(struct work_struct *work)
  5690. {
  5691. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  5692. sma_message_work);
  5693. struct hfi1_devdata *dd = ppd->dd;
  5694. u64 msg;
  5695. int ret;
  5696. /*
  5697. * msg is bytes 1-4 of the 40-bit idle message - the command code
  5698. * is stripped off
  5699. */
  5700. ret = read_idle_sma(dd, &msg);
  5701. if (ret)
  5702. return;
  5703. dd_dev_info(dd, "%s: SMA message 0x%llx\n", __func__, msg);
  5704. /*
  5705. * React to the SMA message. Byte[1] (0 for us) is the command.
  5706. */
  5707. switch (msg & 0xff) {
  5708. case SMA_IDLE_ARM:
  5709. /*
  5710. * See OPAv1 table 9-14 - HFI and External Switch Ports Key
  5711. * State Transitions
  5712. *
  5713. * Only expected in INIT or ARMED, discard otherwise.
  5714. */
  5715. if (ppd->host_link_state & (HLS_UP_INIT | HLS_UP_ARMED))
  5716. ppd->neighbor_normal = 1;
  5717. break;
  5718. case SMA_IDLE_ACTIVE:
  5719. /*
  5720. * See OPAv1 table 9-14 - HFI and External Switch Ports Key
  5721. * State Transitions
  5722. *
  5723. * Can activate the node. Discard otherwise.
  5724. */
  5725. if (ppd->host_link_state == HLS_UP_ARMED &&
  5726. ppd->is_active_optimize_enabled) {
  5727. ppd->neighbor_normal = 1;
  5728. ret = set_link_state(ppd, HLS_UP_ACTIVE);
  5729. if (ret)
  5730. dd_dev_err(
  5731. dd,
  5732. "%s: received Active SMA idle message, couldn't set link to Active\n",
  5733. __func__);
  5734. }
  5735. break;
  5736. default:
  5737. dd_dev_err(dd,
  5738. "%s: received unexpected SMA idle message 0x%llx\n",
  5739. __func__, msg);
  5740. break;
  5741. }
  5742. }
  5743. static void adjust_rcvctrl(struct hfi1_devdata *dd, u64 add, u64 clear)
  5744. {
  5745. u64 rcvctrl;
  5746. unsigned long flags;
  5747. spin_lock_irqsave(&dd->rcvctrl_lock, flags);
  5748. rcvctrl = read_csr(dd, RCV_CTRL);
  5749. rcvctrl |= add;
  5750. rcvctrl &= ~clear;
  5751. write_csr(dd, RCV_CTRL, rcvctrl);
  5752. spin_unlock_irqrestore(&dd->rcvctrl_lock, flags);
  5753. }
  5754. static inline void add_rcvctrl(struct hfi1_devdata *dd, u64 add)
  5755. {
  5756. adjust_rcvctrl(dd, add, 0);
  5757. }
  5758. static inline void clear_rcvctrl(struct hfi1_devdata *dd, u64 clear)
  5759. {
  5760. adjust_rcvctrl(dd, 0, clear);
  5761. }
  5762. /*
  5763. * Called from all interrupt handlers to start handling an SPC freeze.
  5764. */
  5765. void start_freeze_handling(struct hfi1_pportdata *ppd, int flags)
  5766. {
  5767. struct hfi1_devdata *dd = ppd->dd;
  5768. struct send_context *sc;
  5769. int i;
  5770. if (flags & FREEZE_SELF)
  5771. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
  5772. /* enter frozen mode */
  5773. dd->flags |= HFI1_FROZEN;
  5774. /* notify all SDMA engines that they are going into a freeze */
  5775. sdma_freeze_notify(dd, !!(flags & FREEZE_LINK_DOWN));
  5776. /* do halt pre-handling on all enabled send contexts */
  5777. for (i = 0; i < dd->num_send_contexts; i++) {
  5778. sc = dd->send_contexts[i].sc;
  5779. if (sc && (sc->flags & SCF_ENABLED))
  5780. sc_stop(sc, SCF_FROZEN | SCF_HALTED);
  5781. }
  5782. /* Send context are frozen. Notify user space */
  5783. hfi1_set_uevent_bits(ppd, _HFI1_EVENT_FROZEN_BIT);
  5784. if (flags & FREEZE_ABORT) {
  5785. dd_dev_err(dd,
  5786. "Aborted freeze recovery. Please REBOOT system\n");
  5787. return;
  5788. }
  5789. /* queue non-interrupt handler */
  5790. queue_work(ppd->hfi1_wq, &ppd->freeze_work);
  5791. }
  5792. /*
  5793. * Wait until all 4 sub-blocks indicate that they have frozen or unfrozen,
  5794. * depending on the "freeze" parameter.
  5795. *
  5796. * No need to return an error if it times out, our only option
  5797. * is to proceed anyway.
  5798. */
  5799. static void wait_for_freeze_status(struct hfi1_devdata *dd, int freeze)
  5800. {
  5801. unsigned long timeout;
  5802. u64 reg;
  5803. timeout = jiffies + msecs_to_jiffies(FREEZE_STATUS_TIMEOUT);
  5804. while (1) {
  5805. reg = read_csr(dd, CCE_STATUS);
  5806. if (freeze) {
  5807. /* waiting until all indicators are set */
  5808. if ((reg & ALL_FROZE) == ALL_FROZE)
  5809. return; /* all done */
  5810. } else {
  5811. /* waiting until all indicators are clear */
  5812. if ((reg & ALL_FROZE) == 0)
  5813. return; /* all done */
  5814. }
  5815. if (time_after(jiffies, timeout)) {
  5816. dd_dev_err(dd,
  5817. "Time out waiting for SPC %sfreeze, bits 0x%llx, expecting 0x%llx, continuing",
  5818. freeze ? "" : "un", reg & ALL_FROZE,
  5819. freeze ? ALL_FROZE : 0ull);
  5820. return;
  5821. }
  5822. usleep_range(80, 120);
  5823. }
  5824. }
  5825. /*
  5826. * Do all freeze handling for the RXE block.
  5827. */
  5828. static void rxe_freeze(struct hfi1_devdata *dd)
  5829. {
  5830. int i;
  5831. /* disable port */
  5832. clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  5833. /* disable all receive contexts */
  5834. for (i = 0; i < dd->num_rcv_contexts; i++)
  5835. hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_DIS, i);
  5836. }
  5837. /*
  5838. * Unfreeze handling for the RXE block - kernel contexts only.
  5839. * This will also enable the port. User contexts will do unfreeze
  5840. * handling on a per-context basis as they call into the driver.
  5841. *
  5842. */
  5843. static void rxe_kernel_unfreeze(struct hfi1_devdata *dd)
  5844. {
  5845. u32 rcvmask;
  5846. int i;
  5847. /* enable all kernel contexts */
  5848. for (i = 0; i < dd->n_krcv_queues; i++) {
  5849. rcvmask = HFI1_RCVCTRL_CTXT_ENB;
  5850. /* HFI1_RCVCTRL_TAILUPD_[ENB|DIS] needs to be set explicitly */
  5851. rcvmask |= HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, DMA_RTAIL) ?
  5852. HFI1_RCVCTRL_TAILUPD_ENB : HFI1_RCVCTRL_TAILUPD_DIS;
  5853. hfi1_rcvctrl(dd, rcvmask, i);
  5854. }
  5855. /* enable port */
  5856. add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  5857. }
  5858. /*
  5859. * Non-interrupt SPC freeze handling.
  5860. *
  5861. * This is a work-queue function outside of the triggering interrupt.
  5862. */
  5863. void handle_freeze(struct work_struct *work)
  5864. {
  5865. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  5866. freeze_work);
  5867. struct hfi1_devdata *dd = ppd->dd;
  5868. /* wait for freeze indicators on all affected blocks */
  5869. wait_for_freeze_status(dd, 1);
  5870. /* SPC is now frozen */
  5871. /* do send PIO freeze steps */
  5872. pio_freeze(dd);
  5873. /* do send DMA freeze steps */
  5874. sdma_freeze(dd);
  5875. /* do send egress freeze steps - nothing to do */
  5876. /* do receive freeze steps */
  5877. rxe_freeze(dd);
  5878. /*
  5879. * Unfreeze the hardware - clear the freeze, wait for each
  5880. * block's frozen bit to clear, then clear the frozen flag.
  5881. */
  5882. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
  5883. wait_for_freeze_status(dd, 0);
  5884. if (is_ax(dd)) {
  5885. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
  5886. wait_for_freeze_status(dd, 1);
  5887. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
  5888. wait_for_freeze_status(dd, 0);
  5889. }
  5890. /* do send PIO unfreeze steps for kernel contexts */
  5891. pio_kernel_unfreeze(dd);
  5892. /* do send DMA unfreeze steps */
  5893. sdma_unfreeze(dd);
  5894. /* do send egress unfreeze steps - nothing to do */
  5895. /* do receive unfreeze steps for kernel contexts */
  5896. rxe_kernel_unfreeze(dd);
  5897. /*
  5898. * The unfreeze procedure touches global device registers when
  5899. * it disables and re-enables RXE. Mark the device unfrozen
  5900. * after all that is done so other parts of the driver waiting
  5901. * for the device to unfreeze don't do things out of order.
  5902. *
  5903. * The above implies that the meaning of HFI1_FROZEN flag is
  5904. * "Device has gone into freeze mode and freeze mode handling
  5905. * is still in progress."
  5906. *
  5907. * The flag will be removed when freeze mode processing has
  5908. * completed.
  5909. */
  5910. dd->flags &= ~HFI1_FROZEN;
  5911. wake_up(&dd->event_queue);
  5912. /* no longer frozen */
  5913. }
  5914. /*
  5915. * Handle a link up interrupt from the 8051.
  5916. *
  5917. * This is a work-queue function outside of the interrupt.
  5918. */
  5919. void handle_link_up(struct work_struct *work)
  5920. {
  5921. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  5922. link_up_work);
  5923. set_link_state(ppd, HLS_UP_INIT);
  5924. /* cache the read of DC_LCB_STS_ROUND_TRIP_LTP_CNT */
  5925. read_ltp_rtt(ppd->dd);
  5926. /*
  5927. * OPA specifies that certain counters are cleared on a transition
  5928. * to link up, so do that.
  5929. */
  5930. clear_linkup_counters(ppd->dd);
  5931. /*
  5932. * And (re)set link up default values.
  5933. */
  5934. set_linkup_defaults(ppd);
  5935. /* enforce link speed enabled */
  5936. if ((ppd->link_speed_active & ppd->link_speed_enabled) == 0) {
  5937. /* oops - current speed is not enabled, bounce */
  5938. dd_dev_err(ppd->dd,
  5939. "Link speed active 0x%x is outside enabled 0x%x, downing link\n",
  5940. ppd->link_speed_active, ppd->link_speed_enabled);
  5941. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SPEED_POLICY, 0,
  5942. OPA_LINKDOWN_REASON_SPEED_POLICY);
  5943. set_link_state(ppd, HLS_DN_OFFLINE);
  5944. start_link(ppd);
  5945. }
  5946. }
  5947. /*
  5948. * Several pieces of LNI information were cached for SMA in ppd.
  5949. * Reset these on link down
  5950. */
  5951. static void reset_neighbor_info(struct hfi1_pportdata *ppd)
  5952. {
  5953. ppd->neighbor_guid = 0;
  5954. ppd->neighbor_port_number = 0;
  5955. ppd->neighbor_type = 0;
  5956. ppd->neighbor_fm_security = 0;
  5957. }
  5958. static const char * const link_down_reason_strs[] = {
  5959. [OPA_LINKDOWN_REASON_NONE] = "None",
  5960. [OPA_LINKDOWN_REASON_RCV_ERROR_0] = "Recive error 0",
  5961. [OPA_LINKDOWN_REASON_BAD_PKT_LEN] = "Bad packet length",
  5962. [OPA_LINKDOWN_REASON_PKT_TOO_LONG] = "Packet too long",
  5963. [OPA_LINKDOWN_REASON_PKT_TOO_SHORT] = "Packet too short",
  5964. [OPA_LINKDOWN_REASON_BAD_SLID] = "Bad SLID",
  5965. [OPA_LINKDOWN_REASON_BAD_DLID] = "Bad DLID",
  5966. [OPA_LINKDOWN_REASON_BAD_L2] = "Bad L2",
  5967. [OPA_LINKDOWN_REASON_BAD_SC] = "Bad SC",
  5968. [OPA_LINKDOWN_REASON_RCV_ERROR_8] = "Receive error 8",
  5969. [OPA_LINKDOWN_REASON_BAD_MID_TAIL] = "Bad mid tail",
  5970. [OPA_LINKDOWN_REASON_RCV_ERROR_10] = "Receive error 10",
  5971. [OPA_LINKDOWN_REASON_PREEMPT_ERROR] = "Preempt error",
  5972. [OPA_LINKDOWN_REASON_PREEMPT_VL15] = "Preempt vl15",
  5973. [OPA_LINKDOWN_REASON_BAD_VL_MARKER] = "Bad VL marker",
  5974. [OPA_LINKDOWN_REASON_RCV_ERROR_14] = "Receive error 14",
  5975. [OPA_LINKDOWN_REASON_RCV_ERROR_15] = "Receive error 15",
  5976. [OPA_LINKDOWN_REASON_BAD_HEAD_DIST] = "Bad head distance",
  5977. [OPA_LINKDOWN_REASON_BAD_TAIL_DIST] = "Bad tail distance",
  5978. [OPA_LINKDOWN_REASON_BAD_CTRL_DIST] = "Bad control distance",
  5979. [OPA_LINKDOWN_REASON_BAD_CREDIT_ACK] = "Bad credit ack",
  5980. [OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER] = "Unsupported VL marker",
  5981. [OPA_LINKDOWN_REASON_BAD_PREEMPT] = "Bad preempt",
  5982. [OPA_LINKDOWN_REASON_BAD_CONTROL_FLIT] = "Bad control flit",
  5983. [OPA_LINKDOWN_REASON_EXCEED_MULTICAST_LIMIT] = "Exceed multicast limit",
  5984. [OPA_LINKDOWN_REASON_RCV_ERROR_24] = "Receive error 24",
  5985. [OPA_LINKDOWN_REASON_RCV_ERROR_25] = "Receive error 25",
  5986. [OPA_LINKDOWN_REASON_RCV_ERROR_26] = "Receive error 26",
  5987. [OPA_LINKDOWN_REASON_RCV_ERROR_27] = "Receive error 27",
  5988. [OPA_LINKDOWN_REASON_RCV_ERROR_28] = "Receive error 28",
  5989. [OPA_LINKDOWN_REASON_RCV_ERROR_29] = "Receive error 29",
  5990. [OPA_LINKDOWN_REASON_RCV_ERROR_30] = "Receive error 30",
  5991. [OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN] =
  5992. "Excessive buffer overrun",
  5993. [OPA_LINKDOWN_REASON_UNKNOWN] = "Unknown",
  5994. [OPA_LINKDOWN_REASON_REBOOT] = "Reboot",
  5995. [OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN] = "Neighbor unknown",
  5996. [OPA_LINKDOWN_REASON_FM_BOUNCE] = "FM bounce",
  5997. [OPA_LINKDOWN_REASON_SPEED_POLICY] = "Speed policy",
  5998. [OPA_LINKDOWN_REASON_WIDTH_POLICY] = "Width policy",
  5999. [OPA_LINKDOWN_REASON_DISCONNECTED] = "Disconnected",
  6000. [OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED] =
  6001. "Local media not installed",
  6002. [OPA_LINKDOWN_REASON_NOT_INSTALLED] = "Not installed",
  6003. [OPA_LINKDOWN_REASON_CHASSIS_CONFIG] = "Chassis config",
  6004. [OPA_LINKDOWN_REASON_END_TO_END_NOT_INSTALLED] =
  6005. "End to end not installed",
  6006. [OPA_LINKDOWN_REASON_POWER_POLICY] = "Power policy",
  6007. [OPA_LINKDOWN_REASON_LINKSPEED_POLICY] = "Link speed policy",
  6008. [OPA_LINKDOWN_REASON_LINKWIDTH_POLICY] = "Link width policy",
  6009. [OPA_LINKDOWN_REASON_SWITCH_MGMT] = "Switch management",
  6010. [OPA_LINKDOWN_REASON_SMA_DISABLED] = "SMA disabled",
  6011. [OPA_LINKDOWN_REASON_TRANSIENT] = "Transient"
  6012. };
  6013. /* return the neighbor link down reason string */
  6014. static const char *link_down_reason_str(u8 reason)
  6015. {
  6016. const char *str = NULL;
  6017. if (reason < ARRAY_SIZE(link_down_reason_strs))
  6018. str = link_down_reason_strs[reason];
  6019. if (!str)
  6020. str = "(invalid)";
  6021. return str;
  6022. }
  6023. /*
  6024. * Handle a link down interrupt from the 8051.
  6025. *
  6026. * This is a work-queue function outside of the interrupt.
  6027. */
  6028. void handle_link_down(struct work_struct *work)
  6029. {
  6030. u8 lcl_reason, neigh_reason = 0;
  6031. u8 link_down_reason;
  6032. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6033. link_down_work);
  6034. int was_up;
  6035. static const char ldr_str[] = "Link down reason: ";
  6036. if ((ppd->host_link_state &
  6037. (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) &&
  6038. ppd->port_type == PORT_TYPE_FIXED)
  6039. ppd->offline_disabled_reason =
  6040. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NOT_INSTALLED);
  6041. /* Go offline first, then deal with reading/writing through 8051 */
  6042. was_up = !!(ppd->host_link_state & HLS_UP);
  6043. set_link_state(ppd, HLS_DN_OFFLINE);
  6044. if (was_up) {
  6045. lcl_reason = 0;
  6046. /* link down reason is only valid if the link was up */
  6047. read_link_down_reason(ppd->dd, &link_down_reason);
  6048. switch (link_down_reason) {
  6049. case LDR_LINK_TRANSFER_ACTIVE_LOW:
  6050. /* the link went down, no idle message reason */
  6051. dd_dev_info(ppd->dd, "%sUnexpected link down\n",
  6052. ldr_str);
  6053. break;
  6054. case LDR_RECEIVED_LINKDOWN_IDLE_MSG:
  6055. /*
  6056. * The neighbor reason is only valid if an idle message
  6057. * was received for it.
  6058. */
  6059. read_planned_down_reason_code(ppd->dd, &neigh_reason);
  6060. dd_dev_info(ppd->dd,
  6061. "%sNeighbor link down message %d, %s\n",
  6062. ldr_str, neigh_reason,
  6063. link_down_reason_str(neigh_reason));
  6064. break;
  6065. case LDR_RECEIVED_HOST_OFFLINE_REQ:
  6066. dd_dev_info(ppd->dd,
  6067. "%sHost requested link to go offline\n",
  6068. ldr_str);
  6069. break;
  6070. default:
  6071. dd_dev_info(ppd->dd, "%sUnknown reason 0x%x\n",
  6072. ldr_str, link_down_reason);
  6073. break;
  6074. }
  6075. /*
  6076. * If no reason, assume peer-initiated but missed
  6077. * LinkGoingDown idle flits.
  6078. */
  6079. if (neigh_reason == 0)
  6080. lcl_reason = OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN;
  6081. } else {
  6082. /* went down while polling or going up */
  6083. lcl_reason = OPA_LINKDOWN_REASON_TRANSIENT;
  6084. }
  6085. set_link_down_reason(ppd, lcl_reason, neigh_reason, 0);
  6086. /* inform the SMA when the link transitions from up to down */
  6087. if (was_up && ppd->local_link_down_reason.sma == 0 &&
  6088. ppd->neigh_link_down_reason.sma == 0) {
  6089. ppd->local_link_down_reason.sma =
  6090. ppd->local_link_down_reason.latest;
  6091. ppd->neigh_link_down_reason.sma =
  6092. ppd->neigh_link_down_reason.latest;
  6093. }
  6094. reset_neighbor_info(ppd);
  6095. /* disable the port */
  6096. clear_rcvctrl(ppd->dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  6097. /*
  6098. * If there is no cable attached, turn the DC off. Otherwise,
  6099. * start the link bring up.
  6100. */
  6101. if (ppd->port_type == PORT_TYPE_QSFP && !qsfp_mod_present(ppd))
  6102. dc_shutdown(ppd->dd);
  6103. else
  6104. start_link(ppd);
  6105. }
  6106. void handle_link_bounce(struct work_struct *work)
  6107. {
  6108. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6109. link_bounce_work);
  6110. /*
  6111. * Only do something if the link is currently up.
  6112. */
  6113. if (ppd->host_link_state & HLS_UP) {
  6114. set_link_state(ppd, HLS_DN_OFFLINE);
  6115. start_link(ppd);
  6116. } else {
  6117. dd_dev_info(ppd->dd, "%s: link not up (%s), nothing to do\n",
  6118. __func__, link_state_name(ppd->host_link_state));
  6119. }
  6120. }
  6121. /*
  6122. * Mask conversion: Capability exchange to Port LTP. The capability
  6123. * exchange has an implicit 16b CRC that is mandatory.
  6124. */
  6125. static int cap_to_port_ltp(int cap)
  6126. {
  6127. int port_ltp = PORT_LTP_CRC_MODE_16; /* this mode is mandatory */
  6128. if (cap & CAP_CRC_14B)
  6129. port_ltp |= PORT_LTP_CRC_MODE_14;
  6130. if (cap & CAP_CRC_48B)
  6131. port_ltp |= PORT_LTP_CRC_MODE_48;
  6132. if (cap & CAP_CRC_12B_16B_PER_LANE)
  6133. port_ltp |= PORT_LTP_CRC_MODE_PER_LANE;
  6134. return port_ltp;
  6135. }
  6136. /*
  6137. * Convert an OPA Port LTP mask to capability mask
  6138. */
  6139. int port_ltp_to_cap(int port_ltp)
  6140. {
  6141. int cap_mask = 0;
  6142. if (port_ltp & PORT_LTP_CRC_MODE_14)
  6143. cap_mask |= CAP_CRC_14B;
  6144. if (port_ltp & PORT_LTP_CRC_MODE_48)
  6145. cap_mask |= CAP_CRC_48B;
  6146. if (port_ltp & PORT_LTP_CRC_MODE_PER_LANE)
  6147. cap_mask |= CAP_CRC_12B_16B_PER_LANE;
  6148. return cap_mask;
  6149. }
  6150. /*
  6151. * Convert a single DC LCB CRC mode to an OPA Port LTP mask.
  6152. */
  6153. static int lcb_to_port_ltp(int lcb_crc)
  6154. {
  6155. int port_ltp = 0;
  6156. if (lcb_crc == LCB_CRC_12B_16B_PER_LANE)
  6157. port_ltp = PORT_LTP_CRC_MODE_PER_LANE;
  6158. else if (lcb_crc == LCB_CRC_48B)
  6159. port_ltp = PORT_LTP_CRC_MODE_48;
  6160. else if (lcb_crc == LCB_CRC_14B)
  6161. port_ltp = PORT_LTP_CRC_MODE_14;
  6162. else
  6163. port_ltp = PORT_LTP_CRC_MODE_16;
  6164. return port_ltp;
  6165. }
  6166. /*
  6167. * Our neighbor has indicated that we are allowed to act as a fabric
  6168. * manager, so place the full management partition key in the second
  6169. * (0-based) pkey array position (see OPAv1, section 20.2.2.6.8). Note
  6170. * that we should already have the limited management partition key in
  6171. * array element 1, and also that the port is not yet up when
  6172. * add_full_mgmt_pkey() is invoked.
  6173. */
  6174. static void add_full_mgmt_pkey(struct hfi1_pportdata *ppd)
  6175. {
  6176. struct hfi1_devdata *dd = ppd->dd;
  6177. /* Sanity check - ppd->pkeys[2] should be 0, or already initalized */
  6178. if (!((ppd->pkeys[2] == 0) || (ppd->pkeys[2] == FULL_MGMT_P_KEY)))
  6179. dd_dev_warn(dd, "%s pkey[2] already set to 0x%x, resetting it to 0x%x\n",
  6180. __func__, ppd->pkeys[2], FULL_MGMT_P_KEY);
  6181. ppd->pkeys[2] = FULL_MGMT_P_KEY;
  6182. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
  6183. hfi1_event_pkey_change(ppd->dd, ppd->port);
  6184. }
  6185. static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd)
  6186. {
  6187. if (ppd->pkeys[2] != 0) {
  6188. ppd->pkeys[2] = 0;
  6189. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
  6190. hfi1_event_pkey_change(ppd->dd, ppd->port);
  6191. }
  6192. }
  6193. /*
  6194. * Convert the given link width to the OPA link width bitmask.
  6195. */
  6196. static u16 link_width_to_bits(struct hfi1_devdata *dd, u16 width)
  6197. {
  6198. switch (width) {
  6199. case 0:
  6200. /*
  6201. * Simulator and quick linkup do not set the width.
  6202. * Just set it to 4x without complaint.
  6203. */
  6204. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR || quick_linkup)
  6205. return OPA_LINK_WIDTH_4X;
  6206. return 0; /* no lanes up */
  6207. case 1: return OPA_LINK_WIDTH_1X;
  6208. case 2: return OPA_LINK_WIDTH_2X;
  6209. case 3: return OPA_LINK_WIDTH_3X;
  6210. default:
  6211. dd_dev_info(dd, "%s: invalid width %d, using 4\n",
  6212. __func__, width);
  6213. /* fall through */
  6214. case 4: return OPA_LINK_WIDTH_4X;
  6215. }
  6216. }
  6217. /*
  6218. * Do a population count on the bottom nibble.
  6219. */
  6220. static const u8 bit_counts[16] = {
  6221. 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
  6222. };
  6223. static inline u8 nibble_to_count(u8 nibble)
  6224. {
  6225. return bit_counts[nibble & 0xf];
  6226. }
  6227. /*
  6228. * Read the active lane information from the 8051 registers and return
  6229. * their widths.
  6230. *
  6231. * Active lane information is found in these 8051 registers:
  6232. * enable_lane_tx
  6233. * enable_lane_rx
  6234. */
  6235. static void get_link_widths(struct hfi1_devdata *dd, u16 *tx_width,
  6236. u16 *rx_width)
  6237. {
  6238. u16 tx, rx;
  6239. u8 enable_lane_rx;
  6240. u8 enable_lane_tx;
  6241. u8 tx_polarity_inversion;
  6242. u8 rx_polarity_inversion;
  6243. u8 max_rate;
  6244. /* read the active lanes */
  6245. read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
  6246. &rx_polarity_inversion, &max_rate);
  6247. read_local_lni(dd, &enable_lane_rx);
  6248. /* convert to counts */
  6249. tx = nibble_to_count(enable_lane_tx);
  6250. rx = nibble_to_count(enable_lane_rx);
  6251. /*
  6252. * Set link_speed_active here, overriding what was set in
  6253. * handle_verify_cap(). The ASIC 8051 firmware does not correctly
  6254. * set the max_rate field in handle_verify_cap until v0.19.
  6255. */
  6256. if ((dd->icode == ICODE_RTL_SILICON) &&
  6257. (dd->dc8051_ver < dc8051_ver(0, 19))) {
  6258. /* max_rate: 0 = 12.5G, 1 = 25G */
  6259. switch (max_rate) {
  6260. case 0:
  6261. dd->pport[0].link_speed_active = OPA_LINK_SPEED_12_5G;
  6262. break;
  6263. default:
  6264. dd_dev_err(dd,
  6265. "%s: unexpected max rate %d, using 25Gb\n",
  6266. __func__, (int)max_rate);
  6267. /* fall through */
  6268. case 1:
  6269. dd->pport[0].link_speed_active = OPA_LINK_SPEED_25G;
  6270. break;
  6271. }
  6272. }
  6273. dd_dev_info(dd,
  6274. "Fabric active lanes (width): tx 0x%x (%d), rx 0x%x (%d)\n",
  6275. enable_lane_tx, tx, enable_lane_rx, rx);
  6276. *tx_width = link_width_to_bits(dd, tx);
  6277. *rx_width = link_width_to_bits(dd, rx);
  6278. }
  6279. /*
  6280. * Read verify_cap_local_fm_link_width[1] to obtain the link widths.
  6281. * Valid after the end of VerifyCap and during LinkUp. Does not change
  6282. * after link up. I.e. look elsewhere for downgrade information.
  6283. *
  6284. * Bits are:
  6285. * + bits [7:4] contain the number of active transmitters
  6286. * + bits [3:0] contain the number of active receivers
  6287. * These are numbers 1 through 4 and can be different values if the
  6288. * link is asymmetric.
  6289. *
  6290. * verify_cap_local_fm_link_width[0] retains its original value.
  6291. */
  6292. static void get_linkup_widths(struct hfi1_devdata *dd, u16 *tx_width,
  6293. u16 *rx_width)
  6294. {
  6295. u16 widths, tx, rx;
  6296. u8 misc_bits, local_flags;
  6297. u16 active_tx, active_rx;
  6298. read_vc_local_link_width(dd, &misc_bits, &local_flags, &widths);
  6299. tx = widths >> 12;
  6300. rx = (widths >> 8) & 0xf;
  6301. *tx_width = link_width_to_bits(dd, tx);
  6302. *rx_width = link_width_to_bits(dd, rx);
  6303. /* print the active widths */
  6304. get_link_widths(dd, &active_tx, &active_rx);
  6305. }
  6306. /*
  6307. * Set ppd->link_width_active and ppd->link_width_downgrade_active using
  6308. * hardware information when the link first comes up.
  6309. *
  6310. * The link width is not available until after VerifyCap.AllFramesReceived
  6311. * (the trigger for handle_verify_cap), so this is outside that routine
  6312. * and should be called when the 8051 signals linkup.
  6313. */
  6314. void get_linkup_link_widths(struct hfi1_pportdata *ppd)
  6315. {
  6316. u16 tx_width, rx_width;
  6317. /* get end-of-LNI link widths */
  6318. get_linkup_widths(ppd->dd, &tx_width, &rx_width);
  6319. /* use tx_width as the link is supposed to be symmetric on link up */
  6320. ppd->link_width_active = tx_width;
  6321. /* link width downgrade active (LWD.A) starts out matching LW.A */
  6322. ppd->link_width_downgrade_tx_active = ppd->link_width_active;
  6323. ppd->link_width_downgrade_rx_active = ppd->link_width_active;
  6324. /* per OPA spec, on link up LWD.E resets to LWD.S */
  6325. ppd->link_width_downgrade_enabled = ppd->link_width_downgrade_supported;
  6326. /* cache the active egress rate (units {10^6 bits/sec]) */
  6327. ppd->current_egress_rate = active_egress_rate(ppd);
  6328. }
  6329. /*
  6330. * Handle a verify capabilities interrupt from the 8051.
  6331. *
  6332. * This is a work-queue function outside of the interrupt.
  6333. */
  6334. void handle_verify_cap(struct work_struct *work)
  6335. {
  6336. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6337. link_vc_work);
  6338. struct hfi1_devdata *dd = ppd->dd;
  6339. u64 reg;
  6340. u8 power_management;
  6341. u8 continious;
  6342. u8 vcu;
  6343. u8 vau;
  6344. u8 z;
  6345. u16 vl15buf;
  6346. u16 link_widths;
  6347. u16 crc_mask;
  6348. u16 crc_val;
  6349. u16 device_id;
  6350. u16 active_tx, active_rx;
  6351. u8 partner_supported_crc;
  6352. u8 remote_tx_rate;
  6353. u8 device_rev;
  6354. set_link_state(ppd, HLS_VERIFY_CAP);
  6355. lcb_shutdown(dd, 0);
  6356. adjust_lcb_for_fpga_serdes(dd);
  6357. /*
  6358. * These are now valid:
  6359. * remote VerifyCap fields in the general LNI config
  6360. * CSR DC8051_STS_REMOTE_GUID
  6361. * CSR DC8051_STS_REMOTE_NODE_TYPE
  6362. * CSR DC8051_STS_REMOTE_FM_SECURITY
  6363. * CSR DC8051_STS_REMOTE_PORT_NO
  6364. */
  6365. read_vc_remote_phy(dd, &power_management, &continious);
  6366. read_vc_remote_fabric(dd, &vau, &z, &vcu, &vl15buf,
  6367. &partner_supported_crc);
  6368. read_vc_remote_link_width(dd, &remote_tx_rate, &link_widths);
  6369. read_remote_device_id(dd, &device_id, &device_rev);
  6370. /*
  6371. * And the 'MgmtAllowed' information, which is exchanged during
  6372. * LNI, is also be available at this point.
  6373. */
  6374. read_mgmt_allowed(dd, &ppd->mgmt_allowed);
  6375. /* print the active widths */
  6376. get_link_widths(dd, &active_tx, &active_rx);
  6377. dd_dev_info(dd,
  6378. "Peer PHY: power management 0x%x, continuous updates 0x%x\n",
  6379. (int)power_management, (int)continious);
  6380. dd_dev_info(dd,
  6381. "Peer Fabric: vAU %d, Z %d, vCU %d, vl15 credits 0x%x, CRC sizes 0x%x\n",
  6382. (int)vau, (int)z, (int)vcu, (int)vl15buf,
  6383. (int)partner_supported_crc);
  6384. dd_dev_info(dd, "Peer Link Width: tx rate 0x%x, widths 0x%x\n",
  6385. (u32)remote_tx_rate, (u32)link_widths);
  6386. dd_dev_info(dd, "Peer Device ID: 0x%04x, Revision 0x%02x\n",
  6387. (u32)device_id, (u32)device_rev);
  6388. /*
  6389. * The peer vAU value just read is the peer receiver value. HFI does
  6390. * not support a transmit vAU of 0 (AU == 8). We advertised that
  6391. * with Z=1 in the fabric capabilities sent to the peer. The peer
  6392. * will see our Z=1, and, if it advertised a vAU of 0, will move its
  6393. * receive to vAU of 1 (AU == 16). Do the same here. We do not care
  6394. * about the peer Z value - our sent vAU is 3 (hardwired) and is not
  6395. * subject to the Z value exception.
  6396. */
  6397. if (vau == 0)
  6398. vau = 1;
  6399. set_up_vl15(dd, vau, vl15buf);
  6400. /* set up the LCB CRC mode */
  6401. crc_mask = ppd->port_crc_mode_enabled & partner_supported_crc;
  6402. /* order is important: use the lowest bit in common */
  6403. if (crc_mask & CAP_CRC_14B)
  6404. crc_val = LCB_CRC_14B;
  6405. else if (crc_mask & CAP_CRC_48B)
  6406. crc_val = LCB_CRC_48B;
  6407. else if (crc_mask & CAP_CRC_12B_16B_PER_LANE)
  6408. crc_val = LCB_CRC_12B_16B_PER_LANE;
  6409. else
  6410. crc_val = LCB_CRC_16B;
  6411. dd_dev_info(dd, "Final LCB CRC mode: %d\n", (int)crc_val);
  6412. write_csr(dd, DC_LCB_CFG_CRC_MODE,
  6413. (u64)crc_val << DC_LCB_CFG_CRC_MODE_TX_VAL_SHIFT);
  6414. /* set (14b only) or clear sideband credit */
  6415. reg = read_csr(dd, SEND_CM_CTRL);
  6416. if (crc_val == LCB_CRC_14B && crc_14b_sideband) {
  6417. write_csr(dd, SEND_CM_CTRL,
  6418. reg | SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
  6419. } else {
  6420. write_csr(dd, SEND_CM_CTRL,
  6421. reg & ~SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
  6422. }
  6423. ppd->link_speed_active = 0; /* invalid value */
  6424. if (dd->dc8051_ver < dc8051_ver(0, 20)) {
  6425. /* remote_tx_rate: 0 = 12.5G, 1 = 25G */
  6426. switch (remote_tx_rate) {
  6427. case 0:
  6428. ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
  6429. break;
  6430. case 1:
  6431. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6432. break;
  6433. }
  6434. } else {
  6435. /* actual rate is highest bit of the ANDed rates */
  6436. u8 rate = remote_tx_rate & ppd->local_tx_rate;
  6437. if (rate & 2)
  6438. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6439. else if (rate & 1)
  6440. ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
  6441. }
  6442. if (ppd->link_speed_active == 0) {
  6443. dd_dev_err(dd, "%s: unexpected remote tx rate %d, using 25Gb\n",
  6444. __func__, (int)remote_tx_rate);
  6445. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6446. }
  6447. /*
  6448. * Cache the values of the supported, enabled, and active
  6449. * LTP CRC modes to return in 'portinfo' queries. But the bit
  6450. * flags that are returned in the portinfo query differ from
  6451. * what's in the link_crc_mask, crc_sizes, and crc_val
  6452. * variables. Convert these here.
  6453. */
  6454. ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
  6455. /* supported crc modes */
  6456. ppd->port_ltp_crc_mode |=
  6457. cap_to_port_ltp(ppd->port_crc_mode_enabled) << 4;
  6458. /* enabled crc modes */
  6459. ppd->port_ltp_crc_mode |= lcb_to_port_ltp(crc_val);
  6460. /* active crc mode */
  6461. /* set up the remote credit return table */
  6462. assign_remote_cm_au_table(dd, vcu);
  6463. /*
  6464. * The LCB is reset on entry to handle_verify_cap(), so this must
  6465. * be applied on every link up.
  6466. *
  6467. * Adjust LCB error kill enable to kill the link if
  6468. * these RBUF errors are seen:
  6469. * REPLAY_BUF_MBE_SMASK
  6470. * FLIT_INPUT_BUF_MBE_SMASK
  6471. */
  6472. if (is_ax(dd)) { /* fixed in B0 */
  6473. reg = read_csr(dd, DC_LCB_CFG_LINK_KILL_EN);
  6474. reg |= DC_LCB_CFG_LINK_KILL_EN_REPLAY_BUF_MBE_SMASK
  6475. | DC_LCB_CFG_LINK_KILL_EN_FLIT_INPUT_BUF_MBE_SMASK;
  6476. write_csr(dd, DC_LCB_CFG_LINK_KILL_EN, reg);
  6477. }
  6478. /* pull LCB fifos out of reset - all fifo clocks must be stable */
  6479. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  6480. /* give 8051 access to the LCB CSRs */
  6481. write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
  6482. set_8051_lcb_access(dd);
  6483. ppd->neighbor_guid =
  6484. read_csr(dd, DC_DC8051_STS_REMOTE_GUID);
  6485. ppd->neighbor_port_number = read_csr(dd, DC_DC8051_STS_REMOTE_PORT_NO) &
  6486. DC_DC8051_STS_REMOTE_PORT_NO_VAL_SMASK;
  6487. ppd->neighbor_type =
  6488. read_csr(dd, DC_DC8051_STS_REMOTE_NODE_TYPE) &
  6489. DC_DC8051_STS_REMOTE_NODE_TYPE_VAL_MASK;
  6490. ppd->neighbor_fm_security =
  6491. read_csr(dd, DC_DC8051_STS_REMOTE_FM_SECURITY) &
  6492. DC_DC8051_STS_LOCAL_FM_SECURITY_DISABLED_MASK;
  6493. dd_dev_info(dd,
  6494. "Neighbor Guid: %llx Neighbor type %d MgmtAllowed %d FM security bypass %d\n",
  6495. ppd->neighbor_guid, ppd->neighbor_type,
  6496. ppd->mgmt_allowed, ppd->neighbor_fm_security);
  6497. if (ppd->mgmt_allowed)
  6498. add_full_mgmt_pkey(ppd);
  6499. /* tell the 8051 to go to LinkUp */
  6500. set_link_state(ppd, HLS_GOING_UP);
  6501. }
  6502. /*
  6503. * Apply the link width downgrade enabled policy against the current active
  6504. * link widths.
  6505. *
  6506. * Called when the enabled policy changes or the active link widths change.
  6507. */
  6508. void apply_link_downgrade_policy(struct hfi1_pportdata *ppd, int refresh_widths)
  6509. {
  6510. int do_bounce = 0;
  6511. int tries;
  6512. u16 lwde;
  6513. u16 tx, rx;
  6514. /* use the hls lock to avoid a race with actual link up */
  6515. tries = 0;
  6516. retry:
  6517. mutex_lock(&ppd->hls_lock);
  6518. /* only apply if the link is up */
  6519. if (ppd->host_link_state & HLS_DOWN) {
  6520. /* still going up..wait and retry */
  6521. if (ppd->host_link_state & HLS_GOING_UP) {
  6522. if (++tries < 1000) {
  6523. mutex_unlock(&ppd->hls_lock);
  6524. usleep_range(100, 120); /* arbitrary */
  6525. goto retry;
  6526. }
  6527. dd_dev_err(ppd->dd,
  6528. "%s: giving up waiting for link state change\n",
  6529. __func__);
  6530. }
  6531. goto done;
  6532. }
  6533. lwde = ppd->link_width_downgrade_enabled;
  6534. if (refresh_widths) {
  6535. get_link_widths(ppd->dd, &tx, &rx);
  6536. ppd->link_width_downgrade_tx_active = tx;
  6537. ppd->link_width_downgrade_rx_active = rx;
  6538. }
  6539. if (ppd->link_width_downgrade_tx_active == 0 ||
  6540. ppd->link_width_downgrade_rx_active == 0) {
  6541. /* the 8051 reported a dead link as a downgrade */
  6542. dd_dev_err(ppd->dd, "Link downgrade is really a link down, ignoring\n");
  6543. } else if (lwde == 0) {
  6544. /* downgrade is disabled */
  6545. /* bounce if not at starting active width */
  6546. if ((ppd->link_width_active !=
  6547. ppd->link_width_downgrade_tx_active) ||
  6548. (ppd->link_width_active !=
  6549. ppd->link_width_downgrade_rx_active)) {
  6550. dd_dev_err(ppd->dd,
  6551. "Link downgrade is disabled and link has downgraded, downing link\n");
  6552. dd_dev_err(ppd->dd,
  6553. " original 0x%x, tx active 0x%x, rx active 0x%x\n",
  6554. ppd->link_width_active,
  6555. ppd->link_width_downgrade_tx_active,
  6556. ppd->link_width_downgrade_rx_active);
  6557. do_bounce = 1;
  6558. }
  6559. } else if ((lwde & ppd->link_width_downgrade_tx_active) == 0 ||
  6560. (lwde & ppd->link_width_downgrade_rx_active) == 0) {
  6561. /* Tx or Rx is outside the enabled policy */
  6562. dd_dev_err(ppd->dd,
  6563. "Link is outside of downgrade allowed, downing link\n");
  6564. dd_dev_err(ppd->dd,
  6565. " enabled 0x%x, tx active 0x%x, rx active 0x%x\n",
  6566. lwde, ppd->link_width_downgrade_tx_active,
  6567. ppd->link_width_downgrade_rx_active);
  6568. do_bounce = 1;
  6569. }
  6570. done:
  6571. mutex_unlock(&ppd->hls_lock);
  6572. if (do_bounce) {
  6573. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_WIDTH_POLICY, 0,
  6574. OPA_LINKDOWN_REASON_WIDTH_POLICY);
  6575. set_link_state(ppd, HLS_DN_OFFLINE);
  6576. start_link(ppd);
  6577. }
  6578. }
  6579. /*
  6580. * Handle a link downgrade interrupt from the 8051.
  6581. *
  6582. * This is a work-queue function outside of the interrupt.
  6583. */
  6584. void handle_link_downgrade(struct work_struct *work)
  6585. {
  6586. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6587. link_downgrade_work);
  6588. dd_dev_info(ppd->dd, "8051: Link width downgrade\n");
  6589. apply_link_downgrade_policy(ppd, 1);
  6590. }
  6591. static char *dcc_err_string(char *buf, int buf_len, u64 flags)
  6592. {
  6593. return flag_string(buf, buf_len, flags, dcc_err_flags,
  6594. ARRAY_SIZE(dcc_err_flags));
  6595. }
  6596. static char *lcb_err_string(char *buf, int buf_len, u64 flags)
  6597. {
  6598. return flag_string(buf, buf_len, flags, lcb_err_flags,
  6599. ARRAY_SIZE(lcb_err_flags));
  6600. }
  6601. static char *dc8051_err_string(char *buf, int buf_len, u64 flags)
  6602. {
  6603. return flag_string(buf, buf_len, flags, dc8051_err_flags,
  6604. ARRAY_SIZE(dc8051_err_flags));
  6605. }
  6606. static char *dc8051_info_err_string(char *buf, int buf_len, u64 flags)
  6607. {
  6608. return flag_string(buf, buf_len, flags, dc8051_info_err_flags,
  6609. ARRAY_SIZE(dc8051_info_err_flags));
  6610. }
  6611. static char *dc8051_info_host_msg_string(char *buf, int buf_len, u64 flags)
  6612. {
  6613. return flag_string(buf, buf_len, flags, dc8051_info_host_msg_flags,
  6614. ARRAY_SIZE(dc8051_info_host_msg_flags));
  6615. }
  6616. static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg)
  6617. {
  6618. struct hfi1_pportdata *ppd = dd->pport;
  6619. u64 info, err, host_msg;
  6620. int queue_link_down = 0;
  6621. char buf[96];
  6622. /* look at the flags */
  6623. if (reg & DC_DC8051_ERR_FLG_SET_BY_8051_SMASK) {
  6624. /* 8051 information set by firmware */
  6625. /* read DC8051_DBG_ERR_INFO_SET_BY_8051 for details */
  6626. info = read_csr(dd, DC_DC8051_DBG_ERR_INFO_SET_BY_8051);
  6627. err = (info >> DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_SHIFT)
  6628. & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_MASK;
  6629. host_msg = (info >>
  6630. DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_SHIFT)
  6631. & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_MASK;
  6632. /*
  6633. * Handle error flags.
  6634. */
  6635. if (err & FAILED_LNI) {
  6636. /*
  6637. * LNI error indications are cleared by the 8051
  6638. * only when starting polling. Only pay attention
  6639. * to them when in the states that occur during
  6640. * LNI.
  6641. */
  6642. if (ppd->host_link_state
  6643. & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
  6644. queue_link_down = 1;
  6645. dd_dev_info(dd, "Link error: %s\n",
  6646. dc8051_info_err_string(buf,
  6647. sizeof(buf),
  6648. err &
  6649. FAILED_LNI));
  6650. }
  6651. err &= ~(u64)FAILED_LNI;
  6652. }
  6653. /* unknown frames can happen durning LNI, just count */
  6654. if (err & UNKNOWN_FRAME) {
  6655. ppd->unknown_frame_count++;
  6656. err &= ~(u64)UNKNOWN_FRAME;
  6657. }
  6658. if (err) {
  6659. /* report remaining errors, but do not do anything */
  6660. dd_dev_err(dd, "8051 info error: %s\n",
  6661. dc8051_info_err_string(buf, sizeof(buf),
  6662. err));
  6663. }
  6664. /*
  6665. * Handle host message flags.
  6666. */
  6667. if (host_msg & HOST_REQ_DONE) {
  6668. /*
  6669. * Presently, the driver does a busy wait for
  6670. * host requests to complete. This is only an
  6671. * informational message.
  6672. * NOTE: The 8051 clears the host message
  6673. * information *on the next 8051 command*.
  6674. * Therefore, when linkup is achieved,
  6675. * this flag will still be set.
  6676. */
  6677. host_msg &= ~(u64)HOST_REQ_DONE;
  6678. }
  6679. if (host_msg & BC_SMA_MSG) {
  6680. queue_work(ppd->hfi1_wq, &ppd->sma_message_work);
  6681. host_msg &= ~(u64)BC_SMA_MSG;
  6682. }
  6683. if (host_msg & LINKUP_ACHIEVED) {
  6684. dd_dev_info(dd, "8051: Link up\n");
  6685. queue_work(ppd->hfi1_wq, &ppd->link_up_work);
  6686. host_msg &= ~(u64)LINKUP_ACHIEVED;
  6687. }
  6688. if (host_msg & EXT_DEVICE_CFG_REQ) {
  6689. handle_8051_request(ppd);
  6690. host_msg &= ~(u64)EXT_DEVICE_CFG_REQ;
  6691. }
  6692. if (host_msg & VERIFY_CAP_FRAME) {
  6693. queue_work(ppd->hfi1_wq, &ppd->link_vc_work);
  6694. host_msg &= ~(u64)VERIFY_CAP_FRAME;
  6695. }
  6696. if (host_msg & LINK_GOING_DOWN) {
  6697. const char *extra = "";
  6698. /* no downgrade action needed if going down */
  6699. if (host_msg & LINK_WIDTH_DOWNGRADED) {
  6700. host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
  6701. extra = " (ignoring downgrade)";
  6702. }
  6703. dd_dev_info(dd, "8051: Link down%s\n", extra);
  6704. queue_link_down = 1;
  6705. host_msg &= ~(u64)LINK_GOING_DOWN;
  6706. }
  6707. if (host_msg & LINK_WIDTH_DOWNGRADED) {
  6708. queue_work(ppd->hfi1_wq, &ppd->link_downgrade_work);
  6709. host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
  6710. }
  6711. if (host_msg) {
  6712. /* report remaining messages, but do not do anything */
  6713. dd_dev_info(dd, "8051 info host message: %s\n",
  6714. dc8051_info_host_msg_string(buf,
  6715. sizeof(buf),
  6716. host_msg));
  6717. }
  6718. reg &= ~DC_DC8051_ERR_FLG_SET_BY_8051_SMASK;
  6719. }
  6720. if (reg & DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK) {
  6721. /*
  6722. * Lost the 8051 heartbeat. If this happens, we
  6723. * receive constant interrupts about it. Disable
  6724. * the interrupt after the first.
  6725. */
  6726. dd_dev_err(dd, "Lost 8051 heartbeat\n");
  6727. write_csr(dd, DC_DC8051_ERR_EN,
  6728. read_csr(dd, DC_DC8051_ERR_EN) &
  6729. ~DC_DC8051_ERR_EN_LOST_8051_HEART_BEAT_SMASK);
  6730. reg &= ~DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK;
  6731. }
  6732. if (reg) {
  6733. /* report the error, but do not do anything */
  6734. dd_dev_err(dd, "8051 error: %s\n",
  6735. dc8051_err_string(buf, sizeof(buf), reg));
  6736. }
  6737. if (queue_link_down) {
  6738. /*
  6739. * if the link is already going down or disabled, do not
  6740. * queue another
  6741. */
  6742. if ((ppd->host_link_state &
  6743. (HLS_GOING_OFFLINE | HLS_LINK_COOLDOWN)) ||
  6744. ppd->link_enabled == 0) {
  6745. dd_dev_info(dd, "%s: not queuing link down\n",
  6746. __func__);
  6747. } else {
  6748. queue_work(ppd->hfi1_wq, &ppd->link_down_work);
  6749. }
  6750. }
  6751. }
  6752. static const char * const fm_config_txt[] = {
  6753. [0] =
  6754. "BadHeadDist: Distance violation between two head flits",
  6755. [1] =
  6756. "BadTailDist: Distance violation between two tail flits",
  6757. [2] =
  6758. "BadCtrlDist: Distance violation between two credit control flits",
  6759. [3] =
  6760. "BadCrdAck: Credits return for unsupported VL",
  6761. [4] =
  6762. "UnsupportedVLMarker: Received VL Marker",
  6763. [5] =
  6764. "BadPreempt: Exceeded the preemption nesting level",
  6765. [6] =
  6766. "BadControlFlit: Received unsupported control flit",
  6767. /* no 7 */
  6768. [8] =
  6769. "UnsupportedVLMarker: Received VL Marker for unconfigured or disabled VL",
  6770. };
  6771. static const char * const port_rcv_txt[] = {
  6772. [1] =
  6773. "BadPktLen: Illegal PktLen",
  6774. [2] =
  6775. "PktLenTooLong: Packet longer than PktLen",
  6776. [3] =
  6777. "PktLenTooShort: Packet shorter than PktLen",
  6778. [4] =
  6779. "BadSLID: Illegal SLID (0, using multicast as SLID, does not include security validation of SLID)",
  6780. [5] =
  6781. "BadDLID: Illegal DLID (0, doesn't match HFI)",
  6782. [6] =
  6783. "BadL2: Illegal L2 opcode",
  6784. [7] =
  6785. "BadSC: Unsupported SC",
  6786. [9] =
  6787. "BadRC: Illegal RC",
  6788. [11] =
  6789. "PreemptError: Preempting with same VL",
  6790. [12] =
  6791. "PreemptVL15: Preempting a VL15 packet",
  6792. };
  6793. #define OPA_LDR_FMCONFIG_OFFSET 16
  6794. #define OPA_LDR_PORTRCV_OFFSET 0
  6795. static void handle_dcc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  6796. {
  6797. u64 info, hdr0, hdr1;
  6798. const char *extra;
  6799. char buf[96];
  6800. struct hfi1_pportdata *ppd = dd->pport;
  6801. u8 lcl_reason = 0;
  6802. int do_bounce = 0;
  6803. if (reg & DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK) {
  6804. if (!(dd->err_info_uncorrectable & OPA_EI_STATUS_SMASK)) {
  6805. info = read_csr(dd, DCC_ERR_INFO_UNCORRECTABLE);
  6806. dd->err_info_uncorrectable = info & OPA_EI_CODE_SMASK;
  6807. /* set status bit */
  6808. dd->err_info_uncorrectable |= OPA_EI_STATUS_SMASK;
  6809. }
  6810. reg &= ~DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK;
  6811. }
  6812. if (reg & DCC_ERR_FLG_LINK_ERR_SMASK) {
  6813. struct hfi1_pportdata *ppd = dd->pport;
  6814. /* this counter saturates at (2^32) - 1 */
  6815. if (ppd->link_downed < (u32)UINT_MAX)
  6816. ppd->link_downed++;
  6817. reg &= ~DCC_ERR_FLG_LINK_ERR_SMASK;
  6818. }
  6819. if (reg & DCC_ERR_FLG_FMCONFIG_ERR_SMASK) {
  6820. u8 reason_valid = 1;
  6821. info = read_csr(dd, DCC_ERR_INFO_FMCONFIG);
  6822. if (!(dd->err_info_fmconfig & OPA_EI_STATUS_SMASK)) {
  6823. dd->err_info_fmconfig = info & OPA_EI_CODE_SMASK;
  6824. /* set status bit */
  6825. dd->err_info_fmconfig |= OPA_EI_STATUS_SMASK;
  6826. }
  6827. switch (info) {
  6828. case 0:
  6829. case 1:
  6830. case 2:
  6831. case 3:
  6832. case 4:
  6833. case 5:
  6834. case 6:
  6835. extra = fm_config_txt[info];
  6836. break;
  6837. case 8:
  6838. extra = fm_config_txt[info];
  6839. if (ppd->port_error_action &
  6840. OPA_PI_MASK_FM_CFG_UNSUPPORTED_VL_MARKER) {
  6841. do_bounce = 1;
  6842. /*
  6843. * lcl_reason cannot be derived from info
  6844. * for this error
  6845. */
  6846. lcl_reason =
  6847. OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER;
  6848. }
  6849. break;
  6850. default:
  6851. reason_valid = 0;
  6852. snprintf(buf, sizeof(buf), "reserved%lld", info);
  6853. extra = buf;
  6854. break;
  6855. }
  6856. if (reason_valid && !do_bounce) {
  6857. do_bounce = ppd->port_error_action &
  6858. (1 << (OPA_LDR_FMCONFIG_OFFSET + info));
  6859. lcl_reason = info + OPA_LINKDOWN_REASON_BAD_HEAD_DIST;
  6860. }
  6861. /* just report this */
  6862. dd_dev_info(dd, "DCC Error: fmconfig error: %s\n", extra);
  6863. reg &= ~DCC_ERR_FLG_FMCONFIG_ERR_SMASK;
  6864. }
  6865. if (reg & DCC_ERR_FLG_RCVPORT_ERR_SMASK) {
  6866. u8 reason_valid = 1;
  6867. info = read_csr(dd, DCC_ERR_INFO_PORTRCV);
  6868. hdr0 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR0);
  6869. hdr1 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR1);
  6870. if (!(dd->err_info_rcvport.status_and_code &
  6871. OPA_EI_STATUS_SMASK)) {
  6872. dd->err_info_rcvport.status_and_code =
  6873. info & OPA_EI_CODE_SMASK;
  6874. /* set status bit */
  6875. dd->err_info_rcvport.status_and_code |=
  6876. OPA_EI_STATUS_SMASK;
  6877. /*
  6878. * save first 2 flits in the packet that caused
  6879. * the error
  6880. */
  6881. dd->err_info_rcvport.packet_flit1 = hdr0;
  6882. dd->err_info_rcvport.packet_flit2 = hdr1;
  6883. }
  6884. switch (info) {
  6885. case 1:
  6886. case 2:
  6887. case 3:
  6888. case 4:
  6889. case 5:
  6890. case 6:
  6891. case 7:
  6892. case 9:
  6893. case 11:
  6894. case 12:
  6895. extra = port_rcv_txt[info];
  6896. break;
  6897. default:
  6898. reason_valid = 0;
  6899. snprintf(buf, sizeof(buf), "reserved%lld", info);
  6900. extra = buf;
  6901. break;
  6902. }
  6903. if (reason_valid && !do_bounce) {
  6904. do_bounce = ppd->port_error_action &
  6905. (1 << (OPA_LDR_PORTRCV_OFFSET + info));
  6906. lcl_reason = info + OPA_LINKDOWN_REASON_RCV_ERROR_0;
  6907. }
  6908. /* just report this */
  6909. dd_dev_info(dd, "DCC Error: PortRcv error: %s\n", extra);
  6910. dd_dev_info(dd, " hdr0 0x%llx, hdr1 0x%llx\n",
  6911. hdr0, hdr1);
  6912. reg &= ~DCC_ERR_FLG_RCVPORT_ERR_SMASK;
  6913. }
  6914. if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK) {
  6915. /* informative only */
  6916. dd_dev_info(dd, "8051 access to LCB blocked\n");
  6917. reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK;
  6918. }
  6919. if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK) {
  6920. /* informative only */
  6921. dd_dev_info(dd, "host access to LCB blocked\n");
  6922. reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK;
  6923. }
  6924. /* report any remaining errors */
  6925. if (reg)
  6926. dd_dev_info(dd, "DCC Error: %s\n",
  6927. dcc_err_string(buf, sizeof(buf), reg));
  6928. if (lcl_reason == 0)
  6929. lcl_reason = OPA_LINKDOWN_REASON_UNKNOWN;
  6930. if (do_bounce) {
  6931. dd_dev_info(dd, "%s: PortErrorAction bounce\n", __func__);
  6932. set_link_down_reason(ppd, lcl_reason, 0, lcl_reason);
  6933. queue_work(ppd->hfi1_wq, &ppd->link_bounce_work);
  6934. }
  6935. }
  6936. static void handle_lcb_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  6937. {
  6938. char buf[96];
  6939. dd_dev_info(dd, "LCB Error: %s\n",
  6940. lcb_err_string(buf, sizeof(buf), reg));
  6941. }
  6942. /*
  6943. * CCE block DC interrupt. Source is < 8.
  6944. */
  6945. static void is_dc_int(struct hfi1_devdata *dd, unsigned int source)
  6946. {
  6947. const struct err_reg_info *eri = &dc_errs[source];
  6948. if (eri->handler) {
  6949. interrupt_clear_down(dd, 0, eri);
  6950. } else if (source == 3 /* dc_lbm_int */) {
  6951. /*
  6952. * This indicates that a parity error has occurred on the
  6953. * address/control lines presented to the LBM. The error
  6954. * is a single pulse, there is no associated error flag,
  6955. * and it is non-maskable. This is because if a parity
  6956. * error occurs on the request the request is dropped.
  6957. * This should never occur, but it is nice to know if it
  6958. * ever does.
  6959. */
  6960. dd_dev_err(dd, "Parity error in DC LBM block\n");
  6961. } else {
  6962. dd_dev_err(dd, "Invalid DC interrupt %u\n", source);
  6963. }
  6964. }
  6965. /*
  6966. * TX block send credit interrupt. Source is < 160.
  6967. */
  6968. static void is_send_credit_int(struct hfi1_devdata *dd, unsigned int source)
  6969. {
  6970. sc_group_release_update(dd, source);
  6971. }
  6972. /*
  6973. * TX block SDMA interrupt. Source is < 48.
  6974. *
  6975. * SDMA interrupts are grouped by type:
  6976. *
  6977. * 0 - N-1 = SDma
  6978. * N - 2N-1 = SDmaProgress
  6979. * 2N - 3N-1 = SDmaIdle
  6980. */
  6981. static void is_sdma_eng_int(struct hfi1_devdata *dd, unsigned int source)
  6982. {
  6983. /* what interrupt */
  6984. unsigned int what = source / TXE_NUM_SDMA_ENGINES;
  6985. /* which engine */
  6986. unsigned int which = source % TXE_NUM_SDMA_ENGINES;
  6987. #ifdef CONFIG_SDMA_VERBOSITY
  6988. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", which,
  6989. slashstrip(__FILE__), __LINE__, __func__);
  6990. sdma_dumpstate(&dd->per_sdma[which]);
  6991. #endif
  6992. if (likely(what < 3 && which < dd->num_sdma)) {
  6993. sdma_engine_interrupt(&dd->per_sdma[which], 1ull << source);
  6994. } else {
  6995. /* should not happen */
  6996. dd_dev_err(dd, "Invalid SDMA interrupt 0x%x\n", source);
  6997. }
  6998. }
  6999. /*
  7000. * RX block receive available interrupt. Source is < 160.
  7001. */
  7002. static void is_rcv_avail_int(struct hfi1_devdata *dd, unsigned int source)
  7003. {
  7004. struct hfi1_ctxtdata *rcd;
  7005. char *err_detail;
  7006. if (likely(source < dd->num_rcv_contexts)) {
  7007. rcd = dd->rcd[source];
  7008. if (rcd) {
  7009. if (source < dd->first_user_ctxt)
  7010. rcd->do_interrupt(rcd, 0);
  7011. else
  7012. handle_user_interrupt(rcd);
  7013. return; /* OK */
  7014. }
  7015. /* received an interrupt, but no rcd */
  7016. err_detail = "dataless";
  7017. } else {
  7018. /* received an interrupt, but are not using that context */
  7019. err_detail = "out of range";
  7020. }
  7021. dd_dev_err(dd, "unexpected %s receive available context interrupt %u\n",
  7022. err_detail, source);
  7023. }
  7024. /*
  7025. * RX block receive urgent interrupt. Source is < 160.
  7026. */
  7027. static void is_rcv_urgent_int(struct hfi1_devdata *dd, unsigned int source)
  7028. {
  7029. struct hfi1_ctxtdata *rcd;
  7030. char *err_detail;
  7031. if (likely(source < dd->num_rcv_contexts)) {
  7032. rcd = dd->rcd[source];
  7033. if (rcd) {
  7034. /* only pay attention to user urgent interrupts */
  7035. if (source >= dd->first_user_ctxt)
  7036. handle_user_interrupt(rcd);
  7037. return; /* OK */
  7038. }
  7039. /* received an interrupt, but no rcd */
  7040. err_detail = "dataless";
  7041. } else {
  7042. /* received an interrupt, but are not using that context */
  7043. err_detail = "out of range";
  7044. }
  7045. dd_dev_err(dd, "unexpected %s receive urgent context interrupt %u\n",
  7046. err_detail, source);
  7047. }
  7048. /*
  7049. * Reserved range interrupt. Should not be called in normal operation.
  7050. */
  7051. static void is_reserved_int(struct hfi1_devdata *dd, unsigned int source)
  7052. {
  7053. char name[64];
  7054. dd_dev_err(dd, "unexpected %s interrupt\n",
  7055. is_reserved_name(name, sizeof(name), source));
  7056. }
  7057. static const struct is_table is_table[] = {
  7058. /*
  7059. * start end
  7060. * name func interrupt func
  7061. */
  7062. { IS_GENERAL_ERR_START, IS_GENERAL_ERR_END,
  7063. is_misc_err_name, is_misc_err_int },
  7064. { IS_SDMAENG_ERR_START, IS_SDMAENG_ERR_END,
  7065. is_sdma_eng_err_name, is_sdma_eng_err_int },
  7066. { IS_SENDCTXT_ERR_START, IS_SENDCTXT_ERR_END,
  7067. is_sendctxt_err_name, is_sendctxt_err_int },
  7068. { IS_SDMA_START, IS_SDMA_END,
  7069. is_sdma_eng_name, is_sdma_eng_int },
  7070. { IS_VARIOUS_START, IS_VARIOUS_END,
  7071. is_various_name, is_various_int },
  7072. { IS_DC_START, IS_DC_END,
  7073. is_dc_name, is_dc_int },
  7074. { IS_RCVAVAIL_START, IS_RCVAVAIL_END,
  7075. is_rcv_avail_name, is_rcv_avail_int },
  7076. { IS_RCVURGENT_START, IS_RCVURGENT_END,
  7077. is_rcv_urgent_name, is_rcv_urgent_int },
  7078. { IS_SENDCREDIT_START, IS_SENDCREDIT_END,
  7079. is_send_credit_name, is_send_credit_int},
  7080. { IS_RESERVED_START, IS_RESERVED_END,
  7081. is_reserved_name, is_reserved_int},
  7082. };
  7083. /*
  7084. * Interrupt source interrupt - called when the given source has an interrupt.
  7085. * Source is a bit index into an array of 64-bit integers.
  7086. */
  7087. static void is_interrupt(struct hfi1_devdata *dd, unsigned int source)
  7088. {
  7089. const struct is_table *entry;
  7090. /* avoids a double compare by walking the table in-order */
  7091. for (entry = &is_table[0]; entry->is_name; entry++) {
  7092. if (source < entry->end) {
  7093. trace_hfi1_interrupt(dd, entry, source);
  7094. entry->is_int(dd, source - entry->start);
  7095. return;
  7096. }
  7097. }
  7098. /* fell off the end */
  7099. dd_dev_err(dd, "invalid interrupt source %u\n", source);
  7100. }
  7101. /*
  7102. * General interrupt handler. This is able to correctly handle
  7103. * all interrupts in case INTx is used.
  7104. */
  7105. static irqreturn_t general_interrupt(int irq, void *data)
  7106. {
  7107. struct hfi1_devdata *dd = data;
  7108. u64 regs[CCE_NUM_INT_CSRS];
  7109. u32 bit;
  7110. int i;
  7111. this_cpu_inc(*dd->int_counter);
  7112. /* phase 1: scan and clear all handled interrupts */
  7113. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  7114. if (dd->gi_mask[i] == 0) {
  7115. regs[i] = 0; /* used later */
  7116. continue;
  7117. }
  7118. regs[i] = read_csr(dd, CCE_INT_STATUS + (8 * i)) &
  7119. dd->gi_mask[i];
  7120. /* only clear if anything is set */
  7121. if (regs[i])
  7122. write_csr(dd, CCE_INT_CLEAR + (8 * i), regs[i]);
  7123. }
  7124. /* phase 2: call the appropriate handler */
  7125. for_each_set_bit(bit, (unsigned long *)&regs[0],
  7126. CCE_NUM_INT_CSRS * 64) {
  7127. is_interrupt(dd, bit);
  7128. }
  7129. return IRQ_HANDLED;
  7130. }
  7131. static irqreturn_t sdma_interrupt(int irq, void *data)
  7132. {
  7133. struct sdma_engine *sde = data;
  7134. struct hfi1_devdata *dd = sde->dd;
  7135. u64 status;
  7136. #ifdef CONFIG_SDMA_VERBOSITY
  7137. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  7138. slashstrip(__FILE__), __LINE__, __func__);
  7139. sdma_dumpstate(sde);
  7140. #endif
  7141. this_cpu_inc(*dd->int_counter);
  7142. /* This read_csr is really bad in the hot path */
  7143. status = read_csr(dd,
  7144. CCE_INT_STATUS + (8 * (IS_SDMA_START / 64)))
  7145. & sde->imask;
  7146. if (likely(status)) {
  7147. /* clear the interrupt(s) */
  7148. write_csr(dd,
  7149. CCE_INT_CLEAR + (8 * (IS_SDMA_START / 64)),
  7150. status);
  7151. /* handle the interrupt(s) */
  7152. sdma_engine_interrupt(sde, status);
  7153. } else
  7154. dd_dev_err(dd, "SDMA engine %u interrupt, but no status bits set\n",
  7155. sde->this_idx);
  7156. return IRQ_HANDLED;
  7157. }
  7158. /*
  7159. * Clear the receive interrupt. Use a read of the interrupt clear CSR
  7160. * to insure that the write completed. This does NOT guarantee that
  7161. * queued DMA writes to memory from the chip are pushed.
  7162. */
  7163. static inline void clear_recv_intr(struct hfi1_ctxtdata *rcd)
  7164. {
  7165. struct hfi1_devdata *dd = rcd->dd;
  7166. u32 addr = CCE_INT_CLEAR + (8 * rcd->ireg);
  7167. mmiowb(); /* make sure everything before is written */
  7168. write_csr(dd, addr, rcd->imask);
  7169. /* force the above write on the chip and get a value back */
  7170. (void)read_csr(dd, addr);
  7171. }
  7172. /* force the receive interrupt */
  7173. void force_recv_intr(struct hfi1_ctxtdata *rcd)
  7174. {
  7175. write_csr(rcd->dd, CCE_INT_FORCE + (8 * rcd->ireg), rcd->imask);
  7176. }
  7177. /*
  7178. * Return non-zero if a packet is present.
  7179. *
  7180. * This routine is called when rechecking for packets after the RcvAvail
  7181. * interrupt has been cleared down. First, do a quick check of memory for
  7182. * a packet present. If not found, use an expensive CSR read of the context
  7183. * tail to determine the actual tail. The CSR read is necessary because there
  7184. * is no method to push pending DMAs to memory other than an interrupt and we
  7185. * are trying to determine if we need to force an interrupt.
  7186. */
  7187. static inline int check_packet_present(struct hfi1_ctxtdata *rcd)
  7188. {
  7189. u32 tail;
  7190. int present;
  7191. if (!HFI1_CAP_IS_KSET(DMA_RTAIL))
  7192. present = (rcd->seq_cnt ==
  7193. rhf_rcv_seq(rhf_to_cpu(get_rhf_addr(rcd))));
  7194. else /* is RDMA rtail */
  7195. present = (rcd->head != get_rcvhdrtail(rcd));
  7196. if (present)
  7197. return 1;
  7198. /* fall back to a CSR read, correct indpendent of DMA_RTAIL */
  7199. tail = (u32)read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
  7200. return rcd->head != tail;
  7201. }
  7202. /*
  7203. * Receive packet IRQ handler. This routine expects to be on its own IRQ.
  7204. * This routine will try to handle packets immediately (latency), but if
  7205. * it finds too many, it will invoke the thread handler (bandwitdh). The
  7206. * chip receive interrupt is *not* cleared down until this or the thread (if
  7207. * invoked) is finished. The intent is to avoid extra interrupts while we
  7208. * are processing packets anyway.
  7209. */
  7210. static irqreturn_t receive_context_interrupt(int irq, void *data)
  7211. {
  7212. struct hfi1_ctxtdata *rcd = data;
  7213. struct hfi1_devdata *dd = rcd->dd;
  7214. int disposition;
  7215. int present;
  7216. trace_hfi1_receive_interrupt(dd, rcd->ctxt);
  7217. this_cpu_inc(*dd->int_counter);
  7218. aspm_ctx_disable(rcd);
  7219. /* receive interrupt remains blocked while processing packets */
  7220. disposition = rcd->do_interrupt(rcd, 0);
  7221. /*
  7222. * Too many packets were seen while processing packets in this
  7223. * IRQ handler. Invoke the handler thread. The receive interrupt
  7224. * remains blocked.
  7225. */
  7226. if (disposition == RCV_PKT_LIMIT)
  7227. return IRQ_WAKE_THREAD;
  7228. /*
  7229. * The packet processor detected no more packets. Clear the receive
  7230. * interrupt and recheck for a packet packet that may have arrived
  7231. * after the previous check and interrupt clear. If a packet arrived,
  7232. * force another interrupt.
  7233. */
  7234. clear_recv_intr(rcd);
  7235. present = check_packet_present(rcd);
  7236. if (present)
  7237. force_recv_intr(rcd);
  7238. return IRQ_HANDLED;
  7239. }
  7240. /*
  7241. * Receive packet thread handler. This expects to be invoked with the
  7242. * receive interrupt still blocked.
  7243. */
  7244. static irqreturn_t receive_context_thread(int irq, void *data)
  7245. {
  7246. struct hfi1_ctxtdata *rcd = data;
  7247. int present;
  7248. /* receive interrupt is still blocked from the IRQ handler */
  7249. (void)rcd->do_interrupt(rcd, 1);
  7250. /*
  7251. * The packet processor will only return if it detected no more
  7252. * packets. Hold IRQs here so we can safely clear the interrupt and
  7253. * recheck for a packet that may have arrived after the previous
  7254. * check and the interrupt clear. If a packet arrived, force another
  7255. * interrupt.
  7256. */
  7257. local_irq_disable();
  7258. clear_recv_intr(rcd);
  7259. present = check_packet_present(rcd);
  7260. if (present)
  7261. force_recv_intr(rcd);
  7262. local_irq_enable();
  7263. return IRQ_HANDLED;
  7264. }
  7265. /* ========================================================================= */
  7266. u32 read_physical_state(struct hfi1_devdata *dd)
  7267. {
  7268. u64 reg;
  7269. reg = read_csr(dd, DC_DC8051_STS_CUR_STATE);
  7270. return (reg >> DC_DC8051_STS_CUR_STATE_PORT_SHIFT)
  7271. & DC_DC8051_STS_CUR_STATE_PORT_MASK;
  7272. }
  7273. u32 read_logical_state(struct hfi1_devdata *dd)
  7274. {
  7275. u64 reg;
  7276. reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
  7277. return (reg >> DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT)
  7278. & DCC_CFG_PORT_CONFIG_LINK_STATE_MASK;
  7279. }
  7280. static void set_logical_state(struct hfi1_devdata *dd, u32 chip_lstate)
  7281. {
  7282. u64 reg;
  7283. reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
  7284. /* clear current state, set new state */
  7285. reg &= ~DCC_CFG_PORT_CONFIG_LINK_STATE_SMASK;
  7286. reg |= (u64)chip_lstate << DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT;
  7287. write_csr(dd, DCC_CFG_PORT_CONFIG, reg);
  7288. }
  7289. /*
  7290. * Use the 8051 to read a LCB CSR.
  7291. */
  7292. static int read_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 *data)
  7293. {
  7294. u32 regno;
  7295. int ret;
  7296. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  7297. if (acquire_lcb_access(dd, 0) == 0) {
  7298. *data = read_csr(dd, addr);
  7299. release_lcb_access(dd, 0);
  7300. return 0;
  7301. }
  7302. return -EBUSY;
  7303. }
  7304. /* register is an index of LCB registers: (offset - base) / 8 */
  7305. regno = (addr - DC_LCB_CFG_RUN) >> 3;
  7306. ret = do_8051_command(dd, HCMD_READ_LCB_CSR, regno, data);
  7307. if (ret != HCMD_SUCCESS)
  7308. return -EBUSY;
  7309. return 0;
  7310. }
  7311. /*
  7312. * Read an LCB CSR. Access may not be in host control, so check.
  7313. * Return 0 on success, -EBUSY on failure.
  7314. */
  7315. int read_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 *data)
  7316. {
  7317. struct hfi1_pportdata *ppd = dd->pport;
  7318. /* if up, go through the 8051 for the value */
  7319. if (ppd->host_link_state & HLS_UP)
  7320. return read_lcb_via_8051(dd, addr, data);
  7321. /* if going up or down, no access */
  7322. if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE))
  7323. return -EBUSY;
  7324. /* otherwise, host has access */
  7325. *data = read_csr(dd, addr);
  7326. return 0;
  7327. }
  7328. /*
  7329. * Use the 8051 to write a LCB CSR.
  7330. */
  7331. static int write_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 data)
  7332. {
  7333. u32 regno;
  7334. int ret;
  7335. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR ||
  7336. (dd->dc8051_ver < dc8051_ver(0, 20))) {
  7337. if (acquire_lcb_access(dd, 0) == 0) {
  7338. write_csr(dd, addr, data);
  7339. release_lcb_access(dd, 0);
  7340. return 0;
  7341. }
  7342. return -EBUSY;
  7343. }
  7344. /* register is an index of LCB registers: (offset - base) / 8 */
  7345. regno = (addr - DC_LCB_CFG_RUN) >> 3;
  7346. ret = do_8051_command(dd, HCMD_WRITE_LCB_CSR, regno, &data);
  7347. if (ret != HCMD_SUCCESS)
  7348. return -EBUSY;
  7349. return 0;
  7350. }
  7351. /*
  7352. * Write an LCB CSR. Access may not be in host control, so check.
  7353. * Return 0 on success, -EBUSY on failure.
  7354. */
  7355. int write_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 data)
  7356. {
  7357. struct hfi1_pportdata *ppd = dd->pport;
  7358. /* if up, go through the 8051 for the value */
  7359. if (ppd->host_link_state & HLS_UP)
  7360. return write_lcb_via_8051(dd, addr, data);
  7361. /* if going up or down, no access */
  7362. if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE))
  7363. return -EBUSY;
  7364. /* otherwise, host has access */
  7365. write_csr(dd, addr, data);
  7366. return 0;
  7367. }
  7368. /*
  7369. * Returns:
  7370. * < 0 = Linux error, not able to get access
  7371. * > 0 = 8051 command RETURN_CODE
  7372. */
  7373. static int do_8051_command(
  7374. struct hfi1_devdata *dd,
  7375. u32 type,
  7376. u64 in_data,
  7377. u64 *out_data)
  7378. {
  7379. u64 reg, completed;
  7380. int return_code;
  7381. unsigned long flags;
  7382. unsigned long timeout;
  7383. hfi1_cdbg(DC8051, "type %d, data 0x%012llx", type, in_data);
  7384. /*
  7385. * Alternative to holding the lock for a long time:
  7386. * - keep busy wait - have other users bounce off
  7387. */
  7388. spin_lock_irqsave(&dd->dc8051_lock, flags);
  7389. /* We can't send any commands to the 8051 if it's in reset */
  7390. if (dd->dc_shutdown) {
  7391. return_code = -ENODEV;
  7392. goto fail;
  7393. }
  7394. /*
  7395. * If an 8051 host command timed out previously, then the 8051 is
  7396. * stuck.
  7397. *
  7398. * On first timeout, attempt to reset and restart the entire DC
  7399. * block (including 8051). (Is this too big of a hammer?)
  7400. *
  7401. * If the 8051 times out a second time, the reset did not bring it
  7402. * back to healthy life. In that case, fail any subsequent commands.
  7403. */
  7404. if (dd->dc8051_timed_out) {
  7405. if (dd->dc8051_timed_out > 1) {
  7406. dd_dev_err(dd,
  7407. "Previous 8051 host command timed out, skipping command %u\n",
  7408. type);
  7409. return_code = -ENXIO;
  7410. goto fail;
  7411. }
  7412. spin_unlock_irqrestore(&dd->dc8051_lock, flags);
  7413. dc_shutdown(dd);
  7414. dc_start(dd);
  7415. spin_lock_irqsave(&dd->dc8051_lock, flags);
  7416. }
  7417. /*
  7418. * If there is no timeout, then the 8051 command interface is
  7419. * waiting for a command.
  7420. */
  7421. /*
  7422. * When writing a LCB CSR, out_data contains the full value to
  7423. * to be written, while in_data contains the relative LCB
  7424. * address in 7:0. Do the work here, rather than the caller,
  7425. * of distrubting the write data to where it needs to go:
  7426. *
  7427. * Write data
  7428. * 39:00 -> in_data[47:8]
  7429. * 47:40 -> DC8051_CFG_EXT_DEV_0.RETURN_CODE
  7430. * 63:48 -> DC8051_CFG_EXT_DEV_0.RSP_DATA
  7431. */
  7432. if (type == HCMD_WRITE_LCB_CSR) {
  7433. in_data |= ((*out_data) & 0xffffffffffull) << 8;
  7434. reg = ((((*out_data) >> 40) & 0xff) <<
  7435. DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT)
  7436. | ((((*out_data) >> 48) & 0xffff) <<
  7437. DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
  7438. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, reg);
  7439. }
  7440. /*
  7441. * Do two writes: the first to stabilize the type and req_data, the
  7442. * second to activate.
  7443. */
  7444. reg = ((u64)type & DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_MASK)
  7445. << DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_SHIFT
  7446. | (in_data & DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_MASK)
  7447. << DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_SHIFT;
  7448. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
  7449. reg |= DC_DC8051_CFG_HOST_CMD_0_REQ_NEW_SMASK;
  7450. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
  7451. /* wait for completion, alternate: interrupt */
  7452. timeout = jiffies + msecs_to_jiffies(DC8051_COMMAND_TIMEOUT);
  7453. while (1) {
  7454. reg = read_csr(dd, DC_DC8051_CFG_HOST_CMD_1);
  7455. completed = reg & DC_DC8051_CFG_HOST_CMD_1_COMPLETED_SMASK;
  7456. if (completed)
  7457. break;
  7458. if (time_after(jiffies, timeout)) {
  7459. dd->dc8051_timed_out++;
  7460. dd_dev_err(dd, "8051 host command %u timeout\n", type);
  7461. if (out_data)
  7462. *out_data = 0;
  7463. return_code = -ETIMEDOUT;
  7464. goto fail;
  7465. }
  7466. udelay(2);
  7467. }
  7468. if (out_data) {
  7469. *out_data = (reg >> DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_SHIFT)
  7470. & DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_MASK;
  7471. if (type == HCMD_READ_LCB_CSR) {
  7472. /* top 16 bits are in a different register */
  7473. *out_data |= (read_csr(dd, DC_DC8051_CFG_EXT_DEV_1)
  7474. & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SMASK)
  7475. << (48
  7476. - DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT);
  7477. }
  7478. }
  7479. return_code = (reg >> DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_SHIFT)
  7480. & DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_MASK;
  7481. dd->dc8051_timed_out = 0;
  7482. /*
  7483. * Clear command for next user.
  7484. */
  7485. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, 0);
  7486. fail:
  7487. spin_unlock_irqrestore(&dd->dc8051_lock, flags);
  7488. return return_code;
  7489. }
  7490. static int set_physical_link_state(struct hfi1_devdata *dd, u64 state)
  7491. {
  7492. return do_8051_command(dd, HCMD_CHANGE_PHY_STATE, state, NULL);
  7493. }
  7494. int load_8051_config(struct hfi1_devdata *dd, u8 field_id,
  7495. u8 lane_id, u32 config_data)
  7496. {
  7497. u64 data;
  7498. int ret;
  7499. data = (u64)field_id << LOAD_DATA_FIELD_ID_SHIFT
  7500. | (u64)lane_id << LOAD_DATA_LANE_ID_SHIFT
  7501. | (u64)config_data << LOAD_DATA_DATA_SHIFT;
  7502. ret = do_8051_command(dd, HCMD_LOAD_CONFIG_DATA, data, NULL);
  7503. if (ret != HCMD_SUCCESS) {
  7504. dd_dev_err(dd,
  7505. "load 8051 config: field id %d, lane %d, err %d\n",
  7506. (int)field_id, (int)lane_id, ret);
  7507. }
  7508. return ret;
  7509. }
  7510. /*
  7511. * Read the 8051 firmware "registers". Use the RAM directly. Always
  7512. * set the result, even on error.
  7513. * Return 0 on success, -errno on failure
  7514. */
  7515. int read_8051_config(struct hfi1_devdata *dd, u8 field_id, u8 lane_id,
  7516. u32 *result)
  7517. {
  7518. u64 big_data;
  7519. u32 addr;
  7520. int ret;
  7521. /* address start depends on the lane_id */
  7522. if (lane_id < 4)
  7523. addr = (4 * NUM_GENERAL_FIELDS)
  7524. + (lane_id * 4 * NUM_LANE_FIELDS);
  7525. else
  7526. addr = 0;
  7527. addr += field_id * 4;
  7528. /* read is in 8-byte chunks, hardware will truncate the address down */
  7529. ret = read_8051_data(dd, addr, 8, &big_data);
  7530. if (ret == 0) {
  7531. /* extract the 4 bytes we want */
  7532. if (addr & 0x4)
  7533. *result = (u32)(big_data >> 32);
  7534. else
  7535. *result = (u32)big_data;
  7536. } else {
  7537. *result = 0;
  7538. dd_dev_err(dd, "%s: direct read failed, lane %d, field %d!\n",
  7539. __func__, lane_id, field_id);
  7540. }
  7541. return ret;
  7542. }
  7543. static int write_vc_local_phy(struct hfi1_devdata *dd, u8 power_management,
  7544. u8 continuous)
  7545. {
  7546. u32 frame;
  7547. frame = continuous << CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT
  7548. | power_management << POWER_MANAGEMENT_SHIFT;
  7549. return load_8051_config(dd, VERIFY_CAP_LOCAL_PHY,
  7550. GENERAL_CONFIG, frame);
  7551. }
  7552. static int write_vc_local_fabric(struct hfi1_devdata *dd, u8 vau, u8 z, u8 vcu,
  7553. u16 vl15buf, u8 crc_sizes)
  7554. {
  7555. u32 frame;
  7556. frame = (u32)vau << VAU_SHIFT
  7557. | (u32)z << Z_SHIFT
  7558. | (u32)vcu << VCU_SHIFT
  7559. | (u32)vl15buf << VL15BUF_SHIFT
  7560. | (u32)crc_sizes << CRC_SIZES_SHIFT;
  7561. return load_8051_config(dd, VERIFY_CAP_LOCAL_FABRIC,
  7562. GENERAL_CONFIG, frame);
  7563. }
  7564. static void read_vc_local_link_width(struct hfi1_devdata *dd, u8 *misc_bits,
  7565. u8 *flag_bits, u16 *link_widths)
  7566. {
  7567. u32 frame;
  7568. read_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG,
  7569. &frame);
  7570. *misc_bits = (frame >> MISC_CONFIG_BITS_SHIFT) & MISC_CONFIG_BITS_MASK;
  7571. *flag_bits = (frame >> LOCAL_FLAG_BITS_SHIFT) & LOCAL_FLAG_BITS_MASK;
  7572. *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
  7573. }
  7574. static int write_vc_local_link_width(struct hfi1_devdata *dd,
  7575. u8 misc_bits,
  7576. u8 flag_bits,
  7577. u16 link_widths)
  7578. {
  7579. u32 frame;
  7580. frame = (u32)misc_bits << MISC_CONFIG_BITS_SHIFT
  7581. | (u32)flag_bits << LOCAL_FLAG_BITS_SHIFT
  7582. | (u32)link_widths << LINK_WIDTH_SHIFT;
  7583. return load_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG,
  7584. frame);
  7585. }
  7586. static int write_local_device_id(struct hfi1_devdata *dd, u16 device_id,
  7587. u8 device_rev)
  7588. {
  7589. u32 frame;
  7590. frame = ((u32)device_id << LOCAL_DEVICE_ID_SHIFT)
  7591. | ((u32)device_rev << LOCAL_DEVICE_REV_SHIFT);
  7592. return load_8051_config(dd, LOCAL_DEVICE_ID, GENERAL_CONFIG, frame);
  7593. }
  7594. static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
  7595. u8 *device_rev)
  7596. {
  7597. u32 frame;
  7598. read_8051_config(dd, REMOTE_DEVICE_ID, GENERAL_CONFIG, &frame);
  7599. *device_id = (frame >> REMOTE_DEVICE_ID_SHIFT) & REMOTE_DEVICE_ID_MASK;
  7600. *device_rev = (frame >> REMOTE_DEVICE_REV_SHIFT)
  7601. & REMOTE_DEVICE_REV_MASK;
  7602. }
  7603. void read_misc_status(struct hfi1_devdata *dd, u8 *ver_a, u8 *ver_b)
  7604. {
  7605. u32 frame;
  7606. read_8051_config(dd, MISC_STATUS, GENERAL_CONFIG, &frame);
  7607. *ver_a = (frame >> STS_FM_VERSION_A_SHIFT) & STS_FM_VERSION_A_MASK;
  7608. *ver_b = (frame >> STS_FM_VERSION_B_SHIFT) & STS_FM_VERSION_B_MASK;
  7609. }
  7610. static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
  7611. u8 *continuous)
  7612. {
  7613. u32 frame;
  7614. read_8051_config(dd, VERIFY_CAP_REMOTE_PHY, GENERAL_CONFIG, &frame);
  7615. *power_management = (frame >> POWER_MANAGEMENT_SHIFT)
  7616. & POWER_MANAGEMENT_MASK;
  7617. *continuous = (frame >> CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT)
  7618. & CONTINIOUS_REMOTE_UPDATE_SUPPORT_MASK;
  7619. }
  7620. static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
  7621. u8 *vcu, u16 *vl15buf, u8 *crc_sizes)
  7622. {
  7623. u32 frame;
  7624. read_8051_config(dd, VERIFY_CAP_REMOTE_FABRIC, GENERAL_CONFIG, &frame);
  7625. *vau = (frame >> VAU_SHIFT) & VAU_MASK;
  7626. *z = (frame >> Z_SHIFT) & Z_MASK;
  7627. *vcu = (frame >> VCU_SHIFT) & VCU_MASK;
  7628. *vl15buf = (frame >> VL15BUF_SHIFT) & VL15BUF_MASK;
  7629. *crc_sizes = (frame >> CRC_SIZES_SHIFT) & CRC_SIZES_MASK;
  7630. }
  7631. static void read_vc_remote_link_width(struct hfi1_devdata *dd,
  7632. u8 *remote_tx_rate,
  7633. u16 *link_widths)
  7634. {
  7635. u32 frame;
  7636. read_8051_config(dd, VERIFY_CAP_REMOTE_LINK_WIDTH, GENERAL_CONFIG,
  7637. &frame);
  7638. *remote_tx_rate = (frame >> REMOTE_TX_RATE_SHIFT)
  7639. & REMOTE_TX_RATE_MASK;
  7640. *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
  7641. }
  7642. static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx)
  7643. {
  7644. u32 frame;
  7645. read_8051_config(dd, LOCAL_LNI_INFO, GENERAL_CONFIG, &frame);
  7646. *enable_lane_rx = (frame >> ENABLE_LANE_RX_SHIFT) & ENABLE_LANE_RX_MASK;
  7647. }
  7648. static void read_mgmt_allowed(struct hfi1_devdata *dd, u8 *mgmt_allowed)
  7649. {
  7650. u32 frame;
  7651. read_8051_config(dd, REMOTE_LNI_INFO, GENERAL_CONFIG, &frame);
  7652. *mgmt_allowed = (frame >> MGMT_ALLOWED_SHIFT) & MGMT_ALLOWED_MASK;
  7653. }
  7654. static void read_last_local_state(struct hfi1_devdata *dd, u32 *lls)
  7655. {
  7656. read_8051_config(dd, LAST_LOCAL_STATE_COMPLETE, GENERAL_CONFIG, lls);
  7657. }
  7658. static void read_last_remote_state(struct hfi1_devdata *dd, u32 *lrs)
  7659. {
  7660. read_8051_config(dd, LAST_REMOTE_STATE_COMPLETE, GENERAL_CONFIG, lrs);
  7661. }
  7662. void hfi1_read_link_quality(struct hfi1_devdata *dd, u8 *link_quality)
  7663. {
  7664. u32 frame;
  7665. int ret;
  7666. *link_quality = 0;
  7667. if (dd->pport->host_link_state & HLS_UP) {
  7668. ret = read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG,
  7669. &frame);
  7670. if (ret == 0)
  7671. *link_quality = (frame >> LINK_QUALITY_SHIFT)
  7672. & LINK_QUALITY_MASK;
  7673. }
  7674. }
  7675. static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc)
  7676. {
  7677. u32 frame;
  7678. read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG, &frame);
  7679. *pdrrc = (frame >> DOWN_REMOTE_REASON_SHIFT) & DOWN_REMOTE_REASON_MASK;
  7680. }
  7681. static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr)
  7682. {
  7683. u32 frame;
  7684. read_8051_config(dd, LINK_DOWN_REASON, GENERAL_CONFIG, &frame);
  7685. *ldr = (frame & 0xff);
  7686. }
  7687. static int read_tx_settings(struct hfi1_devdata *dd,
  7688. u8 *enable_lane_tx,
  7689. u8 *tx_polarity_inversion,
  7690. u8 *rx_polarity_inversion,
  7691. u8 *max_rate)
  7692. {
  7693. u32 frame;
  7694. int ret;
  7695. ret = read_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, &frame);
  7696. *enable_lane_tx = (frame >> ENABLE_LANE_TX_SHIFT)
  7697. & ENABLE_LANE_TX_MASK;
  7698. *tx_polarity_inversion = (frame >> TX_POLARITY_INVERSION_SHIFT)
  7699. & TX_POLARITY_INVERSION_MASK;
  7700. *rx_polarity_inversion = (frame >> RX_POLARITY_INVERSION_SHIFT)
  7701. & RX_POLARITY_INVERSION_MASK;
  7702. *max_rate = (frame >> MAX_RATE_SHIFT) & MAX_RATE_MASK;
  7703. return ret;
  7704. }
  7705. static int write_tx_settings(struct hfi1_devdata *dd,
  7706. u8 enable_lane_tx,
  7707. u8 tx_polarity_inversion,
  7708. u8 rx_polarity_inversion,
  7709. u8 max_rate)
  7710. {
  7711. u32 frame;
  7712. /* no need to mask, all variable sizes match field widths */
  7713. frame = enable_lane_tx << ENABLE_LANE_TX_SHIFT
  7714. | tx_polarity_inversion << TX_POLARITY_INVERSION_SHIFT
  7715. | rx_polarity_inversion << RX_POLARITY_INVERSION_SHIFT
  7716. | max_rate << MAX_RATE_SHIFT;
  7717. return load_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, frame);
  7718. }
  7719. /*
  7720. * Read an idle LCB message.
  7721. *
  7722. * Returns 0 on success, -EINVAL on error
  7723. */
  7724. static int read_idle_message(struct hfi1_devdata *dd, u64 type, u64 *data_out)
  7725. {
  7726. int ret;
  7727. ret = do_8051_command(dd, HCMD_READ_LCB_IDLE_MSG, type, data_out);
  7728. if (ret != HCMD_SUCCESS) {
  7729. dd_dev_err(dd, "read idle message: type %d, err %d\n",
  7730. (u32)type, ret);
  7731. return -EINVAL;
  7732. }
  7733. dd_dev_info(dd, "%s: read idle message 0x%llx\n", __func__, *data_out);
  7734. /* return only the payload as we already know the type */
  7735. *data_out >>= IDLE_PAYLOAD_SHIFT;
  7736. return 0;
  7737. }
  7738. /*
  7739. * Read an idle SMA message. To be done in response to a notification from
  7740. * the 8051.
  7741. *
  7742. * Returns 0 on success, -EINVAL on error
  7743. */
  7744. static int read_idle_sma(struct hfi1_devdata *dd, u64 *data)
  7745. {
  7746. return read_idle_message(dd, (u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT,
  7747. data);
  7748. }
  7749. /*
  7750. * Send an idle LCB message.
  7751. *
  7752. * Returns 0 on success, -EINVAL on error
  7753. */
  7754. static int send_idle_message(struct hfi1_devdata *dd, u64 data)
  7755. {
  7756. int ret;
  7757. dd_dev_info(dd, "%s: sending idle message 0x%llx\n", __func__, data);
  7758. ret = do_8051_command(dd, HCMD_SEND_LCB_IDLE_MSG, data, NULL);
  7759. if (ret != HCMD_SUCCESS) {
  7760. dd_dev_err(dd, "send idle message: data 0x%llx, err %d\n",
  7761. data, ret);
  7762. return -EINVAL;
  7763. }
  7764. return 0;
  7765. }
  7766. /*
  7767. * Send an idle SMA message.
  7768. *
  7769. * Returns 0 on success, -EINVAL on error
  7770. */
  7771. int send_idle_sma(struct hfi1_devdata *dd, u64 message)
  7772. {
  7773. u64 data;
  7774. data = ((message & IDLE_PAYLOAD_MASK) << IDLE_PAYLOAD_SHIFT) |
  7775. ((u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT);
  7776. return send_idle_message(dd, data);
  7777. }
  7778. /*
  7779. * Initialize the LCB then do a quick link up. This may or may not be
  7780. * in loopback.
  7781. *
  7782. * return 0 on success, -errno on error
  7783. */
  7784. static int do_quick_linkup(struct hfi1_devdata *dd)
  7785. {
  7786. u64 reg;
  7787. unsigned long timeout;
  7788. int ret;
  7789. lcb_shutdown(dd, 0);
  7790. if (loopback) {
  7791. /* LCB_CFG_LOOPBACK.VAL = 2 */
  7792. /* LCB_CFG_LANE_WIDTH.VAL = 0 */
  7793. write_csr(dd, DC_LCB_CFG_LOOPBACK,
  7794. IB_PACKET_TYPE << DC_LCB_CFG_LOOPBACK_VAL_SHIFT);
  7795. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
  7796. }
  7797. /* start the LCBs */
  7798. /* LCB_CFG_TX_FIFOS_RESET.VAL = 0 */
  7799. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  7800. /* simulator only loopback steps */
  7801. if (loopback && dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  7802. /* LCB_CFG_RUN.EN = 1 */
  7803. write_csr(dd, DC_LCB_CFG_RUN,
  7804. 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
  7805. /* watch LCB_STS_LINK_TRANSFER_ACTIVE */
  7806. timeout = jiffies + msecs_to_jiffies(10);
  7807. while (1) {
  7808. reg = read_csr(dd, DC_LCB_STS_LINK_TRANSFER_ACTIVE);
  7809. if (reg)
  7810. break;
  7811. if (time_after(jiffies, timeout)) {
  7812. dd_dev_err(dd,
  7813. "timeout waiting for LINK_TRANSFER_ACTIVE\n");
  7814. return -ETIMEDOUT;
  7815. }
  7816. udelay(2);
  7817. }
  7818. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP,
  7819. 1ull << DC_LCB_CFG_ALLOW_LINK_UP_VAL_SHIFT);
  7820. }
  7821. if (!loopback) {
  7822. /*
  7823. * When doing quick linkup and not in loopback, both
  7824. * sides must be done with LCB set-up before either
  7825. * starts the quick linkup. Put a delay here so that
  7826. * both sides can be started and have a chance to be
  7827. * done with LCB set up before resuming.
  7828. */
  7829. dd_dev_err(dd,
  7830. "Pausing for peer to be finished with LCB set up\n");
  7831. msleep(5000);
  7832. dd_dev_err(dd, "Continuing with quick linkup\n");
  7833. }
  7834. write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
  7835. set_8051_lcb_access(dd);
  7836. /*
  7837. * State "quick" LinkUp request sets the physical link state to
  7838. * LinkUp without a verify capability sequence.
  7839. * This state is in simulator v37 and later.
  7840. */
  7841. ret = set_physical_link_state(dd, PLS_QUICK_LINKUP);
  7842. if (ret != HCMD_SUCCESS) {
  7843. dd_dev_err(dd,
  7844. "%s: set physical link state to quick LinkUp failed with return %d\n",
  7845. __func__, ret);
  7846. set_host_lcb_access(dd);
  7847. write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
  7848. if (ret >= 0)
  7849. ret = -EINVAL;
  7850. return ret;
  7851. }
  7852. return 0; /* success */
  7853. }
  7854. /*
  7855. * Set the SerDes to internal loopback mode.
  7856. * Returns 0 on success, -errno on error.
  7857. */
  7858. static int set_serdes_loopback_mode(struct hfi1_devdata *dd)
  7859. {
  7860. int ret;
  7861. ret = set_physical_link_state(dd, PLS_INTERNAL_SERDES_LOOPBACK);
  7862. if (ret == HCMD_SUCCESS)
  7863. return 0;
  7864. dd_dev_err(dd,
  7865. "Set physical link state to SerDes Loopback failed with return %d\n",
  7866. ret);
  7867. if (ret >= 0)
  7868. ret = -EINVAL;
  7869. return ret;
  7870. }
  7871. /*
  7872. * Do all special steps to set up loopback.
  7873. */
  7874. static int init_loopback(struct hfi1_devdata *dd)
  7875. {
  7876. dd_dev_info(dd, "Entering loopback mode\n");
  7877. /* all loopbacks should disable self GUID check */
  7878. write_csr(dd, DC_DC8051_CFG_MODE,
  7879. (read_csr(dd, DC_DC8051_CFG_MODE) | DISABLE_SELF_GUID_CHECK));
  7880. /*
  7881. * The simulator has only one loopback option - LCB. Switch
  7882. * to that option, which includes quick link up.
  7883. *
  7884. * Accept all valid loopback values.
  7885. */
  7886. if ((dd->icode == ICODE_FUNCTIONAL_SIMULATOR) &&
  7887. (loopback == LOOPBACK_SERDES || loopback == LOOPBACK_LCB ||
  7888. loopback == LOOPBACK_CABLE)) {
  7889. loopback = LOOPBACK_LCB;
  7890. quick_linkup = 1;
  7891. return 0;
  7892. }
  7893. /* handle serdes loopback */
  7894. if (loopback == LOOPBACK_SERDES) {
  7895. /* internal serdes loopack needs quick linkup on RTL */
  7896. if (dd->icode == ICODE_RTL_SILICON)
  7897. quick_linkup = 1;
  7898. return set_serdes_loopback_mode(dd);
  7899. }
  7900. /* LCB loopback - handled at poll time */
  7901. if (loopback == LOOPBACK_LCB) {
  7902. quick_linkup = 1; /* LCB is always quick linkup */
  7903. /* not supported in emulation due to emulation RTL changes */
  7904. if (dd->icode == ICODE_FPGA_EMULATION) {
  7905. dd_dev_err(dd,
  7906. "LCB loopback not supported in emulation\n");
  7907. return -EINVAL;
  7908. }
  7909. return 0;
  7910. }
  7911. /* external cable loopback requires no extra steps */
  7912. if (loopback == LOOPBACK_CABLE)
  7913. return 0;
  7914. dd_dev_err(dd, "Invalid loopback mode %d\n", loopback);
  7915. return -EINVAL;
  7916. }
  7917. /*
  7918. * Translate from the OPA_LINK_WIDTH handed to us by the FM to bits
  7919. * used in the Verify Capability link width attribute.
  7920. */
  7921. static u16 opa_to_vc_link_widths(u16 opa_widths)
  7922. {
  7923. int i;
  7924. u16 result = 0;
  7925. static const struct link_bits {
  7926. u16 from;
  7927. u16 to;
  7928. } opa_link_xlate[] = {
  7929. { OPA_LINK_WIDTH_1X, 1 << (1 - 1) },
  7930. { OPA_LINK_WIDTH_2X, 1 << (2 - 1) },
  7931. { OPA_LINK_WIDTH_3X, 1 << (3 - 1) },
  7932. { OPA_LINK_WIDTH_4X, 1 << (4 - 1) },
  7933. };
  7934. for (i = 0; i < ARRAY_SIZE(opa_link_xlate); i++) {
  7935. if (opa_widths & opa_link_xlate[i].from)
  7936. result |= opa_link_xlate[i].to;
  7937. }
  7938. return result;
  7939. }
  7940. /*
  7941. * Set link attributes before moving to polling.
  7942. */
  7943. static int set_local_link_attributes(struct hfi1_pportdata *ppd)
  7944. {
  7945. struct hfi1_devdata *dd = ppd->dd;
  7946. u8 enable_lane_tx;
  7947. u8 tx_polarity_inversion;
  7948. u8 rx_polarity_inversion;
  7949. int ret;
  7950. /* reset our fabric serdes to clear any lingering problems */
  7951. fabric_serdes_reset(dd);
  7952. /* set the local tx rate - need to read-modify-write */
  7953. ret = read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
  7954. &rx_polarity_inversion, &ppd->local_tx_rate);
  7955. if (ret)
  7956. goto set_local_link_attributes_fail;
  7957. if (dd->dc8051_ver < dc8051_ver(0, 20)) {
  7958. /* set the tx rate to the fastest enabled */
  7959. if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
  7960. ppd->local_tx_rate = 1;
  7961. else
  7962. ppd->local_tx_rate = 0;
  7963. } else {
  7964. /* set the tx rate to all enabled */
  7965. ppd->local_tx_rate = 0;
  7966. if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
  7967. ppd->local_tx_rate |= 2;
  7968. if (ppd->link_speed_enabled & OPA_LINK_SPEED_12_5G)
  7969. ppd->local_tx_rate |= 1;
  7970. }
  7971. enable_lane_tx = 0xF; /* enable all four lanes */
  7972. ret = write_tx_settings(dd, enable_lane_tx, tx_polarity_inversion,
  7973. rx_polarity_inversion, ppd->local_tx_rate);
  7974. if (ret != HCMD_SUCCESS)
  7975. goto set_local_link_attributes_fail;
  7976. /*
  7977. * DC supports continuous updates.
  7978. */
  7979. ret = write_vc_local_phy(dd,
  7980. 0 /* no power management */,
  7981. 1 /* continuous updates */);
  7982. if (ret != HCMD_SUCCESS)
  7983. goto set_local_link_attributes_fail;
  7984. /* z=1 in the next call: AU of 0 is not supported by the hardware */
  7985. ret = write_vc_local_fabric(dd, dd->vau, 1, dd->vcu, dd->vl15_init,
  7986. ppd->port_crc_mode_enabled);
  7987. if (ret != HCMD_SUCCESS)
  7988. goto set_local_link_attributes_fail;
  7989. ret = write_vc_local_link_width(dd, 0, 0,
  7990. opa_to_vc_link_widths(
  7991. ppd->link_width_enabled));
  7992. if (ret != HCMD_SUCCESS)
  7993. goto set_local_link_attributes_fail;
  7994. /* let peer know who we are */
  7995. ret = write_local_device_id(dd, dd->pcidev->device, dd->minrev);
  7996. if (ret == HCMD_SUCCESS)
  7997. return 0;
  7998. set_local_link_attributes_fail:
  7999. dd_dev_err(dd,
  8000. "Failed to set local link attributes, return 0x%x\n",
  8001. ret);
  8002. return ret;
  8003. }
  8004. /*
  8005. * Call this to start the link.
  8006. * Do not do anything if the link is disabled.
  8007. * Returns 0 if link is disabled, moved to polling, or the driver is not ready.
  8008. */
  8009. int start_link(struct hfi1_pportdata *ppd)
  8010. {
  8011. /*
  8012. * Tune the SerDes to a ballpark setting for optimal signal and bit
  8013. * error rate. Needs to be done before starting the link.
  8014. */
  8015. tune_serdes(ppd);
  8016. if (!ppd->link_enabled) {
  8017. dd_dev_info(ppd->dd,
  8018. "%s: stopping link start because link is disabled\n",
  8019. __func__);
  8020. return 0;
  8021. }
  8022. if (!ppd->driver_link_ready) {
  8023. dd_dev_info(ppd->dd,
  8024. "%s: stopping link start because driver is not ready\n",
  8025. __func__);
  8026. return 0;
  8027. }
  8028. /*
  8029. * FULL_MGMT_P_KEY is cleared from the pkey table, so that the
  8030. * pkey table can be configured properly if the HFI unit is connected
  8031. * to switch port with MgmtAllowed=NO
  8032. */
  8033. clear_full_mgmt_pkey(ppd);
  8034. return set_link_state(ppd, HLS_DN_POLL);
  8035. }
  8036. static void wait_for_qsfp_init(struct hfi1_pportdata *ppd)
  8037. {
  8038. struct hfi1_devdata *dd = ppd->dd;
  8039. u64 mask;
  8040. unsigned long timeout;
  8041. /*
  8042. * Some QSFP cables have a quirk that asserts the IntN line as a side
  8043. * effect of power up on plug-in. We ignore this false positive
  8044. * interrupt until the module has finished powering up by waiting for
  8045. * a minimum timeout of the module inrush initialization time of
  8046. * 500 ms (SFF 8679 Table 5-6) to ensure the voltage rails in the
  8047. * module have stabilized.
  8048. */
  8049. msleep(500);
  8050. /*
  8051. * Check for QSFP interrupt for t_init (SFF 8679 Table 8-1)
  8052. */
  8053. timeout = jiffies + msecs_to_jiffies(2000);
  8054. while (1) {
  8055. mask = read_csr(dd, dd->hfi1_id ?
  8056. ASIC_QSFP2_IN : ASIC_QSFP1_IN);
  8057. if (!(mask & QSFP_HFI0_INT_N))
  8058. break;
  8059. if (time_after(jiffies, timeout)) {
  8060. dd_dev_info(dd, "%s: No IntN detected, reset complete\n",
  8061. __func__);
  8062. break;
  8063. }
  8064. udelay(2);
  8065. }
  8066. }
  8067. static void set_qsfp_int_n(struct hfi1_pportdata *ppd, u8 enable)
  8068. {
  8069. struct hfi1_devdata *dd = ppd->dd;
  8070. u64 mask;
  8071. mask = read_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK);
  8072. if (enable) {
  8073. /*
  8074. * Clear the status register to avoid an immediate interrupt
  8075. * when we re-enable the IntN pin
  8076. */
  8077. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
  8078. QSFP_HFI0_INT_N);
  8079. mask |= (u64)QSFP_HFI0_INT_N;
  8080. } else {
  8081. mask &= ~(u64)QSFP_HFI0_INT_N;
  8082. }
  8083. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK, mask);
  8084. }
  8085. void reset_qsfp(struct hfi1_pportdata *ppd)
  8086. {
  8087. struct hfi1_devdata *dd = ppd->dd;
  8088. u64 mask, qsfp_mask;
  8089. /* Disable INT_N from triggering QSFP interrupts */
  8090. set_qsfp_int_n(ppd, 0);
  8091. /* Reset the QSFP */
  8092. mask = (u64)QSFP_HFI0_RESET_N;
  8093. qsfp_mask = read_csr(dd,
  8094. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT);
  8095. qsfp_mask &= ~mask;
  8096. write_csr(dd,
  8097. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
  8098. udelay(10);
  8099. qsfp_mask |= mask;
  8100. write_csr(dd,
  8101. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
  8102. wait_for_qsfp_init(ppd);
  8103. /*
  8104. * Allow INT_N to trigger the QSFP interrupt to watch
  8105. * for alarms and warnings
  8106. */
  8107. set_qsfp_int_n(ppd, 1);
  8108. }
  8109. static int handle_qsfp_error_conditions(struct hfi1_pportdata *ppd,
  8110. u8 *qsfp_interrupt_status)
  8111. {
  8112. struct hfi1_devdata *dd = ppd->dd;
  8113. if ((qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_ALARM) ||
  8114. (qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_WARNING))
  8115. dd_dev_info(dd, "%s: QSFP cable on fire\n",
  8116. __func__);
  8117. if ((qsfp_interrupt_status[0] & QSFP_LOW_TEMP_ALARM) ||
  8118. (qsfp_interrupt_status[0] & QSFP_LOW_TEMP_WARNING))
  8119. dd_dev_info(dd, "%s: QSFP cable temperature too low\n",
  8120. __func__);
  8121. /*
  8122. * The remaining alarms/warnings don't matter if the link is down.
  8123. */
  8124. if (ppd->host_link_state & HLS_DOWN)
  8125. return 0;
  8126. if ((qsfp_interrupt_status[1] & QSFP_HIGH_VCC_ALARM) ||
  8127. (qsfp_interrupt_status[1] & QSFP_HIGH_VCC_WARNING))
  8128. dd_dev_info(dd, "%s: QSFP supply voltage too high\n",
  8129. __func__);
  8130. if ((qsfp_interrupt_status[1] & QSFP_LOW_VCC_ALARM) ||
  8131. (qsfp_interrupt_status[1] & QSFP_LOW_VCC_WARNING))
  8132. dd_dev_info(dd, "%s: QSFP supply voltage too low\n",
  8133. __func__);
  8134. /* Byte 2 is vendor specific */
  8135. if ((qsfp_interrupt_status[3] & QSFP_HIGH_POWER_ALARM) ||
  8136. (qsfp_interrupt_status[3] & QSFP_HIGH_POWER_WARNING))
  8137. dd_dev_info(dd, "%s: Cable RX channel 1/2 power too high\n",
  8138. __func__);
  8139. if ((qsfp_interrupt_status[3] & QSFP_LOW_POWER_ALARM) ||
  8140. (qsfp_interrupt_status[3] & QSFP_LOW_POWER_WARNING))
  8141. dd_dev_info(dd, "%s: Cable RX channel 1/2 power too low\n",
  8142. __func__);
  8143. if ((qsfp_interrupt_status[4] & QSFP_HIGH_POWER_ALARM) ||
  8144. (qsfp_interrupt_status[4] & QSFP_HIGH_POWER_WARNING))
  8145. dd_dev_info(dd, "%s: Cable RX channel 3/4 power too high\n",
  8146. __func__);
  8147. if ((qsfp_interrupt_status[4] & QSFP_LOW_POWER_ALARM) ||
  8148. (qsfp_interrupt_status[4] & QSFP_LOW_POWER_WARNING))
  8149. dd_dev_info(dd, "%s: Cable RX channel 3/4 power too low\n",
  8150. __func__);
  8151. if ((qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_ALARM) ||
  8152. (qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_WARNING))
  8153. dd_dev_info(dd, "%s: Cable TX channel 1/2 bias too high\n",
  8154. __func__);
  8155. if ((qsfp_interrupt_status[5] & QSFP_LOW_BIAS_ALARM) ||
  8156. (qsfp_interrupt_status[5] & QSFP_LOW_BIAS_WARNING))
  8157. dd_dev_info(dd, "%s: Cable TX channel 1/2 bias too low\n",
  8158. __func__);
  8159. if ((qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_ALARM) ||
  8160. (qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_WARNING))
  8161. dd_dev_info(dd, "%s: Cable TX channel 3/4 bias too high\n",
  8162. __func__);
  8163. if ((qsfp_interrupt_status[6] & QSFP_LOW_BIAS_ALARM) ||
  8164. (qsfp_interrupt_status[6] & QSFP_LOW_BIAS_WARNING))
  8165. dd_dev_info(dd, "%s: Cable TX channel 3/4 bias too low\n",
  8166. __func__);
  8167. if ((qsfp_interrupt_status[7] & QSFP_HIGH_POWER_ALARM) ||
  8168. (qsfp_interrupt_status[7] & QSFP_HIGH_POWER_WARNING))
  8169. dd_dev_info(dd, "%s: Cable TX channel 1/2 power too high\n",
  8170. __func__);
  8171. if ((qsfp_interrupt_status[7] & QSFP_LOW_POWER_ALARM) ||
  8172. (qsfp_interrupt_status[7] & QSFP_LOW_POWER_WARNING))
  8173. dd_dev_info(dd, "%s: Cable TX channel 1/2 power too low\n",
  8174. __func__);
  8175. if ((qsfp_interrupt_status[8] & QSFP_HIGH_POWER_ALARM) ||
  8176. (qsfp_interrupt_status[8] & QSFP_HIGH_POWER_WARNING))
  8177. dd_dev_info(dd, "%s: Cable TX channel 3/4 power too high\n",
  8178. __func__);
  8179. if ((qsfp_interrupt_status[8] & QSFP_LOW_POWER_ALARM) ||
  8180. (qsfp_interrupt_status[8] & QSFP_LOW_POWER_WARNING))
  8181. dd_dev_info(dd, "%s: Cable TX channel 3/4 power too low\n",
  8182. __func__);
  8183. /* Bytes 9-10 and 11-12 are reserved */
  8184. /* Bytes 13-15 are vendor specific */
  8185. return 0;
  8186. }
  8187. /* This routine will only be scheduled if the QSFP module present is asserted */
  8188. void qsfp_event(struct work_struct *work)
  8189. {
  8190. struct qsfp_data *qd;
  8191. struct hfi1_pportdata *ppd;
  8192. struct hfi1_devdata *dd;
  8193. qd = container_of(work, struct qsfp_data, qsfp_work);
  8194. ppd = qd->ppd;
  8195. dd = ppd->dd;
  8196. /* Sanity check */
  8197. if (!qsfp_mod_present(ppd))
  8198. return;
  8199. /*
  8200. * Turn DC back on after cable has been re-inserted. Up until
  8201. * now, the DC has been in reset to save power.
  8202. */
  8203. dc_start(dd);
  8204. if (qd->cache_refresh_required) {
  8205. set_qsfp_int_n(ppd, 0);
  8206. wait_for_qsfp_init(ppd);
  8207. /*
  8208. * Allow INT_N to trigger the QSFP interrupt to watch
  8209. * for alarms and warnings
  8210. */
  8211. set_qsfp_int_n(ppd, 1);
  8212. start_link(ppd);
  8213. }
  8214. if (qd->check_interrupt_flags) {
  8215. u8 qsfp_interrupt_status[16] = {0,};
  8216. if (one_qsfp_read(ppd, dd->hfi1_id, 6,
  8217. &qsfp_interrupt_status[0], 16) != 16) {
  8218. dd_dev_info(dd,
  8219. "%s: Failed to read status of QSFP module\n",
  8220. __func__);
  8221. } else {
  8222. unsigned long flags;
  8223. handle_qsfp_error_conditions(
  8224. ppd, qsfp_interrupt_status);
  8225. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  8226. ppd->qsfp_info.check_interrupt_flags = 0;
  8227. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  8228. flags);
  8229. }
  8230. }
  8231. }
  8232. static void init_qsfp_int(struct hfi1_devdata *dd)
  8233. {
  8234. struct hfi1_pportdata *ppd = dd->pport;
  8235. u64 qsfp_mask, cce_int_mask;
  8236. const int qsfp1_int_smask = QSFP1_INT % 64;
  8237. const int qsfp2_int_smask = QSFP2_INT % 64;
  8238. /*
  8239. * disable QSFP1 interrupts for HFI1, QSFP2 interrupts for HFI0
  8240. * Qsfp1Int and Qsfp2Int are adjacent bits in the same CSR,
  8241. * therefore just one of QSFP1_INT/QSFP2_INT can be used to find
  8242. * the index of the appropriate CSR in the CCEIntMask CSR array
  8243. */
  8244. cce_int_mask = read_csr(dd, CCE_INT_MASK +
  8245. (8 * (QSFP1_INT / 64)));
  8246. if (dd->hfi1_id) {
  8247. cce_int_mask &= ~((u64)1 << qsfp1_int_smask);
  8248. write_csr(dd, CCE_INT_MASK + (8 * (QSFP1_INT / 64)),
  8249. cce_int_mask);
  8250. } else {
  8251. cce_int_mask &= ~((u64)1 << qsfp2_int_smask);
  8252. write_csr(dd, CCE_INT_MASK + (8 * (QSFP2_INT / 64)),
  8253. cce_int_mask);
  8254. }
  8255. qsfp_mask = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
  8256. /* Clear current status to avoid spurious interrupts */
  8257. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
  8258. qsfp_mask);
  8259. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK,
  8260. qsfp_mask);
  8261. set_qsfp_int_n(ppd, 0);
  8262. /* Handle active low nature of INT_N and MODPRST_N pins */
  8263. if (qsfp_mod_present(ppd))
  8264. qsfp_mask &= ~(u64)QSFP_HFI0_MODPRST_N;
  8265. write_csr(dd,
  8266. dd->hfi1_id ? ASIC_QSFP2_INVERT : ASIC_QSFP1_INVERT,
  8267. qsfp_mask);
  8268. }
  8269. /*
  8270. * Do a one-time initialize of the LCB block.
  8271. */
  8272. static void init_lcb(struct hfi1_devdata *dd)
  8273. {
  8274. /* simulator does not correctly handle LCB cclk loopback, skip */
  8275. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
  8276. return;
  8277. /* the DC has been reset earlier in the driver load */
  8278. /* set LCB for cclk loopback on the port */
  8279. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x01);
  8280. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0x00);
  8281. write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0x00);
  8282. write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
  8283. write_csr(dd, DC_LCB_CFG_CLK_CNTR, 0x08);
  8284. write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x02);
  8285. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x00);
  8286. }
  8287. /*
  8288. * Perform a test read on the QSFP. Return 0 on success, -ERRNO
  8289. * on error.
  8290. */
  8291. static int test_qsfp_read(struct hfi1_pportdata *ppd)
  8292. {
  8293. int ret;
  8294. u8 status;
  8295. /* report success if not a QSFP */
  8296. if (ppd->port_type != PORT_TYPE_QSFP)
  8297. return 0;
  8298. /* read byte 2, the status byte */
  8299. ret = one_qsfp_read(ppd, ppd->dd->hfi1_id, 2, &status, 1);
  8300. if (ret < 0)
  8301. return ret;
  8302. if (ret != 1)
  8303. return -EIO;
  8304. return 0; /* success */
  8305. }
  8306. /*
  8307. * Values for QSFP retry.
  8308. *
  8309. * Give up after 10s (20 x 500ms). The overall timeout was empirically
  8310. * arrived at from experience on a large cluster.
  8311. */
  8312. #define MAX_QSFP_RETRIES 20
  8313. #define QSFP_RETRY_WAIT 500 /* msec */
  8314. /*
  8315. * Try a QSFP read. If it fails, schedule a retry for later.
  8316. * Called on first link activation after driver load.
  8317. */
  8318. static void try_start_link(struct hfi1_pportdata *ppd)
  8319. {
  8320. if (test_qsfp_read(ppd)) {
  8321. /* read failed */
  8322. if (ppd->qsfp_retry_count >= MAX_QSFP_RETRIES) {
  8323. dd_dev_err(ppd->dd, "QSFP not responding, giving up\n");
  8324. return;
  8325. }
  8326. dd_dev_info(ppd->dd,
  8327. "QSFP not responding, waiting and retrying %d\n",
  8328. (int)ppd->qsfp_retry_count);
  8329. ppd->qsfp_retry_count++;
  8330. queue_delayed_work(ppd->hfi1_wq, &ppd->start_link_work,
  8331. msecs_to_jiffies(QSFP_RETRY_WAIT));
  8332. return;
  8333. }
  8334. ppd->qsfp_retry_count = 0;
  8335. start_link(ppd);
  8336. }
  8337. /*
  8338. * Workqueue function to start the link after a delay.
  8339. */
  8340. void handle_start_link(struct work_struct *work)
  8341. {
  8342. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  8343. start_link_work.work);
  8344. try_start_link(ppd);
  8345. }
  8346. int bringup_serdes(struct hfi1_pportdata *ppd)
  8347. {
  8348. struct hfi1_devdata *dd = ppd->dd;
  8349. u64 guid;
  8350. int ret;
  8351. if (HFI1_CAP_IS_KSET(EXTENDED_PSN))
  8352. add_rcvctrl(dd, RCV_CTRL_RCV_EXTENDED_PSN_ENABLE_SMASK);
  8353. guid = ppd->guid;
  8354. if (!guid) {
  8355. if (dd->base_guid)
  8356. guid = dd->base_guid + ppd->port - 1;
  8357. ppd->guid = guid;
  8358. }
  8359. /* Set linkinit_reason on power up per OPA spec */
  8360. ppd->linkinit_reason = OPA_LINKINIT_REASON_LINKUP;
  8361. /* one-time init of the LCB */
  8362. init_lcb(dd);
  8363. if (loopback) {
  8364. ret = init_loopback(dd);
  8365. if (ret < 0)
  8366. return ret;
  8367. }
  8368. get_port_type(ppd);
  8369. if (ppd->port_type == PORT_TYPE_QSFP) {
  8370. set_qsfp_int_n(ppd, 0);
  8371. wait_for_qsfp_init(ppd);
  8372. set_qsfp_int_n(ppd, 1);
  8373. }
  8374. try_start_link(ppd);
  8375. return 0;
  8376. }
  8377. void hfi1_quiet_serdes(struct hfi1_pportdata *ppd)
  8378. {
  8379. struct hfi1_devdata *dd = ppd->dd;
  8380. /*
  8381. * Shut down the link and keep it down. First turn off that the
  8382. * driver wants to allow the link to be up (driver_link_ready).
  8383. * Then make sure the link is not automatically restarted
  8384. * (link_enabled). Cancel any pending restart. And finally
  8385. * go offline.
  8386. */
  8387. ppd->driver_link_ready = 0;
  8388. ppd->link_enabled = 0;
  8389. ppd->qsfp_retry_count = MAX_QSFP_RETRIES; /* prevent more retries */
  8390. flush_delayed_work(&ppd->start_link_work);
  8391. cancel_delayed_work_sync(&ppd->start_link_work);
  8392. ppd->offline_disabled_reason =
  8393. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED);
  8394. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SMA_DISABLED, 0,
  8395. OPA_LINKDOWN_REASON_SMA_DISABLED);
  8396. set_link_state(ppd, HLS_DN_OFFLINE);
  8397. /* disable the port */
  8398. clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  8399. }
  8400. static inline int init_cpu_counters(struct hfi1_devdata *dd)
  8401. {
  8402. struct hfi1_pportdata *ppd;
  8403. int i;
  8404. ppd = (struct hfi1_pportdata *)(dd + 1);
  8405. for (i = 0; i < dd->num_pports; i++, ppd++) {
  8406. ppd->ibport_data.rvp.rc_acks = NULL;
  8407. ppd->ibport_data.rvp.rc_qacks = NULL;
  8408. ppd->ibport_data.rvp.rc_acks = alloc_percpu(u64);
  8409. ppd->ibport_data.rvp.rc_qacks = alloc_percpu(u64);
  8410. ppd->ibport_data.rvp.rc_delayed_comp = alloc_percpu(u64);
  8411. if (!ppd->ibport_data.rvp.rc_acks ||
  8412. !ppd->ibport_data.rvp.rc_delayed_comp ||
  8413. !ppd->ibport_data.rvp.rc_qacks)
  8414. return -ENOMEM;
  8415. }
  8416. return 0;
  8417. }
  8418. static const char * const pt_names[] = {
  8419. "expected",
  8420. "eager",
  8421. "invalid"
  8422. };
  8423. static const char *pt_name(u32 type)
  8424. {
  8425. return type >= ARRAY_SIZE(pt_names) ? "unknown" : pt_names[type];
  8426. }
  8427. /*
  8428. * index is the index into the receive array
  8429. */
  8430. void hfi1_put_tid(struct hfi1_devdata *dd, u32 index,
  8431. u32 type, unsigned long pa, u16 order)
  8432. {
  8433. u64 reg;
  8434. void __iomem *base = (dd->rcvarray_wc ? dd->rcvarray_wc :
  8435. (dd->kregbase + RCV_ARRAY));
  8436. if (!(dd->flags & HFI1_PRESENT))
  8437. goto done;
  8438. if (type == PT_INVALID) {
  8439. pa = 0;
  8440. } else if (type > PT_INVALID) {
  8441. dd_dev_err(dd,
  8442. "unexpected receive array type %u for index %u, not handled\n",
  8443. type, index);
  8444. goto done;
  8445. }
  8446. hfi1_cdbg(TID, "type %s, index 0x%x, pa 0x%lx, bsize 0x%lx",
  8447. pt_name(type), index, pa, (unsigned long)order);
  8448. #define RT_ADDR_SHIFT 12 /* 4KB kernel address boundary */
  8449. reg = RCV_ARRAY_RT_WRITE_ENABLE_SMASK
  8450. | (u64)order << RCV_ARRAY_RT_BUF_SIZE_SHIFT
  8451. | ((pa >> RT_ADDR_SHIFT) & RCV_ARRAY_RT_ADDR_MASK)
  8452. << RCV_ARRAY_RT_ADDR_SHIFT;
  8453. writeq(reg, base + (index * 8));
  8454. if (type == PT_EAGER)
  8455. /*
  8456. * Eager entries are written one-by-one so we have to push them
  8457. * after we write the entry.
  8458. */
  8459. flush_wc();
  8460. done:
  8461. return;
  8462. }
  8463. void hfi1_clear_tids(struct hfi1_ctxtdata *rcd)
  8464. {
  8465. struct hfi1_devdata *dd = rcd->dd;
  8466. u32 i;
  8467. /* this could be optimized */
  8468. for (i = rcd->eager_base; i < rcd->eager_base +
  8469. rcd->egrbufs.alloced; i++)
  8470. hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
  8471. for (i = rcd->expected_base;
  8472. i < rcd->expected_base + rcd->expected_count; i++)
  8473. hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
  8474. }
  8475. struct ib_header *hfi1_get_msgheader(
  8476. struct hfi1_devdata *dd, __le32 *rhf_addr)
  8477. {
  8478. u32 offset = rhf_hdrq_offset(rhf_to_cpu(rhf_addr));
  8479. return (struct ib_header *)
  8480. (rhf_addr - dd->rhf_offset + offset);
  8481. }
  8482. static const char * const ib_cfg_name_strings[] = {
  8483. "HFI1_IB_CFG_LIDLMC",
  8484. "HFI1_IB_CFG_LWID_DG_ENB",
  8485. "HFI1_IB_CFG_LWID_ENB",
  8486. "HFI1_IB_CFG_LWID",
  8487. "HFI1_IB_CFG_SPD_ENB",
  8488. "HFI1_IB_CFG_SPD",
  8489. "HFI1_IB_CFG_RXPOL_ENB",
  8490. "HFI1_IB_CFG_LREV_ENB",
  8491. "HFI1_IB_CFG_LINKLATENCY",
  8492. "HFI1_IB_CFG_HRTBT",
  8493. "HFI1_IB_CFG_OP_VLS",
  8494. "HFI1_IB_CFG_VL_HIGH_CAP",
  8495. "HFI1_IB_CFG_VL_LOW_CAP",
  8496. "HFI1_IB_CFG_OVERRUN_THRESH",
  8497. "HFI1_IB_CFG_PHYERR_THRESH",
  8498. "HFI1_IB_CFG_LINKDEFAULT",
  8499. "HFI1_IB_CFG_PKEYS",
  8500. "HFI1_IB_CFG_MTU",
  8501. "HFI1_IB_CFG_LSTATE",
  8502. "HFI1_IB_CFG_VL_HIGH_LIMIT",
  8503. "HFI1_IB_CFG_PMA_TICKS",
  8504. "HFI1_IB_CFG_PORT"
  8505. };
  8506. static const char *ib_cfg_name(int which)
  8507. {
  8508. if (which < 0 || which >= ARRAY_SIZE(ib_cfg_name_strings))
  8509. return "invalid";
  8510. return ib_cfg_name_strings[which];
  8511. }
  8512. int hfi1_get_ib_cfg(struct hfi1_pportdata *ppd, int which)
  8513. {
  8514. struct hfi1_devdata *dd = ppd->dd;
  8515. int val = 0;
  8516. switch (which) {
  8517. case HFI1_IB_CFG_LWID_ENB: /* allowed Link-width */
  8518. val = ppd->link_width_enabled;
  8519. break;
  8520. case HFI1_IB_CFG_LWID: /* currently active Link-width */
  8521. val = ppd->link_width_active;
  8522. break;
  8523. case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
  8524. val = ppd->link_speed_enabled;
  8525. break;
  8526. case HFI1_IB_CFG_SPD: /* current Link speed */
  8527. val = ppd->link_speed_active;
  8528. break;
  8529. case HFI1_IB_CFG_RXPOL_ENB: /* Auto-RX-polarity enable */
  8530. case HFI1_IB_CFG_LREV_ENB: /* Auto-Lane-reversal enable */
  8531. case HFI1_IB_CFG_LINKLATENCY:
  8532. goto unimplemented;
  8533. case HFI1_IB_CFG_OP_VLS:
  8534. val = ppd->vls_operational;
  8535. break;
  8536. case HFI1_IB_CFG_VL_HIGH_CAP: /* VL arb high priority table size */
  8537. val = VL_ARB_HIGH_PRIO_TABLE_SIZE;
  8538. break;
  8539. case HFI1_IB_CFG_VL_LOW_CAP: /* VL arb low priority table size */
  8540. val = VL_ARB_LOW_PRIO_TABLE_SIZE;
  8541. break;
  8542. case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  8543. val = ppd->overrun_threshold;
  8544. break;
  8545. case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  8546. val = ppd->phy_error_threshold;
  8547. break;
  8548. case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  8549. val = dd->link_default;
  8550. break;
  8551. case HFI1_IB_CFG_HRTBT: /* Heartbeat off/enable/auto */
  8552. case HFI1_IB_CFG_PMA_TICKS:
  8553. default:
  8554. unimplemented:
  8555. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  8556. dd_dev_info(
  8557. dd,
  8558. "%s: which %s: not implemented\n",
  8559. __func__,
  8560. ib_cfg_name(which));
  8561. break;
  8562. }
  8563. return val;
  8564. }
  8565. /*
  8566. * The largest MAD packet size.
  8567. */
  8568. #define MAX_MAD_PACKET 2048
  8569. /*
  8570. * Return the maximum header bytes that can go on the _wire_
  8571. * for this device. This count includes the ICRC which is
  8572. * not part of the packet held in memory but it is appended
  8573. * by the HW.
  8574. * This is dependent on the device's receive header entry size.
  8575. * HFI allows this to be set per-receive context, but the
  8576. * driver presently enforces a global value.
  8577. */
  8578. u32 lrh_max_header_bytes(struct hfi1_devdata *dd)
  8579. {
  8580. /*
  8581. * The maximum non-payload (MTU) bytes in LRH.PktLen are
  8582. * the Receive Header Entry Size minus the PBC (or RHF) size
  8583. * plus one DW for the ICRC appended by HW.
  8584. *
  8585. * dd->rcd[0].rcvhdrqentsize is in DW.
  8586. * We use rcd[0] as all context will have the same value. Also,
  8587. * the first kernel context would have been allocated by now so
  8588. * we are guaranteed a valid value.
  8589. */
  8590. return (dd->rcd[0]->rcvhdrqentsize - 2/*PBC/RHF*/ + 1/*ICRC*/) << 2;
  8591. }
  8592. /*
  8593. * Set Send Length
  8594. * @ppd - per port data
  8595. *
  8596. * Set the MTU by limiting how many DWs may be sent. The SendLenCheck*
  8597. * registers compare against LRH.PktLen, so use the max bytes included
  8598. * in the LRH.
  8599. *
  8600. * This routine changes all VL values except VL15, which it maintains at
  8601. * the same value.
  8602. */
  8603. static void set_send_length(struct hfi1_pportdata *ppd)
  8604. {
  8605. struct hfi1_devdata *dd = ppd->dd;
  8606. u32 max_hb = lrh_max_header_bytes(dd), dcmtu;
  8607. u32 maxvlmtu = dd->vld[15].mtu;
  8608. u64 len1 = 0, len2 = (((dd->vld[15].mtu + max_hb) >> 2)
  8609. & SEND_LEN_CHECK1_LEN_VL15_MASK) <<
  8610. SEND_LEN_CHECK1_LEN_VL15_SHIFT;
  8611. int i, j;
  8612. u32 thres;
  8613. for (i = 0; i < ppd->vls_supported; i++) {
  8614. if (dd->vld[i].mtu > maxvlmtu)
  8615. maxvlmtu = dd->vld[i].mtu;
  8616. if (i <= 3)
  8617. len1 |= (((dd->vld[i].mtu + max_hb) >> 2)
  8618. & SEND_LEN_CHECK0_LEN_VL0_MASK) <<
  8619. ((i % 4) * SEND_LEN_CHECK0_LEN_VL1_SHIFT);
  8620. else
  8621. len2 |= (((dd->vld[i].mtu + max_hb) >> 2)
  8622. & SEND_LEN_CHECK1_LEN_VL4_MASK) <<
  8623. ((i % 4) * SEND_LEN_CHECK1_LEN_VL5_SHIFT);
  8624. }
  8625. write_csr(dd, SEND_LEN_CHECK0, len1);
  8626. write_csr(dd, SEND_LEN_CHECK1, len2);
  8627. /* adjust kernel credit return thresholds based on new MTUs */
  8628. /* all kernel receive contexts have the same hdrqentsize */
  8629. for (i = 0; i < ppd->vls_supported; i++) {
  8630. thres = min(sc_percent_to_threshold(dd->vld[i].sc, 50),
  8631. sc_mtu_to_threshold(dd->vld[i].sc,
  8632. dd->vld[i].mtu,
  8633. dd->rcd[0]->rcvhdrqentsize));
  8634. for (j = 0; j < INIT_SC_PER_VL; j++)
  8635. sc_set_cr_threshold(
  8636. pio_select_send_context_vl(dd, j, i),
  8637. thres);
  8638. }
  8639. thres = min(sc_percent_to_threshold(dd->vld[15].sc, 50),
  8640. sc_mtu_to_threshold(dd->vld[15].sc,
  8641. dd->vld[15].mtu,
  8642. dd->rcd[0]->rcvhdrqentsize));
  8643. sc_set_cr_threshold(dd->vld[15].sc, thres);
  8644. /* Adjust maximum MTU for the port in DC */
  8645. dcmtu = maxvlmtu == 10240 ? DCC_CFG_PORT_MTU_CAP_10240 :
  8646. (ilog2(maxvlmtu >> 8) + 1);
  8647. len1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG);
  8648. len1 &= ~DCC_CFG_PORT_CONFIG_MTU_CAP_SMASK;
  8649. len1 |= ((u64)dcmtu & DCC_CFG_PORT_CONFIG_MTU_CAP_MASK) <<
  8650. DCC_CFG_PORT_CONFIG_MTU_CAP_SHIFT;
  8651. write_csr(ppd->dd, DCC_CFG_PORT_CONFIG, len1);
  8652. }
  8653. static void set_lidlmc(struct hfi1_pportdata *ppd)
  8654. {
  8655. int i;
  8656. u64 sreg = 0;
  8657. struct hfi1_devdata *dd = ppd->dd;
  8658. u32 mask = ~((1U << ppd->lmc) - 1);
  8659. u64 c1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG1);
  8660. c1 &= ~(DCC_CFG_PORT_CONFIG1_TARGET_DLID_SMASK
  8661. | DCC_CFG_PORT_CONFIG1_DLID_MASK_SMASK);
  8662. c1 |= ((ppd->lid & DCC_CFG_PORT_CONFIG1_TARGET_DLID_MASK)
  8663. << DCC_CFG_PORT_CONFIG1_TARGET_DLID_SHIFT) |
  8664. ((mask & DCC_CFG_PORT_CONFIG1_DLID_MASK_MASK)
  8665. << DCC_CFG_PORT_CONFIG1_DLID_MASK_SHIFT);
  8666. write_csr(ppd->dd, DCC_CFG_PORT_CONFIG1, c1);
  8667. /*
  8668. * Iterate over all the send contexts and set their SLID check
  8669. */
  8670. sreg = ((mask & SEND_CTXT_CHECK_SLID_MASK_MASK) <<
  8671. SEND_CTXT_CHECK_SLID_MASK_SHIFT) |
  8672. (((ppd->lid & mask) & SEND_CTXT_CHECK_SLID_VALUE_MASK) <<
  8673. SEND_CTXT_CHECK_SLID_VALUE_SHIFT);
  8674. for (i = 0; i < dd->chip_send_contexts; i++) {
  8675. hfi1_cdbg(LINKVERB, "SendContext[%d].SLID_CHECK = 0x%x",
  8676. i, (u32)sreg);
  8677. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, sreg);
  8678. }
  8679. /* Now we have to do the same thing for the sdma engines */
  8680. sdma_update_lmc(dd, mask, ppd->lid);
  8681. }
  8682. static int wait_phy_linkstate(struct hfi1_devdata *dd, u32 state, u32 msecs)
  8683. {
  8684. unsigned long timeout;
  8685. u32 curr_state;
  8686. timeout = jiffies + msecs_to_jiffies(msecs);
  8687. while (1) {
  8688. curr_state = read_physical_state(dd);
  8689. if (curr_state == state)
  8690. break;
  8691. if (time_after(jiffies, timeout)) {
  8692. dd_dev_err(dd,
  8693. "timeout waiting for phy link state 0x%x, current state is 0x%x\n",
  8694. state, curr_state);
  8695. return -ETIMEDOUT;
  8696. }
  8697. usleep_range(1950, 2050); /* sleep 2ms-ish */
  8698. }
  8699. return 0;
  8700. }
  8701. static const char *state_completed_string(u32 completed)
  8702. {
  8703. static const char * const state_completed[] = {
  8704. "EstablishComm",
  8705. "OptimizeEQ",
  8706. "VerifyCap"
  8707. };
  8708. if (completed < ARRAY_SIZE(state_completed))
  8709. return state_completed[completed];
  8710. return "unknown";
  8711. }
  8712. static const char all_lanes_dead_timeout_expired[] =
  8713. "All lanes were inactive – was the interconnect media removed?";
  8714. static const char tx_out_of_policy[] =
  8715. "Passing lanes on local port do not meet the local link width policy";
  8716. static const char no_state_complete[] =
  8717. "State timeout occurred before link partner completed the state";
  8718. static const char * const state_complete_reasons[] = {
  8719. [0x00] = "Reason unknown",
  8720. [0x01] = "Link was halted by driver, refer to LinkDownReason",
  8721. [0x02] = "Link partner reported failure",
  8722. [0x10] = "Unable to achieve frame sync on any lane",
  8723. [0x11] =
  8724. "Unable to find a common bit rate with the link partner",
  8725. [0x12] =
  8726. "Unable to achieve frame sync on sufficient lanes to meet the local link width policy",
  8727. [0x13] =
  8728. "Unable to identify preset equalization on sufficient lanes to meet the local link width policy",
  8729. [0x14] = no_state_complete,
  8730. [0x15] =
  8731. "State timeout occurred before link partner identified equalization presets",
  8732. [0x16] =
  8733. "Link partner completed the EstablishComm state, but the passing lanes do not meet the local link width policy",
  8734. [0x17] = tx_out_of_policy,
  8735. [0x20] = all_lanes_dead_timeout_expired,
  8736. [0x21] =
  8737. "Unable to achieve acceptable BER on sufficient lanes to meet the local link width policy",
  8738. [0x22] = no_state_complete,
  8739. [0x23] =
  8740. "Link partner completed the OptimizeEq state, but the passing lanes do not meet the local link width policy",
  8741. [0x24] = tx_out_of_policy,
  8742. [0x30] = all_lanes_dead_timeout_expired,
  8743. [0x31] =
  8744. "State timeout occurred waiting for host to process received frames",
  8745. [0x32] = no_state_complete,
  8746. [0x33] =
  8747. "Link partner completed the VerifyCap state, but the passing lanes do not meet the local link width policy",
  8748. [0x34] = tx_out_of_policy,
  8749. };
  8750. static const char *state_complete_reason_code_string(struct hfi1_pportdata *ppd,
  8751. u32 code)
  8752. {
  8753. const char *str = NULL;
  8754. if (code < ARRAY_SIZE(state_complete_reasons))
  8755. str = state_complete_reasons[code];
  8756. if (str)
  8757. return str;
  8758. return "Reserved";
  8759. }
  8760. /* describe the given last state complete frame */
  8761. static void decode_state_complete(struct hfi1_pportdata *ppd, u32 frame,
  8762. const char *prefix)
  8763. {
  8764. struct hfi1_devdata *dd = ppd->dd;
  8765. u32 success;
  8766. u32 state;
  8767. u32 reason;
  8768. u32 lanes;
  8769. /*
  8770. * Decode frame:
  8771. * [ 0: 0] - success
  8772. * [ 3: 1] - state
  8773. * [ 7: 4] - next state timeout
  8774. * [15: 8] - reason code
  8775. * [31:16] - lanes
  8776. */
  8777. success = frame & 0x1;
  8778. state = (frame >> 1) & 0x7;
  8779. reason = (frame >> 8) & 0xff;
  8780. lanes = (frame >> 16) & 0xffff;
  8781. dd_dev_err(dd, "Last %s LNI state complete frame 0x%08x:\n",
  8782. prefix, frame);
  8783. dd_dev_err(dd, " last reported state state: %s (0x%x)\n",
  8784. state_completed_string(state), state);
  8785. dd_dev_err(dd, " state successfully completed: %s\n",
  8786. success ? "yes" : "no");
  8787. dd_dev_err(dd, " fail reason 0x%x: %s\n",
  8788. reason, state_complete_reason_code_string(ppd, reason));
  8789. dd_dev_err(dd, " passing lane mask: 0x%x", lanes);
  8790. }
  8791. /*
  8792. * Read the last state complete frames and explain them. This routine
  8793. * expects to be called if the link went down during link negotiation
  8794. * and initialization (LNI). That is, anywhere between polling and link up.
  8795. */
  8796. static void check_lni_states(struct hfi1_pportdata *ppd)
  8797. {
  8798. u32 last_local_state;
  8799. u32 last_remote_state;
  8800. read_last_local_state(ppd->dd, &last_local_state);
  8801. read_last_remote_state(ppd->dd, &last_remote_state);
  8802. /*
  8803. * Don't report anything if there is nothing to report. A value of
  8804. * 0 means the link was taken down while polling and there was no
  8805. * training in-process.
  8806. */
  8807. if (last_local_state == 0 && last_remote_state == 0)
  8808. return;
  8809. decode_state_complete(ppd, last_local_state, "transmitted");
  8810. decode_state_complete(ppd, last_remote_state, "received");
  8811. }
  8812. /*
  8813. * Helper for set_link_state(). Do not call except from that routine.
  8814. * Expects ppd->hls_mutex to be held.
  8815. *
  8816. * @rem_reason value to be sent to the neighbor
  8817. *
  8818. * LinkDownReasons only set if transition succeeds.
  8819. */
  8820. static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason)
  8821. {
  8822. struct hfi1_devdata *dd = ppd->dd;
  8823. u32 pstate, previous_state;
  8824. int ret;
  8825. int do_transition;
  8826. int do_wait;
  8827. previous_state = ppd->host_link_state;
  8828. ppd->host_link_state = HLS_GOING_OFFLINE;
  8829. pstate = read_physical_state(dd);
  8830. if (pstate == PLS_OFFLINE) {
  8831. do_transition = 0; /* in right state */
  8832. do_wait = 0; /* ...no need to wait */
  8833. } else if ((pstate & 0xff) == PLS_OFFLINE) {
  8834. do_transition = 0; /* in an offline transient state */
  8835. do_wait = 1; /* ...wait for it to settle */
  8836. } else {
  8837. do_transition = 1; /* need to move to offline */
  8838. do_wait = 1; /* ...will need to wait */
  8839. }
  8840. if (do_transition) {
  8841. ret = set_physical_link_state(dd,
  8842. (rem_reason << 8) | PLS_OFFLINE);
  8843. if (ret != HCMD_SUCCESS) {
  8844. dd_dev_err(dd,
  8845. "Failed to transition to Offline link state, return %d\n",
  8846. ret);
  8847. return -EINVAL;
  8848. }
  8849. if (ppd->offline_disabled_reason ==
  8850. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))
  8851. ppd->offline_disabled_reason =
  8852. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
  8853. }
  8854. if (do_wait) {
  8855. /* it can take a while for the link to go down */
  8856. ret = wait_phy_linkstate(dd, PLS_OFFLINE, 10000);
  8857. if (ret < 0)
  8858. return ret;
  8859. }
  8860. /* make sure the logical state is also down */
  8861. wait_logical_linkstate(ppd, IB_PORT_DOWN, 1000);
  8862. /*
  8863. * Now in charge of LCB - must be after the physical state is
  8864. * offline.quiet and before host_link_state is changed.
  8865. */
  8866. set_host_lcb_access(dd);
  8867. write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
  8868. ppd->host_link_state = HLS_LINK_COOLDOWN; /* LCB access allowed */
  8869. if (ppd->port_type == PORT_TYPE_QSFP &&
  8870. ppd->qsfp_info.limiting_active &&
  8871. qsfp_mod_present(ppd)) {
  8872. int ret;
  8873. ret = acquire_chip_resource(dd, qsfp_resource(dd), QSFP_WAIT);
  8874. if (ret == 0) {
  8875. set_qsfp_tx(ppd, 0);
  8876. release_chip_resource(dd, qsfp_resource(dd));
  8877. } else {
  8878. /* not fatal, but should warn */
  8879. dd_dev_err(dd,
  8880. "Unable to acquire lock to turn off QSFP TX\n");
  8881. }
  8882. }
  8883. /*
  8884. * The LNI has a mandatory wait time after the physical state
  8885. * moves to Offline.Quiet. The wait time may be different
  8886. * depending on how the link went down. The 8051 firmware
  8887. * will observe the needed wait time and only move to ready
  8888. * when that is completed. The largest of the quiet timeouts
  8889. * is 6s, so wait that long and then at least 0.5s more for
  8890. * other transitions, and another 0.5s for a buffer.
  8891. */
  8892. ret = wait_fm_ready(dd, 7000);
  8893. if (ret) {
  8894. dd_dev_err(dd,
  8895. "After going offline, timed out waiting for the 8051 to become ready to accept host requests\n");
  8896. /* state is really offline, so make it so */
  8897. ppd->host_link_state = HLS_DN_OFFLINE;
  8898. return ret;
  8899. }
  8900. /*
  8901. * The state is now offline and the 8051 is ready to accept host
  8902. * requests.
  8903. * - change our state
  8904. * - notify others if we were previously in a linkup state
  8905. */
  8906. ppd->host_link_state = HLS_DN_OFFLINE;
  8907. if (previous_state & HLS_UP) {
  8908. /* went down while link was up */
  8909. handle_linkup_change(dd, 0);
  8910. } else if (previous_state
  8911. & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
  8912. /* went down while attempting link up */
  8913. check_lni_states(ppd);
  8914. }
  8915. /* the active link width (downgrade) is 0 on link down */
  8916. ppd->link_width_active = 0;
  8917. ppd->link_width_downgrade_tx_active = 0;
  8918. ppd->link_width_downgrade_rx_active = 0;
  8919. ppd->current_egress_rate = 0;
  8920. return 0;
  8921. }
  8922. /* return the link state name */
  8923. static const char *link_state_name(u32 state)
  8924. {
  8925. const char *name;
  8926. int n = ilog2(state);
  8927. static const char * const names[] = {
  8928. [__HLS_UP_INIT_BP] = "INIT",
  8929. [__HLS_UP_ARMED_BP] = "ARMED",
  8930. [__HLS_UP_ACTIVE_BP] = "ACTIVE",
  8931. [__HLS_DN_DOWNDEF_BP] = "DOWNDEF",
  8932. [__HLS_DN_POLL_BP] = "POLL",
  8933. [__HLS_DN_DISABLE_BP] = "DISABLE",
  8934. [__HLS_DN_OFFLINE_BP] = "OFFLINE",
  8935. [__HLS_VERIFY_CAP_BP] = "VERIFY_CAP",
  8936. [__HLS_GOING_UP_BP] = "GOING_UP",
  8937. [__HLS_GOING_OFFLINE_BP] = "GOING_OFFLINE",
  8938. [__HLS_LINK_COOLDOWN_BP] = "LINK_COOLDOWN"
  8939. };
  8940. name = n < ARRAY_SIZE(names) ? names[n] : NULL;
  8941. return name ? name : "unknown";
  8942. }
  8943. /* return the link state reason name */
  8944. static const char *link_state_reason_name(struct hfi1_pportdata *ppd, u32 state)
  8945. {
  8946. if (state == HLS_UP_INIT) {
  8947. switch (ppd->linkinit_reason) {
  8948. case OPA_LINKINIT_REASON_LINKUP:
  8949. return "(LINKUP)";
  8950. case OPA_LINKINIT_REASON_FLAPPING:
  8951. return "(FLAPPING)";
  8952. case OPA_LINKINIT_OUTSIDE_POLICY:
  8953. return "(OUTSIDE_POLICY)";
  8954. case OPA_LINKINIT_QUARANTINED:
  8955. return "(QUARANTINED)";
  8956. case OPA_LINKINIT_INSUFIC_CAPABILITY:
  8957. return "(INSUFIC_CAPABILITY)";
  8958. default:
  8959. break;
  8960. }
  8961. }
  8962. return "";
  8963. }
  8964. /*
  8965. * driver_physical_state - convert the driver's notion of a port's
  8966. * state (an HLS_*) into a physical state (a {IB,OPA}_PORTPHYSSTATE_*).
  8967. * Return -1 (converted to a u32) to indicate error.
  8968. */
  8969. u32 driver_physical_state(struct hfi1_pportdata *ppd)
  8970. {
  8971. switch (ppd->host_link_state) {
  8972. case HLS_UP_INIT:
  8973. case HLS_UP_ARMED:
  8974. case HLS_UP_ACTIVE:
  8975. return IB_PORTPHYSSTATE_LINKUP;
  8976. case HLS_DN_POLL:
  8977. return IB_PORTPHYSSTATE_POLLING;
  8978. case HLS_DN_DISABLE:
  8979. return IB_PORTPHYSSTATE_DISABLED;
  8980. case HLS_DN_OFFLINE:
  8981. return OPA_PORTPHYSSTATE_OFFLINE;
  8982. case HLS_VERIFY_CAP:
  8983. return IB_PORTPHYSSTATE_POLLING;
  8984. case HLS_GOING_UP:
  8985. return IB_PORTPHYSSTATE_POLLING;
  8986. case HLS_GOING_OFFLINE:
  8987. return OPA_PORTPHYSSTATE_OFFLINE;
  8988. case HLS_LINK_COOLDOWN:
  8989. return OPA_PORTPHYSSTATE_OFFLINE;
  8990. case HLS_DN_DOWNDEF:
  8991. default:
  8992. dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
  8993. ppd->host_link_state);
  8994. return -1;
  8995. }
  8996. }
  8997. /*
  8998. * driver_logical_state - convert the driver's notion of a port's
  8999. * state (an HLS_*) into a logical state (a IB_PORT_*). Return -1
  9000. * (converted to a u32) to indicate error.
  9001. */
  9002. u32 driver_logical_state(struct hfi1_pportdata *ppd)
  9003. {
  9004. if (ppd->host_link_state && (ppd->host_link_state & HLS_DOWN))
  9005. return IB_PORT_DOWN;
  9006. switch (ppd->host_link_state & HLS_UP) {
  9007. case HLS_UP_INIT:
  9008. return IB_PORT_INIT;
  9009. case HLS_UP_ARMED:
  9010. return IB_PORT_ARMED;
  9011. case HLS_UP_ACTIVE:
  9012. return IB_PORT_ACTIVE;
  9013. default:
  9014. dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
  9015. ppd->host_link_state);
  9016. return -1;
  9017. }
  9018. }
  9019. void set_link_down_reason(struct hfi1_pportdata *ppd, u8 lcl_reason,
  9020. u8 neigh_reason, u8 rem_reason)
  9021. {
  9022. if (ppd->local_link_down_reason.latest == 0 &&
  9023. ppd->neigh_link_down_reason.latest == 0) {
  9024. ppd->local_link_down_reason.latest = lcl_reason;
  9025. ppd->neigh_link_down_reason.latest = neigh_reason;
  9026. ppd->remote_link_down_reason = rem_reason;
  9027. }
  9028. }
  9029. /*
  9030. * Change the physical and/or logical link state.
  9031. *
  9032. * Do not call this routine while inside an interrupt. It contains
  9033. * calls to routines that can take multiple seconds to finish.
  9034. *
  9035. * Returns 0 on success, -errno on failure.
  9036. */
  9037. int set_link_state(struct hfi1_pportdata *ppd, u32 state)
  9038. {
  9039. struct hfi1_devdata *dd = ppd->dd;
  9040. struct ib_event event = {.device = NULL};
  9041. int ret1, ret = 0;
  9042. int orig_new_state, poll_bounce;
  9043. mutex_lock(&ppd->hls_lock);
  9044. orig_new_state = state;
  9045. if (state == HLS_DN_DOWNDEF)
  9046. state = dd->link_default;
  9047. /* interpret poll -> poll as a link bounce */
  9048. poll_bounce = ppd->host_link_state == HLS_DN_POLL &&
  9049. state == HLS_DN_POLL;
  9050. dd_dev_info(dd, "%s: current %s, new %s %s%s\n", __func__,
  9051. link_state_name(ppd->host_link_state),
  9052. link_state_name(orig_new_state),
  9053. poll_bounce ? "(bounce) " : "",
  9054. link_state_reason_name(ppd, state));
  9055. /*
  9056. * If we're going to a (HLS_*) link state that implies the logical
  9057. * link state is neither of (IB_PORT_ARMED, IB_PORT_ACTIVE), then
  9058. * reset is_sm_config_started to 0.
  9059. */
  9060. if (!(state & (HLS_UP_ARMED | HLS_UP_ACTIVE)))
  9061. ppd->is_sm_config_started = 0;
  9062. /*
  9063. * Do nothing if the states match. Let a poll to poll link bounce
  9064. * go through.
  9065. */
  9066. if (ppd->host_link_state == state && !poll_bounce)
  9067. goto done;
  9068. switch (state) {
  9069. case HLS_UP_INIT:
  9070. if (ppd->host_link_state == HLS_DN_POLL &&
  9071. (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR)) {
  9072. /*
  9073. * Quick link up jumps from polling to here.
  9074. *
  9075. * Whether in normal or loopback mode, the
  9076. * simulator jumps from polling to link up.
  9077. * Accept that here.
  9078. */
  9079. /* OK */
  9080. } else if (ppd->host_link_state != HLS_GOING_UP) {
  9081. goto unexpected;
  9082. }
  9083. ppd->host_link_state = HLS_UP_INIT;
  9084. ret = wait_logical_linkstate(ppd, IB_PORT_INIT, 1000);
  9085. if (ret) {
  9086. /* logical state didn't change, stay at going_up */
  9087. ppd->host_link_state = HLS_GOING_UP;
  9088. dd_dev_err(dd,
  9089. "%s: logical state did not change to INIT\n",
  9090. __func__);
  9091. } else {
  9092. /* clear old transient LINKINIT_REASON code */
  9093. if (ppd->linkinit_reason >= OPA_LINKINIT_REASON_CLEAR)
  9094. ppd->linkinit_reason =
  9095. OPA_LINKINIT_REASON_LINKUP;
  9096. /* enable the port */
  9097. add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  9098. handle_linkup_change(dd, 1);
  9099. }
  9100. break;
  9101. case HLS_UP_ARMED:
  9102. if (ppd->host_link_state != HLS_UP_INIT)
  9103. goto unexpected;
  9104. ppd->host_link_state = HLS_UP_ARMED;
  9105. set_logical_state(dd, LSTATE_ARMED);
  9106. ret = wait_logical_linkstate(ppd, IB_PORT_ARMED, 1000);
  9107. if (ret) {
  9108. /* logical state didn't change, stay at init */
  9109. ppd->host_link_state = HLS_UP_INIT;
  9110. dd_dev_err(dd,
  9111. "%s: logical state did not change to ARMED\n",
  9112. __func__);
  9113. }
  9114. /*
  9115. * The simulator does not currently implement SMA messages,
  9116. * so neighbor_normal is not set. Set it here when we first
  9117. * move to Armed.
  9118. */
  9119. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
  9120. ppd->neighbor_normal = 1;
  9121. break;
  9122. case HLS_UP_ACTIVE:
  9123. if (ppd->host_link_state != HLS_UP_ARMED)
  9124. goto unexpected;
  9125. ppd->host_link_state = HLS_UP_ACTIVE;
  9126. set_logical_state(dd, LSTATE_ACTIVE);
  9127. ret = wait_logical_linkstate(ppd, IB_PORT_ACTIVE, 1000);
  9128. if (ret) {
  9129. /* logical state didn't change, stay at armed */
  9130. ppd->host_link_state = HLS_UP_ARMED;
  9131. dd_dev_err(dd,
  9132. "%s: logical state did not change to ACTIVE\n",
  9133. __func__);
  9134. } else {
  9135. /* tell all engines to go running */
  9136. sdma_all_running(dd);
  9137. /* Signal the IB layer that the port has went active */
  9138. event.device = &dd->verbs_dev.rdi.ibdev;
  9139. event.element.port_num = ppd->port;
  9140. event.event = IB_EVENT_PORT_ACTIVE;
  9141. }
  9142. break;
  9143. case HLS_DN_POLL:
  9144. if ((ppd->host_link_state == HLS_DN_DISABLE ||
  9145. ppd->host_link_state == HLS_DN_OFFLINE) &&
  9146. dd->dc_shutdown)
  9147. dc_start(dd);
  9148. /* Hand LED control to the DC */
  9149. write_csr(dd, DCC_CFG_LED_CNTRL, 0);
  9150. if (ppd->host_link_state != HLS_DN_OFFLINE) {
  9151. u8 tmp = ppd->link_enabled;
  9152. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9153. if (ret) {
  9154. ppd->link_enabled = tmp;
  9155. break;
  9156. }
  9157. ppd->remote_link_down_reason = 0;
  9158. if (ppd->driver_link_ready)
  9159. ppd->link_enabled = 1;
  9160. }
  9161. set_all_slowpath(ppd->dd);
  9162. ret = set_local_link_attributes(ppd);
  9163. if (ret)
  9164. break;
  9165. ppd->port_error_action = 0;
  9166. ppd->host_link_state = HLS_DN_POLL;
  9167. if (quick_linkup) {
  9168. /* quick linkup does not go into polling */
  9169. ret = do_quick_linkup(dd);
  9170. } else {
  9171. ret1 = set_physical_link_state(dd, PLS_POLLING);
  9172. if (ret1 != HCMD_SUCCESS) {
  9173. dd_dev_err(dd,
  9174. "Failed to transition to Polling link state, return 0x%x\n",
  9175. ret1);
  9176. ret = -EINVAL;
  9177. }
  9178. }
  9179. ppd->offline_disabled_reason =
  9180. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
  9181. /*
  9182. * If an error occurred above, go back to offline. The
  9183. * caller may reschedule another attempt.
  9184. */
  9185. if (ret)
  9186. goto_offline(ppd, 0);
  9187. break;
  9188. case HLS_DN_DISABLE:
  9189. /* link is disabled */
  9190. ppd->link_enabled = 0;
  9191. /* allow any state to transition to disabled */
  9192. /* must transition to offline first */
  9193. if (ppd->host_link_state != HLS_DN_OFFLINE) {
  9194. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9195. if (ret)
  9196. break;
  9197. ppd->remote_link_down_reason = 0;
  9198. }
  9199. ret1 = set_physical_link_state(dd, PLS_DISABLED);
  9200. if (ret1 != HCMD_SUCCESS) {
  9201. dd_dev_err(dd,
  9202. "Failed to transition to Disabled link state, return 0x%x\n",
  9203. ret1);
  9204. ret = -EINVAL;
  9205. break;
  9206. }
  9207. ppd->host_link_state = HLS_DN_DISABLE;
  9208. dc_shutdown(dd);
  9209. break;
  9210. case HLS_DN_OFFLINE:
  9211. if (ppd->host_link_state == HLS_DN_DISABLE)
  9212. dc_start(dd);
  9213. /* allow any state to transition to offline */
  9214. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9215. if (!ret)
  9216. ppd->remote_link_down_reason = 0;
  9217. break;
  9218. case HLS_VERIFY_CAP:
  9219. if (ppd->host_link_state != HLS_DN_POLL)
  9220. goto unexpected;
  9221. ppd->host_link_state = HLS_VERIFY_CAP;
  9222. break;
  9223. case HLS_GOING_UP:
  9224. if (ppd->host_link_state != HLS_VERIFY_CAP)
  9225. goto unexpected;
  9226. ret1 = set_physical_link_state(dd, PLS_LINKUP);
  9227. if (ret1 != HCMD_SUCCESS) {
  9228. dd_dev_err(dd,
  9229. "Failed to transition to link up state, return 0x%x\n",
  9230. ret1);
  9231. ret = -EINVAL;
  9232. break;
  9233. }
  9234. ppd->host_link_state = HLS_GOING_UP;
  9235. break;
  9236. case HLS_GOING_OFFLINE: /* transient within goto_offline() */
  9237. case HLS_LINK_COOLDOWN: /* transient within goto_offline() */
  9238. default:
  9239. dd_dev_info(dd, "%s: state 0x%x: not supported\n",
  9240. __func__, state);
  9241. ret = -EINVAL;
  9242. break;
  9243. }
  9244. goto done;
  9245. unexpected:
  9246. dd_dev_err(dd, "%s: unexpected state transition from %s to %s\n",
  9247. __func__, link_state_name(ppd->host_link_state),
  9248. link_state_name(state));
  9249. ret = -EINVAL;
  9250. done:
  9251. mutex_unlock(&ppd->hls_lock);
  9252. if (event.device)
  9253. ib_dispatch_event(&event);
  9254. return ret;
  9255. }
  9256. int hfi1_set_ib_cfg(struct hfi1_pportdata *ppd, int which, u32 val)
  9257. {
  9258. u64 reg;
  9259. int ret = 0;
  9260. switch (which) {
  9261. case HFI1_IB_CFG_LIDLMC:
  9262. set_lidlmc(ppd);
  9263. break;
  9264. case HFI1_IB_CFG_VL_HIGH_LIMIT:
  9265. /*
  9266. * The VL Arbitrator high limit is sent in units of 4k
  9267. * bytes, while HFI stores it in units of 64 bytes.
  9268. */
  9269. val *= 4096 / 64;
  9270. reg = ((u64)val & SEND_HIGH_PRIORITY_LIMIT_LIMIT_MASK)
  9271. << SEND_HIGH_PRIORITY_LIMIT_LIMIT_SHIFT;
  9272. write_csr(ppd->dd, SEND_HIGH_PRIORITY_LIMIT, reg);
  9273. break;
  9274. case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  9275. /* HFI only supports POLL as the default link down state */
  9276. if (val != HLS_DN_POLL)
  9277. ret = -EINVAL;
  9278. break;
  9279. case HFI1_IB_CFG_OP_VLS:
  9280. if (ppd->vls_operational != val) {
  9281. ppd->vls_operational = val;
  9282. if (!ppd->port)
  9283. ret = -EINVAL;
  9284. }
  9285. break;
  9286. /*
  9287. * For link width, link width downgrade, and speed enable, always AND
  9288. * the setting with what is actually supported. This has two benefits.
  9289. * First, enabled can't have unsupported values, no matter what the
  9290. * SM or FM might want. Second, the ALL_SUPPORTED wildcards that mean
  9291. * "fill in with your supported value" have all the bits in the
  9292. * field set, so simply ANDing with supported has the desired result.
  9293. */
  9294. case HFI1_IB_CFG_LWID_ENB: /* set allowed Link-width */
  9295. ppd->link_width_enabled = val & ppd->link_width_supported;
  9296. break;
  9297. case HFI1_IB_CFG_LWID_DG_ENB: /* set allowed link width downgrade */
  9298. ppd->link_width_downgrade_enabled =
  9299. val & ppd->link_width_downgrade_supported;
  9300. break;
  9301. case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
  9302. ppd->link_speed_enabled = val & ppd->link_speed_supported;
  9303. break;
  9304. case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  9305. /*
  9306. * HFI does not follow IB specs, save this value
  9307. * so we can report it, if asked.
  9308. */
  9309. ppd->overrun_threshold = val;
  9310. break;
  9311. case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  9312. /*
  9313. * HFI does not follow IB specs, save this value
  9314. * so we can report it, if asked.
  9315. */
  9316. ppd->phy_error_threshold = val;
  9317. break;
  9318. case HFI1_IB_CFG_MTU:
  9319. set_send_length(ppd);
  9320. break;
  9321. case HFI1_IB_CFG_PKEYS:
  9322. if (HFI1_CAP_IS_KSET(PKEY_CHECK))
  9323. set_partition_keys(ppd);
  9324. break;
  9325. default:
  9326. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  9327. dd_dev_info(ppd->dd,
  9328. "%s: which %s, val 0x%x: not implemented\n",
  9329. __func__, ib_cfg_name(which), val);
  9330. break;
  9331. }
  9332. return ret;
  9333. }
  9334. /* begin functions related to vl arbitration table caching */
  9335. static void init_vl_arb_caches(struct hfi1_pportdata *ppd)
  9336. {
  9337. int i;
  9338. BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
  9339. VL_ARB_LOW_PRIO_TABLE_SIZE);
  9340. BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
  9341. VL_ARB_HIGH_PRIO_TABLE_SIZE);
  9342. /*
  9343. * Note that we always return values directly from the
  9344. * 'vl_arb_cache' (and do no CSR reads) in response to a
  9345. * 'Get(VLArbTable)'. This is obviously correct after a
  9346. * 'Set(VLArbTable)', since the cache will then be up to
  9347. * date. But it's also correct prior to any 'Set(VLArbTable)'
  9348. * since then both the cache, and the relevant h/w registers
  9349. * will be zeroed.
  9350. */
  9351. for (i = 0; i < MAX_PRIO_TABLE; i++)
  9352. spin_lock_init(&ppd->vl_arb_cache[i].lock);
  9353. }
  9354. /*
  9355. * vl_arb_lock_cache
  9356. *
  9357. * All other vl_arb_* functions should be called only after locking
  9358. * the cache.
  9359. */
  9360. static inline struct vl_arb_cache *
  9361. vl_arb_lock_cache(struct hfi1_pportdata *ppd, int idx)
  9362. {
  9363. if (idx != LO_PRIO_TABLE && idx != HI_PRIO_TABLE)
  9364. return NULL;
  9365. spin_lock(&ppd->vl_arb_cache[idx].lock);
  9366. return &ppd->vl_arb_cache[idx];
  9367. }
  9368. static inline void vl_arb_unlock_cache(struct hfi1_pportdata *ppd, int idx)
  9369. {
  9370. spin_unlock(&ppd->vl_arb_cache[idx].lock);
  9371. }
  9372. static void vl_arb_get_cache(struct vl_arb_cache *cache,
  9373. struct ib_vl_weight_elem *vl)
  9374. {
  9375. memcpy(vl, cache->table, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9376. }
  9377. static void vl_arb_set_cache(struct vl_arb_cache *cache,
  9378. struct ib_vl_weight_elem *vl)
  9379. {
  9380. memcpy(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9381. }
  9382. static int vl_arb_match_cache(struct vl_arb_cache *cache,
  9383. struct ib_vl_weight_elem *vl)
  9384. {
  9385. return !memcmp(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9386. }
  9387. /* end functions related to vl arbitration table caching */
  9388. static int set_vl_weights(struct hfi1_pportdata *ppd, u32 target,
  9389. u32 size, struct ib_vl_weight_elem *vl)
  9390. {
  9391. struct hfi1_devdata *dd = ppd->dd;
  9392. u64 reg;
  9393. unsigned int i, is_up = 0;
  9394. int drain, ret = 0;
  9395. mutex_lock(&ppd->hls_lock);
  9396. if (ppd->host_link_state & HLS_UP)
  9397. is_up = 1;
  9398. drain = !is_ax(dd) && is_up;
  9399. if (drain)
  9400. /*
  9401. * Before adjusting VL arbitration weights, empty per-VL
  9402. * FIFOs, otherwise a packet whose VL weight is being
  9403. * set to 0 could get stuck in a FIFO with no chance to
  9404. * egress.
  9405. */
  9406. ret = stop_drain_data_vls(dd);
  9407. if (ret) {
  9408. dd_dev_err(
  9409. dd,
  9410. "%s: cannot stop/drain VLs - refusing to change VL arbitration weights\n",
  9411. __func__);
  9412. goto err;
  9413. }
  9414. for (i = 0; i < size; i++, vl++) {
  9415. /*
  9416. * NOTE: The low priority shift and mask are used here, but
  9417. * they are the same for both the low and high registers.
  9418. */
  9419. reg = (((u64)vl->vl & SEND_LOW_PRIORITY_LIST_VL_MASK)
  9420. << SEND_LOW_PRIORITY_LIST_VL_SHIFT)
  9421. | (((u64)vl->weight
  9422. & SEND_LOW_PRIORITY_LIST_WEIGHT_MASK)
  9423. << SEND_LOW_PRIORITY_LIST_WEIGHT_SHIFT);
  9424. write_csr(dd, target + (i * 8), reg);
  9425. }
  9426. pio_send_control(dd, PSC_GLOBAL_VLARB_ENABLE);
  9427. if (drain)
  9428. open_fill_data_vls(dd); /* reopen all VLs */
  9429. err:
  9430. mutex_unlock(&ppd->hls_lock);
  9431. return ret;
  9432. }
  9433. /*
  9434. * Read one credit merge VL register.
  9435. */
  9436. static void read_one_cm_vl(struct hfi1_devdata *dd, u32 csr,
  9437. struct vl_limit *vll)
  9438. {
  9439. u64 reg = read_csr(dd, csr);
  9440. vll->dedicated = cpu_to_be16(
  9441. (reg >> SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT)
  9442. & SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_MASK);
  9443. vll->shared = cpu_to_be16(
  9444. (reg >> SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT)
  9445. & SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_MASK);
  9446. }
  9447. /*
  9448. * Read the current credit merge limits.
  9449. */
  9450. static int get_buffer_control(struct hfi1_devdata *dd,
  9451. struct buffer_control *bc, u16 *overall_limit)
  9452. {
  9453. u64 reg;
  9454. int i;
  9455. /* not all entries are filled in */
  9456. memset(bc, 0, sizeof(*bc));
  9457. /* OPA and HFI have a 1-1 mapping */
  9458. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  9459. read_one_cm_vl(dd, SEND_CM_CREDIT_VL + (8 * i), &bc->vl[i]);
  9460. /* NOTE: assumes that VL* and VL15 CSRs are bit-wise identical */
  9461. read_one_cm_vl(dd, SEND_CM_CREDIT_VL15, &bc->vl[15]);
  9462. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9463. bc->overall_shared_limit = cpu_to_be16(
  9464. (reg >> SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT)
  9465. & SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_MASK);
  9466. if (overall_limit)
  9467. *overall_limit = (reg
  9468. >> SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT)
  9469. & SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_MASK;
  9470. return sizeof(struct buffer_control);
  9471. }
  9472. static int get_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
  9473. {
  9474. u64 reg;
  9475. int i;
  9476. /* each register contains 16 SC->VLnt mappings, 4 bits each */
  9477. reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_15_0);
  9478. for (i = 0; i < sizeof(u64); i++) {
  9479. u8 byte = *(((u8 *)&reg) + i);
  9480. dp->vlnt[2 * i] = byte & 0xf;
  9481. dp->vlnt[(2 * i) + 1] = (byte & 0xf0) >> 4;
  9482. }
  9483. reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_31_16);
  9484. for (i = 0; i < sizeof(u64); i++) {
  9485. u8 byte = *(((u8 *)&reg) + i);
  9486. dp->vlnt[16 + (2 * i)] = byte & 0xf;
  9487. dp->vlnt[16 + (2 * i) + 1] = (byte & 0xf0) >> 4;
  9488. }
  9489. return sizeof(struct sc2vlnt);
  9490. }
  9491. static void get_vlarb_preempt(struct hfi1_devdata *dd, u32 nelems,
  9492. struct ib_vl_weight_elem *vl)
  9493. {
  9494. unsigned int i;
  9495. for (i = 0; i < nelems; i++, vl++) {
  9496. vl->vl = 0xf;
  9497. vl->weight = 0;
  9498. }
  9499. }
  9500. static void set_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
  9501. {
  9502. write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0,
  9503. DC_SC_VL_VAL(15_0,
  9504. 0, dp->vlnt[0] & 0xf,
  9505. 1, dp->vlnt[1] & 0xf,
  9506. 2, dp->vlnt[2] & 0xf,
  9507. 3, dp->vlnt[3] & 0xf,
  9508. 4, dp->vlnt[4] & 0xf,
  9509. 5, dp->vlnt[5] & 0xf,
  9510. 6, dp->vlnt[6] & 0xf,
  9511. 7, dp->vlnt[7] & 0xf,
  9512. 8, dp->vlnt[8] & 0xf,
  9513. 9, dp->vlnt[9] & 0xf,
  9514. 10, dp->vlnt[10] & 0xf,
  9515. 11, dp->vlnt[11] & 0xf,
  9516. 12, dp->vlnt[12] & 0xf,
  9517. 13, dp->vlnt[13] & 0xf,
  9518. 14, dp->vlnt[14] & 0xf,
  9519. 15, dp->vlnt[15] & 0xf));
  9520. write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16,
  9521. DC_SC_VL_VAL(31_16,
  9522. 16, dp->vlnt[16] & 0xf,
  9523. 17, dp->vlnt[17] & 0xf,
  9524. 18, dp->vlnt[18] & 0xf,
  9525. 19, dp->vlnt[19] & 0xf,
  9526. 20, dp->vlnt[20] & 0xf,
  9527. 21, dp->vlnt[21] & 0xf,
  9528. 22, dp->vlnt[22] & 0xf,
  9529. 23, dp->vlnt[23] & 0xf,
  9530. 24, dp->vlnt[24] & 0xf,
  9531. 25, dp->vlnt[25] & 0xf,
  9532. 26, dp->vlnt[26] & 0xf,
  9533. 27, dp->vlnt[27] & 0xf,
  9534. 28, dp->vlnt[28] & 0xf,
  9535. 29, dp->vlnt[29] & 0xf,
  9536. 30, dp->vlnt[30] & 0xf,
  9537. 31, dp->vlnt[31] & 0xf));
  9538. }
  9539. static void nonzero_msg(struct hfi1_devdata *dd, int idx, const char *what,
  9540. u16 limit)
  9541. {
  9542. if (limit != 0)
  9543. dd_dev_info(dd, "Invalid %s limit %d on VL %d, ignoring\n",
  9544. what, (int)limit, idx);
  9545. }
  9546. /* change only the shared limit portion of SendCmGLobalCredit */
  9547. static void set_global_shared(struct hfi1_devdata *dd, u16 limit)
  9548. {
  9549. u64 reg;
  9550. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9551. reg &= ~SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK;
  9552. reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT;
  9553. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  9554. }
  9555. /* change only the total credit limit portion of SendCmGLobalCredit */
  9556. static void set_global_limit(struct hfi1_devdata *dd, u16 limit)
  9557. {
  9558. u64 reg;
  9559. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9560. reg &= ~SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK;
  9561. reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
  9562. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  9563. }
  9564. /* set the given per-VL shared limit */
  9565. static void set_vl_shared(struct hfi1_devdata *dd, int vl, u16 limit)
  9566. {
  9567. u64 reg;
  9568. u32 addr;
  9569. if (vl < TXE_NUM_DATA_VL)
  9570. addr = SEND_CM_CREDIT_VL + (8 * vl);
  9571. else
  9572. addr = SEND_CM_CREDIT_VL15;
  9573. reg = read_csr(dd, addr);
  9574. reg &= ~SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SMASK;
  9575. reg |= (u64)limit << SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT;
  9576. write_csr(dd, addr, reg);
  9577. }
  9578. /* set the given per-VL dedicated limit */
  9579. static void set_vl_dedicated(struct hfi1_devdata *dd, int vl, u16 limit)
  9580. {
  9581. u64 reg;
  9582. u32 addr;
  9583. if (vl < TXE_NUM_DATA_VL)
  9584. addr = SEND_CM_CREDIT_VL + (8 * vl);
  9585. else
  9586. addr = SEND_CM_CREDIT_VL15;
  9587. reg = read_csr(dd, addr);
  9588. reg &= ~SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SMASK;
  9589. reg |= (u64)limit << SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT;
  9590. write_csr(dd, addr, reg);
  9591. }
  9592. /* spin until the given per-VL status mask bits clear */
  9593. static void wait_for_vl_status_clear(struct hfi1_devdata *dd, u64 mask,
  9594. const char *which)
  9595. {
  9596. unsigned long timeout;
  9597. u64 reg;
  9598. timeout = jiffies + msecs_to_jiffies(VL_STATUS_CLEAR_TIMEOUT);
  9599. while (1) {
  9600. reg = read_csr(dd, SEND_CM_CREDIT_USED_STATUS) & mask;
  9601. if (reg == 0)
  9602. return; /* success */
  9603. if (time_after(jiffies, timeout))
  9604. break; /* timed out */
  9605. udelay(1);
  9606. }
  9607. dd_dev_err(dd,
  9608. "%s credit change status not clearing after %dms, mask 0x%llx, not clear 0x%llx\n",
  9609. which, VL_STATUS_CLEAR_TIMEOUT, mask, reg);
  9610. /*
  9611. * If this occurs, it is likely there was a credit loss on the link.
  9612. * The only recovery from that is a link bounce.
  9613. */
  9614. dd_dev_err(dd,
  9615. "Continuing anyway. A credit loss may occur. Suggest a link bounce\n");
  9616. }
  9617. /*
  9618. * The number of credits on the VLs may be changed while everything
  9619. * is "live", but the following algorithm must be followed due to
  9620. * how the hardware is actually implemented. In particular,
  9621. * Return_Credit_Status[] is the only correct status check.
  9622. *
  9623. * if (reducing Global_Shared_Credit_Limit or any shared limit changing)
  9624. * set Global_Shared_Credit_Limit = 0
  9625. * use_all_vl = 1
  9626. * mask0 = all VLs that are changing either dedicated or shared limits
  9627. * set Shared_Limit[mask0] = 0
  9628. * spin until Return_Credit_Status[use_all_vl ? all VL : mask0] == 0
  9629. * if (changing any dedicated limit)
  9630. * mask1 = all VLs that are lowering dedicated limits
  9631. * lower Dedicated_Limit[mask1]
  9632. * spin until Return_Credit_Status[mask1] == 0
  9633. * raise Dedicated_Limits
  9634. * raise Shared_Limits
  9635. * raise Global_Shared_Credit_Limit
  9636. *
  9637. * lower = if the new limit is lower, set the limit to the new value
  9638. * raise = if the new limit is higher than the current value (may be changed
  9639. * earlier in the algorithm), set the new limit to the new value
  9640. */
  9641. int set_buffer_control(struct hfi1_pportdata *ppd,
  9642. struct buffer_control *new_bc)
  9643. {
  9644. struct hfi1_devdata *dd = ppd->dd;
  9645. u64 changing_mask, ld_mask, stat_mask;
  9646. int change_count;
  9647. int i, use_all_mask;
  9648. int this_shared_changing;
  9649. int vl_count = 0, ret;
  9650. /*
  9651. * A0: add the variable any_shared_limit_changing below and in the
  9652. * algorithm above. If removing A0 support, it can be removed.
  9653. */
  9654. int any_shared_limit_changing;
  9655. struct buffer_control cur_bc;
  9656. u8 changing[OPA_MAX_VLS];
  9657. u8 lowering_dedicated[OPA_MAX_VLS];
  9658. u16 cur_total;
  9659. u32 new_total = 0;
  9660. const u64 all_mask =
  9661. SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK
  9662. | SEND_CM_CREDIT_USED_STATUS_VL1_RETURN_CREDIT_STATUS_SMASK
  9663. | SEND_CM_CREDIT_USED_STATUS_VL2_RETURN_CREDIT_STATUS_SMASK
  9664. | SEND_CM_CREDIT_USED_STATUS_VL3_RETURN_CREDIT_STATUS_SMASK
  9665. | SEND_CM_CREDIT_USED_STATUS_VL4_RETURN_CREDIT_STATUS_SMASK
  9666. | SEND_CM_CREDIT_USED_STATUS_VL5_RETURN_CREDIT_STATUS_SMASK
  9667. | SEND_CM_CREDIT_USED_STATUS_VL6_RETURN_CREDIT_STATUS_SMASK
  9668. | SEND_CM_CREDIT_USED_STATUS_VL7_RETURN_CREDIT_STATUS_SMASK
  9669. | SEND_CM_CREDIT_USED_STATUS_VL15_RETURN_CREDIT_STATUS_SMASK;
  9670. #define valid_vl(idx) ((idx) < TXE_NUM_DATA_VL || (idx) == 15)
  9671. #define NUM_USABLE_VLS 16 /* look at VL15 and less */
  9672. /* find the new total credits, do sanity check on unused VLs */
  9673. for (i = 0; i < OPA_MAX_VLS; i++) {
  9674. if (valid_vl(i)) {
  9675. new_total += be16_to_cpu(new_bc->vl[i].dedicated);
  9676. continue;
  9677. }
  9678. nonzero_msg(dd, i, "dedicated",
  9679. be16_to_cpu(new_bc->vl[i].dedicated));
  9680. nonzero_msg(dd, i, "shared",
  9681. be16_to_cpu(new_bc->vl[i].shared));
  9682. new_bc->vl[i].dedicated = 0;
  9683. new_bc->vl[i].shared = 0;
  9684. }
  9685. new_total += be16_to_cpu(new_bc->overall_shared_limit);
  9686. /* fetch the current values */
  9687. get_buffer_control(dd, &cur_bc, &cur_total);
  9688. /*
  9689. * Create the masks we will use.
  9690. */
  9691. memset(changing, 0, sizeof(changing));
  9692. memset(lowering_dedicated, 0, sizeof(lowering_dedicated));
  9693. /*
  9694. * NOTE: Assumes that the individual VL bits are adjacent and in
  9695. * increasing order
  9696. */
  9697. stat_mask =
  9698. SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK;
  9699. changing_mask = 0;
  9700. ld_mask = 0;
  9701. change_count = 0;
  9702. any_shared_limit_changing = 0;
  9703. for (i = 0; i < NUM_USABLE_VLS; i++, stat_mask <<= 1) {
  9704. if (!valid_vl(i))
  9705. continue;
  9706. this_shared_changing = new_bc->vl[i].shared
  9707. != cur_bc.vl[i].shared;
  9708. if (this_shared_changing)
  9709. any_shared_limit_changing = 1;
  9710. if (new_bc->vl[i].dedicated != cur_bc.vl[i].dedicated ||
  9711. this_shared_changing) {
  9712. changing[i] = 1;
  9713. changing_mask |= stat_mask;
  9714. change_count++;
  9715. }
  9716. if (be16_to_cpu(new_bc->vl[i].dedicated) <
  9717. be16_to_cpu(cur_bc.vl[i].dedicated)) {
  9718. lowering_dedicated[i] = 1;
  9719. ld_mask |= stat_mask;
  9720. }
  9721. }
  9722. /* bracket the credit change with a total adjustment */
  9723. if (new_total > cur_total)
  9724. set_global_limit(dd, new_total);
  9725. /*
  9726. * Start the credit change algorithm.
  9727. */
  9728. use_all_mask = 0;
  9729. if ((be16_to_cpu(new_bc->overall_shared_limit) <
  9730. be16_to_cpu(cur_bc.overall_shared_limit)) ||
  9731. (is_ax(dd) && any_shared_limit_changing)) {
  9732. set_global_shared(dd, 0);
  9733. cur_bc.overall_shared_limit = 0;
  9734. use_all_mask = 1;
  9735. }
  9736. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9737. if (!valid_vl(i))
  9738. continue;
  9739. if (changing[i]) {
  9740. set_vl_shared(dd, i, 0);
  9741. cur_bc.vl[i].shared = 0;
  9742. }
  9743. }
  9744. wait_for_vl_status_clear(dd, use_all_mask ? all_mask : changing_mask,
  9745. "shared");
  9746. if (change_count > 0) {
  9747. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9748. if (!valid_vl(i))
  9749. continue;
  9750. if (lowering_dedicated[i]) {
  9751. set_vl_dedicated(dd, i,
  9752. be16_to_cpu(new_bc->
  9753. vl[i].dedicated));
  9754. cur_bc.vl[i].dedicated =
  9755. new_bc->vl[i].dedicated;
  9756. }
  9757. }
  9758. wait_for_vl_status_clear(dd, ld_mask, "dedicated");
  9759. /* now raise all dedicated that are going up */
  9760. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9761. if (!valid_vl(i))
  9762. continue;
  9763. if (be16_to_cpu(new_bc->vl[i].dedicated) >
  9764. be16_to_cpu(cur_bc.vl[i].dedicated))
  9765. set_vl_dedicated(dd, i,
  9766. be16_to_cpu(new_bc->
  9767. vl[i].dedicated));
  9768. }
  9769. }
  9770. /* next raise all shared that are going up */
  9771. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9772. if (!valid_vl(i))
  9773. continue;
  9774. if (be16_to_cpu(new_bc->vl[i].shared) >
  9775. be16_to_cpu(cur_bc.vl[i].shared))
  9776. set_vl_shared(dd, i, be16_to_cpu(new_bc->vl[i].shared));
  9777. }
  9778. /* finally raise the global shared */
  9779. if (be16_to_cpu(new_bc->overall_shared_limit) >
  9780. be16_to_cpu(cur_bc.overall_shared_limit))
  9781. set_global_shared(dd,
  9782. be16_to_cpu(new_bc->overall_shared_limit));
  9783. /* bracket the credit change with a total adjustment */
  9784. if (new_total < cur_total)
  9785. set_global_limit(dd, new_total);
  9786. /*
  9787. * Determine the actual number of operational VLS using the number of
  9788. * dedicated and shared credits for each VL.
  9789. */
  9790. if (change_count > 0) {
  9791. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  9792. if (be16_to_cpu(new_bc->vl[i].dedicated) > 0 ||
  9793. be16_to_cpu(new_bc->vl[i].shared) > 0)
  9794. vl_count++;
  9795. ppd->actual_vls_operational = vl_count;
  9796. ret = sdma_map_init(dd, ppd->port - 1, vl_count ?
  9797. ppd->actual_vls_operational :
  9798. ppd->vls_operational,
  9799. NULL);
  9800. if (ret == 0)
  9801. ret = pio_map_init(dd, ppd->port - 1, vl_count ?
  9802. ppd->actual_vls_operational :
  9803. ppd->vls_operational, NULL);
  9804. if (ret)
  9805. return ret;
  9806. }
  9807. return 0;
  9808. }
  9809. /*
  9810. * Read the given fabric manager table. Return the size of the
  9811. * table (in bytes) on success, and a negative error code on
  9812. * failure.
  9813. */
  9814. int fm_get_table(struct hfi1_pportdata *ppd, int which, void *t)
  9815. {
  9816. int size;
  9817. struct vl_arb_cache *vlc;
  9818. switch (which) {
  9819. case FM_TBL_VL_HIGH_ARB:
  9820. size = 256;
  9821. /*
  9822. * OPA specifies 128 elements (of 2 bytes each), though
  9823. * HFI supports only 16 elements in h/w.
  9824. */
  9825. vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
  9826. vl_arb_get_cache(vlc, t);
  9827. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  9828. break;
  9829. case FM_TBL_VL_LOW_ARB:
  9830. size = 256;
  9831. /*
  9832. * OPA specifies 128 elements (of 2 bytes each), though
  9833. * HFI supports only 16 elements in h/w.
  9834. */
  9835. vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
  9836. vl_arb_get_cache(vlc, t);
  9837. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  9838. break;
  9839. case FM_TBL_BUFFER_CONTROL:
  9840. size = get_buffer_control(ppd->dd, t, NULL);
  9841. break;
  9842. case FM_TBL_SC2VLNT:
  9843. size = get_sc2vlnt(ppd->dd, t);
  9844. break;
  9845. case FM_TBL_VL_PREEMPT_ELEMS:
  9846. size = 256;
  9847. /* OPA specifies 128 elements, of 2 bytes each */
  9848. get_vlarb_preempt(ppd->dd, OPA_MAX_VLS, t);
  9849. break;
  9850. case FM_TBL_VL_PREEMPT_MATRIX:
  9851. size = 256;
  9852. /*
  9853. * OPA specifies that this is the same size as the VL
  9854. * arbitration tables (i.e., 256 bytes).
  9855. */
  9856. break;
  9857. default:
  9858. return -EINVAL;
  9859. }
  9860. return size;
  9861. }
  9862. /*
  9863. * Write the given fabric manager table.
  9864. */
  9865. int fm_set_table(struct hfi1_pportdata *ppd, int which, void *t)
  9866. {
  9867. int ret = 0;
  9868. struct vl_arb_cache *vlc;
  9869. switch (which) {
  9870. case FM_TBL_VL_HIGH_ARB:
  9871. vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
  9872. if (vl_arb_match_cache(vlc, t)) {
  9873. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  9874. break;
  9875. }
  9876. vl_arb_set_cache(vlc, t);
  9877. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  9878. ret = set_vl_weights(ppd, SEND_HIGH_PRIORITY_LIST,
  9879. VL_ARB_HIGH_PRIO_TABLE_SIZE, t);
  9880. break;
  9881. case FM_TBL_VL_LOW_ARB:
  9882. vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
  9883. if (vl_arb_match_cache(vlc, t)) {
  9884. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  9885. break;
  9886. }
  9887. vl_arb_set_cache(vlc, t);
  9888. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  9889. ret = set_vl_weights(ppd, SEND_LOW_PRIORITY_LIST,
  9890. VL_ARB_LOW_PRIO_TABLE_SIZE, t);
  9891. break;
  9892. case FM_TBL_BUFFER_CONTROL:
  9893. ret = set_buffer_control(ppd, t);
  9894. break;
  9895. case FM_TBL_SC2VLNT:
  9896. set_sc2vlnt(ppd->dd, t);
  9897. break;
  9898. default:
  9899. ret = -EINVAL;
  9900. }
  9901. return ret;
  9902. }
  9903. /*
  9904. * Disable all data VLs.
  9905. *
  9906. * Return 0 if disabled, non-zero if the VLs cannot be disabled.
  9907. */
  9908. static int disable_data_vls(struct hfi1_devdata *dd)
  9909. {
  9910. if (is_ax(dd))
  9911. return 1;
  9912. pio_send_control(dd, PSC_DATA_VL_DISABLE);
  9913. return 0;
  9914. }
  9915. /*
  9916. * open_fill_data_vls() - the counterpart to stop_drain_data_vls().
  9917. * Just re-enables all data VLs (the "fill" part happens
  9918. * automatically - the name was chosen for symmetry with
  9919. * stop_drain_data_vls()).
  9920. *
  9921. * Return 0 if successful, non-zero if the VLs cannot be enabled.
  9922. */
  9923. int open_fill_data_vls(struct hfi1_devdata *dd)
  9924. {
  9925. if (is_ax(dd))
  9926. return 1;
  9927. pio_send_control(dd, PSC_DATA_VL_ENABLE);
  9928. return 0;
  9929. }
  9930. /*
  9931. * drain_data_vls() - assumes that disable_data_vls() has been called,
  9932. * wait for occupancy (of per-VL FIFOs) for all contexts, and SDMA
  9933. * engines to drop to 0.
  9934. */
  9935. static void drain_data_vls(struct hfi1_devdata *dd)
  9936. {
  9937. sc_wait(dd);
  9938. sdma_wait(dd);
  9939. pause_for_credit_return(dd);
  9940. }
  9941. /*
  9942. * stop_drain_data_vls() - disable, then drain all per-VL fifos.
  9943. *
  9944. * Use open_fill_data_vls() to resume using data VLs. This pair is
  9945. * meant to be used like this:
  9946. *
  9947. * stop_drain_data_vls(dd);
  9948. * // do things with per-VL resources
  9949. * open_fill_data_vls(dd);
  9950. */
  9951. int stop_drain_data_vls(struct hfi1_devdata *dd)
  9952. {
  9953. int ret;
  9954. ret = disable_data_vls(dd);
  9955. if (ret == 0)
  9956. drain_data_vls(dd);
  9957. return ret;
  9958. }
  9959. /*
  9960. * Convert a nanosecond time to a cclock count. No matter how slow
  9961. * the cclock, a non-zero ns will always have a non-zero result.
  9962. */
  9963. u32 ns_to_cclock(struct hfi1_devdata *dd, u32 ns)
  9964. {
  9965. u32 cclocks;
  9966. if (dd->icode == ICODE_FPGA_EMULATION)
  9967. cclocks = (ns * 1000) / FPGA_CCLOCK_PS;
  9968. else /* simulation pretends to be ASIC */
  9969. cclocks = (ns * 1000) / ASIC_CCLOCK_PS;
  9970. if (ns && !cclocks) /* if ns nonzero, must be at least 1 */
  9971. cclocks = 1;
  9972. return cclocks;
  9973. }
  9974. /*
  9975. * Convert a cclock count to nanoseconds. Not matter how slow
  9976. * the cclock, a non-zero cclocks will always have a non-zero result.
  9977. */
  9978. u32 cclock_to_ns(struct hfi1_devdata *dd, u32 cclocks)
  9979. {
  9980. u32 ns;
  9981. if (dd->icode == ICODE_FPGA_EMULATION)
  9982. ns = (cclocks * FPGA_CCLOCK_PS) / 1000;
  9983. else /* simulation pretends to be ASIC */
  9984. ns = (cclocks * ASIC_CCLOCK_PS) / 1000;
  9985. if (cclocks && !ns)
  9986. ns = 1;
  9987. return ns;
  9988. }
  9989. /*
  9990. * Dynamically adjust the receive interrupt timeout for a context based on
  9991. * incoming packet rate.
  9992. *
  9993. * NOTE: Dynamic adjustment does not allow rcv_intr_count to be zero.
  9994. */
  9995. static void adjust_rcv_timeout(struct hfi1_ctxtdata *rcd, u32 npkts)
  9996. {
  9997. struct hfi1_devdata *dd = rcd->dd;
  9998. u32 timeout = rcd->rcvavail_timeout;
  9999. /*
  10000. * This algorithm doubles or halves the timeout depending on whether
  10001. * the number of packets received in this interrupt were less than or
  10002. * greater equal the interrupt count.
  10003. *
  10004. * The calculations below do not allow a steady state to be achieved.
  10005. * Only at the endpoints it is possible to have an unchanging
  10006. * timeout.
  10007. */
  10008. if (npkts < rcv_intr_count) {
  10009. /*
  10010. * Not enough packets arrived before the timeout, adjust
  10011. * timeout downward.
  10012. */
  10013. if (timeout < 2) /* already at minimum? */
  10014. return;
  10015. timeout >>= 1;
  10016. } else {
  10017. /*
  10018. * More than enough packets arrived before the timeout, adjust
  10019. * timeout upward.
  10020. */
  10021. if (timeout >= dd->rcv_intr_timeout_csr) /* already at max? */
  10022. return;
  10023. timeout = min(timeout << 1, dd->rcv_intr_timeout_csr);
  10024. }
  10025. rcd->rcvavail_timeout = timeout;
  10026. /*
  10027. * timeout cannot be larger than rcv_intr_timeout_csr which has already
  10028. * been verified to be in range
  10029. */
  10030. write_kctxt_csr(dd, rcd->ctxt, RCV_AVAIL_TIME_OUT,
  10031. (u64)timeout <<
  10032. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
  10033. }
  10034. void update_usrhead(struct hfi1_ctxtdata *rcd, u32 hd, u32 updegr, u32 egrhd,
  10035. u32 intr_adjust, u32 npkts)
  10036. {
  10037. struct hfi1_devdata *dd = rcd->dd;
  10038. u64 reg;
  10039. u32 ctxt = rcd->ctxt;
  10040. /*
  10041. * Need to write timeout register before updating RcvHdrHead to ensure
  10042. * that a new value is used when the HW decides to restart counting.
  10043. */
  10044. if (intr_adjust)
  10045. adjust_rcv_timeout(rcd, npkts);
  10046. if (updegr) {
  10047. reg = (egrhd & RCV_EGR_INDEX_HEAD_HEAD_MASK)
  10048. << RCV_EGR_INDEX_HEAD_HEAD_SHIFT;
  10049. write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, reg);
  10050. }
  10051. mmiowb();
  10052. reg = ((u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT) |
  10053. (((u64)hd & RCV_HDR_HEAD_HEAD_MASK)
  10054. << RCV_HDR_HEAD_HEAD_SHIFT);
  10055. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
  10056. mmiowb();
  10057. }
  10058. u32 hdrqempty(struct hfi1_ctxtdata *rcd)
  10059. {
  10060. u32 head, tail;
  10061. head = (read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_HEAD)
  10062. & RCV_HDR_HEAD_HEAD_SMASK) >> RCV_HDR_HEAD_HEAD_SHIFT;
  10063. if (rcd->rcvhdrtail_kvaddr)
  10064. tail = get_rcvhdrtail(rcd);
  10065. else
  10066. tail = read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
  10067. return head == tail;
  10068. }
  10069. /*
  10070. * Context Control and Receive Array encoding for buffer size:
  10071. * 0x0 invalid
  10072. * 0x1 4 KB
  10073. * 0x2 8 KB
  10074. * 0x3 16 KB
  10075. * 0x4 32 KB
  10076. * 0x5 64 KB
  10077. * 0x6 128 KB
  10078. * 0x7 256 KB
  10079. * 0x8 512 KB (Receive Array only)
  10080. * 0x9 1 MB (Receive Array only)
  10081. * 0xa 2 MB (Receive Array only)
  10082. *
  10083. * 0xB-0xF - reserved (Receive Array only)
  10084. *
  10085. *
  10086. * This routine assumes that the value has already been sanity checked.
  10087. */
  10088. static u32 encoded_size(u32 size)
  10089. {
  10090. switch (size) {
  10091. case 4 * 1024: return 0x1;
  10092. case 8 * 1024: return 0x2;
  10093. case 16 * 1024: return 0x3;
  10094. case 32 * 1024: return 0x4;
  10095. case 64 * 1024: return 0x5;
  10096. case 128 * 1024: return 0x6;
  10097. case 256 * 1024: return 0x7;
  10098. case 512 * 1024: return 0x8;
  10099. case 1 * 1024 * 1024: return 0x9;
  10100. case 2 * 1024 * 1024: return 0xa;
  10101. }
  10102. return 0x1; /* if invalid, go with the minimum size */
  10103. }
  10104. void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op, int ctxt)
  10105. {
  10106. struct hfi1_ctxtdata *rcd;
  10107. u64 rcvctrl, reg;
  10108. int did_enable = 0;
  10109. rcd = dd->rcd[ctxt];
  10110. if (!rcd)
  10111. return;
  10112. hfi1_cdbg(RCVCTRL, "ctxt %d op 0x%x", ctxt, op);
  10113. rcvctrl = read_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL);
  10114. /* if the context already enabled, don't do the extra steps */
  10115. if ((op & HFI1_RCVCTRL_CTXT_ENB) &&
  10116. !(rcvctrl & RCV_CTXT_CTRL_ENABLE_SMASK)) {
  10117. /* reset the tail and hdr addresses, and sequence count */
  10118. write_kctxt_csr(dd, ctxt, RCV_HDR_ADDR,
  10119. rcd->rcvhdrq_dma);
  10120. if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL))
  10121. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10122. rcd->rcvhdrqtailaddr_dma);
  10123. rcd->seq_cnt = 1;
  10124. /* reset the cached receive header queue head value */
  10125. rcd->head = 0;
  10126. /*
  10127. * Zero the receive header queue so we don't get false
  10128. * positives when checking the sequence number. The
  10129. * sequence numbers could land exactly on the same spot.
  10130. * E.g. a rcd restart before the receive header wrapped.
  10131. */
  10132. memset(rcd->rcvhdrq, 0, rcd->rcvhdrq_size);
  10133. /* starting timeout */
  10134. rcd->rcvavail_timeout = dd->rcv_intr_timeout_csr;
  10135. /* enable the context */
  10136. rcvctrl |= RCV_CTXT_CTRL_ENABLE_SMASK;
  10137. /* clean the egr buffer size first */
  10138. rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
  10139. rcvctrl |= ((u64)encoded_size(rcd->egrbufs.rcvtid_size)
  10140. & RCV_CTXT_CTRL_EGR_BUF_SIZE_MASK)
  10141. << RCV_CTXT_CTRL_EGR_BUF_SIZE_SHIFT;
  10142. /* zero RcvHdrHead - set RcvHdrHead.Counter after enable */
  10143. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0);
  10144. did_enable = 1;
  10145. /* zero RcvEgrIndexHead */
  10146. write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, 0);
  10147. /* set eager count and base index */
  10148. reg = (((u64)(rcd->egrbufs.alloced >> RCV_SHIFT)
  10149. & RCV_EGR_CTRL_EGR_CNT_MASK)
  10150. << RCV_EGR_CTRL_EGR_CNT_SHIFT) |
  10151. (((rcd->eager_base >> RCV_SHIFT)
  10152. & RCV_EGR_CTRL_EGR_BASE_INDEX_MASK)
  10153. << RCV_EGR_CTRL_EGR_BASE_INDEX_SHIFT);
  10154. write_kctxt_csr(dd, ctxt, RCV_EGR_CTRL, reg);
  10155. /*
  10156. * Set TID (expected) count and base index.
  10157. * rcd->expected_count is set to individual RcvArray entries,
  10158. * not pairs, and the CSR takes a pair-count in groups of
  10159. * four, so divide by 8.
  10160. */
  10161. reg = (((rcd->expected_count >> RCV_SHIFT)
  10162. & RCV_TID_CTRL_TID_PAIR_CNT_MASK)
  10163. << RCV_TID_CTRL_TID_PAIR_CNT_SHIFT) |
  10164. (((rcd->expected_base >> RCV_SHIFT)
  10165. & RCV_TID_CTRL_TID_BASE_INDEX_MASK)
  10166. << RCV_TID_CTRL_TID_BASE_INDEX_SHIFT);
  10167. write_kctxt_csr(dd, ctxt, RCV_TID_CTRL, reg);
  10168. if (ctxt == HFI1_CTRL_CTXT)
  10169. write_csr(dd, RCV_VL15, HFI1_CTRL_CTXT);
  10170. }
  10171. if (op & HFI1_RCVCTRL_CTXT_DIS) {
  10172. write_csr(dd, RCV_VL15, 0);
  10173. /*
  10174. * When receive context is being disabled turn on tail
  10175. * update with a dummy tail address and then disable
  10176. * receive context.
  10177. */
  10178. if (dd->rcvhdrtail_dummy_dma) {
  10179. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10180. dd->rcvhdrtail_dummy_dma);
  10181. /* Enabling RcvCtxtCtrl.TailUpd is intentional. */
  10182. rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10183. }
  10184. rcvctrl &= ~RCV_CTXT_CTRL_ENABLE_SMASK;
  10185. }
  10186. if (op & HFI1_RCVCTRL_INTRAVAIL_ENB)
  10187. rcvctrl |= RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
  10188. if (op & HFI1_RCVCTRL_INTRAVAIL_DIS)
  10189. rcvctrl &= ~RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
  10190. if (op & HFI1_RCVCTRL_TAILUPD_ENB && rcd->rcvhdrqtailaddr_dma)
  10191. rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10192. if (op & HFI1_RCVCTRL_TAILUPD_DIS) {
  10193. /* See comment on RcvCtxtCtrl.TailUpd above */
  10194. if (!(op & HFI1_RCVCTRL_CTXT_DIS))
  10195. rcvctrl &= ~RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10196. }
  10197. if (op & HFI1_RCVCTRL_TIDFLOW_ENB)
  10198. rcvctrl |= RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
  10199. if (op & HFI1_RCVCTRL_TIDFLOW_DIS)
  10200. rcvctrl &= ~RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
  10201. if (op & HFI1_RCVCTRL_ONE_PKT_EGR_ENB) {
  10202. /*
  10203. * In one-packet-per-eager mode, the size comes from
  10204. * the RcvArray entry.
  10205. */
  10206. rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
  10207. rcvctrl |= RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
  10208. }
  10209. if (op & HFI1_RCVCTRL_ONE_PKT_EGR_DIS)
  10210. rcvctrl &= ~RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
  10211. if (op & HFI1_RCVCTRL_NO_RHQ_DROP_ENB)
  10212. rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
  10213. if (op & HFI1_RCVCTRL_NO_RHQ_DROP_DIS)
  10214. rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
  10215. if (op & HFI1_RCVCTRL_NO_EGR_DROP_ENB)
  10216. rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
  10217. if (op & HFI1_RCVCTRL_NO_EGR_DROP_DIS)
  10218. rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
  10219. rcd->rcvctrl = rcvctrl;
  10220. hfi1_cdbg(RCVCTRL, "ctxt %d rcvctrl 0x%llx\n", ctxt, rcvctrl);
  10221. write_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL, rcd->rcvctrl);
  10222. /* work around sticky RcvCtxtStatus.BlockedRHQFull */
  10223. if (did_enable &&
  10224. (rcvctrl & RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK)) {
  10225. reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
  10226. if (reg != 0) {
  10227. dd_dev_info(dd, "ctxt %d status %lld (blocked)\n",
  10228. ctxt, reg);
  10229. read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
  10230. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x10);
  10231. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x00);
  10232. read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
  10233. reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
  10234. dd_dev_info(dd, "ctxt %d status %lld (%s blocked)\n",
  10235. ctxt, reg, reg == 0 ? "not" : "still");
  10236. }
  10237. }
  10238. if (did_enable) {
  10239. /*
  10240. * The interrupt timeout and count must be set after
  10241. * the context is enabled to take effect.
  10242. */
  10243. /* set interrupt timeout */
  10244. write_kctxt_csr(dd, ctxt, RCV_AVAIL_TIME_OUT,
  10245. (u64)rcd->rcvavail_timeout <<
  10246. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
  10247. /* set RcvHdrHead.Counter, zero RcvHdrHead.Head (again) */
  10248. reg = (u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT;
  10249. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
  10250. }
  10251. if (op & (HFI1_RCVCTRL_TAILUPD_DIS | HFI1_RCVCTRL_CTXT_DIS))
  10252. /*
  10253. * If the context has been disabled and the Tail Update has
  10254. * been cleared, set the RCV_HDR_TAIL_ADDR CSR to dummy address
  10255. * so it doesn't contain an address that is invalid.
  10256. */
  10257. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10258. dd->rcvhdrtail_dummy_dma);
  10259. }
  10260. u32 hfi1_read_cntrs(struct hfi1_devdata *dd, char **namep, u64 **cntrp)
  10261. {
  10262. int ret;
  10263. u64 val = 0;
  10264. if (namep) {
  10265. ret = dd->cntrnameslen;
  10266. *namep = dd->cntrnames;
  10267. } else {
  10268. const struct cntr_entry *entry;
  10269. int i, j;
  10270. ret = (dd->ndevcntrs) * sizeof(u64);
  10271. /* Get the start of the block of counters */
  10272. *cntrp = dd->cntrs;
  10273. /*
  10274. * Now go and fill in each counter in the block.
  10275. */
  10276. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10277. entry = &dev_cntrs[i];
  10278. hfi1_cdbg(CNTR, "reading %s", entry->name);
  10279. if (entry->flags & CNTR_DISABLED) {
  10280. /* Nothing */
  10281. hfi1_cdbg(CNTR, "\tDisabled\n");
  10282. } else {
  10283. if (entry->flags & CNTR_VL) {
  10284. hfi1_cdbg(CNTR, "\tPer VL\n");
  10285. for (j = 0; j < C_VL_COUNT; j++) {
  10286. val = entry->rw_cntr(entry,
  10287. dd, j,
  10288. CNTR_MODE_R,
  10289. 0);
  10290. hfi1_cdbg(
  10291. CNTR,
  10292. "\t\tRead 0x%llx for %d\n",
  10293. val, j);
  10294. dd->cntrs[entry->offset + j] =
  10295. val;
  10296. }
  10297. } else if (entry->flags & CNTR_SDMA) {
  10298. hfi1_cdbg(CNTR,
  10299. "\t Per SDMA Engine\n");
  10300. for (j = 0; j < dd->chip_sdma_engines;
  10301. j++) {
  10302. val =
  10303. entry->rw_cntr(entry, dd, j,
  10304. CNTR_MODE_R, 0);
  10305. hfi1_cdbg(CNTR,
  10306. "\t\tRead 0x%llx for %d\n",
  10307. val, j);
  10308. dd->cntrs[entry->offset + j] =
  10309. val;
  10310. }
  10311. } else {
  10312. val = entry->rw_cntr(entry, dd,
  10313. CNTR_INVALID_VL,
  10314. CNTR_MODE_R, 0);
  10315. dd->cntrs[entry->offset] = val;
  10316. hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
  10317. }
  10318. }
  10319. }
  10320. }
  10321. return ret;
  10322. }
  10323. /*
  10324. * Used by sysfs to create files for hfi stats to read
  10325. */
  10326. u32 hfi1_read_portcntrs(struct hfi1_pportdata *ppd, char **namep, u64 **cntrp)
  10327. {
  10328. int ret;
  10329. u64 val = 0;
  10330. if (namep) {
  10331. ret = ppd->dd->portcntrnameslen;
  10332. *namep = ppd->dd->portcntrnames;
  10333. } else {
  10334. const struct cntr_entry *entry;
  10335. int i, j;
  10336. ret = ppd->dd->nportcntrs * sizeof(u64);
  10337. *cntrp = ppd->cntrs;
  10338. for (i = 0; i < PORT_CNTR_LAST; i++) {
  10339. entry = &port_cntrs[i];
  10340. hfi1_cdbg(CNTR, "reading %s", entry->name);
  10341. if (entry->flags & CNTR_DISABLED) {
  10342. /* Nothing */
  10343. hfi1_cdbg(CNTR, "\tDisabled\n");
  10344. continue;
  10345. }
  10346. if (entry->flags & CNTR_VL) {
  10347. hfi1_cdbg(CNTR, "\tPer VL");
  10348. for (j = 0; j < C_VL_COUNT; j++) {
  10349. val = entry->rw_cntr(entry, ppd, j,
  10350. CNTR_MODE_R,
  10351. 0);
  10352. hfi1_cdbg(
  10353. CNTR,
  10354. "\t\tRead 0x%llx for %d",
  10355. val, j);
  10356. ppd->cntrs[entry->offset + j] = val;
  10357. }
  10358. } else {
  10359. val = entry->rw_cntr(entry, ppd,
  10360. CNTR_INVALID_VL,
  10361. CNTR_MODE_R,
  10362. 0);
  10363. ppd->cntrs[entry->offset] = val;
  10364. hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
  10365. }
  10366. }
  10367. }
  10368. return ret;
  10369. }
  10370. static void free_cntrs(struct hfi1_devdata *dd)
  10371. {
  10372. struct hfi1_pportdata *ppd;
  10373. int i;
  10374. if (dd->synth_stats_timer.data)
  10375. del_timer_sync(&dd->synth_stats_timer);
  10376. dd->synth_stats_timer.data = 0;
  10377. ppd = (struct hfi1_pportdata *)(dd + 1);
  10378. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10379. kfree(ppd->cntrs);
  10380. kfree(ppd->scntrs);
  10381. free_percpu(ppd->ibport_data.rvp.rc_acks);
  10382. free_percpu(ppd->ibport_data.rvp.rc_qacks);
  10383. free_percpu(ppd->ibport_data.rvp.rc_delayed_comp);
  10384. ppd->cntrs = NULL;
  10385. ppd->scntrs = NULL;
  10386. ppd->ibport_data.rvp.rc_acks = NULL;
  10387. ppd->ibport_data.rvp.rc_qacks = NULL;
  10388. ppd->ibport_data.rvp.rc_delayed_comp = NULL;
  10389. }
  10390. kfree(dd->portcntrnames);
  10391. dd->portcntrnames = NULL;
  10392. kfree(dd->cntrs);
  10393. dd->cntrs = NULL;
  10394. kfree(dd->scntrs);
  10395. dd->scntrs = NULL;
  10396. kfree(dd->cntrnames);
  10397. dd->cntrnames = NULL;
  10398. }
  10399. static u64 read_dev_port_cntr(struct hfi1_devdata *dd, struct cntr_entry *entry,
  10400. u64 *psval, void *context, int vl)
  10401. {
  10402. u64 val;
  10403. u64 sval = *psval;
  10404. if (entry->flags & CNTR_DISABLED) {
  10405. dd_dev_err(dd, "Counter %s not enabled", entry->name);
  10406. return 0;
  10407. }
  10408. hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
  10409. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_R, 0);
  10410. /* If its a synthetic counter there is more work we need to do */
  10411. if (entry->flags & CNTR_SYNTH) {
  10412. if (sval == CNTR_MAX) {
  10413. /* No need to read already saturated */
  10414. return CNTR_MAX;
  10415. }
  10416. if (entry->flags & CNTR_32BIT) {
  10417. /* 32bit counters can wrap multiple times */
  10418. u64 upper = sval >> 32;
  10419. u64 lower = (sval << 32) >> 32;
  10420. if (lower > val) { /* hw wrapped */
  10421. if (upper == CNTR_32BIT_MAX)
  10422. val = CNTR_MAX;
  10423. else
  10424. upper++;
  10425. }
  10426. if (val != CNTR_MAX)
  10427. val = (upper << 32) | val;
  10428. } else {
  10429. /* If we rolled we are saturated */
  10430. if ((val < sval) || (val > CNTR_MAX))
  10431. val = CNTR_MAX;
  10432. }
  10433. }
  10434. *psval = val;
  10435. hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
  10436. return val;
  10437. }
  10438. static u64 write_dev_port_cntr(struct hfi1_devdata *dd,
  10439. struct cntr_entry *entry,
  10440. u64 *psval, void *context, int vl, u64 data)
  10441. {
  10442. u64 val;
  10443. if (entry->flags & CNTR_DISABLED) {
  10444. dd_dev_err(dd, "Counter %s not enabled", entry->name);
  10445. return 0;
  10446. }
  10447. hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
  10448. if (entry->flags & CNTR_SYNTH) {
  10449. *psval = data;
  10450. if (entry->flags & CNTR_32BIT) {
  10451. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
  10452. (data << 32) >> 32);
  10453. val = data; /* return the full 64bit value */
  10454. } else {
  10455. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
  10456. data);
  10457. }
  10458. } else {
  10459. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W, data);
  10460. }
  10461. *psval = val;
  10462. hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
  10463. return val;
  10464. }
  10465. u64 read_dev_cntr(struct hfi1_devdata *dd, int index, int vl)
  10466. {
  10467. struct cntr_entry *entry;
  10468. u64 *sval;
  10469. entry = &dev_cntrs[index];
  10470. sval = dd->scntrs + entry->offset;
  10471. if (vl != CNTR_INVALID_VL)
  10472. sval += vl;
  10473. return read_dev_port_cntr(dd, entry, sval, dd, vl);
  10474. }
  10475. u64 write_dev_cntr(struct hfi1_devdata *dd, int index, int vl, u64 data)
  10476. {
  10477. struct cntr_entry *entry;
  10478. u64 *sval;
  10479. entry = &dev_cntrs[index];
  10480. sval = dd->scntrs + entry->offset;
  10481. if (vl != CNTR_INVALID_VL)
  10482. sval += vl;
  10483. return write_dev_port_cntr(dd, entry, sval, dd, vl, data);
  10484. }
  10485. u64 read_port_cntr(struct hfi1_pportdata *ppd, int index, int vl)
  10486. {
  10487. struct cntr_entry *entry;
  10488. u64 *sval;
  10489. entry = &port_cntrs[index];
  10490. sval = ppd->scntrs + entry->offset;
  10491. if (vl != CNTR_INVALID_VL)
  10492. sval += vl;
  10493. if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
  10494. (index <= C_RCV_HDR_OVF_LAST)) {
  10495. /* We do not want to bother for disabled contexts */
  10496. return 0;
  10497. }
  10498. return read_dev_port_cntr(ppd->dd, entry, sval, ppd, vl);
  10499. }
  10500. u64 write_port_cntr(struct hfi1_pportdata *ppd, int index, int vl, u64 data)
  10501. {
  10502. struct cntr_entry *entry;
  10503. u64 *sval;
  10504. entry = &port_cntrs[index];
  10505. sval = ppd->scntrs + entry->offset;
  10506. if (vl != CNTR_INVALID_VL)
  10507. sval += vl;
  10508. if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
  10509. (index <= C_RCV_HDR_OVF_LAST)) {
  10510. /* We do not want to bother for disabled contexts */
  10511. return 0;
  10512. }
  10513. return write_dev_port_cntr(ppd->dd, entry, sval, ppd, vl, data);
  10514. }
  10515. static void update_synth_timer(unsigned long opaque)
  10516. {
  10517. u64 cur_tx;
  10518. u64 cur_rx;
  10519. u64 total_flits;
  10520. u8 update = 0;
  10521. int i, j, vl;
  10522. struct hfi1_pportdata *ppd;
  10523. struct cntr_entry *entry;
  10524. struct hfi1_devdata *dd = (struct hfi1_devdata *)opaque;
  10525. /*
  10526. * Rather than keep beating on the CSRs pick a minimal set that we can
  10527. * check to watch for potential roll over. We can do this by looking at
  10528. * the number of flits sent/recv. If the total flits exceeds 32bits then
  10529. * we have to iterate all the counters and update.
  10530. */
  10531. entry = &dev_cntrs[C_DC_RCV_FLITS];
  10532. cur_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
  10533. entry = &dev_cntrs[C_DC_XMIT_FLITS];
  10534. cur_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
  10535. hfi1_cdbg(
  10536. CNTR,
  10537. "[%d] curr tx=0x%llx rx=0x%llx :: last tx=0x%llx rx=0x%llx\n",
  10538. dd->unit, cur_tx, cur_rx, dd->last_tx, dd->last_rx);
  10539. if ((cur_tx < dd->last_tx) || (cur_rx < dd->last_rx)) {
  10540. /*
  10541. * May not be strictly necessary to update but it won't hurt and
  10542. * simplifies the logic here.
  10543. */
  10544. update = 1;
  10545. hfi1_cdbg(CNTR, "[%d] Tripwire counter rolled, updating",
  10546. dd->unit);
  10547. } else {
  10548. total_flits = (cur_tx - dd->last_tx) + (cur_rx - dd->last_rx);
  10549. hfi1_cdbg(CNTR,
  10550. "[%d] total flits 0x%llx limit 0x%llx\n", dd->unit,
  10551. total_flits, (u64)CNTR_32BIT_MAX);
  10552. if (total_flits >= CNTR_32BIT_MAX) {
  10553. hfi1_cdbg(CNTR, "[%d] 32bit limit hit, updating",
  10554. dd->unit);
  10555. update = 1;
  10556. }
  10557. }
  10558. if (update) {
  10559. hfi1_cdbg(CNTR, "[%d] Updating dd and ppd counters", dd->unit);
  10560. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10561. entry = &dev_cntrs[i];
  10562. if (entry->flags & CNTR_VL) {
  10563. for (vl = 0; vl < C_VL_COUNT; vl++)
  10564. read_dev_cntr(dd, i, vl);
  10565. } else {
  10566. read_dev_cntr(dd, i, CNTR_INVALID_VL);
  10567. }
  10568. }
  10569. ppd = (struct hfi1_pportdata *)(dd + 1);
  10570. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10571. for (j = 0; j < PORT_CNTR_LAST; j++) {
  10572. entry = &port_cntrs[j];
  10573. if (entry->flags & CNTR_VL) {
  10574. for (vl = 0; vl < C_VL_COUNT; vl++)
  10575. read_port_cntr(ppd, j, vl);
  10576. } else {
  10577. read_port_cntr(ppd, j, CNTR_INVALID_VL);
  10578. }
  10579. }
  10580. }
  10581. /*
  10582. * We want the value in the register. The goal is to keep track
  10583. * of the number of "ticks" not the counter value. In other
  10584. * words if the register rolls we want to notice it and go ahead
  10585. * and force an update.
  10586. */
  10587. entry = &dev_cntrs[C_DC_XMIT_FLITS];
  10588. dd->last_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
  10589. CNTR_MODE_R, 0);
  10590. entry = &dev_cntrs[C_DC_RCV_FLITS];
  10591. dd->last_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
  10592. CNTR_MODE_R, 0);
  10593. hfi1_cdbg(CNTR, "[%d] setting last tx/rx to 0x%llx 0x%llx",
  10594. dd->unit, dd->last_tx, dd->last_rx);
  10595. } else {
  10596. hfi1_cdbg(CNTR, "[%d] No update necessary", dd->unit);
  10597. }
  10598. mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
  10599. }
  10600. #define C_MAX_NAME 16 /* 15 chars + one for /0 */
  10601. static int init_cntrs(struct hfi1_devdata *dd)
  10602. {
  10603. int i, rcv_ctxts, j;
  10604. size_t sz;
  10605. char *p;
  10606. char name[C_MAX_NAME];
  10607. struct hfi1_pportdata *ppd;
  10608. const char *bit_type_32 = ",32";
  10609. const int bit_type_32_sz = strlen(bit_type_32);
  10610. /* set up the stats timer; the add_timer is done at the end */
  10611. setup_timer(&dd->synth_stats_timer, update_synth_timer,
  10612. (unsigned long)dd);
  10613. /***********************/
  10614. /* per device counters */
  10615. /***********************/
  10616. /* size names and determine how many we have*/
  10617. dd->ndevcntrs = 0;
  10618. sz = 0;
  10619. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10620. if (dev_cntrs[i].flags & CNTR_DISABLED) {
  10621. hfi1_dbg_early("\tSkipping %s\n", dev_cntrs[i].name);
  10622. continue;
  10623. }
  10624. if (dev_cntrs[i].flags & CNTR_VL) {
  10625. dev_cntrs[i].offset = dd->ndevcntrs;
  10626. for (j = 0; j < C_VL_COUNT; j++) {
  10627. snprintf(name, C_MAX_NAME, "%s%d",
  10628. dev_cntrs[i].name, vl_from_idx(j));
  10629. sz += strlen(name);
  10630. /* Add ",32" for 32-bit counters */
  10631. if (dev_cntrs[i].flags & CNTR_32BIT)
  10632. sz += bit_type_32_sz;
  10633. sz++;
  10634. dd->ndevcntrs++;
  10635. }
  10636. } else if (dev_cntrs[i].flags & CNTR_SDMA) {
  10637. dev_cntrs[i].offset = dd->ndevcntrs;
  10638. for (j = 0; j < dd->chip_sdma_engines; j++) {
  10639. snprintf(name, C_MAX_NAME, "%s%d",
  10640. dev_cntrs[i].name, j);
  10641. sz += strlen(name);
  10642. /* Add ",32" for 32-bit counters */
  10643. if (dev_cntrs[i].flags & CNTR_32BIT)
  10644. sz += bit_type_32_sz;
  10645. sz++;
  10646. dd->ndevcntrs++;
  10647. }
  10648. } else {
  10649. /* +1 for newline. */
  10650. sz += strlen(dev_cntrs[i].name) + 1;
  10651. /* Add ",32" for 32-bit counters */
  10652. if (dev_cntrs[i].flags & CNTR_32BIT)
  10653. sz += bit_type_32_sz;
  10654. dev_cntrs[i].offset = dd->ndevcntrs;
  10655. dd->ndevcntrs++;
  10656. }
  10657. }
  10658. /* allocate space for the counter values */
  10659. dd->cntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
  10660. if (!dd->cntrs)
  10661. goto bail;
  10662. dd->scntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
  10663. if (!dd->scntrs)
  10664. goto bail;
  10665. /* allocate space for the counter names */
  10666. dd->cntrnameslen = sz;
  10667. dd->cntrnames = kmalloc(sz, GFP_KERNEL);
  10668. if (!dd->cntrnames)
  10669. goto bail;
  10670. /* fill in the names */
  10671. for (p = dd->cntrnames, i = 0; i < DEV_CNTR_LAST; i++) {
  10672. if (dev_cntrs[i].flags & CNTR_DISABLED) {
  10673. /* Nothing */
  10674. } else if (dev_cntrs[i].flags & CNTR_VL) {
  10675. for (j = 0; j < C_VL_COUNT; j++) {
  10676. snprintf(name, C_MAX_NAME, "%s%d",
  10677. dev_cntrs[i].name,
  10678. vl_from_idx(j));
  10679. memcpy(p, name, strlen(name));
  10680. p += strlen(name);
  10681. /* Counter is 32 bits */
  10682. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10683. memcpy(p, bit_type_32, bit_type_32_sz);
  10684. p += bit_type_32_sz;
  10685. }
  10686. *p++ = '\n';
  10687. }
  10688. } else if (dev_cntrs[i].flags & CNTR_SDMA) {
  10689. for (j = 0; j < dd->chip_sdma_engines; j++) {
  10690. snprintf(name, C_MAX_NAME, "%s%d",
  10691. dev_cntrs[i].name, j);
  10692. memcpy(p, name, strlen(name));
  10693. p += strlen(name);
  10694. /* Counter is 32 bits */
  10695. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10696. memcpy(p, bit_type_32, bit_type_32_sz);
  10697. p += bit_type_32_sz;
  10698. }
  10699. *p++ = '\n';
  10700. }
  10701. } else {
  10702. memcpy(p, dev_cntrs[i].name, strlen(dev_cntrs[i].name));
  10703. p += strlen(dev_cntrs[i].name);
  10704. /* Counter is 32 bits */
  10705. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10706. memcpy(p, bit_type_32, bit_type_32_sz);
  10707. p += bit_type_32_sz;
  10708. }
  10709. *p++ = '\n';
  10710. }
  10711. }
  10712. /*********************/
  10713. /* per port counters */
  10714. /*********************/
  10715. /*
  10716. * Go through the counters for the overflows and disable the ones we
  10717. * don't need. This varies based on platform so we need to do it
  10718. * dynamically here.
  10719. */
  10720. rcv_ctxts = dd->num_rcv_contexts;
  10721. for (i = C_RCV_HDR_OVF_FIRST + rcv_ctxts;
  10722. i <= C_RCV_HDR_OVF_LAST; i++) {
  10723. port_cntrs[i].flags |= CNTR_DISABLED;
  10724. }
  10725. /* size port counter names and determine how many we have*/
  10726. sz = 0;
  10727. dd->nportcntrs = 0;
  10728. for (i = 0; i < PORT_CNTR_LAST; i++) {
  10729. if (port_cntrs[i].flags & CNTR_DISABLED) {
  10730. hfi1_dbg_early("\tSkipping %s\n", port_cntrs[i].name);
  10731. continue;
  10732. }
  10733. if (port_cntrs[i].flags & CNTR_VL) {
  10734. port_cntrs[i].offset = dd->nportcntrs;
  10735. for (j = 0; j < C_VL_COUNT; j++) {
  10736. snprintf(name, C_MAX_NAME, "%s%d",
  10737. port_cntrs[i].name, vl_from_idx(j));
  10738. sz += strlen(name);
  10739. /* Add ",32" for 32-bit counters */
  10740. if (port_cntrs[i].flags & CNTR_32BIT)
  10741. sz += bit_type_32_sz;
  10742. sz++;
  10743. dd->nportcntrs++;
  10744. }
  10745. } else {
  10746. /* +1 for newline */
  10747. sz += strlen(port_cntrs[i].name) + 1;
  10748. /* Add ",32" for 32-bit counters */
  10749. if (port_cntrs[i].flags & CNTR_32BIT)
  10750. sz += bit_type_32_sz;
  10751. port_cntrs[i].offset = dd->nportcntrs;
  10752. dd->nportcntrs++;
  10753. }
  10754. }
  10755. /* allocate space for the counter names */
  10756. dd->portcntrnameslen = sz;
  10757. dd->portcntrnames = kmalloc(sz, GFP_KERNEL);
  10758. if (!dd->portcntrnames)
  10759. goto bail;
  10760. /* fill in port cntr names */
  10761. for (p = dd->portcntrnames, i = 0; i < PORT_CNTR_LAST; i++) {
  10762. if (port_cntrs[i].flags & CNTR_DISABLED)
  10763. continue;
  10764. if (port_cntrs[i].flags & CNTR_VL) {
  10765. for (j = 0; j < C_VL_COUNT; j++) {
  10766. snprintf(name, C_MAX_NAME, "%s%d",
  10767. port_cntrs[i].name, vl_from_idx(j));
  10768. memcpy(p, name, strlen(name));
  10769. p += strlen(name);
  10770. /* Counter is 32 bits */
  10771. if (port_cntrs[i].flags & CNTR_32BIT) {
  10772. memcpy(p, bit_type_32, bit_type_32_sz);
  10773. p += bit_type_32_sz;
  10774. }
  10775. *p++ = '\n';
  10776. }
  10777. } else {
  10778. memcpy(p, port_cntrs[i].name,
  10779. strlen(port_cntrs[i].name));
  10780. p += strlen(port_cntrs[i].name);
  10781. /* Counter is 32 bits */
  10782. if (port_cntrs[i].flags & CNTR_32BIT) {
  10783. memcpy(p, bit_type_32, bit_type_32_sz);
  10784. p += bit_type_32_sz;
  10785. }
  10786. *p++ = '\n';
  10787. }
  10788. }
  10789. /* allocate per port storage for counter values */
  10790. ppd = (struct hfi1_pportdata *)(dd + 1);
  10791. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10792. ppd->cntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
  10793. if (!ppd->cntrs)
  10794. goto bail;
  10795. ppd->scntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
  10796. if (!ppd->scntrs)
  10797. goto bail;
  10798. }
  10799. /* CPU counters need to be allocated and zeroed */
  10800. if (init_cpu_counters(dd))
  10801. goto bail;
  10802. mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
  10803. return 0;
  10804. bail:
  10805. free_cntrs(dd);
  10806. return -ENOMEM;
  10807. }
  10808. static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate)
  10809. {
  10810. switch (chip_lstate) {
  10811. default:
  10812. dd_dev_err(dd,
  10813. "Unknown logical state 0x%x, reporting IB_PORT_DOWN\n",
  10814. chip_lstate);
  10815. /* fall through */
  10816. case LSTATE_DOWN:
  10817. return IB_PORT_DOWN;
  10818. case LSTATE_INIT:
  10819. return IB_PORT_INIT;
  10820. case LSTATE_ARMED:
  10821. return IB_PORT_ARMED;
  10822. case LSTATE_ACTIVE:
  10823. return IB_PORT_ACTIVE;
  10824. }
  10825. }
  10826. u32 chip_to_opa_pstate(struct hfi1_devdata *dd, u32 chip_pstate)
  10827. {
  10828. /* look at the HFI meta-states only */
  10829. switch (chip_pstate & 0xf0) {
  10830. default:
  10831. dd_dev_err(dd, "Unexpected chip physical state of 0x%x\n",
  10832. chip_pstate);
  10833. /* fall through */
  10834. case PLS_DISABLED:
  10835. return IB_PORTPHYSSTATE_DISABLED;
  10836. case PLS_OFFLINE:
  10837. return OPA_PORTPHYSSTATE_OFFLINE;
  10838. case PLS_POLLING:
  10839. return IB_PORTPHYSSTATE_POLLING;
  10840. case PLS_CONFIGPHY:
  10841. return IB_PORTPHYSSTATE_TRAINING;
  10842. case PLS_LINKUP:
  10843. return IB_PORTPHYSSTATE_LINKUP;
  10844. case PLS_PHYTEST:
  10845. return IB_PORTPHYSSTATE_PHY_TEST;
  10846. }
  10847. }
  10848. /* return the OPA port logical state name */
  10849. const char *opa_lstate_name(u32 lstate)
  10850. {
  10851. static const char * const port_logical_names[] = {
  10852. "PORT_NOP",
  10853. "PORT_DOWN",
  10854. "PORT_INIT",
  10855. "PORT_ARMED",
  10856. "PORT_ACTIVE",
  10857. "PORT_ACTIVE_DEFER",
  10858. };
  10859. if (lstate < ARRAY_SIZE(port_logical_names))
  10860. return port_logical_names[lstate];
  10861. return "unknown";
  10862. }
  10863. /* return the OPA port physical state name */
  10864. const char *opa_pstate_name(u32 pstate)
  10865. {
  10866. static const char * const port_physical_names[] = {
  10867. "PHYS_NOP",
  10868. "reserved1",
  10869. "PHYS_POLL",
  10870. "PHYS_DISABLED",
  10871. "PHYS_TRAINING",
  10872. "PHYS_LINKUP",
  10873. "PHYS_LINK_ERR_RECOVER",
  10874. "PHYS_PHY_TEST",
  10875. "reserved8",
  10876. "PHYS_OFFLINE",
  10877. "PHYS_GANGED",
  10878. "PHYS_TEST",
  10879. };
  10880. if (pstate < ARRAY_SIZE(port_physical_names))
  10881. return port_physical_names[pstate];
  10882. return "unknown";
  10883. }
  10884. /*
  10885. * Read the hardware link state and set the driver's cached value of it.
  10886. * Return the (new) current value.
  10887. */
  10888. u32 get_logical_state(struct hfi1_pportdata *ppd)
  10889. {
  10890. u32 new_state;
  10891. new_state = chip_to_opa_lstate(ppd->dd, read_logical_state(ppd->dd));
  10892. if (new_state != ppd->lstate) {
  10893. dd_dev_info(ppd->dd, "logical state changed to %s (0x%x)\n",
  10894. opa_lstate_name(new_state), new_state);
  10895. ppd->lstate = new_state;
  10896. }
  10897. /*
  10898. * Set port status flags in the page mapped into userspace
  10899. * memory. Do it here to ensure a reliable state - this is
  10900. * the only function called by all state handling code.
  10901. * Always set the flags due to the fact that the cache value
  10902. * might have been changed explicitly outside of this
  10903. * function.
  10904. */
  10905. if (ppd->statusp) {
  10906. switch (ppd->lstate) {
  10907. case IB_PORT_DOWN:
  10908. case IB_PORT_INIT:
  10909. *ppd->statusp &= ~(HFI1_STATUS_IB_CONF |
  10910. HFI1_STATUS_IB_READY);
  10911. break;
  10912. case IB_PORT_ARMED:
  10913. *ppd->statusp |= HFI1_STATUS_IB_CONF;
  10914. break;
  10915. case IB_PORT_ACTIVE:
  10916. *ppd->statusp |= HFI1_STATUS_IB_READY;
  10917. break;
  10918. }
  10919. }
  10920. return ppd->lstate;
  10921. }
  10922. /**
  10923. * wait_logical_linkstate - wait for an IB link state change to occur
  10924. * @ppd: port device
  10925. * @state: the state to wait for
  10926. * @msecs: the number of milliseconds to wait
  10927. *
  10928. * Wait up to msecs milliseconds for IB link state change to occur.
  10929. * For now, take the easy polling route.
  10930. * Returns 0 if state reached, otherwise -ETIMEDOUT.
  10931. */
  10932. static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  10933. int msecs)
  10934. {
  10935. unsigned long timeout;
  10936. timeout = jiffies + msecs_to_jiffies(msecs);
  10937. while (1) {
  10938. if (get_logical_state(ppd) == state)
  10939. return 0;
  10940. if (time_after(jiffies, timeout))
  10941. break;
  10942. msleep(20);
  10943. }
  10944. dd_dev_err(ppd->dd, "timeout waiting for link state 0x%x\n", state);
  10945. return -ETIMEDOUT;
  10946. }
  10947. u8 hfi1_ibphys_portstate(struct hfi1_pportdata *ppd)
  10948. {
  10949. u32 pstate;
  10950. u32 ib_pstate;
  10951. pstate = read_physical_state(ppd->dd);
  10952. ib_pstate = chip_to_opa_pstate(ppd->dd, pstate);
  10953. if (ppd->last_pstate != ib_pstate) {
  10954. dd_dev_info(ppd->dd,
  10955. "%s: physical state changed to %s (0x%x), phy 0x%x\n",
  10956. __func__, opa_pstate_name(ib_pstate), ib_pstate,
  10957. pstate);
  10958. ppd->last_pstate = ib_pstate;
  10959. }
  10960. return ib_pstate;
  10961. }
  10962. #define CLEAR_STATIC_RATE_CONTROL_SMASK(r) \
  10963. (r &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
  10964. #define SET_STATIC_RATE_CONTROL_SMASK(r) \
  10965. (r |= SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
  10966. int hfi1_init_ctxt(struct send_context *sc)
  10967. {
  10968. if (sc) {
  10969. struct hfi1_devdata *dd = sc->dd;
  10970. u64 reg;
  10971. u8 set = (sc->type == SC_USER ?
  10972. HFI1_CAP_IS_USET(STATIC_RATE_CTRL) :
  10973. HFI1_CAP_IS_KSET(STATIC_RATE_CTRL));
  10974. reg = read_kctxt_csr(dd, sc->hw_context,
  10975. SEND_CTXT_CHECK_ENABLE);
  10976. if (set)
  10977. CLEAR_STATIC_RATE_CONTROL_SMASK(reg);
  10978. else
  10979. SET_STATIC_RATE_CONTROL_SMASK(reg);
  10980. write_kctxt_csr(dd, sc->hw_context,
  10981. SEND_CTXT_CHECK_ENABLE, reg);
  10982. }
  10983. return 0;
  10984. }
  10985. int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp)
  10986. {
  10987. int ret = 0;
  10988. u64 reg;
  10989. if (dd->icode != ICODE_RTL_SILICON) {
  10990. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  10991. dd_dev_info(dd, "%s: tempsense not supported by HW\n",
  10992. __func__);
  10993. return -EINVAL;
  10994. }
  10995. reg = read_csr(dd, ASIC_STS_THERM);
  10996. temp->curr = ((reg >> ASIC_STS_THERM_CURR_TEMP_SHIFT) &
  10997. ASIC_STS_THERM_CURR_TEMP_MASK);
  10998. temp->lo_lim = ((reg >> ASIC_STS_THERM_LO_TEMP_SHIFT) &
  10999. ASIC_STS_THERM_LO_TEMP_MASK);
  11000. temp->hi_lim = ((reg >> ASIC_STS_THERM_HI_TEMP_SHIFT) &
  11001. ASIC_STS_THERM_HI_TEMP_MASK);
  11002. temp->crit_lim = ((reg >> ASIC_STS_THERM_CRIT_TEMP_SHIFT) &
  11003. ASIC_STS_THERM_CRIT_TEMP_MASK);
  11004. /* triggers is a 3-bit value - 1 bit per trigger. */
  11005. temp->triggers = (u8)((reg >> ASIC_STS_THERM_LOW_SHIFT) & 0x7);
  11006. return ret;
  11007. }
  11008. /* ========================================================================= */
  11009. /*
  11010. * Enable/disable chip from delivering interrupts.
  11011. */
  11012. void set_intr_state(struct hfi1_devdata *dd, u32 enable)
  11013. {
  11014. int i;
  11015. /*
  11016. * In HFI, the mask needs to be 1 to allow interrupts.
  11017. */
  11018. if (enable) {
  11019. /* enable all interrupts */
  11020. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11021. write_csr(dd, CCE_INT_MASK + (8 * i), ~(u64)0);
  11022. init_qsfp_int(dd);
  11023. } else {
  11024. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11025. write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
  11026. }
  11027. }
  11028. /*
  11029. * Clear all interrupt sources on the chip.
  11030. */
  11031. static void clear_all_interrupts(struct hfi1_devdata *dd)
  11032. {
  11033. int i;
  11034. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11035. write_csr(dd, CCE_INT_CLEAR + (8 * i), ~(u64)0);
  11036. write_csr(dd, CCE_ERR_CLEAR, ~(u64)0);
  11037. write_csr(dd, MISC_ERR_CLEAR, ~(u64)0);
  11038. write_csr(dd, RCV_ERR_CLEAR, ~(u64)0);
  11039. write_csr(dd, SEND_ERR_CLEAR, ~(u64)0);
  11040. write_csr(dd, SEND_PIO_ERR_CLEAR, ~(u64)0);
  11041. write_csr(dd, SEND_DMA_ERR_CLEAR, ~(u64)0);
  11042. write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~(u64)0);
  11043. for (i = 0; i < dd->chip_send_contexts; i++)
  11044. write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~(u64)0);
  11045. for (i = 0; i < dd->chip_sdma_engines; i++)
  11046. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~(u64)0);
  11047. write_csr(dd, DCC_ERR_FLG_CLR, ~(u64)0);
  11048. write_csr(dd, DC_LCB_ERR_CLR, ~(u64)0);
  11049. write_csr(dd, DC_DC8051_ERR_CLR, ~(u64)0);
  11050. }
  11051. /* Move to pcie.c? */
  11052. static void disable_intx(struct pci_dev *pdev)
  11053. {
  11054. pci_intx(pdev, 0);
  11055. }
  11056. static void clean_up_interrupts(struct hfi1_devdata *dd)
  11057. {
  11058. int i;
  11059. /* remove irqs - must happen before disabling/turning off */
  11060. if (dd->num_msix_entries) {
  11061. /* MSI-X */
  11062. struct hfi1_msix_entry *me = dd->msix_entries;
  11063. for (i = 0; i < dd->num_msix_entries; i++, me++) {
  11064. if (!me->arg) /* => no irq, no affinity */
  11065. continue;
  11066. hfi1_put_irq_affinity(dd, &dd->msix_entries[i]);
  11067. free_irq(me->msix.vector, me->arg);
  11068. }
  11069. } else {
  11070. /* INTx */
  11071. if (dd->requested_intx_irq) {
  11072. free_irq(dd->pcidev->irq, dd);
  11073. dd->requested_intx_irq = 0;
  11074. }
  11075. }
  11076. /* turn off interrupts */
  11077. if (dd->num_msix_entries) {
  11078. /* MSI-X */
  11079. pci_disable_msix(dd->pcidev);
  11080. } else {
  11081. /* INTx */
  11082. disable_intx(dd->pcidev);
  11083. }
  11084. /* clean structures */
  11085. kfree(dd->msix_entries);
  11086. dd->msix_entries = NULL;
  11087. dd->num_msix_entries = 0;
  11088. }
  11089. /*
  11090. * Remap the interrupt source from the general handler to the given MSI-X
  11091. * interrupt.
  11092. */
  11093. static void remap_intr(struct hfi1_devdata *dd, int isrc, int msix_intr)
  11094. {
  11095. u64 reg;
  11096. int m, n;
  11097. /* clear from the handled mask of the general interrupt */
  11098. m = isrc / 64;
  11099. n = isrc % 64;
  11100. dd->gi_mask[m] &= ~((u64)1 << n);
  11101. /* direct the chip source to the given MSI-X interrupt */
  11102. m = isrc / 8;
  11103. n = isrc % 8;
  11104. reg = read_csr(dd, CCE_INT_MAP + (8 * m));
  11105. reg &= ~((u64)0xff << (8 * n));
  11106. reg |= ((u64)msix_intr & 0xff) << (8 * n);
  11107. write_csr(dd, CCE_INT_MAP + (8 * m), reg);
  11108. }
  11109. static void remap_sdma_interrupts(struct hfi1_devdata *dd,
  11110. int engine, int msix_intr)
  11111. {
  11112. /*
  11113. * SDMA engine interrupt sources grouped by type, rather than
  11114. * engine. Per-engine interrupts are as follows:
  11115. * SDMA
  11116. * SDMAProgress
  11117. * SDMAIdle
  11118. */
  11119. remap_intr(dd, IS_SDMA_START + 0 * TXE_NUM_SDMA_ENGINES + engine,
  11120. msix_intr);
  11121. remap_intr(dd, IS_SDMA_START + 1 * TXE_NUM_SDMA_ENGINES + engine,
  11122. msix_intr);
  11123. remap_intr(dd, IS_SDMA_START + 2 * TXE_NUM_SDMA_ENGINES + engine,
  11124. msix_intr);
  11125. }
  11126. static int request_intx_irq(struct hfi1_devdata *dd)
  11127. {
  11128. int ret;
  11129. snprintf(dd->intx_name, sizeof(dd->intx_name), DRIVER_NAME "_%d",
  11130. dd->unit);
  11131. ret = request_irq(dd->pcidev->irq, general_interrupt,
  11132. IRQF_SHARED, dd->intx_name, dd);
  11133. if (ret)
  11134. dd_dev_err(dd, "unable to request INTx interrupt, err %d\n",
  11135. ret);
  11136. else
  11137. dd->requested_intx_irq = 1;
  11138. return ret;
  11139. }
  11140. static int request_msix_irqs(struct hfi1_devdata *dd)
  11141. {
  11142. int first_general, last_general;
  11143. int first_sdma, last_sdma;
  11144. int first_rx, last_rx;
  11145. int i, ret = 0;
  11146. /* calculate the ranges we are going to use */
  11147. first_general = 0;
  11148. last_general = first_general + 1;
  11149. first_sdma = last_general;
  11150. last_sdma = first_sdma + dd->num_sdma;
  11151. first_rx = last_sdma;
  11152. last_rx = first_rx + dd->n_krcv_queues;
  11153. /*
  11154. * Sanity check - the code expects all SDMA chip source
  11155. * interrupts to be in the same CSR, starting at bit 0. Verify
  11156. * that this is true by checking the bit location of the start.
  11157. */
  11158. BUILD_BUG_ON(IS_SDMA_START % 64);
  11159. for (i = 0; i < dd->num_msix_entries; i++) {
  11160. struct hfi1_msix_entry *me = &dd->msix_entries[i];
  11161. const char *err_info;
  11162. irq_handler_t handler;
  11163. irq_handler_t thread = NULL;
  11164. void *arg;
  11165. int idx;
  11166. struct hfi1_ctxtdata *rcd = NULL;
  11167. struct sdma_engine *sde = NULL;
  11168. /* obtain the arguments to request_irq */
  11169. if (first_general <= i && i < last_general) {
  11170. idx = i - first_general;
  11171. handler = general_interrupt;
  11172. arg = dd;
  11173. snprintf(me->name, sizeof(me->name),
  11174. DRIVER_NAME "_%d", dd->unit);
  11175. err_info = "general";
  11176. me->type = IRQ_GENERAL;
  11177. } else if (first_sdma <= i && i < last_sdma) {
  11178. idx = i - first_sdma;
  11179. sde = &dd->per_sdma[idx];
  11180. handler = sdma_interrupt;
  11181. arg = sde;
  11182. snprintf(me->name, sizeof(me->name),
  11183. DRIVER_NAME "_%d sdma%d", dd->unit, idx);
  11184. err_info = "sdma";
  11185. remap_sdma_interrupts(dd, idx, i);
  11186. me->type = IRQ_SDMA;
  11187. } else if (first_rx <= i && i < last_rx) {
  11188. idx = i - first_rx;
  11189. rcd = dd->rcd[idx];
  11190. /* no interrupt if no rcd */
  11191. if (!rcd)
  11192. continue;
  11193. /*
  11194. * Set the interrupt register and mask for this
  11195. * context's interrupt.
  11196. */
  11197. rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
  11198. rcd->imask = ((u64)1) <<
  11199. ((IS_RCVAVAIL_START + idx) % 64);
  11200. handler = receive_context_interrupt;
  11201. thread = receive_context_thread;
  11202. arg = rcd;
  11203. snprintf(me->name, sizeof(me->name),
  11204. DRIVER_NAME "_%d kctxt%d", dd->unit, idx);
  11205. err_info = "receive context";
  11206. remap_intr(dd, IS_RCVAVAIL_START + idx, i);
  11207. me->type = IRQ_RCVCTXT;
  11208. } else {
  11209. /* not in our expected range - complain, then
  11210. * ignore it
  11211. */
  11212. dd_dev_err(dd,
  11213. "Unexpected extra MSI-X interrupt %d\n", i);
  11214. continue;
  11215. }
  11216. /* no argument, no interrupt */
  11217. if (!arg)
  11218. continue;
  11219. /* make sure the name is terminated */
  11220. me->name[sizeof(me->name) - 1] = 0;
  11221. ret = request_threaded_irq(me->msix.vector, handler, thread, 0,
  11222. me->name, arg);
  11223. if (ret) {
  11224. dd_dev_err(dd,
  11225. "unable to allocate %s interrupt, vector %d, index %d, err %d\n",
  11226. err_info, me->msix.vector, idx, ret);
  11227. return ret;
  11228. }
  11229. /*
  11230. * assign arg after request_irq call, so it will be
  11231. * cleaned up
  11232. */
  11233. me->arg = arg;
  11234. ret = hfi1_get_irq_affinity(dd, me);
  11235. if (ret)
  11236. dd_dev_err(dd,
  11237. "unable to pin IRQ %d\n", ret);
  11238. }
  11239. return ret;
  11240. }
  11241. /*
  11242. * Set the general handler to accept all interrupts, remap all
  11243. * chip interrupts back to MSI-X 0.
  11244. */
  11245. static void reset_interrupts(struct hfi1_devdata *dd)
  11246. {
  11247. int i;
  11248. /* all interrupts handled by the general handler */
  11249. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11250. dd->gi_mask[i] = ~(u64)0;
  11251. /* all chip interrupts map to MSI-X 0 */
  11252. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11253. write_csr(dd, CCE_INT_MAP + (8 * i), 0);
  11254. }
  11255. static int set_up_interrupts(struct hfi1_devdata *dd)
  11256. {
  11257. struct hfi1_msix_entry *entries;
  11258. u32 total, request;
  11259. int i, ret;
  11260. int single_interrupt = 0; /* we expect to have all the interrupts */
  11261. /*
  11262. * Interrupt count:
  11263. * 1 general, "slow path" interrupt (includes the SDMA engines
  11264. * slow source, SDMACleanupDone)
  11265. * N interrupts - one per used SDMA engine
  11266. * M interrupt - one per kernel receive context
  11267. */
  11268. total = 1 + dd->num_sdma + dd->n_krcv_queues;
  11269. entries = kcalloc(total, sizeof(*entries), GFP_KERNEL);
  11270. if (!entries) {
  11271. ret = -ENOMEM;
  11272. goto fail;
  11273. }
  11274. /* 1-1 MSI-X entry assignment */
  11275. for (i = 0; i < total; i++)
  11276. entries[i].msix.entry = i;
  11277. /* ask for MSI-X interrupts */
  11278. request = total;
  11279. request_msix(dd, &request, entries);
  11280. if (request == 0) {
  11281. /* using INTx */
  11282. /* dd->num_msix_entries already zero */
  11283. kfree(entries);
  11284. single_interrupt = 1;
  11285. dd_dev_err(dd, "MSI-X failed, using INTx interrupts\n");
  11286. } else {
  11287. /* using MSI-X */
  11288. dd->num_msix_entries = request;
  11289. dd->msix_entries = entries;
  11290. if (request != total) {
  11291. /* using MSI-X, with reduced interrupts */
  11292. dd_dev_err(
  11293. dd,
  11294. "cannot handle reduced interrupt case, want %u, got %u\n",
  11295. total, request);
  11296. ret = -EINVAL;
  11297. goto fail;
  11298. }
  11299. dd_dev_info(dd, "%u MSI-X interrupts allocated\n", total);
  11300. }
  11301. /* mask all interrupts */
  11302. set_intr_state(dd, 0);
  11303. /* clear all pending interrupts */
  11304. clear_all_interrupts(dd);
  11305. /* reset general handler mask, chip MSI-X mappings */
  11306. reset_interrupts(dd);
  11307. if (single_interrupt)
  11308. ret = request_intx_irq(dd);
  11309. else
  11310. ret = request_msix_irqs(dd);
  11311. if (ret)
  11312. goto fail;
  11313. return 0;
  11314. fail:
  11315. clean_up_interrupts(dd);
  11316. return ret;
  11317. }
  11318. /*
  11319. * Set up context values in dd. Sets:
  11320. *
  11321. * num_rcv_contexts - number of contexts being used
  11322. * n_krcv_queues - number of kernel contexts
  11323. * first_user_ctxt - first non-kernel context in array of contexts
  11324. * freectxts - number of free user contexts
  11325. * num_send_contexts - number of PIO send contexts being used
  11326. */
  11327. static int set_up_context_variables(struct hfi1_devdata *dd)
  11328. {
  11329. unsigned long num_kernel_contexts;
  11330. int total_contexts;
  11331. int ret;
  11332. unsigned ngroups;
  11333. int qos_rmt_count;
  11334. int user_rmt_reduced;
  11335. /*
  11336. * Kernel receive contexts:
  11337. * - Context 0 - control context (VL15/multicast/error)
  11338. * - Context 1 - first kernel context
  11339. * - Context 2 - second kernel context
  11340. * ...
  11341. */
  11342. if (n_krcvqs)
  11343. /*
  11344. * n_krcvqs is the sum of module parameter kernel receive
  11345. * contexts, krcvqs[]. It does not include the control
  11346. * context, so add that.
  11347. */
  11348. num_kernel_contexts = n_krcvqs + 1;
  11349. else
  11350. num_kernel_contexts = DEFAULT_KRCVQS + 1;
  11351. /*
  11352. * Every kernel receive context needs an ACK send context.
  11353. * one send context is allocated for each VL{0-7} and VL15
  11354. */
  11355. if (num_kernel_contexts > (dd->chip_send_contexts - num_vls - 1)) {
  11356. dd_dev_err(dd,
  11357. "Reducing # kernel rcv contexts to: %d, from %lu\n",
  11358. (int)(dd->chip_send_contexts - num_vls - 1),
  11359. num_kernel_contexts);
  11360. num_kernel_contexts = dd->chip_send_contexts - num_vls - 1;
  11361. }
  11362. /*
  11363. * User contexts:
  11364. * - default to 1 user context per real (non-HT) CPU core if
  11365. * num_user_contexts is negative
  11366. */
  11367. if (num_user_contexts < 0)
  11368. num_user_contexts =
  11369. cpumask_weight(&node_affinity.real_cpu_mask);
  11370. total_contexts = num_kernel_contexts + num_user_contexts;
  11371. /*
  11372. * Adjust the counts given a global max.
  11373. */
  11374. if (total_contexts > dd->chip_rcv_contexts) {
  11375. dd_dev_err(dd,
  11376. "Reducing # user receive contexts to: %d, from %d\n",
  11377. (int)(dd->chip_rcv_contexts - num_kernel_contexts),
  11378. (int)num_user_contexts);
  11379. num_user_contexts = dd->chip_rcv_contexts - num_kernel_contexts;
  11380. /* recalculate */
  11381. total_contexts = num_kernel_contexts + num_user_contexts;
  11382. }
  11383. /* each user context requires an entry in the RMT */
  11384. qos_rmt_count = qos_rmt_entries(dd, NULL, NULL);
  11385. if (qos_rmt_count + num_user_contexts > NUM_MAP_ENTRIES) {
  11386. user_rmt_reduced = NUM_MAP_ENTRIES - qos_rmt_count;
  11387. dd_dev_err(dd,
  11388. "RMT size is reducing the number of user receive contexts from %d to %d\n",
  11389. (int)num_user_contexts,
  11390. user_rmt_reduced);
  11391. /* recalculate */
  11392. num_user_contexts = user_rmt_reduced;
  11393. total_contexts = num_kernel_contexts + num_user_contexts;
  11394. }
  11395. /* the first N are kernel contexts, the rest are user contexts */
  11396. dd->num_rcv_contexts = total_contexts;
  11397. dd->n_krcv_queues = num_kernel_contexts;
  11398. dd->first_user_ctxt = num_kernel_contexts;
  11399. dd->num_user_contexts = num_user_contexts;
  11400. dd->freectxts = num_user_contexts;
  11401. dd_dev_info(dd,
  11402. "rcv contexts: chip %d, used %d (kernel %d, user %d)\n",
  11403. (int)dd->chip_rcv_contexts,
  11404. (int)dd->num_rcv_contexts,
  11405. (int)dd->n_krcv_queues,
  11406. (int)dd->num_rcv_contexts - dd->n_krcv_queues);
  11407. /*
  11408. * Receive array allocation:
  11409. * All RcvArray entries are divided into groups of 8. This
  11410. * is required by the hardware and will speed up writes to
  11411. * consecutive entries by using write-combining of the entire
  11412. * cacheline.
  11413. *
  11414. * The number of groups are evenly divided among all contexts.
  11415. * any left over groups will be given to the first N user
  11416. * contexts.
  11417. */
  11418. dd->rcv_entries.group_size = RCV_INCREMENT;
  11419. ngroups = dd->chip_rcv_array_count / dd->rcv_entries.group_size;
  11420. dd->rcv_entries.ngroups = ngroups / dd->num_rcv_contexts;
  11421. dd->rcv_entries.nctxt_extra = ngroups -
  11422. (dd->num_rcv_contexts * dd->rcv_entries.ngroups);
  11423. dd_dev_info(dd, "RcvArray groups %u, ctxts extra %u\n",
  11424. dd->rcv_entries.ngroups,
  11425. dd->rcv_entries.nctxt_extra);
  11426. if (dd->rcv_entries.ngroups * dd->rcv_entries.group_size >
  11427. MAX_EAGER_ENTRIES * 2) {
  11428. dd->rcv_entries.ngroups = (MAX_EAGER_ENTRIES * 2) /
  11429. dd->rcv_entries.group_size;
  11430. dd_dev_info(dd,
  11431. "RcvArray group count too high, change to %u\n",
  11432. dd->rcv_entries.ngroups);
  11433. dd->rcv_entries.nctxt_extra = 0;
  11434. }
  11435. /*
  11436. * PIO send contexts
  11437. */
  11438. ret = init_sc_pools_and_sizes(dd);
  11439. if (ret >= 0) { /* success */
  11440. dd->num_send_contexts = ret;
  11441. dd_dev_info(
  11442. dd,
  11443. "send contexts: chip %d, used %d (kernel %d, ack %d, user %d, vl15 %d)\n",
  11444. dd->chip_send_contexts,
  11445. dd->num_send_contexts,
  11446. dd->sc_sizes[SC_KERNEL].count,
  11447. dd->sc_sizes[SC_ACK].count,
  11448. dd->sc_sizes[SC_USER].count,
  11449. dd->sc_sizes[SC_VL15].count);
  11450. ret = 0; /* success */
  11451. }
  11452. return ret;
  11453. }
  11454. /*
  11455. * Set the device/port partition key table. The MAD code
  11456. * will ensure that, at least, the partial management
  11457. * partition key is present in the table.
  11458. */
  11459. static void set_partition_keys(struct hfi1_pportdata *ppd)
  11460. {
  11461. struct hfi1_devdata *dd = ppd->dd;
  11462. u64 reg = 0;
  11463. int i;
  11464. dd_dev_info(dd, "Setting partition keys\n");
  11465. for (i = 0; i < hfi1_get_npkeys(dd); i++) {
  11466. reg |= (ppd->pkeys[i] &
  11467. RCV_PARTITION_KEY_PARTITION_KEY_A_MASK) <<
  11468. ((i % 4) *
  11469. RCV_PARTITION_KEY_PARTITION_KEY_B_SHIFT);
  11470. /* Each register holds 4 PKey values. */
  11471. if ((i % 4) == 3) {
  11472. write_csr(dd, RCV_PARTITION_KEY +
  11473. ((i - 3) * 2), reg);
  11474. reg = 0;
  11475. }
  11476. }
  11477. /* Always enable HW pkeys check when pkeys table is set */
  11478. add_rcvctrl(dd, RCV_CTRL_RCV_PARTITION_KEY_ENABLE_SMASK);
  11479. }
  11480. /*
  11481. * These CSRs and memories are uninitialized on reset and must be
  11482. * written before reading to set the ECC/parity bits.
  11483. *
  11484. * NOTE: All user context CSRs that are not mmaped write-only
  11485. * (e.g. the TID flows) must be initialized even if the driver never
  11486. * reads them.
  11487. */
  11488. static void write_uninitialized_csrs_and_memories(struct hfi1_devdata *dd)
  11489. {
  11490. int i, j;
  11491. /* CceIntMap */
  11492. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11493. write_csr(dd, CCE_INT_MAP + (8 * i), 0);
  11494. /* SendCtxtCreditReturnAddr */
  11495. for (i = 0; i < dd->chip_send_contexts; i++)
  11496. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
  11497. /* PIO Send buffers */
  11498. /* SDMA Send buffers */
  11499. /*
  11500. * These are not normally read, and (presently) have no method
  11501. * to be read, so are not pre-initialized
  11502. */
  11503. /* RcvHdrAddr */
  11504. /* RcvHdrTailAddr */
  11505. /* RcvTidFlowTable */
  11506. for (i = 0; i < dd->chip_rcv_contexts; i++) {
  11507. write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
  11508. write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
  11509. for (j = 0; j < RXE_NUM_TID_FLOWS; j++)
  11510. write_uctxt_csr(dd, i, RCV_TID_FLOW_TABLE + (8 * j), 0);
  11511. }
  11512. /* RcvArray */
  11513. for (i = 0; i < dd->chip_rcv_array_count; i++)
  11514. write_csr(dd, RCV_ARRAY + (8 * i),
  11515. RCV_ARRAY_RT_WRITE_ENABLE_SMASK);
  11516. /* RcvQPMapTable */
  11517. for (i = 0; i < 32; i++)
  11518. write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
  11519. }
  11520. /*
  11521. * Use the ctrl_bits in CceCtrl to clear the status_bits in CceStatus.
  11522. */
  11523. static void clear_cce_status(struct hfi1_devdata *dd, u64 status_bits,
  11524. u64 ctrl_bits)
  11525. {
  11526. unsigned long timeout;
  11527. u64 reg;
  11528. /* is the condition present? */
  11529. reg = read_csr(dd, CCE_STATUS);
  11530. if ((reg & status_bits) == 0)
  11531. return;
  11532. /* clear the condition */
  11533. write_csr(dd, CCE_CTRL, ctrl_bits);
  11534. /* wait for the condition to clear */
  11535. timeout = jiffies + msecs_to_jiffies(CCE_STATUS_TIMEOUT);
  11536. while (1) {
  11537. reg = read_csr(dd, CCE_STATUS);
  11538. if ((reg & status_bits) == 0)
  11539. return;
  11540. if (time_after(jiffies, timeout)) {
  11541. dd_dev_err(dd,
  11542. "Timeout waiting for CceStatus to clear bits 0x%llx, remaining 0x%llx\n",
  11543. status_bits, reg & status_bits);
  11544. return;
  11545. }
  11546. udelay(1);
  11547. }
  11548. }
  11549. /* set CCE CSRs to chip reset defaults */
  11550. static void reset_cce_csrs(struct hfi1_devdata *dd)
  11551. {
  11552. int i;
  11553. /* CCE_REVISION read-only */
  11554. /* CCE_REVISION2 read-only */
  11555. /* CCE_CTRL - bits clear automatically */
  11556. /* CCE_STATUS read-only, use CceCtrl to clear */
  11557. clear_cce_status(dd, ALL_FROZE, CCE_CTRL_SPC_UNFREEZE_SMASK);
  11558. clear_cce_status(dd, ALL_TXE_PAUSE, CCE_CTRL_TXE_RESUME_SMASK);
  11559. clear_cce_status(dd, ALL_RXE_PAUSE, CCE_CTRL_RXE_RESUME_SMASK);
  11560. for (i = 0; i < CCE_NUM_SCRATCH; i++)
  11561. write_csr(dd, CCE_SCRATCH + (8 * i), 0);
  11562. /* CCE_ERR_STATUS read-only */
  11563. write_csr(dd, CCE_ERR_MASK, 0);
  11564. write_csr(dd, CCE_ERR_CLEAR, ~0ull);
  11565. /* CCE_ERR_FORCE leave alone */
  11566. for (i = 0; i < CCE_NUM_32_BIT_COUNTERS; i++)
  11567. write_csr(dd, CCE_COUNTER_ARRAY32 + (8 * i), 0);
  11568. write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_RESETCSR);
  11569. /* CCE_PCIE_CTRL leave alone */
  11570. for (i = 0; i < CCE_NUM_MSIX_VECTORS; i++) {
  11571. write_csr(dd, CCE_MSIX_TABLE_LOWER + (8 * i), 0);
  11572. write_csr(dd, CCE_MSIX_TABLE_UPPER + (8 * i),
  11573. CCE_MSIX_TABLE_UPPER_RESETCSR);
  11574. }
  11575. for (i = 0; i < CCE_NUM_MSIX_PBAS; i++) {
  11576. /* CCE_MSIX_PBA read-only */
  11577. write_csr(dd, CCE_MSIX_INT_GRANTED, ~0ull);
  11578. write_csr(dd, CCE_MSIX_VEC_CLR_WITHOUT_INT, ~0ull);
  11579. }
  11580. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11581. write_csr(dd, CCE_INT_MAP, 0);
  11582. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  11583. /* CCE_INT_STATUS read-only */
  11584. write_csr(dd, CCE_INT_MASK + (8 * i), 0);
  11585. write_csr(dd, CCE_INT_CLEAR + (8 * i), ~0ull);
  11586. /* CCE_INT_FORCE leave alone */
  11587. /* CCE_INT_BLOCKED read-only */
  11588. }
  11589. for (i = 0; i < CCE_NUM_32_BIT_INT_COUNTERS; i++)
  11590. write_csr(dd, CCE_INT_COUNTER_ARRAY32 + (8 * i), 0);
  11591. }
  11592. /* set MISC CSRs to chip reset defaults */
  11593. static void reset_misc_csrs(struct hfi1_devdata *dd)
  11594. {
  11595. int i;
  11596. for (i = 0; i < 32; i++) {
  11597. write_csr(dd, MISC_CFG_RSA_R2 + (8 * i), 0);
  11598. write_csr(dd, MISC_CFG_RSA_SIGNATURE + (8 * i), 0);
  11599. write_csr(dd, MISC_CFG_RSA_MODULUS + (8 * i), 0);
  11600. }
  11601. /*
  11602. * MISC_CFG_SHA_PRELOAD leave alone - always reads 0 and can
  11603. * only be written 128-byte chunks
  11604. */
  11605. /* init RSA engine to clear lingering errors */
  11606. write_csr(dd, MISC_CFG_RSA_CMD, 1);
  11607. write_csr(dd, MISC_CFG_RSA_MU, 0);
  11608. write_csr(dd, MISC_CFG_FW_CTRL, 0);
  11609. /* MISC_STS_8051_DIGEST read-only */
  11610. /* MISC_STS_SBM_DIGEST read-only */
  11611. /* MISC_STS_PCIE_DIGEST read-only */
  11612. /* MISC_STS_FAB_DIGEST read-only */
  11613. /* MISC_ERR_STATUS read-only */
  11614. write_csr(dd, MISC_ERR_MASK, 0);
  11615. write_csr(dd, MISC_ERR_CLEAR, ~0ull);
  11616. /* MISC_ERR_FORCE leave alone */
  11617. }
  11618. /* set TXE CSRs to chip reset defaults */
  11619. static void reset_txe_csrs(struct hfi1_devdata *dd)
  11620. {
  11621. int i;
  11622. /*
  11623. * TXE Kernel CSRs
  11624. */
  11625. write_csr(dd, SEND_CTRL, 0);
  11626. __cm_reset(dd, 0); /* reset CM internal state */
  11627. /* SEND_CONTEXTS read-only */
  11628. /* SEND_DMA_ENGINES read-only */
  11629. /* SEND_PIO_MEM_SIZE read-only */
  11630. /* SEND_DMA_MEM_SIZE read-only */
  11631. write_csr(dd, SEND_HIGH_PRIORITY_LIMIT, 0);
  11632. pio_reset_all(dd); /* SEND_PIO_INIT_CTXT */
  11633. /* SEND_PIO_ERR_STATUS read-only */
  11634. write_csr(dd, SEND_PIO_ERR_MASK, 0);
  11635. write_csr(dd, SEND_PIO_ERR_CLEAR, ~0ull);
  11636. /* SEND_PIO_ERR_FORCE leave alone */
  11637. /* SEND_DMA_ERR_STATUS read-only */
  11638. write_csr(dd, SEND_DMA_ERR_MASK, 0);
  11639. write_csr(dd, SEND_DMA_ERR_CLEAR, ~0ull);
  11640. /* SEND_DMA_ERR_FORCE leave alone */
  11641. /* SEND_EGRESS_ERR_STATUS read-only */
  11642. write_csr(dd, SEND_EGRESS_ERR_MASK, 0);
  11643. write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~0ull);
  11644. /* SEND_EGRESS_ERR_FORCE leave alone */
  11645. write_csr(dd, SEND_BTH_QP, 0);
  11646. write_csr(dd, SEND_STATIC_RATE_CONTROL, 0);
  11647. write_csr(dd, SEND_SC2VLT0, 0);
  11648. write_csr(dd, SEND_SC2VLT1, 0);
  11649. write_csr(dd, SEND_SC2VLT2, 0);
  11650. write_csr(dd, SEND_SC2VLT3, 0);
  11651. write_csr(dd, SEND_LEN_CHECK0, 0);
  11652. write_csr(dd, SEND_LEN_CHECK1, 0);
  11653. /* SEND_ERR_STATUS read-only */
  11654. write_csr(dd, SEND_ERR_MASK, 0);
  11655. write_csr(dd, SEND_ERR_CLEAR, ~0ull);
  11656. /* SEND_ERR_FORCE read-only */
  11657. for (i = 0; i < VL_ARB_LOW_PRIO_TABLE_SIZE; i++)
  11658. write_csr(dd, SEND_LOW_PRIORITY_LIST + (8 * i), 0);
  11659. for (i = 0; i < VL_ARB_HIGH_PRIO_TABLE_SIZE; i++)
  11660. write_csr(dd, SEND_HIGH_PRIORITY_LIST + (8 * i), 0);
  11661. for (i = 0; i < dd->chip_send_contexts / NUM_CONTEXTS_PER_SET; i++)
  11662. write_csr(dd, SEND_CONTEXT_SET_CTRL + (8 * i), 0);
  11663. for (i = 0; i < TXE_NUM_32_BIT_COUNTER; i++)
  11664. write_csr(dd, SEND_COUNTER_ARRAY32 + (8 * i), 0);
  11665. for (i = 0; i < TXE_NUM_64_BIT_COUNTER; i++)
  11666. write_csr(dd, SEND_COUNTER_ARRAY64 + (8 * i), 0);
  11667. write_csr(dd, SEND_CM_CTRL, SEND_CM_CTRL_RESETCSR);
  11668. write_csr(dd, SEND_CM_GLOBAL_CREDIT, SEND_CM_GLOBAL_CREDIT_RESETCSR);
  11669. /* SEND_CM_CREDIT_USED_STATUS read-only */
  11670. write_csr(dd, SEND_CM_TIMER_CTRL, 0);
  11671. write_csr(dd, SEND_CM_LOCAL_AU_TABLE0_TO3, 0);
  11672. write_csr(dd, SEND_CM_LOCAL_AU_TABLE4_TO7, 0);
  11673. write_csr(dd, SEND_CM_REMOTE_AU_TABLE0_TO3, 0);
  11674. write_csr(dd, SEND_CM_REMOTE_AU_TABLE4_TO7, 0);
  11675. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  11676. write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
  11677. write_csr(dd, SEND_CM_CREDIT_VL15, 0);
  11678. /* SEND_CM_CREDIT_USED_VL read-only */
  11679. /* SEND_CM_CREDIT_USED_VL15 read-only */
  11680. /* SEND_EGRESS_CTXT_STATUS read-only */
  11681. /* SEND_EGRESS_SEND_DMA_STATUS read-only */
  11682. write_csr(dd, SEND_EGRESS_ERR_INFO, ~0ull);
  11683. /* SEND_EGRESS_ERR_INFO read-only */
  11684. /* SEND_EGRESS_ERR_SOURCE read-only */
  11685. /*
  11686. * TXE Per-Context CSRs
  11687. */
  11688. for (i = 0; i < dd->chip_send_contexts; i++) {
  11689. write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
  11690. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_CTRL, 0);
  11691. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
  11692. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_FORCE, 0);
  11693. write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, 0);
  11694. write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~0ull);
  11695. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_ENABLE, 0);
  11696. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_VL, 0);
  11697. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_JOB_KEY, 0);
  11698. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_PARTITION_KEY, 0);
  11699. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, 0);
  11700. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_OPCODE, 0);
  11701. }
  11702. /*
  11703. * TXE Per-SDMA CSRs
  11704. */
  11705. for (i = 0; i < dd->chip_sdma_engines; i++) {
  11706. write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
  11707. /* SEND_DMA_STATUS read-only */
  11708. write_kctxt_csr(dd, i, SEND_DMA_BASE_ADDR, 0);
  11709. write_kctxt_csr(dd, i, SEND_DMA_LEN_GEN, 0);
  11710. write_kctxt_csr(dd, i, SEND_DMA_TAIL, 0);
  11711. /* SEND_DMA_HEAD read-only */
  11712. write_kctxt_csr(dd, i, SEND_DMA_HEAD_ADDR, 0);
  11713. write_kctxt_csr(dd, i, SEND_DMA_PRIORITY_THLD, 0);
  11714. /* SEND_DMA_IDLE_CNT read-only */
  11715. write_kctxt_csr(dd, i, SEND_DMA_RELOAD_CNT, 0);
  11716. write_kctxt_csr(dd, i, SEND_DMA_DESC_CNT, 0);
  11717. /* SEND_DMA_DESC_FETCHED_CNT read-only */
  11718. /* SEND_DMA_ENG_ERR_STATUS read-only */
  11719. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, 0);
  11720. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~0ull);
  11721. /* SEND_DMA_ENG_ERR_FORCE leave alone */
  11722. write_kctxt_csr(dd, i, SEND_DMA_CHECK_ENABLE, 0);
  11723. write_kctxt_csr(dd, i, SEND_DMA_CHECK_VL, 0);
  11724. write_kctxt_csr(dd, i, SEND_DMA_CHECK_JOB_KEY, 0);
  11725. write_kctxt_csr(dd, i, SEND_DMA_CHECK_PARTITION_KEY, 0);
  11726. write_kctxt_csr(dd, i, SEND_DMA_CHECK_SLID, 0);
  11727. write_kctxt_csr(dd, i, SEND_DMA_CHECK_OPCODE, 0);
  11728. write_kctxt_csr(dd, i, SEND_DMA_MEMORY, 0);
  11729. }
  11730. }
  11731. /*
  11732. * Expect on entry:
  11733. * o Packet ingress is disabled, i.e. RcvCtrl.RcvPortEnable == 0
  11734. */
  11735. static void init_rbufs(struct hfi1_devdata *dd)
  11736. {
  11737. u64 reg;
  11738. int count;
  11739. /*
  11740. * Wait for DMA to stop: RxRbufPktPending and RxPktInProgress are
  11741. * clear.
  11742. */
  11743. count = 0;
  11744. while (1) {
  11745. reg = read_csr(dd, RCV_STATUS);
  11746. if ((reg & (RCV_STATUS_RX_RBUF_PKT_PENDING_SMASK
  11747. | RCV_STATUS_RX_PKT_IN_PROGRESS_SMASK)) == 0)
  11748. break;
  11749. /*
  11750. * Give up after 1ms - maximum wait time.
  11751. *
  11752. * RBuf size is 136KiB. Slowest possible is PCIe Gen1 x1 at
  11753. * 250MB/s bandwidth. Lower rate to 66% for overhead to get:
  11754. * 136 KB / (66% * 250MB/s) = 844us
  11755. */
  11756. if (count++ > 500) {
  11757. dd_dev_err(dd,
  11758. "%s: in-progress DMA not clearing: RcvStatus 0x%llx, continuing\n",
  11759. __func__, reg);
  11760. break;
  11761. }
  11762. udelay(2); /* do not busy-wait the CSR */
  11763. }
  11764. /* start the init - expect RcvCtrl to be 0 */
  11765. write_csr(dd, RCV_CTRL, RCV_CTRL_RX_RBUF_INIT_SMASK);
  11766. /*
  11767. * Read to force the write of Rcvtrl.RxRbufInit. There is a brief
  11768. * period after the write before RcvStatus.RxRbufInitDone is valid.
  11769. * The delay in the first run through the loop below is sufficient and
  11770. * required before the first read of RcvStatus.RxRbufInintDone.
  11771. */
  11772. read_csr(dd, RCV_CTRL);
  11773. /* wait for the init to finish */
  11774. count = 0;
  11775. while (1) {
  11776. /* delay is required first time through - see above */
  11777. udelay(2); /* do not busy-wait the CSR */
  11778. reg = read_csr(dd, RCV_STATUS);
  11779. if (reg & (RCV_STATUS_RX_RBUF_INIT_DONE_SMASK))
  11780. break;
  11781. /* give up after 100us - slowest possible at 33MHz is 73us */
  11782. if (count++ > 50) {
  11783. dd_dev_err(dd,
  11784. "%s: RcvStatus.RxRbufInit not set, continuing\n",
  11785. __func__);
  11786. break;
  11787. }
  11788. }
  11789. }
  11790. /* set RXE CSRs to chip reset defaults */
  11791. static void reset_rxe_csrs(struct hfi1_devdata *dd)
  11792. {
  11793. int i, j;
  11794. /*
  11795. * RXE Kernel CSRs
  11796. */
  11797. write_csr(dd, RCV_CTRL, 0);
  11798. init_rbufs(dd);
  11799. /* RCV_STATUS read-only */
  11800. /* RCV_CONTEXTS read-only */
  11801. /* RCV_ARRAY_CNT read-only */
  11802. /* RCV_BUF_SIZE read-only */
  11803. write_csr(dd, RCV_BTH_QP, 0);
  11804. write_csr(dd, RCV_MULTICAST, 0);
  11805. write_csr(dd, RCV_BYPASS, 0);
  11806. write_csr(dd, RCV_VL15, 0);
  11807. /* this is a clear-down */
  11808. write_csr(dd, RCV_ERR_INFO,
  11809. RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK);
  11810. /* RCV_ERR_STATUS read-only */
  11811. write_csr(dd, RCV_ERR_MASK, 0);
  11812. write_csr(dd, RCV_ERR_CLEAR, ~0ull);
  11813. /* RCV_ERR_FORCE leave alone */
  11814. for (i = 0; i < 32; i++)
  11815. write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
  11816. for (i = 0; i < 4; i++)
  11817. write_csr(dd, RCV_PARTITION_KEY + (8 * i), 0);
  11818. for (i = 0; i < RXE_NUM_32_BIT_COUNTERS; i++)
  11819. write_csr(dd, RCV_COUNTER_ARRAY32 + (8 * i), 0);
  11820. for (i = 0; i < RXE_NUM_64_BIT_COUNTERS; i++)
  11821. write_csr(dd, RCV_COUNTER_ARRAY64 + (8 * i), 0);
  11822. for (i = 0; i < RXE_NUM_RSM_INSTANCES; i++) {
  11823. write_csr(dd, RCV_RSM_CFG + (8 * i), 0);
  11824. write_csr(dd, RCV_RSM_SELECT + (8 * i), 0);
  11825. write_csr(dd, RCV_RSM_MATCH + (8 * i), 0);
  11826. }
  11827. for (i = 0; i < 32; i++)
  11828. write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), 0);
  11829. /*
  11830. * RXE Kernel and User Per-Context CSRs
  11831. */
  11832. for (i = 0; i < dd->chip_rcv_contexts; i++) {
  11833. /* kernel */
  11834. write_kctxt_csr(dd, i, RCV_CTXT_CTRL, 0);
  11835. /* RCV_CTXT_STATUS read-only */
  11836. write_kctxt_csr(dd, i, RCV_EGR_CTRL, 0);
  11837. write_kctxt_csr(dd, i, RCV_TID_CTRL, 0);
  11838. write_kctxt_csr(dd, i, RCV_KEY_CTRL, 0);
  11839. write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
  11840. write_kctxt_csr(dd, i, RCV_HDR_CNT, 0);
  11841. write_kctxt_csr(dd, i, RCV_HDR_ENT_SIZE, 0);
  11842. write_kctxt_csr(dd, i, RCV_HDR_SIZE, 0);
  11843. write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
  11844. write_kctxt_csr(dd, i, RCV_AVAIL_TIME_OUT, 0);
  11845. write_kctxt_csr(dd, i, RCV_HDR_OVFL_CNT, 0);
  11846. /* user */
  11847. /* RCV_HDR_TAIL read-only */
  11848. write_uctxt_csr(dd, i, RCV_HDR_HEAD, 0);
  11849. /* RCV_EGR_INDEX_TAIL read-only */
  11850. write_uctxt_csr(dd, i, RCV_EGR_INDEX_HEAD, 0);
  11851. /* RCV_EGR_OFFSET_TAIL read-only */
  11852. for (j = 0; j < RXE_NUM_TID_FLOWS; j++) {
  11853. write_uctxt_csr(dd, i,
  11854. RCV_TID_FLOW_TABLE + (8 * j), 0);
  11855. }
  11856. }
  11857. }
  11858. /*
  11859. * Set sc2vl tables.
  11860. *
  11861. * They power on to zeros, so to avoid send context errors
  11862. * they need to be set:
  11863. *
  11864. * SC 0-7 -> VL 0-7 (respectively)
  11865. * SC 15 -> VL 15
  11866. * otherwise
  11867. * -> VL 0
  11868. */
  11869. static void init_sc2vl_tables(struct hfi1_devdata *dd)
  11870. {
  11871. int i;
  11872. /* init per architecture spec, constrained by hardware capability */
  11873. /* HFI maps sent packets */
  11874. write_csr(dd, SEND_SC2VLT0, SC2VL_VAL(
  11875. 0,
  11876. 0, 0, 1, 1,
  11877. 2, 2, 3, 3,
  11878. 4, 4, 5, 5,
  11879. 6, 6, 7, 7));
  11880. write_csr(dd, SEND_SC2VLT1, SC2VL_VAL(
  11881. 1,
  11882. 8, 0, 9, 0,
  11883. 10, 0, 11, 0,
  11884. 12, 0, 13, 0,
  11885. 14, 0, 15, 15));
  11886. write_csr(dd, SEND_SC2VLT2, SC2VL_VAL(
  11887. 2,
  11888. 16, 0, 17, 0,
  11889. 18, 0, 19, 0,
  11890. 20, 0, 21, 0,
  11891. 22, 0, 23, 0));
  11892. write_csr(dd, SEND_SC2VLT3, SC2VL_VAL(
  11893. 3,
  11894. 24, 0, 25, 0,
  11895. 26, 0, 27, 0,
  11896. 28, 0, 29, 0,
  11897. 30, 0, 31, 0));
  11898. /* DC maps received packets */
  11899. write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0, DC_SC_VL_VAL(
  11900. 15_0,
  11901. 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  11902. 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 15));
  11903. write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16, DC_SC_VL_VAL(
  11904. 31_16,
  11905. 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0,
  11906. 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0));
  11907. /* initialize the cached sc2vl values consistently with h/w */
  11908. for (i = 0; i < 32; i++) {
  11909. if (i < 8 || i == 15)
  11910. *((u8 *)(dd->sc2vl) + i) = (u8)i;
  11911. else
  11912. *((u8 *)(dd->sc2vl) + i) = 0;
  11913. }
  11914. }
  11915. /*
  11916. * Read chip sizes and then reset parts to sane, disabled, values. We cannot
  11917. * depend on the chip going through a power-on reset - a driver may be loaded
  11918. * and unloaded many times.
  11919. *
  11920. * Do not write any CSR values to the chip in this routine - there may be
  11921. * a reset following the (possible) FLR in this routine.
  11922. *
  11923. */
  11924. static void init_chip(struct hfi1_devdata *dd)
  11925. {
  11926. int i;
  11927. /*
  11928. * Put the HFI CSRs in a known state.
  11929. * Combine this with a DC reset.
  11930. *
  11931. * Stop the device from doing anything while we do a
  11932. * reset. We know there are no other active users of
  11933. * the device since we are now in charge. Turn off
  11934. * off all outbound and inbound traffic and make sure
  11935. * the device does not generate any interrupts.
  11936. */
  11937. /* disable send contexts and SDMA engines */
  11938. write_csr(dd, SEND_CTRL, 0);
  11939. for (i = 0; i < dd->chip_send_contexts; i++)
  11940. write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
  11941. for (i = 0; i < dd->chip_sdma_engines; i++)
  11942. write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
  11943. /* disable port (turn off RXE inbound traffic) and contexts */
  11944. write_csr(dd, RCV_CTRL, 0);
  11945. for (i = 0; i < dd->chip_rcv_contexts; i++)
  11946. write_csr(dd, RCV_CTXT_CTRL, 0);
  11947. /* mask all interrupt sources */
  11948. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11949. write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
  11950. /*
  11951. * DC Reset: do a full DC reset before the register clear.
  11952. * A recommended length of time to hold is one CSR read,
  11953. * so reread the CceDcCtrl. Then, hold the DC in reset
  11954. * across the clear.
  11955. */
  11956. write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_DC_RESET_SMASK);
  11957. (void)read_csr(dd, CCE_DC_CTRL);
  11958. if (use_flr) {
  11959. /*
  11960. * A FLR will reset the SPC core and part of the PCIe.
  11961. * The parts that need to be restored have already been
  11962. * saved.
  11963. */
  11964. dd_dev_info(dd, "Resetting CSRs with FLR\n");
  11965. /* do the FLR, the DC reset will remain */
  11966. hfi1_pcie_flr(dd);
  11967. /* restore command and BARs */
  11968. restore_pci_variables(dd);
  11969. if (is_ax(dd)) {
  11970. dd_dev_info(dd, "Resetting CSRs with FLR\n");
  11971. hfi1_pcie_flr(dd);
  11972. restore_pci_variables(dd);
  11973. }
  11974. } else {
  11975. dd_dev_info(dd, "Resetting CSRs with writes\n");
  11976. reset_cce_csrs(dd);
  11977. reset_txe_csrs(dd);
  11978. reset_rxe_csrs(dd);
  11979. reset_misc_csrs(dd);
  11980. }
  11981. /* clear the DC reset */
  11982. write_csr(dd, CCE_DC_CTRL, 0);
  11983. /* Set the LED off */
  11984. setextled(dd, 0);
  11985. /*
  11986. * Clear the QSFP reset.
  11987. * An FLR enforces a 0 on all out pins. The driver does not touch
  11988. * ASIC_QSFPn_OUT otherwise. This leaves RESET_N low and
  11989. * anything plugged constantly in reset, if it pays attention
  11990. * to RESET_N.
  11991. * Prime examples of this are optical cables. Set all pins high.
  11992. * I2CCLK and I2CDAT will change per direction, and INT_N and
  11993. * MODPRS_N are input only and their value is ignored.
  11994. */
  11995. write_csr(dd, ASIC_QSFP1_OUT, 0x1f);
  11996. write_csr(dd, ASIC_QSFP2_OUT, 0x1f);
  11997. init_chip_resources(dd);
  11998. }
  11999. static void init_early_variables(struct hfi1_devdata *dd)
  12000. {
  12001. int i;
  12002. /* assign link credit variables */
  12003. dd->vau = CM_VAU;
  12004. dd->link_credits = CM_GLOBAL_CREDITS;
  12005. if (is_ax(dd))
  12006. dd->link_credits--;
  12007. dd->vcu = cu_to_vcu(hfi1_cu);
  12008. /* enough room for 8 MAD packets plus header - 17K */
  12009. dd->vl15_init = (8 * (2048 + 128)) / vau_to_au(dd->vau);
  12010. if (dd->vl15_init > dd->link_credits)
  12011. dd->vl15_init = dd->link_credits;
  12012. write_uninitialized_csrs_and_memories(dd);
  12013. if (HFI1_CAP_IS_KSET(PKEY_CHECK))
  12014. for (i = 0; i < dd->num_pports; i++) {
  12015. struct hfi1_pportdata *ppd = &dd->pport[i];
  12016. set_partition_keys(ppd);
  12017. }
  12018. init_sc2vl_tables(dd);
  12019. }
  12020. static void init_kdeth_qp(struct hfi1_devdata *dd)
  12021. {
  12022. /* user changed the KDETH_QP */
  12023. if (kdeth_qp != 0 && kdeth_qp >= 0xff) {
  12024. /* out of range or illegal value */
  12025. dd_dev_err(dd, "Invalid KDETH queue pair prefix, ignoring");
  12026. kdeth_qp = 0;
  12027. }
  12028. if (kdeth_qp == 0) /* not set, or failed range check */
  12029. kdeth_qp = DEFAULT_KDETH_QP;
  12030. write_csr(dd, SEND_BTH_QP,
  12031. (kdeth_qp & SEND_BTH_QP_KDETH_QP_MASK) <<
  12032. SEND_BTH_QP_KDETH_QP_SHIFT);
  12033. write_csr(dd, RCV_BTH_QP,
  12034. (kdeth_qp & RCV_BTH_QP_KDETH_QP_MASK) <<
  12035. RCV_BTH_QP_KDETH_QP_SHIFT);
  12036. }
  12037. /**
  12038. * init_qpmap_table
  12039. * @dd - device data
  12040. * @first_ctxt - first context
  12041. * @last_ctxt - first context
  12042. *
  12043. * This return sets the qpn mapping table that
  12044. * is indexed by qpn[8:1].
  12045. *
  12046. * The routine will round robin the 256 settings
  12047. * from first_ctxt to last_ctxt.
  12048. *
  12049. * The first/last looks ahead to having specialized
  12050. * receive contexts for mgmt and bypass. Normal
  12051. * verbs traffic will assumed to be on a range
  12052. * of receive contexts.
  12053. */
  12054. static void init_qpmap_table(struct hfi1_devdata *dd,
  12055. u32 first_ctxt,
  12056. u32 last_ctxt)
  12057. {
  12058. u64 reg = 0;
  12059. u64 regno = RCV_QP_MAP_TABLE;
  12060. int i;
  12061. u64 ctxt = first_ctxt;
  12062. for (i = 0; i < 256; i++) {
  12063. reg |= ctxt << (8 * (i % 8));
  12064. ctxt++;
  12065. if (ctxt > last_ctxt)
  12066. ctxt = first_ctxt;
  12067. if (i % 8 == 7) {
  12068. write_csr(dd, regno, reg);
  12069. reg = 0;
  12070. regno += 8;
  12071. }
  12072. }
  12073. add_rcvctrl(dd, RCV_CTRL_RCV_QP_MAP_ENABLE_SMASK
  12074. | RCV_CTRL_RCV_BYPASS_ENABLE_SMASK);
  12075. }
  12076. struct rsm_map_table {
  12077. u64 map[NUM_MAP_REGS];
  12078. unsigned int used;
  12079. };
  12080. struct rsm_rule_data {
  12081. u8 offset;
  12082. u8 pkt_type;
  12083. u32 field1_off;
  12084. u32 field2_off;
  12085. u32 index1_off;
  12086. u32 index1_width;
  12087. u32 index2_off;
  12088. u32 index2_width;
  12089. u32 mask1;
  12090. u32 value1;
  12091. u32 mask2;
  12092. u32 value2;
  12093. };
  12094. /*
  12095. * Return an initialized RMT map table for users to fill in. OK if it
  12096. * returns NULL, indicating no table.
  12097. */
  12098. static struct rsm_map_table *alloc_rsm_map_table(struct hfi1_devdata *dd)
  12099. {
  12100. struct rsm_map_table *rmt;
  12101. u8 rxcontext = is_ax(dd) ? 0 : 0xff; /* 0 is default if a0 ver. */
  12102. rmt = kmalloc(sizeof(*rmt), GFP_KERNEL);
  12103. if (rmt) {
  12104. memset(rmt->map, rxcontext, sizeof(rmt->map));
  12105. rmt->used = 0;
  12106. }
  12107. return rmt;
  12108. }
  12109. /*
  12110. * Write the final RMT map table to the chip and free the table. OK if
  12111. * table is NULL.
  12112. */
  12113. static void complete_rsm_map_table(struct hfi1_devdata *dd,
  12114. struct rsm_map_table *rmt)
  12115. {
  12116. int i;
  12117. if (rmt) {
  12118. /* write table to chip */
  12119. for (i = 0; i < NUM_MAP_REGS; i++)
  12120. write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), rmt->map[i]);
  12121. /* enable RSM */
  12122. add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12123. }
  12124. }
  12125. /*
  12126. * Add a receive side mapping rule.
  12127. */
  12128. static void add_rsm_rule(struct hfi1_devdata *dd, u8 rule_index,
  12129. struct rsm_rule_data *rrd)
  12130. {
  12131. write_csr(dd, RCV_RSM_CFG + (8 * rule_index),
  12132. (u64)rrd->offset << RCV_RSM_CFG_OFFSET_SHIFT |
  12133. 1ull << rule_index | /* enable bit */
  12134. (u64)rrd->pkt_type << RCV_RSM_CFG_PACKET_TYPE_SHIFT);
  12135. write_csr(dd, RCV_RSM_SELECT + (8 * rule_index),
  12136. (u64)rrd->field1_off << RCV_RSM_SELECT_FIELD1_OFFSET_SHIFT |
  12137. (u64)rrd->field2_off << RCV_RSM_SELECT_FIELD2_OFFSET_SHIFT |
  12138. (u64)rrd->index1_off << RCV_RSM_SELECT_INDEX1_OFFSET_SHIFT |
  12139. (u64)rrd->index1_width << RCV_RSM_SELECT_INDEX1_WIDTH_SHIFT |
  12140. (u64)rrd->index2_off << RCV_RSM_SELECT_INDEX2_OFFSET_SHIFT |
  12141. (u64)rrd->index2_width << RCV_RSM_SELECT_INDEX2_WIDTH_SHIFT);
  12142. write_csr(dd, RCV_RSM_MATCH + (8 * rule_index),
  12143. (u64)rrd->mask1 << RCV_RSM_MATCH_MASK1_SHIFT |
  12144. (u64)rrd->value1 << RCV_RSM_MATCH_VALUE1_SHIFT |
  12145. (u64)rrd->mask2 << RCV_RSM_MATCH_MASK2_SHIFT |
  12146. (u64)rrd->value2 << RCV_RSM_MATCH_VALUE2_SHIFT);
  12147. }
  12148. /* return the number of RSM map table entries that will be used for QOS */
  12149. static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp,
  12150. unsigned int *np)
  12151. {
  12152. int i;
  12153. unsigned int m, n;
  12154. u8 max_by_vl = 0;
  12155. /* is QOS active at all? */
  12156. if (dd->n_krcv_queues <= MIN_KERNEL_KCTXTS ||
  12157. num_vls == 1 ||
  12158. krcvqsset <= 1)
  12159. goto no_qos;
  12160. /* determine bits for qpn */
  12161. for (i = 0; i < min_t(unsigned int, num_vls, krcvqsset); i++)
  12162. if (krcvqs[i] > max_by_vl)
  12163. max_by_vl = krcvqs[i];
  12164. if (max_by_vl > 32)
  12165. goto no_qos;
  12166. m = ilog2(__roundup_pow_of_two(max_by_vl));
  12167. /* determine bits for vl */
  12168. n = ilog2(__roundup_pow_of_two(num_vls));
  12169. /* reject if too much is used */
  12170. if ((m + n) > 7)
  12171. goto no_qos;
  12172. if (mp)
  12173. *mp = m;
  12174. if (np)
  12175. *np = n;
  12176. return 1 << (m + n);
  12177. no_qos:
  12178. if (mp)
  12179. *mp = 0;
  12180. if (np)
  12181. *np = 0;
  12182. return 0;
  12183. }
  12184. /**
  12185. * init_qos - init RX qos
  12186. * @dd - device data
  12187. * @rmt - RSM map table
  12188. *
  12189. * This routine initializes Rule 0 and the RSM map table to implement
  12190. * quality of service (qos).
  12191. *
  12192. * If all of the limit tests succeed, qos is applied based on the array
  12193. * interpretation of krcvqs where entry 0 is VL0.
  12194. *
  12195. * The number of vl bits (n) and the number of qpn bits (m) are computed to
  12196. * feed both the RSM map table and the single rule.
  12197. */
  12198. static void init_qos(struct hfi1_devdata *dd, struct rsm_map_table *rmt)
  12199. {
  12200. struct rsm_rule_data rrd;
  12201. unsigned qpns_per_vl, ctxt, i, qpn, n = 1, m;
  12202. unsigned int rmt_entries;
  12203. u64 reg;
  12204. if (!rmt)
  12205. goto bail;
  12206. rmt_entries = qos_rmt_entries(dd, &m, &n);
  12207. if (rmt_entries == 0)
  12208. goto bail;
  12209. qpns_per_vl = 1 << m;
  12210. /* enough room in the map table? */
  12211. rmt_entries = 1 << (m + n);
  12212. if (rmt->used + rmt_entries >= NUM_MAP_ENTRIES)
  12213. goto bail;
  12214. /* add qos entries to the the RSM map table */
  12215. for (i = 0, ctxt = FIRST_KERNEL_KCTXT; i < num_vls; i++) {
  12216. unsigned tctxt;
  12217. for (qpn = 0, tctxt = ctxt;
  12218. krcvqs[i] && qpn < qpns_per_vl; qpn++) {
  12219. unsigned idx, regoff, regidx;
  12220. /* generate the index the hardware will produce */
  12221. idx = rmt->used + ((qpn << n) ^ i);
  12222. regoff = (idx % 8) * 8;
  12223. regidx = idx / 8;
  12224. /* replace default with context number */
  12225. reg = rmt->map[regidx];
  12226. reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK
  12227. << regoff);
  12228. reg |= (u64)(tctxt++) << regoff;
  12229. rmt->map[regidx] = reg;
  12230. if (tctxt == ctxt + krcvqs[i])
  12231. tctxt = ctxt;
  12232. }
  12233. ctxt += krcvqs[i];
  12234. }
  12235. rrd.offset = rmt->used;
  12236. rrd.pkt_type = 2;
  12237. rrd.field1_off = LRH_BTH_MATCH_OFFSET;
  12238. rrd.field2_off = LRH_SC_MATCH_OFFSET;
  12239. rrd.index1_off = LRH_SC_SELECT_OFFSET;
  12240. rrd.index1_width = n;
  12241. rrd.index2_off = QPN_SELECT_OFFSET;
  12242. rrd.index2_width = m + n;
  12243. rrd.mask1 = LRH_BTH_MASK;
  12244. rrd.value1 = LRH_BTH_VALUE;
  12245. rrd.mask2 = LRH_SC_MASK;
  12246. rrd.value2 = LRH_SC_VALUE;
  12247. /* add rule 0 */
  12248. add_rsm_rule(dd, 0, &rrd);
  12249. /* mark RSM map entries as used */
  12250. rmt->used += rmt_entries;
  12251. /* map everything else to the mcast/err/vl15 context */
  12252. init_qpmap_table(dd, HFI1_CTRL_CTXT, HFI1_CTRL_CTXT);
  12253. dd->qos_shift = n + 1;
  12254. return;
  12255. bail:
  12256. dd->qos_shift = 1;
  12257. init_qpmap_table(dd, FIRST_KERNEL_KCTXT, dd->n_krcv_queues - 1);
  12258. }
  12259. static void init_user_fecn_handling(struct hfi1_devdata *dd,
  12260. struct rsm_map_table *rmt)
  12261. {
  12262. struct rsm_rule_data rrd;
  12263. u64 reg;
  12264. int i, idx, regoff, regidx;
  12265. u8 offset;
  12266. /* there needs to be enough room in the map table */
  12267. if (rmt->used + dd->num_user_contexts >= NUM_MAP_ENTRIES) {
  12268. dd_dev_err(dd, "User FECN handling disabled - too many user contexts allocated\n");
  12269. return;
  12270. }
  12271. /*
  12272. * RSM will extract the destination context as an index into the
  12273. * map table. The destination contexts are a sequential block
  12274. * in the range first_user_ctxt...num_rcv_contexts-1 (inclusive).
  12275. * Map entries are accessed as offset + extracted value. Adjust
  12276. * the added offset so this sequence can be placed anywhere in
  12277. * the table - as long as the entries themselves do not wrap.
  12278. * There are only enough bits in offset for the table size, so
  12279. * start with that to allow for a "negative" offset.
  12280. */
  12281. offset = (u8)(NUM_MAP_ENTRIES + (int)rmt->used -
  12282. (int)dd->first_user_ctxt);
  12283. for (i = dd->first_user_ctxt, idx = rmt->used;
  12284. i < dd->num_rcv_contexts; i++, idx++) {
  12285. /* replace with identity mapping */
  12286. regoff = (idx % 8) * 8;
  12287. regidx = idx / 8;
  12288. reg = rmt->map[regidx];
  12289. reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK << regoff);
  12290. reg |= (u64)i << regoff;
  12291. rmt->map[regidx] = reg;
  12292. }
  12293. /*
  12294. * For RSM intercept of Expected FECN packets:
  12295. * o packet type 0 - expected
  12296. * o match on F (bit 95), using select/match 1, and
  12297. * o match on SH (bit 133), using select/match 2.
  12298. *
  12299. * Use index 1 to extract the 8-bit receive context from DestQP
  12300. * (start at bit 64). Use that as the RSM map table index.
  12301. */
  12302. rrd.offset = offset;
  12303. rrd.pkt_type = 0;
  12304. rrd.field1_off = 95;
  12305. rrd.field2_off = 133;
  12306. rrd.index1_off = 64;
  12307. rrd.index1_width = 8;
  12308. rrd.index2_off = 0;
  12309. rrd.index2_width = 0;
  12310. rrd.mask1 = 1;
  12311. rrd.value1 = 1;
  12312. rrd.mask2 = 1;
  12313. rrd.value2 = 1;
  12314. /* add rule 1 */
  12315. add_rsm_rule(dd, 1, &rrd);
  12316. rmt->used += dd->num_user_contexts;
  12317. }
  12318. static void init_rxe(struct hfi1_devdata *dd)
  12319. {
  12320. struct rsm_map_table *rmt;
  12321. /* enable all receive errors */
  12322. write_csr(dd, RCV_ERR_MASK, ~0ull);
  12323. rmt = alloc_rsm_map_table(dd);
  12324. /* set up QOS, including the QPN map table */
  12325. init_qos(dd, rmt);
  12326. init_user_fecn_handling(dd, rmt);
  12327. complete_rsm_map_table(dd, rmt);
  12328. kfree(rmt);
  12329. /*
  12330. * make sure RcvCtrl.RcvWcb <= PCIe Device Control
  12331. * Register Max_Payload_Size (PCI_EXP_DEVCTL in Linux PCIe config
  12332. * space, PciCfgCap2.MaxPayloadSize in HFI). There is only one
  12333. * invalid configuration: RcvCtrl.RcvWcb set to its max of 256 and
  12334. * Max_PayLoad_Size set to its minimum of 128.
  12335. *
  12336. * Presently, RcvCtrl.RcvWcb is not modified from its default of 0
  12337. * (64 bytes). Max_Payload_Size is possibly modified upward in
  12338. * tune_pcie_caps() which is called after this routine.
  12339. */
  12340. }
  12341. static void init_other(struct hfi1_devdata *dd)
  12342. {
  12343. /* enable all CCE errors */
  12344. write_csr(dd, CCE_ERR_MASK, ~0ull);
  12345. /* enable *some* Misc errors */
  12346. write_csr(dd, MISC_ERR_MASK, DRIVER_MISC_MASK);
  12347. /* enable all DC errors, except LCB */
  12348. write_csr(dd, DCC_ERR_FLG_EN, ~0ull);
  12349. write_csr(dd, DC_DC8051_ERR_EN, ~0ull);
  12350. }
  12351. /*
  12352. * Fill out the given AU table using the given CU. A CU is defined in terms
  12353. * AUs. The table is a an encoding: given the index, how many AUs does that
  12354. * represent?
  12355. *
  12356. * NOTE: Assumes that the register layout is the same for the
  12357. * local and remote tables.
  12358. */
  12359. static void assign_cm_au_table(struct hfi1_devdata *dd, u32 cu,
  12360. u32 csr0to3, u32 csr4to7)
  12361. {
  12362. write_csr(dd, csr0to3,
  12363. 0ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE0_SHIFT |
  12364. 1ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE1_SHIFT |
  12365. 2ull * cu <<
  12366. SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE2_SHIFT |
  12367. 4ull * cu <<
  12368. SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE3_SHIFT);
  12369. write_csr(dd, csr4to7,
  12370. 8ull * cu <<
  12371. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE4_SHIFT |
  12372. 16ull * cu <<
  12373. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE5_SHIFT |
  12374. 32ull * cu <<
  12375. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE6_SHIFT |
  12376. 64ull * cu <<
  12377. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE7_SHIFT);
  12378. }
  12379. static void assign_local_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
  12380. {
  12381. assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_LOCAL_AU_TABLE0_TO3,
  12382. SEND_CM_LOCAL_AU_TABLE4_TO7);
  12383. }
  12384. void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
  12385. {
  12386. assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_REMOTE_AU_TABLE0_TO3,
  12387. SEND_CM_REMOTE_AU_TABLE4_TO7);
  12388. }
  12389. static void init_txe(struct hfi1_devdata *dd)
  12390. {
  12391. int i;
  12392. /* enable all PIO, SDMA, general, and Egress errors */
  12393. write_csr(dd, SEND_PIO_ERR_MASK, ~0ull);
  12394. write_csr(dd, SEND_DMA_ERR_MASK, ~0ull);
  12395. write_csr(dd, SEND_ERR_MASK, ~0ull);
  12396. write_csr(dd, SEND_EGRESS_ERR_MASK, ~0ull);
  12397. /* enable all per-context and per-SDMA engine errors */
  12398. for (i = 0; i < dd->chip_send_contexts; i++)
  12399. write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, ~0ull);
  12400. for (i = 0; i < dd->chip_sdma_engines; i++)
  12401. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, ~0ull);
  12402. /* set the local CU to AU mapping */
  12403. assign_local_cm_au_table(dd, dd->vcu);
  12404. /*
  12405. * Set reasonable default for Credit Return Timer
  12406. * Don't set on Simulator - causes it to choke.
  12407. */
  12408. if (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)
  12409. write_csr(dd, SEND_CM_TIMER_CTRL, HFI1_CREDIT_RETURN_RATE);
  12410. }
  12411. int hfi1_set_ctxt_jkey(struct hfi1_devdata *dd, unsigned ctxt, u16 jkey)
  12412. {
  12413. struct hfi1_ctxtdata *rcd = dd->rcd[ctxt];
  12414. unsigned sctxt;
  12415. int ret = 0;
  12416. u64 reg;
  12417. if (!rcd || !rcd->sc) {
  12418. ret = -EINVAL;
  12419. goto done;
  12420. }
  12421. sctxt = rcd->sc->hw_context;
  12422. reg = SEND_CTXT_CHECK_JOB_KEY_MASK_SMASK | /* mask is always 1's */
  12423. ((jkey & SEND_CTXT_CHECK_JOB_KEY_VALUE_MASK) <<
  12424. SEND_CTXT_CHECK_JOB_KEY_VALUE_SHIFT);
  12425. /* JOB_KEY_ALLOW_PERMISSIVE is not allowed by default */
  12426. if (HFI1_CAP_KGET_MASK(rcd->flags, ALLOW_PERM_JKEY))
  12427. reg |= SEND_CTXT_CHECK_JOB_KEY_ALLOW_PERMISSIVE_SMASK;
  12428. write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_JOB_KEY, reg);
  12429. /*
  12430. * Enable send-side J_KEY integrity check, unless this is A0 h/w
  12431. */
  12432. if (!is_ax(dd)) {
  12433. reg = read_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE);
  12434. reg |= SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  12435. write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12436. }
  12437. /* Enable J_KEY check on receive context. */
  12438. reg = RCV_KEY_CTRL_JOB_KEY_ENABLE_SMASK |
  12439. ((jkey & RCV_KEY_CTRL_JOB_KEY_VALUE_MASK) <<
  12440. RCV_KEY_CTRL_JOB_KEY_VALUE_SHIFT);
  12441. write_kctxt_csr(dd, ctxt, RCV_KEY_CTRL, reg);
  12442. done:
  12443. return ret;
  12444. }
  12445. int hfi1_clear_ctxt_jkey(struct hfi1_devdata *dd, unsigned ctxt)
  12446. {
  12447. struct hfi1_ctxtdata *rcd = dd->rcd[ctxt];
  12448. unsigned sctxt;
  12449. int ret = 0;
  12450. u64 reg;
  12451. if (!rcd || !rcd->sc) {
  12452. ret = -EINVAL;
  12453. goto done;
  12454. }
  12455. sctxt = rcd->sc->hw_context;
  12456. write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_JOB_KEY, 0);
  12457. /*
  12458. * Disable send-side J_KEY integrity check, unless this is A0 h/w.
  12459. * This check would not have been enabled for A0 h/w, see
  12460. * set_ctxt_jkey().
  12461. */
  12462. if (!is_ax(dd)) {
  12463. reg = read_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE);
  12464. reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  12465. write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12466. }
  12467. /* Turn off the J_KEY on the receive side */
  12468. write_kctxt_csr(dd, ctxt, RCV_KEY_CTRL, 0);
  12469. done:
  12470. return ret;
  12471. }
  12472. int hfi1_set_ctxt_pkey(struct hfi1_devdata *dd, unsigned ctxt, u16 pkey)
  12473. {
  12474. struct hfi1_ctxtdata *rcd;
  12475. unsigned sctxt;
  12476. int ret = 0;
  12477. u64 reg;
  12478. if (ctxt < dd->num_rcv_contexts) {
  12479. rcd = dd->rcd[ctxt];
  12480. } else {
  12481. ret = -EINVAL;
  12482. goto done;
  12483. }
  12484. if (!rcd || !rcd->sc) {
  12485. ret = -EINVAL;
  12486. goto done;
  12487. }
  12488. sctxt = rcd->sc->hw_context;
  12489. reg = ((u64)pkey & SEND_CTXT_CHECK_PARTITION_KEY_VALUE_MASK) <<
  12490. SEND_CTXT_CHECK_PARTITION_KEY_VALUE_SHIFT;
  12491. write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_PARTITION_KEY, reg);
  12492. reg = read_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE);
  12493. reg |= SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
  12494. reg &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK;
  12495. write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12496. done:
  12497. return ret;
  12498. }
  12499. int hfi1_clear_ctxt_pkey(struct hfi1_devdata *dd, unsigned ctxt)
  12500. {
  12501. struct hfi1_ctxtdata *rcd;
  12502. unsigned sctxt;
  12503. int ret = 0;
  12504. u64 reg;
  12505. if (ctxt < dd->num_rcv_contexts) {
  12506. rcd = dd->rcd[ctxt];
  12507. } else {
  12508. ret = -EINVAL;
  12509. goto done;
  12510. }
  12511. if (!rcd || !rcd->sc) {
  12512. ret = -EINVAL;
  12513. goto done;
  12514. }
  12515. sctxt = rcd->sc->hw_context;
  12516. reg = read_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE);
  12517. reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
  12518. write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12519. write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_PARTITION_KEY, 0);
  12520. done:
  12521. return ret;
  12522. }
  12523. /*
  12524. * Start doing the clean up the the chip. Our clean up happens in multiple
  12525. * stages and this is just the first.
  12526. */
  12527. void hfi1_start_cleanup(struct hfi1_devdata *dd)
  12528. {
  12529. aspm_exit(dd);
  12530. free_cntrs(dd);
  12531. free_rcverr(dd);
  12532. clean_up_interrupts(dd);
  12533. finish_chip_resources(dd);
  12534. }
  12535. #define HFI_BASE_GUID(dev) \
  12536. ((dev)->base_guid & ~(1ULL << GUID_HFI_INDEX_SHIFT))
  12537. /*
  12538. * Information can be shared between the two HFIs on the same ASIC
  12539. * in the same OS. This function finds the peer device and sets
  12540. * up a shared structure.
  12541. */
  12542. static int init_asic_data(struct hfi1_devdata *dd)
  12543. {
  12544. unsigned long flags;
  12545. struct hfi1_devdata *tmp, *peer = NULL;
  12546. struct hfi1_asic_data *asic_data;
  12547. int ret = 0;
  12548. /* pre-allocate the asic structure in case we are the first device */
  12549. asic_data = kzalloc(sizeof(*dd->asic_data), GFP_KERNEL);
  12550. if (!asic_data)
  12551. return -ENOMEM;
  12552. spin_lock_irqsave(&hfi1_devs_lock, flags);
  12553. /* Find our peer device */
  12554. list_for_each_entry(tmp, &hfi1_dev_list, list) {
  12555. if ((HFI_BASE_GUID(dd) == HFI_BASE_GUID(tmp)) &&
  12556. dd->unit != tmp->unit) {
  12557. peer = tmp;
  12558. break;
  12559. }
  12560. }
  12561. if (peer) {
  12562. /* use already allocated structure */
  12563. dd->asic_data = peer->asic_data;
  12564. kfree(asic_data);
  12565. } else {
  12566. dd->asic_data = asic_data;
  12567. mutex_init(&dd->asic_data->asic_resource_mutex);
  12568. }
  12569. dd->asic_data->dds[dd->hfi1_id] = dd; /* self back-pointer */
  12570. spin_unlock_irqrestore(&hfi1_devs_lock, flags);
  12571. /* first one through - set up i2c devices */
  12572. if (!peer)
  12573. ret = set_up_i2c(dd, dd->asic_data);
  12574. return ret;
  12575. }
  12576. /*
  12577. * Set dd->boardname. Use a generic name if a name is not returned from
  12578. * EFI variable space.
  12579. *
  12580. * Return 0 on success, -ENOMEM if space could not be allocated.
  12581. */
  12582. static int obtain_boardname(struct hfi1_devdata *dd)
  12583. {
  12584. /* generic board description */
  12585. const char generic[] =
  12586. "Intel Omni-Path Host Fabric Interface Adapter 100 Series";
  12587. unsigned long size;
  12588. int ret;
  12589. ret = read_hfi1_efi_var(dd, "description", &size,
  12590. (void **)&dd->boardname);
  12591. if (ret) {
  12592. dd_dev_info(dd, "Board description not found\n");
  12593. /* use generic description */
  12594. dd->boardname = kstrdup(generic, GFP_KERNEL);
  12595. if (!dd->boardname)
  12596. return -ENOMEM;
  12597. }
  12598. return 0;
  12599. }
  12600. /*
  12601. * Check the interrupt registers to make sure that they are mapped correctly.
  12602. * It is intended to help user identify any mismapping by VMM when the driver
  12603. * is running in a VM. This function should only be called before interrupt
  12604. * is set up properly.
  12605. *
  12606. * Return 0 on success, -EINVAL on failure.
  12607. */
  12608. static int check_int_registers(struct hfi1_devdata *dd)
  12609. {
  12610. u64 reg;
  12611. u64 all_bits = ~(u64)0;
  12612. u64 mask;
  12613. /* Clear CceIntMask[0] to avoid raising any interrupts */
  12614. mask = read_csr(dd, CCE_INT_MASK);
  12615. write_csr(dd, CCE_INT_MASK, 0ull);
  12616. reg = read_csr(dd, CCE_INT_MASK);
  12617. if (reg)
  12618. goto err_exit;
  12619. /* Clear all interrupt status bits */
  12620. write_csr(dd, CCE_INT_CLEAR, all_bits);
  12621. reg = read_csr(dd, CCE_INT_STATUS);
  12622. if (reg)
  12623. goto err_exit;
  12624. /* Set all interrupt status bits */
  12625. write_csr(dd, CCE_INT_FORCE, all_bits);
  12626. reg = read_csr(dd, CCE_INT_STATUS);
  12627. if (reg != all_bits)
  12628. goto err_exit;
  12629. /* Restore the interrupt mask */
  12630. write_csr(dd, CCE_INT_CLEAR, all_bits);
  12631. write_csr(dd, CCE_INT_MASK, mask);
  12632. return 0;
  12633. err_exit:
  12634. write_csr(dd, CCE_INT_MASK, mask);
  12635. dd_dev_err(dd, "Interrupt registers not properly mapped by VMM\n");
  12636. return -EINVAL;
  12637. }
  12638. /**
  12639. * Allocate and initialize the device structure for the hfi.
  12640. * @dev: the pci_dev for hfi1_ib device
  12641. * @ent: pci_device_id struct for this dev
  12642. *
  12643. * Also allocates, initializes, and returns the devdata struct for this
  12644. * device instance
  12645. *
  12646. * This is global, and is called directly at init to set up the
  12647. * chip-specific function pointers for later use.
  12648. */
  12649. struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
  12650. const struct pci_device_id *ent)
  12651. {
  12652. struct hfi1_devdata *dd;
  12653. struct hfi1_pportdata *ppd;
  12654. u64 reg;
  12655. int i, ret;
  12656. static const char * const inames[] = { /* implementation names */
  12657. "RTL silicon",
  12658. "RTL VCS simulation",
  12659. "RTL FPGA emulation",
  12660. "Functional simulator"
  12661. };
  12662. struct pci_dev *parent = pdev->bus->self;
  12663. dd = hfi1_alloc_devdata(pdev, NUM_IB_PORTS *
  12664. sizeof(struct hfi1_pportdata));
  12665. if (IS_ERR(dd))
  12666. goto bail;
  12667. ppd = dd->pport;
  12668. for (i = 0; i < dd->num_pports; i++, ppd++) {
  12669. int vl;
  12670. /* init common fields */
  12671. hfi1_init_pportdata(pdev, ppd, dd, 0, 1);
  12672. /* DC supports 4 link widths */
  12673. ppd->link_width_supported =
  12674. OPA_LINK_WIDTH_1X | OPA_LINK_WIDTH_2X |
  12675. OPA_LINK_WIDTH_3X | OPA_LINK_WIDTH_4X;
  12676. ppd->link_width_downgrade_supported =
  12677. ppd->link_width_supported;
  12678. /* start out enabling only 4X */
  12679. ppd->link_width_enabled = OPA_LINK_WIDTH_4X;
  12680. ppd->link_width_downgrade_enabled =
  12681. ppd->link_width_downgrade_supported;
  12682. /* link width active is 0 when link is down */
  12683. /* link width downgrade active is 0 when link is down */
  12684. if (num_vls < HFI1_MIN_VLS_SUPPORTED ||
  12685. num_vls > HFI1_MAX_VLS_SUPPORTED) {
  12686. hfi1_early_err(&pdev->dev,
  12687. "Invalid num_vls %u, using %u VLs\n",
  12688. num_vls, HFI1_MAX_VLS_SUPPORTED);
  12689. num_vls = HFI1_MAX_VLS_SUPPORTED;
  12690. }
  12691. ppd->vls_supported = num_vls;
  12692. ppd->vls_operational = ppd->vls_supported;
  12693. ppd->actual_vls_operational = ppd->vls_supported;
  12694. /* Set the default MTU. */
  12695. for (vl = 0; vl < num_vls; vl++)
  12696. dd->vld[vl].mtu = hfi1_max_mtu;
  12697. dd->vld[15].mtu = MAX_MAD_PACKET;
  12698. /*
  12699. * Set the initial values to reasonable default, will be set
  12700. * for real when link is up.
  12701. */
  12702. ppd->lstate = IB_PORT_DOWN;
  12703. ppd->overrun_threshold = 0x4;
  12704. ppd->phy_error_threshold = 0xf;
  12705. ppd->port_crc_mode_enabled = link_crc_mask;
  12706. /* initialize supported LTP CRC mode */
  12707. ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
  12708. /* initialize enabled LTP CRC mode */
  12709. ppd->port_ltp_crc_mode |= cap_to_port_ltp(link_crc_mask) << 4;
  12710. /* start in offline */
  12711. ppd->host_link_state = HLS_DN_OFFLINE;
  12712. init_vl_arb_caches(ppd);
  12713. ppd->last_pstate = 0xff; /* invalid value */
  12714. }
  12715. dd->link_default = HLS_DN_POLL;
  12716. /*
  12717. * Do remaining PCIe setup and save PCIe values in dd.
  12718. * Any error printing is already done by the init code.
  12719. * On return, we have the chip mapped.
  12720. */
  12721. ret = hfi1_pcie_ddinit(dd, pdev);
  12722. if (ret < 0)
  12723. goto bail_free;
  12724. /* verify that reads actually work, save revision for reset check */
  12725. dd->revision = read_csr(dd, CCE_REVISION);
  12726. if (dd->revision == ~(u64)0) {
  12727. dd_dev_err(dd, "cannot read chip CSRs\n");
  12728. ret = -EINVAL;
  12729. goto bail_cleanup;
  12730. }
  12731. dd->majrev = (dd->revision >> CCE_REVISION_CHIP_REV_MAJOR_SHIFT)
  12732. & CCE_REVISION_CHIP_REV_MAJOR_MASK;
  12733. dd->minrev = (dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT)
  12734. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  12735. /*
  12736. * Check interrupt registers mapping if the driver has no access to
  12737. * the upstream component. In this case, it is likely that the driver
  12738. * is running in a VM.
  12739. */
  12740. if (!parent) {
  12741. ret = check_int_registers(dd);
  12742. if (ret)
  12743. goto bail_cleanup;
  12744. }
  12745. /*
  12746. * obtain the hardware ID - NOT related to unit, which is a
  12747. * software enumeration
  12748. */
  12749. reg = read_csr(dd, CCE_REVISION2);
  12750. dd->hfi1_id = (reg >> CCE_REVISION2_HFI_ID_SHIFT)
  12751. & CCE_REVISION2_HFI_ID_MASK;
  12752. /* the variable size will remove unwanted bits */
  12753. dd->icode = reg >> CCE_REVISION2_IMPL_CODE_SHIFT;
  12754. dd->irev = reg >> CCE_REVISION2_IMPL_REVISION_SHIFT;
  12755. dd_dev_info(dd, "Implementation: %s, revision 0x%x\n",
  12756. dd->icode < ARRAY_SIZE(inames) ?
  12757. inames[dd->icode] : "unknown", (int)dd->irev);
  12758. /* speeds the hardware can support */
  12759. dd->pport->link_speed_supported = OPA_LINK_SPEED_25G;
  12760. /* speeds allowed to run at */
  12761. dd->pport->link_speed_enabled = dd->pport->link_speed_supported;
  12762. /* give a reasonable active value, will be set on link up */
  12763. dd->pport->link_speed_active = OPA_LINK_SPEED_25G;
  12764. dd->chip_rcv_contexts = read_csr(dd, RCV_CONTEXTS);
  12765. dd->chip_send_contexts = read_csr(dd, SEND_CONTEXTS);
  12766. dd->chip_sdma_engines = read_csr(dd, SEND_DMA_ENGINES);
  12767. dd->chip_pio_mem_size = read_csr(dd, SEND_PIO_MEM_SIZE);
  12768. dd->chip_sdma_mem_size = read_csr(dd, SEND_DMA_MEM_SIZE);
  12769. /* fix up link widths for emulation _p */
  12770. ppd = dd->pport;
  12771. if (dd->icode == ICODE_FPGA_EMULATION && is_emulator_p(dd)) {
  12772. ppd->link_width_supported =
  12773. ppd->link_width_enabled =
  12774. ppd->link_width_downgrade_supported =
  12775. ppd->link_width_downgrade_enabled =
  12776. OPA_LINK_WIDTH_1X;
  12777. }
  12778. /* insure num_vls isn't larger than number of sdma engines */
  12779. if (HFI1_CAP_IS_KSET(SDMA) && num_vls > dd->chip_sdma_engines) {
  12780. dd_dev_err(dd, "num_vls %u too large, using %u VLs\n",
  12781. num_vls, dd->chip_sdma_engines);
  12782. num_vls = dd->chip_sdma_engines;
  12783. ppd->vls_supported = dd->chip_sdma_engines;
  12784. ppd->vls_operational = ppd->vls_supported;
  12785. }
  12786. /*
  12787. * Convert the ns parameter to the 64 * cclocks used in the CSR.
  12788. * Limit the max if larger than the field holds. If timeout is
  12789. * non-zero, then the calculated field will be at least 1.
  12790. *
  12791. * Must be after icode is set up - the cclock rate depends
  12792. * on knowing the hardware being used.
  12793. */
  12794. dd->rcv_intr_timeout_csr = ns_to_cclock(dd, rcv_intr_timeout) / 64;
  12795. if (dd->rcv_intr_timeout_csr >
  12796. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK)
  12797. dd->rcv_intr_timeout_csr =
  12798. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK;
  12799. else if (dd->rcv_intr_timeout_csr == 0 && rcv_intr_timeout)
  12800. dd->rcv_intr_timeout_csr = 1;
  12801. /* needs to be done before we look for the peer device */
  12802. read_guid(dd);
  12803. /* set up shared ASIC data with peer device */
  12804. ret = init_asic_data(dd);
  12805. if (ret)
  12806. goto bail_cleanup;
  12807. /* obtain chip sizes, reset chip CSRs */
  12808. init_chip(dd);
  12809. /* read in the PCIe link speed information */
  12810. ret = pcie_speeds(dd);
  12811. if (ret)
  12812. goto bail_cleanup;
  12813. /* call before get_platform_config(), after init_chip_resources() */
  12814. ret = eprom_init(dd);
  12815. if (ret)
  12816. goto bail_free_rcverr;
  12817. /* Needs to be called before hfi1_firmware_init */
  12818. get_platform_config(dd);
  12819. /* read in firmware */
  12820. ret = hfi1_firmware_init(dd);
  12821. if (ret)
  12822. goto bail_cleanup;
  12823. /*
  12824. * In general, the PCIe Gen3 transition must occur after the
  12825. * chip has been idled (so it won't initiate any PCIe transactions
  12826. * e.g. an interrupt) and before the driver changes any registers
  12827. * (the transition will reset the registers).
  12828. *
  12829. * In particular, place this call after:
  12830. * - init_chip() - the chip will not initiate any PCIe transactions
  12831. * - pcie_speeds() - reads the current link speed
  12832. * - hfi1_firmware_init() - the needed firmware is ready to be
  12833. * downloaded
  12834. */
  12835. ret = do_pcie_gen3_transition(dd);
  12836. if (ret)
  12837. goto bail_cleanup;
  12838. /* start setting dd values and adjusting CSRs */
  12839. init_early_variables(dd);
  12840. parse_platform_config(dd);
  12841. ret = obtain_boardname(dd);
  12842. if (ret)
  12843. goto bail_cleanup;
  12844. snprintf(dd->boardversion, BOARD_VERS_MAX,
  12845. "ChipABI %u.%u, ChipRev %u.%u, SW Compat %llu\n",
  12846. HFI1_CHIP_VERS_MAJ, HFI1_CHIP_VERS_MIN,
  12847. (u32)dd->majrev,
  12848. (u32)dd->minrev,
  12849. (dd->revision >> CCE_REVISION_SW_SHIFT)
  12850. & CCE_REVISION_SW_MASK);
  12851. ret = set_up_context_variables(dd);
  12852. if (ret)
  12853. goto bail_cleanup;
  12854. /* set initial RXE CSRs */
  12855. init_rxe(dd);
  12856. /* set initial TXE CSRs */
  12857. init_txe(dd);
  12858. /* set initial non-RXE, non-TXE CSRs */
  12859. init_other(dd);
  12860. /* set up KDETH QP prefix in both RX and TX CSRs */
  12861. init_kdeth_qp(dd);
  12862. ret = hfi1_dev_affinity_init(dd);
  12863. if (ret)
  12864. goto bail_cleanup;
  12865. /* send contexts must be set up before receive contexts */
  12866. ret = init_send_contexts(dd);
  12867. if (ret)
  12868. goto bail_cleanup;
  12869. ret = hfi1_create_ctxts(dd);
  12870. if (ret)
  12871. goto bail_cleanup;
  12872. dd->rcvhdrsize = DEFAULT_RCVHDRSIZE;
  12873. /*
  12874. * rcd[0] is guaranteed to be valid by this point. Also, all
  12875. * context are using the same value, as per the module parameter.
  12876. */
  12877. dd->rhf_offset = dd->rcd[0]->rcvhdrqentsize - sizeof(u64) / sizeof(u32);
  12878. ret = init_pervl_scs(dd);
  12879. if (ret)
  12880. goto bail_cleanup;
  12881. /* sdma init */
  12882. for (i = 0; i < dd->num_pports; ++i) {
  12883. ret = sdma_init(dd, i);
  12884. if (ret)
  12885. goto bail_cleanup;
  12886. }
  12887. /* use contexts created by hfi1_create_ctxts */
  12888. ret = set_up_interrupts(dd);
  12889. if (ret)
  12890. goto bail_cleanup;
  12891. /* set up LCB access - must be after set_up_interrupts() */
  12892. init_lcb_access(dd);
  12893. /*
  12894. * Serial number is created from the base guid:
  12895. * [27:24] = base guid [38:35]
  12896. * [23: 0] = base guid [23: 0]
  12897. */
  12898. snprintf(dd->serial, SERIAL_MAX, "0x%08llx\n",
  12899. (dd->base_guid & 0xFFFFFF) |
  12900. ((dd->base_guid >> 11) & 0xF000000));
  12901. dd->oui1 = dd->base_guid >> 56 & 0xFF;
  12902. dd->oui2 = dd->base_guid >> 48 & 0xFF;
  12903. dd->oui3 = dd->base_guid >> 40 & 0xFF;
  12904. ret = load_firmware(dd); /* asymmetric with dispose_firmware() */
  12905. if (ret)
  12906. goto bail_clear_intr;
  12907. thermal_init(dd);
  12908. ret = init_cntrs(dd);
  12909. if (ret)
  12910. goto bail_clear_intr;
  12911. ret = init_rcverr(dd);
  12912. if (ret)
  12913. goto bail_free_cntrs;
  12914. init_completion(&dd->user_comp);
  12915. /* The user refcount starts with one to inidicate an active device */
  12916. atomic_set(&dd->user_refcount, 1);
  12917. goto bail;
  12918. bail_free_rcverr:
  12919. free_rcverr(dd);
  12920. bail_free_cntrs:
  12921. free_cntrs(dd);
  12922. bail_clear_intr:
  12923. clean_up_interrupts(dd);
  12924. bail_cleanup:
  12925. hfi1_pcie_ddcleanup(dd);
  12926. bail_free:
  12927. hfi1_free_devdata(dd);
  12928. dd = ERR_PTR(ret);
  12929. bail:
  12930. return dd;
  12931. }
  12932. static u16 delay_cycles(struct hfi1_pportdata *ppd, u32 desired_egress_rate,
  12933. u32 dw_len)
  12934. {
  12935. u32 delta_cycles;
  12936. u32 current_egress_rate = ppd->current_egress_rate;
  12937. /* rates here are in units of 10^6 bits/sec */
  12938. if (desired_egress_rate == -1)
  12939. return 0; /* shouldn't happen */
  12940. if (desired_egress_rate >= current_egress_rate)
  12941. return 0; /* we can't help go faster, only slower */
  12942. delta_cycles = egress_cycles(dw_len * 4, desired_egress_rate) -
  12943. egress_cycles(dw_len * 4, current_egress_rate);
  12944. return (u16)delta_cycles;
  12945. }
  12946. /**
  12947. * create_pbc - build a pbc for transmission
  12948. * @flags: special case flags or-ed in built pbc
  12949. * @srate: static rate
  12950. * @vl: vl
  12951. * @dwlen: dword length (header words + data words + pbc words)
  12952. *
  12953. * Create a PBC with the given flags, rate, VL, and length.
  12954. *
  12955. * NOTE: The PBC created will not insert any HCRC - all callers but one are
  12956. * for verbs, which does not use this PSM feature. The lone other caller
  12957. * is for the diagnostic interface which calls this if the user does not
  12958. * supply their own PBC.
  12959. */
  12960. u64 create_pbc(struct hfi1_pportdata *ppd, u64 flags, int srate_mbs, u32 vl,
  12961. u32 dw_len)
  12962. {
  12963. u64 pbc, delay = 0;
  12964. if (unlikely(srate_mbs))
  12965. delay = delay_cycles(ppd, srate_mbs, dw_len);
  12966. pbc = flags
  12967. | (delay << PBC_STATIC_RATE_CONTROL_COUNT_SHIFT)
  12968. | ((u64)PBC_IHCRC_NONE << PBC_INSERT_HCRC_SHIFT)
  12969. | (vl & PBC_VL_MASK) << PBC_VL_SHIFT
  12970. | (dw_len & PBC_LENGTH_DWS_MASK)
  12971. << PBC_LENGTH_DWS_SHIFT;
  12972. return pbc;
  12973. }
  12974. #define SBUS_THERMAL 0x4f
  12975. #define SBUS_THERM_MONITOR_MODE 0x1
  12976. #define THERM_FAILURE(dev, ret, reason) \
  12977. dd_dev_err((dd), \
  12978. "Thermal sensor initialization failed: %s (%d)\n", \
  12979. (reason), (ret))
  12980. /*
  12981. * Initialize the thermal sensor.
  12982. *
  12983. * After initialization, enable polling of thermal sensor through
  12984. * SBus interface. In order for this to work, the SBus Master
  12985. * firmware has to be loaded due to the fact that the HW polling
  12986. * logic uses SBus interrupts, which are not supported with
  12987. * default firmware. Otherwise, no data will be returned through
  12988. * the ASIC_STS_THERM CSR.
  12989. */
  12990. static int thermal_init(struct hfi1_devdata *dd)
  12991. {
  12992. int ret = 0;
  12993. if (dd->icode != ICODE_RTL_SILICON ||
  12994. check_chip_resource(dd, CR_THERM_INIT, NULL))
  12995. return ret;
  12996. ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
  12997. if (ret) {
  12998. THERM_FAILURE(dd, ret, "Acquire SBus");
  12999. return ret;
  13000. }
  13001. dd_dev_info(dd, "Initializing thermal sensor\n");
  13002. /* Disable polling of thermal readings */
  13003. write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x0);
  13004. msleep(100);
  13005. /* Thermal Sensor Initialization */
  13006. /* Step 1: Reset the Thermal SBus Receiver */
  13007. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13008. RESET_SBUS_RECEIVER, 0);
  13009. if (ret) {
  13010. THERM_FAILURE(dd, ret, "Bus Reset");
  13011. goto done;
  13012. }
  13013. /* Step 2: Set Reset bit in Thermal block */
  13014. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13015. WRITE_SBUS_RECEIVER, 0x1);
  13016. if (ret) {
  13017. THERM_FAILURE(dd, ret, "Therm Block Reset");
  13018. goto done;
  13019. }
  13020. /* Step 3: Write clock divider value (100MHz -> 2MHz) */
  13021. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x1,
  13022. WRITE_SBUS_RECEIVER, 0x32);
  13023. if (ret) {
  13024. THERM_FAILURE(dd, ret, "Write Clock Div");
  13025. goto done;
  13026. }
  13027. /* Step 4: Select temperature mode */
  13028. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x3,
  13029. WRITE_SBUS_RECEIVER,
  13030. SBUS_THERM_MONITOR_MODE);
  13031. if (ret) {
  13032. THERM_FAILURE(dd, ret, "Write Mode Sel");
  13033. goto done;
  13034. }
  13035. /* Step 5: De-assert block reset and start conversion */
  13036. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13037. WRITE_SBUS_RECEIVER, 0x2);
  13038. if (ret) {
  13039. THERM_FAILURE(dd, ret, "Write Reset Deassert");
  13040. goto done;
  13041. }
  13042. /* Step 5.1: Wait for first conversion (21.5ms per spec) */
  13043. msleep(22);
  13044. /* Enable polling of thermal readings */
  13045. write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x1);
  13046. /* Set initialized flag */
  13047. ret = acquire_chip_resource(dd, CR_THERM_INIT, 0);
  13048. if (ret)
  13049. THERM_FAILURE(dd, ret, "Unable to set thermal init flag");
  13050. done:
  13051. release_chip_resource(dd, CR_SBUS);
  13052. return ret;
  13053. }
  13054. static void handle_temp_err(struct hfi1_devdata *dd)
  13055. {
  13056. struct hfi1_pportdata *ppd = &dd->pport[0];
  13057. /*
  13058. * Thermal Critical Interrupt
  13059. * Put the device into forced freeze mode, take link down to
  13060. * offline, and put DC into reset.
  13061. */
  13062. dd_dev_emerg(dd,
  13063. "Critical temperature reached! Forcing device into freeze mode!\n");
  13064. dd->flags |= HFI1_FORCED_FREEZE;
  13065. start_freeze_handling(ppd, FREEZE_SELF | FREEZE_ABORT);
  13066. /*
  13067. * Shut DC down as much and as quickly as possible.
  13068. *
  13069. * Step 1: Take the link down to OFFLINE. This will cause the
  13070. * 8051 to put the Serdes in reset. However, we don't want to
  13071. * go through the entire link state machine since we want to
  13072. * shutdown ASAP. Furthermore, this is not a graceful shutdown
  13073. * but rather an attempt to save the chip.
  13074. * Code below is almost the same as quiet_serdes() but avoids
  13075. * all the extra work and the sleeps.
  13076. */
  13077. ppd->driver_link_ready = 0;
  13078. ppd->link_enabled = 0;
  13079. set_physical_link_state(dd, (OPA_LINKDOWN_REASON_SMA_DISABLED << 8) |
  13080. PLS_OFFLINE);
  13081. /*
  13082. * Step 2: Shutdown LCB and 8051
  13083. * After shutdown, do not restore DC_CFG_RESET value.
  13084. */
  13085. dc_shutdown(dd);
  13086. }